@@ -347,59 +347,59 @@ OptionalParseResult Parser::parseOptionalDecimalInteger(APInt &result) {
347
347
return success ();
348
348
}
349
349
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) {
353
353
// Check for a floating point value.
354
354
if (tok.is (Token::floatliteral)) {
355
355
auto val = tok.getFloatingPointValue ();
356
356
if (!val)
357
357
return emitError (tok.getLoc ()) << " floating point value too large" ;
358
358
359
- APFloat result (isNegative ? -*val : *val);
359
+ result. emplace (isNegative ? -*val : *val);
360
360
bool unused;
361
- result. convert (semantics, APFloat::rmNearestTiesToEven, &unused);
362
- return result ;
361
+ result-> convert (semantics, APFloat::rmNearestTiesToEven, &unused);
362
+ return success () ;
363
363
}
364
364
365
365
// Check for a hexadecimal float value.
366
366
if (tok.is (Token::integer))
367
- return parseFloatFromIntegerLiteral (tok, isNegative, semantics);
367
+ return parseFloatFromIntegerLiteral (result, tok, isNegative, semantics);
368
368
369
369
return emitError (tok.getLoc ()) << " expected floating point literal" ;
370
370
}
371
371
372
372
// / 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,
375
376
const llvm::fltSemantics &semantics) {
376
377
StringRef spelling = tok.getSpelling ();
377
378
bool isHex = spelling.size () > 1 && spelling[1 ] == ' x' ;
378
379
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" ;
384
384
}
385
385
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 " );
389
389
}
390
390
391
391
APInt intValue;
392
392
tok.getSpelling ().getAsInteger (isHex ? 0 : 10 , intValue);
393
393
auto typeSizeInBits = APFloat::semanticsSizeInBits (semantics);
394
394
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" );
398
397
}
399
398
400
399
APInt truncatedValue (typeSizeInBits, intValue.getNumWords (),
401
400
intValue.getRawData ());
402
- return APFloat (semantics, truncatedValue);
401
+ result.emplace (semantics, truncatedValue);
402
+ return success ();
403
403
}
404
404
405
405
ParseResult Parser::parseOptionalKeyword (StringRef *keyword) {
0 commit comments