1 /* Part of CPP library. (Macro hash table support.)
2 Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
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
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.
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
16 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 #ifndef __GCC_CPPHASH__
19 #define __GCC_CPPHASH__
21 /* Structure allocated for every #define. For a simple replacement
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,
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
39 { (0, 1), (1, 1), (1, 1), ..., (1, 1), NULL }
40 where (x, y) means (nchars, argno). */
45 char stringify; /* nonzero if this arg was preceded by a
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) */
55 typedef struct definition DEFINITION;
59 int length; /* length of expansion string */
61 int line; /* Line number of definition */
63 const char *file; /* File of definition */
64 char rest_args; /* Nonzero if last arg. absorbs the rest */
65 struct reflist *pattern;
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. */
73 /* different kinds of things that can appear in the value field
77 const char *cpval; /* some predefined macros */
78 DEFINITION *defn; /* #define */
79 struct hashnode *aschain; /* #assert */
82 typedef struct hashnode 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 */
95 extern HASHNODE *cpp_install PARAMS ((cpp_reader *, const U_CHAR *, int,
96 enum node_type, const char *));
97 extern HASHNODE *cpp_lookup PARAMS ((cpp_reader *, const U_CHAR *, int));
98 extern void free_definition PARAMS ((DEFINITION *));
99 extern void delete_macro PARAMS ((HASHNODE *));
101 extern DEFINITION *create_definition PARAMS ((cpp_reader *, int));
102 extern int compare_defs PARAMS ((cpp_reader *, DEFINITION *,
104 extern void macroexpand PARAMS ((cpp_reader *, HASHNODE *));
105 extern void dump_definition PARAMS ((cpp_reader *, const U_CHAR *, long,