[cfe-commits] r45174 - in /cfe/trunk: AST/ASTContext.cpp AST/Type.cpp Driver/RewriteTest.cpp Sema/SemaType.cpp include/clang/AST/ASTContext.h include/clang/AST/Type.h test/Sema/id-test-3.m
Fariborz Jahanian
fjahanian at apple.com
Tue Dec 18 13:33:44 PST 2007
Author: fjahanian
Date: Tue Dec 18 15:33:44 2007
New Revision: 45174
URL: http://llvm.org/viewvc/llvm-project?rev=45174&view=rev
Log:
Refactoring work. ObjcQualifiedIdType is now derived from 'Type'.
Modified:
cfe/trunk/AST/ASTContext.cpp
cfe/trunk/AST/Type.cpp
cfe/trunk/Driver/RewriteTest.cpp
cfe/trunk/Sema/SemaType.cpp
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/test/Sema/id-test-3.m
Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=45174&r1=45173&r2=45174&view=diff
==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Tue Dec 18 15:33:44 2007
@@ -258,6 +258,8 @@
}
break;
}
+ case Type::ObjcQualifiedId: Target.getPointerInfo(Size, Align, getFullLoc(L));
+ break;
case Type::Pointer: Target.getPointerInfo(Size, Align, getFullLoc(L)); break;
case Type::Reference:
// "When applied to a reference or a reference type, the result is the size
@@ -721,7 +723,7 @@
/// getObjcQualifiedIdType - Return a
/// getObjcQualifiedIdType type for the 'id' decl and
/// the conforming protocol list.
-QualType ASTContext::getObjcQualifiedIdType(TypedefDecl *Decl,
+QualType ASTContext::getObjcQualifiedIdType(QualType idType,
ObjcProtocolDecl **Protocols,
unsigned NumProtocols) {
llvm::FoldingSetNodeID ID;
@@ -733,9 +735,17 @@
return QualType(QT, 0);
// No Match;
- QualType Canonical = Decl->getUnderlyingType().getCanonicalType();
- ObjcQualifiedIdType *QType =
- new ObjcQualifiedIdType(Decl, Canonical, Protocols, NumProtocols);
+ QualType Canonical;
+ if (!idType->isCanonical()) {
+ Canonical = getObjcQualifiedIdType(idType.getCanonicalType(),
+ Protocols, NumProtocols);
+ ObjcQualifiedIdType *NewQT =
+ ObjcQualifiedIdTypes.FindNodeOrInsertPos(ID, InsertPos);
+ assert(NewQT == 0 && "Shouldn't be in the map!");
+ }
+
+ ObjcQualifiedIdType *QType =
+ new ObjcQualifiedIdType(Canonical, Protocols, NumProtocols);
Types.push_back(QType);
ObjcQualifiedIdTypes.InsertNode(QType, InsertPos);
return QualType(QType, 0);
@@ -1072,9 +1082,9 @@
S += encoding;
}
- else if (const ObjcQualifiedIdType *QIT = dyn_cast<ObjcQualifiedIdType>(T)) {
+ else if (T->isObjcQualifiedIdType()) {
// Treat id<P...> same as 'id' for encoding purposes.
- return getObjcEncodingForType(QIT->getDecl()->getUnderlyingType(), S);
+ return getObjcEncodingForType(getObjcIdType(), S);
}
else if (const PointerType *PT = T->getAsPointerType()) {
Modified: cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Type.cpp?rev=45174&r1=45173&r2=45174&view=diff
==============================================================================
--- cfe/trunk/AST/Type.cpp (original)
+++ cfe/trunk/AST/Type.cpp Tue Dec 18 15:33:44 2007
@@ -433,7 +433,8 @@
return false;
}
return isa<PointerType>(CanonicalType) || isa<ComplexType>(CanonicalType) ||
- isa<VectorType>(CanonicalType);
+ isa<VectorType>(CanonicalType) ||
+ isa<ObjcQualifiedIdType>(CanonicalType);
}
bool Type::isAggregateType() const {
Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=45174&r1=45173&r2=45174&view=diff
==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Tue Dec 18 15:33:44 2007
@@ -490,7 +490,7 @@
void RewriteTest::RewriteObjcMethodDecl(ObjcMethodDecl *OMD,
std::string &ResultStr) {
ResultStr += "\nstatic ";
- if (isa<ObjcQualifiedIdType>(OMD->getResultType()))
+ if (OMD->getResultType()->isObjcQualifiedIdType())
ResultStr += "id";
else
ResultStr += OMD->getResultType().getAsString();
@@ -551,7 +551,7 @@
for (int i = 0; i < OMD->getNumParams(); i++) {
ParmVarDecl *PDecl = OMD->getParamDecl(i);
ResultStr += ", ";
- if (isa<ObjcQualifiedIdType>(PDecl->getType()))
+ if (PDecl->getType()->isObjcQualifiedIdType())
ResultStr += "id";
else
ResultStr += PDecl->getType().getAsString();
@@ -999,7 +999,7 @@
if (T == Context->getObjcIdType())
return true;
- if (isa<ObjcQualifiedIdType>(T))
+ if (T->isObjcQualifiedIdType())
return true;
if (const PointerType *pType = T->getAsPointerType()) {
@@ -1321,7 +1321,7 @@
if (ParmVarDecl *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) {
if (!strcmp(PVD->getName(), "self")) {
// is this id<P1..> type?
- if (isa<ObjcQualifiedIdType>(CE->getType()))
+ if (CE->getType()->isObjcQualifiedIdType())
return 0;
if (const PointerType *PT = CE->getType()->getAsPointerType()) {
if (ObjcInterfaceType *IT =
@@ -1516,9 +1516,18 @@
// Make all implicit casts explicit...ICE comes in handy:-)
if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(userExpr)) {
// Reuse the ICE type, it is exactly what the doctor ordered.
- userExpr = new CastExpr(isa<ObjcQualifiedIdType>(ICE->getType())
+ userExpr = new CastExpr(ICE->getType()->isObjcQualifiedIdType()
? Context->getObjcIdType()
: ICE->getType(), userExpr, SourceLocation());
+ }
+ // Make id<P...> cast into an 'id' cast.
+ else if (CastExpr *CE = dyn_cast<CastExpr>(userExpr)) {
+ if (CE->getType()->isObjcQualifiedIdType()) {
+ while ((CE = dyn_cast<CastExpr>(userExpr)))
+ userExpr = CE->getSubExpr();
+ userExpr = new CastExpr(Context->getObjcIdType(),
+ userExpr, SourceLocation());
+ }
}
MsgExprs.push_back(userExpr);
// We've transferred the ownership to MsgExprs. Null out the argument in
@@ -1539,12 +1548,12 @@
if (ObjcMethodDecl *mDecl = Exp->getMethodDecl()) {
// Push any user argument types.
for (int i = 0; i < mDecl->getNumParams(); i++) {
- QualType t = isa<ObjcQualifiedIdType>(mDecl->getParamDecl(i)->getType())
+ QualType t = mDecl->getParamDecl(i)->getType()->isObjcQualifiedIdType()
? Context->getObjcIdType()
: mDecl->getParamDecl(i)->getType();
ArgTypes.push_back(t);
}
- returnType = isa<ObjcQualifiedIdType>(mDecl->getResultType())
+ returnType = mDecl->getResultType()->isObjcQualifiedIdType()
? Context->getObjcIdType() : mDecl->getResultType();
} else {
returnType = Context->getObjcIdType();
Modified: cfe/trunk/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaType.cpp?rev=45174&r1=45173&r2=45174&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/trunk/Sema/SemaType.cpp Tue Dec 18 15:33:44 2007
@@ -118,7 +118,7 @@
&& DS.getProtocolQualifiers()) {
// id<protocol-list>
Action::DeclTy **PPDecl = &(*DS.getProtocolQualifiers())[0];
- return Ctx.getObjcQualifiedIdType(typeDecl,
+ return Ctx.getObjcQualifiedIdType(typeDecl->getUnderlyingType(),
reinterpret_cast<ObjcProtocolDecl**>(PPDecl),
DS.NumProtocolQualifiers());
}
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=45174&r1=45173&r2=45174&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue Dec 18 15:33:44 2007
@@ -172,7 +172,7 @@
/// getObjcQualifiedIdType - Return an ObjcQualifiedIdType for a
/// given 'id' and conforming protocol list.
- QualType getObjcQualifiedIdType(TypedefDecl *Decl,
+ QualType getObjcQualifiedIdType(QualType idType,
ObjcProtocolDecl **ProtocolList,
unsigned NumProtocols);
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=45174&r1=45173&r2=45174&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Dec 18 15:33:44 2007
@@ -295,6 +295,7 @@
bool isVectorType() const; // GCC vector type.
bool isOCUVectorType() const; // OCU vector type.
bool isObjcInterfaceType() const; // includes conforming protocol type
+ bool isObjcQualifiedIdType() const; // id includes conforming protocol type
// Type Checking Functions: Check to see if this type is structurally the
// specified type, ignoring typedefs, and return a pointer to the best type
@@ -956,15 +957,14 @@
};
/// ObjcQualifiedIdType - to represent id<protocol-list>
-class ObjcQualifiedIdType : public TypedefType,
+class ObjcQualifiedIdType : public Type,
public llvm::FoldingSetNode {
// List of protocols for this protocol conforming 'id' type
// List is sorted on protocol name. No protocol is enterred more than once.
llvm::SmallVector<ObjcProtocolDecl*, 8> Protocols;
- ObjcQualifiedIdType(TypedefDecl *TD, QualType can,
- ObjcProtocolDecl **Protos, unsigned NumP) :
- TypedefType(ObjcQualifiedId, TD, can),
+ ObjcQualifiedIdType(QualType can, ObjcProtocolDecl **Protos, unsigned NumP)
+ : Type(ObjcQualifiedId, can),
Protocols(Protos, Protos+NumP) { }
friend class ASTContext; // ASTContext creates these.
public:
@@ -1051,6 +1051,9 @@
return isa<ObjcInterfaceType>(CanonicalType)
|| isa<ObjcQualifiedInterfaceType>(CanonicalType);
}
+inline bool Type::isObjcQualifiedIdType() const {
+ return isa<ObjcQualifiedIdType>(CanonicalType);
+}
} // end namespace clang
#endif
Modified: cfe/trunk/test/Sema/id-test-3.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/id-test-3.m?rev=45174&r1=45173&r2=45174&view=diff
==============================================================================
--- cfe/trunk/test/Sema/id-test-3.m (original)
+++ cfe/trunk/test/Sema/id-test-3.m Tue Dec 18 15:33:44 2007
@@ -1,4 +1,4 @@
-// RUN: clang -rewrite-test %s
+// RUN: clang -rewrite-test %s | clang
@protocol P
- (id<P>) Meth: (id<P>) Arg;
@@ -9,6 +9,6 @@
@end
@implementation INTF
-- (id<P>)IMeth { return [(id<P>)self Meth: 0]; }
+- (id<P>)IMeth { return [(id<P>)self Meth: (id<P>)0]; }
- (id<P>) Meth : (id<P>) Arg {}
@end
More information about the cfe-commits
mailing list