GDB (API)
|
00001 /* Interface to C preprocessor macro expansion for GDB. 00002 Copyright (C) 2002-2013 Free Software Foundation, Inc. 00003 Contributed by Red Hat, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 00021 #ifndef MACROEXP_H 00022 #define MACROEXP_H 00023 00024 /* A function for looking up preprocessor macro definitions. Return 00025 the preprocessor definition of NAME in scope according to BATON, or 00026 zero if NAME is not defined as a preprocessor macro. 00027 00028 The caller must not free or modify the definition returned. It is 00029 probably unwise for the caller to hold pointers to it for very 00030 long; it probably lives in some objfile's obstacks. */ 00031 typedef struct macro_definition *(macro_lookup_ftype) (const char *name, 00032 void *baton); 00033 00034 00035 /* Expand any preprocessor macros in SOURCE, and return the expanded 00036 text. Use LOOKUP_FUNC and LOOKUP_FUNC_BATON to find identifiers' 00037 preprocessor definitions. SOURCE is a null-terminated string. The 00038 result is a null-terminated string, allocated using xmalloc; it is 00039 the caller's responsibility to free it. */ 00040 char *macro_expand (const char *source, 00041 macro_lookup_ftype *lookup_func, 00042 void *lookup_func_baton); 00043 00044 00045 /* Expand all preprocessor macro references that appear explicitly in 00046 SOURCE, but do not expand any new macro references introduced by 00047 that first level of expansion. Use LOOKUP_FUNC and 00048 LOOKUP_FUNC_BATON to find identifiers' preprocessor definitions. 00049 SOURCE is a null-terminated string. The result is a 00050 null-terminated string, allocated using xmalloc; it is the caller's 00051 responsibility to free it. */ 00052 char *macro_expand_once (const char *source, 00053 macro_lookup_ftype *lookup_func, 00054 void *lookup_func_baton); 00055 00056 00057 /* If the null-terminated string pointed to by *LEXPTR begins with a 00058 macro invocation, return the result of expanding that invocation as 00059 a null-terminated string, and set *LEXPTR to the next character 00060 after the invocation. The result is completely expanded; it 00061 contains no further macro invocations. 00062 00063 Otherwise, if *LEXPTR does not start with a macro invocation, 00064 return zero, and leave *LEXPTR unchanged. 00065 00066 Use LOOKUP_FUNC and LOOKUP_BATON to find macro definitions. 00067 00068 If this function returns a string, the caller is responsible for 00069 freeing it, using xfree. 00070 00071 We need this expand-one-token-at-a-time interface in order to 00072 accomodate GDB's C expression parser, which may not consume the 00073 entire string. When the user enters a command like 00074 00075 (gdb) break *func+20 if x == 5 00076 00077 the parser is expected to consume `func+20', and then stop when it 00078 sees the "if". But of course, "if" appearing in a character string 00079 or as part of a larger identifier doesn't count. So you pretty 00080 much have to do tokenization to find the end of the string that 00081 needs to be macro-expanded. Our C/C++ tokenizer isn't really 00082 designed to be called by anything but the yacc parser engine. */ 00083 char *macro_expand_next (const char **lexptr, 00084 macro_lookup_ftype *lookup_func, 00085 void *lookup_baton); 00086 00087 /* Functions to classify characters according to cpp rules. */ 00088 00089 int macro_is_whitespace (int c); 00090 int macro_is_identifier_nondigit (int c); 00091 int macro_is_digit (int c); 00092 00093 00094 /* Stringify STR according to C rules and return an xmalloc'd pointer 00095 to the result. */ 00096 00097 char *macro_stringify (const char *str); 00098 00099 #endif /* MACROEXP_H */