aboutsummaryrefslogtreecommitdiffstats
path: root/NameAndTypeResolver.h
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-10-15 21:54:41 +0800
committerChristian <c@ethdev.com>2014-10-16 00:41:44 +0800
commitd557fbac9c39e6e2b40ff4c4a3093be2f08df602 (patch)
tree3c5acd40804f62172bfc7f7ad6a30c30ed3d14e3 /NameAndTypeResolver.h
parentdf142782bc3a1435f70d9f5f4c8e04ae8d7e1678 (diff)
downloaddexon-solidity-d557fbac9c39e6e2b40ff4c4a3093be2f08df602.tar.gz
dexon-solidity-d557fbac9c39e6e2b40ff4c4a3093be2f08df602.tar.zst
dexon-solidity-d557fbac9c39e6e2b40ff4c4a3093be2f08df602.zip
Some fixes for the type system, should be quite usable now.
Diffstat (limited to 'NameAndTypeResolver.h')
-rw-r--r--NameAndTypeResolver.h56
1 files changed, 43 insertions, 13 deletions
diff --git a/NameAndTypeResolver.h b/NameAndTypeResolver.h
index 036c3fba..f5a3c84e 100644
--- a/NameAndTypeResolver.h
+++ b/NameAndTypeResolver.h
@@ -32,34 +32,64 @@
namespace dev {
namespace solidity {
+
class NameAndTypeResolver : private boost::noncopyable
{
public:
NameAndTypeResolver();
void resolveNamesAndTypes(ContractDefinition& _contract);
+ Declaration* getNameFromCurrentScope(ASTString const& _name, bool _recursive = true);
private:
- class ScopeHelper; //< RIIA helper to open and close scopes
-
void reset();
- void handleContract(ContractDefinition& _contract);
- void handleFunction(FunctionDefinition& _function);
- void registerVariablesInFunction(FunctionDefinition& _function);
- void resolveReferencesInFunction(ParameterList& _returnParameters,
- Block& _functionBody);
+ //! Maps nodes declaring a scope to scopes, i.e. ContractDefinition, FunctionDeclaration and
+ //! StructDefinition (@todo not yet implemented), where nullptr denotes the global scope.
+ std::map<ASTNode*, Scope> m_scopes;
- void registerVariableDeclarationAndResolveType(VariableDeclaration& _variable);
- void registerDeclaration(Declaration& _declaration);
- Declaration* getNameFromCurrentScope(ASTString const& _name, bool _recursive = true);
+ Scope* m_currentScope;
+};
+
+//! Traverses the given AST upon construction and fills _scopes with all declarations inside the
+//! AST.
+class DeclarationRegistrationHelper : private ASTVisitor
+{
+public:
+ DeclarationRegistrationHelper(std::map<ASTNode*, Scope>& _scopes, ASTNode& _astRoot);
+
+private:
+ bool visit(ContractDefinition& _contract);
+ void endVisit(ContractDefinition& _contract);
+ bool visit(StructDefinition& _struct);
+ void endVisit(StructDefinition& _struct);
+ bool visit(FunctionDefinition& _function);
+ void endVisit(FunctionDefinition& _function);
+ bool visit(VariableDeclaration& _declaration);
+ void endVisit(VariableDeclaration& _declaration);
void enterNewSubScope(ASTNode& _node);
void closeCurrentScope();
+ void registerDeclaration(Declaration& _declaration, bool _opensScope);
- Scope m_globalScope; // not part of the map
- std::map<ASTNode*, Scope> m_scopes;
-
+ std::map<ASTNode*, Scope>& m_scopes;
Scope* m_currentScope;
};
+//! Resolves references to declarations (of variables and types) and also establishes the link
+//! between a return statement and the return parameter list.
+class ReferencesResolver : private ASTVisitor
+{
+public:
+ ReferencesResolver(ASTNode& _root, NameAndTypeResolver& _resolver, ParameterList* _returnParameters);
+private:
+ virtual void endVisit(VariableDeclaration& _variable) override;
+ virtual bool visit(Identifier& _identifier) override;
+ virtual bool visit(UserDefinedTypeName& _typeName) override;
+ virtual bool visit(Mapping&) override;
+ virtual bool visit(Return& _return) override;
+private:
+ NameAndTypeResolver& m_resolver;
+ ParameterList* m_returnParameters;
+};
+
} }