Skip to content

Commit

Permalink
Rewrite method definition bodies. Also renamed a method to distinguis…
Browse files Browse the repository at this point in the history
…h between method declarations and definitions.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44080 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Steve Naroff committed Nov 13, 2007
1 parent 950ba9c commit 71c0a95
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
34 changes: 19 additions & 15 deletions Driver/RewriteTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace {
void RewriteObjcMethodDecl(ObjcMethodDecl *MDecl, std::string &ResultStr);
void RewriteCategoryDecl(ObjcCategoryDecl *Dcl);
void RewriteProtocolDecl(ObjcProtocolDecl *Dcl);
void RewriteMethods(int nMethods, ObjcMethodDecl **Methods);
void RewriteMethodDeclarations(int nMethods, ObjcMethodDecl **Methods);
void RewriteProperties(int nProperties, ObjcPropertyDecl **Properties);
void RewriteFunctionDecl(FunctionDecl *FD);
void RewriteObjcQualifiedInterfaceTypes(
Expand Down Expand Up @@ -189,7 +189,11 @@ void RewriteTest::HandleDeclInMainFile(Decl *D) {
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
if (Stmt *Body = FD->getBody())
FD->setBody(RewriteFunctionBodyOrGlobalInitializer(Body));


if (ObjcMethodDecl *MD = dyn_cast<ObjcMethodDecl>(D)) {
if (Stmt *Body = MD->getBody())
MD->setBody(RewriteFunctionBodyOrGlobalInitializer(Body));
}
if (ObjcImplementationDecl *CI = dyn_cast<ObjcImplementationDecl>(D))
ClassImplementation.push_back(CI);
else if (ObjcCategoryImplDecl *CI = dyn_cast<ObjcCategoryImplDecl>(D))
Expand Down Expand Up @@ -325,7 +329,7 @@ void RewriteTest::RewriteForwardClassDecl(ObjcClassDecl *ClassDecl) {
typedefString.c_str(), typedefString.size());
}

void RewriteTest::RewriteMethods(int nMethods, ObjcMethodDecl **Methods) {
void RewriteTest::RewriteMethodDeclarations(int nMethods, ObjcMethodDecl **Methods) {
for (int i = 0; i < nMethods; i++) {
ObjcMethodDecl *Method = Methods[i];
SourceLocation Loc = Method->getLocStart();
Expand Down Expand Up @@ -354,10 +358,10 @@ void RewriteTest::RewriteCategoryDecl(ObjcCategoryDecl *CatDecl) {
// 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());
RewriteMethodDeclarations(CatDecl->getNumInstanceMethods(),
CatDecl->getInstanceMethods());
RewriteMethodDeclarations(CatDecl->getNumClassMethods(),
CatDecl->getClassMethods());
// Lastly, comment out the @end.
Rewrite.ReplaceText(CatDecl->getAtEndLoc(), 0, "// ", 3);
}
Expand All @@ -368,10 +372,10 @@ void RewriteTest::RewriteProtocolDecl(ObjcProtocolDecl *PDecl) {
// FIXME: handle protocol headers that are declared across multiple lines.
Rewrite.ReplaceText(LocStart, 0, "// ", 3);

RewriteMethods(PDecl->getNumInstanceMethods(),
PDecl->getInstanceMethods());
RewriteMethods(PDecl->getNumClassMethods(),
PDecl->getClassMethods());
RewriteMethodDeclarations(PDecl->getNumInstanceMethods(),
PDecl->getInstanceMethods());
RewriteMethodDeclarations(PDecl->getNumClassMethods(),
PDecl->getClassMethods());
// Lastly, comment out the @end.
Rewrite.ReplaceText(PDecl->getAtEndLoc(), 0, "// ", 3);
}
Expand Down Expand Up @@ -533,10 +537,10 @@ void RewriteTest::RewriteInterfaceDecl(ObjcInterfaceDecl *ClassDecl) {
ResultStr.c_str(), ResultStr.size());
RewriteProperties(ClassDecl->getNumPropertyDecl(),
ClassDecl->getPropertyDecl());
RewriteMethods(ClassDecl->getNumInstanceMethods(),
ClassDecl->getInstanceMethods());
RewriteMethods(ClassDecl->getNumClassMethods(),
ClassDecl->getClassMethods());
RewriteMethodDeclarations(ClassDecl->getNumInstanceMethods(),
ClassDecl->getInstanceMethods());
RewriteMethodDeclarations(ClassDecl->getNumClassMethods(),
ClassDecl->getClassMethods());

// Lastly, comment out the @end.
Rewrite.ReplaceText(ClassDecl->getAtEndLoc(), 0, "// ", 3);
Expand Down
5 changes: 3 additions & 2 deletions Parse/ParseObjc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ Parser::StmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {

/// objc-method-def: objc-method-proto ';'[opt] '{' body '}'
///
void Parser::ParseObjCMethodDefinition() {
Parser::DeclTy *Parser::ParseObjCMethodDefinition() {
DeclTy *MDecl = ParseObjCMethodPrototype(ObjcImpDecl);
// parse optional ';'
if (Tok.is(tok::semi))
Expand All @@ -1154,7 +1154,7 @@ void Parser::ParseObjCMethodDefinition() {

// If we didn't find the '{', bail out.
if (Tok.isNot(tok::l_brace))
return;
return 0;
}
SourceLocation BraceLoc = Tok.getLocation();

Expand All @@ -1176,6 +1176,7 @@ void Parser::ParseObjCMethodDefinition() {

// TODO: Pass argument information.
Actions.ActOnFinishFunctionBody(MDecl, FnBody.Val);
return MDecl;
}

Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
Expand Down
2 changes: 1 addition & 1 deletion Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ Parser::DeclTy *Parser::ParseExternalDeclaration() {
case tok::minus:
case tok::plus:
if (getLang().ObjC1)
ParseObjCMethodDefinition();
return ParseObjCMethodDefinition();
else {
Diag(Tok, diag::err_expected_external_declaration);
ConsumeToken();
Expand Down
2 changes: 1 addition & 1 deletion include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class Parser {
void ParseObjCPropertyAttribute(ObjcDeclSpec &DS);
DeclTy *ParseObjCPropertyDecl(DeclTy *interfaceDecl, SourceLocation AtLoc);

void ParseObjCMethodDefinition();
DeclTy *ParseObjCMethodDefinition();

//===--------------------------------------------------------------------===//
// C99 6.5: Expressions.
Expand Down

0 comments on commit 71c0a95

Please sign in to comment.