mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use locationOf helper instead of accessing debugData directly.
This commit is contained in:
+32
-32
@@ -96,22 +96,22 @@ AsmAnalysisInfo AsmAnalyzer::analyzeStrictAssertCorrect(Dialect const& _dialect,
|
||||
|
||||
vector<YulString> AsmAnalyzer::operator()(Literal const& _literal)
|
||||
{
|
||||
expectValidType(_literal.type, _literal.debugData->location);
|
||||
expectValidType(_literal.type, locationOf(_literal));
|
||||
if (_literal.kind == LiteralKind::String && _literal.value.str().size() > 32)
|
||||
m_errorReporter.typeError(
|
||||
3069_error,
|
||||
_literal.debugData->location,
|
||||
locationOf(_literal),
|
||||
"String literal too long (" + to_string(_literal.value.str().size()) + " > 32)"
|
||||
);
|
||||
else if (_literal.kind == LiteralKind::Number && bigint(_literal.value.str()) > u256(-1))
|
||||
m_errorReporter.typeError(6708_error, _literal.debugData->location, "Number literal too large (> 256 bits)");
|
||||
m_errorReporter.typeError(6708_error, locationOf(_literal), "Number literal too large (> 256 bits)");
|
||||
else if (_literal.kind == LiteralKind::Boolean)
|
||||
yulAssert(_literal.value == "true"_yulstring || _literal.value == "false"_yulstring, "");
|
||||
|
||||
if (!m_dialect.validTypeForLiteral(_literal.kind, _literal.value, _literal.type))
|
||||
m_errorReporter.typeError(
|
||||
5170_error,
|
||||
_literal.debugData->location,
|
||||
locationOf(_literal),
|
||||
"Invalid type \"" + _literal.type.str() + "\" for literal \"" + _literal.value.str() + "\"."
|
||||
);
|
||||
|
||||
@@ -131,7 +131,7 @@ vector<YulString> AsmAnalyzer::operator()(Identifier const& _identifier)
|
||||
if (!m_activeVariables.count(&_var))
|
||||
m_errorReporter.declarationError(
|
||||
4990_error,
|
||||
_identifier.debugData->location,
|
||||
locationOf(_identifier),
|
||||
"Variable " + _identifier.name.str() + " used before it was declared."
|
||||
);
|
||||
type = _var.type;
|
||||
@@ -140,7 +140,7 @@ vector<YulString> AsmAnalyzer::operator()(Identifier const& _identifier)
|
||||
{
|
||||
m_errorReporter.typeError(
|
||||
6041_error,
|
||||
_identifier.debugData->location,
|
||||
locationOf(_identifier),
|
||||
"Function " + _identifier.name.str() + " used without being called."
|
||||
);
|
||||
}
|
||||
@@ -165,7 +165,7 @@ vector<YulString> AsmAnalyzer::operator()(Identifier const& _identifier)
|
||||
// Only add an error message if the callback did not do it.
|
||||
m_errorReporter.declarationError(
|
||||
8198_error,
|
||||
_identifier.debugData->location,
|
||||
locationOf(_identifier),
|
||||
"Identifier \"" + _identifier.name.str() + "\" not found."
|
||||
);
|
||||
|
||||
@@ -181,7 +181,7 @@ void AsmAnalyzer::operator()(ExpressionStatement const& _statement)
|
||||
if (watcher.ok() && !types.empty())
|
||||
m_errorReporter.typeError(
|
||||
3083_error,
|
||||
_statement.debugData->location,
|
||||
locationOf(_statement),
|
||||
"Top-level expressions are not supposed to return values (this expression returns " +
|
||||
to_string(types.size()) +
|
||||
" value" +
|
||||
@@ -201,7 +201,7 @@ void AsmAnalyzer::operator()(Assignment const& _assignment)
|
||||
if (!variables.insert(_variableName.name).second)
|
||||
m_errorReporter.declarationError(
|
||||
9005_error,
|
||||
_assignment.debugData->location,
|
||||
locationOf(_assignment),
|
||||
"Variable " +
|
||||
_variableName.name.str() +
|
||||
" occurs multiple times on the left-hand side of the assignment."
|
||||
@@ -212,7 +212,7 @@ void AsmAnalyzer::operator()(Assignment const& _assignment)
|
||||
if (types.size() != numVariables)
|
||||
m_errorReporter.declarationError(
|
||||
8678_error,
|
||||
_assignment.debugData->location,
|
||||
locationOf(_assignment),
|
||||
"Variable count for assignment to \"" +
|
||||
joinHumanReadable(applyMap(_assignment.variableNames, [](auto const& _identifier){ return _identifier.name.str(); })) +
|
||||
"\" does not match number of values (" +
|
||||
@@ -240,8 +240,8 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
|
||||
);
|
||||
for (auto const& variable: _varDecl.variables)
|
||||
{
|
||||
expectValidIdentifier(variable.name, variable.debugData->location);
|
||||
expectValidType(variable.type, variable.debugData->location);
|
||||
expectValidIdentifier(variable.name, locationOf(variable));
|
||||
expectValidType(variable.type, locationOf(variable));
|
||||
}
|
||||
|
||||
if (_varDecl.value)
|
||||
@@ -250,7 +250,7 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
|
||||
if (types.size() != numVariables)
|
||||
m_errorReporter.declarationError(
|
||||
3812_error,
|
||||
_varDecl.debugData->location,
|
||||
locationOf(_varDecl),
|
||||
"Variable count mismatch for declaration of \"" +
|
||||
joinHumanReadable(applyMap(_varDecl.variables, [](auto const& _identifier){ return _identifier.name.str(); })) +
|
||||
+ "\": " +
|
||||
@@ -269,7 +269,7 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
|
||||
if (variable.type != givenType)
|
||||
m_errorReporter.typeError(
|
||||
3947_error,
|
||||
variable.debugData->location,
|
||||
locationOf(variable),
|
||||
"Assigning value of type \"" + givenType.str() + "\" to variable of type \"" + variable.type.str() + "\"."
|
||||
);
|
||||
}
|
||||
@@ -284,14 +284,14 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
|
||||
void AsmAnalyzer::operator()(FunctionDefinition const& _funDef)
|
||||
{
|
||||
yulAssert(!_funDef.name.empty(), "");
|
||||
expectValidIdentifier(_funDef.name, _funDef.debugData->location);
|
||||
expectValidIdentifier(_funDef.name, locationOf(_funDef));
|
||||
Block const* virtualBlock = m_info.virtualBlocks.at(&_funDef).get();
|
||||
yulAssert(virtualBlock, "");
|
||||
Scope& varScope = scope(virtualBlock);
|
||||
for (auto const& var: _funDef.parameters + _funDef.returnVariables)
|
||||
{
|
||||
expectValidIdentifier(var.name, var.debugData->location);
|
||||
expectValidType(var.type, var.debugData->location);
|
||||
expectValidIdentifier(var.name, locationOf(var));
|
||||
expectValidType(var.type, locationOf(var));
|
||||
m_activeVariables.insert(&std::get<Scope::Variable>(varScope.identifiers.at(var.name)));
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
|
||||
{
|
||||
m_errorReporter.typeError(
|
||||
4202_error,
|
||||
_funCall.functionName.debugData->location,
|
||||
locationOf(_funCall.functionName),
|
||||
"Attempt to call variable instead of function."
|
||||
);
|
||||
},
|
||||
@@ -344,7 +344,7 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
|
||||
if (!validateInstructions(_funCall))
|
||||
m_errorReporter.declarationError(
|
||||
4619_error,
|
||||
_funCall.functionName.debugData->location,
|
||||
locationOf(_funCall.functionName),
|
||||
"Function \"" + _funCall.functionName.name.str() + "\" not found."
|
||||
);
|
||||
yulAssert(!watcher.ok(), "Expected a reported error.");
|
||||
@@ -353,7 +353,7 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
|
||||
if (parameterTypes && _funCall.arguments.size() != parameterTypes->size())
|
||||
m_errorReporter.typeError(
|
||||
7000_error,
|
||||
_funCall.functionName.debugData->location,
|
||||
locationOf(_funCall.functionName),
|
||||
"Function \"" + _funCall.functionName.name.str() + "\" expects " +
|
||||
to_string(parameterTypes->size()) +
|
||||
" arguments but got " +
|
||||
@@ -373,13 +373,13 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
|
||||
if (!holds_alternative<Literal>(arg))
|
||||
m_errorReporter.typeError(
|
||||
9114_error,
|
||||
_funCall.functionName.debugData->location,
|
||||
locationOf(_funCall.functionName),
|
||||
"Function expects direct literals as arguments."
|
||||
);
|
||||
else if (*literalArgumentKind != get<Literal>(arg).kind)
|
||||
m_errorReporter.typeError(
|
||||
5859_error,
|
||||
get<Literal>(arg).debugData->location,
|
||||
locationOf(arg),
|
||||
"Function expects " + to_string(*literalArgumentKind) + " literal."
|
||||
);
|
||||
else if (*literalArgumentKind == LiteralKind::String)
|
||||
@@ -390,7 +390,7 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
|
||||
if (!m_dataNames.count(get<Literal>(arg).value))
|
||||
m_errorReporter.typeError(
|
||||
3517_error,
|
||||
get<Literal>(arg).debugData->location,
|
||||
locationOf(arg),
|
||||
"Unknown data object \"" + std::get<Literal>(arg).value.str() + "\"."
|
||||
);
|
||||
}
|
||||
@@ -399,7 +399,7 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
|
||||
if (get<Literal>(arg).value.empty())
|
||||
m_errorReporter.typeError(
|
||||
1844_error,
|
||||
get<Literal>(arg).debugData->location,
|
||||
locationOf(arg),
|
||||
"The \"verbatim_*\" builtins cannot be used with empty bytecode."
|
||||
);
|
||||
}
|
||||
@@ -442,7 +442,7 @@ void AsmAnalyzer::operator()(Switch const& _switch)
|
||||
if (_switch.cases.size() == 1 && !_switch.cases[0].value)
|
||||
m_errorReporter.warning(
|
||||
9592_error,
|
||||
_switch.debugData->location,
|
||||
locationOf(_switch),
|
||||
"\"switch\" statement with only a default case."
|
||||
);
|
||||
|
||||
@@ -455,7 +455,7 @@ void AsmAnalyzer::operator()(Switch const& _switch)
|
||||
{
|
||||
auto watcher = m_errorReporter.errorWatcher();
|
||||
|
||||
expectType(valueType, _case.value->type, _case.value->debugData->location);
|
||||
expectType(valueType, _case.value->type, locationOf(*_case.value));
|
||||
|
||||
// We cannot use "expectExpression" here because *_case.value is not an
|
||||
// Expression and would be converted to an Expression otherwise.
|
||||
@@ -465,7 +465,7 @@ void AsmAnalyzer::operator()(Switch const& _switch)
|
||||
if (watcher.ok() && !cases.insert(valueOfLiteral(*_case.value)).second)
|
||||
m_errorReporter.declarationError(
|
||||
6792_error,
|
||||
_case.debugData->location,
|
||||
locationOf(_case),
|
||||
"Duplicate case \"" +
|
||||
valueOfLiteral(*_case.value).str() +
|
||||
"\" defined."
|
||||
@@ -565,11 +565,11 @@ void AsmAnalyzer::checkAssignment(Identifier const& _variable, YulString _valueT
|
||||
);
|
||||
|
||||
if (!holds_alternative<Scope::Variable>(*var))
|
||||
m_errorReporter.typeError(2657_error, _variable.debugData->location, "Assignment requires variable.");
|
||||
m_errorReporter.typeError(2657_error, locationOf(_variable), "Assignment requires variable.");
|
||||
else if (!m_activeVariables.count(&std::get<Scope::Variable>(*var)))
|
||||
m_errorReporter.declarationError(
|
||||
1133_error,
|
||||
_variable.debugData->location,
|
||||
locationOf(_variable),
|
||||
"Variable " + _variable.name.str() + " used before it was declared."
|
||||
);
|
||||
else
|
||||
@@ -588,11 +588,11 @@ void AsmAnalyzer::checkAssignment(Identifier const& _variable, YulString _valueT
|
||||
|
||||
if (!found && watcher.ok())
|
||||
// Only add message if the callback did not.
|
||||
m_errorReporter.declarationError(4634_error, _variable.debugData->location, "Variable not found or variable not lvalue.");
|
||||
m_errorReporter.declarationError(4634_error, locationOf(_variable), "Variable not found or variable not lvalue.");
|
||||
if (variableType && *variableType != _valueType)
|
||||
m_errorReporter.typeError(
|
||||
9547_error,
|
||||
_variable.debugData->location,
|
||||
locationOf(_variable),
|
||||
"Assigning a value of type \"" +
|
||||
_valueType.str() +
|
||||
"\" to a variable of type \"" +
|
||||
@@ -738,5 +738,5 @@ bool AsmAnalyzer::validateInstructions(evmasm::Instruction _instr, SourceLocatio
|
||||
|
||||
bool AsmAnalyzer::validateInstructions(FunctionCall const& _functionCall)
|
||||
{
|
||||
return validateInstructions(_functionCall.functionName.name.str(), _functionCall.functionName.debugData->location);
|
||||
return validateInstructions(_functionCall.functionName.name.str(), locationOf(_functionCall.functionName));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user