unsigned numInsMembers,
ObjcMethodDecl **clsMethods,
unsigned numClsMembers,
- SourceLocation AtEndLoc) {
+ SourceLocation endLoc) {
NumInstanceMethods = numInsMembers;
if (numInsMembers) {
InstanceMethods = new ObjcMethodDecl*[numInsMembers];
ClassMethods = new ObjcMethodDecl*[numClsMembers];
memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*));
}
+ AtEndLoc = endLoc;
}
/// addMethods - Insert instance and methods declarations into
unsigned numInsMembers,
ObjcMethodDecl **clsMethods,
unsigned numClsMembers,
- SourceLocation AtEndLoc) {
+ SourceLocation endLoc) {
NumInstanceMethods = numInsMembers;
if (numInsMembers) {
InstanceMethods = new ObjcMethodDecl*[numInsMembers];
ClassMethods = new ObjcMethodDecl*[numClsMembers];
memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*));
}
+ AtEndLoc = endLoc;
}
/// addMethods - Insert instance and methods declarations into
void RewriteTabs();
void RewriteForwardClassDecl(ObjcClassDecl *Dcl);
void RewriteInterfaceDecl(ObjcInterfaceDecl *Dcl);
+ void RewriteCategoryDecl(ObjcCategoryDecl *Dcl);
+ void RewriteMethods(int nMethods, ObjcMethodDecl **Methods);
// Expression Rewriting.
Stmt *RewriteFunctionBody(Stmt *S);
SelGetUidFunctionDecl = FD;
} else if (ObjcInterfaceDecl *MD = dyn_cast<ObjcInterfaceDecl>(D)) {
RewriteInterfaceDecl(MD);
+ } else if (ObjcCategoryDecl *CD = dyn_cast<ObjcCategoryDecl>(D)) {
+ RewriteCategoryDecl(CD);
}
// If we have a decl in the main file, see if we should rewrite it.
if (SM->getDecomposedFileLoc(Loc).first == MainFileID)
typedefString.c_str(), typedefString.size());
}
+void RewriteTest::RewriteMethods(int nMethods, ObjcMethodDecl **Methods) {
+ for (int i = 0; i < nMethods; i++) {
+ ObjcMethodDecl *Method = Methods[i];
+ SourceLocation Loc = Method->getLocStart();
+
+ Rewrite.ReplaceText(Loc, 0, "// ", 3);
+
+ // FIXME: handle methods that are declared across multiple lines.
+ }
+}
+
+void RewriteTest::RewriteCategoryDecl(ObjcCategoryDecl *CatDecl) {
+ SourceLocation LocStart = CatDecl->getLocStart();
+
+ // FIXME: handle category headers that are declared across multiple lines.
+ Rewrite.ReplaceText(LocStart, 0, "// ", 3);
+
+ RewriteMethods(CatDecl->getNumInstanceMethods(),
+ CatDecl->getInstanceMethods());
+ RewriteMethods(CatDecl->getNumClassMethods(),
+ CatDecl->getClassMethods());
+ // Lastly, comment out the @end.
+ Rewrite.ReplaceText(CatDecl->getAtEndLoc(), 0, "// ", 3);
+}
+
void RewriteTest::RewriteInterfaceDecl(ObjcInterfaceDecl *ClassDecl) {
SourceLocation LocStart = ClassDecl->getLocStart();
Rewrite.ReplaceText(LocStart, endBuf-startBuf,
ResultStr.c_str(), ResultStr.size());
- int nInstanceMethods = ClassDecl->getNumInstanceMethods();
- ObjcMethodDecl **instanceMethods = ClassDecl->getInstanceMethods();
+ RewriteMethods(ClassDecl->getNumInstanceMethods(),
+ ClassDecl->getInstanceMethods());
+ RewriteMethods(ClassDecl->getNumClassMethods(),
+ ClassDecl->getClassMethods());
- for (int i = 0; i < nInstanceMethods; i++) {
- ObjcMethodDecl *instanceMethod = instanceMethods[i];
- SourceLocation Loc = instanceMethod->getLocStart();
-
- Rewrite.ReplaceText(Loc, 0, "// ", 3);
-
- // FIXME: handle methods that are declared across multiple lines.
- }
- int nClassMethods = ClassDecl->getNumClassMethods();
- ObjcMethodDecl **classMethods = ClassDecl->getClassMethods();
-
- for (int i = 0; i < nClassMethods; i++) {
- ObjcMethodDecl *classMethod = classMethods[i];
- SourceLocation Loc = classMethod->getLocStart();
-
- Rewrite.ReplaceText(Loc, 0, "// ", 3);
-
- // FIXME: handle methods that are declared across multiple lines.
- }
// Lastly, comment out the @end.
Rewrite.ReplaceText(ClassDecl->getAtEndLoc(), 0, "// ", 3);
}
DeclTy *CategoryType = Actions.ActOnStartCategoryInterface(atLoc,
nameId, nameLoc, categoryId, categoryLoc,
- &ProtocolRefs[0], ProtocolRefs.size());
+ &ProtocolRefs[0], ProtocolRefs.size(),
+ endProtoLoc);
ParseObjCInterfaceDeclList(CategoryType, tok::objc_not_keyword);
SourceLocation AtInterfaceLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
- IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs);
+ IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs,
+ SourceLocation EndProtoLoc);
virtual DeclTy *ActOnStartClassImplementation(
SourceLocation AtClassImplLoc,
ObjcProtocols[ProtocolName] = PDecl;
}
- /// Check then save referenced protocols
- for (unsigned int i = 0; i != NumProtoRefs; i++) {
- ObjcProtocolDecl* RefPDecl = ObjcProtocols[ProtoRefNames[i]];
- if (!RefPDecl || RefPDecl->isForwardDecl())
- Diag(ProtocolLoc, diag::err_undef_protocolref,
- ProtoRefNames[i]->getName(),
- ProtocolName->getName());
- PDecl->setReferencedProtocols((int)i, RefPDecl);
+ if (NumProtoRefs) {
+ /// Check then save referenced protocols
+ for (unsigned int i = 0; i != NumProtoRefs; i++) {
+ ObjcProtocolDecl* RefPDecl = ObjcProtocols[ProtoRefNames[i]];
+ if (!RefPDecl || RefPDecl->isForwardDecl())
+ Diag(ProtocolLoc, diag::err_undef_protocolref,
+ ProtoRefNames[i]->getName(),
+ ProtocolName->getName());
+ PDecl->setReferencedProtocols((int)i, RefPDecl);
+ }
+ PDecl->setLocEnd(EndProtoLoc);
}
-
return PDecl;
}
SourceLocation AtInterfaceLoc,
IdentifierInfo *ClassName, SourceLocation ClassLoc,
IdentifierInfo *CategoryName, SourceLocation CategoryLoc,
- IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs) {
+ IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs,
+ SourceLocation EndProtoLoc) {
ObjcInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName);
/// Check that class of this category is already completely declared.
if (!CDeclChain)
CDecl->insertNextClassCategory();
- /// Check then save referenced protocols
- for (unsigned int i = 0; i != NumProtoRefs; i++) {
- ObjcProtocolDecl* RefPDecl = ObjcProtocols[ProtoRefNames[i]];
- if (!RefPDecl || RefPDecl->isForwardDecl()) {
- Diag(CategoryLoc, diag::err_undef_protocolref,
- ProtoRefNames[i]->getName(),
- CategoryName->getName());
+ if (NumProtoRefs) {
+ /// Check then save referenced protocols
+ for (unsigned int i = 0; i != NumProtoRefs; i++) {
+ ObjcProtocolDecl* RefPDecl = ObjcProtocols[ProtoRefNames[i]];
+ if (!RefPDecl || RefPDecl->isForwardDecl()) {
+ Diag(CategoryLoc, diag::err_undef_protocolref,
+ ProtoRefNames[i]->getName(),
+ CategoryName->getName());
+ }
+ CDecl->setCatReferencedProtocols((int)i, RefPDecl);
}
- CDecl->setCatReferencedProtocols((int)i, RefPDecl);
+ CDecl->setLocEnd(EndProtoLoc);
}
-
return CDecl;
}
int NumClassMethods; // -1 if not defined
bool isForwardProtoDecl; // declared with @protocol.
+
+ SourceLocation EndLoc; // marks the '>' or identifier.
+ SourceLocation AtEndLoc; // marks the end of the entire interface.
public:
ObjcProtocolDecl(SourceLocation L, unsigned numRefProtos,
IdentifierInfo *Id, bool FD = false)
bool isForwardDecl() const { return isForwardProtoDecl; }
void setForwardDecl(bool val) { isForwardProtoDecl = val; }
+ // Location information, modeled after the Stmt API.
+ SourceLocation getLocStart() const { return getLocation(); } // '@'protocol
+ SourceLocation getLocEnd() const { return EndLoc; }
+ void setLocEnd(SourceLocation LE) { EndLoc = LE; };
+
+ // We also need to record the @end location.
+ SourceLocation getAtEndLoc() const { return AtEndLoc; }
+
static bool classof(const Decl *D) { return D->getKind() == ObjcProtocol; }
static bool classof(const ObjcProtocolDecl *D) { return true; }
};
/// Next category belonging to this class
ObjcCategoryDecl *NextClassCategory;
+ SourceLocation EndLoc; // marks the '>' or identifier.
+ SourceLocation AtEndLoc; // marks the end of the entire interface.
public:
ObjcCategoryDecl(SourceLocation L, unsigned numRefProtocol,IdentifierInfo *Id)
: NamedDecl(ObjcCategory, L, Id),
NextClassCategory = ClassInterface->getCategoryList();
ClassInterface->setCategoryList(this);
}
+ // Location information, modeled after the Stmt API.
+ SourceLocation getLocStart() const { return getLocation(); } // '@'interface
+ SourceLocation getLocEnd() const { return EndLoc; }
+ void setLocEnd(SourceLocation LE) { EndLoc = LE; };
+
+ // We also need to record the @end location.
+ SourceLocation getAtEndLoc() const { return AtEndLoc; }
static bool classof(const Decl *D) { return D->getKind() == ObjcCategory; }
static bool classof(const ObjcCategoryDecl *D) { return true; }
IdentifierInfo *CategoryName,
SourceLocation CategoryLoc,
IdentifierInfo **ProtoRefNames,
- unsigned NumProtoRefs) {
+ unsigned NumProtoRefs,
+ SourceLocation EndProtoLoc) {
return 0;
}
// ActOnStartClassImplementation - this action is called immdiately after