Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
clonker committed Jul 9, 2024
1 parent e8c587e commit 0d97464
Show file tree
Hide file tree
Showing 25 changed files with 93 additions and 99 deletions.
2 changes: 1 addition & 1 deletion libsolidity/analysis/PostTypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ class YulLValueChecker : public solidity::yul::ASTWalker

if (ranges::any_of(
_assignment.variableNames,
[&](auto const& yulIdentifier) { return m_yulNameRepository.labelOf(yulIdentifier.name) == m_identifierName; }
[&](auto const& yulIdentifier) { return m_yulNameRepository.requiredLabelOf(yulIdentifier.name) == m_identifierName; }
))
m_willBeWrittenTo = true;
}
Expand Down
10 changes: 5 additions & 5 deletions libsolidity/analysis/ReferencesResolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ void ReferencesResolver::operator()(yul::FunctionDefinition const& _function)
{
solAssert(m_yulNameRepository != nullptr);
solAssert(nativeLocationOf(_function) == originLocationOf(_function), "");
validateYulIdentifierName(m_yulNameRepository->labelOf(_function.name), nativeLocationOf(_function));
validateYulIdentifierName(m_yulNameRepository->requiredLabelOf(_function.name), nativeLocationOf(_function));
for (yul::TypedName const& varName: _function.parameters + _function.returnVariables)
{
solAssert(nativeLocationOf(varName) == originLocationOf(varName), "");
validateYulIdentifierName(m_yulNameRepository->labelOf(varName.name), nativeLocationOf(varName));
validateYulIdentifierName(m_yulNameRepository->requiredLabelOf(varName.name), nativeLocationOf(varName));
}

bool wasInsideFunction = m_yulInsideFunction;
Expand All @@ -291,7 +291,7 @@ void ReferencesResolver::operator()(yul::Identifier const& _identifier)
{
solAssert(m_yulNameRepository != nullptr);
solAssert(nativeLocationOf(_identifier) == originLocationOf(_identifier), "");
auto const identifierLabel = m_yulNameRepository->labelOf(_identifier.name);
auto const identifierLabel = m_yulNameRepository->requiredLabelOf(_identifier.name);
if (m_resolver.experimentalSolidity())
{
std::vector<std::string> splitName;
Expand Down Expand Up @@ -399,10 +399,10 @@ void ReferencesResolver::operator()(yul::VariableDeclaration const& _varDecl)
for (auto const& identifier: _varDecl.variables)
{
solAssert(nativeLocationOf(identifier) == originLocationOf(identifier), "");
validateYulIdentifierName(m_yulNameRepository->labelOf(identifier.name), nativeLocationOf(identifier));
validateYulIdentifierName(m_yulNameRepository->requiredLabelOf(identifier.name), nativeLocationOf(identifier));

if (
auto declarations = m_resolver.nameFromCurrentScope(std::string(m_yulNameRepository->labelOf(identifier.name)));
auto declarations = m_resolver.nameFromCurrentScope(std::string(m_yulNameRepository->requiredLabelOf(identifier.name)));
!declarations.empty()
)
{
Expand Down
2 changes: 1 addition & 1 deletion libsolidity/ast/ASTJsonExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ bool ASTJsonExporter::visit(InlineAssembly const& _node)
for (auto const& it: _node.annotation().externalReferences)
if (it.first)
externalReferences.emplace_back(std::make_pair(
_node.operations().nameRepository().labelOf(it.first->name),
_node.operations().nameRepository().requiredLabelOf(it.first->name),
inlineAssemblyIdentifierToJson(it)
));

Expand Down
2 changes: 1 addition & 1 deletion libsolidity/codegen/ir/IRGeneratorForStatements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct CopyTranslate: public yul::ASTCopier
if (m_yulNameRepository.isBuiltinName(_name))
return _name;
else
return m_yulNameRepository.defineName("usr$" + std::string(m_yulNameRepository.labelOf(_name)));
return m_yulNameRepository.defineName("usr$" + std::string(m_yulNameRepository.requiredLabelOf(_name)));
}

yul::Identifier translate(yul::Identifier const& _identifier) override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct CopyTranslate: public yul::ASTCopier
if (m_yulNameRepository.isBuiltinName(_name))
return _name;
else
return m_yulNameRepository.defineName("usr$" + std::string(m_yulNameRepository.labelOf(_name)));
return m_yulNameRepository.defineName("usr$" + std::string(m_yulNameRepository.requiredLabelOf(_name)));
}

yul::Identifier translate(yul::Identifier const& _identifier) override
Expand Down
4 changes: 2 additions & 2 deletions libsolidity/lsp/RenameSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void RenameSymbol::extractNameAndDeclaration(InlineAssembly const& _inlineAssemb
if (location.containsOffset(_cursorBytePosition))
{
m_declarationToRename = externalReference.declaration;
m_symbolName = _inlineAssembly.operations().nameRepository().labelOf(identifier->name);
m_symbolName = _inlineAssembly.operations().nameRepository().requiredLabelOf(identifier->name);

if (!externalReference.suffix.empty())
m_symbolName = m_symbolName.substr(0, m_symbolName.length() - externalReference.suffix.size() - 1);
Expand All @@ -296,7 +296,7 @@ void RenameSymbol::Visitor::endVisit(InlineAssembly const& _node)
{
for (auto&& [identifier, externalReference]: _node.annotation().externalReferences)
{
auto identifierName = _node.operations().nameRepository().labelOf(identifier->name);
auto identifierName = _node.operations().nameRepository().requiredLabelOf(identifier->name);
if (!externalReference.suffix.empty())
identifierName = identifierName.substr(0, identifierName.length() - externalReference.suffix.size() - 1);

Expand Down
42 changes: 21 additions & 21 deletions libyul/AsmAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ std::vector<Type> AsmAnalyzer::operator()(Literal const& _literal)
nativeLocationOf(_literal),
fmt::format(
R"(Invalid type "{}" for literal "{}".)",
m_yulNameRepository.labelOf(_literal.type),
m_yulNameRepository.requiredLabelOf(_literal.type),
formatLiteral(_literal, false)
)
);
Expand All @@ -151,7 +151,7 @@ std::vector<Type> AsmAnalyzer::operator()(Identifier const& _identifier)
nativeLocationOf(_identifier),
fmt::format(
"Variable {} used before it was declared.",
m_yulNameRepository.labelOf(_identifier.name)
m_yulNameRepository.requiredLabelOf(_identifier.name)
)
);
type = _var.type;
Expand All @@ -161,7 +161,7 @@ std::vector<Type> AsmAnalyzer::operator()(Identifier const& _identifier)
m_errorReporter.typeError(
6041_error,
nativeLocationOf(_identifier),
fmt::format("Function {} used without being called.", m_yulNameRepository.labelOf(_identifier.name))
fmt::format("Function {} used without being called.", m_yulNameRepository.requiredLabelOf(_identifier.name))
);
}
}))
Expand All @@ -186,7 +186,7 @@ std::vector<Type> AsmAnalyzer::operator()(Identifier const& _identifier)
m_errorReporter.declarationError(
8198_error,
nativeLocationOf(_identifier),
fmt::format("Identifier \"{}\" not found.", m_yulNameRepository.labelOf(_identifier.name))
fmt::format("Identifier \"{}\" not found.", m_yulNameRepository.requiredLabelOf(_identifier.name))
);

}
Expand Down Expand Up @@ -224,7 +224,7 @@ void AsmAnalyzer::operator()(Assignment const& _assignment)
nativeLocationOf(_assignment),
fmt::format(
"Variable {} occurs multiple times on the left-hand side of the assignment.",
m_yulNameRepository.labelOf(_variableName.name)
m_yulNameRepository.requiredLabelOf(_variableName.name)
)
);

