diff options
-rw-r--r-- | libsolidity/AST.cpp | 14 | ||||
-rw-r--r-- | libsolidity/ASTJsonConverter.cpp | 22 | ||||
-rw-r--r-- | libsolidity/ASTJsonConverter.h | 2 | ||||
-rw-r--r-- | libsolidity/ASTPrinter.cpp | 12 | ||||
-rw-r--r-- | libsolidity/ASTPrinter.h | 2 | ||||
-rw-r--r-- | libsolidity/Compiler.h | 4 | ||||
-rw-r--r-- | libsolidity/CompilerStack.cpp | 8 | ||||
-rw-r--r-- | libsolidity/ExpressionCompiler.cpp | 10 | ||||
-rw-r--r-- | libsolidity/GasEstimator.cpp | 2 | ||||
-rw-r--r-- | libsolidity/InterfaceHandler.cpp | 4 | ||||
-rw-r--r-- | libsolidity/Types.cpp | 6 | ||||
-rw-r--r-- | test/libsolidity/Assembly.cpp | 6 | ||||
-rw-r--r-- | test/libsolidity/SolidityExpressionCompiler.cpp | 6 | ||||
-rw-r--r-- | test/libsolidity/SolidityInterface.cpp | 18 | ||||
-rw-r--r-- | test/libsolidity/SolidityOptimizer.cpp | 16 |
15 files changed, 72 insertions, 60 deletions
diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index ad413352..a9382031 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -817,10 +817,16 @@ void BinaryOperation::checkTypeRequirements(TypePointers const*) m_right->checkTypeRequirements(nullptr); m_commonType = m_left->type()->binaryOperatorResult(m_operator, m_right->type()); if (!m_commonType) - BOOST_THROW_EXCEPTION(createTypeError("Operator " + string(Token::toString(m_operator)) + - " not compatible with types " + - m_left->type()->toString() + " and " + - m_right->type()->toString())); + BOOST_THROW_EXCEPTION( + createTypeError( + "Operator " + + string(Token::toString(m_operator)) + + " not compatible with types " + + m_left->type()->toString() + + " and " + + m_right->type()->toString() + ) + ); m_type = Token::isCompareOp(m_operator) ? make_shared<BoolType>() : m_commonType; } diff --git a/libsolidity/ASTJsonConverter.cpp b/libsolidity/ASTJsonConverter.cpp index 82c48a73..3d119a4e 100644 --- a/libsolidity/ASTJsonConverter.cpp +++ b/libsolidity/ASTJsonConverter.cpp @@ -209,7 +209,7 @@ bool ASTJsonConverter::visit(Assignment const& _node) { addJsonNode("Assignment", { make_pair("operator", Token::toString(_node.assignmentOperator())), - make_pair("type", getType(_node)) }, + make_pair("type", type(_node)) }, true); return true; } @@ -219,7 +219,7 @@ bool ASTJsonConverter::visit(UnaryOperation const& _node) addJsonNode("UnaryOperation", { make_pair("prefix", boost::lexical_cast<std::string>(_node.isPrefixOperation())), make_pair("operator", Token::toString(_node.getOperator())), - make_pair("type", getType(_node)) }, + make_pair("type", type(_node)) }, true); return true; } @@ -228,7 +228,7 @@ bool ASTJsonConverter::visit(BinaryOperation const& _node) { addJsonNode("BinaryOperation", { make_pair("operator", Token::toString(_node.getOperator())), - make_pair("type", getType(_node))}, + make_pair("type", type(_node))}, true); return true; } @@ -237,14 +237,14 @@ bool ASTJsonConverter::visit(FunctionCall const& _node) { addJsonNode("FunctionCall", { make_pair("type_conversion", boost::lexical_cast<std::string>(_node.isTypeConversion())), - make_pair("type", getType(_node)) }, + make_pair("type", type(_node)) }, true); return true; } bool ASTJsonConverter::visit(NewExpression const& _node) { - addJsonNode("NewExpression", { make_pair("type", getType(_node)) }, true); + addJsonNode("NewExpression", { make_pair("type", type(_node)) }, true); return true; } @@ -252,28 +252,28 @@ bool ASTJsonConverter::visit(MemberAccess const& _node) { addJsonNode("MemberAccess", { make_pair("member_name", _node.memberName()), - make_pair("type", getType(_node)) }, + make_pair("type", type(_node)) }, true); return true; } bool ASTJsonConverter::visit(IndexAccess const& _node) { - addJsonNode("IndexAccess", { make_pair("type", getType(_node)) }, true); + addJsonNode("IndexAccess", { make_pair("type", type(_node)) }, true); return true; } bool ASTJsonConverter::visit(Identifier const& _node) { addJsonNode("Identifier", - { make_pair("value", _node.name()), make_pair("type", getType(_node)) }); + { make_pair("value", _node.name()), make_pair("type", type(_node)) }); return true; } bool ASTJsonConverter::visit(ElementaryTypeNameExpression const& _node) { addJsonNode("ElementaryTypenameExpression", - { make_pair("value", Token::toString(_node.typeToken())), make_pair("type", getType(_node)) }); + { make_pair("value", Token::toString(_node.typeToken())), make_pair("type", type(_node)) }); return true; } @@ -283,7 +283,7 @@ bool ASTJsonConverter::visit(Literal const& _node) addJsonNode("Literal", { make_pair("string", (tokenString) ? tokenString : "null"), make_pair("value", _node.value()), - make_pair("type", getType(_node)) }); + make_pair("type", type(_node)) }); return true; } @@ -428,7 +428,7 @@ void ASTJsonConverter::process() processed = true; } -string ASTJsonConverter::getType(Expression const& _expression) +string ASTJsonConverter::type(Expression const& _expression) { return (_expression.type()) ? _expression.type()->toString() : "Unknown"; } diff --git a/libsolidity/ASTJsonConverter.h b/libsolidity/ASTJsonConverter.h index aaa54f7f..09217e97 100644 --- a/libsolidity/ASTJsonConverter.h +++ b/libsolidity/ASTJsonConverter.h @@ -112,7 +112,7 @@ private: void addJsonNode(std::string const& _nodeName, std::initializer_list<std::pair<std::string const, std::string const>> _list, bool _hasChildren); - std::string getType(Expression const& _expression); + std::string type(Expression const& _expression); inline void goUp() { solAssert(!m_jsonNodePtrs.empty(), "Uneven json nodes stack. Internal error."); diff --git a/libsolidity/ASTPrinter.cpp b/libsolidity/ASTPrinter.cpp index 9c701766..a64e8490 100644 --- a/libsolidity/ASTPrinter.cpp +++ b/libsolidity/ASTPrinter.cpp @@ -507,11 +507,11 @@ void ASTPrinter::endVisit(Literal const&) void ASTPrinter::printSourcePart(ASTNode const& _node) { if (m_gasCosts.count(&_node)) - *m_ostream << getIndentation() << " Gas costs: " << m_gasCosts.at(&_node) << endl; + *m_ostream << indentation() << " Gas costs: " << m_gasCosts.at(&_node) << endl; if (!m_source.empty()) { SourceLocation const& location(_node.location()); - *m_ostream << getIndentation() << " Source: " + *m_ostream << indentation() << " Source: " << escaped(m_source.substr(location.start, location.end - location.start), false) << endl; } } @@ -519,19 +519,19 @@ void ASTPrinter::printSourcePart(ASTNode const& _node) void ASTPrinter::printType(Expression const& _expression) { if (_expression.type()) - *m_ostream << getIndentation() << " Type: " << _expression.type()->toString() << "\n"; + *m_ostream << indentation() << " Type: " << _expression.type()->toString() << "\n"; else - *m_ostream << getIndentation() << " Type unknown.\n"; + *m_ostream << indentation() << " Type unknown.\n"; } -string ASTPrinter::getIndentation() const +string ASTPrinter::indentation() const { return string(m_indentation * 2, ' '); } void ASTPrinter::writeLine(string const& _line) { - *m_ostream << getIndentation() << _line << endl; + *m_ostream << indentation() << _line << endl; } } diff --git a/libsolidity/ASTPrinter.h b/libsolidity/ASTPrinter.h index cdf651f3..8c8be112 100644 --- a/libsolidity/ASTPrinter.h +++ b/libsolidity/ASTPrinter.h @@ -126,7 +126,7 @@ public: private: void printSourcePart(ASTNode const& _node); void printType(Expression const& _expression); - std::string getIndentation() const; + std::string indentation() const; void writeLine(std::string const& _line); bool goDeeper() { m_indentation++; return true; } diff --git a/libsolidity/Compiler.h b/libsolidity/Compiler.h index f9b12a02..f283683f 100644 --- a/libsolidity/Compiler.h +++ b/libsolidity/Compiler.h @@ -59,9 +59,9 @@ public: return m_context.streamAssembly(_stream, _sourceCodes, _inJsonFormat); } /// @returns Assembly items of the normal compiler context - eth::AssemblyItems const& assemblyItems() const { return m_context.assembly().getItems(); } + eth::AssemblyItems const& assemblyItems() const { return m_context.assembly().items(); } /// @returns Assembly items of the runtime compiler context - eth::AssemblyItems const& runtimeAssemblyItems() const { return m_context.assembly().getSub(m_runtimeSub).getItems(); } + eth::AssemblyItems const& runtimeAssemblyItems() const { return m_context.assembly().sub(m_runtimeSub).items(); } /// @returns the entry label of the given function. Might return an AssemblyItem of type /// UndefinedItem if it does not exist yet. diff --git a/libsolidity/CompilerStack.cpp b/libsolidity/CompilerStack.cpp index f46febfb..53ac5344 100644 --- a/libsolidity/CompilerStack.cpp +++ b/libsolidity/CompilerStack.cpp @@ -339,9 +339,11 @@ void CompilerStack::resolveImports() { string const& id = import->identifier(); if (!m_sources.count(id)) - BOOST_THROW_EXCEPTION(ParserError() - << errinfo_sourceLocation(import->location()) - << errinfo_comment("Source not found.")); + BOOST_THROW_EXCEPTION( + ParserError() + << errinfo_sourceLocation(import->location()) + << errinfo_comment("Source not found.") + ); toposort(&m_sources[id]); } sourceOrder.push_back(_source); diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index f5b8d5dc..449267a7 100644 --- a/libsolidity/ExpressionCompiler.cpp +++ b/libsolidity/ExpressionCompiler.cpp @@ -450,8 +450,8 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) arg->accept(*this); argumentTypes.push_back(arg->type()); } - ContractDefinition const& contract = dynamic_cast<ContractType const&>( - *function.returnParameterTypes().front()).contractDefinition(); + ContractDefinition const& contract = + dynamic_cast<ContractType const&>(*function.returnParameterTypes().front()).contractDefinition(); // copy the contract's code into memory bytes const& bytecode = m_context.compiledContract(contract); utils().fetchFreeMemoryPointer(); @@ -1087,8 +1087,10 @@ void ExpressionCompiler::appendExternalFunctionCall( vector<ASTPointer<Expression const>> const& _arguments ) { - solAssert(_functionType.takesArbitraryParameters() || - _arguments.size() == _functionType.parameterTypes().size(), ""); + solAssert( + _functionType.takesArbitraryParameters() || + _arguments.size() == _functionType.parameterTypes().size(), "" + ); // Assumed stack content here: // <stack top> diff --git a/libsolidity/GasEstimator.cpp b/libsolidity/GasEstimator.cpp index 5ff6814d..d576561a 100644 --- a/libsolidity/GasEstimator.cpp +++ b/libsolidity/GasEstimator.cpp @@ -52,7 +52,7 @@ GasEstimator::ASTGasConsumptionSelfAccumulated GasEstimator::structuralEstimatio GasMeter meter(block.startState->copy()); auto const end = _items.begin() + block.end; for (auto iter = _items.begin() + block.begin; iter != end; ++iter) - particularCosts[iter->getLocation()] += meter.estimateMax(*iter); + particularCosts[iter->location()] += meter.estimateMax(*iter); } set<ASTNode const*> finestNodes = finestNodesAtLocation(_ast); diff --git a/libsolidity/InterfaceHandler.cpp b/libsolidity/InterfaceHandler.cpp index 0c2a4287..a52357d0 100644 --- a/libsolidity/InterfaceHandler.cpp +++ b/libsolidity/InterfaceHandler.cpp @@ -393,7 +393,7 @@ string::const_iterator InterfaceHandler::appendDocTag( } } -static inline string::const_iterator getFirstSpaceOrNl( +static inline string::const_iterator firstSpaceOrNl( string::const_iterator _pos, string::const_iterator _end ) @@ -416,7 +416,7 @@ void InterfaceHandler::parseDocString(string const& _string, CommentOwner _owner if (tagPos != end && tagPos < nlPos) { // we found a tag - auto tagNameEndPos = getFirstSpaceOrNl(tagPos, end); + auto tagNameEndPos = firstSpaceOrNl(tagPos, end); if (tagNameEndPos == end) BOOST_THROW_EXCEPTION( DocstringParsingError() << diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index ebc7e1b2..d1c59ba5 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -697,8 +697,10 @@ bool ContractType::isImplicitlyConvertibleTo(Type const& _convertTo) const bool ContractType::isExplicitlyConvertibleTo(Type const& _convertTo) const { - return isImplicitlyConvertibleTo(_convertTo) || _convertTo.category() == Category::Integer || - _convertTo.category() == Category::Contract; + return + isImplicitlyConvertibleTo(_convertTo) || + _convertTo.category() == Category::Integer || + _convertTo.category() == Category::Contract; } TypePointer ContractType::unaryOperatorResult(Token::Value _operator) const diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp index aab612dc..eb4999e7 100644 --- a/test/libsolidity/Assembly.cpp +++ b/test/libsolidity/Assembly.cpp @@ -80,10 +80,10 @@ void checkAssemblyLocations(AssemblyItems const& _items, vector<SourceLocation> for (size_t i = 0; i < min(_items.size(), _locations.size()); ++i) { BOOST_CHECK_MESSAGE( - _items[i].getLocation() == _locations[i], + _items[i].location() == _locations[i], "Location mismatch for assembly item " + to_string(i) + ". Found: " + - to_string(_items[i].getLocation().start) + "-" + - to_string(_items[i].getLocation().end) + ", expected: " + + to_string(_items[i].location().start) + "-" + + to_string(_items[i].location().end) + ", expected: " + to_string(_locations[i].start) + "-" + to_string(_locations[i].end)); } diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp index dfbb1c65..9b1c026f 100644 --- a/test/libsolidity/SolidityExpressionCompiler.cpp +++ b/test/libsolidity/SolidityExpressionCompiler.cpp @@ -48,7 +48,7 @@ class FirstExpressionExtractor: private ASTVisitor { public: FirstExpressionExtractor(ASTNode& _node): m_expression(nullptr) { _node.accept(*this); } - Expression* getExpression() const { return m_expression; } + Expression* expression() const { return m_expression; } private: virtual bool visit(Assignment& _expression) override { return checkExpression(_expression); } virtual bool visit(UnaryOperation& _expression) override { return checkExpression(_expression); } @@ -123,7 +123,7 @@ bytes compileFirstExpression(const string& _sourceCode, vector<vector<string>> _ if (ContractDefinition* contract = dynamic_cast<ContractDefinition*>(node.get())) { FirstExpressionExtractor extractor(*contract); - BOOST_REQUIRE(extractor.getExpression() != nullptr); + BOOST_REQUIRE(extractor.expression() != nullptr); CompilerContext context; context.resetVisitedNodes(contract); @@ -134,7 +134,7 @@ bytes compileFirstExpression(const string& _sourceCode, vector<vector<string>> _ context.addVariable(dynamic_cast<VariableDeclaration const&>(resolveDeclaration(variable, resolver)), parametersSize--); - ExpressionCompiler(context).compile(*extractor.getExpression()); + ExpressionCompiler(context).compile(*extractor.expression()); for (vector<string> const& function: _functions) context << context.functionEntryLabel(dynamic_cast<FunctionDefinition const&>(resolveDeclaration(function, resolver))); diff --git a/test/libsolidity/SolidityInterface.cpp b/test/libsolidity/SolidityInterface.cpp index 39703cfc..d77bccbd 100644 --- a/test/libsolidity/SolidityInterface.cpp +++ b/test/libsolidity/SolidityInterface.cpp @@ -48,7 +48,7 @@ public: return m_reCompiler.contractDefinition(_contractName); } - string getSourcePart(ASTNode const& _node) const + string sourcePart(ASTNode const& _node) const { SourceLocation location = _node.location(); BOOST_REQUIRE(!location.isEmpty()); @@ -67,7 +67,7 @@ BOOST_FIXTURE_TEST_SUITE(SolidityInterface, SolidityInterfaceChecker) BOOST_AUTO_TEST_CASE(empty_contract) { ContractDefinition const& contract = checkInterface("contract test {}"); - BOOST_CHECK_EQUAL(getSourcePart(contract), "contract test{}"); + BOOST_CHECK_EQUAL(sourcePart(contract), "contract test{}"); } BOOST_AUTO_TEST_CASE(single_function) @@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(single_function) " function f(uint a) returns(uint d) { return a * 7; }\n" "}\n"); BOOST_REQUIRE_EQUAL(1, contract.definedFunctions().size()); - BOOST_CHECK_EQUAL(getSourcePart(*contract.definedFunctions().front()), + BOOST_CHECK_EQUAL(sourcePart(*contract.definedFunctions().front()), "function f(uint256 a)returns(uint256 d);"); } @@ -86,7 +86,7 @@ BOOST_AUTO_TEST_CASE(single_constant_function) ContractDefinition const& contract = checkInterface( "contract test { function f(uint a) constant returns(bytes1 x) { 1==2; } }"); BOOST_REQUIRE_EQUAL(1, contract.definedFunctions().size()); - BOOST_CHECK_EQUAL(getSourcePart(*contract.definedFunctions().front()), + BOOST_CHECK_EQUAL(sourcePart(*contract.definedFunctions().front()), "function f(uint256 a)constant returns(bytes1 x);"); } @@ -100,15 +100,15 @@ BOOST_AUTO_TEST_CASE(multiple_functions) set<string> expectation({"function f(uint256 a)returns(uint256 d);", "function g(uint256 b)returns(uint256 e);"}); BOOST_REQUIRE_EQUAL(2, contract.definedFunctions().size()); - BOOST_CHECK(expectation == set<string>({getSourcePart(*contract.definedFunctions().at(0)), - getSourcePart(*contract.definedFunctions().at(1))})); + BOOST_CHECK(expectation == set<string>({sourcePart(*contract.definedFunctions().at(0)), + sourcePart(*contract.definedFunctions().at(1))})); } BOOST_AUTO_TEST_CASE(exclude_fallback_function) { char const* sourceCode = "contract test { function() {} }"; ContractDefinition const& contract = checkInterface(sourceCode); - BOOST_CHECK_EQUAL(getSourcePart(contract), "contract test{}"); + BOOST_CHECK_EQUAL(sourcePart(contract), "contract test{}"); } BOOST_AUTO_TEST_CASE(events) @@ -138,8 +138,8 @@ BOOST_AUTO_TEST_CASE(inheritance) set<string> expectedFunctions({"function baseFunction(uint256 p)returns(uint256 i);", "function derivedFunction(bytes32 p)returns(bytes32 i);"}); BOOST_REQUIRE_EQUAL(2, contract.definedFunctions().size()); - BOOST_CHECK(expectedFunctions == set<string>({getSourcePart(*contract.definedFunctions().at(0)), - getSourcePart(*contract.definedFunctions().at(1))})); + BOOST_CHECK(expectedFunctions == set<string>({sourcePart(*contract.definedFunctions().at(0)), + sourcePart(*contract.definedFunctions().at(1))})); } BOOST_AUTO_TEST_SUITE_END() diff --git a/test/libsolidity/SolidityOptimizer.cpp b/test/libsolidity/SolidityOptimizer.cpp index 85a88c03..20d59a04 100644 --- a/test/libsolidity/SolidityOptimizer.cpp +++ b/test/libsolidity/SolidityOptimizer.cpp @@ -101,7 +101,7 @@ public: return state; } - AssemblyItems getCSE(AssemblyItems const& _input, eth::KnownState const& _state = eth::KnownState()) + AssemblyItems CSE(AssemblyItems const& _input, eth::KnownState const& _state = eth::KnownState()) { AssemblyItems input = addDummyLocations(_input); @@ -111,7 +111,7 @@ public: for (AssemblyItem const& item: output) { - BOOST_CHECK(item == Instruction::POP || !item.getLocation().isEmpty()); + BOOST_CHECK(item == Instruction::POP || !item.location().isEmpty()); } return output; } @@ -122,11 +122,11 @@ public: KnownState const& _state = eth::KnownState() ) { - AssemblyItems output = getCSE(_input, _state); + AssemblyItems output = CSE(_input, _state); BOOST_CHECK_EQUAL_COLLECTIONS(_expectation.begin(), _expectation.end(), output.begin(), output.end()); } - AssemblyItems getCFG(AssemblyItems const& _input) + AssemblyItems CFG(AssemblyItems const& _input) { AssemblyItems output = _input; // Running it four times should be enough for these tests. @@ -144,7 +144,7 @@ public: void checkCFG(AssemblyItems const& _input, AssemblyItems const& _expectation) { - AssemblyItems output = getCFG(_input); + AssemblyItems output = CFG(_input); BOOST_CHECK_EQUAL_COLLECTIONS(_expectation.begin(), _expectation.end(), output.begin(), output.end()); } @@ -890,7 +890,7 @@ BOOST_AUTO_TEST_CASE(cse_sha3_twice_same_content_noninterfering_store_in_between Instruction::SHA3 // sha3(m[12..(12+32)]) }; // if this changes too often, only count the number of SHA3 and MSTORE instructions - AssemblyItems output = getCSE(input); + AssemblyItems output = CSE(input); BOOST_CHECK_EQUAL(4, count(output.begin(), output.end(), AssemblyItem(Instruction::MSTORE))); BOOST_CHECK_EQUAL(1, count(output.begin(), output.end(), AssemblyItem(Instruction::SHA3))); } @@ -914,7 +914,7 @@ BOOST_AUTO_TEST_CASE(cse_equality_on_initially_known_stack) AssemblyItems input{ Instruction::EQ }; - AssemblyItems output = getCSE(input, state); + AssemblyItems output = CSE(input, state); // check that it directly pushes 1 (true) BOOST_CHECK(find(output.begin(), output.end(), AssemblyItem(u256(1))) != output.end()); } @@ -938,7 +938,7 @@ BOOST_AUTO_TEST_CASE(cse_access_previous_sequence) u256(0), Instruction::SLOAD, }; - BOOST_CHECK_THROW(getCSE(input, state), StackTooDeepException); + BOOST_CHECK_THROW(CSE(input, state), StackTooDeepException); // @todo for now, this throws an exception, but it should recover to the following // (or an even better version) at some point: // 0, SLOAD, 1, ADD, SSTORE, 0 SLOAD |