[cfe-commits] r70015 - in /cfe/trunk: include/clang/AST/Decl.h lib/AST/Decl.cpp lib/Sema/SemaDecl.cpp

Chris Lattner sabre at nondot.org
Fri Apr 24 23:03:54 PDT 2009


Author: lattner
Date: Sat Apr 25 01:03:53 2009
New Revision: 70015

URL: http://llvm.org/viewvc/llvm-project?rev=70015&view=rev
Log:
rename getNumParmVarDeclsFromType back to getNumParams(),
remove a special case that was apparently for typeof() and
generalize the code in SemaDecl that handles typedefs to 
handle any sugar type (including typedef, typeof, etc).
Improve comment to make it more clear what is going on.


Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=70015&r1=70014&r2=70015&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sat Apr 25 01:03:53 2009
@@ -643,9 +643,6 @@
 
   unsigned getBuiltinID(ASTContext &Context) const;
 
-  /// getNumParmVarDeclsFromType - Ignoring the actual argument list, this
-  /// returns the number of ParmVarDecls that the FunctionType of this function
-  /// expects.
   unsigned getNumParmVarDeclsFromType() const;
   
   // Iterator access to formal parameters.
@@ -659,7 +656,11 @@
   param_const_iterator param_begin() const { return ParamInfo; }
   param_const_iterator param_end() const   { return ParamInfo+param_size(); }
   
+  /// getNumParams - Return the number of parameters this function must have
+  /// based on its functiontype.  This is the length of the PararmInfo array
+  /// after it has been created.
   unsigned getNumParams() const;
+  
   const ParmVarDecl *getParamDecl(unsigned i) const {
     assert(i < getNumParams() && "Illegal param #");
     return ParamInfo[i];

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=70015&r1=70014&r2=70015&view=diff

==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Sat Apr 25 01:03:53 2009
@@ -431,10 +431,10 @@
 }
 
 
-/// getNumParmVarDeclsFromType - Ignoring the actual argument list, this
-/// returns the number of ParmVarDecls that the FunctionType of this function
-/// expects.
-unsigned FunctionDecl::getNumParmVarDeclsFromType() const {
+/// getNumParams - Return the number of parameters this function must have
+/// based on its functiontype.  This is the length of the PararmInfo array
+/// after it has been created.
+unsigned FunctionDecl::getNumParams() const {
   const FunctionType *FT = getType()->getAsFunctionType();
   if (isa<FunctionNoProtoType>(FT))
     return 0;
@@ -442,18 +442,10 @@
   
 }
 
-unsigned FunctionDecl::getNumParams() const {
-  // Can happen if a FunctionDecl is declared using typeof(some_other_func) bar;
-  if (!ParamInfo)
-    return 0;
-  
-  return getNumParmVarDeclsFromType();
-}
-
 void FunctionDecl::setParams(ASTContext& C, ParmVarDecl **NewParamInfo,
                              unsigned NumParams) {
   assert(ParamInfo == 0 && "Already has param info!");
-  assert(NumParams == getNumParmVarDeclsFromType() &&
+  assert(NumParams == getNumParams() &&
          "Parameter count mismatch!");
   
   // Zero params -> null pointer.

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Apr 25 01:03:53 2009
@@ -2153,8 +2153,8 @@
     }
   
     NewFD->setParams(Context, &Params[0], Params.size());
-  } else if (isa<TypedefType>(R)) {
-    // When we're declaring a function with a typedef, as in the
+  } else if (const FunctionProtoType *FT = R->getAsFunctionProtoType()) {
+    // When we're declaring a function with a typedef, typeof, etc as in the
     // following example, we'll need to synthesize (unnamed)
     // parameters for use in the declaration.
     //
@@ -2162,20 +2162,19 @@
     // typedef void fn(int);
     // fn f;
     // @endcode
-    if (const FunctionProtoType *FT = R->getAsFunctionProtoType()) {
-      // Synthesize a parameter for each argument type.
-      llvm::SmallVector<ParmVarDecl*, 16> Params;
-      for (FunctionProtoType::arg_type_iterator ArgType = FT->arg_type_begin();
-           ArgType != FT->arg_type_end(); ++ArgType) {
-        ParmVarDecl *Param = ParmVarDecl::Create(Context, DC,
-                                                 SourceLocation(), 0,
-                                                 *ArgType, VarDecl::None, 0);
-        Param->setImplicit();
-        Params.push_back(Param);
-      }
-
-      NewFD->setParams(Context, &Params[0], Params.size());
+    
+    // Synthesize a parameter for each argument type.
+    llvm::SmallVector<ParmVarDecl*, 16> Params;
+    for (FunctionProtoType::arg_type_iterator AI = FT->arg_type_begin(),
+         AE = FT->arg_type_end(); AI != AE; ++AI) {
+      ParmVarDecl *Param = ParmVarDecl::Create(Context, DC,
+                                               SourceLocation(), 0,
+                                               *AI, VarDecl::None, 0);
+      Param->setImplicit();
+      Params.push_back(Param);
     }
+
+    NewFD->setParams(Context, &Params[0], Params.size());
   }
     
   // If name lookup finds a previous declaration that is not in the





More information about the cfe-commits mailing list