Added anonymous flag to event.

added test
This commit is contained in:
Liana Husikyan 2015-03-16 19:19:34 +01:00
parent fc0bdc3d81
commit 2986ecbd75
5 changed files with 20 additions and 6 deletions

7
AST.h
View File

@ -556,14 +556,16 @@ public:
EventDefinition(SourceLocation const& _location,
ASTPointer<ASTString> const& _name,
ASTPointer<ASTString> const& _documentation,
ASTPointer<ParameterList> const& _parameters):
Declaration(_location, _name), Documented(_documentation), m_parameters(_parameters) {}
ASTPointer<ParameterList> const& _parameters,
bool _anonymous = false):
Declaration(_location, _name), Documented(_documentation), m_parameters(_parameters) , m_anonymous(_anonymous){}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
std::vector<ASTPointer<VariableDeclaration>> const& getParameters() const { return m_parameters->getParameters(); }
ParameterList const& getParameterList() const { return *m_parameters; }
bool IsAnonymous() const { return m_anonymous; }
virtual TypePointer getType(ContractDefinition const* = nullptr) const override
{
@ -574,6 +576,7 @@ public:
private:
ASTPointer<ParameterList> m_parameters;
bool m_anonymous;
};
/**

View File

@ -542,9 +542,12 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
appendTypeConversion(*arguments[arg - 1]->getType(),
*function.getParameterTypes()[arg - 1], true);
}
m_context << u256(h256::Arith(dev::sha3(function.getCanonicalSignature(event.getName()))));
++numIndexed;
solAssert(numIndexed <= 4, "Too many indexed arguments.");
if (!event.IsAnonymous())
{
m_context << u256(h256::Arith(dev::sha3(function.getCanonicalSignature(event.getName()))));
++numIndexed;
}
solAssert(numIndexed <= 4 - (event.IsAnonymous() ? 1 : 0), "Too many indexed arguments.");
// Copy all non-indexed arguments to memory (data)
m_context << u256(0);
for (unsigned arg = 0; arg < arguments.size(); ++arg)

View File

@ -70,6 +70,7 @@ std::unique_ptr<std::string> InterfaceHandler::getABIInterface(ContractDefinitio
Json::Value event;
event["type"] = "event";
event["name"] = it->getName();
//todo add anonymous!;
Json::Value params(Json::arrayValue);
for (auto const& p: it->getParameters())
{

View File

@ -388,6 +388,12 @@ ASTPointer<EventDefinition> Parser::parseEventDefinition()
docstring = make_shared<ASTString>(m_scanner->getCurrentCommentLiteral());
expectToken(Token::Event);
bool anonymous = false;
if (m_scanner->getCurrentToken() == Token::Anonymous)
{
anonymous = true;
m_scanner->next();
}
ASTPointer<ASTString> name(expectIdentifierToken());
ASTPointer<ParameterList> parameters;
if (m_scanner->getCurrentToken() == Token::LParen)
@ -396,7 +402,7 @@ ASTPointer<EventDefinition> Parser::parseEventDefinition()
parameters = createEmptyParameterList();
nodeFactory.markEndPosition();
expectToken(Token::Semicolon);
return nodeFactory.createNode<EventDefinition>(name, docstring, parameters);
return nodeFactory.createNode<EventDefinition>(name, docstring, parameters, anonymous);
}
ASTPointer<ModifierInvocation> Parser::parseModifierInvocation()

View File

@ -145,6 +145,7 @@ namespace solidity
K(Break, "break", 0) \
K(Case, "case", 0) \
K(Const, "constant", 0) \
K(Anonymous, "anonymous", 0) \
K(Continue, "continue", 0) \
K(Contract, "contract", 0) \
K(Default, "default", 0) \