]> granicus.if.org Git - clang/commitdiff
Patch to implement "Protocol" as a built-in type declared as
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 7 Dec 2007 00:18:54 +0000 (00:18 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 7 Dec 2007 00:18:54 +0000 (00:18 +0000)
"@class Protocol;"

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44670 91177308-0d34-0410-b5e6-96231b3b80d8

AST/ASTContext.cpp
Parse/MinimalAction.cpp
Sema/Sema.cpp
Sema/Sema.h
Sema/SemaExpr.cpp
include/clang/AST/ASTContext.h
test/Sema/protocol-expr-1.m
test/Sema/protocol-expr-neg-1.m

index 3f5a7fbc586b3973da3ac9c3d8dee0914a0ed07e..e8ed9a209fbaea1dfa4870fb5aea1996ca92f59f 100644 (file)
@@ -1121,15 +1121,10 @@ void ASTContext::setObjcSelType(TypedefDecl *TD)
   SelStructType = rec;
 }
 
-void ASTContext::setObjcProtoType(TypedefDecl *TD)
+void ASTContext::setObjcProtoType(QualType QT)
 {
   assert(ObjcProtoType.isNull() && "'Protocol' type already set!");
-  
-  // typedef struct Protocol Protocol;
-  ObjcProtoType = TD->getUnderlyingType();
-  // Protocol * type
-  ObjcProtoType = getPointerType(ObjcProtoType);  
-  ProtoStructType = TD->getUnderlyingType()->getAsStructureType();
+  ObjcProtoType = QT;
 }
 
 void ASTContext::setObjcClassType(TypedefDecl *TD)
index 92d997f59cf518f71da20c98afa0b5982ca70174..54261527d9835630376a8a35e6b8b9b1016ff668 100644 (file)
@@ -43,6 +43,9 @@ void MinimalAction:: ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
   II = &Idents.get("Class");
   TI = new TypeNameInfo(1, II->getFETokenInfo<TypeNameInfo>());
   II->setFETokenInfo(TI);
+  II = &Idents.get("Protocol");
+  TI = new TypeNameInfo(1, II->getFETokenInfo<TypeNameInfo>());
+  II->setFETokenInfo(TI);
 }
 
 /// isTypeName - This looks at the IdentifierInfo::FETokenInfo field to
index 7bafd7db883e4a82b051f44288a21d0b605a1606..7a657cd5e1533b4bd4ac8fb05d4215b38f182929 100644 (file)
@@ -23,7 +23,7 @@ using namespace clang;
 bool Sema::isBuiltinObjcType(TypedefDecl *TD) {
   const char *typeName = TD->getIdentifier()->getName();
   return strcmp(typeName, "id") == 0 || strcmp(typeName, "Class") == 0 ||
-         strcmp(typeName, "SEL") == 0;
+         strcmp(typeName, "SEL") == 0 || strcmp(typeName, "Protocol") == 0;
 }
 
 void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
@@ -38,31 +38,16 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
     t = dyn_cast<TypedefType>(Context.getObjcClassType().getTypePtr());
     t->getDecl()->getIdentifier()->setFETokenInfo(t->getDecl());
     TUScope->AddDecl(t->getDecl());
+    ObjcInterfaceType *it = dyn_cast<ObjcInterfaceType>(Context.getObjcProtoType());
+    ObjcInterfaceDecl *IDecl = it->getDecl();
+    IDecl->getIdentifier()->setFETokenInfo(IDecl);
+    TUScope->AddDecl(IDecl);
     t = dyn_cast<TypedefType>(Context.getObjcSelType().getTypePtr());
     t->getDecl()->getIdentifier()->setFETokenInfo(t->getDecl());
     TUScope->AddDecl(t->getDecl());
   }
 }
 
