|
// CPPScope.cpp: Implementation of CPPScope base class.
#include "CPPScope.h"
////////////////////////////////////////////////////////////////////
// Statics
////////////////////////////////////////////////////////////////////
long CPPScope::uniqueIdx = 1;
////////////////////////////////////////////////////////////////////
// ctor
////////////////////////////////////////////////////////////////////
CPPScope::CPPScope(
Flavor flavor_,
const JLStr& name_
) :
flavor(flavor_),
name(name_),
parentScope(0)
#ifndef NDEBUG
, magic(CPPScopeMagic)
#endif
{
}
////////////////////////////////////////////////////////////////////
// dtor
////////////////////////////////////////////////////////////////////
CPPScope::~CPPScope()
{
assertValid();
#ifndef NDEBUG
magic = 0;
#endif
}
////////////////////////////////////////////////////////////////////
// Misc methods //
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// CPPScope::UniqueName: Return a JLStr representing a
// sub-scope or declaration name that is unique to this scope.
//
// Inputs: none
// Outputs: none
// Return:
// JLStr A unique name
////////////////////////////////////////////////////////////////////
// static
JLStr
CPPScope::UniqueName()
{
char buf[40];
sprintf(buf, "__unnamed%d", uniqueIdx++);
return buf;
}
////////////////////////////////////////////////////////////////////
// CPPScope::IsGeneratedName: Test a name to see if it was generated
// by UniqueName()
//
// Inputs:
// const JLStr& name The name to test
// Outputs: none
// Return:
// bool true if the name is computer-generated
////////////////////////////////////////////////////////////////////
// static
bool
CPPScope::IsGeneratedName(
const JLStr& name
)
{
return (strncmp(name.c_str(), "__unnamed", 9) == 0);
}
////////////////////////////////////////////////////////////////////
// CPPScope::ChangeParentScope: remove a scope from its current
// parent and make the entry in a different scope.
// The scope must currently have a parent
//
// Inputs:
// CPPScope* newParent The new parent scope
// Outputs: none
// Return: none
////////////////////////////////////////////////////////////////////
void
CPPScope::ChangeParentScope(
CPPScope* newParent
)
{
ChangeParentScope(newParent, GetName());
}
////////////////////////////////////////////////////////////////////
// CPPScope::ChangeParentScope: remove a scope from its current
// parent and make the entry in a different scope, possibly under
// a different name. The scope must currently have a parent
//
// Inputs:
// CPPScope* newParent The new parent scope
// const JLStr& newName The new scope name
// Outputs: none
// Return: none
////////////////////////////////////////////////////////////////////
void
CPPScope::ChangeParentScope(
CPPScope* newParent,
const JLStr& newName
)
{
assert(parentScope != 0);
// make sure that ref-counting doesn't delete this as we move it around
CPPScopeRefI tmpRef(this);
// Remove from existing parent
parentScope->RemoveScope(this);
parentScope = 0;
// Change the name
name = newName;
// Add to new parent
newParent->AddScope(this);
}
|
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.
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
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.