Skip to content

Commit fdb537b

Browse files
committed
LibYul: Replace all occurrences of YulString with a YulName typedef, so that it can be replaced more easily.
1 parent 5091b5b commit fdb537b

File tree

109 files changed

+640
-602
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+640
-602
lines changed

libsolidity/analysis/ReferencesResolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ void ReferencesResolver::resolveInheritDoc(StructuredDocumentation const& _docum
488488
}
489489
}
490490

491-
void ReferencesResolver::validateYulIdentifierName(yul::YulString _name, SourceLocation const& _location)
491+
void ReferencesResolver::validateYulIdentifierName(yul::YulName _name, SourceLocation const& _location)
492492
{
493493
if (util::contains(_name.str(), '.'))
494494
m_errorReporter.declarationError(

libsolidity/analysis/ReferencesResolver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <libsolidity/ast/ASTAnnotations.h>
2828
#include <liblangutil/EVMVersion.h>
2929
#include <libyul/optimiser/ASTWalker.h>
30+
#include <libyul/YulName.h>
3031

3132
#include <list>
3233
#include <map>
@@ -94,7 +95,7 @@ class ReferencesResolver: private ASTConstVisitor, private yul::ASTWalker
9495
void resolveInheritDoc(StructuredDocumentation const& _documentation, StructurallyDocumentedAnnotation& _annotation);
9596

9697
/// Checks if the name contains a '.'.
97-
void validateYulIdentifierName(yul::YulString _name, langutil::SourceLocation const& _location);
98+
void validateYulIdentifierName(yul::YulName _name, langutil::SourceLocation const& _location);
9899

99100
langutil::ErrorReporter& m_errorReporter;
100101
NameAndTypeResolver& m_resolver;

libsolidity/codegen/CompilerContext.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,11 @@ void CompilerContext::appendInlineAssembly(
388388
{
389389
unsigned startStackHeight = stackHeight();
390390

391-
std::set<yul::YulString> externallyUsedIdentifiers;
391+
std::set<yul::YulName> externallyUsedIdentifiers;
392392
for (auto const& fun: _externallyUsedFunctions)
393-
externallyUsedIdentifiers.insert(yul::YulString(fun));
393+
externallyUsedIdentifiers.insert(yul::YulName(fun));
394394
for (auto const& var: _localVariables)
395-
externallyUsedIdentifiers.insert(yul::YulString(var));
395+
externallyUsedIdentifiers.insert(yul::YulName(var));
396396

397397
yul::ExternalIdentifierAccess identifierAccess;
398398
identifierAccess.resolve = [&](
@@ -532,7 +532,7 @@ void CompilerContext::appendInlineAssembly(
532532
}
533533

534534

535-
void CompilerContext::optimizeYul(yul::Object& _object, yul::EVMDialect const& _dialect, OptimiserSettings const& _optimiserSettings, std::set<yul::YulString> const& _externalIdentifiers)
535+
void CompilerContext::optimizeYul(yul::Object& _object, yul::EVMDialect const& _dialect, OptimiserSettings const& _optimiserSettings, std::set<yul::YulName> const& _externalIdentifiers)
536536
{
537537
#ifdef SOL_OUTPUT_ASM
538538
cout << yul::AsmPrinter(*dialect)(*_object.code) << endl;

libsolidity/codegen/ir/IRGeneratorForStatements.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct CopyTranslate: public yul::ASTCopier
7676
return ASTCopier::operator()(_identifier);
7777
}
7878

79-
yul::YulString translateIdentifier(yul::YulString _name) override
79+
yul::YulName translateIdentifier(yul::YulName _name) override
8080
{
8181
// Strictly, the dialect used by inline assembly (m_dialect) could be different
8282
// from the Yul dialect we are compiling to. So we are assuming here that the builtin
@@ -85,7 +85,7 @@ struct CopyTranslate: public yul::ASTCopier
8585
if (m_dialect.builtin(_name))
8686
return _name;
8787
else
88-
return yul::YulString{"usr$" + _name.str()};
88+
return yul::YulName{"usr$" + _name.str()};
8989
}
9090

9191
yul::Identifier translate(yul::Identifier const& _identifier) override
@@ -202,9 +202,9 @@ struct CopyTranslate: public yul::ASTCopier
202202
solAssert(false);
203203

204204
if (isDigit(value.front()))
205-
return yul::Literal{_identifier.debugData, yul::LiteralKind::Number, yul::YulString{value}, {}};
205+
return yul::Literal{_identifier.debugData, yul::LiteralKind::Number, yul::YulName{value}, {}};
206206
else
207-
return yul::Identifier{_identifier.debugData, yul::YulString{value}};
207+
return yul::Identifier{_identifier.debugData, yul::YulName{value}};
208208
}
209209

210210

libsolidity/experimental/codegen/IRGeneratorForStatements.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ struct CopyTranslate: public yul::ASTCopier
7070
return ASTCopier::operator()(_identifier);
7171
}
7272

73-
yul::YulString translateIdentifier(yul::YulString _name) override
73+
yul::YulName translateIdentifier(yul::YulName _name) override
7474
{
7575
if (m_dialect.builtin(_name))
7676
return _name;
7777
else
78-
return yul::YulString{"usr$" + _name.str()};
78+
return yul::YulName{"usr$" + _name.str()};
7979
}
8080

8181
yul::Identifier translate(yul::Identifier const& _identifier) override
@@ -102,7 +102,7 @@ struct CopyTranslate: public yul::ASTCopier
102102
solAssert(type);
103103
solAssert(m_context.env->typeEquals(*type, m_context.analysis.typeSystem().type(PrimitiveType::Word, {})));
104104
std::string value = IRNames::localVariable(*varDecl);
105-
return yul::Identifier{_identifier.debugData, yul::YulString{value}};
105+
return yul::Identifier{_identifier.debugData, yul::YulName{value}};
106106
}
107107

108108
IRGenerationContext const& m_context;

libsolidity/formal/SMTEncoder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ void SMTEncoder::endVisit(Block const& _block)
306306

307307
bool SMTEncoder::visit(InlineAssembly const& _inlineAsm)
308308
{
309-
/// This is very similar to `yul::Assignments`, except I need to collect `Identifier`s and not just names as `YulString`s.
309+
/// This is very similar to `yul::Assignments`, except I need to collect `Identifier`s and not just names as `YulName`s.
310310
struct AssignedExternalsCollector: public yul::ASTWalker
311311
{
312312
AssignedExternalsCollector(InlineAssembly const& _inlineAsm): externalReferences(_inlineAsm.annotation().externalReferences)

libyul/AsmAnalysis.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ AsmAnalysisInfo AsmAnalyzer::analyzeStrictAssertCorrect(Dialect const& _dialect,
9898
return analysisInfo;
9999
}
100100

101-
std::vector<YulString> AsmAnalyzer::operator()(Literal const& _literal)
101+
std::vector<YulName> AsmAnalyzer::operator()(Literal const& _literal)
102102
{
103103
expectValidType(_literal.type, nativeLocationOf(_literal));
104104
if (_literal.kind == LiteralKind::String && _literal.value.str().size() > 32)
@@ -122,11 +122,11 @@ std::vector<YulString> AsmAnalyzer::operator()(Literal const& _literal)
122122
return {_literal.type};
123123
}
124124

125-
std::vector<YulString> AsmAnalyzer::operator()(Identifier const& _identifier)
125+
std::vector<YulName> AsmAnalyzer::operator()(Identifier const& _identifier)
126126
{
127127
yulAssert(!_identifier.name.empty(), "");
128128
auto watcher = m_errorReporter.errorWatcher();
129-
YulString type = m_dialect.defaultType;
129+
YulName type = m_dialect.defaultType;
130130

131131
if (m_currentScope->lookup(_identifier.name, GenericVisitor{
132132
[&](Scope::Variable const& _var)
@@ -180,7 +180,7 @@ std::vector<YulString> AsmAnalyzer::operator()(Identifier const& _identifier)
180180
void AsmAnalyzer::operator()(ExpressionStatement const& _statement)
181181
{
182182
auto watcher = m_errorReporter.errorWatcher();
183-
std::vector<YulString> types = std::visit(*this, _statement.expression);
183+
std::vector<YulName> types = std::visit(*this, _statement.expression);
184184
if (watcher.ok() && !types.empty())
185185
m_errorReporter.typeError(
186186
3083_error,
@@ -199,7 +199,7 @@ void AsmAnalyzer::operator()(Assignment const& _assignment)
199199
size_t const numVariables = _assignment.variableNames.size();
200200
yulAssert(numVariables >= 1, "");
201201

202-
std::set<YulString> variables;
202+
std::set<YulName> variables;
203203
for (auto const& _variableName: _assignment.variableNames)
204204
if (!variables.insert(_variableName.name).second)
205205
m_errorReporter.declarationError(
@@ -210,7 +210,7 @@ void AsmAnalyzer::operator()(Assignment const& _assignment)
210210
" occurs multiple times on the left-hand side of the assignment."
211211
);
212212

213-
std::vector<YulString> types = std::visit(*this, *_assignment.value);
213+
std::vector<YulName> types = std::visit(*this, *_assignment.value);
214214

215215
if (types.size() != numVariables)
216216
m_errorReporter.declarationError(
@@ -249,7 +249,7 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
249249

250250
if (_varDecl.value)
251251
{
252-
std::vector<YulString> types = std::visit(*this, *_varDecl.value);
252+
std::vector<YulName> types = std::visit(*this, *_varDecl.value);
253253
if (types.size() != numVariables)
254254
m_errorReporter.declarationError(
255255
3812_error,
@@ -265,7 +265,7 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
265265

266266
for (size_t i = 0; i < _varDecl.variables.size(); ++i)
267267
{
268-
YulString givenType = m_dialect.defaultType;
268+
YulName givenType = m_dialect.defaultType;
269269
if (i < types.size())
270270
givenType = types[i];
271271
TypedName const& variable = _varDecl.variables[i];
@@ -301,12 +301,12 @@ void AsmAnalyzer::operator()(FunctionDefinition const& _funDef)
301301
(*this)(_funDef.body);
302302
}
303303

304-
std::vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
304+
std::vector<YulName> AsmAnalyzer::operator()(FunctionCall const& _funCall)
305305
{
306306
yulAssert(!_funCall.functionName.name.empty(), "");
307307
auto watcher = m_errorReporter.errorWatcher();
308-
std::vector<YulString> const* parameterTypes = nullptr;
309-
std::vector<YulString> const* returnTypes = nullptr;
308+
std::vector<YulName> const* parameterTypes = nullptr;
309+
std::vector<YulName> const* returnTypes = nullptr;
310310
std::vector<std::optional<LiteralKind>> const* literalArguments = nullptr;
311311

312312
if (BuiltinFunction const* f = m_dialect.builtin(_funCall.functionName.name))
@@ -390,7 +390,7 @@ std::vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
390390
std::to_string(_funCall.arguments.size()) + "."
391391
);
392392

393-
std::vector<YulString> argTypes;
393+
std::vector<YulName> argTypes;
394394
for (size_t i = _funCall.arguments.size(); i > 0; i--)
395395
{
396396
Expression const& arg = _funCall.arguments[i - 1];
@@ -453,7 +453,7 @@ std::vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
453453
return *returnTypes;
454454
}
455455
else if (returnTypes)
456-
return std::vector<YulString>(returnTypes->size(), m_dialect.defaultType);
456+
return std::vector<YulName>(returnTypes->size(), m_dialect.defaultType);
457457
else
458458
return {};
459459
}
@@ -476,7 +476,7 @@ void AsmAnalyzer::operator()(Switch const& _switch)
476476
"\"switch\" statement with only a default case."
477477
);
478478

479-
YulString valueType = expectExpression(*_switch.expression);
479+
YulName valueType = expectExpression(*_switch.expression);
480480

481481
std::set<u256> cases;
482482
for (auto const& _case: _switch.cases)
@@ -541,9 +541,9 @@ void AsmAnalyzer::operator()(Block const& _block)
541541
m_currentScope = previousScope;
542542
}
543543

544-
YulString AsmAnalyzer::expectExpression(Expression const& _expr)
544+
YulName AsmAnalyzer::expectExpression(Expression const& _expr)
545545
{
546-
std::vector<YulString> types = std::visit(*this, _expr);
546+
std::vector<YulName> types = std::visit(*this, _expr);
547547
if (types.size() != 1)
548548
m_errorReporter.typeError(
549549
3950_error,
@@ -555,7 +555,7 @@ YulString AsmAnalyzer::expectExpression(Expression const& _expr)
555555
return types.empty() ? m_dialect.defaultType : types.front();
556556
}
557557

558-
YulString AsmAnalyzer::expectUnlimitedStringLiteral(Literal const& _literal)
558+
YulName AsmAnalyzer::expectUnlimitedStringLiteral(Literal const& _literal)
559559
{
560560
yulAssert(_literal.kind == LiteralKind::String, "");
561561
yulAssert(m_dialect.validTypeForLiteral(LiteralKind::String, _literal.value, _literal.type), "");
@@ -565,7 +565,7 @@ YulString AsmAnalyzer::expectUnlimitedStringLiteral(Literal const& _literal)
565565

566566
void AsmAnalyzer::expectBoolExpression(Expression const& _expr)
567567
{
568-
YulString type = expectExpression(_expr);
568+
YulName type = expectExpression(_expr);
569569
if (type != m_dialect.boolType)
570570
m_errorReporter.typeError(
571571
1733_error,
@@ -578,11 +578,11 @@ void AsmAnalyzer::expectBoolExpression(Expression const& _expr)
578578
);
579579
}
580580

581-
void AsmAnalyzer::checkAssignment(Identifier const& _variable, YulString _valueType)
581+
void AsmAnalyzer::checkAssignment(Identifier const& _variable, YulName _valueType)
582582
{
583583
yulAssert(!_variable.name.empty(), "");
584584
auto watcher = m_errorReporter.errorWatcher();
585-
YulString const* variableType = nullptr;
585+
YulName const* variableType = nullptr;
586586
bool found = false;
587587
if (Scope::Identifier const* var = m_currentScope->lookup(_variable.name))
588588
{
@@ -641,7 +641,7 @@ Scope& AsmAnalyzer::scope(Block const* _block)
641641
return *scopePtr;
642642
}
643643

644-
void AsmAnalyzer::expectValidIdentifier(YulString _identifier, SourceLocation const& _location)
644+
void AsmAnalyzer::expectValidIdentifier(YulName _identifier, SourceLocation const& _location)
645645
{
646646
// NOTE: the leading dot case is handled by the parser not allowing it.
647647
if (boost::ends_with(_identifier.str(), "."))
@@ -666,7 +666,7 @@ void AsmAnalyzer::expectValidIdentifier(YulString _identifier, SourceLocation co
666666
);
667667
}
668668

669-
void AsmAnalyzer::expectValidType(YulString _type, SourceLocation const& _location)
669+
void AsmAnalyzer::expectValidType(YulName _type, SourceLocation const& _location)
670670
{
671671
if (!m_dialect.types.count(_type))
672672
m_errorReporter.typeError(
@@ -676,7 +676,7 @@ void AsmAnalyzer::expectValidType(YulString _type, SourceLocation const& _locati
676676
);
677677
}
678678

679-
void AsmAnalyzer::expectType(YulString _expectedType, YulString _givenType, SourceLocation const& _location)
679+
void AsmAnalyzer::expectType(YulName _expectedType, YulName _givenType, SourceLocation const& _location)
680680
{
681681
if (_expectedType != _givenType)
682682
m_errorReporter.typeError(
@@ -689,7 +689,7 @@ void AsmAnalyzer::expectType(YulString _expectedType, YulString _givenType, Sour
689689
bool AsmAnalyzer::validateInstructions(std::string const& _instructionIdentifier, langutil::SourceLocation const& _location)
690690
{
691691
// NOTE: This function uses the default EVM version instead of the currently selected one.
692-
auto const builtin = EVMDialect::strictAssemblyForEVM(EVMVersion{}).builtin(YulString(_instructionIdentifier));
692+
auto const builtin = EVMDialect::strictAssemblyForEVM(EVMVersion{}).builtin(YulName(_instructionIdentifier));
693693
if (builtin && builtin->instruction.has_value())
694694
return validateInstructions(builtin->instruction.value(), _location);
695695
else

libyul/AsmAnalysis.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class AsmAnalyzer
6161
langutil::ErrorReporter& _errorReporter,
6262
Dialect const& _dialect,
6363
ExternalIdentifierAccess::Resolver _resolver = ExternalIdentifierAccess::Resolver(),
64-
std::set<YulString> _dataNames = {}
64+
std::set<YulName> _dataNames = {}
6565
):
6666
m_resolver(std::move(_resolver)),
6767
m_info(_analysisInfo),
@@ -107,12 +107,12 @@ class AsmAnalyzer
107107

108108
/// Verifies that a variable to be assigned to exists, can be assigned to
109109
/// and has the same type as the value.
110-
void checkAssignment(Identifier const& _variable, YulString _valueType);
110+
void checkAssignment(Identifier const& _variable, YulName _valueType);
111111

112112
Scope& scope(Block const* _block);
113-
void expectValidIdentifier(YulString _identifier, langutil::SourceLocation const& _location);
114-
void expectValidType(YulString _type, langutil::SourceLocation const& _location);
115-
void expectType(YulString _expectedType, YulString _givenType, langutil::SourceLocation const& _location);
113+
void expectValidIdentifier(YulName _identifier, langutil::SourceLocation const& _location);
114+
void expectValidType(YulName _type, langutil::SourceLocation const& _location);
115+
void expectType(YulName _expectedType, YulName _givenType, langutil::SourceLocation const& _location);
116116

117117
bool validateInstructions(evmasm::Instruction _instr, langutil::SourceLocation const& _location);
118118
bool validateInstructions(std::string const& _instrIdentifier, langutil::SourceLocation const& _location);

libyul/AsmJsonImporter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ Json AsmJsonImporter::member(Json const& _node, std::string const& _name)
7171
TypedName AsmJsonImporter::createTypedName(Json const& _node)
7272
{
7373
auto typedName = createAsmNode<TypedName>(_node);
74-
typedName.type = YulString{member(_node, "type").get<std::string>()};
75-
typedName.name = YulString{member(_node, "name").get<std::string>()};
74+
typedName.type = YulName{member(_node, "type").get<std::string>()};
75+
typedName.name = YulName{member(_node, "name").get<std::string>()};
7676
return typedName;
7777
}
7878

@@ -166,11 +166,11 @@ Literal AsmJsonImporter::createLiteral(Json const& _node)
166166

167167
solAssert(member(_node, "hexValue").is_string() || member(_node, "value").is_string(), "");
168168
if (_node.contains("hexValue"))
169-
lit.value = YulString{util::asString(util::fromHex(member(_node, "hexValue").get<std::string>()))};
169+
lit.value = YulName{util::asString(util::fromHex(member(_node, "hexValue").get<std::string>()))};
170170
else
171-
lit.value = YulString{member(_node, "value").get<std::string>()};
171+
lit.value = YulName{member(_node, "value").get<std::string>()};
172172

173-
lit.type= YulString{member(_node, "type").get<std::string>()};
173+
lit.type= YulName{member(_node, "type").get<std::string>()};
174174

175175
if (kind == "number")
176176
{
@@ -215,7 +215,7 @@ Leave AsmJsonImporter::createLeave(Json const& _node)
215215
Identifier AsmJsonImporter::createIdentifier(Json const& _node)
216216
{
217217
auto identifier = createAsmNode<Identifier>(_node);
218-
identifier.name = YulString(member(_node, "name").get<std::string>());
218+
identifier.name = YulName(member(_node, "name").get<std::string>());
219219
return identifier;
220220
}
221221

libyul/AsmParser.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ std::variant<Literal, Identifier> Parser::parseLiteralOrIdentifier()
501501
{
502502
case Token::Identifier:
503503
{
504-
Identifier identifier{createDebugData(), YulString{currentLiteral()}};
504+
Identifier identifier{createDebugData(), YulName{currentLiteral()}};
505505
advance();
506506
return identifier;
507507
}
@@ -534,7 +534,7 @@ std::variant<Literal, Identifier> Parser::parseLiteralOrIdentifier()
534534
Literal literal{
535535
createDebugData(),
536536
kind,
537-
YulString{currentLiteral()},
537+
YulName{currentLiteral()},
538538
kind == LiteralKind::Boolean ? m_dialect.boolType : m_dialect.defaultType
539539
};
540540
advance();
@@ -671,9 +671,9 @@ TypedName Parser::parseTypedName()
671671
return typedName;
672672
}
673673

674-
YulString Parser::expectAsmIdentifier()
674+
YulName Parser::expectAsmIdentifier()
675675
{
676-
YulString name{currentLiteral()};
676+
YulName name{currentLiteral()};
677677
if (currentToken() == Token::Identifier && m_dialect.builtin(name))
678678
fatalParserError(5568_error, "Cannot use builtin function name \"" + name.str() + "\" as identifier name.");
679679
// NOTE: We keep the expectation here to ensure the correct source location for the error above.

0 commit comments

Comments
 (0)