Separate DebugData fields for Solidity and Yul source locations

This commit is contained in:
Kamil Śliwak
2021-09-22 13:11:39 +02:00
parent 9c1d40debf
commit ce4420f857
21 changed files with 281 additions and 242 deletions
+35 -35
View File
@@ -96,22 +96,22 @@ AsmAnalysisInfo AsmAnalyzer::analyzeStrictAssertCorrect(Dialect const& _dialect,
vector<YulString> AsmAnalyzer::operator()(Literal const& _literal)
{
expectValidType(_literal.type, locationOf(_literal));
expectValidType(_literal.type, nativeLocationOf(_literal));
if (_literal.kind == LiteralKind::String && _literal.value.str().size() > 32)
m_errorReporter.typeError(
3069_error,
locationOf(_literal),
nativeLocationOf(_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, locationOf(_literal), "Number literal too large (> 256 bits)");
m_errorReporter.typeError(6708_error, nativeLocationOf(_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,
locationOf(_literal),
nativeLocationOf(_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,
locationOf(_identifier),
nativeLocationOf(_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,
locationOf(_identifier),
nativeLocationOf(_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,
locationOf(_identifier),
nativeLocationOf(_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,
locationOf(_statement),
nativeLocationOf(_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,
locationOf(_assignment),
nativeLocationOf(_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,
locationOf(_assignment),
nativeLocationOf(_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, locationOf(variable));
expectValidType(variable.type, locationOf(variable));
expectValidIdentifier(variable.name, nativeLocationOf(variable));
expectValidType(variable.type, nativeLocationOf(variable));
}
if (_varDecl.value)
@@ -250,7 +250,7 @@ void AsmAnalyzer::operator()(VariableDeclaration const& _varDecl)
if (types.size() != numVariables)
m_errorReporter.declarationError(
3812_error,
locationOf(_varDecl),
nativeLocationOf(_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,
locationOf(variable),
nativeLocationOf(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, locationOf(_funDef));
expectValidIdentifier(_funDef.name, nativeLocationOf(_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, locationOf(var));
expectValidType(var.type, locationOf(var));
expectValidIdentifier(var.name, nativeLocationOf(var));
expectValidType(var.type, nativeLocationOf(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,
locationOf(_funCall.functionName),
nativeLocationOf(_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,
locationOf(_funCall.functionName),
nativeLocationOf(_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,
locationOf(_funCall.functionName),
nativeLocationOf(_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,
locationOf(_funCall.functionName),
nativeLocationOf(_funCall.functionName),
"Function expects direct literals as arguments."
);
else if (*literalArgumentKind != get<Literal>(arg).kind)
m_errorReporter.typeError(
5859_error,
locationOf(arg),
nativeLocationOf(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,
locationOf(arg),
nativeLocationOf(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,
locationOf(arg),
nativeLocationOf(arg),
"The \"verbatim_*\" builtins cannot be used with empty bytecode."
);
}
@@ -414,7 +414,7 @@ vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
if (parameterTypes && parameterTypes->size() == argTypes.size())
for (size_t i = 0; i < parameterTypes->size(); ++i)
expectType((*parameterTypes)[i], argTypes[i], locationOf(_funCall.arguments[i]));
expectType((*parameterTypes)[i], argTypes[i], nativeLocationOf(_funCall.arguments[i]));
if (watcher.ok())
{
@@ -442,7 +442,7 @@ void AsmAnalyzer::operator()(Switch const& _switch)
if (_switch.cases.size() == 1 && !_switch.cases[0].value)
m_errorReporter.warning(
9592_error,
locationOf(_switch),
nativeLocationOf(_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, locationOf(*_case.value));
expectType(valueType, _case.value->type, nativeLocationOf(*_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,
locationOf(_case),
nativeLocationOf(_case),
"Duplicate case \"" +
valueOfLiteral(*_case.value).str() +
"\" defined."
@@ -517,7 +517,7 @@ YulString AsmAnalyzer::expectExpression(Expression const& _expr)
if (types.size() != 1)
m_errorReporter.typeError(
3950_error,
locationOf(_expr),
nativeLocationOf(_expr),
"Expected expression to evaluate to one value, but got " +
to_string(types.size()) +
" values instead."
@@ -539,7 +539,7 @@ void AsmAnalyzer::expectBoolExpression(Expression const& _expr)
if (type != m_dialect.boolType)
m_errorReporter.typeError(
1733_error,
locationOf(_expr),
nativeLocationOf(_expr),
"Expected a value of boolean type \"" +
m_dialect.boolType.str() +
"\" but got \"" +
@@ -565,11 +565,11 @@ void AsmAnalyzer::checkAssignment(Identifier const& _variable, YulString _valueT
);
if (!holds_alternative<Scope::Variable>(*var))
m_errorReporter.typeError(2657_error, locationOf(_variable), "Assignment requires variable.");
m_errorReporter.typeError(2657_error, nativeLocationOf(_variable), "Assignment requires variable.");
else if (!m_activeVariables.count(&std::get<Scope::Variable>(*var)))
m_errorReporter.declarationError(
1133_error,
locationOf(_variable),
nativeLocationOf(_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, locationOf(_variable), "Variable not found or variable not lvalue.");
m_errorReporter.declarationError(4634_error, nativeLocationOf(_variable), "Variable not found or variable not lvalue.");
if (variableType && *variableType != _valueType)
m_errorReporter.typeError(
9547_error,
locationOf(_variable),
nativeLocationOf(_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(), locationOf(_functionCall.functionName));
return validateInstructions(_functionCall.functionName.name.str(), nativeLocationOf(_functionCall.functionName));
}