Click here to Skip to main content
15,886,823 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.9K   1.3K   19  
An article on the usage and design of another Enum Viewer
// CPPScopeTemplate.cpp: Implementation of special template-parameter scope class

#ifdef _MSC_VER
   // Disable some warnings that appear commonly in Rogue Wave STL
   #pragma warning (disable:4786)    // long debug names
   #pragma warning (disable:4146)    // unary minus operator applied to unsigned type
   #pragma warning (disable:4018)    // '>' : signed/unsigned mismatch
#endif

#include "CPPScopeTemplate.h"
#include "CPPTypeBuiltin.h"
#include "CPPTypeTemplatePlaceholder.h"
#include "CPPDecl.h"

////////////////////////////////////////////////////////////////////
// Note:  The whole idea of a special template scope is a hack.
// But a hack that generalizes nicely to cover all sorts of problems
// when parsing template declarations.
// 
// It it there to satisfy certain predicates in the grammar
// about the existence of various declarations and subscopes
// in the template parameter scope.  This hack is designed 
// to always satisfy the following queries.
//
// Given a templated declaration like
//   template <class T> class A {...};
// Then the following assertions should all be true in the declaration of A,
// for any TT, TTT, and X
//    T has a subscope TT
//    T::TT has subscope TTT.  This can be continued to an arbitrary depth.
//    T::X (T::TT::X, etc.) exists but is not a type
//    T::X (T::TT::X, etc.) is not templated
////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////
// CPPScopeTemplate statics.  These are returned as the result of
// querying the template placeholder scope, and are mostly meaningless
// except that they in turn are template placeholders.
////////////////////////////////////////////////////////////////////

CPPDeclRefI CPPScopeTemplate::theObjectDecl = new CPPDeclObject(
   "templateDecl",
   CPPConst::asPUBLIC,
   new CPPTypeTemplatePlaceholder(0,0),
   CPPConst::scNONE,
   CPPConst::dmNONE
);

CPPDeclRefI CPPScopeTemplate::theTypeDecl = new CPPDeclObject(
   "templateDecl",
   CPPConst::asPUBLIC,
   new CPPTypeTemplatePlaceholder(0,0),
   CPPConst::scNONE,
   CPPConst::dmNONE
);


////////////////////////////////////////////////////////////////////
// CPPScopeTemplate: ctor.
//
// Inputs:
//    const JLStr&   name              The scope name
////////////////////////////////////////////////////////////////////
CPPScopeTemplate::CPPScopeTemplate() : 
   CPPScope(ScopeTemplate, "templatePlaceholder")
   #ifndef NDEBUG
      ,magicTemplate(CPPScopeMagicTemplate)
   #endif
{
}

////////////////////////////////////////////////////////////////////
// CPPScopeTemplate: dtor
////////////////////////////////////////////////////////////////////
//virtual 
CPPScopeTemplate::~CPPScopeTemplate()
{
   #ifndef NDEBUG
      magicTemplate = 0;
   #endif
}

////////////////////////////////////////////////////////////////////
// GetCurrentAccess: Return the current access of the template
// placeholder scope.  This is irrelevant.
//
// Inputs: none
// Return: CPPConst::asPUBLIC
////////////////////////////////////////////////////////////////////
//virtual 
CPPConst::AccessSpecifier 
CPPScopeTemplate::GetCurrentAccess() const
{
   return CPPConst::asPUBLIC;
}

////////////////////////////////////////////////////////////////////
// SetCurrentAccess: Change the current access of the template
// placeholder scope.  This is invalid;
//
// Inputs: 
//    CPPConst::AccessSpecifier     unused
// Return: none
////////////////////////////////////////////////////////////////////
//virtual 
void 
CPPScopeTemplate::SetCurrentAccess(
   CPPConst::AccessSpecifier
)
{
   assert(0);
}

////////////////////////////////////////////////////////////////////
// FindDeclByName.  Find a declaration in the template 
// placeholder scope.  This always returns a static object decl.
//
// Inputs:
//    const JLStr&      unused
//    DeclIterator&     unused
////////////////////////////////////////////////////////////////////
//virtual 
CPPDeclRefI 
CPPScopeTemplate::FindDeclByName(
   const JLStr&, 
   DeclIterator& 
) const
{
   assertValid();
   return theObjectDecl;
}

////////////////////////////////////////////////////////////////////
// FindTypeDeclByName.  Find a type declaration in the template 
// placeholder scope.  This always returns a static type decl.
//
// Inputs:
//    const JLStr&      unused
////////////////////////////////////////////////////////////////////
//virtual 
CPPDeclRefI 
CPPScopeTemplate::FindTypeDeclByName(
   const JLStr&
) const
{
   assertValid(); 
   return theTypeDecl;
}

////////////////////////////////////////////////////////////////////
// FindClassDeclByName.  Find a class declaration in the template 
// placeholder scope.  This always returns a static type decl.
//
// Inputs:
//    const JLStr&      unused
////////////////////////////////////////////////////////////////////
//virtual 
CPPDeclRefI 
CPPScopeTemplate::FindClassDeclByName(
   const JLStr&
) const
{
   assertValid(); 
   return theTypeDecl;
}

////////////////////////////////////////////////////////////////////
// FindTemplateDeclByName.  Find a template declaration in the template 
// placeholder scope.  This always returns a static object decl.
// TODO: This is probably not quite right...
//
// Inputs:
//    const JLStr&      unused
////////////////////////////////////////////////////////////////////
//virtual 
CPPDeclRefI 
CPPScopeTemplate::FindTemplatedDeclByName(
   const JLStr&
) const
{
   assertValid(); 
   return theObjectDecl;
}

////////////////////////////////////////////////////////////////////
// FindScope.  Find a subscope in the template.  This always returns
// this scope.
//
// Inputs:
//    const JLStr&      unused
////////////////////////////////////////////////////////////////////
//virtual 
CPPScopeRefI 
CPPScopeTemplate::FindScope(
   const JLStr&
)
{
   assertValid(); 
   return this;
}

////////////////////////////////////////////////////////////////////
// CPPScopeTemplate::FormatPrefix:  Return a JLStr representing a 
//    the prefix string for this scope
//
// Inputs:
//    bool    formatGlobal   true to preprend "::" to the scope
// Outputs: none
// Return:
//     JLStr     A unique name
////////////////////////////////////////////////////////////////////
JLStr 
CPPScopeTemplate::FormatPrefix(
   bool formatGlobal
) const
{
   assertValid();
   JLStr prefixStr;

   if (GetParentScope().get() != 0)
   {
      prefixStr = GetParentScope()->FormatPrefix(formatGlobal);
   }

   return prefixStr + GetName() + "::";
}

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