@@ -101,22 +101,22 @@ AsmAnalysisInfo AsmAnalyzer::analyzeStrictAssertCorrect(Dialect const& _dialect,
101101std::vector<YulString> AsmAnalyzer::operator ()(Literal const & _literal)
102102{
103103 expectValidType (_literal.type , nativeLocationOf (_literal));
104- if (_literal.kind == LiteralKind::String && _literal. value . str (). size () > 32 )
104+ if (_literal.kind == LiteralKind::String && ! validStringLiteral (_literal) )
105105 m_errorReporter.typeError (
106106 3069_error,
107107 nativeLocationOf (_literal),
108- " String literal too long (" + std::to_string (_literal. value . str ( ).size ()) + " > 32)"
108+ " String literal too long (" + std::to_string (formatLiteral (_literal ).size ()) + " > 32)"
109109 );
110- else if (_literal.kind == LiteralKind::Number && bigint (_literal. value . str ()) > u256 (- 1 ))
110+ else if (_literal.kind == LiteralKind::Number && ! validNumberLiteral (_literal))
111111 m_errorReporter.typeError (6708_error, nativeLocationOf (_literal), " Number literal too large (> 256 bits)" );
112112 else if (_literal.kind == LiteralKind::Boolean)
113- yulAssert (_literal. value == " true " _yulstring || _literal. value == " false " _yulstring, " " );
113+ yulAssert (validBoolLiteral ( _literal) );
114114
115115 if (!m_dialect.validTypeForLiteral (_literal.kind , _literal.value , _literal.type ))
116116 m_errorReporter.typeError (
117117 5170_error,
118118 nativeLocationOf (_literal),
119- " Invalid type \" " + _literal.type .str () + " \" for literal \" " + _literal. value . str ( ) + " \" ."
119+ " Invalid type \" " + _literal.type .str () + " \" for literal \" " + formatLiteral (_literal ) + " \" ."
120120 );
121121
122122 return {_literal.type };
@@ -417,24 +417,31 @@ std::vector<YulString> AsmAnalyzer::operator()(FunctionCall const& _funCall)
417417 std::string functionName = _funCall.functionName .name .str ();
418418 if (functionName == " datasize" || functionName == " dataoffset" )
419419 {
420- if (!m_dataNames.count (std::get<Literal>(arg).value ))
420+ auto const & argumentAsLiteral = std::get<Literal>(arg);
421+ if (!m_dataNames.count (YulString (formatLiteral (argumentAsLiteral))))
421422 m_errorReporter.typeError (
422423 3517_error,
423424 nativeLocationOf (arg),
424- " Unknown data object \" " + std::get<Literal>(arg). value . str ( ) + " \" ."
425+ " Unknown data object \" " + formatLiteral (argumentAsLiteral ) + " \" ."
425426 );
426427 }
427428 else if (functionName.substr (0 , " verbatim_" s.size ()) == " verbatim_" )
428429 {
429- if (std::get<Literal>(arg).value .empty ())
430+ static u256 const empty {valueOfStringLiteral (" " ).value ()};
431+ auto const & literalValue = std::get<Literal>(arg).value ;
432+ if ((literalValue.unlimited () && literalValue.builtinStringLiteralValue ().empty ()) || (!literalValue.unlimited () && literalValue.value () == empty))
430433 m_errorReporter.typeError (
431434 1844_error,
432435 nativeLocationOf (arg),
433436 " The \" verbatim_*\" builtins cannot be used with empty bytecode."
434437 );
435438 }
436-
437- argTypes.emplace_back (expectUnlimitedStringLiteral (std::get<Literal>(arg)));
439+ bool const isUnlimitedLiteralArgument = [&]() {
440+ if (BuiltinFunction const * f = m_dialect.builtin (_funCall.functionName .name ))
441+ return f->literalArguments .size () >= i && f->literalArguments .at (i-1 ).has_value ();
442+ return false ;
443+ }();
444+ argTypes.emplace_back (expectStringLiteral (std::get<Literal>(arg), isUnlimitedLiteralArgument));
438445 continue ;
439446 }
440447 }
@@ -492,12 +499,12 @@ void AsmAnalyzer::operator()(Switch const& _switch)
492499 (*this )(*_case.value );
493500
494501 // / Note: the parser ensures there is only one default case
495- if (watcher.ok () && !cases.insert (valueOfLiteral (* _case.value )).second )
502+ if (watcher.ok () && !cases.insert (_case.value -> value . value ( )).second )
496503 m_errorReporter.declarationError (
497504 6792_error,
498505 nativeLocationOf (_case),
499506 " Duplicate case \" " +
500- valueOfLiteral (*_case.value ). str ( ) +
507+ formatLiteral (*_case.value ) +
501508 " \" defined."
502509 );
503510 }
@@ -555,10 +562,11 @@ YulString AsmAnalyzer::expectExpression(Expression const& _expr)
555562 return types.empty () ? m_dialect.defaultType : types.front ();
556563}
557564
558- YulString AsmAnalyzer::expectUnlimitedStringLiteral (Literal const & _literal)
565+ YulString AsmAnalyzer::expectStringLiteral (Literal const & _literal, bool const _expectUnlimitedLiteralArgument )
559566{
560567 yulAssert (_literal.kind == LiteralKind::String, " " );
561568 yulAssert (m_dialect.validTypeForLiteral (LiteralKind::String, _literal.value , _literal.type ), " " );
569+ yulAssert (_literal.value .unlimited () == _expectUnlimitedLiteralArgument);
562570
563571 return {_literal.type };
564572}
0 commit comments