Submitted by:
Reviewed by:
Added primitive support for 32-bit floating point literals.

llvm-svn: 39719
This commit is contained in:
Steve Naroff 2007-07-09 23:53:58 +00:00
parent 2ada32ed7d
commit 97b9e91eb7
3 changed files with 14 additions and 2 deletions

View File

@ -410,6 +410,13 @@ bool NumericLiteralParser::GetIntegerValue(llvm::APInt &Val) {
return OverflowOccurred;
}
// GetFloatValue - Poor man's floatvalue (FIXME).
float NumericLiteralParser::GetFloatValue() {
char floatChars[256];
strncpy(floatChars, ThisTokBegin, ThisTokEnd-ThisTokBegin);
floatChars[ThisTokEnd-ThisTokBegin] = '\0';
return strtof(floatChars, 0);
}
void NumericLiteralParser::Diag(SourceLocation Loc, unsigned DiagID,
const std::string &M) {

View File

@ -208,8 +208,9 @@ Action::ExprResult Sema::ParseNumericConstant(const LexerToken &Tok) {
return new IntegerLiteral(ResultVal, t, Tok.getLocation());
} else if (Literal.isFloatingLiteral()) {
// FIXME: fill in the value and compute the real type...
return new FloatingLiteral(7.7, Context.FloatTy, Tok.getLocation());
// FIXME: handle float values > 32 (including compute the real type...).
return new FloatingLiteral(Literal.GetFloatValue(), Context.FloatTy,
Tok.getLocation());
}
return ExprResult(true);
}

View File

@ -71,6 +71,10 @@ public:
/// value read is larger than the APInt's bits will hold), set Val to the low
/// bits of the result and return true. Otherwise, return false.
bool GetIntegerValue(llvm::APInt &Val);
/// GetFloatValue - Convert this numeric literal to a float.
/// FIXME: the return value is fixed size - make more general.
float GetFloatValue();
private:
void Diag(SourceLocation Loc, unsigned DiagID,