2018-11-04 08:34:21 +00:00
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
*/
|
2020-07-17 14:54:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2018-11-04 08:34:21 +00:00
|
|
|
/**
|
|
|
|
* Parser for Yul code and data object container.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <libyul/YulString.h>
|
|
|
|
#include <libyul/Object.h>
|
2018-12-03 14:49:23 +00:00
|
|
|
#include <libyul/Dialect.h>
|
2018-11-04 08:34:21 +00:00
|
|
|
|
|
|
|
#include <liblangutil/ErrorReporter.h>
|
|
|
|
#include <liblangutil/ParserBase.h>
|
|
|
|
|
2020-01-06 10:52:23 +00:00
|
|
|
#include <libsolutil/Common.h>
|
2018-11-04 08:34:21 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::langutil
|
2018-11-04 08:34:21 +00:00
|
|
|
{
|
|
|
|
class Scanner;
|
|
|
|
}
|
|
|
|
|
2019-12-11 16:31:36 +00:00
|
|
|
namespace solidity::yul
|
2018-11-04 08:34:21 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Yul object parser. Invokes the inline assembly parser.
|
|
|
|
*/
|
|
|
|
class ObjectParser: public langutil::ParserBase
|
|
|
|
{
|
|
|
|
public:
|
2019-05-16 08:56:56 +00:00
|
|
|
explicit ObjectParser(langutil::ErrorReporter& _errorReporter, Dialect const& _dialect):
|
|
|
|
ParserBase(_errorReporter), m_dialect(_dialect) {}
|
2018-11-04 08:34:21 +00:00
|
|
|
|
|
|
|
/// Parses a Yul object.
|
|
|
|
/// Falls back to code-only parsing if the source starts with `{`.
|
|
|
|
/// @param _reuseScanner if true, do check for end of input after the last `}`.
|
|
|
|
/// @returns an empty shared pointer on error.
|
|
|
|
std::shared_ptr<Object> parse(std::shared_ptr<langutil::Scanner> const& _scanner, bool _reuseScanner);
|
|
|
|
|
2021-07-12 10:05:26 +00:00
|
|
|
using SourceNameMap = std::map<unsigned, std::shared_ptr<std::string const>>;
|
|
|
|
std::optional<SourceNameMap> const& sourceNameMapping() const noexcept { return m_sourceNameMapping; }
|
|
|
|
|
2018-11-04 08:34:21 +00:00
|
|
|
private:
|
2021-07-12 10:05:26 +00:00
|
|
|
std::optional<SourceNameMap> tryParseSourceNameMapping() const;
|
2018-11-04 08:34:21 +00:00
|
|
|
std::shared_ptr<Object> parseObject(Object* _containingObject = nullptr);
|
|
|
|
std::shared_ptr<Block> parseCode();
|
|
|
|
std::shared_ptr<Block> parseBlock();
|
|
|
|
void parseData(Object& _containingObject);
|
|
|
|
|
|
|
|
/// Tries to parse a name that is non-empty and unique inside the containing object.
|
|
|
|
YulString parseUniqueName(Object const* _containingObject);
|
|
|
|
void addNamedSubObject(Object& _container, YulString _name, std::shared_ptr<ObjectNode> _subObject);
|
|
|
|
|
2019-05-16 08:56:56 +00:00
|
|
|
Dialect const& m_dialect;
|
2021-07-12 10:05:26 +00:00
|
|
|
|
|
|
|
std::optional<SourceNameMap> m_sourceNameMapping;
|
2018-11-04 08:34:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|