Click here to Skip to main content
15,881,669 members
Articles / Desktop Programming / MFC

Another Enum Viewer

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
22 Oct 20015 min read 82.8K   1.3K   19  
An article on the usage and design of another Enum Viewer
// 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;

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions