aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-08-20 01:57:21 +0800
committerchriseth <c@ethdev.com>2016-09-01 06:02:51 +0800
commit3c412ed2f63a58b27eeb00fe584b9378311b099f (patch)
treecba706f91c05658a8b1f8794ad21745ea5619e39 /libsolidity/ast
parent52d9f897126394dcc7388277d4fbd3ef7b4df38a (diff)
downloaddexon-solidity-3c412ed2f63a58b27eeb00fe584b9378311b099f.tar.gz
dexon-solidity-3c412ed2f63a58b27eeb00fe584b9378311b099f.tar.zst
dexon-solidity-3c412ed2f63a58b27eeb00fe584b9378311b099f.zip
Version pragma.
Diffstat (limited to 'libsolidity/ast')
-rw-r--r--libsolidity/ast/AST.h28
-rw-r--r--libsolidity/ast/ASTForward.h1
-rw-r--r--libsolidity/ast/ASTJsonConverter.cpp13
-rw-r--r--libsolidity/ast/ASTJsonConverter.h2
-rw-r--r--libsolidity/ast/ASTPrinter.cpp12
-rw-r--r--libsolidity/ast/ASTPrinter.h2
-rw-r--r--libsolidity/ast/ASTVisitor.h4
-rw-r--r--libsolidity/ast/AST_accept.h12
8 files changed, 74 insertions, 0 deletions
diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h
index bf275869..761d85fe 100644
--- a/libsolidity/ast/AST.h
+++ b/libsolidity/ast/AST.h
@@ -176,6 +176,34 @@ private:
};
/**
+ * Pragma directive, only version requirements in the form `pragma solidity "^0.4.0";` are
+ * supported for now.
+ */
+class PragmaDirective: public ASTNode
+{
+public:
+ PragmaDirective(
+ SourceLocation const& _location,
+ std::vector<Token::Value> const& _tokens,
+ std::vector<ASTString> const& _literals
+ ): ASTNode(_location), m_tokens(_tokens), m_literals(_literals)
+ {}
+
+ virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
+
+ std::vector<Token::Value> const& tokens() const { return m_tokens; }
+ std::vector<ASTString> const& literals() const { return m_literals; }
+
+private:
+
+ /// Sequence of tokens following the "pragma" keyword.
+ std::vector<Token::Value> m_tokens;
+ /// Sequence of literals following the "pragma" keyword.
+ std::vector<ASTString> m_literals;
+};
+
+/**
* Import directive for referencing other files / source objects.
* Example: import "abc.sol" // imports all symbols of "abc.sol" into current scope
* Source objects are identified by a string which can be a file name but does not have to be.
diff --git a/libsolidity/ast/ASTForward.h b/libsolidity/ast/ASTForward.h
index dad2b2e2..59fc1b57 100644
--- a/libsolidity/ast/ASTForward.h
+++ b/libsolidity/ast/ASTForward.h
@@ -35,6 +35,7 @@ namespace solidity
class ASTNode;
class SourceUnit;
+class PragmaDirective;
class ImportDirective;
class Declaration;
class ContractDefinition;
diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp
index 35fd0b7d..49ee6d34 100644
--- a/libsolidity/ast/ASTJsonConverter.cpp
+++ b/libsolidity/ast/ASTJsonConverter.cpp
@@ -103,6 +103,15 @@ bool ASTJsonConverter::visit(SourceUnit const&)
return true;
}
+bool ASTJsonConverter::visit(PragmaDirective const& _node)
+{
+ Json::Value literals(Json::arrayValue);
+ for (auto const& literal: _node.literals())
+ literals.append(literal);
+ addJsonNode(_node, "PragmaDirective", { make_pair("literals", literals) });
+ return true;
+}
+
bool ASTJsonConverter::visit(ImportDirective const& _node)
{
addJsonNode(_node, "ImportDirective", { make_pair("file", _node.path())});
@@ -401,6 +410,10 @@ void ASTJsonConverter::endVisit(SourceUnit const&)
goUp();
}
+void ASTJsonConverter::endVisit(PragmaDirective const&)
+{
+}
+
void ASTJsonConverter::endVisit(ImportDirective const&)
{
}
diff --git a/libsolidity/ast/ASTJsonConverter.h b/libsolidity/ast/ASTJsonConverter.h
index 97aa8654..7c7b37f8 100644
--- a/libsolidity/ast/ASTJsonConverter.h
+++ b/libsolidity/ast/ASTJsonConverter.h
@@ -52,6 +52,7 @@ public:
Json::Value const& json();
bool visit(SourceUnit const& _node) override;
+ bool visit(PragmaDirective const& _node) override;
bool visit(ImportDirective const& _node) override;
bool visit(ContractDefinition const& _node) override;
bool visit(InheritanceSpecifier const& _node) override;
@@ -96,6 +97,7 @@ public:
bool visit(Literal const& _node) override;
void endVisit(SourceUnit const&) override;
+ void endVisit(PragmaDirective const&) override;
void endVisit(ImportDirective const&) override;
void endVisit(ContractDefinition const&) override;
void endVisit(InheritanceSpecifier const&) override;
diff --git a/libsolidity/ast/ASTPrinter.cpp b/libsolidity/ast/ASTPrinter.cpp
index 9ed9c6d5..a9de457a 100644
--- a/libsolidity/ast/ASTPrinter.cpp
+++ b/libsolidity/ast/ASTPrinter.cpp
@@ -47,6 +47,13 @@ void ASTPrinter::print(ostream& _stream)
}
+bool ASTPrinter::visit(PragmaDirective const& _node)
+{
+ writeLine("PragmaDirective");
+ printSourcePart(_node);
+ return goDeeper();
+}
+
bool ASTPrinter::visit(ImportDirective const& _node)
{
writeLine("ImportDirective \"" + _node.path() + "\"");
@@ -355,6 +362,11 @@ bool ASTPrinter::visit(Literal const& _node)
return goDeeper();
}
+void ASTPrinter::endVisit(PragmaDirective const&)
+{
+ m_indentation--;
+}
+
void ASTPrinter::endVisit(ImportDirective const&)
{
m_indentation--;
diff --git a/libsolidity/ast/ASTPrinter.h b/libsolidity/ast/ASTPrinter.h
index a2546935..f0ab1098 100644
--- a/libsolidity/ast/ASTPrinter.h
+++ b/libsolidity/ast/ASTPrinter.h
@@ -47,6 +47,7 @@ public:
/// Output the string representation of the AST to _stream.
void print(std::ostream& _stream);
+ bool visit(PragmaDirective const& _node) override;
bool visit(ImportDirective const& _node) override;
bool visit(ContractDefinition const& _node) override;
bool visit(InheritanceSpecifier const& _node) override;
@@ -89,6 +90,7 @@ public:
bool visit(ElementaryTypeNameExpression const& _node) override;
bool visit(Literal const& _node) override;
+ void endVisit(PragmaDirective const&) override;
void endVisit(ImportDirective const&) override;
void endVisit(ContractDefinition const&) override;
void endVisit(InheritanceSpecifier const&) override;
diff --git a/libsolidity/ast/ASTVisitor.h b/libsolidity/ast/ASTVisitor.h
index 5aac2066..3a1b55d3 100644
--- a/libsolidity/ast/ASTVisitor.h
+++ b/libsolidity/ast/ASTVisitor.h
@@ -44,6 +44,7 @@ class ASTVisitor
{
public:
virtual bool visit(SourceUnit& _node) { return visitNode(_node); }
+ virtual bool visit(PragmaDirective& _node) { return visitNode(_node); }
virtual bool visit(ImportDirective& _node) { return visitNode(_node); }
virtual bool visit(ContractDefinition& _node) { return visitNode(_node); }
virtual bool visit(InheritanceSpecifier& _node) { return visitNode(_node); }
@@ -88,6 +89,7 @@ public:
virtual bool visit(Literal& _node) { return visitNode(_node); }
virtual void endVisit(SourceUnit& _node) { endVisitNode(_node); }
+ virtual void endVisit(PragmaDirective& _node) { endVisitNode(_node); }
virtual void endVisit(ImportDirective& _node) { endVisitNode(_node); }
virtual void endVisit(ContractDefinition& _node) { endVisitNode(_node); }
virtual void endVisit(InheritanceSpecifier& _node) { endVisitNode(_node); }
@@ -144,6 +146,7 @@ class ASTConstVisitor
{
public:
virtual bool visit(SourceUnit const& _node) { return visitNode(_node); }
+ virtual bool visit(PragmaDirective const& _node) { return visitNode(_node); }
virtual bool visit(ImportDirective const& _node) { return visitNode(_node); }
virtual bool visit(ContractDefinition const& _node) { return visitNode(_node); }
virtual bool visit(InheritanceSpecifier const& _node) { return visitNode(_node); }
@@ -188,6 +191,7 @@ public:
virtual bool visit(Literal const& _node) { return visitNode(_node); }
virtual void endVisit(SourceUnit const& _node) { endVisitNode(_node); }
+ virtual void endVisit(PragmaDirective const& _node) { endVisitNode(_node); }
virtual void endVisit(ImportDirective const& _node) { endVisitNode(_node); }
virtual void endVisit(ContractDefinition const& _node) { endVisitNode(_node); }
virtual void endVisit(InheritanceSpecifier const& _node) { endVisitNode(_node); }
diff --git a/libsolidity/ast/AST_accept.h b/libsolidity/ast/AST_accept.h
index dd2a7d60..b5a3806b 100644
--- a/libsolidity/ast/AST_accept.h
+++ b/libsolidity/ast/AST_accept.h
@@ -45,6 +45,18 @@ void SourceUnit::accept(ASTConstVisitor& _visitor) const
_visitor.endVisit(*this);
}
+void PragmaDirective::accept(ASTVisitor& _visitor)
+{
+ _visitor.visit(*this);
+ _visitor.endVisit(*this);
+}
+
+void PragmaDirective::accept(ASTConstVisitor& _visitor) const
+{
+ _visitor.visit(*this);
+ _visitor.endVisit(*this);
+}
+
void ImportDirective::accept(ASTVisitor& _visitor)
{
_visitor.visit(*this);