aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/AST/ASTContext.h17
-rw-r--r--include/clang/Serialization/ASTBitCodes.h25
-rw-r--r--lib/AST/ASTContext.cpp18
-rw-r--r--lib/Sema/Sema.cpp18
-rw-r--r--lib/Serialization/ASTReader.cpp9
-rw-r--r--lib/Serialization/ASTWriter.cpp5
6 files changed, 50 insertions, 42 deletions
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index 6feda32c54..4d5ba677a6 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -192,9 +192,9 @@ class ASTContext : public llvm::RefCountedBase<ASTContext> {
QualType ObjCProtoType;
const RecordType *ProtoStructType;
- /// ObjCClassType - another pseudo built-in typedef type (set by Sema).
- QualType ObjCClassTypedefType;
-
+ /// \brief The typedef for the predefined 'Class' type.
+ mutable TypedefDecl *ObjCClassDecl;
+
// Typedefs which may be provided defining the structure of Objective-C
// pseudo-builtins
QualType ObjCIdRedefinitionType;
@@ -968,11 +968,16 @@ public:
void setObjCProtoType(QualType QT);
QualType getObjCProtoType() const { return ObjCProtoType; }
+ /// \brief Retrieve the typedef declaration corresponding to the predefined
+ /// Objective-C 'Class' type.
+ TypedefDecl *getObjCClassDecl() const;
+
/// This setter/getter repreents the ObjC 'Class' type. It is setup lazily, by
/// Sema. 'Class' is always a (typedef for a) pointer type, a pointer to a
/// struct.
- QualType getObjCClassType() const { return ObjCClassTypedefType; }
- void setObjCClassType(QualType T);
+ QualType getObjCClassType() const {
+ return getTypeDeclType(getObjCClassDecl());
+ }
void setBuiltinVaListType(QualType T);
QualType getBuiltinVaListType() const { return BuiltinVaListType; }
@@ -1423,7 +1428,7 @@ public:
return T == getObjCIdType();
}
bool isObjCClassType(QualType T) const {
- return T == ObjCClassTypedefType;
+ return T == getObjCClassType();
}
bool isObjCSelType(QualType T) const {
return T == ObjCSelTypedefType;
diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h
index f9896e6ab8..c4a7f86622 100644
--- a/include/clang/Serialization/ASTBitCodes.h
+++ b/include/clang/Serialization/ASTBitCodes.h
@@ -644,24 +644,22 @@ namespace clang {
SPECIAL_TYPE_OBJC_SELECTOR = 1,
/// \brief Objective-C Protocol type
SPECIAL_TYPE_OBJC_PROTOCOL = 2,
- /// \brief Objective-C Class type
- SPECIAL_TYPE_OBJC_CLASS = 3,
/// \brief CFConstantString type
- SPECIAL_TYPE_CF_CONSTANT_STRING = 4,
+ SPECIAL_TYPE_CF_CONSTANT_STRING = 3,
/// \brief C FILE typedef type
- SPECIAL_TYPE_FILE = 5,
+ SPECIAL_TYPE_FILE = 4,
/// \brief C jmp_buf typedef type
- SPECIAL_TYPE_jmp_buf = 6,
+ SPECIAL_TYPE_jmp_buf = 5,
/// \brief C sigjmp_buf typedef type
- SPECIAL_TYPE_sigjmp_buf = 7,
+ SPECIAL_TYPE_sigjmp_buf = 6,
/// \brief Objective-C "id" redefinition type
- SPECIAL_TYPE_OBJC_ID_REDEFINITION = 8,
+ SPECIAL_TYPE_OBJC_ID_REDEFINITION = 7,
/// \brief Objective-C "Class" redefinition type
- SPECIAL_TYPE_OBJC_CLASS_REDEFINITION = 9,
+ SPECIAL_TYPE_OBJC_CLASS_REDEFINITION = 8,
/// \brief Objective-C "SEL" redefinition type
- SPECIAL_TYPE_OBJC_SEL_REDEFINITION = 10,
+ SPECIAL_TYPE_OBJC_SEL_REDEFINITION = 9,
/// \brief Whether __[u]int128_t identifier is installed.
- SPECIAL_TYPE_INT128_INSTALLED = 11
+ SPECIAL_TYPE_INT128_INSTALLED = 10
};
/// \brief Predefined declaration IDs.
@@ -678,14 +676,17 @@ namespace clang {
PREDEF_DECL_TRANSLATION_UNIT_ID = 1,
/// \brief The Objective-C 'id' type.
- PREDEF_DECL_OBJC_ID_ID = 2
+ PREDEF_DECL_OBJC_ID_ID = 2,
+
+ /// \brief The Objective-C 'Class' type.
+ PREDEF_DECL_OBJC_CLASS_ID = 3
};
/// \brief The number of declaration IDs that are predefined.
///
/// For more information about predefined declarations, see the
/// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants.
- const unsigned int NUM_PREDEF_DECL_IDS = 3;
+ const unsigned int NUM_PREDEF_DECL_IDS = 4;
/// \brief Record codes for each kind of declaration.
///
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index cf4535bd90..5951fcfe0e 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -222,7 +222,8 @@ ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,
DependentTemplateSpecializationTypes(this_()),
SubstTemplateTemplateParmPacks(this_()),
GlobalNestedNameSpecifier(0), IsInt128Installed(false),
- ObjCIdDecl(0), CFConstantStringTypeDecl(0),
+ ObjCIdDecl(0), ObjCClassDecl(0),
+ CFConstantStringTypeDecl(0),
FILEDecl(0),
jmp_bufDecl(0), sigjmp_bufDecl(0), BlockDescriptorType(0),
BlockDescriptorExtendedType(0), cudaConfigureCallDecl(0),
@@ -430,7 +431,6 @@ void ASTContext::InitBuiltinTypes() {
BuiltinVaListType = QualType();
// "Builtin" typedefs set by Sema::ActOnTranslationUnitScope().
- ObjCClassTypedefType = QualType();
ObjCSelTypedefType = QualType();
// Builtin types for 'id', 'Class', and 'SEL'.
@@ -4640,8 +4640,18 @@ void ASTContext::setObjCProtoType(QualType QT) {
ObjCProtoType = QT;
}
-void ASTContext::setObjCClassType(QualType T) {
- ObjCClassTypedefType = T;
+TypedefDecl *ASTContext::getObjCClassDecl() const {
+ if (!ObjCClassDecl) {
+ QualType T = getObjCObjectType(ObjCBuiltinClassTy, 0, 0);
+ T = getObjCObjectPointerType(T);
+ TypeSourceInfo *ClassInfo = getTrivialTypeSourceInfo(T);
+ ObjCClassDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this),
+ getTranslationUnitDecl(),
+ SourceLocation(), SourceLocation(),
+ &Idents.get("Class"), ClassInfo);
+ }
+
+ return ObjCClassDecl;
}
void ASTContext::setObjCConstantStringInterface(ObjCInterfaceDecl *Decl) {
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index adc749dd70..2377d186ef 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -105,19 +105,6 @@ void Sema::ActOnTranslationUnitScope(Scope *S) {
SourceLocation(), true);
Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl));
PushOnScopeChains(ProtocolDecl, TUScope, false);
- }
-
- // Create the built-in typedef for 'Class'.
- if (Context.getObjCClassType().isNull()) {
- QualType T = Context.getObjCObjectType(Context.ObjCBuiltinClassTy, 0, 0);
- T = Context.getObjCObjectPointerType(T);
- TypeSourceInfo *ClassInfo = Context.getTrivialTypeSourceInfo(T);
- TypedefDecl *ClassTypedef
- = TypedefDecl::Create(Context, CurContext,
- SourceLocation(), SourceLocation(),
- &Context.Idents.get("Class"), ClassInfo);
- PushOnScopeChains(ClassTypedef, TUScope);
- Context.setObjCClassType(Context.getTypeDeclType(ClassTypedef));
}
}
@@ -175,6 +162,11 @@ void Sema::Initialize() {
DeclarationName Id = &Context.Idents.get("id");
if (IdentifierResolver::begin(Id) == IdentifierResolver::end())
PushOnScopeChains(Context.getObjCIdDecl(), TUScope);
+
+ // Create the built-in typedef for 'Class'.
+ DeclarationName Class = &Context.Idents.get("Class");
+ if (IdentifierResolver::begin(Class) == IdentifierResolver::end())
+ PushOnScopeChains(Context.getObjCClassDecl(), TUScope);
}
}
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index 2e9e1bee68..2d4cde05a9 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -2997,11 +2997,6 @@ void ASTReader::InitializeContext(ASTContext &Ctx) {
Context->ObjCProtoType = GetType(Proto);
}
- if (unsigned Class = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS]) {
- if (Context->ObjCClassTypedefType.isNull())
- Context->ObjCClassTypedefType = GetType(Class);
- }
-
if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) {
if (!Context->CFConstantStringTypeDecl)
Context->setCFConstantStringType(GetType(String));
@@ -4224,6 +4219,10 @@ Decl *ASTReader::GetDecl(DeclID ID) {
case PREDEF_DECL_OBJC_ID_ID:
assert(Context && "No context available?");
return Context->getObjCIdDecl();
+
+ case PREDEF_DECL_OBJC_CLASS_ID:
+ assert(Context && "No context available?");
+ return Context->getObjCClassDecl();
}
return 0;
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index 2377369c74..b92b760863 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -2810,7 +2810,9 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
DeclIDs[Context.getTranslationUnitDecl()] = PREDEF_DECL_TRANSLATION_UNIT_ID;
if (Context.ObjCIdDecl)
DeclIDs[Context.ObjCIdDecl] = PREDEF_DECL_OBJC_ID_ID;
-
+ if (Context.ObjCClassDecl)
+ DeclIDs[Context.ObjCClassDecl] = PREDEF_DECL_OBJC_CLASS_ID;
+
if (!Chain) {
// Make sure that we emit IdentifierInfos (and any attached
// declarations) for builtins. We don't need to do this when we're
@@ -3019,7 +3021,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
AddTypeRef(Context.getBuiltinVaListType(), SpecialTypes);
AddTypeRef(Context.ObjCSelTypedefType, SpecialTypes);
AddTypeRef(Context.ObjCProtoType, SpecialTypes);
- AddTypeRef(Context.ObjCClassTypedefType, SpecialTypes);
AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes);
AddTypeRef(Context.getFILEType(), SpecialTypes);
AddTypeRef(Context.getjmp_bufType(), SpecialTypes);