1 /* Interface to C preprocessor macro expansion for GDB. 2 Copyright (C) 2002, 2007, 2008, 2009, 2010, 2011 3 Free Software Foundation, Inc. 4 Contributed by Red Hat, Inc. 5 6 This file is part of GDB. 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 3 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20 21 22 #ifndef MACROEXP_H 23 #define MACROEXP_H 24 25 /* A function for looking up preprocessor macro definitions. Return 26 the preprocessor definition of NAME in scope according to BATON, or 27 zero if NAME is not defined as a preprocessor macro. 28 29 The caller must not free or modify the definition returned. It is 30 probably unwise for the caller to hold pointers to it for very 31 long; it probably lives in some objfile's obstacks. */ 32 typedef struct macro_definition *(macro_lookup_ftype) (const char *name, 33 void *baton); 34 35 36 /* Expand any preprocessor macros in SOURCE, and return the expanded 37 text. Use LOOKUP_FUNC and LOOKUP_FUNC_BATON to find identifiers' 38 preprocessor definitions. SOURCE is a null-terminated string. The 39 result is a null-terminated string, allocated using xmalloc; it is 40 the caller's responsibility to free it. */ 41 char *macro_expand (const char *source, 42 macro_lookup_ftype *lookup_func, 43 void *lookup_func_baton); 44 45 46 /* Expand all preprocessor macro references that appear explicitly in 47 SOURCE, but do not expand any new macro references introduced by 48 that first level of expansion. Use LOOKUP_FUNC and 49 LOOKUP_FUNC_BATON to find identifiers' preprocessor definitions. 50 SOURCE is a null-terminated string. The result is a 51 null-terminated string, allocated using xmalloc; it is the caller's 52 responsibility to free it. */ 53 char *macro_expand_once (const char *source, 54 macro_lookup_ftype *lookup_func, 55 void *lookup_func_baton); 56 57 58 /* If the null-terminated string pointed to by *LEXPTR begins with a 59 macro invocation, return the result of expanding that invocation as 60 a null-terminated string, and set *LEXPTR to the next character 61 after the invocation. The result is completely expanded; it 62 contains no further macro invocations. 63 64 Otherwise, if *LEXPTR does not start with a macro invocation, 65 return zero, and leave *LEXPTR unchanged. 66 67 Use LOOKUP_FUNC and LOOKUP_BATON to find macro definitions. 68 69 If this function returns a string, the caller is responsible for 70 freeing it, using xfree. 71 72 We need this expand-one-token-at-a-time interface in order to 73 accomodate GDB's C expression parser, which may not consume the 74 entire string. When the user enters a command like 75 76 (gdb) break *func+20 if x == 5 77 78 the parser is expected to consume `func+20', and then stop when it 79 sees the "if". But of course, "if" appearing in a character string 80 or as part of a larger identifier doesn't count. So you pretty 81 much have to do tokenization to find the end of the string that 82 needs to be macro-expanded. Our C/C++ tokenizer isn't really 83 designed to be called by anything but the yacc parser engine. */ 84 char *macro_expand_next (char **lexptr, 85 macro_lookup_ftype *lookup_func, 86 void *lookup_baton); 87 88 /* Functions to classify characters according to cpp rules. */ 89 90 int macro_is_whitespace (int c); 91 int macro_is_identifier_nondigit (int c); 92 int macro_is_digit (int c); 93 94 95 #endif /* MACROEXP_H */ 96