diff options
author | chriseth <c@ethdev.com> | 2016-04-18 19:47:40 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2016-04-20 00:35:21 +0800 |
commit | ed9da5171b84e6e1846820a45d97e5c041d57206 (patch) | |
tree | fd74dd485ded436d3b170be627087857396ea65d /libsolidity/inlineasm/AsmData.h | |
parent | 81ae2a78321fddcd2d32efc51568ebeca28866a8 (diff) | |
download | dexon-solidity-ed9da5171b84e6e1846820a45d97e5c041d57206.tar.gz dexon-solidity-ed9da5171b84e6e1846820a45d97e5c041d57206.tar.zst dexon-solidity-ed9da5171b84e6e1846820a45d97e5c041d57206.zip |
Source location for inline assembly.
Diffstat (limited to 'libsolidity/inlineasm/AsmData.h')
-rw-r--r-- | libsolidity/inlineasm/AsmData.h | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/libsolidity/inlineasm/AsmData.h b/libsolidity/inlineasm/AsmData.h index 42f0ae31..d6abf67f 100644 --- a/libsolidity/inlineasm/AsmData.h +++ b/libsolidity/inlineasm/AsmData.h @@ -24,6 +24,7 @@ #include <boost/variant.hpp> #include <libevmasm/Instruction.h> +#include <libevmasm/SourceLocation.h> namespace dev { @@ -35,29 +36,43 @@ namespace assembly /// What follows are the AST nodes for assembly. /// Direct EVM instruction (except PUSHi and JUMPDEST) -struct Instruction { solidity::Instruction instruction; }; +struct Instruction { SourceLocation location; solidity::Instruction instruction; }; /// Literal number or string (up to 32 bytes) -struct Literal { bool isNumber; std::string value; }; +struct Literal { SourceLocation location; bool isNumber; std::string value; }; /// External / internal identifier or label reference -struct Identifier { std::string name; }; +struct Identifier { SourceLocation location; std::string name; }; struct FunctionalInstruction; /// Jump label ("name:") -struct Label { std::string name; }; +struct Label { SourceLocation location; std::string name; }; /// Assignemnt (":= x", moves stack top into x, potentially multiple slots) -struct Assignment { Identifier variableName; }; +struct Assignment { SourceLocation location; Identifier variableName; }; struct FunctionalAssignment; struct VariableDeclaration; struct Block; using Statement = boost::variant<Instruction, Literal, Label, Assignment, Identifier, FunctionalAssignment, FunctionalInstruction, VariableDeclaration, Block>; /// Functional assignment ("x := mload(20)", expects push-1-expression on the right hand /// side and requires x to occupy exactly one stack slot. -struct FunctionalAssignment { Identifier variableName; std::shared_ptr<Statement> value; }; +struct FunctionalAssignment { SourceLocation location; Identifier variableName; std::shared_ptr<Statement> value; }; /// Functional instruction, e.g. "mul(mload(20), add(2, x))" -struct FunctionalInstruction { Instruction instruction; std::vector<Statement> arguments; }; +struct FunctionalInstruction { SourceLocation location; Instruction instruction; std::vector<Statement> arguments; }; /// Block-scope variable declaration ("let x := mload(20)"), non-hoisted -struct VariableDeclaration { std::string name; std::shared_ptr<Statement> value; }; +struct VariableDeclaration { SourceLocation location; std::string name; std::shared_ptr<Statement> value; }; /// Block that creates a scope (frees declared stack variables) -struct Block { std::vector<Statement> statements; }; +struct Block { SourceLocation location; std::vector<Statement> statements; }; + +struct LocationExtractor: boost::static_visitor<SourceLocation> +{ + template <class T> SourceLocation operator()(T const& _node) const + { + return _node.location; + } +}; + +/// Extracts the source location from an inline assembly node. +template <class T> inline SourceLocation locationOf(T const& _node) +{ + return boost::apply_visitor(LocationExtractor(), _node); +} } } |