Expand All @@ -236,7 +236,7 @@ void AsmAnalyzer::operator()(Assignment const& _assignment)
nativeLocationOf(_assignment),
fmt::format(
"Variable count for assignment to \"{}\" does not match number of values ({} vs. {})",
joinHumanReadable(applyMap(_assignment.variableNames, [this](auto const& _identifier){ return m_yulNameRepository.labelOf(_identifier.name); })),
joinHumanReadable(applyMap(_assignment.variableNames, [this](auto const& _identifier){ return m_yulNameRepository.requiredLabelOf(_identifier.name); })),
numVariables,
types.size()
)
Expand Down Expand Up @@ -273,7 +273,7 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
nativeLocationOf(_varDecl),
fmt::format(
"Variable count mismatch for declaration of \"{}\": {} variables and {} values.",
joinHumanReadable(applyMap(_varDecl.variables, [this](auto const& _identifier){ return m_yulNameRepository.labelOf(_identifier.name); })),
joinHumanReadable(applyMap(_varDecl.variables, [this](auto const& _identifier){ return m_yulNameRepository.requiredLabelOf(_identifier.name); })),
numVariables,
types.size()
)
Expand All @@ -291,8 +291,8 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
nativeLocationOf(variable),
fmt::format(
R"(Assigning value of type "{}" to variable of type "{}".)",
m_yulNameRepository.labelOf(givenType),
m_yulNameRepository.labelOf(variable.type)
m_yulNameRepository.requiredLabelOf(givenType),
m_yulNameRepository.requiredLabelOf(variable.type)
)
);
}
Expand Down Expand Up @@ -395,7 +395,7 @@ std::vector<Type> AsmAnalyzer::operator()(FunctionCall const& _funCall)
m_errorReporter.declarationError(
4619_error,
nativeLocationOf(_funCall.functionName),
fmt::format("Function \"{}\" not found.", m_yulNameRepository.labelOf(_funCall.functionName.name))
fmt::format("Function \"{}\" not found.", m_yulNameRepository.requiredLabelOf(_funCall.functionName.name))
);
yulAssert(!watcher.ok(), "Expected a reported error.");
}
Expand All @@ -406,7 +406,7 @@ std::vector<Type> AsmAnalyzer::operator()(FunctionCall const& _funCall)
nativeLocationOf(_funCall.functionName),
fmt::format(
"Function \"{}\" expects {} arguments but got {}.",
m_yulNameRepository.labelOf(_funCall.functionName.name),
m_yulNameRepository.requiredLabelOf(_funCall.functionName.name),
parameterTypes->size(),
_funCall.arguments.size()
)
Expand Down Expand Up @@ -597,8 +597,8 @@ void AsmAnalyzer::expectBoolExpression(Expression const& _expr)
nativeLocationOf(_expr),
fmt::format(
R"(Expected a value of boolean type "{}" but got "{}")",
m_yulNameRepository.labelOf(m_yulNameRepository.predefined().boolType),
m_yulNameRepository.labelOf(type)
m_yulNameRepository.requiredLabelOf(m_yulNameRepository.predefined().boolType),
m_yulNameRepository.requiredLabelOf(type)
)
);
}
Expand All @@ -625,7 +625,7 @@ void AsmAnalyzer::checkAssignment(Identifier const& _variable, Type _valueType)
m_errorReporter.declarationError(
1133_error,
nativeLocationOf(_variable),
fmt::format("Variable {} used before it was declared.", m_yulNameRepository.labelOf(_variable.name))
fmt::format("Variable {} used before it was declared.", m_yulNameRepository.requiredLabelOf(_variable.name))
);
else
variableType = &std::get<Scope::Variable>(*var).type;
Expand All @@ -650,8 +650,8 @@ void AsmAnalyzer::checkAssignment(Identifier const& _variable, Type _valueType)
nativeLocationOf(_variable),
fmt::format(
R"(Assigning a value of type "{}" to a variable of type "{}".)",
m_yulNameRepository.labelOf(_valueType),
m_yulNameRepository.labelOf(*variableType)
m_yulNameRepository.requiredLabelOf(_valueType),
m_yulNameRepository.requiredLabelOf(*variableType)
)
);

