📄 undname.cpp
字号:
case '?':
if ( gName[1] == '_' && gName[2] == '?' ) {
//
// Anonymous namespace name (new style)
//
gName++;
scope = getOperatorName () + scope;
// There should be a zname termination @...
if ( *gName == '@' ) {
gName++;
}
}
else if ( !doNameOnly() )
scope = '`' + getDecoratedName () + '\'' + scope;
else
getDecoratedName(); // Skip lexical scope info
break;
case '$':
// It's a template name, which is a kind of zname; back up
// and handle like a zname.
gName--;
scope = getZName () + scope;
break;
case '%':
//
// It an anonymous namespace (old-style);
// skip the (unreadable) name and instead insert
// an appropriate string
//
while ( *gName != '@' ) {
gName++;
}
gName++;
scope = "`anonymous namespace'" + scope;
break;
case 'I':
//
// This is the interface whose method the class is
// implementing
//
gName++;
scope = getZName () + ']' + scope;
fNeedBracket = true;
break;
default:
if ( !doNameOnly() )
scope = getLexicalFrame () + scope;
else
getLexicalFrame(); // Skip lexical scope info
break;
} // End of SWITCH
else
scope = getZName () + scope;
} // End of WHILE
// Catch error conditions
switch ( *gName )
{
case 0:
if ( scope.isEmpty() )
scope = DN_truncated;
else
scope = DName ( DN_truncated ) + "::" + scope;
break;
case '@': // '@' expected to end the scope list
break;
default:
scope = DN_invalid;
break;
} // End of SWITCH
// Return the composed scope
return scope;
} // End of "UnDecorator" FUNCTION "getScope"
DName __near UnDecorator::getSignedDimension ( void )
{
if ( !*gName )
return DN_truncated;
elif ( *gName == '?' ) {
gName++; // skip the '?'
return '-' + getDimension();
}
else
return getDimension();
} // End of "Undecorator" FUNCTION "getSignedDimension"
DName __near UnDecorator::getDimension ( void )
{
if ( !*gName )
return DN_truncated;
elif (( *gName >= '0' ) && ( *gName <= '9' ))
return DName ((unsigned long)( *gName++ - '0' + 1 ));
else
{
unsigned long dim = 0L;
// Don't bother detecting overflow, it's not worth it
while ( *gName != '@' )
{
if ( !*gName )
return DN_truncated;
elif (( *gName >= 'A' ) && ( *gName <= 'P' ))
dim = ( dim << 4 ) + ( *gName - 'A' );
else
return DN_invalid;
gName++;
} // End of WHILE
// Ensure integrity, and return
if ( *gName++ != '@' )
return DN_invalid; // Should never get here
return dim;
} // End of ELIF else
} // End of "UnDecorator" FUNCTION "getDimension"
int __near UnDecorator::getNumberOfDimensions ( void )
{
if ( !*gName )
return 0;
elif (( *gName >= '0' ) && ( *gName <= '9' ))
return (( *gName++ - '0' ) + 1 );
else
{
int dim = 0;
// Don't bother detecting overflow, it's not worth it
while ( *gName != '@' )
{
if ( !*gName )
return 0;
elif (( *gName >= 'A' ) && ( *gName <= 'P' ))
dim = ( dim << 4 ) + ( *gName - 'A' );
else
return -1;
gName++;
} // End of WHILE
// Ensure integrity, and return
if ( *gName++ != '@' )
return -1; // Should never get here
return dim;
} // End of ELIF else
} // End of "UnDecorator" FUNCTION "getNumberOfDimensions"
DName __near UnDecorator::getTemplateName ( void )
{
//
// First make sure we're really looking at a template name
//
if ( gName[0] != '?' || gName[1] != '$' )
return DN_invalid;
gName += 2; // Skip the marker characters
//
// Stack the replicators, since template names are their own replicator scope:
//
Replicator * pSaveArgList = pArgList;
Replicator * pSaveZNameList = pZNameList;
Replicator * pSaveTemplateArgList = pTemplateArgList;
Replicator localArgList, localZNameList, localTemplateArgList;
pArgList = &localArgList;
pZNameList = &localZNameList;
pTemplateArgList = &localTemplateArgList;
//
// Crack the template name:
//
DName templateName = getZName ();
if ( !templateName.isEmpty ())
{
templateName += '<' + getTemplateArgumentList ();
if ( templateName.getLastChar () == '>' )
templateName += ' ';
templateName += '>';
}
//
// Restore the previous replicators:
//
pArgList = pSaveArgList;
pZNameList = pSaveZNameList;
pTemplateArgList = pSaveTemplateArgList;
// Return the completed 'template-name'
return templateName;
} // End of "UnDecorator" FUNCTION "getTemplateName"
DName __near UnDecorator::getTemplateArgumentList ( void )
{
int first = TRUE;
DName aList;
while (( aList.status () == DN_valid ) && *gName && ( *gName != AT_endoflist ))
{
// Insert the argument list separator if not the first argument
if ( first )
first = FALSE;
else
aList += ',';
// Get the individual argument type
int argIndex = *gName - '0';
// Handle 'template-argument-replicators', otherwise a new argument type
if (( argIndex >= 0 ) && ( argIndex <= 9 ))
{
gName++; // Skip past the replicator
// Append to the argument list
aList += ( *pTemplateArgList )[ argIndex ];
} // End of IF then
else
{
pcchar_t oldGName = gName;
DName arg;
//
// Extract the 'argument' type
//
if ( *gName == DT_void ) {
gName++;
arg = "void";
}
elif ( (*gName == '$') && (gName[1] != '$')) {
gName++;
arg = getTemplateConstant();
}
elif ( *gName == '?' ) {
//
// This is a template-parameter, i.e. we have a "specialization" of
// X<T>. so get the template-parameter-index and use a "generic" name
// for this parameter
//
DName dimension = getSignedDimension();
if ( haveTemplateParameters()) {
char buffer[16];
dimension.getString( buffer, 16 );
char *str = (*m_pGetParameter)(atol(buffer));
if ( str != NULL ) {
arg = str;
}
else {
arg = "`template-parameter" + dimension + "'";
}
}
else {
arg = "`template-parameter" + dimension + "'";
}
}
else {
arg = getPrimaryDataType ( DName() );
}
// Add it to the current list of 'template-argument's, if it is bigger than a one byte encoding
if ((( gName - oldGName ) > 1 ) && !pTemplateArgList->isFull ())
*pTemplateArgList += arg;
// Append to the argument list
aList += arg;
} // End of IF else
} // End of WHILE
// Return the completed template argument list
return aList;
} // End of "UnDecorator" FUNCTION "getTemplateArgumentList"
DName __near UnDecorator::getTemplateConstant(void)
{
//
// template-constant ::=
// '0' <template-integral-constant>
// '1' <template-address-constant>
// '2' <template-floating-point-constant>
//
switch ( *gName++ )
{
//
// template-integral-constant ::=
// <signed-dimension>
//
case TC_integral:
return getSignedDimension ();
//
// template-address-constant ::=
// '@' // Null pointer
// <decorated-name>
//
case TC_address:
if ( *gName == TC_nullptr )
{
gName++;
return "NULL";
}
else
return DName("&") + getDecoratedName ();
case TC_name:
return getDecoratedName ();
//
// template-floating-point-constant ::=
// <normalized-mantissa><exponent>
//
case TC_fp:
{
DName mantissa ( getSignedDimension () );
DName exponent ( getSignedDimension () );
if ( mantissa.isValid() && exponent.isValid() )
{
//
// Get string representation of mantissa
//
char buf[100]; // Way overkill for a compiler generated fp constant
if ( !mantissa.getString( &(buf[1]), 100 ) )
return DN_invalid;
//
// Insert decimal point
//
buf[0] = buf[1];
if ( buf[0] == '-' )
{
buf[1] = buf[2];
buf[2] = '.';
}
else
buf[1] = '.';
//
// String it all together
//
return DName( buf ) + 'e' + exponent;
} // End of IF then
else
return DN_truncated;
} // End of BLOCK case TC_fp
case TC_dummy:
{
//
// This is a template-parameter, i.e. we have a "specialization" of
// X<n>. so get the template-parameter-index and use a "generic" name
// for this parameter
//
DName dimension = getSignedDimension();
if ( haveTemplateParameters()) {
char buffer[16];
dimension.getString( buffer, 16 );
char *str = (*m_pGetParameter)(atol(buffer));
if ( str != NULL ) {
return str;
}
}
return "`template-parameter" + dimension + "'";
}
break;
case '\0':
--gName;
return DN_truncated;
default:
return DN_invalid;
} // End of SWITCH
} // End of "UnDecorator" FUNCTION "getTemplateConstant"
inline DName __near UnDecorator::composeDeclaration ( const DName & symbol )
{
DName declaration;
unsigned int typeCode = getTypeEncoding ();
int symIsUDC = symbol.isUDC ();
// Handle bad typeCode's, or truncation
if ( TE_isbadtype ( typeCode ))
return DN_invalid;
elif ( TE_istruncated ( typeCode ))
return ( DN_truncated + symbol );
// This is a very complex part. The type of the declaration must be
// determined, and the exact composition must be dictated by this type.
// Is it any type of a function ?
// However, for ease of decoding, treat the 'localdtor' thunk as data, since
// its decoration is a function of the variable to which it belongs and not
// a usual function type of decoration.
#if ( NO_COMPILER_NAMES )
if ( TE_isthunk ( typeCode ))
return DN_invalid;
if ( TE_isfunction ( typeCode ))
#else // } elif !NO_COMPILER_NAMES {
if ( TE_isfunction ( typeCode ) && !(( TE_isthunk ( typeCode ) && TE_islocaldtor ( typeCode )) ||
( TE_isthunk ( typeCode ) && ( TE_istemplatector ( typeCode ) || TE_istemplatedtor ( typeCode )))))
#endif // !NO_COMPILER_NAMES
{
// If it is based, then compose the 'based' prefix for the name
if ( TE_isbased ( typeCode ))
if ( doMSKeywords () && doAllocationModel ())
declaration = ' ' + getBasedType ();
else
declaration |= getBasedType (); // Just lose the 'based-type'
#if ( !NO_COMPILER_NAMES )
// Check for some of the specially composed 'thunk's
if ( TE_isthunk ( typeCode ) && TE_isvcall ( typeCode ))
{
declaration += symbol + '{' + getCallIndex () + ',';
declaration += getVCallThunkType () + "}' ";
if ( doMSKeywords () && doAllocationLanguage ())
declaration = ' ' + getCallingConvention () + ' ' + declaration; // What calling convention ?
else
declaration |= getCallingConvention (); // Just lose the 'calling-convention'
} // End of IF then
else
#endif // !NO_COMPILER_NAMES
{
DName vtorDisp;
DName adjustment;
DName thisType;
#if ( !NO_COMPILER_NAMES )
if ( TE_isthunk ( typeCode ))
{
if ( TE_isvtoradj ( typeCode ))
vtorDisp = getDisplacement ();
adjustment = getDisplacement ();
} // End of IF else
#endif // !NO_COMPILER_NAMES
// Get the 'this-type' for non-static function members
if ( TE_ismember ( typeCode ) && !TE_isstatic ( typeCode ))
if ( doThisTypes ())
thisType = getThisType ();
else
thisType |= getThisType ();
if ( doMSKeywords ())
{
// Attach the calling convention
if ( doAllocationLanguage ())
declaration = getCallingConvention () + declaration; // What calling convention ?
else
declaration |= getCallingConvention (); // Just lose the 'calling-convention'
// Any model specifiers ?
#if !VERS_32BIT
if ( doAllocationModel ())
if ( TE_isnear ( typeCode ))
declaration = UScore ( TOK_nearSp ) + declaration;
elif ( TE_isfar ( typeCode ))
declaration = UScore ( TOK_farSp ) + declaration;
#endif
} // End of IF
else
declaration |= getCallingConvention (); // Just lose the 'calling-convention'
// Now put them all together
if ( !symbol.isEmpty ())
if ( !declaration.isEmpty () && !doNameOnly() ) // And the symbol name
declaration += ' ' + symbol;
else
declaration = symbol;
// Compose the return type, catching the UDC case
DName * pDeclarator = 0;
DName returnType;
if ( symIsUDC ) // Is the symbol a UDC operator ?
{
declaration += " " + getReturnType ();
if ( doNameOnly() )
return declaration;
}
else
{
pDeclarator = gnew DName;
returnType = getReturnType ( pDeclarator );
} // End of IF else
#if ( !NO_COMPILER_NAMES )
// Add the displacements for virtual function thunks
if ( TE_isthunk ( typeCode ))
{
if ( TE_isvtoradj ( typeCode ))
declaration += "`vtordisp{" + vtorDisp + ',';
else
declaration += "`adjustor{";
declaration += adjustment + "}' ";
} // End of IF
#endif // !NO_COMPILER_NAMES
// Add the function argument prototype
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -