mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Parse default dialect and omit when printing.
This commit is contained in:
@@ -608,7 +608,7 @@ Scope& AsmAnalyzer::scope(Block const* _block)
|
||||
}
|
||||
void AsmAnalyzer::expectValidType(YulString _type, SourceLocation const& _location)
|
||||
{
|
||||
if (!_type.empty() && !contains(m_dialect.types, _type))
|
||||
if (!_type.empty() && !m_dialect.types.count(_type))
|
||||
m_errorReporter.typeError(
|
||||
_location,
|
||||
"\"" + _type.str() + "\" is not a valid type (user defined types are not yet supported)."
|
||||
|
||||
@@ -366,7 +366,7 @@ Parser::ElementaryOperation Parser::parseElementaryOperation()
|
||||
location(),
|
||||
kind,
|
||||
YulString{currentLiteral()},
|
||||
{}
|
||||
kind == LiteralKind::Boolean ? m_dialect.boolType : m_dialect.defaultType
|
||||
};
|
||||
advance();
|
||||
if (currentToken() == Token::Colon)
|
||||
@@ -497,6 +497,9 @@ TypedName Parser::parseTypedName()
|
||||
typedName.location.end = endPosition();
|
||||
typedName.type = expectAsmIdentifier();
|
||||
}
|
||||
else
|
||||
typedName.type = m_dialect.defaultType;
|
||||
|
||||
return typedName;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <libyul/AsmPrinter.h>
|
||||
#include <libyul/AsmData.h>
|
||||
#include <libyul/Exceptions.h>
|
||||
#include <libyul/Dialect.h>
|
||||
|
||||
#include <libsolutil/CommonData.h>
|
||||
|
||||
@@ -238,7 +239,8 @@ string AsmPrinter::formatTypedName(TypedName _variable) const
|
||||
|
||||
string AsmPrinter::appendTypeName(YulString _type) const
|
||||
{
|
||||
if (!_type.empty())
|
||||
if (_type.empty() || (m_dialect && _type == m_dialect->defaultType))
|
||||
return {};
|
||||
else
|
||||
return ":" + _type.str();
|
||||
return "";
|
||||
}
|
||||
|
||||
+9
-1
@@ -30,10 +30,16 @@ namespace solidity::yul
|
||||
{
|
||||
struct Dialect;
|
||||
|
||||
/**
|
||||
* Converts a parsed Yul AST into readable string representation.
|
||||
* Ignores source locations.
|
||||
* If a dialect is provided, the dialect's default type is omitted.
|
||||
*/
|
||||
class AsmPrinter
|
||||
{
|
||||
public:
|
||||
explicit AsmPrinter() {}
|
||||
AsmPrinter() {}
|
||||
explicit AsmPrinter(Dialect const& _dialect): m_dialect(&_dialect) {}
|
||||
|
||||
std::string operator()(Literal const& _literal) const;
|
||||
std::string operator()(Identifier const& _identifier) const;
|
||||
@@ -53,6 +59,8 @@ public:
|
||||
private:
|
||||
std::string formatTypedName(TypedName _variable) const;
|
||||
std::string appendTypeName(YulString _type) const;
|
||||
|
||||
Dialect const* m_dialect = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ struct Dialect: boost::noncopyable
|
||||
YulString defaultType;
|
||||
/// Type used for the literals "true" and "false".
|
||||
YulString boolType;
|
||||
std::vector<YulString> types;
|
||||
std::set<YulString> types;
|
||||
|
||||
/// @returns the builtin function of the given name or a nullptr if it is not a builtin function.
|
||||
virtual BuiltinFunction const* builtin(YulString /*_name*/) const { return nullptr; }
|
||||
|
||||
@@ -218,6 +218,9 @@ EVMDialectTyped::EVMDialectTyped(langutil::EVMVersion _evmVersion, bool _objectA
|
||||
EVMDialect(_evmVersion, _objectAccess)
|
||||
{
|
||||
defaultType = "u256"_yulstring;
|
||||
boolType = "bool"_yulstring;
|
||||
types = {defaultType, boolType};
|
||||
|
||||
m_functions["lt"_yulstring].returns = {"bool"_yulstring};
|
||||
m_functions["gt"_yulstring].returns = {"bool"_yulstring};
|
||||
m_functions["slt"_yulstring].returns = {"bool"_yulstring};
|
||||
|
||||
Reference in New Issue
Block a user