⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cplusdem.cpp

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 CPP
字号:
/* cplusDem.cpp - C++ link name demangler *//* Copyright 1993 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02b,12jun98,sn   merged in fix to spr 8947 which moves the work of                 the demangler into cplus-dem.c.		 fixed (disastrous) typo in cplusDemanglerInit		 moved code that removes compiler prepended leading underscores                 to cplusDemStub.cpp so that we can use it even if the		 C++ runtime isn't included.		 made _cplusDemangle distinguish between modes TERSE and                 COMPLETE as required by the docs for cplusDemanglerSet.02a,10apr98,sn   moved a stub definition of cplusDemangle into cplusDemStub.cpp                 but retained the body under the new name _cplusDemangle.		 added cplusDemanglerInit.01d,03jun93,srh  doc cleanup01c,23apr93,srh  implemented new force-link/initialization scheme01b,22apr92,srh  Added support for T<n> and N<n><n> constructs.		 The demangler should be cleaned up and rewritten, using		 the T and N support generally, instead of redundantly.01a,31jan93,srh  written.*//*DESCRIPTIONThis module provides an interface to a C++ name demangler. It contains no user-callable routines.INTERNALThe real work of the demangler is done in cplus-dem.c. In thisfile we provide extra functionality required by the target showroutines such as lkup.NOMANUAL*//* includes */#include "vxWorks.h"#include "ctype.h"#include "stdlib.h"#include "stdio.h"#include "string.h"#include "cplusLib.h"#include "demangle.h"/* defines */#define MAX_OVERLOAD_SYMS 50/* typedefs */char __cplusDem_o;/* locals */LOCAL char * overloadMatches [MAX_OVERLOAD_SYMS];LOCAL int overloadMatchCount;LOCAL BOOL findMatches    (    char *name,    int,    SYM_TYPE,    int string    );LOCAL const char * startsWith    (    const char *	string,    const char *	isubstr    );/********************************************************************************* _cplusDemangle - demangle symbol** This routine takes a C or C++ symbol and attempts to demangle it* in the manner specified by cplusDemanglerMode. It does not* attempt to remove compiler prepended underscores. The caller* must take care of this.** See documentation for cplusDemanglerSet for an explanation* of the demangler modes.** RETURNS:* Destination string if demangling is successful, otherwise source string.** NOMANUAL*/char * _cplusDemangle    (    char * source,                // mangled name    char	* dest,                  // buffer for demangled copy    int n                         // maximum length of copy    )    {    if (cplusDemanglerMode == OFF)	{	return source;	}    else	{	char *buf;        int options;    // see demangle.h for a list of cplus_demangle options	switch (cplusDemanglerMode)	  {	  case TERSE : options = 0 ; break;	  case COMPLETE : options = DMGL_PARAMS | DMGL_ANSI;	  }	buf = cplus_demangle (			     source,			     options			     );	if (buf !=0)	    {	    strncpy (dest, buf, n);	    free (buf);	    return dest;	    }	else	    {	    return source;	    }	  	}    }/********************************************************************************* cplusDemanglerInit -  initialize the demangler** RETURNS: N/A* ** NOMANUAL*/void cplusDemanglerInit (){    cplusDemangleFunc = _cplusDemangle;}/********************************************************************************* askUser - ask user to choose among overloaded name alternatives** This routine is used by cplusMatchMangled when a name is overloaded.** RETURNS:* index into overloadMatches, or negative if no symbol is selected** NOMANUAL*/LOCAL int askUser    (    char *name    )    {    CPLUS_DEMANGLER_MODES	  savedMode;    char			  demangled [MAX_SYS_SYM_LEN + 1];    char			  userInput [10];    const char 			* nameToPrint;    int				  choice;    int				  i;    savedMode		= cplusDemanglerMode;    cplusDemanglerMode	= COMPLETE;    do	{	printf ("\"%s\" is overloaded - Please select:\n", name);	for (i = 0; i < overloadMatchCount; i++)	    {	    nameToPrint = cplusDemangle (overloadMatches [i], demangled,					 MAX_SYS_SYM_LEN + 1);	    printf ("  %3d: %s\n", i+1, nameToPrint);	    }	printf ("Enter <number> to select, anything else to stop: ");	fgets (userInput, 10, stdin);	choice = atoi (userInput) - 1;	}    while (choice >= overloadMatchCount);    cplusDemanglerMode = savedMode;    return choice;    }/********************************************************************************* cplusMatchMangled - match string against mangled symbol table entries** This function seeks a partial match between the given <string> and* symbols in the given <symTab>. If <string> matches one symbol, that* symbol's value and type are copied to <pValue> and <pType>. If <string>* matches multiple symbols, the shell user is prompted to disambiguate* her choice among the various alternatives.** RETURNS: TRUE if a unique match is resolved, otherwise FALSE.** NOMANUAL*/extern "C" BOOL cplusMatchMangled    (    SYMTAB_ID		symTab,			/* symbol table to search */    char		*string,		/* goal string */    SYM_TYPE		*pType,			/* type of matched symbol */    int			*pValue			/* value of matched symbol */    )    {    int userChoice;        overloadMatchCount = 0;    symEach (symTab, (FUNCPTR) findMatches, (int) string);    switch (overloadMatchCount)	{    case 0:	return FALSE;    case 1:	return (symFindByName (symTab, overloadMatches[0],			       (char **) pValue, pType)		== OK);    default:	userChoice = askUser (string);	if (userChoice >= 0)	    {	    return (symFindByName (symTab, overloadMatches [userChoice],				   (char **)pValue, pType)		    == OK);	    }	else	    {	    return FALSE;	    }	}    }/********************************************************************************* findMatches - find (possibly overloaded) symbols that match goal string** This function is used by cplusMatchMangled. A match occurs when* <goalString> is an initial substring of <name> and the occurrence* of <goalString> is followed in <name> by "__", which is assumed* to be followed by the function's encoded signature.** RETURNS: TRUE** NOMANUAL*/LOCAL BOOL findMatches    (    char *name,    int,    SYM_TYPE,    int string    )    {    const char * goalString = (const char *) string;    const char *pMatch;    if ((pMatch = startsWith (name + 1, goalString)) != 0	&&	(startsWith (pMatch + 1, "__") != 0))	    {	    if (overloadMatchCount < MAX_OVERLOAD_SYMS)		{		overloadMatches [overloadMatchCount++] = name;		}            }    /* Check for symbol does not start with underscore */    else if ((pMatch = startsWith (name, goalString)) != 0	     && 	     (startsWith (pMatch + 1, "__") != 0))	     {	     if (overloadMatchCount < MAX_OVERLOAD_SYMS)		{		overloadMatches [overloadMatchCount++] = name;		}	     }    return TRUE;    }/********************************************************************************* startsWith - determine if <string> starts with <isubstr>** RETURNS:* Pointer to final non-EOS character of <isubstr> where it occurs in <string>,* if <string> in fact starts with <isubstr>, otherwise 0.** NOMANUAL*/LOCAL const char * startsWith    (    const char *	string,    const char *	isubstr    )    {    if (*isubstr == EOS || *string == EOS)	{	return 0;	}    for ( ; (*string == *isubstr); string++, isubstr++)	{	if (*isubstr == EOS)	    {	    return string - 1;	    }	}    if (*isubstr == EOS)	{	return string - 1;	}    return 0;    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -