diff options
Diffstat (limited to 'src/wasm/wasm-s-parser.cpp')
-rw-r--r-- | src/wasm/wasm-s-parser.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/wasm/wasm-s-parser.cpp b/src/wasm/wasm-s-parser.cpp index 1087eedc6..0c413af2a 100644 --- a/src/wasm/wasm-s-parser.cpp +++ b/src/wasm/wasm-s-parser.cpp @@ -140,7 +140,7 @@ void Element::dump() { std::cout << "dumping " << this << " : " << *this << ".\n"; } -SExpressionParser::SExpressionParser(char* input) : input(input) { +SExpressionParser::SExpressionParser(char const* input) : input(input) { root = nullptr; line = 1; lineStart = input; @@ -190,15 +190,15 @@ Element* SExpressionParser::parse() { void SExpressionParser::parseDebugLocation() { // Extracting debug location (if valid) - char* debugLoc = input + 3; // skipping ";;@" + char const* debugLoc = input + 3; // skipping ";;@" while (debugLoc[0] && debugLoc[0] == ' ') { debugLoc++; } - char* debugLocEnd = debugLoc; + char const* debugLocEnd = debugLoc; while (debugLocEnd[0] && debugLocEnd[0] != '\n') { debugLocEnd++; } - char* pos = debugLoc; + char const* pos = debugLoc; while (pos < debugLocEnd && pos[0] != ':') { pos++; } @@ -206,7 +206,7 @@ void SExpressionParser::parseDebugLocation() { return; // no line number } std::string name(debugLoc, pos); - char* lineStart = ++pos; + char const* lineStart = ++pos; while (pos < debugLocEnd && pos[0] != ':') { pos++; } @@ -279,7 +279,7 @@ Element* SExpressionParser::parseString() { input++; dollared = true; } - char* start = input; + char const* start = input; if (input[0] == '"') { // parse escaping \", but leave code escaped - we'll handle escaping in // memory segments specifically @@ -317,12 +317,14 @@ Element* SExpressionParser::parseString() { if (start == input) { throw ParseException("expected string", line, input - lineStart); } - char temp = input[0]; - input[0] = 0; + + std::string temp; + temp.assign(start, input - start); + auto ret = allocator.alloc<Element>() - ->setString(IString(start, false), dollared, false) + ->setString(IString(temp.c_str(), false), dollared, false) ->setMetadata(line, start - lineStart, loc); - input[0] = temp; + return ret; } |