[cfe-commits] r43967 - in /cfe/trunk: Parse/ParseObjc.cpp Parse/Parser.cpp Sema/Sema.h Sema/SemaDecl.cpp Sema/SemaType.cpp include/clang/Parse/Action.h include/clang/Parse/Parser.h

Fariborz Jahanian fjahanian at apple.com
Fri Nov 9 14:28:00 PST 2007


Author: fjahanian
Date: Fri Nov  9 16:27:59 2007
New Revision: 43967

URL: http://llvm.org/viewvc/llvm-project?rev=43967&view=rev
Log:
Some code clean up in the form of name changes for functions which
process method definitions.

Modified:
    cfe/trunk/Parse/ParseObjc.cpp
    cfe/trunk/Parse/Parser.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/Sema/SemaType.cpp
    cfe/trunk/include/clang/Parse/Action.h
    cfe/trunk/include/clang/Parse/Parser.h

Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=43967&r1=43966&r2=43967&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Fri Nov  9 16:27:59 2007
@@ -1160,7 +1160,7 @@
     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 @@
     Diag (Tok, diag::err_expected_lbrace);
     return 0;
   }
-  return ObjcParseFunctionDefinition(MDecl);
+  return ObjcParseMethodDefinition(MDecl);
 }
 
 Parser::ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {

Modified: cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/Parser.cpp?rev=43967&r1=43966&r2=43967&view=diff

==============================================================================
--- cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/trunk/Parse/Parser.cpp Fri Nov  9 16:27:59 2007
@@ -465,7 +465,9 @@
   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 @@
   
   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);  
 }

Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=43967&r1=43966&r2=43967&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Fri Nov  9 16:27:59 2007
@@ -172,7 +172,7 @@
   //
   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 @@
   //
   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 @@
   /// 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);

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=43967&r1=43966&r2=43967&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Fri Nov  9 16:27:59 2007
@@ -544,14 +544,16 @@
   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<ObjcMethodDecl>(static_cast<Decl *>(D));
   
   ScopedDecl *LastDeclarator = dyn_cast_or_null<ScopedDecl>((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 @@
     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<ScopedDecl>());
-    II->setFETokenInfo(New);
-    S->AddDecl(New);
-  }
+  New->setNext(II->getFETokenInfo<ScopedDecl>());
+  II->setFETokenInfo(New);
+  S->AddDecl(New);
   
   if (S->getParent() == 0)
     AddTopLevelDecl(New, LastDeclarator);
@@ -890,18 +889,11 @@
   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 @@
   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<ObjcMethodDecl>(static_cast<Decl *>(D));
   
@@ -1040,7 +1034,7 @@
   Scope *GlobalScope = FnBodyScope->getParent();
   
   FunctionDecl *FD =
-  static_cast<FunctionDecl*>(ObjcActOnDeclarator(GlobalScope, D, 0));
+  static_cast<FunctionDecl*>(ObjcActOnMethodDefinition(GlobalScope, D, 0));
   CurFunctionDecl = FD;
   
   // Create Decl objects for each parameter, adding them to the FunctionDecl.
@@ -1059,16 +1053,16 @@
     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());

Modified: cfe/trunk/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaType.cpp?rev=43967&r1=43966&r2=43967&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/trunk/Sema/SemaType.cpp Fri Nov  9 16:27:59 2007
@@ -325,9 +325,9 @@
   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<ObjcMethodDecl>(static_cast<Decl *>(D));
   QualType T = MDecl->getResultType();
   llvm::SmallVector<QualType, 16> ArgTys;
@@ -346,20 +346,9 @@
     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())

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=43967&r1=43966&r2=43967&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Fri Nov  9 16:27:59 2007
@@ -107,7 +107,8 @@
     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 @@
     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

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=43967&r1=43966&r2=43967&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Fri Nov  9 16:27:59 2007
@@ -250,7 +250,7 @@
   DeclTy *ParseExternalDeclaration();
   DeclTy *ParseDeclarationOrFunctionDefinition();
   DeclTy *ParseFunctionDefinition(Declarator &D);
-  DeclTy *ObjcParseFunctionDefinition(DeclTy *D);
+  DeclTy *ObjcParseMethodDefinition(DeclTy *D);
   void ParseKNRParamDeclarations(Declarator &D);
   void ParseSimpleAsm();
   void ParseAsmStringLiteral();





More information about the cfe-commits mailing list