Create a new TypeNameType class, which represents typedefs as types. This
allows us to handle stuff like:
typedef int G;
..
X = sizeof(G);
llvm-svn: 39189
diff --git a/clang/AST/ASTContext.cpp b/clang/AST/ASTContext.cpp
index 9406edb..cf42cdb 100644
--- a/clang/AST/ASTContext.cpp
+++ b/clang/AST/ASTContext.cpp
@@ -12,7 +12,7 @@
//===----------------------------------------------------------------------===//
#include "clang/AST/ASTContext.h"
-#include "clang/AST/Type.h"
+#include "clang/AST/Decl.h"
#include "clang/Lex/Preprocessor.h"
using namespace llvm;
using namespace clang;
@@ -119,3 +119,20 @@
}
+/// getTypeDeclType - Return the unique reference to the type for the
+/// specified typename decl.
+TypeRef ASTContext::getTypeDeclType(TypeDecl *Decl) {
+ // FIXME: This is obviously braindead!
+ // Unique TypeDecl, to guarantee there is only one TypeDeclType.
+ for (unsigned i = 0, e = Types.size(); i != e; ++i)
+ if (TypeNameType *Ty = dyn_cast<TypeNameType>(Types[i]))
+ if (Ty->getDecl() == Decl)
+ return Types[i];
+
+ // FIXME: does this lose qualifiers from the typedef??
+
+ Type *Canonical = Decl->getType().getTypePtr();
+ Types.push_back(new TypeNameType(Decl, Canonical));
+ return Types.back();
+}
+