From dfd637f2047f634136efd3bf1739ff4558017aa0 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 25 Apr 2009 05:56:45 +0000 Subject: [PATCH] add a new helper function to FunctionDecl instead of it being static in Decl.cpp. llvm-svn: 70014 --- clang/include/clang/AST/Decl.h | 5 +++++ clang/lib/AST/Decl.cpp | 13 ++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 1d2c39e18a10..901da704ce9e 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -643,6 +643,11 @@ public: 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. unsigned param_size() const { return getNumParams(); } typedef ParmVarDecl **param_iterator; diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 0326b34960fc..a715531c74a5 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -431,12 +431,15 @@ unsigned FunctionDecl::getBuiltinID(ASTContext &Context) const { } -// Helper function for FunctionDecl::getNumParams and FunctionDecl::setParams() -static unsigned getNumTypeParams(QualType T) { - const FunctionType *FT = T->getAsFunctionType(); +/// getNumParmVarDeclsFromType - Ignoring the actual argument list, this +/// returns the number of ParmVarDecls that the FunctionType of this function +/// expects. +unsigned FunctionDecl::getNumParmVarDeclsFromType() const { + const FunctionType *FT = getType()->getAsFunctionType(); if (isa(FT)) return 0; return cast(FT)->getNumArgs(); + } unsigned FunctionDecl::getNumParams() const { @@ -444,13 +447,13 @@ unsigned FunctionDecl::getNumParams() const { if (!ParamInfo) return 0; - return getNumTypeParams(getType()); + return getNumParmVarDeclsFromType(); } void FunctionDecl::setParams(ASTContext& C, ParmVarDecl **NewParamInfo, unsigned NumParams) { assert(ParamInfo == 0 && "Already has param info!"); - assert(NumParams == getNumTypeParams(getType()) && + assert(NumParams == getNumParmVarDeclsFromType() && "Parameter count mismatch!"); // Zero params -> null pointer.