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 returned by create_definition */
22 typedef struct macrodef MACRODEF
;
25 struct definition
*defn
;
30 /* Structure allocated for every #define. For a simple replacement
33 nargs = -1, the `pattern' list is null, and the expansion is just
34 the replacement text. Nargs = 0 means a functionlike macro with no args,
36 #define getchar() getc (stdin) .
37 When there are args, the expansion is the replacement text with the
38 args squashed out, and the reflist is a list describing how to
39 build the output from the input: e.g., "3 chars, then the 1st arg,
40 then 9 chars, then the 3rd arg, then 0 chars, then the 2nd arg".
41 The chars here come from the expansion. Whatever is left of the
42 expansion after the last arg-occurrence is copied after that arg.
43 Note that the reflist can be arbitrarily long---
44 its length depends on the number of times the arguments appear in
45 the replacement text, not how many args there are. Example:
46 #define f(x) x+x+x+x+x+x+x would have replacement text "++++++" and
48 { (0, 1), (1, 1), (1, 1), ..., (1, 1), NULL }
49 where (x, y) means (nchars, argno). */
51 typedef struct definition DEFINITION
;
54 int length
; /* length of expansion string */
55 unsigned char *expansion
;
56 int line
; /* Line number of definition */
57 const char *file
; /* File of definition */
58 char rest_args
; /* Nonzero if last arg. absorbs the rest */
61 char stringify
; /* nonzero if this arg was preceded by a
63 char raw_before
; /* Nonzero if a ## operator before arg. */
64 char raw_after
; /* Nonzero if a ## operator after arg. */
65 char rest_args
; /* Nonzero if this arg. absorbs the rest */
66 int nchars
; /* Number of literal chars to copy before
67 this arg occurrence. */
68 int argno
; /* Number of arg to substitute (origin-0) */
70 /* Names of macro args, concatenated in reverse order
71 with comma-space between them.
72 The only use of this is that we warn on redefinition
73 if this differs between the old and new definitions. */
74 unsigned char *argnames
;
77 /* different kinds of things that can appear in the value field
81 const char *cpval
; /* some predefined macros */
82 DEFINITION
*defn
; /* #define */
83 struct hashnode
*aschain
; /* #assert */
86 typedef struct hashnode HASHNODE
;
88 struct hashnode
*next
; /* double links for easy deletion */
89 struct hashnode
*prev
;
90 struct hashnode
**bucket_hdr
; /* also, a back pointer to this node's hash
91 chain is kept, in case the node is the head
92 of the chain and gets deleted. */
93 enum node_type type
; /* type of special token */
94 int length
; /* length of token, for quick comparison */
95 U_CHAR
*name
; /* the actual name */
96 union hashval value
; /* pointer to expansion, or whatever */
99 extern HASHNODE
*cpp_install
PARAMS ((cpp_reader
*, const U_CHAR
*, int,
100 enum node_type
, const char *));
101 extern HASHNODE
*cpp_lookup
PARAMS ((cpp_reader
*, const U_CHAR
*, int));
102 extern void free_definition
PARAMS ((DEFINITION
*));
103 extern void delete_macro
PARAMS ((HASHNODE
*));
105 extern MACRODEF create_definition
PARAMS ((U_CHAR
*, U_CHAR
*,
107 extern int compare_defs
PARAMS ((cpp_reader
*, DEFINITION
*,
109 extern void macroexpand
PARAMS ((cpp_reader
*, HASHNODE
*));
110 extern void dump_definition
PARAMS ((cpp_reader
*, const U_CHAR
*, long,