mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge branch 'develop' of github.com:ethereum/cpp-ethereum into develop
Conflicts: libsolidity/InterfaceHandler.cpp
This commit is contained in:
commit
ef05913743
17
AST.cpp
17
AST.cpp
@ -152,6 +152,23 @@ void ContractDefinition::checkIllegalOverrides() const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<ASTPointer<EventDefinition>> const& ContractDefinition::getInterfaceEvents() const
|
||||||
|
{
|
||||||
|
if (!m_interfaceEvents)
|
||||||
|
{
|
||||||
|
set<string> eventsSeen;
|
||||||
|
m_interfaceEvents.reset(new std::vector<ASTPointer<EventDefinition>>());
|
||||||
|
for (ContractDefinition const* contract: getLinearizedBaseContracts())
|
||||||
|
for (ASTPointer<EventDefinition> const& e: contract->getEvents())
|
||||||
|
if (eventsSeen.count(e->getName()) == 0)
|
||||||
|
{
|
||||||
|
eventsSeen.insert(e->getName());
|
||||||
|
m_interfaceEvents->push_back(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return *m_interfaceEvents;
|
||||||
|
}
|
||||||
|
|
||||||
vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getInterfaceFunctionList() const
|
vector<pair<FixedHash<4>, FunctionTypePointer>> const& ContractDefinition::getInterfaceFunctionList() const
|
||||||
{
|
{
|
||||||
if (!m_interfaceFunctionList)
|
if (!m_interfaceFunctionList)
|
||||||
|
4
AST.h
4
AST.h
@ -222,6 +222,7 @@ public:
|
|||||||
std::vector<ASTPointer<ModifierDefinition>> const& getFunctionModifiers() const { return m_functionModifiers; }
|
std::vector<ASTPointer<ModifierDefinition>> const& getFunctionModifiers() const { return m_functionModifiers; }
|
||||||
std::vector<ASTPointer<FunctionDefinition>> const& getDefinedFunctions() const { return m_definedFunctions; }
|
std::vector<ASTPointer<FunctionDefinition>> const& getDefinedFunctions() const { return m_definedFunctions; }
|
||||||
std::vector<ASTPointer<EventDefinition>> const& getEvents() const { return m_events; }
|
std::vector<ASTPointer<EventDefinition>> const& getEvents() const { return m_events; }
|
||||||
|
std::vector<ASTPointer<EventDefinition>> const& getInterfaceEvents() const;
|
||||||
|
|
||||||
virtual TypePointer getType(ContractDefinition const* m_currentContract) const override;
|
virtual TypePointer getType(ContractDefinition const* m_currentContract) const override;
|
||||||
|
|
||||||
@ -257,6 +258,7 @@ private:
|
|||||||
|
|
||||||
std::vector<ContractDefinition const*> m_linearizedBaseContracts;
|
std::vector<ContractDefinition const*> m_linearizedBaseContracts;
|
||||||
mutable std::unique_ptr<std::vector<std::pair<FixedHash<4>, FunctionTypePointer>>> m_interfaceFunctionList;
|
mutable std::unique_ptr<std::vector<std::pair<FixedHash<4>, FunctionTypePointer>>> m_interfaceFunctionList;
|
||||||
|
mutable std::unique_ptr<std::vector<ASTPointer<EventDefinition>>> m_interfaceEvents;
|
||||||
};
|
};
|
||||||
|
|
||||||
class InheritanceSpecifier: public ASTNode
|
class InheritanceSpecifier: public ASTNode
|
||||||
@ -471,7 +473,7 @@ private:
|
|||||||
/**
|
/**
|
||||||
* Definition of a (loggable) event.
|
* Definition of a (loggable) event.
|
||||||
*/
|
*/
|
||||||
class EventDefinition: public Declaration, public Documented
|
class EventDefinition: public Declaration, public VariableScope, public Documented
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EventDefinition(Location const& _location,
|
EventDefinition(Location const& _location,
|
||||||
|
@ -37,47 +37,24 @@ std::unique_ptr<std::string> InterfaceHandler::getDocumentation(ContractDefiniti
|
|||||||
|
|
||||||
std::unique_ptr<std::string> InterfaceHandler::getABIInterface(ContractDefinition const& _contractDef)
|
std::unique_ptr<std::string> InterfaceHandler::getABIInterface(ContractDefinition const& _contractDef)
|
||||||
{
|
{
|
||||||
Json::Value members(Json::arrayValue);
|
Json::Value abi(Json::arrayValue);
|
||||||
/*
|
|
||||||
for (ASTPointer<EventDefinition> const& it: _contractDef.getEvents())
|
|
||||||
{
|
|
||||||
Json::Value event;5
|
|
||||||
Json::Value inputs(Json::arrayValue);
|
|
||||||
|
|
||||||
event["type"] = "event";
|
|
||||||
Json::Value params(Json::arrayValue);
|
|
||||||
for (ASTPointer<VariableDeclaration> const& p: it->getParameters())
|
|
||||||
{
|
|
||||||
Json::Value param;
|
|
||||||
param["name"] = p->getName();
|
|
||||||
param["type"] = p->getType()->toString();
|
|
||||||
param["indexed"] = p->isIndexed();
|
|
||||||
params.append(param);
|
|
||||||
}
|
|
||||||
event["inputs"] = params;
|
|
||||||
members.append(event);
|
|
||||||
}*/
|
|
||||||
for (auto const& it: _contractDef.getInterfaceFunctions())
|
for (auto const& it: _contractDef.getInterfaceFunctions())
|
||||||
{
|
{
|
||||||
auto populateParameters = [](vector<string> const& _paramNames,
|
auto populateParameters = [](vector<string> const& _paramNames, vector<string> const& _paramTypes)
|
||||||
vector<string> const& _paramTypes)
|
|
||||||
{
|
{
|
||||||
Json::Value params(Json::arrayValue);
|
Json::Value params(Json::arrayValue);
|
||||||
solAssert(_paramNames.size() == _paramTypes.size(), "Names and types vector size does not match");
|
solAssert(_paramNames.size() == _paramTypes.size(), "Names and types vector size does not match");
|
||||||
for (unsigned i = 0; i < _paramNames.size(); ++i)
|
for (unsigned i = 0; i < _paramNames.size(); ++i)
|
||||||
{
|
{
|
||||||
Json::Value input;
|
Json::Value param;
|
||||||
input["name"] = _paramNames[i];
|
param["name"] = _paramNames[i];
|
||||||
input["type"] = _paramTypes[i];
|
param["type"] = _paramTypes[i];
|
||||||
params.append(input);
|
params.append(param);
|
||||||
}
|
}
|
||||||
return params;
|
return params;
|
||||||
};
|
};
|
||||||
|
|
||||||
Json::Value method;
|
Json::Value method;
|
||||||
Json::Value inputs(Json::arrayValue);
|
|
||||||
Json::Value outputs(Json::arrayValue);
|
|
||||||
|
|
||||||
method["type"] = "function";
|
method["type"] = "function";
|
||||||
method["name"] = it.second->getDeclaration().getName();
|
method["name"] = it.second->getDeclaration().getName();
|
||||||
method["constant"] = it.second->isConstant();
|
method["constant"] = it.second->isConstant();
|
||||||
@ -85,9 +62,27 @@ std::unique_ptr<std::string> InterfaceHandler::getABIInterface(ContractDefinitio
|
|||||||
it.second->getParameterTypeNames());
|
it.second->getParameterTypeNames());
|
||||||
method["outputs"] = populateParameters(it.second->getReturnParameterNames(),
|
method["outputs"] = populateParameters(it.second->getReturnParameterNames(),
|
||||||
it.second->getReturnParameterTypeNames());
|
it.second->getReturnParameterTypeNames());
|
||||||
members.append(method);
|
abi.append(method);
|
||||||
}
|
}
|
||||||
return std::unique_ptr<std::string>(new std::string(m_writer.write(members)));
|
|
||||||
|
for (auto const& it: _contractDef.getInterfaceEvents())
|
||||||
|
{
|
||||||
|
Json::Value event;
|
||||||
|
event["type"] = "event";
|
||||||
|
event["name"] = it->getName();
|
||||||
|
Json::Value params(Json::arrayValue);
|
||||||
|
for (auto const& p: it->getParameters())
|
||||||
|
{
|
||||||
|
Json::Value input;
|
||||||
|
input["name"] = p->getName();
|
||||||
|
input["type"] = p->getType()->toString();
|
||||||
|
input["indexed"] = p->isIndexed();
|
||||||
|
params.append(input);
|
||||||
|
}
|
||||||
|
event["inputs"] = params;
|
||||||
|
abi.append(event);
|
||||||
|
}
|
||||||
|
return std::unique_ptr<std::string>(new std::string(m_writer.write(abi)));
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<string> InterfaceHandler::getABISolidityInterface(ContractDefinition const& _contractDef)
|
unique_ptr<string> InterfaceHandler::getABISolidityInterface(ContractDefinition const& _contractDef)
|
||||||
@ -113,6 +108,16 @@ unique_ptr<string> InterfaceHandler::getABISolidityInterface(ContractDefinition
|
|||||||
ret.pop_back();
|
ret.pop_back();
|
||||||
ret += "{}";
|
ret += "{}";
|
||||||
}
|
}
|
||||||
|
for (auto const& it: _contractDef.getInterfaceEvents())
|
||||||
|
{
|
||||||
|
std::string params;
|
||||||
|
for (auto const& p: it->getParameters())
|
||||||
|
params += (params.empty() ? "(" : ",") + p->getType()->toString() + (p->isIndexed() ? " indexed " : " ") + p->getName();
|
||||||
|
if (!params.empty())
|
||||||
|
params += ")";
|
||||||
|
|
||||||
|
ret += "event " + it->getName() + params + ";";
|
||||||
|
}
|
||||||
return unique_ptr<string>(new string(ret + "}"));
|
return unique_ptr<string>(new string(ret + "}"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,10 +263,15 @@ bool DeclarationRegistrationHelper::visit(VariableDeclaration& _declaration)
|
|||||||
|
|
||||||
bool DeclarationRegistrationHelper::visit(EventDefinition& _event)
|
bool DeclarationRegistrationHelper::visit(EventDefinition& _event)
|
||||||
{
|
{
|
||||||
registerDeclaration(_event, false);
|
registerDeclaration(_event, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeclarationRegistrationHelper::endVisit(EventDefinition&)
|
||||||
|
{
|
||||||
|
closeCurrentScope();
|
||||||
|
}
|
||||||
|
|
||||||
void DeclarationRegistrationHelper::enterNewSubScope(Declaration const& _declaration)
|
void DeclarationRegistrationHelper::enterNewSubScope(Declaration const& _declaration)
|
||||||
{
|
{
|
||||||
map<ASTNode const*, DeclarationContainer>::iterator iter;
|
map<ASTNode const*, DeclarationContainer>::iterator iter;
|
||||||
|
@ -94,17 +94,18 @@ public:
|
|||||||
DeclarationRegistrationHelper(std::map<ASTNode const*, DeclarationContainer>& _scopes, ASTNode& _astRoot);
|
DeclarationRegistrationHelper(std::map<ASTNode const*, DeclarationContainer>& _scopes, ASTNode& _astRoot);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool visit(ContractDefinition& _contract);
|
bool visit(ContractDefinition& _contract) override;
|
||||||
void endVisit(ContractDefinition& _contract);
|
void endVisit(ContractDefinition& _contract) override;
|
||||||
bool visit(StructDefinition& _struct);
|
bool visit(StructDefinition& _struct) override;
|
||||||
void endVisit(StructDefinition& _struct);
|
void endVisit(StructDefinition& _struct) override;
|
||||||
bool visit(FunctionDefinition& _function);
|
bool visit(FunctionDefinition& _function) override;
|
||||||
void endVisit(FunctionDefinition& _function);
|
void endVisit(FunctionDefinition& _function) override;
|
||||||
bool visit(ModifierDefinition& _modifier);
|
bool visit(ModifierDefinition& _modifier) override;
|
||||||
void endVisit(ModifierDefinition& _modifier);
|
void endVisit(ModifierDefinition& _modifier) override;
|
||||||
void endVisit(VariableDefinition& _variableDefinition);
|
void endVisit(VariableDefinition& _variableDefinition) override;
|
||||||
bool visit(VariableDeclaration& _declaration);
|
bool visit(VariableDeclaration& _declaration) override;
|
||||||
bool visit(EventDefinition& _event);
|
bool visit(EventDefinition& _event) override;
|
||||||
|
void endVisit(EventDefinition& _event) override;
|
||||||
|
|
||||||
void enterNewSubScope(Declaration const& _declaration);
|
void enterNewSubScope(Declaration const& _declaration);
|
||||||
void closeCurrentScope();
|
void closeCurrentScope();
|
||||||
|
Loading…
Reference in New Issue
Block a user