Expand All @@ -668,7 +668,7 @@ Scope& AsmAnalyzer::scope(Block const* _block)

void AsmAnalyzer::expectValidIdentifier(YulName _identifier, SourceLocation const& _location)
{
auto const label = m_yulNameRepository.labelOf(_identifier);
auto const label = m_yulNameRepository.requiredLabelOf(_identifier);
// NOTE: the leading dot case is handled by the parser not allowing it.
if (boost::ends_with(label, "."))
m_errorReporter.syntaxError(
Expand Down Expand Up @@ -698,7 +698,7 @@ void AsmAnalyzer::expectValidType(Type _type, SourceLocation const& _location)
m_errorReporter.typeError(
5473_error,
_location,
fmt::format("\"{}\" is not a valid type (user defined types are not yet supported).", m_yulNameRepository.labelOf(_type))
fmt::format("\"{}\" is not a valid type (user defined types are not yet supported).", m_yulNameRepository.requiredLabelOf(_type))
);
}

Expand All @@ -710,8 +710,8 @@ void AsmAnalyzer::expectType(Type _expectedType, Type _givenType, SourceLocation
_location,
fmt::format(
R"(Expected a value of type "{}" but got "{}".)",
m_yulNameRepository.labelOf(_expectedType),
m_yulNameRepository.labelOf(_givenType)
m_yulNameRepository.requiredLabelOf(_expectedType),
m_yulNameRepository.requiredLabelOf(_givenType)
)
);
}
Expand Down Expand Up @@ -806,5 +806,5 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio

