mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #11951 from ethereum/scopeFillerNullptr
Use locationOf helper instead of accessing debugData directly.
This commit is contained in:
commit
a66e6f08c0
@ -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));
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ namespace solidity::yul
|
||||
|
||||
Json::Value AsmJsonConverter::operator()(Block const& _node) const
|
||||
{
|
||||
Json::Value ret = createAstNode(_node.debugData->location, "YulBlock");
|
||||
Json::Value ret = createAstNode(locationOf(_node), "YulBlock");
|
||||
ret["statements"] = vectorOfVariantsToJson(_node.statements);
|
||||
return ret;
|
||||
}
|
||||
@ -41,7 +41,7 @@ Json::Value AsmJsonConverter::operator()(Block const& _node) const
|
||||
Json::Value AsmJsonConverter::operator()(TypedName const& _node) const
|
||||
{
|
||||
yulAssert(!_node.name.empty(), "Invalid variable name.");
|
||||
Json::Value ret = createAstNode(_node.debugData->location, "YulTypedName");
|
||||
Json::Value ret = createAstNode(locationOf(_node), "YulTypedName");
|
||||
ret["name"] = _node.name.str();
|
||||
ret["type"] = _node.type.str();
|
||||
return ret;
|
||||
@ -49,7 +49,7 @@ Json::Value AsmJsonConverter::operator()(TypedName const& _node) const
|
||||
|
||||
Json::Value AsmJsonConverter::operator()(Literal const& _node) const
|
||||
{
|
||||
Json::Value ret = createAstNode(_node.debugData->location, "YulLiteral");
|
||||
Json::Value ret = createAstNode(locationOf(_node), "YulLiteral");
|
||||
switch (_node.kind)
|
||||
{
|
||||
case LiteralKind::Number:
|
||||
@ -76,7 +76,7 @@ Json::Value AsmJsonConverter::operator()(Literal const& _node) const
|
||||
Json::Value AsmJsonConverter::operator()(Identifier const& _node) const
|
||||
{
|
||||
yulAssert(!_node.name.empty(), "Invalid identifier");
|
||||
Json::Value ret = createAstNode(_node.debugData->location, "YulIdentifier");
|
||||
Json::Value ret = createAstNode(locationOf(_node), "YulIdentifier");
|
||||
ret["name"] = _node.name.str();
|
||||
return ret;
|
||||
}
|
||||
@ -84,7 +84,7 @@ Json::Value AsmJsonConverter::operator()(Identifier const& _node) const
|
||||
Json::Value AsmJsonConverter::operator()(Assignment const& _node) const
|
||||
{
|
||||
yulAssert(_node.variableNames.size() >= 1, "Invalid assignment syntax");
|
||||
Json::Value ret = createAstNode(_node.debugData->location, "YulAssignment");
|
||||
Json::Value ret = createAstNode(locationOf(_node), "YulAssignment");
|
||||
for (auto const& var: _node.variableNames)
|
||||
ret["variableNames"].append((*this)(var));
|
||||
ret["value"] = _node.value ? std::visit(*this, *_node.value) : Json::nullValue;
|
||||
@ -93,7 +93,7 @@ Json::Value AsmJsonConverter::operator()(Assignment const& _node) const
|
||||
|
||||
Json::Value AsmJsonConverter::operator()(FunctionCall const& _node) const
|
||||
{
|
||||
Json::Value ret = createAstNode(_node.debugData->location, "YulFunctionCall");
|
||||
Json::Value ret = createAstNode(locationOf(_node), "YulFunctionCall");
|
||||
ret["functionName"] = (*this)(_node.functionName);
|
||||
ret["arguments"] = vectorOfVariantsToJson(_node.arguments);
|
||||
return ret;
|
||||
@ -101,14 +101,14 @@ Json::Value AsmJsonConverter::operator()(FunctionCall const& _node) const
|
||||
|
||||
Json::Value AsmJsonConverter::operator()(ExpressionStatement const& _node) const
|
||||
{
|
||||
Json::Value ret = createAstNode(_node.debugData->location, "YulExpressionStatement");
|
||||
Json::Value ret = createAstNode(locationOf(_node), "YulExpressionStatement");
|
||||
ret["expression"] = std::visit(*this, _node.expression);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Json::Value AsmJsonConverter::operator()(VariableDeclaration const& _node) const
|
||||
{
|
||||
Json::Value ret = createAstNode(_node.debugData->location, "YulVariableDeclaration");
|
||||
Json::Value ret = createAstNode(locationOf(_node), "YulVariableDeclaration");
|
||||
for (auto const& var: _node.variables)
|
||||
ret["variables"].append((*this)(var));
|
||||
|
||||
@ -120,7 +120,7 @@ Json::Value AsmJsonConverter::operator()(VariableDeclaration const& _node) const
|
||||
Json::Value AsmJsonConverter::operator()(FunctionDefinition const& _node) const
|
||||
{
|
||||
yulAssert(!_node.name.empty(), "Invalid function name.");
|
||||
Json::Value ret = createAstNode(_node.debugData->location, "YulFunctionDefinition");
|
||||
Json::Value ret = createAstNode(locationOf(_node), "YulFunctionDefinition");
|
||||
ret["name"] = _node.name.str();
|
||||
for (auto const& var: _node.parameters)
|
||||
ret["parameters"].append((*this)(var));
|
||||
@ -133,7 +133,7 @@ Json::Value AsmJsonConverter::operator()(FunctionDefinition const& _node) const
|
||||
Json::Value AsmJsonConverter::operator()(If const& _node) const
|
||||
{
|
||||
yulAssert(_node.condition, "Invalid if condition.");
|
||||
Json::Value ret = createAstNode(_node.debugData->location, "YulIf");
|
||||
Json::Value ret = createAstNode(locationOf(_node), "YulIf");
|
||||
ret["condition"] = std::visit(*this, *_node.condition);
|
||||
ret["body"] = (*this)(_node.body);
|
||||
return ret;
|
||||
@ -142,7 +142,7 @@ Json::Value AsmJsonConverter::operator()(If const& _node) const
|
||||
Json::Value AsmJsonConverter::operator()(Switch const& _node) const
|
||||
{
|
||||
yulAssert(_node.expression, "Invalid expression pointer.");
|
||||
Json::Value ret = createAstNode(_node.debugData->location, "YulSwitch");
|
||||
Json::Value ret = createAstNode(locationOf(_node), "YulSwitch");
|
||||
ret["expression"] = std::visit(*this, *_node.expression);
|
||||
for (auto const& var: _node.cases)
|
||||
ret["cases"].append((*this)(var));
|
||||
@ -151,7 +151,7 @@ Json::Value AsmJsonConverter::operator()(Switch const& _node) const
|
||||
|
||||
Json::Value AsmJsonConverter::operator()(Case const& _node) const
|
||||
{
|
||||
Json::Value ret = createAstNode(_node.debugData->location, "YulCase");
|
||||
Json::Value ret = createAstNode(locationOf(_node), "YulCase");
|
||||
ret["value"] = _node.value ? (*this)(*_node.value) : "default";
|
||||
ret["body"] = (*this)(_node.body);
|
||||
return ret;
|
||||
@ -160,7 +160,7 @@ Json::Value AsmJsonConverter::operator()(Case const& _node) const
|
||||
Json::Value AsmJsonConverter::operator()(ForLoop const& _node) const
|
||||
{
|
||||
yulAssert(_node.condition, "Invalid for loop condition.");
|
||||
Json::Value ret = createAstNode(_node.debugData->location, "YulForLoop");
|
||||
Json::Value ret = createAstNode(locationOf(_node), "YulForLoop");
|
||||
ret["pre"] = (*this)(_node.pre);
|
||||
ret["condition"] = std::visit(*this, *_node.condition);
|
||||
ret["post"] = (*this)(_node.post);
|
||||
@ -170,17 +170,17 @@ Json::Value AsmJsonConverter::operator()(ForLoop const& _node) const
|
||||
|
||||
Json::Value AsmJsonConverter::operator()(Break const& _node) const
|
||||
{
|
||||
return createAstNode(_node.debugData->location, "YulBreak");
|
||||
return createAstNode(locationOf(_node), "YulBreak");
|
||||
}
|
||||
|
||||
Json::Value AsmJsonConverter::operator()(Continue const& _node) const
|
||||
{
|
||||
return createAstNode(_node.debugData->location, "YulContinue");
|
||||
return createAstNode(locationOf(_node), "YulContinue");
|
||||
}
|
||||
|
||||
Json::Value AsmJsonConverter::operator()(Leave const& _node) const
|
||||
{
|
||||
return createAstNode(_node.debugData->location, "YulLeave");
|
||||
return createAstNode(locationOf(_node), "YulLeave");
|
||||
}
|
||||
|
||||
Json::Value AsmJsonConverter::createAstNode(langutil::SourceLocation const& _location, string _nodeType) const
|
||||
|
@ -52,7 +52,7 @@ shared_ptr<DebugData const> updateLocationEndFrom(
|
||||
langutil::SourceLocation const& _location
|
||||
)
|
||||
{
|
||||
SourceLocation updatedLocation = _debugData->location;
|
||||
SourceLocation updatedLocation = _debugData ? _debugData->location : langutil::SourceLocation{};
|
||||
updatedLocation.end = _location.end;
|
||||
return make_shared<DebugData const>(updatedLocation);
|
||||
}
|
||||
@ -245,7 +245,7 @@ Statement Parser::parseStatement()
|
||||
_if.condition = make_unique<Expression>(parseExpression());
|
||||
_if.body = parseBlock();
|
||||
if (m_useSourceLocationFrom == UseSourceLocationFrom::Scanner)
|
||||
_if.debugData = updateLocationEndFrom(_if.debugData, _if.body.debugData->location);
|
||||
_if.debugData = updateLocationEndFrom(_if.debugData, locationOf(_if.body));
|
||||
return Statement{move(_if)};
|
||||
}
|
||||
case Token::Switch:
|
||||
@ -264,7 +264,7 @@ Statement Parser::parseStatement()
|
||||
if (_switch.cases.empty())
|
||||
fatalParserError(2418_error, "Switch statement without any cases.");
|
||||
if (m_useSourceLocationFrom == UseSourceLocationFrom::Scanner)
|
||||
_switch.debugData = updateLocationEndFrom(_switch.debugData, _switch.cases.back().body.debugData->location);
|
||||
_switch.debugData = updateLocationEndFrom(_switch.debugData, locationOf(_switch.cases.back().body));
|
||||
return Statement{move(_switch)};
|
||||
}
|
||||
case Token::For:
|
||||
@ -378,7 +378,7 @@ Case Parser::parseCase()
|
||||
yulAssert(false, "Case or default case expected.");
|
||||
_case.body = parseBlock();
|
||||
if (m_useSourceLocationFrom == UseSourceLocationFrom::Scanner)
|
||||
_case.debugData = updateLocationEndFrom(_case.debugData, _case.body.debugData->location);
|
||||
_case.debugData = updateLocationEndFrom(_case.debugData, locationOf(_case.body));
|
||||
return _case;
|
||||
}
|
||||
|
||||
@ -399,7 +399,7 @@ ForLoop Parser::parseForLoop()
|
||||
m_currentForLoopComponent = ForLoopComponent::ForLoopBody;
|
||||
forLoop.body = parseBlock();
|
||||
if (m_useSourceLocationFrom == UseSourceLocationFrom::Scanner)
|
||||
forLoop.debugData = updateLocationEndFrom(forLoop.debugData, forLoop.body.debugData->location);
|
||||
forLoop.debugData = updateLocationEndFrom(forLoop.debugData, locationOf(forLoop.body));
|
||||
|
||||
m_currentForLoopComponent = outerForLoopComponent;
|
||||
|
||||
@ -419,7 +419,7 @@ Expression Parser::parseExpression()
|
||||
if (m_dialect.builtin(_identifier.name))
|
||||
fatalParserError(
|
||||
7104_error,
|
||||
_identifier.debugData->location,
|
||||
locationOf(_identifier),
|
||||
"Builtin function \"" + _identifier.name.str() + "\" must be called."
|
||||
);
|
||||
return move(_identifier);
|
||||
@ -515,7 +515,7 @@ VariableDeclaration Parser::parseVariableDeclaration()
|
||||
varDecl.debugData = updateLocationEndFrom(varDecl.debugData, locationOf(*varDecl.value));
|
||||
}
|
||||
else if (m_useSourceLocationFrom == UseSourceLocationFrom::Scanner)
|
||||
varDecl.debugData = updateLocationEndFrom(varDecl.debugData, varDecl.variables.back().debugData->location);
|
||||
varDecl.debugData = updateLocationEndFrom(varDecl.debugData, locationOf(varDecl.variables.back()));
|
||||
|
||||
return varDecl;
|
||||
}
|
||||
@ -562,7 +562,7 @@ FunctionDefinition Parser::parseFunctionDefinition()
|
||||
funDef.body = parseBlock();
|
||||
m_insideFunction = preInsideFunction;
|
||||
if (m_useSourceLocationFrom == UseSourceLocationFrom::Scanner)
|
||||
funDef.debugData = updateLocationEndFrom(funDef.debugData, funDef.body.debugData->location);
|
||||
funDef.debugData = updateLocationEndFrom(funDef.debugData, locationOf(funDef.body));
|
||||
|
||||
m_currentForLoopComponent = outerForLoopComponent;
|
||||
return funDef;
|
||||
|
@ -53,7 +53,7 @@ bool ScopeFiller::operator()(ExpressionStatement const& _expr)
|
||||
bool ScopeFiller::operator()(VariableDeclaration const& _varDecl)
|
||||
{
|
||||
for (auto const& variable: _varDecl.variables)
|
||||
if (!registerVariable(variable, _varDecl.debugData->location, *m_currentScope))
|
||||
if (!registerVariable(variable, locationOf(_varDecl), *m_currentScope))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@ -68,7 +68,7 @@ bool ScopeFiller::operator()(FunctionDefinition const& _funDef)
|
||||
|
||||
bool success = true;
|
||||
for (auto const& var: _funDef.parameters + _funDef.returnVariables)
|
||||
if (!registerVariable(var, _funDef.debugData->location, varScope))
|
||||
if (!registerVariable(var, locationOf(_funDef), varScope))
|
||||
success = false;
|
||||
|
||||
if (!(*this)(_funDef.body))
|
||||
@ -162,7 +162,7 @@ bool ScopeFiller::registerFunction(FunctionDefinition const& _funDef)
|
||||
//@TODO secondary location
|
||||
m_errorReporter.declarationError(
|
||||
6052_error,
|
||||
_funDef.debugData->location,
|
||||
locationOf(_funDef),
|
||||
"Function name " + _funDef.name.str() + " already taken in this scope."
|
||||
);
|
||||
return false;
|
||||
|
@ -44,16 +44,6 @@ using namespace solidity;
|
||||
using namespace solidity::yul;
|
||||
using namespace solidity::util;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
langutil::SourceLocation extractSourceLocationFromDebugData(shared_ptr<DebugData const> const& _debugData)
|
||||
{
|
||||
return _debugData ? _debugData->location : langutil::SourceLocation{};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
CodeTransform::CodeTransform(
|
||||
AbstractAssembly& _assembly,
|
||||
AsmAnalysisInfo& _analysisInfo,
|
||||
@ -155,13 +145,13 @@ void CodeTransform::operator()(VariableDeclaration const& _varDecl)
|
||||
}
|
||||
else
|
||||
{
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_varDecl.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_varDecl));
|
||||
size_t variablesLeft = numVariables;
|
||||
while (variablesLeft--)
|
||||
m_assembly.appendConstant(u256(0));
|
||||
}
|
||||
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_varDecl.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_varDecl));
|
||||
bool atTopOfStack = true;
|
||||
for (size_t varIndex = 0; varIndex < numVariables; ++varIndex)
|
||||
{
|
||||
@ -223,13 +213,13 @@ void CodeTransform::operator()(Assignment const& _assignment)
|
||||
std::visit(*this, *_assignment.value);
|
||||
expectDeposit(static_cast<int>(_assignment.variableNames.size()), height);
|
||||
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_assignment.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_assignment));
|
||||
generateMultiAssignment(_assignment.variableNames);
|
||||
}
|
||||
|
||||
void CodeTransform::operator()(ExpressionStatement const& _statement)
|
||||
{
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_statement.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_statement));
|
||||
std::visit(*this, _statement.expression);
|
||||
}
|
||||
|
||||
@ -237,13 +227,13 @@ void CodeTransform::operator()(FunctionCall const& _call)
|
||||
{
|
||||
yulAssert(m_scope, "");
|
||||
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_call.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_call));
|
||||
if (BuiltinFunctionForEVM const* builtin = m_dialect.builtin(_call.functionName.name))
|
||||
{
|
||||
for (auto&& [i, arg]: _call.arguments | ranges::views::enumerate | ranges::views::reverse)
|
||||
if (!builtin->literalArgument(i))
|
||||
visitExpression(arg);
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_call.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_call));
|
||||
builtin->generateCode(_call, m_assembly, m_builtinContext);
|
||||
}
|
||||
else
|
||||
@ -260,7 +250,7 @@ void CodeTransform::operator()(FunctionCall const& _call)
|
||||
yulAssert(function->arguments.size() == _call.arguments.size(), "");
|
||||
for (auto const& arg: _call.arguments | ranges::views::reverse)
|
||||
visitExpression(arg);
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_call.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_call));
|
||||
m_assembly.appendJumpTo(
|
||||
functionEntryID(_call.functionName.name, *function),
|
||||
static_cast<int>(function->returns.size() - function->arguments.size()) - 1,
|
||||
@ -272,7 +262,7 @@ void CodeTransform::operator()(FunctionCall const& _call)
|
||||
|
||||
void CodeTransform::operator()(Identifier const& _identifier)
|
||||
{
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_identifier.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_identifier));
|
||||
// First search internals, then externals.
|
||||
yulAssert(m_scope, "");
|
||||
if (m_scope->lookup(_identifier.name, GenericVisitor{
|
||||
@ -304,19 +294,19 @@ void CodeTransform::operator()(Identifier const& _identifier)
|
||||
|
||||
void CodeTransform::operator()(Literal const& _literal)
|
||||
{
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_literal.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_literal));
|
||||
m_assembly.appendConstant(valueOfLiteral(_literal));
|
||||
}
|
||||
|
||||
void CodeTransform::operator()(If const& _if)
|
||||
{
|
||||
visitExpression(*_if.condition);
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_if.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_if));
|
||||
m_assembly.appendInstruction(evmasm::Instruction::ISZERO);
|
||||
AbstractAssembly::LabelID end = m_assembly.newLabelId();
|
||||
m_assembly.appendJumpToIf(end);
|
||||
(*this)(_if.body);
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_if.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_if));
|
||||
m_assembly.appendLabel(end);
|
||||
}
|
||||
|
||||
@ -331,7 +321,7 @@ void CodeTransform::operator()(Switch const& _switch)
|
||||
if (c.value)
|
||||
{
|
||||
(*this)(*c.value);
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(c.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(c));
|
||||
AbstractAssembly::LabelID bodyLabel = m_assembly.newLabelId();
|
||||
caseBodies[&c] = bodyLabel;
|
||||
yulAssert(m_assembly.stackHeight() == expressionHeight + 1, "");
|
||||
@ -343,24 +333,24 @@ void CodeTransform::operator()(Switch const& _switch)
|
||||
// default case
|
||||
(*this)(c.body);
|
||||
}
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_switch.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_switch));
|
||||
m_assembly.appendJumpTo(end);
|
||||
|
||||
size_t numCases = caseBodies.size();
|
||||
for (auto const& c: caseBodies)
|
||||
{
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(c.first->debugData));
|
||||
m_assembly.setSourceLocation(locationOf(*c.first));
|
||||
m_assembly.appendLabel(c.second);
|
||||
(*this)(c.first->body);
|
||||
// Avoid useless "jump to next" for the last case.
|
||||
if (--numCases > 0)
|
||||
{
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(c.first->debugData));
|
||||
m_assembly.setSourceLocation(locationOf(*c.first));
|
||||
m_assembly.appendJumpTo(end);
|
||||
}
|
||||
}
|
||||
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_switch.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_switch));
|
||||
m_assembly.appendLabel(end);
|
||||
m_assembly.appendInstruction(evmasm::Instruction::POP);
|
||||
}
|
||||
@ -381,7 +371,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
|
||||
m_context->variableStackHeights[&var] = height++;
|
||||
}
|
||||
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_function.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_function));
|
||||
int const stackHeightBefore = m_assembly.stackHeight();
|
||||
|
||||
m_assembly.appendLabel(functionEntryID(_function.name, function));
|
||||
@ -417,7 +407,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
|
||||
|
||||
subTransform(_function.body);
|
||||
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_function.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_function));
|
||||
if (!subTransform.m_stackErrors.empty())
|
||||
{
|
||||
m_assembly.markAsInvalid();
|
||||
@ -508,11 +498,11 @@ void CodeTransform::operator()(ForLoop const& _forLoop)
|
||||
AbstractAssembly::LabelID postPart = m_assembly.newLabelId();
|
||||
AbstractAssembly::LabelID loopEnd = m_assembly.newLabelId();
|
||||
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_forLoop.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_forLoop));
|
||||
m_assembly.appendLabel(loopStart);
|
||||
|
||||
visitExpression(*_forLoop.condition);
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_forLoop.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_forLoop));
|
||||
m_assembly.appendInstruction(evmasm::Instruction::ISZERO);
|
||||
m_assembly.appendJumpToIf(loopEnd);
|
||||
|
||||
@ -520,12 +510,12 @@ void CodeTransform::operator()(ForLoop const& _forLoop)
|
||||
m_context->forLoopStack.emplace(Context::ForLoopLabels{ {postPart, stackHeightBody}, {loopEnd, stackHeightBody} });
|
||||
(*this)(_forLoop.body);
|
||||
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_forLoop.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_forLoop));
|
||||
m_assembly.appendLabel(postPart);
|
||||
|
||||
(*this)(_forLoop.post);
|
||||
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_forLoop.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_forLoop));
|
||||
m_assembly.appendJumpTo(loopStart);
|
||||
m_assembly.appendLabel(loopEnd);
|
||||
|
||||
@ -545,7 +535,7 @@ int CodeTransform::appendPopUntil(int _targetDepth)
|
||||
void CodeTransform::operator()(Break const& _break)
|
||||
{
|
||||
yulAssert(!m_context->forLoopStack.empty(), "Invalid break-statement. Requires surrounding for-loop in code generation.");
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_break.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_break));
|
||||
|
||||
Context::JumpInfo const& jump = m_context->forLoopStack.top().done;
|
||||
m_assembly.appendJumpTo(jump.label, appendPopUntil(jump.targetStackHeight));
|
||||
@ -554,7 +544,7 @@ void CodeTransform::operator()(Break const& _break)
|
||||
void CodeTransform::operator()(Continue const& _continue)
|
||||
{
|
||||
yulAssert(!m_context->forLoopStack.empty(), "Invalid continue-statement. Requires surrounding for-loop in code generation.");
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_continue.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_continue));
|
||||
|
||||
Context::JumpInfo const& jump = m_context->forLoopStack.top().post;
|
||||
m_assembly.appendJumpTo(jump.label, appendPopUntil(jump.targetStackHeight));
|
||||
@ -564,7 +554,7 @@ void CodeTransform::operator()(Leave const& _leaveStatement)
|
||||
{
|
||||
yulAssert(m_functionExitLabel, "Invalid leave-statement. Requires surrounding function in code generation.");
|
||||
yulAssert(m_functionExitStackHeight, "");
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_leaveStatement.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_leaveStatement));
|
||||
m_assembly.appendJumpTo(*m_functionExitLabel, appendPopUntil(*m_functionExitStackHeight));
|
||||
}
|
||||
|
||||
@ -676,7 +666,7 @@ void CodeTransform::visitStatements(vector<Statement> const& _statements)
|
||||
auto const* functionDefinition = std::get_if<FunctionDefinition>(&statement);
|
||||
if (functionDefinition && !jumpTarget)
|
||||
{
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(functionDefinition->debugData));
|
||||
m_assembly.setSourceLocation(locationOf(*functionDefinition));
|
||||
jumpTarget = m_assembly.newLabelId();
|
||||
m_assembly.appendJumpTo(*jumpTarget, 0);
|
||||
}
|
||||
@ -697,7 +687,7 @@ void CodeTransform::visitStatements(vector<Statement> const& _statements)
|
||||
|
||||
void CodeTransform::finalizeBlock(Block const& _block, optional<int> blockStartStackHeight)
|
||||
{
|
||||
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_block.debugData));
|
||||
m_assembly.setSourceLocation(locationOf(_block));
|
||||
|
||||
freeUnusedVariables();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user