Rename source location function.

This commit is contained in:
chriseth 2021-09-06 18:26:30 +02:00
parent f14b7598c7
commit 5093cff7ae
5 changed files with 29 additions and 28 deletions

View File

@ -127,7 +127,7 @@ string IRNames::zeroValue(Type const& _type, string const& _variableName)
return "zero_" + _type.identifier() + _variableName;
}
string sourceLocationComment(langutil::SourceLocation const& _location, IRGenerationContext& _context)
string dispenseLocationComment(langutil::SourceLocation const& _location, IRGenerationContext& _context)
{
solAssert(_location.sourceName, "");
_context.markSourceUsed(*_location.sourceName);
@ -139,9 +139,9 @@ string sourceLocationComment(langutil::SourceLocation const& _location, IRGenera
+ to_string(_location.end);
}
string sourceLocationComment(ASTNode const& _node, IRGenerationContext& _context)
string dispenseLocationComment(ASTNode const& _node, IRGenerationContext& _context)
{
return sourceLocationComment(_node.location(), _context);
return dispenseLocationComment(_node.location(), _context);
}
}

View File

@ -71,10 +71,11 @@ struct IRNames
/**
* @returns a source location comment in the form of
* `/// @src <sourceIndex>:<locationStart>:<locationEnd>`.
* `/// @src <sourceIndex>:<locationStart>:<locationEnd>`
* and marks the source index as used.
*/
std::string sourceLocationComment(langutil::SourceLocation const& _location, IRGenerationContext& _context);
std::string sourceLocationComment(ASTNode const& _node, IRGenerationContext& _context);
std::string dispenseLocationComment(langutil::SourceLocation const& _location, IRGenerationContext& _context);
std::string dispenseLocationComment(ASTNode const& _node, IRGenerationContext& _context);
}

View File

