7b62c16b4f2e265daa7ec0b6566f36e4488af9d5
[gcc.git] / gcc / ch / lang.c
1 /* Language-specific hook definitions for CHILL front end.
2 Copyright (C) 1992, 93, 94, 98, 99, 2000 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21
22 #include "config.h"
23 #include "system.h"
24 #include "tree.h"
25 #include "ch-tree.h"
26 #include "lex.h"
27 #include "input.h"
28 #include "toplev.h"
29
30 /* Type node for boolean types. */
31
32 tree boolean_type_node;
33
34 /* True if STRING(INDEX) yields a CHARS(1) (or BOOLS(1)) rather than
35 a CHAR (or BOOL). Also, makes CHARS(1) similar for CHAR,
36 and BOOLS(1) similar to BOOL. This is for compatibility
37 for the 1984 version of Z.200.*/
38 int flag_old_strings = 0;
39
40 /* This is set non-zero to force user input tokens to lower case.
41 This is non-standard. See Z.200, page 8. */
42 int ignore_case = 1;
43
44 /* True if reserved and predefined words ('special' words in the Z.200
45 terminology) are in uppercase. Obviously, this had better not be
46 true if we're ignoring input case. */
47 int special_UC = 0;
48
49 /* The actual name of the input file, regardless of any #line directives */
50 const char* chill_real_input_filename;
51 extern FILE* finput;
52
53 static int deep_const_expr PARAMS ((tree));
54 static void chill_print_error_function PARAMS ((const char *));
55 \f
56 /* Return 1 if the expression tree given has all
57 constant nodes as its leaves,otherwise. */
58
59 static int
60 deep_const_expr (exp)
61 tree exp;
62 {
63 enum chill_tree_code code;
64 int length;
65 int i;
66
67 if (exp == NULL_TREE)
68 return 0;
69
70 code = TREE_CODE (exp);
71 length = first_rtl_op (TREE_CODE (exp));
72
73 /* constant leaf? return TRUE */
74 if (TREE_CODE_CLASS (code) == 'c')
75 return 1;
76
77 /* Recursively check next level down. */
78 for (i = 0; i < length; i++)
79 if (! deep_const_expr (TREE_OPERAND (exp, i)))
80 return 0;
81 return 1;
82 }
83
84
85 tree
86 const_expr (exp)
87 tree exp;
88 {
89 if (TREE_CODE (exp) == INTEGER_CST)
90 return exp;
91 if (TREE_CODE (exp) == CONST_DECL)
92 return const_expr (DECL_INITIAL (exp));
93 if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'd'
94 && DECL_INITIAL (exp) != NULL_TREE
95 && TREE_READONLY (exp))
96 return DECL_INITIAL (exp);
97 if (deep_const_expr (exp))
98 return exp;
99 if (TREE_CODE (exp) != ERROR_MARK)
100 error ("non-constant expression");
101 return error_mark_node;
102 }
103
104 /* Each of the functions defined here
105 is an alternative to a function in objc-actions.c. */
106
107 /* Used by c-lex.c, but only for objc. */
108 tree
109 lookup_interface (arg)
110 tree arg ATTRIBUTE_UNUSED;
111 {
112 return 0;
113 }
114
115 int
116 maybe_objc_comptypes (lhs, rhs)
117 tree lhs ATTRIBUTE_UNUSED, rhs ATTRIBUTE_UNUSED;
118 {
119 return -1;
120 }
121
122 tree
123 maybe_building_objc_message_expr ()
124 {
125 return 0;
126 }
127
128 int
129 recognize_objc_keyword ()
130 {
131 return 0;
132 }
133
134 void
135 lang_init_options ()
136 {
137 }
138
139 /* used by print-tree.c */
140
141 void
142 lang_print_xnode (file, node, indent)
143 FILE *file ATTRIBUTE_UNUSED;
144 tree node ATTRIBUTE_UNUSED;
145 int indent ATTRIBUTE_UNUSED;
146 {
147 }
148
149 void
150 GNU_xref_begin ()
151 {
152 fatal ("GCC does not yet support XREF");
153 }
154
155 void
156 GNU_xref_end ()
157 {
158 fatal ("GCC does not yet support XREF");
159 }
160 \f
161 /*
162 * process chill-specific compiler command-line options
163 * do not complain if the option is not recognised
164 */
165 int
166 lang_decode_option (argc, argv)
167 int argc;
168 char **argv;
169 {
170 char *p = argv[0];
171 static int explicit_ignore_case = 0;
172 if (!strcmp(p, "-lang-chill"))
173 ; /* do nothing */
174 else if (!strcmp (p, "-fruntime-checking"))
175 {
176 range_checking = 1;
177 empty_checking = 1;
178 }
179 else if (!strcmp (p, "-fno-runtime-checking"))
180 {
181 range_checking = 0;
182 empty_checking = 0;
183 runtime_checking_flag = 0;
184 }
185 else if (!strcmp (p, "-flocal-loop-counter"))
186 flag_local_loop_counter = 1;
187 else if (!strcmp (p, "-fno-local-loop-counter"))
188 flag_local_loop_counter = 0;
189 else if (!strcmp (p, "-fold-strings"))
190 flag_old_strings = 1;
191 else if (!strcmp (p, "-fno-old-strings"))
192 flag_old_strings = 0;
193 else if (!strcmp (p, "-fignore-case"))
194 {
195 explicit_ignore_case = 1;
196 if (special_UC)
197 {
198 error ("Ignoring case upon input and");
199 error ("making special words uppercase wouldn't work.");
200 }
201 else
202 ignore_case = 1;
203 }
204 else if (!strcmp (p, "-fno-ignore-case"))
205 ignore_case = 0;
206 else if (!strcmp (p, "-fspecial_UC"))
207 {
208 if (explicit_ignore_case)
209 {
210 error ("Making special words uppercase and");
211 error (" ignoring case upon input wouldn't work.");
212 }
213 else
214 special_UC = 1, ignore_case = 0;
215 }
216 else if (!strcmp (p, "-fspecial_LC"))
217 special_UC = 0;
218 else if (!strcmp (p, "-fpack"))
219 maximum_field_alignment = BITS_PER_UNIT;
220 else if (!strcmp (p, "-fno-pack"))
221 maximum_field_alignment = 0;
222 else if (!strcmp (p, "-fchill-grant-only"))
223 grant_only_flag = 1;
224 else if (!strcmp (p, "-fgrant-only"))
225 grant_only_flag = 1;
226 /* user has specified a seize-file path */
227 else if (p[0] == '-' && p[1] == 'I')
228 register_seize_path (&p[2]);
229 if (!strcmp(p, "-itu")) /* Force Z.200 semantics */
230 {
231 pedantic = 1; /* FIXME: new flag name? */
232 flag_local_loop_counter = 1;
233 }
234 else
235 return c_decode_option (argc, argv);
236
237 return 1;
238 }
239
240 static void
241 chill_print_error_function (file)
242 const char *file;
243 {
244 static tree last_error_function = NULL_TREE;
245 static struct module *last_error_module = NULL;
246
247 if (last_error_function == current_function_decl
248 && last_error_module == current_module)
249 return;
250
251 last_error_function = current_function_decl;
252 last_error_module = current_module;
253
254 if (file)
255 fprintf (stderr, "%s: ", file);
256
257 if (current_function_decl == global_function_decl
258 || current_function_decl == NULL_TREE)
259 {
260 if (current_module == NULL)
261 fprintf (stderr, "At top level:\n");
262 else
263 fprintf (stderr, "In module %s:\n",
264 IDENTIFIER_POINTER (current_module->name));
265 }
266 else
267 {
268 const char *kind = "function";
269 const char *name = (*decl_printable_name) (current_function_decl, 2);
270 fprintf (stderr, "In %s `%s':\n", kind, name);
271 }
272 }
273
274 /* Print an error message for invalid use of an incomplete type.
275 VALUE is the expression that was used (or 0 if that isn't known)
276 and TYPE is the type that was invalid. */
277
278 void
279 incomplete_type_error (value, type)
280 tree value ATTRIBUTE_UNUSED;
281 tree type ATTRIBUTE_UNUSED;
282 {
283 error ("internal error - use of undefined type");
284 }
285
286 /* Return the typed-based alias set for T, which may be an expression
287 or a type. Return -1 if we don't do anything special. */
288
289 HOST_WIDE_INT
290 lang_get_alias_set (t)
291 tree t;
292 {
293 /* ??? Need to figure out what the rules are. Certainly we'd need
294 to handle union-like things, and probably variant records.
295 Until then, turn off type-based aliasing completely. */
296 return 0;
297 }
298
299 void
300 lang_init ()
301 {
302 chill_real_input_filename = input_filename;
303
304 /* the beginning of the file is a new line; check for # */
305 /* With luck, we discover the real source file's name from that
306 and put it in input_filename. */
307
308 ungetc (check_newline (), finput);
309
310 /* set default grant file */
311 set_default_grant_file ();
312
313 print_error_function = chill_print_error_function;
314 }