aboutsummaryrefslogtreecommitdiffstats
path: root/GlobalContext.cpp
diff options
context:
space:
mode:
authorChristian <c@ethdev.com>2014-11-22 02:14:56 +0800
committerChristian <c@ethdev.com>2014-11-24 04:28:45 +0800
commit583a315d3d282ab9fd871bb2ea3beded367be6d0 (patch)
tree8471241f34041fe5aadd7fc0a574fef8c80e2aa8 /GlobalContext.cpp
parentc50cd646ce3b8b6c20da747efee89f9420526cae (diff)
downloaddexon-solidity-583a315d3d282ab9fd871bb2ea3beded367be6d0.tar
dexon-solidity-583a315d3d282ab9fd871bb2ea3beded367be6d0.tar.gz
dexon-solidity-583a315d3d282ab9fd871bb2ea3beded367be6d0.tar.bz2
dexon-solidity-583a315d3d282ab9fd871bb2ea3beded367be6d0.tar.lz
dexon-solidity-583a315d3d282ab9fd871bb2ea3beded367be6d0.tar.xz
dexon-solidity-583a315d3d282ab9fd871bb2ea3beded367be6d0.tar.zst
dexon-solidity-583a315d3d282ab9fd871bb2ea3beded367be6d0.zip
Magic variables.
Diffstat (limited to 'GlobalContext.cpp')
-rw-r--r--GlobalContext.cpp32
1 files changed, 22 insertions, 10 deletions
diff --git a/GlobalContext.cpp b/GlobalContext.cpp
index 6179722b..f2e6d9ce 100644
--- a/GlobalContext.cpp
+++ b/GlobalContext.cpp
@@ -45,25 +45,37 @@ GlobalContext::GlobalContext()
void GlobalContext::setCurrentContract(ContractDefinition const& _contract)
{
- m_this = createVariable("this", make_shared<ContractType>(_contract));
+ m_currentContract = &_contract;
}
vector<Declaration*> GlobalContext::getDeclarations() const
{
vector<Declaration*> declarations;
- declarations.reserve(m_objects.size() + 1);
- for (ASTPointer<Declaration> const& declaration: m_objects)
- declarations.push_back(declaration.get());
- declarations.push_back(m_this.get());
+ declarations.reserve(m_magicVariables.size() + 1);
+ for (ASTPointer<Declaration> const& variable: m_magicVariables)
+ declarations.push_back(variable.get());
+ declarations.push_back(getCurrentThis());
return declarations;
}
-ASTPointer<VariableDeclaration> GlobalContext::createVariable(const string& _name, shared_ptr<const Type> const& _type)
+MagicVariableDeclaration*GlobalContext::getCurrentThis() const
{
- ASTPointer<VariableDeclaration> variable = make_shared<VariableDeclaration>(Location(), ASTPointer<TypeName>(),
- make_shared<ASTString>(_name));
- variable->setType(_type);
- return variable;
+ if (!m_thisPointer[m_currentContract])
+ m_thisPointer[m_currentContract] = make_shared<MagicVariableDeclaration>(
+ MagicVariableDeclaration::VariableKind::THIS,
+ "this", make_shared<ContractType>(*m_currentContract));
+ return m_thisPointer[m_currentContract].get();
+
+}
+
+vector<MagicVariableDeclaration const*> GlobalContext::getMagicVariables() const
+{
+ vector<MagicVariableDeclaration const*> declarations;
+ declarations.reserve(m_magicVariables.size() + 1);
+ for (ASTPointer<MagicVariableDeclaration const> const& variable: m_magicVariables)
+ declarations.push_back(variable.get());
+ declarations.push_back(getCurrentThis());
+ return declarations;
}
}