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