Switch the Objective-C 'SEL' type over to a predefined type in the

AST file format, lazily generating the actual declaration in
ASTContext as needed.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137434 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Douglas Gregor 2011-08-12 06:17:30 +00:00
Родитель 79d6726921
Коммит 7a27ea52b7
6 изменённых файлов: 49 добавлений и 44 удалений

Просмотреть файл

@ -185,10 +185,9 @@ class ASTContext : public llvm::RefCountedBase<ASTContext> {
/// \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;
@ -961,9 +960,16 @@ public:
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; }
@ -1431,7 +1437,7 @@ public:
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,

Просмотреть файл

@ -640,26 +640,24 @@ namespace clang {
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.
@ -678,15 +676,18 @@ namespace clang {
/// \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.
///

Просмотреть файл

@ -222,7 +222,7 @@ ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,
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),
@ -430,9 +430,6 @@ void ASTContext::InitBuiltinTypes() {
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);
@ -4632,8 +4629,16 @@ TypedefDecl *ASTContext::getObjCIdDecl() const {
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) {

Просмотреть файл

@ -84,19 +84,6 @@ void Sema::ActOnTranslationUnitScope(Scope *S) {
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 =
@ -157,6 +144,12 @@ void Sema::Initialize() {
// 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");

Просмотреть файл

@ -2987,11 +2987,6 @@ void ASTReader::InitializeContext(ASTContext &Ctx) {
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);
@ -4220,6 +4215,10 @@ Decl *ASTReader::GetDecl(DeclID ID) {
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();

Просмотреть файл

@ -2810,6 +2810,8 @@ 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.ObjCSelDecl)
DeclIDs[Context.ObjCSelDecl] = PREDEF_DECL_OBJC_SEL_ID;
if (Context.ObjCClassDecl)
DeclIDs[Context.ObjCClassDecl] = PREDEF_DECL_OBJC_CLASS_ID;
@ -3019,7 +3021,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
// 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);