aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ast
diff options
context:
space:
mode:
Diffstat (limited to 'libsolidity/ast')
-rw-r--r--libsolidity/ast/AST.h27
-rw-r--r--libsolidity/ast/ASTVisitor.h4
-rw-r--r--libsolidity/ast/AST_accept.h22
3 files changed, 53 insertions, 0 deletions
diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h
index a28d9f4f..2d6e9cfc 100644
--- a/libsolidity/ast/AST.h
+++ b/libsolidity/ast/AST.h
@@ -335,6 +335,33 @@ private:
std::vector<ASTPointer<Expression>> m_arguments;
};
+/**
+ * `using LibraryName for uint` will attach all functions from the library LibraryName
+ * to `uint` if the first parameter matches the type. `using LibraryName for *` attaches
+ * the function to any matching type.
+ */
+class UsingForDirective: public ASTNode
+{
+public:
+ UsingForDirective(
+ SourceLocation const& _location,
+ ASTPointer<Identifier> const& _libraryName,
+ ASTPointer<TypeName> const& _typeName
+ ):
+ ASTNode(_location), m_libraryName(_libraryName), m_typeName(_typeName) {}
+
+ virtual void accept(ASTVisitor& _visitor) override;
+ virtual void accept(ASTConstVisitor& _visitor) const override;
+
+ Identifier const& libraryName() const { return *m_libraryName; }
+ /// @returns the type name the library is attached to, null for `*`.
+ TypeName const* typeName() const { return m_typeName.get(); }
+
+private:
+ ASTPointer<Identifier> m_libraryName;
+ ASTPointer<TypeName> m_typeName;
+};
+
class StructDefinition: public Declaration
{
public:
diff --git a/libsolidity/ast/ASTVisitor.h b/libsolidity/ast/ASTVisitor.h
index 14c09fb4..f04d9682 100644
--- a/libsolidity/ast/ASTVisitor.h
+++ b/libsolidity/ast/ASTVisitor.h
@@ -47,6 +47,7 @@ public:
virtual bool visit(ImportDirective& _node) { return visitNode(_node); }
virtual bool visit(ContractDefinition& _node) { return visitNode(_node); }
virtual bool visit(InheritanceSpecifier& _node) { return visitNode(_node); }
+ virtual bool visit(UsingForDirective& _node) { return visitNode(_node); }
virtual bool visit(StructDefinition& _node) { return visitNode(_node); }
virtual bool visit(EnumDefinition& _node) { return visitNode(_node); }
virtual bool visit(EnumValue& _node) { return visitNode(_node); }
@@ -88,6 +89,7 @@ public:
virtual void endVisit(ImportDirective& _node) { endVisitNode(_node); }
virtual void endVisit(ContractDefinition& _node) { endVisitNode(_node); }
virtual void endVisit(InheritanceSpecifier& _node) { endVisitNode(_node); }
+ virtual void endVisit(UsingForDirective& _node) { endVisitNode(_node); }
virtual void endVisit(StructDefinition& _node) { endVisitNode(_node); }
virtual void endVisit(EnumDefinition& _node) { endVisitNode(_node); }
virtual void endVisit(EnumValue& _node) { endVisitNode(_node); }
@@ -142,6 +144,7 @@ public:
virtual bool visit(ContractDefinition const& _node) { return visitNode(_node); }
virtual bool visit(InheritanceSpecifier const& _node) { return visitNode(_node); }
virtual bool visit(StructDefinition const& _node) { return visitNode(_node); }
+ virtual bool visit(UsingForDirective const& _node) { return visitNode(_node); }
virtual bool visit(EnumDefinition const& _node) { return visitNode(_node); }
virtual bool visit(EnumValue const& _node) { return visitNode(_node); }
virtual bool visit(ParameterList const& _node) { return visitNode(_node); }
@@ -182,6 +185,7 @@ public:
virtual void endVisit(ImportDirective const& _node) { endVisitNode(_node); }
virtual void endVisit(ContractDefinition const& _node) { endVisitNode(_node); }
virtual void endVisit(InheritanceSpecifier const& _node) { endVisitNode(_node); }
+ virtual void endVisit(UsingForDirective const& _node) { endVisitNode(_node); }
virtual void endVisit(StructDefinition const& _node) { endVisitNode(_node); }
virtual void endVisit(EnumDefinition const& _node) { endVisitNode(_node); }
virtual void endVisit(EnumValue const& _node) { endVisitNode(_node); }
diff --git a/libsolidity/ast/AST_accept.h b/libsolidity/ast/AST_accept.h
index f65595b8..3f7b8d36 100644
--- a/libsolidity/ast/AST_accept.h
+++ b/libsolidity/ast/AST_accept.h
@@ -123,6 +123,28 @@ void EnumValue::accept(ASTConstVisitor& _visitor) const
_visitor.endVisit(*this);
}
+void UsingForDirective::accept(ASTVisitor& _visitor)
+{
+ if (_visitor.visit(*this))
+ {
+ if (m_libraryName)
+ m_libraryName->accept(_visitor);
+ m_typeName->accept(_visitor);
+ }
+ _visitor.endVisit(*this);
+}
+
+void UsingForDirective::accept(ASTConstVisitor& _visitor) const
+{
+ if (_visitor.visit(*this))
+ {
+ if (m_libraryName)
+ m_libraryName->accept(_visitor);
+ m_typeName->accept(_visitor);
+ }
+ _visitor.endVisit(*this);
+}
+
void StructDefinition::accept(ASTVisitor& _visitor)
{
if (_visitor.visit(*this))