2001-01-04 20:45:49 +01:00
|
|
|
/*
|
|
|
|
* Symbol functions
|
|
|
|
*
|
|
|
|
* Copyright 2000 Jon Griffiths
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-01-04 20:45:49 +01:00
|
|
|
*/
|
2002-04-26 21:05:15 +02:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
2021-09-29 11:14:01 +02:00
|
|
|
#include "../tools.h"
|
2001-09-07 18:04:38 +02:00
|
|
|
#include "winedump.h"
|
2001-01-04 20:45:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* Items that are swapped in arguments after the symbol structure
|
|
|
|
* has been populated
|
|
|
|
*/
|
2006-11-26 09:04:56 +01:00
|
|
|
static const char * const swap_after[] =
|
2001-01-04 20:45:49 +01:00
|
|
|
{
|
|
|
|
"\r", " ", /* Remove whitespace, normalise pointers and brackets */
|
|
|
|
"\t", " ",
|
|
|
|
" ", " ",
|
|
|
|
" * ", " *",
|
|
|
|
"* *", "**",
|
|
|
|
"* ", "*",
|
|
|
|
" ,", ",",
|
|
|
|
"( ", "(",
|
|
|
|
" )", ")",
|
2008-01-16 02:28:45 +01:00
|
|
|
"wchar_t", "WCHAR", /* Help with Unicode compiles */
|
2001-01-04 20:45:49 +01:00
|
|
|
"wctype_t", "WCHAR",
|
|
|
|
"wint_t", "WCHAR",
|
|
|
|
NULL, NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Items containing these substrings are assumed to be wide character
|
2005-03-02 14:53:50 +01:00
|
|
|
* strings, unless they contain more that one '*'. A preceding 'LP'
|
2001-01-04 20:45:49 +01:00
|
|
|
* counts as a '*', so 'LPWCSTR *' is a pointer, not a string
|
|
|
|
*/
|
2006-11-26 09:04:56 +01:00
|
|
|
static const char * const wide_strings[] =
|
2001-01-04 20:45:49 +01:00
|
|
|
{
|
|
|
|
"WSTR", "WCSTR", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Items containing these substrings are assumed to be wide characters,
|
2005-03-02 14:53:50 +01:00
|
|
|
* unless they contain one '*'. A preceding 'LP' counts as a '*',
|
2001-01-04 20:45:49 +01:00
|
|
|
* so 'WCHAR *' is string, while 'LPWCHAR *' is a pointer
|
|
|
|
*/
|
2006-11-26 09:04:56 +01:00
|
|
|
static const char * const wide_chars[] =
|
2001-01-04 20:45:49 +01:00
|
|
|
{
|
|
|
|
"WCHAR", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Items containing these substrings are assumed to be ASCII character
|
|
|
|
* strings, as above
|
|
|
|
*/
|
2006-11-26 09:04:56 +01:00
|
|
|
static const char * const ascii_strings[] =
|
2001-01-04 20:45:49 +01:00
|
|
|
{
|
|
|
|
"STR", "CSTR", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Items containing these substrings are assumed to be ASCII characters,
|
|
|
|
* as above
|
|
|
|
*/
|
2006-11-26 09:04:56 +01:00
|
|
|
static const char * const ascii_chars[] =
|
2001-01-04 20:45:49 +01:00
|
|
|
{
|
|
|
|
"CHAR", "char", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Any type other than the following will produce a FIXME warning with -v
|
|
|
|
* when mapped to a long, to allow fixups
|
|
|
|
*/
|
2006-11-26 09:04:56 +01:00
|
|
|
static const char * const known_longs[] =
|
2001-01-04 20:45:49 +01:00
|
|
|
{
|
|
|
|
"char", "CHAR", "float", "int", "INT", "short", "SHORT", "long", "LONG",
|
2001-02-16 20:06:05 +01:00
|
|
|
"WCHAR", "BOOL", "bool", "INT16", "WORD", "DWORD", NULL
|
2001-01-04 20:45:49 +01:00
|
|
|
};
|
|
|
|
|
2014-01-02 02:16:51 +01:00
|
|
|
void symbol_init(parsed_symbol* sym, const char* name)
|
2001-09-17 22:26:27 +02:00
|
|
|
{
|
|
|
|
memset(sym, 0, sizeof(parsed_symbol));
|
2021-09-29 11:14:01 +02:00
|
|
|
sym->symbol = xstrdup(name);
|
2001-09-17 22:26:27 +02:00
|
|
|
}
|
2001-01-04 20:45:49 +01:00
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* symbol_clear
|
|
|
|
*
|
|
|
|
* Free the memory used by a symbol and initialise it
|
|
|
|
*/
|
|
|
|
void symbol_clear(parsed_symbol *sym)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
assert (sym);
|
|
|
|
assert (sym->symbol);
|
|
|
|
|
|
|
|
free (sym->symbol);
|
2006-10-09 23:34:53 +02:00
|
|
|
free (sym->return_text);
|
|
|
|
free (sym->function_name);
|
2001-01-04 20:45:49 +01:00
|
|
|
|
|
|
|
for (i = sym->argc - 1; i >= 0; i--)
|
|
|
|
{
|
2006-10-09 23:34:53 +02:00
|
|
|
free (sym->arg_text [i]);
|
|
|
|
free (sym->arg_name [i]);
|
2001-01-04 20:45:49 +01:00
|
|
|
}
|
|
|
|
memset (sym, 0, sizeof (parsed_symbol));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* symbol_is_valid_c
|
|
|
|
*
|
|
|
|
* Check if a symbol is a valid C identifier
|
|
|
|
*/
|
2013-12-24 10:24:27 +01:00
|
|
|
BOOL symbol_is_valid_c(const parsed_symbol *sym)
|
2001-01-04 20:45:49 +01:00
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
assert (sym);
|
|
|
|
assert (sym->symbol);
|
|
|
|
|
|
|
|
name = sym->symbol;
|
|
|
|
|
|
|
|
while (*name)
|
|
|
|
{
|
|
|
|
if (!isalnum (*name) && *name != '_')
|
2013-12-24 10:24:27 +01:00
|
|
|
return FALSE;
|
2001-01-04 20:45:49 +01:00
|
|
|
name++;
|
|
|
|
}
|
2013-12-24 10:24:27 +01:00
|
|
|
return TRUE;
|
2001-01-04 20:45:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
2001-02-16 20:06:05 +01:00
|
|
|
* symbol_get_call_convention
|
2001-01-04 20:45:49 +01:00
|
|
|
*
|
2001-02-16 20:06:05 +01:00
|
|
|
* Return the calling convention of a symbol
|
2001-01-04 20:45:49 +01:00
|
|
|
*/
|
2001-02-16 20:06:05 +01:00
|
|
|
const char *symbol_get_call_convention(const parsed_symbol *sym)
|
2001-01-04 20:45:49 +01:00
|
|
|
{
|
2001-02-16 20:06:05 +01:00
|
|
|
int call = sym->flags ? sym->flags : CALLING_CONVENTION;
|
|
|
|
|
2001-01-04 20:45:49 +01:00
|
|
|
assert (sym);
|
|
|
|
assert (sym->symbol);
|
|
|
|
|
2001-02-16 20:06:05 +01:00
|
|
|
if (call & SYM_CDECL)
|
|
|
|
return "cdecl";
|
|
|
|
return "stdcall";
|
2001-01-04 20:45:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* symbol_get_spec_type
|
|
|
|
*
|
2008-01-16 02:28:45 +01:00
|
|
|
* Get the .spec file text for a symbol's argument
|
2001-01-04 20:45:49 +01:00
|
|
|
*/
|
|
|
|
const char *symbol_get_spec_type (const parsed_symbol *sym, size_t arg)
|
|
|
|
{
|
|
|
|
assert (arg < sym->argc);
|
|
|
|
switch (sym->arg_type [arg])
|
|
|
|
{
|
|
|
|
case ARG_STRING: return "str";
|
|
|
|
case ARG_WIDE_STRING: return "wstr";
|
|
|
|
case ARG_POINTER: return "ptr";
|
|
|
|
case ARG_DOUBLE: return "double";
|
|
|
|
case ARG_STRUCT:
|
|
|
|
case ARG_FLOAT:
|
|
|
|
case ARG_LONG: return "long";
|
|
|
|
}
|
|
|
|
assert (0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* symbol_get_type
|
|
|
|
*
|
|
|
|
* Get the ARG_ constant for a type string
|
|
|
|
*/
|
|
|
|
int symbol_get_type (const char *string)
|
|
|
|
{
|
|
|
|
const char *iter = string;
|
2006-11-26 09:04:56 +01:00
|
|
|
const char * const *tab;
|
2001-01-04 20:45:49 +01:00
|
|
|
int ptrs = 0;
|
|
|
|
|
2001-02-16 20:06:05 +01:00
|
|
|
while (*iter && isspace(*iter))
|
|
|
|
iter++;
|
|
|
|
if (*iter == 'P' || *iter == 'H')
|
|
|
|
ptrs++; /* Win32 type pointer */
|
|
|
|
|
|
|
|
iter = string;
|
2001-01-04 20:45:49 +01:00
|
|
|
while (*iter)
|
|
|
|
{
|
|
|
|
if (*iter == '*' || (*iter == 'L' && iter[1] == 'P')
|
|
|
|
|| (*iter == '[' && iter[1] == ']'))
|
|
|
|
ptrs++;
|
|
|
|
if (ptrs > 1)
|
|
|
|
return ARG_POINTER;
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 0 or 1 pointer */
|
|
|
|
tab = wide_strings;
|
|
|
|
while (*tab++)
|
|
|
|
if (strstr (string, tab[-1]))
|
|
|
|
{
|
2001-02-16 20:06:05 +01:00
|
|
|
if (ptrs < 2) return ARG_WIDE_STRING;
|
|
|
|
else return ARG_POINTER;
|
2001-01-04 20:45:49 +01:00
|
|
|
}
|
|
|
|
tab = wide_chars;
|
|
|
|
while (*tab++)
|
|
|
|
if (strstr (string, tab[-1]))
|
|
|
|
{
|
|
|
|
if (!ptrs) return ARG_LONG;
|
|
|
|
else return ARG_WIDE_STRING;
|
|
|
|
}
|
|
|
|
tab = ascii_strings;
|
|
|
|
while (*tab++)
|
|
|
|
if (strstr (string, tab[-1]))
|
|
|
|
{
|
2001-02-16 20:06:05 +01:00
|
|
|
if (ptrs < 2) return ARG_STRING;
|
|
|
|
else return ARG_POINTER;
|
2001-01-04 20:45:49 +01:00
|
|
|
}
|
|
|
|
tab = ascii_chars;
|
|
|
|
while (*tab++)
|
|
|
|
if (strstr (string, tab[-1]))
|
|
|
|
{
|
|
|
|
if (!ptrs) return ARG_LONG;
|
|
|
|
else {
|
|
|
|
if (!strstr (string, "unsigned")) /* unsigned char * => ptr */
|
|
|
|
return ARG_STRING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ptrs)
|
|
|
|
return ARG_POINTER; /* Pointer to some other type */
|
|
|
|
|
|
|
|
/* No pointers */
|
|
|
|
if (strstr (string, "double"))
|
|
|
|
return ARG_DOUBLE;
|
|
|
|
|
2005-01-03 21:16:23 +01:00
|
|
|
if (strstr (string, "float") || strstr (string, "FLOAT"))
|
2003-07-22 02:56:31 +02:00
|
|
|
return ARG_FLOAT;
|
|
|
|
|
2001-02-16 20:06:05 +01:00
|
|
|
if (strstr (string, "void") || strstr (string, "VOID"))
|
2001-01-04 20:45:49 +01:00
|
|
|
return ARG_VOID;
|
|
|
|
|
|
|
|
if (strstr (string, "struct") || strstr (string, "union"))
|
|
|
|
return ARG_STRUCT; /* Struct by value, ugh */
|
|
|
|
|
|
|
|
if (VERBOSE)
|
|
|
|
{
|
2013-12-03 23:36:09 +01:00
|
|
|
BOOL known = FALSE;
|
2001-01-04 20:45:49 +01:00
|
|
|
|
|
|
|
tab = known_longs;
|
|
|
|
while (*tab++)
|
|
|
|
if (strstr (string, tab[-1]))
|
|
|
|
{
|
2013-12-03 23:36:09 +01:00
|
|
|
known = TRUE;
|
2001-01-04 20:45:49 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Unknown types passed by value can be 'grep'ed out for fixup later */
|
|
|
|
if (!known)
|
|
|
|
printf ("/* FIXME: By value type: Assumed 'int' */ typedef int %s;\n",
|
|
|
|
string);
|
|
|
|
}
|
|
|
|
return ARG_LONG;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************
|
|
|
|
* symbol_clean_string
|
|
|
|
*
|
|
|
|
* Make a type string more Wine-friendly. Logically const :-)
|
|
|
|
*/
|
2010-04-02 18:44:37 +02:00
|
|
|
void symbol_clean_string (char *str)
|
2001-01-04 20:45:49 +01:00
|
|
|
{
|
2006-11-26 09:04:56 +01:00
|
|
|
const char * const *tab = swap_after;
|
2001-01-04 20:45:49 +01:00
|
|
|
|
|
|
|
#define SWAP(i, p, x, y) do { i = p; while ((i = str_replace (i, x, y))); } while(0)
|
|
|
|
|
|
|
|
while (tab [0])
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
SWAP (p, str, tab [0], tab [1]);
|
|
|
|
tab += 2;
|
|
|
|
}
|
|
|
|
if (str [strlen (str) - 1] == ' ')
|
|
|
|
str [strlen (str) - 1] = '\0'; /* no trailing space */
|
|
|
|
|
|
|
|
if (*str == ' ')
|
|
|
|
memmove (str, str + 1, strlen (str)); /* No leading spaces */
|
|
|
|
}
|