@@ -347,59 +347,59 @@ OptionalParseResult Parser::parseOptionalDecimalInteger(APInt &result) {
347347 return success ();
348348}
349349
350- FailureOr <APFloat>
351- Parser::parseFloatFromLiteral ( const Token &tok, bool isNegative,
352- const llvm::fltSemantics &semantics) {
350+ ParseResult Parser::parseFloatFromLiteral (std::optional <APFloat> &result,
351+ const Token &tok, bool isNegative,
352+ const llvm::fltSemantics &semantics) {
353353 // Check for a floating point value.
354354 if (tok.is (Token::floatliteral)) {
355355 auto val = tok.getFloatingPointValue ();
356356 if (!val)
357357 return emitError (tok.getLoc ()) << " floating point value too large" ;
358358
359- APFloat result (isNegative ? -*val : *val);
359+ result. emplace (isNegative ? -*val : *val);
360360 bool unused;
361- result. convert (semantics, APFloat::rmNearestTiesToEven, &unused);
362- return result ;
361+ result-> convert (semantics, APFloat::rmNearestTiesToEven, &unused);
362+ return success () ;
363363 }
364364
365365 // Check for a hexadecimal float value.
366366 if (tok.is (Token::integer))
367- return parseFloatFromIntegerLiteral (tok, isNegative, semantics);
367+ return parseFloatFromIntegerLiteral (result, tok, isNegative, semantics);
368368
369369 return emitError (tok.getLoc ()) << " expected floating point literal" ;
370370}
371371
372372// / Parse a floating point value from an integer literal token.
373- FailureOr<APFloat>
374- Parser::parseFloatFromIntegerLiteral (const Token &tok, bool isNegative,
373+ ParseResult
374+ Parser::parseFloatFromIntegerLiteral (std::optional<APFloat> &result,
375+ const Token &tok, bool isNegative,
375376 const llvm::fltSemantics &semantics) {
376377 StringRef spelling = tok.getSpelling ();
377378 bool isHex = spelling.size () > 1 && spelling[1 ] == ' x' ;
378379 if (!isHex) {
379- auto error = emitError (tok.getLoc ());
380- error << " unexpected decimal integer literal for a "
381- " floating point value" ;
382- error.attachNote () << " add a trailing dot to make the literal a float" ;
383- return failure ();
380+ return emitError (tok.getLoc (), " unexpected decimal integer literal for a "
381+ " floating point value" )
382+ .attachNote ()
383+ << " add a trailing dot to make the literal a float" ;
384384 }
385385 if (isNegative) {
386- emitError (tok.getLoc ()) << " hexadecimal float literal should not have a "
387- " leading minus " ;
388- return failure ( );
386+ return emitError (tok.getLoc (),
387+ " hexadecimal float literal should not have a "
388+ " leading minus " );
389389 }
390390
391391 APInt intValue;
392392 tok.getSpelling ().getAsInteger (isHex ? 0 : 10 , intValue);
393393 auto typeSizeInBits = APFloat::semanticsSizeInBits (semantics);
394394 if (intValue.getActiveBits () > typeSizeInBits) {
395- return emitError (tok.getLoc ())
396- << " hexadecimal float constant out of range for type" ;
397- return failure ();
395+ return emitError (tok.getLoc (),
396+ " hexadecimal float constant out of range for type" );
398397 }
399398
400399 APInt truncatedValue (typeSizeInBits, intValue.getNumWords (),
401400 intValue.getRawData ());
402- return APFloat (semantics, truncatedValue);
401+ result.emplace (semantics, truncatedValue);
402+ return success ();
403403}
404404
405405ParseResult Parser::parseOptionalKeyword (StringRef *keyword) {
0 commit comments