@ -179,7 +179,7 @@ string IRGenerator::generate(
m_context.registerImmutableVariable(*var);
t("CreationObject", IRNames::creationObject(_contract));
t("sourceLocationCommentCreation", sourceLocationComment(_contract));
t("sourceLocationCommentCreation", dispenseLocationComment(_contract));
t("library", _contract.isLibrary());
FunctionDefinition const* constructor = _contract.constructor();
@ -220,7 +220,7 @@ string IRGenerator::generate(
// Do not register immutables to avoid assignment.
t("DeployedObject", IRNames::deployedObject(_contract));
t("sourceLocationCommentDeployed", sourceLocationComment(_contract));
t("sourceLocationCommentDeployed", dispenseLocationComment(_contract));
t("library_address", IRNames::libraryAddressImmutable());
t("dispatch", dispatchRoutine(_contract));
set<FunctionDefinition const*> deployedFunctionList = generateQueuedFunctions();
@ -294,7 +294,7 @@ InternalDispatchMap IRGenerator::generateInternalDispatchFunctions(ContractDefin
}
<sourceLocationComment>
)");
templ("sourceLocationComment", sourceLocationComment(_contract));
templ("sourceLocationComment", dispenseLocationComment(_contract));
templ("functionName", funName);
templ("panic", m_utils.panicFunction(PanicCode::InvalidInternalFunction));
templ("in", suffixedVariableNameList("in_", 0, arity.in));
@ -347,10 +347,10 @@ string IRGenerator::generateFunction(FunctionDefinition const& _function)
<contractSourceLocationComment>
)");
t("sourceLocationComment", sourceLocationComment(_function));
t("sourceLocationComment", dispenseLocationComment(_function));
t(
"contractSourceLocationComment",
sourceLocationComment(m_context.mostDerivedContract())
dispenseLocationComment(m_context.mostDerivedContract())
);
t("functionName", functionName);
@ -436,10 +436,10 @@ string IRGenerator::generateModifier(
_modifierInvocation.name().annotation().referencedDeclaration
);
solAssert(modifier, "");
t("sourceLocationComment", sourceLocationComment(*modifier));
t("sourceLocationComment", dispenseLocationComment(*modifier));
t(
"contractSourceLocationComment",
sourceLocationComment(m_context.mostDerivedContract())
dispenseLocationComment(m_context.mostDerivedContract())
);
switch (*_modifierInvocation.name().annotation().requiredLookup)
@ -499,10 +499,10 @@ string IRGenerator::generateFunctionWithModifierInner(FunctionDefinition const&
}
<contractSourceLocationComment>
)");
t("sourceLocationComment", sourceLocationComment(_function));
t("sourceLocationComment", dispenseLocationComment(_function));
t(
"contractSourceLocationComment",
sourceLocationComment(m_context.mostDerivedContract())
dispenseLocationComment(m_context.mostDerivedContract())
);
t("functionName", functionName);
vector<string> retParams;
@ -547,10 +547,10 @@ string IRGenerator::generateGetter(VariableDeclaration const& _varDecl)
}
<contractSourceLocationComment>
)")
("sourceLocationComment", sourceLocationComment(_varDecl))
("sourceLocationComment", dispenseLocationComment(_varDecl))
(
"contractSourceLocationComment",
sourceLocationComment(m_context.mostDerivedContract())
dispenseLocationComment(m_context.mostDerivedContract())
)
("functionName", functionName)
("id", to_string(_varDecl.id()))
@ -566,10 +566,10 @@ string IRGenerator::generateGetter(VariableDeclaration const& _varDecl)
}
<contractSourceLocationComment>
)")
("sourceLocationComment", sourceLocationComment(_varDecl))
("sourceLocationComment", dispenseLocationComment(_varDecl))
(
"contractSourceLocationComment",
sourceLocationComment(m_context.mostDerivedContract())
dispenseLocationComment(m_context.mostDerivedContract())
)
("functionName", functionName)
("constantValueFunction", IRGeneratorForStatements(m_context, m_utils).constantValueFunction(_varDecl))
@ -692,10 +692,10 @@ string IRGenerator::generateGetter(VariableDeclaration const& _varDecl)
("params", joinHumanReadable(parameters))
("retVariables", joinHumanReadable(returnVariables))
("code", std::move(code))
("sourceLocationComment", sourceLocationComment(_varDecl))
("sourceLocationComment", dispenseLocationComment(_varDecl))
(
"contractSourceLocationComment",
sourceLocationComment(m_context.mostDerivedContract())
dispenseLocationComment(m_context.mostDerivedContract())
)
.render();
});
@ -818,14 +818,14 @@ void IRGenerator::generateConstructors(ContractDefinition const& _contract)
for (ASTPointer<VariableDeclaration> const& varDecl: contract->constructor()->parameters())
params += m_context.addLocalVariable(*varDecl).stackSlots();
t("sourceLocationComment", sourceLocationComment(
t("sourceLocationComment", dispenseLocationComment(
contract->constructor() ?
dynamic_cast<ASTNode const&>(*contract->constructor()) :
dynamic_cast<ASTNode const&>(*contract)
));
t(
"contractSourceLocationComment",
sourceLocationComment(m_context.mostDerivedContract())
dispenseLocationComment(m_context.mostDerivedContract())
);
t("params", joinHumanReadable(params));
@ -1073,7 +1073,7 @@ void IRGenerator::resetContext(ContractDefinition const& _contract, ExecutionCon
m_context.addStateVariable(*get<0>(var), get<1>(var), get<2>(var));
}
string IRGenerator::sourceLocationComment(ASTNode const& _node)
string IRGenerator::dispenseLocationComment(ASTNode const& _node)
{
return ::sourceLocationComment(_node, m_context);
return ::dispenseLocationComment(_node, m_context);
}

View File

@ -119,7 +119,7 @@ private:
void resetContext(ContractDefinition const& _contract, ExecutionContext _context);
std::string sourceLocationComment(ASTNode const& _node);
std::string dispenseLocationComment(ASTNode const& _node);
langutil::EVMVersion const m_evmVersion;
OptimiserSettings const m_optimiserSettings;

View File

@ -217,7 +217,7 @@ std::ostringstream& IRGeneratorForStatementsBase::appendCode(bool _addLocationCo
m_currentLocation.isValid() &&
m_lastLocation != m_currentLocation
)
m_code << sourceLocationComment(m_currentLocation, m_context) << "\n";
m_code << dispenseLocationComment(m_currentLocation, m_context) << "\n";
m_lastLocation = m_currentLocation;
@ -340,7 +340,7 @@ string IRGeneratorForStatements::constantValueFunction(VariableDeclaration const
<ret> := <value>
}
)");
templ("sourceLocationComment", sourceLocationComment(_constant, m_context));
templ("sourceLocationComment", dispenseLocationComment(_constant, m_context));
templ("functionName", functionName);
IRGeneratorForStatements generator(m_context, m_utils);
solAssert(_constant.value(), "");