1*e4b17023SJohn Marino /* MD reader definitions.
2*e4b17023SJohn Marino Copyright (C) 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3*e4b17023SJohn Marino 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010
4*e4b17023SJohn Marino Free Software Foundation, Inc.
5*e4b17023SJohn Marino
6*e4b17023SJohn Marino This file is part of GCC.
7*e4b17023SJohn Marino
8*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under
9*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free
10*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later
11*e4b17023SJohn Marino version.
12*e4b17023SJohn Marino
13*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or
15*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16*e4b17023SJohn Marino for more details.
17*e4b17023SJohn Marino
18*e4b17023SJohn Marino You should have received a copy of the GNU General Public License
19*e4b17023SJohn Marino along with GCC; see the file COPYING3. If not see
20*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */
21*e4b17023SJohn Marino
22*e4b17023SJohn Marino #include "obstack.h"
23*e4b17023SJohn Marino #include "hashtab.h"
24*e4b17023SJohn Marino
25*e4b17023SJohn Marino /* Holds one symbol or number in the .md file. */
26*e4b17023SJohn Marino struct md_name {
27*e4b17023SJohn Marino /* The name as it appeared in the .md file. Names are syntactically
28*e4b17023SJohn Marino limited to the length of this buffer. */
29*e4b17023SJohn Marino char buffer[256];
30*e4b17023SJohn Marino
31*e4b17023SJohn Marino /* The name that should actually be used by the generator programs.
32*e4b17023SJohn Marino This is an expansion of NAME, after things like constant substitution. */
33*e4b17023SJohn Marino char *string;
34*e4b17023SJohn Marino };
35*e4b17023SJohn Marino
36*e4b17023SJohn Marino /* This structure represents a constant defined by define_constant,
37*e4b17023SJohn Marino define_enum, or such-like. */
38*e4b17023SJohn Marino struct md_constant {
39*e4b17023SJohn Marino /* The name of the constant. */
40*e4b17023SJohn Marino char *name;
41*e4b17023SJohn Marino
42*e4b17023SJohn Marino /* The string to which the constants expands. */
43*e4b17023SJohn Marino char *value;
44*e4b17023SJohn Marino
45*e4b17023SJohn Marino /* If the constant is associated with a enumeration, this field
46*e4b17023SJohn Marino points to that enumeration, otherwise it is null. */
47*e4b17023SJohn Marino struct enum_type *parent_enum;
48*e4b17023SJohn Marino };
49*e4b17023SJohn Marino
50*e4b17023SJohn Marino /* This structure represents one value in an enum_type. */
51*e4b17023SJohn Marino struct enum_value {
52*e4b17023SJohn Marino /* The next value in the enum, or null if this is the last. */
53*e4b17023SJohn Marino struct enum_value *next;
54*e4b17023SJohn Marino
55*e4b17023SJohn Marino /* The name of the value as it appears in the .md file. */
56*e4b17023SJohn Marino char *name;
57*e4b17023SJohn Marino
58*e4b17023SJohn Marino /* The definition of the related C value. */
59*e4b17023SJohn Marino struct md_constant *def;
60*e4b17023SJohn Marino };
61*e4b17023SJohn Marino
62*e4b17023SJohn Marino /* This structure represents an enum defined by define_enum or the like. */
63*e4b17023SJohn Marino struct enum_type {
64*e4b17023SJohn Marino /* The C name of the enumeration. */
65*e4b17023SJohn Marino char *name;
66*e4b17023SJohn Marino
67*e4b17023SJohn Marino /* True if this is an md-style enum (DEFINE_ENUM) rather than
68*e4b17023SJohn Marino a C-style enum (DEFINE_C_ENUM). */
69*e4b17023SJohn Marino bool md_p;
70*e4b17023SJohn Marino
71*e4b17023SJohn Marino /* The values of the enumeration. There is always at least one. */
72*e4b17023SJohn Marino struct enum_value *values;
73*e4b17023SJohn Marino
74*e4b17023SJohn Marino /* A pointer to the null terminator in VALUES. */
75*e4b17023SJohn Marino struct enum_value **tail_ptr;
76*e4b17023SJohn Marino
77*e4b17023SJohn Marino /* The number of enumeration values. */
78*e4b17023SJohn Marino unsigned int num_values;
79*e4b17023SJohn Marino };
80*e4b17023SJohn Marino
81*e4b17023SJohn Marino /* A callback that handles a single .md-file directive, up to but not
82*e4b17023SJohn Marino including the closing ')'. It takes two arguments: the line number on
83*e4b17023SJohn Marino which the directive started, and the name of the directive. The next
84*e4b17023SJohn Marino unread character is the optional space after the directive name. */
85*e4b17023SJohn Marino typedef void (*directive_handler_t) (int, const char *);
86*e4b17023SJohn Marino
87*e4b17023SJohn Marino extern const char *in_fname;
88*e4b17023SJohn Marino extern FILE *read_md_file;
89*e4b17023SJohn Marino extern int read_md_lineno;
90*e4b17023SJohn Marino extern const char *read_md_filename;
91*e4b17023SJohn Marino extern struct obstack string_obstack;
92*e4b17023SJohn Marino extern void (*include_callback) (const char *);
93*e4b17023SJohn Marino
94*e4b17023SJohn Marino /* Read the next character from the MD file. */
95*e4b17023SJohn Marino
96*e4b17023SJohn Marino static inline int
read_char(void)97*e4b17023SJohn Marino read_char (void)
98*e4b17023SJohn Marino {
99*e4b17023SJohn Marino int ch;
100*e4b17023SJohn Marino
101*e4b17023SJohn Marino ch = getc (read_md_file);
102*e4b17023SJohn Marino if (ch == '\n')
103*e4b17023SJohn Marino read_md_lineno++;
104*e4b17023SJohn Marino return ch;
105*e4b17023SJohn Marino }
106*e4b17023SJohn Marino
107*e4b17023SJohn Marino /* Put back CH, which was the last character read from the MD file. */
108*e4b17023SJohn Marino
109*e4b17023SJohn Marino static inline void
unread_char(int ch)110*e4b17023SJohn Marino unread_char (int ch)
111*e4b17023SJohn Marino {
112*e4b17023SJohn Marino if (ch == '\n')
113*e4b17023SJohn Marino read_md_lineno--;
114*e4b17023SJohn Marino ungetc (ch, read_md_file);
115*e4b17023SJohn Marino }
116*e4b17023SJohn Marino
117*e4b17023SJohn Marino extern hashval_t leading_string_hash (const void *);
118*e4b17023SJohn Marino extern int leading_string_eq_p (const void *, const void *);
119*e4b17023SJohn Marino extern void copy_md_ptr_loc (const void *, const void *);
120*e4b17023SJohn Marino extern void print_md_ptr_loc (const void *);
121*e4b17023SJohn Marino extern const char *join_c_conditions (const char *, const char *);
122*e4b17023SJohn Marino extern void print_c_condition (const char *);
123*e4b17023SJohn Marino extern void message_with_line (int, const char *, ...) ATTRIBUTE_PRINTF_2;
124*e4b17023SJohn Marino extern void error_with_line (int, const char *, ...) ATTRIBUTE_PRINTF_2;
125*e4b17023SJohn Marino extern void fatal_with_file_and_line (const char *, ...)
126*e4b17023SJohn Marino ATTRIBUTE_PRINTF_1 ATTRIBUTE_NORETURN;
127*e4b17023SJohn Marino extern void fatal_expected_char (int, int) ATTRIBUTE_NORETURN;
128*e4b17023SJohn Marino extern int read_skip_spaces (void);
129*e4b17023SJohn Marino extern void read_name (struct md_name *);
130*e4b17023SJohn Marino extern char *read_quoted_string (void);
131*e4b17023SJohn Marino extern char *read_string (int);
132*e4b17023SJohn Marino extern void read_skip_construct (int, int);
133*e4b17023SJohn Marino extern int n_comma_elts (const char *);
134*e4b17023SJohn Marino extern const char *scan_comma_elt (const char **);
135*e4b17023SJohn Marino extern void upcase_string (char *);
136*e4b17023SJohn Marino extern void traverse_md_constants (htab_trav, void *);
137*e4b17023SJohn Marino extern void traverse_enum_types (htab_trav, void *);
138*e4b17023SJohn Marino extern struct enum_type *lookup_enum_type (const char *);
139*e4b17023SJohn Marino extern bool read_md_files (int, char **, bool (*) (const char *),
140*e4b17023SJohn Marino directive_handler_t);
141