// CPPSymTableSpecializeFunction.cpp: Templated function specialization
#include "CPPSymTable.h"
#include "TemplateParameterList.h"
#include "TemplateArgumentList.h"
////////////////////////////////////////////////////////////////////
// LookupFunctionSpecialization: Given the name of a class template
// and a list of template arguments, create a specialization of the
// class if one does not exist.
//
// Inputs:
// const JLStr& functionName Name of the function template
// CPPScopeRefI containingScope
// The scope in which the class
// template is declared
// CPPScopeRefI containingScope
// The scope in which the function
// template is declared
// TemplateArgumentListRef argList List of actual template
// arguments (types or values)
// const ANTLRTokenPtr& errTok A token to use for error reporting
// Outputs:
// JLStr& specializationNameReturn
// If successful, contains the
// name of the function specialization.
// CPPTypeRefI& specializationTypeReturn
// If successful, points to the type
// entry for the function specialization.
// Return:
// bool true on success, false if something was wrong with
// the specialization, in which case an error has
// already been reported.
//
// Notes: A function specialization name contains the types of
// the arguments, for example:
// template declaration invocation name
// -------------------- ---------- ----
// template <class T> foo(T) foo(int) foo<int>
// template <class T> foo(T) foo(char***) foo<char***>
////////////////////////////////////////////////////////////////////
// virtual
bool
CPPSymTable::LookupFunctionSpecialization(
const JLStr& functionName,
CPPScopeRefI containingScope,
TemplateArgumentListRefI argList,
const ANTLRTokenPtr& errTok,
JLStr& specializationNameReturn,
CPPTypeRefI& specializationTypeReturn
)
{
// NYI
return false;
}
///////////////////////////////////////////////////////////////////
// FormatFunctionSpecializationName: Given the name of a templated
// function, a list of template parameters, and a list of
// specialization arguments (which may be derived from the function arguments),
// sythesize a name for the function that is unique compared with
// other possible specializations.
//
// This constructs a name composed of the raw name combined
// with the formatted type names and values of the arguments, with
// the exception that the template placeholder types are formatted to
// indicate their position in the template parameter list. Some examples:
//
// name template-parm-list arguments result
// ==== ================== ============== =====================
// f <class M, class N> (M, N*) f<$0,$1><$0,$1*>
// f <class M> (M,M*,int) f<$0><$0,$0*,int>
// f <> (int,char**) f<><int,char**>
//
// For nested template declarations, the index variables have an additional
// number indicating their template nesting level in addition to parameter
// position. For example:
// template <class T1> class A {
// template <class T2> void f(T*);
// };
// Yields A<$0>::f<$0_1><$0_1*> for the name of the template method
//
// Inputs:
// const JLStr& name
// The name of the declaration
// TemplateParameterListRefI templateParameterList
// List of formal template parameters
// TemplateArgumentListRefI specializationArgList
// List of template specialization
// arguments. May be empty
///////////////////////////////////////////////////////////////////
JLStr
CPPSymTable::FormatFunctionSpecializationName(
const JLStr& name,
TemplateParameterListRefI templateParameterList,
TemplateArgumentListRefI specializationArgList
)
{
JLStr specializedName = name;
// Format the formal parameters
specializedName += "<";
for (
TemplateParameterList::iterator parmIter = templateParameterList->begin();
parmIter != templateParameterList->end();
parmIter++
)
{
if (parmIter != templateParameterList->begin())
{
specializedName += ",";
}
specializedName += (*parmIter)->Format();
}
specializedName += ">";
// Format the specialization arguments
specializedName += "<";
for (
TemplateArgumentList::iterator argIter = specializationArgList->begin();
argIter != specializationArgList->end();
argIter++
)
{
if (argIter != specializationArgList->begin())
{
specializedName += ",";
}
specializedName += (*argIter)->Format();
}
specializedName += ">";
return specializedName;
}