/// \brief The typedef for the predefined 'id' type.
mutable TypedefDecl *ObjCIdDecl;
- /// ObjCSelType - another pseudo built-in typedef type (set by Sema).
- QualType ObjCSelTypedefType;
+ /// \brief The typedef for the predefined 'SEL' type.
+ mutable TypedefDecl *ObjCSelDecl;
- /// ObjCProtoType - another pseudo built-in typedef type (set by Sema).
QualType ObjCProtoType;
const RecordType *ProtoStructType;
QualType getObjCIdType() const {
return getTypeDeclType(getObjCIdDecl());
}
+
+ /// \brief Retrieve the typedef corresponding to the predefined 'SEL' type
+ /// in Objective-C.
+ TypedefDecl *getObjCSelDecl() const;
- void setObjCSelType(QualType T);
- QualType getObjCSelType() const { return ObjCSelTypedefType; }
+ /// \brief Retrieve the type that corresponds to the predefined Objective-C
+ /// 'SEL' type.
+ QualType getObjCSelType() const {
+ return getTypeDeclType(getObjCSelDecl());
+ }
void setObjCProtoType(QualType QT);
QualType getObjCProtoType() const { return ObjCProtoType; }
return T == getObjCClassType();
}
bool isObjCSelType(QualType T) const {
- return T == ObjCSelTypedefType;
+ return T == getObjCSelType();
}
bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS);
bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
enum SpecialTypeIDs {
/// \brief __builtin_va_list
SPECIAL_TYPE_BUILTIN_VA_LIST = 0,
- /// \brief Objective-C selector type
- SPECIAL_TYPE_OBJC_SELECTOR = 1,
/// \brief Objective-C Protocol type
- SPECIAL_TYPE_OBJC_PROTOCOL = 2,
+ SPECIAL_TYPE_OBJC_PROTOCOL = 1,
/// \brief CFConstantString type
- SPECIAL_TYPE_CF_CONSTANT_STRING = 3,
+ SPECIAL_TYPE_CF_CONSTANT_STRING = 2,
/// \brief C FILE typedef type
- SPECIAL_TYPE_FILE = 4,
+ SPECIAL_TYPE_FILE = 3,
/// \brief C jmp_buf typedef type
- SPECIAL_TYPE_jmp_buf = 5,
+ SPECIAL_TYPE_jmp_buf = 4,
/// \brief C sigjmp_buf typedef type
- SPECIAL_TYPE_sigjmp_buf = 6,
+ SPECIAL_TYPE_sigjmp_buf = 5,
/// \brief Objective-C "id" redefinition type
- SPECIAL_TYPE_OBJC_ID_REDEFINITION = 7,
+ SPECIAL_TYPE_OBJC_ID_REDEFINITION = 6,
/// \brief Objective-C "Class" redefinition type
- SPECIAL_TYPE_OBJC_CLASS_REDEFINITION = 8,
+ SPECIAL_TYPE_OBJC_CLASS_REDEFINITION = 7,
/// \brief Objective-C "SEL" redefinition type
- SPECIAL_TYPE_OBJC_SEL_REDEFINITION = 9,
+ SPECIAL_TYPE_OBJC_SEL_REDEFINITION = 8,
/// \brief Whether __[u]int128_t identifier is installed.
- SPECIAL_TYPE_INT128_INSTALLED = 10
+ SPECIAL_TYPE_INT128_INSTALLED = 9
};
/// \brief Predefined declaration IDs.
/// \brief The Objective-C 'id' type.
PREDEF_DECL_OBJC_ID_ID = 2,
+ /// \brief The Objective-C 'SEL' type.
+ PREDEF_DECL_OBJC_SEL_ID = 3,
+
/// \brief The Objective-C 'Class' type.
- PREDEF_DECL_OBJC_CLASS_ID = 3
+ PREDEF_DECL_OBJC_CLASS_ID = 4
};
/// \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 = 4;
+ const unsigned int NUM_PREDEF_DECL_IDS = 5;
/// \brief Record codes for each kind of declaration.
///
DependentTemplateSpecializationTypes(this_()),
SubstTemplateTemplateParmPacks(this_()),
GlobalNestedNameSpecifier(0), IsInt128Installed(false),
- ObjCIdDecl(0), ObjCClassDecl(0),
+ ObjCIdDecl(0), ObjCSelDecl(0), ObjCClassDecl(0),
CFConstantStringTypeDecl(0),
FILEDecl(0),
jmp_bufDecl(0), sigjmp_bufDecl(0), BlockDescriptorType(0),
BuiltinVaListType = QualType();
- // "Builtin" typedefs set by Sema::ActOnTranslationUnitScope().
- ObjCSelTypedefType = QualType();
-
// Builtin types for 'id', 'Class', and 'SEL'.
InitBuiltinType(ObjCBuiltinIdTy, BuiltinType::ObjCId);
InitBuiltinType(ObjCBuiltinClassTy, BuiltinType::ObjCClass);
return ObjCIdDecl;
}
-void ASTContext::setObjCSelType(QualType T) {
- ObjCSelTypedefType = T;
+TypedefDecl *ASTContext::getObjCSelDecl() const {
+ if (!ObjCSelDecl) {
+ QualType SelT = getPointerType(ObjCBuiltinSelTy);
+ TypeSourceInfo *SelInfo = getTrivialTypeSourceInfo(SelT);
+ ObjCSelDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this),
+ getTranslationUnitDecl(),
+ SourceLocation(), SourceLocation(),
+ &Idents.get("SEL"), SelInfo);
+ }
+ return ObjCSelDecl;
}
void ASTContext::setObjCProtoType(QualType QT) {
if (!PP.getLangOptions().ObjC1) return;
- // Built-in ObjC types may already be set by ASTReader (hence isNull checks).
- if (Context.getObjCSelType().isNull()) {
- // Create the built-in typedef for 'SEL'.
- QualType SelT = Context.getPointerType(Context.ObjCBuiltinSelTy);
- TypeSourceInfo *SelInfo = Context.getTrivialTypeSourceInfo(SelT);
- TypedefDecl *SelTypedef
- = TypedefDecl::Create(Context, CurContext,
- SourceLocation(), SourceLocation(),
- &Context.Idents.get("SEL"), SelInfo);
- PushOnScopeChains(SelTypedef, TUScope);
- Context.setObjCSelType(Context.getTypeDeclType(SelTypedef));
- }
-
// Synthesize "@class Protocol;
if (Context.getObjCProtoType().isNull()) {
ObjCInterfaceDecl *ProtocolDecl =
// Initialize predefined Objective-C types:
if (PP.getLangOptions().ObjC1) {
+ // If 'SEL' does not yet refer to any declarations, make it refer to the
+ // predefined 'SEL'.
+ DeclarationName SEL = &Context.Idents.get("SEL");
+ if (IdentifierResolver::begin(SEL) == IdentifierResolver::end())
+ PushOnScopeChains(Context.getObjCSelDecl(), TUScope);
+
// If 'id' does not yet refer to any declarations, make it refer to the
// predefined 'id'.
DeclarationName Id = &Context.Idents.get("id");
GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST]));
}
- if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) {
- if (Context->ObjCSelTypedefType.isNull())
- Context->ObjCSelTypedefType = GetType(Sel);
- }
-
if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) {
if (Context->ObjCProtoType.isNull())
Context->ObjCProtoType = GetType(Proto);
assert(Context && "No context available?");
return Context->getObjCIdDecl();
+ case PREDEF_DECL_OBJC_SEL_ID:
+ assert(Context && "No context available?");
+ return Context->getObjCSelDecl();
+
case PREDEF_DECL_OBJC_CLASS_ID:
assert(Context && "No context available?");
return Context->getObjCClassDecl();
DeclIDs[Context.getTranslationUnitDecl()] = PREDEF_DECL_TRANSLATION_UNIT_ID;
if (Context.ObjCIdDecl)
DeclIDs[Context.ObjCIdDecl] = PREDEF_DECL_OBJC_ID_ID;
+ if (Context.ObjCSelDecl)
+ DeclIDs[Context.ObjCSelDecl] = PREDEF_DECL_OBJC_SEL_ID;
if (Context.ObjCClassDecl)
DeclIDs[Context.ObjCClassDecl] = PREDEF_DECL_OBJC_CLASS_ID;
// Form the record of special types.
RecordData SpecialTypes;
AddTypeRef(Context.getBuiltinVaListType(), SpecialTypes);
- AddTypeRef(Context.ObjCSelTypedefType, SpecialTypes);
AddTypeRef(Context.ObjCProtoType, SpecialTypes);
AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes);
AddTypeRef(Context.getFILEType(), SpecialTypes);