4 * Basic parsing data structures. Statements and symbols.
6 * Copyright (C) 2003 Transmeta Corp.
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
48 enum statement_type type
;
50 struct statement
*parent
;
52 struct /* declaration */ {
53 struct symbol_list
*declaration
;
55 struct /* context */ {
56 struct expression
*expression
;
57 struct expression
*context
;
59 struct /* return_statement */ {
60 struct expression
*ret_value
;
61 struct symbol
*ret_target
;
63 struct /* if_statement */ {
64 struct expression
*if_conditional
;
65 struct statement
*if_true
;
66 struct statement
*if_false
;
68 struct /* compound_struct */ {
69 struct statement_list
*stmts
;
71 struct symbol
*inline_fn
;
72 struct statement
*args
;
74 struct /* labeled_struct */ {
75 struct symbol
*label_identifier
;
76 struct scope
*label_scope
;
77 struct statement
*label_statement
;
79 struct /* case_struct */ {
80 struct expression
*case_expression
;
81 struct expression
*case_to
;
82 struct statement
*case_statement
;
83 struct symbol
*case_label
;
85 struct /* switch_struct */ {
86 struct expression
*switch_expression
;
87 struct statement
*switch_statement
;
88 struct symbol
*switch_break
, *switch_case
;
90 struct /* iterator_struct */ {
91 struct symbol
*iterator_break
;
92 struct symbol
*iterator_continue
;
93 struct symbol_list
*iterator_syms
;
94 struct statement
*iterator_pre_statement
;
95 struct expression
*iterator_pre_condition
;
97 struct statement
*iterator_statement
;
99 struct statement
*iterator_post_statement
;
100 struct expression
*iterator_post_condition
;
102 struct /* goto_struct */ {
103 struct symbol
*goto_label
;
105 /* computed gotos have these: */
106 struct expression
*goto_expression
;
107 struct symbol_list
*target_list
;
110 struct expression
*asm_string
;
111 struct asm_operand_list
*asm_outputs
;
112 struct asm_operand_list
*asm_inputs
;
113 struct expression_list
*asm_clobbers
;
114 struct symbol_list
*asm_labels
;
117 struct expression
*range_expression
;
118 struct expression
*range_low
;
119 struct expression
*range_high
;
124 extern struct symbol_list
*function_computed_target_list
;
125 extern struct statement_list
*function_computed_goto_list
;
127 extern struct token
*parse_expression(struct token
*, struct expression
**);
128 extern struct symbol
*label_symbol(struct token
*token
, int used
);
129 extern void check_label_usage(struct symbol
*label
, struct position use_pos
);
131 extern int show_statement(struct statement
*);
132 extern void show_statement_list(struct statement_list
*, const char *);
133 extern int show_expression(struct expression
*);
135 typedef void (*validate_decl_t
)(struct symbol
*decl
);
136 extern struct token
*external_declaration(struct token
*, struct symbol_list
**, validate_decl_t
);
138 extern struct symbol
*ctype_integer(int size
, int want_unsigned
);
140 extern int inline_function(struct expression
*expr
, struct symbol
*sym
);
141 extern void uninline(struct symbol
*sym
);
142 extern void init_parser(int);
144 static inline void stmt_set_parent_stmt(struct statement
*stmt
, struct statement
*parent
)
148 stmt
->parent
= parent
;
151 static inline struct statement
*stmt_get_parent_stmt(struct statement
*stmt
)
155 struct token
*expect(struct token
*, int, const char *);