From c94b1f81730c27480cb5813a7a909511613c14c5 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 17 Aug 2017 00:07:07 +0100 Subject: Set variable to nullptr in ASTPrinter --- libsolidity/ast/ASTPrinter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libsolidity') diff --git a/libsolidity/ast/ASTPrinter.h b/libsolidity/ast/ASTPrinter.h index 4a37f17f..193f9296 100644 --- a/libsolidity/ast/ASTPrinter.h +++ b/libsolidity/ast/ASTPrinter.h @@ -146,7 +146,7 @@ private: std::string m_source; ASTNode const* m_ast; GasEstimator::ASTGasConsumption m_gasCosts; - std::ostream* m_ostream; + std::ostream* m_ostream = nullptr; }; } -- cgit From e2cfc9ee92158169b5dd058074f25d67959e9875 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 17 Aug 2017 01:14:15 +0100 Subject: Mark a lot of functions const (where possible) --- libsolidity/ast/ASTJsonConverter.h | 6 +++--- libsolidity/codegen/ABIFunctions.cpp | 2 +- libsolidity/codegen/ABIFunctions.h | 2 +- libsolidity/codegen/Compiler.h | 6 +++--- libsolidity/codegen/CompilerContext.h | 4 ++-- libsolidity/codegen/ExpressionCompiler.cpp | 2 +- libsolidity/codegen/ExpressionCompiler.h | 2 +- libsolidity/inlineasm/AsmParser.h | 2 +- libsolidity/inlineasm/AsmPrinter.cpp | 2 +- libsolidity/inlineasm/AsmPrinter.h | 2 +- libsolidity/inlineasm/AsmScope.cpp | 2 +- libsolidity/inlineasm/AsmScope.h | 2 +- libsolidity/interface/CompilerStack.h | 2 +- libsolidity/parsing/Scanner.h | 10 +++++----- 14 files changed, 23 insertions(+), 23 deletions(-) (limited to 'libsolidity') diff --git a/libsolidity/ast/ASTJsonConverter.h b/libsolidity/ast/ASTJsonConverter.h index 70e260db..cc589d4a 100644 --- a/libsolidity/ast/ASTJsonConverter.h +++ b/libsolidity/ast/ASTJsonConverter.h @@ -119,7 +119,7 @@ private: ); std::string sourceLocationToString(SourceLocation const& _location) const; std::string namePathToString(std::vector const& _namePath) const; - Json::Value idOrNull(ASTNode const* _pt) + Json::Value idOrNull(ASTNode const* _pt) const { return _pt ? Json::Value(nodeId(*_pt)) : Json::nullValue; } @@ -134,12 +134,12 @@ private: std::string literalTokenKind(Token::Value _token); std::string type(Expression const& _expression); std::string type(VariableDeclaration const& _varDecl); - int nodeId(ASTNode const& _node) + int nodeId(ASTNode const& _node) const { return _node.id(); } template - Json::Value getContainerIds(Container const& container) + Json::Value getContainerIds(Container const& container) const { Json::Value tmp(Json::arrayValue); for (auto const& element: container) diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp index a2938ed7..2313473f 100644 --- a/libsolidity/codegen/ABIFunctions.cpp +++ b/libsolidity/codegen/ABIFunctions.cpp @@ -1056,7 +1056,7 @@ string ABIFunctions::createFunction(string const& _name, function con return _name; } -size_t ABIFunctions::headSize(TypePointers const& _targetTypes) +size_t ABIFunctions::headSize(TypePointers const& _targetTypes) const { size_t headSize = 0; for (auto const& t: _targetTypes) diff --git a/libsolidity/codegen/ABIFunctions.h b/libsolidity/codegen/ABIFunctions.h index 76f4b467..103df5ae 100644 --- a/libsolidity/codegen/ABIFunctions.h +++ b/libsolidity/codegen/ABIFunctions.h @@ -162,7 +162,7 @@ private: std::string createFunction(std::string const& _name, std::function const& _creator); /// @returns the size of the static part of the encoding of the given types. - size_t headSize(TypePointers const& _targetTypes); + size_t headSize(TypePointers const& _targetTypes) const; /// Map from function name to code for a multi-use function. std::map m_requestedFunctions; diff --git a/libsolidity/codegen/Compiler.h b/libsolidity/codegen/Compiler.h index eef078c1..8c63ea9c 100644 --- a/libsolidity/codegen/Compiler.h +++ b/libsolidity/codegen/Compiler.h @@ -51,9 +51,9 @@ public: ContractDefinition const& _contract, std::map const& _contracts ); - eth::Assembly const& assembly() { return m_context.assembly(); } - eth::LinkerObject assembledObject() { return m_context.assembledObject(); } - eth::LinkerObject runtimeObject() { return m_context.assembledRuntimeObject(m_runtimeSub); } + eth::Assembly const& assembly() const { return m_context.assembly(); } + eth::LinkerObject assembledObject() const { return m_context.assembledObject(); } + eth::LinkerObject runtimeObject() const { return m_context.assembledRuntimeObject(m_runtimeSub); } /// @arg _sourceCodes is the map of input files to source code strings /// @arg _inJsonFromat shows whether the out should be in Json format Json::Value streamAssembly(std::ostream& _stream, StringMap const& _sourceCodes = StringMap(), bool _inJsonFormat = false) const diff --git a/libsolidity/codegen/CompilerContext.h b/libsolidity/codegen/CompilerContext.h index 583360ea..96cbf6c1 100644 --- a/libsolidity/codegen/CompilerContext.h +++ b/libsolidity/codegen/CompilerContext.h @@ -208,8 +208,8 @@ public: return m_asm->stream(_stream, "", _sourceCodes, _inJsonFormat); } - eth::LinkerObject const& assembledObject() { return m_asm->assemble(); } - eth::LinkerObject const& assembledRuntimeObject(size_t _subIndex) { return m_asm->sub(_subIndex).assemble(); } + eth::LinkerObject const& assembledObject() const { return m_asm->assemble(); } + eth::LinkerObject const& assembledRuntimeObject(size_t _subIndex) const { return m_asm->sub(_subIndex).assemble(); } /** * Helper class to pop the visited nodes stack when a scope closes diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 55d35c44..639bfc32 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -1811,7 +1811,7 @@ void ExpressionCompiler::setLValueToStorageItem(Expression const& _expression) setLValue(_expression, *_expression.annotation().type); } -bool ExpressionCompiler::cleanupNeededForOp(Type::Category _type, Token::Value _op) +bool ExpressionCompiler::cleanupNeededForOp(Type::Category _type, Token::Value _op) const { if (Token::isCompareOp(_op) || Token::isShiftOp(_op)) return true; diff --git a/libsolidity/codegen/ExpressionCompiler.h b/libsolidity/codegen/ExpressionCompiler.h index 3b8cf1c6..5f6c3d64 100644 --- a/libsolidity/codegen/ExpressionCompiler.h +++ b/libsolidity/codegen/ExpressionCompiler.h @@ -119,7 +119,7 @@ private: /// @returns true if the operator applied to the given type requires a cleanup prior to the /// operation. - bool cleanupNeededForOp(Type::Category _type, Token::Value _op); + bool cleanupNeededForOp(Type::Category _type, Token::Value _op) const; /// @returns the CompilerUtils object containing the current context. CompilerUtils utils(); diff --git a/libsolidity/inlineasm/AsmParser.h b/libsolidity/inlineasm/AsmParser.h index a48a3393..e46d1732 100644 --- a/libsolidity/inlineasm/AsmParser.h +++ b/libsolidity/inlineasm/AsmParser.h @@ -45,7 +45,7 @@ public: protected: /// Creates an inline assembly node with the given source location. - template T createWithLocation(SourceLocation const& _loc = SourceLocation()) + template T createWithLocation(SourceLocation const& _loc = SourceLocation()) const { T r; r.location = _loc; diff --git a/libsolidity/inlineasm/AsmPrinter.cpp b/libsolidity/inlineasm/AsmPrinter.cpp index 4f96a3e9..47ede91d 100644 --- a/libsolidity/inlineasm/AsmPrinter.cpp +++ b/libsolidity/inlineasm/AsmPrinter.cpp @@ -209,7 +209,7 @@ string AsmPrinter::operator()(Block const& _block) return "{\n " + body + "\n}"; } -string AsmPrinter::appendTypeName(std::string const& _type) +string AsmPrinter::appendTypeName(std::string const& _type) const { if (m_julia) return ":" + _type; diff --git a/libsolidity/inlineasm/AsmPrinter.h b/libsolidity/inlineasm/AsmPrinter.h index f57dddc8..66520632 100644 --- a/libsolidity/inlineasm/AsmPrinter.h +++ b/libsolidity/inlineasm/AsmPrinter.h @@ -53,7 +53,7 @@ public: std::string operator()(assembly::Block const& _block); private: - std::string appendTypeName(std::string const& _type); + std::string appendTypeName(std::string const& _type) const; bool m_julia = false; }; diff --git a/libsolidity/inlineasm/AsmScope.cpp b/libsolidity/inlineasm/AsmScope.cpp index 315d5953..64d5bd9a 100644 --- a/libsolidity/inlineasm/AsmScope.cpp +++ b/libsolidity/inlineasm/AsmScope.cpp @@ -70,7 +70,7 @@ Scope::Identifier* Scope::lookup(string const& _name) return nullptr; } -bool Scope::exists(string const& _name) +bool Scope::exists(string const& _name) const { if (identifiers.count(_name)) return true; diff --git a/libsolidity/inlineasm/AsmScope.h b/libsolidity/inlineasm/AsmScope.h index cc240565..447d6490 100644 --- a/libsolidity/inlineasm/AsmScope.h +++ b/libsolidity/inlineasm/AsmScope.h @@ -107,7 +107,7 @@ struct Scope } /// @returns true if the name exists in this scope or in super scopes (also searches /// across function and assembly boundaries). - bool exists(std::string const& _name); + bool exists(std::string const& _name) const; /// @returns the number of variables directly registered inside the scope. size_t numberOfVariables() const; diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index 54e3e23f..bb0f4126 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -88,7 +88,7 @@ public: m_errorReporter(m_errorList) {} /// @returns the list of errors that occured during parsing and type checking. - ErrorList const& errors() { return m_errorReporter.errors(); } + ErrorList const& errors() const { return m_errorReporter.errors(); } /// @returns the current state. State state() const { return m_stackState; } diff --git a/libsolidity/parsing/Scanner.h b/libsolidity/parsing/Scanner.h index d6b48c6f..0adaa6fd 100644 --- a/libsolidity/parsing/Scanner.h +++ b/libsolidity/parsing/Scanner.h @@ -75,7 +75,7 @@ public: int position() const { return m_position; } bool isPastEndOfInput(size_t _charsForward = 0) const { return (m_position + _charsForward) >= m_source.size(); } char get(size_t _charsForward = 0) const { return m_source[m_position + _charsForward]; } - char advanceAndGet(size_t _chars=1); + char advanceAndGet(size_t _chars = 1); char rollback(size_t _amount); void reset() { m_position = 0; } @@ -118,11 +118,11 @@ public: ///@name Information about the current token /// @returns the current token - Token::Value currentToken() + Token::Value currentToken() const { return m_currentToken.token; } - ElementaryTypeNameToken currentElementaryTypeNameToken() + ElementaryTypeNameToken currentElementaryTypeNameToken() const { unsigned firstSize; unsigned secondSize; @@ -219,8 +219,8 @@ private: bool scanEscape(); /// Return the current source position. - int sourcePos() { return m_source.position(); } - bool isSourcePastEndOfInput() { return m_source.isPastEndOfInput(); } + int sourcePos() const { return m_source.position(); } + bool isSourcePastEndOfInput() const { return m_source.isPastEndOfInput(); } TokenDesc m_skippedComment; // desc for current skipped comment TokenDesc m_nextSkippedComment; // desc for next skiped comment -- cgit From 2a5772cff7d03de0d02c5358a6a6755e8f802697 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 21 Aug 2017 15:42:17 +0100 Subject: Mark appropriate constructors explicit --- libsolidity/codegen/ArrayUtils.h | 2 +- libsolidity/codegen/CompilerUtils.h | 2 +- libsolidity/codegen/ContractCompiler.cpp | 2 +- libsolidity/inlineasm/AsmCodeGen.cpp | 2 +- libsolidity/interface/ErrorReporter.h | 2 +- libsolidity/interface/StandardCompiler.h | 2 +- libsolidity/parsing/Parser.cpp | 4 ++-- libsolidity/parsing/Parser.h | 2 +- libsolidity/parsing/ParserBase.h | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) (limited to 'libsolidity') diff --git a/libsolidity/codegen/ArrayUtils.h b/libsolidity/codegen/ArrayUtils.h index 806fbea7..f3ddc4ee 100644 --- a/libsolidity/codegen/ArrayUtils.h +++ b/libsolidity/codegen/ArrayUtils.h @@ -40,7 +40,7 @@ using TypePointer = std::shared_ptr; class ArrayUtils { public: - ArrayUtils(CompilerContext& _context): m_context(_context) {} + explicit ArrayUtils(CompilerContext& _context): m_context(_context) {} /// Copies an array to an array in storage. The arrays can be of different types only if /// their storage representation is the same. diff --git a/libsolidity/codegen/CompilerUtils.h b/libsolidity/codegen/CompilerUtils.h index 09427788..18b70250 100644 --- a/libsolidity/codegen/CompilerUtils.h +++ b/libsolidity/codegen/CompilerUtils.h @@ -33,7 +33,7 @@ class Type; // forward class CompilerUtils { public: - CompilerUtils(CompilerContext& _context): m_context(_context) {} + explicit CompilerUtils(CompilerContext& _context): m_context(_context) {} /// Stores the initial value of the free-memory-pointer at its position; void initialiseFreeMemoryPointer(); diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index 29a22fae..e53f1b94 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -45,7 +45,7 @@ using namespace dev::solidity; class StackHeightChecker { public: - StackHeightChecker(CompilerContext const& _context): + explicit StackHeightChecker(CompilerContext const& _context): m_context(_context), stackHeight(m_context.stackHeight()) {} void check() { solAssert(m_context.stackHeight() == stackHeight, std::string("I sense a disturbance in the stack: ") + std::to_string(m_context.stackHeight()) + " vs " + std::to_string(stackHeight)); } private: diff --git a/libsolidity/inlineasm/AsmCodeGen.cpp b/libsolidity/inlineasm/AsmCodeGen.cpp index 74743737..24aa4ba8 100644 --- a/libsolidity/inlineasm/AsmCodeGen.cpp +++ b/libsolidity/inlineasm/AsmCodeGen.cpp @@ -52,7 +52,7 @@ using namespace dev::solidity::assembly; class EthAssemblyAdapter: public julia::AbstractAssembly { public: - EthAssemblyAdapter(eth::Assembly& _assembly): + explicit EthAssemblyAdapter(eth::Assembly& _assembly): m_assembly(_assembly) { } diff --git a/libsolidity/interface/ErrorReporter.h b/libsolidity/interface/ErrorReporter.h index 12f4e8df..241d6b43 100644 --- a/libsolidity/interface/ErrorReporter.h +++ b/libsolidity/interface/ErrorReporter.h @@ -36,7 +36,7 @@ class ErrorReporter { public: - ErrorReporter(ErrorList& _errors): + explicit ErrorReporter(ErrorList& _errors): m_errorList(_errors) { } ErrorReporter& operator=(ErrorReporter const& _errorReporter); diff --git a/libsolidity/interface/StandardCompiler.h b/libsolidity/interface/StandardCompiler.h index dfaf88cd..d9787a40 100644 --- a/libsolidity/interface/StandardCompiler.h +++ b/libsolidity/interface/StandardCompiler.h @@ -40,7 +40,7 @@ public: /// Creates a new StandardCompiler. /// @param _readFile callback to used to read files for import statements. Must return /// and must not emit exceptions. - StandardCompiler(ReadFile::Callback const& _readFile = ReadFile::Callback()) + explicit StandardCompiler(ReadFile::Callback const& _readFile = ReadFile::Callback()) : m_compilerStack(_readFile), m_readFile(_readFile) { } diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index d3a6aa45..7455cbca 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -40,7 +40,7 @@ namespace solidity class Parser::ASTNodeFactory { public: - ASTNodeFactory(Parser const& _parser): + explicit ASTNodeFactory(Parser const& _parser): m_parser(_parser), m_location(_parser.position(), -1, _parser.sourceName()) {} ASTNodeFactory(Parser const& _parser, ASTPointer const& _childNode): m_parser(_parser), m_location(_childNode->location()) {} @@ -69,7 +69,7 @@ private: class Parser::RecursionGuard { public: - RecursionGuard(Parser& _parser): + explicit RecursionGuard(Parser& _parser): m_parser(_parser) { m_parser.increaseRecursionDepth(); diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h index 5e6f3ef6..0f74880c 100644 --- a/libsolidity/parsing/Parser.h +++ b/libsolidity/parsing/Parser.h @@ -35,7 +35,7 @@ class Scanner; class Parser: public ParserBase { public: - Parser(ErrorReporter& _errorReporter): ParserBase(_errorReporter) {} + explicit Parser(ErrorReporter& _errorReporter): ParserBase(_errorReporter) {} ASTPointer parse(std::shared_ptr const& _scanner); diff --git a/libsolidity/parsing/ParserBase.h b/libsolidity/parsing/ParserBase.h index 5b03ab5e..48733fc1 100644 --- a/libsolidity/parsing/ParserBase.h +++ b/libsolidity/parsing/ParserBase.h @@ -36,7 +36,7 @@ class Scanner; class ParserBase { public: - ParserBase(ErrorReporter& errorReporter): m_errorReporter(errorReporter) {} + explicit ParserBase(ErrorReporter& errorReporter): m_errorReporter(errorReporter) {} std::shared_ptr const& sourceName() const; -- cgit From 9897c56b2cacf162f8fd41d60e91b7f71863f8d5 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Mon, 21 Aug 2017 22:05:24 +0100 Subject: Mark a lot of functions static (where possible) --- libsolidity/ast/ASTJsonConverter.h | 6 +++--- libsolidity/codegen/ABIFunctions.cpp | 2 +- libsolidity/codegen/ABIFunctions.h | 2 +- libsolidity/inlineasm/AsmCodeGen.cpp | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'libsolidity') diff --git a/libsolidity/ast/ASTJsonConverter.h b/libsolidity/ast/ASTJsonConverter.h index cc589d4a..186607ce 100644 --- a/libsolidity/ast/ASTJsonConverter.h +++ b/libsolidity/ast/ASTJsonConverter.h @@ -119,7 +119,7 @@ private: ); std::string sourceLocationToString(SourceLocation const& _location) const; std::string namePathToString(std::vector const& _namePath) const; - Json::Value idOrNull(ASTNode const* _pt) const + static Json::Value idOrNull(ASTNode const* _pt) { return _pt ? Json::Value(nodeId(*_pt)) : Json::nullValue; } @@ -134,12 +134,12 @@ private: std::string literalTokenKind(Token::Value _token); std::string type(Expression const& _expression); std::string type(VariableDeclaration const& _varDecl); - int nodeId(ASTNode const& _node) const + static int nodeId(ASTNode const& _node) { return _node.id(); } template - Json::Value getContainerIds(Container const& container) const + static Json::Value getContainerIds(Container const& container) { Json::Value tmp(Json::arrayValue); for (auto const& element: container) diff --git a/libsolidity/codegen/ABIFunctions.cpp b/libsolidity/codegen/ABIFunctions.cpp index 2313473f..a2938ed7 100644 --- a/libsolidity/codegen/ABIFunctions.cpp +++ b/libsolidity/codegen/ABIFunctions.cpp @@ -1056,7 +1056,7 @@ string ABIFunctions::createFunction(string const& _name, function con return _name; } -size_t ABIFunctions::headSize(TypePointers const& _targetTypes) const +size_t ABIFunctions::headSize(TypePointers const& _targetTypes) { size_t headSize = 0; for (auto const& t: _targetTypes) diff --git a/libsolidity/codegen/ABIFunctions.h b/libsolidity/codegen/ABIFunctions.h index 103df5ae..e43e2323 100644 --- a/libsolidity/codegen/ABIFunctions.h +++ b/libsolidity/codegen/ABIFunctions.h @@ -162,7 +162,7 @@ private: std::string createFunction(std::string const& _name, std::function const& _creator); /// @returns the size of the static part of the encoding of the given types. - size_t headSize(TypePointers const& _targetTypes) const; + static size_t headSize(TypePointers const& _targetTypes); /// Map from function name to code for a multi-use function. std::map m_requestedFunctions; diff --git a/libsolidity/inlineasm/AsmCodeGen.cpp b/libsolidity/inlineasm/AsmCodeGen.cpp index 24aa4ba8..6d0c0255 100644 --- a/libsolidity/inlineasm/AsmCodeGen.cpp +++ b/libsolidity/inlineasm/AsmCodeGen.cpp @@ -127,7 +127,7 @@ public: } private: - LabelID assemblyTagToIdentifier(eth::AssemblyItem const& _tag) const + static LabelID assemblyTagToIdentifier(eth::AssemblyItem const& _tag) { u256 id = _tag.data(); solAssert(id <= std::numeric_limits::max(), "Tag id too large."); -- cgit