aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-02-21 07:41:57 +0800
committerGitHub <noreply@github.com>2018-02-21 07:41:57 +0800
commit3076a434baccfebb1c3f35b4cb74a3283a195e26 (patch)
tree9c4bdd3627078cd6e0fa7eb505e713f7dc4cde33 /libsolidity
parent70790d4729a8cee7d587bf274ed1733b255b2120 (diff)
parente2bf5de8a278e04623c7bb34a925372039095ba7 (diff)
downloaddexon-solidity-3076a434baccfebb1c3f35b4cb74a3283a195e26.tar.gz
dexon-solidity-3076a434baccfebb1c3f35b4cb74a3283a195e26.tar.zst
dexon-solidity-3076a434baccfebb1c3f35b4cb74a3283a195e26.zip
Merge pull request #3554 from ethereum/reuseScannerOrNot
Expect end of string at end of top-level block for assembly parser.
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/codegen/CompilerContext.cpp2
-rw-r--r--libsolidity/inlineasm/AsmParser.cpp7
-rw-r--r--libsolidity/inlineasm/AsmParser.h3
-rw-r--r--libsolidity/interface/AssemblyStack.cpp2
-rw-r--r--libsolidity/parsing/Parser.cpp2
5 files changed, 10 insertions, 6 deletions
diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp
index 7a88475a..0198a107 100644
--- a/libsolidity/codegen/CompilerContext.cpp
+++ b/libsolidity/codegen/CompilerContext.cpp
@@ -319,7 +319,7 @@ void CompilerContext::appendInlineAssembly(
ErrorList errors;
ErrorReporter errorReporter(errors);
auto scanner = make_shared<Scanner>(CharStream(_assembly), "--CODEGEN--");
- auto parserResult = assembly::Parser(errorReporter, assembly::AsmFlavour::Strict).parse(scanner);
+ auto parserResult = assembly::Parser(errorReporter, assembly::AsmFlavour::Strict).parse(scanner, false);
#ifdef SOL_OUTPUT_ASM
cout << assembly::AsmPrinter()(*parserResult) << endl;
#endif
diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp
index 306b07e6..7f618e07 100644
--- a/libsolidity/inlineasm/AsmParser.cpp
+++ b/libsolidity/inlineasm/AsmParser.cpp
@@ -34,13 +34,16 @@ using namespace dev;
using namespace dev::solidity;
using namespace dev::solidity::assembly;
-shared_ptr<assembly::Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner)
+shared_ptr<assembly::Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner, bool _reuseScanner)
{
m_recursionDepth = 0;
try
{
m_scanner = _scanner;
- return make_shared<Block>(parseBlock());
+ auto block = make_shared<Block>(parseBlock());
+ if (!_reuseScanner)
+ expectToken(Token::EOS);
+ return block;
}
catch (FatalError const&)
{
diff --git a/libsolidity/inlineasm/AsmParser.h b/libsolidity/inlineasm/AsmParser.h
index 015aeef3..41117228 100644
--- a/libsolidity/inlineasm/AsmParser.h
+++ b/libsolidity/inlineasm/AsmParser.h
@@ -41,8 +41,9 @@ public:
ParserBase(_errorReporter), m_flavour(_flavour) {}
/// Parses an inline assembly block starting with `{` and ending with `}`.
+ /// @param _reuseScanner if true, do check for end of input after the `}`.
/// @returns an empty shared pointer on error.
- std::shared_ptr<Block> parse(std::shared_ptr<Scanner> const& _scanner);
+ std::shared_ptr<Block> parse(std::shared_ptr<Scanner> const& _scanner, bool _reuseScanner);
protected:
using ElementaryOperation = boost::variant<assembly::Instruction, assembly::Literal, assembly::Identifier>;
diff --git a/libsolidity/interface/AssemblyStack.cpp b/libsolidity/interface/AssemblyStack.cpp
index 1b4bd270..c9e534c7 100644
--- a/libsolidity/interface/AssemblyStack.cpp
+++ b/libsolidity/interface/AssemblyStack.cpp
@@ -69,7 +69,7 @@ bool AssemblyStack::parseAndAnalyze(std::string const& _sourceName, std::string
m_errors.clear();
m_analysisSuccessful = false;
m_scanner = make_shared<Scanner>(CharStream(_source), _sourceName);
- m_parserResult = assembly::Parser(m_errorReporter, languageToAsmFlavour(m_language)).parse(m_scanner);
+ m_parserResult = assembly::Parser(m_errorReporter, languageToAsmFlavour(m_language)).parse(m_scanner, false);
if (!m_errorReporter.errors().empty())
return false;
solAssert(m_parserResult, "");
diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp
index 05b877b5..e306e21b 100644
--- a/libsolidity/parsing/Parser.cpp
+++ b/libsolidity/parsing/Parser.cpp
@@ -926,7 +926,7 @@ ASTPointer<InlineAssembly> Parser::parseInlineAssembly(ASTPointer<ASTString> con
}
assembly::Parser asmParser(m_errorReporter);
- shared_ptr<assembly::Block> block = asmParser.parse(m_scanner);
+ shared_ptr<assembly::Block> block = asmParser.parse(m_scanner, true);
nodeFactory.markEndPosition();
return nodeFactory.createNode<InlineAssembly>(_docString, block);
}