From 0b14d26f6bcdbd2cbe45289a9121ed364d0169a9 Mon Sep 17 00:00:00 2001 From: Liana Husikyan Date: Mon, 16 Mar 2015 19:19:34 +0100 Subject: [PATCH] Added anonymous flag to event. added test --- libsolidity/AST.h | 7 +++++-- libsolidity/ExpressionCompiler.cpp | 9 ++++++--- libsolidity/InterfaceHandler.cpp | 1 + libsolidity/Parser.cpp | 8 +++++++- libsolidity/Token.h | 1 + test/SolidityEndToEndTest.cpp | 2 +- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/libsolidity/AST.h b/libsolidity/AST.h index f5f6a3f38..c0ae3c164 100644 --- a/libsolidity/AST.h +++ b/libsolidity/AST.h @@ -556,14 +556,16 @@ public: EventDefinition(SourceLocation const& _location, ASTPointer const& _name, ASTPointer const& _documentation, - ASTPointer const& _parameters): - Declaration(_location, _name), Documented(_documentation), m_parameters(_parameters) {} + ASTPointer 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> 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 m_parameters; + bool m_anonymous; }; /** diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index a0a688bbd..99673edde 100644 --- a/libsolidity/ExpressionCompiler.cpp +++ b/libsolidity/ExpressionCompiler.cpp @@ -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) diff --git a/libsolidity/InterfaceHandler.cpp b/libsolidity/InterfaceHandler.cpp index 99a7db96e..2b855e243 100644 --- a/libsolidity/InterfaceHandler.cpp +++ b/libsolidity/InterfaceHandler.cpp @@ -70,6 +70,7 @@ std::unique_ptr 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()) { diff --git a/libsolidity/Parser.cpp b/libsolidity/Parser.cpp index 459a34bd0..098a38344 100644 --- a/libsolidity/Parser.cpp +++ b/libsolidity/Parser.cpp @@ -388,6 +388,12 @@ ASTPointer Parser::parseEventDefinition() docstring = make_shared(m_scanner->getCurrentCommentLiteral()); expectToken(Token::Event); + bool anonymous = false; + if (m_scanner->getCurrentToken() == Token::Anonymous) + { + anonymous = true; + m_scanner->next(); + } ASTPointer name(expectIdentifierToken()); ASTPointer parameters; if (m_scanner->getCurrentToken() == Token::LParen) @@ -396,7 +402,7 @@ ASTPointer Parser::parseEventDefinition() parameters = createEmptyParameterList(); nodeFactory.markEndPosition(); expectToken(Token::Semicolon); - return nodeFactory.createNode(name, docstring, parameters); + return nodeFactory.createNode(name, docstring, parameters, anonymous); } ASTPointer Parser::parseModifierInvocation() diff --git a/libsolidity/Token.h b/libsolidity/Token.h index 2d8a49fcd..b2951e939 100644 --- a/libsolidity/Token.h +++ b/libsolidity/Token.h @@ -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) \ diff --git a/test/SolidityEndToEndTest.cpp b/test/SolidityEndToEndTest.cpp index d9cbbfdef..05d2e3af8 100644 --- a/test/SolidityEndToEndTest.cpp +++ b/test/SolidityEndToEndTest.cpp @@ -2214,7 +2214,7 @@ BOOST_AUTO_TEST_CASE(event_anonymous) )"; compileAndRun(sourceCode); callContractFunction("deposit()"); - BOOST_REQUIRE_EQUAL(m_logs.size(), 0); + BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 0); } BOOST_AUTO_TEST_CASE(event_lots_of_data)