aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/AST/ASTContext.cpp17
-rw-r--r--lib/Sema/Sema.cpp22
-rw-r--r--lib/Serialization/ASTReader.cpp9
-rw-r--r--lib/Serialization/ASTWriter.cpp5
4 files changed, 30 insertions, 23 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index c4955721e9..cf4535bd90 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -222,7 +222,7 @@ ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,
DependentTemplateSpecializationTypes(this_()),
SubstTemplateTemplateParmPacks(this_()),
GlobalNestedNameSpecifier(0), IsInt128Installed(false),
- CFConstantStringTypeDecl(0),
+ ObjCIdDecl(0), CFConstantStringTypeDecl(0),
FILEDecl(0),
jmp_bufDecl(0), sigjmp_bufDecl(0), BlockDescriptorType(0),
BlockDescriptorExtendedType(0), cudaConfigureCallDecl(0),
@@ -430,7 +430,6 @@ void ASTContext::InitBuiltinTypes() {
BuiltinVaListType = QualType();
// "Builtin" typedefs set by Sema::ActOnTranslationUnitScope().
- ObjCIdTypedefType = QualType();
ObjCClassTypedefType = QualType();
ObjCSelTypedefType = QualType();
@@ -4619,8 +4618,18 @@ void ASTContext::setBuiltinVaListType(QualType T) {
BuiltinVaListType = T;
}
-void ASTContext::setObjCIdType(QualType T) {
- ObjCIdTypedefType = T;
+TypedefDecl *ASTContext::getObjCIdDecl() const {
+ if (!ObjCIdDecl) {
+ QualType T = getObjCObjectType(ObjCBuiltinIdTy, 0, 0);
+ T = getObjCObjectPointerType(T);
+ TypeSourceInfo *IdInfo = getTrivialTypeSourceInfo(T);
+ ObjCIdDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this),
+ getTranslationUnitDecl(),
+ SourceLocation(), SourceLocation(),
+ &Idents.get("id"), IdInfo);
+ }
+
+ return ObjCIdDecl;
}
void ASTContext::setObjCSelType(QualType T) {
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index 7451fa4391..adc749dd70 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -106,18 +106,7 @@ void Sema::ActOnTranslationUnitScope(Scope *S) {
Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl));
PushOnScopeChains(ProtocolDecl, TUScope, false);
}
- // Create the built-in typedef for 'id'.
- if (Context.getObjCIdType().isNull()) {
- QualType T = Context.getObjCObjectType(Context.ObjCBuiltinIdTy, 0, 0);
- T = Context.getObjCObjectPointerType(T);
- TypeSourceInfo *IdInfo = Context.getTrivialTypeSourceInfo(T);
- TypedefDecl *IdTypedef
- = TypedefDecl::Create(Context, CurContext,
- SourceLocation(), SourceLocation(),
- &Context.Idents.get("id"), IdInfo);
- PushOnScopeChains(IdTypedef, TUScope);
- Context.setObjCIdType(Context.getTypeDeclType(IdTypedef));
- }
+
// Create the built-in typedef for 'Class'.
if (Context.getObjCClassType().isNull()) {
QualType T = Context.getObjCObjectType(Context.ObjCBuiltinClassTy, 0, 0);
@@ -178,6 +167,15 @@ void Sema::Initialize() {
if (ExternalSemaSource *ExternalSema
= dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource()))
ExternalSema->InitializeSema(*this);
+
+ // Initialize predefined Objective-C types:
+ if (PP.getLangOptions().ObjC1) {
+ // If 'id' does not yet refer to any declarations, make it refer to the
+ // predefined 'id'.
+ DeclarationName Id = &Context.Idents.get("id");
+ if (IdentifierResolver::begin(Id) == IdentifierResolver::end())
+ PushOnScopeChains(Context.getObjCIdDecl(), TUScope);
+ }
}
Sema::~Sema() {
diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp
index 43435b6754..2e9e1bee68 100644
--- a/lib/Serialization/ASTReader.cpp
+++ b/lib/Serialization/ASTReader.cpp
@@ -2987,11 +2987,6 @@ void ASTReader::InitializeContext(ASTContext &Ctx) {
GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST]));
}
- if (unsigned Id = SpecialTypes[SPECIAL_TYPE_OBJC_ID]) {
- if (Context->ObjCIdTypedefType.isNull())
- Context->ObjCIdTypedefType = GetType(Id);
- }
-
if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) {
if (Context->ObjCSelTypedefType.isNull())
Context->ObjCSelTypedefType = GetType(Sel);
@@ -4225,6 +4220,10 @@ Decl *ASTReader::GetDecl(DeclID ID) {
case PREDEF_DECL_TRANSLATION_UNIT_ID:
assert(Context && "No context available?");
return Context->getTranslationUnitDecl();
+
+ case PREDEF_DECL_OBJC_ID_ID:
+ assert(Context && "No context available?");
+ return Context->getObjCIdDecl();
}
return 0;
diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp
index 2654ae3fdf..2377369c74 100644
--- a/lib/Serialization/ASTWriter.cpp
+++ b/lib/Serialization/ASTWriter.cpp
@@ -2808,7 +2808,9 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
// Set up predefined declaration IDs.
DeclIDs[Context.getTranslationUnitDecl()] = PREDEF_DECL_TRANSLATION_UNIT_ID;
-
+ if (Context.ObjCIdDecl)
+ DeclIDs[Context.ObjCIdDecl] = PREDEF_DECL_OBJC_ID_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
@@ -3015,7 +3017,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
// Form the record of special types.
RecordData SpecialTypes;
AddTypeRef(Context.getBuiltinVaListType(), SpecialTypes);
- AddTypeRef(Context.ObjCIdTypedefType, SpecialTypes);
AddTypeRef(Context.ObjCSelTypedefType, SpecialTypes);
AddTypeRef(Context.ObjCProtoType, SpecialTypes);
AddTypeRef(Context.ObjCClassTypedefType, SpecialTypes);