Bug #:
Submitted by:
Reviewed by:
-Converted the preprocessor to use NumericLiteralParser.
-Several minor changes to LiteralSupport interface/implementation.
-Added an error diagnostic for floating point usage in pp expr's.

llvm-svn: 39352
diff --git a/clang/Lex/PPExpressions.cpp b/clang/Lex/PPExpressions.cpp
index 34cd73f..ffc6535 100644
--- a/clang/Lex/PPExpressions.cpp
+++ b/clang/Lex/PPExpressions.cpp
@@ -13,7 +13,6 @@
 //===----------------------------------------------------------------------===//
 //
 // FIXME: implement testing for asserts.
-// FIXME: Parse integer constants correctly.  Reject 123.0, etc.
 // FIXME: Track signed/unsigned correctly.
 // FIXME: Track and report integer overflow correctly.
 //
@@ -21,9 +20,11 @@
 
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/MacroInfo.h"
+#include "clang/Lex/LiteralSupport.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TokenKinds.h"
 #include "clang/Basic/Diagnostic.h"
+#include "llvm/ADT/SmallString.h"
 using namespace llvm;
 using namespace clang;
 
@@ -144,10 +145,18 @@
     PP.Diag(PeekTok, diag::err_pp_expected_value_in_expr);
     return true;
   case tok::numeric_constant: {
-    // FIXME: faster.  FIXME: track signs.
-    std::string Spell = PP.getSpelling(PeekTok);
-    // FIXME: COMPUTE integer constants CORRECTLY.
-    Result = atoi(Spell.c_str());
+    // FIXME: track signs. ?? snaroff: talk to Chris...
+    SmallString<512> IntegerBuffer;
+    IntegerBuffer.resize(PeekTok.getLength());
+    const char *ThisTokBegin = &IntegerBuffer[0];
+    unsigned ActualLength = PP.getSpelling(PeekTok, ThisTokBegin);
+    NumericLiteralParser Literal(ThisTokBegin, ThisTokBegin+ActualLength, 
+                                 PeekTok.getLocation(), PP);
+    if (Literal.isIntegerLiteral()) {
+      Literal.GetIntegerValue(Result);
+    } else if (Literal.isFloatingLiteral()) {
+      PP.Diag(PeekTok, diag::err_pp_illegal_floating_literal);
+    }
     PP.LexNonComment(PeekTok);
     return false;
   }