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;
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; }
return T == getObjCIdType();
}
bool isObjCClassType(QualType T) const {
- return T == ObjCClassTypedefType;
+ return T == getObjCClassType();
}
bool isObjCSelType(QualType T) const {
return T == ObjCSelTypedefType;
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.
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.
///
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),
BuiltinVaListType = QualType();
// "Builtin" typedefs set by Sema::ActOnTranslationUnitScope().
- ObjCClassTypedefType = QualType();
ObjCSelTypedefType = QualType();
// Builtin types for 'id', 'Class', and 'SEL'.
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) {
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));
}
}
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);
}
}
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));
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;
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
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);