mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #5427 from ethereum/liblangutil
Factor out langutil, a new static library that is shared between libyul/libsolidity
This commit is contained in:
commit
b5acc63008
@ -45,6 +45,7 @@ include(EthOptions)
|
||||
configure_project(TESTS)
|
||||
|
||||
add_subdirectory(libdevcore)
|
||||
add_subdirectory(liblangutil)
|
||||
add_subdirectory(libevmasm)
|
||||
add_subdirectory(libsolidity)
|
||||
add_subdirectory(libsolc)
|
||||
|
@ -35,6 +35,7 @@
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace dev::eth;
|
||||
using namespace langutil;
|
||||
|
||||
void Assembly::append(Assembly const& _a)
|
||||
{
|
||||
|
@ -18,12 +18,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <libevmasm/Instruction.h>
|
||||
#include <libevmasm/SourceLocation.h>
|
||||
#include <liblangutil/SourceLocation.h>
|
||||
#include <libevmasm/AssemblyItem.h>
|
||||
#include <libevmasm/LinkerObject.h>
|
||||
#include <libevmasm/Exceptions.h>
|
||||
|
||||
#include <libsolidity/interface/EVMVersion.h>
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
|
||||
#include <libdevcore/Common.h>
|
||||
#include <libdevcore/Assertions.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)
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include <libdevcore/Common.h>
|
||||
#include <libdevcore/Assertions.h>
|
||||
#include <libevmasm/Instruction.h>
|
||||
#include <libevmasm/SourceLocation.h>
|
||||
#include <liblangutil/SourceLocation.h>
|
||||
#include "Exceptions.h"
|
||||
using namespace dev::solidity;
|
||||
|
||||
@ -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<u256> 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.
|
||||
|
@ -30,6 +30,7 @@
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace dev::eth;
|
||||
using namespace langutil;
|
||||
|
||||
vector<AssemblyItem> CommonSubexpressionEliminator::getOptimizedItems()
|
||||
{
|
||||
|
@ -34,6 +34,11 @@
|
||||
#include <libevmasm/SemanticInformation.h>
|
||||
#include <libevmasm/KnownState.h>
|
||||
|
||||
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);
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
#include <libevmasm/Exceptions.h>
|
||||
|
||||
#include <libsolidity/interface/EVMVersion.h>
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
|
||||
#include <libdevcore/Assertions.h>
|
||||
#include <libdevcore/CommonData.h>
|
||||
|
@ -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<u256> tags = state->tagsInExpression(
|
||||
state->stackElement(state->stackHeight(), SourceLocation())
|
||||
state->stackElement(state->stackHeight(), langutil::SourceLocation{})
|
||||
);
|
||||
state->feedItem(m_items.at(pc++));
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -31,6 +31,11 @@
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
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.
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include <libevmasm/ExpressionClasses.h>
|
||||
#include <libevmasm/AssemblyItem.h>
|
||||
|
||||
#include <libsolidity/interface/EVMVersion.h>
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
|
||||
#include <ostream>
|
||||
#include <tuple>
|
||||
|
@ -29,6 +29,7 @@
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace dev::eth;
|
||||
using namespace langutil;
|
||||
|
||||
ostream& KnownState::stream(ostream& _out) const
|
||||
{
|
||||
|
@ -46,6 +46,11 @@
|
||||
#include <libevmasm/ExpressionClasses.h>
|
||||
#include <libevmasm/SemanticInformation.h>
|
||||
|
||||
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<u256> _tags);
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
#include <libevmasm/GasMeter.h>
|
||||
|
||||
#include <libsolidity/interface/EVMVersion.h>
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
@ -38,7 +38,7 @@
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace dev::eth;
|
||||
|
||||
using namespace langutil;
|
||||
|
||||
SimplificationRule<Pattern> const* Rules::findFirstMatch(
|
||||
Expression const& _expr,
|
||||
|
@ -31,6 +31,11 @@
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
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<Pattern> 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.
|
||||
|
6
liblangutil/CMakeLists.txt
Normal file
6
liblangutil/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
# Solidity Commons Library (Solidity related sharing bits between libsolidity and libyul)
|
||||
file(GLOB sources "*.cpp")
|
||||
file(GLOB headers "*.h")
|
||||
|
||||
add_library(langutil ${sources} ${headers})
|
||||
target_link_libraries(langutil PUBLIC devcore)
|
108
liblangutil/CharStream.cpp
Normal file
108
liblangutil/CharStream.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
This file is derived from the file "scanner.cc", which was part of the
|
||||
V8 project. The original copyright header follows:
|
||||
|
||||
Copyright 2006-2012, the V8 project authors. All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* @author Christian <c@ethdev.com>
|
||||
* @date 2014
|
||||
* Solidity scanner.
|
||||
*/
|
||||
|
||||
#include <liblangutil/CharStream.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace langutil;
|
||||
|
||||
char CharStream::advanceAndGet(size_t _chars)
|
||||
{
|
||||
if (isPastEndOfInput())
|
||||
return 0;
|
||||
m_position += _chars;
|
||||
if (isPastEndOfInput())
|
||||
return 0;
|
||||
return m_source[m_position];
|
||||
}
|
||||
|
||||
char CharStream::rollback(size_t _amount)
|
||||
{
|
||||
solAssert(m_position >= _amount, "");
|
||||
m_position -= _amount;
|
||||
return get();
|
||||
}
|
||||
|
||||
string CharStream::lineAtPosition(int _position) const
|
||||
{
|
||||
// if _position points to \n, it returns the line before the \n
|
||||
using size_type = string::size_type;
|
||||
size_type searchStart = min<size_type>(m_source.size(), _position);
|
||||
if (searchStart > 0)
|
||||
searchStart--;
|
||||
size_type lineStart = m_source.rfind('\n', searchStart);
|
||||
if (lineStart == string::npos)
|
||||
lineStart = 0;
|
||||
else
|
||||
lineStart++;
|
||||
return m_source.substr(lineStart, min(m_source.find('\n', lineStart),
|
||||
m_source.size()) - lineStart);
|
||||
}
|
||||
|
||||
tuple<int, int> CharStream::translatePositionToLineColumn(int _position) const
|
||||
{
|
||||
using size_type = string::size_type;
|
||||
size_type searchPosition = min<size_type>(m_source.size(), _position);
|
||||
int lineNumber = count(m_source.begin(), m_source.begin() + searchPosition, '\n');
|
||||
size_type lineStart;
|
||||
if (searchPosition == 0)
|
||||
lineStart = 0;
|
||||
else
|
||||
{
|
||||
lineStart = m_source.rfind('\n', searchPosition - 1);
|
||||
lineStart = lineStart == string::npos ? 0 : lineStart + 1;
|
||||
}
|
||||
return tuple<int, int>(lineNumber, searchPosition - lineStart);
|
||||
}
|
||||
|
||||
|
97
liblangutil/CharStream.h
Normal file
97
liblangutil/CharStream.h
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
This file is derived from the file "scanner.h", which was part of the
|
||||
V8 project. The original copyright header follows:
|
||||
|
||||
Copyright 2006-2012, the V8 project authors. All rights reserved.
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following
|
||||
disclaimer in the documentation and/or other materials provided
|
||||
with the distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* @author Christian <c@ethdev.com>
|
||||
* @date 2014
|
||||
* Solidity scanner.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
namespace langutil
|
||||
{
|
||||
|
||||
/**
|
||||
* Bidirectional stream of characters.
|
||||
*
|
||||
* This CharStream is used by lexical analyzers as the source.
|
||||
*/
|
||||
class CharStream
|
||||
{
|
||||
public:
|
||||
CharStream(): m_position(0) {}
|
||||
explicit CharStream(std::string const& _source): m_source(_source), m_position(0) {}
|
||||
|
||||
int position() const { return m_position; }
|
||||
bool isPastEndOfInput(size_t _charsForward = 0) const { return (m_position + _charsForward) >= m_source.size(); }
|
||||
|
||||
char get(size_t _charsForward = 0) const { return m_source[m_position + _charsForward]; }
|
||||
char advanceAndGet(size_t _chars = 1);
|
||||
char rollback(size_t _amount);
|
||||
|
||||
void reset() { m_position = 0; }
|
||||
|
||||
std::string const& source() const { return m_source; }
|
||||
|
||||
///@{
|
||||
///@name Error printing helper functions
|
||||
/// Functions that help pretty-printing parse errors
|
||||
/// Do only use in error cases, they are quite expensive.
|
||||
std::string lineAtPosition(int _position) const;
|
||||
std::tuple<int, int> translatePositionToLineColumn(int _position) const;
|
||||
///@}
|
||||
|
||||
private:
|
||||
std::string m_source;
|
||||
size_t m_position;
|
||||
};
|
||||
|
||||
}
|
@ -20,13 +20,13 @@
|
||||
* Error helper class.
|
||||
*/
|
||||
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <libsolidity/ast/AST.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <liblangutil/SourceLocation.h>
|
||||
#include <memory>
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace dev::solidity;
|
||||
using namespace langutil;
|
||||
|
||||
ErrorReporter& ErrorReporter::operator=(ErrorReporter const& _errorReporter)
|
||||
{
|
@ -22,15 +22,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <libevmasm/SourceLocation.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
#include <liblangutil/SourceLocation.h>
|
||||
|
||||
namespace dev
|
||||
namespace langutil
|
||||
{
|
||||
namespace solidity
|
||||
{
|
||||
|
||||
class ASTNode;
|
||||
|
||||
class ErrorReporter
|
||||
{
|
||||
@ -120,7 +116,5 @@ private:
|
||||
const unsigned c_maxErrorsAllowed = 256;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -20,11 +20,11 @@
|
||||
* Solidity exception hierarchy.
|
||||
*/
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
|
||||
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)
|
@ -24,33 +24,33 @@
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <libdevcore/Exceptions.h>
|
||||
#include <libdevcore/Assertions.h>
|
||||
#include <libevmasm/SourceLocation.h>
|
||||
#include <liblangutil/SourceLocation.h>
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
namespace langutil
|
||||
{
|
||||
class Error;
|
||||
using ErrorList = std::vector<std::shared_ptr<Error const>>;
|
||||
|
||||
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<std::string, SourceLocation>;
|
||||
|
||||
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<errorSourceLocationInfo> infos;
|
||||
};
|
||||
|
||||
|
||||
using errinfo_sourceLocation = boost::error_info<struct tag_sourceLocation, SourceLocation>;
|
||||
using errinfo_secondarySourceLocation = boost::error_info<struct tag_secondarySourceLocation, SecondarySourceLocation>;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -20,13 +20,12 @@
|
||||
* Solidity parser shared functionality.
|
||||
*/
|
||||
|
||||
#include <libsolidity/parsing/ParserBase.h>
|
||||
#include <libsolidity/parsing/Scanner.h>
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <liblangutil/ParserBase.h>
|
||||
#include <liblangutil/Scanner.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace dev::solidity;
|
||||
using namespace langutil;
|
||||
|
||||
std::shared_ptr<string const> const& ParserBase::sourceName() const
|
||||
{
|
@ -22,12 +22,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <liblangutil/Token.h>
|
||||
#include <memory>
|
||||
#include <libsolidity/parsing/Token.h>
|
||||
#include <string>
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
namespace langutil
|
||||
{
|
||||
|
||||
class ErrorReporter;
|
||||
@ -90,4 +89,3 @@ protected:
|
||||
};
|
||||
|
||||
}
|
||||
}
|
@ -50,16 +50,14 @@
|
||||
* Solidity scanner.
|
||||
*/
|
||||
|
||||
#include <liblangutil/Exceptions.h>
|
||||
#include <liblangutil/Scanner.h>
|
||||
#include <algorithm>
|
||||
#include <tuple>
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <libsolidity/parsing/Scanner.h>
|
||||
|
||||
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<string const>(_sourceName);
|
||||
m_source = std::move(_source);
|
||||
m_sourceName = make_shared<string const>(std::move(_sourceName));
|
||||
reset();
|
||||
}
|
||||
|
||||
@ -866,55 +864,5 @@ tuple<Token, unsigned, unsigned> Scanner::scanIdentifierOrKeyword()
|
||||
return TokenTraits::fromIdentifierOrKeyword(m_nextToken.literal);
|
||||
}
|
||||
|
||||
char CharStream::advanceAndGet(size_t _chars)
|
||||
{
|
||||
if (isPastEndOfInput())
|
||||
return 0;
|
||||
m_position += _chars;
|
||||
if (isPastEndOfInput())
|
||||
return 0;
|
||||
return m_source[m_position];
|
||||
}
|
||||
|
||||
char CharStream::rollback(size_t _amount)
|
||||
{
|
||||
solAssert(m_position >= _amount, "");
|
||||
m_position -= _amount;
|
||||
return get();
|
||||
}
|
||||
|
||||
string CharStream::lineAtPosition(int _position) const
|
||||
{
|
||||
// if _position points to \n, it returns the line before the \n
|
||||
using size_type = string::size_type;
|
||||
size_type searchStart = min<size_type>(m_source.size(), _position);
|
||||
if (searchStart > 0)
|
||||
searchStart--;
|
||||
size_type lineStart = m_source.rfind('\n', searchStart);
|
||||
if (lineStart == string::npos)
|
||||
lineStart = 0;
|
||||
else
|
||||
lineStart++;
|
||||
return m_source.substr(lineStart, min(m_source.find('\n', lineStart),
|
||||
m_source.size()) - lineStart);
|
||||
}
|
||||
|
||||
tuple<int, int> CharStream::translatePositionToLineColumn(int _position) const
|
||||
{
|
||||
using size_type = string::size_type;
|
||||
size_type searchPosition = min<size_type>(m_source.size(), _position);
|
||||
int lineNumber = count(m_source.begin(), m_source.begin() + searchPosition, '\n');
|
||||
size_type lineStart;
|
||||
if (searchPosition == 0)
|
||||
lineStart = 0;
|
||||
else
|
||||
{
|
||||
lineStart = m_source.rfind('\n', searchPosition - 1);
|
||||
lineStart = lineStart == string::npos ? 0 : lineStart + 1;
|
||||
}
|
||||
return tuple<int, int>(lineNumber, searchPosition - lineStart);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -52,62 +52,29 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <liblangutil/Token.h>
|
||||
#include <liblangutil/CharStream.h>
|
||||
#include <liblangutil/SourceLocation.h>
|
||||
#include <libdevcore/Common.h>
|
||||
#include <libdevcore/CommonData.h>
|
||||
#include <libevmasm/SourceLocation.h>
|
||||
#include <libsolidity/parsing/Token.h>
|
||||
|
||||
namespace dev
|
||||
namespace langutil
|
||||
{
|
||||
namespace solidity
|
||||
{
|
||||
|
||||
|
||||
class AstRawString;
|
||||
class AstValueFactory;
|
||||
class ParserRecorder;
|
||||
|
||||
class CharStream
|
||||
{
|
||||
public:
|
||||
CharStream(): m_position(0) {}
|
||||
explicit CharStream(std::string const& _source): m_source(_source), m_position(0) {}
|
||||
int position() const { return m_position; }
|
||||
bool isPastEndOfInput(size_t _charsForward = 0) const { return (m_position + _charsForward) >= m_source.size(); }
|
||||
char get(size_t _charsForward = 0) const { return m_source[m_position + _charsForward]; }
|
||||
char advanceAndGet(size_t _chars = 1);
|
||||
char rollback(size_t _amount);
|
||||
|
||||
void reset() { m_position = 0; }
|
||||
|
||||
std::string const& source() const { return m_source; }
|
||||
|
||||
///@{
|
||||
///@name Error printing helper functions
|
||||
/// Functions that help pretty-printing parse errors
|
||||
/// Do only use in error cases, they are quite expensive.
|
||||
std::string lineAtPosition(int _position) const;
|
||||
std::tuple<int, int> translatePositionToLineColumn(int _position) const;
|
||||
///@}
|
||||
|
||||
private:
|
||||
std::string m_source;
|
||||
size_t m_position;
|
||||
};
|
||||
|
||||
|
||||
|
||||
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();
|
||||
|
||||
@ -246,4 +213,3 @@ private:
|
||||
};
|
||||
|
||||
}
|
||||
}
|
@ -22,13 +22,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libdevcore/Common.h> // defines noexcept macro for MSVC
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
#include <tuple>
|
||||
#include <libdevcore/Common.h> // defines noexcept macro for MSVC
|
||||
|
||||
namespace dev
|
||||
namespace langutil
|
||||
{
|
||||
|
||||
/**
|
@ -40,15 +40,13 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with solidity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include <map>
|
||||
#include <libsolidity/parsing/Token.h>
|
||||
#include <liblangutil/Token.h>
|
||||
#include <boost/range/iterator_range.hpp>
|
||||
#include <map>
|
||||
|
||||
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<Token, unsigned int, unsigned int> fromIdentifierOrKeyword(string const& _
|
||||
|
||||
}
|
||||
}
|
||||
}
|
378
liblangutil/Token.h
Normal file
378
liblangutil/Token.h
Normal file
@ -0,0 +1,378 @@
|
||||
// Copyright 2006-2012, the V8 project authors. All rights reserved.
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials provided
|
||||
// with the distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived
|
||||
// from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// Modifications as part of solidity under the following license:
|
||||
//
|
||||
// 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libdevcore/Common.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
#include <liblangutil/UndefMacros.h>
|
||||
|
||||
#include <iosfwd>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
|
||||
namespace langutil
|
||||
{
|
||||
|
||||
// TOKEN_LIST takes a list of 3 macros M, all of which satisfy the
|
||||
// same signature M(name, string, precedence), where name is the
|
||||
// symbolic token name, string is the corresponding syntactic symbol
|
||||
// (or NULL, for literals), and precedence is the precedence (or 0).
|
||||
// The parameters are invoked for token categories as follows:
|
||||
//
|
||||
// T: Non-keyword tokens
|
||||
// K: Keyword tokens
|
||||
|
||||
// IGNORE_TOKEN is a convenience macro that can be supplied as
|
||||
// an argument (at any position) for a TOKEN_LIST call. It does
|
||||
// nothing with tokens belonging to the respective category.
|
||||
|
||||
#define IGNORE_TOKEN(name, string, precedence)
|
||||
|
||||
#define TOKEN_LIST(T, K) \
|
||||
/* End of source indicator. */ \
|
||||
T(EOS, "EOS", 0) \
|
||||
\
|
||||
/* Punctuators (ECMA-262, section 7.7, page 15). */ \
|
||||
T(LParen, "(", 0) \
|
||||
T(RParen, ")", 0) \
|
||||
T(LBrack, "[", 0) \
|
||||
T(RBrack, "]", 0) \
|
||||
T(LBrace, "{", 0) \
|
||||
T(RBrace, "}", 0) \
|
||||
T(Colon, ":", 0) \
|
||||
T(Semicolon, ";", 0) \
|
||||
T(Period, ".", 0) \
|
||||
T(Conditional, "?", 3) \
|
||||
T(Arrow, "=>", 0) \
|
||||
\
|
||||
/* Assignment operators. */ \
|
||||
/* IsAssignmentOp() relies on this block of enum values being */ \
|
||||
/* contiguous and sorted in the same order!*/ \
|
||||
T(Assign, "=", 2) \
|
||||
/* The following have to be in exactly the same order as the simple binary operators*/ \
|
||||
T(AssignBitOr, "|=", 2) \
|
||||
T(AssignBitXor, "^=", 2) \
|
||||
T(AssignBitAnd, "&=", 2) \
|
||||
T(AssignShl, "<<=", 2) \
|
||||
T(AssignSar, ">>=", 2) \
|
||||
T(AssignShr, ">>>=", 2) \
|
||||
T(AssignAdd, "+=", 2) \
|
||||
T(AssignSub, "-=", 2) \
|
||||
T(AssignMul, "*=", 2) \
|
||||
T(AssignDiv, "/=", 2) \
|
||||
T(AssignMod, "%=", 2) \
|
||||
\
|
||||
/* Binary operators sorted by precedence. */ \
|
||||
/* IsBinaryOp() relies on this block of enum values */ \
|
||||
/* being contiguous and sorted in the same order! */ \
|
||||
T(Comma, ",", 1) \
|
||||
T(Or, "||", 4) \
|
||||
T(And, "&&", 5) \
|
||||
T(BitOr, "|", 8) \
|
||||
T(BitXor, "^", 9) \
|
||||
T(BitAnd, "&", 10) \
|
||||
T(SHL, "<<", 11) \
|
||||
T(SAR, ">>", 11) \
|
||||
T(SHR, ">>>", 11) \
|
||||
T(Add, "+", 12) \
|
||||
T(Sub, "-", 12) \
|
||||
T(Mul, "*", 13) \
|
||||
T(Div, "/", 13) \
|
||||
T(Mod, "%", 13) \
|
||||
T(Exp, "**", 14) \
|
||||
\
|
||||
/* Compare operators sorted by precedence. */ \
|
||||
/* IsCompareOp() relies on this block of enum values */ \
|
||||
/* being contiguous and sorted in the same order! */ \
|
||||
T(Equal, "==", 6) \
|
||||
T(NotEqual, "!=", 6) \
|
||||
T(LessThan, "<", 7) \
|
||||
T(GreaterThan, ">", 7) \
|
||||
T(LessThanOrEqual, "<=", 7) \
|
||||
T(GreaterThanOrEqual, ">=", 7) \
|
||||
\
|
||||
/* Unary operators. */ \
|
||||
/* IsUnaryOp() relies on this block of enum values */ \
|
||||
/* being contiguous and sorted in the same order! */ \
|
||||
T(Not, "!", 0) \
|
||||
T(BitNot, "~", 0) \
|
||||
T(Inc, "++", 0) \
|
||||
T(Dec, "--", 0) \
|
||||
K(Delete, "delete", 0) \
|
||||
\
|
||||
/* Keywords */ \
|
||||
K(Anonymous, "anonymous", 0) \
|
||||
K(As, "as", 0) \
|
||||
K(Assembly, "assembly", 0) \
|
||||
K(Break, "break", 0) \
|
||||
K(Constant, "constant", 0) \
|
||||
K(Constructor, "constructor", 0) \
|
||||
K(Continue, "continue", 0) \
|
||||
K(Contract, "contract", 0) \
|
||||
K(Do, "do", 0) \
|
||||
K(Else, "else", 0) \
|
||||
K(Enum, "enum", 0) \
|
||||
K(Emit, "emit", 0) \
|
||||
K(Event, "event", 0) \
|
||||
K(External, "external", 0) \
|
||||
K(For, "for", 0) \
|
||||
K(Function, "function", 0) \
|
||||
K(Hex, "hex", 0) \
|
||||
K(If, "if", 0) \
|
||||
K(Indexed, "indexed", 0) \
|
||||
K(Interface, "interface", 0) \
|
||||
K(Internal, "internal", 0) \
|
||||
K(Import, "import", 0) \
|
||||
K(Is, "is", 0) \
|
||||
K(Library, "library", 0) \
|
||||
K(Mapping, "mapping", 0) \
|
||||
K(Memory, "memory", 0) \
|
||||
K(Modifier, "modifier", 0) \
|
||||
K(New, "new", 0) \
|
||||
K(Payable, "payable", 0) \
|
||||
K(Public, "public", 0) \
|
||||
K(Pragma, "pragma", 0) \
|
||||
K(Private, "private", 0) \
|
||||
K(Pure, "pure", 0) \
|
||||
K(Return, "return", 0) \
|
||||
K(Returns, "returns", 0) \
|
||||
K(Storage, "storage", 0) \
|
||||
K(CallData, "calldata", 0) \
|
||||
K(Struct, "struct", 0) \
|
||||
K(Throw, "throw", 0) \
|
||||
K(Using, "using", 0) \
|
||||
K(Var, "var", 0) \
|
||||
K(View, "view", 0) \
|
||||
K(While, "while", 0) \
|
||||
\
|
||||
/* Ether subdenominations */ \
|
||||
K(SubWei, "wei", 0) \
|
||||
K(SubSzabo, "szabo", 0) \
|
||||
K(SubFinney, "finney", 0) \
|
||||
K(SubEther, "ether", 0) \
|
||||
K(SubSecond, "seconds", 0) \
|
||||
K(SubMinute, "minutes", 0) \
|
||||
K(SubHour, "hours", 0) \
|
||||
K(SubDay, "days", 0) \
|
||||
K(SubWeek, "weeks", 0) \
|
||||
K(SubYear, "years", 0) \
|
||||
/* type keywords*/ \
|
||||
K(Int, "int", 0) \
|
||||
K(UInt, "uint", 0) \
|
||||
K(Bytes, "bytes", 0) \
|
||||
K(Byte, "byte", 0) \
|
||||
K(String, "string", 0) \
|
||||
K(Address, "address", 0) \
|
||||
K(Bool, "bool", 0) \
|
||||
K(Fixed, "fixed", 0) \
|
||||
K(UFixed, "ufixed", 0) \
|
||||
T(IntM, "intM", 0) \
|
||||
T(UIntM, "uintM", 0) \
|
||||
T(BytesM, "bytesM", 0) \
|
||||
T(FixedMxN, "fixedMxN", 0) \
|
||||
T(UFixedMxN, "ufixedMxN", 0) \
|
||||
T(TypesEnd, NULL, 0) /* used as type enum end marker */ \
|
||||
\
|
||||
/* Literals */ \
|
||||
K(TrueLiteral, "true", 0) \
|
||||
K(FalseLiteral, "false", 0) \
|
||||
T(Number, NULL, 0) \
|
||||
T(StringLiteral, NULL, 0) \
|
||||
T(CommentLiteral, NULL, 0) \
|
||||
\
|
||||
/* Identifiers (not keywords or future reserved words). */ \
|
||||
T(Identifier, NULL, 0) \
|
||||
\
|
||||
/* Keywords reserved for future use. */ \
|
||||
K(Abstract, "abstract", 0) \
|
||||
K(After, "after", 0) \
|
||||
K(Alias, "alias", 0) \
|
||||
K(Apply, "apply", 0) \
|
||||
K(Auto, "auto", 0) \
|
||||
K(Case, "case", 0) \
|
||||
K(Catch, "catch", 0) \
|
||||
K(CopyOf, "copyof", 0) \
|
||||
K(Default, "default", 0) \
|
||||
K(Define, "define", 0) \
|
||||
K(Final, "final", 0) \
|
||||
K(Immutable, "immutable", 0) \
|
||||
K(Implements, "implements", 0) \
|
||||
K(In, "in", 0) \
|
||||
K(Inline, "inline", 0) \
|
||||
K(Let, "let", 0) \
|
||||
K(Macro, "macro", 0) \
|
||||
K(Match, "match", 0) \
|
||||
K(Mutable, "mutable", 0) \
|
||||
K(NullLiteral, "null", 0) \
|
||||
K(Of, "of", 0) \
|
||||
K(Override, "override", 0) \
|
||||
K(Partial, "partial", 0) \
|
||||
K(Promise, "promise", 0) \
|
||||
K(Reference, "reference", 0) \
|
||||
K(Relocatable, "relocatable", 0) \
|
||||
K(Sealed, "sealed", 0) \
|
||||
K(Sizeof, "sizeof", 0) \
|
||||
K(Static, "static", 0) \
|
||||
K(Supports, "supports", 0) \
|
||||
K(Switch, "switch", 0) \
|
||||
K(Try, "try", 0) \
|
||||
K(Type, "type", 0) \
|
||||
K(Typedef, "typedef", 0) \
|
||||
K(TypeOf, "typeof", 0) \
|
||||
K(Unchecked, "unchecked", 0) \
|
||||
\
|
||||
/* Illegal token - not able to scan. */ \
|
||||
T(Illegal, "ILLEGAL", 0) \
|
||||
/* Illegal hex token */ \
|
||||
T(IllegalHex, "ILLEGAL_HEX", 0) \
|
||||
\
|
||||
/* Scanner-internal use only. */ \
|
||||
T(Whitespace, NULL, 0)
|
||||
|
||||
// All token values.
|
||||
// attention! msvc issue:
|
||||
// http://stackoverflow.com/questions/9567868/compile-errors-after-adding-v8-to-my-project-c2143-c2059
|
||||
// @todo: avoid TOKEN_LIST macro
|
||||
enum class Token : unsigned int {
|
||||
#define T(name, string, precedence) name,
|
||||
TOKEN_LIST(T, T)
|
||||
NUM_TOKENS
|
||||
#undef T
|
||||
};
|
||||
|
||||
namespace TokenTraits
|
||||
{
|
||||
constexpr size_t count() { return static_cast<size_t>(Token::NUM_TOKENS); }
|
||||
|
||||
// Predicates
|
||||
constexpr bool isElementaryTypeName(Token tok) { return Token::Int <= tok && tok < Token::TypesEnd; }
|
||||
constexpr bool isAssignmentOp(Token tok) { return Token::Assign <= tok && tok <= Token::AssignMod; }
|
||||
constexpr bool isBinaryOp(Token op) { return Token::Comma <= op && op <= Token::Exp; }
|
||||
constexpr bool isCommutativeOp(Token op) { return op == Token::BitOr || op == Token::BitXor || op == Token::BitAnd ||
|
||||
op == Token::Add || op == Token::Mul || op == Token::Equal || op == Token::NotEqual; }
|
||||
constexpr bool isArithmeticOp(Token op) { return Token::Add <= op && op <= Token::Exp; }
|
||||
constexpr bool isCompareOp(Token op) { return Token::Equal <= op && op <= Token::GreaterThanOrEqual; }
|
||||
|
||||
constexpr bool isBitOp(Token op) { return (Token::BitOr <= op && op <= Token::BitAnd) || op == Token::BitNot; }
|
||||
constexpr bool isBooleanOp(Token op) { return (Token::Or <= op && op <= Token::And) || op == Token::Not; }
|
||||
constexpr bool isUnaryOp(Token op) { return (Token::Not <= op && op <= Token::Delete) || op == Token::Add || op == Token::Sub; }
|
||||
constexpr bool isCountOp(Token op) { return op == Token::Inc || op == Token::Dec; }
|
||||
constexpr bool isShiftOp(Token op) { return (Token::SHL <= op) && (op <= Token::SHR); }
|
||||
constexpr bool isVariableVisibilitySpecifier(Token op) { return op == Token::Public || op == Token::Private || op == Token::Internal; }
|
||||
constexpr bool isVisibilitySpecifier(Token op) { return isVariableVisibilitySpecifier(op) || op == Token::External; }
|
||||
constexpr bool isLocationSpecifier(Token op) { return op == Token::Memory || op == Token::Storage || op == Token::CallData; }
|
||||
|
||||
constexpr bool isStateMutabilitySpecifier(Token op, bool _allowConstant = true)
|
||||
{
|
||||
return (op == Token::Constant && _allowConstant)
|
||||
|| op == Token::Pure || op == Token::View || op == Token::Payable;
|
||||
}
|
||||
|
||||
constexpr bool isEtherSubdenomination(Token op) { return op == Token::SubWei || op == Token::SubSzabo || op == Token::SubFinney || op == Token::SubEther; }
|
||||
constexpr bool isTimeSubdenomination(Token op) { return op == Token::SubSecond || op == Token::SubMinute || op == Token::SubHour || op == Token::SubDay || op == Token::SubWeek || op == Token::SubYear; }
|
||||
constexpr bool isReservedKeyword(Token op) { return (Token::Abstract <= op && op <= Token::Unchecked); }
|
||||
|
||||
inline Token AssignmentToBinaryOp(Token op)
|
||||
{
|
||||
solAssert(isAssignmentOp(op) && op != Token::Assign, "");
|
||||
return static_cast<Token>(static_cast<int>(op) + (static_cast<int>(Token::BitOr) - static_cast<int>(Token::AssignBitOr)));
|
||||
}
|
||||
|
||||
// @returns the precedence > 0 for binary and compare
|
||||
// operators; returns 0 otherwise.
|
||||
int precedence(Token tok);
|
||||
|
||||
std::tuple<Token, unsigned int, unsigned int> fromIdentifierOrKeyword(std::string const& _literal);
|
||||
|
||||
// @returns a string corresponding to the C++ token name
|
||||
// (e.g. "LT" for the token LT).
|
||||
char const* name(Token tok);
|
||||
|
||||
// @returns a string corresponding to the JS token string
|
||||
// (.e., "<" for the token LT) or NULL if the token doesn't
|
||||
// have a (unique) string (e.g. an IDENTIFIER).
|
||||
char const* toString(Token tok);
|
||||
|
||||
std::string friendlyName(Token tok);
|
||||
}
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, Token token)
|
||||
{
|
||||
os << TokenTraits::friendlyName(token);
|
||||
return os;
|
||||
}
|
||||
|
||||
class ElementaryTypeNameToken
|
||||
{
|
||||
public:
|
||||
ElementaryTypeNameToken(Token _token, unsigned const& _firstNumber, unsigned const& _secondNumber)
|
||||
{
|
||||
assertDetails(_token, _firstNumber, _secondNumber);
|
||||
}
|
||||
|
||||
unsigned int firstNumber() const { return m_firstNumber; }
|
||||
unsigned int secondNumber() const { return m_secondNumber; }
|
||||
Token token() const { return m_token; }
|
||||
|
||||
///if tokValue is set to true, then returns the actual token type name, otherwise, returns full type
|
||||
std::string toString(bool const& tokenValue = false) const
|
||||
{
|
||||
std::string name = TokenTraits::toString(m_token);
|
||||
if (tokenValue || (firstNumber() == 0 && secondNumber() == 0))
|
||||
return name;
|
||||
solAssert(name.size() >= 3, "Token name size should be greater than 3. Should not reach here.");
|
||||
if (m_token == Token::FixedMxN || m_token == Token::UFixedMxN)
|
||||
return name.substr(0, name.size() - 3) + std::to_string(m_firstNumber) + "x" + std::to_string(m_secondNumber);
|
||||
else
|
||||
return name.substr(0, name.size() - 1) + std::to_string(m_firstNumber);
|
||||
}
|
||||
|
||||
private:
|
||||
Token m_token;
|
||||
unsigned int m_firstNumber;
|
||||
unsigned int m_secondNumber;
|
||||
/// throws if type is not properly sized
|
||||
void assertDetails(Token _baseType, unsigned const& _first, unsigned const& _second);
|
||||
};
|
||||
|
||||
}
|
@ -23,7 +23,7 @@
|
||||
|
||||
#include <libdevcore/Common.h>
|
||||
|
||||
#include <libsolidity/interface/EVMVersion.h>
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -26,7 +26,7 @@ if (NOT (${Z3_FOUND} OR ${CVC4_FOUND}))
|
||||
endif()
|
||||
|
||||
add_library(solidity ${sources} ${headers})
|
||||
target_link_libraries(solidity PUBLIC evmasm devcore ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY})
|
||||
target_link_libraries(solidity PUBLIC evmasm langutil devcore ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY})
|
||||
|
||||
if (${Z3_FOUND})
|
||||
target_link_libraries(solidity PUBLIC ${Z3_LIBRARY})
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include <libsolidity/analysis/ConstantEvaluator.h>
|
||||
#include <libsolidity/ast/AST.h>
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
|
@ -24,12 +24,16 @@
|
||||
|
||||
#include <libsolidity/ast/ASTVisitor.h>
|
||||
|
||||
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<std::map<ASTNode const*, TypePointer>> _types = std::make_shared<std::map<ASTNode const*, TypePointer>>()
|
||||
):
|
||||
@ -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<std::map<ASTNode const*, TypePointer>> m_types;
|
||||
|
@ -16,8 +16,10 @@
|
||||
*/
|
||||
|
||||
#include <libsolidity/analysis/ControlFlowAnalyzer.h>
|
||||
#include <liblangutil/SourceLocation.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
|
||||
bool ControlFlowAnalyzer::analyze(ASTNode const& _astRoot)
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include <libsolidity/ast/AST.h>
|
||||
#include <libsolidity/ast/ASTVisitor.h>
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
@ -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
|
||||
|
@ -23,11 +23,12 @@
|
||||
|
||||
#include <libsolidity/analysis/DocStringAnalyser.h>
|
||||
#include <libsolidity/ast/AST.h>
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <libsolidity/parsing/DocStringParser.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
|
||||
bool DocStringAnalyser::analyseDocStrings(SourceUnit const& _sourceUnit)
|
||||
|
@ -25,13 +25,16 @@
|
||||
|
||||
#include <libsolidity/ast/ASTVisitor.h>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -24,12 +24,13 @@
|
||||
|
||||
#include <libsolidity/ast/AST.h>
|
||||
#include <libsolidity/analysis/TypeChecker.h>
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <libdevcore/StringUtils.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
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.
|
||||
|
@ -30,13 +30,16 @@
|
||||
#include <libsolidity/ast/ASTVisitor.h>
|
||||
#include <libsolidity/ast/ASTAnnotations.h>
|
||||
|
||||
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<Declaration const*> const& _globals,
|
||||
std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>>& _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<ASTNode const*, std::shared_ptr<DeclarationContainer>>& m_scopes;
|
||||
|
||||
DeclarationContainer* m_currentScope = nullptr;
|
||||
ErrorReporter& m_errorReporter;
|
||||
langutil::ErrorReporter& m_errorReporter;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -142,7 +145,7 @@ public:
|
||||
DeclarationRegistrationHelper(
|
||||
std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>>& _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<ASTNode const*, std::shared_ptr<DeclarationContainer>>& m_scopes;
|
||||
ASTNode const* m_currentScope = nullptr;
|
||||
VariableScope* m_currentFunction = nullptr;
|
||||
ErrorReporter& m_errorReporter;
|
||||
langutil::ErrorReporter& m_errorReporter;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include <libsolidity/analysis/PostTypeChecker.h>
|
||||
#include <libsolidity/ast/AST.h>
|
||||
#include <libsolidity/analysis/SemVerHandler.h>
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <libsolidity/interface/Version.h>
|
||||
|
||||
#include <libdevcore/Algorithms.h>
|
||||
@ -29,6 +29,7 @@
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
|
||||
|
||||
|
@ -23,13 +23,17 @@
|
||||
#include <libsolidity/ast/ASTForward.h>
|
||||
#include <libsolidity/ast/ASTVisitor.h>
|
||||
|
||||
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<VariableDeclaration const*> m_constVariables; ///< Required for determinism.
|
||||
|
@ -23,12 +23,12 @@
|
||||
#include <libsolidity/analysis/ReferencesResolver.h>
|
||||
#include <libsolidity/ast/AST.h>
|
||||
#include <libsolidity/analysis/NameAndTypeResolver.h>
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
#include <libsolidity/analysis/ConstantEvaluator.h>
|
||||
#include <libsolidity/inlineasm/AsmAnalysis.h>
|
||||
#include <libsolidity/inlineasm/AsmAnalysisInfo.h>
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
|
||||
#include <libdevcore/StringUtils.h>
|
||||
|
||||
@ -36,9 +36,12 @@
|
||||
#include <boost/range/adaptor/transformed.hpp>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -28,12 +28,17 @@
|
||||
#include <libsolidity/ast/ASTVisitor.h>
|
||||
#include <libsolidity/ast/ASTAnnotations.h>
|
||||
|
||||
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<ParameterList const*> m_returnParameters;
|
||||
|
@ -22,8 +22,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <libsolidity/parsing/Token.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace dev
|
||||
{
|
||||
|
@ -23,11 +23,12 @@
|
||||
#include <libsolidity/analysis/StaticAnalyzer.h>
|
||||
#include <libsolidity/analysis/ConstantEvaluator.h>
|
||||
#include <libsolidity/ast/AST.h>
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <memory>
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
|
||||
bool StaticAnalyzer::analyze(SourceUnit const& _sourceUnit)
|
||||
|
@ -28,6 +28,11 @@
|
||||
#include <libsolidity/ast/ASTForward.h>
|
||||
#include <libsolidity/ast/ASTVisitor.h>
|
||||
|
||||
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<StructDefinition const*>& _structsSeen);
|
||||
|
||||
ErrorReporter& m_errorReporter;
|
||||
langutil::ErrorReporter& m_errorReporter;
|
||||
|
||||
/// Flag that indicates whether the current contract definition is a library.
|
||||
bool m_library = false;
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include <libsolidity/ast/AST.h>
|
||||
#include <libsolidity/ast/ExperimentalFeatures.h>
|
||||
#include <libsolidity/analysis/SemVerHandler.h>
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <libsolidity/interface/Version.h>
|
||||
#include <boost/algorithm/cxx11/all_of.hpp>
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
|
||||
|
||||
|
@ -23,6 +23,11 @@
|
||||
#include <libsolidity/ast/ASTForward.h>
|
||||
#include <libsolidity/ast/ASTVisitor.h>
|
||||
|
||||
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;
|
||||
|
@ -30,11 +30,12 @@
|
||||
#include <libsolidity/inlineasm/AsmAnalysis.h>
|
||||
#include <libsolidity/inlineasm/AsmAnalysisInfo.h>
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <libdevcore/Algorithms.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
|
||||
namespace
|
||||
|
@ -22,20 +22,23 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libsolidity/interface/EVMVersion.h>
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
|
||||
#include <libsolidity/ast/Types.h>
|
||||
#include <libsolidity/ast/ASTAnnotations.h>
|
||||
#include <libsolidity/ast/ASTForward.h>
|
||||
#include <libsolidity/ast/ASTVisitor.h>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -22,10 +22,13 @@
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
#include <libsolidity/ast/ExperimentalFeatures.h>
|
||||
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
|
||||
#include <functional>
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
|
||||
namespace
|
||||
|
@ -21,11 +21,15 @@
|
||||
#include <libsolidity/ast/ASTForward.h>
|
||||
#include <libsolidity/ast/ASTVisitor.h>
|
||||
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
namespace langutil
|
||||
{
|
||||
class ErrorReporter;
|
||||
struct SourceLocation;
|
||||
}
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
@ -34,7 +38,7 @@ namespace solidity
|
||||
class ViewPureChecker: private ASTConstVisitor
|
||||
{
|
||||
public:
|
||||
ViewPureChecker(std::vector<std::shared_ptr<ASTNode>> const& _ast, ErrorReporter& _errorReporter):
|
||||
ViewPureChecker(std::vector<std::shared_ptr<ASTNode>> 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<SourceLocation> const& _nestedLocation = {}
|
||||
langutil::SourceLocation const& _location,
|
||||
boost::optional<langutil::SourceLocation> const& _nestedLocation = {}
|
||||
);
|
||||
|
||||
std::vector<std::shared_ptr<ASTNode>> 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<ModifierDefinition const*, MutabilityAndLocation> m_inferredMutability;
|
||||
};
|
||||
|
@ -23,13 +23,13 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <libsolidity/ast/ASTForward.h>
|
||||
#include <libsolidity/parsing/Token.h>
|
||||
#include <libsolidity/ast/ASTForward.h>
|
||||
#include <libsolidity/ast/Types.h>
|
||||
#include <libsolidity/ast/ASTAnnotations.h>
|
||||
#include <libsolidity/ast/ASTEnums.h>
|
||||
|
||||
#include <libevmasm/SourceLocation.h>
|
||||
#include <liblangutil/SourceLocation.h>
|
||||
#include <libevmasm/Instruction.h>
|
||||
|
||||
#include <libdevcore/FixedHash.h>
|
||||
@ -58,6 +58,8 @@ class ASTConstVisitor;
|
||||
class ASTNode: private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
using SourceLocation = langutil::SourceLocation;
|
||||
|
||||
explicit ASTNode(SourceLocation const& _location);
|
||||
virtual ~ASTNode();
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <libsolidity/inlineasm/AsmPrinter.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace langutil;
|
||||
|
||||
namespace dev
|
||||
{
|
||||
|
@ -25,10 +25,15 @@
|
||||
#include <ostream>
|
||||
#include <stack>
|
||||
#include <libsolidity/ast/ASTVisitor.h>
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
#include <libsolidity/ast/ASTAnnotations.h>
|
||||
#include <json/json.h>
|
||||
|
||||
namespace langutil
|
||||
{
|
||||
struct SourceLocation;
|
||||
}
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
@ -120,7 +125,7 @@ private:
|
||||
std::string const& _nodeName,
|
||||
std::vector<std::pair<std::string, Json::Value>>&& _attributes
|
||||
);
|
||||
std::string sourceLocationToString(SourceLocation const& _location) const;
|
||||
std::string sourceLocationToString(langutil::SourceLocation const& _location) const;
|
||||
static std::string namePathToString(std::vector<ASTString> const& _namePath);
|
||||
static Json::Value idOrNull(ASTNode const* _pt)
|
||||
{
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace langutil;
|
||||
|
||||
namespace dev
|
||||
{
|
||||
|
@ -45,6 +45,7 @@
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
|
||||
namespace
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
#include <libsolidity/ast/ASTForward.h>
|
||||
#include <libsolidity/ast/ASTEnums.h>
|
||||
#include <libsolidity/parsing/Token.h>
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libsolidity/interface/EVMVersion.h>
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
|
||||
#include <libsolidity/ast/ASTForward.h>
|
||||
|
||||
|
@ -25,11 +25,12 @@
|
||||
#include <libsolidity/codegen/CompilerContext.h>
|
||||
#include <libsolidity/codegen/CompilerUtils.h>
|
||||
#include <libsolidity/ast/Types.h>
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
#include <libsolidity/codegen/LValue.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace solidity;
|
||||
|
||||
void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType const& _sourceType) const
|
||||
|
@ -23,7 +23,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <libsolidity/codegen/CompilerContext.h>
|
||||
#include <libsolidity/interface/EVMVersion.h>
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
|
||||
#include <libevmasm/Assembly.h>
|
||||
|
||||
|
@ -25,9 +25,10 @@
|
||||
#include <libsolidity/ast/AST.h>
|
||||
#include <libsolidity/codegen/Compiler.h>
|
||||
#include <libsolidity/interface/Version.h>
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <liblangutil/Scanner.h>
|
||||
#include <libsolidity/interface/SourceReferenceFormatter.h>
|
||||
#include <libsolidity/parsing/Scanner.h>
|
||||
#include <liblangutil/Scanner.h>
|
||||
#include <libsolidity/inlineasm/AsmParser.h>
|
||||
#include <libsolidity/inlineasm/AsmCodeGen.h>
|
||||
#include <libsolidity/inlineasm/AsmAnalysis.h>
|
||||
@ -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<Scanner>(CharStream(_assembly), "--CODEGEN--");
|
||||
auto scanner = make_shared<langutil::Scanner>(langutil::CharStream(_assembly), "--CODEGEN--");
|
||||
auto parserResult = assembly::Parser(errorReporter, assembly::AsmFlavour::Strict).parse(scanner, false);
|
||||
#ifdef SOL_OUTPUT_ASM
|
||||
cout << assembly::AsmPrinter()(*parserResult) << endl;
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
#include <libsolidity/codegen/ABIFunctions.h>
|
||||
|
||||
#include <libsolidity/interface/EVMVersion.h>
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
|
||||
#include <libsolidity/ast/ASTForward.h>
|
||||
#include <libsolidity/ast/Types.h>
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <libdevcore/Whiskers.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace langutil;
|
||||
|
||||
namespace dev
|
||||
{
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <libsolidity/codegen/ContractCompiler.h>
|
||||
#include <libsolidity/inlineasm/AsmCodeGen.h>
|
||||
#include <libsolidity/ast/AST.h>
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <libsolidity/codegen/ExpressionCompiler.h>
|
||||
#include <libsolidity/codegen/CompilerUtils.h>
|
||||
|
||||
@ -37,6 +37,7 @@
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
|
||||
namespace
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include <libdevcore/Whiskers.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace langutil;
|
||||
|
||||
namespace dev
|
||||
{
|
||||
|
@ -25,10 +25,10 @@
|
||||
#include <memory>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <libdevcore/Common.h>
|
||||
#include <libevmasm/SourceLocation.h>
|
||||
#include <liblangutil/SourceLocation.h>
|
||||
#include <libsolidity/ast/ASTVisitor.h>
|
||||
#include <libsolidity/codegen/LValue.h>
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
|
||||
namespace dev {
|
||||
namespace eth
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace solidity;
|
||||
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <libevmasm/SourceLocation.h>
|
||||
#include <liblangutil/SourceLocation.h>
|
||||
#include <libsolidity/codegen/ArrayUtils.h>
|
||||
|
||||
namespace dev
|
||||
@ -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<std::unique_ptr<LValue>>&& _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;
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#include <libsolidity/formal/CVC4Interface.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
|
||||
#include <libdevcore/CommonIO.h>
|
||||
|
||||
|
@ -22,13 +22,14 @@
|
||||
#include <libsolidity/formal/VariableUsage.h>
|
||||
#include <libsolidity/formal/SymbolicTypes.h>
|
||||
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
|
||||
#include <boost/range/adaptor/map.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
|
||||
SMTChecker::SMTChecker(ErrorReporter& _errorReporter, ReadCallback::Callback const& _readFileCallback):
|
||||
|
@ -25,26 +25,31 @@
|
||||
|
||||
#include <libsolidity/interface/ReadFile.h>
|
||||
|
||||
#include <libsolidity/parsing/Scanner.h>
|
||||
#include <liblangutil/Scanner.h>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
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<Scanner> const& _scanner);
|
||||
void analyze(SourceUnit const& _sources, std::shared_ptr<langutil::Scanner> 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<VariableDeclaration const*, int>;
|
||||
@ -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<smt::CheckResult, std::vector<std::string>>
|
||||
@ -200,8 +205,8 @@ private:
|
||||
/// Used to retrieve models.
|
||||
std::vector<Expression const*> m_uninterpretedTerms;
|
||||
std::vector<smt::Expression> m_pathConditions;
|
||||
ErrorReporter& m_errorReporter;
|
||||
std::shared_ptr<Scanner> m_scanner;
|
||||
langutil::ErrorReporter& m_errorReporter;
|
||||
std::shared_ptr<langutil::Scanner> m_scanner;
|
||||
|
||||
/// Stores the current path of function calls.
|
||||
std::vector<FunctionDefinition const*> m_functionPath;
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#include <libsolidity/formal/SMTLib2Interface.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
#include <libsolidity/interface/ReadFile.h>
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
#include <libsolidity/formal/SolverInterface.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
#include <libsolidity/interface/ReadFile.h>
|
||||
|
||||
#include <libdevcore/Common.h>
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
#include <libsolidity/interface/ReadFile.h>
|
||||
|
||||
#include <libdevcore/Common.h>
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#include <libsolidity/formal/Z3Interface.h>
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
|
||||
#include <libdevcore/CommonIO.h>
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <libsolidity/inlineasm/AsmScope.h>
|
||||
#include <libsolidity/inlineasm/AsmAnalysisInfo.h>
|
||||
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
|
||||
#include <boost/range/adaptor/reversed.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
@ -35,6 +35,7 @@
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
using namespace dev::solidity::assembly;
|
||||
|
||||
|
@ -20,8 +20,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <libsolidity/interface/EVMVersion.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
|
||||
#include <libsolidity/inlineasm/AsmScope.h>
|
||||
|
||||
@ -35,11 +35,16 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace langutil
|
||||
{
|
||||
class ErrorReporter;
|
||||
struct SourceLocation;
|
||||
}
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
{
|
||||
class ErrorReporter;
|
||||
namespace assembly
|
||||
{
|
||||
|
||||
@ -55,9 +60,9 @@ class AsmAnalyzer: public boost::static_visitor<bool>
|
||||
public:
|
||||
explicit AsmAnalyzer(
|
||||
AsmAnalysisInfo& _analysisInfo,
|
||||
ErrorReporter& _errorReporter,
|
||||
langutil::ErrorReporter& _errorReporter,
|
||||
EVMVersion _evmVersion,
|
||||
boost::optional<Error::Type> _errorTypeForLoose,
|
||||
boost::optional<langutil::Error::Type> _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<Scope::Variable const*> m_activeVariables;
|
||||
AsmAnalysisInfo& m_info;
|
||||
ErrorReporter& m_errorReporter;
|
||||
langutil::ErrorReporter& m_errorReporter;
|
||||
EVMVersion m_evmVersion;
|
||||
AsmFlavour m_flavour = AsmFlavour::Loose;
|
||||
boost::optional<Error::Type> m_errorTypeForLoose;
|
||||
boost::optional<langutil::Error::Type> m_errorTypeForLoose;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include <libsolidity/inlineasm/AsmAnalysisInfo.h>
|
||||
|
||||
#include <libevmasm/Assembly.h>
|
||||
#include <libevmasm/SourceLocation.h>
|
||||
#include <liblangutil/SourceLocation.h>
|
||||
#include <libevmasm/Instruction.h>
|
||||
|
||||
#include <libyul/backends/evm/AbstractAssembly.h>
|
||||
@ -46,6 +46,7 @@
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
using namespace dev::solidity::assembly;
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
#include <libsolidity/inlineasm/AsmDataForward.h>
|
||||
|
||||
#include <libevmasm/Instruction.h>
|
||||
#include <libevmasm/SourceLocation.h>
|
||||
#include <liblangutil/SourceLocation.h>
|
||||
|
||||
#include <libyul/YulString.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<TypedName>;
|
||||
|
||||
/// 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<Identifier> variableNames; std::shared_ptr<Expression> value; };
|
||||
struct Assignment { langutil::SourceLocation location; std::vector<Identifier> variableNames; std::shared_ptr<Expression> value; };
|
||||
/// Functional instruction, e.g. "mul(mload(20:u256), add(2:u256, x))"
|
||||
struct FunctionalInstruction { SourceLocation location; solidity::Instruction instruction; std::vector<Expression> arguments; };
|
||||
struct FunctionCall { SourceLocation location; Identifier functionName; std::vector<Expression> arguments; };
|
||||
struct FunctionalInstruction { langutil::SourceLocation location; solidity::Instruction instruction; std::vector<Expression> arguments; };
|
||||
struct FunctionCall { langutil::SourceLocation location; Identifier functionName; std::vector<Expression> 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<Expression> value; };
|
||||
struct VariableDeclaration { langutil::SourceLocation location; TypedNameList variables; std::shared_ptr<Expression> value; };
|
||||
/// Block that creates a scope (frees declared stack variables)
|
||||
struct Block { SourceLocation location; std::vector<Statement> statements; };
|
||||
struct Block { langutil::SourceLocation location; std::vector<Statement> 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<Expression> condition; Block body; };
|
||||
struct If { langutil::SourceLocation location; std::shared_ptr<Expression> condition; Block body; };
|
||||
/// Switch case or default case
|
||||
struct Case { SourceLocation location; std::shared_ptr<Literal> value; Block body; };
|
||||
struct Case { langutil::SourceLocation location; std::shared_ptr<Literal> value; Block body; };
|
||||
/// Switch statement
|
||||
struct Switch { SourceLocation location; std::shared_ptr<Expression> expression; std::vector<Case> cases; };
|
||||
struct ForLoop { SourceLocation location; Block pre; std::shared_ptr<Expression> condition; Block post; Block body; };
|
||||
struct Switch { langutil::SourceLocation location; std::shared_ptr<Expression> expression; std::vector<Case> cases; };
|
||||
struct ForLoop { langutil::SourceLocation location; Block pre; std::shared_ptr<Expression> condition; Block post; Block body; };
|
||||
|
||||
struct LocationExtractor: boost::static_visitor<SourceLocation>
|
||||
struct LocationExtractor: boost::static_visitor<langutil::SourceLocation>
|
||||
{
|
||||
template <class T> SourceLocation operator()(T const& _node) const
|
||||
template <class T> langutil::SourceLocation operator()(T const& _node) const
|
||||
{
|
||||
return _node.location;
|
||||
}
|
||||
};
|
||||
|
||||
/// Extracts the source location from an inline assembly node.
|
||||
template <class T> inline SourceLocation locationOf(T const& _node)
|
||||
template <class T> inline langutil::SourceLocation locationOf(T const& _node)
|
||||
{
|
||||
return boost::apply_visitor(LocationExtractor(), _node);
|
||||
}
|
||||
|
@ -21,8 +21,8 @@
|
||||
*/
|
||||
|
||||
#include <libsolidity/inlineasm/AsmParser.h>
|
||||
#include <libsolidity/parsing/Scanner.h>
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <liblangutil/Scanner.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
@ -31,6 +31,7 @@
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
using namespace dev::solidity::assembly;
|
||||
|
||||
|
@ -25,7 +25,9 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
#include <libsolidity/parsing/ParserBase.h>
|
||||
#include <liblangutil/SourceLocation.h>
|
||||
#include <liblangutil/Scanner.h>
|
||||
#include <liblangutil/ParserBase.h>
|
||||
|
||||
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<Block> parse(std::shared_ptr<Scanner> const& _scanner, bool _reuseScanner);
|
||||
std::shared_ptr<Block> parse(std::shared_ptr<langutil::Scanner> const& _scanner, bool _reuseScanner);
|
||||
|
||||
protected:
|
||||
using ElementaryOperation = boost::variant<assembly::Instruction, assembly::Literal, assembly::Identifier>;
|
||||
|
||||
/// Creates an inline assembly node with the given source location.
|
||||
template <class T> T createWithLocation(SourceLocation const& _loc = SourceLocation()) const
|
||||
template <class T> 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();
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include <libsolidity/inlineasm/AsmPrinter.h>
|
||||
#include <libsolidity/inlineasm/AsmData.h>
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
|
||||
#include <libdevcore/CommonData.h>
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
|
||||
#include <libyul/YulString.h>
|
||||
|
||||
|
@ -24,8 +24,8 @@
|
||||
#include <libsolidity/inlineasm/AsmScope.h>
|
||||
#include <libsolidity/inlineasm/AsmAnalysisInfo.h>
|
||||
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
|
||||
#include <libdevcore/CommonData.h>
|
||||
|
||||
@ -36,6 +36,7 @@
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
using namespace dev::solidity::assembly;
|
||||
|
||||
|
@ -27,12 +27,16 @@
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
namespace dev
|
||||
{
|
||||
struct SourceLocation;
|
||||
namespace solidity
|
||||
namespace langutil
|
||||
{
|
||||
class ErrorReporter;
|
||||
struct SourceLocation;
|
||||
}
|
||||
|
||||
namespace dev
|
||||
{
|
||||
namespace solidity
|
||||
{
|
||||
namespace assembly
|
||||
{
|
||||
|
||||
@ -47,7 +51,7 @@ struct AsmAnalysisInfo;
|
||||
class ScopeFiller: public boost::static_visitor<bool>
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#include <libsolidity/interface/AssemblyStack.h>
|
||||
|
||||
#include <libsolidity/parsing/Scanner.h>
|
||||
#include <liblangutil/Scanner.h>
|
||||
#include <libsolidity/inlineasm/AsmPrinter.h>
|
||||
#include <libsolidity/inlineasm/AsmParser.h>
|
||||
#include <libsolidity/inlineasm/AsmAnalysis.h>
|
||||
@ -36,6 +36,7 @@
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
|
||||
namespace
|
||||
|
@ -21,19 +21,23 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <libsolidity/interface/EVMVersion.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
|
||||
#include <libevmasm/LinkerObject.h>
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
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<Scanner> m_scanner;
|
||||
std::shared_ptr<langutil::Scanner> m_scanner;
|
||||
|
||||
bool m_analysisSuccessful = false;
|
||||
std::shared_ptr<assembly::Block> m_parserResult;
|
||||
std::shared_ptr<assembly::AsmAnalysisInfo> m_analysisInfo;
|
||||
ErrorList m_errors;
|
||||
ErrorReporter m_errorReporter;
|
||||
langutil::ErrorList m_errors;
|
||||
langutil::ErrorReporter m_errorReporter;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include <libsolidity/interface/Version.h>
|
||||
#include <libsolidity/analysis/SemVerHandler.h>
|
||||
#include <libsolidity/ast/AST.h>
|
||||
#include <libsolidity/parsing/Scanner.h>
|
||||
#include <liblangutil/Scanner.h>
|
||||
#include <libsolidity/parsing/Parser.h>
|
||||
#include <libsolidity/analysis/ControlFlowAnalyzer.h>
|
||||
#include <libsolidity/analysis/ControlFlowGraph.h>
|
||||
@ -58,6 +58,7 @@
|
||||
|
||||
using namespace std;
|
||||
using namespace dev;
|
||||
using namespace langutil;
|
||||
using namespace dev::solidity;
|
||||
|
||||
boost::optional<CompilerStack::Remapping> CompilerStack::parseRemapping(string const& _remapping)
|
||||
|
@ -23,11 +23,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libsolidity/interface/ErrorReporter.h>
|
||||
#include <libsolidity/interface/ReadFile.h>
|
||||
#include <libsolidity/interface/EVMVersion.h>
|
||||
|
||||
#include <libevmasm/SourceLocation.h>
|
||||
#include <liblangutil/ErrorReporter.h>
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
#include <liblangutil/SourceLocation.h>
|
||||
|
||||
#include <libevmasm/LinkerObject.h>
|
||||
|
||||
#include <libdevcore/Common.h>
|
||||
@ -43,6 +44,11 @@
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
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<std::string, unsigned> 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<int, int, int, int> positionFromSourceLocation(SourceLocation const& _sourceLocation) const;
|
||||
std::tuple<int, int, int, int> positionFromSourceLocation(langutil::SourceLocation const& _sourceLocation) const;
|
||||
|
||||
/// @returns a list of the contract names in the sources.
|
||||
std::vector<std::string> contractNames() const;
|
||||
@ -248,7 +252,7 @@ private:
|
||||
/// The state per source unit. Filled gradually during parsing.
|
||||
struct Source
|
||||
{
|
||||
std::shared_ptr<Scanner> scanner;
|
||||
std::shared_ptr<langutil::Scanner> scanner;
|
||||
std::shared_ptr<SourceUnit> ast;
|
||||
bool isLibrary = false;
|
||||
void reset() { scanner.reset(); ast.reset(); }
|
||||
@ -345,8 +349,8 @@ private:
|
||||
/// This is updated during compilation.
|
||||
std::map<ASTNode const*, std::shared_ptr<DeclarationContainer>> m_scopes;
|
||||
std::map<std::string const, Contract> m_contracts;
|
||||
ErrorList m_errorList;
|
||||
ErrorReporter m_errorReporter;
|
||||
langutil::ErrorList m_errorList;
|
||||
langutil::ErrorReporter m_errorReporter;
|
||||
bool m_metadataLiteralSources = false;
|
||||
State m_stackState = Empty;
|
||||
};
|
||||
|
@ -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(
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <libsolidity/interface/EVMVersion.h>
|
||||
#include <liblangutil/EVMVersion.h>
|
||||
|
||||
#include <libevmasm/GasMeter.h>
|
||||
#include <libevmasm/Assembly.h>
|
||||
|
@ -21,10 +21,11 @@
|
||||
*/
|
||||
|
||||
#include <libsolidity/interface/SourceReferenceFormatter.h>
|
||||
#include <libsolidity/parsing/Scanner.h>
|
||||
#include <libsolidity/interface/Exceptions.h>
|
||||
#include <liblangutil/Scanner.h>
|
||||
#include <liblangutil/Exceptions.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace langutil;
|
||||
|
||||
namespace dev
|
||||
{
|
||||
|
@ -25,7 +25,12 @@
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#include <functional>
|
||||
#include <libevmasm/SourceLocation.h>
|
||||
|
||||
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<Scanner const&(std::string const&)>;
|
||||
using ScannerFromSourceNameFun = std::function<langutil::Scanner const&(std::string const&)>;
|
||||
|
||||
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;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user