diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-04-28 21:33:52 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-06-16 17:56:21 +0800 |
commit | 47925bc14e80d0c33c491dabc3c3dd3ea787b63c (patch) | |
tree | 10f0dc08bf0a78a02a921d7fa69449c94d6676a3 /libsolidity | |
parent | 54e97d1c34d7c291673e695a991db8df627c503e (diff) | |
download | dexon-solidity-47925bc14e80d0c33c491dabc3c3dd3ea787b63c.tar dexon-solidity-47925bc14e80d0c33c491dabc3c3dd3ea787b63c.tar.gz dexon-solidity-47925bc14e80d0c33c491dabc3c3dd3ea787b63c.tar.bz2 dexon-solidity-47925bc14e80d0c33c491dabc3c3dd3ea787b63c.tar.lz dexon-solidity-47925bc14e80d0c33c491dabc3c3dd3ea787b63c.tar.xz dexon-solidity-47925bc14e80d0c33c491dabc3c3dd3ea787b63c.tar.zst dexon-solidity-47925bc14e80d0c33c491dabc3c3dd3ea787b63c.zip |
Parse for statement in assembly parser / printer
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/inlineasm/AsmAnalysis.cpp | 5 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmAnalysis.h | 4 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmAnalysisInfo.h | 3 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmData.h | 4 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmParser.cpp | 16 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmParser.h | 1 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmPrinter.cpp | 13 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmPrinter.h | 2 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmScopeFiller.cpp | 5 | ||||
-rw-r--r-- | libsolidity/inlineasm/AsmScopeFiller.h | 2 |
10 files changed, 52 insertions, 3 deletions
diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp index 1a529118..68c940e7 100644 --- a/libsolidity/inlineasm/AsmAnalysis.cpp +++ b/libsolidity/inlineasm/AsmAnalysis.cpp @@ -310,6 +310,11 @@ bool AsmAnalyzer::operator()(Switch const& _switch) return success; } +bool AsmAnalyzer::operator()(assembly::ForLoop const&) +{ + solAssert(false, "For loop not supported."); +} + bool AsmAnalyzer::operator()(Block const& _block) { bool success = true; diff --git a/libsolidity/inlineasm/AsmAnalysis.h b/libsolidity/inlineasm/AsmAnalysis.h index 2516722a..5cdf72b1 100644 --- a/libsolidity/inlineasm/AsmAnalysis.h +++ b/libsolidity/inlineasm/AsmAnalysis.h @@ -51,7 +51,8 @@ struct StackAssignment; struct FunctionDefinition; struct FunctionCall; struct Switch; -using Statement = boost::variant<Instruction, Literal, Label, StackAssignment, Identifier, Assignment, FunctionCall, FunctionalInstruction, VariableDeclaration, FunctionDefinition, Switch, Block>; +struct ForLoop; +using Statement = boost::variant<Instruction, Literal, Label, StackAssignment, Identifier, Assignment, FunctionCall, FunctionalInstruction, VariableDeclaration, FunctionDefinition, Switch, Block, ForLoop>; struct AsmAnalysisInfo; @@ -83,6 +84,7 @@ public: bool operator()(assembly::FunctionDefinition const& _functionDefinition); bool operator()(assembly::FunctionCall const& _functionCall); bool operator()(assembly::Switch const& _switch); + bool operator()(assembly::ForLoop const& _forLoop); bool operator()(assembly::Block const& _block); private: diff --git a/libsolidity/inlineasm/AsmAnalysisInfo.h b/libsolidity/inlineasm/AsmAnalysisInfo.h index 78c1fbe0..a75413a2 100644 --- a/libsolidity/inlineasm/AsmAnalysisInfo.h +++ b/libsolidity/inlineasm/AsmAnalysisInfo.h @@ -45,10 +45,11 @@ struct StackAssignment; struct FunctionDefinition; struct FunctionCall; struct Switch; +struct ForLoop; struct Scope; -using Statement = boost::variant<Instruction, Literal, Label, StackAssignment, Identifier, Assignment, FunctionCall, FunctionalInstruction, VariableDeclaration, FunctionDefinition, Switch, Block>; +using Statement = boost::variant<Instruction, Literal, Label, StackAssignment, Identifier, Assignment, FunctionCall, FunctionalInstruction, VariableDeclaration, FunctionDefinition, Switch, ForLoop, Block>; struct AsmAnalysisInfo { diff --git a/libsolidity/inlineasm/AsmData.h b/libsolidity/inlineasm/AsmData.h index 72afeef1..c2458bd7 100644 --- a/libsolidity/inlineasm/AsmData.h +++ b/libsolidity/inlineasm/AsmData.h @@ -51,9 +51,10 @@ struct FunctionalInstruction; struct FunctionDefinition; struct FunctionCall; struct Switch; +struct ForLoop; struct Block; -using Statement = boost::variant<Instruction, Literal, Label, StackAssignment, Identifier, Assignment, FunctionCall, FunctionalInstruction, VariableDeclaration, FunctionDefinition, Switch, Block>; +using Statement = boost::variant<Instruction, Literal, Label, StackAssignment, Identifier, Assignment, FunctionCall, FunctionalInstruction, VariableDeclaration, FunctionDefinition, Switch, ForLoop, Block>; /// Direct EVM instruction (except PUSHi and JUMPDEST) struct Instruction { SourceLocation location; solidity::Instruction instruction; }; @@ -82,6 +83,7 @@ struct FunctionDefinition { SourceLocation location; std::string name; TypedName struct Case { SourceLocation location; std::shared_ptr<Literal> value; Block body; }; /// Switch statement struct Switch { SourceLocation location; std::shared_ptr<Statement> expression; std::vector<Case> cases; }; +struct ForLoop { SourceLocation location; Block pre; std::shared_ptr<Statement> condition; Block post; Block body; }; struct LocationExtractor: boost::static_visitor<SourceLocation> { diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp index f9b073ba..d282a30d 100644 --- a/libsolidity/inlineasm/AsmParser.cpp +++ b/libsolidity/inlineasm/AsmParser.cpp @@ -87,6 +87,8 @@ assembly::Statement Parser::parseStatement() _switch.location.end = _switch.cases.back().body.location.end; return _switch; } + case Token::For: + return parseForLoop(); case Token::Assign: { if (m_julia) @@ -171,6 +173,20 @@ assembly::Case Parser::parseCase() return _case; } +assembly::ForLoop Parser::parseForLoop() +{ + ForLoop forLoop = createWithLocation<ForLoop>(); + expectToken(Token::For); + forLoop.pre = parseBlock(); + forLoop.condition = make_shared<Statement>(parseExpression()); + if (forLoop.condition->type() == typeid(assembly::Instruction)) + fatalParserError("Instructions are not supported as conditions for the for statement."); + forLoop.post = parseBlock(); + forLoop.body = parseBlock(); + forLoop.location.end = forLoop.body.location.end; + return forLoop; +} + assembly::Statement Parser::parseExpression() { Statement operation = parseElementaryOperation(true); diff --git a/libsolidity/inlineasm/AsmParser.h b/libsolidity/inlineasm/AsmParser.h index 5fafad23..45708afd 100644 --- a/libsolidity/inlineasm/AsmParser.h +++ b/libsolidity/inlineasm/AsmParser.h @@ -63,6 +63,7 @@ protected: Block parseBlock(); Statement parseStatement(); Case parseCase(); + ForLoop parseForLoop(); /// Parses a functional expression that has to push exactly one stack element Statement parseExpression(); static std::map<std::string, dev::solidity::Instruction> const& instructions(); diff --git a/libsolidity/inlineasm/AsmPrinter.cpp b/libsolidity/inlineasm/AsmPrinter.cpp index e282e5e8..0d06fedd 100644 --- a/libsolidity/inlineasm/AsmPrinter.cpp +++ b/libsolidity/inlineasm/AsmPrinter.cpp @@ -181,6 +181,19 @@ string AsmPrinter::operator()(Switch const& _switch) return out; } +string AsmPrinter::operator()(assembly::ForLoop const& _forLoop) +{ + string out = "for "; + out += (*this)(_forLoop.pre); + out += "\n"; + out += boost::apply_visitor(*this, *_forLoop.condition); + out += "\n"; + out += (*this)(_forLoop.post); + out += "\n"; + out += (*this)(_forLoop.body); + return out; +} + string AsmPrinter::operator()(Block const& _block) { if (_block.statements.empty()) diff --git a/libsolidity/inlineasm/AsmPrinter.h b/libsolidity/inlineasm/AsmPrinter.h index b0d7fc09..8808b058 100644 --- a/libsolidity/inlineasm/AsmPrinter.h +++ b/libsolidity/inlineasm/AsmPrinter.h @@ -41,6 +41,7 @@ struct VariableDeclaration; struct FunctionDefinition; struct FunctionCall; struct Switch; +struct ForLoop; struct Block; class AsmPrinter: public boost::static_visitor<std::string> @@ -59,6 +60,7 @@ public: std::string operator()(assembly::FunctionDefinition const& _functionDefinition); std::string operator()(assembly::FunctionCall const& _functionCall); std::string operator()(assembly::Switch const& _switch); + std::string operator()(assembly::ForLoop const& _forLoop); std::string operator()(assembly::Block const& _block); private: diff --git a/libsolidity/inlineasm/AsmScopeFiller.cpp b/libsolidity/inlineasm/AsmScopeFiller.cpp index 4d26dcf8..1aac902a 100644 --- a/libsolidity/inlineasm/AsmScopeFiller.cpp +++ b/libsolidity/inlineasm/AsmScopeFiller.cpp @@ -111,6 +111,11 @@ bool ScopeFiller::operator()(Switch const& _switch) return success; } +bool ScopeFiller::operator()(ForLoop const&) +{ + solAssert(false, "For loop not supported."); +} + bool ScopeFiller::operator()(Block const& _block) { bool success = true; diff --git a/libsolidity/inlineasm/AsmScopeFiller.h b/libsolidity/inlineasm/AsmScopeFiller.h index 1166d50f..f04352c9 100644 --- a/libsolidity/inlineasm/AsmScopeFiller.h +++ b/libsolidity/inlineasm/AsmScopeFiller.h @@ -47,6 +47,7 @@ struct StackAssignment; struct FunctionDefinition; struct FunctionCall; struct Switch; +struct ForLoop; struct Scope; struct AsmAnalysisInfo; @@ -71,6 +72,7 @@ public: bool operator()(assembly::FunctionDefinition const& _functionDefinition); bool operator()(assembly::FunctionCall const&) { return true; } bool operator()(assembly::Switch const& _switch); + bool operator()(assembly::ForLoop const& _forLoop); bool operator()(assembly::Block const& _block); private: |