From af23f69aa6247e6bd20a66b2e16babb91f192535 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Sat, 18 Apr 2009 20:20:22 +0000 Subject: Make CodeGenFunction::EmitCallArgs a template function that takes a generic "Type Info" parameter. The type info parameter knows how to iterate over its arguments. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69469 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenFunction.h | 44 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'lib/CodeGen/CodeGenFunction.h') diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index d511da3f7f..45f96d33b7 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -811,14 +811,46 @@ private: RValue EmitCallArg(const Expr *E, QualType ArgType); /// EmitCallArgs - Emit call arguments for a function. - /// FIXME: It should be possible to generalize this and pass a generic - /// "argument type container" type instead of the FunctionProtoType. This way - /// it can work on Objective-C methods as well. - void EmitCallArgs(CallArgList& args, const FunctionProtoType *FPT, + /// The CallArgTypeInfo parameter is used for iterating over the known + /// argument types of the function being called. + template + void EmitCallArgs(CallArgList& Args, const T* CallArgTypeInfo, CallExpr::const_arg_iterator ArgBeg, - CallExpr::const_arg_iterator ArgEnd); - + CallExpr::const_arg_iterator ArgEnd) { + CallExpr::const_arg_iterator Arg = ArgBeg; + + // First, use the argument types that the type info knows about + if (CallArgTypeInfo) { + for (typename T::arg_type_iterator I = CallArgTypeInfo->arg_type_begin(), + E = CallArgTypeInfo->arg_type_end(); I != E; ++I, ++Arg) { + QualType ArgType = *I; + + assert(getContext().getCanonicalType(ArgType.getNonReferenceType()). + getTypePtr() == + getContext().getCanonicalType(Arg->getType()).getTypePtr() && + "type mismatch in call argument!"); + + Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType), + ArgType)); + } + + // Either we've emitted all the call args, or we have a call to a + // variadic function. + assert(Arg == ArgEnd || CallArgTypeInfo->isVariadic() && + "Extra arguments in non-variadic function!"); + + } + + // If we still have any arguments, emit them using the type of the argument. + for (; Arg != ArgEnd; ++Arg) { + QualType ArgType = Arg->getType(); + Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType), + ArgType)); + } + } }; + + } // end namespace CodeGen } // end namespace clang -- cgit v1.2.3