]> granicus.if.org Git - clang/commitdiff
Added "isExact" field to FloatingLiteral. This flag indicates whether or not
authorTed Kremenek <kremenek@apple.com>
Thu, 29 Nov 2007 00:56:49 +0000 (00:56 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 29 Nov 2007 00:56:49 +0000 (00:56 +0000)
the APFloat representing the parsed literal can represent the literal value
exactly.  This is useful when performing various semantic checks on the code,
and issuing appropriate warnings to users.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44423 91177308-0d34-0410-b5e6-96231b3b80d8

AST/StmtSerialization.cpp
Sema/SemaExpr.cpp
include/clang/AST/Expr.h

index 3134f8859c478a6abb7644bb0347756566750be9..120b68e5c5ca5edc1aae66e49d653fc5495a35e0 100644 (file)
@@ -507,14 +507,16 @@ DoStmt* DoStmt::CreateImpl(Deserializer& D) {
 void FloatingLiteral::EmitImpl(Serializer& S) const {
   S.Emit(Loc);
   S.Emit(getType());
+  S.EmitBool(isExact());
   S.Emit(Value);
 }
 
 FloatingLiteral* FloatingLiteral::CreateImpl(Deserializer& D) {
   SourceLocation Loc = SourceLocation::ReadVal(D);
   QualType t = QualType::ReadVal(D);
+  bool isExact = D.ReadBool();
   llvm::APFloat Val = llvm::APFloat::ReadVal(D);
-  FloatingLiteral* expr = new FloatingLiteral(Val,t,Loc);
+  FloatingLiteral* expr = new FloatingLiteral(Val,&isExact,t,Loc);
   return expr;
 }
 
index 14302aab08275593d741e43f6d33c73b6bc0a638..336dca716e47818a90b398f57b4af52322881dbf 100644 (file)
@@ -188,8 +188,12 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
       Context.Target.getDoubleInfo(Size, Align, Format, Tok.getLocation());
     }
     
-    Res = new FloatingLiteral(Literal.GetFloatValue(*Format), Ty,
-                              Tok.getLocation());
+    // isExact will be set by GetFloatValue().
+    bool isExact = false;
+    
+    Res = new FloatingLiteral(Literal.GetFloatValue(*Format,&isExact), &isExact, 
+                              Ty, Tok.getLocation());
+    
   } else if (!Literal.isIntegerLiteral()) {
     return ExprResult(true);
   } else {
index 7ee3afc6b787aad30a85dbd8cdcead5c5929c9ff..91cee5ef00c5417255b331f1bbcc2cff4f18be67 100644 (file)
@@ -240,12 +240,16 @@ public:
 
 class FloatingLiteral : public Expr {
   llvm::APFloat Value;
+  bool IsExact : 1;
   SourceLocation Loc;
 public:
-  FloatingLiteral(const llvm::APFloat &V, QualType Type, SourceLocation L)
-    : Expr(FloatingLiteralClass, Type), Value(V), Loc(L) {} 
+  FloatingLiteral(const llvm::APFloat &V, bool* isexact, 
+                  QualType Type, SourceLocation L)
+    : Expr(FloatingLiteralClass, Type), Value(V), IsExact(*isexact), Loc(L) {} 
 
   const llvm::APFloat &getValue() const { return Value; }
+  
+  bool isExact() const { return IsExact; }
 
   /// getValueAsDouble - This returns the value as an inaccurate double.  Note
   /// that this may cause loss of precision, but is useful for debugging dumps