diff options
author | chriseth <chris@ethereum.org> | 2018-12-20 01:06:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-20 01:06:13 +0800 |
commit | 1df8f40cd2fd7b47698d847907b8ca7b47eb488d (patch) | |
tree | 5ed5816fe2d1a8a207e750d39884aca7957c8289 /libyul/AsmParser.cpp | |
parent | c8a2cb62832afb2dc09ccee6fd42c1516dfdb981 (diff) | |
parent | ddf54b21d1d002903624f61173ab4af197f50053 (diff) | |
download | dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar.gz dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar.bz2 dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar.lz dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar.xz dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.tar.zst dexon-solidity-1df8f40cd2fd7b47698d847907b8ca7b47eb488d.zip |
Merge pull request #5697 from ethereum/develop
Merge develop into release for 0.5.2
Diffstat (limited to 'libyul/AsmParser.cpp')
-rw-r--r-- | libyul/AsmParser.cpp | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/libyul/AsmParser.cpp b/libyul/AsmParser.cpp index 2ce94f85..f3ca6cd0 100644 --- a/libyul/AsmParser.cpp +++ b/libyul/AsmParser.cpp @@ -107,14 +107,16 @@ Statement Parser::parseStatement() return parseForLoop(); case Token::Assign: { - if (m_flavour != AsmFlavour::Loose) + if (m_dialect->flavour != AsmFlavour::Loose) break; StackAssignment assignment = createWithLocation<StackAssignment>(); advance(); expectToken(Token::Colon); assignment.variableName.location = location(); assignment.variableName.name = YulString(currentLiteral()); - if (instructions().count(assignment.variableName.name.str())) + if (m_dialect->builtin(assignment.variableName.name)) + fatalParserError("Identifier expected, got builtin symbol."); + else if (instructions().count(assignment.variableName.name.str())) fatalParserError("Identifier expected, got instruction name."); assignment.location.end = endPosition(); expectToken(Token::Identifier); @@ -174,7 +176,9 @@ Statement Parser::parseStatement() if (currentToken() == Token::Assign && peekNextToken() != Token::Colon) { Assignment assignment = createWithLocation<Assignment>(identifier.location); - if (m_flavour != AsmFlavour::Yul && instructions().count(identifier.name.str())) + if (m_dialect->builtin(identifier.name)) + fatalParserError("Cannot assign to builtin function \"" + identifier.name.str() + "\"."); + else if (m_dialect->flavour != AsmFlavour::Yul && instructions().count(identifier.name.str())) fatalParserError("Cannot use instruction names for identifier names."); advance(); assignment.variableNames.emplace_back(identifier); @@ -185,7 +189,7 @@ Statement Parser::parseStatement() else { // label - if (m_flavour != AsmFlavour::Loose) + if (m_dialect->flavour != AsmFlavour::Loose) fatalParserError("Labels are not supported."); Label label = createWithLocation<Label>(identifier.location); label.name = identifier.name; @@ -193,7 +197,7 @@ Statement Parser::parseStatement() } } default: - if (m_flavour != AsmFlavour::Loose) + if (m_dialect->flavour != AsmFlavour::Loose) fatalParserError("Call or assignment expected."); break; } @@ -269,7 +273,7 @@ Expression Parser::parseExpression() instructionNames().at(instr.instruction) + "\" not allowed in this context." ); - if (m_flavour != AsmFlavour::Loose && currentToken() != Token::LParen) + if (m_dialect->flavour != AsmFlavour::Loose && currentToken() != Token::LParen) fatalParserError( "Non-functional instructions are not allowed in this context." ); @@ -289,7 +293,7 @@ Expression Parser::parseExpression() else if (operation.type() == typeid(Instruction)) { // Instructions not taking arguments are allowed as expressions. - solAssert(m_flavour == AsmFlavour::Loose, ""); + solAssert(m_dialect->flavour == AsmFlavour::Loose, ""); Instruction& instr = boost::get<Instruction>(operation); return FunctionalInstruction{std::move(instr.location), instr.instruction, {}}; } @@ -348,23 +352,25 @@ Parser::ElementaryOperation Parser::parseElementaryOperation() case Token::Byte: case Token::Address: { - string literal; + YulString literal; if (currentToken() == Token::Return) - literal = "return"; + literal = "return"_yulstring; else if (currentToken() == Token::Byte) - literal = "byte"; + literal = "byte"_yulstring; else if (currentToken() == Token::Address) - literal = "address"; + literal = "address"_yulstring; else - literal = currentLiteral(); - // first search the set of instructions. - if (m_flavour != AsmFlavour::Yul && instructions().count(literal)) + literal = YulString{currentLiteral()}; + // first search the set of builtins, then the instructions. + if (m_dialect->builtin(literal)) + ret = Identifier{location(), literal}; + else if (m_dialect->flavour != AsmFlavour::Yul && instructions().count(literal.str())) { - dev::solidity::Instruction const& instr = instructions().at(literal); + dev::solidity::Instruction const& instr = instructions().at(literal.str()); ret = Instruction{location(), instr}; } else - ret = Identifier{location(), YulString{literal}}; + ret = Identifier{location(), literal}; advance(); break; } @@ -399,11 +405,11 @@ Parser::ElementaryOperation Parser::parseElementaryOperation() {} }; advance(); - if (m_flavour == AsmFlavour::Yul) + if (m_dialect->flavour == AsmFlavour::Yul) { expectToken(Token::Colon); literal.location.end = endPosition(); - literal.type = YulString{expectAsmIdentifier()}; + literal.type = expectAsmIdentifier(); } else if (kind == LiteralKind::Boolean) fatalParserError("True and false are not valid literals."); @@ -412,7 +418,7 @@ Parser::ElementaryOperation Parser::parseElementaryOperation() } default: fatalParserError( - m_flavour == AsmFlavour::Yul ? + m_dialect->flavour == AsmFlavour::Yul ? "Literal or identifier expected." : "Literal, identifier or instruction expected." ); @@ -450,7 +456,7 @@ FunctionDefinition Parser::parseFunctionDefinition() RecursionGuard recursionGuard(*this); FunctionDefinition funDef = createWithLocation<FunctionDefinition>(); expectToken(Token::Function); - funDef.name = YulString{expectAsmIdentifier()}; + funDef.name = expectAsmIdentifier(); expectToken(Token::LParen); while (currentToken() != Token::RParen) { @@ -482,7 +488,7 @@ Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp) RecursionGuard recursionGuard(*this); if (_initialOp.type() == typeid(Instruction)) { - solAssert(m_flavour != AsmFlavour::Yul, "Instructions are invalid in Yul"); + solAssert(m_dialect->flavour != AsmFlavour::Yul, "Instructions are invalid in Yul"); Instruction& instruction = boost::get<Instruction>(_initialOp); FunctionalInstruction ret; ret.instruction = instruction.instruction; @@ -553,7 +559,7 @@ Expression Parser::parseCall(Parser::ElementaryOperation&& _initialOp) } else fatalParserError( - m_flavour == AsmFlavour::Yul ? + m_dialect->flavour == AsmFlavour::Yul ? "Function name expected." : "Assembly instruction or function name required in front of \"(\")" ); @@ -565,20 +571,20 @@ TypedName Parser::parseTypedName() { RecursionGuard recursionGuard(*this); TypedName typedName = createWithLocation<TypedName>(); - typedName.name = YulString{expectAsmIdentifier()}; - if (m_flavour == AsmFlavour::Yul) + typedName.name = expectAsmIdentifier(); + if (m_dialect->flavour == AsmFlavour::Yul) { expectToken(Token::Colon); typedName.location.end = endPosition(); - typedName.type = YulString{expectAsmIdentifier()}; + typedName.type = expectAsmIdentifier(); } return typedName; } -string Parser::expectAsmIdentifier() +YulString Parser::expectAsmIdentifier() { - string name = currentLiteral(); - if (m_flavour == AsmFlavour::Yul) + YulString name = YulString{currentLiteral()}; + if (m_dialect->flavour == AsmFlavour::Yul) { switch (currentToken()) { @@ -592,7 +598,9 @@ string Parser::expectAsmIdentifier() break; } } - else if (instructions().count(name)) + else if (m_dialect->builtin(name)) + fatalParserError("Cannot use builtin function name \"" + name.str() + "\" as identifier name."); + else if (instructions().count(name.str())) fatalParserError("Cannot use instruction names for identifier names."); expectToken(Token::Identifier); return name; |