-/// FIXME: remove this.
-/// GetObjcProtoType - See comments for Sema::GetObjcIdType above; replace "id"
-/// with "Protocol".
-QualType Sema::GetObjcProtoType(SourceLocation Loc) {
-  assert(TUScope && "GetObjcProtoType(): Top-level scope is null");
-  if (Context.getObjcProtoType().isNull()) {
-    IdentifierInfo *ProtoIdent = &Context.Idents.get("Protocol");
-    ScopedDecl *ProtoDecl = LookupScopedDecl(ProtoIdent, Decl::IDNS_Ordinary, 
-                                           SourceLocation(), TUScope);
-    TypedefDecl *ObjcProtoTypedef = dyn_cast_or_null<TypedefDecl>(ProtoDecl);
-    if (!ObjcProtoTypedef) {
-      Diag(Loc, diag::err_missing_proto_definition);
-      return QualType();
-    }
-    Context.setObjcProtoType(ObjcProtoTypedef);
-  }
-  return Context.getObjcProtoType();
-}
-
 Sema::Sema(Preprocessor &pp, ASTContext &ctxt)
   : PP(pp), Context(ctxt), CurFunctionDecl(0), CurMethodDecl(0) {
   
@@ -91,6 +76,11 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt)
                                                 ClassT, 0);
     Context.setObjcClassType(ClassTypedef);
     
+    // Synthesize "@class Protocol;
+    ObjcInterfaceDecl *ProtocolDecl = new ObjcInterfaceDecl(SourceLocation(), 0, 
+                                        &Context.Idents.get("Protocol"), true);
+    Context.setObjcProtoType(Context.getObjcInterfaceType(ProtocolDecl));
+    
     // Synthesize "typedef struct objc_object { Class isa; } *id;"
     RecordDecl *ObjectTag = new RecordDecl(Decl::Struct, SourceLocation(), 
                                           &IT.get("objc_object"), 0);
@@ -111,6 +101,7 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt)
                                               &Context.Idents.get("SEL"),
                                               SelT, 0);
     Context.setObjcSelType(SelTypedef);
+    
   }
   TUScope = 0;
 }
index 00133f885ab83f19e24d60ff14fbc1e0259c43fa..234fc157d878fdc2f4e817676e21d96e61f53fb3 100644 (file)
@@ -277,10 +277,8 @@ private:
   bool MatchTwoMethodDeclarations(const ObjcMethodDecl *Method, 
                                   const ObjcMethodDecl *PrevMethod); 
 
-  /// GetObjcSelType - Getter for the build-in "Protocol *" type.
-  QualType GetObjcProtoType(SourceLocation Loc = SourceLocation());
-  
-  /// isBuiltinObjcType - Returns true of the type is "id", "SEL", "Class".
+  /// isBuiltinObjcType - Returns true of the type is "id", "SEL", "Class"
+  /// or "Protocol".
   bool isBuiltinObjcType(TypedefDecl *TD);
 
   /// AddInstanceMethodToGlobalPool - All instance methods in a translation
index 379a033d418830f8b37e9fb532eae8c5723c6cec..9d3e9eb970e8a5b9be43664abc0963bdf5a471b4 100644 (file)
@@ -2061,9 +2061,10 @@ Sema::ExprResult Sema::ParseObjCProtocolExpression(IdentifierInfo *ProtocolId,
     return true;
   }
   
-  QualType t = GetObjcProtoType(AtLoc);
+  QualType t = Context.getObjcProtoType();
   if (t.isNull())
     return true;
+  t = Context.getPointerType(t);
   return new ObjCProtocolExpr(t, PDecl, AtLoc, RParenLoc);
 }
 
index c4a7c85c6b32435af0cfa15f6b952db6f354f692..c8a80b02f618e4479f8e556d8d75869d10ae0efa 100644 (file)
@@ -212,7 +212,7 @@ public:
   void setObjcSelType(TypedefDecl *Decl);
   QualType getObjcSelType() const { return ObjcSelType; }
   
-  void setObjcProtoType(TypedefDecl *Decl);
+  void setObjcProtoType(QualType QT);
   QualType getObjcProtoType() const { return ObjcProtoType; }
   
   void setObjcClassType(TypedefDecl *Decl);
index 23cb5dd903dad6ecd5c686ed2259109717b02989..dff2866020d553121a04ffb450c2538953f1a7d1 100644 (file)
@@ -1,7 +1,5 @@
 // RUN: clang -fsyntax-only -verify %s
 
-typedef struct Protocol Protocol;
-
 @protocol fproto;
 
 @protocol p1 
index d59d83fd78c4511a2870bf121263193e71b35730..427e74417ab460641443ca1a21bbc26aab051b46 100644 (file)
@@ -1,6 +1,6 @@
 // RUN: clang -fsyntax-only -verify %s
 
-typedef struct Protocol Protocol;
+@class Protocol;
 
 @protocol fproto;