void RewriteInclude(SourceLocation Loc);
void RewriteTabs();
void RewriteForwardClassDecl(ObjcClassDecl *Dcl);
+ void RewriteInterfaceDecl(ObjcInterfaceDecl *Dcl);
// Expression Rewriting.
Stmt *RewriteFunctionBody(Stmt *S);
GetClassFunctionDecl = FD;
else if (strcmp(FD->getName(), "sel_getUid") == 0)
SelGetUidFunctionDecl = FD;
+ } else if (ObjcInterfaceDecl *MD = dyn_cast<ObjcInterfaceDecl>(D)) {
+ RewriteInterfaceDecl(MD);
}
-
// If we have a decl in the main file, see if we should rewrite it.
if (SM->getDecomposedFileLoc(Loc).first == MainFileID)
return HandleDeclInMainFile(D);
typedefString.c_str(), typedefString.size());
}
+void RewriteTest::RewriteInterfaceDecl(ObjcInterfaceDecl *ClassDecl) {
+ int nInstanceMethods = ClassDecl->getNumInstanceMethods();
+ ObjcMethodDecl **instanceMethods = ClassDecl->getInstanceMethods();
+
+ 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.
+ }
+}
+
//===----------------------------------------------------------------------===//
// Function Body / Expression rewriting
//===----------------------------------------------------------------------===//
messString += "// ";
messString.append(startBuf, endBuf-startBuf+1);
messString += "\n";
-
+
// FIXME: Missing definition of Rewrite.InsertText(clang::SourceLocation, char const*, unsigned int).
// Rewrite.InsertText(startLoc, messString.c_str(), messString.size());
// Tried this, but it didn't work either...
- // Rewrite.ReplaceText(startLoc, 0, messString.c_str(), messString.size());
+ Rewrite.ReplaceText(startLoc, 0, messString.c_str(), messString.size());
return RewriteMessageExpr(MessExpr);
}
// Return this stmt unmodified.
assert((Tok.is(tok::minus) || Tok.is(tok::plus)) && "expected +/-");
tok::TokenKind methodType = Tok.getKind();
- ConsumeToken();
+ SourceLocation mLoc = ConsumeToken();
- DeclTy *MDecl = ParseObjCMethodDecl(methodType, MethodImplKind);
+ DeclTy *MDecl = ParseObjCMethodDecl(mLoc, methodType, MethodImplKind);
// Since this rule is used for both method declarations and definitions,
// the caller is (optionally) responsible for consuming the ';'.
return MDecl;
/// objc-keyword-attributes: [OBJC2]
/// __attribute__((unused))
///
-Parser::DeclTy *Parser::ParseObjCMethodDecl(tok::TokenKind mType,
+Parser::DeclTy *Parser::ParseObjCMethodDecl(SourceLocation mLoc,
+ tok::TokenKind mType,
tok::ObjCKeywordKind MethodImplKind)
{
// Parse the return type.
TypeTy *ReturnType = 0;
if (Tok.is(tok::l_paren))
ReturnType = ParseObjCTypeName();
- SourceLocation mLoc;
- IdentifierInfo *SelIdent = ParseObjCSelector(mLoc);
+ SourceLocation selLoc;
+ IdentifierInfo *SelIdent = ParseObjCSelector(selLoc);
if (Tok.isNot(tok::colon)) {
if (!SelIdent) {
Diag(Tok, diag::err_expected_ident); // missing selector name.
MethodAttrs = ParseAttributes();
Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent);
- return Actions.ActOnMethodDeclaration(mLoc, mType, ReturnType, Sel,
+ return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
+ mType, ReturnType, Sel,
0, 0, MethodAttrs, MethodImplKind);
}
Selector Sel = PP.getSelectorTable().getSelector(KeyIdents.size(),
&KeyIdents[0]);
- return Actions.ActOnMethodDeclaration(mLoc, mType, ReturnType, Sel,
+ return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
+ mType, ReturnType, Sel,
&KeyTypes[0], &ArgNames[0],
MethodAttrs, MethodImplKind);
}
virtual void ActOnAddMethodsToObjcDecl(Scope* S, DeclTy *ClassDecl,
DeclTy **allMethods, unsigned allNum);
- virtual DeclTy *ActOnMethodDeclaration(SourceLocation MethodLoc,
+ virtual DeclTy *ActOnMethodDeclaration(
+ SourceLocation BeginLoc, // location of the + or -.
+ SourceLocation EndLoc, // location of the ; or {.
tok::TokenKind MethodType, TypeTy *ReturnType, Selector Sel,
// optional arguments. The number of types/arguments is obtained
// from the Sel.getNumArgs().
// is obtained from Sel.getNumArgs().
virtual ExprResult ActOnClassMessage(
IdentifierInfo *receivingClassName, Selector Sel,
- SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs);
+ SourceLocation lbrac, SourceLocation rbrac, ExprTy **ArgExprs);
// ActOnInstanceMessage - used for both unary and keyword messages.
// ArgExprs is optional - if it is present, the number of expressions
}
}
-Sema::DeclTy *Sema::ActOnMethodDeclaration(SourceLocation MethodLoc,
+Sema::DeclTy *Sema::ActOnMethodDeclaration(
+ SourceLocation MethodLoc, SourceLocation EndLoc,
tok::TokenKind MethodType, TypeTy *ReturnType, Selector Sel,
// optional arguments. The number of types/arguments is obtained
// from the Sel.getNumArgs().
else // get the type for "id".
resultDeclType = GetObjcIdType(MethodLoc);
- ObjcMethodDecl* ObjcMethod = new ObjcMethodDecl(MethodLoc, Sel,
+ ObjcMethodDecl* ObjcMethod = new ObjcMethodDecl(MethodLoc, EndLoc, Sel,
resultDeclType, 0, -1, AttrList,
MethodType == tok::minus,
MethodDeclKind == tok::objc_optional ?
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
- compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
/// List of attributes for this method declaration.
AttributeList *MethodAttrs;
+ SourceLocation EndLoc; // the location of the ';' or '{'.
public:
- ObjcMethodDecl(SourceLocation L, Selector SelInfo, QualType T,
+ ObjcMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
+ Selector SelInfo, QualType T,
ParmVarDecl **paramInfo = 0, int numParams=-1,
AttributeList *M = 0, bool isInstance = true,
ImplementationControl impControl = None,
Decl *PrevDecl = 0)
- : Decl(ObjcMethod, L),
+ : Decl(ObjcMethod, beginLoc),
IsInstance(isInstance), DeclImplementation(impControl),
SelName(SelInfo), MethodDeclType(T),
ParamInfo(paramInfo), NumMethodParams(numParams),
- MethodAttrs(M) {}
+ MethodAttrs(M), EndLoc(endLoc) {}
virtual ~ObjcMethodDecl();
+ // Location information, modeled after the Stmt API.
+ SourceLocation getLocStart() const { return getLocation(); }
+ SourceLocation getLocEnd() const { return EndLoc; }
+
Selector getSelector() const { return SelName; }
QualType getResultType() const { return MethodDeclType; }
}
// ActOnMethodDeclaration - called for all method declarations.
virtual DeclTy *ActOnMethodDeclaration(
- SourceLocation MethodLoc,
+ SourceLocation BeginLoc, // location of the + or -.
+ SourceLocation EndLoc, // location of the ; or {.
tok::TokenKind MethodType, // tok::minus for instance, tok::plus for class.
TypeTy *ReturnType, // the method return type.
Selector Sel, // a unique name for the method.
void ParseObjCMethodRequirement();
DeclTy *ParseObjCMethodPrototype(DeclTy *classOrCat,
tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
- DeclTy *ParseObjCMethodDecl(tok::TokenKind mType,
+ DeclTy *ParseObjCMethodDecl(SourceLocation mLoc, tok::TokenKind mType,
tok::ObjCKeywordKind MethodImplKind = tok::objc_not_keyword);
void ParseObjCPropertyAttribute(DeclTy *interfaceDecl);
void ParseObjCPropertyDecl(DeclTy *interfaceDecl);