aboutsummaryrefslogtreecommitdiffstats
path: root/NameAndTypeResolver.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-11-21 01:33:23 +0800
committerChristian <c@ethdev.com>2014-11-24 04:28:44 +0800
commitc50cd646ce3b8b6c20da747efee89f9420526cae (patch)
treea6ebf3a1fe6088d9b8c5e3d4f36caa09bfd3fdd7 /NameAndTypeResolver.cpp
parentfa987e0a206bba35cfe6e311f8bad1470d9b5d4f (diff)
downloaddexon-solidity-c50cd646ce3b8b6c20da747efee89f9420526cae.tar.gz
dexon-solidity-c50cd646ce3b8b6c20da747efee89f9420526cae.tar.zst
dexon-solidity-c50cd646ce3b8b6c20da747efee89f9420526cae.zip
Contracts as types and framework for special global variables.
Diffstat (limited to 'NameAndTypeResolver.cpp')
-rw-r--r--NameAndTypeResolver.cpp43
1 files changed, 12 insertions, 31 deletions
diff --git a/NameAndTypeResolver.cpp b/NameAndTypeResolver.cpp
index aa772658..225f2a78 100644
--- a/NameAndTypeResolver.cpp
+++ b/NameAndTypeResolver.cpp
@@ -32,15 +32,20 @@ namespace solidity
{
+NameAndTypeResolver::NameAndTypeResolver(std::vector<Declaration*> const& _globals)
+{
+ for (Declaration* declaration: _globals)
+ m_scopes[nullptr].registerDeclaration(*declaration);
+}
+
void NameAndTypeResolver::resolveNamesAndTypes(ContractDefinition& _contract)
{
- reset();
DeclarationRegistrationHelper registrar(m_scopes, _contract);
m_currentScope = &m_scopes[&_contract];
for (ASTPointer<StructDefinition> const& structDef: _contract.getDefinedStructs())
ReferencesResolver resolver(*structDef, *this, nullptr);
for (ASTPointer<StructDefinition> const& structDef: _contract.getDefinedStructs())
- checkForRecursion(*structDef);
+ structDef->checkValidityOfMembers();
for (ASTPointer<VariableDeclaration> const& variable: _contract.getStateVariables())
ReferencesResolver resolver(*variable, *this, nullptr);
for (ASTPointer<FunctionDefinition> const& function: _contract.getDefinedFunctions())
@@ -73,30 +78,6 @@ Declaration* NameAndTypeResolver::getNameFromCurrentScope(ASTString const& _name
return m_currentScope->resolveName(_name, _recursive);
}
-void NameAndTypeResolver::checkForRecursion(StructDefinition const& _struct)
-{
- set<StructDefinition const*> definitionsSeen;
- vector<StructDefinition const*> queue = {&_struct};
- while (!queue.empty())
- {
- StructDefinition const* def = queue.back();
- queue.pop_back();
- if (definitionsSeen.count(def))
- BOOST_THROW_EXCEPTION(ParserError() << errinfo_sourceLocation(def->getLocation())
- << errinfo_comment("Recursive struct definition."));
- definitionsSeen.insert(def);
- for (ASTPointer<VariableDeclaration> const& member: def->getMembers())
- if (member->getType()->getCategory() == Type::Category::STRUCT)
- queue.push_back(dynamic_cast<UserDefinedTypeName&>(*member->getTypeName()).getReferencedStruct());
- }
-}
-
-void NameAndTypeResolver::reset()
-{
- m_scopes.clear();
- m_currentScope = nullptr;
-}
-
DeclarationRegistrationHelper::DeclarationRegistrationHelper(map<ASTNode const*, Scope>& _scopes,
ASTNode& _astRoot):
m_scopes(_scopes), m_currentScope(&m_scopes[nullptr])
@@ -195,7 +176,11 @@ void ReferencesResolver::endVisit(VariableDeclaration& _variable)
// endVisit because the internal type needs resolving if it is a user defined type
// or mapping
if (_variable.getTypeName())
+ {
_variable.setType(_variable.getTypeName()->toType());
+ if (!_variable.getType())
+ BOOST_THROW_EXCEPTION(_variable.getTypeName()->createTypeError("Invalid type name"));
+ }
else if (!m_allowLazyTypes)
BOOST_THROW_EXCEPTION(_variable.createTypeError("Explicit type needed."));
// otherwise we have a "var"-declaration whose type is resolved by the first assignment
@@ -221,11 +206,7 @@ bool ReferencesResolver::visit(UserDefinedTypeName& _typeName)
if (!declaration)
BOOST_THROW_EXCEPTION(DeclarationError() << errinfo_sourceLocation(_typeName.getLocation())
<< errinfo_comment("Undeclared identifier."));
- StructDefinition* referencedStruct = dynamic_cast<StructDefinition*>(declaration);
- //@todo later, contracts are also valid types
- if (!referencedStruct)
- BOOST_THROW_EXCEPTION(_typeName.createTypeError("Identifier does not name a type name."));
- _typeName.setReferencedStruct(*referencedStruct);
+ _typeName.setReferencedDeclaration(*declaration);
return false;
}