From 360300ca2ee298d585d29baf006519507d968812 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 9 Nov 2007 22:27:59 +0000 Subject: [PATCH] Some code clean up in the form of name changes for functions which process method definitions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43967 91177308-0d34-0410-b5e6-96231b3b80d8 --- Parse/ParseObjc.cpp | 4 ++-- Parse/Parser.cpp | 12 ++++++----- Sema/Sema.h | 9 ++++---- Sema/SemaDecl.cpp | 42 ++++++++++++++++-------------------- Sema/SemaType.cpp | 19 ++++------------ include/clang/Parse/Action.h | 7 +++--- include/clang/Parse/Parser.h | 2 +- 7 files changed, 41 insertions(+), 54 deletions(-) diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index a3fb0e80ab..b8b5b913ee 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -1160,7 +1160,7 @@ Parser::DeclTy *Parser::ParseObjCInstanceMethodDefinition() { Diag (Tok, diag::err_expected_lbrace); return 0; } - return ObjcParseFunctionDefinition(MDecl); + return ObjcParseMethodDefinition(MDecl); } /// objc-method-def: objc-method-proto ';'[opt] '{' body '}' @@ -1177,7 +1177,7 @@ Parser::DeclTy *Parser::ParseObjCClassMethodDefinition() { Diag (Tok, diag::err_expected_lbrace); return 0; } - return ObjcParseFunctionDefinition(MDecl); + return ObjcParseMethodDefinition(MDecl); } Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) { diff --git a/Parse/Parser.cpp b/Parse/Parser.cpp index 59a077d21b..cfa92e1020 100644 --- a/Parse/Parser.cpp +++ b/Parse/Parser.cpp @@ -465,7 +465,9 @@ Parser::DeclTy *Parser::ParseFunctionDefinition(Declarator &D) { return ParseFunctionStatementBody(Res, BraceLoc, BraceLoc); } -Parser::DeclTy *Parser::ObjcParseFunctionDefinition(DeclTy *D) { +/// ObjcParseMethodDefinition - This routine parses a method definition and +/// returns its AST. +Parser::DeclTy *Parser::ObjcParseMethodDefinition(DeclTy *D) { // We should have an opening brace now. if (Tok.isNot(tok::l_brace)) { Diag(Tok, diag::err_expected_fn_body); @@ -480,12 +482,12 @@ Parser::DeclTy *Parser::ObjcParseFunctionDefinition(DeclTy *D) { SourceLocation BraceLoc = Tok.getLocation(); - // Enter a scope for the function body. + // Enter a scope for the method body. EnterScope(Scope::FnScope|Scope::DeclScope); - // Tell the actions module that we have entered a function definition with the - // specified Declarator for the function. - DeclTy *Res = Actions.ObjcActOnStartOfFunctionDef(CurScope, D); + // Tell the actions module that we have entered a method definition with the + // specified Declarator for the method. + DeclTy *Res = Actions.ObjcActOnStartOfMethodDef(CurScope, D); return ParseFunctionStatementBody(Res, BraceLoc, BraceLoc); } diff --git a/Sema/Sema.h b/Sema/Sema.h index 50a604619c..9816e81009 100644 --- a/Sema/Sema.h +++ b/Sema/Sema.h @@ -172,7 +172,7 @@ public: // QualType GetTypeForDeclarator(Declarator &D, Scope *S); - QualType ObjcGetTypeForDeclarator(DeclTy *D, Scope *S); + QualType ObjcGetTypeForMethodDefinition(DeclTy *D, Scope *S); virtual TypeResult ActOnTypeName(Scope *S, Declarator &D); @@ -184,12 +184,13 @@ private: // virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const; virtual DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup); - virtual DeclTy *ObjcActOnDeclarator(Scope *S, DeclTy *D, DeclTy *LastInGroup); + virtual DeclTy *ObjcActOnMethodDefinition(Scope *S, DeclTy *D, + DeclTy *LastInGroup); void AddInitializerToDecl(DeclTy *dcl, ExprTy *init); virtual DeclTy *FinalizeDeclaratorGroup(Scope *S, DeclTy *Group); virtual DeclTy *ActOnStartOfFunctionDef(Scope *S, Declarator &D); - virtual DeclTy *ObjcActOnStartOfFunctionDef(Scope *S, DeclTy *D); + virtual DeclTy *ObjcActOnStartOfMethodDef(Scope *S, DeclTy *D); virtual DeclTy *ActOnFunctionDefBody(DeclTy *Decl, StmtTy *Body); /// Scope actions. @@ -231,7 +232,7 @@ private: /// More parsing and symbol table subroutines... ParmVarDecl *ParseParamDeclarator(DeclaratorChunk &FI, unsigned ArgNo, Scope *FnBodyScope); - ParmVarDecl *ObjcParseParamDeclarator(ParmVarDecl *param, Scope *FnBodyScope); + ParmVarDecl *ObjcBuildMethodParameter(ParmVarDecl *param, Scope *FnBodyScope); ScopedDecl *LookupScopedDecl(IdentifierInfo *II, unsigned NSI, SourceLocation IdLoc, Scope *S); diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp index 41f509ad95..1fb221931a 100644 --- a/Sema/SemaDecl.cpp +++ b/Sema/SemaDecl.cpp @@ -544,14 +544,16 @@ bool Sema::CheckInitializer(Expr *&Init, QualType &DeclType, bool isStatic) { return hadError; } +/// ObjcActOnMethodDefinition - Build the AST node for a method definition +/// header. Return this AST. Sema::DeclTy * -Sema::ObjcActOnDeclarator(Scope *S, DeclTy *D, DeclTy *lastDecl) { +Sema::ObjcActOnMethodDefinition(Scope *S, DeclTy *D, DeclTy *lastDecl) { ObjcMethodDecl *MDecl = dyn_cast(static_cast(D)); ScopedDecl *LastDeclarator = dyn_cast_or_null((Decl *)lastDecl); const char *name = MDecl->getSelector().getName().c_str(); IdentifierInfo *II = &Context.Idents.get(name); - assert (II && "ObjcActOnDeclarator - selector name is missing"); + assert (II && "ObjcActOnMethodDefinition - selector name is missing"); // The scope passed in may not be a decl scope. Zip up the scope tree until // we find one that is. @@ -559,20 +561,17 @@ Sema::ObjcActOnDeclarator(Scope *S, DeclTy *D, DeclTy *lastDecl) { S = S->getParent(); ScopedDecl *New; - QualType R = ObjcGetTypeForDeclarator(MDecl, S); - assert(!R.isNull() && "ObjcGetTypeForDeclarator() returned null type"); + QualType R = ObjcGetTypeForMethodDefinition(MDecl, S); + assert(!R.isNull() && "ObjcGetTypeForMethodDefinition() returned null type"); FunctionDecl *NewFD = new FunctionDecl(MDecl->getLocation(), II, R, FunctionDecl::Static, false, LastDeclarator); New = NewFD; - // If this has an identifier, add it to the scope stack. - if (II) { - New->setNext(II->getFETokenInfo()); - II->setFETokenInfo(New); - S->AddDecl(New); - } + New->setNext(II->getFETokenInfo()); + II->setFETokenInfo(New); + S->AddDecl(New); if (S->getParent() == 0) AddTopLevelDecl(New, LastDeclarator); @@ -890,18 +889,11 @@ Sema::ParseParamDeclarator(DeclaratorChunk &FTI, unsigned ArgNo, return New; } -// Called from Sema::ObjcParseStartOfFunctionDef(). +// Called from Sema::ObjcParseStartOfMethodDef(). ParmVarDecl * -Sema::ObjcParseParamDeclarator(ParmVarDecl *PI, Scope *FnScope) { +Sema::ObjcBuildMethodParameter(ParmVarDecl *PI, Scope *FnScope) { IdentifierInfo *II = PI->getIdentifier(); - // TODO: CHECK FOR CONFLICTS, multiple decls with same name in one scope. - // Can this happen for params? We already checked that they don't conflict - // among each other. Here they can only shadow globals, which is ok. - if (/*Decl *PrevDecl = */LookupScopedDecl(II, Decl::IDNS_Ordinary, - PI->getLocation(), FnScope)) { - - } // FIXME: Handle storage class (auto, register). No declarator? // TODO: Chain to previous parameter with the prevdeclarator chain? @@ -1031,7 +1023,9 @@ Sema::DeclTy *Sema::ActOnFunctionDefBody(DeclTy *D, StmtTy *Body) { return FD; } -Sema::DeclTy *Sema::ObjcActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) { +/// ObjcActOnStartOfMethodDef - This routine sets up parameters; invisible +/// and user declared, in the method definition's AST. +Sema::DeclTy *Sema::ObjcActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) { assert(CurFunctionDecl == 0 && "Function parsing confused"); ObjcMethodDecl *MDecl = dyn_cast(static_cast(D)); @@ -1040,7 +1034,7 @@ Sema::DeclTy *Sema::ObjcActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) { Scope *GlobalScope = FnBodyScope->getParent(); FunctionDecl *FD = - static_cast(ObjcActOnDeclarator(GlobalScope, D, 0)); + static_cast(ObjcActOnMethodDefinition(GlobalScope, D, 0)); CurFunctionDecl = FD; // Create Decl objects for each parameter, adding them to the FunctionDecl. @@ -1059,16 +1053,16 @@ Sema::DeclTy *Sema::ObjcActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) { PDecl = new ParmVarDecl(SourceLocation(/*FIXME*/), &Context.Idents.get("self"), Context.getObjcIdType(), VarDecl::None, 0); - Params.push_back(ObjcParseParamDeclarator(PDecl, FnBodyScope)); + Params.push_back(ObjcBuildMethodParameter(PDecl, FnBodyScope)); PDecl = new ParmVarDecl(SourceLocation(/*FIXME*/), &Context.Idents.get("_cmd"), Context.getObjcSelType(), VarDecl::None, 0); - Params.push_back(ObjcParseParamDeclarator(PDecl, FnBodyScope)); + Params.push_back(ObjcBuildMethodParameter(PDecl, FnBodyScope)); for (int i = 0; i < MDecl->getNumParams(); i++) { PDecl = MDecl->getParamDecl(i); - Params.push_back(ObjcParseParamDeclarator(PDecl, FnBodyScope)); + Params.push_back(ObjcBuildMethodParameter(PDecl, FnBodyScope)); } FD->setParams(&Params[0], Params.size()); diff --git a/Sema/SemaType.cpp b/Sema/SemaType.cpp index 71ec3f395d..7eb546efbf 100644 --- a/Sema/SemaType.cpp +++ b/Sema/SemaType.cpp @@ -325,9 +325,9 @@ QualType Sema::GetTypeForDeclarator(Declarator &D, Scope *S) { return T; } -/// ObjcGetTypeForDeclarator - Convert the type for the specified declarator to Type -/// instances. -QualType Sema::ObjcGetTypeForDeclarator(DeclTy *D, Scope *S) { +/// ObjcGetTypeForMethodDefinition - Builds the type for a method definition +/// declarator +QualType Sema::ObjcGetTypeForMethodDefinition(DeclTy *D, Scope *S) { ObjcMethodDecl *MDecl = dyn_cast(static_cast(D)); QualType T = MDecl->getResultType(); llvm::SmallVector ArgTys; @@ -346,20 +346,9 @@ QualType Sema::ObjcGetTypeForDeclarator(DeclTy *D, Scope *S) { ParmVarDecl *PDecl = MDecl->getParamDecl(i); QualType ArgTy = PDecl->getType(); assert(!ArgTy.isNull() && "Couldn't parse type?"); - // // Perform the default function/array conversion (C99 6.7.5.3p[7,8]). // This matches the conversion that is done in - // Sema::ParseParamDeclarator(). Without this conversion, the - // argument type in the function prototype *will not* match the - // type in ParmVarDecl (which makes the code generator unhappy). - // - // FIXME: We still apparently need the conversion in - // Sema::ParseParamDeclarator(). This doesn't make any sense, since - // it should be driving off the type being created here. - // - // FIXME: If a source translation tool needs to see the original type, - // then we need to consider storing both types somewhere... - // + // Sema::ObjcBuildMethodParameter(). if (const ArrayType *AT = ArgTy->getAsArrayType()) ArgTy = Context.getPointerType(AT->getElementType()); else if (ArgTy->isFunctionType()) diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index 17bf9b9643..c91caded27 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -107,7 +107,8 @@ public: return 0; } - virtual DeclTy *ObjcActOnDeclarator(Scope *S, DeclTy *D,DeclTy *LastInGroup) { + virtual DeclTy *ObjcActOnMethodDefinition(Scope *S, DeclTy *D, + DeclTy *LastInGroup) { return 0; } /// AddInitializerToDecl - This action is called immediately after @@ -134,9 +135,9 @@ public: return ActOnDeclarator(FnBodyScope, D, 0); } - virtual DeclTy *ObjcActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) { + virtual DeclTy *ObjcActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) { // Default to ActOnDeclarator. - return ObjcActOnDeclarator(FnBodyScope, D, 0); + return ObjcActOnMethodDefinition(FnBodyScope, D, 0); } /// ActOnFunctionDefBody - This is called when a function body has completed diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index e453aa769e..3a1e7d18ce 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -250,7 +250,7 @@ private: DeclTy *ParseExternalDeclaration(); DeclTy *ParseDeclarationOrFunctionDefinition(); DeclTy *ParseFunctionDefinition(Declarator &D); - DeclTy *ObjcParseFunctionDefinition(DeclTy *D); + DeclTy *ObjcParseMethodDefinition(DeclTy *D); void ParseKNRParamDeclarations(Declarator &D); void ParseSimpleAsm(); void ParseAsmStringLiteral();