bool AsmAnalyzer::validateInstructions(FunctionCall const& _functionCall)
{
return validateInstructions(m_yulNameRepository.labelOf(_functionCall.functionName.name), nativeLocationOf(_functionCall.functionName));
return validateInstructions(m_yulNameRepository.requiredLabelOf(_functionCall.functionName.name), nativeLocationOf(_functionCall.functionName));
}
10 changes: 5 additions & 5 deletions libyul/AsmJsonConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Json AsmJsonConverter::operator()(TypedName const& _node) const
{
yulAssert(YulNameRepository::emptyName() != _node.name, "Invalid variable name.");
Json ret = createAstNode(originLocationOf(_node), nativeLocationOf(_node), "YulTypedName");
ret["name"] = m_yulNameRepository.labelOf(_node.name);
ret["type"] = m_yulNameRepository.labelOf(_node.type);
ret["name"] = m_yulNameRepository.requiredLabelOf(_node.name);
ret["type"] = m_yulNameRepository.requiredLabelOf(_node.type);
return ret;
}

Expand All @@ -67,7 +67,7 @@ Json AsmJsonConverter::operator()(Literal const& _node) const
ret["hexValue"] = util::toHex(util::asBytes(formatLiteral(_node)));
break;
}
ret["type"] = m_yulNameRepository.labelOf(_node.type);
ret["type"] = m_yulNameRepository.requiredLabelOf(_node.type);
{
auto const formattedLiteral = formatLiteral(_node);
if (util::validateUTF8(formattedLiteral))
Expand All @@ -80,7 +80,7 @@ Json AsmJsonConverter::operator()(Identifier const& _node) const
{
yulAssert(YulNameRepository::emptyName() != _node.name, "Invalid identifier");
Json ret = createAstNode(originLocationOf(_node), nativeLocationOf(_node), "YulIdentifier");
ret["name"] = m_yulNameRepository.labelOf(_node.name);
ret["name"] = m_yulNameRepository.requiredLabelOf(_node.name);
return ret;
}

Expand Down Expand Up @@ -122,7 +122,7 @@ Json AsmJsonConverter::operator()(FunctionDefinition const& _node) const
{
yulAssert(YulNameRepository::emptyName() != _node.name, "Invalid function name.");
Json ret = createAstNode(originLocationOf(_node), nativeLocationOf(_node), "YulFunctionDefinition");
ret["name"] = m_yulNameRepository.labelOf(_node.name);
ret["name"] = m_yulNameRepository.requiredLabelOf(_node.name);
for (auto const& var: _node.parameters)
ret["parameters"].emplace_back((*this)(var));
for (auto const& var: _node.returnVariables)
Expand Down
4 changes: 2 additions & 2 deletions libyul/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ Statement Parser::parseStatement(YulNameRepository& _nameRepository)
6272_error,
fmt::format(
"Cannot assign to builtin function \"{}\".",
_nameRepository.labelOf(identifier.name)
_nameRepository.requiredLabelOf(identifier.name)
)
);

Expand Down Expand Up @@ -530,7 +530,7 @@ Expression Parser::parseExpression(YulNameRepository& _nameRepository, bool _unl
fatalParserError(
7104_error,
nativeLocationOf(_identifier),
fmt::format("Builtin function \"{}\" must be called.", _nameRepository.labelOf(_identifier.name))
fmt::format("Builtin function \"{}\" must be called.", _nameRepository.requiredLabelOf(_identifier.name))
);
return std::move(_identifier);
},
Expand Down
8 changes: 4 additions & 4 deletions libyul/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ std::string AsmPrinter::operator()(Literal const& _literal)
std::string AsmPrinter::operator()(Identifier const& _identifier)
{
yulAssert(_identifier.name != YulNameRepository::emptyName(), "Invalid identifier.");
return formatDebugData(_identifier) + std::string(m_nameRepository.labelOf(_identifier.name));
return formatDebugData(_identifier) + std::string(m_nameRepository.requiredLabelOf(_identifier.name));
}

std::string AsmPrinter::operator()(ExpressionStatement const& _statement)
Expand Down Expand Up @@ -112,7 +112,7 @@ std::string AsmPrinter::operator()(FunctionDefinition const& _functionDefinition
yulAssert(_functionDefinition.name != YulNameRepository::emptyName(), "Invalid function name.");

std::string out = formatDebugData(_functionDefinition);
out += "function " + std::string(m_nameRepository.labelOf(_functionDefinition.name)) + "(";
out += "function " + std::string(m_nameRepository.requiredLabelOf(_functionDefinition.name)) + "(";
out += boost::algorithm::join(
_functionDefinition.parameters | ranges::views::transform(
[this](TypedName argument) { return formatTypedName(argument); }
Expand Down Expand Up @@ -240,7 +240,7 @@ std::string AsmPrinter::operator()(Block const& _block)
std::string AsmPrinter::formatTypedName(TypedName const& _variable)
{
yulAssert(_variable.name != YulNameRepository::emptyName(), "Invalid variable name.");
return formatDebugData(_variable) + std::string(m_nameRepository.labelOf(_variable.name)) + appendTypeName(_variable.type);
return formatDebugData(_variable) + std::string(m_nameRepository.requiredLabelOf(_variable.name)) + appendTypeName(_variable.type);
}

std::string AsmPrinter::appendTypeName(Type _type, bool const _isBoolLiteral) const
Expand All @@ -256,7 +256,7 @@ std::string AsmPrinter::appendTypeName(Type _type, bool const _isBoolLiteral) co
if (_type == YulNameRepository::emptyName())
return {};
else
return fmt::format(":{}", m_nameRepository.labelOf(_type));
return fmt::format(":{}", m_nameRepository.requiredLabelOf(_type));
}

std::string AsmPrinter::formatSourceLocation(
Expand Down
4 changes: 2 additions & 2 deletions libyul/ScopeFiller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ bool ScopeFiller::registerVariable(TypedName const& _name, SourceLocation const&
m_errorReporter.declarationError(
1395_error,
_location,
fmt::format("Variable name {} already taken in this scope.", m_yulNameRegistry.labelOf(_name.name))
fmt::format("Variable name {} already taken in this scope.", m_yulNameRegistry.requiredLabelOf(_name.name))
);
return false;
}
Expand All @@ -163,7 +163,7 @@ bool ScopeFiller::registerFunction(FunctionDefinition const& _funDef)
m_errorReporter.declarationError(
6052_error,
nativeLocationOf(_funDef),
fmt::format("Function name {} already taken in this scope.", m_yulNameRegistry.labelOf(_funDef.name))
fmt::format("Function name {} already taken in this scope.", m_yulNameRegistry.requiredLabelOf(_funDef.name))
);
return false;
}
Expand Down
7 changes: 7 additions & 0 deletions libyul/YulName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ std::optional<std::string_view> YulNameRepository::labelOf(YulName const _name)
return std::nullopt;
}

std::string_view YulNameRepository::requiredLabelOf(YulName const _name) const
{
auto const label = labelOf(_name);
yulAssert(label.has_value(), "YulName currently has no defined label in the YulNameRepository.");
return label.value();
}

YulNameRepository::YulName YulNameRepository::baseNameOf(YulName _name) const
{
yulAssert(nameWithinBounds(_name), "YulName exceeds repository size, probably stems from another instance.");
Expand Down
Loading

0 comments on commit 0d97464

Please sign in to comment.