[cfe-commits] r44670 - in /cfe/trunk: 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
Fariborz Jahanian
fjahanian at apple.com
Thu Dec 6 16:18:54 PST 2007
Author: fjahanian
Date: Thu Dec 6 18:18:54 2007
New Revision: 44670
URL: http://llvm.org/viewvc/llvm-project?rev=44670&view=rev
Log:
Patch to implement "Protocol" as a built-in type declared as
"@class Protocol;"
Modified:
cfe/trunk/AST/ASTContext.cpp
cfe/trunk/Parse/MinimalAction.cpp
cfe/trunk/Sema/Sema.cpp
cfe/trunk/Sema/Sema.h
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/test/Sema/protocol-expr-1.m
cfe/trunk/test/Sema/protocol-expr-neg-1.m
Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=44670&r1=44669&r2=44670&view=diff
==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Thu Dec 6 18:18:54 2007
@@ -1121,15 +1121,10 @@
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)
Modified: cfe/trunk/Parse/MinimalAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/MinimalAction.cpp?rev=44670&r1=44669&r2=44670&view=diff
==============================================================================
--- cfe/trunk/Parse/MinimalAction.cpp (original)
+++ cfe/trunk/Parse/MinimalAction.cpp Thu Dec 6 18:18:54 2007
@@ -43,6 +43,9 @@
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
Modified: cfe/trunk/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.cpp?rev=44670&r1=44669&r2=44670&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/trunk/Sema/Sema.cpp Thu Dec 6 18:18:54 2007
@@ -23,7 +23,7 @@
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 @@
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 @@
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 @@
&Context.Idents.get("SEL"),
SelT, 0);
Context.setObjcSelType(SelTypedef);
+
}
TUScope = 0;
}
Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=44670&r1=44669&r2=44670&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Thu Dec 6 18:18:54 2007
@@ -277,10 +277,8 @@
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
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=44670&r1=44669&r2=44670&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Thu Dec 6 18:18:54 2007
@@ -2061,9 +2061,10 @@
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);
}
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=44670&r1=44669&r2=44670&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Thu Dec 6 18:18:54 2007
@@ -212,7 +212,7 @@
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);
Modified: cfe/trunk/test/Sema/protocol-expr-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/protocol-expr-1.m?rev=44670&r1=44669&r2=44670&view=diff
==============================================================================
--- cfe/trunk/test/Sema/protocol-expr-1.m (original)
+++ cfe/trunk/test/Sema/protocol-expr-1.m Thu Dec 6 18:18:54 2007
@@ -1,7 +1,5 @@
// RUN: clang -fsyntax-only -verify %s
-typedef struct Protocol Protocol;
-
@protocol fproto;
@protocol p1
Modified: cfe/trunk/test/Sema/protocol-expr-neg-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/protocol-expr-neg-1.m?rev=44670&r1=44669&r2=44670&view=diff
==============================================================================
--- cfe/trunk/test/Sema/protocol-expr-neg-1.m (original)
+++ cfe/trunk/test/Sema/protocol-expr-neg-1.m Thu Dec 6 18:18:54 2007
@@ -1,6 +1,6 @@
// RUN: clang -fsyntax-only -verify %s
-typedef struct Protocol Protocol;
+ at class Protocol;
@protocol fproto;
More information about the cfe-commits
mailing list