[cfe-commits] r40677 - /cfe/trunk/AST/ASTContext.cpp

Steve Naroff snaroff at apple.com
Wed Aug 1 11:02:17 PDT 2007


Author: snaroff
Date: Wed Aug  1 13:02:17 2007
New Revision: 40677

URL: http://llvm.org/viewvc/llvm-project?rev=40677&view=rev
Log:

Add comments to getTypeOfExpr/getTypeOfType.
Also add instances of TypeOfExpr/TypeOfType to the Types vector (so we can keep track of them).


Modified:
    cfe/trunk/AST/ASTContext.cpp

Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=40677&r1=40676&r2=40677&view=diff

==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Wed Aug  1 13:02:17 2007
@@ -584,16 +584,28 @@
   return QualType(Decl->TypeForDecl, 0);
 }
 
+/// getTypeOfExpr - Unlike many "get<Type>" functions, we can't unique
+/// TypeOfExpr AST's (since expression's are never shared). For example,
+/// multiple declarations that refer to "typeof(x)" all contain different
+/// DeclRefExpr's. This doesn't effect the type checker, since it operates 
+/// on canonical type's (which are always unique).
 QualType ASTContext::getTypeOfExpr(Expr *tofExpr) {
   QualType Canonical = tofExpr->getType().getCanonicalType();
-  // Note: TypeOfExpr's aren't uniqued.
-  return QualType(new TypeOfExpr(tofExpr, Canonical), 0);
+  TypeOfExpr *toe = new TypeOfExpr(tofExpr, Canonical);
+  Types.push_back(toe);
+  return QualType(toe, 0);
 }
 
+/// getTypeOfType -  Unlike many "get<Type>" functions, we don't unique
+/// TypeOfType AST's. The only motivation to unique these nodes would be
+/// memory savings. Since typeof(t) is fairly uncommon, space shouldn't be
+/// an issue. This doesn't effect the type checker, since it operates 
+/// on canonical type's (which are always unique).
 QualType ASTContext::getTypeOfType(QualType tofType) {
   QualType Canonical = tofType.getCanonicalType();
-  // Note: TypeOfType's aren't uniqued.
-  return QualType(new TypeOfType(tofType, Canonical), 0);
+  TypeOfType *tot = new TypeOfType(tofType, Canonical);
+  Types.push_back(tot);
+  return QualType(tot, 0);
 }
 
 /// getTagDeclType - Return the unique reference to the type for the





More information about the cfe-commits mailing list