* configure.in: Arrange to include defaults.h in [ht]config.h/tm.h.
[official-gcc.git] / gcc / ch / decl.c
blob18a4cc66f67719c7e44d385e102cc96973883717
1 /* Process declarations and variables for GNU CHILL compiler.
2 Copyright (C) 1992, 1993, 1994, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* Process declarations and symbol lookup for CHILL front end.
24 Also constructs types; the standard scalar types at initialization,
25 and structure, union, array and enum types when they are declared. */
27 /* NOTES on Chill name resolution
29 Chill allows one to refer to an identifier that is declared later in
30 the same Group. Hence, a single pass over the code (as in C) is
31 insufficient.
33 This implementation uses two complete passes over the source code,
34 plus some extra passes over internal data structures.
36 Loosely, during pass 1, a 'scope' object is created for each Chill
37 reach. Each scope object contains a list of 'decl' objects,
38 one for each 'defining occurrence' in the reach. (This list
39 is in the 'remembered_decls' field of each scope.)
40 The scopes and their decls are replayed in pass 2: As each reach
41 is entered, the decls saved from pass 1 are made visible.
43 There are some exceptions. Declarations that cannot be referenced
44 before their declaration (i.e. whose defining occurrence precede
45 their reach), can be deferred to pass 2. These include formal
46 parameter declarations, and names defined in a DO action.
48 During pass 2, as each scope is entered, we must make visible all
49 the declarations defined in the scope, before we generate any code.
50 We must also simplify the declarations from pass 1: For example
51 a VAR_DECL may have a array type whose bounds are expressions;
52 these need to be folded. But of course the expressions may contain
53 identifiers that may be defined later in the scope - or even in
54 a different module.
56 The "satisfy" process has two main phases:
58 1: Binding. Each identifier *referenced* in a declaration (i.e. in
59 a mode or the RHS of a synonum declaration) must be bound to its
60 defining occurrence. This may need to be linking via
61 grants and/or seizes (which are represented by ALIAS_DECLs).
62 A further complication is handling implied name strings.
64 2: Layout. Each CONST_DECL or TYPE_DECL *referenced* in a declaration
65 must than be replaced by its value (or type). Constants must be
66 folded. Types and declarstions must be laid out. DECL_RTL must be set.
67 While doing this, we must watch out for circular dependencies.
69 If a scope contains nested modulions, then the Binding phase must be
70 done for each nested module (recursively) before the Layout phase
71 can start for that scope. As an example of why this is needed, consider:
73 M1: MODULE
74 DCL a ARRAY [1:y] int; -- This should have 7 elements.
75 SYN x = 5;
76 SEIZE y;
77 END M1;
78 M2: MODULE
79 SYN x = 2;
80 SYN y = x + 5;
81 GRANT y;
82 END M2;
84 Here, the 'x' in "x + 5" must be Bound to the 'x' in module M2.
85 This must be done before we can Layout a.
86 The reason this is an issue is that we do *not* have a lookup
87 (or hash) table per scope (or module). Instead we have a single
88 global table we keep adding and removing bindings from.
89 (This is both for speed, and because of gcc history.)
91 Note that a SEIZE generates a declaration in the current scope,
92 linked to something in the surrounding scope. Determining (binding)
93 the link must be done in pass 2. On the other hand, a GRANT
94 generates a declaration in the surrounding scope, linked to
95 something in the current scope. This linkage is Bound in pass 1.
97 The sequence for the above example is:
98 - Enter the declarations of M1 (i.e. {a, x, y}) into the hash table.
99 - For each of {a, x, y}, examine dependent expression (the
100 rhs of x, the bounds of a), and Bind any identifiers to
101 the current declarations (as found in the hash table). Specifically,
102 the 'y' in the array bounds of 'a' is bound to the 'y' declared by
103 the SEIZE declaration. Also, 'y' is Bound to the implicit
104 declaration in the global scope (generated from the GRANT in M2).
105 - Remove the bindings for M1 (i.e. {a, x, y}) from the hash table.
106 - Enter the declarations of M2 (i.e. {x, y}) into the hash table.
107 - For each of {x, y} examine the dependent expressions (the rhs of
108 x and y), and Bind any identifiers to their current declarartions
109 (in this case the 'x' in "x + 5" is bound to the 'x' that is 2.
110 - Remove the bindings for M2 (i.e. {x, y}) from the hash table.
111 - Perform Layout for M1: This requires the size of a, which
112 requires the value of y. The 'y' is Bound to the implicit
113 declaration in the global scope, which is Bound to the declaration
114 of y in M2. We now require the value of this 'y', which is "x + 5"
115 where x is bound to the x in M2 (thanks to our previous Binding
116 phase). So we get that the value of y is 7.
117 - Perform layout of M2. This implies calculating (constant folding)
118 the value of y - but we already did that, so we're done.
120 An example illustating the problem with implied names:
122 M1: MODULE
123 SEIZE y;
124 use(e); -- e is implied by y.
125 END M1;
126 M2: MODULE
127 GRANT y;
128 SYNMODE y = x;
129 SEIZE x;
130 END M2;
131 M3: MODULE
132 GRANT x;
133 SYNMODE x = SET (e);
134 END M3;
136 This implies that determining the implied name e in M1
137 must be done after Binding of y to x in M2.
139 Yet another nasty:
140 M1: MODULE
141 SEIZE v;
142 DCL a ARRAY(v:v) int;
143 END M1;
144 M2: MODULE
145 GRANT v;
146 SEIZE x;
147 SYN v x = e;
148 END M2;
149 M3: MODULE
150 GRANT x;
151 SYNMODE x = SET(e);
152 END M3;
154 This one implies that determining the implied name e in M2,
155 must be done before Layout of a in M1.
157 These two examples togother indicate the determining implieed
158 names requries yet another phase.
159 - Bind strong names in M1.
160 - Bind strong names in M2.
161 - Bind strong names in M3.
162 - Determine weak names implied by SEIZEs in M1.
163 - Bind the weak names in M1.
164 - Determine weak names implied by SEIZEs in M2.
165 - Bind the weak names in M2.
166 - Determine weak names implied by SEIZEs in M3.
167 - Bind the weak names in M3.
168 - Layout M1.
169 - Layout M2.
170 - Layout M3.
172 We must bind the strong names in every module before we can determine
173 weak names in any module (because of seized/granted synmode/newmodes).
174 We must bind the weak names in every module before we can do Layout
175 in any module.
177 Sigh.
181 /* ??? not all decl nodes are given the most useful possible
182 line numbers. For example, the CONST_DECLs for enum values. */
184 #include "config.h"
185 #include "system.h"
186 #include "tree.h"
187 #include "flags.h"
188 #include "ch-tree.h"
189 #include "lex.h"
190 #include "obstack.h"
191 #include "input.h"
192 #include "rtl.h"
193 #include "toplev.h"
195 #define IS_UNKNOWN_TYPE(type) (TYPE_SIZE(type)==0)
196 #define BUILTIN_NESTING_LEVEL (-1)
198 /* For backward compatibility, we define Chill INT to be the same
199 as SHORT (i.e. 16 bits), at least if C INT is the same as LONG.
200 This is a lose. */
201 #define CHILL_INT_IS_SHORT (INT_TYPE_SIZE==LONG_TYPE_SIZE)
203 extern int ignore_case;
204 extern tree process_type;
205 extern struct obstack *saveable_obstack;
206 extern tree signal_code;
207 extern int special_UC;
209 static tree get_next_decl PARAMS ((void));
210 static tree lookup_name_for_seizing PARAMS ((tree));
211 #if 0
212 static tree lookup_name_current_level PARAMS ((tree));
213 #endif
214 static void save_decl PARAMS ((tree));
216 extern struct obstack permanent_obstack;
217 extern int in_pseudo_module;
219 struct module *current_module = NULL;
220 struct module *first_module = NULL;
221 struct module **next_module = &first_module;
223 extern int in_pseudo_module;
225 int module_number = 0;
227 /* This is only used internally (by signed_type). */
229 tree signed_boolean_type_node;
231 tree global_function_decl = NULL_TREE;
233 /* This is a temportary used by RESULT to store its value.
234 Note we cannot directly use DECL_RESULT for two reasons:
235 a) If DECL_RESULT is a register, it may get clobbered by a
236 subsequent function call; and
237 b) if the function returns a struct, we might (visibly) modify the
238 destination before we're supposed to. */
239 tree chill_result_decl;
241 int result_never_set;
243 /* forward declarations */
244 static void pushdecllist PARAMS ((tree, int));
245 static int init_nonvalue_struct PARAMS ((tree));
246 static int init_nonvalue_array PARAMS ((tree));
247 static void set_nesting_level PARAMS ((tree, int));
248 static tree make_chill_variants PARAMS ((tree, tree, tree));
249 static tree fix_identifier PARAMS ((tree));
250 static void proclaim_decl PARAMS ((tree, int));
251 static tree maybe_acons PARAMS ((tree, tree));
252 static void push_scope_decls PARAMS ((int));
253 static void pop_scope_decls PARAMS ((tree, tree));
254 static tree build_implied_names PARAMS ((tree));
255 static void bind_sub_modules PARAMS ((int));
256 static void layout_array_type PARAMS ((tree));
257 static void do_based_decl PARAMS ((tree, tree, tree));
258 static void handle_one_level PARAMS ((tree, tree));
260 int current_nesting_level = BUILTIN_NESTING_LEVEL;
261 int current_module_nesting_level = 0;
263 /* Lots of declarations copied from c-decl.c. */
264 /* ??? not all decl nodes are given the most useful possible
265 line numbers. For example, the CONST_DECLs for enum values. */
268 /* We let tm.h override the types used here, to handle trivial differences
269 such as the choice of unsigned int or long unsigned int for size_t.
270 When machines start needing nontrivial differences in the size type,
271 it would be best to do something here to figure out automatically
272 from other information what type to use. */
274 #ifndef PTRDIFF_TYPE
275 #define PTRDIFF_TYPE "long int"
276 #endif
278 #ifndef WCHAR_TYPE
279 #define WCHAR_TYPE "int"
280 #endif
282 tree wchar_type_node;
283 tree signed_wchar_type_node;
284 tree unsigned_wchar_type_node;
286 tree void_list_node;
288 /* type of initializer structure, which points to
289 a module's module-level code, and to the next
290 such structure. */
291 tree initializer_type;
293 /* type of a CHILL predefined value builtin routine */
294 tree chill_predefined_function_type;
296 /* type `int ()' -- used for implicit declaration of functions. */
298 tree default_function_type;
300 const char **boolean_code_name;
302 /* A node for the integer constant -1. */
303 tree integer_minus_one_node;
305 /* Nodes for boolean constants TRUE and FALSE. */
306 tree boolean_true_node, boolean_false_node;
308 tree string_one_type_node; /* The type of CHARS(1). */
309 tree bitstring_one_type_node; /* The type of BOOLS(1). */
310 tree bit_zero_node; /* B'0' */
311 tree bit_one_node; /* B'1' */
313 /* Nonzero if we have seen an invalid cross reference
314 to a struct, union, or enum, but not yet printed the message. */
316 tree pending_invalid_xref;
317 /* File and line to appear in the eventual error message. */
318 char *pending_invalid_xref_file;
319 int pending_invalid_xref_line;
321 /* After parsing the declarator that starts a function definition,
322 `start_function' puts here the list of parameter names or chain of decls.
323 `store_parm_decls' finds it here. */
325 static tree current_function_parms;
327 /* Nonzero when store_parm_decls is called indicates a varargs function.
328 Value not meaningful after store_parm_decls. */
330 static int c_function_varargs;
332 /* These are irrelevant for Chill, but are referenced from from c-typeck.c. */
333 int warn_format;
334 int warn_traditional;
335 int warn_bad_function_cast;
337 /* Identifiers that hold VAR_LENGTH and VAR_DATA. */
338 tree var_length_id, var_data_id;
340 tree case_else_node;
342 /* For each binding contour we allocate a scope structure
343 * which records the names defined in that contour.
344 * Contours include:
345 * 0) the global one
346 * 1) one for each function definition,
347 * where internal declarations of the parameters appear.
348 * 2) one for each compound statement,
349 * to record its declarations.
351 * The current meaning of a name can be found by searching the levels from
352 * the current one out to the global one.
355 /* To communicate between pass 1 and 2, we maintain a list of "scopes".
356 Each scope corrresponds to a nested source scope/block that contain
357 that can contain declarations. The TREE_VALUE of the scope points
358 to the list of declarations declared in that scope.
359 The TREE_PURPOSE of the scope points to the surrounding scope.
360 (We may need to handle nested modules later. FIXME)
361 The TREE_CHAIN field contains a list of scope as they are seen
362 in chronological order. (Reverse order during first pass,
363 but it is reverse before pass 2.) */
365 struct scope
367 /* The enclosing scope. */
368 struct scope *enclosing;
370 /* The next scope, in chronlogical order. */
371 struct scope *next;
373 /* A chain of DECLs constructed using save_decl during pass 1. */
374 tree remembered_decls;
376 /* A chain of _DECL nodes for all variables, constants, functions,
377 and typedef types belong to this scope. */
378 tree decls;
380 /* List of declarations that have been granted into this scope. */
381 tree granted_decls;
383 /* List of implied (weak) names. */
384 tree weak_decls;
386 /* For each level, a list of shadowed outer-level local definitions
387 to be restored when this level is popped.
388 Each link is a TREE_LIST whose TREE_PURPOSE is an identifier and
389 whose TREE_VALUE is its old definition (a kind of ..._DECL node). */
390 tree shadowed;
392 /* For each level (except not the global one),
393 a chain of BLOCK nodes for all the levels
394 that were entered and exited one level down. */
395 tree blocks;
397 /* The BLOCK node for this level, if one has been preallocated.
398 If 0, the BLOCK is allocated (if needed) when the level is popped. */
399 tree this_block;
401 /* The binding level which this one is contained in (inherits from). */
402 struct scope *level_chain;
404 /* Nonzero for a level that corresponds to a module. */
405 char module_flag;
407 /* Zero means called from backend code. */
408 char two_pass;
410 /* The modules that are directly enclosed by this scope
411 are chained together. */
412 struct scope* first_child_module;
413 struct scope** tail_child_module;
414 struct scope* next_sibling_module;
417 /* The outermost binding level, for pre-defined (builtin) names. */
419 static struct scope builtin_scope = {
420 NULL, NULL, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
421 NULL_TREE, NULL_TREE, NULL, 0, 0, NULL, NULL, NULL};
423 struct scope *global_scope;
425 /* The binding level currently in effect. */
427 static struct scope *current_scope = &builtin_scope;
429 /* The most recently seen scope. */
430 struct scope *last_scope = &builtin_scope;
432 /* Binding level structures are initialized by copying this one. */
434 static struct scope clear_scope = {
435 NULL, NULL, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE,
436 NULL_TREE, NULL_TREE, NULL, 0, 0, NULL, NULL, NULL};
438 /* Chain of decls accessible through IDENTIFIER_OUTER_VALUE.
439 Decls with the same DECL_NAME are adjacent in the chain. */
441 static tree outer_decls = NULL_TREE;
443 /* C-specific option variables. */
445 /* Nonzero means allow type mismatches in conditional expressions;
446 just make their values `void'. */
448 int flag_cond_mismatch;
450 /* Nonzero means give `double' the same size as `float'. */
452 int flag_short_double;
454 /* Nonzero means don't recognize the keyword `asm'. */
456 int flag_no_asm;
458 /* Nonzero means don't recognize any builtin functions. */
460 int flag_no_builtin;
462 /* Nonzero means don't recognize the non-ANSI builtin functions.
463 -ansi sets this. */
465 int flag_no_nonansi_builtin;
467 /* Nonzero means do some things the same way PCC does. */
469 int flag_traditional;
471 /* Nonzero means to allow single precision math even if we're generally
472 being traditional. */
473 int flag_allow_single_precision = 0;
475 /* Nonzero means to treat bitfields as signed unless they say `unsigned'. */
477 int flag_signed_bitfields = 1;
478 int explicit_flag_signed_bitfields = 0;
480 /* Nonzero means warn about implicit declarations. */
482 int warn_implicit;
484 /* Nonzero means give string constants the type `const char *'
485 to get extra warnings from them. These warnings will be too numerous
486 to be useful, except in thoroughly ANSIfied programs. */
488 int warn_write_strings;
490 /* Nonzero means warn about pointer casts that can drop a type qualifier
491 from the pointer target type. */
493 int warn_cast_qual;
495 /* Nonzero means warn about sizeof(function) or addition/subtraction
496 of function pointers. */
498 int warn_pointer_arith;
500 /* Nonzero means warn for non-prototype function decls
501 or non-prototyped defs without previous prototype. */
503 int warn_strict_prototypes;
505 /* Nonzero means warn for any global function def
506 without separate previous prototype decl. */
508 int warn_missing_prototypes;
510 /* Nonzero means warn about multiple (redundant) decls for the same single
511 variable or function. */
513 int warn_redundant_decls = 0;
515 /* Nonzero means warn about extern declarations of objects not at
516 file-scope level and about *all* declarations of functions (whether
517 extern or static) not at file-scope level. Note that we exclude
518 implicit function declarations. To get warnings about those, use
519 -Wimplicit. */
521 int warn_nested_externs = 0;
523 /* Warn about a subscript that has type char. */
525 int warn_char_subscripts = 0;
527 /* Warn if a type conversion is done that might have confusing results. */
529 int warn_conversion;
531 /* Warn if adding () is suggested. */
533 int warn_parentheses;
535 /* Warn if initializer is not completely bracketed. */
537 int warn_missing_braces;
539 /* Define the special tree codes that we use. */
541 /* Table indexed by tree code giving a string containing a character
542 classifying the tree code. Possibilities are
543 t, d, s, c, r, <, 1 and 2. See ch-tree.def for details. */
545 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
547 const char chill_tree_code_type[] = {
548 'x',
549 #include "ch-tree.def"
551 #undef DEFTREECODE
553 /* Table indexed by tree code giving number of expression
554 operands beyond the fixed part of the node structure.
555 Not used for types or decls. */
557 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
559 int chill_tree_code_length[] = {
561 #include "ch-tree.def"
563 #undef DEFTREECODE
566 /* Names of tree components.
567 Used for printing out the tree and error messages. */
568 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
570 const char *chill_tree_code_name[] = {
571 "@@dummy",
572 #include "ch-tree.def"
574 #undef DEFTREECODE
576 /* Nonzero means `$' can be in an identifier. */
577 #ifndef DOLLARS_IN_IDENTIFIERS
578 #define DOLLARS_IN_IDENTIFIERS 0
579 #endif
580 int dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 1;
582 /* An identifier that is used internally to indicate
583 an "ALL" prefix for granting or seizing.
584 We use "*" rather than the external name "ALL", partly for convenience,
585 and partly to avoid case senstivity problems. */
587 tree ALL_POSTFIX;
589 void
590 allocate_lang_decl (t)
591 tree t ATTRIBUTE_UNUSED;
593 /* Nothing needed */
596 void
597 copy_lang_decl (node)
598 tree node ATTRIBUTE_UNUSED;
600 /* Nothing needed */
603 tree
604 build_lang_decl (code, name, type)
605 enum chill_tree_code code;
606 tree name;
607 tree type;
609 return build_decl (code, name, type);
612 /* Decode the string P as a language-specific option for C.
613 Return the number of strings consumed for a valid option.
614 Return 0 for an invalid option. */
617 c_decode_option (argc, argv)
618 int argc ATTRIBUTE_UNUSED;
619 char **argv;
621 char *p = argv[0];
622 if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional"))
624 flag_traditional = 1;
625 flag_writable_strings = 1;
626 #if DOLLARS_IN_IDENTIFIERS > 0
627 dollars_in_ident = 1;
628 #endif
630 else if (!strcmp (p, "-fnotraditional") || !strcmp (p, "-fno-traditional"))
632 flag_traditional = 0;
633 flag_writable_strings = 0;
634 dollars_in_ident = DOLLARS_IN_IDENTIFIERS > 1;
636 else if (!strcmp (p, "-fsigned-char"))
637 flag_signed_char = 1;
638 else if (!strcmp (p, "-funsigned-char"))
639 flag_signed_char = 0;
640 else if (!strcmp (p, "-fno-signed-char"))
641 flag_signed_char = 0;
642 else if (!strcmp (p, "-fno-unsigned-char"))
643 flag_signed_char = 1;
644 else if (!strcmp (p, "-fsigned-bitfields")
645 || !strcmp (p, "-fno-unsigned-bitfields"))
647 flag_signed_bitfields = 1;
648 explicit_flag_signed_bitfields = 1;
650 else if (!strcmp (p, "-funsigned-bitfields")
651 || !strcmp (p, "-fno-signed-bitfields"))
653 flag_signed_bitfields = 0;
654 explicit_flag_signed_bitfields = 1;
656 else if (!strcmp (p, "-fshort-enums"))
657 flag_short_enums = 1;
658 else if (!strcmp (p, "-fno-short-enums"))
659 flag_short_enums = 0;
660 else if (!strcmp (p, "-fcond-mismatch"))
661 flag_cond_mismatch = 1;
662 else if (!strcmp (p, "-fno-cond-mismatch"))
663 flag_cond_mismatch = 0;
664 else if (!strcmp (p, "-fshort-double"))
665 flag_short_double = 1;
666 else if (!strcmp (p, "-fno-short-double"))
667 flag_short_double = 0;
668 else if (!strcmp (p, "-fasm"))
669 flag_no_asm = 0;
670 else if (!strcmp (p, "-fno-asm"))
671 flag_no_asm = 1;
672 else if (!strcmp (p, "-fbuiltin"))
673 flag_no_builtin = 0;
674 else if (!strcmp (p, "-fno-builtin"))
675 flag_no_builtin = 1;
676 else if (!strcmp (p, "-ansi"))
677 flag_no_asm = 1, flag_no_nonansi_builtin = 1, dollars_in_ident = 0;
678 else if (!strcmp (p, "-Wimplicit"))
679 warn_implicit = 1;
680 else if (!strcmp (p, "-Wno-implicit"))
681 warn_implicit = 0;
682 else if (!strcmp (p, "-Wwrite-strings"))
683 warn_write_strings = 1;
684 else if (!strcmp (p, "-Wno-write-strings"))
685 warn_write_strings = 0;
686 else if (!strcmp (p, "-Wcast-qual"))
687 warn_cast_qual = 1;
688 else if (!strcmp (p, "-Wno-cast-qual"))
689 warn_cast_qual = 0;
690 else if (!strcmp (p, "-Wpointer-arith"))
691 warn_pointer_arith = 1;
692 else if (!strcmp (p, "-Wno-pointer-arith"))
693 warn_pointer_arith = 0;
694 else if (!strcmp (p, "-Wstrict-prototypes"))
695 warn_strict_prototypes = 1;
696 else if (!strcmp (p, "-Wno-strict-prototypes"))
697 warn_strict_prototypes = 0;
698 else if (!strcmp (p, "-Wmissing-prototypes"))
699 warn_missing_prototypes = 1;
700 else if (!strcmp (p, "-Wno-missing-prototypes"))
701 warn_missing_prototypes = 0;
702 else if (!strcmp (p, "-Wredundant-decls"))
703 warn_redundant_decls = 1;
704 else if (!strcmp (p, "-Wno-redundant-decls"))
705 warn_redundant_decls = 0;
706 else if (!strcmp (p, "-Wnested-externs"))
707 warn_nested_externs = 1;
708 else if (!strcmp (p, "-Wno-nested-externs"))
709 warn_nested_externs = 0;
710 else if (!strcmp (p, "-Wchar-subscripts"))
711 warn_char_subscripts = 1;
712 else if (!strcmp (p, "-Wno-char-subscripts"))
713 warn_char_subscripts = 0;
714 else if (!strcmp (p, "-Wconversion"))
715 warn_conversion = 1;
716 else if (!strcmp (p, "-Wno-conversion"))
717 warn_conversion = 0;
718 else if (!strcmp (p, "-Wparentheses"))
719 warn_parentheses = 1;
720 else if (!strcmp (p, "-Wno-parentheses"))
721 warn_parentheses = 0;
722 else if (!strcmp (p, "-Wreturn-type"))
723 warn_return_type = 1;
724 else if (!strcmp (p, "-Wno-return-type"))
725 warn_return_type = 0;
726 else if (!strcmp (p, "-Wcomment"))
727 ; /* cpp handles this one. */
728 else if (!strcmp (p, "-Wno-comment"))
729 ; /* cpp handles this one. */
730 else if (!strcmp (p, "-Wcomments"))
731 ; /* cpp handles this one. */
732 else if (!strcmp (p, "-Wno-comments"))
733 ; /* cpp handles this one. */
734 else if (!strcmp (p, "-Wtrigraphs"))
735 ; /* cpp handles this one. */
736 else if (!strcmp (p, "-Wno-trigraphs"))
737 ; /* cpp handles this one. */
738 else if (!strcmp (p, "-Wimport"))
739 ; /* cpp handles this one. */
740 else if (!strcmp (p, "-Wno-import"))
741 ; /* cpp handles this one. */
742 else if (!strcmp (p, "-Wmissing-braces"))
743 warn_missing_braces = 1;
744 else if (!strcmp (p, "-Wno-missing-braces"))
745 warn_missing_braces = 0;
746 else if (!strcmp (p, "-Wall"))
748 extra_warnings = 1;
749 /* We save the value of warn_uninitialized, since if they put
750 -Wuninitialized on the command line, we need to generate a
751 warning about not using it without also specifying -O. */
752 if (warn_uninitialized != 1)
753 warn_uninitialized = 2;
754 warn_implicit = 1;
755 warn_return_type = 1;
756 set_Wunused (1);
757 warn_char_subscripts = 1;
758 warn_parentheses = 1;
759 warn_missing_braces = 1;
761 else
762 return 0;
764 return 1;
767 /* Hooks for print_node. */
769 void
770 print_lang_decl (file, node, indent)
771 FILE *file;
772 tree node;
773 int indent;
775 indent_to (file, indent + 3);
776 fputs ("nesting_level ", file);
777 fprintf (file, HOST_WIDE_INT_PRINT_DEC, DECL_NESTING_LEVEL (node));
778 fputs (" ", file);
779 if (DECL_WEAK_NAME (node))
780 fprintf (file, "weak_name ");
781 if (CH_DECL_SIGNAL (node))
782 fprintf (file, "decl_signal ");
783 print_node (file, "tasking_code",
784 (tree)DECL_TASKING_CODE_DECL (node), indent + 4);
788 void
789 print_lang_type (file, node, indent)
790 FILE *file;
791 tree node;
792 int indent;
794 tree temp;
796 indent_to (file, indent + 3);
797 if (CH_IS_BUFFER_MODE (node))
798 fprintf (file, "buffer_mode ");
799 if (CH_IS_EVENT_MODE (node))
800 fprintf (file, "event_mode ");
802 if (CH_IS_EVENT_MODE (node) || CH_IS_BUFFER_MODE (node))
804 temp = max_queue_size (node);
805 if (temp)
806 print_node_brief (file, "qsize", temp, indent + 4);
810 void
811 print_lang_identifier (file, node, indent)
812 FILE *file;
813 tree node;
814 int indent;
816 print_node (file, "local", IDENTIFIER_LOCAL_VALUE (node), indent + 4);
817 print_node (file, "outer", IDENTIFIER_OUTER_VALUE (node), indent + 4);
818 print_node (file, "implicit", IDENTIFIER_IMPLICIT_DECL (node), indent + 4);
819 print_node (file, "error locus", IDENTIFIER_ERROR_LOCUS (node), indent + 4);
820 print_node (file, "signal_dest", IDENTIFIER_SIGNAL_DEST (node), indent + 4);
821 indent_to (file, indent + 3);
822 if (IDENTIFIER_SIGNAL_DATA(node))
823 fprintf (file, "signal_data ");
826 /* initialise non-value struct */
828 static int
829 init_nonvalue_struct (expr)
830 tree expr;
832 tree type = TREE_TYPE (expr);
833 tree field;
834 int res = 0;
836 if (CH_IS_BUFFER_MODE (type))
838 expand_expr_stmt (
839 build_chill_modify_expr (
840 build_component_ref (expr, get_identifier ("__buffer_data")),
841 null_pointer_node));
842 return 1;
844 else if (CH_IS_EVENT_MODE (type))
846 expand_expr_stmt (
847 build_chill_modify_expr (
848 build_component_ref (expr, get_identifier ("__event_data")),
849 null_pointer_node));
850 return 1;
852 else if (CH_IS_ASSOCIATION_MODE (type))
854 expand_expr_stmt (
855 build_chill_modify_expr (expr,
856 chill_convert_for_assignment (type, association_init_value,
857 "association")));
858 return 1;
860 else if (CH_IS_ACCESS_MODE (type))
862 init_access_location (expr, type);
863 return 1;
865 else if (CH_IS_TEXT_MODE (type))
867 init_text_location (expr, type);
868 return 1;
871 for (field = TYPE_FIELDS (type); field != NULL_TREE; field = TREE_CHAIN (field))
873 type = TREE_TYPE (field);
874 if (CH_TYPE_NONVALUE_P (type))
876 tree exp = build_component_ref (expr, DECL_NAME (field));
877 if (TREE_CODE (type) == RECORD_TYPE)
878 res |= init_nonvalue_struct (exp);
879 else if (TREE_CODE (type) == ARRAY_TYPE)
880 res |= init_nonvalue_array (exp);
883 return res;
886 /* initialize non-value array */
887 /* do it with DO FOR unique-id IN expr; ... OD; */
888 static int
889 init_nonvalue_array (expr)
890 tree expr;
892 tree tmpvar = get_unique_identifier ("NONVALINIT");
893 tree type;
894 int res = 0;
896 push_loop_block ();
897 build_loop_iterator (tmpvar, expr, NULL_TREE, NULL_TREE, 0, 1, 0);
898 nonvalue_begin_loop_scope ();
899 build_loop_start (NULL_TREE);
900 tmpvar = lookup_name (tmpvar);
901 type = TREE_TYPE (tmpvar);
902 if (CH_TYPE_NONVALUE_P (type))
904 if (TREE_CODE (type) == RECORD_TYPE)
905 res |= init_nonvalue_struct (tmpvar);
906 else if (TREE_CODE (type) == ARRAY_TYPE)
907 res |= init_nonvalue_array (tmpvar);
909 build_loop_end ();
910 nonvalue_end_loop_scope ();
911 pop_loop_block ();
912 return res;
915 /* This excessive piece of code sets DECL_NESTING_LEVEL (DECL) to LEVEL. */
917 static void
918 set_nesting_level (decl, level)
919 tree decl;
920 int level;
922 static tree *small_ints = NULL;
923 static int max_small_ints = 0;
925 if (level < 0)
926 decl->decl.vindex = NULL_TREE;
927 else
929 if (level >= max_small_ints)
931 int new_max = level + 20;
932 if (small_ints == NULL)
933 small_ints = (tree*)xmalloc (new_max * sizeof(tree));
934 else
935 small_ints = (tree*)xrealloc (small_ints, new_max * sizeof(tree));
936 while (max_small_ints < new_max)
937 small_ints[max_small_ints++] = NULL_TREE;
939 if (small_ints[level] == NULL_TREE)
941 push_obstacks (&permanent_obstack, &permanent_obstack);
942 small_ints[level] = build_int_2 (level, 0);
943 pop_obstacks ();
945 /* set DECL_NESTING_LEVEL */
946 decl->decl.vindex = small_ints[level];
950 /* OPT_EXTERNAL is non-zero when the declaration is at module level.
951 * OPT_EXTERNAL == 2 means implicitly grant it.
953 void
954 do_decls (names, type, opt_static, lifetime_bound, opt_init, opt_external)
955 tree names;
956 tree type;
957 int opt_static;
958 int lifetime_bound;
959 tree opt_init;
960 int opt_external;
962 if (names == NULL_TREE || TREE_CODE (names) == TREE_LIST)
964 for (; names != NULL_TREE; names = TREE_CHAIN (names))
965 do_decl (TREE_VALUE (names), type, opt_static, lifetime_bound,
966 opt_init, opt_external);
968 else if (TREE_CODE (names) != ERROR_MARK)
969 do_decl (names, type, opt_static, lifetime_bound, opt_init, opt_external);
972 tree
973 do_decl (name, type, is_static, lifetime_bound, opt_init, opt_external)
974 tree name, type;
975 int is_static;
976 int lifetime_bound;
977 tree opt_init;
978 int opt_external;
980 tree decl;
982 if (current_function_decl == global_function_decl
983 && ! lifetime_bound /*&& opt_init != NULL_TREE*/)
984 seen_action = 1;
986 if (pass < 2)
988 push_obstacks (&permanent_obstack, &permanent_obstack);
989 decl = make_node (VAR_DECL);
990 DECL_NAME (decl) = name;
991 TREE_TYPE (decl) = type;
992 DECL_ASSEMBLER_NAME (decl) = name;
994 /* Try to put things in common when possible.
995 Tasking variables must go into common. */
996 DECL_COMMON (decl) = 1;
997 DECL_EXTERNAL (decl) = opt_external > 0;
998 TREE_PUBLIC (decl) = opt_external > 0;
999 TREE_STATIC (decl) = is_static;
1001 if (pass == 0)
1003 /* We have to set this here, since we build the decl w/o
1004 calling `build_decl'. */
1005 DECL_INITIAL (decl) = opt_init;
1006 pushdecl (decl);
1007 finish_decl (decl);
1009 else
1011 save_decl (decl);
1012 pop_obstacks ();
1014 DECL_INITIAL (decl) = opt_init;
1015 if (opt_external > 1 || in_pseudo_module)
1016 push_granted (DECL_NAME (decl), decl);
1018 else /* pass == 2 */
1020 tree temp = NULL_TREE;
1021 int init_it = 0;
1023 decl = get_next_decl ();
1025 if (name != DECL_NAME (decl))
1026 abort ();
1028 type = TREE_TYPE (decl);
1030 push_obstacks_nochange ();
1031 if (TYPE_READONLY_PROPERTY (type))
1033 if (CH_TYPE_NONVALUE_P (type))
1035 error_with_decl (decl, "`%s' must not be declared readonly");
1036 opt_init = NULL_TREE; /* prevent subsequent errors */
1038 else if (opt_init == NULL_TREE && !opt_external)
1039 error("declaration of readonly variable without initialization");
1041 TREE_READONLY (decl) = TYPE_READONLY (type);
1043 if (!opt_init && chill_varying_type_p (type))
1045 tree fixed_part_type = TREE_TYPE (TREE_CHAIN (TYPE_FIELDS (type)));
1046 if (fixed_part_type != NULL_TREE && TREE_CODE (fixed_part_type) != ERROR_MARK)
1048 if (CH_CHARS_TYPE_P (fixed_part_type))
1049 opt_init = build_chill_string (0, "");
1050 else
1051 opt_init = build_nt (CONSTRUCTOR, NULL_TREE, NULL_TREE);
1052 lifetime_bound = 1;
1056 if (opt_init)
1058 if (CH_TYPE_NONVALUE_P (type))
1060 error_with_decl (decl,
1061 "no initialisation allowed for `%s'");
1062 temp = NULL_TREE;
1064 else if (TREE_CODE (type) == REFERENCE_TYPE)
1065 { /* A loc-identity declaration */
1066 if (! CH_LOCATION_P (opt_init))
1068 error_with_decl (decl,
1069 "value for loc-identity `%s' is not a location");
1070 temp = NULL_TREE;
1072 else if (! CH_READ_COMPATIBLE (TREE_TYPE (type),
1073 TREE_TYPE (opt_init)))
1075 error_with_decl (decl,
1076 "location for `%s' not read-compatible");
1077 temp = NULL_TREE;
1079 else
1080 temp = convert (type, opt_init);
1082 else
1083 { /* Normal location declaration */
1084 char place[80];
1085 sprintf (place, "`%.60s' initializer",
1086 IDENTIFIER_POINTER (DECL_NAME (decl)));
1087 temp = chill_convert_for_assignment (type, opt_init, place);
1090 else if (CH_TYPE_NONVALUE_P (type))
1092 temp = NULL_TREE;
1093 init_it = 1;
1095 DECL_INITIAL (decl) = NULL_TREE;
1097 if (temp != NULL_TREE && TREE_CODE (temp) != ERROR_MARK)
1099 /* The same for stack variables (assuming no nested modules). */
1100 if (lifetime_bound || !is_static)
1102 if (is_static && ! TREE_CONSTANT (temp))
1103 error_with_decl (decl, "nonconstant initializer for `%s'");
1104 else
1105 DECL_INITIAL (decl) = temp;
1108 finish_decl (decl);
1109 /* Initialize the variable unless initialized statically. */
1110 if ((!is_static || ! lifetime_bound) &&
1111 temp != NULL_TREE && TREE_CODE (temp) != ERROR_MARK)
1113 int was_used = TREE_USED (decl);
1114 emit_line_note (input_filename, lineno);
1115 expand_expr_stmt (build_chill_modify_expr (decl, temp));
1116 /* Don't let the initialization count as "using" the variable. */
1117 TREE_USED (decl) = was_used;
1118 if (current_function_decl == global_function_decl)
1119 build_constructor = 1;
1121 else if (init_it && TREE_CODE (type) != ERROR_MARK)
1123 /* Initialize variables with non-value type */
1124 int was_used = TREE_USED (decl);
1125 int something_initialised = 0;
1127 emit_line_note (input_filename, lineno);
1128 if (TREE_CODE (type) == RECORD_TYPE)
1129 something_initialised = init_nonvalue_struct (decl);
1130 else if (TREE_CODE (type) == ARRAY_TYPE)
1131 something_initialised = init_nonvalue_array (decl);
1132 if (! something_initialised)
1134 error ("do_decl: internal error: don't know what to initialize");
1135 abort ();
1137 /* Don't let the initialization count as "using" the variable. */
1138 TREE_USED (decl) = was_used;
1139 if (current_function_decl == global_function_decl)
1140 build_constructor = 1;
1143 return decl;
1147 * ARGTYPES is a tree_list of formal argument types. TREE_VALUE
1148 * is the type tree for each argument, while the attribute is in
1149 * TREE_PURPOSE.
1151 tree
1152 build_chill_function_type (return_type, argtypes, exceptions, recurse_p)
1153 tree return_type, argtypes, exceptions, recurse_p;
1155 tree ftype, arg;
1157 if (exceptions != NULL_TREE)
1159 /* if we have exceptions we add 2 arguments, callers filename
1160 and linenumber. These arguments will be added automatically
1161 when calling a function which may raise exceptions. */
1162 argtypes = chainon (argtypes,
1163 build_tree_list (NULL_TREE, ridpointers[(int) RID_PTR]));
1164 argtypes = chainon (argtypes,
1165 build_tree_list (NULL_TREE, ridpointers[(int) RID_LONG]));
1168 /* Indicate the argument list is complete. */
1169 argtypes = chainon (argtypes,
1170 build_tree_list (NULL_TREE, void_type_node));
1172 /* INOUT and OUT parameters must be a REFERENCE_TYPE since
1173 we'll be passing a temporary's address at call time. */
1174 for (arg = argtypes; arg; arg = TREE_CHAIN (arg))
1175 if (TREE_PURPOSE (arg) == ridpointers[(int) RID_LOC]
1176 || TREE_PURPOSE (arg) == ridpointers[(int) RID_OUT]
1177 || TREE_PURPOSE (arg) == ridpointers[(int) RID_INOUT]
1179 TREE_VALUE (arg) =
1180 build_chill_reference_type (TREE_VALUE (arg));
1182 /* Cannot use build_function_type, because if does hash-canonlicalization. */
1183 ftype = make_node (FUNCTION_TYPE);
1184 TREE_TYPE (ftype) = return_type ? return_type : void_type_node ;
1185 TYPE_ARG_TYPES (ftype) = argtypes;
1187 if (exceptions)
1188 ftype = build_exception_variant (ftype, exceptions);
1190 if (recurse_p)
1191 sorry ("RECURSIVE PROCs");
1193 return ftype;
1197 * ARGTYPES is a tree_list of formal argument types.
1199 tree
1200 push_extern_function (name, typespec, argtypes, exceptions, granting)
1201 tree name, typespec, argtypes, exceptions;
1202 int granting ATTRIBUTE_UNUSED;/*If 0 do pushdecl(); if 1 do push_granted()*/
1204 tree ftype, fndecl;
1206 push_obstacks_nochange ();
1207 end_temporary_allocation ();
1209 if (pass < 2)
1211 ftype = build_chill_function_type (typespec, argtypes,
1212 exceptions, NULL_TREE);
1214 fndecl = build_decl (FUNCTION_DECL, name, ftype);
1216 DECL_EXTERNAL(fndecl) = 1;
1217 TREE_STATIC (fndecl) = 1;
1218 TREE_PUBLIC (fndecl) = 1;
1219 if (pass == 0)
1221 pushdecl (fndecl);
1222 finish_decl (fndecl);
1224 else
1226 save_decl (fndecl);
1227 pop_obstacks ();
1229 make_function_rtl (fndecl);
1231 else
1233 fndecl = get_next_decl ();
1234 finish_decl (fndecl);
1236 #if 0
1238 if (granting)
1239 push_granted (name, decl);
1240 else
1241 pushdecl(decl);
1242 #endif
1243 return fndecl;
1248 void
1249 push_extern_process (name, argtypes, exceptions, granting)
1250 tree name, argtypes, exceptions;
1251 int granting;
1253 tree decl, func, arglist;
1255 push_obstacks_nochange ();
1256 end_temporary_allocation ();
1258 if (pass < 2)
1260 tree proc_struct = make_process_struct (name, argtypes);
1261 arglist = (argtypes == NULL_TREE) ? NULL_TREE :
1262 tree_cons (NULL_TREE,
1263 build_chill_pointer_type (proc_struct), NULL_TREE);
1265 else
1266 arglist = NULL_TREE;
1268 func = push_extern_function (name, NULL_TREE, arglist,
1269 exceptions, granting);
1271 /* declare the code variable */
1272 decl = generate_tasking_code_variable (name, &process_type, 1);
1273 CH_DECL_PROCESS (func) = 1;
1274 /* remember the code variable in the function decl */
1275 DECL_TASKING_CODE_DECL (func) = (struct lang_decl *)decl;
1277 add_taskstuff_to_list (decl, "_TT_Process", NULL_TREE, func, NULL_TREE);
1280 void
1281 push_extern_signal (signame, sigmodelist, optsigdest)
1282 tree signame, sigmodelist, optsigdest;
1284 tree decl, sigtype;
1286 push_obstacks_nochange ();
1287 end_temporary_allocation ();
1289 sigtype =
1290 build_signal_struct_type (signame, sigmodelist, optsigdest);
1292 /* declare the code variable outside the process */
1293 decl = generate_tasking_code_variable (signame, &signal_code, 1);
1294 add_taskstuff_to_list (decl, "_TT_Signal", NULL_TREE, sigtype, NULL_TREE);
1297 void
1298 print_mode (mode)
1299 tree mode;
1301 while (mode != NULL_TREE)
1303 switch (TREE_CODE (mode))
1305 case POINTER_TYPE:
1306 printf (" REF ");
1307 mode = TREE_TYPE (mode);
1308 break;
1309 case INTEGER_TYPE:
1310 case REAL_TYPE:
1311 printf (" %s ", IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (mode))));
1312 mode = NULL_TREE;
1313 break;
1314 case ARRAY_TYPE:
1316 tree itype = TYPE_DOMAIN (mode);
1317 if (CH_STRING_TYPE_P (mode))
1319 fputs (" STRING (", stdout);
1320 printf (HOST_WIDE_INT_PRINT_DEC,
1321 TREE_INT_CST_LOW (TYPE_MAX_VALUE (itype)));
1322 fputs (") OF ", stdout);
1324 else
1326 fputs (" ARRAY (", stdout);
1327 printf (HOST_WIDE_INT_PRINT_DEC,
1328 TREE_INT_CST_LOW (TYPE_MIN_VALUE (itype)));
1329 fputs (":", stdout);
1330 printf (HOST_WIDE_INT_PRINT_DEC,
1331 TREE_INT_CST_LOW (TYPE_MAX_VALUE (itype)));
1332 fputs (") OF ", stdout);
1334 mode = TREE_TYPE (mode);
1335 break;
1337 case RECORD_TYPE:
1339 tree fields = TYPE_FIELDS (mode);
1340 printf (" RECORD (");
1341 while (fields != NULL_TREE)
1343 printf (" %s:", IDENTIFIER_POINTER (DECL_NAME (fields)));
1344 print_mode (TREE_TYPE (fields));
1345 if (TREE_CHAIN (fields))
1346 printf (",");
1347 fields = TREE_CHAIN (fields);
1349 printf (")");
1350 mode = NULL_TREE;
1351 break;
1353 default:
1354 abort ();
1359 tree
1360 chill_munge_params (nodes, type, attr)
1361 tree nodes, type, attr;
1363 tree node;
1364 if (pass == 1)
1366 /* Convert the list of identifiers to a list of types. */
1367 for (node = nodes; node != NULL_TREE; node = TREE_CHAIN (node))
1369 TREE_VALUE (node) = type; /* this was the identifier node */
1370 TREE_PURPOSE (node) = attr;
1373 return nodes;
1376 /* Push the declarations described by SYN_DEFS into the current scope. */
1377 void
1378 push_syndecl (name, mode, value)
1379 tree name, mode, value;
1381 if (pass == 1)
1383 tree decl = make_node (CONST_DECL);
1384 DECL_NAME (decl) = name;
1385 DECL_ASSEMBLER_NAME (decl) = name;
1386 TREE_TYPE (decl) = mode;
1387 DECL_INITIAL (decl) = value;
1388 TREE_READONLY (decl) = 1;
1389 save_decl (decl);
1390 if (in_pseudo_module)
1391 push_granted (DECL_NAME (decl), decl);
1393 else /* pass == 2 */
1394 get_next_decl ();
1399 /* Push the declarations described by (MODENAME,MODE) into the current scope.
1400 MAKE_NEWMODE is 1 for NEWMODE, 0 for SYNMODE, and
1401 -1 for internal use (in which case the mode does not need to be copied). */
1403 tree
1404 push_modedef (modename, mode, make_newmode)
1405 tree modename;
1406 tree mode; /* ignored if pass==2. */
1407 int make_newmode;
1409 tree newdecl, newmode;
1411 if (pass == 1)
1413 /* FIXME: need to check here for SYNMODE fred fred; */
1414 push_obstacks (&permanent_obstack, &permanent_obstack);
1416 newdecl = build_lang_decl (TYPE_DECL, modename, mode);
1418 if (make_newmode >= 0)
1420 newmode = make_node (LANG_TYPE);
1421 TREE_TYPE (newmode) = mode;
1422 TREE_TYPE (newdecl) = newmode;
1423 TYPE_NAME (newmode) = newdecl;
1424 if (make_newmode > 0)
1425 CH_NOVELTY (newmode) = newdecl;
1428 save_decl (newdecl);
1429 pop_obstacks ();
1432 else /* pass == 2 */
1434 /* FIXME: need to check here for SYNMODE fred fred; */
1435 newdecl = get_next_decl ();
1436 if (DECL_NAME (newdecl) != modename)
1437 abort ();
1438 if (TREE_CODE (TREE_TYPE (newdecl)) != ERROR_MARK)
1440 /* ASSOCIATION, ACCESS, TEXT, BUFFER, and EVENT must not be READOnly */
1441 if (TREE_READONLY (TREE_TYPE (newdecl)) &&
1442 (CH_IS_ASSOCIATION_MODE (TREE_TYPE (newdecl)) ||
1443 CH_IS_ACCESS_MODE (TREE_TYPE (newdecl)) ||
1444 CH_IS_TEXT_MODE (TREE_TYPE (newdecl)) ||
1445 CH_IS_BUFFER_MODE (TREE_TYPE (newdecl)) ||
1446 CH_IS_EVENT_MODE (TREE_TYPE (newdecl))))
1447 error_with_decl (newdecl, "`%s' must not be READonly");
1448 rest_of_decl_compilation (newdecl, NULL_PTR,
1449 global_bindings_p (), 0);
1452 return newdecl;
1455 /* Return a chain of FIELD_DECLs for the names in NAMELIST. All of
1456 of type TYPE. When NAMELIST is passed in from the parser, it is
1457 in reverse order.
1458 LAYOUT is (NULL_TREE, integer_one_node, integer_zero_node, tree_list),
1459 meaning (default, pack, nopack, POS (...) ). */
1461 tree
1462 grok_chill_fixedfields (namelist, type, layout)
1463 tree namelist, type;
1464 tree layout;
1466 tree decls = NULL_TREE;
1468 if (layout != NULL_TREE && TREE_CHAIN (namelist) != NULL_TREE)
1470 if (layout != integer_one_node && layout != integer_zero_node)
1472 layout = NULL_TREE;
1473 error ("POS may not be specified for a list of field declarations");
1477 /* we build the chain of FIELD_DECLs backwards, effectively
1478 unreversing the reversed names in NAMELIST. */
1479 for (; namelist; namelist = TREE_CHAIN (namelist))
1481 tree decl = build_decl (FIELD_DECL,
1482 TREE_VALUE (namelist), type);
1483 DECL_INITIAL (decl) = layout;
1484 TREE_CHAIN (decl) = decls;
1485 decls = decl;
1488 return decls;
1491 struct tree_pair
1493 tree value;
1494 tree decl;
1497 static int label_value_cmp PARAMS ((struct tree_pair *,
1498 struct tree_pair *));
1500 /* Function to help qsort sort variant labels by value order. */
1501 static int
1502 label_value_cmp (x, y)
1503 struct tree_pair *x, *y;
1505 return TREE_INT_CST_LOW (x->value) - TREE_INT_CST_LOW (y->value);
1508 static tree
1509 make_chill_variants (tagfields, body, variantelse)
1510 tree tagfields;
1511 tree body;
1512 tree variantelse;
1514 tree utype;
1515 tree first = NULL_TREE;
1516 for (; body; body = TREE_CHAIN (body))
1518 tree decls = TREE_VALUE (body);
1519 tree labellist = TREE_PURPOSE (body);
1521 if (labellist != NULL_TREE
1522 && TREE_CODE (TREE_VALUE (labellist)) == TREE_LIST
1523 && TREE_VALUE (TREE_VALUE (labellist)) == case_else_node
1524 && TREE_CHAIN (labellist) == NULL_TREE)
1526 if (variantelse)
1527 error ("(ELSE) case label as well as ELSE variant");
1528 variantelse = decls;
1530 else
1532 tree rtype = start_struct (RECORD_TYPE, NULL_TREE);
1533 rtype = finish_struct (rtype, decls);
1535 first = chainon (first, build_decl (FIELD_DECL, NULL_TREE, rtype));
1537 TYPE_TAG_VALUES (rtype) = labellist;
1541 if (variantelse != NULL_TREE)
1543 tree rtype = start_struct (RECORD_TYPE, NULL_TREE);
1544 rtype = finish_struct (rtype, variantelse);
1545 first = chainon (first,
1546 build_decl (FIELD_DECL,
1547 ELSE_VARIANT_NAME, rtype));
1550 utype = start_struct (UNION_TYPE, NULL_TREE);
1551 utype = finish_struct (utype, first);
1552 TYPE_TAGFIELDS (utype) = tagfields;
1553 return utype;
1556 tree
1557 layout_chill_variants (utype)
1558 tree utype;
1560 tree first = TYPE_FIELDS (utype);
1561 int nlabels, label_index = 0;
1562 struct tree_pair *label_value_array;
1563 tree decl;
1564 extern int errorcount;
1566 if (TYPE_SIZE (utype))
1567 return utype;
1569 for (decl = first; decl; decl = TREE_CHAIN (decl))
1571 tree tagfields = TYPE_TAGFIELDS (utype);
1572 tree t = TREE_TYPE (decl);
1573 tree taglist = TYPE_TAG_VALUES (t);
1574 if (DECL_NAME (decl) == ELSE_VARIANT_NAME)
1575 continue;
1576 if (tagfields == NULL_TREE)
1577 continue;
1578 for ( ; tagfields != NULL_TREE && taglist != NULL_TREE;
1579 tagfields = TREE_CHAIN (tagfields), taglist = TREE_CHAIN (taglist))
1581 tree labellist = TREE_VALUE (taglist);
1582 for (; labellist; labellist = TREE_CHAIN (labellist))
1584 int compat_error = 0;
1585 tree label_value = TREE_VALUE (labellist);
1586 if (TREE_CODE (label_value) == RANGE_EXPR)
1588 if (TREE_OPERAND (label_value, 0) != NULL_TREE)
1590 if (!CH_COMPATIBLE (TREE_OPERAND (label_value, 0),
1591 TREE_TYPE (TREE_VALUE (tagfields)))
1592 || !CH_COMPATIBLE (TREE_OPERAND (label_value, 1),
1593 TREE_TYPE (TREE_VALUE (tagfields))))
1594 compat_error = 1;
1597 else if (TREE_CODE (label_value) == TYPE_DECL)
1599 if (!CH_COMPATIBLE (label_value,
1600 TREE_TYPE (TREE_VALUE (tagfields))))
1601 compat_error = 1;
1603 else if (TREE_CODE (label_value) == INTEGER_CST)
1605 if (!CH_COMPATIBLE (label_value,
1606 TREE_TYPE (TREE_VALUE (tagfields))))
1607 compat_error = 1;
1609 if (compat_error)
1611 if (TYPE_FIELDS (t) == NULL_TREE)
1612 error ("inconsistent modes between labels and tag field");
1613 else
1614 error_with_decl (TYPE_FIELDS (t),
1615 "inconsistent modes between labels and tag field");
1619 if (tagfields != NULL_TREE)
1620 error ("too few tag labels");
1621 if (taglist != NULL_TREE)
1622 error ("too many tag labels");
1625 /* Compute the number of labels to be checked for duplicates. */
1626 nlabels = 0;
1627 for (decl = first; decl; decl = TREE_CHAIN (decl))
1629 tree t = TREE_TYPE (decl);
1630 /* Only one tag (first case_label_list) supported, for now. */
1631 tree labellist = TYPE_TAG_VALUES (t);
1632 if (labellist)
1633 labellist = TREE_VALUE (labellist);
1635 for (; labellist != NULL_TREE; labellist = TREE_CHAIN (labellist))
1636 if (TREE_CODE (TREE_VALUE (labellist)) == INTEGER_CST)
1637 nlabels++;
1640 /* Check for duplicate label values. */
1641 label_value_array = (struct tree_pair *)alloca (nlabels * sizeof (struct tree_pair));
1642 for (decl = first; decl; decl = TREE_CHAIN (decl))
1644 tree t = TREE_TYPE (decl);
1645 /* Only one tag (first case_label_list) supported, for now. */
1646 tree labellist = TYPE_TAG_VALUES (t);
1647 if (labellist)
1648 labellist = TREE_VALUE (labellist);
1650 for (; labellist != NULL_TREE; labellist = TREE_CHAIN (labellist))
1652 struct tree_pair p;
1654 tree x = TREE_VALUE (labellist);
1655 if (TREE_CODE (x) == RANGE_EXPR)
1657 if (TREE_OPERAND (x, 0) != NULL_TREE)
1659 if (TREE_CODE (TREE_OPERAND (x, 0)) != INTEGER_CST)
1660 error ("case label lower limit is not a discrete constant expression");
1661 if (TREE_CODE (TREE_OPERAND (x, 1)) != INTEGER_CST)
1662 error ("case label upper limit is not a discrete constant expression");
1664 continue;
1666 else if (TREE_CODE (x) == TYPE_DECL)
1667 continue;
1668 else if (TREE_CODE (x) == ERROR_MARK)
1669 continue;
1670 else if (TREE_CODE (x) != INTEGER_CST) /* <-- FIXME: what about CONST_DECLs? */
1672 error ("case label must be a discrete constant expression");
1673 continue;
1676 if (TREE_CODE (x) == CONST_DECL)
1677 x = DECL_INITIAL (x);
1678 if (TREE_CODE (x) != INTEGER_CST) abort ();
1679 p.value = x;
1680 p.decl = decl;
1681 if (p.decl == NULL_TREE)
1682 p.decl = TREE_VALUE (labellist);
1683 label_value_array[label_index++] = p;
1686 if (errorcount == 0)
1688 int limit;
1689 qsort (label_value_array,
1690 label_index, sizeof (struct tree_pair),
1691 (int (*) PARAMS ((const void *, const void *))) label_value_cmp);
1692 limit = label_index - 1;
1693 for (label_index = 0; label_index < limit; label_index++)
1695 if (tree_int_cst_equal (label_value_array[label_index].value,
1696 label_value_array[label_index+1].value))
1698 error_with_decl (label_value_array[label_index].decl,
1699 "variant label declared here...");
1700 error_with_decl (label_value_array[label_index+1].decl,
1701 "...is duplicated here");
1705 layout_type (utype);
1706 return utype;
1709 /* Convert a TREE_LIST of tag field names into a list of
1710 field decls, found from FIXED_FIELDS, re-using the input list. */
1712 tree
1713 lookup_tag_fields (tag_field_names, fixed_fields)
1714 tree tag_field_names;
1715 tree fixed_fields;
1717 tree list;
1718 for (list = tag_field_names; list != NULL_TREE; list = TREE_CHAIN (list))
1720 tree decl = fixed_fields;
1721 for ( ; decl != NULL_TREE; decl = TREE_CHAIN (decl))
1723 if (DECL_NAME (decl) == TREE_VALUE (list))
1725 TREE_VALUE (list) = decl;
1726 break;
1729 if (decl == NULL_TREE)
1731 error ("no field (yet) for tag %s",
1732 IDENTIFIER_POINTER (TREE_VALUE (list)));
1733 TREE_VALUE (list) = error_mark_node;
1736 return tag_field_names;
1739 /* If non-NULL, TAGFIELDS is the tag fields for this variant record.
1740 BODY is a TREE_LIST of (optlabels, fixed fields).
1741 If non-null, VARIANTELSE is a fixed field for the else part of the
1742 variant record. */
1744 tree
1745 grok_chill_variantdefs (tagfields, body, variantelse)
1746 tree tagfields, body, variantelse;
1748 tree t;
1750 t = make_chill_variants (tagfields, body, variantelse);
1751 if (pass != 1)
1752 t = layout_chill_variants (t);
1753 return build_decl (FIELD_DECL, NULL_TREE, t);
1757 In pass 1, PARMS is a list of types (with attributes).
1758 In pass 2, PARMS is a chain of PARM_DECLs.
1762 start_chill_function (label, rtype, parms, exceptlist, attrs)
1763 tree label, rtype, parms, exceptlist, attrs;
1765 tree decl, fndecl, type, result_type, func_type;
1766 int nested = current_function_decl != 0;
1767 if (pass == 1)
1769 func_type
1770 = build_chill_function_type (rtype, parms, exceptlist, 0);
1771 fndecl = build_decl (FUNCTION_DECL, label, func_type);
1773 save_decl (fndecl);
1775 /* Make the init_value nonzero so pushdecl knows this is not tentative.
1776 error_mark_node is replaced below (in poplevel) with the BLOCK. */
1777 DECL_INITIAL (fndecl) = error_mark_node;
1779 DECL_EXTERNAL (fndecl) = 0;
1781 /* This function exists in static storage.
1782 (This does not mean `static' in the C sense!) */
1783 TREE_STATIC (fndecl) = 1;
1785 for (; attrs != NULL_TREE; attrs = TREE_CHAIN (attrs))
1787 if (TREE_VALUE (attrs) == ridpointers[RID_GENERAL])
1788 CH_DECL_GENERAL (fndecl) = 1;
1789 else if (TREE_VALUE (attrs) == ridpointers[RID_SIMPLE])
1790 CH_DECL_SIMPLE (fndecl) = 1;
1791 else if (TREE_VALUE (attrs) == ridpointers[RID_RECURSIVE])
1792 CH_DECL_RECURSIVE (fndecl) = 1;
1793 else if (TREE_VALUE (attrs) == ridpointers[RID_INLINE])
1794 DECL_INLINE (fndecl) = 1;
1795 else
1796 abort ();
1799 else /* pass == 2 */
1801 fndecl = get_next_decl ();
1802 if (DECL_NAME (fndecl) != label)
1803 abort (); /* outta sync - got wrong decl */
1804 func_type = TREE_TYPE (fndecl);
1805 if (TYPE_RAISES_EXCEPTIONS (func_type) != NULL_TREE)
1807 /* In this case we have to add 2 parameters.
1808 See build_chill_function_type (pass == 1). */
1809 tree arg;
1811 arg = make_node (PARM_DECL);
1812 DECL_ASSEMBLER_NAME (arg) = DECL_NAME (arg) = get_identifier (CALLER_FILE);
1813 DECL_IGNORED_P (arg) = 1;
1814 parms = chainon (parms, arg);
1816 arg = make_node (PARM_DECL);
1817 DECL_ASSEMBLER_NAME (arg) = DECL_NAME (arg) = get_identifier (CALLER_LINE);
1818 DECL_IGNORED_P (arg) = 1;
1819 parms = chainon (parms, arg);
1823 current_function_decl = fndecl;
1824 result_type = TREE_TYPE (func_type);
1825 if (CH_TYPE_NONVALUE_P (result_type))
1826 error ("non-value mode may only returned by LOC");
1828 pushlevel (1); /* Push parameters. */
1830 if (pass == 2)
1832 DECL_ARGUMENTS (fndecl) = parms;
1833 for (decl = DECL_ARGUMENTS (fndecl), type = TYPE_ARG_TYPES (func_type);
1834 decl != NULL_TREE;
1835 decl = TREE_CHAIN (decl), type = TREE_CHAIN (type))
1837 /* check here that modes with the non-value property (like
1838 BUFFER's, EVENT's, ASSOCIATION's, ACCESS's, or TEXT's) only
1839 gets passed by LOC */
1840 tree argtype = TREE_VALUE (type);
1841 tree argattr = TREE_PURPOSE (type);
1843 if (TREE_CODE (argtype) == REFERENCE_TYPE)
1844 argtype = TREE_TYPE (argtype);
1846 if (TREE_CODE (argtype) != ERROR_MARK &&
1847 TREE_CODE_CLASS (TREE_CODE (argtype)) != 't')
1849 error_with_decl (decl, "mode of `%s' is not a mode");
1850 TREE_VALUE (type) = error_mark_node;
1853 if (CH_TYPE_NONVALUE_P (argtype) &&
1854 argattr != ridpointers[(int) RID_LOC])
1855 error_with_decl (decl, "`%s' may only be passed by LOC");
1856 TREE_TYPE (decl) = TREE_VALUE (type);
1857 DECL_ARG_TYPE (decl) = TREE_TYPE (decl);
1858 DECL_CONTEXT (decl) = fndecl;
1859 TREE_READONLY (decl) = TYPE_READONLY (argtype);
1860 layout_decl (decl, 0);
1863 pushdecllist (DECL_ARGUMENTS (fndecl), 0);
1865 DECL_RESULT (current_function_decl)
1866 = build_decl (RESULT_DECL, NULL_TREE, result_type);
1868 #if 0
1869 /* Write a record describing this function definition to the prototypes
1870 file (if requested). */
1871 gen_aux_info_record (fndecl, 1, 0, prototype);
1872 #endif
1874 if (fndecl != global_function_decl || seen_action)
1876 /* Initialize the RTL code for the function. */
1877 init_function_start (fndecl, input_filename, lineno);
1879 /* Set up parameters and prepare for return, for the function. */
1880 expand_function_start (fndecl, 0);
1883 if (!nested)
1884 /* Allocate further tree nodes temporarily during compilation
1885 of this function only. */
1886 temporary_allocation ();
1888 /* If this fcn was already referenced via a block-scope `extern' decl (or
1889 an implicit decl), propagate certain information about the usage. */
1890 if (TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (current_function_decl)))
1891 TREE_ADDRESSABLE (current_function_decl) = 1;
1894 /* Z.200 requires that formal parameter names be defined in
1895 the same block as the procedure body.
1896 We could do this by keeping boths sets of DECLs in the same
1897 scope, but we would have to be careful to not merge the
1898 two chains (e.g. DECL_ARGUEMENTS musr not contains locals).
1899 Instead, we just make sure they have the same nesting_level. */
1900 current_nesting_level--;
1901 pushlevel (1); /* Push local variables. */
1903 if (pass == 2 && (fndecl != global_function_decl || seen_action))
1905 /* generate label for possible 'exit' */
1906 expand_start_bindings (1);
1908 result_never_set = 1;
1911 if (TREE_CODE (result_type) == VOID_TYPE)
1912 chill_result_decl = NULL_TREE;
1913 else
1915 /* We use the same name as the keyword.
1916 This makes it easy to print and change the RESULT from gdb. */
1917 const char *result_str =
1918 (ignore_case || ! special_UC) ? "result" : "RESULT";
1919 if (pass == 2 && TREE_CODE (result_type) == ERROR_MARK)
1920 TREE_TYPE (current_scope->remembered_decls) = result_type;
1921 chill_result_decl = do_decl (get_identifier (result_str),
1922 result_type, 0, 0, 0, 0);
1923 DECL_CONTEXT (chill_result_decl) = fndecl;
1926 return 1;
1929 /* For checking purpose added pname as new argument
1930 MW Wed Oct 14 14:22:10 1992 */
1931 void
1932 finish_chill_function ()
1934 register tree fndecl = current_function_decl;
1935 tree outer_function = decl_function_context (fndecl);
1936 int nested;
1937 if (outer_function == NULL_TREE && fndecl != global_function_decl)
1938 outer_function = global_function_decl;
1939 nested = current_function_decl != global_function_decl;
1940 if (pass == 2 && (fndecl != global_function_decl || seen_action))
1941 expand_end_bindings (getdecls (), 1, 0);
1943 /* pop out of function */
1944 poplevel (1, 1, 0);
1945 current_nesting_level++;
1946 /* pop out of its parameters */
1947 poplevel (1, 0, 1);
1949 if (pass == 2)
1951 /* TREE_READONLY (fndecl) = 1;
1952 This caused &foo to be of type ptr-to-const-function which
1953 then got a warning when stored in a ptr-to-function variable. */
1955 BLOCK_SUPERCONTEXT (DECL_INITIAL (fndecl)) = fndecl;
1957 /* Must mark the RESULT_DECL as being in this function. */
1959 DECL_CONTEXT (DECL_RESULT (fndecl)) = fndecl;
1961 if (fndecl != global_function_decl || seen_action)
1963 /* Generate rtl for function exit. */
1964 expand_function_end (input_filename, lineno, 0);
1966 /* Run the optimizers and output assembler code for this function. */
1967 rest_of_compilation (fndecl);
1970 if (DECL_SAVED_INSNS (fndecl) == 0 && ! nested)
1972 /* Stop pointing to the local nodes about to be freed. */
1973 /* But DECL_INITIAL must remain nonzero so we know this
1974 was an actual function definition. */
1975 /* For a nested function, this is done in pop_chill_function_context. */
1976 DECL_INITIAL (fndecl) = error_mark_node;
1977 DECL_ARGUMENTS (fndecl) = 0;
1980 current_function_decl = outer_function;
1983 /* process SEIZE */
1985 /* Points to the head of the _DECLs read from seize files. */
1986 #if 0
1987 static tree seized_decls;
1989 static tree processed_seize_files = 0;
1990 #endif
1992 void
1993 chill_seize (old_prefix, new_prefix, postfix)
1994 tree old_prefix, new_prefix, postfix;
1996 if (pass == 1)
1998 tree decl = build_alias_decl (old_prefix, new_prefix, postfix);
1999 DECL_SEIZEFILE(decl) = use_seizefile_name;
2000 save_decl (decl);
2002 else /* pass == 2 */
2004 /* Do nothing - get_next_decl automatically ignores ALIAS_DECLs */
2007 #if 0
2010 * output a debug dump of a scope structure
2012 void
2013 debug_scope (sp)
2014 struct scope *sp;
2016 if (sp == (struct scope *)NULL)
2018 fprintf (stderr, "null scope ptr\n");
2019 return;
2021 fprintf (stderr, "enclosing 0x%x ", sp->enclosing);
2022 fprintf (stderr, "next 0x%x ", sp->next);
2023 fprintf (stderr, "remembered_decls 0x%x ", sp->remembered_decls);
2024 fprintf (stderr, "decls 0x%x\n", sp->decls);
2025 fprintf (stderr, "shadowed 0x%x ", sp->shadowed);
2026 fprintf (stderr, "blocks 0x%x ", sp->blocks);
2027 fprintf (stderr, "this_block 0x%x ", sp->this_block);
2028 fprintf (stderr, "level_chain 0x%x\n", sp->level_chain);
2029 fprintf (stderr, "module_flag %c ", sp->module_flag ? 'T' : 'F');
2030 fprintf (stderr, "first_child_module 0x%x ", sp->first_child_module);
2031 fprintf (stderr, "next_sibling_module 0x%x\n", sp->next_sibling_module);
2032 if (sp->remembered_decls != NULL_TREE)
2034 tree temp;
2035 fprintf (stderr, "remembered_decl chain:\n");
2036 for (temp = sp->remembered_decls; temp; temp = TREE_CHAIN (temp))
2037 debug_tree (temp);
2040 #endif
2042 static void
2043 save_decl (decl)
2044 tree decl;
2046 if (current_function_decl != global_function_decl)
2047 DECL_CONTEXT (decl) = current_function_decl;
2049 TREE_CHAIN (decl) = current_scope->remembered_decls;
2050 current_scope->remembered_decls = decl;
2051 #if 0
2052 fprintf (stderr, "\n\nsave_decl 0x%x\n", decl);
2053 debug_scope (current_scope); /* ************* */
2054 #endif
2055 set_nesting_level (decl, current_nesting_level);
2058 static tree
2059 get_next_decl ()
2061 tree decl;
2064 decl = current_scope->remembered_decls;
2065 current_scope->remembered_decls = TREE_CHAIN (decl);
2066 /* We ignore ALIAS_DECLs, because push_scope_decls
2067 can convert a single ALIAS_DECL representing 'SEIZE ALL'
2068 into one ALIAS_DECL for each seizeable name.
2069 This means we lose the nice one-to-one mapping
2070 between pass 1 decls and pass 2 decls.
2071 (Perhaps ALIAS_DECLs should not be on the remembered_decls list.) */
2072 } while (decl && TREE_CODE (decl) == ALIAS_DECL);
2073 return decl;
2076 /* At the end of pass 1, we reverse the chronological chain of scopes. */
2078 void
2079 switch_to_pass_2 ()
2081 #if 0
2082 extern int errorcount, sorrycount;
2083 #endif
2084 if (current_scope != &builtin_scope)
2085 abort ();
2086 last_scope = &builtin_scope;
2087 builtin_scope.remembered_decls = nreverse (builtin_scope.remembered_decls);
2088 write_grant_file ();
2090 #if 0
2091 if (errorcount || sorrycount)
2092 exit (FATAL_EXIT_CODE);
2093 else
2094 #endif
2095 if (grant_only_flag)
2096 exit (SUCCESS_EXIT_CODE);
2098 pass = 2;
2099 module_number = 0;
2100 next_module = &first_module;
2104 * Called during pass 2, when we're processing actions, to
2105 * generate a temporary variable. These don't need satisfying
2106 * because they're compiler-generated and always declared
2107 * before they're used.
2109 tree
2110 decl_temp1 (name, type, opt_static, opt_init,
2111 opt_external, opt_public)
2112 tree name, type;
2113 int opt_static;
2114 tree opt_init;
2115 int opt_external, opt_public;
2117 int orig_pass = pass; /* be cautious */
2118 tree mydecl;
2120 pass = 1;
2121 mydecl = do_decl (name, type, opt_static, opt_static,
2122 opt_init, opt_external);
2124 if (opt_public)
2125 TREE_PUBLIC (mydecl) = 1;
2126 pass = 2;
2127 do_decl (name, type, opt_static, opt_static, opt_init, opt_external);
2129 pass = orig_pass;
2130 return mydecl;
2133 /* True if we're reading a seizefile, but we haven't seen a SPEC MODULE yet.
2134 For backwards compatibility, we treat declarations in such a context
2135 as implicity granted. */
2137 tree
2138 set_module_name (name)
2139 tree name;
2141 module_number++;
2142 if (name == NULL_TREE)
2144 /* NOTE: build_prefix_clause assumes a generated
2145 module starts with a '_'. */
2146 char buf[20];
2147 sprintf (buf, "_MODULE_%d", module_number);
2148 name = get_identifier (buf);
2150 return name;
2153 tree
2154 push_module (name, is_spec_module)
2155 tree name;
2156 int is_spec_module;
2158 struct module *new_module;
2159 if (pass == 1)
2161 new_module = (struct module*) permalloc (sizeof (struct module));
2162 new_module->prev_module = current_module;
2164 *next_module = new_module;
2166 else
2168 new_module = *next_module;
2170 next_module = &new_module->next_module;
2172 new_module->procedure_seen = 0;
2173 new_module->is_spec_module = is_spec_module;
2174 new_module->name = name;
2175 if (current_module)
2176 new_module->prefix_name
2177 = get_identifier3 (IDENTIFIER_POINTER (current_module->prefix_name),
2178 "__", IDENTIFIER_POINTER (name));
2179 else
2180 new_module->prefix_name = name;
2182 new_module->granted_decls = NULL_TREE;
2183 new_module->nesting_level = current_nesting_level + 1;
2185 current_module = new_module;
2186 current_module_nesting_level = new_module->nesting_level;
2187 in_pseudo_module = name ? 0 : 1;
2189 pushlevel (1);
2191 current_scope->module_flag = 1;
2193 *current_scope->enclosing->tail_child_module = current_scope;
2194 current_scope->enclosing->tail_child_module
2195 = &current_scope->next_sibling_module;
2197 /* Rename the global function to have the same name as
2198 the first named non-spec module. */
2199 if (!is_spec_module
2200 && IDENTIFIER_POINTER (name)[0] != '_'
2201 && IDENTIFIER_POINTER (DECL_NAME (global_function_decl))[0] == '_')
2203 tree fname = get_identifier3 ("", IDENTIFIER_POINTER (name), "_");
2204 DECL_NAME (global_function_decl) = fname;
2205 DECL_ASSEMBLER_NAME (global_function_decl) = fname;
2208 return name; /* may have generated a name */
2210 /* Make a copy of the identifier NAME, replacing each '!' by '__'. */
2211 static tree
2212 fix_identifier (name)
2213 tree name;
2215 char *buf = (char*)alloca (2 * IDENTIFIER_LENGTH (name) + 1);
2216 int fixed = 0;
2217 register char *dptr = buf;
2218 register const char *sptr = IDENTIFIER_POINTER (name);
2219 for (; *sptr; sptr++)
2221 if (*sptr == '!')
2223 *dptr++ = '_';
2224 *dptr++ = '_';
2225 fixed++;
2227 else
2228 *dptr++ = *sptr;
2230 *dptr = '\0';
2231 return fixed ? get_identifier (buf) : name;
2234 void
2235 find_granted_decls ()
2237 if (pass == 1)
2239 /* Match each granted name to a granted decl. */
2241 tree alias = current_module->granted_decls;
2242 tree next_alias, decl;
2243 /* This is an O(M*N) algorithm. FIXME! */
2244 for (; alias; alias = next_alias)
2246 int found = 0;
2247 next_alias = TREE_CHAIN (alias);
2248 for (decl = current_scope->remembered_decls;
2249 decl; decl = TREE_CHAIN (decl))
2251 tree new_name = (! DECL_NAME (decl)) ? NULL_TREE :
2252 decl_check_rename (alias,
2253 DECL_NAME (decl));
2255 if (!new_name)
2256 continue;
2257 /* A Seized declaration is not grantable. */
2258 if (TREE_CODE (decl) == ALIAS_DECL && !CH_DECL_GRANTED (decl))
2259 continue;
2260 found = 1;
2261 if (global_bindings_p ())
2262 TREE_PUBLIC (decl) = 1;
2263 if (DECL_ASSEMBLER_NAME (decl) == NULL_TREE)
2264 DECL_ASSEMBLER_NAME (decl) = fix_identifier (new_name);
2265 if (DECL_POSTFIX_ALL (alias))
2267 tree new_alias
2268 = build_alias_decl (NULL_TREE, NULL_TREE, new_name);
2269 TREE_CHAIN (new_alias) = TREE_CHAIN (alias);
2270 TREE_CHAIN (alias) = new_alias;
2271 DECL_ABSTRACT_ORIGIN (new_alias) = decl;
2272 DECL_SOURCE_LINE (new_alias) = 0;
2273 DECL_SEIZEFILE (new_alias) = DECL_SEIZEFILE (alias);
2275 else
2277 DECL_ABSTRACT_ORIGIN (alias) = decl;
2278 break;
2281 if (!found)
2283 error_with_decl (alias, "Nothing named `%s' to grant.");
2284 DECL_ABSTRACT_ORIGIN (alias) = error_mark_node;
2290 void
2291 pop_module ()
2293 tree decl;
2294 struct scope *module_scope = current_scope;
2296 poplevel (0, 0, 0);
2298 if (pass == 1)
2300 /* Write out the grant file. */
2301 if (!current_module->is_spec_module)
2303 /* After reversal, TREE_CHAIN (last_old_decl) is the oldest
2304 decl of the current module. */
2305 write_spec_module (module_scope->remembered_decls,
2306 current_module->granted_decls);
2309 /* Move the granted decls into the enclosing scope. */
2310 if (current_scope == global_scope)
2312 tree next_decl;
2313 for (decl = current_module->granted_decls; decl; decl = next_decl)
2315 tree name = DECL_NAME (decl);
2316 next_decl = TREE_CHAIN (decl);
2317 if (name != NULL_TREE)
2319 tree old_decl = IDENTIFIER_OUTER_VALUE (name);
2320 set_nesting_level (decl, current_nesting_level);
2321 if (old_decl != NULL_TREE)
2323 pedwarn_with_decl (decl, "duplicate grant for `%s'");
2324 pedwarn_with_decl (old_decl, "previous grant for `%s'");
2325 TREE_CHAIN (decl) = TREE_CHAIN (old_decl);
2326 TREE_CHAIN (old_decl) = decl;
2328 else
2330 TREE_CHAIN (decl) = outer_decls;
2331 outer_decls = decl;
2332 IDENTIFIER_OUTER_VALUE (name) = decl;
2337 else
2338 current_scope->granted_decls = chainon (current_module->granted_decls,
2339 current_scope->granted_decls);
2342 chill_check_no_handlers (); /* Sanity test */
2343 current_module = current_module->prev_module;
2344 current_module_nesting_level = current_module ?
2345 current_module->nesting_level : 0;
2346 in_pseudo_module = 0;
2349 /* Nonzero if we are currently in the global binding level. */
2352 global_bindings_p ()
2354 /* We return -1 here for the sake of variable_size() in ../stor-layout.c. */
2355 return (current_function_decl == NULL_TREE
2356 || current_function_decl == global_function_decl) ? -1 : 0;
2359 /* Nonzero if the current level needs to have a BLOCK made. */
2362 kept_level_p ()
2364 return current_scope->decls != 0;
2367 /* Make DECL visible.
2368 Save any existing definition.
2369 Check redefinitions at the same level.
2370 Suppress error messages if QUIET is true. */
2372 static void
2373 proclaim_decl (decl, quiet)
2374 tree decl;
2375 int quiet;
2377 tree name = DECL_NAME (decl);
2378 if (name)
2380 tree old_decl = IDENTIFIER_LOCAL_VALUE (name);
2381 if (old_decl == NULL) ; /* No duplication */
2382 else if (DECL_NESTING_LEVEL (old_decl) != current_nesting_level)
2384 /* Record for restoration when this binding level ends. */
2385 current_scope->shadowed
2386 = tree_cons (name, old_decl, current_scope->shadowed);
2388 else if (DECL_WEAK_NAME (decl))
2389 return;
2390 else if (!DECL_WEAK_NAME (old_decl))
2392 tree base_decl = decl, base_old_decl = old_decl;
2393 while (TREE_CODE (base_decl) == ALIAS_DECL)
2394 base_decl = DECL_ABSTRACT_ORIGIN (base_decl);
2395 while (TREE_CODE (base_old_decl) == ALIAS_DECL)
2396 base_old_decl = DECL_ABSTRACT_ORIGIN (base_old_decl);
2397 /* Note that duplicate definitions are allowed for set elements
2398 of similar set modes. See Z200 (1988) 12.2.2.
2399 However, if the types are identical, we are defining the
2400 same name multiple times in the same SET, which is naughty. */
2401 if (!quiet && base_decl != base_old_decl)
2403 if (TREE_CODE (base_decl) != CONST_DECL
2404 || TREE_CODE (base_old_decl) != CONST_DECL
2405 || !CH_DECL_ENUM (base_decl)
2406 || !CH_DECL_ENUM (base_old_decl)
2407 || TREE_TYPE (base_decl) == TREE_TYPE (base_old_decl)
2408 || !CH_SIMILAR (TREE_TYPE (base_decl),
2409 TREE_TYPE(base_old_decl)))
2411 error_with_decl (decl, "duplicate definition `%s'");
2412 error_with_decl (old_decl, "previous definition of `%s'");
2416 IDENTIFIER_LOCAL_VALUE (name) = decl;
2418 /* Should be redundant most of the time ... */
2419 set_nesting_level (decl, current_nesting_level);
2422 /* Return tree_cons (NULL_TREE, ELEMENT, LIST) unless ELEMENT
2423 is already in LIST, in which case return LIST. */
2425 static tree
2426 maybe_acons (element, list)
2427 tree element, list;
2429 tree pair;
2430 for (pair = list; pair; pair = TREE_CHAIN (pair))
2431 if (element == TREE_VALUE (pair))
2432 return list;
2433 return tree_cons (NULL_TREE, element, list);
2436 struct path
2438 struct path *prev;
2439 tree node;
2442 static tree find_implied_types PARAMS ((tree, struct path *, tree));
2444 /* Look for implied types (enumeral types) implied by TYPE (a decl or type).
2445 Add these to list.
2446 Use old_path to guard against cycles. */
2448 static tree
2449 find_implied_types (type, old_path, list)
2450 tree type;
2451 struct path *old_path;
2452 tree list;
2454 struct path path[1], *link;
2455 if (type == NULL_TREE)
2456 return list;
2457 path[0].prev = old_path;
2458 path[0].node = type;
2460 /* Check for a cycle. Something more clever might be appropriate. FIXME? */
2461 for (link = old_path; link; link = link->prev)
2462 if (link->node == type)
2463 return list;
2465 switch (TREE_CODE (type))
2467 case ENUMERAL_TYPE:
2468 return maybe_acons (type, list);
2469 case LANG_TYPE:
2470 case POINTER_TYPE:
2471 case REFERENCE_TYPE:
2472 case INTEGER_TYPE:
2473 return find_implied_types (TREE_TYPE (type), path, list);
2474 case SET_TYPE:
2475 return find_implied_types (TYPE_DOMAIN (type), path, list);
2476 case FUNCTION_TYPE:
2477 #if 0
2478 case PROCESS_TYPE:
2479 #endif
2480 { tree t;
2481 list = find_implied_types (TREE_TYPE (type), path, list);
2482 for (t = TYPE_ARG_TYPES (type); t != NULL_TREE; t = TREE_CHAIN (t))
2483 list = find_implied_types (TREE_VALUE (t), path, list);
2484 return list;
2486 case ARRAY_TYPE:
2487 list = find_implied_types (TYPE_DOMAIN (type), path, list);
2488 return find_implied_types (TREE_TYPE (type), path, list);
2489 case RECORD_TYPE:
2490 case UNION_TYPE:
2491 { tree fields;
2492 for (fields = TYPE_FIELDS (type); fields != NULL_TREE;
2493 fields = TREE_CHAIN (fields))
2494 list = find_implied_types (TREE_TYPE (fields), path, list);
2495 return list;
2498 case IDENTIFIER_NODE:
2499 return find_implied_types (lookup_name (type), path, list);
2500 break;
2501 case ALIAS_DECL:
2502 return find_implied_types (DECL_ABSTRACT_ORIGIN (type), path, list);
2503 case VAR_DECL:
2504 case FUNCTION_DECL:
2505 case TYPE_DECL:
2506 return find_implied_types (TREE_TYPE (type), path, list);
2507 default:
2508 return list;
2512 /* Make declarations in current scope visible.
2513 Also, expand SEIZEs, and make correspondong ALIAS_DECLs visible. */
2515 static void
2516 push_scope_decls (quiet)
2517 int quiet; /* If 1, we're pre-scanning, so suppress errors. */
2519 tree decl;
2521 /* First make everything except 'SEIZE ALL' names visible, before
2522 handling 'SEIZE ALL'. (This makes it easier to check 'seizable'). */
2523 for (decl = current_scope->remembered_decls; decl; decl = TREE_CHAIN (decl))
2525 if (TREE_CODE (decl) == ALIAS_DECL)
2527 if (DECL_POSTFIX_ALL (decl))
2528 continue;
2529 if (DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE)
2531 tree val = lookup_name_for_seizing (decl);
2532 if (val == NULL_TREE)
2534 error_with_file_and_line
2535 (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl),
2536 "cannot SEIZE `%s'",
2537 IDENTIFIER_POINTER (DECL_OLD_NAME (decl)));
2538 val = error_mark_node;
2540 DECL_ABSTRACT_ORIGIN (decl) = val;
2543 proclaim_decl (decl, quiet);
2546 pushdecllist (current_scope->granted_decls, quiet);
2548 /* Now handle SEIZE ALLs. */
2549 for (decl = current_scope->remembered_decls; decl; )
2551 tree next_decl = TREE_CHAIN (decl);
2552 if (TREE_CODE (decl) == ALIAS_DECL
2553 && DECL_ABSTRACT_ORIGIN (decl) == NULL_TREE
2554 && DECL_POSTFIX_ALL (decl))
2556 /* We saw a "SEIZE ALL". Replace it be a SEIZE for each
2557 declaration visible in the surrounding scope.
2558 Note that this complicates get_next_decl(). */
2559 tree candidate;
2560 tree last_new_alias = decl;
2561 DECL_ABSTRACT_ORIGIN (decl) = error_mark_node;
2562 if (current_scope->enclosing == global_scope)
2563 candidate = outer_decls;
2564 else
2565 candidate = current_scope->enclosing->decls;
2566 for ( ; candidate; candidate = TREE_CHAIN (candidate))
2568 tree seizename = DECL_NAME (candidate);
2569 tree new_name;
2570 tree new_alias;
2571 if (!seizename)
2572 continue;
2573 new_name = decl_check_rename (decl, seizename);
2574 if (!new_name)
2575 continue;
2577 /* Check if candidate is seizable. */
2578 if (lookup_name (new_name) != NULL_TREE)
2579 continue;
2581 new_alias = build_alias_decl (NULL_TREE,NULL_TREE, new_name);
2582 TREE_CHAIN (new_alias) = TREE_CHAIN (last_new_alias);
2583 TREE_CHAIN (last_new_alias) = new_alias;
2584 last_new_alias = new_alias;
2585 DECL_ABSTRACT_ORIGIN (new_alias) = candidate;
2586 DECL_SOURCE_LINE (new_alias) = 0;
2588 proclaim_decl (new_alias, quiet);
2591 decl = next_decl;
2594 /* Link current_scope->remembered_decls at the head of the
2595 current_scope->decls list (just like pushdecllist, but
2596 without calling proclaim_decl, since we've already done that). */
2597 if ((decl = current_scope->remembered_decls) != NULL_TREE)
2599 while (TREE_CHAIN (decl) != NULL_TREE)
2600 decl = TREE_CHAIN (decl);
2601 TREE_CHAIN (decl) = current_scope->decls;
2602 current_scope->decls = current_scope->remembered_decls;
2606 static void
2607 pop_scope_decls (decls_limit, shadowed_limit)
2608 tree decls_limit, shadowed_limit;
2610 /* Remove the temporary bindings we made. */
2611 tree link = current_scope->shadowed;
2612 tree decl = current_scope->decls;
2613 if (decl != decls_limit)
2615 while (decl != decls_limit)
2617 tree next = TREE_CHAIN (decl);
2618 if (DECL_NAME (decl))
2620 /* If the ident. was used or addressed via a local extern decl,
2621 don't forget that fact. */
2622 if (DECL_EXTERNAL (decl))
2624 if (TREE_USED (decl))
2625 TREE_USED (DECL_NAME (decl)) = 1;
2626 if (TREE_ADDRESSABLE (decl))
2627 TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (decl)) = 1;
2629 IDENTIFIER_LOCAL_VALUE (DECL_NAME (decl)) = 0;
2631 if (next == decls_limit)
2633 TREE_CHAIN (decl) = NULL_TREE;
2634 break;
2636 decl = next;
2638 current_scope->decls = decls_limit;
2641 /* Restore all name-meanings of the outer levels
2642 that were shadowed by this level. */
2643 for ( ; link != shadowed_limit; link = TREE_CHAIN (link))
2644 IDENTIFIER_LOCAL_VALUE (TREE_PURPOSE (link)) = TREE_VALUE (link);
2645 current_scope->shadowed = shadowed_limit;
2648 /* Return list of weak names (as ALIAS_DECLs) implied by IMPLIED_TYPES. */
2650 static tree
2651 build_implied_names (implied_types)
2652 tree implied_types;
2654 tree aliases = NULL_TREE;
2656 for ( ; implied_types; implied_types = TREE_CHAIN (implied_types))
2658 tree enum_type = TREE_VALUE (implied_types);
2659 tree link = TYPE_VALUES (enum_type);
2660 if (TREE_CODE (enum_type) != ENUMERAL_TYPE)
2661 abort ();
2663 for ( ; link; link = TREE_CHAIN (link))
2665 /* We don't handle renaming/prefixes (Blue Book p 163) FIXME */
2666 /* Note that before enum_type is laid out, TREE_VALUE (link)
2667 is a CONST_DECL, while after it is laid out,
2668 TREE_VALUE (link) is an INTEGER_CST. Either works. */
2669 tree alias
2670 = build_alias_decl (NULL_TREE, NULL_TREE, TREE_PURPOSE (link));
2671 DECL_ABSTRACT_ORIGIN (alias) = TREE_VALUE (link);
2672 DECL_WEAK_NAME (alias) = 1;
2673 TREE_CHAIN (alias) = aliases;
2674 aliases = alias;
2675 /* Strictlt speaking, we should have a pointer from the alias
2676 to the decl, so we can make sure that the alias is only
2677 visible when the decl is. FIXME */
2680 return aliases;
2683 static void
2684 bind_sub_modules (do_weak)
2685 int do_weak;
2687 tree decl;
2688 int save_module_nesting_level = current_module_nesting_level;
2689 struct scope *saved_scope = current_scope;
2690 struct scope *nested_module = current_scope->first_child_module;
2692 while (nested_module != NULL)
2694 tree saved_shadowed = nested_module->shadowed;
2695 tree saved_decls = nested_module->decls;
2696 current_nesting_level++;
2697 current_scope = nested_module;
2698 current_module_nesting_level = current_nesting_level;
2699 if (do_weak == 0)
2700 push_scope_decls (1);
2701 else
2703 tree implied_types = NULL_TREE;
2704 /* Push weak names implied by decls in current_scope. */
2705 for (decl = current_scope->remembered_decls;
2706 decl; decl = TREE_CHAIN (decl))
2707 if (TREE_CODE (decl) == ALIAS_DECL)
2708 implied_types = find_implied_types (decl, NULL, implied_types);
2709 for (decl = current_scope->granted_decls;
2710 decl; decl = TREE_CHAIN (decl))
2711 implied_types = find_implied_types (decl, NULL, implied_types);
2712 current_scope->weak_decls = build_implied_names (implied_types);
2713 pushdecllist (current_scope->weak_decls, 1);
2716 bind_sub_modules (do_weak);
2717 for (decl = current_scope->remembered_decls;
2718 decl; decl = TREE_CHAIN (decl))
2719 satisfy_decl (decl, 1);
2720 pop_scope_decls (saved_decls, saved_shadowed);
2721 current_nesting_level--;
2722 nested_module = nested_module->next_sibling_module;
2725 current_scope = saved_scope;
2726 current_module_nesting_level = save_module_nesting_level;
2729 /* Enter a new binding level.
2730 If two_pass==0, assume we are called from non-Chill-specific parts
2731 of the compiler. These parts assume a single pass.
2732 If two_pass==1, we're called from Chill parts of the compiler.
2735 void
2736 pushlevel (two_pass)
2737 int two_pass;
2739 register struct scope *newlevel;
2741 current_nesting_level++;
2742 if (!two_pass)
2744 newlevel = (struct scope *)xmalloc (sizeof(struct scope));
2745 *newlevel = clear_scope;
2746 newlevel->enclosing = current_scope;
2747 current_scope = newlevel;
2749 else if (pass < 2)
2751 newlevel = (struct scope *)permalloc (sizeof(struct scope));
2752 *newlevel = clear_scope;
2753 newlevel->tail_child_module = &newlevel->first_child_module;
2754 newlevel->enclosing = current_scope;
2755 current_scope = newlevel;
2756 last_scope->next = newlevel;
2757 last_scope = newlevel;
2759 else /* pass == 2 */
2761 tree decl;
2762 newlevel = current_scope = last_scope = last_scope->next;
2764 push_scope_decls (0);
2765 pushdecllist (current_scope->weak_decls, 0);
2767 /* If this is not a module scope, scan ahead for locally nested
2768 modules. (If this is a module, that's already done.) */
2769 if (!current_scope->module_flag)
2771 bind_sub_modules (0);
2772 bind_sub_modules (1);
2775 for (decl = current_scope->remembered_decls;
2776 decl; decl = TREE_CHAIN (decl))
2777 satisfy_decl (decl, 0);
2780 /* Add this level to the front of the chain (stack) of levels that
2781 are active. */
2783 newlevel->level_chain = current_scope;
2784 current_scope = newlevel;
2786 newlevel->two_pass = two_pass;
2789 /* Exit a binding level.
2790 Pop the level off, and restore the state of the identifier-decl mappings
2791 that were in effect when this level was entered.
2793 If KEEP is nonzero, this level had explicit declarations, so
2794 and create a "block" (a BLOCK node) for the level
2795 to record its declarations and subblocks for symbol table output.
2797 If FUNCTIONBODY is nonzero, this level is the body of a function,
2798 so create a block as if KEEP were set and also clear out all
2799 label names.
2801 If REVERSE is nonzero, reverse the order of decls before putting
2802 them into the BLOCK. */
2804 tree
2805 poplevel (keep, reverse, functionbody)
2806 int keep;
2807 int reverse;
2808 int functionbody;
2810 register tree link;
2811 /* The chain of decls was accumulated in reverse order.
2812 Put it into forward order, just for cleanliness. */
2813 tree decls;
2814 tree subblocks;
2815 tree block = 0;
2816 tree decl;
2817 int block_previously_created = 0;
2819 if (current_scope == NULL)
2820 return error_mark_node;
2822 subblocks = current_scope->blocks;
2824 /* Get the decls in the order they were written.
2825 Usually current_scope->decls is in reverse order.
2826 But parameter decls were previously put in forward order. */
2828 if (reverse)
2829 current_scope->decls
2830 = decls = nreverse (current_scope->decls);
2831 else
2832 decls = current_scope->decls;
2834 if (pass == 2)
2836 /* Output any nested inline functions within this block
2837 if they weren't already output. */
2839 for (decl = decls; decl; decl = TREE_CHAIN (decl))
2840 if (TREE_CODE (decl) == FUNCTION_DECL
2841 && ! TREE_ASM_WRITTEN (decl)
2842 && DECL_INITIAL (decl) != 0
2843 && TREE_ADDRESSABLE (decl))
2845 /* If this decl was copied from a file-scope decl
2846 on account of a block-scope extern decl,
2847 propagate TREE_ADDRESSABLE to the file-scope decl. */
2848 if (DECL_ABSTRACT_ORIGIN (decl) != 0)
2849 TREE_ADDRESSABLE (DECL_ABSTRACT_ORIGIN (decl)) = 1;
2850 else
2852 push_function_context ();
2853 output_inline_function (decl);
2854 pop_function_context ();
2858 /* Clear out the meanings of the local variables of this level. */
2859 pop_scope_decls (NULL_TREE, NULL_TREE);
2861 /* If there were any declarations or structure tags in that level,
2862 or if this level is a function body,
2863 create a BLOCK to record them for the life of this function. */
2865 block = 0;
2866 block_previously_created = (current_scope->this_block != 0);
2867 if (block_previously_created)
2868 block = current_scope->this_block;
2869 else if (keep || functionbody)
2870 block = make_node (BLOCK);
2871 if (block != 0)
2873 tree *ptr;
2874 BLOCK_VARS (block) = decls;
2876 /* Splice out ALIAS_DECL and LABEL_DECLs,
2877 since instantiate_decls can't handle them. */
2878 for (ptr = &BLOCK_VARS (block); *ptr; )
2880 decl = *ptr;
2881 if (TREE_CODE (decl) == ALIAS_DECL
2882 || TREE_CODE (decl) == LABEL_DECL)
2883 *ptr = TREE_CHAIN (decl);
2884 else
2885 ptr = &TREE_CHAIN(*ptr);
2888 BLOCK_SUBBLOCKS (block) = subblocks;
2891 /* In each subblock, record that this is its superior. */
2893 for (link = subblocks; link; link = TREE_CHAIN (link))
2894 BLOCK_SUPERCONTEXT (link) = block;
2898 /* If the level being exited is the top level of a function,
2899 check over all the labels, and clear out the current
2900 (function local) meanings of their names. */
2902 if (pass == 2 && functionbody)
2904 /* If this is the top level block of a function,
2905 the vars are the function's parameters.
2906 Don't leave them in the BLOCK because they are
2907 found in the FUNCTION_DECL instead. */
2909 BLOCK_VARS (block) = 0;
2911 #if 0
2912 /* Clear out the definitions of all label names,
2913 since their scopes end here,
2914 and add them to BLOCK_VARS. */
2916 for (link = named_labels; link; link = TREE_CHAIN (link))
2918 register tree label = TREE_VALUE (link);
2920 if (DECL_INITIAL (label) == 0)
2922 error_with_decl (label, "label `%s' used but not defined");
2923 /* Avoid crashing later. */
2924 define_label (input_filename, lineno,
2925 DECL_NAME (label));
2927 else if (warn_unused_label && !TREE_USED (label))
2928 warning_with_decl (label, "label `%s' defined but not used");
2929 IDENTIFIER_LABEL_VALUE (DECL_NAME (label)) = 0;
2931 /* Put the labels into the "variables" of the
2932 top-level block, so debugger can see them. */
2933 TREE_CHAIN (label) = BLOCK_VARS (block);
2934 BLOCK_VARS (block) = label;
2936 #endif
2939 if (pass < 2)
2941 current_scope->remembered_decls
2942 = nreverse (current_scope->remembered_decls);
2943 current_scope->granted_decls = nreverse (current_scope->granted_decls);
2946 current_scope = current_scope->enclosing;
2947 current_nesting_level--;
2949 if (pass < 2)
2951 return NULL_TREE;
2954 /* Dispose of the block that we just made inside some higher level. */
2955 if (functionbody)
2956 DECL_INITIAL (current_function_decl) = block;
2957 else if (block)
2959 if (!block_previously_created)
2960 current_scope->blocks
2961 = chainon (current_scope->blocks, block);
2963 /* If we did not make a block for the level just exited,
2964 any blocks made for inner levels
2965 (since they cannot be recorded as subblocks in that level)
2966 must be carried forward so they will later become subblocks
2967 of something else. */
2968 else if (subblocks)
2969 current_scope->blocks
2970 = chainon (current_scope->blocks, subblocks);
2972 if (block)
2973 TREE_USED (block) = 1;
2974 return block;
2977 /* Delete the node BLOCK from the current binding level.
2978 This is used for the block inside a stmt expr ({...})
2979 so that the block can be reinserted where appropriate. */
2981 void
2982 delete_block (block)
2983 tree block;
2985 tree t;
2986 if (current_scope->blocks == block)
2987 current_scope->blocks = TREE_CHAIN (block);
2988 for (t = current_scope->blocks; t;)
2990 if (TREE_CHAIN (t) == block)
2991 TREE_CHAIN (t) = TREE_CHAIN (block);
2992 else
2993 t = TREE_CHAIN (t);
2995 TREE_CHAIN (block) = NULL;
2996 /* Clear TREE_USED which is always set by poplevel.
2997 The flag is set again if insert_block is called. */
2998 TREE_USED (block) = 0;
3001 /* Insert BLOCK at the end of the list of subblocks of the
3002 current binding level. This is used when a BIND_EXPR is expanded,
3003 to handle the BLOCK node inside teh BIND_EXPR. */
3005 void
3006 insert_block (block)
3007 tree block;
3009 TREE_USED (block) = 1;
3010 current_scope->blocks
3011 = chainon (current_scope->blocks, block);
3014 /* Set the BLOCK node for the innermost scope
3015 (the one we are currently in). */
3017 void
3018 set_block (block)
3019 register tree block;
3021 current_scope->this_block = block;
3024 /* Record a decl-node X as belonging to the current lexical scope.
3025 Check for errors (such as an incompatible declaration for the same
3026 name already seen in the same scope).
3028 Returns either X or an old decl for the same name.
3029 If an old decl is returned, it may have been smashed
3030 to agree with what X says. */
3032 tree
3033 pushdecl (x)
3034 tree x;
3036 register tree name = DECL_NAME (x);
3037 register struct scope *b = current_scope;
3039 DECL_CONTEXT (x) = current_function_decl;
3040 /* A local extern declaration for a function doesn't constitute nesting.
3041 A local auto declaration does, since it's a forward decl
3042 for a nested function coming later. */
3043 if (TREE_CODE (x) == FUNCTION_DECL && DECL_INITIAL (x) == 0
3044 && DECL_EXTERNAL (x))
3045 DECL_CONTEXT (x) = 0;
3047 if (name)
3048 proclaim_decl (x, 0);
3050 if (TREE_CODE (x) == TYPE_DECL && DECL_SOURCE_LINE (x) == 0
3051 && TYPE_NAME (TREE_TYPE (x)) == 0)
3052 TYPE_NAME (TREE_TYPE (x)) = x;
3054 /* Put decls on list in reverse order.
3055 We will reverse them later if necessary. */
3056 TREE_CHAIN (x) = b->decls;
3057 b->decls = x;
3059 return x;
3062 /* Make DECLS (a chain of decls) visible in the current_scope. */
3064 static void
3065 pushdecllist (decls, quiet)
3066 tree decls;
3067 int quiet;
3069 tree last = NULL_TREE, decl;
3071 for (decl = decls; decl != NULL_TREE;
3072 last = decl, decl = TREE_CHAIN (decl))
3074 proclaim_decl (decl, quiet);
3077 if (last)
3079 TREE_CHAIN (last) = current_scope->decls;
3080 current_scope->decls = decls;
3084 /* Like pushdecl, only it places X in GLOBAL_SCOPE, if appropriate. */
3086 tree
3087 pushdecl_top_level (x)
3088 tree x;
3090 register tree t;
3091 register struct scope *b = current_scope;
3093 current_scope = global_scope;
3094 t = pushdecl (x);
3095 current_scope = b;
3096 return t;
3099 /* Define a label, specifying the location in the source file.
3100 Return the LABEL_DECL node for the label, if the definition is valid.
3101 Otherwise return 0. */
3103 tree
3104 define_label (filename, line, name)
3105 const char *filename;
3106 int line;
3107 tree name;
3109 tree decl;
3111 if (pass == 1)
3113 decl = build_decl (LABEL_DECL, name, void_type_node);
3115 /* A label not explicitly declared must be local to where it's ref'd. */
3116 DECL_CONTEXT (decl) = current_function_decl;
3118 DECL_MODE (decl) = VOIDmode;
3120 /* Say where one reference is to the label,
3121 for the sake of the error if it is not defined. */
3122 DECL_SOURCE_LINE (decl) = line;
3123 DECL_SOURCE_FILE (decl) = filename;
3125 /* Mark label as having been defined. */
3126 DECL_INITIAL (decl) = error_mark_node;
3128 DECL_ACTION_NESTING_LEVEL (decl) = action_nesting_level;
3130 save_decl (decl);
3132 else
3134 decl = get_next_decl ();
3135 /* Make sure every label has an rtx. */
3137 label_rtx (decl);
3138 expand_label (decl);
3140 return decl;
3143 /* Return the list of declarations of the current level.
3144 Note that this list is in reverse order unless/until
3145 you nreverse it; and when you do nreverse it, you must
3146 store the result back using `storedecls' or you will lose. */
3148 tree
3149 getdecls ()
3151 /* This is a kludge, so that dbxout_init can get the predefined types,
3152 which are in the builtin_scope, though when it is called,
3153 the current_scope is the global_scope.. */
3154 if (current_scope == global_scope)
3155 return builtin_scope.decls;
3156 return current_scope->decls;
3159 #if 0
3160 /* Store the list of declarations of the current level.
3161 This is done for the parameter declarations of a function being defined,
3162 after they are modified in the light of any missing parameters. */
3164 static void
3165 storedecls (decls)
3166 tree decls;
3168 current_scope->decls = decls;
3170 #endif
3172 /* Look up NAME in the current binding level and its superiors
3173 in the namespace of variables, functions and typedefs.
3174 Return a ..._DECL node of some kind representing its definition,
3175 or return 0 if it is undefined. */
3177 tree
3178 lookup_name (name)
3179 tree name;
3181 register tree val = IDENTIFIER_LOCAL_VALUE (name);
3183 if (val == NULL_TREE)
3184 return NULL_TREE;
3185 if (TREE_CODE_CLASS (TREE_CODE (val)) == 'c')
3186 return val;
3187 if (DECL_NESTING_LEVEL (val) > BUILTIN_NESTING_LEVEL
3188 && DECL_NESTING_LEVEL (val) < current_module_nesting_level)
3190 return NULL_TREE;
3192 while (TREE_CODE (val) == ALIAS_DECL)
3194 val = DECL_ABSTRACT_ORIGIN (val);
3195 if (TREE_CODE (val) == ERROR_MARK)
3196 return NULL_TREE;
3198 if (TREE_CODE (val) == BASED_DECL)
3200 return build_chill_indirect_ref (DECL_ABSTRACT_ORIGIN (val),
3201 TREE_TYPE (val), 1);
3203 if (TREE_CODE (val) == WITH_DECL)
3204 return build_component_ref (DECL_ABSTRACT_ORIGIN (val), DECL_NAME (val));
3205 return val;
3208 #if 0
3209 /* Similar to `lookup_name' but look only at current binding level. */
3211 static tree
3212 lookup_name_current_level (name)
3213 tree name;
3215 register tree val = IDENTIFIER_LOCAL_VALUE (name);
3216 if (val && DECL_NESTING_LEVEL (val) == current_nesting_level)
3217 return val;
3218 return NULL_TREE;
3220 #endif
3222 static tree
3223 lookup_name_for_seizing (seize_decl)
3224 tree seize_decl;
3226 tree name = DECL_OLD_NAME (seize_decl);
3227 register tree val;
3228 val = IDENTIFIER_LOCAL_VALUE (name);
3229 if (val == NULL_TREE || DECL_NESTING_LEVEL (val) == BUILTIN_NESTING_LEVEL)
3231 val = IDENTIFIER_OUTER_VALUE (name);
3232 if (val == NULL_TREE)
3233 return NULL_TREE;
3234 if (TREE_CHAIN (val) && DECL_NAME (TREE_CHAIN (val)) == name)
3235 { /* More than one decl with the same name has been granted
3236 into the same global scope. Pick the one (we hope) that
3237 came from a seizefile the matches the most recent
3238 seizefile (as given by DECL_SEIZEFILE (seize_decl).) */
3239 tree d, best = NULL_TREE;
3240 for (d = val; d != NULL_TREE && DECL_NAME (d) == name;
3241 d = TREE_CHAIN (d))
3242 if (DECL_SEIZEFILE (d) == DECL_SEIZEFILE (seize_decl))
3244 if (best)
3246 error_with_decl (seize_decl,
3247 "ambiguous choice for seize `%s' -");
3248 error_with_decl (best, " - can seize this `%s' -");
3249 error_with_decl (d, " - or this granted decl `%s'");
3250 return NULL_TREE;
3252 best = d;
3254 if (best == NULL_TREE)
3256 error_with_decl (seize_decl,
3257 "ambiguous choice for seize `%s' -");
3258 error_with_decl (val, " - can seize this `%s' -");
3259 error_with_decl (TREE_CHAIN (val),
3260 " - or this granted decl `%s'");
3261 return NULL_TREE;
3263 val = best;
3266 #if 0
3267 /* We don't need to handle this, as long as we
3268 resolve the seize targets before pushing them. */
3269 if (DECL_NESTING_LEVEL (val) >= current_module_nesting_level)
3271 /* VAL was declared inside current module. We need something
3272 from the scope *enclosing* the current module, so search
3273 through the shadowed declarations. */
3274 /* TODO - FIXME */
3276 #endif
3277 if (current_module && current_module->prev_module
3278 && DECL_NESTING_LEVEL (val)
3279 < current_module->prev_module->nesting_level)
3282 /* It's declared in a scope enclosing the module enclosing
3283 the current module. Hence it's not visible. */
3284 return NULL_TREE;
3286 while (TREE_CODE (val) == ALIAS_DECL)
3288 val = DECL_ABSTRACT_ORIGIN (val);
3289 if (TREE_CODE (val) == ERROR_MARK)
3290 return NULL_TREE;
3292 return val;
3295 /* Create the predefined scalar types of C,
3296 and some nodes representing standard constants (0, 1, (void *)0).
3297 Initialize the global binding level.
3298 Make definitions for built-in primitive functions. */
3300 void
3301 init_decl_processing ()
3303 int wchar_type_size;
3304 tree bool_ftype_int_ptr_int;
3305 tree bool_ftype_int_ptr_int_int;
3306 tree bool_ftype_luns_ptr_luns_long;
3307 tree bool_ftype_luns_ptr_luns_long_ptr_int;
3308 tree bool_ftype_ptr_int_ptr_int;
3309 tree bool_ftype_ptr_int_ptr_int_int;
3310 tree find_bit_ftype;
3311 tree bool_ftype_ptr_ptr_int;
3312 tree bool_ftype_ptr_ptr_luns;
3313 tree bool_ftype_ptr_ptr_ptr_luns;
3314 tree endlink;
3315 tree int_ftype_int;
3316 tree int_ftype_int_int;
3317 tree int_ftype_int_ptr_int;
3318 tree int_ftype_ptr;
3319 tree int_ftype_ptr_int;
3320 tree int_ftype_ptr_int_int_ptr_int;
3321 tree int_ftype_ptr_luns_long_ptr_int;
3322 tree int_ftype_ptr_ptr_int;
3323 tree int_ftype_ptr_ptr_luns;
3324 tree long_ftype_ptr_luns;
3325 tree memcpy_ftype;
3326 tree memcmp_ftype;
3327 tree ptr_ftype_ptr_int_int;
3328 tree ptr_ftype_ptr_ptr_int;
3329 tree ptr_ftype_ptr_ptr_int_ptr_int;
3330 tree real_ftype_real;
3331 tree temp;
3332 tree void_ftype_cptr_cptr_int;
3333 tree void_ftype_long_int_ptr_int_ptr_int;
3334 tree void_ftype_ptr;
3335 tree void_ftype_ptr_int_int_int_int;
3336 tree void_ftype_ptr_int_ptr_int_int_int;
3337 tree void_ftype_ptr_int_ptr_int_ptr_int;
3338 tree void_ftype_ptr_luns_long_long_bool_ptr_int;
3339 tree void_ftype_ptr_luns_ptr_luns_luns_luns;
3340 tree void_ftype_ptr_ptr_ptr_int;
3341 tree void_ftype_ptr_ptr_ptr_luns;
3342 tree void_ftype_refptr_int_ptr_int;
3343 tree void_ftype_void;
3344 tree void_ftype_ptr_ptr_int;
3345 tree void_ftype_ptr_luns_luns_cptr_luns_luns_luns;
3346 tree ptr_ftype_luns_ptr_int;
3347 tree double_ftype_double;
3349 /* allow 0-255 enums to occupy only a byte */
3350 flag_short_enums = 1;
3352 current_function_decl = NULL;
3354 set_alignment = BITS_PER_UNIT;
3356 ALL_POSTFIX = get_identifier ("*");
3357 string_index_type_dummy = get_identifier("%string-index%");
3359 var_length_id = get_identifier (VAR_LENGTH);
3360 var_data_id = get_identifier (VAR_DATA);
3362 build_common_tree_nodes (1);
3364 if (CHILL_INT_IS_SHORT)
3365 long_integer_type_node = integer_type_node;
3366 else
3367 long_integer_type_node = make_signed_type (LONG_TYPE_SIZE);
3369 /* `unsigned long' is the standard type for sizeof.
3370 Note that stddef.h uses `unsigned long',
3371 and this must agree, even of long and int are the same size. */
3372 #ifndef SIZE_TYPE
3373 set_sizetype (long_unsigned_type_node);
3374 #else
3376 const char *size_type_c_name = SIZE_TYPE;
3377 if (strncmp (size_type_c_name, "long long ", 10) == 0)
3378 set_sizetype (long_long_unsigned_type_node);
3379 else if (strncmp (size_type_c_name, "long ", 5) == 0)
3380 set_sizetype (long_unsigned_type_node);
3381 else
3382 set_sizetype (unsigned_type_node);
3384 #endif
3386 pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_FLOAT],
3387 float_type_node));
3388 pushdecl (build_decl (TYPE_DECL, ridpointers[(int) RID_DOUBLE],
3389 double_type_node));
3391 integer_minus_one_node = build_int_2 (-1, -1);
3392 TREE_TYPE (integer_minus_one_node) = integer_type_node;
3394 build_common_tree_nodes_2 (flag_short_double);
3396 pushdecl (build_decl (TYPE_DECL,
3397 ridpointers[(int) RID_VOID], void_type_node));
3398 /* We are not going to have real types in C with less than byte alignment,
3399 so we might as well not have any types that claim to have it. */
3400 TYPE_ALIGN (void_type_node) = BITS_PER_UNIT;
3401 TYPE_USER_ALIGN (void_type_node) = 0;
3403 /* This is for wide string constants. */
3404 wchar_type_node = short_unsigned_type_node;
3405 wchar_type_size = TYPE_PRECISION (wchar_type_node);
3406 signed_wchar_type_node = type_for_size (wchar_type_size, 0);
3407 unsigned_wchar_type_node = type_for_size (wchar_type_size, 1);
3409 default_function_type
3410 = build_function_type (integer_type_node, NULL_TREE);
3412 ptr_type_node = build_pointer_type (void_type_node);
3413 const_ptr_type_node
3414 = build_pointer_type (build_type_variant (void_type_node, 1, 0));
3416 void_list_node = build_tree_list (NULL_TREE, void_type_node);
3418 boolean_type_node = make_node (BOOLEAN_TYPE);
3419 TYPE_PRECISION (boolean_type_node) = 1;
3420 fixup_unsigned_type (boolean_type_node);
3421 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
3422 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
3423 pushdecl (build_decl (TYPE_DECL, ridpointers[(int)RID_BOOL],
3424 boolean_type_node));
3426 /* TRUE and FALSE have the BOOL derived class */
3427 CH_DERIVED_FLAG (boolean_true_node) = 1;
3428 CH_DERIVED_FLAG (boolean_false_node) = 1;
3430 signed_boolean_type_node = make_node (BOOLEAN_TYPE);
3431 temp = build_int_2 (-1, -1);
3432 TREE_TYPE (temp) = signed_boolean_type_node;
3433 TYPE_MIN_VALUE (signed_boolean_type_node) = temp;
3434 temp = build_int_2 (0, 0);
3435 TREE_TYPE (temp) = signed_boolean_type_node;
3436 TYPE_MAX_VALUE (signed_boolean_type_node) = temp;
3437 layout_type (signed_boolean_type_node);
3440 bitstring_one_type_node = build_bitstring_type (integer_one_node);
3441 bit_zero_node = build (CONSTRUCTOR, bitstring_one_type_node, NULL_TREE,
3442 NULL_TREE);
3443 bit_one_node = build (CONSTRUCTOR, bitstring_one_type_node, NULL_TREE,
3444 build_tree_list (NULL_TREE, integer_zero_node));
3446 pushdecl (build_decl (TYPE_DECL, ridpointers[(int)RID_CHAR],
3447 char_type_node));
3449 if (CHILL_INT_IS_SHORT)
3451 chill_integer_type_node = short_integer_type_node;
3452 chill_unsigned_type_node = short_unsigned_type_node;
3454 else
3456 chill_integer_type_node = integer_type_node;
3457 chill_unsigned_type_node = unsigned_type_node;
3460 string_one_type_node = build_string_type (char_type_node, integer_one_node);
3462 pushdecl (build_decl (TYPE_DECL, ridpointers[(int)RID_BYTE],
3463 signed_char_type_node));
3464 pushdecl (build_decl (TYPE_DECL, ridpointers[(int)RID_UBYTE],
3465 unsigned_char_type_node));
3467 pushdecl (build_decl (TYPE_DECL, ridpointers[(int)RID_INT],
3468 chill_integer_type_node));
3470 pushdecl (build_decl (TYPE_DECL, ridpointers[(int)RID_UINT],
3471 chill_unsigned_type_node));
3473 pushdecl (build_decl (TYPE_DECL, ridpointers[(int)RID_LONG],
3474 long_integer_type_node));
3476 set_sizetype (long_integer_type_node);
3477 #if 0
3478 ptrdiff_type_node
3479 = TREE_TYPE (IDENTIFIER_LOCAL_VALUE (get_identifier (PTRDIFF_TYPE)));
3480 #endif
3481 pushdecl (build_decl (TYPE_DECL, ridpointers[(int)RID_ULONG],
3482 long_unsigned_type_node));
3483 pushdecl (build_decl (TYPE_DECL, ridpointers[(int)RID_REAL],
3484 float_type_node));
3485 pushdecl (build_decl (TYPE_DECL, ridpointers[(int)RID_LONG_REAL],
3486 double_type_node));
3487 pushdecl (build_decl (TYPE_DECL, ridpointers[(int)RID_PTR],
3488 ptr_type_node));
3490 IDENTIFIER_LOCAL_VALUE (ridpointers[(int)RID_TRUE]) =
3491 boolean_true_node;
3492 IDENTIFIER_LOCAL_VALUE (ridpointers[(int)RID_FALSE]) =
3493 boolean_false_node;
3494 IDENTIFIER_LOCAL_VALUE (ridpointers[(int)RID_NULL]) =
3495 null_pointer_node;
3497 /* The second operand is set to non-NULL to distinguish
3498 (ELSE) from (*). Used when writing grant files. */
3499 case_else_node = build (RANGE_EXPR,
3500 NULL_TREE, NULL_TREE, boolean_false_node);
3502 pushdecl (temp = build_decl (TYPE_DECL,
3503 get_identifier ("__tmp_initializer"),
3504 build_init_struct ()));
3505 DECL_SOURCE_LINE (temp) = 0;
3506 initializer_type = TREE_TYPE (temp);
3508 memcpy (tree_code_type + (int) LAST_AND_UNUSED_TREE_CODE,
3509 chill_tree_code_type,
3510 (((int) LAST_CHILL_TREE_CODE - (int) LAST_AND_UNUSED_TREE_CODE)
3511 * sizeof (char)));
3512 memcpy (tree_code_length + (int) LAST_AND_UNUSED_TREE_CODE,
3513 chill_tree_code_length,
3514 (((int) LAST_CHILL_TREE_CODE - (int) LAST_AND_UNUSED_TREE_CODE)
3515 * sizeof (int)));
3516 memcpy (tree_code_name + (int) LAST_AND_UNUSED_TREE_CODE,
3517 chill_tree_code_name,
3518 (((int) LAST_CHILL_TREE_CODE - (int) LAST_AND_UNUSED_TREE_CODE)
3519 * sizeof (char *)));
3520 boolean_code_name = (const char **) xcalloc (sizeof (char *),
3521 (int) LAST_CHILL_TREE_CODE);
3523 boolean_code_name[EQ_EXPR] = "=";
3524 boolean_code_name[NE_EXPR] = "/=";
3525 boolean_code_name[LT_EXPR] = "<";
3526 boolean_code_name[GT_EXPR] = ">";
3527 boolean_code_name[LE_EXPR] = "<=";
3528 boolean_code_name[GE_EXPR] = ">=";
3529 boolean_code_name[SET_IN_EXPR] = "in";
3530 boolean_code_name[TRUTH_ANDIF_EXPR] = "andif";
3531 boolean_code_name[TRUTH_ORIF_EXPR] = "orif";
3532 boolean_code_name[TRUTH_AND_EXPR] = "and";
3533 boolean_code_name[TRUTH_OR_EXPR] = "or";
3534 boolean_code_name[BIT_AND_EXPR] = "and";
3535 boolean_code_name[BIT_IOR_EXPR] = "or";
3536 boolean_code_name[BIT_XOR_EXPR] = "xor";
3538 endlink = void_list_node;
3540 chill_predefined_function_type
3541 = build_function_type (integer_type_node,
3542 tree_cons (NULL_TREE, integer_type_node,
3543 endlink));
3545 bool_ftype_int_ptr_int
3546 = build_function_type (boolean_type_node,
3547 tree_cons (NULL_TREE, integer_type_node,
3548 tree_cons (NULL_TREE, ptr_type_node,
3549 tree_cons (NULL_TREE, integer_type_node,
3550 endlink))));
3551 bool_ftype_int_ptr_int
3552 = build_function_type (boolean_type_node,
3553 tree_cons (NULL_TREE, integer_type_node,
3554 tree_cons (NULL_TREE, ptr_type_node,
3555 tree_cons (NULL_TREE, integer_type_node,
3556 tree_cons (NULL_TREE, integer_type_node,
3557 endlink)))));
3558 bool_ftype_int_ptr_int_int
3559 = build_function_type (boolean_type_node,
3560 tree_cons (NULL_TREE, integer_type_node,
3561 tree_cons (NULL_TREE, ptr_type_node,
3562 tree_cons (NULL_TREE, integer_type_node,
3563 tree_cons (NULL_TREE, integer_type_node,
3564 endlink)))));
3565 bool_ftype_luns_ptr_luns_long
3566 = build_function_type (boolean_type_node,
3567 tree_cons (NULL_TREE, long_unsigned_type_node,
3568 tree_cons (NULL_TREE, ptr_type_node,
3569 tree_cons (NULL_TREE, long_unsigned_type_node,
3570 tree_cons (NULL_TREE, long_integer_type_node,
3571 endlink)))));
3572 bool_ftype_luns_ptr_luns_long_ptr_int
3573 = build_function_type (boolean_type_node,
3574 tree_cons (NULL_TREE, long_unsigned_type_node,
3575 tree_cons (NULL_TREE, ptr_type_node,
3576 tree_cons (NULL_TREE, long_unsigned_type_node,
3577 tree_cons (NULL_TREE, long_integer_type_node,
3578 tree_cons (NULL_TREE, ptr_type_node,
3579 tree_cons (NULL_TREE, integer_type_node,
3580 endlink)))))));
3581 bool_ftype_ptr_ptr_int
3582 = build_function_type (boolean_type_node,
3583 tree_cons (NULL_TREE, ptr_type_node,
3584 tree_cons (NULL_TREE, ptr_type_node,
3585 tree_cons (NULL_TREE, integer_type_node,
3586 endlink))));
3587 bool_ftype_ptr_ptr_luns
3588 = build_function_type (boolean_type_node,
3589 tree_cons (NULL_TREE, ptr_type_node,
3590 tree_cons (NULL_TREE, ptr_type_node,
3591 tree_cons (NULL_TREE, long_unsigned_type_node,
3592 endlink))));
3593 bool_ftype_ptr_ptr_ptr_luns
3594 = build_function_type (boolean_type_node,
3595 tree_cons (NULL_TREE, ptr_type_node,
3596 tree_cons (NULL_TREE, ptr_type_node,
3597 tree_cons (NULL_TREE, ptr_type_node,
3598 tree_cons (NULL_TREE, long_unsigned_type_node,
3599 endlink)))));
3600 bool_ftype_ptr_int_ptr_int
3601 = build_function_type (boolean_type_node,
3602 tree_cons (NULL_TREE, ptr_type_node,
3603 tree_cons (NULL_TREE, integer_type_node,
3604 tree_cons (NULL_TREE, ptr_type_node,
3605 tree_cons (NULL_TREE, integer_type_node,
3606 endlink)))));
3607 bool_ftype_ptr_int_ptr_int_int
3608 = build_function_type (boolean_type_node,
3609 tree_cons (NULL_TREE, ptr_type_node,
3610 tree_cons (NULL_TREE, integer_type_node,
3611 tree_cons (NULL_TREE, ptr_type_node,
3612 tree_cons (NULL_TREE, integer_type_node,
3613 tree_cons (NULL_TREE, integer_type_node,
3614 endlink))))));
3615 find_bit_ftype
3616 = build_function_type (integer_type_node,
3617 tree_cons (NULL_TREE, ptr_type_node,
3618 tree_cons (NULL_TREE, long_unsigned_type_node,
3619 tree_cons (NULL_TREE, integer_type_node,
3620 endlink))));
3621 int_ftype_int
3622 = build_function_type (integer_type_node,
3623 tree_cons (NULL_TREE, integer_type_node,
3624 endlink));
3625 int_ftype_int_int
3626 = build_function_type (integer_type_node,
3627 tree_cons (NULL_TREE, integer_type_node,
3628 tree_cons (NULL_TREE, integer_type_node,
3629 endlink)));
3630 int_ftype_int_ptr_int
3631 = build_function_type (integer_type_node,
3632 tree_cons (NULL_TREE, integer_type_node,
3633 tree_cons (NULL_TREE, ptr_type_node,
3634 tree_cons (NULL_TREE, integer_type_node,
3635 endlink))));
3636 int_ftype_ptr
3637 = build_function_type (integer_type_node,
3638 tree_cons (NULL_TREE, ptr_type_node,
3639 endlink));
3640 int_ftype_ptr_int
3641 = build_function_type (integer_type_node,
3642 tree_cons (NULL_TREE, ptr_type_node,
3643 tree_cons (NULL_TREE, integer_type_node,
3644 endlink)));
3646 long_ftype_ptr_luns
3647 = build_function_type (long_integer_type_node,
3648 tree_cons (NULL_TREE, ptr_type_node,
3649 tree_cons (NULL_TREE, long_unsigned_type_node,
3650 endlink)));
3652 int_ftype_ptr_int_int_ptr_int
3653 = build_function_type (integer_type_node,
3654 tree_cons (NULL_TREE, ptr_type_node,
3655 tree_cons (NULL_TREE, integer_type_node,
3656 tree_cons (NULL_TREE, integer_type_node,
3657 tree_cons (NULL_TREE, ptr_type_node,
3658 tree_cons (NULL_TREE, integer_type_node,
3659 endlink))))));
3661 int_ftype_ptr_luns_long_ptr_int
3662 = build_function_type (integer_type_node,
3663 tree_cons (NULL_TREE, ptr_type_node,
3664 tree_cons (NULL_TREE, long_unsigned_type_node,
3665 tree_cons (NULL_TREE, long_integer_type_node,
3666 tree_cons (NULL_TREE, ptr_type_node,
3667 tree_cons (NULL_TREE, integer_type_node,
3668 endlink))))));
3670 int_ftype_ptr_ptr_int
3671 = build_function_type (integer_type_node,
3672 tree_cons (NULL_TREE, ptr_type_node,
3673 tree_cons (NULL_TREE, ptr_type_node,
3674 tree_cons (NULL_TREE, integer_type_node,
3675 endlink))));
3676 int_ftype_ptr_ptr_luns
3677 = build_function_type (integer_type_node,
3678 tree_cons (NULL_TREE, ptr_type_node,
3679 tree_cons (NULL_TREE, ptr_type_node,
3680 tree_cons (NULL_TREE, long_unsigned_type_node,
3681 endlink))));
3682 memcpy_ftype /* memcpy/memmove prototype */
3683 = build_function_type (ptr_type_node,
3684 tree_cons (NULL_TREE, ptr_type_node,
3685 tree_cons (NULL_TREE, const_ptr_type_node,
3686 tree_cons (NULL_TREE, sizetype,
3687 endlink))));
3688 memcmp_ftype /* memcmp prototype */
3689 = build_function_type (integer_type_node,
3690 tree_cons (NULL_TREE, ptr_type_node,
3691 tree_cons (NULL_TREE, ptr_type_node,
3692 tree_cons (NULL_TREE, sizetype,
3693 endlink))));
3695 ptr_ftype_ptr_int_int
3696 = build_function_type (ptr_type_node,
3697 tree_cons (NULL_TREE, ptr_type_node,
3698 tree_cons (NULL_TREE, integer_type_node,
3699 tree_cons (NULL_TREE, integer_type_node,
3700 endlink))));
3701 ptr_ftype_ptr_ptr_int
3702 = build_function_type (ptr_type_node,
3703 tree_cons (NULL_TREE, ptr_type_node,
3704 tree_cons (NULL_TREE, ptr_type_node,
3705 tree_cons (NULL_TREE, integer_type_node,
3706 endlink))));
3707 ptr_ftype_ptr_ptr_int_ptr_int
3708 = build_function_type (void_type_node,
3709 tree_cons (NULL_TREE, ptr_type_node,
3710 tree_cons (NULL_TREE, ptr_type_node,
3711 tree_cons (NULL_TREE, integer_type_node,
3712 tree_cons (NULL_TREE, ptr_type_node,
3713 tree_cons (NULL_TREE, integer_type_node,
3714 endlink))))));
3715 real_ftype_real
3716 = build_function_type (float_type_node,
3717 tree_cons (NULL_TREE, float_type_node,
3718 endlink));
3720 void_ftype_ptr
3721 = build_function_type (void_type_node,
3722 tree_cons (NULL_TREE, ptr_type_node, endlink));
3724 void_ftype_cptr_cptr_int
3725 = build_function_type (void_type_node,
3726 tree_cons (NULL_TREE, const_ptr_type_node,
3727 tree_cons (NULL_TREE, const_ptr_type_node,
3728 tree_cons (NULL_TREE, integer_type_node,
3729 endlink))));
3731 void_ftype_refptr_int_ptr_int
3732 = build_function_type (void_type_node,
3733 tree_cons (NULL_TREE, build_reference_type(ptr_type_node),
3734 tree_cons (NULL_TREE, integer_type_node,
3735 tree_cons (NULL_TREE, ptr_type_node,
3736 tree_cons (NULL_TREE, integer_type_node,
3737 endlink)))));
3739 void_ftype_ptr_ptr_ptr_int
3740 = build_function_type (void_type_node,
3741 tree_cons (NULL_TREE, ptr_type_node,
3742 tree_cons (NULL_TREE, ptr_type_node,
3743 tree_cons (NULL_TREE, ptr_type_node,
3744 tree_cons (NULL_TREE, integer_type_node,
3745 endlink)))));
3746 void_ftype_ptr_ptr_ptr_luns
3747 = build_function_type (void_type_node,
3748 tree_cons (NULL_TREE, ptr_type_node,
3749 tree_cons (NULL_TREE, ptr_type_node,
3750 tree_cons (NULL_TREE, ptr_type_node,
3751 tree_cons (NULL_TREE, long_unsigned_type_node,
3752 endlink)))));
3753 void_ftype_ptr_int_int_int_int
3754 = build_function_type (void_type_node,
3755 tree_cons (NULL_TREE, ptr_type_node,
3756 tree_cons (NULL_TREE, integer_type_node,
3757 tree_cons (NULL_TREE, integer_type_node,
3758 tree_cons (NULL_TREE, integer_type_node,
3759 tree_cons (NULL_TREE, integer_type_node,
3760 endlink))))));
3761 void_ftype_ptr_luns_long_long_bool_ptr_int
3762 = build_function_type (void_type_node,
3763 tree_cons (NULL_TREE, ptr_type_node,
3764 tree_cons (NULL_TREE, long_unsigned_type_node,
3765 tree_cons (NULL_TREE, long_integer_type_node,
3766 tree_cons (NULL_TREE, long_integer_type_node,
3767 tree_cons (NULL_TREE, boolean_type_node,
3768 tree_cons (NULL_TREE, ptr_type_node,
3769 tree_cons (NULL_TREE, integer_type_node,
3770 endlink))))))));
3771 void_ftype_ptr_int_ptr_int_int_int
3772 = build_function_type (void_type_node,
3773 tree_cons (NULL_TREE, ptr_type_node,
3774 tree_cons (NULL_TREE, integer_type_node,
3775 tree_cons (NULL_TREE, ptr_type_node,
3776 tree_cons (NULL_TREE, integer_type_node,
3777 tree_cons (NULL_TREE, integer_type_node,
3778 tree_cons (NULL_TREE, integer_type_node,
3779 endlink)))))));
3780 void_ftype_ptr_luns_ptr_luns_luns_luns
3781 = build_function_type (void_type_node,
3782 tree_cons (NULL_TREE, ptr_type_node,
3783 tree_cons (NULL_TREE, long_unsigned_type_node,
3784 tree_cons (NULL_TREE, ptr_type_node,
3785 tree_cons (NULL_TREE, long_unsigned_type_node,
3786 tree_cons (NULL_TREE, long_unsigned_type_node,
3787 tree_cons (NULL_TREE, long_unsigned_type_node,
3788 endlink)))))));
3789 void_ftype_ptr_int_ptr_int_ptr_int
3790 = build_function_type (void_type_node,
3791 tree_cons (NULL_TREE, ptr_type_node,
3792 tree_cons (NULL_TREE, integer_type_node,
3793 tree_cons (NULL_TREE, ptr_type_node,
3794 tree_cons (NULL_TREE, integer_type_node,
3795 tree_cons (NULL_TREE, ptr_type_node,
3796 tree_cons (NULL_TREE, integer_type_node,
3797 endlink)))))));
3798 void_ftype_long_int_ptr_int_ptr_int
3799 = build_function_type (void_type_node,
3800 tree_cons (NULL_TREE, long_integer_type_node,
3801 tree_cons (NULL_TREE, integer_type_node,
3802 tree_cons (NULL_TREE, ptr_type_node,
3803 tree_cons (NULL_TREE, integer_type_node,
3804 tree_cons (NULL_TREE, ptr_type_node,
3805 tree_cons (NULL_TREE, integer_type_node,
3806 endlink)))))));
3807 void_ftype_void
3808 = build_function_type (void_type_node,
3809 tree_cons (NULL_TREE, void_type_node,
3810 endlink));
3812 void_ftype_ptr_ptr_int
3813 = build_function_type (void_type_node,
3814 tree_cons (NULL_TREE, ptr_type_node,
3815 tree_cons (NULL_TREE, ptr_type_node,
3816 tree_cons (NULL_TREE, integer_type_node,
3817 endlink))));
3819 void_ftype_ptr_luns_luns_cptr_luns_luns_luns
3820 = build_function_type (void_type_node,
3821 tree_cons (NULL_TREE, ptr_type_node,
3822 tree_cons (NULL_TREE, long_unsigned_type_node,
3823 tree_cons (NULL_TREE, long_unsigned_type_node,
3824 tree_cons (NULL_TREE, const_ptr_type_node,
3825 tree_cons (NULL_TREE, long_unsigned_type_node,
3826 tree_cons (NULL_TREE, long_unsigned_type_node,
3827 tree_cons (NULL_TREE, long_unsigned_type_node,
3828 endlink))))))));
3830 ptr_ftype_luns_ptr_int
3831 = build_function_type (ptr_type_node,
3832 tree_cons (NULL_TREE, long_unsigned_type_node,
3833 tree_cons (NULL_TREE, ptr_type_node,
3834 tree_cons (NULL_TREE, integer_type_node,
3835 endlink))));
3837 double_ftype_double
3838 = build_function_type (double_type_node,
3839 tree_cons (NULL_TREE, double_type_node,
3840 endlink));
3842 /* These are compiler-internal function calls, not intended
3843 to be directly called by user code */
3844 builtin_function ("__allocate", ptr_ftype_luns_ptr_int,
3845 0, NOT_BUILT_IN, NULL_PTR);
3846 builtin_function ("_allocate_global_memory", void_ftype_refptr_int_ptr_int,
3847 0, NOT_BUILT_IN, NULL_PTR);
3848 builtin_function ("_allocate_memory", void_ftype_refptr_int_ptr_int,
3849 0, NOT_BUILT_IN, NULL_PTR);
3850 builtin_function ("__andpowerset", bool_ftype_ptr_ptr_ptr_luns,
3851 0, NOT_BUILT_IN, NULL_PTR);
3852 builtin_function ("__bitsetpowerset", void_ftype_ptr_int_int_int_int,
3853 0, NOT_BUILT_IN, NULL_PTR);
3854 builtin_function ("__cardpowerset", long_ftype_ptr_luns,
3855 0, NOT_BUILT_IN, NULL_PTR);
3856 builtin_function ("__cause_ex1", void_ftype_cptr_cptr_int,
3857 0, NOT_BUILT_IN, NULL_PTR);
3858 builtin_function ("__concatstring", ptr_ftype_ptr_ptr_int_ptr_int,
3859 0, NOT_BUILT_IN, NULL_PTR);
3860 builtin_function ("__continue", void_ftype_ptr_ptr_int,
3861 0, NOT_BUILT_IN, NULL_PTR);
3862 builtin_function ("__diffpowerset", void_ftype_ptr_ptr_ptr_luns,
3863 0, NOT_BUILT_IN, NULL_PTR);
3864 builtin_function ("__eqpowerset", bool_ftype_ptr_ptr_luns,
3865 0, NOT_BUILT_IN, NULL_PTR);
3866 builtin_function ("__ffsetclrpowerset", find_bit_ftype,
3867 0, NOT_BUILT_IN, NULL_PTR);
3868 builtin_function ("__flsetclrpowerset", find_bit_ftype,
3869 0, NOT_BUILT_IN, NULL_PTR);
3870 builtin_function ("__flsetpowerset", int_ftype_ptr_luns_long_ptr_int,
3871 0, NOT_BUILT_IN, NULL_PTR);
3872 builtin_function ("__ffsetpowerset", int_ftype_ptr_luns_long_ptr_int,
3873 0, NOT_BUILT_IN, NULL_PTR);
3874 builtin_function ("__inbitstring", bool_ftype_luns_ptr_luns_long_ptr_int,
3875 0, NOT_BUILT_IN, NULL_PTR);
3876 builtin_function ("__inpowerset", bool_ftype_luns_ptr_luns_long,
3877 0, NOT_BUILT_IN, NULL_PTR);
3878 builtin_function ("__lepowerset", bool_ftype_ptr_ptr_luns,
3879 0, NOT_BUILT_IN, NULL_PTR);
3880 builtin_function ("__ltpowerset", bool_ftype_ptr_ptr_luns,
3881 0, NOT_BUILT_IN, NULL_PTR);
3882 /* Currently under experimentation. */
3883 builtin_function ("memmove", memcpy_ftype,
3884 0, NOT_BUILT_IN, NULL_PTR);
3885 builtin_function ("memcmp", memcmp_ftype,
3886 0, NOT_BUILT_IN, NULL_PTR);
3888 /* this comes from c-decl.c (init_decl_processing) */
3889 builtin_function ("__builtin_alloca",
3890 build_function_type (ptr_type_node,
3891 tree_cons (NULL_TREE,
3892 sizetype,
3893 endlink)),
3894 BUILT_IN_ALLOCA, BUILT_IN_NORMAL, "alloca");
3896 builtin_function ("memset", ptr_ftype_ptr_int_int,
3897 0, NOT_BUILT_IN, NULL_PTR);
3898 builtin_function ("__notpowerset", bool_ftype_ptr_ptr_luns,
3899 0, NOT_BUILT_IN, NULL_PTR);
3900 builtin_function ("__orpowerset", bool_ftype_ptr_ptr_ptr_luns,
3901 0, NOT_BUILT_IN, NULL_PTR);
3902 builtin_function ("__psslice", void_ftype_ptr_int_ptr_int_int_int,
3903 0, NOT_BUILT_IN, NULL_PTR);
3904 builtin_function ("__pscpy", void_ftype_ptr_luns_luns_cptr_luns_luns_luns,
3905 0, NOT_BUILT_IN, NULL_PTR);
3906 builtin_function ("_return_memory", void_ftype_ptr_ptr_int,
3907 0, NOT_BUILT_IN, NULL_PTR);
3908 builtin_function ("__setbitpowerset", void_ftype_ptr_luns_long_long_bool_ptr_int,
3909 0, NOT_BUILT_IN, NULL_PTR);
3910 builtin_function ("__terminate", void_ftype_ptr_ptr_int,
3911 0, NOT_BUILT_IN, NULL_PTR);
3912 builtin_function ("__unhandled_ex", void_ftype_cptr_cptr_int,
3913 0, NOT_BUILT_IN, NULL_PTR);
3914 builtin_function ("__xorpowerset", bool_ftype_ptr_ptr_ptr_luns,
3915 0, NOT_BUILT_IN, NULL_PTR);
3917 /* declare floating point functions */
3918 builtin_function ("__sin", double_ftype_double, 0, NOT_BUILT_IN, "sin");
3919 builtin_function ("__cos", double_ftype_double, 0, NOT_BUILT_IN, "cos");
3920 builtin_function ("__tan", double_ftype_double, 0, NOT_BUILT_IN, "tan");
3921 builtin_function ("__asin", double_ftype_double, 0, NOT_BUILT_IN, "asin");
3922 builtin_function ("__acos", double_ftype_double, 0, NOT_BUILT_IN, "acos");
3923 builtin_function ("__atan", double_ftype_double, 0, NOT_BUILT_IN, "atan");
3924 builtin_function ("__exp", double_ftype_double, 0, NOT_BUILT_IN, "exp");
3925 builtin_function ("__log", double_ftype_double, 0, NOT_BUILT_IN, "log");
3926 builtin_function ("__log10", double_ftype_double, 0, NOT_BUILT_IN, "log10");
3927 builtin_function ("__sqrt", double_ftype_double, 0, NOT_BUILT_IN, "sqrt");
3929 tasking_init ();
3930 timing_init ();
3931 inout_init ();
3933 /* These are predefined value builtin routine calls, built
3934 by the compiler, but over-ridable by user procedures of
3935 the same names. Note the lack of a leading underscore. */
3936 builtin_function ((ignore_case || ! special_UC) ? "abs" : "ABS",
3937 chill_predefined_function_type,
3938 BUILT_IN_CH_ABS, BUILT_IN_NORMAL, NULL_PTR);
3939 builtin_function ((ignore_case || ! special_UC) ? "abstime" : "ABSTIME",
3940 chill_predefined_function_type,
3941 BUILT_IN_ABSTIME, BUILT_IN_NORMAL, NULL_PTR);
3942 builtin_function ((ignore_case || ! special_UC) ? "allocate" : "ALLOCATE",
3943 chill_predefined_function_type,
3944 BUILT_IN_ALLOCATE, BUILT_IN_NORMAL, NULL_PTR);
3945 builtin_function ((ignore_case || ! special_UC) ? "allocate_memory" : "ALLOCATE_MEMORY",
3946 chill_predefined_function_type,
3947 BUILT_IN_ALLOCATE_MEMORY, BUILT_IN_NORMAL, NULL_PTR);
3948 builtin_function ((ignore_case || ! special_UC) ? "addr" : "ADDR",
3949 chill_predefined_function_type,
3950 BUILT_IN_ADDR, BUILT_IN_NORMAL, NULL_PTR);
3951 builtin_function ((ignore_case || ! special_UC) ? "allocate_global_memory" : "ALLOCATE_GLOBAL_MEMORY",
3952 chill_predefined_function_type,
3953 BUILT_IN_ALLOCATE_GLOBAL_MEMORY, BUILT_IN_NORMAL, NULL_PTR);
3954 builtin_function ((ignore_case || ! special_UC) ? "arccos" : "ARCCOS",
3955 chill_predefined_function_type,
3956 BUILT_IN_ARCCOS, BUILT_IN_NORMAL, NULL_PTR);
3957 builtin_function ((ignore_case || ! special_UC) ? "arcsin" : "ARCSIN",
3958 chill_predefined_function_type,
3959 BUILT_IN_ARCSIN, BUILT_IN_NORMAL, NULL_PTR);
3960 builtin_function ((ignore_case || ! special_UC) ? "arctan" : "ARCTAN",
3961 chill_predefined_function_type,
3962 BUILT_IN_ARCTAN, BUILT_IN_NORMAL, NULL_PTR);
3963 builtin_function ((ignore_case || ! special_UC) ? "card" : "CARD",
3964 chill_predefined_function_type,
3965 BUILT_IN_CARD, BUILT_IN_NORMAL, NULL_PTR);
3966 builtin_function ((ignore_case || ! special_UC) ? "cos" : "COS",
3967 chill_predefined_function_type,
3968 BUILT_IN_CH_COS, BUILT_IN_NORMAL, NULL_PTR);
3969 builtin_function ((ignore_case || ! special_UC) ? "days" : "DAYS",
3970 chill_predefined_function_type,
3971 BUILT_IN_DAYS, BUILT_IN_NORMAL, NULL_PTR);
3972 builtin_function ((ignore_case || ! special_UC) ? "descr" : "DESCR",
3973 chill_predefined_function_type,
3974 BUILT_IN_DESCR, BUILT_IN_NORMAL, NULL_PTR);
3975 builtin_function ((ignore_case || ! special_UC) ? "getstack" : "GETSTACK",
3976 chill_predefined_function_type,
3977 BUILT_IN_GETSTACK, BUILT_IN_NORMAL, NULL_PTR);
3978 builtin_function ((ignore_case || ! special_UC) ? "exp" : "EXP",
3979 chill_predefined_function_type,
3980 BUILT_IN_EXP, BUILT_IN_NORMAL, NULL_PTR);
3981 builtin_function ((ignore_case || ! special_UC) ? "hours" : "HOURS",
3982 chill_predefined_function_type,
3983 BUILT_IN_HOURS, BUILT_IN_NORMAL, NULL_PTR);
3984 builtin_function ((ignore_case || ! special_UC) ? "inttime" : "INTTIME",
3985 chill_predefined_function_type,
3986 BUILT_IN_INTTIME, BUILT_IN_NORMAL, NULL_PTR);
3987 builtin_function ((ignore_case || ! special_UC) ? "length" : "LENGTH",
3988 chill_predefined_function_type,
3989 BUILT_IN_LENGTH, BUILT_IN_NORMAL, NULL_PTR);
3990 builtin_function ((ignore_case || ! special_UC) ? "log" : "LOG",
3991 chill_predefined_function_type,
3992 BUILT_IN_LOG, BUILT_IN_NORMAL, NULL_PTR);
3993 builtin_function ((ignore_case || ! special_UC) ? "lower" : "LOWER",
3994 chill_predefined_function_type,
3995 BUILT_IN_LOWER, BUILT_IN_NORMAL, NULL_PTR);
3996 builtin_function ((ignore_case || ! special_UC) ? "ln" : "LN",
3997 chill_predefined_function_type,
3998 BUILT_IN_LN, BUILT_IN_NORMAL, NULL_PTR);
3999 /* Note: these are *not* the C integer MAX and MIN. They're
4000 for powerset arguments. */
4001 builtin_function ((ignore_case || ! special_UC) ? "max" : "MAX",
4002 chill_predefined_function_type,
4003 BUILT_IN_MAX, BUILT_IN_NORMAL, NULL_PTR);
4004 builtin_function ((ignore_case || ! special_UC) ? "millisecs" : "MILLISECS",
4005 chill_predefined_function_type,
4006 BUILT_IN_MILLISECS, BUILT_IN_NORMAL, NULL_PTR);
4007 builtin_function ((ignore_case || ! special_UC) ? "min" : "MIN",
4008 chill_predefined_function_type,
4009 BUILT_IN_MIN, BUILT_IN_NORMAL, NULL_PTR);
4010 builtin_function ((ignore_case || ! special_UC) ? "minutes" : "MINUTES",
4011 chill_predefined_function_type,
4012 BUILT_IN_MINUTES, BUILT_IN_NORMAL, NULL_PTR);
4013 builtin_function ((ignore_case || ! special_UC) ? "num" : "NUM",
4014 chill_predefined_function_type,
4015 BUILT_IN_NUM, BUILT_IN_NORMAL, NULL_PTR);
4016 builtin_function ((ignore_case || ! special_UC) ? "pred" : "PRED",
4017 chill_predefined_function_type,
4018 BUILT_IN_PRED, BUILT_IN_NORMAL, NULL_PTR);
4019 builtin_function ((ignore_case || ! special_UC) ? "return_memory" : "RETURN_MEMORY",
4020 chill_predefined_function_type,
4021 BUILT_IN_RETURN_MEMORY, BUILT_IN_NORMAL, NULL_PTR);
4022 builtin_function ((ignore_case || ! special_UC) ? "secs" : "SECS",
4023 chill_predefined_function_type,
4024 BUILT_IN_SECS, BUILT_IN_NORMAL, NULL_PTR);
4025 builtin_function ((ignore_case || ! special_UC) ? "sin" : "SIN",
4026 chill_predefined_function_type,
4027 BUILT_IN_CH_SIN, BUILT_IN_NORMAL, NULL_PTR);
4028 builtin_function ((ignore_case || ! special_UC) ? "size" : "SIZE",
4029 chill_predefined_function_type,
4030 BUILT_IN_SIZE, BUILT_IN_NORMAL, NULL_PTR);
4031 builtin_function ((ignore_case || ! special_UC) ? "sqrt" : "SQRT",
4032 chill_predefined_function_type,
4033 BUILT_IN_SQRT, BUILT_IN_NORMAL, NULL_PTR);
4034 builtin_function ((ignore_case || ! special_UC) ? "succ" : "SUCC",
4035 chill_predefined_function_type,
4036 BUILT_IN_SUCC, BUILT_IN_NORMAL, NULL_PTR);
4037 builtin_function ((ignore_case || ! special_UC) ? "tan" : "TAN",
4038 chill_predefined_function_type,
4039 BUILT_IN_TAN, BUILT_IN_NORMAL, NULL_PTR);
4040 builtin_function ((ignore_case || ! special_UC) ? "terminate" : "TERMINATE",
4041 chill_predefined_function_type,
4042 BUILT_IN_TERMINATE, BUILT_IN_NORMAL, NULL_PTR);
4043 builtin_function ((ignore_case || ! special_UC) ? "upper" : "UPPER",
4044 chill_predefined_function_type,
4045 BUILT_IN_UPPER, BUILT_IN_NORMAL, NULL_PTR);
4047 build_chill_descr_type ();
4048 build_chill_inttime_type ();
4050 endlink = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
4052 start_identifier_warnings ();
4054 pass = 1;
4057 /* Return a definition for a builtin function named NAME and whose data type
4058 is TYPE. TYPE should be a function type with argument types.
4059 FUNCTION_CODE tells later passes how to compile calls to this function.
4060 See tree.h for its possible values.
4062 If LIBRARY_NAME is nonzero, use that for DECL_ASSEMBLER_NAME,
4063 the name to be called if we can't opencode the function. */
4065 tree
4066 builtin_function (name, type, function_code, class, library_name)
4067 const char *name;
4068 tree type;
4069 int function_code;
4070 enum built_in_class class;
4071 const char *library_name;
4073 tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
4074 DECL_EXTERNAL (decl) = 1;
4075 TREE_PUBLIC (decl) = 1;
4076 /* If -traditional, permit redefining a builtin function any way you like.
4077 (Though really, if the program redefines these functions,
4078 it probably won't work right unless compiled with -fno-builtin.) */
4079 if (flag_traditional && name[0] != '_')
4080 DECL_BUILT_IN_NONANSI (decl) = 1;
4081 if (library_name)
4082 DECL_ASSEMBLER_NAME (decl) = get_identifier (library_name);
4083 make_decl_rtl (decl, NULL_PTR, 1);
4084 pushdecl (decl);
4085 DECL_BUILT_IN_CLASS (decl) = class;
4086 DECL_FUNCTION_CODE (decl) = function_code;
4088 return decl;
4091 /* Print a warning if a constant expression had overflow in folding.
4092 Invoke this function on every expression that the language
4093 requires to be a constant expression. */
4095 void
4096 constant_expression_warning (value)
4097 tree value;
4099 if ((TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST
4100 || TREE_CODE (value) == COMPLEX_CST)
4101 && TREE_CONSTANT_OVERFLOW (value) && pedantic)
4102 pedwarn ("overflow in constant expression");
4106 /* Finish processing of a declaration;
4107 If the length of an array type is not known before,
4108 it must be determined now, from the initial value, or it is an error. */
4110 void
4111 finish_decl (decl)
4112 tree decl;
4114 int was_incomplete = (DECL_SIZE (decl) == 0);
4115 int temporary = allocation_temporary_p ();
4117 /* Pop back to the obstack that is current for this binding level.
4118 This is because MAXINDEX, rtl, etc. to be made below
4119 must go in the permanent obstack. But don't discard the
4120 temporary data yet. */
4121 pop_obstacks ();
4122 #if 0 /* pop_obstacks was near the end; this is what was here. */
4123 if (current_scope == global_scope && temporary)
4124 end_temporary_allocation ();
4125 #endif
4127 if (TREE_CODE (decl) == VAR_DECL)
4129 if (DECL_SIZE (decl) == 0
4130 && TYPE_SIZE (TREE_TYPE (decl)) != 0)
4131 layout_decl (decl, 0);
4133 if (DECL_SIZE (decl) == 0 && TREE_CODE (TREE_TYPE (decl)) != ERROR_MARK)
4135 error_with_decl (decl, "storage size of `%s' isn't known");
4136 TREE_TYPE (decl) = error_mark_node;
4139 if ((DECL_EXTERNAL (decl) || TREE_STATIC (decl))
4140 && DECL_SIZE (decl) != 0)
4142 if (TREE_CODE (DECL_SIZE (decl)) == INTEGER_CST)
4143 constant_expression_warning (DECL_SIZE (decl));
4147 /* Output the assembler code and/or RTL code for variables and functions,
4148 unless the type is an undefined structure or union.
4149 If not, it will get done when the type is completed. */
4151 if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)
4153 /* The last argument (at_end) is set to 1 as a kludge to force
4154 assemble_variable to be called. */
4155 if (TREE_CODE (TREE_TYPE (decl)) != ERROR_MARK)
4156 rest_of_decl_compilation (decl, (char*) 0, global_bindings_p (), 1);
4158 /* Compute the RTL of a decl if not yet set.
4159 (For normal user variables, satisfy_decl sets it.) */
4160 if (! TREE_STATIC (decl) && ! DECL_EXTERNAL (decl))
4162 if (was_incomplete)
4164 /* If we used it already as memory, it must stay in memory. */
4165 TREE_ADDRESSABLE (decl) = TREE_USED (decl);
4166 /* If it's still incomplete now, no init will save it. */
4167 if (DECL_SIZE (decl) == 0)
4168 DECL_INITIAL (decl) = 0;
4169 expand_decl (decl);
4174 if (TREE_CODE (decl) == TYPE_DECL)
4176 rest_of_decl_compilation (decl, NULL_PTR,
4177 global_bindings_p (), 0);
4180 /* ??? After 2.3, test (init != 0) instead of TREE_CODE. */
4181 if (!(TREE_CODE (decl) == FUNCTION_DECL && DECL_INLINE (decl))
4182 && temporary && TREE_PERMANENT (decl))
4184 /* We need to remember that this array HAD an initialization,
4185 but discard the actual temporary nodes,
4186 since we can't have a permanent node keep pointing to them. */
4187 /* We make an exception for inline functions, since it's
4188 normal for a local extern redeclaration of an inline function
4189 to have a copy of the top-level decl's DECL_INLINE. */
4190 if (DECL_INITIAL (decl) != 0)
4191 DECL_INITIAL (decl) = error_mark_node;
4194 #if 0
4195 /* Resume permanent allocation, if not within a function. */
4196 /* The corresponding push_obstacks_nochange is in start_decl,
4197 and in push_parm_decl and in grokfield. */
4198 pop_obstacks ();
4199 #endif
4201 /* If we have gone back from temporary to permanent allocation,
4202 actually free the temporary space that we no longer need. */
4203 if (temporary && !allocation_temporary_p ())
4204 permanent_allocation (0);
4206 /* At the end of a declaration, throw away any variable type sizes
4207 of types defined inside that declaration. There is no use
4208 computing them in the following function definition. */
4209 if (current_scope == global_scope)
4210 get_pending_sizes ();
4213 /* If DECL has a cleanup, build and return that cleanup here.
4214 This is a callback called by expand_expr. */
4216 tree
4217 maybe_build_cleanup (decl)
4218 tree decl ATTRIBUTE_UNUSED;
4220 /* There are no cleanups in C. */
4221 return NULL_TREE;
4224 /* Make TYPE a complete type based on INITIAL_VALUE.
4225 Return 0 if successful, 1 if INITIAL_VALUE can't be deciphered,
4226 2 if there was no information (in which case assume 1 if DO_DEFAULT). */
4229 complete_array_type (type, initial_value, do_default)
4230 tree type ATTRIBUTE_UNUSED, initial_value ATTRIBUTE_UNUSED;
4231 int do_default ATTRIBUTE_UNUSED;
4233 /* Only needed so we can link with ../c-typeck.c. */
4234 abort ();
4237 /* Make sure that the tag NAME is defined *in the current binding level*
4238 at least as a forward reference.
4239 CODE says which kind of tag NAME ought to be.
4241 We also do a push_obstacks_nochange
4242 whose matching pop is in finish_struct. */
4244 tree
4245 start_struct (code, name)
4246 enum chill_tree_code code;
4247 tree name ATTRIBUTE_UNUSED;
4249 /* If there is already a tag defined at this binding level
4250 (as a forward reference), just return it. */
4252 register tree ref = 0;
4254 push_obstacks_nochange ();
4255 if (current_scope == global_scope)
4256 end_temporary_allocation ();
4258 /* Otherwise create a forward-reference just so the tag is in scope. */
4260 ref = make_node (code);
4261 /* pushtag (name, ref); */
4262 return ref;
4265 #if 0
4266 /* Function to help qsort sort FIELD_DECLs by name order. */
4268 static int
4269 field_decl_cmp (x, y)
4270 tree *x, *y;
4272 return (long)DECL_NAME (*x) - (long)DECL_NAME (*y);
4274 #endif
4275 /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T.
4276 FIELDLIST is a chain of FIELD_DECL nodes for the fields.
4278 We also do a pop_obstacks to match the push in start_struct. */
4280 tree
4281 finish_struct (t, fieldlist)
4282 register tree t, fieldlist;
4284 register tree x;
4286 /* Install struct as DECL_CONTEXT of each field decl. */
4287 for (x = fieldlist; x; x = TREE_CHAIN (x))
4288 DECL_CONTEXT (x) = t;
4290 TYPE_FIELDS (t) = fieldlist;
4292 if (pass != 1)
4293 t = layout_chill_struct_type (t);
4295 /* The matching push is in start_struct. */
4296 pop_obstacks ();
4298 return t;
4301 /* Lay out the type T, and its element type, and so on. */
4303 static void
4304 layout_array_type (t)
4305 tree t;
4307 if (TYPE_SIZE (t) != 0)
4308 return;
4309 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
4310 layout_array_type (TREE_TYPE (t));
4311 layout_type (t);
4314 /* Begin compiling the definition of an enumeration type.
4315 NAME is its name (or null if anonymous).
4316 Returns the type object, as yet incomplete.
4317 Also records info about it so that build_enumerator
4318 may be used to declare the individual values as they are read. */
4320 tree
4321 start_enum (name)
4322 tree name ATTRIBUTE_UNUSED;
4324 register tree enumtype;
4326 /* If this is the real definition for a previous forward reference,
4327 fill in the contents in the same object that used to be the
4328 forward reference. */
4330 #if 0
4331 /* The corresponding pop_obstacks is in finish_enum. */
4332 push_obstacks_nochange ();
4333 /* If these symbols and types are global, make them permanent. */
4334 if (current_scope == global_scope)
4335 end_temporary_allocation ();
4336 #endif
4338 enumtype = make_node (ENUMERAL_TYPE);
4339 /* pushtag (name, enumtype); */
4340 return enumtype;
4343 /* Determine the precision this type needs. */
4344 unsigned
4345 get_type_precision (minnode, maxnode)
4346 tree minnode, maxnode;
4348 unsigned precision = 0;
4350 if (TREE_INT_CST_HIGH (minnode) >= 0
4351 ? tree_int_cst_lt (TYPE_MAX_VALUE (unsigned_type_node), maxnode)
4352 : (tree_int_cst_lt (minnode, TYPE_MIN_VALUE (integer_type_node))
4353 || tree_int_cst_lt (TYPE_MAX_VALUE (integer_type_node), maxnode)))
4354 precision = TYPE_PRECISION (long_long_integer_type_node);
4355 else
4357 HOST_WIDE_INT maxvalue = TREE_INT_CST_LOW (maxnode);
4358 HOST_WIDE_INT minvalue = TREE_INT_CST_LOW (minnode);
4360 if (maxvalue > 0)
4361 precision = floor_log2 (maxvalue) + 1;
4362 if (minvalue < 0)
4364 /* Compute number of bits to represent magnitude of a negative value.
4365 Add one to MINVALUE since range of negative numbers
4366 includes the power of two. */
4367 unsigned negprecision = floor_log2 (-minvalue - 1) + 1;
4368 if (negprecision > precision)
4369 precision = negprecision;
4370 precision += 1; /* room for sign bit */
4373 if (!precision)
4374 precision = 1;
4376 return precision;
4379 void
4380 layout_enum (enumtype)
4381 tree enumtype;
4383 register tree pair, tem;
4384 tree minnode = 0, maxnode = 0;
4385 unsigned precision = 0;
4387 /* Do arithmetic using double integers, but don't use fold/build. */
4388 union tree_node enum_next_node;
4389 /* This is 1 plus the last enumerator constant value. */
4390 tree enum_next_value = &enum_next_node;
4392 /* Nonzero means that there was overflow computing enum_next_value. */
4393 int enum_overflow = 0;
4395 tree values = TYPE_VALUES (enumtype);
4397 if (TYPE_SIZE (enumtype) != NULL_TREE)
4398 return;
4400 /* Initialize enum_next_value to zero. */
4401 TREE_TYPE (enum_next_value) = integer_type_node;
4402 TREE_INT_CST_LOW (enum_next_value) = TREE_INT_CST_LOW (integer_zero_node);
4403 TREE_INT_CST_HIGH (enum_next_value) = TREE_INT_CST_HIGH (integer_zero_node);
4405 /* After processing and defining all the values of an enumeration type,
4406 install their decls in the enumeration type and finish it off.
4408 TYPE_VALUES currently contains a list of (purpose: NAME, value: DECL).
4409 This gets converted to a list of (purpose: NAME, value: VALUE). */
4412 /* For each enumerator, calculate values, if defaulted.
4413 Convert to correct type (the enumtype).
4414 Also, calculate the minimum and maximum values. */
4416 for (pair = values; pair; pair = TREE_CHAIN (pair))
4418 tree decl = TREE_VALUE (pair);
4419 tree value = DECL_INITIAL (decl);
4421 /* Remove no-op casts from the value. */
4422 if (value != NULL_TREE)
4423 STRIP_TYPE_NOPS (value);
4425 if (value != NULL_TREE)
4427 if (TREE_CODE (value) == INTEGER_CST)
4429 constant_expression_warning (value);
4430 if (tree_int_cst_lt (value, integer_zero_node))
4432 error ("enumerator value for `%s' is less then 0",
4433 IDENTIFIER_POINTER (DECL_NAME (decl)));
4434 value = error_mark_node;
4437 else
4439 error ("enumerator value for `%s' not integer constant",
4440 IDENTIFIER_POINTER (DECL_NAME (decl)));
4441 value = error_mark_node;
4445 if (value != error_mark_node)
4447 if (value == NULL_TREE) /* Default based on previous value. */
4449 value = enum_next_value;
4450 if (enum_overflow)
4451 error ("overflow in enumeration values");
4453 value = build_int_2 (TREE_INT_CST_LOW (value),
4454 TREE_INT_CST_HIGH (value));
4455 TREE_TYPE (value) = enumtype;
4456 DECL_INITIAL (decl) = value;
4457 CH_DERIVED_FLAG (value) = 1;
4459 if (pair == values)
4460 minnode = maxnode = value;
4461 else
4463 if (tree_int_cst_lt (maxnode, value))
4464 maxnode = value;
4465 if (tree_int_cst_lt (value, minnode))
4466 minnode = value;
4469 /* Set basis for default for next value. */
4470 add_double (TREE_INT_CST_LOW (value), TREE_INT_CST_HIGH (value), 1, 0,
4471 &TREE_INT_CST_LOW (enum_next_value),
4472 &TREE_INT_CST_HIGH (enum_next_value));
4473 enum_overflow = tree_int_cst_lt (enum_next_value, value);
4475 else
4476 DECL_INITIAL (decl) = value; /* error_mark_node */
4479 /* Fix all error_mark_nodes in enum. Increment maxnode and assign value.
4480 This is neccessary to make a duplicate value check in the enum */
4481 for (pair = values; pair; pair = TREE_CHAIN (pair))
4483 tree decl = TREE_VALUE (pair);
4484 if (DECL_INITIAL (decl) == error_mark_node)
4486 tree value;
4487 add_double (TREE_INT_CST_LOW (maxnode), TREE_INT_CST_HIGH (maxnode), 1, 0,
4488 &TREE_INT_CST_LOW (enum_next_value),
4489 &TREE_INT_CST_HIGH (enum_next_value));
4490 value = build_int_2 (TREE_INT_CST_LOW (enum_next_value),
4491 TREE_INT_CST_HIGH (enum_next_value));
4492 TREE_TYPE (value) = enumtype;
4493 CH_DERIVED_FLAG (value) = 1;
4494 DECL_INITIAL (decl) = value;
4496 maxnode = value;
4500 /* Now check if we have duplicate values within the enum */
4501 for (pair = values; pair; pair = TREE_CHAIN (pair))
4503 tree succ;
4504 tree decl1 = TREE_VALUE (pair);
4505 tree val1 = DECL_INITIAL (decl1);
4507 for (succ = TREE_CHAIN (pair); succ; succ = TREE_CHAIN (succ))
4509 if (pair != succ)
4511 tree decl2 = TREE_VALUE (succ);
4512 tree val2 = DECL_INITIAL (decl2);
4513 if (tree_int_cst_equal (val1, val2))
4514 error ("enumerators `%s' and `%s' have equal values",
4515 IDENTIFIER_POINTER (DECL_NAME (decl1)),
4516 IDENTIFIER_POINTER (DECL_NAME (decl2)));
4521 TYPE_MIN_VALUE (enumtype) = minnode;
4522 TYPE_MAX_VALUE (enumtype) = maxnode;
4524 precision = get_type_precision (minnode, maxnode);
4526 if (flag_short_enums || precision > TYPE_PRECISION (integer_type_node))
4527 /* Use the width of the narrowest normal C type which is wide enough. */
4528 TYPE_PRECISION (enumtype) = TYPE_PRECISION (type_for_size (precision, 1));
4529 else
4530 TYPE_PRECISION (enumtype) = TYPE_PRECISION (integer_type_node);
4532 layout_type (enumtype);
4534 #if 0
4535 /* An enum can have some negative values; then it is signed. */
4536 TREE_UNSIGNED (enumtype) = ! tree_int_cst_lt (minnode, integer_zero_node);
4537 #else
4538 /* Z200/1988 page 19 says:
4539 For each pair of integer literal expression e1, e2 in the set list NUM (e1)
4540 and NUM (e2) must deliver different non-negative results */
4541 TREE_UNSIGNED (enumtype) = 1;
4542 #endif
4544 for (pair = values; pair; pair = TREE_CHAIN (pair))
4546 tree decl = TREE_VALUE (pair);
4548 DECL_SIZE (decl) = TYPE_SIZE (enumtype);
4549 DECL_SIZE_UNIT (decl) = TYPE_SIZE_UNIT (enumtype);
4550 DECL_ALIGN (decl) = TYPE_ALIGN (enumtype);
4551 DECL_USER_ALIGN (decl) = TYPE_USER_ALIGN (enumtype);
4553 /* Set the TREE_VALUE to the name, rather than the decl,
4554 since that is what the rest of the compiler expects. */
4555 TREE_VALUE (pair) = DECL_INITIAL (decl);
4558 /* Fix up all variant types of this enum type. */
4559 for (tem = TYPE_MAIN_VARIANT (enumtype); tem; tem = TYPE_NEXT_VARIANT (tem))
4561 TYPE_VALUES (tem) = TYPE_VALUES (enumtype);
4562 TYPE_MIN_VALUE (tem) = TYPE_MIN_VALUE (enumtype);
4563 TYPE_MAX_VALUE (tem) = TYPE_MAX_VALUE (enumtype);
4564 TYPE_SIZE (tem) = TYPE_SIZE (enumtype);
4565 TYPE_MODE (tem) = TYPE_MODE (enumtype);
4566 TYPE_PRECISION (tem) = TYPE_PRECISION (enumtype);
4567 TYPE_ALIGN (tem) = TYPE_ALIGN (enumtype);
4568 TYPE_USER_ALIGN (tem) = TYPE_USER_ALIGN (enumtype);
4569 TREE_UNSIGNED (tem) = TREE_UNSIGNED (enumtype);
4572 #if 0
4573 /* This matches a push in start_enum. */
4574 pop_obstacks ();
4575 #endif
4578 tree
4579 finish_enum (enumtype, values)
4580 register tree enumtype, values;
4582 TYPE_VALUES (enumtype) = values = nreverse (values);
4584 /* If satisfy_decl is called on one of the enum CONST_DECLs,
4585 this will make sure that the enumtype gets laid out then. */
4586 for ( ; values; values = TREE_CHAIN (values))
4587 TREE_TYPE (TREE_VALUE (values)) = enumtype;
4589 return enumtype;
4593 /* Build and install a CONST_DECL for one value of the
4594 current enumeration type (one that was begun with start_enum).
4595 Return a tree-list containing the CONST_DECL and its value.
4596 Assignment of sequential values by default is handled here. */
4598 tree
4599 build_enumerator (name, value)
4600 tree name, value;
4602 register tree decl;
4603 int named = name != NULL_TREE;
4605 if (pass == 2)
4607 if (name)
4608 (void) get_next_decl ();
4609 return NULL_TREE;
4612 if (name == NULL_TREE)
4614 static int unnamed_value_warned = 0;
4615 static int next_dummy_enum_value = 0;
4616 char buf[20];
4617 if (!unnamed_value_warned)
4619 unnamed_value_warned = 1;
4620 warning ("undefined value in SET mode is obsolete and deprecated.");
4622 sprintf (buf, "__star_%d", next_dummy_enum_value++);
4623 name = get_identifier (buf);
4626 decl = build_decl (CONST_DECL, name, integer_type_node);
4627 CH_DECL_ENUM (decl) = 1;
4628 DECL_INITIAL (decl) = value;
4629 if (named)
4631 if (pass == 0)
4633 push_obstacks_nochange ();
4634 pushdecl (decl);
4635 finish_decl (decl);
4637 else
4638 save_decl (decl);
4640 return build_tree_list (name, decl);
4642 #if 0
4643 tree old_value = lookup_name_current_level (name);
4645 if (old_value != NULL_TREE
4646 && TREE_CODE (old_value)=!= CONST_DECL
4647 && (value == NULL_TREE || operand_equal_p (value, old_value, 1)))
4649 if (value == NULL_TREE)
4651 if (TREE_CODE (old_value) == CONST_DECL)
4652 value = DECL_INITIAL (old_value);
4653 else
4654 abort ();
4656 return saveable_tree_cons (old_value, value, NULL_TREE);
4658 #endif
4661 /* Record that this function is going to be a varargs function.
4662 This is called before store_parm_decls, which is too early
4663 to call mark_varargs directly. */
4665 void
4666 c_mark_varargs ()
4668 c_function_varargs = 1;
4671 /* Function needed for CHILL interface. */
4672 tree
4673 get_parm_decls ()
4675 return current_function_parms;
4678 /* Save and restore the variables in this file and elsewhere
4679 that keep track of the progress of compilation of the current function.
4680 Used for nested functions. */
4682 struct c_function
4684 struct c_function *next;
4685 struct scope *scope;
4686 tree chill_result_decl;
4687 int result_never_set;
4690 struct c_function *c_function_chain;
4692 /* Save and reinitialize the variables
4693 used during compilation of a C function. */
4695 void
4696 push_chill_function_context ()
4698 struct c_function *p
4699 = (struct c_function *) xmalloc (sizeof (struct c_function));
4701 push_function_context ();
4703 p->next = c_function_chain;
4704 c_function_chain = p;
4706 p->scope = current_scope;
4707 p->chill_result_decl = chill_result_decl;
4708 p->result_never_set = result_never_set;
4711 /* Restore the variables used during compilation of a C function. */
4713 void
4714 pop_chill_function_context ()
4716 struct c_function *p = c_function_chain;
4717 #if 0
4718 tree link;
4719 /* Bring back all the labels that were shadowed. */
4720 for (link = shadowed_labels; link; link = TREE_CHAIN (link))
4721 if (DECL_NAME (TREE_VALUE (link)) != 0)
4722 IDENTIFIER_LABEL_VALUE (DECL_NAME (TREE_VALUE (link)))
4723 = TREE_VALUE (link);
4724 #endif
4726 pop_function_context ();
4728 c_function_chain = p->next;
4730 current_scope = p->scope;
4731 chill_result_decl = p->chill_result_decl;
4732 result_never_set = p->result_never_set;
4734 free (p);
4737 /* Following from Jukka Virtanen's GNU Pascal */
4738 /* To implement WITH statement:
4740 1) Call shadow_record_fields for each record_type element in the WITH
4741 element list. Each call creates a new binding level.
4743 2) construct a component_ref for EACH field in the record,
4744 and store it to the IDENTIFIER_LOCAL_VALUE after adding
4745 the old value to the shadow list
4747 3) let lookup_name do the rest
4749 4) pop all of the binding levels after the WITH statement ends.
4750 (restoring old local values) You have to keep track of the number
4751 of times you called it.
4755 * Save an arbitrary tree-expression as the IDENTIFIER_LOCAL_VALUE
4756 * of a name. Save the name's previous value. Check for name
4757 * collisions with another value under the same name at the same
4758 * nesting level. This is used to implement the DO WITH construct
4759 * and the temporary for the location iteration loop.
4761 void
4762 save_expr_under_name (name, expr)
4763 tree name, expr;
4765 tree alias = build_alias_decl (NULL_TREE, NULL_TREE, name);
4767 DECL_ABSTRACT_ORIGIN (alias) = expr;
4768 TREE_CHAIN (alias) = NULL_TREE;
4769 pushdecllist (alias, 0);
4772 static void
4773 do_based_decl (name, mode, base_var)
4774 tree name, mode, base_var;
4776 tree decl;
4777 if (pass == 1)
4779 push_obstacks (&permanent_obstack, &permanent_obstack);
4780 decl = make_node (BASED_DECL);
4781 DECL_NAME (decl) = name;
4782 TREE_TYPE (decl) = mode;
4783 DECL_ABSTRACT_ORIGIN (decl) = base_var;
4784 save_decl (decl);
4785 pop_obstacks ();
4787 else
4789 tree base_decl;
4790 decl = get_next_decl ();
4791 if (name != DECL_NAME (decl))
4792 abort();
4793 /* FIXME: This isn't a complete test */
4794 base_decl = lookup_name (base_var);
4795 if (base_decl == NULL_TREE)
4796 error ("BASE variable never declared");
4797 else if (TREE_CODE (base_decl) == FUNCTION_DECL)
4798 error ("cannot BASE a variable on a PROC/PROCESS name");
4802 void
4803 do_based_decls (names, mode, base_var)
4804 tree names, mode, base_var;
4806 if (names == NULL_TREE || TREE_CODE (names) == TREE_LIST)
4808 for (; names != NULL_TREE; names = TREE_CHAIN (names))
4809 do_based_decl (names, mode, base_var);
4811 else if (TREE_CODE (names) != ERROR_MARK)
4812 do_based_decl (names, mode, base_var);
4816 * Declare the fields so that lookup_name() will find them as
4817 * component refs for Pascal WITH or CHILL DO WITH.
4819 * Proceeds to the inner layers of Pascal/CHILL variant record
4821 * Internal routine of shadow_record_fields ()
4823 static void
4824 handle_one_level (parent, fields)
4825 tree parent, fields;
4827 tree field, name;
4829 switch (TREE_CODE (TREE_TYPE (parent)))
4831 case RECORD_TYPE:
4832 case UNION_TYPE:
4833 for (field = fields; field; field = TREE_CHAIN (field)) {
4834 name = DECL_NAME (field);
4835 if (name == NULL_TREE || name == ELSE_VARIANT_NAME)
4836 /* proceed through variant part */
4837 handle_one_level (parent, TYPE_FIELDS (TREE_TYPE (field)));
4838 else
4840 tree field_alias = make_node (WITH_DECL);
4841 DECL_NAME (field_alias) = name;
4842 TREE_TYPE (field_alias) = TREE_TYPE (field);
4843 DECL_ABSTRACT_ORIGIN (field_alias) = parent;
4844 TREE_CHAIN (field_alias) = NULL_TREE;
4845 pushdecllist (field_alias, 0);
4848 break;
4849 default:
4850 error ("INTERNAL ERROR: handle_one_level is broken");
4855 * For each FIELD_DECL node in a RECORD_TYPE, we have to declare
4856 * a name so that lookup_name will find a COMPONENT_REF node
4857 * when the name is referenced. This happens in Pascal WITH statement.
4859 void
4860 shadow_record_fields (struct_val)
4861 tree struct_val;
4863 if (pass == 1 || struct_val == NULL_TREE)
4864 return;
4866 handle_one_level (struct_val, TYPE_FIELDS (TREE_TYPE (struct_val)));
4869 static char exception_prefix [] = "__Ex_";
4871 tree
4872 build_chill_exception_decl (name)
4873 const char *name;
4875 tree decl, ex_name, ex_init, ex_type;
4876 int name_len = strlen (name);
4877 char *ex_string = (char *)
4878 alloca (strlen (exception_prefix) + name_len + 1);
4880 sprintf(ex_string, "%s%s", exception_prefix, name);
4881 ex_name = get_identifier (ex_string);
4882 decl = IDENTIFIER_LOCAL_VALUE (ex_name);
4883 if (decl)
4884 return decl;
4886 /* finish_decl is too eager about switching back to the
4887 ambient context. This decl's rtl must live in the permanent_obstack. */
4888 push_obstacks (&permanent_obstack, &permanent_obstack);
4889 push_obstacks_nochange ();
4890 ex_type = build_array_type (char_type_node,
4891 build_index_2_type (integer_zero_node,
4892 build_int_2 (name_len, 0)));
4893 decl = build_lang_decl (VAR_DECL, ex_name, ex_type);
4894 ex_init = build_string (name_len, name);
4895 TREE_TYPE (ex_init) = ex_type;
4896 DECL_INITIAL (decl) = ex_init;
4897 TREE_READONLY (decl) = 1;
4898 TREE_STATIC (decl) = 1;
4899 pushdecl_top_level (decl);
4900 finish_decl (decl);
4901 pop_obstacks (); /* Return to the ambient context. */
4902 return decl;
4905 extern tree module_init_list;
4908 * This function is called from the parser to preface the entire
4909 * compilation. It contains module-level actions and reach-bound
4910 * initialization.
4912 void
4913 start_outer_function ()
4915 start_chill_function (pass < 2 ? get_identifier ("_GLOBAL_")
4916 : DECL_NAME (global_function_decl),
4917 void_type_node, NULL_TREE, NULL_TREE, NULL_TREE);
4918 global_function_decl = current_function_decl;
4919 global_scope = current_scope;
4920 chill_at_module_level = 1;
4923 /* This function finishes the global_function_decl, and if it is non-empty
4924 * (as indiacted by seen_action), adds it to module_init_list.
4926 void
4927 finish_outer_function ()
4929 /* If there was module-level code in this module (not just function
4930 declarations), we allocate space for this module's init list entry,
4931 and fill in the module's function's address. */
4933 extern tree initializer_type;
4934 const char *fname_str = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
4935 char *init_entry_name = (char *)xmalloc ((unsigned)(strlen (fname_str) + 20));
4936 tree init_entry_id;
4937 tree init_entry_decl;
4938 tree initializer;
4940 finish_chill_function ();
4942 chill_at_module_level = 0;
4945 if (!seen_action)
4946 return;
4948 sprintf (init_entry_name, "__tmp_%s_init_entry", fname_str);
4949 init_entry_id = get_identifier (init_entry_name);
4951 init_entry_decl = build1 (ADDR_EXPR,
4952 TREE_TYPE (TYPE_FIELDS (initializer_type)),
4953 global_function_decl);
4954 TREE_CONSTANT (init_entry_decl) = 1;
4955 initializer = build (CONSTRUCTOR, initializer_type, NULL_TREE,
4956 tree_cons (NULL_TREE, init_entry_decl,
4957 build_tree_list (NULL_TREE,
4958 null_pointer_node)));
4959 TREE_CONSTANT (initializer) = 1;
4960 init_entry_decl
4961 = do_decl (init_entry_id, initializer_type, 1, 1, initializer, 0);
4962 DECL_SOURCE_LINE (init_entry_decl) = 0;
4963 if (pass == 1)
4964 /* tell chill_finish_compile that there's
4965 module-level code to be processed. */
4966 module_init_list = integer_one_node;
4967 else if (build_constructor)
4968 module_init_list = tree_cons (global_function_decl,
4969 init_entry_decl,
4970 module_init_list);
4972 make_decl_rtl (global_function_decl, NULL, 0);