[cfe-commits] r44423 - in /cfe/trunk: AST/StmtSerialization.cpp Sema/SemaExpr.cpp include/clang/AST/Expr.h

Ted Kremenek kremenek at apple.com
Wed Nov 28 16:56:49 PST 2007


Author: kremenek
Date: Wed Nov 28 18:56:49 2007
New Revision: 44423

URL: http://llvm.org/viewvc/llvm-project?rev=44423&view=rev
Log:
Added "isExact" field to FloatingLiteral.  This flag indicates whether or not
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.

Modified:
    cfe/trunk/AST/StmtSerialization.cpp
    cfe/trunk/Sema/SemaExpr.cpp
    cfe/trunk/include/clang/AST/Expr.h

Modified: cfe/trunk/AST/StmtSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtSerialization.cpp?rev=44423&r1=44422&r2=44423&view=diff

==============================================================================
--- cfe/trunk/AST/StmtSerialization.cpp (original)
+++ cfe/trunk/AST/StmtSerialization.cpp Wed Nov 28 18:56:49 2007
@@ -507,14 +507,16 @@
 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;
 }
 

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=44423&r1=44422&r2=44423&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Wed Nov 28 18:56:49 2007
@@ -188,8 +188,12 @@
       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 {

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=44423&r1=44422&r2=44423&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Nov 28 18:56:49 2007
@@ -240,12 +240,16 @@
 
 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





More information about the cfe-commits mailing list