@@ -236,7 +236,9 @@ bool ReferencesResolver::visit(UsingForDirective const& _usingFor)
236236bool ReferencesResolver::visit (InlineAssembly const & _inlineAssembly)
237237{
238238 m_yulAnnotation = &_inlineAssembly.annotation ();
239+ m_yulNameRepository = &_inlineAssembly.nameRepository ();
239240 (*this )(_inlineAssembly.operations ());
241+ m_yulNameRepository = nullptr ;
240242 m_yulAnnotation = nullptr ;
241243
242244 return false ;
@@ -270,12 +272,13 @@ bool ReferencesResolver::visit(BinaryOperation const& _binaryOperation)
270272
271273void ReferencesResolver::operator ()(yul::FunctionDefinition const & _function)
272274{
275+ solAssert (m_yulNameRepository != nullptr );
273276 solAssert (nativeLocationOf (_function) == originLocationOf (_function), " " );
274- validateYulIdentifierName (_function.name , nativeLocationOf (_function));
277+ validateYulIdentifierName (m_yulNameRepository-> labelOf ( _function.name ) , nativeLocationOf (_function));
275278 for (yul::TypedName const & varName: _function.parameters + _function.returnVariables )
276279 {
277280 solAssert (nativeLocationOf (varName) == originLocationOf (varName), " " );
278- validateYulIdentifierName (varName.name , nativeLocationOf (varName));
281+ validateYulIdentifierName (m_yulNameRepository-> labelOf ( varName.name ) , nativeLocationOf (varName));
279282 }
280283
281284 bool wasInsideFunction = m_yulInsideFunction;
@@ -286,12 +289,13 @@ void ReferencesResolver::operator()(yul::FunctionDefinition const& _function)
286289
287290void ReferencesResolver::operator ()(yul::Identifier const & _identifier)
288291{
292+ solAssert (m_yulNameRepository != nullptr );
289293 solAssert (nativeLocationOf (_identifier) == originLocationOf (_identifier), " " );
290-
294+ auto const identifierLabel = m_yulNameRepository-> labelOf (_identifier. name );
291295 if (m_resolver.experimentalSolidity ())
292296 {
293297 std::vector<std::string> splitName;
294- boost::split (splitName, _identifier. name . str () , boost::is_any_of (" ." ));
298+ boost::split (splitName, identifierLabel , boost::is_any_of (" ." ));
295299 solAssert (!splitName.empty ());
296300 if (splitName.size () > 2 )
297301 {
@@ -332,22 +336,22 @@ void ReferencesResolver::operator()(yul::Identifier const& _identifier)
332336 static std::set<std::string> suffixes{" slot" , " offset" , " length" , " address" , " selector" };
333337 std::string suffix;
334338 for (std::string const & s: suffixes)
335- if (boost::algorithm::ends_with (_identifier. name . str () , " ." + s))
339+ if (boost::algorithm::ends_with (identifierLabel , " ." + s))
336340 suffix = s;
337341
338342 // Could also use `pathFromCurrentScope`, split by '.'.
339343 // If we do that, suffix should only be set for when it has a special
340344 // meaning, not for normal identifierPaths.
341- auto declarations = m_resolver.nameFromCurrentScope (_identifier. name . str ( ));
345+ auto declarations = m_resolver.nameFromCurrentScope (std::string (identifierLabel ));
342346 if (!suffix.empty ())
343347 {
344348 // special mode to access storage variables
345349 if (!declarations.empty ())
346350 // the special identifier exists itself, we should not allow that.
347351 return ;
348- std::string realName = _identifier. name . str (). substr (0 , _identifier. name . str () .size () - suffix.size () - 1 );
352+ auto const realName = identifierLabel. substr (0 , identifierLabel .size () - suffix.size () - 1 );
349353 solAssert (!realName.empty (), " Empty name." );
350- declarations = m_resolver.nameFromCurrentScope (realName);
354+ declarations = m_resolver.nameFromCurrentScope (std::string ( realName) );
351355 if (!declarations.empty ())
352356 // To support proper path resolution, we have to use pathFromCurrentScope.
353357 solAssert (!util::contains (realName, ' .' ), " " );
@@ -364,8 +368,8 @@ void ReferencesResolver::operator()(yul::Identifier const& _identifier)
364368 else if (declarations.size () == 0 )
365369 {
366370 if (
367- boost::algorithm::ends_with (_identifier. name . str () , " _slot" ) ||
368- boost::algorithm::ends_with (_identifier. name . str () , " _offset" )
371+ boost::algorithm::ends_with (identifierLabel , " _slot" ) ||
372+ boost::algorithm::ends_with (identifierLabel , " _offset" )
369373 )
370374 m_errorReporter.declarationError (
371375 9467_error,
@@ -391,13 +395,14 @@ void ReferencesResolver::operator()(yul::Identifier const& _identifier)
391395
392396void ReferencesResolver::operator ()(yul::VariableDeclaration const & _varDecl)
393397{
398+ solAssert (m_yulNameRepository != nullptr );
394399 for (auto const & identifier: _varDecl.variables )
395400 {
396401 solAssert (nativeLocationOf (identifier) == originLocationOf (identifier), " " );
397- validateYulIdentifierName (identifier.name , nativeLocationOf (identifier));
402+ validateYulIdentifierName (m_yulNameRepository-> labelOf ( identifier.name ) , nativeLocationOf (identifier));
398403
399404 if (
400- auto declarations = m_resolver.nameFromCurrentScope (identifier.name . str ( ));
405+ auto declarations = m_resolver.nameFromCurrentScope (std::string (m_yulNameRepository-> labelOf ( identifier.name ) ));
401406 !declarations.empty ()
402407 )
403408 {
@@ -488,19 +493,19 @@ void ReferencesResolver::resolveInheritDoc(StructuredDocumentation const& _docum
488493 }
489494}
490495
491- void ReferencesResolver::validateYulIdentifierName (yul::YulString _name, SourceLocation const & _location)
496+ void ReferencesResolver::validateYulIdentifierName (std::string_view const _name, SourceLocation const & _location)
492497{
493- if (util::contains (_name. str () , ' .' ))
498+ if (util::contains (_name, ' .' ))
494499 m_errorReporter.declarationError (
495500 3927_error,
496501 _location,
497502 " User-defined identifiers in inline assembly cannot contain '.'."
498503 );
499504
500- if (std::set<std::string> {" this" , " super" , " _" }.count (_name. str () ))
505+ if (std::set<std::string, std::less<>> {" this" , " super" , " _" }.count (_name))
501506 m_errorReporter.declarationError (
502507 4113_error,
503508 _location,
504- " The identifier name \" " + _name. str () + " \" is reserved."
509+ fmt::format ( " The identifier name \" {} \" is reserved." , _name)
505510 );
506511}
0 commit comments