From f85aee08267ba5c59d8d0ebb32bdc38df41bba81 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 23 Feb 2015 17:14:59 +0100 Subject: [PATCH] Moving Source Location libdevcore - Big plus is we now remove the useless header libsolibity/BaseTypes.h --- .../SourceLocation.h | 17 ++-- libevmcore/Assembly.cpp | 2 +- libevmcore/Assembly.h | 8 +- libsolidity/AST.h | 94 +++++++++---------- libsolidity/ASTPrinter.cpp | 2 +- libsolidity/Exceptions.h | 4 +- libsolidity/ExpressionCompiler.cpp | 12 +-- libsolidity/ExpressionCompiler.h | 10 +- libsolidity/Parser.cpp | 6 +- libsolidity/Scanner.h | 10 +- libsolidity/SourceReferenceFormatter.cpp | 4 +- libsolidity/SourceReferenceFormatter.h | 4 +- mix/CodeHighlighter.cpp | 4 +- mix/CodeHighlighter.h | 5 +- mix/CodeModel.cpp | 3 +- test/SolidityInterface.cpp | 2 +- 16 files changed, 92 insertions(+), 95 deletions(-) rename libsolidity/BaseTypes.h => libdevcore/SourceLocation.h (79%) diff --git a/libsolidity/BaseTypes.h b/libdevcore/SourceLocation.h similarity index 79% rename from libsolidity/BaseTypes.h rename to libdevcore/SourceLocation.h index 057289ef3..75919061b 100644 --- a/libsolidity/BaseTypes.h +++ b/libdevcore/SourceLocation.h @@ -15,9 +15,9 @@ along with cpp-ethereum. If not, see . */ /** - * @author Christian - * @date 2014 - * Some elementary types for the parser. + * @author Lefteris Karapetsas + * @date 2015 + * Represents a location in a source file */ #pragma once @@ -28,18 +28,16 @@ namespace dev { -namespace solidity -{ /** * Representation of an interval of source positions. * The interval includes start and excludes end. */ -struct Location +struct SourceLocation { - Location(int _start, int _end, std::shared_ptr _sourceName): + SourceLocation(int _start, int _end, std::shared_ptr _sourceName): start(_start), end(_end), sourceName(_sourceName) { } - Location(): start(-1), end(-1) { } + SourceLocation(): start(-1), end(-1) { } bool isEmpty() const { return start == -1 && end == -1; } @@ -49,7 +47,7 @@ struct Location }; /// Stream output for Location (used e.g. in boost exceptions). -inline std::ostream& operator<<(std::ostream& _out, Location const& _location) +inline std::ostream& operator<<(std::ostream& _out, SourceLocation const& _location) { if (_location.isEmpty()) return _out << "NO_LOCATION_SPECIFIED"; @@ -57,4 +55,3 @@ inline std::ostream& operator<<(std::ostream& _out, Location const& _location) } } -} diff --git a/libevmcore/Assembly.cpp b/libevmcore/Assembly.cpp index 04d3f85fd..80ac8c68f 100644 --- a/libevmcore/Assembly.cpp +++ b/libevmcore/Assembly.cpp @@ -229,7 +229,7 @@ ostream& Assembly::streamRLP(ostream& _out, string const& _prefix) const return _out; } -AssemblyItem const& Assembly::append(AssemblyItem const& _i, solidity::Location const& _location) +AssemblyItem const& Assembly::append(AssemblyItem const& _i, SourceLocation const& _location) { m_deposit += _i.deposit(); m_items.push_back(_i); diff --git a/libevmcore/Assembly.h b/libevmcore/Assembly.h index 47eaefa56..68235777f 100644 --- a/libevmcore/Assembly.h +++ b/libevmcore/Assembly.h @@ -24,8 +24,8 @@ #include #include #include +#include #include -#include #include "Exceptions.h" namespace dev @@ -58,12 +58,12 @@ public: int deposit() const; bool match(AssemblyItem const& _i) const { return _i.m_type == UndefinedItem || (m_type == _i.m_type && (m_type != Operation || m_data == _i.m_data)); } - void setLocation(dev::solidity::Location const& _location) { m_location = _location;} + void setLocation(dev::SourceLocation const& _location) { m_location = _location;} private: AssemblyItemType m_type; u256 m_data; - dev::solidity::Location m_location; + dev::SourceLocation m_location; }; using AssemblyItems = std::vector; @@ -87,7 +87,7 @@ public: AssemblyItem append() { return append(newTag()); } void append(Assembly const& _a); void append(Assembly const& _a, int _deposit); - AssemblyItem const& append(AssemblyItem const& _i, solidity::Location const& _location = solidity::Location()); + AssemblyItem const& append(AssemblyItem const& _i, SourceLocation const& _location = SourceLocation()); AssemblyItem const& append(std::string const& _data) { return append(newPushString(_data)); } AssemblyItem const& append(bytes const& _data) { return append(newData(_data)); } AssemblyItem appendSubSize(Assembly const& _a) { auto ret = newSub(_a); append(newPushSubSize(ret.data())); return ret; } diff --git a/libsolidity/AST.h b/libsolidity/AST.h index 60648cdc2..27dc008a8 100644 --- a/libsolidity/AST.h +++ b/libsolidity/AST.h @@ -27,9 +27,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -51,7 +51,7 @@ class ASTConstVisitor; class ASTNode: private boost::noncopyable { public: - explicit ASTNode(Location const& _location): m_location(_location) {} + explicit ASTNode(SourceLocation const& _location): m_location(_location) {} virtual ~ASTNode() {} @@ -71,7 +71,7 @@ public: } /// Returns the source code location of this node. - Location const& getLocation() const { return m_location; } + SourceLocation const& getLocation() const { return m_location; } /// Creates a @ref TypeError exception and decorates it with the location of the node and /// the given description @@ -85,7 +85,7 @@ public: ///@} private: - Location m_location; + SourceLocation m_location; }; /** @@ -94,7 +94,7 @@ private: class SourceUnit: public ASTNode { public: - SourceUnit(Location const& _location, std::vector> const& _nodes): + SourceUnit(SourceLocation const& _location, std::vector> const& _nodes): ASTNode(_location), m_nodes(_nodes) {} virtual void accept(ASTVisitor& _visitor) override; @@ -114,7 +114,7 @@ private: class ImportDirective: public ASTNode { public: - ImportDirective(Location const& _location, ASTPointer const& _identifier): + ImportDirective(SourceLocation const& _location, ASTPointer const& _identifier): ASTNode(_location), m_identifier(_identifier) {} virtual void accept(ASTVisitor& _visitor) override; @@ -135,7 +135,7 @@ public: /// Visibility ordered from restricted to unrestricted. enum class Visibility { Default, Private, Internal, Public, External }; - Declaration(Location const& _location, ASTPointer const& _name, + Declaration(SourceLocation const& _location, ASTPointer const& _name, Visibility _visibility = Visibility::Default): ASTNode(_location), m_name(_name), m_visibility(_visibility), m_scope(nullptr) {} @@ -205,7 +205,7 @@ protected: class ContractDefinition: public Declaration, public Documented { public: - ContractDefinition(Location const& _location, + ContractDefinition(SourceLocation const& _location, ASTPointer const& _name, ASTPointer const& _documentation, std::vector> const& _baseContracts, @@ -278,7 +278,7 @@ private: class InheritanceSpecifier: public ASTNode { public: - InheritanceSpecifier(Location const& _location, ASTPointer const& _baseName, + InheritanceSpecifier(SourceLocation const& _location, ASTPointer const& _baseName, std::vector> _arguments): ASTNode(_location), m_baseName(_baseName), m_arguments(_arguments) {} @@ -298,7 +298,7 @@ private: class StructDefinition: public Declaration { public: - StructDefinition(Location const& _location, + StructDefinition(SourceLocation const& _location, ASTPointer const& _name, std::vector> const& _members): Declaration(_location, _name), m_members(_members) {} @@ -323,7 +323,7 @@ private: class EnumDefinition: public Declaration { public: - EnumDefinition(Location const& _location, + EnumDefinition(SourceLocation const& _location, ASTPointer const& _name, std::vector> const& _members): Declaration(_location, _name), m_members(_members) {} @@ -344,7 +344,7 @@ private: class EnumValue: public Declaration { public: - EnumValue(Location const& _location, + EnumValue(SourceLocation const& _location, ASTPointer const& _name): Declaration(_location, _name) {} @@ -361,7 +361,7 @@ class EnumValue: public Declaration class ParameterList: public ASTNode { public: - ParameterList(Location const& _location, + ParameterList(SourceLocation const& _location, std::vector> const& _parameters): ASTNode(_location), m_parameters(_parameters) {} virtual void accept(ASTVisitor& _visitor) override; @@ -376,7 +376,7 @@ private: class FunctionDefinition: public Declaration, public VariableScope, public Documented { public: - FunctionDefinition(Location const& _location, ASTPointer const& _name, + FunctionDefinition(SourceLocation const& _location, ASTPointer const& _name, Declaration::Visibility _visibility, bool _isConstructor, ASTPointer const& _documentation, ASTPointer const& _parameters, @@ -431,7 +431,7 @@ private: class VariableDeclaration: public Declaration { public: - VariableDeclaration(Location const& _location, ASTPointer const& _type, + VariableDeclaration(SourceLocation const& _location, ASTPointer const& _type, ASTPointer const& _name, ASTPointer _value, Visibility _visibility, bool _isStateVar = false, bool _isIndexed = false): @@ -476,7 +476,7 @@ private: class ModifierDefinition: public Declaration, public VariableScope, public Documented { public: - ModifierDefinition(Location const& _location, + ModifierDefinition(SourceLocation const& _location, ASTPointer const& _name, ASTPointer const& _documentation, ASTPointer const& _parameters, @@ -506,7 +506,7 @@ private: class ModifierInvocation: public ASTNode { public: - ModifierInvocation(Location const& _location, ASTPointer const& _name, + ModifierInvocation(SourceLocation const& _location, ASTPointer const& _name, std::vector> _arguments): ASTNode(_location), m_modifierName(_name), m_arguments(_arguments) {} @@ -529,7 +529,7 @@ private: class EventDefinition: public Declaration, public VariableScope, public Documented { public: - EventDefinition(Location const& _location, + EventDefinition(SourceLocation const& _location, ASTPointer const& _name, ASTPointer const& _documentation, ASTPointer const& _parameters): @@ -560,7 +560,7 @@ class MagicVariableDeclaration: public Declaration { public: MagicVariableDeclaration(ASTString const& _name, std::shared_ptr const& _type): - Declaration(Location(), std::make_shared(_name)), m_type(_type) {} + Declaration(SourceLocation(), std::make_shared(_name)), m_type(_type) {} virtual void accept(ASTVisitor&) override { BOOST_THROW_EXCEPTION(InternalCompilerError() << errinfo_comment("MagicVariableDeclaration used inside real AST.")); } virtual void accept(ASTConstVisitor&) const override { BOOST_THROW_EXCEPTION(InternalCompilerError() @@ -581,7 +581,7 @@ private: class TypeName: public ASTNode { public: - explicit TypeName(Location const& _location): ASTNode(_location) {} + explicit TypeName(SourceLocation const& _location): ASTNode(_location) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; @@ -598,7 +598,7 @@ public: class ElementaryTypeName: public TypeName { public: - explicit ElementaryTypeName(Location const& _location, Token::Value _type): + explicit ElementaryTypeName(SourceLocation const& _location, Token::Value _type): TypeName(_location), m_type(_type) { solAssert(Token::isElementaryTypeName(_type), ""); @@ -619,7 +619,7 @@ private: class UserDefinedTypeName: public TypeName { public: - UserDefinedTypeName(Location const& _location, ASTPointer const& _name): + UserDefinedTypeName(SourceLocation const& _location, ASTPointer const& _name): TypeName(_location), m_name(_name), m_referencedDeclaration(nullptr) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; @@ -641,7 +641,7 @@ private: class Mapping: public TypeName { public: - Mapping(Location const& _location, ASTPointer const& _keyType, + Mapping(SourceLocation const& _location, ASTPointer const& _keyType, ASTPointer const& _valueType): TypeName(_location), m_keyType(_keyType), m_valueType(_valueType) {} virtual void accept(ASTVisitor& _visitor) override; @@ -689,7 +689,7 @@ private: class Statement: public ASTNode { public: - explicit Statement(Location const& _location): ASTNode(_location) {} + explicit Statement(SourceLocation const& _location): ASTNode(_location) {} /// Check all type requirements, throws exception if some requirement is not met. /// This includes checking that operators are applicable to their arguments but also that @@ -703,7 +703,7 @@ public: class Block: public Statement { public: - Block(Location const& _location, std::vector> const& _statements): + Block(SourceLocation const& _location, std::vector> const& _statements): Statement(_location), m_statements(_statements) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; @@ -721,7 +721,7 @@ private: class PlaceholderStatement: public Statement { public: - PlaceholderStatement(Location const& _location): Statement(_location) {} + PlaceholderStatement(SourceLocation const& _location): Statement(_location) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; @@ -736,7 +736,7 @@ public: class IfStatement: public Statement { public: - IfStatement(Location const& _location, ASTPointer const& _condition, + IfStatement(SourceLocation const& _location, ASTPointer const& _condition, ASTPointer const& _trueBody, ASTPointer const& _falseBody): Statement(_location), m_condition(_condition), m_trueBody(_trueBody), m_falseBody(_falseBody) {} @@ -761,13 +761,13 @@ private: class BreakableStatement: public Statement { public: - BreakableStatement(Location const& _location): Statement(_location) {} + BreakableStatement(SourceLocation const& _location): Statement(_location) {} }; class WhileStatement: public BreakableStatement { public: - WhileStatement(Location const& _location, ASTPointer const& _condition, + WhileStatement(SourceLocation const& _location, ASTPointer const& _condition, ASTPointer const& _body): BreakableStatement(_location), m_condition(_condition), m_body(_body) {} virtual void accept(ASTVisitor& _visitor) override; @@ -788,7 +788,7 @@ private: class ForStatement: public BreakableStatement { public: - ForStatement(Location const& _location, + ForStatement(SourceLocation const& _location, ASTPointer const& _initExpression, ASTPointer const& _conditionExpression, ASTPointer const& _loopExpression, @@ -821,7 +821,7 @@ private: class Continue: public Statement { public: - Continue(Location const& _location): Statement(_location) {} + Continue(SourceLocation const& _location): Statement(_location) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; virtual void checkTypeRequirements() override {} @@ -830,7 +830,7 @@ public: class Break: public Statement { public: - Break(Location const& _location): Statement(_location) {} + Break(SourceLocation const& _location): Statement(_location) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; virtual void checkTypeRequirements() override {} @@ -839,7 +839,7 @@ public: class Return: public Statement { public: - Return(Location const& _location, ASTPointer _expression): + Return(SourceLocation const& _location, ASTPointer _expression): Statement(_location), m_expression(_expression), m_returnParameters(nullptr) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; @@ -864,7 +864,7 @@ private: class VariableDeclarationStatement: public Statement { public: - VariableDeclarationStatement(Location const& _location, ASTPointer _variable): + VariableDeclarationStatement(SourceLocation const& _location, ASTPointer _variable): Statement(_location), m_variable(_variable) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; @@ -883,7 +883,7 @@ private: class ExpressionStatement: public Statement { public: - ExpressionStatement(Location const& _location, ASTPointer _expression): + ExpressionStatement(SourceLocation const& _location, ASTPointer _expression): Statement(_location), m_expression(_expression) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; @@ -908,7 +908,7 @@ private: class Expression: public ASTNode { public: - Expression(Location const& _location): ASTNode(_location) {} + Expression(SourceLocation const& _location): ASTNode(_location) {} virtual void checkTypeRequirements() = 0; std::shared_ptr const& getType() const { return m_type; } @@ -939,7 +939,7 @@ protected: class Assignment: public Expression { public: - Assignment(Location const& _location, ASTPointer const& _leftHandSide, + Assignment(SourceLocation const& _location, ASTPointer const& _leftHandSide, Token::Value _assignmentOperator, ASTPointer const& _rightHandSide): Expression(_location), m_leftHandSide(_leftHandSide), m_assigmentOperator(_assignmentOperator), m_rightHandSide(_rightHandSide) @@ -967,7 +967,7 @@ private: class UnaryOperation: public Expression { public: - UnaryOperation(Location const& _location, Token::Value _operator, + UnaryOperation(SourceLocation const& _location, Token::Value _operator, ASTPointer const& _subExpression, bool _isPrefix): Expression(_location), m_operator(_operator), m_subExpression(_subExpression), m_isPrefix(_isPrefix) @@ -995,7 +995,7 @@ private: class BinaryOperation: public Expression { public: - BinaryOperation(Location const& _location, ASTPointer const& _left, + BinaryOperation(SourceLocation const& _location, ASTPointer const& _left, Token::Value _operator, ASTPointer const& _right): Expression(_location), m_left(_left), m_operator(_operator), m_right(_right) { @@ -1026,7 +1026,7 @@ private: class FunctionCall: public Expression { public: - FunctionCall(Location const& _location, ASTPointer const& _expression, + FunctionCall(SourceLocation const& _location, ASTPointer const& _expression, std::vector> const& _arguments, std::vector> const& _names): Expression(_location), m_expression(_expression), m_arguments(_arguments), m_names(_names) {} virtual void accept(ASTVisitor& _visitor) override; @@ -1053,7 +1053,7 @@ private: class NewExpression: public Expression { public: - NewExpression(Location const& _location, ASTPointer const& _contractName): + NewExpression(SourceLocation const& _location, ASTPointer const& _contractName): Expression(_location), m_contractName(_contractName) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; @@ -1074,7 +1074,7 @@ private: class MemberAccess: public Expression { public: - MemberAccess(Location const& _location, ASTPointer _expression, + MemberAccess(SourceLocation const& _location, ASTPointer _expression, ASTPointer const& _memberName): Expression(_location), m_expression(_expression), m_memberName(_memberName) {} virtual void accept(ASTVisitor& _visitor) override; @@ -1094,7 +1094,7 @@ private: class IndexAccess: public Expression { public: - IndexAccess(Location const& _location, ASTPointer const& _base, + IndexAccess(SourceLocation const& _location, ASTPointer const& _base, ASTPointer const& _index): Expression(_location), m_base(_base), m_index(_index) {} virtual void accept(ASTVisitor& _visitor) override; @@ -1116,7 +1116,7 @@ private: class PrimaryExpression: public Expression { public: - PrimaryExpression(Location const& _location): Expression(_location) {} + PrimaryExpression(SourceLocation const& _location): Expression(_location) {} }; /** @@ -1125,7 +1125,7 @@ public: class Identifier: public PrimaryExpression { public: - Identifier(Location const& _location, ASTPointer const& _name): + Identifier(SourceLocation const& _location, ASTPointer const& _name): PrimaryExpression(_location), m_name(_name) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; @@ -1160,7 +1160,7 @@ private: class ElementaryTypeNameExpression: public PrimaryExpression { public: - ElementaryTypeNameExpression(Location const& _location, Token::Value _typeToken): + ElementaryTypeNameExpression(SourceLocation const& _location, Token::Value _typeToken): PrimaryExpression(_location), m_typeToken(_typeToken) { solAssert(Token::isElementaryTypeName(_typeToken), ""); @@ -1189,7 +1189,7 @@ public: Finney = Token::SubFinney, Ether = Token::SubEther }; - Literal(Location const& _location, Token::Value _token, + Literal(SourceLocation const& _location, Token::Value _token, ASTPointer const& _value, SubDenomination _sub = SubDenomination::None): PrimaryExpression(_location), m_token(_token), m_value(_value), m_subDenomination(_sub) {} diff --git a/libsolidity/ASTPrinter.cpp b/libsolidity/ASTPrinter.cpp index 5bcc46df7..d0b27b317 100644 --- a/libsolidity/ASTPrinter.cpp +++ b/libsolidity/ASTPrinter.cpp @@ -555,7 +555,7 @@ void ASTPrinter::printSourcePart(ASTNode const& _node) { if (!m_source.empty()) { - Location const& location(_node.getLocation()); + SourceLocation const& location(_node.getLocation()); *m_ostream << getIndentation() << " Source: " << escaped(m_source.substr(location.start, location.end - location.start), false) << endl; } diff --git a/libsolidity/Exceptions.h b/libsolidity/Exceptions.h index 0b25abee1..48dfc52e5 100644 --- a/libsolidity/Exceptions.h +++ b/libsolidity/Exceptions.h @@ -24,7 +24,7 @@ #include #include -#include +#include namespace dev { @@ -38,7 +38,7 @@ struct CompilerError: virtual Exception {}; struct InternalCompilerError: virtual Exception {}; struct DocstringParsingError: virtual Exception {}; -using errinfo_sourceLocation = boost::error_info; +using errinfo_sourceLocation = boost::error_info; } } diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index 9f8c8bbbe..5a78aaadb 100644 --- a/libsolidity/ExpressionCompiler.cpp +++ b/libsolidity/ExpressionCompiler.cpp @@ -1035,7 +1035,7 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& << structType->getStorageOffsetOfMember(names[i]) << eth::Instruction::ADD; m_currentLValue = LValue(m_context, LValue::LValueType::Storage, types[i]); - m_currentLValue.retrieveValue(Location(), true); + m_currentLValue.retrieveValue(SourceLocation(), true); solAssert(types[i]->getSizeOnStack() == 1, "Returning struct elements with stack size != 1 not yet implemented."); m_context << eth::Instruction::SWAP1; retSizeOnStack += types[i]->getSizeOnStack(); @@ -1047,7 +1047,7 @@ void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& // simple value solAssert(accessorType.getReturnParameterTypes().size() == 1, ""); m_currentLValue = LValue(m_context, LValue::LValueType::Storage, returnType); - m_currentLValue.retrieveValue(Location(), true); + m_currentLValue.retrieveValue(SourceLocation(), true); retSizeOnStack = returnType->getSizeOnStack(); } solAssert(retSizeOnStack <= 15, "Stack too deep."); @@ -1068,7 +1068,7 @@ ExpressionCompiler::LValue::LValue(CompilerContext& _compilerContext, LValueType m_size = unsigned(m_dataType->getSizeOnStack()); } -void ExpressionCompiler::LValue::fromDeclaration(Declaration const& _declaration, Location const& _location) +void ExpressionCompiler::LValue::fromDeclaration(Declaration const& _declaration, SourceLocation const& _location) { if (m_context->isLocalVariable(&_declaration)) { @@ -1091,7 +1091,7 @@ void ExpressionCompiler::LValue::fromDeclaration(Declaration const& _declaration << errinfo_comment("Identifier type not supported or identifier not found.")); } -void ExpressionCompiler::LValue::retrieveValue(Location const& _location, bool _remove) const +void ExpressionCompiler::LValue::retrieveValue(SourceLocation const& _location, bool _remove) const { switch (m_type) { @@ -1140,7 +1140,7 @@ void ExpressionCompiler::LValue::retrieveValueFromStorage(bool _remove) const } } -void ExpressionCompiler::LValue::storeValue(Type const& _sourceType, Location const& _location, bool _move) const +void ExpressionCompiler::LValue::storeValue(Type const& _sourceType, SourceLocation const& _location, bool _move) const { switch (m_type) { @@ -1243,7 +1243,7 @@ void ExpressionCompiler::LValue::storeValue(Type const& _sourceType, Location co } } -void ExpressionCompiler::LValue::setToZero(Location const& _location) const +void ExpressionCompiler::LValue::setToZero(SourceLocation const& _location) const { switch (m_type) { diff --git a/libsolidity/ExpressionCompiler.h b/libsolidity/ExpressionCompiler.h index 31bcc924a..bae5afb40 100644 --- a/libsolidity/ExpressionCompiler.h +++ b/libsolidity/ExpressionCompiler.h @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include namespace dev { @@ -133,7 +133,7 @@ private: /// Set type according to the declaration and retrieve the reference. /// @a _location is the current location - void fromDeclaration(Declaration const& _declaration, Location const& _location); + void fromDeclaration(Declaration const& _declaration, SourceLocation const& _location); void reset() { m_type = LValueType::None; m_dataType.reset(); m_baseStackOffset = 0; m_size = 0; } @@ -148,15 +148,15 @@ private: /// 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 (note that is does not reset the type to @a NONE). /// @a _location source location of the current expression, used for error reporting. - void retrieveValue(Location const& _location, bool _remove = false) const; + void retrieveValue(SourceLocation const& _location, bool _remove = false) const; /// 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) - void storeValue(Type const& _sourceType, Location const& _location = Location(), bool _move = false) const; + void storeValue(Type const& _sourceType, SourceLocation const& _location = SourceLocation(), bool _move = false) const; /// Stores zero in the lvalue. /// @a _location is the source location of the requested operation - void setToZero(Location const& _location = Location()) const; + void setToZero(SourceLocation const& _location = SourceLocation()) const; /// Convenience function to convert the stored reference to a value and reset type to NONE if /// the reference was not requested by @a _expression. void retrieveValueIfLValueNotRequested(Expression const& _expression); diff --git a/libsolidity/Parser.cpp b/libsolidity/Parser.cpp index 1fc5ec98f..ea56d68f3 100644 --- a/libsolidity/Parser.cpp +++ b/libsolidity/Parser.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include @@ -60,7 +60,7 @@ public: private: Parser const& m_parser; - Location m_location; + SourceLocation m_location; }; ASTPointer Parser::parse(shared_ptr const& _scanner) @@ -983,7 +983,7 @@ ASTPointer Parser::createEmptyParameterList() ParserError Parser::createParserError(string const& _description) const { - return ParserError() << errinfo_sourceLocation(Location(getPosition(), getPosition(), getSourceName())) + return ParserError() << errinfo_sourceLocation(SourceLocation(getPosition(), getPosition(), getSourceName())) << errinfo_comment(_description); } diff --git a/libsolidity/Scanner.h b/libsolidity/Scanner.h index d93b79df0..61fb89035 100644 --- a/libsolidity/Scanner.h +++ b/libsolidity/Scanner.h @@ -55,7 +55,7 @@ #include #include #include -#include +#include #include namespace dev @@ -120,14 +120,14 @@ public: return m_currentToken.token; } - Location getCurrentLocation() const { return m_currentToken.location; } + SourceLocation getCurrentLocation() const { return m_currentToken.location; } std::string const& getCurrentLiteral() const { return m_currentToken.literal; } ///@} ///@{ ///@name Information about the current comment token - Location getCurrentCommentLocation() const { return m_skippedComment.location; } + SourceLocation getCurrentCommentLocation() const { return m_skippedComment.location; } std::string const& getCurrentCommentLiteral() const { return m_skippedComment.literal; } /// Called by the parser during FunctionDefinition parsing to clear the current comment void clearCurrentCommentLiteral() { m_skippedComment.literal.clear(); } @@ -139,7 +139,7 @@ public: /// Returns the next token without advancing input. Token::Value peekNextToken() const { return m_nextToken.token; } - Location peekLocation() const { return m_nextToken.location; } + SourceLocation peekLocation() const { return m_nextToken.location; } std::string const& peekLiteral() const { return m_nextToken.literal; } ///@} @@ -158,7 +158,7 @@ private: struct TokenDesc { Token::Value token; - Location location; + SourceLocation location; std::string literal; }; diff --git a/libsolidity/SourceReferenceFormatter.cpp b/libsolidity/SourceReferenceFormatter.cpp index c61f9b685..489a676ed 100644 --- a/libsolidity/SourceReferenceFormatter.cpp +++ b/libsolidity/SourceReferenceFormatter.cpp @@ -33,7 +33,7 @@ namespace solidity { void SourceReferenceFormatter::printSourceLocation(ostream& _stream, - Location const& _location, + SourceLocation const& _location, Scanner const& _scanner) { int startLine; @@ -63,7 +63,7 @@ void SourceReferenceFormatter::printExceptionInformation(ostream& _stream, string const& _name, CompilerStack const& _compiler) { - Location const* location = boost::get_error_info(_exception); + SourceLocation const* location = boost::get_error_info(_exception); Scanner const* scanner; if (location) diff --git a/libsolidity/SourceReferenceFormatter.h b/libsolidity/SourceReferenceFormatter.h index 98f1c745d..337e60659 100644 --- a/libsolidity/SourceReferenceFormatter.h +++ b/libsolidity/SourceReferenceFormatter.h @@ -23,7 +23,7 @@ #pragma once #include -#include +#include namespace dev { @@ -39,7 +39,7 @@ class CompilerStack; // forward struct SourceReferenceFormatter { public: - static void printSourceLocation(std::ostream& _stream, Location const& _location, Scanner const& _scanner); + static void printSourceLocation(std::ostream& _stream, SourceLocation const& _location, Scanner const& _scanner); static void printExceptionInformation(std::ostream& _stream, Exception const& _exception, std::string const& _name, CompilerStack const& _compiler); }; diff --git a/mix/CodeHighlighter.cpp b/mix/CodeHighlighter.cpp index 86dfe9e5d..5a7b1f4d5 100644 --- a/mix/CodeHighlighter.cpp +++ b/mix/CodeHighlighter.cpp @@ -64,7 +64,7 @@ namespace }; } -CodeHighlighter::FormatRange::FormatRange(CodeHighlighterSettings::Token _t, dev::solidity::Location const& _location): +CodeHighlighter::FormatRange::FormatRange(CodeHighlighterSettings::Token _t, dev::SourceLocation const& _location): token(_t), start(_location.start), length(_location.end - _location.start) {} @@ -101,7 +101,7 @@ void CodeHighlighter::processAST(dev::solidity::ASTNode const& _ast) void CodeHighlighter::processError(dev::Exception const& _exception) { - Location const* location = boost::get_error_info(_exception); + SourceLocation const* location = boost::get_error_info(_exception); if (location) m_formats.push_back(FormatRange(CodeHighlighterSettings::CompilationError, *location)); } diff --git a/mix/CodeHighlighter.h b/mix/CodeHighlighter.h index 3bdff5647..7fce7ed95 100644 --- a/mix/CodeHighlighter.h +++ b/mix/CodeHighlighter.h @@ -32,11 +32,10 @@ namespace dev { struct Exception; - +struct SourceLocation; namespace solidity { class ASTNode; - struct Location; } namespace mix @@ -74,7 +73,7 @@ public: struct FormatRange { FormatRange(CodeHighlighterSettings::Token _t, int _start, int _length): token(_t), start(_start), length(_length) {} - FormatRange(CodeHighlighterSettings::Token _t, solidity::Location const& _location); + FormatRange(CodeHighlighterSettings::Token _t, SourceLocation const& _location); bool operator<(FormatRange const& _other) const { return start < _other.start || (start == _other.start && length < _other.length); } CodeHighlighterSettings::Token token; diff --git a/mix/CodeModel.cpp b/mix/CodeModel.cpp index 7a38594ce..9ca4d07bb 100644 --- a/mix/CodeModel.cpp +++ b/mix/CodeModel.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -212,7 +213,7 @@ void CodeModel::runCompilationJob(int _jobId) { std::ostringstream error; solidity::SourceReferenceFormatter::printExceptionInformation(error, _exception, "Error", cs); - solidity::Location const* location = boost::get_error_info(_exception); + SourceLocation const* location = boost::get_error_info(_exception); QString message = QString::fromStdString(error.str()); CompiledContract* contract = nullptr; if (location && location->sourceName.get() && (contract = contractByDocumentId(QString::fromStdString(*location->sourceName)))) diff --git a/test/SolidityInterface.cpp b/test/SolidityInterface.cpp index a73c118bb..354715182 100644 --- a/test/SolidityInterface.cpp +++ b/test/SolidityInterface.cpp @@ -50,7 +50,7 @@ public: string getSourcePart(ASTNode const& _node) const { - Location location = _node.getLocation(); + SourceLocation location = _node.getLocation(); BOOST_REQUIRE(!location.isEmpty()); return m_interface.substr(location.start, location.end - location.start); }