]>
Commit | Line | Data |
---|---|---|
4283012f JL |
1 | /* Part of CPP library. (Macro hash table support.) |
2 | Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc. | |
3 | ||
4 | This program is free software; you can redistribute it and/or modify it | |
5 | under the terms of the GNU General Public License as published by the | |
6 | Free Software Foundation; either version 2, or (at your option) any | |
7 | later version. | |
8 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along with this program; if not, write to the Free Software | |
42b17236 | 16 | Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
4283012f | 17 | |
bb52fa7f ZW |
18 | #ifndef __GCC_CPPHASH__ |
19 | #define __GCC_CPPHASH__ | |
20 | ||
bb52fa7f ZW |
21 | /* Structure allocated for every #define. For a simple replacement |
22 | such as | |
23 | #define foo bar , | |
24 | nargs = -1, the `pattern' list is null, and the expansion is just | |
25 | the replacement text. Nargs = 0 means a functionlike macro with no args, | |
26 | e.g., | |
27 | #define getchar() getc (stdin) . | |
28 | When there are args, the expansion is the replacement text with the | |
29 | args squashed out, and the reflist is a list describing how to | |
30 | build the output from the input: e.g., "3 chars, then the 1st arg, | |
31 | then 9 chars, then the 3rd arg, then 0 chars, then the 2nd arg". | |
32 | The chars here come from the expansion. Whatever is left of the | |
33 | expansion after the last arg-occurrence is copied after that arg. | |
34 | Note that the reflist can be arbitrarily long--- | |
35 | its length depends on the number of times the arguments appear in | |
36 | the replacement text, not how many args there are. Example: | |
37 | #define f(x) x+x+x+x+x+x+x would have replacement text "++++++" and | |
38 | pattern list | |
39 | { (0, 1), (1, 1), (1, 1), ..., (1, 1), NULL } | |
40 | where (x, y) means (nchars, argno). */ | |
41 | ||
ba412f14 ZW |
42 | struct reflist |
43 | { | |
44 | struct reflist *next; | |
45 | char stringify; /* nonzero if this arg was preceded by a | |
46 | # operator. */ | |
47 | char raw_before; /* Nonzero if a ## operator before arg. */ | |
48 | char raw_after; /* Nonzero if a ## operator after arg. */ | |
49 | char rest_args; /* Nonzero if this arg. absorbs the rest */ | |
50 | int nchars; /* Number of literal chars to copy before | |
51 | this arg occurrence. */ | |
52 | int argno; /* Number of arg to substitute (origin-0) */ | |
53 | }; | |
54 | ||
bb52fa7f | 55 | typedef struct definition DEFINITION; |
ba412f14 ZW |
56 | struct definition |
57 | { | |
bb52fa7f ZW |
58 | int nargs; |
59 | int length; /* length of expansion string */ | |
ba412f14 | 60 | U_CHAR *expansion; |
bb52fa7f | 61 | int line; /* Line number of definition */ |
ba412f14 | 62 | int col; |
bb52fa7f ZW |
63 | const char *file; /* File of definition */ |
64 | char rest_args; /* Nonzero if last arg. absorbs the rest */ | |
ba412f14 ZW |
65 | struct reflist *pattern; |
66 | ||
67 | /* Names of macro args, concatenated in order with commas between | |
68 | them. The only use of this is that we warn on redefinition if | |
69 | this differs between the old and new definitions. */ | |
70 | U_CHAR *argnames; | |
bb52fa7f ZW |
71 | }; |
72 | ||
7f2935c7 | 73 | /* different kinds of things that can appear in the value field |
5dfa4da1 ZW |
74 | of a hash node. */ |
75 | union hashval | |
76 | { | |
77 | const char *cpval; /* some predefined macros */ | |
78 | DEFINITION *defn; /* #define */ | |
79 | struct hashnode *aschain; /* #assert */ | |
7f2935c7 PB |
80 | }; |
81 | ||
cf4ed945 | 82 | typedef struct hashnode HASHNODE; |
7f2935c7 PB |
83 | struct hashnode { |
84 | struct hashnode *next; /* double links for easy deletion */ | |
85 | struct hashnode *prev; | |
86 | struct hashnode **bucket_hdr; /* also, a back pointer to this node's hash | |
87 | chain is kept, in case the node is the head | |
88 | of the chain and gets deleted. */ | |
89 | enum node_type type; /* type of special token */ | |
90 | int length; /* length of token, for quick comparison */ | |
91 | U_CHAR *name; /* the actual name */ | |
92 | union hashval value; /* pointer to expansion, or whatever */ | |
93 | }; | |
94 | ||
b0699dad | 95 | extern HASHNODE *_cpp_install PARAMS ((cpp_reader *, const U_CHAR *, int, |
bb52fa7f | 96 | enum node_type, const char *)); |
b0699dad ZW |
97 | extern HASHNODE *_cpp_lookup PARAMS ((cpp_reader *, const U_CHAR *, int)); |
98 | extern void _cpp_free_definition PARAMS ((DEFINITION *)); | |
99 | extern void _cpp_delete_macro PARAMS ((HASHNODE *)); | |
6de1e2a9 | 100 | |
b0699dad ZW |
101 | extern DEFINITION *_cpp_create_definition |
102 | PARAMS ((cpp_reader *, int)); | |
103 | extern int _cpp_compare_defs PARAMS ((cpp_reader *, DEFINITION *, | |
6de1e2a9 | 104 | DEFINITION *)); |
b0699dad ZW |
105 | extern void _cpp_macroexpand PARAMS ((cpp_reader *, HASHNODE *)); |
106 | extern void _cpp_dump_definition PARAMS ((cpp_reader *, const U_CHAR *, long, | |
a2a76ce7 | 107 | DEFINITION *)); |
bb52fa7f ZW |
108 | |
109 | #endif |