From d67322a1861d60a88151f7c25d6c3478a9a39acf Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 14 Nov 2018 17:11:55 +0100 Subject: Introduce namespace `langutil` in liblangutil directory. Also: - Use {}-style list initialisation for SourceLocation construction - Introduce new system includes - Changes the API of the Scanner to take source as value (with move) as opposed to as a reference --- libevmasm/Assembly.cpp | 1 + libevmasm/Assembly.h | 4 +-- libevmasm/AssemblyItem.h | 12 +++---- libevmasm/CommonSubexpressionEliminator.cpp | 1 + libevmasm/CommonSubexpressionEliminator.h | 9 +++-- libevmasm/ControlFlowGraph.cpp | 2 +- libevmasm/ExpressionClasses.cpp | 2 +- libevmasm/ExpressionClasses.h | 7 +++- libevmasm/KnownState.cpp | 1 + libevmasm/KnownState.h | 21 ++++++----- libevmasm/SimplificationRules.cpp | 2 +- libevmasm/SimplificationRules.h | 9 +++-- liblangutil/CharStream.cpp | 11 ++---- liblangutil/CharStream.h | 5 +-- liblangutil/ErrorReporter.cpp | 4 +-- liblangutil/ErrorReporter.h | 8 +---- liblangutil/Exceptions.cpp | 2 +- liblangutil/Exceptions.h | 25 +++++++------ liblangutil/ParserBase.cpp | 3 +- liblangutil/ParserBase.h | 8 ++--- liblangutil/Scanner.cpp | 16 ++++----- liblangutil/Scanner.h | 16 ++++----- liblangutil/SourceLocation.h | 4 +-- liblangutil/Token.cpp | 7 ++-- liblangutil/Token.h | 8 ++--- libsolidity/analysis/ConstantEvaluator.h | 10 ++++-- libsolidity/analysis/ControlFlowAnalyzer.cpp | 2 ++ libsolidity/analysis/ControlFlowAnalyzer.h | 4 +-- libsolidity/analysis/ControlFlowGraph.cpp | 3 +- libsolidity/analysis/ControlFlowGraph.h | 4 +-- libsolidity/analysis/DocStringAnalyser.cpp | 1 + libsolidity/analysis/DocStringAnalyser.h | 11 +++--- libsolidity/analysis/NameAndTypeResolver.cpp | 7 ++-- libsolidity/analysis/NameAndTypeResolver.h | 19 +++++----- libsolidity/analysis/PostTypeChecker.cpp | 1 + libsolidity/analysis/PostTypeChecker.h | 14 +++++--- libsolidity/analysis/ReferencesResolver.cpp | 10 ++++-- libsolidity/analysis/ReferencesResolver.h | 19 ++++++---- libsolidity/analysis/SemVerHandler.h | 3 +- libsolidity/analysis/StaticAnalyzer.cpp | 1 + libsolidity/analysis/StaticAnalyzer.h | 9 +++-- libsolidity/analysis/SyntaxChecker.cpp | 1 + libsolidity/analysis/SyntaxChecker.h | 9 +++-- libsolidity/analysis/TypeChecker.cpp | 1 + libsolidity/analysis/TypeChecker.h | 11 +++--- libsolidity/analysis/ViewPureChecker.cpp | 3 ++ libsolidity/analysis/ViewPureChecker.h | 20 ++++++----- libsolidity/ast/AST.h | 4 ++- libsolidity/ast/ASTJsonConverter.cpp | 1 + libsolidity/ast/ASTJsonConverter.h | 7 +++- libsolidity/ast/ASTPrinter.cpp | 1 + libsolidity/ast/Types.cpp | 1 + libsolidity/ast/Types.h | 2 +- libsolidity/codegen/ArrayUtils.cpp | 1 + libsolidity/codegen/CompilerContext.cpp | 4 ++- libsolidity/codegen/CompilerUtils.cpp | 1 + libsolidity/codegen/ContractCompiler.cpp | 1 + libsolidity/codegen/ExpressionCompiler.cpp | 1 + libsolidity/codegen/LValue.cpp | 1 + libsolidity/codegen/LValue.h | 42 +++++++++++----------- libsolidity/formal/SMTChecker.cpp | 1 + libsolidity/formal/SMTChecker.h | 23 +++++++----- libsolidity/inlineasm/AsmAnalysis.cpp | 1 + libsolidity/inlineasm/AsmAnalysis.h | 23 +++++++----- libsolidity/inlineasm/AsmCodeGen.cpp | 1 + libsolidity/inlineasm/AsmData.h | 40 ++++++++++----------- libsolidity/inlineasm/AsmParser.cpp | 1 + libsolidity/inlineasm/AsmParser.h | 12 ++++--- libsolidity/inlineasm/AsmScopeFiller.cpp | 1 + libsolidity/inlineasm/AsmScopeFiller.h | 14 +++++--- libsolidity/interface/AssemblyStack.cpp | 1 + libsolidity/interface/AssemblyStack.h | 18 ++++++---- libsolidity/interface/CompilerStack.cpp | 1 + libsolidity/interface/CompilerStack.h | 24 +++++++------ libsolidity/interface/GasEstimator.cpp | 1 + libsolidity/interface/SourceReferenceFormatter.cpp | 1 + libsolidity/interface/SourceReferenceFormatter.h | 14 +++++--- libsolidity/interface/StandardCompiler.cpp | 3 +- libsolidity/parsing/DocStringParser.cpp | 1 + libsolidity/parsing/DocStringParser.h | 11 +++--- libsolidity/parsing/Parser.cpp | 1 + libsolidity/parsing/Parser.h | 15 ++++---- libsolidity/parsing/Token.h | 36 +++++++++++++++++++ libyul/backends/evm/AbstractAssembly.h | 8 +++-- libyul/backends/evm/EVMAssembly.cpp | 1 + libyul/backends/evm/EVMAssembly.h | 7 +++- libyul/optimiser/ExpressionSplitter.cpp | 1 + libyul/optimiser/SSATransform.cpp | 1 + libyul/optimiser/SimplificationRules.cpp | 1 + libyul/optimiser/SimplificationRules.h | 2 +- solc/CommandLineInterface.cpp | 3 +- test/libevmasm/Assembler.cpp | 1 + test/libevmasm/Optimiser.cpp | 1 + test/liblangutil/SourceLocation.cpp | 5 +-- test/libsolidity/AnalysisFramework.cpp | 3 +- test/libsolidity/AnalysisFramework.h | 8 ++--- test/libsolidity/Assembly.cpp | 1 + test/libsolidity/ErrorCheck.cpp | 1 + test/libsolidity/ErrorCheck.h | 4 +-- test/libsolidity/GasMeter.cpp | 1 + test/libsolidity/InlineAssembly.cpp | 1 + test/libsolidity/SMTChecker.cpp | 1 + test/libsolidity/SemVerMatcher.cpp | 1 + test/libsolidity/SolidityExecutionFramework.h | 4 +-- test/libsolidity/SolidityExpressionCompiler.cpp | 1 + test/libsolidity/SolidityNameAndTypeResolution.cpp | 1 + test/libsolidity/SolidityNatspecJSON.cpp | 2 ++ test/libsolidity/SolidityParser.cpp | 1 + test/libsolidity/SolidityScanner.cpp | 1 + test/libsolidity/SolidityTypes.cpp | 1 + test/libsolidity/SyntaxTest.cpp | 1 + test/libsolidity/ViewPureChecker.cpp | 1 + test/libyul/Common.cpp | 1 + test/libyul/Common.h | 12 ++++--- test/libyul/Parser.cpp | 1 + test/libyul/YulOptimizerTest.cpp | 6 ++-- test/libyul/YulOptimizerTest.h | 11 +++--- test/tools/yulopti.cpp | 5 +-- 118 files changed, 476 insertions(+), 287 deletions(-) create mode 100644 libsolidity/parsing/Token.h diff --git a/libevmasm/Assembly.cpp b/libevmasm/Assembly.cpp index e63194a0..d80f97c4 100644 --- a/libevmasm/Assembly.cpp +++ b/libevmasm/Assembly.cpp @@ -35,6 +35,7 @@ using namespace std; using namespace dev; using namespace dev::eth; +using namespace langutil; void Assembly::append(Assembly const& _a) { diff --git a/libevmasm/Assembly.h b/libevmasm/Assembly.h index e1993082..d846b475 100644 --- a/libevmasm/Assembly.h +++ b/libevmasm/Assembly.h @@ -93,7 +93,7 @@ public: void setDeposit(int _deposit) { m_deposit = _deposit; assertThrow(m_deposit >= 0, InvalidDeposit, ""); } /// Changes the source location used for each appended item. - void setSourceLocation(SourceLocation const& _location) { m_currentSourceLocation = _location; } + void setSourceLocation(langutil::SourceLocation const& _location) { m_currentSourceLocation = _location; } /// Assembles the assembly into bytecode. The assembly should not be modified after this call, since the assembled version is cached. LinkerObject const& assemble() const; @@ -178,7 +178,7 @@ protected: int m_deposit = 0; - SourceLocation m_currentSourceLocation; + langutil::SourceLocation m_currentSourceLocation; }; inline std::ostream& operator<<(std::ostream& _out, Assembly const& _a) diff --git a/libevmasm/AssemblyItem.h b/libevmasm/AssemblyItem.h index 802bde25..a7875171 100644 --- a/libevmasm/AssemblyItem.h +++ b/libevmasm/AssemblyItem.h @@ -57,14 +57,14 @@ class AssemblyItem public: enum class JumpType { Ordinary, IntoFunction, OutOfFunction }; - AssemblyItem(u256 _push, SourceLocation const& _location = SourceLocation()): + AssemblyItem(u256 _push, langutil::SourceLocation const& _location = langutil::SourceLocation()): AssemblyItem(Push, _push, _location) { } - AssemblyItem(solidity::Instruction _i, SourceLocation const& _location = SourceLocation()): + AssemblyItem(solidity::Instruction _i, langutil::SourceLocation const& _location = langutil::SourceLocation()): m_type(Operation), m_instruction(_i), m_location(_location) {} - AssemblyItem(AssemblyItemType _type, u256 _data = 0, SourceLocation const& _location = SourceLocation()): + AssemblyItem(AssemblyItemType _type, u256 _data = 0, langutil::SourceLocation const& _location = langutil::SourceLocation()): m_type(_type), m_location(_location) { @@ -124,8 +124,8 @@ public: /// @returns true if the assembly item can be used in a functional context. bool canBeFunctional() const; - void setLocation(SourceLocation const& _location) { m_location = _location; } - SourceLocation const& location() const { return m_location; } + void setLocation(langutil::SourceLocation const& _location) { m_location = _location; } + langutil::SourceLocation const& location() const { return m_location; } void setJumpType(JumpType _jumpType) { m_jumpType = _jumpType; } JumpType getJumpType() const { return m_jumpType; } @@ -140,7 +140,7 @@ private: AssemblyItemType m_type; Instruction m_instruction; ///< Only valid if m_type == Operation std::shared_ptr m_data; ///< Only valid if m_type != Operation - SourceLocation m_location; + langutil::SourceLocation m_location; JumpType m_jumpType = JumpType::Ordinary; /// Pushed value for operations with data to be determined during assembly stage, /// e.g. PushSubSize, PushTag, PushSub, etc. diff --git a/libevmasm/CommonSubexpressionEliminator.cpp b/libevmasm/CommonSubexpressionEliminator.cpp index 04926986..949d2c75 100644 --- a/libevmasm/CommonSubexpressionEliminator.cpp +++ b/libevmasm/CommonSubexpressionEliminator.cpp @@ -30,6 +30,7 @@ using namespace std; using namespace dev; using namespace dev::eth; +using namespace langutil; vector CommonSubexpressionEliminator::getOptimizedItems() { diff --git a/libevmasm/CommonSubexpressionEliminator.h b/libevmasm/CommonSubexpressionEliminator.h index b20de246..eba25db0 100644 --- a/libevmasm/CommonSubexpressionEliminator.h +++ b/libevmasm/CommonSubexpressionEliminator.h @@ -34,6 +34,11 @@ #include #include +namespace langutil +{ +struct SourceLocation; +} + namespace dev { namespace eth @@ -137,10 +142,10 @@ private: bool removeStackTopIfPossible(); /// Appends a dup instruction to m_generatedItems to retrieve the element at the given stack position. - void appendDup(int _fromPosition, SourceLocation const& _location); + void appendDup(int _fromPosition, langutil::SourceLocation const& _location); /// Appends a swap instruction to m_generatedItems to retrieve the element at the given stack position. /// @note this might also remove the last item if it exactly the same swap instruction. - void appendOrRemoveSwap(int _fromPosition, SourceLocation const& _location); + void appendOrRemoveSwap(int _fromPosition, langutil::SourceLocation const& _location); /// Appends the given assembly item. void appendItem(AssemblyItem const& _item); diff --git a/libevmasm/ControlFlowGraph.cpp b/libevmasm/ControlFlowGraph.cpp index 86f16d48..d62f5436 100644 --- a/libevmasm/ControlFlowGraph.cpp +++ b/libevmasm/ControlFlowGraph.cpp @@ -275,7 +275,7 @@ void ControlFlowGraph::gatherKnowledge() //@todo in the case of JUMPI, add knowledge about the condition to the state // (for both values of the condition) set tags = state->tagsInExpression( - state->stackElement(state->stackHeight(), SourceLocation()) + state->stackElement(state->stackHeight(), langutil::SourceLocation{}) ); state->feedItem(m_items.at(pc++)); diff --git a/libevmasm/ExpressionClasses.cpp b/libevmasm/ExpressionClasses.cpp index 42a1819a..abbbbc2c 100644 --- a/libevmasm/ExpressionClasses.cpp +++ b/libevmasm/ExpressionClasses.cpp @@ -34,7 +34,7 @@ using namespace std; using namespace dev; using namespace dev::eth; - +using namespace langutil; bool ExpressionClasses::Expression::operator<(ExpressionClasses::Expression const& _other) const { diff --git a/libevmasm/ExpressionClasses.h b/libevmasm/ExpressionClasses.h index df8082f9..a34844c5 100644 --- a/libevmasm/ExpressionClasses.h +++ b/libevmasm/ExpressionClasses.h @@ -31,6 +31,11 @@ #include #include +namespace langutil +{ +struct SourceLocation; +} + namespace dev { namespace eth @@ -82,7 +87,7 @@ public: void forceEqual(Id _id, AssemblyItem const& _item, Ids const& _arguments, bool _copyItem = true); /// @returns the id of a new class which is different to all other classes. - Id newClass(SourceLocation const& _location); + Id newClass(langutil::SourceLocation const& _location); /// @returns true if the values of the given classes are known to be different (on every input). /// @note that this function might still return false for some different inputs. diff --git a/libevmasm/KnownState.cpp b/libevmasm/KnownState.cpp index b6c1bcc9..a5546e61 100644 --- a/libevmasm/KnownState.cpp +++ b/libevmasm/KnownState.cpp @@ -29,6 +29,7 @@ using namespace std; using namespace dev; using namespace dev::eth; +using namespace langutil; ostream& KnownState::stream(ostream& _out) const { diff --git a/libevmasm/KnownState.h b/libevmasm/KnownState.h index cd50550e..3ab1c4b1 100644 --- a/libevmasm/KnownState.h +++ b/libevmasm/KnownState.h @@ -46,6 +46,11 @@ #include #include +namespace langutil +{ +struct SourceLocation; +} + namespace dev { namespace eth @@ -121,9 +126,9 @@ public: /// Retrieves the current equivalence class fo the given stack element (or generates a new /// one if it does not exist yet). - Id stackElement(int _stackHeight, SourceLocation const& _location); + Id stackElement(int _stackHeight, langutil::SourceLocation const& _location); /// @returns the stackElement relative to the current stack height. - Id relativeStackElement(int _stackOffset, SourceLocation const& _location = SourceLocation()); + Id relativeStackElement(int _stackOffset, langutil::SourceLocation const& _location = {}); /// @returns its set of tags if the given expression class is a known tag union; returns a set /// containing the tag if it is a PushTag expression and the empty set otherwise. @@ -142,22 +147,22 @@ private: /// Assigns a new equivalence class to the next sequence number of the given stack element. void setStackElement(int _stackHeight, Id _class); /// Swaps the given stack elements in their next sequence number. - void swapStackElements(int _stackHeightA, int _stackHeightB, SourceLocation const& _location); + void swapStackElements(int _stackHeightA, int _stackHeightB, langutil::SourceLocation const& _location); /// Increments the sequence number, deletes all storage information that might be overwritten /// and stores the new value at the given slot. /// @returns the store operation, which might be invalid if storage was not modified - StoreOperation storeInStorage(Id _slot, Id _value, SourceLocation const& _location); + StoreOperation storeInStorage(Id _slot, Id _value, langutil::SourceLocation const& _location); /// Retrieves the current value at the given slot in storage or creates a new special sload class. - Id loadFromStorage(Id _slot, SourceLocation const& _location); + Id loadFromStorage(Id _slot, langutil::SourceLocation const& _location); /// Increments the sequence number, deletes all memory information that might be overwritten /// and stores the new value at the given slot. /// @returns the store operation, which might be invalid if memory was not modified - StoreOperation storeInMemory(Id _slot, Id _value, SourceLocation const& _location); + StoreOperation storeInMemory(Id _slot, Id _value, langutil::SourceLocation const& _location); /// Retrieves the current value at the given slot in memory or creates a new special mload class. - Id loadFromMemory(Id _slot, SourceLocation const& _location); + Id loadFromMemory(Id _slot, langutil::SourceLocation const& _location); /// Finds or creates a new expression that applies the Keccak-256 hash function to the contents in memory. - Id applyKeccak256(Id _start, Id _length, SourceLocation const& _location); + Id applyKeccak256(Id _start, Id _length, langutil::SourceLocation const& _location); /// @returns a new or already used Id representing the given set of tags. Id tagUnion(std::set _tags); diff --git a/libevmasm/SimplificationRules.cpp b/libevmasm/SimplificationRules.cpp index 120d1787..1dce5f1e 100644 --- a/libevmasm/SimplificationRules.cpp +++ b/libevmasm/SimplificationRules.cpp @@ -38,7 +38,7 @@ using namespace std; using namespace dev; using namespace dev::eth; - +using namespace langutil; SimplificationRule const* Rules::findFirstMatch( Expression const& _expr, diff --git a/libevmasm/SimplificationRules.h b/libevmasm/SimplificationRules.h index fbe5a2b0..fc45a46c 100644 --- a/libevmasm/SimplificationRules.h +++ b/libevmasm/SimplificationRules.h @@ -31,6 +31,11 @@ #include #include +namespace langutil +{ +struct SourceLocation; +} + namespace dev { namespace eth @@ -97,7 +102,7 @@ public: unsigned matchGroup() const { return m_matchGroup; } bool matches(Expression const& _expr, ExpressionClasses const& _classes) const; - AssemblyItem toAssemblyItem(SourceLocation const& _location) const; + AssemblyItem toAssemblyItem(langutil::SourceLocation const& _location) const; std::vector arguments() const { return m_arguments; } /// @returns the id of the matched expression if this pattern is part of a match group. @@ -135,7 +140,7 @@ struct ExpressionTemplate { using Expression = ExpressionClasses::Expression; using Id = ExpressionClasses::Id; - explicit ExpressionTemplate(Pattern const& _pattern, SourceLocation const& _location); + explicit ExpressionTemplate(Pattern const& _pattern, langutil::SourceLocation const& _location); std::string toString() const; bool hasId = false; /// Id of the matched expression, if available. diff --git a/liblangutil/CharStream.cpp b/liblangutil/CharStream.cpp index 04490fa6..aee7cb3e 100644 --- a/liblangutil/CharStream.cpp +++ b/liblangutil/CharStream.cpp @@ -52,15 +52,9 @@ #include #include -#include -#include using namespace std; - -namespace dev -{ -namespace solidity -{ +using namespace langutil; char CharStream::advanceAndGet(size_t _chars) { @@ -111,5 +105,4 @@ tuple CharStream::translatePositionToLineColumn(int _position) const return tuple(lineNumber, searchPosition - lineStart); } -} -} + diff --git a/liblangutil/CharStream.h b/liblangutil/CharStream.h index 7c5488a0..72aacacf 100644 --- a/liblangutil/CharStream.h +++ b/liblangutil/CharStream.h @@ -56,9 +56,7 @@ #include #include -namespace dev -{ -namespace solidity +namespace langutil { /** @@ -97,4 +95,3 @@ private: }; } -} diff --git a/liblangutil/ErrorReporter.cpp b/liblangutil/ErrorReporter.cpp index 5edb0eeb..5b6e0072 100644 --- a/liblangutil/ErrorReporter.cpp +++ b/liblangutil/ErrorReporter.cpp @@ -21,12 +21,12 @@ */ #include -#include +#include #include using namespace std; using namespace dev; -using namespace dev::solidity; +using namespace langutil; ErrorReporter& ErrorReporter::operator=(ErrorReporter const& _errorReporter) { diff --git a/liblangutil/ErrorReporter.h b/liblangutil/ErrorReporter.h index 72cf16a4..d90e652e 100644 --- a/liblangutil/ErrorReporter.h +++ b/liblangutil/ErrorReporter.h @@ -25,12 +25,8 @@ #include #include -namespace dev +namespace langutil { -namespace solidity -{ - -class ASTNode; class ErrorReporter { @@ -120,7 +116,5 @@ private: const unsigned c_maxErrorsAllowed = 256; }; - -} } diff --git a/liblangutil/Exceptions.cpp b/liblangutil/Exceptions.cpp index 069619dd..346313d5 100644 --- a/liblangutil/Exceptions.cpp +++ b/liblangutil/Exceptions.cpp @@ -24,7 +24,7 @@ using namespace std; using namespace dev; -using namespace dev::solidity; +using namespace langutil; Error::Error(Type _type, SourceLocation const& _location, string const& _description): m_type(_type) diff --git a/liblangutil/Exceptions.h b/liblangutil/Exceptions.h index 69efd6dd..5ad31ab2 100644 --- a/liblangutil/Exceptions.h +++ b/liblangutil/Exceptions.h @@ -24,33 +24,33 @@ #include #include +#include +#include #include #include #include -namespace dev -{ -namespace solidity +namespace langutil { class Error; using ErrorList = std::vector>; -struct CompilerError: virtual Exception {}; -struct InternalCompilerError: virtual Exception {}; -struct FatalError: virtual Exception {}; -struct UnimplementedFeatureError: virtual Exception{}; +struct CompilerError: virtual dev::Exception {}; +struct InternalCompilerError: virtual dev::Exception {}; +struct FatalError: virtual dev::Exception {}; +struct UnimplementedFeatureError: virtual dev::Exception {}; /// Assertion that throws an InternalCompilerError containing the given description if it is not met. #define solAssert(CONDITION, DESCRIPTION) \ - assertThrow(CONDITION, ::dev::solidity::InternalCompilerError, DESCRIPTION) + assertThrow(CONDITION, ::langutil::InternalCompilerError, DESCRIPTION) #define solUnimplementedAssert(CONDITION, DESCRIPTION) \ - assertThrow(CONDITION, ::dev::solidity::UnimplementedFeatureError, DESCRIPTION) + assertThrow(CONDITION, ::langutil::UnimplementedFeatureError, DESCRIPTION) #define solUnimplemented(DESCRIPTION) \ solUnimplementedAssert(false, DESCRIPTION) -class Error: virtual public Exception +class Error: virtual public dev::Exception { public: enum class Type @@ -98,7 +98,6 @@ private: std::string m_typeName; }; - using errorSourceLocationInfo = std::pair; class SecondarySourceLocation @@ -109,6 +108,7 @@ public: infos.push_back(std::make_pair(_errMsg, _sourceLocation)); return *this; } + /// Limits the number of secondary source locations to 32 and appends a notice to the /// error message. void limitSize(std::string& _message) @@ -124,9 +124,8 @@ public: std::vector infos; }; - using errinfo_sourceLocation = boost::error_info; using errinfo_secondarySourceLocation = boost::error_info; -} + } diff --git a/liblangutil/ParserBase.cpp b/liblangutil/ParserBase.cpp index 197c2d65..8156f9b9 100644 --- a/liblangutil/ParserBase.cpp +++ b/liblangutil/ParserBase.cpp @@ -25,8 +25,7 @@ #include using namespace std; -using namespace dev; -using namespace dev::solidity; +using namespace langutil; std::shared_ptr const& ParserBase::sourceName() const { diff --git a/liblangutil/ParserBase.h b/liblangutil/ParserBase.h index 0cd94eee..3ecabed5 100644 --- a/liblangutil/ParserBase.h +++ b/liblangutil/ParserBase.h @@ -22,12 +22,11 @@ #pragma once -#include #include +#include +#include -namespace dev -{ -namespace solidity +namespace langutil { class ErrorReporter; @@ -90,4 +89,3 @@ protected: }; } -} diff --git a/liblangutil/Scanner.cpp b/liblangutil/Scanner.cpp index beb39a4f..3d7527d4 100644 --- a/liblangutil/Scanner.cpp +++ b/liblangutil/Scanner.cpp @@ -50,16 +50,14 @@ * Solidity scanner. */ -#include -#include #include #include +#include +#include using namespace std; -namespace dev -{ -namespace solidity +namespace langutil { namespace @@ -143,10 +141,10 @@ private: }; // end of LiteralScope class -void Scanner::reset(CharStream const& _source, string const& _sourceName) +void Scanner::reset(CharStream _source, string _sourceName) { - m_source = _source; - m_sourceName = make_shared(_sourceName); + m_source = std::move(_source); + m_sourceName = make_shared(std::move(_sourceName)); reset(); } @@ -866,5 +864,5 @@ tuple Scanner::scanIdentifierOrKeyword() return TokenTraits::fromIdentifierOrKeyword(m_nextToken.literal); } -} + } diff --git a/liblangutil/Scanner.h b/liblangutil/Scanner.h index 5e5ddfdd..da5e3dfb 100644 --- a/liblangutil/Scanner.h +++ b/liblangutil/Scanner.h @@ -52,15 +52,13 @@ #pragma once -#include -#include +#include #include #include -#include +#include +#include -namespace dev -{ -namespace solidity +namespace langutil { class AstRawString; @@ -71,13 +69,12 @@ class Scanner { friend class LiteralScope; public: - - explicit Scanner(CharStream const& _source = CharStream(), std::string const& _sourceName = "") { reset(_source, _sourceName); } + explicit Scanner(CharStream _source = CharStream(), std::string _sourceName = "") { reset(std::move(_source), std::move(_sourceName)); } std::string source() const { return m_source.source(); } /// Resets the scanner as if newly constructed with _source and _sourceName as input. - void reset(CharStream const& _source, std::string const& _sourceName); + void reset(CharStream _source, std::string _sourceName); /// Resets scanner to the start of input. void reset(); @@ -216,4 +213,3 @@ private: }; } -} diff --git a/liblangutil/SourceLocation.h b/liblangutil/SourceLocation.h index b42c3aa9..eeb81e94 100644 --- a/liblangutil/SourceLocation.h +++ b/liblangutil/SourceLocation.h @@ -22,13 +22,13 @@ #pragma once +#include // defines noexcept macro for MSVC #include #include #include #include -#include // defines noexcept macro for MSVC -namespace dev +namespace langutil { /** diff --git a/liblangutil/Token.cpp b/liblangutil/Token.cpp index 2e754733..cbfd4a8c 100644 --- a/liblangutil/Token.cpp +++ b/liblangutil/Token.cpp @@ -40,15 +40,13 @@ // You should have received a copy of the GNU General Public License // along with solidity. If not, see . -#include #include #include +#include using namespace std; -namespace dev -{ -namespace solidity +namespace langutil { void ElementaryTypeNameToken::assertDetails(Token _baseType, unsigned const& _first, unsigned const& _second) @@ -204,4 +202,3 @@ tuple fromIdentifierOrKeyword(string const& _ } } -} diff --git a/liblangutil/Token.h b/liblangutil/Token.h index 89dd4c01..0b7d9f71 100644 --- a/liblangutil/Token.h +++ b/liblangutil/Token.h @@ -45,11 +45,12 @@ #include #include #include + #include +#include +#include -namespace dev -{ -namespace solidity +namespace langutil { // TOKEN_LIST takes a list of 3 macros M, all of which satisfy the @@ -375,4 +376,3 @@ private: }; } -} diff --git a/libsolidity/analysis/ConstantEvaluator.h b/libsolidity/analysis/ConstantEvaluator.h index ac3a24a1..23ca3628 100644 --- a/libsolidity/analysis/ConstantEvaluator.h +++ b/libsolidity/analysis/ConstantEvaluator.h @@ -24,12 +24,16 @@ #include +namespace langutil +{ +class ErrorReporter; +} + namespace dev { namespace solidity { -class ErrorReporter; class TypeChecker; /** @@ -39,7 +43,7 @@ class ConstantEvaluator: private ASTConstVisitor { public: ConstantEvaluator( - ErrorReporter& _errorReporter, + langutil::ErrorReporter& _errorReporter, size_t _newDepth = 0, std::shared_ptr> _types = std::make_shared>() ): @@ -61,7 +65,7 @@ private: void setType(ASTNode const& _node, TypePointer const& _type); TypePointer type(ASTNode const& _node); - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; /// Current recursion depth. size_t m_depth = 0; std::shared_ptr> m_types; diff --git a/libsolidity/analysis/ControlFlowAnalyzer.cpp b/libsolidity/analysis/ControlFlowAnalyzer.cpp index 8a608552..fe58f0aa 100644 --- a/libsolidity/analysis/ControlFlowAnalyzer.cpp +++ b/libsolidity/analysis/ControlFlowAnalyzer.cpp @@ -16,8 +16,10 @@ */ #include +#include using namespace std; +using namespace langutil; using namespace dev::solidity; bool ControlFlowAnalyzer::analyze(ASTNode const& _astRoot) diff --git a/libsolidity/analysis/ControlFlowAnalyzer.h b/libsolidity/analysis/ControlFlowAnalyzer.h index aaaf1bff..411d57ff 100644 --- a/libsolidity/analysis/ControlFlowAnalyzer.h +++ b/libsolidity/analysis/ControlFlowAnalyzer.h @@ -29,7 +29,7 @@ namespace solidity class ControlFlowAnalyzer: private ASTConstVisitor { public: - explicit ControlFlowAnalyzer(CFG const& _cfg, ErrorReporter& _errorReporter): + explicit ControlFlowAnalyzer(CFG const& _cfg, langutil::ErrorReporter& _errorReporter): m_cfg(_cfg), m_errorReporter(_errorReporter) {} bool analyze(ASTNode const& _astRoot); @@ -45,7 +45,7 @@ private: ) const; CFG const& m_cfg; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; }; } diff --git a/libsolidity/analysis/ControlFlowGraph.cpp b/libsolidity/analysis/ControlFlowGraph.cpp index 9b3da0eb..b8860158 100644 --- a/libsolidity/analysis/ControlFlowGraph.cpp +++ b/libsolidity/analysis/ControlFlowGraph.cpp @@ -23,6 +23,7 @@ #include using namespace std; +using namespace langutil; using namespace dev::solidity; bool CFG::constructFlow(ASTNode const& _astRoot) @@ -133,4 +134,4 @@ void CFG::applyModifierFlowToFunctionFlow( _functionFlow->entry = copySrcToCopyDst[_modifierFlow.entry]; _functionFlow->exit = copySrcToCopyDst[_modifierFlow.exit]; -} \ No newline at end of file +} diff --git a/libsolidity/analysis/ControlFlowGraph.h b/libsolidity/analysis/ControlFlowGraph.h index 257ce07f..8fe9fe8e 100644 --- a/libsolidity/analysis/ControlFlowGraph.h +++ b/libsolidity/analysis/ControlFlowGraph.h @@ -101,7 +101,7 @@ struct ModifierFlow: FunctionFlow class CFG: private ASTConstVisitor { public: - explicit CFG(ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} + explicit CFG(langutil::ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} bool constructFlow(ASTNode const& _astRoot); @@ -133,7 +133,7 @@ private: FunctionFlow* _functionFlow ); - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; /// Node container. /// All nodes allocated during the construction of the control flow graph diff --git a/libsolidity/analysis/DocStringAnalyser.cpp b/libsolidity/analysis/DocStringAnalyser.cpp index f91d72f0..69a7a43c 100644 --- a/libsolidity/analysis/DocStringAnalyser.cpp +++ b/libsolidity/analysis/DocStringAnalyser.cpp @@ -28,6 +28,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; bool DocStringAnalyser::analyseDocStrings(SourceUnit const& _sourceUnit) diff --git a/libsolidity/analysis/DocStringAnalyser.h b/libsolidity/analysis/DocStringAnalyser.h index 82746207..f6b236db 100644 --- a/libsolidity/analysis/DocStringAnalyser.h +++ b/libsolidity/analysis/DocStringAnalyser.h @@ -25,13 +25,16 @@ #include +namespace langutil +{ +class ErrorReporter; +} + namespace dev { namespace solidity { -class ErrorReporter; - /** * Parses and analyses the doc strings. * Stores the parsing results in the AST annotations and reports errors. @@ -39,7 +42,7 @@ class ErrorReporter; class DocStringAnalyser: private ASTConstVisitor { public: - DocStringAnalyser(ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} + DocStringAnalyser(langutil::ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} bool analyseDocStrings(SourceUnit const& _sourceUnit); private: @@ -75,7 +78,7 @@ private: void appendError(std::string const& _description); bool m_errorOccured = false; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; }; } diff --git a/libsolidity/analysis/NameAndTypeResolver.cpp b/libsolidity/analysis/NameAndTypeResolver.cpp index a6c746ed..e40a2c97 100644 --- a/libsolidity/analysis/NameAndTypeResolver.cpp +++ b/libsolidity/analysis/NameAndTypeResolver.cpp @@ -30,6 +30,7 @@ #include using namespace std; +using namespace langutil; namespace dev { @@ -59,7 +60,7 @@ bool NameAndTypeResolver::registerDeclarations(SourceUnit& _sourceUnit, ASTNode { DeclarationRegistrationHelper registrar(m_scopes, _sourceUnit, m_errorReporter, _currentScope); } - catch (FatalError const&) + catch (langutil::FatalError const&) { if (m_errorReporter.errors().empty()) throw; // Something is weird here, rather throw again. @@ -129,7 +130,7 @@ bool NameAndTypeResolver::resolveNamesAndTypes(ASTNode& _node, bool _resolveInsi { return resolveNamesAndTypesInternal(_node, _resolveInsideCode); } - catch (FatalError const&) + catch (langutil::FatalError const&) { if (m_errorReporter.errors().empty()) throw; // Something is weird here, rather throw again. @@ -144,7 +145,7 @@ bool NameAndTypeResolver::updateDeclaration(Declaration const& _declaration) m_scopes[nullptr]->registerDeclaration(_declaration, nullptr, false, true); solAssert(_declaration.scope() == nullptr, "Updated declaration outside global scope."); } - catch (FatalError const&) + catch (langutil::FatalError const&) { if (m_errorReporter.errors().empty()) throw; // Something is weird here, rather throw again. diff --git a/libsolidity/analysis/NameAndTypeResolver.h b/libsolidity/analysis/NameAndTypeResolver.h index a72c21e3..1b034ef4 100644 --- a/libsolidity/analysis/NameAndTypeResolver.h +++ b/libsolidity/analysis/NameAndTypeResolver.h @@ -30,13 +30,16 @@ #include #include +namespace langutil +{ +class ErrorReporter; +} + namespace dev { namespace solidity { -class ErrorReporter; - /** * Resolves name references, typenames and sets the (explicitly given) types for all variable * declarations. @@ -50,7 +53,7 @@ public: NameAndTypeResolver( std::vector const& _globals, std::map>& _scopes, - ErrorReporter& _errorReporter + langutil::ErrorReporter& _errorReporter ); /// Registers all declarations found in the AST node, usually a source unit. /// @returns false in case of error. @@ -125,7 +128,7 @@ private: std::map>& m_scopes; DeclarationContainer* m_currentScope = nullptr; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; }; /** @@ -142,7 +145,7 @@ public: DeclarationRegistrationHelper( std::map>& _scopes, ASTNode& _astRoot, - ErrorReporter& _errorReporter, + langutil::ErrorReporter& _errorReporter, ASTNode const* _currentScope = nullptr ); @@ -150,10 +153,10 @@ public: DeclarationContainer& _container, Declaration const& _declaration, std::string const* _name, - SourceLocation const* _errorLocation, + langutil::SourceLocation const* _errorLocation, bool _warnOnShadow, bool _inactive, - ErrorReporter& _errorReporter + langutil::ErrorReporter& _errorReporter ); private: @@ -194,7 +197,7 @@ private: std::map>& m_scopes; ASTNode const* m_currentScope = nullptr; VariableScope* m_currentFunction = nullptr; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; }; } diff --git a/libsolidity/analysis/PostTypeChecker.cpp b/libsolidity/analysis/PostTypeChecker.cpp index 3f45df42..27cbcd45 100644 --- a/libsolidity/analysis/PostTypeChecker.cpp +++ b/libsolidity/analysis/PostTypeChecker.cpp @@ -29,6 +29,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; diff --git a/libsolidity/analysis/PostTypeChecker.h b/libsolidity/analysis/PostTypeChecker.h index 8382948a..e428b81a 100644 --- a/libsolidity/analysis/PostTypeChecker.h +++ b/libsolidity/analysis/PostTypeChecker.h @@ -23,13 +23,17 @@ #include #include +namespace langutil +{ +class ErrorReporter; +struct SourceLocation; +} + namespace dev { namespace solidity { -class ErrorReporter; - /** * This module performs analyses on the AST that are done after type checking and assignments of types: * - whether there are circular references in constant state variables @@ -39,13 +43,13 @@ class PostTypeChecker: private ASTConstVisitor { public: /// @param _errorReporter provides the error logging functionality. - PostTypeChecker(ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} + PostTypeChecker(langutil::ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} bool check(ASTNode const& _astRoot); private: /// Adds a new error to the list of errors. - void typeError(SourceLocation const& _location, std::string const& _description); + void typeError(langutil::SourceLocation const& _location, std::string const& _description); bool visit(ContractDefinition const& _contract) override; void endVisit(ContractDefinition const& _contract) override; @@ -57,7 +61,7 @@ private: VariableDeclaration const* findCycle(VariableDeclaration const& _startingFrom); - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; VariableDeclaration const* m_currentConstVariable = nullptr; std::vector m_constVariables; ///< Required for determinism. diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp index cae92203..7ac3ceff 100644 --- a/libsolidity/analysis/ReferencesResolver.cpp +++ b/libsolidity/analysis/ReferencesResolver.cpp @@ -36,9 +36,12 @@ #include using namespace std; -using namespace dev; -using namespace dev::solidity; +using namespace langutil; +namespace dev +{ +namespace solidity +{ bool ReferencesResolver::resolve(ASTNode const& _root) { @@ -454,3 +457,6 @@ void ReferencesResolver::fatalDeclarationError(SourceLocation const& _location, m_errorOccurred = true; m_errorReporter.fatalDeclarationError(_location, _description); } + +} +} diff --git a/libsolidity/analysis/ReferencesResolver.h b/libsolidity/analysis/ReferencesResolver.h index 34dbca96..32c0553f 100644 --- a/libsolidity/analysis/ReferencesResolver.h +++ b/libsolidity/analysis/ReferencesResolver.h @@ -28,12 +28,17 @@ #include #include +namespace langutil +{ +class ErrorReporter; +struct SourceLocation; +} + namespace dev { namespace solidity { -class ErrorReporter; class NameAndTypeResolver; /** @@ -44,7 +49,7 @@ class ReferencesResolver: private ASTConstVisitor { public: ReferencesResolver( - ErrorReporter& _errorReporter, + langutil::ErrorReporter& _errorReporter, NameAndTypeResolver& _resolver, bool _resolveInsideCode = false ): @@ -77,18 +82,18 @@ private: void endVisit(VariableDeclaration const& _variable) override; /// Adds a new error to the list of errors. - void typeError(SourceLocation const& _location, std::string const& _description); + void typeError(langutil::SourceLocation const& _location, std::string const& _description); /// Adds a new error to the list of errors and throws to abort reference resolving. - void fatalTypeError(SourceLocation const& _location, std::string const& _description); + void fatalTypeError(langutil::SourceLocation const& _location, std::string const& _description); /// Adds a new error to the list of errors. - void declarationError(SourceLocation const& _location, std::string const& _description); + void declarationError(langutil::SourceLocation const& _location, std::string const& _description); /// Adds a new error to the list of errors and throws to abort reference resolving. - void fatalDeclarationError(SourceLocation const& _location, std::string const& _description); + void fatalDeclarationError(langutil::SourceLocation const& _location, std::string const& _description); - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; NameAndTypeResolver& m_resolver; /// Stack of return parameters. std::vector m_returnParameters; diff --git a/libsolidity/analysis/SemVerHandler.h b/libsolidity/analysis/SemVerHandler.h index edf4fbd8..80185612 100644 --- a/libsolidity/analysis/SemVerHandler.h +++ b/libsolidity/analysis/SemVerHandler.h @@ -22,8 +22,9 @@ #pragma once +#include +#include #include -#include namespace dev { diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp index 353c1755..38391841 100644 --- a/libsolidity/analysis/StaticAnalyzer.cpp +++ b/libsolidity/analysis/StaticAnalyzer.cpp @@ -28,6 +28,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; bool StaticAnalyzer::analyze(SourceUnit const& _sourceUnit) diff --git a/libsolidity/analysis/StaticAnalyzer.h b/libsolidity/analysis/StaticAnalyzer.h index f5f3dbce..ff33fa3a 100644 --- a/libsolidity/analysis/StaticAnalyzer.h +++ b/libsolidity/analysis/StaticAnalyzer.h @@ -28,6 +28,11 @@ #include #include +namespace langutil +{ +class ErrorReporter; +} + namespace dev { namespace solidity @@ -44,7 +49,7 @@ class StaticAnalyzer: private ASTConstVisitor { public: /// @param _errorReporter provides the error logging functionality. - explicit StaticAnalyzer(ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} + explicit StaticAnalyzer(langutil::ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} /// Performs static analysis on the given source unit and all of its sub-nodes. /// @returns true iff all checks passed. Note even if all checks passed, errors() can still contain warnings @@ -70,7 +75,7 @@ private: /// @returns the size of this type in storage, including all sub-types. static bigint structureSizeEstimate(Type const& _type, std::set& _structsSeen); - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; /// Flag that indicates whether the current contract definition is a library. bool m_library = false; diff --git a/libsolidity/analysis/SyntaxChecker.cpp b/libsolidity/analysis/SyntaxChecker.cpp index 9ac0478e..a73d7e5c 100644 --- a/libsolidity/analysis/SyntaxChecker.cpp +++ b/libsolidity/analysis/SyntaxChecker.cpp @@ -29,6 +29,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; diff --git a/libsolidity/analysis/SyntaxChecker.h b/libsolidity/analysis/SyntaxChecker.h index 9e3c4652..c2463955 100644 --- a/libsolidity/analysis/SyntaxChecker.h +++ b/libsolidity/analysis/SyntaxChecker.h @@ -23,6 +23,11 @@ #include #include +namespace langutil +{ +class ErrorReporter; +} + namespace dev { namespace solidity @@ -39,7 +44,7 @@ class SyntaxChecker: private ASTConstVisitor { public: /// @param _errorReporter provides the error logging functionality. - SyntaxChecker(ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} + SyntaxChecker(langutil::ErrorReporter& _errorReporter): m_errorReporter(_errorReporter) {} bool checkSyntax(ASTNode const& _astRoot); @@ -81,7 +86,7 @@ private: bool visit(StructDefinition const& _struct) override; bool visit(Literal const& _literal) override; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; /// Flag that indicates whether a function modifier actually contains '_'. bool m_placeholderFound = false; diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 7531da65..69de9f12 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -35,6 +35,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; namespace diff --git a/libsolidity/analysis/TypeChecker.h b/libsolidity/analysis/TypeChecker.h index 392a923c..c98a4c7f 100644 --- a/libsolidity/analysis/TypeChecker.h +++ b/libsolidity/analysis/TypeChecker.h @@ -29,13 +29,16 @@ #include #include +namespace langutil +{ +class ErrorReporter; +} + namespace dev { namespace solidity { -class ErrorReporter; - /** * The module that performs type analysis on the AST, checks the applicability of operations on * those types and stores errors for invalid operations. @@ -45,7 +48,7 @@ class TypeChecker: private ASTConstVisitor { public: /// @param _errorReporter provides the error logging functionality. - TypeChecker(EVMVersion _evmVersion, ErrorReporter& _errorReporter): + TypeChecker(EVMVersion _evmVersion, langutil::ErrorReporter& _errorReporter): m_evmVersion(_evmVersion), m_errorReporter(_errorReporter) {} @@ -183,7 +186,7 @@ private: /// Flag indicating whether we are currently inside a StructDefinition. bool m_insideStruct = false; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; }; } diff --git a/libsolidity/analysis/ViewPureChecker.cpp b/libsolidity/analysis/ViewPureChecker.cpp index b0cacc43..3fb4c026 100644 --- a/libsolidity/analysis/ViewPureChecker.cpp +++ b/libsolidity/analysis/ViewPureChecker.cpp @@ -22,10 +22,13 @@ #include #include +#include + #include using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; namespace diff --git a/libsolidity/analysis/ViewPureChecker.h b/libsolidity/analysis/ViewPureChecker.h index 9615d04f..fd2432a7 100644 --- a/libsolidity/analysis/ViewPureChecker.h +++ b/libsolidity/analysis/ViewPureChecker.h @@ -21,11 +21,15 @@ #include #include -#include - #include #include +namespace langutil +{ +class ErrorReporter; +struct SourceLocation; +} + namespace dev { namespace solidity @@ -34,7 +38,7 @@ namespace solidity class ViewPureChecker: private ASTConstVisitor { public: - ViewPureChecker(std::vector> const& _ast, ErrorReporter& _errorReporter): + ViewPureChecker(std::vector> const& _ast, langutil::ErrorReporter& _errorReporter): m_ast(_ast), m_errorReporter(_errorReporter) {} bool check(); @@ -43,7 +47,7 @@ private: struct MutabilityAndLocation { StateMutability mutability; - SourceLocation location; + langutil::SourceLocation location; }; bool visit(FunctionDefinition const& _funDef) override; @@ -62,15 +66,15 @@ private: /// Creates appropriate warnings and errors and sets @a m_currentBestMutability. void reportMutability( StateMutability _mutability, - SourceLocation const& _location, - boost::optional const& _nestedLocation = {} + langutil::SourceLocation const& _location, + boost::optional const& _nestedLocation = {} ); std::vector> const& m_ast; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; bool m_errors = false; - MutabilityAndLocation m_bestMutabilityAndLocation = MutabilityAndLocation{StateMutability::Payable, SourceLocation()}; + MutabilityAndLocation m_bestMutabilityAndLocation = MutabilityAndLocation{StateMutability::Payable, langutil::SourceLocation()}; FunctionDefinition const* m_currentFunction = nullptr; std::map m_inferredMutability; }; diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index 2c44841e..d23562ad 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -23,8 +23,8 @@ #pragma once +#include #include -#include #include #include #include @@ -58,6 +58,8 @@ class ASTConstVisitor; class ASTNode: private boost::noncopyable { public: + using SourceLocation = langutil::SourceLocation; + explicit ASTNode(SourceLocation const& _location); virtual ~ASTNode(); diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp index 2d26ce8a..6b9f7227 100644 --- a/libsolidity/ast/ASTJsonConverter.cpp +++ b/libsolidity/ast/ASTJsonConverter.cpp @@ -27,6 +27,7 @@ #include using namespace std; +using namespace langutil; namespace dev { diff --git a/libsolidity/ast/ASTJsonConverter.h b/libsolidity/ast/ASTJsonConverter.h index da0d840a..dec3ac96 100644 --- a/libsolidity/ast/ASTJsonConverter.h +++ b/libsolidity/ast/ASTJsonConverter.h @@ -29,6 +29,11 @@ #include #include +namespace langutil +{ +struct SourceLocation; +} + namespace dev { namespace solidity @@ -120,7 +125,7 @@ private: std::string const& _nodeName, std::vector>&& _attributes ); - std::string sourceLocationToString(SourceLocation const& _location) const; + std::string sourceLocationToString(langutil::SourceLocation const& _location) const; static std::string namePathToString(std::vector const& _namePath); static Json::Value idOrNull(ASTNode const* _pt) { diff --git a/libsolidity/ast/ASTPrinter.cpp b/libsolidity/ast/ASTPrinter.cpp index 255cb9be..cdc6ae7d 100644 --- a/libsolidity/ast/ASTPrinter.cpp +++ b/libsolidity/ast/ASTPrinter.cpp @@ -28,6 +28,7 @@ #include using namespace std; +using namespace langutil; namespace dev { diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 4b31d2e8..0eab75aa 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -45,6 +45,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; namespace diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h index 79a656e9..482d6735 100644 --- a/libsolidity/ast/Types.h +++ b/libsolidity/ast/Types.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include diff --git a/libsolidity/codegen/ArrayUtils.cpp b/libsolidity/codegen/ArrayUtils.cpp index a4000d60..4878f9f3 100644 --- a/libsolidity/codegen/ArrayUtils.cpp +++ b/libsolidity/codegen/ArrayUtils.cpp @@ -30,6 +30,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace solidity; void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType const& _sourceType) const diff --git a/libsolidity/codegen/CompilerContext.cpp b/libsolidity/codegen/CompilerContext.cpp index fa6dfe60..9e4f2882 100644 --- a/libsolidity/codegen/CompilerContext.cpp +++ b/libsolidity/codegen/CompilerContext.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +48,7 @@ using namespace std; +using namespace langutil; namespace dev { @@ -359,7 +361,7 @@ void CompilerContext::appendInlineAssembly( ErrorList errors; ErrorReporter errorReporter(errors); - auto scanner = make_shared(CharStream(_assembly), "--CODEGEN--"); + auto scanner = make_shared(langutil::CharStream(_assembly), "--CODEGEN--"); auto parserResult = assembly::Parser(errorReporter, assembly::AsmFlavour::Strict).parse(scanner, false); #ifdef SOL_OUTPUT_ASM cout << assembly::AsmPrinter()(*parserResult) << endl; diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index a0d11017..93c8cc77 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -32,6 +32,7 @@ #include using namespace std; +using namespace langutil; namespace dev { diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp index c8d9d9d3..7a1dcd70 100644 --- a/libsolidity/codegen/ContractCompiler.cpp +++ b/libsolidity/codegen/ContractCompiler.cpp @@ -37,6 +37,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; namespace diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index bdf91fbf..57b513d2 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -36,6 +36,7 @@ #include using namespace std; +using namespace langutil; namespace dev { diff --git a/libsolidity/codegen/LValue.cpp b/libsolidity/codegen/LValue.cpp index 790ab309..6d71d36f 100644 --- a/libsolidity/codegen/LValue.cpp +++ b/libsolidity/codegen/LValue.cpp @@ -28,6 +28,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace solidity; diff --git a/libsolidity/codegen/LValue.h b/libsolidity/codegen/LValue.h index f39eaee1..d854857b 100644 --- a/libsolidity/codegen/LValue.h +++ b/libsolidity/codegen/LValue.h @@ -55,17 +55,17 @@ public: /// Copies the value of the current lvalue to the top of the stack and, if @a _remove is true, /// also removes the reference from the stack. /// @a _location source location of the current expression, used for error reporting. - virtual void retrieveValue(SourceLocation const& _location, bool _remove = false) const = 0; + virtual void retrieveValue(langutil::SourceLocation const& _location, bool _remove = false) const = 0; /// Moves a value from the stack to the lvalue. Removes the value if @a _move is true. /// @a _location is the source location of the expression that caused this operation. /// Stack pre: value [lvalue_ref] /// Stack post: if !_move: value_of(lvalue_ref) virtual void storeValue(Type const& _sourceType, - SourceLocation const& _location = SourceLocation(), bool _move = false) const = 0; + langutil::SourceLocation const& _location = {}, bool _move = false) const = 0; /// Stores zero in the lvalue. Removes the reference from the stack if @a _removeReference is true. /// @a _location is the source location of the requested operation virtual void setToZero( - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _removeReference = true ) const = 0; @@ -83,14 +83,14 @@ public: StackVariable(CompilerContext& _compilerContext, VariableDeclaration const& _declaration); unsigned sizeOnStack() const override { return 0; } - void retrieveValue(SourceLocation const& _location, bool _remove = false) const override; + void retrieveValue(langutil::SourceLocation const& _location, bool _remove = false) const override; virtual void storeValue( Type const& _sourceType, - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _move = false ) const override; virtual void setToZero( - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _removeReference = true ) const override; @@ -109,14 +109,14 @@ class MemoryItem: public LValue public: MemoryItem(CompilerContext& _compilerContext, Type const& _type, bool _padded = true); unsigned sizeOnStack() const override { return 1; } - void retrieveValue(SourceLocation const& _location, bool _remove = false) const override; + void retrieveValue(langutil::SourceLocation const& _location, bool _remove = false) const override; virtual void storeValue( Type const& _sourceType, - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _move = false ) const override; virtual void setToZero( - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _removeReference = true ) const override; private: @@ -137,14 +137,14 @@ public: /// Constructs the LValue and assumes that the storage reference is already on the stack. StorageItem(CompilerContext& _compilerContext, Type const& _type); unsigned sizeOnStack() const override { return 2; } - void retrieveValue(SourceLocation const& _location, bool _remove = false) const override; + void retrieveValue(langutil::SourceLocation const& _location, bool _remove = false) const override; virtual void storeValue( Type const& _sourceType, - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _move = false ) const override; virtual void setToZero( - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _removeReference = true ) const override; }; @@ -159,14 +159,14 @@ public: /// Constructs the LValue and assumes that the storage reference is already on the stack. StorageByteArrayElement(CompilerContext& _compilerContext); unsigned sizeOnStack() const override { return 2; } - void retrieveValue(SourceLocation const& _location, bool _remove = false) const override; + void retrieveValue(langutil::SourceLocation const& _location, bool _remove = false) const override; virtual void storeValue( Type const& _sourceType, - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _move = false ) const override; virtual void setToZero( - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _removeReference = true ) const override; }; @@ -181,14 +181,14 @@ class StorageArrayLength: public LValue public: /// Constructs the LValue, assumes that the reference to the array head is already on the stack. StorageArrayLength(CompilerContext& _compilerContext, ArrayType const& _arrayType); - void retrieveValue(SourceLocation const& _location, bool _remove = false) const override; + void retrieveValue(langutil::SourceLocation const& _location, bool _remove = false) const override; virtual void storeValue( Type const& _sourceType, - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _move = false ) const override; virtual void setToZero( - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _removeReference = true ) const override; @@ -206,14 +206,14 @@ public: /// Empty unique_ptrs are possible if e.g. some values should be ignored during assignment. TupleObject(CompilerContext& _compilerContext, std::vector>&& _lvalues); unsigned sizeOnStack() const override; - void retrieveValue(SourceLocation const& _location, bool _remove = false) const override; + void retrieveValue(langutil::SourceLocation const& _location, bool _remove = false) const override; virtual void storeValue( Type const& _sourceType, - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _move = false ) const override; virtual void setToZero( - SourceLocation const& _location = SourceLocation(), + langutil::SourceLocation const& _location = {}, bool _removeReference = true ) const override; diff --git a/libsolidity/formal/SMTChecker.cpp b/libsolidity/formal/SMTChecker.cpp index a8595190..7e75df87 100644 --- a/libsolidity/formal/SMTChecker.cpp +++ b/libsolidity/formal/SMTChecker.cpp @@ -29,6 +29,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; SMTChecker::SMTChecker(ErrorReporter& _errorReporter, ReadCallback::Callback const& _readFileCallback): diff --git a/libsolidity/formal/SMTChecker.h b/libsolidity/formal/SMTChecker.h index ae9f32e9..d7f86cbc 100644 --- a/libsolidity/formal/SMTChecker.h +++ b/libsolidity/formal/SMTChecker.h @@ -31,20 +31,25 @@ #include #include +namespace langutil +{ +class ErrorReporter; +struct SourceLocation; +} + namespace dev { namespace solidity { class VariableUsage; -class ErrorReporter; class SMTChecker: private ASTConstVisitor { public: - SMTChecker(ErrorReporter& _errorReporter, ReadCallback::Callback const& _readCallback); + SMTChecker(langutil::ErrorReporter& _errorReporter, ReadCallback::Callback const& _readCallback); - void analyze(SourceUnit const& _sources, std::shared_ptr const& _scanner); + void analyze(SourceUnit const& _sources, std::shared_ptr const& _scanner); private: // TODO: Check that we do not have concurrent reads and writes to a variable, @@ -89,8 +94,8 @@ private: /// of rounding for signed division. smt::Expression division(smt::Expression _left, smt::Expression _right, IntegerType const& _type); - void assignment(VariableDeclaration const& _variable, Expression const& _value, SourceLocation const& _location); - void assignment(VariableDeclaration const& _variable, smt::Expression const& _value, SourceLocation const& _location); + void assignment(VariableDeclaration const& _variable, Expression const& _value, langutil::SourceLocation const& _location); + void assignment(VariableDeclaration const& _variable, smt::Expression const& _value, langutil::SourceLocation const& _location); /// Maps a variable to an SSA index. using VariableIndices = std::unordered_map; @@ -104,7 +109,7 @@ private: /// Check that a condition can be satisfied. void checkCondition( smt::Expression _condition, - SourceLocation const& _location, + langutil::SourceLocation const& _location, std::string const& _description, std::string const& _additionalValueName = "", smt::Expression* _additionalValue = nullptr @@ -117,7 +122,7 @@ private: std::string const& _description ); /// Checks that the value is in the range given by the type. - void checkUnderOverflow(smt::Expression _value, IntegerType const& _Type, SourceLocation const& _location); + void checkUnderOverflow(smt::Expression _value, IntegerType const& _Type, langutil::SourceLocation const& _location); std::pair> @@ -200,8 +205,8 @@ private: /// Used to retrieve models. std::vector m_uninterpretedTerms; std::vector m_pathConditions; - ErrorReporter& m_errorReporter; - std::shared_ptr m_scanner; + langutil::ErrorReporter& m_errorReporter; + std::shared_ptr m_scanner; /// Stores the current path of function calls. std::vector m_functionPath; diff --git a/libsolidity/inlineasm/AsmAnalysis.cpp b/libsolidity/inlineasm/AsmAnalysis.cpp index 95c8537d..fb96f73c 100644 --- a/libsolidity/inlineasm/AsmAnalysis.cpp +++ b/libsolidity/inlineasm/AsmAnalysis.cpp @@ -35,6 +35,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; using namespace dev::solidity::assembly; diff --git a/libsolidity/inlineasm/AsmAnalysis.h b/libsolidity/inlineasm/AsmAnalysis.h index 7ae27ebd..194f736e 100644 --- a/libsolidity/inlineasm/AsmAnalysis.h +++ b/libsolidity/inlineasm/AsmAnalysis.h @@ -35,11 +35,16 @@ #include #include +namespace langutil +{ +class ErrorReporter; +struct SourceLocation; +} + namespace dev { namespace solidity { -class ErrorReporter; namespace assembly { @@ -55,9 +60,9 @@ class AsmAnalyzer: public boost::static_visitor public: explicit AsmAnalyzer( AsmAnalysisInfo& _analysisInfo, - ErrorReporter& _errorReporter, + langutil::ErrorReporter& _errorReporter, EVMVersion _evmVersion, - boost::optional _errorTypeForLoose, + boost::optional _errorTypeForLoose, AsmFlavour _flavour = AsmFlavour::Loose, yul::ExternalIdentifierAccess::Resolver const& _resolver = yul::ExternalIdentifierAccess::Resolver() ): @@ -90,20 +95,20 @@ public: private: /// Visits the statement and expects it to deposit one item onto the stack. bool expectExpression(Expression const& _expr); - bool expectDeposit(int _deposit, int _oldHeight, SourceLocation const& _location); + bool expectDeposit(int _deposit, int _oldHeight, langutil::SourceLocation const& _location); /// Verifies that a variable to be assigned to exists and has the same size /// as the value, @a _valueSize, unless that is equal to -1. bool checkAssignment(assembly::Identifier const& _assignment, size_t _valueSize = size_t(-1)); Scope& scope(assembly::Block const* _block); - void expectValidType(std::string const& type, SourceLocation const& _location); - void warnOnInstructions(solidity::Instruction _instr, SourceLocation const& _location); + void expectValidType(std::string const& type, langutil::SourceLocation const& _location); + void warnOnInstructions(solidity::Instruction _instr, langutil::SourceLocation const& _location); /// Depending on @a m_flavour and @a m_errorTypeForLoose, throws an internal compiler /// exception (if the flavour is not Loose), reports an error/warning /// (if m_errorTypeForLoose is set) or does nothing. - void checkLooseFeature(SourceLocation const& _location, std::string const& _description); + void checkLooseFeature(langutil::SourceLocation const& _location, std::string const& _description); int m_stackHeight = 0; yul::ExternalIdentifierAccess::Resolver m_resolver; @@ -112,10 +117,10 @@ private: /// "part of the scope but not yet declared") std::set m_activeVariables; AsmAnalysisInfo& m_info; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; EVMVersion m_evmVersion; AsmFlavour m_flavour = AsmFlavour::Loose; - boost::optional m_errorTypeForLoose; + boost::optional m_errorTypeForLoose; }; } diff --git a/libsolidity/inlineasm/AsmCodeGen.cpp b/libsolidity/inlineasm/AsmCodeGen.cpp index ee69b44f..2800cc7b 100644 --- a/libsolidity/inlineasm/AsmCodeGen.cpp +++ b/libsolidity/inlineasm/AsmCodeGen.cpp @@ -46,6 +46,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; using namespace dev::solidity::assembly; diff --git a/libsolidity/inlineasm/AsmData.h b/libsolidity/inlineasm/AsmData.h index e9bf4841..23a9db75 100644 --- a/libsolidity/inlineasm/AsmData.h +++ b/libsolidity/inlineasm/AsmData.h @@ -45,56 +45,56 @@ namespace assembly using YulString = dev::yul::YulString; using Type = YulString; -struct TypedName { SourceLocation location; YulString name; Type type; }; +struct TypedName { langutil::SourceLocation location; YulString name; Type type; }; using TypedNameList = std::vector; /// Direct EVM instruction (except PUSHi and JUMPDEST) -struct Instruction { SourceLocation location; solidity::Instruction instruction; }; +struct Instruction { langutil::SourceLocation location; solidity::Instruction instruction; }; /// Literal number or string (up to 32 bytes) enum class LiteralKind { Number, Boolean, String }; -struct Literal { SourceLocation location; LiteralKind kind; YulString value; Type type; }; +struct Literal { langutil::SourceLocation location; LiteralKind kind; YulString value; Type type; }; /// External / internal identifier or label reference -struct Identifier { SourceLocation location; YulString name; }; +struct Identifier { langutil::SourceLocation location; YulString name; }; /// Jump label ("name:") -struct Label { SourceLocation location; YulString name; }; +struct Label { langutil::SourceLocation location; YulString name; }; /// Assignment from stack (":= x", moves stack top into x, potentially multiple slots) -struct StackAssignment { SourceLocation location; Identifier variableName; }; +struct StackAssignment { langutil::SourceLocation location; Identifier variableName; }; /// Assignment ("x := mload(20:u256)", expects push-1-expression on the right hand /// side and requires x to occupy exactly one stack slot. /// /// Multiple assignment ("x, y := f()"), where the left hand side variables each occupy /// a single stack slot and expects a single expression on the right hand returning /// the same amount of items as the number of variables. -struct Assignment { SourceLocation location; std::vector variableNames; std::shared_ptr value; }; +struct Assignment { langutil::SourceLocation location; std::vector variableNames; std::shared_ptr value; }; /// Functional instruction, e.g. "mul(mload(20:u256), add(2:u256, x))" -struct FunctionalInstruction { SourceLocation location; solidity::Instruction instruction; std::vector arguments; }; -struct FunctionCall { SourceLocation location; Identifier functionName; std::vector arguments; }; +struct FunctionalInstruction { langutil::SourceLocation location; solidity::Instruction instruction; std::vector arguments; }; +struct FunctionCall { langutil::SourceLocation location; Identifier functionName; std::vector arguments; }; /// Statement that contains only a single expression -struct ExpressionStatement { SourceLocation location; Expression expression; }; +struct ExpressionStatement { langutil::SourceLocation location; Expression expression; }; /// Block-scope variable declaration ("let x:u256 := mload(20:u256)"), non-hoisted -struct VariableDeclaration { SourceLocation location; TypedNameList variables; std::shared_ptr value; }; +struct VariableDeclaration { langutil::SourceLocation location; TypedNameList variables; std::shared_ptr value; }; /// Block that creates a scope (frees declared stack variables) -struct Block { SourceLocation location; std::vector statements; }; +struct Block { langutil::SourceLocation location; std::vector statements; }; /// Function definition ("function f(a, b) -> (d, e) { ... }") -struct FunctionDefinition { SourceLocation location; YulString name; TypedNameList parameters; TypedNameList returnVariables; Block body; }; +struct FunctionDefinition { langutil::SourceLocation location; YulString name; TypedNameList parameters; TypedNameList returnVariables; Block body; }; /// Conditional execution without "else" part. -struct If { SourceLocation location; std::shared_ptr condition; Block body; }; +struct If { langutil::SourceLocation location; std::shared_ptr condition; Block body; }; /// Switch case or default case -struct Case { SourceLocation location; std::shared_ptr value; Block body; }; +struct Case { langutil::SourceLocation location; std::shared_ptr value; Block body; }; /// Switch statement -struct Switch { SourceLocation location; std::shared_ptr expression; std::vector cases; }; -struct ForLoop { SourceLocation location; Block pre; std::shared_ptr condition; Block post; Block body; }; +struct Switch { langutil::SourceLocation location; std::shared_ptr expression; std::vector cases; }; +struct ForLoop { langutil::SourceLocation location; Block pre; std::shared_ptr condition; Block post; Block body; }; -struct LocationExtractor: boost::static_visitor +struct LocationExtractor: boost::static_visitor { - template SourceLocation operator()(T const& _node) const + template langutil::SourceLocation operator()(T const& _node) const { return _node.location; } }; /// Extracts the source location from an inline assembly node. -template inline SourceLocation locationOf(T const& _node) +template inline langutil::SourceLocation locationOf(T const& _node) { return boost::apply_visitor(LocationExtractor(), _node); } diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp index 3103e2b3..b11f70e0 100644 --- a/libsolidity/inlineasm/AsmParser.cpp +++ b/libsolidity/inlineasm/AsmParser.cpp @@ -31,6 +31,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; using namespace dev::solidity::assembly; diff --git a/libsolidity/inlineasm/AsmParser.h b/libsolidity/inlineasm/AsmParser.h index b3d74df1..9e13799a 100644 --- a/libsolidity/inlineasm/AsmParser.h +++ b/libsolidity/inlineasm/AsmParser.h @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include namespace dev @@ -34,22 +36,22 @@ namespace solidity namespace assembly { -class Parser: public ParserBase +class Parser: public langutil::ParserBase { public: - explicit Parser(ErrorReporter& _errorReporter, AsmFlavour _flavour = AsmFlavour::Loose): + explicit Parser(langutil::ErrorReporter& _errorReporter, AsmFlavour _flavour = AsmFlavour::Loose): ParserBase(_errorReporter), m_flavour(_flavour) {} /// Parses an inline assembly block starting with `{` and ending with `}`. /// @param _reuseScanner if true, do check for end of input after the `}`. /// @returns an empty shared pointer on error. - std::shared_ptr parse(std::shared_ptr const& _scanner, bool _reuseScanner); + std::shared_ptr parse(std::shared_ptr const& _scanner, bool _reuseScanner); protected: using ElementaryOperation = boost::variant; /// Creates an inline assembly node with the given source location. - template T createWithLocation(SourceLocation const& _loc = SourceLocation()) const + template T createWithLocation(langutil::SourceLocation const& _loc = {}) const { T r; r.location = _loc; @@ -62,7 +64,7 @@ protected: r.location.sourceName = sourceName(); return r; } - SourceLocation location() const { return SourceLocation(position(), endPosition(), sourceName()); } + langutil::SourceLocation location() const { return {position(), endPosition(), sourceName()}; } Block parseBlock(); Statement parseStatement(); diff --git a/libsolidity/inlineasm/AsmScopeFiller.cpp b/libsolidity/inlineasm/AsmScopeFiller.cpp index c7625fe0..09934bd8 100644 --- a/libsolidity/inlineasm/AsmScopeFiller.cpp +++ b/libsolidity/inlineasm/AsmScopeFiller.cpp @@ -36,6 +36,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; using namespace dev::solidity::assembly; diff --git a/libsolidity/inlineasm/AsmScopeFiller.h b/libsolidity/inlineasm/AsmScopeFiller.h index bb023f61..7454fd6c 100644 --- a/libsolidity/inlineasm/AsmScopeFiller.h +++ b/libsolidity/inlineasm/AsmScopeFiller.h @@ -27,12 +27,16 @@ #include #include -namespace dev +namespace langutil { +class ErrorReporter; struct SourceLocation; +} + +namespace dev +{ namespace solidity { -class ErrorReporter; namespace assembly { @@ -47,7 +51,7 @@ struct AsmAnalysisInfo; class ScopeFiller: public boost::static_visitor { public: - ScopeFiller(AsmAnalysisInfo& _info, ErrorReporter& _errorReporter); + ScopeFiller(AsmAnalysisInfo& _info, langutil::ErrorReporter& _errorReporter); bool operator()(assembly::Instruction const&) { return true; } bool operator()(assembly::Literal const&) { return true; } @@ -68,7 +72,7 @@ public: private: bool registerVariable( TypedName const& _name, - SourceLocation const& _location, + langutil::SourceLocation const& _location, Scope& _scope ); @@ -76,7 +80,7 @@ private: Scope* m_currentScope = nullptr; AsmAnalysisInfo& m_info; - ErrorReporter& m_errorReporter; + langutil::ErrorReporter& m_errorReporter; }; } diff --git a/libsolidity/interface/AssemblyStack.cpp b/libsolidity/interface/AssemblyStack.cpp index 26879e8b..5b6b1113 100644 --- a/libsolidity/interface/AssemblyStack.cpp +++ b/libsolidity/interface/AssemblyStack.cpp @@ -36,6 +36,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; namespace diff --git a/libsolidity/interface/AssemblyStack.h b/libsolidity/interface/AssemblyStack.h index aad65ffc..d6ee33cf 100644 --- a/libsolidity/interface/AssemblyStack.h +++ b/libsolidity/interface/AssemblyStack.h @@ -29,11 +29,15 @@ #include #include +namespace langutil +{ +class Scanner; +} + namespace dev { namespace solidity { -class Scanner; namespace assembly { struct AsmAnalysisInfo; @@ -61,7 +65,7 @@ public: {} /// @returns the scanner used during parsing - Scanner const& scanner() const; + langutil::Scanner const& scanner() const; /// Runs parsing and analysis steps, returns false if input cannot be assembled. /// Multiple calls overwrite the previous state. @@ -69,13 +73,13 @@ public: /// Runs analysis step on the supplied block, returns false if input cannot be assembled. /// Multiple calls overwrite the previous state. - bool analyze(assembly::Block const& _block, Scanner const* _scanner = nullptr); + bool analyze(assembly::Block const& _block, langutil::Scanner const* _scanner = nullptr); /// Run the assembly step (should only be called after parseAndAnalyze). MachineAssemblyObject assemble(Machine _machine) const; /// @returns the errors generated during parsing, analysis (and potentially assembly). - ErrorList const& errors() const { return m_errors; } + langutil::ErrorList const& errors() const { return m_errors; } /// Pretty-print the input after having parsed it. std::string print() const; @@ -86,13 +90,13 @@ private: Language m_language = Language::Assembly; EVMVersion m_evmVersion; - std::shared_ptr m_scanner; + std::shared_ptr m_scanner; bool m_analysisSuccessful = false; std::shared_ptr m_parserResult; std::shared_ptr m_analysisInfo; - ErrorList m_errors; - ErrorReporter m_errorReporter; + langutil::ErrorList m_errors; + langutil::ErrorReporter m_errorReporter; }; } diff --git a/libsolidity/interface/CompilerStack.cpp b/libsolidity/interface/CompilerStack.cpp index 08a248dd..a5674705 100644 --- a/libsolidity/interface/CompilerStack.cpp +++ b/libsolidity/interface/CompilerStack.cpp @@ -58,6 +58,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; boost::optional CompilerStack::parseRemapping(string const& _remapping) diff --git a/libsolidity/interface/CompilerStack.h b/libsolidity/interface/CompilerStack.h index a7e312ad..8c50266e 100644 --- a/libsolidity/interface/CompilerStack.h +++ b/libsolidity/interface/CompilerStack.h @@ -23,11 +23,12 @@ #pragma once -#include #include -#include +#include +#include #include + #include #include @@ -43,6 +44,11 @@ #include #include +namespace langutil +{ +class Scanner; +} + namespace dev { @@ -57,7 +63,6 @@ namespace solidity { // forward declarations -class Scanner; class ASTNode; class ContractDefinition; class FunctionDefinition; @@ -65,7 +70,6 @@ class SourceUnit; class Compiler; class GlobalContext; class Natspec; -class Error; class DeclarationContainer; /** @@ -100,7 +104,7 @@ public: m_errorReporter(m_errorList) {} /// @returns the list of errors that occurred during parsing and type checking. - ErrorList const& errors() const { return m_errorReporter.errors(); } + langutil::ErrorList const& errors() const { return m_errorReporter.errors(); } /// @returns the current state. State state() const { return m_stackState; } @@ -174,7 +178,7 @@ public: std::map sourceIndices() const; /// @returns the previously used scanner, useful for counting lines during error reporting. - Scanner const& scanner(std::string const& _sourceName) const; + langutil::Scanner const& scanner(std::string const& _sourceName) const; /// @returns the parsed source unit with the supplied name. SourceUnit const& ast(std::string const& _sourceName) const; @@ -182,7 +186,7 @@ public: /// Helper function for logs printing. Do only use in error cases, it's quite expensive. /// line and columns are numbered starting from 1 with following order: /// start line, start column, end line, end column - std::tuple positionFromSourceLocation(SourceLocation const& _sourceLocation) const; + std::tuple positionFromSourceLocation(langutil::SourceLocation const& _sourceLocation) const; /// @returns a list of the contract names in the sources. std::vector contractNames() const; @@ -248,7 +252,7 @@ private: /// The state per source unit. Filled gradually during parsing. struct Source { - std::shared_ptr scanner; + std::shared_ptr scanner; std::shared_ptr ast; bool isLibrary = false; void reset() { scanner.reset(); ast.reset(); } @@ -345,8 +349,8 @@ private: /// This is updated during compilation. std::map> m_scopes; std::map m_contracts; - ErrorList m_errorList; - ErrorReporter m_errorReporter; + langutil::ErrorList m_errorList; + langutil::ErrorReporter m_errorReporter; bool m_metadataLiteralSources = false; State m_stackState = Empty; }; diff --git a/libsolidity/interface/GasEstimator.cpp b/libsolidity/interface/GasEstimator.cpp index 1f20366e..de6b2ce5 100644 --- a/libsolidity/interface/GasEstimator.cpp +++ b/libsolidity/interface/GasEstimator.cpp @@ -35,6 +35,7 @@ using namespace std; using namespace dev; using namespace dev::eth; +using namespace langutil; using namespace dev::solidity; GasEstimator::ASTGasConsumptionSelfAccumulated GasEstimator::structuralEstimation( diff --git a/libsolidity/interface/SourceReferenceFormatter.cpp b/libsolidity/interface/SourceReferenceFormatter.cpp index 9e2c988e..d727afbe 100644 --- a/libsolidity/interface/SourceReferenceFormatter.cpp +++ b/libsolidity/interface/SourceReferenceFormatter.cpp @@ -25,6 +25,7 @@ #include using namespace std; +using namespace langutil; namespace dev { diff --git a/libsolidity/interface/SourceReferenceFormatter.h b/libsolidity/interface/SourceReferenceFormatter.h index 281a4bdc..7dea5254 100644 --- a/libsolidity/interface/SourceReferenceFormatter.h +++ b/libsolidity/interface/SourceReferenceFormatter.h @@ -25,7 +25,12 @@ #include #include #include -#include + +namespace langutil +{ +struct SourceLocation; +class Scanner; +} namespace dev { @@ -35,13 +40,12 @@ struct Exception; // forward namespace solidity { -class Scanner; // forward class CompilerStack; // forward class SourceReferenceFormatter { public: - using ScannerFromSourceNameFun = std::function; + using ScannerFromSourceNameFun = std::function; explicit SourceReferenceFormatter( std::ostream& _stream, @@ -52,7 +56,7 @@ public: {} /// Prints source location if it is given. - void printSourceLocation(SourceLocation const* _location); + void printSourceLocation(langutil::SourceLocation const* _location); void printExceptionInformation(Exception const& _exception, std::string const& _name); static std::string formatExceptionInformation( @@ -69,7 +73,7 @@ public: } private: /// Prints source name if location is given. - void printSourceName(SourceLocation const* _location); + void printSourceName(langutil::SourceLocation const* _location); std::ostream& m_stream; ScannerFromSourceNameFun m_scannerFromSourceName; diff --git a/libsolidity/interface/StandardCompiler.cpp b/libsolidity/interface/StandardCompiler.cpp index c8b03a94..291a1071 100644 --- a/libsolidity/interface/StandardCompiler.cpp +++ b/libsolidity/interface/StandardCompiler.cpp @@ -31,6 +31,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; namespace { @@ -411,7 +412,7 @@ Json::Value StandardCompiler::compileInternal(Json::Value const& _input) Json::Value outputSelection = settings.get("outputSelection", Json::Value()); m_compilerStack.setRequestedContractNames(requestedContractNames(outputSelection)); - auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return m_compilerStack.scanner(_sourceName); }; + auto scannerFromSourceName = [&](string const& _sourceName) -> Scanner const& { return m_compilerStack.scanner(_sourceName); }; try { diff --git a/libsolidity/parsing/DocStringParser.cpp b/libsolidity/parsing/DocStringParser.cpp index 17a7b691..d8927fea 100644 --- a/libsolidity/parsing/DocStringParser.cpp +++ b/libsolidity/parsing/DocStringParser.cpp @@ -8,6 +8,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; diff --git a/libsolidity/parsing/DocStringParser.h b/libsolidity/parsing/DocStringParser.h index 5f2819cc..c83b416d 100644 --- a/libsolidity/parsing/DocStringParser.h +++ b/libsolidity/parsing/DocStringParser.h @@ -25,19 +25,22 @@ #include #include +namespace langutil +{ +class ErrorReporter; +} + namespace dev { namespace solidity { -class ErrorReporter; - class DocStringParser { public: /// Parse the given @a _docString and stores the parsed components internally. /// @returns false on error and appends the error to @a _errors. - bool parse(std::string const& _docString, ErrorReporter& _errorReporter); + bool parse(std::string const& _docString, langutil::ErrorReporter& _errorReporter); std::multimap const& tags() const { return m_docTags; } @@ -63,7 +66,7 @@ private: /// Mapping tag name -> content. std::multimap m_docTags; DocTag* m_lastTag = nullptr; - ErrorReporter* m_errorReporter = nullptr; + langutil::ErrorReporter* m_errorReporter = nullptr; bool m_errorsOccurred = false; }; diff --git a/libsolidity/parsing/Parser.cpp b/libsolidity/parsing/Parser.cpp index f070620d..de5293b4 100644 --- a/libsolidity/parsing/Parser.cpp +++ b/libsolidity/parsing/Parser.cpp @@ -29,6 +29,7 @@ #include using namespace std; +using namespace langutil; namespace dev { diff --git a/libsolidity/parsing/Parser.h b/libsolidity/parsing/Parser.h index f20f01c5..15852096 100644 --- a/libsolidity/parsing/Parser.h +++ b/libsolidity/parsing/Parser.h @@ -25,19 +25,22 @@ #include #include +namespace langutil +{ +class Scanner; +} + namespace dev { namespace solidity { -class Scanner; - -class Parser: public ParserBase +class Parser: public langutil::ParserBase { public: - explicit Parser(ErrorReporter& _errorReporter): ParserBase(_errorReporter) {} + explicit Parser(langutil::ErrorReporter& _errorReporter): ParserBase(_errorReporter) {} - ASTPointer parse(std::shared_ptr const& _scanner); + ASTPointer parse(std::shared_ptr const& _scanner); private: class ASTNodeFactory; @@ -146,7 +149,7 @@ private: struct IndexAccessedPath { std::vector> path; - std::vector, SourceLocation>> indices; + std::vector, langutil::SourceLocation>> indices; bool empty() const; }; diff --git a/libsolidity/parsing/Token.h b/libsolidity/parsing/Token.h new file mode 100644 index 00000000..d61aefb6 --- /dev/null +++ b/libsolidity/parsing/Token.h @@ -0,0 +1,36 @@ +/* + This file is part of solidity. + + solidity is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + solidity is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with solidity. If not, see . +*/ +/** + * Solidity and Yul both share the same Token (and Scanner) API. + * + * This may (or may not) change in the future. But for the time being, we've put both + * at a shared place, and *just* import them. +*/ +#pragma once + +#include + +namespace dev +{ +namespace solidity +{ +namespace TokenTraits = ::langutil::TokenTraits; + +using ::langutil::Token; +using ::langutil::ElementaryTypeNameToken; +} +} diff --git a/libyul/backends/evm/AbstractAssembly.h b/libyul/backends/evm/AbstractAssembly.h index d75058f7..5a1140cb 100644 --- a/libyul/backends/evm/AbstractAssembly.h +++ b/libyul/backends/evm/AbstractAssembly.h @@ -26,9 +26,13 @@ #include -namespace dev +namespace langutil { struct SourceLocation; +} + +namespace dev +{ namespace solidity { enum class Instruction: uint8_t; @@ -52,7 +56,7 @@ public: virtual ~AbstractAssembly() {} /// Set a new source location valid starting from the next instruction. - virtual void setSourceLocation(SourceLocation const& _location) = 0; + virtual void setSourceLocation(langutil::SourceLocation const& _location) = 0; /// Retrieve the current height of the stack. This does not have to be zero /// at the beginning. virtual int stackHeight() const = 0; diff --git a/libyul/backends/evm/EVMAssembly.cpp b/libyul/backends/evm/EVMAssembly.cpp index e4ba37f0..791b6226 100644 --- a/libyul/backends/evm/EVMAssembly.cpp +++ b/libyul/backends/evm/EVMAssembly.cpp @@ -26,6 +26,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::yul; namespace diff --git a/libyul/backends/evm/EVMAssembly.h b/libyul/backends/evm/EVMAssembly.h index 8f92b6e7..c9190634 100644 --- a/libyul/backends/evm/EVMAssembly.h +++ b/libyul/backends/evm/EVMAssembly.h @@ -26,6 +26,11 @@ #include +namespace langutil +{ +struct SourceLocation; +} + namespace dev { namespace yul @@ -38,7 +43,7 @@ public: virtual ~EVMAssembly() {} /// Set a new source location valid starting from the next instruction. - void setSourceLocation(SourceLocation const& _location) override; + void setSourceLocation(langutil::SourceLocation const& _location) override; /// Retrieve the current height of the stack. This does not have to be zero /// at the beginning. int stackHeight() const override { return m_stackHeight; } diff --git a/libyul/optimiser/ExpressionSplitter.cpp b/libyul/optimiser/ExpressionSplitter.cpp index a4b7a909..42730864 100644 --- a/libyul/optimiser/ExpressionSplitter.cpp +++ b/libyul/optimiser/ExpressionSplitter.cpp @@ -31,6 +31,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::yul; using namespace dev::solidity; diff --git a/libyul/optimiser/SSATransform.cpp b/libyul/optimiser/SSATransform.cpp index f209ee7b..6fb4b08d 100644 --- a/libyul/optimiser/SSATransform.cpp +++ b/libyul/optimiser/SSATransform.cpp @@ -31,6 +31,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::yul; using namespace dev::solidity; diff --git a/libyul/optimiser/SimplificationRules.cpp b/libyul/optimiser/SimplificationRules.cpp index 5721042f..a15ed391 100644 --- a/libyul/optimiser/SimplificationRules.cpp +++ b/libyul/optimiser/SimplificationRules.cpp @@ -31,6 +31,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::yul; diff --git a/libyul/optimiser/SimplificationRules.h b/libyul/optimiser/SimplificationRules.h index b608ca91..bd6aa4de 100644 --- a/libyul/optimiser/SimplificationRules.h +++ b/libyul/optimiser/SimplificationRules.h @@ -107,7 +107,7 @@ public: /// Turns this pattern into an actual expression. Should only be called /// for patterns resulting from an action, i.e. with match groups assigned. - Expression toExpression(SourceLocation const& _location) const; + Expression toExpression(langutil::SourceLocation const& _location) const; private: Expression const& matchGroupValue() const; diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 357d0ab3..b9f0bf79 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -62,6 +62,7 @@ #include using namespace std; +using namespace langutil; namespace po = boost::program_options; namespace dev @@ -827,7 +828,7 @@ bool CommandLineInterface::processInput() m_compiler.reset(new CompilerStack(fileReader)); - auto scannerFromSourceName = [&](string const& _sourceName) -> solidity::Scanner const& { return m_compiler->scanner(_sourceName); }; + auto scannerFromSourceName = [&](string const& _sourceName) -> Scanner const& { return m_compiler->scanner(_sourceName); }; SourceReferenceFormatter formatter(cerr, scannerFromSourceName); try diff --git a/test/libevmasm/Assembler.cpp b/test/libevmasm/Assembler.cpp index 1c041596..5ad01594 100644 --- a/test/libevmasm/Assembler.cpp +++ b/test/libevmasm/Assembler.cpp @@ -30,6 +30,7 @@ #include using namespace std; +using namespace langutil; using namespace dev::eth; namespace dev diff --git a/test/libevmasm/Optimiser.cpp b/test/libevmasm/Optimiser.cpp index c01e8758..c061b783 100644 --- a/test/libevmasm/Optimiser.cpp +++ b/test/libevmasm/Optimiser.cpp @@ -36,6 +36,7 @@ #include using namespace std; +using namespace langutil; using namespace dev::eth; namespace dev diff --git a/test/liblangutil/SourceLocation.cpp b/test/liblangutil/SourceLocation.cpp index 29cfb6a0..ac7a2173 100644 --- a/test/liblangutil/SourceLocation.cpp +++ b/test/liblangutil/SourceLocation.cpp @@ -24,9 +24,7 @@ #include -namespace dev -{ -namespace solidity +namespace langutil { namespace test { @@ -45,6 +43,5 @@ BOOST_AUTO_TEST_CASE(test_fail) BOOST_AUTO_TEST_SUITE_END() -} } } // end namespaces diff --git a/test/libsolidity/AnalysisFramework.cpp b/test/libsolidity/AnalysisFramework.cpp index dafd1748..12d63cb7 100644 --- a/test/libsolidity/AnalysisFramework.cpp +++ b/test/libsolidity/AnalysisFramework.cpp @@ -35,6 +35,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; using namespace dev::solidity::test; @@ -127,7 +128,7 @@ string AnalysisFramework::formatError(Error const& _error) const return SourceReferenceFormatter::formatExceptionInformation( _error, (_error.type() == Error::Type::Warning) ? "Warning" : "Error", - [&](std::string const& _sourceName) -> solidity::Scanner const& { return m_compiler.scanner(_sourceName); } + [&](std::string const& _sourceName) -> Scanner const& { return m_compiler.scanner(_sourceName); } ); } diff --git a/test/libsolidity/AnalysisFramework.h b/test/libsolidity/AnalysisFramework.h index a904617d..391a21da 100644 --- a/test/libsolidity/AnalysisFramework.h +++ b/test/libsolidity/AnalysisFramework.h @@ -45,7 +45,7 @@ class AnalysisFramework { protected: - virtual std::pair + virtual std::pair parseAnalyseAndReturnError( std::string const& _source, bool _reportWarnings = false, @@ -56,10 +56,10 @@ protected: SourceUnit const* parseAndAnalyse(std::string const& _source); bool success(std::string const& _source); - ErrorList expectError(std::string const& _source, bool _warning = false, bool _allowMultiple = false); + langutil::ErrorList expectError(std::string const& _source, bool _warning = false, bool _allowMultiple = false); std::string formatErrors() const; - std::string formatError(Error const& _error) const; + std::string formatError(langutil::Error const& _error) const; static ContractDefinition const* retrieveContractByName(SourceUnit const& _source, std::string const& _name); static FunctionTypePointer retrieveFunctionBySignature( @@ -68,7 +68,7 @@ protected: ); // filter out the warnings in m_warningsToFilter or all warnings if _includeWarnings is false - ErrorList filterErrors(ErrorList const& _errorList, bool _includeWarnings) const; + langutil::ErrorList filterErrors(langutil::ErrorList const& _errorList, bool _includeWarnings) const; std::vector m_warningsToFilter = {"This is a pre-release compiler version"}; dev::solidity::CompilerStack m_compiler; diff --git a/test/libsolidity/Assembly.cpp b/test/libsolidity/Assembly.cpp index 78fa7bcf..926e29fe 100644 --- a/test/libsolidity/Assembly.cpp +++ b/test/libsolidity/Assembly.cpp @@ -39,6 +39,7 @@ #include using namespace std; +using namespace langutil; using namespace dev::eth; namespace dev diff --git a/test/libsolidity/ErrorCheck.cpp b/test/libsolidity/ErrorCheck.cpp index fba2c897..e1f48fb2 100644 --- a/test/libsolidity/ErrorCheck.cpp +++ b/test/libsolidity/ErrorCheck.cpp @@ -27,6 +27,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; namespace diff --git a/test/libsolidity/ErrorCheck.h b/test/libsolidity/ErrorCheck.h index c70a6645..c3a2f522 100644 --- a/test/libsolidity/ErrorCheck.h +++ b/test/libsolidity/ErrorCheck.h @@ -30,10 +30,10 @@ namespace dev { namespace solidity { -bool searchErrorMessage(Error const& _err, std::string const& _substr); +bool searchErrorMessage(langutil::Error const& _err, std::string const& _substr); /// Checks that all provided errors are of the given type and have a given substring in their /// description. /// If the expectations are not met, returns a nonempty description, otherwise an empty string. -std::string searchErrors(ErrorList const& _errors, std::vector> const& _expectations); +std::string searchErrors(langutil::ErrorList const& _errors, std::vector> const& _expectations); } } diff --git a/test/libsolidity/GasMeter.cpp b/test/libsolidity/GasMeter.cpp index 4887dd5b..61f16c0f 100644 --- a/test/libsolidity/GasMeter.cpp +++ b/test/libsolidity/GasMeter.cpp @@ -29,6 +29,7 @@ #include using namespace std; +using namespace langutil; using namespace dev::eth; using namespace dev::solidity; using namespace dev::test; diff --git a/test/libsolidity/InlineAssembly.cpp b/test/libsolidity/InlineAssembly.cpp index 3079e032..31d21490 100644 --- a/test/libsolidity/InlineAssembly.cpp +++ b/test/libsolidity/InlineAssembly.cpp @@ -36,6 +36,7 @@ #include using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libsolidity/SMTChecker.cpp b/test/libsolidity/SMTChecker.cpp index 195004cb..13fcc5b4 100644 --- a/test/libsolidity/SMTChecker.cpp +++ b/test/libsolidity/SMTChecker.cpp @@ -25,6 +25,7 @@ #include using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libsolidity/SemVerMatcher.cpp b/test/libsolidity/SemVerMatcher.cpp index b2f4b3c2..2e147847 100644 --- a/test/libsolidity/SemVerMatcher.cpp +++ b/test/libsolidity/SemVerMatcher.cpp @@ -28,6 +28,7 @@ #include using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libsolidity/SolidityExecutionFramework.h b/test/libsolidity/SolidityExecutionFramework.h index ab71a3e0..d43e994d 100644 --- a/test/libsolidity/SolidityExecutionFramework.h +++ b/test/libsolidity/SolidityExecutionFramework.h @@ -72,13 +72,13 @@ public: m_compiler.setOptimiserSettings(m_optimize, m_optimizeRuns); if (!m_compiler.compile()) { - auto scannerFromSourceName = [&](std::string const& _sourceName) -> solidity::Scanner const& { return m_compiler.scanner(_sourceName); }; + auto scannerFromSourceName = [&](std::string const& _sourceName) -> langutil::Scanner const& { return m_compiler.scanner(_sourceName); }; SourceReferenceFormatter formatter(std::cerr, scannerFromSourceName); for (auto const& error: m_compiler.errors()) formatter.printExceptionInformation( *error, - (error->type() == Error::Type::Warning) ? "Warning" : "Error" + (error->type() == langutil::Error::Type::Warning) ? "Warning" : "Error" ); BOOST_ERROR("Compiling contract failed"); } diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp index 37183279..a68eb3df 100644 --- a/test/libsolidity/SolidityExpressionCompiler.cpp +++ b/test/libsolidity/SolidityExpressionCompiler.cpp @@ -33,6 +33,7 @@ #include using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 5ec010c7..75726027 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -33,6 +33,7 @@ #include using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libsolidity/SolidityNatspecJSON.cpp b/test/libsolidity/SolidityNatspecJSON.cpp index 45191ce1..d930f697 100644 --- a/test/libsolidity/SolidityNatspecJSON.cpp +++ b/test/libsolidity/SolidityNatspecJSON.cpp @@ -27,6 +27,8 @@ #include #include +using namespace langutil; + namespace dev { namespace solidity diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index cf5461ba..3534dd5b 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -29,6 +29,7 @@ #include using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libsolidity/SolidityScanner.cpp b/test/libsolidity/SolidityScanner.cpp index 53ec0a4c..2d164ae3 100644 --- a/test/libsolidity/SolidityScanner.cpp +++ b/test/libsolidity/SolidityScanner.cpp @@ -24,6 +24,7 @@ #include using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libsolidity/SolidityTypes.cpp b/test/libsolidity/SolidityTypes.cpp index 6f9d4ce8..c839afd4 100644 --- a/test/libsolidity/SolidityTypes.cpp +++ b/test/libsolidity/SolidityTypes.cpp @@ -26,6 +26,7 @@ #include using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libsolidity/SyntaxTest.cpp b/test/libsolidity/SyntaxTest.cpp index 91d1681f..45d32b55 100644 --- a/test/libsolidity/SyntaxTest.cpp +++ b/test/libsolidity/SyntaxTest.cpp @@ -25,6 +25,7 @@ #include using namespace dev; +using namespace langutil; using namespace solidity; using namespace dev::solidity::test; using namespace dev::solidity::test::formatting; diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp index b7ea1efc..64e52604 100644 --- a/test/libsolidity/ViewPureChecker.cpp +++ b/test/libsolidity/ViewPureChecker.cpp @@ -28,6 +28,7 @@ #include using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libyul/Common.cpp b/test/libyul/Common.cpp index b351483e..8913483f 100644 --- a/test/libyul/Common.cpp +++ b/test/libyul/Common.cpp @@ -37,6 +37,7 @@ #include using namespace std; +using namespace langutil; using namespace dev::yul; using namespace dev::solidity; diff --git a/test/libyul/Common.h b/test/libyul/Common.h index ee191494..390e214f 100644 --- a/test/libyul/Common.h +++ b/test/libyul/Common.h @@ -27,13 +27,17 @@ #include #include -namespace dev -{ -namespace solidity +namespace langutil { class Scanner; class Error; using ErrorList = std::vector>; +} + +namespace dev +{ +namespace solidity +{ namespace assembly { struct AsmAnalysisInfo; @@ -44,7 +48,7 @@ namespace yul namespace test { -void printErrors(solidity::ErrorList const& _errors, solidity::Scanner const& _scanner); +void printErrors(langutil::ErrorList const& _errors, langutil::Scanner const& _scanner); std::pair, std::shared_ptr> parse(std::string const& _source, bool _yul = true); solidity::assembly::Block disambiguate(std::string const& _source, bool _yul = true); diff --git a/test/libyul/Parser.cpp b/test/libyul/Parser.cpp index 3a887176..4aa3dd5c 100644 --- a/test/libyul/Parser.cpp +++ b/test/libyul/Parser.cpp @@ -36,6 +36,7 @@ #include using namespace std; +using namespace langutil; namespace dev { diff --git a/test/libyul/YulOptimizerTest.cpp b/test/libyul/YulOptimizerTest.cpp index 57c4d7f0..6b2b81c3 100644 --- a/test/libyul/YulOptimizerTest.cpp +++ b/test/libyul/YulOptimizerTest.cpp @@ -21,6 +21,9 @@ #include +#include +#include + #include #include #include @@ -41,12 +44,10 @@ #include #include -#include #include #include #include #include -#include #include #include @@ -54,6 +55,7 @@ #include using namespace dev; +using namespace langutil; using namespace dev::yul; using namespace dev::yul::test; using namespace dev::solidity; diff --git a/test/libyul/YulOptimizerTest.h b/test/libyul/YulOptimizerTest.h index 7db17ceb..d11ff8fb 100644 --- a/test/libyul/YulOptimizerTest.h +++ b/test/libyul/YulOptimizerTest.h @@ -19,14 +19,17 @@ #include +namespace langutil +{ +class Scanner; +class Error; +using ErrorList = std::vector>; +} namespace dev { namespace solidity { -class Scanner; -class Error; -using ErrorList = std::vector>; namespace assembly { struct AsmAnalysisInfo; @@ -58,7 +61,7 @@ private: bool parse(std::ostream& _stream, std::string const& _linePrefix, bool const _formatted); void disambiguate(); - static void printErrors(std::ostream& _stream, solidity::ErrorList const& _errors, solidity::Scanner const& _scanner); + static void printErrors(std::ostream& _stream, langutil::ErrorList const& _errors, langutil::Scanner const& _scanner); std::string m_source; bool m_yul = false; diff --git a/test/tools/yulopti.cpp b/test/tools/yulopti.cpp index df5331f7..8bc807d4 100644 --- a/test/tools/yulopti.cpp +++ b/test/tools/yulopti.cpp @@ -19,15 +19,15 @@ */ #include +#include +#include #include #include -#include #include #include #include #include #include -#include #include #include @@ -58,6 +58,7 @@ using namespace std; using namespace dev; +using namespace langutil; using namespace dev::solidity; using namespace dev::solidity::assembly; using namespace dev::yul; -- cgit