1 /* do not edit automatically generated by mc from decl. */
2 /* decl.mod declaration nodes used to create the AST.
4 Copyright (C) 2015-2024 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <gaius@glam.ac.uk>.
7 This file is part of GNU Modula-2.
9 GNU Modula-2 is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GNU Modula-2 is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU Modula-2; see the file COPYING3. If not see
21 <http://www.gnu.org/licenses/>. */
26 # if !defined (PROC_D)
28 typedef void (*PROC_t
) (void);
29 typedef struct { PROC_t proc
; } PROC
;
40 # include "GStorage.h"
42 #if defined(__cplusplus)
46 typedef unsigned int nameKey_Name
;
48 # define nameKey_NulName 0
49 typedef struct mcPretty_writeProc_p mcPretty_writeProc
;
51 typedef struct symbolKey__T8_r symbolKey__T8
;
53 typedef symbolKey__T8
*symbolKey_symbolTree
;
55 typedef struct mcPretty_writeLnProc_p mcPretty_writeLnProc
;
57 typedef unsigned int FIO_File
;
59 extern FIO_File FIO_StdOut
;
60 # define symbolKey_NulKey NULL
61 typedef struct symbolKey_performOperation_p symbolKey_performOperation
;
63 # define ASCII_tab ASCII_ht
64 typedef struct alists__T13_r alists__T13
;
66 typedef alists__T13
*alists_alist
;
68 typedef struct alists__T14_a alists__T14
;
70 # define ASCII_ht (char) 011
71 # define ASCII_lf ASCII_nl
72 # define ASCII_nl (char) 012
73 typedef struct Indexing_IndexProcedure_p Indexing_IndexProcedure
;
75 typedef struct decl_isNodeF_p decl_isNodeF
;
77 # define SYSTEM_BITSPERBYTE 8
78 # define SYSTEM_BYTESPERWORD 4
79 typedef struct M2RTS_ArgCVEnvP_p M2RTS_ArgCVEnvP
;
81 typedef struct symbolKey_isSymbol_p symbolKey_isSymbol
;
83 # define ASCII_nul (char) 000
84 # define ASCII_soh (char) 001
85 # define ASCII_stx (char) 002
86 # define ASCII_etx (char) 003
87 # define ASCII_eot (char) 004
88 # define ASCII_enq (char) 005
89 # define ASCII_ack (char) 006
90 # define ASCII_bel (char) 007
91 # define ASCII_bs (char) 010
92 # define ASCII_vt (char) 013
93 # define ASCII_np (char) 014
94 # define ASCII_cr (char) 015
95 # define ASCII_so (char) 016
96 # define ASCII_si (char) 017
97 # define ASCII_dle (char) 020
98 # define ASCII_dc1 (char) 021
99 # define ASCII_dc2 (char) 022
100 # define ASCII_dc3 (char) 023
101 # define ASCII_dc4 (char) 024
102 # define ASCII_nak (char) 025
103 # define ASCII_syn (char) 026
104 # define ASCII_etb (char) 027
105 # define ASCII_can (char) 030
106 # define ASCII_em (char) 031
107 # define ASCII_sub (char) 032
108 # define ASCII_esc (char) 033
109 # define ASCII_fs (char) 034
110 # define ASCII_gs (char) 035
111 # define ASCII_rs (char) 036
112 # define ASCII_us (char) 037
113 # define ASCII_sp (char) 040
114 # define ASCII_ff ASCII_np
115 # define ASCII_eof ASCII_eot
116 # define ASCII_del (char) 0177
117 # define ASCII_EOL ASCII_nl
118 extern FIO_File FIO_StdErr
;
119 extern FIO_File FIO_StdIn
;
120 typedef long int libc_time_t
;
122 typedef struct libc_tm_r libc_tm
;
124 typedef libc_tm
*libc_ptrToTM
;
126 typedef struct libc_timeb_r libc_timeb
;
128 typedef struct libc_exitP_p libc_exitP
;
130 typedef struct mcError__T11_r mcError__T11
;
132 typedef mcError__T11
*mcError_error
;
134 extern int mcLexBuf_currentinteger
;
135 extern unsigned int mcLexBuf_currentcolumn
;
136 extern void * mcLexBuf_currentstring
;
137 typedef struct alists_performOperation_p alists_performOperation
;
139 typedef struct wlists_performOperation_p wlists_performOperation
;
141 typedef struct StdIO_ProcWrite_p StdIO_ProcWrite
;
143 typedef struct StdIO_ProcRead_p StdIO_ProcRead
;
145 # define indentation 3
146 # define indentationC 2
147 # define debugScopes false
148 # define debugDecl false
149 # define caseException true
150 # define returnException true
151 # define forceCompoundStatement true
152 # define enableDefForCStrings false
153 # define enableMemsetOnAllocation true
154 # define forceQualified true
155 typedef struct decl_nodeRec_r decl_nodeRec
;
157 typedef struct decl_intrinsicT_r decl_intrinsicT
;
159 typedef struct decl_fixupInfo_r decl_fixupInfo
;
161 typedef struct decl_explistT_r decl_explistT
;
163 typedef struct decl_setvalueT_r decl_setvalueT
;
165 typedef struct decl_identlistT_r decl_identlistT
;
167 typedef struct decl_funccallT_r decl_funccallT
;
169 typedef struct decl_commentT_r decl_commentT
;
171 typedef struct decl_stmtT_r decl_stmtT
;
173 typedef struct decl_returnT_r decl_returnT
;
175 typedef struct decl_exitT_r decl_exitT
;
177 typedef struct decl_vardeclT_r decl_vardeclT
;
179 typedef struct decl_typeT_r decl_typeT
;
181 typedef struct decl_recordT_r decl_recordT
;
183 typedef struct decl_varientT_r decl_varientT
;
185 typedef struct decl_varT_r decl_varT
;
187 typedef struct decl_enumerationT_r decl_enumerationT
;
189 typedef struct decl_subrangeT_r decl_subrangeT
;
191 typedef struct decl_subscriptT_r decl_subscriptT
;
193 typedef struct decl_arrayT_r decl_arrayT
;
195 typedef struct decl_stringT_r decl_stringT
;
197 typedef struct decl_literalT_r decl_literalT
;
199 typedef struct decl_constT_r decl_constT
;
201 typedef struct decl_varparamT_r decl_varparamT
;
203 typedef struct decl_paramT_r decl_paramT
;
205 typedef struct decl_varargsT_r decl_varargsT
;
207 typedef struct decl_optargT_r decl_optargT
;
209 typedef struct decl_pointerT_r decl_pointerT
;
211 typedef struct decl_recordfieldT_r decl_recordfieldT
;
213 typedef struct decl_varientfieldT_r decl_varientfieldT
;
215 typedef struct decl_enumerationfieldT_r decl_enumerationfieldT
;
217 typedef struct decl_setT_r decl_setT
;
219 typedef struct decl_componentrefT_r decl_componentrefT
;
221 typedef struct decl_pointerrefT_r decl_pointerrefT
;
223 typedef struct decl_arrayrefT_r decl_arrayrefT
;
225 typedef struct decl_commentPair_r decl_commentPair
;
227 typedef struct decl_assignmentT_r decl_assignmentT
;
229 typedef struct decl_ifT_r decl_ifT
;
231 typedef struct decl_elsifT_r decl_elsifT
;
233 typedef struct decl_loopT_r decl_loopT
;
235 typedef struct decl_whileT_r decl_whileT
;
237 typedef struct decl_repeatT_r decl_repeatT
;
239 typedef struct decl_caseT_r decl_caseT
;
241 typedef struct decl_caselabellistT_r decl_caselabellistT
;
243 typedef struct decl_caselistT_r decl_caselistT
;
245 typedef struct decl_rangeT_r decl_rangeT
;
247 typedef struct decl_forT_r decl_forT
;
249 typedef struct decl_statementT_r decl_statementT
;
251 typedef struct decl_scopeT_r decl_scopeT
;
253 typedef struct decl_procedureT_r decl_procedureT
;
255 typedef struct decl_proctypeT_r decl_proctypeT
;
257 typedef struct decl_binaryT_r decl_binaryT
;
259 typedef struct decl_unaryT_r decl_unaryT
;
261 typedef struct decl_moduleT_r decl_moduleT
;
263 typedef struct decl_defT_r decl_defT
;
265 typedef struct decl_impT_r decl_impT
;
267 typedef struct decl_where_r decl_where
;
269 typedef struct decl_nodeProcedure_p decl_nodeProcedure
;
271 typedef struct decl_cnameT_r decl_cnameT
;
274 # define maxNoOfElements 5
275 typedef enum {decl_explist
, decl_funccall
, decl_exit
, decl_return
, decl_stmtseq
, decl_comment
, decl_halt
, decl_new
, decl_dispose
, decl_inc
, decl_dec
, decl_incl
, decl_excl
, decl_length
, decl_nil
, decl_true
, decl_false
, decl_address
, decl_loc
, decl_byte
, decl_word
, decl_csizet
, decl_cssizet
, decl_char
, decl_cardinal
, decl_longcard
, decl_shortcard
, decl_integer
, decl_longint
, decl_shortint
, decl_real
, decl_longreal
, decl_shortreal
, decl_bitset
, decl_boolean
, decl_proc
, decl_ztype
, decl_rtype
, decl_complex
, decl_longcomplex
, decl_shortcomplex
, decl_type
, decl_record
, decl_varient
, decl_var
, decl_enumeration
, decl_subrange
, decl_array
, decl_subscript
, decl_string
, decl_const
, decl_literal
, decl_varparam
, decl_param
, decl_varargs
, decl_optarg
, decl_pointer
, decl_recordfield
, decl_varientfield
, decl_enumerationfield
, decl_set
, decl_proctype
, decl_procedure
, decl_def
, decl_imp
, decl_module
, decl_loop
, decl_while
, decl_for
, decl_repeat
, decl_case
, decl_caselabellist
, decl_caselist
, decl_range
, decl_assignment
, decl_if
, decl_elsif
, decl_constexp
, decl_neg
, decl_cast
, decl_val
, decl_plus
, decl_sub
, decl_div
, decl_mod
, decl_mult
, decl_divide
, decl_in
, decl_adr
, decl_size
, decl_tsize
, decl_ord
, decl_float
, decl_trunc
, decl_chr
, decl_abs
, decl_cap
, decl_high
, decl_throw
, decl_unreachable
, decl_cmplx
, decl_re
, decl_im
, decl_min
, decl_max
, decl_componentref
, decl_pointerref
, decl_arrayref
, decl_deref
, decl_equal
, decl_notequal
, decl_less
, decl_greater
, decl_greequal
, decl_lessequal
, decl_lsl
, decl_lsr
, decl_lor
, decl_land
, decl_lnot
, decl_lxor
, decl_and
, decl_or
, decl_not
, decl_identlist
, decl_vardecl
, decl_setvalue
} decl_nodeT
;
277 # define MaxnoOfelements 5
278 typedef enum {mcReserved_eoftok
, mcReserved_plustok
, mcReserved_minustok
, mcReserved_timestok
, mcReserved_dividetok
, mcReserved_becomestok
, mcReserved_ambersandtok
, mcReserved_periodtok
, mcReserved_commatok
, mcReserved_semicolontok
, mcReserved_lparatok
, mcReserved_rparatok
, mcReserved_lsbratok
, mcReserved_rsbratok
, mcReserved_lcbratok
, mcReserved_rcbratok
, mcReserved_uparrowtok
, mcReserved_singlequotetok
, mcReserved_equaltok
, mcReserved_hashtok
, mcReserved_lesstok
, mcReserved_greatertok
, mcReserved_lessgreatertok
, mcReserved_lessequaltok
, mcReserved_greaterequaltok
, mcReserved_ldirectivetok
, mcReserved_rdirectivetok
, mcReserved_periodperiodtok
, mcReserved_colontok
, mcReserved_doublequotestok
, mcReserved_bartok
, mcReserved_andtok
, mcReserved_arraytok
, mcReserved_begintok
, mcReserved_bytok
, mcReserved_casetok
, mcReserved_consttok
, mcReserved_definitiontok
, mcReserved_divtok
, mcReserved_dotok
, mcReserved_elsetok
, mcReserved_elsiftok
, mcReserved_endtok
, mcReserved_excepttok
, mcReserved_exittok
, mcReserved_exporttok
, mcReserved_finallytok
, mcReserved_fortok
, mcReserved_fromtok
, mcReserved_iftok
, mcReserved_implementationtok
, mcReserved_importtok
, mcReserved_intok
, mcReserved_looptok
, mcReserved_modtok
, mcReserved_moduletok
, mcReserved_nottok
, mcReserved_oftok
, mcReserved_ortok
, mcReserved_packedsettok
, mcReserved_pointertok
, mcReserved_proceduretok
, mcReserved_qualifiedtok
, mcReserved_unqualifiedtok
, mcReserved_recordtok
, mcReserved_remtok
, mcReserved_repeattok
, mcReserved_retrytok
, mcReserved_returntok
, mcReserved_settok
, mcReserved_thentok
, mcReserved_totok
, mcReserved_typetok
, mcReserved_untiltok
, mcReserved_vartok
, mcReserved_whiletok
, mcReserved_withtok
, mcReserved_asmtok
, mcReserved_volatiletok
, mcReserved_periodperiodperiodtok
, mcReserved_datetok
, mcReserved_linetok
, mcReserved_filetok
, mcReserved_attributetok
, mcReserved_builtintok
, mcReserved_inlinetok
, mcReserved_integertok
, mcReserved_identtok
, mcReserved_realtok
, mcReserved_stringtok
, mcReserved_commenttok
} mcReserved_toktype
;
280 extern mcReserved_toktype mcLexBuf_currenttoken
;
281 typedef enum {decl_ansiC
, decl_ansiCP
, decl_pim4
} decl_language
;
283 typedef enum {decl_completed
, decl_blocked
, decl_partial
, decl_recursive
} decl_dependentState
;
285 typedef enum {decl_text
, decl_punct
, decl_space
} decl_outputStates
;
287 typedef decl_nodeRec
*decl_node
;
289 typedef struct Indexing__T5_r Indexing__T5
;
291 typedef struct mcComment__T6_r mcComment__T6
;
293 typedef enum {mcComment_unknown
, mcComment_procedureHeading
, mcComment_inBody
, mcComment_afterStatement
} mcComment_commentType
;
295 typedef struct DynamicStrings_stringRecord_r DynamicStrings_stringRecord
;
297 typedef struct DynamicStrings_Contents_r DynamicStrings_Contents
;
299 typedef struct wlists__T9_r wlists__T9
;
301 typedef struct mcPretty__T12_r mcPretty__T12
;
303 typedef struct wlists__T10_a wlists__T10
;
305 typedef struct DynamicStrings__T7_a DynamicStrings__T7
;
307 typedef Indexing__T5
*Indexing_Index
;
309 typedef mcComment__T6
*mcComment_commentDesc
;
311 extern mcComment_commentDesc mcLexBuf_currentcomment
;
312 extern mcComment_commentDesc mcLexBuf_lastcomment
;
313 typedef DynamicStrings_stringRecord
*DynamicStrings_String
;
315 typedef wlists__T9
*wlists_wlist
;
317 typedef mcPretty__T12
*mcPretty_pretty
;
319 typedef void (*mcPretty_writeProc_t
) (char);
320 struct mcPretty_writeProc_p
{ mcPretty_writeProc_t proc
; };
322 struct symbolKey__T8_r
{
325 symbolKey_symbolTree left
;
326 symbolKey_symbolTree right
;
329 typedef void (*mcPretty_writeLnProc_t
) (void);
330 struct mcPretty_writeLnProc_p
{ mcPretty_writeLnProc_t proc
; };
332 typedef void (*symbolKey_performOperation_t
) (void *);
333 struct symbolKey_performOperation_p
{ symbolKey_performOperation_t proc
; };
335 struct alists__T14_a
{ void * array
[MaxnoOfelements
-1+1]; };
336 typedef void (*Indexing_IndexProcedure_t
) (void *);
337 struct Indexing_IndexProcedure_p
{ Indexing_IndexProcedure_t proc
; };
339 typedef bool (*decl_isNodeF_t
) (decl_node
);
340 struct decl_isNodeF_p
{ decl_isNodeF_t proc
; };
342 typedef void (*M2RTS_ArgCVEnvP_t
) (int, void *, void *);
343 struct M2RTS_ArgCVEnvP_p
{ M2RTS_ArgCVEnvP_t proc
; };
345 typedef bool (*symbolKey_isSymbol_t
) (void *);
346 struct symbolKey_isSymbol_p
{ symbolKey_isSymbol_t proc
; };
362 struct libc_timeb_r
{
364 short unsigned int millitm
;
365 short unsigned int timezone
;
366 short unsigned int dstflag
;
369 typedef int (*libc_exitP_t
) (void);
370 typedef libc_exitP_t libc_exitP_C
;
372 struct libc_exitP_p
{ libc_exitP_t proc
; };
374 struct mcError__T11_r
{
375 mcError_error parent
;
379 DynamicStrings_String s
;
383 typedef void (*alists_performOperation_t
) (void *);
384 struct alists_performOperation_p
{ alists_performOperation_t proc
; };
386 typedef void (*wlists_performOperation_t
) (unsigned int);
387 struct wlists_performOperation_p
{ wlists_performOperation_t proc
; };
389 typedef void (*StdIO_ProcWrite_t
) (char);
390 struct StdIO_ProcWrite_p
{ StdIO_ProcWrite_t proc
; };
392 typedef void (*StdIO_ProcRead_t
) (char *);
393 struct StdIO_ProcRead_p
{ StdIO_ProcRead_t proc
; };
395 struct decl_fixupInfo_r
{
400 struct decl_explistT_r
{
404 struct decl_setvalueT_r
{
406 Indexing_Index values
;
409 struct decl_identlistT_r
{
414 struct decl_commentT_r
{
415 mcComment_commentDesc content
;
418 struct decl_stmtT_r
{
419 Indexing_Index statements
;
422 struct decl_exitT_r
{
426 struct decl_vardeclT_r
{
432 struct decl_typeT_r
{
440 struct decl_recordT_r
{
441 symbolKey_symbolTree localSymbols
;
442 Indexing_Index listOfSons
;
446 struct decl_varientT_r
{
447 Indexing_Index listOfSons
;
453 struct decl_enumerationT_r
{
454 unsigned int noOfElements
;
455 symbolKey_symbolTree localSymbols
;
456 Indexing_Index listOfSons
;
462 struct decl_subrangeT_r
{
469 struct decl_subscriptT_r
{
474 struct decl_arrayT_r
{
481 struct decl_stringT_r
{
484 bool isCharCompatible
;
485 DynamicStrings_String cstring
;
486 unsigned int clength
;
487 DynamicStrings_String cchar
;
490 struct decl_literalT_r
{
495 struct decl_constT_r
{
502 struct decl_varparamT_r
{
511 struct decl_paramT_r
{
520 struct decl_varargsT_r
{
524 struct decl_optargT_r
{
531 struct decl_pointerT_r
{
536 struct decl_varientfieldT_r
{
541 Indexing_Index listOfSons
;
550 struct decl_componentrefT_r
{
553 decl_node resultType
;
556 struct decl_pointerrefT_r
{
559 decl_node resultType
;
562 struct decl_arrayrefT_r
{
565 decl_node resultType
;
568 struct decl_commentPair_r
{
573 struct decl_loopT_r
{
574 decl_node statements
;
575 unsigned int labelno
;
578 struct decl_caseT_r
{
579 decl_node expression
;
580 Indexing_Index caseLabelList
;
584 struct decl_caselabellistT_r
{
586 decl_node statements
;
589 struct decl_caselistT_r
{
590 Indexing_Index rangePairs
;
593 struct decl_rangeT_r
{
603 decl_node statements
;
606 struct decl_statementT_r
{
607 Indexing_Index sequence
;
610 struct decl_scopeT_r
{
611 symbolKey_symbolTree symbols
;
612 Indexing_Index constants
;
613 Indexing_Index types
;
614 Indexing_Index procedures
;
615 Indexing_Index variables
;
618 struct decl_proctypeT_r
{
619 Indexing_Index parameters
;
624 decl_node returnType
;
627 struct decl_binaryT_r
{
630 decl_node resultType
;
633 struct decl_unaryT_r
{
635 decl_node resultType
;
638 struct decl_where_r
{
639 unsigned int defDeclared
;
640 unsigned int modDeclared
;
641 unsigned int firstUsed
;
644 typedef void (*decl_nodeProcedure_t
) (decl_node
);
645 struct decl_nodeProcedure_p
{ decl_nodeProcedure_t proc
; };
647 struct decl_cnameT_r
{
652 struct Indexing__T5_r
{
654 unsigned int ArraySize
;
662 struct mcComment__T6_r
{
663 mcComment_commentType type
;
664 DynamicStrings_String content
;
665 nameKey_Name procName
;
669 struct wlists__T10_a
{ unsigned int array
[maxNoOfElements
-1+1]; };
670 struct DynamicStrings__T7_a
{ char array
[(MaxBuf
-1)+1]; };
671 struct alists__T13_r
{
672 unsigned int noOfelements
;
673 alists__T14 elements
;
677 struct decl_intrinsicT_r
{
681 decl_commentPair intrinsicComment
;
682 bool postUnreachable
;
685 struct decl_funccallT_r
{
689 decl_commentPair funccallComment
;
692 struct decl_returnT_r
{
695 decl_commentPair returnComment
;
710 struct decl_recordfieldT_r
{
720 struct decl_enumerationfieldT_r
{
728 struct decl_assignmentT_r
{
731 decl_commentPair assignComment
;
739 decl_commentPair ifComment
;
740 decl_commentPair elseComment
;
741 decl_commentPair endComment
;
744 struct decl_elsifT_r
{
749 decl_commentPair elseComment
;
752 struct decl_whileT_r
{
754 decl_node statements
;
755 decl_commentPair doComment
;
756 decl_commentPair endComment
;
759 struct decl_repeatT_r
{
761 decl_node statements
;
762 decl_commentPair repeatComment
;
763 decl_commentPair untilComment
;
766 struct decl_procedureT_r
{
770 Indexing_Index parameters
;
778 unsigned int paramcount
;
780 decl_node returnType
;
781 decl_node beginStatements
;
783 mcComment_commentDesc defComment
;
784 mcComment_commentDesc modComment
;
787 struct decl_moduleT_r
{
790 Indexing_Index importedModules
;
791 decl_fixupInfo constFixup
;
792 decl_fixupInfo enumFixup
;
794 decl_node beginStatements
;
795 decl_node finallyStatements
;
799 decl_commentPair com
;
807 Indexing_Index exported
;
808 Indexing_Index importedModules
;
809 decl_fixupInfo constFixup
;
810 decl_fixupInfo enumFixup
;
815 decl_commentPair com
;
821 Indexing_Index importedModules
;
822 decl_fixupInfo constFixup
;
823 decl_fixupInfo enumFixup
;
824 decl_node beginStatements
;
825 decl_node finallyStatements
;
826 decl_node definitionModule
;
831 decl_commentPair com
;
834 struct DynamicStrings_Contents_r
{
835 DynamicStrings__T7 buf
;
837 DynamicStrings_String next
;
840 struct wlists__T9_r
{
841 unsigned int noOfElements
;
842 wlists__T10 elements
;
846 struct mcPretty__T12_r
{
847 mcPretty_writeProc write_
;
848 mcPretty_writeLnProc writeln
;
851 unsigned int seekPos
;
852 unsigned int curLine
;
855 mcPretty_pretty stacked
;
858 typedef struct DynamicStrings_descriptor_r DynamicStrings_descriptor
;
860 typedef DynamicStrings_descriptor
*DynamicStrings_Descriptor
;
862 typedef struct DynamicStrings_DebugInfo_r DynamicStrings_DebugInfo
;
864 typedef enum {DynamicStrings_inuse
, DynamicStrings_marked
, DynamicStrings_onlist
, DynamicStrings_poisoned
} DynamicStrings_desState
;
866 struct DynamicStrings_descriptor_r
{
869 unsigned int charStarSize
;
871 DynamicStrings_desState state
;
872 DynamicStrings_String garbage
;
875 struct DynamicStrings_DebugInfo_r
{
876 DynamicStrings_String next
;
882 struct decl_nodeRec_r
{
883 decl_nodeT kind
; /* case tag */
885 decl_intrinsicT intrinsicF
;
886 decl_explistT explistF
;
888 decl_returnT returnF
;
890 decl_commentT commentF
;
892 decl_recordT recordF
;
893 decl_varientT varientF
;
895 decl_enumerationT enumerationF
;
896 decl_subrangeT subrangeF
;
897 decl_subscriptT subscriptF
;
899 decl_stringT stringF
;
901 decl_literalT literalF
;
902 decl_varparamT varparamF
;
904 decl_varargsT varargsF
;
905 decl_optargT optargF
;
906 decl_pointerT pointerF
;
907 decl_recordfieldT recordfieldF
;
908 decl_varientfieldT varientfieldF
;
909 decl_enumerationfieldT enumerationfieldF
;
911 decl_proctypeT proctypeF
;
912 decl_procedureT procedureF
;
915 decl_moduleT moduleF
;
919 decl_repeatT repeatF
;
921 decl_caselabellistT caselabellistF
;
922 decl_caselistT caselistF
;
926 decl_assignmentT assignmentF
;
927 decl_arrayrefT arrayrefF
;
928 decl_pointerrefT pointerrefF
;
929 decl_componentrefT componentrefF
;
930 decl_binaryT binaryF
;
932 decl_identlistT identlistF
;
933 decl_vardeclT vardeclF
;
934 decl_funccallT funccallF
;
935 decl_setvalueT setvalueF
;
940 struct DynamicStrings_stringRecord_r
{
941 DynamicStrings_Contents contents
;
942 DynamicStrings_Descriptor head
;
943 DynamicStrings_DebugInfo debug
;
946 static FIO_File outputFile
;
947 static decl_language lang
;
948 static decl_node bitsperunitN
;
949 static decl_node bitsperwordN
;
950 static decl_node bitspercharN
;
951 static decl_node unitsperwordN
;
952 static decl_node mainModule
;
953 static decl_node currentModule
;
954 static decl_node defModule
;
955 static decl_node systemN
;
956 static decl_node addressN
;
957 static decl_node locN
;
958 static decl_node byteN
;
959 static decl_node wordN
;
960 static decl_node csizetN
;
961 static decl_node cssizetN
;
962 static decl_node adrN
;
963 static decl_node sizeN
;
964 static decl_node tsizeN
;
965 static decl_node newN
;
966 static decl_node disposeN
;
967 static decl_node lengthN
;
968 static decl_node incN
;
969 static decl_node decN
;
970 static decl_node inclN
;
971 static decl_node exclN
;
972 static decl_node highN
;
973 static decl_node m2rtsN
;
974 static decl_node haltN
;
975 static decl_node throwN
;
976 static decl_node chrN
;
977 static decl_node capN
;
978 static decl_node absN
;
979 static decl_node floatN
;
980 static decl_node truncN
;
981 static decl_node ordN
;
982 static decl_node valN
;
983 static decl_node minN
;
984 static decl_node maxN
;
985 static decl_node booleanN
;
986 static decl_node procN
;
987 static decl_node charN
;
988 static decl_node integerN
;
989 static decl_node cardinalN
;
990 static decl_node longcardN
;
991 static decl_node shortcardN
;
992 static decl_node longintN
;
993 static decl_node shortintN
;
994 static decl_node bitsetN
;
995 static decl_node bitnumN
;
996 static decl_node ztypeN
;
997 static decl_node rtypeN
;
998 static decl_node complexN
;
999 static decl_node longcomplexN
;
1000 static decl_node shortcomplexN
;
1001 static decl_node cmplxN
;
1002 static decl_node reN
;
1003 static decl_node imN
;
1004 static decl_node realN
;
1005 static decl_node longrealN
;
1006 static decl_node shortrealN
;
1007 static decl_node nilN
;
1008 static decl_node trueN
;
1009 static decl_node falseN
;
1010 static Indexing_Index scopeStack
;
1011 static Indexing_Index defUniverseI
;
1012 static Indexing_Index modUniverseI
;
1013 static symbolKey_symbolTree modUniverse
;
1014 static symbolKey_symbolTree defUniverse
;
1015 static symbolKey_symbolTree baseSymbols
;
1016 static decl_outputStates outputState
;
1017 static mcPretty_pretty doP
;
1018 static alists_alist todoQ
;
1019 static alists_alist partialQ
;
1020 static alists_alist doneQ
;
1021 static bool mustVisitScope
;
1022 static bool simplified
;
1023 static unsigned int tempCount
;
1024 static decl_node globalNode
;
1025 extern "C" void SYSTEM_ShiftVal (unsigned int *s
, unsigned int _s_high
, unsigned int *d
, unsigned int _d_high
, unsigned int SetSizeInBits
, int ShiftCount
);
1026 extern "C" void SYSTEM_ShiftLeft (unsigned int *s
, unsigned int _s_high
, unsigned int *d
, unsigned int _d_high
, unsigned int SetSizeInBits
, unsigned int ShiftCount
);
1027 extern "C" void SYSTEM_ShiftRight (unsigned int *s
, unsigned int _s_high
, unsigned int *d
, unsigned int _d_high
, unsigned int SetSizeInBits
, unsigned int ShiftCount
);
1028 extern "C" void SYSTEM_RotateVal (unsigned int *s
, unsigned int _s_high
, unsigned int *d
, unsigned int _d_high
, unsigned int SetSizeInBits
, int RotateCount
);
1029 extern "C" void SYSTEM_RotateLeft (unsigned int *s
, unsigned int _s_high
, unsigned int *d
, unsigned int _d_high
, unsigned int SetSizeInBits
, unsigned int RotateCount
);
1030 extern "C" void SYSTEM_RotateRight (unsigned int *s
, unsigned int _s_high
, unsigned int *d
, unsigned int _d_high
, unsigned int SetSizeInBits
, unsigned int RotateCount
);
1031 extern "C" void M2RTS_ConstructModules (void * applicationmodule
, void * libname
, void * overrideliborder
, int argc
, void * argv
, void * envp
);
1032 extern "C" void M2RTS_DeconstructModules (void * applicationmodule
, void * libname
, int argc
, void * argv
, void * envp
);
1033 extern "C" void M2RTS_RegisterModule (void * name
, void * libname
, M2RTS_ArgCVEnvP init
, M2RTS_ArgCVEnvP fini
, PROC dependencies
);
1034 extern "C" void M2RTS_RequestDependant (void * modulename
, void * libname
, void * dependantmodule
, void * dependantlibname
);
1035 extern "C" bool M2RTS_InstallTerminationProcedure (PROC p
);
1036 extern "C" void M2RTS_ExecuteInitialProcedures (void);
1037 extern "C" bool M2RTS_InstallInitialProcedure (PROC p
);
1038 extern "C" void M2RTS_ExecuteTerminationProcedures (void);
1039 extern "C" void M2RTS_Terminate (void) __attribute__ ((noreturn
));
1040 extern "C" void M2RTS_HALT (int exitcode
) __attribute__ ((noreturn
));
1041 extern "C" void M2RTS_Halt (const char *description_
, unsigned int _description_high
, const char *filename_
, unsigned int _filename_high
, const char *function_
, unsigned int _function_high
, unsigned int line
) __attribute__ ((noreturn
));
1042 extern "C" void M2RTS_HaltC (void * description
, void * filename
, void * function
, unsigned int line
) __attribute__ ((noreturn
));
1043 extern "C" void M2RTS_ExitOnHalt (int e
);
1044 extern "C" void M2RTS_ErrorMessage (const char *message_
, unsigned int _message_high
, const char *filename_
, unsigned int _filename_high
, unsigned int line
, const char *function_
, unsigned int _function_high
) __attribute__ ((noreturn
));
1045 extern "C" unsigned int M2RTS_Length (const char *a_
, unsigned int _a_high
);
1046 extern "C" void M2RTS_AssignmentException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1047 extern "C" void M2RTS_ReturnException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1048 extern "C" void M2RTS_IncException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1049 extern "C" void M2RTS_DecException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1050 extern "C" void M2RTS_InclException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1051 extern "C" void M2RTS_ExclException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1052 extern "C" void M2RTS_ShiftException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1053 extern "C" void M2RTS_RotateException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1054 extern "C" void M2RTS_StaticArraySubscriptException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1055 extern "C" void M2RTS_DynamicArraySubscriptException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1056 extern "C" void M2RTS_ForLoopBeginException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1057 extern "C" void M2RTS_ForLoopToException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1058 extern "C" void M2RTS_ForLoopEndException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1059 extern "C" void M2RTS_PointerNilException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1060 extern "C" void M2RTS_NoReturnException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1061 extern "C" void M2RTS_CaseException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1062 extern "C" void M2RTS_WholeNonPosDivException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1063 extern "C" void M2RTS_WholeNonPosModException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1064 extern "C" void M2RTS_WholeZeroDivException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1065 extern "C" void M2RTS_WholeZeroRemException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1066 extern "C" void M2RTS_WholeValueException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1067 extern "C" void M2RTS_RealValueException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1068 extern "C" void M2RTS_ParameterException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1069 extern "C" void M2RTS_NoException (void * filename
, unsigned int line
, unsigned int column
, void * scope
, void * message
) __attribute__ ((noreturn
));
1072 getDeclaredMod - returns the token number associated with the nodes declaration
1073 in the implementation or program module.
1076 extern "C" unsigned int decl_getDeclaredMod (decl_node n
);
1079 getDeclaredDef - returns the token number associated with the nodes declaration
1080 in the definition module.
1083 extern "C" unsigned int decl_getDeclaredDef (decl_node n
);
1086 getFirstUsed - returns the token number associated with the first use of
1090 extern "C" unsigned int decl_getFirstUsed (decl_node n
);
1093 isDef - return TRUE if node, n, is a definition module.
1096 extern "C" bool decl_isDef (decl_node n
);
1099 isImp - return TRUE if node, n, is an implementation module.
1102 extern "C" bool decl_isImp (decl_node n
);
1105 isImpOrModule - returns TRUE if, n, is a program module or implementation module.
1108 extern "C" bool decl_isImpOrModule (decl_node n
);
1111 isVisited - returns TRUE if the node was visited.
1114 extern "C" bool decl_isVisited (decl_node n
);
1117 unsetVisited - unset the visited flag on a def/imp/module node.
1120 extern "C" void decl_unsetVisited (decl_node n
);
1123 setVisited - set the visited flag on a def/imp/module node.
1126 extern "C" void decl_setVisited (decl_node n
);
1129 setEnumsComplete - sets the field inside the def or imp or module, n.
1132 extern "C" void decl_setEnumsComplete (decl_node n
);
1135 getEnumsComplete - gets the field from the def or imp or module, n.
1138 extern "C" bool decl_getEnumsComplete (decl_node n
);
1141 resetEnumPos - resets the index into the saved list of enums inside
1145 extern "C" void decl_resetEnumPos (decl_node n
);
1148 getNextEnum - returns the next enumeration node.
1151 extern "C" decl_node
decl_getNextEnum (void);
1154 isModule - return TRUE if node, n, is a program module.
1157 extern "C" bool decl_isModule (decl_node n
);
1160 isMainModule - return TRUE if node, n, is the main module specified
1161 by the source file. This might be a definition,
1162 implementation or program module.
1165 extern "C" bool decl_isMainModule (decl_node n
);
1168 setMainModule - sets node, n, as the main module to be compiled.
1171 extern "C" void decl_setMainModule (decl_node n
);
1174 setCurrentModule - sets node, n, as the current module being compiled.
1177 extern "C" void decl_setCurrentModule (decl_node n
);
1180 lookupDef - returns a definition module node named, n.
1183 extern "C" decl_node
decl_lookupDef (nameKey_Name n
);
1186 lookupImp - returns an implementation module node named, n.
1189 extern "C" decl_node
decl_lookupImp (nameKey_Name n
);
1192 lookupModule - returns a module node named, n.
1195 extern "C" decl_node
decl_lookupModule (nameKey_Name n
);
1198 putDefForC - the definition module was defined FOR "C".
1201 extern "C" void decl_putDefForC (decl_node n
);
1204 lookupInScope - looks up a symbol named, n, from, scope.
1207 extern "C" decl_node
decl_lookupInScope (decl_node scope
, nameKey_Name n
);
1210 isConst - returns TRUE if node, n, is a const.
1213 extern "C" bool decl_isConst (decl_node n
);
1216 isType - returns TRUE if node, n, is a type.
1219 extern "C" bool decl_isType (decl_node n
);
1222 putType - places, exp, as the type alias to des.
1226 extern "C" void decl_putType (decl_node des
, decl_node exp
);
1229 getType - returns the type associated with node, n.
1232 extern "C" decl_node
decl_getType (decl_node n
);
1235 skipType - skips over type aliases.
1238 extern "C" decl_node
decl_skipType (decl_node n
);
1241 putTypeHidden - marks type, des, as being a hidden type.
1245 extern "C" void decl_putTypeHidden (decl_node des
);
1248 isTypeHidden - returns TRUE if type, n, is hidden.
1251 extern "C" bool decl_isTypeHidden (decl_node n
);
1254 hasHidden - returns TRUE if module, n, has a hidden type.
1257 extern "C" bool decl_hasHidden (decl_node n
);
1260 isVar - returns TRUE if node, n, is a type.
1263 extern "C" bool decl_isVar (decl_node n
);
1266 isTemporary - returns TRUE if node, n, is a variable and temporary.
1269 extern "C" bool decl_isTemporary (decl_node n
);
1272 isExported - returns TRUE if symbol, n, is exported from
1273 the definition module.
1276 extern "C" bool decl_isExported (decl_node n
);
1279 getDeclScope - returns the node representing the
1280 current declaration scope.
1283 extern "C" decl_node
decl_getDeclScope (void);
1286 getScope - returns the scope associated with node, n.
1289 extern "C" decl_node
decl_getScope (decl_node n
);
1292 isLiteral - returns TRUE if, n, is a literal.
1295 extern "C" bool decl_isLiteral (decl_node n
);
1298 isConstSet - returns TRUE if, n, is a constant set.
1301 extern "C" bool decl_isConstSet (decl_node n
);
1304 isEnumerationField - returns TRUE if, n, is an enumeration field.
1307 extern "C" bool decl_isEnumerationField (decl_node n
);
1310 isEnumeration - returns TRUE if node, n, is an enumeration type.
1313 extern "C" bool decl_isEnumeration (decl_node n
);
1316 isUnbounded - returns TRUE if, n, is an unbounded array.
1319 extern "C" bool decl_isUnbounded (decl_node n
);
1322 isParameter - returns TRUE if, n, is a parameter.
1325 extern "C" bool decl_isParameter (decl_node n
);
1328 isVarParam - returns TRUE if, n, is a var parameter.
1331 extern "C" bool decl_isVarParam (decl_node n
);
1334 isParam - returns TRUE if, n, is a non var parameter.
1337 extern "C" bool decl_isParam (decl_node n
);
1340 isNonVarParam - is an alias to isParam.
1343 extern "C" bool decl_isNonVarParam (decl_node n
);
1346 addOptParameter - returns an optarg which has been created and added to
1347 procedure node, proc. It has a name, id, and, type,
1348 and an initial value, init.
1351 extern "C" decl_node
decl_addOptParameter (decl_node proc
, nameKey_Name id
, decl_node type
, decl_node init
);
1354 isOptarg - returns TRUE if, n, is an optarg.
1357 extern "C" bool decl_isOptarg (decl_node n
);
1360 isRecord - returns TRUE if, n, is a record.
1363 extern "C" bool decl_isRecord (decl_node n
);
1366 isRecordField - returns TRUE if, n, is a record field.
1369 extern "C" bool decl_isRecordField (decl_node n
);
1372 isVarientField - returns TRUE if, n, is a varient field.
1375 extern "C" bool decl_isVarientField (decl_node n
);
1378 isArray - returns TRUE if, n, is an array.
1381 extern "C" bool decl_isArray (decl_node n
);
1384 isProcType - returns TRUE if, n, is a procedure type.
1387 extern "C" bool decl_isProcType (decl_node n
);
1390 isPointer - returns TRUE if, n, is a pointer.
1393 extern "C" bool decl_isPointer (decl_node n
);
1396 isProcedure - returns TRUE if, n, is a procedure.
1399 extern "C" bool decl_isProcedure (decl_node n
);
1402 isVarient - returns TRUE if, n, is a varient record.
1405 extern "C" bool decl_isVarient (decl_node n
);
1408 isSet - returns TRUE if, n, is a set type.
1411 extern "C" bool decl_isSet (decl_node n
);
1414 isSubrange - returns TRUE if, n, is a subrange type.
1417 extern "C" bool decl_isSubrange (decl_node n
);
1420 isZtype - returns TRUE if, n, is the Z type.
1423 extern "C" bool decl_isZtype (decl_node n
);
1426 isRtype - returns TRUE if, n, is the R type.
1429 extern "C" bool decl_isRtype (decl_node n
);
1432 makeConst - create, initialise and return a const node.
1435 extern "C" decl_node
decl_makeConst (nameKey_Name n
);
1438 putConst - places value, v, into node, n.
1441 extern "C" void decl_putConst (decl_node n
, decl_node v
);
1444 makeType - create, initialise and return a type node.
1447 extern "C" decl_node
decl_makeType (nameKey_Name n
);
1450 makeTypeImp - lookup a type in the definition module
1451 and return it. Otherwise create a new type.
1454 extern "C" decl_node
decl_makeTypeImp (nameKey_Name n
);
1457 makeVar - create, initialise and return a var node.
1460 extern "C" decl_node
decl_makeVar (nameKey_Name n
);
1463 putVar - places, type, as the type for var.
1466 extern "C" void decl_putVar (decl_node var
, decl_node type
, decl_node decl
);
1469 makeVarDecl - create a vardecl node and create a shadow variable in the
1473 extern "C" decl_node
decl_makeVarDecl (decl_node i
, decl_node type
);
1476 makeEnum - creates an enumerated type and returns the node.
1479 extern "C" decl_node
decl_makeEnum (void);
1482 makeEnumField - returns an enumeration field, named, n.
1485 extern "C" decl_node
decl_makeEnumField (decl_node e
, nameKey_Name n
);
1488 makeSubrange - returns a subrange node, built from range: low..high.
1491 extern "C" decl_node
decl_makeSubrange (decl_node low
, decl_node high
);
1494 putSubrangeType - assigns, type, to the subrange type, sub.
1497 extern "C" void decl_putSubrangeType (decl_node sub
, decl_node type
);
1500 makePointer - returns a pointer of, type, node.
1503 extern "C" decl_node
decl_makePointer (decl_node type
);
1506 makeSet - returns a set of, type, node.
1509 extern "C" decl_node
decl_makeSet (decl_node type
);
1512 makeArray - returns a node representing ARRAY subr OF type.
1515 extern "C" decl_node
decl_makeArray (decl_node subr
, decl_node type
);
1518 putUnbounded - sets array, n, as unbounded.
1521 extern "C" void decl_putUnbounded (decl_node n
);
1524 makeRecord - creates and returns a record node.
1527 extern "C" decl_node
decl_makeRecord (void);
1530 makeVarient - creates a new symbol, a varient symbol for record or varient field
1534 extern "C" decl_node
decl_makeVarient (decl_node r
);
1537 addFieldsToRecord - adds fields, i, of type, t, into a record, r.
1541 extern "C" decl_node
decl_addFieldsToRecord (decl_node r
, decl_node v
, decl_node i
, decl_node t
);
1544 buildVarientSelector - builds a field of name, tag, of, type onto:
1545 record or varient field, r.
1549 extern "C" void decl_buildVarientSelector (decl_node r
, decl_node v
, nameKey_Name tag
, decl_node type
);
1552 buildVarientFieldRecord - builds a varient field into a varient symbol, v.
1553 The varient field is returned.
1556 extern "C" decl_node
decl_buildVarientFieldRecord (decl_node v
, decl_node p
);
1559 getSymName - returns the name of symbol, n.
1562 extern "C" nameKey_Name
decl_getSymName (decl_node n
);
1565 import - attempts to add node, n, into the scope of module, m.
1566 It might fail due to a name clash in which case the
1567 previous named symbol is returned. On success, n,
1571 extern "C" decl_node
decl_import (decl_node m
, decl_node n
);
1574 lookupExported - attempts to lookup a node named, i, from definition
1575 module, n. The node is returned if found.
1576 NIL is returned if not found.
1579 extern "C" decl_node
decl_lookupExported (decl_node n
, nameKey_Name i
);
1582 lookupSym - returns the symbol named, n, from the scope stack.
1585 extern "C" decl_node
decl_lookupSym (nameKey_Name n
);
1588 addImportedModule - add module, i, to be imported by, m.
1589 If scoped then module, i, is added to the
1593 extern "C" void decl_addImportedModule (decl_node m
, decl_node i
, bool scoped
);
1596 setSource - sets the source filename for module, n, to s.
1599 extern "C" void decl_setSource (decl_node n
, nameKey_Name s
);
1602 getSource - returns the source filename for module, n.
1605 extern "C" nameKey_Name
decl_getSource (decl_node n
);
1608 getMainModule - returns the main module node.
1611 extern "C" decl_node
decl_getMainModule (void);
1614 getCurrentModule - returns the current module being compiled.
1617 extern "C" decl_node
decl_getCurrentModule (void);
1620 foreachDefModuleDo - foreach definition node, n, in the module universe,
1624 extern "C" void decl_foreachDefModuleDo (symbolKey_performOperation p
);
1627 foreachModModuleDo - foreach implementation or module node, n, in the module universe,
1631 extern "C" void decl_foreachModModuleDo (symbolKey_performOperation p
);
1634 enterScope - pushes symbol, n, to the scope stack.
1637 extern "C" void decl_enterScope (decl_node n
);
1640 leaveScope - removes the top level scope.
1643 extern "C" void decl_leaveScope (void);
1646 makeProcedure - create, initialise and return a procedure node.
1649 extern "C" decl_node
decl_makeProcedure (nameKey_Name n
);
1652 putCommentDefProcedure - remembers the procedure comment (if it exists) as a
1653 definition module procedure heading. NIL is placed
1654 if there is no procedure comment available.
1657 extern "C" void decl_putCommentDefProcedure (decl_node n
);
1660 putCommentModProcedure - remembers the procedure comment (if it exists) as an
1661 implementation/program module procedure heading. NIL is placed
1662 if there is no procedure comment available.
1665 extern "C" void decl_putCommentModProcedure (decl_node n
);
1668 makeProcType - returns a proctype node.
1671 extern "C" decl_node
decl_makeProcType (void);
1674 putReturnType - sets the return type of procedure or proctype, proc, to, type.
1677 extern "C" void decl_putReturnType (decl_node proc
, decl_node type
);
1680 putOptReturn - sets, proctype or procedure, proc, to have an optional return type.
1683 extern "C" void decl_putOptReturn (decl_node proc
);
1686 makeVarParameter - returns a var parameter node with, name: type.
1689 extern "C" decl_node
decl_makeVarParameter (decl_node l
, decl_node type
, decl_node proc
, bool isused
);
1692 makeNonVarParameter - returns a non var parameter node with, name: type.
1695 extern "C" decl_node
decl_makeNonVarParameter (decl_node l
, decl_node type
, decl_node proc
, bool isused
);
1698 paramEnter - reset the parameter count.
1701 extern "C" void decl_paramEnter (decl_node n
);
1704 paramLeave - set paramater checking to TRUE from now onwards.
1707 extern "C" void decl_paramLeave (decl_node n
);
1710 makeIdentList - returns a node which will be used to maintain an ident list.
1713 extern "C" decl_node
decl_makeIdentList (void);
1716 putIdent - places ident, i, into identlist, n. It returns TRUE if
1717 ident, i, is unique.
1720 extern "C" bool decl_putIdent (decl_node n
, nameKey_Name i
);
1723 addVarParameters - adds the identlist, i, of, type, to be VAR parameters
1727 extern "C" void decl_addVarParameters (decl_node n
, decl_node i
, decl_node type
, bool isused
);
1730 addNonVarParameters - adds the identlist, i, of, type, to be parameters
1734 extern "C" void decl_addNonVarParameters (decl_node n
, decl_node i
, decl_node type
, bool isused
);
1737 makeVarargs - returns a varargs node.
1740 extern "C" decl_node
decl_makeVarargs (void);
1743 isVarargs - returns TRUE if, n, is a varargs node.
1746 extern "C" bool decl_isVarargs (decl_node n
);
1749 addParameter - adds a parameter, param, to procedure or proctype, proc.
1752 extern "C" void decl_addParameter (decl_node proc
, decl_node param
);
1755 makeBinaryTok - creates and returns a boolean type node with,
1759 extern "C" decl_node
decl_makeBinaryTok (mcReserved_toktype op
, decl_node l
, decl_node r
);
1762 makeUnaryTok - creates and returns a boolean type node with,
1766 extern "C" decl_node
decl_makeUnaryTok (mcReserved_toktype op
, decl_node e
);
1769 makeComponentRef - build a componentref node which accesses, field,
1770 within, record, rec.
1773 extern "C" decl_node
decl_makeComponentRef (decl_node rec
, decl_node field
);
1776 makePointerRef - build a pointerref node which accesses, field,
1777 within, pointer to record, ptr.
1780 extern "C" decl_node
decl_makePointerRef (decl_node ptr
, decl_node field
);
1783 isPointerRef - returns TRUE if, n, is a pointerref node.
1786 extern "C" bool decl_isPointerRef (decl_node n
);
1789 makeDeRef - dereferences the pointer defined by, n.
1792 extern "C" decl_node
decl_makeDeRef (decl_node n
);
1795 makeArrayRef - build an arrayref node which access element,
1796 index, in, array. array is a variable/expression/constant
1797 which has a type array.
1800 extern "C" decl_node
decl_makeArrayRef (decl_node array
, decl_node index
);
1803 getLastOp - return the right most non leaf node.
1806 extern "C" decl_node
decl_getLastOp (decl_node n
);
1809 getCardinal - returns the cardinal type node.
1812 extern "C" decl_node
decl_getCardinal (void);
1815 makeLiteralInt - creates and returns a literal node based on an integer type.
1818 extern "C" decl_node
decl_makeLiteralInt (nameKey_Name n
);
1821 makeLiteralReal - creates and returns a literal node based on a real type.
1824 extern "C" decl_node
decl_makeLiteralReal (nameKey_Name n
);
1827 makeString - creates and returns a node containing string, n.
1830 extern "C" decl_node
decl_makeString (nameKey_Name n
);
1833 makeSetValue - creates and returns a setvalue node.
1836 extern "C" decl_node
decl_makeSetValue (void);
1839 isSetValue - returns TRUE if, n, is a setvalue node.
1842 extern "C" bool decl_isSetValue (decl_node n
);
1845 putSetValue - assigns the type, t, to the set value, n. The
1846 node, n, is returned.
1849 extern "C" decl_node
decl_putSetValue (decl_node n
, decl_node t
);
1852 includeSetValue - includes the range l..h into the setvalue.
1853 h might be NIL indicating that a single element
1854 is to be included into the set.
1858 extern "C" decl_node
decl_includeSetValue (decl_node n
, decl_node l
, decl_node h
);
1861 getBuiltinConst - creates and returns a builtin const if available.
1864 extern "C" decl_node
decl_getBuiltinConst (nameKey_Name n
);
1867 makeExpList - creates and returns an expList node.
1870 extern "C" decl_node
decl_makeExpList (void);
1873 isExpList - returns TRUE if, n, is an explist node.
1876 extern "C" bool decl_isExpList (decl_node n
);
1879 putExpList - places, expression, e, within the explist, n.
1882 extern "C" void decl_putExpList (decl_node n
, decl_node e
);
1885 makeConstExp - returns a constexp node.
1888 extern "C" decl_node
decl_makeConstExp (void);
1891 getNextConstExp - returns the next constexp node.
1894 extern "C" decl_node
decl_getNextConstExp (void);
1897 setConstExpComplete - sets the field inside the def or imp or module, n.
1900 extern "C" void decl_setConstExpComplete (decl_node n
);
1903 fixupConstExp - assign fixup expression, e, into the argument of, c.
1906 extern "C" decl_node
decl_fixupConstExp (decl_node c
, decl_node e
);
1909 resetConstExpPos - resets the index into the saved list of constexps inside
1913 extern "C" void decl_resetConstExpPos (decl_node n
);
1916 makeFuncCall - builds a function call to c with param list, n.
1919 extern "C" decl_node
decl_makeFuncCall (decl_node c
, decl_node n
);
1922 makeStatementSequence - create and return a statement sequence node.
1925 extern "C" decl_node
decl_makeStatementSequence (void);
1928 isStatementSequence - returns TRUE if node, n, is a statement sequence.
1931 extern "C" bool decl_isStatementSequence (decl_node n
);
1934 addStatement - adds node, n, as a statement to statememt sequence, s.
1937 extern "C" void decl_addStatement (decl_node s
, decl_node n
);
1940 addCommentBody - adds a body comment to a statement sequence node.
1943 extern "C" void decl_addCommentBody (decl_node n
);
1946 addCommentAfter - adds an after comment to a statement sequence node.
1949 extern "C" void decl_addCommentAfter (decl_node n
);
1952 addIfComments - adds the, body, and, after, comments to if node, n.
1955 extern "C" void decl_addIfComments (decl_node n
, decl_node body
, decl_node after
);
1958 addElseComments - adds the, body, and, after, comments to an, if, or an elsif, node, n.
1961 extern "C" void decl_addElseComments (decl_node n
, decl_node body
, decl_node after
);
1964 addIfEndComments - adds the, body, and, after, comments to an, if, node, n.
1967 extern "C" void decl_addIfEndComments (decl_node n
, decl_node body
, decl_node after
);
1970 makeReturn - creates and returns a return node.
1973 extern "C" decl_node
decl_makeReturn (void);
1976 isReturn - returns TRUE if node, n, is a return.
1979 extern "C" bool decl_isReturn (decl_node n
);
1982 putReturn - assigns node, e, as the expression on the return node.
1985 extern "C" void decl_putReturn (decl_node n
, decl_node e
);
1988 makeWhile - creates and returns a while node.
1991 extern "C" decl_node
decl_makeWhile (void);
1994 putWhile - places an expression, e, and statement sequence, s, into the while
1998 extern "C" void decl_putWhile (decl_node n
, decl_node e
, decl_node s
);
2001 isWhile - returns TRUE if node, n, is a while.
2004 extern "C" bool decl_isWhile (decl_node n
);
2007 addWhileDoComment - adds body and after comments to while node, w.
2010 extern "C" void decl_addWhileDoComment (decl_node w
, decl_node body
, decl_node after
);
2013 addWhileEndComment - adds body and after comments to the end of a while node, w.
2016 extern "C" void decl_addWhileEndComment (decl_node w
, decl_node body
, decl_node after
);
2019 makeAssignment - creates and returns an assignment node.
2020 The designator is, d, and expression, e.
2023 extern "C" decl_node
decl_makeAssignment (decl_node d
, decl_node e
);
2026 putBegin - assigns statements, s, to be the normal part in
2027 block, b. The block may be a procedure or module,
2028 or implementation node.
2031 extern "C" void decl_putBegin (decl_node b
, decl_node s
);
2034 putFinally - assigns statements, s, to be the final part in
2035 block, b. The block may be a module
2036 or implementation node.
2039 extern "C" void decl_putFinally (decl_node b
, decl_node s
);
2042 makeExit - creates and returns an exit node.
2045 extern "C" decl_node
decl_makeExit (decl_node l
, unsigned int n
);
2048 isExit - returns TRUE if node, n, is an exit.
2051 extern "C" bool decl_isExit (decl_node n
);
2054 makeLoop - creates and returns a loop node.
2057 extern "C" decl_node
decl_makeLoop (void);
2060 isLoop - returns TRUE if, n, is a loop node.
2063 extern "C" bool decl_isLoop (decl_node n
);
2066 putLoop - places statement sequence, s, into loop, l.
2069 extern "C" void decl_putLoop (decl_node l
, decl_node s
);
2072 makeComment - creates and returns a comment node.
2075 extern "C" decl_node
decl_makeComment (const char *a_
, unsigned int _a_high
);
2078 makeCommentS - creates and returns a comment node.
2081 extern "C" decl_node
decl_makeCommentS (mcComment_commentDesc c
);
2084 makeIf - creates and returns an if node. The if node
2085 will have expression, e, and statement sequence, s,
2086 as the then component.
2089 extern "C" decl_node
decl_makeIf (decl_node e
, decl_node s
);
2092 isIf - returns TRUE if, n, is an if node.
2095 extern "C" bool decl_isIf (decl_node n
);
2098 makeElsif - creates and returns an elsif node.
2099 This node has an expression, e, and statement
2103 extern "C" decl_node
decl_makeElsif (decl_node i
, decl_node e
, decl_node s
);
2106 isElsif - returns TRUE if node, n, is an elsif node.
2109 extern "C" bool decl_isElsif (decl_node n
);
2112 putElse - the else is grafted onto the if/elsif node, i,
2113 and the statement sequence will be, s.
2116 extern "C" void decl_putElse (decl_node i
, decl_node s
);
2119 makeFor - creates and returns a for node.
2122 extern "C" decl_node
decl_makeFor (void);
2125 isFor - returns TRUE if node, n, is a for node.
2128 extern "C" bool decl_isFor (decl_node n
);
2131 putFor - assigns the fields of the for node with
2139 extern "C" void decl_putFor (decl_node f
, decl_node i
, decl_node s
, decl_node e
, decl_node b
, decl_node sq
);
2142 makeRepeat - creates and returns a repeat node.
2145 extern "C" decl_node
decl_makeRepeat (void);
2148 isRepeat - returns TRUE if node, n, is a repeat node.
2151 extern "C" bool decl_isRepeat (decl_node n
);
2154 putRepeat - places statements, s, and expression, e, into
2155 repeat statement, n.
2158 extern "C" void decl_putRepeat (decl_node n
, decl_node s
, decl_node e
);
2161 addRepeatComment - adds body and after comments to repeat node, r.
2164 extern "C" void decl_addRepeatComment (decl_node r
, decl_node body
, decl_node after
);
2167 addUntilComment - adds body and after comments to the until section of a repeat node, r.
2170 extern "C" void decl_addUntilComment (decl_node r
, decl_node body
, decl_node after
);
2173 makeCase - builds and returns a case statement node.
2176 extern "C" decl_node
decl_makeCase (void);
2179 isCase - returns TRUE if node, n, is a case statement.
2182 extern "C" bool decl_isCase (decl_node n
);
2185 putCaseExpression - places expression, e, into case statement, n.
2189 extern "C" decl_node
decl_putCaseExpression (decl_node n
, decl_node e
);
2192 putCaseElse - places else statement, e, into case statement, n.
2196 extern "C" decl_node
decl_putCaseElse (decl_node n
, decl_node e
);
2199 putCaseStatement - places a caselist, l, and associated
2200 statement sequence, s, into case statement, n.
2204 extern "C" decl_node
decl_putCaseStatement (decl_node n
, decl_node l
, decl_node s
);
2207 makeCaseLabelList - creates and returns a caselabellist node.
2210 extern "C" decl_node
decl_makeCaseLabelList (decl_node l
, decl_node s
);
2213 isCaseLabelList - returns TRUE if, n, is a caselabellist.
2216 extern "C" bool decl_isCaseLabelList (decl_node n
);
2219 makeCaseList - creates and returns a case statement node.
2222 extern "C" decl_node
decl_makeCaseList (void);
2225 isCaseList - returns TRUE if, n, is a case list.
2228 extern "C" bool decl_isCaseList (decl_node n
);
2231 putCaseRange - places the case range lo..hi into caselist, n.
2234 extern "C" decl_node
decl_putCaseRange (decl_node n
, decl_node lo
, decl_node hi
);
2237 makeRange - creates and returns a case range.
2240 extern "C" decl_node
decl_makeRange (decl_node lo
, decl_node hi
);
2243 isRange - returns TRUE if node, n, is a range.
2246 extern "C" bool decl_isRange (decl_node n
);
2249 setNoReturn - sets noreturn field inside procedure.
2252 extern "C" void decl_setNoReturn (decl_node n
, bool value
);
2255 dupExpr - duplicate the expression nodes, it does not duplicate
2256 variables, literals, constants but only the expression
2257 operators (including function calls and parameter lists).
2260 extern "C" decl_node
decl_dupExpr (decl_node n
);
2266 extern "C" void decl_setLangC (void);
2272 extern "C" void decl_setLangCP (void);
2278 extern "C" void decl_setLangM2 (void);
2281 out - walks the tree of node declarations for the main module
2282 and writes the output to the outputFile specified in
2283 mcOptions. It outputs the declarations in the language
2287 extern "C" void decl_out (void);
2288 extern "C" nameKey_Name
nameKey_makeKey (const char *a_
, unsigned int _a_high
);
2289 extern "C" nameKey_Name
nameKey_makekey (void * a
);
2290 extern "C" void nameKey_getKey (nameKey_Name key
, char *a
, unsigned int _a_high
);
2291 extern "C" unsigned int nameKey_lengthKey (nameKey_Name key
);
2292 extern "C" bool nameKey_isKey (const char *a_
, unsigned int _a_high
);
2293 extern "C" void nameKey_writeKey (nameKey_Name key
);
2294 extern "C" bool nameKey_isSameExcludingCase (nameKey_Name key1
, nameKey_Name key2
);
2295 extern "C" void * nameKey_keyToCharStar (nameKey_Name key
);
2296 extern "C" symbolKey_symbolTree
symbolKey_initTree (void);
2297 extern "C" void symbolKey_killTree (symbolKey_symbolTree
*t
);
2298 extern "C" void * symbolKey_getSymKey (symbolKey_symbolTree t
, nameKey_Name name
);
2299 extern "C" void symbolKey_putSymKey (symbolKey_symbolTree t
, nameKey_Name name
, void * key
);
2302 delSymKey - deletes an entry in the binary tree.
2304 NB in order for this to work we must ensure that the InitTree sets
2305 both left and right to NIL.
2308 extern "C" void symbolKey_delSymKey (symbolKey_symbolTree t
, nameKey_Name name
);
2311 isEmptyTree - returns true if symbolTree, t, is empty.
2314 extern "C" bool symbolKey_isEmptyTree (symbolKey_symbolTree t
);
2317 doesTreeContainAny - returns true if symbolTree, t, contains any
2318 symbols which in turn return true when procedure,
2319 p, is called with a symbol as its parameter.
2320 The symbolTree root is empty apart from the field,
2321 left, hence we need two procedures.
2324 extern "C" bool symbolKey_doesTreeContainAny (symbolKey_symbolTree t
, symbolKey_isSymbol p
);
2327 foreachNodeDo - for each node in symbolTree, t, a procedure, p,
2328 is called with the node symbol as its parameter.
2329 The tree root node only contains a legal left pointer,
2330 therefore we need two procedures to examine this tree.
2333 extern "C" void symbolKey_foreachNodeDo (symbolKey_symbolTree t
, symbolKey_performOperation p
);
2336 initComment - the start of a new comment has been seen by the lexical analyser.
2337 A new comment block is created and all addText contents are placed
2338 in this block. onlySpaces indicates whether we have only seen
2339 spaces on this line.
2342 extern "C" mcComment_commentDesc
mcComment_initComment (bool onlySpaces
);
2345 addText - cs is a C string (null terminated) which contains comment text.
2346 This is appended to the comment, cd.
2349 extern "C" void mcComment_addText (mcComment_commentDesc cd
, void * cs
);
2352 getContent - returns the content of comment, cd.
2355 extern "C" DynamicStrings_String
mcComment_getContent (mcComment_commentDesc cd
);
2358 getCommentCharStar - returns the C string content of comment, cd.
2361 extern "C" void * mcComment_getCommentCharStar (mcComment_commentDesc cd
);
2364 setProcedureComment - changes the type of comment, cd, to a
2365 procedure heading comment,
2366 providing it has the procname as the first word.
2369 extern "C" void mcComment_setProcedureComment (mcComment_commentDesc cd
, nameKey_Name procname
);
2372 getProcedureComment - returns the current procedure comment if available.
2375 extern "C" DynamicStrings_String
mcComment_getProcedureComment (mcComment_commentDesc cd
);
2378 getAfterStatementComment - returns the current statement after comment if available.
2381 extern "C" DynamicStrings_String
mcComment_getAfterStatementComment (mcComment_commentDesc cd
);
2384 getInbodyStatementComment - returns the current statement after comment if available.
2387 extern "C" DynamicStrings_String
mcComment_getInbodyStatementComment (mcComment_commentDesc cd
);
2390 isProcedureComment - returns TRUE if, cd, is a procedure comment.
2393 extern "C" bool mcComment_isProcedureComment (mcComment_commentDesc cd
);
2396 isBodyComment - returns TRUE if, cd, is a body comment.
2399 extern "C" bool mcComment_isBodyComment (mcComment_commentDesc cd
);
2402 isAfterComment - returns TRUE if, cd, is an after comment.
2405 extern "C" bool mcComment_isAfterComment (mcComment_commentDesc cd
);
2406 extern "C" void mcDebug_assert (bool q
);
2407 extern "C" void mcDebug_writeDebug (const char *a_
, unsigned int _a_high
);
2408 extern "C" void Storage_ALLOCATE (void * *a
, unsigned int Size
);
2409 extern "C" void Storage_DEALLOCATE (void * *a
, unsigned int Size
);
2410 extern "C" void Storage_REALLOCATE (void * *a
, unsigned int Size
);
2411 extern "C" bool Storage_Available (unsigned int Size
);
2412 extern "C" bool SFIO_Exists (DynamicStrings_String fname
);
2413 extern "C" FIO_File
SFIO_OpenToRead (DynamicStrings_String fname
);
2414 extern "C" FIO_File
SFIO_OpenToWrite (DynamicStrings_String fname
);
2415 extern "C" FIO_File
SFIO_OpenForRandom (DynamicStrings_String fname
, bool towrite
, bool newfile
);
2416 extern "C" DynamicStrings_String
SFIO_WriteS (FIO_File file
, DynamicStrings_String s
);
2417 extern "C" DynamicStrings_String
SFIO_ReadS (FIO_File file
);
2418 extern "C" bool FIO_IsNoError (FIO_File f
);
2419 extern "C" bool FIO_IsActive (FIO_File f
);
2420 extern "C" bool FIO_Exists (const char *fname_
, unsigned int _fname_high
);
2421 extern "C" FIO_File
FIO_OpenToRead (const char *fname_
, unsigned int _fname_high
);
2422 extern "C" FIO_File
FIO_OpenToWrite (const char *fname_
, unsigned int _fname_high
);
2423 extern "C" FIO_File
FIO_OpenForRandom (const char *fname_
, unsigned int _fname_high
, bool towrite
, bool newfile
);
2424 extern "C" void FIO_Close (FIO_File f
);
2425 extern "C" bool FIO_exists (void * fname
, unsigned int flength
);
2426 extern "C" FIO_File
FIO_openToRead (void * fname
, unsigned int flength
);
2427 extern "C" FIO_File
FIO_openToWrite (void * fname
, unsigned int flength
);
2428 extern "C" FIO_File
FIO_openForRandom (void * fname
, unsigned int flength
, bool towrite
, bool newfile
);
2429 extern "C" void FIO_FlushBuffer (FIO_File f
);
2430 extern "C" unsigned int FIO_ReadNBytes (FIO_File f
, unsigned int nBytes
, void * dest
);
2431 extern "C" void FIO_ReadAny (FIO_File f
, unsigned char *a
, unsigned int _a_high
);
2432 extern "C" unsigned int FIO_WriteNBytes (FIO_File f
, unsigned int nBytes
, void * src
);
2433 extern "C" void FIO_WriteAny (FIO_File f
, unsigned char *a
, unsigned int _a_high
);
2434 extern "C" void FIO_WriteChar (FIO_File f
, char ch
);
2435 extern "C" bool FIO_EOF (FIO_File f
);
2436 extern "C" bool FIO_EOLN (FIO_File f
);
2437 extern "C" bool FIO_WasEOLN (FIO_File f
);
2438 extern "C" char FIO_ReadChar (FIO_File f
);
2439 extern "C" void FIO_UnReadChar (FIO_File f
, char ch
);
2440 extern "C" void FIO_WriteLine (FIO_File f
);
2441 extern "C" void FIO_WriteString (FIO_File f
, const char *a_
, unsigned int _a_high
);
2442 extern "C" void FIO_ReadString (FIO_File f
, char *a
, unsigned int _a_high
);
2443 extern "C" void FIO_WriteCardinal (FIO_File f
, unsigned int c
);
2444 extern "C" unsigned int FIO_ReadCardinal (FIO_File f
);
2445 extern "C" int FIO_GetUnixFileDescriptor (FIO_File f
);
2446 extern "C" void FIO_SetPositionFromBeginning (FIO_File f
, long int pos
);
2447 extern "C" void FIO_SetPositionFromEnd (FIO_File f
, long int pos
);
2448 extern "C" long int FIO_FindPosition (FIO_File f
);
2449 extern "C" void FIO_GetFileName (FIO_File f
, char *a
, unsigned int _a_high
);
2450 extern "C" void * FIO_getFileName (FIO_File f
);
2451 extern "C" unsigned int FIO_getFileNameLength (FIO_File f
);
2452 extern "C" void FIO_FlushOutErr (void);
2455 InitString - creates and returns a String type object.
2456 Initial contents are, a.
2459 extern "C" DynamicStrings_String
DynamicStrings_InitString (const char *a_
, unsigned int _a_high
);
2462 KillString - frees String, s, and its contents.
2466 extern "C" DynamicStrings_String
DynamicStrings_KillString (DynamicStrings_String s
);
2469 Fin - finishes with a string, it calls KillString with, s.
2470 The purpose of the procedure is to provide a short cut
2471 to calling KillString and then testing the return result.
2474 extern "C" void DynamicStrings_Fin (DynamicStrings_String s
);
2477 InitStringCharStar - initializes and returns a String to contain the C string.
2480 extern "C" DynamicStrings_String
DynamicStrings_InitStringCharStar (void * a
);
2483 InitStringChar - initializes and returns a String to contain the single character, ch.
2486 extern "C" DynamicStrings_String
DynamicStrings_InitStringChar (char ch
);
2489 Mark - marks String, s, ready for garbage collection.
2492 extern "C" DynamicStrings_String
DynamicStrings_Mark (DynamicStrings_String s
);
2495 Length - returns the length of the String, s.
2498 extern "C" unsigned int DynamicStrings_Length (DynamicStrings_String s
);
2501 ConCat - returns String, a, after the contents of, b, have been appended.
2504 extern "C" DynamicStrings_String
DynamicStrings_ConCat (DynamicStrings_String a
, DynamicStrings_String b
);
2507 ConCatChar - returns String, a, after character, ch, has been appended.
2510 extern "C" DynamicStrings_String
DynamicStrings_ConCatChar (DynamicStrings_String a
, char ch
);
2513 Assign - assigns the contents of, b, into, a.
2514 String, a, is returned.
2517 extern "C" DynamicStrings_String
DynamicStrings_Assign (DynamicStrings_String a
, DynamicStrings_String b
);
2520 ReplaceChar - returns string s after it has changed all occurances of from to to.
2523 extern "C" DynamicStrings_String
DynamicStrings_ReplaceChar (DynamicStrings_String s
, char from
, char to
);
2526 Dup - duplicate a String, s, returning the copy of s.
2529 extern "C" DynamicStrings_String
DynamicStrings_Dup (DynamicStrings_String s
);
2532 Add - returns a new String which contains the contents of a and b.
2535 extern "C" DynamicStrings_String
DynamicStrings_Add (DynamicStrings_String a
, DynamicStrings_String b
);
2538 Equal - returns TRUE if String, a, and, b, are equal.
2541 extern "C" bool DynamicStrings_Equal (DynamicStrings_String a
, DynamicStrings_String b
);
2544 EqualCharStar - returns TRUE if contents of String, s, is the same as the
2548 extern "C" bool DynamicStrings_EqualCharStar (DynamicStrings_String s
, void * a
);
2551 EqualArray - returns TRUE if contents of String, s, is the same as the
2555 extern "C" bool DynamicStrings_EqualArray (DynamicStrings_String s
, const char *a_
, unsigned int _a_high
);
2558 Mult - returns a new string which is n concatenations of String, s.
2561 extern "C" DynamicStrings_String
DynamicStrings_Mult (DynamicStrings_String s
, unsigned int n
);
2564 Slice - returns a new string which contains the elements
2567 strings start at element 0
2568 Slice(s, 0, 2) will return elements 0, 1 but not 2
2569 Slice(s, 1, 3) will return elements 1, 2 but not 3
2570 Slice(s, 2, 0) will return elements 2..max
2571 Slice(s, 3, -1) will return elements 3..max-1
2572 Slice(s, 4, -2) will return elements 4..max-2
2575 extern "C" DynamicStrings_String
DynamicStrings_Slice (DynamicStrings_String s
, int low
, int high
);
2578 Index - returns the indice of the first occurance of, ch, in
2579 String, s. -1 is returned if, ch, does not exist.
2580 The search starts at position, o.
2583 extern "C" int DynamicStrings_Index (DynamicStrings_String s
, char ch
, unsigned int o
);
2586 RIndex - returns the indice of the last occurance of, ch,
2587 in String, s. The search starts at position, o.
2588 -1 is returned if, ch, is not found.
2591 extern "C" int DynamicStrings_RIndex (DynamicStrings_String s
, char ch
, unsigned int o
);
2594 RemoveComment - assuming that, comment, is a comment delimiter
2595 which indicates anything to its right is a comment
2596 then strip off the comment and also any white space
2597 on the remaining right hand side.
2598 It leaves any white space on the left hand side alone.
2601 extern "C" DynamicStrings_String
DynamicStrings_RemoveComment (DynamicStrings_String s
, char comment
);
2604 RemoveWhitePrefix - removes any leading white space from String, s.
2605 A new string is returned.
2608 extern "C" DynamicStrings_String
DynamicStrings_RemoveWhitePrefix (DynamicStrings_String s
);
2611 RemoveWhitePostfix - removes any leading white space from String, s.
2612 A new string is returned.
2615 extern "C" DynamicStrings_String
DynamicStrings_RemoveWhitePostfix (DynamicStrings_String s
);
2618 ToUpper - returns string, s, after it has had its lower case characters
2619 replaced by upper case characters.
2620 The string, s, is not duplicated.
2623 extern "C" DynamicStrings_String
DynamicStrings_ToUpper (DynamicStrings_String s
);
2626 ToLower - returns string, s, after it has had its upper case characters
2627 replaced by lower case characters.
2628 The string, s, is not duplicated.
2631 extern "C" DynamicStrings_String
DynamicStrings_ToLower (DynamicStrings_String s
);
2634 CopyOut - copies string, s, to a.
2637 extern "C" void DynamicStrings_CopyOut (char *a
, unsigned int _a_high
, DynamicStrings_String s
);
2640 char - returns the character, ch, at position, i, in String, s.
2643 extern "C" char DynamicStrings_char (DynamicStrings_String s
, int i
);
2646 string - returns the C style char * of String, s.
2649 extern "C" void * DynamicStrings_string (DynamicStrings_String s
);
2652 InitStringDB - the debug version of InitString.
2655 extern "C" DynamicStrings_String
DynamicStrings_InitStringDB (const char *a_
, unsigned int _a_high
, const char *file_
, unsigned int _file_high
, unsigned int line
);
2658 InitStringCharStarDB - the debug version of InitStringCharStar.
2661 extern "C" DynamicStrings_String
DynamicStrings_InitStringCharStarDB (void * a
, const char *file_
, unsigned int _file_high
, unsigned int line
);
2664 InitStringCharDB - the debug version of InitStringChar.
2667 extern "C" DynamicStrings_String
DynamicStrings_InitStringCharDB (char ch
, const char *file_
, unsigned int _file_high
, unsigned int line
);
2670 MultDB - the debug version of MultDB.
2673 extern "C" DynamicStrings_String
DynamicStrings_MultDB (DynamicStrings_String s
, unsigned int n
, const char *file_
, unsigned int _file_high
, unsigned int line
);
2676 DupDB - the debug version of Dup.
2679 extern "C" DynamicStrings_String
DynamicStrings_DupDB (DynamicStrings_String s
, const char *file_
, unsigned int _file_high
, unsigned int line
);
2682 SliceDB - debug version of Slice.
2685 extern "C" DynamicStrings_String
DynamicStrings_SliceDB (DynamicStrings_String s
, int low
, int high
, const char *file_
, unsigned int _file_high
, unsigned int line
);
2688 PushAllocation - pushes the current allocation/deallocation lists.
2691 extern "C" void DynamicStrings_PushAllocation (void);
2694 PopAllocation - test to see that all strings are deallocated since
2695 the last push. Then it pops to the previous
2696 allocation/deallocation lists.
2698 If halt is true then the application terminates
2699 with an exit code of 1.
2702 extern "C" void DynamicStrings_PopAllocation (bool halt
);
2705 PopAllocationExemption - test to see that all strings are deallocated, except
2706 string e since the last push.
2707 Post-condition: it pops to the previous allocation/deallocation
2710 If halt is true then the application terminates
2711 with an exit code of 1.
2714 extern "C" DynamicStrings_String
DynamicStrings_PopAllocationExemption (bool halt
, DynamicStrings_String e
);
2715 extern "C" DynamicStrings_String
StringConvert_IntegerToString (int i
, unsigned int width
, char padding
, bool sign
, unsigned int base
, bool lower
);
2716 extern "C" DynamicStrings_String
StringConvert_CardinalToString (unsigned int c
, unsigned int width
, char padding
, unsigned int base
, bool lower
);
2717 extern "C" int StringConvert_StringToInteger (DynamicStrings_String s
, unsigned int base
, bool *found
);
2718 extern "C" unsigned int StringConvert_StringToCardinal (DynamicStrings_String s
, unsigned int base
, bool *found
);
2719 extern "C" DynamicStrings_String
StringConvert_LongIntegerToString (long int i
, unsigned int width
, char padding
, bool sign
, unsigned int base
, bool lower
);
2720 extern "C" long int StringConvert_StringToLongInteger (DynamicStrings_String s
, unsigned int base
, bool *found
);
2721 extern "C" DynamicStrings_String
StringConvert_LongCardinalToString (long unsigned int c
, unsigned int width
, char padding
, unsigned int base
, bool lower
);
2722 extern "C" long unsigned int StringConvert_StringToLongCardinal (DynamicStrings_String s
, unsigned int base
, bool *found
);
2723 extern "C" DynamicStrings_String
StringConvert_ShortCardinalToString (short unsigned int c
, unsigned int width
, char padding
, unsigned int base
, bool lower
);
2724 extern "C" short unsigned int StringConvert_StringToShortCardinal (DynamicStrings_String s
, unsigned int base
, bool *found
);
2725 extern "C" int StringConvert_stoi (DynamicStrings_String s
);
2726 extern "C" DynamicStrings_String
StringConvert_itos (int i
, unsigned int width
, char padding
, bool sign
);
2727 extern "C" DynamicStrings_String
StringConvert_ctos (unsigned int c
, unsigned int width
, char padding
);
2728 extern "C" unsigned int StringConvert_stoc (DynamicStrings_String s
);
2729 extern "C" int StringConvert_hstoi (DynamicStrings_String s
);
2730 extern "C" int StringConvert_ostoi (DynamicStrings_String s
);
2731 extern "C" int StringConvert_bstoi (DynamicStrings_String s
);
2732 extern "C" unsigned int StringConvert_hstoc (DynamicStrings_String s
);
2733 extern "C" unsigned int StringConvert_ostoc (DynamicStrings_String s
);
2734 extern "C" unsigned int StringConvert_bstoc (DynamicStrings_String s
);
2735 extern "C" long double StringConvert_StringToLongreal (DynamicStrings_String s
, bool *found
);
2736 extern "C" DynamicStrings_String
StringConvert_LongrealToString (long double x
, unsigned int TotalWidth
, unsigned int FractionWidth
);
2737 extern "C" double StringConvert_stor (DynamicStrings_String s
);
2738 extern "C" long double StringConvert_stolr (DynamicStrings_String s
);
2739 extern "C" DynamicStrings_String
StringConvert_ToSigFig (DynamicStrings_String s
, unsigned int n
);
2740 extern "C" DynamicStrings_String
StringConvert_ToDecimalPlaces (DynamicStrings_String s
, unsigned int n
);
2741 extern "C" DynamicStrings_String
mcOptions_handleOptions (void);
2742 extern "C" bool mcOptions_getQuiet (void);
2743 extern "C" bool mcOptions_getVerbose (void);
2744 extern "C" bool mcOptions_getInternalDebugging (void);
2745 extern "C" DynamicStrings_String
mcOptions_getCppCommandLine (void);
2746 extern "C" DynamicStrings_String
mcOptions_getOutputFile (void);
2747 extern "C" bool mcOptions_getExtendedOpaque (void);
2748 extern "C" void mcOptions_setDebugTopological (bool value
);
2749 extern "C" bool mcOptions_getDebugTopological (void);
2750 extern "C" DynamicStrings_String
mcOptions_getHPrefix (void);
2751 extern "C" bool mcOptions_getIgnoreFQ (void);
2752 extern "C" bool mcOptions_getGccConfigSystem (void);
2753 extern "C" bool mcOptions_getScaffoldDynamic (void);
2754 extern "C" bool mcOptions_getScaffoldMain (void);
2755 extern "C" void mcOptions_writeGPLheader (FIO_File f
);
2756 extern "C" void mcOptions_setSuppressNoReturn (bool value
);
2757 extern "C" bool mcOptions_getSuppressNoReturn (void);
2758 extern "C" bool mcOptions_useBool (void);
2759 extern "C" DynamicStrings_String
mcOptions_getCRealType (void);
2760 extern "C" DynamicStrings_String
mcOptions_getCLongRealType (void);
2761 extern "C" DynamicStrings_String
mcOptions_getCShortRealType (void);
2762 extern "C" DynamicStrings_String
FormatStrings_Sprintf0 (DynamicStrings_String fmt
);
2763 extern "C" DynamicStrings_String
FormatStrings_Sprintf1 (DynamicStrings_String fmt
, const unsigned char *w_
, unsigned int _w_high
);
2764 extern "C" DynamicStrings_String
FormatStrings_Sprintf2 (DynamicStrings_String fmt
, const unsigned char *w1_
, unsigned int _w1_high
, const unsigned char *w2_
, unsigned int _w2_high
);
2765 extern "C" DynamicStrings_String
FormatStrings_Sprintf3 (DynamicStrings_String fmt
, const unsigned char *w1_
, unsigned int _w1_high
, const unsigned char *w2_
, unsigned int _w2_high
, const unsigned char *w3_
, unsigned int _w3_high
);
2766 extern "C" DynamicStrings_String
FormatStrings_Sprintf4 (DynamicStrings_String fmt
, const unsigned char *w1_
, unsigned int _w1_high
, const unsigned char *w2_
, unsigned int _w2_high
, const unsigned char *w3_
, unsigned int _w3_high
, const unsigned char *w4_
, unsigned int _w4_high
);
2767 extern "C" DynamicStrings_String
FormatStrings_HandleEscape (DynamicStrings_String s
);
2768 extern "C" ssize_t
libc_write (int d
, void * buf
, size_t nbytes
);
2769 extern "C" ssize_t
libc_read (int d
, void * buf
, size_t nbytes
);
2770 extern "C" int libc_system (void * a
);
2771 extern "C" void libc_abort (void) __attribute__ ((noreturn
));
2772 extern "C" void * libc_malloc (size_t size
);
2773 extern "C" void libc_free (void * ptr
);
2774 extern "C" void * libc_realloc (void * ptr
, size_t size
);
2775 extern "C" int libc_isatty (int fd
);
2776 extern "C" void libc_exit (int r
) __attribute__ ((noreturn
));
2777 extern "C" void * libc_getenv (void * s
);
2778 extern "C" int libc_putenv (void * s
);
2779 extern "C" int libc_getpid (void);
2780 extern "C" int libc_dup (int d
);
2781 extern "C" int libc_close (int d
);
2782 extern "C" int libc_open (void * filename
, int oflag
, ...);
2783 extern "C" int libc_creat (void * filename
, unsigned int mode
);
2784 extern "C" long int libc_lseek (int fd
, long int offset
, int whence
);
2785 extern "C" void libc_perror (const char *string_
, unsigned int _string_high
);
2786 extern "C" int libc_readv (int fd
, void * v
, int n
);
2787 extern "C" int libc_writev (int fd
, void * v
, int n
);
2788 extern "C" void * libc_getcwd (void * buf
, size_t size
);
2789 extern "C" int libc_chown (void * filename
, int uid
, int gid
);
2790 extern "C" size_t libc_strlen (void * a
);
2791 extern "C" void * libc_strcpy (void * dest
, void * src
);
2792 extern "C" void * libc_strncpy (void * dest
, void * src
, unsigned int n
);
2793 extern "C" int libc_unlink (void * file
);
2794 extern "C" void * libc_memcpy (void * dest
, void * src
, size_t size
);
2795 extern "C" void * libc_memset (void * s
, int c
, size_t size
);
2796 extern "C" void * libc_memmove (void * dest
, void * src
, size_t size
);
2797 extern "C" int libc_printf (const char *format_
, unsigned int _format_high
, ...);
2798 extern "C" int libc_snprintf (void * dest
, size_t size
, const char *format_
, unsigned int _format_high
, ...);
2799 extern "C" int libc_setenv (void * name
, void * value
, int overwrite
);
2800 extern "C" void libc_srand (int seed
);
2801 extern "C" int libc_rand (void);
2802 extern "C" libc_time_t
libc_time (void * a
);
2803 extern "C" void * libc_localtime (libc_time_t
*t
);
2804 extern "C" int libc_ftime (libc_timeb
*t
);
2805 extern "C" int libc_shutdown (int s
, int how
);
2806 extern "C" int libc_rename (void * oldpath
, void * newpath
);
2807 extern "C" int libc_setjmp (void * env
);
2808 extern "C" void libc_longjmp (void * env
, int val
);
2809 extern "C" int libc_atexit (libc_exitP_C proc
);
2810 extern "C" void * libc_ttyname (int filedes
);
2811 extern "C" unsigned int libc_sleep (unsigned int seconds
);
2812 extern "C" int libc_execv (void * pathname
, void * argv
);
2813 extern "C" void mcMetaError_metaError1 (const char *m_
, unsigned int _m_high
, const unsigned char *s_
, unsigned int _s_high
);
2814 extern "C" void mcMetaError_metaError2 (const char *m_
, unsigned int _m_high
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
);
2815 extern "C" void mcMetaError_metaError3 (const char *m_
, unsigned int _m_high
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
, const unsigned char *s3_
, unsigned int _s3_high
);
2816 extern "C" void mcMetaError_metaError4 (const char *m_
, unsigned int _m_high
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
, const unsigned char *s3_
, unsigned int _s3_high
, const unsigned char *s4_
, unsigned int _s4_high
);
2817 extern "C" void mcMetaError_metaErrors1 (const char *m1_
, unsigned int _m1_high
, const char *m2_
, unsigned int _m2_high
, const unsigned char *s_
, unsigned int _s_high
);
2818 extern "C" void mcMetaError_metaErrors2 (const char *m1_
, unsigned int _m1_high
, const char *m2_
, unsigned int _m2_high
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
);
2819 extern "C" void mcMetaError_metaErrors3 (const char *m1_
, unsigned int _m1_high
, const char *m2_
, unsigned int _m2_high
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
, const unsigned char *s3_
, unsigned int _s3_high
);
2820 extern "C" void mcMetaError_metaErrors4 (const char *m1_
, unsigned int _m1_high
, const char *m2_
, unsigned int _m2_high
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
, const unsigned char *s3_
, unsigned int _s3_high
, const unsigned char *s4_
, unsigned int _s4_high
);
2821 extern "C" void mcMetaError_metaErrorT1 (unsigned int tok
, const char *m_
, unsigned int _m_high
, const unsigned char *s_
, unsigned int _s_high
);
2822 extern "C" void mcMetaError_metaErrorT2 (unsigned int tok
, const char *m_
, unsigned int _m_high
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
);
2823 extern "C" void mcMetaError_metaErrorT3 (unsigned int tok
, const char *m_
, unsigned int _m_high
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
, const unsigned char *s3_
, unsigned int _s3_high
);
2824 extern "C" void mcMetaError_metaErrorT4 (unsigned int tok
, const char *m_
, unsigned int _m_high
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
, const unsigned char *s3_
, unsigned int _s3_high
, const unsigned char *s4_
, unsigned int _s4_high
);
2825 extern "C" void mcMetaError_metaErrorsT1 (unsigned int tok
, const char *m1_
, unsigned int _m1_high
, const char *m2_
, unsigned int _m2_high
, const unsigned char *s_
, unsigned int _s_high
);
2826 extern "C" void mcMetaError_metaErrorsT2 (unsigned int tok
, const char *m1_
, unsigned int _m1_high
, const char *m2_
, unsigned int _m2_high
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
);
2827 extern "C" void mcMetaError_metaErrorsT3 (unsigned int tok
, const char *m1_
, unsigned int _m1_high
, const char *m2_
, unsigned int _m2_high
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
, const unsigned char *s3_
, unsigned int _s3_high
);
2828 extern "C" void mcMetaError_metaErrorsT4 (unsigned int tok
, const char *m1_
, unsigned int _m1_high
, const char *m2_
, unsigned int _m2_high
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
, const unsigned char *s3_
, unsigned int _s3_high
, const unsigned char *s4_
, unsigned int _s4_high
);
2829 extern "C" void mcMetaError_metaErrorString1 (DynamicStrings_String m
, const unsigned char *s_
, unsigned int _s_high
);
2830 extern "C" void mcMetaError_metaErrorString2 (DynamicStrings_String m
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
);
2831 extern "C" void mcMetaError_metaErrorString3 (DynamicStrings_String m
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
, const unsigned char *s3_
, unsigned int _s3_high
);
2832 extern "C" void mcMetaError_metaErrorString4 (DynamicStrings_String m
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
, const unsigned char *s3_
, unsigned int _s3_high
, const unsigned char *s4_
, unsigned int _s4_high
);
2833 extern "C" void mcMetaError_metaErrorStringT1 (unsigned int tok
, DynamicStrings_String m
, const unsigned char *s_
, unsigned int _s_high
);
2834 extern "C" void mcMetaError_metaErrorStringT2 (unsigned int tok
, DynamicStrings_String m
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
);
2835 extern "C" void mcMetaError_metaErrorStringT3 (unsigned int tok
, DynamicStrings_String m
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
, const unsigned char *s3_
, unsigned int _s3_high
);
2836 extern "C" void mcMetaError_metaErrorStringT4 (unsigned int tok
, DynamicStrings_String m
, const unsigned char *s1_
, unsigned int _s1_high
, const unsigned char *s2_
, unsigned int _s2_high
, const unsigned char *s3_
, unsigned int _s3_high
, const unsigned char *s4_
, unsigned int _s4_high
);
2839 internalError - displays an internal error message together with the compiler source
2840 file and line number.
2841 This function is not buffered and is used when the compiler is about
2845 extern "C" void mcError_internalError (const char *a_
, unsigned int _a_high
, const char *file_
, unsigned int _file_high
, unsigned int line
);
2848 writeFormat0 - displays the source module and line together
2849 with the encapsulated format string.
2850 Used for simple error messages tied to the current token.
2853 extern "C" void mcError_writeFormat0 (const char *a_
, unsigned int _a_high
);
2856 writeFormat1 - displays the source module and line together
2857 with the encapsulated format string.
2858 Used for simple error messages tied to the current token.
2861 extern "C" void mcError_writeFormat1 (const char *a_
, unsigned int _a_high
, const unsigned char *w_
, unsigned int _w_high
);
2864 writeFormat2 - displays the module and line together with the encapsulated
2866 Used for simple error messages tied to the current token.
2869 extern "C" void mcError_writeFormat2 (const char *a_
, unsigned int _a_high
, const unsigned char *w1_
, unsigned int _w1_high
, const unsigned char *w2_
, unsigned int _w2_high
);
2872 writeFormat3 - displays the module and line together with the encapsulated
2874 Used for simple error messages tied to the current token.
2877 extern "C" void mcError_writeFormat3 (const char *a_
, unsigned int _a_high
, const unsigned char *w1_
, unsigned int _w1_high
, const unsigned char *w2_
, unsigned int _w2_high
, const unsigned char *w3_
, unsigned int _w3_high
);
2880 newError - creates and returns a new error handle.
2883 extern "C" mcError_error
mcError_newError (unsigned int atTokenNo
);
2886 newWarning - creates and returns a new error handle suitable for a warning.
2887 A warning will not stop compilation.
2890 extern "C" mcError_error
mcError_newWarning (unsigned int atTokenNo
);
2893 chainError - creates and returns a new error handle, this new error
2894 is associated with, e, and is chained onto the end of, e.
2895 If, e, is NIL then the result to NewError is returned.
2898 extern "C" mcError_error
mcError_chainError (unsigned int atTokenNo
, mcError_error e
);
2899 extern "C" void mcError_errorFormat0 (mcError_error e
, const char *a_
, unsigned int _a_high
);
2900 extern "C" void mcError_errorFormat1 (mcError_error e
, const char *a_
, unsigned int _a_high
, const unsigned char *w_
, unsigned int _w_high
);
2901 extern "C" void mcError_errorFormat2 (mcError_error e
, const char *a_
, unsigned int _a_high
, const unsigned char *w1_
, unsigned int _w1_high
, const unsigned char *w2_
, unsigned int _w2_high
);
2902 extern "C" void mcError_errorFormat3 (mcError_error e
, const char *a_
, unsigned int _a_high
, const unsigned char *w1_
, unsigned int _w1_high
, const unsigned char *w2_
, unsigned int _w2_high
, const unsigned char *w3_
, unsigned int _w3_high
);
2903 extern "C" void mcError_errorString (mcError_error e
, DynamicStrings_String str
);
2906 errorStringAt - given an error string, s, it places this
2907 string at token position, tok.
2908 The string is consumed.
2911 extern "C" void mcError_errorStringAt (DynamicStrings_String s
, unsigned int tok
);
2914 errorStringAt2 - given an error string, s, it places this
2915 string at token positions, tok1 and tok2, respectively.
2916 The string is consumed.
2919 extern "C" void mcError_errorStringAt2 (DynamicStrings_String s
, unsigned int tok1
, unsigned int tok2
);
2922 errorStringsAt2 - given error strings, s1, and, s2, it places these
2923 strings at token positions, tok1 and tok2, respectively.
2924 Both strings are consumed.
2927 extern "C" void mcError_errorStringsAt2 (DynamicStrings_String s1
, DynamicStrings_String s2
, unsigned int tok1
, unsigned int tok2
);
2930 warnStringAt - given an error string, s, it places this
2931 string at token position, tok.
2932 The string is consumed.
2935 extern "C" void mcError_warnStringAt (DynamicStrings_String s
, unsigned int tok
);
2938 warnStringAt2 - given an warning string, s, it places this
2939 string at token positions, tok1 and tok2, respectively.
2940 The string is consumed.
2943 extern "C" void mcError_warnStringAt2 (DynamicStrings_String s
, unsigned int tok1
, unsigned int tok2
);
2946 warnStringsAt2 - given warning strings, s1, and, s2, it places these
2947 strings at token positions, tok1 and tok2, respectively.
2948 Both strings are consumed.
2951 extern "C" void mcError_warnStringsAt2 (DynamicStrings_String s1
, DynamicStrings_String s2
, unsigned int tok1
, unsigned int tok2
);
2952 extern "C" void mcError_warnFormat0 (const char *a_
, unsigned int _a_high
);
2955 warnFormat1 - displays the source module and line together
2956 with the encapsulated format string.
2957 Used for simple warning messages tied to the current token.
2960 extern "C" void mcError_warnFormat1 (const char *a_
, unsigned int _a_high
, const unsigned char *w_
, unsigned int _w_high
);
2963 flushErrors - switches the output channel to the error channel
2964 and then writes out all errors.
2967 extern "C" void mcError_flushErrors (void);
2970 flushWarnings - switches the output channel to the error channel
2971 and then writes out all warnings.
2972 If an error is present the compilation is terminated,
2973 if warnings only were emitted then compilation will
2977 extern "C" void mcError_flushWarnings (void);
2980 errorAbort0 - aborts compiling, it flushes all warnings and errors before aborting.
2983 extern "C" void mcError_errorAbort0 (const char *a_
, unsigned int _a_high
);
2984 extern "C" mcComment_commentDesc
mcLexBuf_getProcedureComment (void);
2985 extern "C" mcComment_commentDesc
mcLexBuf_getBodyComment (void);
2986 extern "C" mcComment_commentDesc
mcLexBuf_getAfterComment (void);
2987 extern "C" bool mcLexBuf_openSource (DynamicStrings_String s
);
2988 extern "C" void mcLexBuf_closeSource (void);
2989 extern "C" void mcLexBuf_reInitialize (void);
2990 extern "C" void mcLexBuf_resetForNewPass (void);
2991 extern "C" void mcLexBuf_getToken (void);
2992 extern "C" void mcLexBuf_insertToken (mcReserved_toktype token
);
2993 extern "C" void mcLexBuf_insertTokenAndRewind (mcReserved_toktype token
);
2994 extern "C" unsigned int mcLexBuf_getPreviousTokenLineNo (void);
2995 extern "C" unsigned int mcLexBuf_getLineNo (void);
2996 extern "C" unsigned int mcLexBuf_getTokenNo (void);
2997 extern "C" unsigned int mcLexBuf_tokenToLineNo (unsigned int tokenNo
, unsigned int depth
);
2998 extern "C" unsigned int mcLexBuf_getColumnNo (void);
2999 extern "C" unsigned int mcLexBuf_tokenToColumnNo (unsigned int tokenNo
, unsigned int depth
);
3000 extern "C" DynamicStrings_String
mcLexBuf_findFileNameFromToken (unsigned int tokenNo
, unsigned int depth
);
3001 extern "C" DynamicStrings_String
mcLexBuf_getFileName (void);
3002 extern "C" void mcLexBuf_addTok (mcReserved_toktype t
);
3003 extern "C" void mcLexBuf_addTokCharStar (mcReserved_toktype t
, void * s
);
3004 extern "C" void mcLexBuf_addTokInteger (mcReserved_toktype t
, int i
);
3005 extern "C" void mcLexBuf_addTokComment (mcReserved_toktype t
, mcComment_commentDesc com
);
3006 extern "C" void mcLexBuf_setFile (void * filename
);
3007 extern "C" void mcLexBuf_pushFile (void * filename
);
3008 extern "C" void mcLexBuf_popFile (void * filename
);
3009 extern "C" void StrLib_StrConCat (const char *a_
, unsigned int _a_high
, const char *b_
, unsigned int _b_high
, char *c
, unsigned int _c_high
);
3010 extern "C" bool StrLib_StrLess (const char *a_
, unsigned int _a_high
, const char *b_
, unsigned int _b_high
);
3011 extern "C" bool StrLib_StrEqual (const char *a_
, unsigned int _a_high
, const char *b_
, unsigned int _b_high
);
3012 extern "C" unsigned int StrLib_StrLen (const char *a_
, unsigned int _a_high
);
3013 extern "C" void StrLib_StrCopy (const char *src_
, unsigned int _src_high
, char *dest
, unsigned int _dest_high
);
3014 extern "C" bool StrLib_IsSubString (const char *a_
, unsigned int _a_high
, const char *b_
, unsigned int _b_high
);
3015 extern "C" void StrLib_StrRemoveWhitePrefix (const char *a_
, unsigned int _a_high
, char *b
, unsigned int _b_high
);
3018 initPretty - initialise a pretty print data structure.
3021 extern "C" mcPretty_pretty
mcPretty_initPretty (mcPretty_writeProc w
, mcPretty_writeLnProc l
);
3024 dupPretty - duplicate a pretty print data structure.
3027 extern "C" mcPretty_pretty
mcPretty_dupPretty (mcPretty_pretty p
);
3030 killPretty - destroy a pretty print data structure.
3031 Post condition: p is assigned to NIL.
3034 extern "C" void mcPretty_killPretty (mcPretty_pretty
*p
);
3037 pushPretty - duplicate, p. Push, p, and return the duplicate.
3040 extern "C" mcPretty_pretty
mcPretty_pushPretty (mcPretty_pretty p
);
3043 popPretty - pops the pretty object from the stack.
3046 extern "C" mcPretty_pretty
mcPretty_popPretty (mcPretty_pretty p
);
3049 getindent - returns the current indent value.
3052 extern "C" unsigned int mcPretty_getindent (mcPretty_pretty p
);
3055 setindent - sets the current indent to, n.
3058 extern "C" void mcPretty_setindent (mcPretty_pretty p
, unsigned int n
);
3061 getcurpos - returns the current cursor position.
3064 extern "C" unsigned int mcPretty_getcurpos (mcPretty_pretty s
);
3067 getseekpos - returns the seek position.
3070 extern "C" unsigned int mcPretty_getseekpos (mcPretty_pretty s
);
3073 getcurline - returns the current line number.
3076 extern "C" unsigned int mcPretty_getcurline (mcPretty_pretty s
);
3077 extern "C" void mcPretty_setNeedSpace (mcPretty_pretty s
);
3080 noSpace - unset needsSpace.
3083 extern "C" void mcPretty_noSpace (mcPretty_pretty s
);
3086 print - print a string using, p.
3089 extern "C" void mcPretty_print (mcPretty_pretty p
, const char *a_
, unsigned int _a_high
);
3092 prints - print a string using, p.
3095 extern "C" void mcPretty_prints (mcPretty_pretty p
, DynamicStrings_String s
);
3098 raw - print out string, s, without any translation of
3102 extern "C" void mcPretty_raw (mcPretty_pretty p
, DynamicStrings_String s
);
3105 InitIndex - creates and returns an Index.
3108 extern "C" Indexing_Index
Indexing_InitIndex (unsigned int low
);
3111 KillIndex - returns Index to free storage.
3114 extern "C" Indexing_Index
Indexing_KillIndex (Indexing_Index i
);
3117 DebugIndex - turns on debugging within an index.
3120 extern "C" Indexing_Index
Indexing_DebugIndex (Indexing_Index i
);
3123 InBounds - returns TRUE if indice, n, is within the bounds
3124 of the dynamic array.
3127 extern "C" bool Indexing_InBounds (Indexing_Index i
, unsigned int n
);
3130 HighIndice - returns the last legally accessible indice of this array.
3133 extern "C" unsigned int Indexing_HighIndice (Indexing_Index i
);
3136 LowIndice - returns the first legally accessible indice of this array.
3139 extern "C" unsigned int Indexing_LowIndice (Indexing_Index i
);
3142 PutIndice - places, a, into the dynamic array at position i[n]
3145 extern "C" void Indexing_PutIndice (Indexing_Index i
, unsigned int n
, void * a
);
3148 GetIndice - retrieves, element i[n] from the dynamic array.
3151 extern "C" void * Indexing_GetIndice (Indexing_Index i
, unsigned int n
);
3154 IsIndiceInIndex - returns TRUE if, a, is in the index, i.
3157 extern "C" bool Indexing_IsIndiceInIndex (Indexing_Index i
, void * a
);
3160 RemoveIndiceFromIndex - removes, a, from Index, i.
3163 extern "C" void Indexing_RemoveIndiceFromIndex (Indexing_Index i
, void * a
);
3166 DeleteIndice - delete i[j] from the array.
3169 extern "C" void Indexing_DeleteIndice (Indexing_Index i
, unsigned int j
);
3172 IncludeIndiceIntoIndex - if the indice is not in the index, then
3176 extern "C" void Indexing_IncludeIndiceIntoIndex (Indexing_Index i
, void * a
);
3179 ForeachIndiceInIndexDo - for each j indice of i, call procedure p(i[j])
3182 extern "C" void Indexing_ForeachIndiceInIndexDo (Indexing_Index i
, Indexing_IndexProcedure p
);
3185 initList - creates a new alist, l.
3188 extern "C" alists_alist
alists_initList (void);
3191 killList - deletes the complete alist, l.
3194 extern "C" void alists_killList (alists_alist
*l
);
3197 putItemIntoList - places an ADDRESS, c, into alist, l.
3200 extern "C" void alists_putItemIntoList (alists_alist l
, void * c
);
3203 getItemFromList - retrieves the nth WORD from alist, l.
3206 extern "C" void * alists_getItemFromList (alists_alist l
, unsigned int n
);
3209 getIndexOfList - returns the index for WORD, c, in alist, l.
3210 If more than one WORD, c, exists the index
3211 for the first is returned.
3214 extern "C" unsigned int alists_getIndexOfList (alists_alist l
, void * c
);
3217 noOfItemsInList - returns the number of items in alist, l.
3220 extern "C" unsigned int alists_noOfItemsInList (alists_alist l
);
3223 includeItemIntoList - adds an ADDRESS, c, into a alist providing
3224 the value does not already exist.
3227 extern "C" void alists_includeItemIntoList (alists_alist l
, void * c
);
3230 removeItemFromList - removes a ADDRESS, c, from a alist.
3231 It assumes that this value only appears once.
3234 extern "C" void alists_removeItemFromList (alists_alist l
, void * c
);
3237 isItemInList - returns true if a ADDRESS, c, was found in alist, l.
3240 extern "C" bool alists_isItemInList (alists_alist l
, void * c
);
3243 foreachItemInListDo - calls procedure, P, foreach item in alist, l.
3246 extern "C" void alists_foreachItemInListDo (alists_alist l
, alists_performOperation p
);
3249 duplicateList - returns a duplicate alist derived from, l.
3252 extern "C" alists_alist
alists_duplicateList (alists_alist l
);
3255 initList - creates a new wlist, l.
3258 extern "C" wlists_wlist
wlists_initList (void);
3261 killList - deletes the complete wlist, l.
3264 extern "C" void wlists_killList (wlists_wlist
*l
);
3267 putItemIntoList - places an WORD, c, into wlist, l.
3270 extern "C" void wlists_putItemIntoList (wlists_wlist l
, unsigned int c
);
3273 getItemFromList - retrieves the nth WORD from wlist, l.
3276 extern "C" unsigned int wlists_getItemFromList (wlists_wlist l
, unsigned int n
);
3279 getIndexOfList - returns the index for WORD, c, in wlist, l.
3280 If more than one WORD, c, exists the index
3281 for the first is returned.
3284 extern "C" unsigned int wlists_getIndexOfList (wlists_wlist l
, unsigned int c
);
3287 noOfItemsInList - returns the number of items in wlist, l.
3290 extern "C" unsigned int wlists_noOfItemsInList (wlists_wlist l
);
3293 includeItemIntoList - adds an WORD, c, into a wlist providing
3294 the value does not already exist.
3297 extern "C" void wlists_includeItemIntoList (wlists_wlist l
, unsigned int c
);
3300 removeItemFromList - removes a WORD, c, from a wlist.
3301 It assumes that this value only appears once.
3304 extern "C" void wlists_removeItemFromList (wlists_wlist l
, unsigned int c
);
3307 replaceItemInList - replace the nth WORD in wlist, l.
3308 The first item in a wlists is at index, 1.
3309 If the index, n, is out of range nothing is changed.
3312 extern "C" void wlists_replaceItemInList (wlists_wlist l
, unsigned int n
, unsigned int w
);
3315 isItemInList - returns true if a WORD, c, was found in wlist, l.
3318 extern "C" bool wlists_isItemInList (wlists_wlist l
, unsigned int c
);
3321 foreachItemInListDo - calls procedure, P, foreach item in wlist, l.
3324 extern "C" void wlists_foreachItemInListDo (wlists_wlist l
, wlists_performOperation p
);
3327 duplicateList - returns a duplicate wlist derived from, l.
3330 extern "C" wlists_wlist
wlists_duplicateList (wlists_wlist l
);
3331 extern "C" void keyc_useUnistd (void);
3332 extern "C" void keyc_useThrow (void);
3333 extern "C" void keyc_useStorage (void);
3334 extern "C" void keyc_useFree (void);
3335 extern "C" void keyc_useMalloc (void);
3336 extern "C" void keyc_useProc (void);
3337 extern "C" void keyc_useTrue (void);
3338 extern "C" void keyc_useFalse (void);
3339 extern "C" void keyc_useNull (void);
3340 extern "C" void keyc_useMemcpy (void);
3341 extern "C" void keyc_useIntMin (void);
3342 extern "C" void keyc_useUIntMin (void);
3343 extern "C" void keyc_useLongMin (void);
3344 extern "C" void keyc_useULongMin (void);
3345 extern "C" void keyc_useCharMin (void);
3346 extern "C" void keyc_useUCharMin (void);
3347 extern "C" void keyc_useIntMax (void);
3348 extern "C" void keyc_useUIntMax (void);
3349 extern "C" void keyc_useLongMax (void);
3350 extern "C" void keyc_useULongMax (void);
3351 extern "C" void keyc_useCharMax (void);
3352 extern "C" void keyc_useUCharMax (void);
3353 extern "C" void keyc_useSize_t (void);
3354 extern "C" void keyc_useSSize_t (void);
3355 extern "C" void keyc_useLabs (void);
3356 extern "C" void keyc_useAbs (void);
3357 extern "C" void keyc_useFabs (void);
3358 extern "C" void keyc_useFabsl (void);
3359 extern "C" void keyc_useException (void);
3360 extern "C" void keyc_useComplex (void);
3361 extern "C" void keyc_useM2RTS (void);
3362 extern "C" void keyc_useStrlen (void);
3363 extern "C" void keyc_useCtype (void);
3364 extern "C" void keyc_genDefs (mcPretty_pretty p
);
3365 extern "C" void keyc_genConfigSystem (mcPretty_pretty p
);
3366 extern "C" void keyc_enterScope (decl_node n
);
3367 extern "C" void keyc_leaveScope (decl_node n
);
3368 extern "C" DynamicStrings_String
keyc_cname (nameKey_Name n
, bool scopes
);
3369 extern "C" nameKey_Name
keyc_cnamen (nameKey_Name n
, bool scopes
);
3370 extern "C" void keyc_cp (void);
3371 extern "C" FIO_File
mcStream_openFrag (unsigned int id
);
3372 extern "C" void mcStream_setDest (FIO_File f
);
3373 extern "C" FIO_File
mcStream_combine (void);
3374 extern "C" void mcStream_removeFiles (void);
3375 extern "C" void StrIO_WriteLn (void);
3376 extern "C" void StrIO_ReadString (char *a
, unsigned int _a_high
);
3377 extern "C" void StrIO_WriteString (const char *a_
, unsigned int _a_high
);
3378 extern "C" void NumberIO_ReadCard (unsigned int *x
);
3379 extern "C" void NumberIO_WriteCard (unsigned int x
, unsigned int n
);
3380 extern "C" void NumberIO_ReadHex (unsigned int *x
);
3381 extern "C" void NumberIO_WriteHex (unsigned int x
, unsigned int n
);
3382 extern "C" void NumberIO_ReadInt (int *x
);
3383 extern "C" void NumberIO_WriteInt (int x
, unsigned int n
);
3384 extern "C" void NumberIO_CardToStr (unsigned int x
, unsigned int n
, char *a
, unsigned int _a_high
);
3385 extern "C" void NumberIO_StrToCard (const char *a_
, unsigned int _a_high
, unsigned int *x
);
3386 extern "C" void NumberIO_HexToStr (unsigned int x
, unsigned int n
, char *a
, unsigned int _a_high
);
3387 extern "C" void NumberIO_StrToHex (const char *a_
, unsigned int _a_high
, unsigned int *x
);
3388 extern "C" void NumberIO_IntToStr (int x
, unsigned int n
, char *a
, unsigned int _a_high
);
3389 extern "C" void NumberIO_StrToInt (const char *a_
, unsigned int _a_high
, int *x
);
3390 extern "C" void NumberIO_ReadOct (unsigned int *x
);
3391 extern "C" void NumberIO_WriteOct (unsigned int x
, unsigned int n
);
3392 extern "C" void NumberIO_OctToStr (unsigned int x
, unsigned int n
, char *a
, unsigned int _a_high
);
3393 extern "C" void NumberIO_StrToOct (const char *a_
, unsigned int _a_high
, unsigned int *x
);
3394 extern "C" void NumberIO_ReadBin (unsigned int *x
);
3395 extern "C" void NumberIO_WriteBin (unsigned int x
, unsigned int n
);
3396 extern "C" void NumberIO_BinToStr (unsigned int x
, unsigned int n
, char *a
, unsigned int _a_high
);
3397 extern "C" void NumberIO_StrToBin (const char *a_
, unsigned int _a_high
, unsigned int *x
);
3398 extern "C" void NumberIO_StrToBinInt (const char *a_
, unsigned int _a_high
, int *x
);
3399 extern "C" void NumberIO_StrToHexInt (const char *a_
, unsigned int _a_high
, int *x
);
3400 extern "C" void NumberIO_StrToOctInt (const char *a_
, unsigned int _a_high
, int *x
);
3401 extern "C" void Debug_Halt (const char *Message_
, unsigned int _Message_high
, const char *Module_
, unsigned int _Module_high
, const char *Function_
, unsigned int _Function_high
, unsigned int LineNo
);
3402 extern "C" void Debug_DebugString (const char *a_
, unsigned int _a_high
);
3403 extern "C" void Assertion_Assert (bool Condition
);
3404 extern "C" void StdIO_Read (char *ch
);
3405 extern "C" void StdIO_Write (char ch
);
3406 extern "C" void StdIO_PushOutput (StdIO_ProcWrite p
);
3407 extern "C" void StdIO_PopOutput (void);
3408 extern "C" StdIO_ProcWrite
StdIO_GetCurrentOutput (void);
3409 extern "C" void StdIO_PushInput (StdIO_ProcRead p
);
3410 extern "C" void StdIO_PopInput (void);
3411 extern "C" StdIO_ProcRead
StdIO_GetCurrentInput (void);
3412 extern "C" void mcPrintf_printf0 (const char *a_
, unsigned int _a_high
);
3413 extern "C" void mcPrintf_printf1 (const char *a_
, unsigned int _a_high
, const unsigned char *w_
, unsigned int _w_high
);
3414 extern "C" void mcPrintf_printf2 (const char *a_
, unsigned int _a_high
, const unsigned char *w1_
, unsigned int _w1_high
, const unsigned char *w2_
, unsigned int _w2_high
);
3415 extern "C" void mcPrintf_printf3 (const char *a_
, unsigned int _a_high
, const unsigned char *w1_
, unsigned int _w1_high
, const unsigned char *w2_
, unsigned int _w2_high
, const unsigned char *w3_
, unsigned int _w3_high
);
3416 extern "C" void mcPrintf_printf4 (const char *a_
, unsigned int _a_high
, const unsigned char *w1_
, unsigned int _w1_high
, const unsigned char *w2_
, unsigned int _w2_high
, const unsigned char *w3_
, unsigned int _w3_high
, const unsigned char *w4_
, unsigned int _w4_high
);
3417 extern "C" void mcPrintf_fprintf0 (FIO_File file
, const char *a_
, unsigned int _a_high
);
3418 extern "C" void mcPrintf_fprintf1 (FIO_File file
, const char *a_
, unsigned int _a_high
, const unsigned char *w_
, unsigned int _w_high
);
3419 extern "C" void mcPrintf_fprintf2 (FIO_File file
, const char *a_
, unsigned int _a_high
, const unsigned char *w1_
, unsigned int _w1_high
, const unsigned char *w2_
, unsigned int _w2_high
);
3420 extern "C" void mcPrintf_fprintf3 (FIO_File file
, const char *a_
, unsigned int _a_high
, const unsigned char *w1_
, unsigned int _w1_high
, const unsigned char *w2_
, unsigned int _w2_high
, const unsigned char *w3_
, unsigned int _w3_high
);
3421 extern "C" void mcPrintf_fprintf4 (FIO_File file
, const char *a_
, unsigned int _a_high
, const unsigned char *w1_
, unsigned int _w1_high
, const unsigned char *w2_
, unsigned int _w2_high
, const unsigned char *w3_
, unsigned int _w3_high
, const unsigned char *w4_
, unsigned int _w4_high
);
3424 newNode - create and return a new node of kind k.
3427 static decl_node
newNode (decl_nodeT k
);
3430 disposeNode - dispose node, n.
3433 static void disposeNode (decl_node
*n
);
3436 isLocal - returns TRUE if symbol, n, is locally declared in a procedure.
3439 static bool isLocal (decl_node n
);
3442 importEnumFields - if, n, is an enumeration type import the all fields into module, m.
3445 static void importEnumFields (decl_node m
, decl_node n
);
3448 isComplex - returns TRUE if, n, is the complex type.
3451 static bool isComplex (decl_node n
);
3454 isLongComplex - returns TRUE if, n, is the longcomplex type.
3457 static bool isLongComplex (decl_node n
);
3460 isShortComplex - returns TRUE if, n, is the shortcomplex type.
3463 static bool isShortComplex (decl_node n
);
3466 isAProcType - returns TRUE if, n, is a proctype or proc node.
3469 static bool isAProcType (decl_node n
);
3472 initFixupInfo - initialize the fixupInfo record.
3475 static decl_fixupInfo
initFixupInfo (void);
3478 makeDef - returns a definition module node named, n.
3481 static decl_node
makeDef (nameKey_Name n
);
3484 makeImp - returns an implementation module node named, n.
3487 static decl_node
makeImp (nameKey_Name n
);
3490 makeModule - returns a module node named, n.
3493 static decl_node
makeModule (nameKey_Name n
);
3496 isDefForC - returns TRUE if the definition module was defined FOR "C".
3499 static bool isDefForC (decl_node n
);
3502 initDecls - initialize the decls, scopeT.
3505 static void initDecls (decl_scopeT
*decls
);
3508 addTo - adds node, d, to scope decls and returns, d.
3509 It stores, d, in the symbols tree associated with decls.
3512 static decl_node
addTo (decl_scopeT
*decls
, decl_node d
);
3515 export - export node, n, from definition module, d.
3518 static void export_ (decl_node d
, decl_node n
);
3521 addToScope - adds node, n, to the current scope and returns, n.
3524 static decl_node
addToScope (decl_node n
);
3527 addModuleToScope - adds module, i, to module, m, scope.
3530 static void addModuleToScope (decl_node m
, decl_node i
);
3533 completedEnum - assign boolean enumsComplete to TRUE if a definition,
3534 implementation or module symbol.
3537 static void completedEnum (decl_node n
);
3540 setUnary - sets a unary node to contain, arg, a, and type, t.
3543 static void setUnary (decl_node u
, decl_nodeT k
, decl_node a
, decl_node t
);
3546 putVarBool - assigns the four booleans associated with a variable.
3549 static void putVarBool (decl_node v
, bool init
, bool param
, bool isvar
, bool isused
);
3552 checkPtr - in C++ we need to create a typedef for a pointer
3553 in case we need to use reinterpret_cast.
3556 static decl_node
checkPtr (decl_node n
);
3559 isVarDecl - returns TRUE if, n, is a vardecl node.
3562 static bool isVarDecl (decl_node n
);
3565 makeVariablesFromParameters - creates variables which are really parameters.
3568 static void makeVariablesFromParameters (decl_node proc
, decl_node id
, decl_node type
, bool isvar
, bool isused
);
3571 addProcedureToScope - add a procedure name n and node d to the
3575 static decl_node
addProcedureToScope (decl_node d
, nameKey_Name n
);
3578 putProcTypeReturn - sets the return type of, proc, to, type.
3581 static void putProcTypeReturn (decl_node proc
, decl_node type
);
3584 putProcTypeOptReturn - sets, proc, to have an optional return type.
3587 static void putProcTypeOptReturn (decl_node proc
);
3590 makeOptParameter - creates and returns an optarg.
3593 static decl_node
makeOptParameter (decl_node l
, decl_node type
, decl_node init
);
3596 setwatch - assign the globalNode to n.
3599 static bool setwatch (decl_node n
);
3602 runwatch - set the globalNode to an identlist.
3605 static bool runwatch (void);
3608 isIdentList - returns TRUE if, n, is an identlist.
3611 static bool isIdentList (decl_node n
);
3614 identListLen - returns the length of identlist.
3617 static unsigned int identListLen (decl_node n
);
3620 checkParameters - placeholder for future parameter checking.
3623 static void checkParameters (decl_node p
, decl_node i
, decl_node type
, bool isvar
, bool isused
);
3626 checkMakeVariables - create shadow local variables for parameters providing that
3627 procedure n has not already been built and we are compiling
3628 a module or an implementation module.
3631 static void checkMakeVariables (decl_node n
, decl_node i
, decl_node type
, bool isvar
, bool isused
);
3634 makeVarientField - create a varient field within varient, v,
3635 The new varient field is returned.
3638 static decl_node
makeVarientField (decl_node v
, decl_node p
);
3641 putFieldVarient - places the field varient, f, as a brother to, the
3642 varient symbol, v, and also tells, f, that its varient
3646 static void putFieldVarient (decl_node f
, decl_node v
);
3649 putFieldRecord - create a new recordfield and place it into record r.
3650 The new field has a tagname and type and can have a
3654 static decl_node
putFieldRecord (decl_node r
, nameKey_Name tag
, decl_node type
, decl_node v
);
3657 ensureOrder - ensures that, a, and, b, exist in, i, and also
3658 ensure that, a, is before, b.
3661 static void ensureOrder (Indexing_Index i
, decl_node a
, decl_node b
);
3664 putVarientTag - places tag into variant v.
3667 static void putVarientTag (decl_node v
, decl_node tag
);
3670 getParent - returns the parent field of recordfield or varientfield symbol, n.
3673 static decl_node
getParent (decl_node n
);
3676 getRecord - returns the record associated with node, n.
3680 static decl_node
getRecord (decl_node n
);
3683 isConstExp - return TRUE if the node kind is a constexp.
3686 static bool isConstExp (decl_node c
);
3689 addEnumToModule - adds enumeration type, e, into the list of enums
3693 static void addEnumToModule (decl_node m
, decl_node e
);
3696 getNextFixup - return the next fixup from from f.
3699 static decl_node
getNextFixup (decl_fixupInfo
*f
);
3702 doMakeEnum - create an enumeration type and add it to the current module.
3705 static decl_node
doMakeEnum (void);
3708 doMakeEnumField - create an enumeration field name and add it to enumeration e.
3709 Return the new field.
3712 static decl_node
doMakeEnumField (decl_node e
, nameKey_Name n
);
3715 getExpList - returns the, n, th argument in an explist.
3718 static decl_node
getExpList (decl_node p
, unsigned int n
);
3721 expListLen - returns the length of explist, p.
3724 static unsigned int expListLen (decl_node p
);
3727 getConstExpComplete - gets the field from the def or imp or module, n.
3730 static bool getConstExpComplete (decl_node n
);
3733 addConstToModule - adds const exp, e, into the list of constant
3734 expressions in module, m.
3737 static void addConstToModule (decl_node m
, decl_node e
);
3740 doMakeConstExp - create a constexp node and add it to the current module.
3743 static decl_node
doMakeConstExp (void);
3746 isAnyType - return TRUE if node n is any type kind.
3749 static bool isAnyType (decl_node n
);
3752 makeVal - creates a VAL (type, expression) node.
3755 static decl_node
makeVal (decl_node params
);
3758 makeCast - creates a cast node TYPENAME (expr).
3761 static decl_node
makeCast (decl_node c
, decl_node p
);
3762 static decl_node
makeIntrinsicProc (decl_nodeT k
, unsigned int noArgs
, decl_node p
);
3765 makeIntrinsicUnaryType - create an intrisic unary type.
3768 static decl_node
makeIntrinsicUnaryType (decl_nodeT k
, decl_node paramList
, decl_node returnType
);
3771 makeIntrinsicBinaryType - create an intrisic binary type.
3774 static decl_node
makeIntrinsicBinaryType (decl_nodeT k
, decl_node paramList
, decl_node returnType
);
3777 checkIntrinsic - checks to see if the function call to, c, with
3778 parameter list, n, is really an intrinic. If it
3779 is an intrinic then an intrinic node is created
3780 and returned. Otherwise NIL is returned.
3783 static decl_node
checkIntrinsic (decl_node c
, decl_node n
);
3786 checkCHeaders - check to see if the function is a C system function and
3787 requires a header file included.
3790 static void checkCHeaders (decl_node c
);
3793 isFuncCall - returns TRUE if, n, is a function/procedure call.
3796 static bool isFuncCall (decl_node n
);
3799 putTypeInternal - marks type, des, as being an internally generated type.
3802 static void putTypeInternal (decl_node des
);
3805 isTypeInternal - returns TRUE if type, n, is internal.
3808 static bool isTypeInternal (decl_node n
);
3811 lookupBase - return node named n from the base symbol scope.
3814 static decl_node
lookupBase (nameKey_Name n
);
3817 dumpScopes - display the names of all the scopes stacked.
3820 static void dumpScopes (void);
3823 out0 - write string a to StdOut.
3826 static void out0 (const char *a_
, unsigned int _a_high
);
3829 out1 - write string a to StdOut using format specifier a.
3832 static void out1 (const char *a_
, unsigned int _a_high
, decl_node s
);
3835 out2 - write string a to StdOut using format specifier a.
3838 static void out2 (const char *a_
, unsigned int _a_high
, unsigned int c
, decl_node s
);
3841 out3 - write string a to StdOut using format specifier a.
3844 static void out3 (const char *a_
, unsigned int _a_high
, unsigned int l
, nameKey_Name n
, decl_node s
);
3847 isUnary - returns TRUE if, n, is an unary node.
3850 static bool isUnary (decl_node n
);
3853 isBinary - returns TRUE if, n, is an binary node.
3856 static bool isBinary (decl_node n
);
3859 makeUnary - create a unary expression node with, e, as the argument
3860 and res as the return type.
3863 static decl_node
makeUnary (decl_nodeT k
, decl_node e
, decl_node res
);
3866 isLeafString - returns TRUE if n is a leaf node which is a string constant.
3869 static bool isLeafString (decl_node n
);
3872 getLiteralStringContents - return the contents of a literal node as a string.
3875 static DynamicStrings_String
getLiteralStringContents (decl_node n
);
3878 getStringContents - return the string contents of a constant, literal,
3879 string or a constexp node.
3882 static DynamicStrings_String
getStringContents (decl_node n
);
3888 static nameKey_Name
addNames (decl_node a
, decl_node b
);
3894 static decl_node
resolveString (decl_node n
);
3900 static decl_node
foldBinary (decl_nodeT k
, decl_node l
, decl_node r
, decl_node res
);
3903 makeBinary - create a binary node with left/right/result type: l, r and resultType.
3906 static decl_node
makeBinary (decl_nodeT k
, decl_node l
, decl_node r
, decl_node resultType
);
3909 doMakeBinary - returns a binary node containing left/right/result values
3910 l, r, res, with a node operator, k.
3913 static decl_node
doMakeBinary (decl_nodeT k
, decl_node l
, decl_node r
, decl_node res
);
3916 doMakeComponentRef -
3919 static decl_node
doMakeComponentRef (decl_node rec
, decl_node field
);
3925 static bool isComponentRef (decl_node n
);
3928 isArrayRef - returns TRUE if the node was an arrayref.
3931 static bool isArrayRef (decl_node n
);
3934 isDeref - returns TRUE if, n, is a deref node.
3937 static bool isDeref (decl_node n
);
3940 makeBase - create a base type or constant.
3941 It only supports the base types and constants
3945 static decl_node
makeBase (decl_nodeT k
);
3948 isOrdinal - returns TRUE if, n, is an ordinal type.
3951 static bool isOrdinal (decl_node n
);
3957 static decl_node
mixTypes (decl_node a
, decl_node b
);
3963 static decl_node
doSetExprType (decl_node
*t
, decl_node n
);
3969 static decl_node
getMaxMinType (decl_node n
);
3975 static decl_node
doGetFuncType (decl_node n
);
3978 doGetExprType - works out the type which is associated with node, n.
3981 static decl_node
doGetExprType (decl_node n
);
3984 getExprType - return the expression type.
3987 static decl_node
getExprType (decl_node n
);
3993 static void openOutput (void);
3999 static void closeOutput (void);
4002 write - outputs a single char, ch.
4005 static void write_ (char ch
);
4011 static void writeln (void);
4014 doIncludeC - include header file for definition module, n.
4017 static void doIncludeC (decl_node n
);
4020 getSymScope - returns the scope where node, n, was declared.
4023 static decl_node
getSymScope (decl_node n
);
4026 isQualifiedForced - should the node be written with a module prefix?
4029 static bool isQualifiedForced (decl_node n
);
4035 static DynamicStrings_String
getFQstring (decl_node n
);
4041 static DynamicStrings_String
getFQDstring (decl_node n
, bool scopes
);
4044 getString - returns the name as a string.
4047 static DynamicStrings_String
getString (decl_node n
);
4053 static void doNone (decl_node n
);
4056 doNothing - does nothing!
4059 static void doNothing (decl_node n
);
4065 static void doConstC (decl_node n
);
4068 needsParen - returns TRUE if expression, n, needs to be enclosed in ().
4071 static bool needsParen (decl_node n
);
4077 static void doUnary (mcPretty_pretty p
, const char *op_
, unsigned int _op_high
, decl_node expr
, decl_node type
, bool l
, bool r
);
4080 doSetSub - perform l & (~ r)
4083 static void doSetSub (mcPretty_pretty p
, decl_node left
, decl_node right
);
4089 static void doPolyBinary (mcPretty_pretty p
, decl_nodeT op
, decl_node left
, decl_node right
, bool l
, bool r
);
4095 static void doBinary (mcPretty_pretty p
, const char *op_
, unsigned int _op_high
, decl_node left
, decl_node right
, bool l
, bool r
, bool unpackProc
);
4101 static void doPostUnary (mcPretty_pretty p
, const char *op_
, unsigned int _op_high
, decl_node expr
);
4107 static void doDeRefC (mcPretty_pretty p
, decl_node expr
);
4110 doGetLastOp - returns, a, if b is a terminal otherwise walk right.
4113 static decl_node
doGetLastOp (decl_node a
, decl_node b
);
4119 static void doComponentRefC (mcPretty_pretty p
, decl_node l
, decl_node r
);
4125 static void doPointerRefC (mcPretty_pretty p
, decl_node l
, decl_node r
);
4131 static void doPreBinary (mcPretty_pretty p
, const char *op_
, unsigned int _op_high
, decl_node left
, decl_node right
, bool l
, bool r
);
4137 static void doConstExpr (mcPretty_pretty p
, decl_node n
);
4140 doEnumerationField -
4143 static void doEnumerationField (mcPretty_pretty p
, decl_node n
);
4146 isZero - returns TRUE if node, n, is zero.
4149 static bool isZero (decl_node n
);
4155 static void doArrayRef (mcPretty_pretty p
, decl_node n
);
4161 static void doProcedure (mcPretty_pretty p
, decl_node n
);
4167 static void doRecordfield (mcPretty_pretty p
, decl_node n
);
4173 static void doCastC (mcPretty_pretty p
, decl_node t
, decl_node e
);
4179 static void doSetValueC (mcPretty_pretty p
, decl_node n
);
4182 getSetLow - returns the low value of the set type from
4186 static decl_node
getSetLow (decl_node n
);
4189 doInC - performs (((1 << (l)) & (r)) != 0)
4192 static void doInC (mcPretty_pretty p
, decl_node l
, decl_node r
);
4198 static void doThrowC (mcPretty_pretty p
, decl_node n
);
4204 static void doUnreachableC (mcPretty_pretty p
, decl_node n
);
4210 static void outNull (mcPretty_pretty p
);
4216 static void outTrue (mcPretty_pretty p
);
4222 static void outFalse (mcPretty_pretty p
);
4228 static void doExprC (mcPretty_pretty p
, decl_node n
);
4234 static void doExprCup (mcPretty_pretty p
, decl_node n
, bool unpackProc
);
4240 static void doExprM2 (mcPretty_pretty p
, decl_node n
);
4246 static void doVar (mcPretty_pretty p
, decl_node n
);
4252 static void doLiteralC (mcPretty_pretty p
, decl_node n
);
4258 static void doLiteral (mcPretty_pretty p
, decl_node n
);
4261 isString - returns TRUE if node, n, is a string.
4264 static bool isString (decl_node n
);
4270 static void doString (mcPretty_pretty p
, decl_node n
);
4273 replaceChar - replace every occurance of, ch, by, a and return modified string, s.
4276 static DynamicStrings_String
replaceChar (DynamicStrings_String s
, char ch
, const char *a_
, unsigned int _a_high
);
4279 toCstring - translates string, n, into a C string
4280 and returns the new String.
4283 static DynamicStrings_String
toCstring (nameKey_Name n
);
4289 static DynamicStrings_String
toCchar (nameKey_Name n
);
4295 static unsigned int countChar (DynamicStrings_String s
, char ch
);
4301 static unsigned int lenCstring (DynamicStrings_String s
);
4307 static void outCstring (mcPretty_pretty p
, decl_node s
, bool aString
);
4313 static void doStringC (mcPretty_pretty p
, decl_node n
);
4319 static bool isPunct (char ch
);
4325 static bool isWhite (char ch
);
4331 static void outText (mcPretty_pretty p
, const char *a_
, unsigned int _a_high
);
4337 static void outRawS (mcPretty_pretty p
, DynamicStrings_String s
);
4343 static mcPretty_pretty
outKm2 (mcPretty_pretty p
, const char *a_
, unsigned int _a_high
);
4349 static mcPretty_pretty
outKc (mcPretty_pretty p
, const char *a_
, unsigned int _a_high
);
4355 static void outTextS (mcPretty_pretty p
, DynamicStrings_String s
);
4361 static void outCard (mcPretty_pretty p
, unsigned int c
);
4367 static void outTextN (mcPretty_pretty p
, nameKey_Name n
);
4373 static void doTypeAliasC (mcPretty_pretty p
, decl_node n
, decl_node
*m
);
4379 static void doEnumerationC (mcPretty_pretty p
, decl_node n
);
4385 static void doNamesC (mcPretty_pretty p
, nameKey_Name n
);
4391 static void doNameC (mcPretty_pretty p
, decl_node n
);
4397 static void initCname (decl_cnameT
*c
);
4403 static nameKey_Name
doCname (nameKey_Name n
, decl_cnameT
*c
, bool scopes
);
4409 static nameKey_Name
getDName (decl_node n
, bool scopes
);
4415 static void doDNameC (mcPretty_pretty p
, decl_node n
, bool scopes
);
4421 static void doFQDNameC (mcPretty_pretty p
, decl_node n
, bool scopes
);
4427 static void doFQNameC (mcPretty_pretty p
, decl_node n
);
4433 static void doNameM2 (mcPretty_pretty p
, decl_node n
);
4439 static void doUsed (mcPretty_pretty p
, bool used
);
4445 static void doHighC (mcPretty_pretty p
, decl_node a
, nameKey_Name n
, bool isused
);
4451 static void doParamConstCast (mcPretty_pretty p
, decl_node n
);
4454 getParameterVariable - returns the variable which shadows the parameter
4455 named, m, in parameter block, n.
4458 static decl_node
getParameterVariable (decl_node n
, nameKey_Name m
);
4461 doParamTypeEmit - emit parameter type for C/C++. It checks to see if the
4462 parameter type is a procedure type and if it were declared
4463 in a definition module for "C" and if so it uses the "C"
4464 definition for a procedure type, rather than the mc
4468 static void doParamTypeEmit (mcPretty_pretty p
, decl_node paramnode
, decl_node paramtype
);
4471 doParamC - emit parameter for C/C++.
4474 static void doParamC (mcPretty_pretty p
, decl_node n
);
4477 doVarParamC - emit a VAR parameter for C/C++.
4480 static void doVarParamC (mcPretty_pretty p
, decl_node n
);
4486 static void doOptargC (mcPretty_pretty p
, decl_node n
);
4492 static void doParameterC (mcPretty_pretty p
, decl_node n
);
4498 static void doProcTypeC (mcPretty_pretty p
, decl_node t
, decl_node n
);
4504 static void doTypesC (decl_node n
);
4507 doCompletePartialC -
4510 static void doCompletePartialC (decl_node n
);
4513 doCompletePartialRecord -
4516 static void doCompletePartialRecord (mcPretty_pretty p
, decl_node t
, decl_node r
);
4519 doCompletePartialArray -
4522 static void doCompletePartialArray (mcPretty_pretty p
, decl_node t
, decl_node r
);
4528 static decl_node
lookupConst (decl_node type
, nameKey_Name n
);
4534 static decl_node
doMin (decl_node n
);
4540 static decl_node
doMax (decl_node n
);
4546 static decl_node
getMax (decl_node n
);
4552 static decl_node
getMin (decl_node n
);
4558 static void doSubtractC (mcPretty_pretty p
, decl_node s
);
4564 static void doSubrC (mcPretty_pretty p
, decl_node s
);
4567 doCompletePartialProcType -
4570 static void doCompletePartialProcType (mcPretty_pretty p
, decl_node t
, decl_node n
);
4576 static bool isBase (decl_node n
);
4582 static void doBoolC (mcPretty_pretty p
);
4588 static void doBaseC (mcPretty_pretty p
, decl_node n
);
4594 static bool isSystem (decl_node n
);
4600 static void doSystemC (mcPretty_pretty p
, decl_node n
);
4606 static void doArrayC (mcPretty_pretty p
, decl_node n
);
4612 static void doPointerC (mcPretty_pretty p
, decl_node n
, decl_node
*m
);
4618 static void doRecordFieldC (mcPretty_pretty p
, decl_node f
);
4624 static void doVarientFieldC (mcPretty_pretty p
, decl_node n
);
4630 static void doVarientC (mcPretty_pretty p
, decl_node n
);
4636 static void doRecordC (mcPretty_pretty p
, decl_node n
, decl_node
*m
);
4642 static bool isBitset (decl_node n
);
4645 isNegative - returns TRUE if expression, n, is negative.
4648 static bool isNegative (decl_node n
);
4654 static void doSubrangeC (mcPretty_pretty p
, decl_node n
);
4657 doSetC - generates a C type which holds the set.
4658 Currently we only support sets of size WORD.
4661 static void doSetC (mcPretty_pretty p
, decl_node n
);
4667 static void doTypeC (mcPretty_pretty p
, decl_node n
, decl_node
*m
);
4670 doArrayNameC - it displays the array declaration (it might be an unbounded).
4673 static void doArrayNameC (mcPretty_pretty p
, decl_node n
);
4676 doRecordNameC - emit the C/C++ record name <name of n>"_r".
4679 static void doRecordNameC (mcPretty_pretty p
, decl_node n
);
4682 doPointerNameC - emit the C/C++ pointer type <name of n>*.
4685 static void doPointerNameC (mcPretty_pretty p
, decl_node n
);
4691 static void doTypeNameC (mcPretty_pretty p
, decl_node n
);
4694 isExternal - returns TRUE if symbol, n, was declared in another module.
4697 static bool isExternal (decl_node n
);
4703 static void doVarC (decl_node n
);
4709 static void doExternCP (mcPretty_pretty p
);
4712 doProcedureCommentText -
4715 static void doProcedureCommentText (mcPretty_pretty p
, DynamicStrings_String s
);
4718 doProcedureComment -
4721 static void doProcedureComment (mcPretty_pretty p
, DynamicStrings_String s
);
4724 doProcedureHeadingC -
4727 static void doProcedureHeadingC (decl_node n
, bool prototype
);
4730 checkDeclareUnboundedParamCopyC -
4733 static bool checkDeclareUnboundedParamCopyC (mcPretty_pretty p
, decl_node n
);
4736 checkUnboundedParamCopyC -
4739 static void checkUnboundedParamCopyC (mcPretty_pretty p
, decl_node n
);
4742 doUnboundedParamCopyC -
4745 static void doUnboundedParamCopyC (mcPretty_pretty p
, decl_node n
);
4751 static void doPrototypeC (decl_node n
);
4754 addTodo - adds, n, to the todo list.
4757 static void addTodo (decl_node n
);
4763 static void addVariablesTodo (decl_node n
);
4769 static void addTypesTodo (decl_node n
);
4775 static DynamicStrings_String
tempName (void);
4778 makeIntermediateType -
4781 static decl_node
makeIntermediateType (DynamicStrings_String s
, decl_node p
);
4787 static void simplifyType (alists_alist l
, decl_node
*p
);
4793 static void simplifyVar (alists_alist l
, decl_node n
);
4799 static void simplifyRecord (alists_alist l
, decl_node n
);
4805 static void simplifyVarient (alists_alist l
, decl_node n
);
4808 simplifyVarientField -
4811 static void simplifyVarientField (alists_alist l
, decl_node n
);
4817 static void doSimplifyNode (alists_alist l
, decl_node n
);
4823 static void simplifyNode (alists_alist l
, decl_node n
);
4829 static void doSimplify (decl_node n
);
4835 static void simplifyTypes (decl_scopeT s
);
4841 static void outDeclsDefC (mcPretty_pretty p
, decl_node n
);
4847 static void includeConstType (decl_scopeT s
);
4850 includeVarProcedure -
4853 static void includeVarProcedure (decl_scopeT s
);
4859 static void includeVar (decl_scopeT s
);
4865 static void includeExternals (decl_node n
);
4868 checkSystemInclude -
4871 static void checkSystemInclude (decl_node n
);
4877 static void addExported (decl_node n
);
4880 addExternal - only adds, n, if this symbol is external to the
4881 implementation module and is not a hidden type.
4884 static void addExternal (decl_node n
);
4887 includeDefConstType -
4890 static void includeDefConstType (decl_node n
);
4893 runIncludeDefConstType -
4896 static void runIncludeDefConstType (decl_node n
);
4899 joinProcedures - copies procedures from definition module,
4900 d, into implementation module, i.
4903 static void joinProcedures (decl_node i
, decl_node d
);
4906 includeDefVarProcedure -
4909 static void includeDefVarProcedure (decl_node n
);
4915 static void foreachModuleDo (decl_node n
, symbolKey_performOperation p
);
4921 static void outDeclsImpC (mcPretty_pretty p
, decl_scopeT s
);
4924 doStatementSequenceC -
4927 static void doStatementSequenceC (mcPretty_pretty p
, decl_node s
);
4930 isStatementSequenceEmpty -
4933 static bool isStatementSequenceEmpty (decl_node s
);
4936 isSingleStatement - returns TRUE if the statement sequence, s, has
4940 static bool isSingleStatement (decl_node s
);
4946 static void doCommentC (mcPretty_pretty p
, decl_node s
);
4949 doAfterCommentC - emit an after comment, c, or a newline if, c, is empty.
4952 static void doAfterCommentC (mcPretty_pretty p
, decl_node c
);
4955 doReturnC - issue a return statement and also place in an after comment if one exists.
4958 static void doReturnC (mcPretty_pretty p
, decl_node s
);
4964 static bool isZtypeEquivalent (decl_node type
);
4967 isEquivalentType - returns TRUE if type1 and type2 are equivalent.
4970 static bool isEquivalentType (decl_node type1
, decl_node type2
);
4973 doExprCastC - build a cast if necessary.
4976 static void doExprCastC (mcPretty_pretty p
, decl_node e
, decl_node type
);
4979 requiresUnpackProc - returns TRUE if either the expr is a procedure or the proctypes differ.
4982 static bool requiresUnpackProc (decl_node s
);
4988 static void doAssignmentC (mcPretty_pretty p
, decl_node s
);
4994 static bool containsStatement (decl_node s
);
5000 static void doCompoundStmt (mcPretty_pretty p
, decl_node s
);
5006 static void doElsifC (mcPretty_pretty p
, decl_node s
);
5012 static bool noIfElse (decl_node n
);
5015 noIfElseChained - returns TRUE if, n, is an IF statement which
5016 has no associated ELSE statement. An IF with an
5017 ELSIF is also checked for no ELSE and will result
5018 in a return value of TRUE.
5021 static bool noIfElseChained (decl_node n
);
5027 static bool hasIfElse (decl_node n
);
5033 static bool isIfElse (decl_node n
);
5036 hasIfAndNoElse - returns TRUE if statement, n, is a single statement
5037 which is an IF and it has no else statement.
5040 static bool hasIfAndNoElse (decl_node n
);
5043 doIfC - issue an if statement and also place in an after comment if one exists.
5044 The if statement might contain an else or elsif which are also handled.
5047 static void doIfC (mcPretty_pretty p
, decl_node s
);
5053 static void doForIncCP (mcPretty_pretty p
, decl_node s
);
5059 static void doForIncC (mcPretty_pretty p
, decl_node s
);
5065 static void doForInc (mcPretty_pretty p
, decl_node s
);
5071 static void doForC (mcPretty_pretty p
, decl_node s
);
5077 static void doRepeatC (mcPretty_pretty p
, decl_node s
);
5083 static void doWhileC (mcPretty_pretty p
, decl_node s
);
5089 static void doFuncHighC (mcPretty_pretty p
, decl_node a
);
5095 static void doMultiplyBySize (mcPretty_pretty p
, decl_node a
);
5101 static void doTotype (mcPretty_pretty p
, decl_node a
, decl_node t
);
5107 static void doFuncUnbounded (mcPretty_pretty p
, decl_node actual
, decl_node formalParam
, decl_node formal
, decl_node func
);
5113 static void doProcedureParamC (mcPretty_pretty p
, decl_node actual
, decl_node formal
);
5119 static void doAdrExprC (mcPretty_pretty p
, decl_node n
);
5125 static bool typePair (decl_node a
, decl_node b
, decl_node x
, decl_node y
);
5128 needsCast - return TRUE if the actual type parameter needs to be cast to
5132 static bool needsCast (decl_node at
, decl_node ft
);
5135 checkSystemCast - checks to see if we are passing to/from
5136 a system generic type (WORD, BYTE, ADDRESS)
5137 and if so emit a cast. It returns the number of
5141 static unsigned int checkSystemCast (mcPretty_pretty p
, decl_node actual
, decl_node formal
);
5147 static void emitN (mcPretty_pretty p
, const char *a_
, unsigned int _a_high
, unsigned int n
);
5150 isForC - return true if node n is a varparam, param or procedure
5151 which was declared inside a definition module for "C".
5154 static bool isForC (decl_node n
);
5157 isDefForCNode - return TRUE if node n was declared inside a definition module for "C".
5160 static bool isDefForCNode (decl_node n
);
5166 static void doFuncParamC (mcPretty_pretty p
, decl_node actual
, decl_node formal
, decl_node func
);
5169 getNthParamType - return the type of parameter, i, in list, l.
5170 If the parameter is a vararg NIL is returned.
5173 static decl_node
getNthParamType (Indexing_Index l
, unsigned int i
);
5176 getNthParam - return the parameter, i, in list, l.
5177 If the parameter is a vararg NIL is returned.
5180 static decl_node
getNthParam (Indexing_Index l
, unsigned int i
);
5186 static void doFuncArgsC (mcPretty_pretty p
, decl_node s
, Indexing_Index l
, bool needParen
);
5192 static void doProcTypeArgsC (mcPretty_pretty p
, decl_node s
, Indexing_Index args
, bool needParen
);
5198 static void doAdrArgC (mcPretty_pretty p
, decl_node n
);
5204 static void doAdrC (mcPretty_pretty p
, decl_node n
);
5210 static void doInc (mcPretty_pretty p
, decl_node n
);
5216 static void doDec (mcPretty_pretty p
, decl_node n
);
5222 static void doIncDecC (mcPretty_pretty p
, decl_node n
, const char *op_
, unsigned int _op_high
);
5228 static void doIncDecCP (mcPretty_pretty p
, decl_node n
, const char *op_
, unsigned int _op_high
);
5234 static void doInclC (mcPretty_pretty p
, decl_node n
);
5240 static void doExclC (mcPretty_pretty p
, decl_node n
);
5246 static void doNewC (mcPretty_pretty p
, decl_node n
);
5252 static void doDisposeC (mcPretty_pretty p
, decl_node n
);
5258 static void doCapC (mcPretty_pretty p
, decl_node n
);
5264 static void doLengthC (mcPretty_pretty p
, decl_node n
);
5270 static void doAbsC (mcPretty_pretty p
, decl_node n
);
5276 static void doValC (mcPretty_pretty p
, decl_node n
);
5282 static void doMinC (mcPretty_pretty p
, decl_node n
);
5288 static void doMaxC (mcPretty_pretty p
, decl_node n
);
5291 isIntrinsic - returns if, n, is an intrinsic procedure.
5292 The intrinsic functions are represented as unary and binary nodes.
5295 static bool isIntrinsic (decl_node n
);
5301 static void doHalt (mcPretty_pretty p
, decl_node n
);
5304 doCreal - emit the appropriate creal function.
5307 static void doCreal (mcPretty_pretty p
, decl_node t
);
5310 doCimag - emit the appropriate cimag function.
5313 static void doCimag (mcPretty_pretty p
, decl_node t
);
5319 static void doReC (mcPretty_pretty p
, decl_node n
);
5325 static void doImC (mcPretty_pretty p
, decl_node n
);
5331 static void doCmplx (mcPretty_pretty p
, decl_node n
);
5337 static void doIntrinsicC (mcPretty_pretty p
, decl_node n
);
5340 isIntrinsicFunction - returns true if, n, is an instrinsic function.
5343 static bool isIntrinsicFunction (decl_node n
);
5349 static void doSizeC (mcPretty_pretty p
, decl_node n
);
5355 static void doConvertC (mcPretty_pretty p
, decl_node n
, const char *conversion_
, unsigned int _conversion_high
);
5361 static void doConvertSC (mcPretty_pretty p
, decl_node n
, DynamicStrings_String conversion
);
5367 static decl_node
getFuncFromExpr (decl_node n
);
5373 static void doFuncExprC (mcPretty_pretty p
, decl_node n
);
5379 static void doFuncCallC (mcPretty_pretty p
, decl_node n
);
5385 static void doCaseStatementC (mcPretty_pretty p
, decl_node n
, bool needBreak
);
5391 static void doExceptionC (mcPretty_pretty p
, const char *a_
, unsigned int _a_high
, decl_node n
);
5397 static void doExceptionCP (mcPretty_pretty p
, const char *a_
, unsigned int _a_high
, decl_node n
);
5403 static void doException (mcPretty_pretty p
, const char *a_
, unsigned int _a_high
, decl_node n
);
5409 static void doRangeListC (mcPretty_pretty p
, decl_node c
);
5415 static void doRangeIfListC (mcPretty_pretty p
, decl_node e
, decl_node c
);
5421 static void doCaseLabels (mcPretty_pretty p
, decl_node n
, bool needBreak
);
5427 static void doCaseLabelListC (mcPretty_pretty p
, decl_node n
, bool haveElse
);
5433 static void doCaseIfLabels (mcPretty_pretty p
, decl_node e
, decl_node n
, unsigned int i
, unsigned int h
);
5436 doCaseIfLabelListC -
5439 static void doCaseIfLabelListC (mcPretty_pretty p
, decl_node n
);
5445 static void doCaseElseC (mcPretty_pretty p
, decl_node n
);
5451 static void doCaseIfElseC (mcPretty_pretty p
, decl_node n
);
5454 canUseSwitchCaseLabels - returns TRUE if all the case labels are
5455 single values and not ranges.
5458 static bool canUseSwitchCaseLabels (decl_node n
);
5461 canUseSwitch - returns TRUE if the case statement can be implement
5462 by a switch statement. This will be TRUE if all case
5463 selectors are single values rather than ranges.
5466 static bool canUseSwitch (decl_node n
);
5472 static void doCaseC (mcPretty_pretty p
, decl_node n
);
5478 static void doLoopC (mcPretty_pretty p
, decl_node s
);
5484 static void doExitC (mcPretty_pretty p
, decl_node s
);
5490 static void doStatementsC (mcPretty_pretty p
, decl_node s
);
5491 static void stop (void);
5497 static void doLocalVarC (mcPretty_pretty p
, decl_scopeT s
);
5500 doLocalConstTypesC -
5503 static void doLocalConstTypesC (mcPretty_pretty p
, decl_scopeT s
);
5509 static void addParamDone (decl_node n
);
5515 static void includeParameters (decl_node n
);
5521 static bool isHalt (decl_node n
);
5527 static bool isReturnOrHalt (decl_node n
);
5530 isLastStatementReturn -
5533 static bool isLastStatementReturn (decl_node n
);
5536 isLastStatementSequence -
5539 static bool isLastStatementSequence (decl_node n
, decl_isNodeF q
);
5545 static bool isLastStatementIf (decl_node n
, decl_isNodeF q
);
5548 isLastStatementElsif -
5551 static bool isLastStatementElsif (decl_node n
, decl_isNodeF q
);
5554 isLastStatementCase -
5557 static bool isLastStatementCase (decl_node n
, decl_isNodeF q
);
5560 isLastStatement - returns TRUE if the last statement in, n, is, q.
5563 static bool isLastStatement (decl_node n
, decl_isNodeF q
);
5569 static void doProcedureC (decl_node n
);
5575 static void outProceduresC (mcPretty_pretty p
, decl_scopeT s
);
5581 static void output (decl_node n
, decl_nodeProcedure c
, decl_nodeProcedure t
, decl_nodeProcedure v
);
5587 static decl_dependentState
allDependants (decl_node n
);
5593 static decl_dependentState
walkDependants (alists_alist l
, decl_node n
);
5599 static decl_dependentState
walkType (alists_alist l
, decl_node n
);
5605 static void db (const char *a_
, unsigned int _a_high
, decl_node n
);
5611 static void dbt (const char *a_
, unsigned int _a_high
);
5617 static void dbs (decl_dependentState s
, decl_node n
);
5623 static void dbq (decl_node n
);
5629 static decl_dependentState
walkRecord (alists_alist l
, decl_node n
);
5635 static decl_dependentState
walkVarient (alists_alist l
, decl_node n
);
5641 static void queueBlocked (decl_node n
);
5647 static decl_dependentState
walkVar (alists_alist l
, decl_node n
);
5653 static decl_dependentState
walkEnumeration (alists_alist l
, decl_node n
);
5659 static decl_dependentState
walkSubrange (alists_alist l
, decl_node n
);
5665 static decl_dependentState
walkSubscript (alists_alist l
, decl_node n
);
5671 static decl_dependentState
walkPointer (alists_alist l
, decl_node n
);
5677 static decl_dependentState
walkArray (alists_alist l
, decl_node n
);
5683 static decl_dependentState
walkConst (alists_alist l
, decl_node n
);
5689 static decl_dependentState
walkVarParam (alists_alist l
, decl_node n
);
5695 static decl_dependentState
walkParam (alists_alist l
, decl_node n
);
5701 static decl_dependentState
walkOptarg (alists_alist l
, decl_node n
);
5707 static decl_dependentState
walkRecordField (alists_alist l
, decl_node n
);
5713 static decl_dependentState
walkVarientField (alists_alist l
, decl_node n
);
5716 walkEnumerationField -
5719 static decl_dependentState
walkEnumerationField (alists_alist l
, decl_node n
);
5725 static decl_dependentState
walkSet (alists_alist l
, decl_node n
);
5731 static decl_dependentState
walkProcType (alists_alist l
, decl_node n
);
5737 static decl_dependentState
walkProcedure (alists_alist l
, decl_node n
);
5743 static decl_dependentState
walkParameters (alists_alist l
, Indexing_Index p
);
5749 static decl_dependentState
walkFuncCall (alists_alist l
, decl_node n
);
5755 static decl_dependentState
walkUnary (alists_alist l
, decl_node n
);
5761 static decl_dependentState
walkBinary (alists_alist l
, decl_node n
);
5767 static decl_dependentState
walkComponentRef (alists_alist l
, decl_node n
);
5773 static decl_dependentState
walkPointerRef (alists_alist l
, decl_node n
);
5779 static decl_dependentState
walkSetValue (alists_alist l
, decl_node n
);
5782 doDependants - return the dependentState depending upon whether
5783 all dependants have been declared.
5786 static decl_dependentState
doDependants (alists_alist l
, decl_node n
);
5789 tryComplete - returns TRUE if node, n, can be and was completed.
5792 static bool tryComplete (decl_node n
, decl_nodeProcedure c
, decl_nodeProcedure t
, decl_nodeProcedure v
);
5795 tryCompleteFromPartial -
5798 static bool tryCompleteFromPartial (decl_node n
, decl_nodeProcedure t
);
5801 visitIntrinsicFunction -
5804 static void visitIntrinsicFunction (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5810 static void visitUnary (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5816 static void visitBinary (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5822 static void visitBoolean (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5828 static void visitScope (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5834 static void visitType (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5840 static void visitIndex (alists_alist v
, Indexing_Index i
, decl_nodeProcedure p
);
5846 static void visitRecord (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5852 static void visitVarient (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5858 static void visitVar (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5864 static void visitEnumeration (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5870 static void visitSubrange (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5876 static void visitPointer (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5882 static void visitArray (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5888 static void visitConst (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5894 static void visitVarParam (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5900 static void visitParam (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5906 static void visitOptarg (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5912 static void visitRecordField (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5918 static void visitVarientField (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5921 visitEnumerationField -
5924 static void visitEnumerationField (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5930 static void visitSet (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5936 static void visitProcType (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5942 static void visitSubscript (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5948 static void visitDecls (alists_alist v
, decl_scopeT s
, decl_nodeProcedure p
);
5954 static void visitProcedure (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5960 static void visitDef (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5966 static void visitImp (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5972 static void visitModule (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5978 static void visitLoop (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5984 static void visitWhile (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5990 static void visitRepeat (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5996 static void visitCase (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
5999 visitCaseLabelList -
6002 static void visitCaseLabelList (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6008 static void visitCaseList (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6014 static void visitRange (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6020 static void visitIf (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6026 static void visitElsif (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6032 static void visitFor (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6038 static void visitAssignment (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6044 static void visitComponentRef (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6050 static void visitPointerRef (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6056 static void visitArrayRef (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6062 static void visitFunccall (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6068 static void visitVarDecl (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6074 static void visitExplist (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6080 static void visitExit (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6086 static void visitReturn (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6092 static void visitStmtSeq (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6098 static void visitVarargs (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6104 static void visitSetValue (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6110 static void visitIntrinsic (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6113 visitDependants - helper procedure function called from visitNode.
6114 node n has just been visited, this procedure will
6115 visit node, n, dependants.
6118 static void visitDependants (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6121 visitNode - visits node, n, if it is not already in the alist, v.
6122 It calls p(n) if the node is unvisited.
6125 static void visitNode (alists_alist v
, decl_node n
, decl_nodeProcedure p
);
6128 genKind - returns a string depending upon the kind of node, n.
6131 static DynamicStrings_String
genKind (decl_node n
);
6134 gen - generate a small string describing node, n.
6137 static DynamicStrings_String
gen (decl_node n
);
6143 static void dumpQ (const char *q_
, unsigned int _q_high
, alists_alist l
);
6149 static void dumpLists (void);
6155 static void outputHidden (decl_node n
);
6158 outputHiddenComplete -
6161 static void outputHiddenComplete (decl_node n
);
6167 static bool tryPartial (decl_node n
, decl_nodeProcedure pt
);
6170 outputPartialRecordArrayProcType -
6173 static void outputPartialRecordArrayProcType (decl_node n
, decl_node q
, unsigned int indirection
);
6179 static void outputPartial (decl_node n
);
6185 static void tryOutputTodo (decl_nodeProcedure c
, decl_nodeProcedure t
, decl_nodeProcedure v
, decl_nodeProcedure pt
);
6191 static void tryOutputPartial (decl_nodeProcedure t
);
6197 static void debugList (const char *a_
, unsigned int _a_high
, alists_alist l
);
6203 static void debugLists (void);
6209 static void addEnumConst (decl_node n
);
6215 static void populateTodo (decl_nodeProcedure p
);
6221 static void topologicallyOut (decl_nodeProcedure c
, decl_nodeProcedure t
, decl_nodeProcedure v
, decl_nodeProcedure tp
, decl_nodeProcedure pc
, decl_nodeProcedure pt
, decl_nodeProcedure pv
);
6227 static void scaffoldStatic (mcPretty_pretty p
, decl_node n
);
6233 static void emitCtor (mcPretty_pretty p
, decl_node n
);
6239 static void scaffoldDynamic (mcPretty_pretty p
, decl_node n
);
6245 static void scaffoldMain (mcPretty_pretty p
, decl_node n
);
6248 outImpInitC - emit the init/fini functions and main function if required.
6251 static void outImpInitC (mcPretty_pretty p
, decl_node n
);
6257 static void runSimplifyTypes (decl_node n
);
6263 static void outDefC (mcPretty_pretty p
, decl_node n
);
6266 runPrototypeExported -
6269 static void runPrototypeExported (decl_node n
);
6275 static void runPrototypeDefC (decl_node n
);
6281 static void outImpC (mcPretty_pretty p
, decl_node n
);
6287 static void outDeclsModuleC (mcPretty_pretty p
, decl_scopeT s
);
6293 static void outModuleInitC (mcPretty_pretty p
, decl_node n
);
6299 static void outModuleC (mcPretty_pretty p
, decl_node n
);
6305 static void outC (mcPretty_pretty p
, decl_node n
);
6308 doIncludeM2 - include modules in module, n.
6311 static void doIncludeM2 (decl_node n
);
6317 static void doConstM2 (decl_node n
);
6323 static void doProcTypeM2 (mcPretty_pretty p
, decl_node n
);
6329 static void doRecordFieldM2 (mcPretty_pretty p
, decl_node f
);
6335 static void doVarientFieldM2 (mcPretty_pretty p
, decl_node n
);
6341 static void doVarientM2 (mcPretty_pretty p
, decl_node n
);
6347 static void doRecordM2 (mcPretty_pretty p
, decl_node n
);
6353 static void doPointerM2 (mcPretty_pretty p
, decl_node n
);
6359 static void doTypeAliasM2 (mcPretty_pretty p
, decl_node n
);
6365 static void doEnumerationM2 (mcPretty_pretty p
, decl_node n
);
6371 static void doBaseM2 (mcPretty_pretty p
, decl_node n
);
6377 static void doSystemM2 (mcPretty_pretty p
, decl_node n
);
6383 static void doTypeM2 (mcPretty_pretty p
, decl_node n
);
6389 static void doTypesM2 (decl_node n
);
6395 static void doVarM2 (decl_node n
);
6401 static void doVarsM2 (decl_node n
);
6407 static void doTypeNameM2 (mcPretty_pretty p
, decl_node n
);
6413 static void doParamM2 (mcPretty_pretty p
, decl_node n
);
6419 static void doVarParamM2 (mcPretty_pretty p
, decl_node n
);
6425 static void doParameterM2 (mcPretty_pretty p
, decl_node n
);
6431 static void doPrototypeM2 (decl_node n
);
6434 outputPartialM2 - just writes out record, array, and proctypes.
6435 No need for forward declarations in Modula-2
6436 but we need to keep topological sort happy.
6437 So when asked to output partial we emit the
6438 full type for these types and then do nothing
6439 when trying to complete partial to full.
6442 static void outputPartialM2 (decl_node n
);
6448 static void outDeclsDefM2 (mcPretty_pretty p
, decl_scopeT s
);
6454 static void outDefM2 (mcPretty_pretty p
, decl_node n
);
6460 static void outDeclsImpM2 (mcPretty_pretty p
, decl_scopeT s
);
6466 static void outImpM2 (mcPretty_pretty p
, decl_node n
);
6472 static void outModuleM2 (mcPretty_pretty p
, decl_node n
);
6478 static void outM2 (mcPretty_pretty p
, decl_node n
);
6481 addDone - adds node, n, to the doneQ.
6484 static void addDone (decl_node n
);
6487 addDoneDef - adds node, n, to the doneQ providing
6488 it is not an opaque of the main module we are compiling.
6491 static void addDoneDef (decl_node n
);
6497 static decl_node
dbgAdd (alists_alist l
, decl_node n
);
6503 static void dbgType (alists_alist l
, decl_node n
);
6509 static void dbgPointer (alists_alist l
, decl_node n
);
6515 static void dbgRecord (alists_alist l
, decl_node n
);
6521 static void dbgVarient (alists_alist l
, decl_node n
);
6527 static void dbgEnumeration (alists_alist l
, decl_node n
);
6533 static void dbgVar (alists_alist l
, decl_node n
);
6539 static void dbgSubrange (alists_alist l
, decl_node n
);
6545 static void dbgArray (alists_alist l
, decl_node n
);
6551 static void doDbg (alists_alist l
, decl_node n
);
6557 static void dbg (decl_node n
);
6560 addGenericBody - adds comment node to funccall, return, assignment
6564 static void addGenericBody (decl_node n
, decl_node c
);
6567 addGenericAfter - adds comment node to funccall, return, assignment
6571 static void addGenericAfter (decl_node n
, decl_node c
);
6577 static bool isAssignment (decl_node n
);
6580 isComment - returns TRUE if node, n, is a comment.
6583 static bool isComment (decl_node n
);
6586 initPair - initialise the commentPair, c.
6589 static void initPair (decl_commentPair
*c
);
6595 static decl_node
dupExplist (decl_node n
);
6601 static decl_node
dupArrayref (decl_node n
);
6607 static decl_node
dupPointerref (decl_node n
);
6613 static decl_node
dupComponentref (decl_node n
);
6619 static decl_node
dupBinary (decl_node n
);
6625 static decl_node
dupUnary (decl_node n
);
6631 static decl_node
dupFunccall (decl_node n
);
6637 static decl_node
dupSetValue (decl_node n
);
6643 static decl_node
doDupExpr (decl_node n
);
6649 static void makeSystem (void);
6655 static void makeM2rts (void);
6661 static decl_node
makeBitnum (void);
6667 static void makeBaseSymbols (void);
6673 static void makeBuiltins (void);
6679 static void init (void);
6683 newNode - create and return a new node of kind k.
6686 static decl_node
newNode (decl_nodeT k
)
6690 Storage_ALLOCATE ((void **) &d
, sizeof (decl_nodeRec
));
6691 if (enableMemsetOnAllocation
)
6693 d
= static_cast<decl_node
> (libc_memset (reinterpret_cast<void *> (d
), 0, static_cast<size_t> (sizeof ((*d
)))));
6698 __builtin_unreachable ();
6703 d
->at
.defDeclared
= 0;
6704 d
->at
.modDeclared
= 0;
6705 d
->at
.firstUsed
= 0;
6708 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
6709 __builtin_unreachable ();
6714 disposeNode - dispose node, n.
6717 static void disposeNode (decl_node
*n
)
6719 Storage_DEALLOCATE ((void **) &(*n
), sizeof (decl_nodeRec
));
6725 isLocal - returns TRUE if symbol, n, is locally declared in a procedure.
6728 static bool isLocal (decl_node n
)
6732 s
= decl_getScope (n
);
6735 return decl_isProcedure (s
);
6738 /* static analysis guarentees a RETURN statement will be used before here. */
6739 __builtin_unreachable ();
6744 importEnumFields - if, n, is an enumeration type import the all fields into module, m.
6747 static void importEnumFields (decl_node m
, decl_node n
)
6754 mcDebug_assert (((decl_isDef (m
)) || (decl_isModule (m
))) || (decl_isImp (m
)));
6755 n
= decl_skipType (n
);
6756 if ((n
!= NULL
) && (decl_isEnumeration (n
)))
6758 i
= Indexing_LowIndice (n
->enumerationF
.listOfSons
);
6759 h
= Indexing_HighIndice (n
->enumerationF
.listOfSons
);
6762 e
= static_cast<decl_node
> (Indexing_GetIndice (n
->enumerationF
.listOfSons
, i
));
6763 r
= decl_import (m
, e
);
6766 mcMetaError_metaError2 ((const char *) "enumeration field {%1ad} cannot be imported implicitly into {%2d} due to a name clash", 85, (const unsigned char *) &e
, (sizeof (e
)-1), (const unsigned char *) &m
, (sizeof (m
)-1));
6775 isComplex - returns TRUE if, n, is the complex type.
6778 static bool isComplex (decl_node n
)
6780 return n
== complexN
;
6781 /* static analysis guarentees a RETURN statement will be used before here. */
6782 __builtin_unreachable ();
6787 isLongComplex - returns TRUE if, n, is the longcomplex type.
6790 static bool isLongComplex (decl_node n
)
6792 return n
== longcomplexN
;
6793 /* static analysis guarentees a RETURN statement will be used before here. */
6794 __builtin_unreachable ();
6799 isShortComplex - returns TRUE if, n, is the shortcomplex type.
6802 static bool isShortComplex (decl_node n
)
6804 return n
== shortcomplexN
;
6805 /* static analysis guarentees a RETURN statement will be used before here. */
6806 __builtin_unreachable ();
6811 isAProcType - returns TRUE if, n, is a proctype or proc node.
6814 static bool isAProcType (decl_node n
)
6816 mcDebug_assert (n
!= NULL
);
6817 return (decl_isProcType (n
)) || (n
== procN
);
6818 /* static analysis guarentees a RETURN statement will be used before here. */
6819 __builtin_unreachable ();
6824 initFixupInfo - initialize the fixupInfo record.
6827 static decl_fixupInfo
initFixupInfo (void)
6832 f
.info
= Indexing_InitIndex (1);
6834 /* static analysis guarentees a RETURN statement will be used before here. */
6835 __builtin_unreachable ();
6840 makeDef - returns a definition module node named, n.
6843 static decl_node
makeDef (nameKey_Name n
)
6847 d
= newNode (decl_def
);
6849 d
->defF
.source
= nameKey_NulName
;
6850 d
->defF
.hasHidden
= false;
6851 d
->defF
.forC
= false;
6852 d
->defF
.exported
= Indexing_InitIndex (1);
6853 d
->defF
.importedModules
= Indexing_InitIndex (1);
6854 d
->defF
.constFixup
= initFixupInfo ();
6855 d
->defF
.enumFixup
= initFixupInfo ();
6856 initDecls (&d
->defF
.decls
);
6857 d
->defF
.enumsComplete
= false;
6858 d
->defF
.constsComplete
= false;
6859 d
->defF
.visited
= false;
6860 initPair (&d
->defF
.com
);
6862 /* static analysis guarentees a RETURN statement will be used before here. */
6863 __builtin_unreachable ();
6868 makeImp - returns an implementation module node named, n.
6871 static decl_node
makeImp (nameKey_Name n
)
6875 d
= newNode (decl_imp
);
6877 d
->impF
.source
= nameKey_NulName
;
6878 d
->impF
.importedModules
= Indexing_InitIndex (1);
6879 d
->impF
.constFixup
= initFixupInfo ();
6880 d
->impF
.enumFixup
= initFixupInfo ();
6881 initDecls (&d
->impF
.decls
);
6882 d
->impF
.beginStatements
= NULL
;
6883 d
->impF
.finallyStatements
= NULL
;
6884 d
->impF
.definitionModule
= NULL
;
6885 d
->impF
.enumsComplete
= false;
6886 d
->impF
.constsComplete
= false;
6887 d
->impF
.visited
= false;
6888 initPair (&d
->impF
.com
);
6890 /* static analysis guarentees a RETURN statement will be used before here. */
6891 __builtin_unreachable ();
6896 makeModule - returns a module node named, n.
6899 static decl_node
makeModule (nameKey_Name n
)
6903 d
= newNode (decl_module
);
6904 d
->moduleF
.name
= n
;
6905 d
->moduleF
.source
= nameKey_NulName
;
6906 d
->moduleF
.importedModules
= Indexing_InitIndex (1);
6907 d
->moduleF
.constFixup
= initFixupInfo ();
6908 d
->moduleF
.enumFixup
= initFixupInfo ();
6909 initDecls (&d
->moduleF
.decls
);
6910 d
->moduleF
.beginStatements
= NULL
;
6911 d
->moduleF
.finallyStatements
= NULL
;
6912 d
->moduleF
.enumsComplete
= false;
6913 d
->moduleF
.constsComplete
= false;
6914 d
->moduleF
.visited
= false;
6915 initPair (&d
->moduleF
.com
);
6917 /* static analysis guarentees a RETURN statement will be used before here. */
6918 __builtin_unreachable ();
6923 isDefForC - returns TRUE if the definition module was defined FOR "C".
6926 static bool isDefForC (decl_node n
)
6928 return (decl_isDef (n
)) && n
->defF
.forC
;
6929 /* static analysis guarentees a RETURN statement will be used before here. */
6930 __builtin_unreachable ();
6935 initDecls - initialize the decls, scopeT.
6938 static void initDecls (decl_scopeT
*decls
)
6940 (*decls
).symbols
= symbolKey_initTree ();
6941 (*decls
).constants
= Indexing_InitIndex (1);
6942 (*decls
).types
= Indexing_InitIndex (1);
6943 (*decls
).procedures
= Indexing_InitIndex (1);
6944 (*decls
).variables
= Indexing_InitIndex (1);
6949 addTo - adds node, d, to scope decls and returns, d.
6950 It stores, d, in the symbols tree associated with decls.
6953 static decl_node
addTo (decl_scopeT
*decls
, decl_node d
)
6957 n
= decl_getSymName (d
);
6958 if (n
!= nameKey_NulName
)
6960 /* avoid gcc warning by using compound statement even if not strictly necessary. */
6961 if ((symbolKey_getSymKey ((*decls
).symbols
, n
)) == NULL
)
6963 symbolKey_putSymKey ((*decls
).symbols
, n
, reinterpret_cast<void *> (d
));
6967 mcMetaError_metaError1 ((const char *) "{%1DMad} was declared", 21, (const unsigned char *) &d
, (sizeof (d
)-1));
6968 mcMetaError_metaError1 ((const char *) "{%1k} and is being declared again", 33, (const unsigned char *) &n
, (sizeof (n
)-1));
6971 if (decl_isConst (d
))
6973 Indexing_IncludeIndiceIntoIndex ((*decls
).constants
, reinterpret_cast<void *> (d
));
6975 else if (decl_isVar (d
))
6977 /* avoid dangling else. */
6978 Indexing_IncludeIndiceIntoIndex ((*decls
).variables
, reinterpret_cast<void *> (d
));
6980 else if (decl_isType (d
))
6982 /* avoid dangling else. */
6983 Indexing_IncludeIndiceIntoIndex ((*decls
).types
, reinterpret_cast<void *> (d
));
6985 else if (decl_isProcedure (d
))
6987 /* avoid dangling else. */
6988 Indexing_IncludeIndiceIntoIndex ((*decls
).procedures
, reinterpret_cast<void *> (d
));
6991 libc_printf ((const char *) "%d procedures on the dynamic array\\n", 36, Indexing_HighIndice ((*decls
).procedures
));
6995 /* static analysis guarentees a RETURN statement will be used before here. */
6996 __builtin_unreachable ();
7001 export - export node, n, from definition module, d.
7004 static void export_ (decl_node d
, decl_node n
)
7006 mcDebug_assert (decl_isDef (d
));
7007 Indexing_IncludeIndiceIntoIndex (d
->defF
.exported
, reinterpret_cast<void *> (n
));
7012 addToScope - adds node, n, to the current scope and returns, n.
7015 static decl_node
addToScope (decl_node n
)
7020 i
= Indexing_HighIndice (scopeStack
);
7021 s
= static_cast<decl_node
> (Indexing_GetIndice (scopeStack
, i
));
7022 if (decl_isProcedure (s
))
7026 outText (doP
, (const char *) "adding ", 7);
7028 outText (doP
, (const char *) " to procedure\\n", 15);
7030 return addTo (&s
->procedureF
.decls
, n
);
7032 else if (decl_isModule (s
))
7034 /* avoid dangling else. */
7037 outText (doP
, (const char *) "adding ", 7);
7039 outText (doP
, (const char *) " to module\\n", 12);
7041 return addTo (&s
->moduleF
.decls
, n
);
7043 else if (decl_isDef (s
))
7045 /* avoid dangling else. */
7048 outText (doP
, (const char *) "adding ", 7);
7050 outText (doP
, (const char *) " to definition module\\n", 23);
7053 return addTo (&s
->defF
.decls
, n
);
7055 else if (decl_isImp (s
))
7057 /* avoid dangling else. */
7060 outText (doP
, (const char *) "adding ", 7);
7062 outText (doP
, (const char *) " to implementation module\\n", 27);
7064 return addTo (&s
->impF
.decls
, n
);
7067 __builtin_unreachable ();
7068 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
7069 __builtin_unreachable ();
7074 addModuleToScope - adds module, i, to module, m, scope.
7077 static void addModuleToScope (decl_node m
, decl_node i
)
7079 mcDebug_assert ((decl_getDeclScope ()) == m
);
7080 if ((decl_lookupSym (decl_getSymName (i
))) == NULL
)
7088 completedEnum - assign boolean enumsComplete to TRUE if a definition,
7089 implementation or module symbol.
7092 static void completedEnum (decl_node n
)
7094 mcDebug_assert (((decl_isDef (n
)) || (decl_isImp (n
))) || (decl_isModule (n
)));
7097 n
->defF
.enumsComplete
= true;
7099 else if (decl_isImp (n
))
7101 /* avoid dangling else. */
7102 n
->impF
.enumsComplete
= true;
7104 else if (decl_isModule (n
))
7106 /* avoid dangling else. */
7107 n
->moduleF
.enumsComplete
= true;
7113 setUnary - sets a unary node to contain, arg, a, and type, t.
7116 static void setUnary (decl_node u
, decl_nodeT k
, decl_node a
, decl_node t
)
7141 u
->unaryF
.resultType
= t
;
7146 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
7147 __builtin_unreachable ();
7153 putVarBool - assigns the four booleans associated with a variable.
7156 static void putVarBool (decl_node v
, bool init
, bool param
, bool isvar
, bool isused
)
7158 mcDebug_assert (decl_isVar (v
));
7159 v
->varF
.isInitialised
= init
;
7160 v
->varF
.isParameter
= param
;
7161 v
->varF
.isVarParameter
= isvar
;
7162 v
->varF
.isUsed
= isused
;
7167 checkPtr - in C++ we need to create a typedef for a pointer
7168 in case we need to use reinterpret_cast.
7171 static decl_node
checkPtr (decl_node n
)
7173 DynamicStrings_String s
;
7176 if (lang
== decl_ansiCP
)
7178 if (decl_isPointer (n
))
7181 p
= decl_makeType (nameKey_makekey (DynamicStrings_string (s
)));
7182 decl_putType (p
, n
);
7183 s
= DynamicStrings_KillString (s
);
7188 /* static analysis guarentees a RETURN statement will be used before here. */
7189 __builtin_unreachable ();
7194 isVarDecl - returns TRUE if, n, is a vardecl node.
7197 static bool isVarDecl (decl_node n
)
7199 return n
->kind
== decl_vardecl
;
7200 /* static analysis guarentees a RETURN statement will be used before here. */
7201 __builtin_unreachable ();
7206 makeVariablesFromParameters - creates variables which are really parameters.
7209 static void makeVariablesFromParameters (decl_node proc
, decl_node id
, decl_node type
, bool isvar
, bool isused
)
7215 DynamicStrings_String s
;
7217 mcDebug_assert (decl_isProcedure (proc
));
7218 mcDebug_assert (isIdentList (id
));
7220 n
= wlists_noOfItemsInList (id
->identlistF
.names
);
7223 m
= static_cast<nameKey_Name
> (wlists_getItemFromList (id
->identlistF
.names
, i
));
7224 v
= decl_makeVar (m
);
7225 decl_putVar (v
, type
, NULL
);
7226 putVarBool (v
, true, true, isvar
, isused
);
7229 libc_printf ((const char *) "adding parameter variable into top scope\\n", 42);
7231 libc_printf ((const char *) " variable name is: ", 19);
7232 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (m
));
7233 if ((DynamicStrings_KillString (SFIO_WriteS (FIO_StdOut
, s
))) == NULL
)
7235 libc_printf ((const char *) "\\n", 2);
7243 addProcedureToScope - add a procedure name n and node d to the
7247 static decl_node
addProcedureToScope (decl_node d
, nameKey_Name n
)
7252 i
= Indexing_HighIndice (scopeStack
);
7253 m
= static_cast<decl_node
> (Indexing_GetIndice (scopeStack
, i
));
7254 if (((decl_isDef (m
)) && ((decl_getSymName (m
)) == (nameKey_makeKey ((const char *) "M2RTS", 5)))) && ((decl_getSymName (d
)) == (nameKey_makeKey ((const char *) "HALT", 4))))
7257 symbolKey_putSymKey (baseSymbols
, n
, reinterpret_cast<void *> (haltN
));
7259 return addToScope (d
);
7260 /* static analysis guarentees a RETURN statement will be used before here. */
7261 __builtin_unreachable ();
7266 putProcTypeReturn - sets the return type of, proc, to, type.
7269 static void putProcTypeReturn (decl_node proc
, decl_node type
)
7271 mcDebug_assert (decl_isProcType (proc
));
7272 proc
->proctypeF
.returnType
= type
;
7277 putProcTypeOptReturn - sets, proc, to have an optional return type.
7280 static void putProcTypeOptReturn (decl_node proc
)
7282 mcDebug_assert (decl_isProcType (proc
));
7283 proc
->proctypeF
.returnopt
= true;
7288 makeOptParameter - creates and returns an optarg.
7291 static decl_node
makeOptParameter (decl_node l
, decl_node type
, decl_node init
)
7295 n
= newNode (decl_optarg
);
7296 n
->optargF
.namelist
= l
;
7297 n
->optargF
.type
= type
;
7298 n
->optargF
.init
= init
;
7299 n
->optargF
.scope
= NULL
;
7301 /* static analysis guarentees a RETURN statement will be used before here. */
7302 __builtin_unreachable ();
7307 setwatch - assign the globalNode to n.
7310 static bool setwatch (decl_node n
)
7314 /* static analysis guarentees a RETURN statement will be used before here. */
7315 __builtin_unreachable ();
7320 runwatch - set the globalNode to an identlist.
7323 static bool runwatch (void)
7325 return globalNode
->kind
== decl_identlist
;
7326 /* static analysis guarentees a RETURN statement will be used before here. */
7327 __builtin_unreachable ();
7332 isIdentList - returns TRUE if, n, is an identlist.
7335 static bool isIdentList (decl_node n
)
7337 return n
->kind
== decl_identlist
;
7338 /* static analysis guarentees a RETURN statement will be used before here. */
7339 __builtin_unreachable ();
7344 identListLen - returns the length of identlist.
7347 static unsigned int identListLen (decl_node n
)
7355 mcDebug_assert (isIdentList (n
));
7356 return wlists_noOfItemsInList (n
->identlistF
.names
);
7358 /* static analysis guarentees a RETURN statement will be used before here. */
7359 __builtin_unreachable ();
7364 checkParameters - placeholder for future parameter checking.
7367 static void checkParameters (decl_node p
, decl_node i
, decl_node type
, bool isvar
, bool isused
)
7375 checkMakeVariables - create shadow local variables for parameters providing that
7376 procedure n has not already been built and we are compiling
7377 a module or an implementation module.
7380 static void checkMakeVariables (decl_node n
, decl_node i
, decl_node type
, bool isvar
, bool isused
)
7382 if (((decl_isImp (currentModule
)) || (decl_isModule (currentModule
))) && ! n
->procedureF
.built
)
7384 makeVariablesFromParameters (n
, i
, type
, isvar
, isused
);
7390 makeVarientField - create a varient field within varient, v,
7391 The new varient field is returned.
7394 static decl_node
makeVarientField (decl_node v
, decl_node p
)
7398 n
= newNode (decl_varientfield
);
7399 n
->varientfieldF
.name
= nameKey_NulName
;
7400 n
->varientfieldF
.parent
= p
;
7401 n
->varientfieldF
.varient
= v
;
7402 n
->varientfieldF
.simple
= false;
7403 n
->varientfieldF
.listOfSons
= Indexing_InitIndex (1);
7404 n
->varientfieldF
.scope
= decl_getDeclScope ();
7406 /* static analysis guarentees a RETURN statement will be used before here. */
7407 __builtin_unreachable ();
7412 putFieldVarient - places the field varient, f, as a brother to, the
7413 varient symbol, v, and also tells, f, that its varient
7417 static void putFieldVarient (decl_node f
, decl_node v
)
7419 mcDebug_assert (decl_isVarient (v
));
7420 mcDebug_assert (decl_isVarientField (f
));
7424 Indexing_IncludeIndiceIntoIndex (v
->varientF
.listOfSons
, reinterpret_cast<void *> (f
));
7429 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
7430 __builtin_unreachable ();
7434 case decl_varientfield
:
7435 f
->varientfieldF
.varient
= v
;
7440 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
7441 __builtin_unreachable ();
7447 putFieldRecord - create a new recordfield and place it into record r.
7448 The new field has a tagname and type and can have a
7452 static decl_node
putFieldRecord (decl_node r
, nameKey_Name tag
, decl_node type
, decl_node v
)
7458 n
= newNode (decl_recordfield
);
7462 Indexing_IncludeIndiceIntoIndex (r
->recordF
.listOfSons
, reinterpret_cast<void *> (n
));
7463 /* ensure that field, n, is in the parents Local Symbols. */
7464 if (tag
!= nameKey_NulName
)
7466 /* avoid gcc warning by using compound statement even if not strictly necessary. */
7467 if ((symbolKey_getSymKey (r
->recordF
.localSymbols
, tag
)) == symbolKey_NulKey
)
7469 symbolKey_putSymKey (r
->recordF
.localSymbols
, tag
, reinterpret_cast<void *> (n
));
7473 f
= static_cast<decl_node
> (symbolKey_getSymKey (r
->recordF
.localSymbols
, tag
));
7474 mcMetaError_metaErrors1 ((const char *) "field record {%1Dad} has already been declared", 46, (const char *) "field record duplicate", 22, (const unsigned char *) &f
, (sizeof (f
)-1));
7479 case decl_varientfield
:
7480 Indexing_IncludeIndiceIntoIndex (r
->varientfieldF
.listOfSons
, reinterpret_cast<void *> (n
));
7482 mcDebug_assert (p
->kind
== decl_record
);
7483 if (tag
!= nameKey_NulName
)
7485 symbolKey_putSymKey (p
->recordF
.localSymbols
, tag
, reinterpret_cast<void *> (n
));
7491 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
7492 __builtin_unreachable ();
7495 n
->recordfieldF
.type
= type
;
7496 n
->recordfieldF
.name
= tag
;
7497 n
->recordfieldF
.parent
= r
;
7498 n
->recordfieldF
.varient
= v
;
7499 n
->recordfieldF
.tag
= false;
7500 n
->recordfieldF
.scope
= NULL
;
7501 initCname (&n
->recordfieldF
.cname
);
7509 /* static analysis guarentees a RETURN statement will be used before here. */
7510 __builtin_unreachable ();
7515 ensureOrder - ensures that, a, and, b, exist in, i, and also
7516 ensure that, a, is before, b.
7519 static void ensureOrder (Indexing_Index i
, decl_node a
, decl_node b
)
7521 mcDebug_assert (Indexing_IsIndiceInIndex (i
, reinterpret_cast<void *> (a
)));
7522 mcDebug_assert (Indexing_IsIndiceInIndex (i
, reinterpret_cast<void *> (b
)));
7523 Indexing_RemoveIndiceFromIndex (i
, reinterpret_cast<void *> (a
));
7524 Indexing_RemoveIndiceFromIndex (i
, reinterpret_cast<void *> (b
));
7525 Indexing_IncludeIndiceIntoIndex (i
, reinterpret_cast<void *> (a
));
7526 Indexing_IncludeIndiceIntoIndex (i
, reinterpret_cast<void *> (b
));
7527 mcDebug_assert (Indexing_IsIndiceInIndex (i
, reinterpret_cast<void *> (a
)));
7528 mcDebug_assert (Indexing_IsIndiceInIndex (i
, reinterpret_cast<void *> (b
)));
7533 putVarientTag - places tag into variant v.
7536 static void putVarientTag (decl_node v
, decl_node tag
)
7540 mcDebug_assert (decl_isVarient (v
));
7544 v
->varientF
.tag
= tag
;
7549 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
7550 __builtin_unreachable ();
7556 getParent - returns the parent field of recordfield or varientfield symbol, n.
7559 static decl_node
getParent (decl_node n
)
7563 case decl_recordfield
:
7564 return n
->recordfieldF
.parent
;
7567 case decl_varientfield
:
7568 return n
->varientfieldF
.parent
;
7573 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
7574 __builtin_unreachable ();
7576 /* static analysis guarentees a RETURN statement will be used before here. */
7577 __builtin_unreachable ();
7582 getRecord - returns the record associated with node, n.
7586 static decl_node
getRecord (decl_node n
)
7588 mcDebug_assert (n
->kind
!= decl_varient
); /* if this fails then we need to add parent field to varient. */
7592 return n
; /* if this fails then we need to add parent field to varient. */
7595 case decl_varientfield
:
7596 return getRecord (getParent (n
));
7601 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
7602 __builtin_unreachable ();
7604 /* static analysis guarentees a RETURN statement will be used before here. */
7605 __builtin_unreachable ();
7610 isConstExp - return TRUE if the node kind is a constexp.
7613 static bool isConstExp (decl_node c
)
7615 mcDebug_assert (c
!= NULL
);
7616 return c
->kind
== decl_constexp
;
7617 /* static analysis guarentees a RETURN statement will be used before here. */
7618 __builtin_unreachable ();
7623 addEnumToModule - adds enumeration type, e, into the list of enums
7627 static void addEnumToModule (decl_node m
, decl_node e
)
7629 mcDebug_assert ((decl_isEnumeration (e
)) || (decl_isEnumerationField (e
)));
7630 mcDebug_assert (((decl_isModule (m
)) || (decl_isDef (m
))) || (decl_isImp (m
)));
7631 if (decl_isModule (m
))
7633 Indexing_IncludeIndiceIntoIndex (m
->moduleF
.enumFixup
.info
, reinterpret_cast<void *> (e
));
7635 else if (decl_isDef (m
))
7637 /* avoid dangling else. */
7638 Indexing_IncludeIndiceIntoIndex (m
->defF
.enumFixup
.info
, reinterpret_cast<void *> (e
));
7640 else if (decl_isImp (m
))
7642 /* avoid dangling else. */
7643 Indexing_IncludeIndiceIntoIndex (m
->impF
.enumFixup
.info
, reinterpret_cast<void *> (e
));
7649 getNextFixup - return the next fixup from from f.
7652 static decl_node
getNextFixup (decl_fixupInfo
*f
)
7655 return static_cast<decl_node
> (Indexing_GetIndice ((*f
).info
, (*f
).count
));
7656 /* static analysis guarentees a RETURN statement will be used before here. */
7657 __builtin_unreachable ();
7662 doMakeEnum - create an enumeration type and add it to the current module.
7665 static decl_node
doMakeEnum (void)
7669 e
= newNode (decl_enumeration
);
7670 e
->enumerationF
.noOfElements
= 0;
7671 e
->enumerationF
.localSymbols
= symbolKey_initTree ();
7672 e
->enumerationF
.scope
= decl_getDeclScope ();
7673 e
->enumerationF
.listOfSons
= Indexing_InitIndex (1);
7674 e
->enumerationF
.low
= NULL
;
7675 e
->enumerationF
.high
= NULL
;
7676 addEnumToModule (currentModule
, e
);
7678 /* static analysis guarentees a RETURN statement will be used before here. */
7679 __builtin_unreachable ();
7684 doMakeEnumField - create an enumeration field name and add it to enumeration e.
7685 Return the new field.
7688 static decl_node
doMakeEnumField (decl_node e
, nameKey_Name n
)
7692 mcDebug_assert (decl_isEnumeration (e
));
7693 f
= decl_lookupSym (n
);
7696 f
= newNode (decl_enumerationfield
);
7697 symbolKey_putSymKey (e
->enumerationF
.localSymbols
, n
, reinterpret_cast<void *> (f
));
7698 Indexing_IncludeIndiceIntoIndex (e
->enumerationF
.listOfSons
, reinterpret_cast<void *> (f
));
7699 f
->enumerationfieldF
.name
= n
;
7700 f
->enumerationfieldF
.type
= e
;
7701 f
->enumerationfieldF
.scope
= decl_getDeclScope ();
7702 f
->enumerationfieldF
.value
= e
->enumerationF
.noOfElements
;
7703 initCname (&f
->enumerationfieldF
.cname
);
7704 e
->enumerationF
.noOfElements
+= 1;
7705 mcDebug_assert ((Indexing_GetIndice (e
->enumerationF
.listOfSons
, e
->enumerationF
.noOfElements
)) == f
);
7706 addEnumToModule (currentModule
, f
);
7707 if (e
->enumerationF
.low
== NULL
)
7709 e
->enumerationF
.low
= f
;
7711 e
->enumerationF
.high
= f
;
7712 return addToScope (f
);
7716 mcMetaError_metaErrors2 ((const char *) "cannot create enumeration field {%1k} as the name is already in use", 67, (const char *) "{%2DMad} was declared elsewhere", 31, (const unsigned char *) &n
, (sizeof (n
)-1), (const unsigned char *) &f
, (sizeof (f
)-1));
7719 /* static analysis guarentees a RETURN statement will be used before here. */
7720 __builtin_unreachable ();
7725 getExpList - returns the, n, th argument in an explist.
7728 static decl_node
getExpList (decl_node p
, unsigned int n
)
7730 mcDebug_assert (p
!= NULL
);
7731 mcDebug_assert (decl_isExpList (p
));
7732 mcDebug_assert (n
<= (Indexing_HighIndice (p
->explistF
.exp
)));
7733 return static_cast<decl_node
> (Indexing_GetIndice (p
->explistF
.exp
, n
));
7734 /* static analysis guarentees a RETURN statement will be used before here. */
7735 __builtin_unreachable ();
7740 expListLen - returns the length of explist, p.
7743 static unsigned int expListLen (decl_node p
)
7751 mcDebug_assert (decl_isExpList (p
));
7752 return Indexing_HighIndice (p
->explistF
.exp
);
7754 /* static analysis guarentees a RETURN statement will be used before here. */
7755 __builtin_unreachable ();
7760 getConstExpComplete - gets the field from the def or imp or module, n.
7763 static bool getConstExpComplete (decl_node n
)
7768 return n
->defF
.constsComplete
;
7772 return n
->impF
.constsComplete
;
7776 return n
->moduleF
.constsComplete
;
7781 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
7782 __builtin_unreachable ();
7784 /* static analysis guarentees a RETURN statement will be used before here. */
7785 __builtin_unreachable ();
7790 addConstToModule - adds const exp, e, into the list of constant
7791 expressions in module, m.
7794 static void addConstToModule (decl_node m
, decl_node e
)
7796 mcDebug_assert (((decl_isModule (m
)) || (decl_isDef (m
))) || (decl_isImp (m
)));
7797 if (decl_isModule (m
))
7799 Indexing_IncludeIndiceIntoIndex (m
->moduleF
.constFixup
.info
, reinterpret_cast<void *> (e
));
7801 else if (decl_isDef (m
))
7803 /* avoid dangling else. */
7804 Indexing_IncludeIndiceIntoIndex (m
->defF
.constFixup
.info
, reinterpret_cast<void *> (e
));
7806 else if (decl_isImp (m
))
7808 /* avoid dangling else. */
7809 Indexing_IncludeIndiceIntoIndex (m
->impF
.constFixup
.info
, reinterpret_cast<void *> (e
));
7815 doMakeConstExp - create a constexp node and add it to the current module.
7818 static decl_node
doMakeConstExp (void)
7822 c
= makeUnary (decl_constexp
, NULL
, NULL
);
7823 addConstToModule (currentModule
, c
);
7825 /* static analysis guarentees a RETURN statement will be used before here. */
7826 __builtin_unreachable ();
7831 isAnyType - return TRUE if node n is any type kind.
7834 static bool isAnyType (decl_node n
)
7836 mcDebug_assert (n
!= NULL
);
7846 case decl_shortcard
:
7851 case decl_longcomplex
:
7852 case decl_shortcomplex
:
7865 /* static analysis guarentees a RETURN statement will be used before here. */
7866 __builtin_unreachable ();
7871 makeVal - creates a VAL (type, expression) node.
7874 static decl_node
makeVal (decl_node params
)
7876 mcDebug_assert (decl_isExpList (params
));
7877 if ((expListLen (params
)) == 2)
7879 return makeBinary (decl_val
, getExpList (params
, 1), getExpList (params
, 2), getExpList (params
, 1));
7884 __builtin_unreachable ();
7886 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
7887 __builtin_unreachable ();
7892 makeCast - creates a cast node TYPENAME (expr).
7895 static decl_node
makeCast (decl_node c
, decl_node p
)
7897 mcDebug_assert (decl_isExpList (p
));
7898 if ((expListLen (p
)) == 1)
7900 return makeBinary (decl_cast
, c
, getExpList (p
, 1), c
);
7905 __builtin_unreachable ();
7907 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
7908 __builtin_unreachable ();
7911 static decl_node
makeIntrinsicProc (decl_nodeT k
, unsigned int noArgs
, decl_node p
)
7916 makeIntrisicProc - create an intrinsic node.
7919 f
->intrinsicF
.args
= p
;
7920 f
->intrinsicF
.noArgs
= noArgs
;
7921 f
->intrinsicF
.type
= NULL
;
7922 f
->intrinsicF
.postUnreachable
= k
== decl_halt
;
7923 initPair (&f
->intrinsicF
.intrinsicComment
);
7925 /* static analysis guarentees a RETURN statement will be used before here. */
7926 __builtin_unreachable ();
7931 makeIntrinsicUnaryType - create an intrisic unary type.
7934 static decl_node
makeIntrinsicUnaryType (decl_nodeT k
, decl_node paramList
, decl_node returnType
)
7936 return makeUnary (k
, getExpList (paramList
, 1), returnType
);
7937 /* static analysis guarentees a RETURN statement will be used before here. */
7938 __builtin_unreachable ();
7943 makeIntrinsicBinaryType - create an intrisic binary type.
7946 static decl_node
makeIntrinsicBinaryType (decl_nodeT k
, decl_node paramList
, decl_node returnType
)
7948 return makeBinary (k
, getExpList (paramList
, 1), getExpList (paramList
, 2), returnType
);
7949 /* static analysis guarentees a RETURN statement will be used before here. */
7950 __builtin_unreachable ();
7955 checkIntrinsic - checks to see if the function call to, c, with
7956 parameter list, n, is really an intrinic. If it
7957 is an intrinic then an intrinic node is created
7958 and returned. Otherwise NIL is returned.
7961 static decl_node
checkIntrinsic (decl_node c
, decl_node n
)
7965 return makeCast (c
, n
);
7969 /* avoid dangling else. */
7970 return makeIntrinsicUnaryType (decl_max
, n
, NULL
);
7974 /* avoid dangling else. */
7975 return makeIntrinsicUnaryType (decl_min
, n
, NULL
);
7977 else if (c
== haltN
)
7979 /* avoid dangling else. */
7980 return makeIntrinsicProc (decl_halt
, expListLen (n
), n
);
7984 /* avoid dangling else. */
7989 /* avoid dangling else. */
7990 return makeIntrinsicUnaryType (decl_adr
, n
, addressN
);
7992 else if (c
== sizeN
)
7994 /* avoid dangling else. */
7995 return makeIntrinsicUnaryType (decl_size
, n
, cardinalN
);
7997 else if (c
== tsizeN
)
7999 /* avoid dangling else. */
8000 return makeIntrinsicUnaryType (decl_tsize
, n
, cardinalN
);
8002 else if (c
== floatN
)
8004 /* avoid dangling else. */
8005 return makeIntrinsicUnaryType (decl_float
, n
, realN
);
8007 else if (c
== truncN
)
8009 /* avoid dangling else. */
8010 return makeIntrinsicUnaryType (decl_trunc
, n
, integerN
);
8014 /* avoid dangling else. */
8015 return makeIntrinsicUnaryType (decl_ord
, n
, cardinalN
);
8019 /* avoid dangling else. */
8020 return makeIntrinsicUnaryType (decl_chr
, n
, charN
);
8024 /* avoid dangling else. */
8025 return makeIntrinsicUnaryType (decl_cap
, n
, charN
);
8029 /* avoid dangling else. */
8030 return makeIntrinsicUnaryType (decl_abs
, n
, NULL
);
8034 /* avoid dangling else. */
8035 return makeIntrinsicUnaryType (decl_im
, n
, NULL
);
8039 /* avoid dangling else. */
8040 return makeIntrinsicUnaryType (decl_re
, n
, NULL
);
8042 else if (c
== cmplxN
)
8044 /* avoid dangling else. */
8045 return makeIntrinsicBinaryType (decl_cmplx
, n
, NULL
);
8047 else if (c
== highN
)
8049 /* avoid dangling else. */
8050 return makeIntrinsicUnaryType (decl_high
, n
, cardinalN
);
8054 /* avoid dangling else. */
8055 return makeIntrinsicProc (decl_inc
, expListLen (n
), n
);
8059 /* avoid dangling else. */
8060 return makeIntrinsicProc (decl_dec
, expListLen (n
), n
);
8062 else if (c
== inclN
)
8064 /* avoid dangling else. */
8065 return makeIntrinsicProc (decl_incl
, expListLen (n
), n
);
8067 else if (c
== exclN
)
8069 /* avoid dangling else. */
8070 return makeIntrinsicProc (decl_excl
, expListLen (n
), n
);
8074 /* avoid dangling else. */
8075 return makeIntrinsicProc (decl_new
, 1, n
);
8077 else if (c
== disposeN
)
8079 /* avoid dangling else. */
8080 return makeIntrinsicProc (decl_dispose
, 1, n
);
8082 else if (c
== lengthN
)
8084 /* avoid dangling else. */
8085 return makeIntrinsicUnaryType (decl_length
, n
, cardinalN
);
8087 else if (c
== throwN
)
8089 /* avoid dangling else. */
8091 return makeIntrinsicProc (decl_throw
, 1, n
);
8094 /* static analysis guarentees a RETURN statement will be used before here. */
8095 __builtin_unreachable ();
8100 checkCHeaders - check to see if the function is a C system function and
8101 requires a header file included.
8104 static void checkCHeaders (decl_node c
)
8109 if (decl_isProcedure (c
))
8111 s
= decl_getScope (c
);
8112 if ((decl_getSymName (s
)) == (nameKey_makeKey ((const char *) "libc", 4)))
8114 name
= decl_getSymName (c
);
8115 if ((((name
== (nameKey_makeKey ((const char *) "read", 4))) || (name
== (nameKey_makeKey ((const char *) "write", 5)))) || (name
== (nameKey_makeKey ((const char *) "open", 4)))) || (name
== (nameKey_makeKey ((const char *) "close", 5))))
8125 isFuncCall - returns TRUE if, n, is a function/procedure call.
8128 static bool isFuncCall (decl_node n
)
8130 mcDebug_assert (n
!= NULL
);
8131 return n
->kind
== decl_funccall
;
8132 /* static analysis guarentees a RETURN statement will be used before here. */
8133 __builtin_unreachable ();
8138 putTypeInternal - marks type, des, as being an internally generated type.
8141 static void putTypeInternal (decl_node des
)
8143 mcDebug_assert (des
!= NULL
);
8144 mcDebug_assert (decl_isType (des
));
8145 des
->typeF
.isInternal
= true;
8150 isTypeInternal - returns TRUE if type, n, is internal.
8153 static bool isTypeInternal (decl_node n
)
8155 mcDebug_assert (n
!= NULL
);
8156 mcDebug_assert (decl_isType (n
));
8157 return n
->typeF
.isInternal
;
8158 /* static analysis guarentees a RETURN statement will be used before here. */
8159 __builtin_unreachable ();
8164 lookupBase - return node named n from the base symbol scope.
8167 static decl_node
lookupBase (nameKey_Name n
)
8171 m
= static_cast<decl_node
> (symbolKey_getSymKey (baseSymbols
, n
));
8176 else if (((m
== complexN
) || (m
== longcomplexN
)) || (m
== shortcomplexN
))
8178 /* avoid dangling else. */
8182 /* static analysis guarentees a RETURN statement will be used before here. */
8183 __builtin_unreachable ();
8188 dumpScopes - display the names of all the scopes stacked.
8191 static void dumpScopes (void)
8196 h
= Indexing_HighIndice (scopeStack
);
8197 libc_printf ((const char *) "total scopes stacked %d\\n", 25, h
);
8200 s
= static_cast<decl_node
> (Indexing_GetIndice (scopeStack
, h
));
8201 out2 ((const char *) " scope [%d] is %s\\n", 19, h
, s
);
8208 out0 - write string a to StdOut.
8211 static void out0 (const char *a_
, unsigned int _a_high
)
8213 DynamicStrings_String m
;
8216 /* make a local copy of each unbounded array. */
8217 memcpy (a
, a_
, _a_high
+1);
8219 m
= FormatStrings_Sprintf0 (DynamicStrings_InitString ((const char *) a
, _a_high
));
8220 m
= DynamicStrings_KillString (SFIO_WriteS (FIO_StdOut
, m
));
8225 out1 - write string a to StdOut using format specifier a.
8228 static void out1 (const char *a_
, unsigned int _a_high
, decl_node s
)
8230 DynamicStrings_String m
;
8234 /* make a local copy of each unbounded array. */
8235 memcpy (a
, a_
, _a_high
+1);
8237 m
= getFQstring (s
);
8238 if (DynamicStrings_EqualArray (m
, (const char *) "", 0))
8240 d
= (unsigned int ) ((long unsigned int ) (s
));
8241 m
= DynamicStrings_KillString (m
);
8242 m
= FormatStrings_Sprintf1 (DynamicStrings_InitString ((const char *) "[%d]", 4), (const unsigned char *) &d
, (sizeof (d
)-1));
8244 m
= FormatStrings_Sprintf1 (DynamicStrings_InitString ((const char *) a
, _a_high
), (const unsigned char *) &m
, (sizeof (m
)-1));
8245 m
= DynamicStrings_KillString (SFIO_WriteS (FIO_StdOut
, m
));
8250 out2 - write string a to StdOut using format specifier a.
8253 static void out2 (const char *a_
, unsigned int _a_high
, unsigned int c
, decl_node s
)
8255 DynamicStrings_String m
;
8256 DynamicStrings_String m1
;
8259 /* make a local copy of each unbounded array. */
8260 memcpy (a
, a_
, _a_high
+1);
8263 m
= FormatStrings_Sprintf2 (DynamicStrings_InitString ((const char *) a
, _a_high
), (const unsigned char *) &c
, (sizeof (c
)-1), (const unsigned char *) &m1
, (sizeof (m1
)-1));
8264 m
= DynamicStrings_KillString (SFIO_WriteS (FIO_StdOut
, m
));
8265 m1
= DynamicStrings_KillString (m1
);
8270 out3 - write string a to StdOut using format specifier a.
8273 static void out3 (const char *a_
, unsigned int _a_high
, unsigned int l
, nameKey_Name n
, decl_node s
)
8275 DynamicStrings_String m
;
8276 DynamicStrings_String m1
;
8277 DynamicStrings_String m2
;
8280 /* make a local copy of each unbounded array. */
8281 memcpy (a
, a_
, _a_high
+1);
8283 m1
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
));
8285 m
= FormatStrings_Sprintf3 (DynamicStrings_InitString ((const char *) a
, _a_high
), (const unsigned char *) &l
, (sizeof (l
)-1), (const unsigned char *) &m1
, (sizeof (m1
)-1), (const unsigned char *) &m2
, (sizeof (m2
)-1));
8286 m
= DynamicStrings_KillString (SFIO_WriteS (FIO_StdOut
, m
));
8287 m1
= DynamicStrings_KillString (m1
);
8288 m2
= DynamicStrings_KillString (m2
);
8293 isUnary - returns TRUE if, n, is an unary node.
8296 static bool isUnary (decl_node n
)
8298 mcDebug_assert (n
!= NULL
);
8328 /* static analysis guarentees a RETURN statement will be used before here. */
8329 __builtin_unreachable ();
8334 isBinary - returns TRUE if, n, is an binary node.
8337 static bool isBinary (decl_node n
)
8339 mcDebug_assert (n
!= NULL
);
8350 case decl_lessequal
:
8368 /* static analysis guarentees a RETURN statement will be used before here. */
8369 __builtin_unreachable ();
8374 makeUnary - create a unary expression node with, e, as the argument
8375 and res as the return type.
8378 static decl_node
makeUnary (decl_nodeT k
, decl_node e
, decl_node res
)
8412 n
->unaryF
.resultType
= res
;
8417 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
8418 __builtin_unreachable ();
8422 /* static analysis guarentees a RETURN statement will be used before here. */
8423 __builtin_unreachable ();
8428 isLeafString - returns TRUE if n is a leaf node which is a string constant.
8431 static bool isLeafString (decl_node n
)
8433 return ((isString (n
)) || ((decl_isLiteral (n
)) && ((decl_getType (n
)) == charN
))) || ((decl_isConst (n
)) && ((getExprType (n
)) == charN
));
8434 /* static analysis guarentees a RETURN statement will be used before here. */
8435 __builtin_unreachable ();
8440 getLiteralStringContents - return the contents of a literal node as a string.
8443 static DynamicStrings_String
getLiteralStringContents (decl_node n
)
8445 DynamicStrings_String number
;
8446 DynamicStrings_String content
;
8447 DynamicStrings_String s
;
8449 mcDebug_assert (n
->kind
== decl_literal
);
8450 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
->literalF
.name
));
8452 if (n
->literalF
.type
== charN
)
8454 if ((DynamicStrings_char (s
, -1)) == 'C')
8456 if ((DynamicStrings_Length (s
)) > 1)
8458 number
= DynamicStrings_Slice (s
, 0, -1);
8459 content
= DynamicStrings_InitStringChar ((char ) (StringConvert_ostoc (number
)));
8460 number
= DynamicStrings_KillString (number
);
8464 content
= DynamicStrings_InitStringChar ('C');
8469 content
= DynamicStrings_Dup (s
);
8474 mcMetaError_metaError1 ((const char *) "cannot obtain string contents from {%1k}", 40, (const unsigned char *) &n
->literalF
.name
, (sizeof (n
->literalF
.name
)-1));
8476 s
= DynamicStrings_KillString (s
);
8478 /* static analysis guarentees a RETURN statement will be used before here. */
8479 __builtin_unreachable ();
8484 getStringContents - return the string contents of a constant, literal,
8485 string or a constexp node.
8488 static DynamicStrings_String
getStringContents (decl_node n
)
8490 if (decl_isConst (n
))
8492 return getStringContents (n
->constF
.value
);
8494 else if (decl_isLiteral (n
))
8496 /* avoid dangling else. */
8497 return getLiteralStringContents (n
);
8499 else if (isString (n
))
8501 /* avoid dangling else. */
8502 return getString (n
);
8504 else if (isConstExp (n
))
8506 /* avoid dangling else. */
8507 return getStringContents (n
->unaryF
.arg
);
8510 __builtin_unreachable ();
8511 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
8512 __builtin_unreachable ();
8520 static nameKey_Name
addNames (decl_node a
, decl_node b
)
8522 DynamicStrings_String sa
;
8523 DynamicStrings_String sb
;
8526 sa
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (a
)));
8527 sb
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (b
)));
8528 sa
= DynamicStrings_ConCat (sa
, sb
);
8529 n
= nameKey_makekey (DynamicStrings_string (sa
));
8530 sa
= DynamicStrings_KillString (sa
);
8531 sb
= DynamicStrings_KillString (sb
);
8533 /* static analysis guarentees a RETURN statement will be used before here. */
8534 __builtin_unreachable ();
8542 static decl_node
resolveString (decl_node n
)
8544 while ((decl_isConst (n
)) || (isConstExp (n
)))
8546 if (decl_isConst (n
))
8548 n
= n
->constF
.value
;
8555 if (n
->kind
== decl_plus
)
8557 n
= decl_makeString (addNames (resolveString (n
->binaryF
.left
), resolveString (n
->binaryF
.right
)));
8560 /* static analysis guarentees a RETURN statement will be used before here. */
8561 __builtin_unreachable ();
8569 static decl_node
foldBinary (decl_nodeT k
, decl_node l
, decl_node r
, decl_node res
)
8572 DynamicStrings_String ls
;
8573 DynamicStrings_String rs
;
8576 if (((k
== decl_plus
) && (isLeafString (l
))) && (isLeafString (r
)))
8578 ls
= getStringContents (l
);
8579 rs
= getStringContents (r
);
8580 ls
= DynamicStrings_Add (ls
, rs
);
8581 n
= decl_makeString (nameKey_makekey (DynamicStrings_string (ls
)));
8582 ls
= DynamicStrings_KillString (ls
);
8583 rs
= DynamicStrings_KillString (rs
);
8586 /* static analysis guarentees a RETURN statement will be used before here. */
8587 __builtin_unreachable ();
8592 makeBinary - create a binary node with left/right/result type: l, r and resultType.
8595 static decl_node
makeBinary (decl_nodeT k
, decl_node l
, decl_node r
, decl_node resultType
)
8599 n
= foldBinary (k
, l
, r
, resultType
);
8602 n
= doMakeBinary (k
, l
, r
, resultType
);
8605 /* static analysis guarentees a RETURN statement will be used before here. */
8606 __builtin_unreachable ();
8611 doMakeBinary - returns a binary node containing left/right/result values
8612 l, r, res, with a node operator, k.
8615 static decl_node
doMakeBinary (decl_nodeT k
, decl_node l
, decl_node r
, decl_node res
)
8628 case decl_lessequal
:
8640 n
->binaryF
.left
= l
;
8641 n
->binaryF
.right
= r
;
8642 n
->binaryF
.resultType
= res
;
8647 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
8648 __builtin_unreachable ();
8651 /* static analysis guarentees a RETURN statement will be used before here. */
8652 __builtin_unreachable ();
8657 doMakeComponentRef -
8660 static decl_node
doMakeComponentRef (decl_node rec
, decl_node field
)
8664 n
= newNode (decl_componentref
);
8665 n
->componentrefF
.rec
= rec
;
8666 n
->componentrefF
.field
= field
;
8667 n
->componentrefF
.resultType
= decl_getType (field
);
8669 /* static analysis guarentees a RETURN statement will be used before here. */
8670 __builtin_unreachable ();
8678 static bool isComponentRef (decl_node n
)
8680 mcDebug_assert (n
!= NULL
);
8681 return n
->kind
== decl_componentref
;
8682 /* static analysis guarentees a RETURN statement will be used before here. */
8683 __builtin_unreachable ();
8688 isArrayRef - returns TRUE if the node was an arrayref.
8691 static bool isArrayRef (decl_node n
)
8693 mcDebug_assert (n
!= NULL
);
8694 return n
->kind
== decl_arrayref
;
8695 /* static analysis guarentees a RETURN statement will be used before here. */
8696 __builtin_unreachable ();
8701 isDeref - returns TRUE if, n, is a deref node.
8704 static bool isDeref (decl_node n
)
8706 mcDebug_assert (n
!= NULL
);
8707 return n
->kind
== decl_deref
;
8708 /* static analysis guarentees a RETURN statement will be used before here. */
8709 __builtin_unreachable ();
8714 makeBase - create a base type or constant.
8715 It only supports the base types and constants
8719 static decl_node
makeBase (decl_nodeT k
)
8745 case decl_shortcard
:
8751 case decl_shortreal
:
8758 case decl_longcomplex
:
8759 case decl_shortcomplex
:
8781 M2RTS_HALT (-1); /* legal kind. */
8782 __builtin_unreachable ();
8786 /* static analysis guarentees a RETURN statement will be used before here. */
8787 __builtin_unreachable ();
8792 isOrdinal - returns TRUE if, n, is an ordinal type.
8795 static bool isOrdinal (decl_node n
)
8811 case decl_shortcard
:
8821 /* static analysis guarentees a RETURN statement will be used before here. */
8822 __builtin_unreachable ();
8830 static decl_node
mixTypes (decl_node a
, decl_node b
)
8832 if ((a
== addressN
) || (b
== addressN
))
8837 /* static analysis guarentees a RETURN statement will be used before here. */
8838 __builtin_unreachable ();
8846 static decl_node
doSetExprType (decl_node
*t
, decl_node n
)
8853 /* static analysis guarentees a RETURN statement will be used before here. */
8854 __builtin_unreachable ();
8862 static decl_node
getMaxMinType (decl_node n
)
8864 if ((decl_isVar (n
)) || (decl_isConst (n
)))
8866 return decl_getType (n
);
8868 else if (isConstExp (n
))
8870 /* avoid dangling else. */
8871 n
= getExprType (n
->unaryF
.arg
);
8883 /* avoid dangling else. */
8886 /* static analysis guarentees a RETURN statement will be used before here. */
8887 __builtin_unreachable ();
8895 static decl_node
doGetFuncType (decl_node n
)
8897 mcDebug_assert (isFuncCall (n
));
8898 return doSetExprType (&n
->funccallF
.type
, decl_getType (n
->funccallF
.function
));
8899 /* static analysis guarentees a RETURN statement will be used before here. */
8900 __builtin_unreachable ();
8905 doGetExprType - works out the type which is associated with node, n.
8908 static decl_node
doGetExprType (decl_node n
)
8914 return getMaxMinType (n
->unaryF
.arg
);
8919 return doSetExprType (&n
->binaryF
.resultType
, n
->binaryF
.left
);
8989 case decl_shortcard
:
9013 case decl_shortreal
:
9033 case decl_longcomplex
:
9037 case decl_shortcomplex
:
9042 /* language features and compound type attributes. */
9043 return n
->typeF
.type
;
9055 return n
->varF
.type
;
9058 case decl_enumeration
:
9063 return n
->subrangeF
.type
;
9067 return n
->arrayF
.type
;
9075 return doSetExprType (&n
->constF
.type
, getExprType (n
->constF
.value
));
9079 return n
->literalF
.type
;
9083 return n
->varparamF
.type
;
9087 return n
->paramF
.type
;
9091 return n
->optargF
.type
;
9095 return n
->pointerF
.type
;
9098 case decl_recordfield
:
9099 return n
->recordfieldF
.type
;
9102 case decl_varientfield
:
9106 case decl_enumerationfield
:
9107 return n
->enumerationfieldF
.type
;
9111 return n
->setF
.type
;
9115 return n
->proctypeF
.returnType
;
9118 case decl_subscript
:
9119 return n
->subscriptF
.type
;
9122 case decl_procedure
:
9124 return n
->procedureF
.returnType
;
9131 case decl_unreachable
:
9144 case decl_assignment
:
9147 __builtin_unreachable ();
9157 return doSetExprType (&n
->binaryF
.resultType
, mixTypes (getExprType (n
->binaryF
.left
), getExprType (n
->binaryF
.right
)));
9168 case decl_lessequal
:
9169 return doSetExprType (&n
->binaryF
.resultType
, booleanN
);
9173 return doSetExprType (&n
->binaryF
.resultType
, complexN
);
9180 return doSetExprType (&n
->unaryF
.resultType
, getExprType (n
->unaryF
.arg
));
9184 return doSetExprType (&n
->unaryF
.resultType
, addressN
);
9189 return doSetExprType (&n
->unaryF
.resultType
, cardinalN
);
9194 return doSetExprType (&n
->unaryF
.resultType
, cardinalN
);
9198 return doSetExprType (&n
->unaryF
.resultType
, realN
);
9202 return doSetExprType (&n
->unaryF
.resultType
, integerN
);
9206 return doSetExprType (&n
->unaryF
.resultType
, charN
);
9210 return doSetExprType (&n
->unaryF
.resultType
, charN
);
9214 return doSetExprType (&n
->unaryF
.resultType
, booleanN
);
9218 return doSetExprType (&n
->unaryF
.resultType
, realN
);
9222 return doSetExprType (&n
->unaryF
.resultType
, realN
);
9226 return n
->arrayrefF
.resultType
;
9229 case decl_componentref
:
9230 return n
->componentrefF
.resultType
;
9233 case decl_pointerref
:
9234 return n
->pointerrefF
.resultType
;
9238 return doSetExprType (&n
->funccallF
.type
, doGetFuncType (n
));
9242 return n
->setvalueF
.type
;
9247 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
9248 __builtin_unreachable ();
9251 __builtin_unreachable ();
9252 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
9253 __builtin_unreachable ();
9258 getExprType - return the expression type.
9261 static decl_node
getExprType (decl_node n
)
9265 if (((isFuncCall (n
)) && ((decl_getType (n
)) != NULL
)) && (decl_isProcType (decl_skipType (decl_getType (n
)))))
9267 return decl_getType (decl_skipType (decl_getType (n
)));
9269 t
= decl_getType (n
);
9272 t
= doGetExprType (n
);
9275 /* static analysis guarentees a RETURN statement will be used before here. */
9276 __builtin_unreachable ();
9284 static void openOutput (void)
9286 DynamicStrings_String s
;
9288 s
= mcOptions_getOutputFile ();
9289 if (DynamicStrings_EqualArray (s
, (const char *) "-", 1))
9291 outputFile
= FIO_StdOut
;
9295 outputFile
= SFIO_OpenToWrite (s
);
9297 mcStream_setDest (outputFile
);
9305 static void closeOutput (void)
9307 DynamicStrings_String s
;
9309 s
= mcOptions_getOutputFile ();
9310 outputFile
= mcStream_combine ();
9311 if (! (DynamicStrings_EqualArray (s
, (const char *) "-", 1)))
9313 FIO_Close (outputFile
);
9319 write - outputs a single char, ch.
9322 static void write_ (char ch
)
9324 FIO_WriteChar (outputFile
, ch
);
9325 FIO_FlushBuffer (outputFile
);
9333 static void writeln (void)
9335 FIO_WriteLine (outputFile
);
9336 FIO_FlushBuffer (outputFile
);
9341 doIncludeC - include header file for definition module, n.
9344 static void doIncludeC (decl_node n
)
9346 DynamicStrings_String s
;
9348 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
)));
9349 if (mcOptions_getExtendedOpaque ())
9351 /* no include in this case. */
9352 else if (decl_isDef (n
))
9354 /* avoid dangling else. */
9355 mcPretty_print (doP
, (const char *) "# include \"", 13);
9356 mcPretty_prints (doP
, mcOptions_getHPrefix ());
9357 mcPretty_prints (doP
, s
);
9358 mcPretty_print (doP
, (const char *) ".h\"\\n", 5);
9359 symbolKey_foreachNodeDo (n
->defF
.decls
.symbols
, (symbolKey_performOperation
) {(symbolKey_performOperation_t
) addDoneDef
});
9361 s
= DynamicStrings_KillString (s
);
9366 getSymScope - returns the scope where node, n, was declared.
9369 static decl_node
getSymScope (decl_node n
)
9374 return n
->constF
.scope
;
9378 return n
->typeF
.scope
;
9382 return n
->varF
.scope
;
9385 case decl_procedure
:
9386 return n
->procedureF
.scope
;
9391 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
9392 __builtin_unreachable ();
9395 __builtin_unreachable ();
9396 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
9397 __builtin_unreachable ();
9402 isQualifiedForced - should the node be written with a module prefix?
9405 static bool isQualifiedForced (decl_node n
)
9407 return forceQualified
&& (((((decl_isType (n
)) || (decl_isRecord (n
))) || (decl_isArray (n
))) || (decl_isEnumeration (n
))) || (decl_isEnumerationField (n
)));
9408 /* static analysis guarentees a RETURN statement will be used before here. */
9409 __builtin_unreachable ();
9417 static DynamicStrings_String
getFQstring (decl_node n
)
9419 DynamicStrings_String i
;
9420 DynamicStrings_String s
;
9422 if ((decl_getScope (n
)) == NULL
)
9424 return DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
)));
9426 else if (isQualifiedForced (n
))
9428 /* avoid dangling else. */
9429 i
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
)));
9430 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (decl_getScope (n
))));
9431 return FormatStrings_Sprintf2 (DynamicStrings_InitString ((const char *) "%s_%s", 5), (const unsigned char *) &s
, (sizeof (s
)-1), (const unsigned char *) &i
, (sizeof (i
)-1));
9433 else if ((! (decl_isExported (n
))) || (mcOptions_getIgnoreFQ ()))
9435 /* avoid dangling else. */
9436 return DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
)));
9440 /* avoid dangling else. */
9441 i
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
)));
9442 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (decl_getScope (n
))));
9443 return FormatStrings_Sprintf2 (DynamicStrings_InitString ((const char *) "%s_%s", 5), (const unsigned char *) &s
, (sizeof (s
)-1), (const unsigned char *) &i
, (sizeof (i
)-1));
9445 /* static analysis guarentees a RETURN statement will be used before here. */
9446 __builtin_unreachable ();
9454 static DynamicStrings_String
getFQDstring (decl_node n
, bool scopes
)
9456 DynamicStrings_String i
;
9457 DynamicStrings_String s
;
9459 if ((decl_getScope (n
)) == NULL
)
9461 return DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (getDName (n
, scopes
)));
9463 else if (isQualifiedForced (n
))
9465 /* avoid dangling else. */
9466 /* we assume a qualified name will never conflict. */
9467 i
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
)));
9468 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (decl_getScope (n
))));
9469 return FormatStrings_Sprintf2 (DynamicStrings_InitString ((const char *) "%s_%s", 5), (const unsigned char *) &s
, (sizeof (s
)-1), (const unsigned char *) &i
, (sizeof (i
)-1));
9471 else if ((! (decl_isExported (n
))) || (mcOptions_getIgnoreFQ ()))
9473 /* avoid dangling else. */
9474 return DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (getDName (n
, scopes
)));
9478 /* avoid dangling else. */
9479 /* we assume a qualified name will never conflict. */
9480 i
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
)));
9481 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (decl_getScope (n
))));
9482 return FormatStrings_Sprintf2 (DynamicStrings_InitString ((const char *) "%s_%s", 5), (const unsigned char *) &s
, (sizeof (s
)-1), (const unsigned char *) &i
, (sizeof (i
)-1));
9484 /* static analysis guarentees a RETURN statement will be used before here. */
9485 __builtin_unreachable ();
9490 getString - returns the name as a string.
9493 static DynamicStrings_String
getString (decl_node n
)
9495 if ((decl_getSymName (n
)) == nameKey_NulName
)
9497 return DynamicStrings_InitString ((const char *) "", 0);
9501 return DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
)));
9503 /* static analysis guarentees a RETURN statement will be used before here. */
9504 __builtin_unreachable ();
9512 static void doNone (decl_node n
)
9515 __builtin_unreachable ();
9520 doNothing - does nothing!
9523 static void doNothing (decl_node n
)
9532 static void doConstC (decl_node n
)
9534 if (! (alists_isItemInList (doneQ
, reinterpret_cast<void *> (n
))))
9536 mcPretty_print (doP
, (const char *) "# define ", 11);
9538 mcPretty_setNeedSpace (doP
);
9539 doExprC (doP
, n
->constF
.value
);
9540 mcPretty_print (doP
, (const char *) "\\n", 2);
9541 alists_includeItemIntoList (doneQ
, reinterpret_cast<void *> (n
));
9547 needsParen - returns TRUE if expression, n, needs to be enclosed in ().
9550 static bool needsParen (decl_node n
)
9552 mcDebug_assert (n
!= NULL
);
9562 return needsParen (n
->unaryF
.arg
);
9566 return needsParen (n
->unaryF
.arg
);
9570 return needsParen (n
->unaryF
.arg
);
9594 case decl_lessequal
:
9598 case decl_componentref
:
9602 case decl_pointerref
:
9630 case decl_enumerationfield
:
9660 case decl_recordfield
:
9671 case decl_shortcard
:
9677 case decl_shortreal
:
9679 case decl_longcomplex
:
9680 case decl_shortcomplex
:
9695 case decl_procedure
:
9708 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
9709 __builtin_unreachable ();
9712 /* static analysis guarentees a RETURN statement will be used before here. */
9713 __builtin_unreachable ();
9721 static void doUnary (mcPretty_pretty p
, const char *op_
, unsigned int _op_high
, decl_node expr
, decl_node type
, bool l
, bool r
)
9723 char op
[_op_high
+1];
9725 /* make a local copy of each unbounded array. */
9726 memcpy (op
, op_
, _op_high
+1);
9730 mcPretty_setNeedSpace (p
);
9732 mcPretty_print (p
, (const char *) op
, _op_high
);
9735 mcPretty_setNeedSpace (p
);
9737 if (needsParen (expr
))
9739 outText (p
, (const char *) "(", 1);
9741 outText (p
, (const char *) ")", 1);
9751 doSetSub - perform l & (~ r)
9754 static void doSetSub (mcPretty_pretty p
, decl_node left
, decl_node right
)
9756 if (needsParen (left
))
9758 outText (p
, (const char *) "(", 1);
9760 outText (p
, (const char *) ")", 1);
9766 mcPretty_setNeedSpace (p
);
9767 outText (p
, (const char *) "&", 1);
9768 mcPretty_setNeedSpace (p
);
9769 if (needsParen (right
))
9771 outText (p
, (const char *) "(~(", 3);
9773 outText (p
, (const char *) "))", 2);
9777 outText (p
, (const char *) "(~", 2);
9779 outText (p
, (const char *) ")", 1);
9788 static void doPolyBinary (mcPretty_pretty p
, decl_nodeT op
, decl_node left
, decl_node right
, bool l
, bool r
)
9793 lt
= decl_skipType (getExprType (left
));
9794 rt
= decl_skipType (getExprType (right
));
9795 if (((lt
!= NULL
) && ((decl_isSet (lt
)) || (isBitset (lt
)))) || ((rt
!= NULL
) && ((decl_isSet (rt
)) || (isBitset (rt
)))))
9800 doBinary (p
, (const char *) "|", 1, left
, right
, l
, r
, false);
9804 doSetSub (p
, left
, right
);
9808 doBinary (p
, (const char *) "&", 1, left
, right
, l
, r
, false);
9812 doBinary (p
, (const char *) "^", 1, left
, right
, l
, r
, false);
9817 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
9818 __builtin_unreachable ();
9826 doBinary (p
, (const char *) "+", 1, left
, right
, l
, r
, false);
9830 doBinary (p
, (const char *) "-", 1, left
, right
, l
, r
, false);
9834 doBinary (p
, (const char *) "*", 1, left
, right
, l
, r
, false);
9838 doBinary (p
, (const char *) "/", 1, left
, right
, l
, r
, false);
9843 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
9844 __builtin_unreachable ();
9854 static void doBinary (mcPretty_pretty p
, const char *op_
, unsigned int _op_high
, decl_node left
, decl_node right
, bool l
, bool r
, bool unpackProc
)
9856 char op
[_op_high
+1];
9858 /* make a local copy of each unbounded array. */
9859 memcpy (op
, op_
, _op_high
+1);
9861 if (needsParen (left
))
9863 outText (p
, (const char *) "(", 1);
9864 doExprCup (p
, left
, unpackProc
);
9865 outText (p
, (const char *) ")", 1);
9869 doExprCup (p
, left
, unpackProc
);
9873 mcPretty_setNeedSpace (p
);
9875 outText (p
, (const char *) op
, _op_high
);
9878 mcPretty_setNeedSpace (p
);
9880 if (needsParen (right
))
9882 outText (p
, (const char *) "(", 1);
9883 doExprCup (p
, right
, unpackProc
);
9884 outText (p
, (const char *) ")", 1);
9888 doExprCup (p
, right
, unpackProc
);
9897 static void doPostUnary (mcPretty_pretty p
, const char *op_
, unsigned int _op_high
, decl_node expr
)
9899 char op
[_op_high
+1];
9901 /* make a local copy of each unbounded array. */
9902 memcpy (op
, op_
, _op_high
+1);
9905 outText (p
, (const char *) op
, _op_high
);
9913 static void doDeRefC (mcPretty_pretty p
, decl_node expr
)
9915 outText (p
, (const char *) "(*", 2);
9917 outText (p
, (const char *) ")", 1);
9922 doGetLastOp - returns, a, if b is a terminal otherwise walk right.
9925 static decl_node
doGetLastOp (decl_node a
, decl_node b
)
9942 return doGetLastOp (b
, b
->unaryF
.arg
);
9946 return doGetLastOp (b
, b
->unaryF
.arg
);
9950 return doGetLastOp (b
, b
->unaryF
.arg
);
9954 return doGetLastOp (b
, b
->unaryF
.arg
);
9958 return doGetLastOp (b
, b
->unaryF
.arg
);
9962 return doGetLastOp (b
, b
->unaryF
.arg
);
9966 return doGetLastOp (b
, b
->unaryF
.arg
);
9971 return doGetLastOp (b
, b
->unaryF
.arg
);
9975 return doGetLastOp (b
, b
->unaryF
.arg
);
9979 return doGetLastOp (b
, b
->unaryF
.arg
);
9983 return doGetLastOp (b
, b
->unaryF
.arg
);
9987 return doGetLastOp (b
, b
->unaryF
.arg
);
9992 return doGetLastOp (b
, b
->unaryF
.arg
);
9996 return doGetLastOp (b
, b
->binaryF
.right
);
10000 return doGetLastOp (b
, b
->binaryF
.right
);
10004 return doGetLastOp (b
, b
->binaryF
.right
);
10008 return doGetLastOp (b
, b
->binaryF
.right
);
10011 case decl_greequal
:
10012 return doGetLastOp (b
, b
->binaryF
.right
);
10015 case decl_lessequal
:
10016 return doGetLastOp (b
, b
->binaryF
.right
);
10019 case decl_componentref
:
10020 return doGetLastOp (b
, b
->componentrefF
.field
);
10023 case decl_pointerref
:
10024 return doGetLastOp (b
, b
->pointerrefF
.field
);
10028 return doGetLastOp (b
, b
->binaryF
.right
);
10032 return doGetLastOp (b
, b
->binaryF
.right
);
10036 return doGetLastOp (b
, b
->binaryF
.right
);
10040 return doGetLastOp (b
, b
->binaryF
.right
);
10044 return doGetLastOp (b
, b
->binaryF
.right
);
10048 return doGetLastOp (b
, b
->binaryF
.right
);
10052 return doGetLastOp (b
, b
->binaryF
.right
);
10056 return doGetLastOp (b
, b
->binaryF
.right
);
10060 return doGetLastOp (b
, b
->binaryF
.right
);
10064 return doGetLastOp (b
, b
->binaryF
.right
);
10068 return doGetLastOp (b
, b
->binaryF
.right
);
10072 return doGetLastOp (b
, b
->binaryF
.right
);
10083 case decl_enumerationfield
:
10092 return doGetLastOp (b
, b
->unaryF
.arg
);
10096 return doGetLastOp (b
, b
->unaryF
.arg
);
10103 case decl_arrayref
:
10107 case decl_funccall
:
10111 case decl_procedure
:
10115 case decl_recordfield
:
10121 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
10122 __builtin_unreachable ();
10124 /* static analysis guarentees a RETURN statement will be used before here. */
10125 __builtin_unreachable ();
10133 static void doComponentRefC (mcPretty_pretty p
, decl_node l
, decl_node r
)
10136 outText (p
, (const char *) ".", 1);
10145 static void doPointerRefC (mcPretty_pretty p
, decl_node l
, decl_node r
)
10148 outText (p
, (const char *) "->", 2);
10157 static void doPreBinary (mcPretty_pretty p
, const char *op_
, unsigned int _op_high
, decl_node left
, decl_node right
, bool l
, bool r
)
10159 char op
[_op_high
+1];
10161 /* make a local copy of each unbounded array. */
10162 memcpy (op
, op_
, _op_high
+1);
10166 mcPretty_setNeedSpace (p
);
10168 outText (p
, (const char *) op
, _op_high
);
10171 mcPretty_setNeedSpace (p
);
10173 outText (p
, (const char *) "(", 1);
10175 outText (p
, (const char *) ",", 1);
10176 mcPretty_setNeedSpace (p
);
10177 doExprC (p
, right
);
10178 outText (p
, (const char *) ")", 1);
10186 static void doConstExpr (mcPretty_pretty p
, decl_node n
)
10193 doEnumerationField -
10196 static void doEnumerationField (mcPretty_pretty p
, decl_node n
)
10198 doFQDNameC (p
, n
, false);
10203 isZero - returns TRUE if node, n, is zero.
10206 static bool isZero (decl_node n
)
10208 if (isConstExp (n
))
10210 return isZero (n
->unaryF
.arg
);
10212 return (decl_getSymName (n
)) == (nameKey_makeKey ((const char *) "0", 1));
10213 /* static analysis guarentees a RETURN statement will be used before here. */
10214 __builtin_unreachable ();
10222 static void doArrayRef (mcPretty_pretty p
, decl_node n
)
10228 mcDebug_assert (n
!= NULL
);
10229 mcDebug_assert (isArrayRef (n
));
10230 t
= decl_skipType (decl_getType (n
->arrayrefF
.array
));
10231 if (decl_isUnbounded (t
))
10233 outTextN (p
, decl_getSymName (n
->arrayrefF
.array
));
10237 doExprC (p
, n
->arrayrefF
.array
);
10238 mcDebug_assert (decl_isArray (t
));
10239 outText (p
, (const char *) ".array", 6);
10241 outText (p
, (const char *) "[", 1);
10243 c
= expListLen (n
->arrayrefF
.index
);
10246 doExprC (p
, getExpList (n
->arrayrefF
.index
, i
));
10247 if (decl_isUnbounded (t
))
10249 mcDebug_assert (c
== 1);
10253 doSubtractC (p
, getMin (t
->arrayF
.subr
));
10256 mcDebug_assert (decl_isArray (t
));
10257 outText (p
, (const char *) "].array[", 8);
10258 t
= decl_skipType (decl_getType (t
));
10263 outText (p
, (const char *) "]", 1);
10271 static void doProcedure (mcPretty_pretty p
, decl_node n
)
10273 mcDebug_assert (decl_isProcedure (n
));
10274 doFQDNameC (p
, n
, true);
10282 static void doRecordfield (mcPretty_pretty p
, decl_node n
)
10284 doDNameC (p
, n
, false);
10292 static void doCastC (mcPretty_pretty p
, decl_node t
, decl_node e
)
10296 outText (p
, (const char *) "(", 1);
10297 doTypeNameC (p
, t
);
10298 outText (p
, (const char *) ")", 1);
10299 mcPretty_setNeedSpace (p
);
10300 et
= decl_skipType (decl_getType (e
));
10301 if (((et
!= NULL
) && (isAProcType (et
))) && (isAProcType (decl_skipType (t
))))
10303 outText (p
, (const char *) "{(", 2);
10305 outText (p
, (const char *) "_t)", 3);
10306 mcPretty_setNeedSpace (p
);
10308 outText (p
, (const char *) ".proc}", 6);
10312 outText (p
, (const char *) "(", 1);
10314 outText (p
, (const char *) ")", 1);
10323 static void doSetValueC (mcPretty_pretty p
, decl_node n
)
10329 mcDebug_assert (decl_isSetValue (n
));
10330 lo
= getSetLow (n
);
10331 if (n
->setvalueF
.type
!= NULL
)
10333 outText (p
, (const char *) "(", 1);
10334 doTypeNameC (p
, n
->setvalueF
.type
);
10335 mcPretty_noSpace (p
);
10336 outText (p
, (const char *) ")", 1);
10337 mcPretty_setNeedSpace (p
);
10339 if ((Indexing_HighIndice (n
->setvalueF
.values
)) == 0)
10341 outText (p
, (const char *) "0", 1);
10345 i
= Indexing_LowIndice (n
->setvalueF
.values
);
10346 h
= Indexing_HighIndice (n
->setvalueF
.values
);
10347 outText (p
, (const char *) "(", 1);
10350 outText (p
, (const char *) "(1", 2);
10351 mcPretty_setNeedSpace (p
);
10352 outText (p
, (const char *) "<<", 2);
10353 mcPretty_setNeedSpace (p
);
10354 outText (p
, (const char *) "(", 1);
10355 doExprC (p
, reinterpret_cast<decl_node
> (Indexing_GetIndice (n
->setvalueF
.values
, i
)));
10356 doSubtractC (p
, lo
);
10357 outText (p
, (const char *) ")", 1);
10358 outText (p
, (const char *) ")", 1);
10361 mcPretty_setNeedSpace (p
);
10362 outText (p
, (const char *) "|", 1);
10363 mcPretty_setNeedSpace (p
);
10367 outText (p
, (const char *) ")", 1);
10373 getSetLow - returns the low value of the set type from
10377 static decl_node
getSetLow (decl_node n
)
10381 if ((decl_getType (n
)) == NULL
)
10383 return decl_makeLiteralInt (nameKey_makeKey ((const char *) "0", 1));
10387 type
= decl_skipType (decl_getType (n
));
10388 if (decl_isSet (type
))
10390 return getMin (decl_skipType (decl_getType (type
)));
10394 return decl_makeLiteralInt (nameKey_makeKey ((const char *) "0", 1));
10397 /* static analysis guarentees a RETURN statement will be used before here. */
10398 __builtin_unreachable ();
10403 doInC - performs (((1 << (l)) & (r)) != 0)
10406 static void doInC (mcPretty_pretty p
, decl_node l
, decl_node r
)
10410 lo
= getSetLow (r
);
10411 outText (p
, (const char *) "(((1", 4);
10412 mcPretty_setNeedSpace (p
);
10413 outText (p
, (const char *) "<<", 2);
10414 mcPretty_setNeedSpace (p
);
10415 outText (p
, (const char *) "(", 1);
10417 doSubtractC (p
, lo
);
10418 outText (p
, (const char *) "))", 2);
10419 mcPretty_setNeedSpace (p
);
10420 outText (p
, (const char *) "&", 1);
10421 mcPretty_setNeedSpace (p
);
10422 outText (p
, (const char *) "(", 1);
10424 outText (p
, (const char *) "))", 2);
10425 mcPretty_setNeedSpace (p
);
10426 outText (p
, (const char *) "!=", 2);
10427 mcPretty_setNeedSpace (p
);
10428 outText (p
, (const char *) "0)", 2);
10436 static void doThrowC (mcPretty_pretty p
, decl_node n
)
10438 mcDebug_assert (isIntrinsic (n
));
10439 outText (p
, (const char *) "throw", 5);
10440 mcPretty_setNeedSpace (p
);
10441 outText (p
, (const char *) "(", 1);
10442 if ((expListLen (n
->intrinsicF
.args
)) == 1)
10444 doExprC (p
, getExpList (n
->intrinsicF
.args
, 1));
10446 outText (p
, (const char *) ")", 1);
10454 static void doUnreachableC (mcPretty_pretty p
, decl_node n
)
10456 mcDebug_assert (isIntrinsic (n
));
10457 outText (p
, (const char *) "__builtin_unreachable", 21);
10458 mcPretty_setNeedSpace (p
);
10459 outText (p
, (const char *) "(", 1);
10460 mcDebug_assert ((expListLen (n
->intrinsicF
.args
)) == 0);
10461 outText (p
, (const char *) ")", 1);
10469 static void outNull (mcPretty_pretty p
)
10472 outText (p
, (const char *) "NULL", 4);
10480 static void outTrue (mcPretty_pretty p
)
10483 if ((mcOptions_useBool ()) && (lang
== decl_ansiCP
))
10485 outText (p
, (const char *) "true", 4);
10489 outText (p
, (const char *) "TRUE", 4);
10498 static void outFalse (mcPretty_pretty p
)
10501 if ((mcOptions_useBool ()) && (lang
== decl_ansiCP
))
10503 outText (p
, (const char *) "false", 5);
10507 outText (p
, (const char *) "FALSE", 5);
10516 static void doExprC (mcPretty_pretty p
, decl_node n
)
10520 mcDebug_assert (n
!= NULL
);
10521 t
= getExprType (n
);
10536 case decl_constexp
:
10537 doUnary (p
, (const char *) "", 0, n
->unaryF
.arg
, n
->unaryF
.resultType
, false, false);
10541 doUnary (p
, (const char *) "-", 1, n
->unaryF
.arg
, n
->unaryF
.resultType
, false, false);
10545 doUnary (p
, (const char *) "!", 1, n
->unaryF
.arg
, n
->unaryF
.resultType
, false, true);
10562 doConvertSC (p
, n
, mcOptions_getCRealType ());
10566 doConvertC (p
, n
, (const char *) "int", 3);
10570 doConvertC (p
, n
, (const char *) "unsigned int", 12);
10574 doConvertC (p
, n
, (const char *) "char", 4);
10586 doFuncHighC (p
, n
->unaryF
.arg
);
10605 case decl_unreachable
:
10606 doUnreachableC (p
, n
);
10622 doDeRefC (p
, n
->unaryF
.arg
);
10626 doBinary (p
, (const char *) "==", 2, n
->binaryF
.left
, n
->binaryF
.right
, true, true, true);
10629 case decl_notequal
:
10630 doBinary (p
, (const char *) "!=", 2, n
->binaryF
.left
, n
->binaryF
.right
, true, true, true);
10634 doBinary (p
, (const char *) "<", 1, n
->binaryF
.left
, n
->binaryF
.right
, true, true, false);
10638 doBinary (p
, (const char *) ">", 1, n
->binaryF
.left
, n
->binaryF
.right
, true, true, false);
10641 case decl_greequal
:
10642 doBinary (p
, (const char *) ">=", 2, n
->binaryF
.left
, n
->binaryF
.right
, true, true, false);
10645 case decl_lessequal
:
10646 doBinary (p
, (const char *) "<=", 2, n
->binaryF
.left
, n
->binaryF
.right
, true, true, false);
10649 case decl_componentref
:
10650 doComponentRefC (p
, n
->componentrefF
.rec
, n
->componentrefF
.field
);
10653 case decl_pointerref
:
10654 doPointerRefC (p
, n
->pointerrefF
.ptr
, n
->pointerrefF
.field
);
10658 doCastC (p
, n
->binaryF
.left
, n
->binaryF
.right
);
10662 doPolyBinary (p
, decl_plus
, n
->binaryF
.left
, n
->binaryF
.right
, false, false);
10666 doPolyBinary (p
, decl_sub
, n
->binaryF
.left
, n
->binaryF
.right
, false, false);
10670 doBinary (p
, (const char *) "/", 1, n
->binaryF
.left
, n
->binaryF
.right
, true, true, false);
10674 doBinary (p
, (const char *) "%", 1, n
->binaryF
.left
, n
->binaryF
.right
, true, true, false);
10678 doPolyBinary (p
, decl_mult
, n
->binaryF
.left
, n
->binaryF
.right
, false, false);
10682 doPolyBinary (p
, decl_divide
, n
->binaryF
.left
, n
->binaryF
.right
, false, false);
10686 doInC (p
, n
->binaryF
.left
, n
->binaryF
.right
);
10690 doBinary (p
, (const char *) "&&", 2, n
->binaryF
.left
, n
->binaryF
.right
, true, true, false);
10694 doBinary (p
, (const char *) "||", 2, n
->binaryF
.left
, n
->binaryF
.right
, true, true, false);
10702 doConstExpr (p
, n
);
10705 case decl_enumerationfield
:
10706 doEnumerationField (p
, n
);
10717 case decl_arrayref
:
10721 case decl_funccall
:
10722 doFuncExprC (p
, n
);
10725 case decl_procedure
:
10726 doProcedure (p
, n
);
10729 case decl_recordfield
:
10730 doRecordfield (p
, n
);
10733 case decl_setvalue
:
10734 doSetValueC (p
, n
);
10738 case decl_cardinal
:
10739 case decl_longcard
:
10740 case decl_shortcard
:
10743 case decl_shortint
:
10745 case decl_longcomplex
:
10746 case decl_shortcomplex
:
10748 case decl_longreal
:
10749 case decl_shortreal
:
10766 doTypeNameC (p
, n
);
10770 doTypeNameC (p
, n
);
10775 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
10776 __builtin_unreachable ();
10785 static void doExprCup (mcPretty_pretty p
, decl_node n
, bool unpackProc
)
10792 t
= decl_skipType (getExprType (n
));
10793 if ((t
!= NULL
) && (isAProcType (t
)))
10795 outText (p
, (const char *) ".proc", 5);
10805 static void doExprM2 (mcPretty_pretty p
, decl_node n
)
10807 mcDebug_assert (n
!= NULL
);
10811 outText (p
, (const char *) "NIL", 3);
10815 outText (p
, (const char *) "TRUE", 4);
10819 outText (p
, (const char *) "FALSE", 5);
10822 case decl_constexp
:
10823 doUnary (p
, (const char *) "", 0, n
->unaryF
.arg
, n
->unaryF
.resultType
, false, false);
10827 doUnary (p
, (const char *) "-", 1, n
->unaryF
.arg
, n
->unaryF
.resultType
, false, false);
10831 doUnary (p
, (const char *) "NOT", 3, n
->unaryF
.arg
, n
->unaryF
.resultType
, true, true);
10835 doUnary (p
, (const char *) "ADR", 3, n
->unaryF
.arg
, n
->unaryF
.resultType
, true, true);
10839 doUnary (p
, (const char *) "SIZE", 4, n
->unaryF
.arg
, n
->unaryF
.resultType
, true, true);
10843 doUnary (p
, (const char *) "TSIZE", 5, n
->unaryF
.arg
, n
->unaryF
.resultType
, true, true);
10847 doUnary (p
, (const char *) "FLOAT", 5, n
->unaryF
.arg
, n
->unaryF
.resultType
, true, true);
10851 doUnary (p
, (const char *) "TRUNC", 5, n
->unaryF
.arg
, n
->unaryF
.resultType
, true, true);
10855 doUnary (p
, (const char *) "ORD", 3, n
->unaryF
.arg
, n
->unaryF
.resultType
, true, true);
10859 doUnary (p
, (const char *) "CHR", 3, n
->unaryF
.arg
, n
->unaryF
.resultType
, true, true);
10863 doUnary (p
, (const char *) "CAP", 3, n
->unaryF
.arg
, n
->unaryF
.resultType
, true, true);
10867 doUnary (p
, (const char *) "HIGH", 4, n
->unaryF
.arg
, n
->unaryF
.resultType
, true, true);
10871 doUnary (p
, (const char *) "RE", 2, n
->unaryF
.arg
, n
->unaryF
.resultType
, true, true);
10875 doUnary (p
, (const char *) "IM", 2, n
->unaryF
.arg
, n
->unaryF
.resultType
, true, true);
10879 doPostUnary (p
, (const char *) "^", 1, n
->unaryF
.arg
);
10883 doBinary (p
, (const char *) "=", 1, n
->binaryF
.left
, n
->binaryF
.right
, true, true, false);
10886 case decl_notequal
:
10887 doBinary (p
, (const char *) "#", 1, n
->binaryF
.left
, n
->binaryF
.right
, true, true, false);
10891 doBinary (p
, (const char *) "<", 1, n
->binaryF
.left
, n
->binaryF
.right
, true, true, false);
10895 doBinary (p
, (const char *) ">", 1, n
->binaryF
.left
, n
->binaryF
.right
, true, true, false);
10898 case decl_greequal
:
10899 doBinary (p
, (const char *) ">=", 2, n
->binaryF
.left
, n
->binaryF
.right
, true, true, false);
10902 case decl_lessequal
:
10903 doBinary (p
, (const char *) "<=", 2, n
->binaryF
.left
, n
->binaryF
.right
, true, true, false);
10906 case decl_componentref
:
10907 doBinary (p
, (const char *) ".", 1, n
->componentrefF
.rec
, n
->componentrefF
.field
, false, false, false);
10910 case decl_pointerref
:
10911 doBinary (p
, (const char *) "^.", 2, n
->pointerrefF
.ptr
, n
->pointerrefF
.field
, false, false, false);
10915 doPreBinary (p
, (const char *) "CAST", 4, n
->binaryF
.left
, n
->binaryF
.right
, true, true);
10919 doPreBinary (p
, (const char *) "VAL", 3, n
->binaryF
.left
, n
->binaryF
.right
, true, true);
10923 doPreBinary (p
, (const char *) "CMPLX", 5, n
->binaryF
.left
, n
->binaryF
.right
, true, true);
10927 doBinary (p
, (const char *) "+", 1, n
->binaryF
.left
, n
->binaryF
.right
, false, false, false);
10931 doBinary (p
, (const char *) "-", 1, n
->binaryF
.left
, n
->binaryF
.right
, false, false, false);
10935 doBinary (p
, (const char *) "DIV", 3, n
->binaryF
.left
, n
->binaryF
.right
, true, true, false);
10939 doBinary (p
, (const char *) "MOD", 3, n
->binaryF
.left
, n
->binaryF
.right
, true, true, false);
10943 doBinary (p
, (const char *) "*", 1, n
->binaryF
.left
, n
->binaryF
.right
, false, false, false);
10947 doBinary (p
, (const char *) "/", 1, n
->binaryF
.left
, n
->binaryF
.right
, false, false, false);
10955 doConstExpr (p
, n
);
10958 case decl_enumerationfield
:
10959 doEnumerationField (p
, n
);
10967 doUnary (p
, (const char *) "MAX", 3, n
->unaryF
.arg
, n
->unaryF
.resultType
, true, true);
10971 doUnary (p
, (const char *) "MIN", 3, n
->unaryF
.arg
, n
->unaryF
.resultType
, true, true);
10980 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
10981 __builtin_unreachable ();
10990 static void doVar (mcPretty_pretty p
, decl_node n
)
10992 mcDebug_assert (decl_isVar (n
));
10993 if (n
->varF
.isVarParameter
)
10995 outText (p
, (const char *) "(*", 2);
10996 doFQDNameC (p
, n
, true);
10997 outText (p
, (const char *) ")", 1);
11001 doFQDNameC (p
, n
, true);
11010 static void doLiteralC (mcPretty_pretty p
, decl_node n
)
11012 DynamicStrings_String s
;
11014 mcDebug_assert (decl_isLiteral (n
));
11015 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
)));
11016 if (n
->literalF
.type
== charN
)
11018 if ((DynamicStrings_char (s
, -1)) == 'C')
11020 s
= DynamicStrings_Slice (DynamicStrings_Mark (s
), 0, -1);
11021 if ((DynamicStrings_char (s
, 0)) != '0')
11023 s
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "0", 1), DynamicStrings_Mark (s
));
11026 outText (p
, (const char *) "(char)", 6);
11027 mcPretty_setNeedSpace (p
);
11029 else if ((DynamicStrings_char (s
, -1)) == 'H')
11031 /* avoid dangling else. */
11032 outText (p
, (const char *) "0x", 2);
11033 s
= DynamicStrings_Slice (DynamicStrings_Mark (s
), 0, -1);
11035 else if ((DynamicStrings_char (s
, -1)) == 'B')
11037 /* avoid dangling else. */
11038 outText (p
, (const char *) "0", 1);
11039 s
= DynamicStrings_Slice (DynamicStrings_Mark (s
), 0, -1);
11042 s
= DynamicStrings_KillString (s
);
11050 static void doLiteral (mcPretty_pretty p
, decl_node n
)
11052 DynamicStrings_String s
;
11054 mcDebug_assert (decl_isLiteral (n
));
11055 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
)));
11056 if (n
->literalF
.type
== charN
)
11058 if ((DynamicStrings_char (s
, -1)) == 'C')
11060 s
= DynamicStrings_Slice (DynamicStrings_Mark (s
), 0, -1);
11061 if ((DynamicStrings_char (s
, 0)) != '0')
11063 s
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "0", 1), DynamicStrings_Mark (s
));
11066 outText (p
, (const char *) "(char)", 6);
11067 mcPretty_setNeedSpace (p
);
11070 s
= DynamicStrings_KillString (s
);
11075 isString - returns TRUE if node, n, is a string.
11078 static bool isString (decl_node n
)
11080 mcDebug_assert (n
!= NULL
);
11081 return n
->kind
== decl_string
;
11082 /* static analysis guarentees a RETURN statement will be used before here. */
11083 __builtin_unreachable ();
11091 static void doString (mcPretty_pretty p
, decl_node n
)
11093 DynamicStrings_String s
;
11095 mcDebug_assert (isString (n
));
11096 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
)));
11098 s
= DynamicStrings_KillString (s
);
11100 IF DynamicStrings.Index (s, '"', 0)=-1
11105 ELSIF DynamicStrings.Index (s, "'", 0)=-1
11111 metaError1 ('illegal string {%1k}', n)
11115 __builtin_unreachable ();
11120 replaceChar - replace every occurance of, ch, by, a and return modified string, s.
11123 static DynamicStrings_String
replaceChar (DynamicStrings_String s
, char ch
, const char *a_
, unsigned int _a_high
)
11128 /* make a local copy of each unbounded array. */
11129 memcpy (a
, a_
, _a_high
+1);
11134 i
= DynamicStrings_Index (s
, ch
, static_cast<unsigned int> (i
));
11137 s
= DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) a
, _a_high
), DynamicStrings_Slice (s
, 1, 0));
11138 i
= StrLib_StrLen ((const char *) a
, _a_high
);
11142 /* avoid dangling else. */
11143 s
= DynamicStrings_ConCat (DynamicStrings_ConCat (DynamicStrings_Slice (s
, 0, i
), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) a
, _a_high
))), DynamicStrings_Slice (s
, i
+1, 0));
11144 i
+= StrLib_StrLen ((const char *) a
, _a_high
);
11148 /* avoid dangling else. */
11152 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
11153 __builtin_unreachable ();
11158 toCstring - translates string, n, into a C string
11159 and returns the new String.
11162 static DynamicStrings_String
toCstring (nameKey_Name n
)
11164 DynamicStrings_String s
;
11166 s
= DynamicStrings_Slice (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
)), 1, -1);
11167 return replaceChar (replaceChar (s
, '\\', (const char *) "\\\\", 2), '"', (const char *) "\\\"", 2);
11168 /* static analysis guarentees a RETURN statement will be used before here. */
11169 __builtin_unreachable ();
11177 static DynamicStrings_String
toCchar (nameKey_Name n
)
11179 DynamicStrings_String s
;
11181 s
= DynamicStrings_Slice (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
)), 1, -1);
11182 return replaceChar (replaceChar (s
, '\\', (const char *) "\\\\", 2), '\'', (const char *) "\\'", 2);
11183 /* static analysis guarentees a RETURN statement will be used before here. */
11184 __builtin_unreachable ();
11192 static unsigned int countChar (DynamicStrings_String s
, char ch
)
11201 i
= DynamicStrings_Index (s
, ch
, static_cast<unsigned int> (i
));
11212 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
11213 __builtin_unreachable ();
11221 static unsigned int lenCstring (DynamicStrings_String s
)
11223 return (DynamicStrings_Length (s
))-(countChar (s
, '\\'));
11224 /* static analysis guarentees a RETURN statement will be used before here. */
11225 __builtin_unreachable ();
11233 static void outCstring (mcPretty_pretty p
, decl_node s
, bool aString
)
11237 outText (p
, (const char *) "\"", 1);
11238 outRawS (p
, s
->stringF
.cstring
);
11239 outText (p
, (const char *) "\"", 1);
11243 outText (p
, (const char *) "'", 1);
11244 outRawS (p
, s
->stringF
.cchar
);
11245 outText (p
, (const char *) "'", 1);
11254 static void doStringC (mcPretty_pretty p
, decl_node n
)
11256 DynamicStrings_String s
;
11258 mcDebug_assert (isString (n
));
11260 s := InitStringCharStar (keyToCharStar (getSymName (n))) ;
11261 IF DynamicStrings.Length (s)>3
11263 IF DynamicStrings.Index (s, '"', 0)=-1
11265 s := DynamicStrings.Slice (s, 1, -1) ;
11267 outCstring (p, s) ;
11269 ELSIF DynamicStrings.Index (s, "'", 0)=-1
11271 s := DynamicStrings.Slice (s, 1, -1) ;
11273 outCstring (p, s) ;
11276 metaError1 ('illegal string {%1k}', n)
11278 ELSIF DynamicStrings.Length (s) = 3
11280 s := DynamicStrings.Slice (s, 1, -1) ;
11282 IF DynamicStrings.char (s, 0) = "'"
11285 ELSIF DynamicStrings.char (s, 0) = "\"
11293 outText (p, "'\0'")
11295 s := KillString (s)
11297 outCstring (p
, n
, ! n
->stringF
.isCharCompatible
);
11305 static bool isPunct (char ch
)
11307 return (((((((((ch
== '.') || (ch
== '(')) || (ch
== ')')) || (ch
== '^')) || (ch
== ':')) || (ch
== ';')) || (ch
== '{')) || (ch
== '}')) || (ch
== ',')) || (ch
== '*');
11308 /* static analysis guarentees a RETURN statement will be used before here. */
11309 __builtin_unreachable ();
11317 static bool isWhite (char ch
)
11319 return ((ch
== ' ') || (ch
== ASCII_tab
)) || (ch
== ASCII_lf
);
11320 /* static analysis guarentees a RETURN statement will be used before here. */
11321 __builtin_unreachable ();
11329 static void outText (mcPretty_pretty p
, const char *a_
, unsigned int _a_high
)
11331 DynamicStrings_String s
;
11334 /* make a local copy of each unbounded array. */
11335 memcpy (a
, a_
, _a_high
+1);
11337 s
= DynamicStrings_InitString ((const char *) a
, _a_high
);
11339 s
= DynamicStrings_KillString (s
);
11347 static void outRawS (mcPretty_pretty p
, DynamicStrings_String s
)
11349 mcPretty_raw (p
, s
);
11357 static mcPretty_pretty
outKm2 (mcPretty_pretty p
, const char *a_
, unsigned int _a_high
)
11360 DynamicStrings_String s
;
11363 /* make a local copy of each unbounded array. */
11364 memcpy (a
, a_
, _a_high
+1);
11366 if (StrLib_StrEqual ((const char *) a
, _a_high
, (const char *) "RECORD", 6))
11368 p
= mcPretty_pushPretty (p
);
11369 i
= mcPretty_getcurpos (p
);
11370 mcPretty_setindent (p
, i
);
11371 outText (p
, (const char *) a
, _a_high
);
11372 p
= mcPretty_pushPretty (p
);
11373 mcPretty_setindent (p
, i
+indentation
);
11375 else if (StrLib_StrEqual ((const char *) a
, _a_high
, (const char *) "END", 3))
11377 /* avoid dangling else. */
11378 p
= mcPretty_popPretty (p
);
11379 outText (p
, (const char *) a
, _a_high
);
11380 p
= mcPretty_popPretty (p
);
11383 /* static analysis guarentees a RETURN statement will be used before here. */
11384 __builtin_unreachable ();
11392 static mcPretty_pretty
outKc (mcPretty_pretty p
, const char *a_
, unsigned int _a_high
)
11396 DynamicStrings_String s
;
11397 DynamicStrings_String t
;
11400 /* make a local copy of each unbounded array. */
11401 memcpy (a
, a_
, _a_high
+1);
11403 s
= DynamicStrings_InitString ((const char *) a
, _a_high
);
11404 i
= DynamicStrings_Index (s
, '\\', 0);
11411 t
= DynamicStrings_Slice (s
, i
, 0);
11412 s
= DynamicStrings_Slice (DynamicStrings_Mark (s
), 0, i
);
11414 if ((DynamicStrings_char (s
, 0)) == '{')
11416 p
= mcPretty_pushPretty (p
);
11417 c
= mcPretty_getcurpos (p
);
11418 mcPretty_setindent (p
, c
);
11420 p
= mcPretty_pushPretty (p
);
11421 mcPretty_setindent (p
, c
+indentationC
);
11423 else if ((DynamicStrings_char (s
, 0)) == '}')
11425 /* avoid dangling else. */
11426 p
= mcPretty_popPretty (p
);
11428 p
= mcPretty_popPretty (p
);
11431 t
= DynamicStrings_KillString (t
);
11432 s
= DynamicStrings_KillString (s
);
11434 /* static analysis guarentees a RETURN statement will be used before here. */
11435 __builtin_unreachable ();
11443 static void outTextS (mcPretty_pretty p
, DynamicStrings_String s
)
11447 mcPretty_prints (p
, s
);
11456 static void outCard (mcPretty_pretty p
, unsigned int c
)
11458 DynamicStrings_String s
;
11460 s
= StringConvert_CardinalToString (c
, 0, ' ', 10, false);
11462 s
= DynamicStrings_KillString (s
);
11470 static void outTextN (mcPretty_pretty p
, nameKey_Name n
)
11472 DynamicStrings_String s
;
11474 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
));
11475 mcPretty_prints (p
, s
);
11476 s
= DynamicStrings_KillString (s
);
11484 static void doTypeAliasC (mcPretty_pretty p
, decl_node n
, decl_node
*m
)
11486 mcPretty_print (p
, (const char *) "typedef", 7);
11487 mcPretty_setNeedSpace (p
);
11488 if ((decl_isTypeHidden (n
)) && ((decl_isDef (decl_getMainModule ())) || ((decl_getScope (n
)) != (decl_getMainModule ()))))
11490 outText (p
, (const char *) "void *", 6);
11494 doTypeC (p
, decl_getType (n
), m
);
11498 doFQNameC (p
, (*m
));
11500 mcPretty_print (p
, (const char *) ";\\n\\n", 5);
11508 static void doEnumerationC (mcPretty_pretty p
, decl_node n
)
11513 DynamicStrings_String t
;
11515 outText (p
, (const char *) "enum {", 6);
11516 i
= Indexing_LowIndice (n
->enumerationF
.listOfSons
);
11517 h
= Indexing_HighIndice (n
->enumerationF
.listOfSons
);
11520 s
= static_cast<decl_node
> (Indexing_GetIndice (n
->enumerationF
.listOfSons
, i
));
11521 doFQDNameC (p
, s
, false);
11524 outText (p
, (const char *) ",", 1);
11525 mcPretty_setNeedSpace (p
);
11529 outText (p
, (const char *) "}", 1);
11537 static void doNamesC (mcPretty_pretty p
, nameKey_Name n
)
11539 DynamicStrings_String s
;
11541 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
));
11543 s
= DynamicStrings_KillString (s
);
11551 static void doNameC (mcPretty_pretty p
, decl_node n
)
11553 if ((n
!= NULL
) && ((decl_getSymName (n
)) != nameKey_NulName
))
11555 doNamesC (p
, decl_getSymName (n
));
11564 static void initCname (decl_cnameT
*c
)
11574 static nameKey_Name
doCname (nameKey_Name n
, decl_cnameT
*c
, bool scopes
)
11576 DynamicStrings_String s
;
11585 s
= keyc_cname (n
, scopes
);
11592 (*c
).name
= nameKey_makekey (DynamicStrings_string (s
));
11593 s
= DynamicStrings_KillString (s
);
11597 /* static analysis guarentees a RETURN statement will be used before here. */
11598 __builtin_unreachable ();
11606 static nameKey_Name
getDName (decl_node n
, bool scopes
)
11610 m
= decl_getSymName (n
);
11613 case decl_procedure
:
11614 return doCname (m
, &n
->procedureF
.cname
, scopes
);
11618 return doCname (m
, &n
->varF
.cname
, scopes
);
11621 case decl_recordfield
:
11622 return doCname (m
, &n
->recordfieldF
.cname
, scopes
);
11625 case decl_enumerationfield
:
11626 return doCname (m
, &n
->enumerationfieldF
.cname
, scopes
);
11634 /* static analysis guarentees a RETURN statement will be used before here. */
11635 __builtin_unreachable ();
11643 static void doDNameC (mcPretty_pretty p
, decl_node n
, bool scopes
)
11645 if ((n
!= NULL
) && ((decl_getSymName (n
)) != nameKey_NulName
))
11647 doNamesC (p
, getDName (n
, scopes
));
11656 static void doFQDNameC (mcPretty_pretty p
, decl_node n
, bool scopes
)
11658 DynamicStrings_String s
;
11660 s
= getFQDstring (n
, scopes
);
11662 s
= DynamicStrings_KillString (s
);
11670 static void doFQNameC (mcPretty_pretty p
, decl_node n
)
11672 DynamicStrings_String s
;
11674 s
= getFQstring (n
);
11676 s
= DynamicStrings_KillString (s
);
11684 static void doNameM2 (mcPretty_pretty p
, decl_node n
)
11694 static void doUsed (mcPretty_pretty p
, bool used
)
11698 mcPretty_setNeedSpace (p
);
11699 outText (p
, (const char *) "__attribute__((unused))", 23);
11708 static void doHighC (mcPretty_pretty p
, decl_node a
, nameKey_Name n
, bool isused
)
11710 if ((decl_isArray (a
)) && (decl_isUnbounded (a
)))
11712 /* need to display high. */
11713 mcPretty_print (p
, (const char *) ",", 1);
11714 mcPretty_setNeedSpace (p
);
11715 doTypeNameC (p
, cardinalN
);
11716 mcPretty_setNeedSpace (p
);
11717 mcPretty_print (p
, (const char *) "_", 1);
11719 mcPretty_print (p
, (const char *) "_high", 5);
11720 doUsed (p
, isused
);
11729 static void doParamConstCast (mcPretty_pretty p
, decl_node n
)
11733 ptype
= decl_getType (n
);
11734 if (((decl_isArray (ptype
)) && (decl_isUnbounded (ptype
))) && (lang
== decl_ansiCP
))
11736 outText (p
, (const char *) "const", 5);
11737 mcPretty_setNeedSpace (p
);
11743 getParameterVariable - returns the variable which shadows the parameter
11744 named, m, in parameter block, n.
11747 static decl_node
getParameterVariable (decl_node n
, nameKey_Name m
)
11751 mcDebug_assert ((decl_isParam (n
)) || (decl_isVarParam (n
)));
11752 if (decl_isParam (n
))
11754 p
= n
->paramF
.scope
;
11758 p
= n
->varparamF
.scope
;
11760 mcDebug_assert (decl_isProcedure (p
));
11761 return decl_lookupInScope (p
, m
);
11762 /* static analysis guarentees a RETURN statement will be used before here. */
11763 __builtin_unreachable ();
11768 doParamTypeEmit - emit parameter type for C/C++. It checks to see if the
11769 parameter type is a procedure type and if it were declared
11770 in a definition module for "C" and if so it uses the "C"
11771 definition for a procedure type, rather than the mc
11775 static void doParamTypeEmit (mcPretty_pretty p
, decl_node paramnode
, decl_node paramtype
)
11777 mcDebug_assert ((decl_isParam (paramnode
)) || (decl_isVarParam (paramnode
)));
11778 if ((isForC (paramnode
)) && (decl_isProcType (decl_skipType (paramtype
))))
11780 doFQNameC (p
, paramtype
);
11781 outText (p
, (const char *) "_C", 2);
11785 doTypeNameC (p
, paramtype
);
11791 doParamC - emit parameter for C/C++.
11794 static void doParamC (mcPretty_pretty p
, decl_node n
)
11803 mcDebug_assert (decl_isParam (n
));
11804 ptype
= decl_getType (n
);
11805 if (n
->paramF
.namelist
== NULL
)
11807 /* avoid dangling else. */
11808 doParamConstCast (p
, n
);
11809 doTypeNameC (p
, ptype
);
11810 doUsed (p
, n
->paramF
.isUsed
);
11811 if ((decl_isArray (ptype
)) && (decl_isUnbounded (ptype
)))
11813 outText (p
, (const char *) ",", 1);
11814 mcPretty_setNeedSpace (p
);
11815 outText (p
, (const char *) "unsigned int", 12);
11820 mcDebug_assert (isIdentList (n
->paramF
.namelist
));
11821 l
= n
->paramF
.namelist
->identlistF
.names
;
11824 /* avoid dangling else. */
11825 doParamConstCast (p
, n
);
11826 doParamTypeEmit (p
, n
, ptype
);
11827 if ((decl_isArray (ptype
)) && (decl_isUnbounded (ptype
)))
11829 doUsed (p
, n
->paramF
.isUsed
);
11830 outText (p
, (const char *) ",", 1);
11831 mcPretty_setNeedSpace (p
);
11832 outText (p
, (const char *) "unsigned int", 12);
11837 t
= wlists_noOfItemsInList (l
);
11841 doParamConstCast (p
, n
);
11842 doParamTypeEmit (p
, n
, ptype
);
11843 i
= static_cast<nameKey_Name
> (wlists_getItemFromList (l
, c
));
11844 if ((decl_isArray (ptype
)) && (decl_isUnbounded (ptype
)))
11846 mcPretty_noSpace (p
);
11850 mcPretty_setNeedSpace (p
);
11852 v
= getParameterVariable (n
, i
);
11855 doNamesC (p
, keyc_cnamen (i
, true));
11859 doFQDNameC (p
, v
, true);
11861 if ((decl_isArray (ptype
)) && (decl_isUnbounded (ptype
)))
11863 outText (p
, (const char *) "_", 1);
11865 doUsed (p
, n
->paramF
.isUsed
);
11866 doHighC (p
, ptype
, i
, n
->paramF
.isUsed
);
11869 outText (p
, (const char *) ",", 1);
11870 mcPretty_setNeedSpace (p
);
11880 doVarParamC - emit a VAR parameter for C/C++.
11883 static void doVarParamC (mcPretty_pretty p
, decl_node n
)
11892 mcDebug_assert (decl_isVarParam (n
));
11893 ptype
= decl_getType (n
);
11894 if (n
->varparamF
.namelist
== NULL
)
11896 /* avoid dangling else. */
11897 doTypeNameC (p
, ptype
);
11898 /* doTypeC (p, ptype, n) ; */
11899 if (! (decl_isArray (ptype
)))
11901 mcPretty_setNeedSpace (p
);
11902 outText (p
, (const char *) "*", 1);
11904 doUsed (p
, n
->varparamF
.isUsed
);
11905 if ((decl_isArray (ptype
)) && (decl_isUnbounded (ptype
)))
11907 outText (p
, (const char *) ",", 1);
11908 mcPretty_setNeedSpace (p
);
11909 outText (p
, (const char *) "unsigned int", 12);
11914 mcDebug_assert (isIdentList (n
->varparamF
.namelist
));
11915 l
= n
->varparamF
.namelist
->identlistF
.names
;
11918 doParamTypeEmit (p
, n
, ptype
);
11919 doUsed (p
, n
->varparamF
.isUsed
);
11923 t
= wlists_noOfItemsInList (l
);
11927 doParamTypeEmit (p
, n
, ptype
);
11928 if (! (decl_isArray (ptype
)))
11930 mcPretty_setNeedSpace (p
);
11931 outText (p
, (const char *) "*", 1);
11933 i
= static_cast<nameKey_Name
> (wlists_getItemFromList (l
, c
));
11934 v
= getParameterVariable (n
, i
);
11937 doNamesC (p
, keyc_cnamen (i
, true));
11941 doFQDNameC (p
, v
, true);
11943 doUsed (p
, n
->varparamF
.isUsed
);
11944 doHighC (p
, ptype
, i
, n
->varparamF
.isUsed
);
11947 outText (p
, (const char *) ",", 1);
11948 mcPretty_setNeedSpace (p
);
11961 static void doOptargC (mcPretty_pretty p
, decl_node n
)
11968 mcDebug_assert (decl_isOptarg (n
));
11969 ptype
= decl_getType (n
);
11970 mcDebug_assert (n
->optargF
.namelist
!= NULL
);
11971 mcDebug_assert (isIdentList (n
->paramF
.namelist
));
11972 l
= n
->paramF
.namelist
->identlistF
.names
;
11973 mcDebug_assert (l
!= NULL
);
11974 t
= wlists_noOfItemsInList (l
);
11975 mcDebug_assert (t
== 1);
11976 doTypeNameC (p
, ptype
);
11977 i
= static_cast<nameKey_Name
> (wlists_getItemFromList (l
, 1));
11978 mcPretty_setNeedSpace (p
);
11987 static void doParameterC (mcPretty_pretty p
, decl_node n
)
11989 if (decl_isParam (n
))
11993 else if (decl_isVarParam (n
))
11995 /* avoid dangling else. */
11996 doVarParamC (p
, n
);
11998 else if (decl_isVarargs (n
))
12000 /* avoid dangling else. */
12001 mcPretty_print (p
, (const char *) "...", 3);
12003 else if (decl_isOptarg (n
))
12005 /* avoid dangling else. */
12015 static void doProcTypeC (mcPretty_pretty p
, decl_node t
, decl_node n
)
12017 mcDebug_assert (decl_isType (t
));
12019 doCompletePartialProcType (p
, t
, n
);
12027 static void doTypesC (decl_node n
)
12031 if (decl_isType (n
))
12033 m
= decl_getType (n
);
12034 if (decl_isProcType (m
))
12036 doProcTypeC (doP
, n
, m
);
12038 else if ((decl_isType (m
)) || (decl_isPointer (m
)))
12040 /* avoid dangling else. */
12041 outText (doP
, (const char *) "typedef", 7);
12042 mcPretty_setNeedSpace (doP
);
12043 doTypeC (doP
, m
, &m
);
12044 if (decl_isType (m
))
12046 mcPretty_setNeedSpace (doP
);
12048 doTypeNameC (doP
, n
);
12049 outText (doP
, (const char *) ";\\n\\n", 5);
12051 else if (decl_isEnumeration (m
))
12053 /* avoid dangling else. */
12054 outText (doP
, (const char *) "typedef", 7);
12055 mcPretty_setNeedSpace (doP
);
12056 doTypeC (doP
, m
, &m
);
12057 mcPretty_setNeedSpace (doP
);
12058 doTypeNameC (doP
, n
);
12059 outText (doP
, (const char *) ";\\n\\n", 5);
12063 /* avoid dangling else. */
12064 outText (doP
, (const char *) "typedef", 7);
12065 mcPretty_setNeedSpace (doP
);
12066 doTypeC (doP
, m
, &m
);
12067 if (decl_isType (m
))
12069 mcPretty_setNeedSpace (doP
);
12071 doTypeNameC (doP
, n
);
12072 outText (doP
, (const char *) ";\\n\\n", 5);
12079 doCompletePartialC -
12082 static void doCompletePartialC (decl_node n
)
12086 if (decl_isType (n
))
12088 m
= decl_getType (n
);
12089 if (decl_isRecord (m
))
12091 doCompletePartialRecord (doP
, n
, m
);
12093 else if (decl_isArray (m
))
12095 /* avoid dangling else. */
12096 doCompletePartialArray (doP
, n
, m
);
12098 else if (decl_isProcType (m
))
12100 /* avoid dangling else. */
12101 doCompletePartialProcType (doP
, n
, m
);
12108 doCompletePartialRecord -
12111 static void doCompletePartialRecord (mcPretty_pretty p
, decl_node t
, decl_node r
)
12117 mcDebug_assert (decl_isRecord (r
));
12118 mcDebug_assert (decl_isType (t
));
12119 outText (p
, (const char *) "struct", 6);
12120 mcPretty_setNeedSpace (p
);
12122 outText (p
, (const char *) "_r", 2);
12123 mcPretty_setNeedSpace (p
);
12124 p
= outKc (p
, (const char *) "{\\n", 3);
12125 i
= Indexing_LowIndice (r
->recordF
.listOfSons
);
12126 h
= Indexing_HighIndice (r
->recordF
.listOfSons
);
12129 f
= static_cast<decl_node
> (Indexing_GetIndice (r
->recordF
.listOfSons
, i
));
12130 if (decl_isRecordField (f
))
12132 /* avoid dangling else. */
12133 if (! f
->recordfieldF
.tag
)
12135 mcPretty_setNeedSpace (p
);
12136 doRecordFieldC (p
, f
);
12137 outText (p
, (const char *) ";\\n", 3);
12140 else if (decl_isVarient (f
))
12142 /* avoid dangling else. */
12144 outText (p
, (const char *) ";\\n", 3);
12146 else if (decl_isVarientField (f
))
12148 /* avoid dangling else. */
12149 doVarientFieldC (p
, f
);
12153 p
= outKc (p
, (const char *) "};\\n\\n", 6);
12158 doCompletePartialArray -
12161 static void doCompletePartialArray (mcPretty_pretty p
, decl_node t
, decl_node r
)
12166 mcDebug_assert (decl_isArray (r
));
12167 type
= r
->arrayF
.type
;
12169 outText (p
, (const char *) "struct", 6);
12170 mcPretty_setNeedSpace (p
);
12172 outText (p
, (const char *) "_a {", 4);
12173 mcPretty_setNeedSpace (p
);
12174 doTypeC (p
, type
, &s
);
12175 mcPretty_setNeedSpace (p
);
12176 outText (p
, (const char *) "array[", 6);
12177 doSubrC (p
, r
->arrayF
.subr
);
12178 outText (p
, (const char *) "];", 2);
12179 mcPretty_setNeedSpace (p
);
12180 outText (p
, (const char *) "};\\n", 4);
12188 static decl_node
lookupConst (decl_node type
, nameKey_Name n
)
12190 return decl_makeLiteralInt (n
);
12191 /* static analysis guarentees a RETURN statement will be used before here. */
12192 __builtin_unreachable ();
12200 static decl_node
doMin (decl_node n
)
12206 else if (n
== integerN
)
12208 /* avoid dangling else. */
12210 return lookupConst (integerN
, nameKey_makeKey ((const char *) "INT_MIN", 7));
12212 else if (n
== cardinalN
)
12214 /* avoid dangling else. */
12215 keyc_useUIntMin ();
12216 return lookupConst (cardinalN
, nameKey_makeKey ((const char *) "UINT_MIN", 8));
12218 else if (n
== longintN
)
12220 /* avoid dangling else. */
12221 keyc_useLongMin ();
12222 return lookupConst (longintN
, nameKey_makeKey ((const char *) "LONG_MIN", 8));
12224 else if (n
== longcardN
)
12226 /* avoid dangling else. */
12227 keyc_useULongMin ();
12228 return lookupConst (longcardN
, nameKey_makeKey ((const char *) "LONG_MIN", 8));
12230 else if (n
== charN
)
12232 /* avoid dangling else. */
12233 keyc_useCharMin ();
12234 return lookupConst (charN
, nameKey_makeKey ((const char *) "CHAR_MIN", 8));
12236 else if (n
== bitsetN
)
12238 /* avoid dangling else. */
12239 mcDebug_assert (decl_isSubrange (bitnumN
));
12240 return bitnumN
->subrangeF
.low
;
12242 else if (n
== locN
)
12244 /* avoid dangling else. */
12245 keyc_useUCharMin ();
12246 return lookupConst (locN
, nameKey_makeKey ((const char *) "UCHAR_MIN", 9));
12248 else if (n
== byteN
)
12250 /* avoid dangling else. */
12251 keyc_useUCharMin ();
12252 return lookupConst (byteN
, nameKey_makeKey ((const char *) "UCHAR_MIN", 9));
12254 else if (n
== wordN
)
12256 /* avoid dangling else. */
12257 keyc_useUIntMin ();
12258 return lookupConst (wordN
, nameKey_makeKey ((const char *) "UCHAR_MIN", 9));
12260 else if (n
== addressN
)
12262 /* avoid dangling else. */
12263 return lookupConst (addressN
, nameKey_makeKey ((const char *) "((void *) 0)", 12));
12267 /* avoid dangling else. */
12268 M2RTS_HALT (-1); /* finish the cacading elsif statement. */
12269 __builtin_unreachable ();
12271 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
12272 __builtin_unreachable ();
12280 static decl_node
doMax (decl_node n
)
12286 else if (n
== integerN
)
12288 /* avoid dangling else. */
12290 return lookupConst (integerN
, nameKey_makeKey ((const char *) "INT_MAX", 7));
12292 else if (n
== cardinalN
)
12294 /* avoid dangling else. */
12295 keyc_useUIntMax ();
12296 return lookupConst (cardinalN
, nameKey_makeKey ((const char *) "UINT_MAX", 8));
12298 else if (n
== longintN
)
12300 /* avoid dangling else. */
12301 keyc_useLongMax ();
12302 return lookupConst (longintN
, nameKey_makeKey ((const char *) "LONG_MAX", 8));
12304 else if (n
== longcardN
)
12306 /* avoid dangling else. */
12307 keyc_useULongMax ();
12308 return lookupConst (longcardN
, nameKey_makeKey ((const char *) "ULONG_MAX", 9));
12310 else if (n
== charN
)
12312 /* avoid dangling else. */
12313 keyc_useCharMax ();
12314 return lookupConst (charN
, nameKey_makeKey ((const char *) "CHAR_MAX", 8));
12316 else if (n
== bitsetN
)
12318 /* avoid dangling else. */
12319 mcDebug_assert (decl_isSubrange (bitnumN
));
12320 return bitnumN
->subrangeF
.high
;
12322 else if (n
== locN
)
12324 /* avoid dangling else. */
12325 keyc_useUCharMax ();
12326 return lookupConst (locN
, nameKey_makeKey ((const char *) "UCHAR_MAX", 9));
12328 else if (n
== byteN
)
12330 /* avoid dangling else. */
12331 keyc_useUCharMax ();
12332 return lookupConst (byteN
, nameKey_makeKey ((const char *) "UCHAR_MAX", 9));
12334 else if (n
== wordN
)
12336 /* avoid dangling else. */
12337 keyc_useUIntMax ();
12338 return lookupConst (wordN
, nameKey_makeKey ((const char *) "UINT_MAX", 8));
12340 else if (n
== addressN
)
12342 /* avoid dangling else. */
12343 mcMetaError_metaError1 ((const char *) "trying to obtain MAX ({%1ad}) is illegal", 40, (const unsigned char *) &n
, (sizeof (n
)-1));
12348 /* avoid dangling else. */
12349 M2RTS_HALT (-1); /* finish the cacading elsif statement. */
12350 __builtin_unreachable ();
12352 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
12353 __builtin_unreachable ();
12361 static decl_node
getMax (decl_node n
)
12363 n
= decl_skipType (n
);
12364 if (decl_isSubrange (n
))
12366 return n
->subrangeF
.high
;
12368 else if (decl_isEnumeration (n
))
12370 /* avoid dangling else. */
12371 return n
->enumerationF
.high
;
12375 /* avoid dangling else. */
12376 mcDebug_assert (isOrdinal (n
));
12379 /* static analysis guarentees a RETURN statement will be used before here. */
12380 __builtin_unreachable ();
12388 static decl_node
getMin (decl_node n
)
12390 n
= decl_skipType (n
);
12391 if (decl_isSubrange (n
))
12393 return n
->subrangeF
.low
;
12395 else if (decl_isEnumeration (n
))
12397 /* avoid dangling else. */
12398 return n
->enumerationF
.low
;
12402 /* avoid dangling else. */
12403 mcDebug_assert (isOrdinal (n
));
12406 /* static analysis guarentees a RETURN statement will be used before here. */
12407 __builtin_unreachable ();
12415 static void doSubtractC (mcPretty_pretty p
, decl_node s
)
12417 if (! (isZero (s
)))
12419 outText (p
, (const char *) "-", 1);
12429 static void doSubrC (mcPretty_pretty p
, decl_node s
)
12434 s
= decl_skipType (s
);
12440 doSubtractC (p
, low
);
12441 outText (p
, (const char *) "+1", 2);
12443 else if (decl_isEnumeration (s
))
12445 /* avoid dangling else. */
12449 doSubtractC (p
, low
);
12450 outText (p
, (const char *) "+1", 2);
12454 /* avoid dangling else. */
12455 mcDebug_assert (decl_isSubrange (s
));
12456 if ((s
->subrangeF
.high
== NULL
) || (s
->subrangeF
.low
== NULL
))
12458 doSubrC (p
, decl_getType (s
));
12462 doExprC (p
, s
->subrangeF
.high
);
12463 doSubtractC (p
, s
->subrangeF
.low
);
12464 outText (p
, (const char *) "+1", 2);
12471 doCompletePartialProcType -
12474 static void doCompletePartialProcType (mcPretty_pretty p
, decl_node t
, decl_node n
)
12481 mcDebug_assert (decl_isProcType (n
));
12483 outText (p
, (const char *) "typedef", 7);
12484 mcPretty_setNeedSpace (p
);
12485 doTypeC (p
, n
->proctypeF
.returnType
, &u
);
12486 mcPretty_setNeedSpace (p
);
12487 outText (p
, (const char *) "(*", 2);
12489 outText (p
, (const char *) "_t) (", 5);
12490 i
= Indexing_LowIndice (n
->proctypeF
.parameters
);
12491 h
= Indexing_HighIndice (n
->proctypeF
.parameters
);
12494 v
= static_cast<decl_node
> (Indexing_GetIndice (n
->proctypeF
.parameters
, i
));
12495 doParameterC (p
, v
);
12496 mcPretty_noSpace (p
);
12499 outText (p
, (const char *) ",", 1);
12500 mcPretty_setNeedSpace (p
);
12506 outText (p
, (const char *) "void", 4);
12508 outText (p
, (const char *) ");\\n", 4);
12509 if (isDefForCNode (n
))
12511 /* emit a C named type which differs from the m2 proctype. */
12512 outText (p
, (const char *) "typedef", 7);
12513 mcPretty_setNeedSpace (p
);
12515 outText (p
, (const char *) "_t", 2);
12516 mcPretty_setNeedSpace (p
);
12518 outText (p
, (const char *) "_C;\\n\\n", 7);
12520 outText (p
, (const char *) "struct", 6);
12521 mcPretty_setNeedSpace (p
);
12523 outText (p
, (const char *) "_p {", 4);
12524 mcPretty_setNeedSpace (p
);
12526 outText (p
, (const char *) "_t proc; };\\n\\n", 15);
12534 static bool isBase (decl_node n
)
12539 case decl_cardinal
:
12540 case decl_longcard
:
12541 case decl_shortcard
:
12544 case decl_shortint
:
12546 case decl_longcomplex
:
12547 case decl_shortcomplex
:
12549 case decl_longreal
:
12550 case decl_shortreal
:
12562 /* static analysis guarentees a RETURN statement will be used before here. */
12563 __builtin_unreachable ();
12571 static void doBoolC (mcPretty_pretty p
)
12573 if (mcOptions_useBool ())
12575 outText (p
, (const char *) "bool", 4);
12579 outText (p
, (const char *) "unsigned int", 12);
12588 static void doBaseC (mcPretty_pretty p
, decl_node n
)
12593 outText (p
, (const char *) "char", 4);
12596 case decl_cardinal
:
12597 outText (p
, (const char *) "unsigned int", 12);
12600 case decl_longcard
:
12601 outText (p
, (const char *) "long unsigned int", 17);
12604 case decl_shortcard
:
12605 outText (p
, (const char *) "short unsigned int", 18);
12609 outText (p
, (const char *) "int", 3);
12613 outText (p
, (const char *) "long int", 8);
12616 case decl_shortint
:
12617 outText (p
, (const char *) "short int", 9);
12621 outText (p
, (const char *) "double complex", 14);
12624 case decl_longcomplex
:
12625 outText (p
, (const char *) "long double complex", 19);
12628 case decl_shortcomplex
:
12629 outText (p
, (const char *) "float complex", 13);
12633 outTextS (p
, mcOptions_getCRealType ());
12636 case decl_longreal
:
12637 outTextS (p
, mcOptions_getCLongRealType ());
12640 case decl_shortreal
:
12641 outTextS (p
, mcOptions_getCShortRealType ());
12645 outText (p
, (const char *) "unsigned int", 12);
12653 outText (p
, (const char *) "PROC", 4);
12658 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
12659 __builtin_unreachable ();
12661 mcPretty_setNeedSpace (p
);
12669 static bool isSystem (decl_node n
)
12702 /* static analysis guarentees a RETURN statement will be used before here. */
12703 __builtin_unreachable ();
12711 static void doSystemC (mcPretty_pretty p
, decl_node n
)
12716 outText (p
, (const char *) "void *", 6);
12720 outText (p
, (const char *) "unsigned char", 13);
12721 mcPretty_setNeedSpace (p
);
12725 outText (p
, (const char *) "unsigned char", 13);
12726 mcPretty_setNeedSpace (p
);
12730 outText (p
, (const char *) "unsigned int", 12);
12731 mcPretty_setNeedSpace (p
);
12735 outText (p
, (const char *) "size_t", 6);
12736 mcPretty_setNeedSpace (p
);
12741 outText (p
, (const char *) "ssize_t", 7);
12742 mcPretty_setNeedSpace (p
);
12743 keyc_useSSize_t ();
12748 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
12749 __builtin_unreachable ();
12758 static void doArrayC (mcPretty_pretty p
, decl_node n
)
12764 mcDebug_assert (decl_isArray (n
));
12765 t
= n
->arrayF
.type
;
12766 s
= n
->arrayF
.subr
;
12770 doTypeC (p
, t
, &u
);
12771 mcPretty_setNeedSpace (p
);
12772 outText (p
, (const char *) "*", 1);
12776 outText (p
, (const char *) "struct", 6);
12777 mcPretty_setNeedSpace (p
);
12778 outText (p
, (const char *) "{", 1);
12779 mcPretty_setNeedSpace (p
);
12780 doTypeC (p
, t
, &u
);
12781 mcPretty_setNeedSpace (p
);
12782 outText (p
, (const char *) "array[", 6);
12783 if (isZero (getMin (s
)))
12785 doExprC (p
, getMax (s
));
12789 doExprC (p
, getMax (s
));
12790 doSubtractC (p
, getMin (s
));
12792 outText (p
, (const char *) "];", 2);
12793 mcPretty_setNeedSpace (p
);
12794 outText (p
, (const char *) "}", 1);
12795 mcPretty_setNeedSpace (p
);
12804 static void doPointerC (mcPretty_pretty p
, decl_node n
, decl_node
*m
)
12809 t
= n
->pointerF
.type
;
12811 doTypeC (p
, t
, &s
);
12812 mcPretty_setNeedSpace (p
);
12813 outText (p
, (const char *) "*", 1);
12821 static void doRecordFieldC (mcPretty_pretty p
, decl_node f
)
12826 mcPretty_setNeedSpace (p
);
12827 doTypeC (p
, f
->recordfieldF
.type
, &m
);
12828 doDNameC (p
, f
, false);
12836 static void doVarientFieldC (mcPretty_pretty p
, decl_node n
)
12842 mcDebug_assert (decl_isVarientField (n
));
12843 if (! n
->varientfieldF
.simple
)
12845 outText (p
, (const char *) "struct", 6);
12846 mcPretty_setNeedSpace (p
);
12847 p
= outKc (p
, (const char *) "{\\n", 3);
12849 i
= Indexing_LowIndice (n
->varientfieldF
.listOfSons
);
12850 t
= Indexing_HighIndice (n
->varientfieldF
.listOfSons
);
12853 q
= static_cast<decl_node
> (Indexing_GetIndice (n
->varientfieldF
.listOfSons
, i
));
12854 if (decl_isRecordField (q
))
12856 /* avoid dangling else. */
12857 if (! q
->recordfieldF
.tag
)
12859 doRecordFieldC (p
, q
);
12860 outText (p
, (const char *) ";\\n", 3);
12863 else if (decl_isVarient (q
))
12865 /* avoid dangling else. */
12867 outText (p
, (const char *) ";\\n", 3);
12871 /* avoid dangling else. */
12873 __builtin_unreachable ();
12877 if (! n
->varientfieldF
.simple
)
12879 p
= outKc (p
, (const char *) "};\\n", 4);
12888 static void doVarientC (mcPretty_pretty p
, decl_node n
)
12894 mcDebug_assert (decl_isVarient (n
));
12895 if (n
->varientF
.tag
!= NULL
)
12897 /* avoid gcc warning by using compound statement even if not strictly necessary. */
12898 if (decl_isRecordField (n
->varientF
.tag
))
12900 doRecordFieldC (p
, n
->varientF
.tag
);
12901 outText (p
, (const char *) "; /* case tag */\\n", 19);
12903 else if (decl_isVarientField (n
->varientF
.tag
))
12905 /* avoid dangling else. */
12906 /* doVarientFieldC (p, n^.varientF.tag) */
12908 __builtin_unreachable ();
12912 /* avoid dangling else. */
12914 __builtin_unreachable ();
12917 outText (p
, (const char *) "union", 5);
12918 mcPretty_setNeedSpace (p
);
12919 p
= outKc (p
, (const char *) "{\\n", 3);
12920 i
= Indexing_LowIndice (n
->varientF
.listOfSons
);
12921 t
= Indexing_HighIndice (n
->varientF
.listOfSons
);
12924 q
= static_cast<decl_node
> (Indexing_GetIndice (n
->varientF
.listOfSons
, i
));
12925 if (decl_isRecordField (q
))
12927 /* avoid dangling else. */
12928 if (! q
->recordfieldF
.tag
)
12930 doRecordFieldC (p
, q
);
12931 outText (p
, (const char *) ";\\n", 3);
12934 else if (decl_isVarientField (q
))
12936 /* avoid dangling else. */
12937 doVarientFieldC (p
, q
);
12941 /* avoid dangling else. */
12943 __builtin_unreachable ();
12947 p
= outKc (p
, (const char *) "}", 1);
12955 static void doRecordC (mcPretty_pretty p
, decl_node n
, decl_node
*m
)
12961 mcDebug_assert (decl_isRecord (n
));
12962 outText (p
, (const char *) "struct", 6);
12963 mcPretty_setNeedSpace (p
);
12964 p
= outKc (p
, (const char *) "{", 1);
12965 i
= Indexing_LowIndice (n
->recordF
.listOfSons
);
12966 h
= Indexing_HighIndice (n
->recordF
.listOfSons
);
12967 mcPretty_setindent (p
, (mcPretty_getcurpos (p
))+indentation
);
12968 outText (p
, (const char *) "\\n", 2);
12971 f
= static_cast<decl_node
> (Indexing_GetIndice (n
->recordF
.listOfSons
, i
));
12972 if (decl_isRecordField (f
))
12974 /* avoid dangling else. */
12975 if (! f
->recordfieldF
.tag
)
12977 doRecordFieldC (p
, f
);
12978 outText (p
, (const char *) ";\\n", 3);
12981 else if (decl_isVarient (f
))
12983 /* avoid dangling else. */
12985 outText (p
, (const char *) ";\\n", 3);
12987 else if (decl_isVarientField (f
))
12989 /* avoid dangling else. */
12990 doVarientFieldC (p
, f
);
12994 p
= outKc (p
, (const char *) "}", 1);
12995 mcPretty_setNeedSpace (p
);
13003 static bool isBitset (decl_node n
)
13005 return n
== bitsetN
;
13006 /* static analysis guarentees a RETURN statement will be used before here. */
13007 __builtin_unreachable ();
13012 isNegative - returns TRUE if expression, n, is negative.
13015 static bool isNegative (decl_node n
)
13017 /* --fixme-- needs to be completed. */
13019 /* static analysis guarentees a RETURN statement will be used before here. */
13020 __builtin_unreachable ();
13028 static void doSubrangeC (mcPretty_pretty p
, decl_node n
)
13030 mcDebug_assert (decl_isSubrange (n
));
13031 if (isNegative (n
->subrangeF
.low
))
13033 outText (p
, (const char *) "int", 3);
13034 mcPretty_setNeedSpace (p
);
13038 outText (p
, (const char *) "unsigned int", 12);
13039 mcPretty_setNeedSpace (p
);
13045 doSetC - generates a C type which holds the set.
13046 Currently we only support sets of size WORD.
13049 static void doSetC (mcPretty_pretty p
, decl_node n
)
13051 mcDebug_assert (decl_isSet (n
));
13052 outText (p
, (const char *) "unsigned int", 12);
13053 mcPretty_setNeedSpace (p
);
13061 static void doTypeC (mcPretty_pretty p
, decl_node n
, decl_node
*m
)
13065 outText (p
, (const char *) "void", 4);
13067 else if (isBase (n
))
13069 /* avoid dangling else. */
13072 else if (isSystem (n
))
13074 /* avoid dangling else. */
13077 else if (decl_isEnumeration (n
))
13079 /* avoid dangling else. */
13080 doEnumerationC (p
, n
);
13082 else if (decl_isType (n
))
13084 /* avoid dangling else. */
13087 ELSIF isProcType (n) OR isArray (n) OR isRecord (n)
13089 HALT n should have been simplified.
13091 mcPretty_setNeedSpace (p
);
13093 else if (decl_isProcType (n
))
13095 /* avoid dangling else. */
13096 doProcTypeC (p
, n
, (*m
));
13098 else if (decl_isArray (n
))
13100 /* avoid dangling else. */
13103 else if (decl_isRecord (n
))
13105 /* avoid dangling else. */
13106 doRecordC (p
, n
, m
);
13108 else if (decl_isPointer (n
))
13110 /* avoid dangling else. */
13111 doPointerC (p
, n
, m
);
13113 else if (decl_isSubrange (n
))
13115 /* avoid dangling else. */
13116 doSubrangeC (p
, n
);
13118 else if (decl_isSet (n
))
13120 /* avoid dangling else. */
13125 /* avoid dangling else. */
13127 mcPretty_print (p
, (const char *) "to do ... typedef etc etc ", 27);
13129 mcPretty_print (p
, (const char *) ";\\n", 3);
13131 __builtin_unreachable ();
13137 doArrayNameC - it displays the array declaration (it might be an unbounded).
13140 static void doArrayNameC (mcPretty_pretty p
, decl_node n
)
13142 doTypeNameC (p
, decl_getType (n
));
13143 mcPretty_setNeedSpace (p
);
13144 outText (p
, (const char *) "*", 1);
13149 doRecordNameC - emit the C/C++ record name <name of n>"_r".
13152 static void doRecordNameC (mcPretty_pretty p
, decl_node n
)
13154 DynamicStrings_String s
;
13156 s
= getFQstring (n
);
13157 s
= DynamicStrings_ConCat (s
, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "_r", 2)));
13159 s
= DynamicStrings_KillString (s
);
13164 doPointerNameC - emit the C/C++ pointer type <name of n>*.
13167 static void doPointerNameC (mcPretty_pretty p
, decl_node n
)
13169 doTypeNameC (p
, decl_getType (n
));
13170 mcPretty_setNeedSpace (p
);
13171 outText (p
, (const char *) "*", 1);
13179 static void doTypeNameC (mcPretty_pretty p
, decl_node n
)
13181 DynamicStrings_String t
;
13185 outText (p
, (const char *) "void", 4);
13186 mcPretty_setNeedSpace (p
);
13188 else if (isBase (n
))
13190 /* avoid dangling else. */
13193 else if (isSystem (n
))
13195 /* avoid dangling else. */
13198 else if (decl_isEnumeration (n
))
13200 /* avoid dangling else. */
13201 mcPretty_print (p
, (const char *) "is enumeration type name required\\n", 35);
13203 else if (decl_isType (n
))
13205 /* avoid dangling else. */
13208 else if (decl_isProcType (n
))
13210 /* avoid dangling else. */
13212 outText (p
, (const char *) "_t", 2);
13214 else if (decl_isArray (n
))
13216 /* avoid dangling else. */
13217 doArrayNameC (p
, n
);
13219 else if (decl_isRecord (n
))
13221 /* avoid dangling else. */
13222 doRecordNameC (p
, n
);
13224 else if (decl_isPointer (n
))
13226 /* avoid dangling else. */
13227 doPointerNameC (p
, n
);
13229 else if (decl_isSubrange (n
))
13231 /* avoid dangling else. */
13232 doSubrangeC (p
, n
);
13236 /* avoid dangling else. */
13237 mcPretty_print (p
, (const char *) "is type unknown required\\n", 26);
13244 isExternal - returns TRUE if symbol, n, was declared in another module.
13247 static bool isExternal (decl_node n
)
13251 s
= decl_getScope (n
);
13252 return ((s
!= NULL
) && (decl_isDef (s
))) && (((decl_isImp (decl_getMainModule ())) && (s
!= (decl_lookupDef (decl_getSymName (decl_getMainModule ()))))) || (decl_isModule (decl_getMainModule ())));
13253 /* static analysis guarentees a RETURN statement will be used before here. */
13254 __builtin_unreachable ();
13262 static void doVarC (decl_node n
)
13266 if (decl_isDef (decl_getMainModule ()))
13268 mcPretty_print (doP
, (const char *) "EXTERN", 6);
13269 mcPretty_setNeedSpace (doP
);
13271 else if ((! (decl_isExported (n
))) && (! (isLocal (n
))))
13273 /* avoid dangling else. */
13274 mcPretty_print (doP
, (const char *) "static", 6);
13275 mcPretty_setNeedSpace (doP
);
13277 else if (mcOptions_getExtendedOpaque ())
13279 /* avoid dangling else. */
13280 if (isExternal (n
))
13282 /* different module declared this variable, therefore it is extern. */
13283 mcPretty_print (doP
, (const char *) "extern", 6);
13284 mcPretty_setNeedSpace (doP
);
13288 doTypeC (doP
, decl_getType (n
), &s
);
13289 mcPretty_setNeedSpace (doP
);
13290 doFQDNameC (doP
, n
, false);
13291 mcPretty_print (doP
, (const char *) ";\\n", 3);
13299 static void doExternCP (mcPretty_pretty p
)
13301 if (lang
== decl_ansiCP
)
13303 outText (p
, (const char *) "extern \"C\"", 10);
13304 mcPretty_setNeedSpace (p
);
13310 doProcedureCommentText -
13313 static void doProcedureCommentText (mcPretty_pretty p
, DynamicStrings_String s
)
13316 from the start of the comment. */
13317 while (((DynamicStrings_Length (s
)) > 0) && ((DynamicStrings_char (s
, 0)) == ASCII_lf
))
13319 s
= DynamicStrings_Slice (s
, 1, 0);
13326 doProcedureComment -
13329 static void doProcedureComment (mcPretty_pretty p
, DynamicStrings_String s
)
13333 outText (p
, (const char *) "\\n/*\\n", 6);
13334 doProcedureCommentText (p
, s
);
13335 outText (p
, (const char *) "*/\\n\\n", 6);
13341 doProcedureHeadingC -
13344 static void doProcedureHeadingC (decl_node n
, bool prototype
)
13351 mcDebug_assert (decl_isProcedure (n
));
13352 mcPretty_noSpace (doP
);
13353 if (decl_isDef (decl_getMainModule ()))
13355 doProcedureComment (doP
, mcComment_getContent (n
->procedureF
.defComment
));
13356 outText (doP
, (const char *) "EXTERN", 6);
13357 mcPretty_setNeedSpace (doP
);
13359 else if (decl_isExported (n
))
13361 /* avoid dangling else. */
13362 doProcedureComment (doP
, mcComment_getContent (n
->procedureF
.modComment
));
13367 /* avoid dangling else. */
13368 doProcedureComment (doP
, mcComment_getContent (n
->procedureF
.modComment
));
13369 outText (doP
, (const char *) "static", 6);
13370 mcPretty_setNeedSpace (doP
);
13373 doTypeC (doP
, n
->procedureF
.returnType
, &q
);
13374 mcPretty_setNeedSpace (doP
);
13375 doFQDNameC (doP
, n
, false);
13376 mcPretty_setNeedSpace (doP
);
13377 outText (doP
, (const char *) "(", 1);
13378 i
= Indexing_LowIndice (n
->procedureF
.parameters
);
13379 h
= Indexing_HighIndice (n
->procedureF
.parameters
);
13382 p
= static_cast<decl_node
> (Indexing_GetIndice (n
->procedureF
.parameters
, i
));
13383 doParameterC (doP
, p
);
13384 mcPretty_noSpace (doP
);
13387 mcPretty_print (doP
, (const char *) ",", 1);
13388 mcPretty_setNeedSpace (doP
);
13394 outText (doP
, (const char *) "void", 4);
13396 mcPretty_print (doP
, (const char *) ")", 1);
13397 if ((n
->procedureF
.noreturn
&& prototype
) && (! (mcOptions_getSuppressNoReturn ())))
13399 mcPretty_setNeedSpace (doP
);
13400 outText (doP
, (const char *) "__attribute__ ((noreturn))", 26);
13406 checkDeclareUnboundedParamCopyC -
13409 static bool checkDeclareUnboundedParamCopyC (mcPretty_pretty p
, decl_node n
)
13418 t
= decl_getType (n
);
13419 l
= n
->paramF
.namelist
->identlistF
.names
;
13420 if (((decl_isArray (t
)) && (decl_isUnbounded (t
))) && (l
!= NULL
))
13422 t
= decl_getType (t
);
13423 c
= wlists_noOfItemsInList (l
);
13427 doTypeNameC (p
, t
);
13428 mcPretty_setNeedSpace (p
);
13429 doNamesC (p
, wlists_getItemFromList (l
, i
));
13430 outText (p
, (const char *) "[_", 2);
13431 doNamesC (p
, wlists_getItemFromList (l
, i
));
13432 outText (p
, (const char *) "_high+1];\\n", 11);
13438 /* static analysis guarentees a RETURN statement will be used before here. */
13439 __builtin_unreachable ();
13444 checkUnboundedParamCopyC -
13447 static void checkUnboundedParamCopyC (mcPretty_pretty p
, decl_node n
)
13455 t
= decl_getType (n
);
13456 l
= n
->paramF
.namelist
->identlistF
.names
;
13457 if (((decl_isArray (t
)) && (decl_isUnbounded (t
))) && (l
!= NULL
))
13459 c
= wlists_noOfItemsInList (l
);
13461 t
= decl_getType (t
);
13462 s
= decl_skipType (t
);
13466 outText (p
, (const char *) "memcpy (", 8);
13467 doNamesC (p
, wlists_getItemFromList (l
, i
));
13468 outText (p
, (const char *) ",", 1);
13469 mcPretty_setNeedSpace (p
);
13470 doNamesC (p
, wlists_getItemFromList (l
, i
));
13471 outText (p
, (const char *) "_, ", 3);
13472 if (((s
== charN
) || (s
== byteN
)) || (s
== locN
))
13474 outText (p
, (const char *) "_", 1);
13475 doNamesC (p
, wlists_getItemFromList (l
, i
));
13476 outText (p
, (const char *) "_high+1);\\n", 11);
13480 outText (p
, (const char *) "(_", 2);
13481 doNamesC (p
, wlists_getItemFromList (l
, i
));
13482 outText (p
, (const char *) "_high+1)", 8);
13483 mcPretty_setNeedSpace (p
);
13484 doMultiplyBySize (p
, t
);
13485 outText (p
, (const char *) ");\\n", 4);
13494 doUnboundedParamCopyC -
13497 static void doUnboundedParamCopyC (mcPretty_pretty p
, decl_node n
)
13504 mcDebug_assert (decl_isProcedure (n
));
13505 i
= Indexing_LowIndice (n
->procedureF
.parameters
);
13506 h
= Indexing_HighIndice (n
->procedureF
.parameters
);
13510 q
= static_cast<decl_node
> (Indexing_GetIndice (n
->procedureF
.parameters
, i
));
13511 if (decl_isParam (q
))
13513 seen
= (checkDeclareUnboundedParamCopyC (p
, q
)) || seen
;
13519 outText (p
, (const char *) "\\n", 2);
13520 outText (p
, (const char *) "/* make a local copy of each unbounded array. */\\n", 51);
13521 i
= Indexing_LowIndice (n
->procedureF
.parameters
);
13524 q
= static_cast<decl_node
> (Indexing_GetIndice (n
->procedureF
.parameters
, i
));
13525 if (decl_isParam (q
))
13527 checkUnboundedParamCopyC (p
, q
);
13539 static void doPrototypeC (decl_node n
)
13541 if (! (decl_isExported (n
)))
13543 keyc_enterScope (n
);
13544 doProcedureHeadingC (n
, true);
13545 mcPretty_print (doP
, (const char *) ";\\n", 3);
13546 keyc_leaveScope (n
);
13552 addTodo - adds, n, to the todo list.
13555 static void addTodo (decl_node n
)
13557 if (((n
!= NULL
) && (! (alists_isItemInList (partialQ
, reinterpret_cast<void *> (n
))))) && (! (alists_isItemInList (doneQ
, reinterpret_cast<void *> (n
)))))
13559 mcDebug_assert (! (decl_isVarient (n
)));
13560 mcDebug_assert (! (decl_isVarientField (n
)));
13561 mcDebug_assert (! (decl_isDef (n
)));
13562 alists_includeItemIntoList (todoQ
, reinterpret_cast<void *> (n
));
13571 static void addVariablesTodo (decl_node n
)
13573 if (decl_isVar (n
))
13575 /* avoid gcc warning by using compound statement even if not strictly necessary. */
13576 if (n
->varF
.isParameter
|| n
->varF
.isVarParameter
)
13579 addTodo (decl_getType (n
));
13593 static void addTypesTodo (decl_node n
)
13595 if (decl_isUnbounded (n
))
13610 static DynamicStrings_String
tempName (void)
13613 return FormatStrings_Sprintf1 (DynamicStrings_InitString ((const char *) "_T%d", 4), (const unsigned char *) &tempCount
, (sizeof (tempCount
)-1));
13614 /* static analysis guarentees a RETURN statement will be used before here. */
13615 __builtin_unreachable ();
13620 makeIntermediateType -
13623 static decl_node
makeIntermediateType (DynamicStrings_String s
, decl_node p
)
13628 n
= nameKey_makekey (DynamicStrings_string (s
));
13629 decl_enterScope (decl_getScope (p
));
13631 p
= decl_makeType (nameKey_makekey (DynamicStrings_string (s
)));
13632 decl_putType (p
, o
);
13633 putTypeInternal (p
);
13634 decl_leaveScope ();
13636 /* static analysis guarentees a RETURN statement will be used before here. */
13637 __builtin_unreachable ();
13645 static void simplifyType (alists_alist l
, decl_node
*p
)
13647 DynamicStrings_String s
;
13649 if ((((*p
) != NULL
) && (((decl_isRecord ((*p
))) || (decl_isArray ((*p
)))) || (decl_isProcType ((*p
))))) && (! (decl_isUnbounded ((*p
)))))
13652 (*p
) = makeIntermediateType (s
, (*p
));
13653 s
= DynamicStrings_KillString (s
);
13654 simplified
= false;
13656 simplifyNode (l
, (*p
));
13664 static void simplifyVar (alists_alist l
, decl_node n
)
13672 mcDebug_assert (decl_isVar (n
));
13674 simplifyType (l
, &n
->varF
.type
);
13675 if (o
!= n
->varF
.type
)
13677 /* simplification has occurred, make sure that all other variables of this type
13678 use the new type. */
13680 mcDebug_assert (isVarDecl (d
));
13681 t
= wlists_noOfItemsInList (d
->vardeclF
.names
);
13685 v
= decl_lookupInScope (n
->varF
.scope
, wlists_getItemFromList (d
->vardeclF
.names
, i
));
13686 mcDebug_assert (decl_isVar (v
));
13687 v
->varF
.type
= n
->varF
.type
;
13698 static void simplifyRecord (alists_alist l
, decl_node n
)
13704 i
= Indexing_LowIndice (n
->recordF
.listOfSons
);
13705 t
= Indexing_HighIndice (n
->recordF
.listOfSons
);
13708 q
= static_cast<decl_node
> (Indexing_GetIndice (n
->recordF
.listOfSons
, i
));
13709 simplifyNode (l
, q
);
13719 static void simplifyVarient (alists_alist l
, decl_node n
)
13725 simplifyNode (l
, n
->varientF
.tag
);
13726 i
= Indexing_LowIndice (n
->varientF
.listOfSons
);
13727 t
= Indexing_HighIndice (n
->varientF
.listOfSons
);
13730 q
= static_cast<decl_node
> (Indexing_GetIndice (n
->varientF
.listOfSons
, i
));
13731 simplifyNode (l
, q
);
13738 simplifyVarientField -
13741 static void simplifyVarientField (alists_alist l
, decl_node n
)
13747 i
= Indexing_LowIndice (n
->varientfieldF
.listOfSons
);
13748 t
= Indexing_HighIndice (n
->varientfieldF
.listOfSons
);
13751 q
= static_cast<decl_node
> (Indexing_GetIndice (n
->varientfieldF
.listOfSons
, i
));
13752 simplifyNode (l
, q
);
13762 static void doSimplifyNode (alists_alist l
, decl_node n
)
13766 else if (decl_isType (n
))
13768 /* avoid dangling else. */
13769 /* no need to simplify a type. */
13770 simplifyNode (l
, decl_getType (n
));
13772 else if (decl_isVar (n
))
13774 /* avoid dangling else. */
13775 simplifyVar (l
, n
);
13777 else if (decl_isRecord (n
))
13779 /* avoid dangling else. */
13780 simplifyRecord (l
, n
);
13782 else if (decl_isRecordField (n
))
13784 /* avoid dangling else. */
13785 simplifyType (l
, &n
->recordfieldF
.type
);
13787 else if (decl_isArray (n
))
13789 /* avoid dangling else. */
13790 simplifyType (l
, &n
->arrayF
.type
);
13792 else if (decl_isVarient (n
))
13794 /* avoid dangling else. */
13795 simplifyVarient (l
, n
);
13797 else if (decl_isVarientField (n
))
13799 /* avoid dangling else. */
13800 simplifyVarientField (l
, n
);
13802 else if (decl_isPointer (n
))
13804 /* avoid dangling else. */
13805 simplifyType (l
, &n
->pointerF
.type
);
13814 static void simplifyNode (alists_alist l
, decl_node n
)
13816 if (! (alists_isItemInList (l
, reinterpret_cast<void *> (n
))))
13818 alists_includeItemIntoList (l
, reinterpret_cast<void *> (n
));
13819 doSimplifyNode (l
, n
);
13828 static void doSimplify (decl_node n
)
13832 l
= alists_initList ();
13833 simplifyNode (l
, n
);
13834 alists_killList (&l
);
13842 static void simplifyTypes (decl_scopeT s
)
13846 Indexing_ForeachIndiceInIndexDo (s
.types
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) doSimplify
});
13847 Indexing_ForeachIndiceInIndexDo (s
.variables
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) doSimplify
});
13848 } while (! (simplified
));
13856 static void outDeclsDefC (mcPretty_pretty p
, decl_node n
)
13862 includeConstType (s
);
13864 topologicallyOut ((decl_nodeProcedure
) {(decl_nodeProcedure_t
) doConstC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doTypesC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doVarC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) outputPartial
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNone
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doCompletePartialC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNone
});
13865 /* try and output types, constants before variables and procedures. */
13866 includeDefVarProcedure (n
);
13867 topologicallyOut ((decl_nodeProcedure
) {(decl_nodeProcedure_t
) doConstC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doTypesC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doVarC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) outputPartial
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNone
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doCompletePartialC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNone
});
13868 Indexing_ForeachIndiceInIndexDo (s
.procedures
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) doPrototypeC
});
13876 static void includeConstType (decl_scopeT s
)
13878 Indexing_ForeachIndiceInIndexDo (s
.constants
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) addTodo
});
13879 Indexing_ForeachIndiceInIndexDo (s
.types
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) addTypesTodo
});
13884 includeVarProcedure -
13887 static void includeVarProcedure (decl_scopeT s
)
13889 Indexing_ForeachIndiceInIndexDo (s
.procedures
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) addTodo
});
13890 Indexing_ForeachIndiceInIndexDo (s
.variables
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) addVariablesTodo
});
13898 static void includeVar (decl_scopeT s
)
13900 Indexing_ForeachIndiceInIndexDo (s
.variables
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) addTodo
});
13908 static void includeExternals (decl_node n
)
13912 l
= alists_initList ();
13913 visitNode (l
, n
, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) addExported
});
13914 alists_killList (&l
);
13919 checkSystemInclude -
13922 static void checkSystemInclude (decl_node n
)
13931 static void addExported (decl_node n
)
13935 s
= decl_getScope (n
);
13936 if (((s
!= NULL
) && (decl_isDef (s
))) && (s
!= defModule
))
13938 if (((decl_isType (n
)) || (decl_isVar (n
))) || (decl_isConst (n
)))
13947 addExternal - only adds, n, if this symbol is external to the
13948 implementation module and is not a hidden type.
13951 static void addExternal (decl_node n
)
13953 if (((((decl_getScope (n
)) == defModule
) && (decl_isType (n
))) && (decl_isTypeHidden (n
))) && (! (mcOptions_getExtendedOpaque ())))
13956 else if (! (decl_isDef (n
)))
13958 /* avoid dangling else. */
13965 includeDefConstType -
13968 static void includeDefConstType (decl_node n
)
13972 if (decl_isImp (n
))
13974 defModule
= decl_lookupDef (decl_getSymName (n
));
13975 if (defModule
!= NULL
)
13977 simplifyTypes (defModule
->defF
.decls
);
13978 includeConstType (defModule
->defF
.decls
);
13979 symbolKey_foreachNodeDo (defModule
->defF
.decls
.symbols
, (symbolKey_performOperation
) {(symbolKey_performOperation_t
) addExternal
});
13986 runIncludeDefConstType -
13989 static void runIncludeDefConstType (decl_node n
)
13993 if (decl_isDef (n
))
13995 simplifyTypes (n
->defF
.decls
);
13996 includeConstType (n
->defF
.decls
);
13997 symbolKey_foreachNodeDo (n
->defF
.decls
.symbols
, (symbolKey_performOperation
) {(symbolKey_performOperation_t
) addExternal
});
14003 joinProcedures - copies procedures from definition module,
14004 d, into implementation module, i.
14007 static void joinProcedures (decl_node i
, decl_node d
)
14012 mcDebug_assert (decl_isDef (d
));
14013 mcDebug_assert (decl_isImp (i
));
14015 h
= Indexing_HighIndice (d
->defF
.decls
.procedures
);
14018 Indexing_IncludeIndiceIntoIndex (i
->impF
.decls
.procedures
, Indexing_GetIndice (d
->defF
.decls
.procedures
, j
));
14025 includeDefVarProcedure -
14028 static void includeDefVarProcedure (decl_node n
)
14032 if (decl_isImp (n
))
14034 /* avoid dangling else. */
14035 defModule
= decl_lookupDef (decl_getSymName (n
));
14036 if (defModule
!= NULL
)
14039 includeVar (defModule^.defF.decls) ;
14040 simplifyTypes (defModule^.defF.decls) ;
14042 joinProcedures (n
, defModule
);
14045 else if (decl_isDef (n
))
14047 /* avoid dangling else. */
14048 includeVar (n
->defF
.decls
);
14049 simplifyTypes (n
->defF
.decls
);
14058 static void foreachModuleDo (decl_node n
, symbolKey_performOperation p
)
14060 decl_foreachDefModuleDo (p
);
14061 decl_foreachModModuleDo (p
);
14069 static void outDeclsImpC (mcPretty_pretty p
, decl_scopeT s
)
14072 includeConstType (s
);
14074 topologicallyOut ((decl_nodeProcedure
) {(decl_nodeProcedure_t
) doConstC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doTypesC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doVarC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) outputPartial
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNone
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doCompletePartialC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNone
});
14075 /* try and output types, constants before variables and procedures. */
14076 includeVarProcedure (s
);
14077 topologicallyOut ((decl_nodeProcedure
) {(decl_nodeProcedure_t
) doConstC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doTypesC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doVarC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) outputPartial
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNone
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doCompletePartialC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNone
});
14082 doStatementSequenceC -
14085 static void doStatementSequenceC (mcPretty_pretty p
, decl_node s
)
14090 mcDebug_assert (decl_isStatementSequence (s
));
14091 h
= Indexing_HighIndice (s
->stmtF
.statements
);
14095 doStatementsC (p
, reinterpret_cast<decl_node
> (Indexing_GetIndice (s
->stmtF
.statements
, i
)));
14102 isStatementSequenceEmpty -
14105 static bool isStatementSequenceEmpty (decl_node s
)
14107 mcDebug_assert (decl_isStatementSequence (s
));
14108 return (Indexing_HighIndice (s
->stmtF
.statements
)) == 0;
14109 /* static analysis guarentees a RETURN statement will be used before here. */
14110 __builtin_unreachable ();
14115 isSingleStatement - returns TRUE if the statement sequence, s, has
14116 only one statement.
14119 static bool isSingleStatement (decl_node s
)
14123 mcDebug_assert (decl_isStatementSequence (s
));
14124 h
= Indexing_HighIndice (s
->stmtF
.statements
);
14125 if ((h
== 0) || (h
> 1))
14129 s
= static_cast<decl_node
> (Indexing_GetIndice (s
->stmtF
.statements
, 1));
14130 return (! (decl_isStatementSequence (s
))) || (isSingleStatement (s
));
14131 /* static analysis guarentees a RETURN statement will be used before here. */
14132 __builtin_unreachable ();
14140 static void doCommentC (mcPretty_pretty p
, decl_node s
)
14142 DynamicStrings_String c
;
14146 mcDebug_assert (isComment (s
));
14147 if (! (mcComment_isProcedureComment (s
->commentF
.content
)))
14149 if (mcComment_isAfterComment (s
->commentF
.content
))
14151 mcPretty_setNeedSpace (p
);
14152 outText (p
, (const char *) " /* ", 4);
14156 outText (p
, (const char *) "/* ", 3);
14158 c
= mcComment_getContent (s
->commentF
.content
);
14159 c
= DynamicStrings_RemoveWhitePrefix (DynamicStrings_RemoveWhitePostfix (c
));
14161 outText (p
, (const char *) " */\\n", 6);
14168 doAfterCommentC - emit an after comment, c, or a newline if, c, is empty.
14171 static void doAfterCommentC (mcPretty_pretty p
, decl_node c
)
14175 outText (p
, (const char *) "\\n", 2);
14185 doReturnC - issue a return statement and also place in an after comment if one exists.
14188 static void doReturnC (mcPretty_pretty p
, decl_node s
)
14190 mcDebug_assert (decl_isReturn (s
));
14191 doCommentC (p
, s
->returnF
.returnComment
.body
);
14192 outText (p
, (const char *) "return", 6);
14193 if (s
->returnF
.scope
!= NULL
)
14195 mcPretty_setNeedSpace (p
);
14196 if ((! (decl_isProcedure (s
->returnF
.scope
))) || ((decl_getType (s
->returnF
.scope
)) == NULL
))
14198 mcMetaError_metaError1 ((const char *) "{%1DMad} has no return type", 27, (const unsigned char *) &s
->returnF
.scope
, (sizeof (s
->returnF
.scope
)-1));
14202 doExprCastC (p
, s
->returnF
.exp
, decl_getType (s
->returnF
.scope
));
14205 outText (p
, (const char *) ";", 1);
14206 doAfterCommentC (p
, s
->returnF
.returnComment
.after
);
14211 isZtypeEquivalent -
14214 static bool isZtypeEquivalent (decl_node type
)
14216 switch (type
->kind
)
14218 case decl_cardinal
:
14219 case decl_longcard
:
14220 case decl_shortcard
:
14223 case decl_shortint
:
14233 /* static analysis guarentees a RETURN statement will be used before here. */
14234 __builtin_unreachable ();
14239 isEquivalentType - returns TRUE if type1 and type2 are equivalent.
14242 static bool isEquivalentType (decl_node type1
, decl_node type2
)
14244 type1
= decl_skipType (type1
);
14245 type2
= decl_skipType (type2
);
14246 return (type1
== type2
) || ((isZtypeEquivalent (type1
)) && (isZtypeEquivalent (type2
)));
14247 /* static analysis guarentees a RETURN statement will be used before here. */
14248 __builtin_unreachable ();
14253 doExprCastC - build a cast if necessary.
14256 static void doExprCastC (mcPretty_pretty p
, decl_node e
, decl_node type
)
14260 stype
= decl_skipType (type
);
14261 if ((! (isEquivalentType (type
, getExprType (e
)))) && (! ((e
->kind
== decl_nil
) && ((decl_isPointer (stype
)) || (stype
->kind
== decl_address
)))))
14263 if (lang
== decl_ansiCP
)
14265 /* avoid gcc warning by using compound statement even if not strictly necessary. */
14266 /* potentially a cast is required. */
14267 if ((decl_isPointer (type
)) || (type
== addressN
))
14269 outText (p
, (const char *) "reinterpret_cast<", 17);
14270 doTypeNameC (p
, type
);
14271 mcPretty_noSpace (p
);
14272 outText (p
, (const char *) "> (", 3);
14274 outText (p
, (const char *) ")", 1);
14279 outText (p
, (const char *) "static_cast<", 12);
14280 if (decl_isProcType (decl_skipType (type
)))
14282 doTypeNameC (p
, type
);
14283 outText (p
, (const char *) "_t", 2);
14287 doTypeNameC (p
, type
);
14289 mcPretty_noSpace (p
);
14290 outText (p
, (const char *) "> (", 3);
14292 outText (p
, (const char *) ")", 1);
14302 requiresUnpackProc - returns TRUE if either the expr is a procedure or the proctypes differ.
14305 static bool requiresUnpackProc (decl_node s
)
14307 mcDebug_assert (isAssignment (s
));
14308 return (decl_isProcedure (s
->assignmentF
.expr
)) || ((decl_skipType (decl_getType (s
->assignmentF
.des
))) != (decl_skipType (decl_getType (s
->assignmentF
.expr
))));
14309 /* static analysis guarentees a RETURN statement will be used before here. */
14310 __builtin_unreachable ();
14318 static void doAssignmentC (mcPretty_pretty p
, decl_node s
)
14320 mcDebug_assert (isAssignment (s
));
14321 doCommentC (p
, s
->assignmentF
.assignComment
.body
);
14322 doExprCup (p
, s
->assignmentF
.des
, requiresUnpackProc (s
));
14323 mcPretty_setNeedSpace (p
);
14324 outText (p
, (const char *) "=", 1);
14325 mcPretty_setNeedSpace (p
);
14326 doExprCastC (p
, s
->assignmentF
.expr
, decl_getType (s
->assignmentF
.des
));
14327 outText (p
, (const char *) ";", 1);
14328 doAfterCommentC (p
, s
->assignmentF
.assignComment
.after
);
14333 containsStatement -
14336 static bool containsStatement (decl_node s
)
14338 return ((s
!= NULL
) && (decl_isStatementSequence (s
))) && (! (isStatementSequenceEmpty (s
)));
14339 /* static analysis guarentees a RETURN statement will be used before here. */
14340 __builtin_unreachable ();
14348 static void doCompoundStmt (mcPretty_pretty p
, decl_node s
)
14350 if ((s
== NULL
) || ((decl_isStatementSequence (s
)) && (isStatementSequenceEmpty (s
))))
14352 p
= mcPretty_pushPretty (p
);
14353 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
14354 outText (p
, (const char *) "{} /* empty. */\\n", 19);
14355 p
= mcPretty_popPretty (p
);
14357 else if (((decl_isStatementSequence (s
)) && (isSingleStatement (s
))) && ! forceCompoundStatement
)
14359 /* avoid dangling else. */
14360 p
= mcPretty_pushPretty (p
);
14361 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
14362 doStatementSequenceC (p
, s
);
14363 p
= mcPretty_popPretty (p
);
14367 /* avoid dangling else. */
14368 p
= mcPretty_pushPretty (p
);
14369 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
14370 outText (p
, (const char *) "{\\n", 3);
14371 p
= mcPretty_pushPretty (p
);
14372 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
14373 doStatementSequenceC (p
, s
);
14374 p
= mcPretty_popPretty (p
);
14375 outText (p
, (const char *) "}\\n", 3);
14376 p
= mcPretty_popPretty (p
);
14385 static void doElsifC (mcPretty_pretty p
, decl_node s
)
14387 mcDebug_assert (decl_isElsif (s
));
14388 outText (p
, (const char *) "else if", 7);
14389 mcPretty_setNeedSpace (p
);
14390 outText (p
, (const char *) "(", 1);
14391 doExprC (p
, s
->elsifF
.expr
);
14392 outText (p
, (const char *) ")\\n", 3);
14393 mcDebug_assert ((s
->elsifF
.else_
== NULL
) || (s
->elsifF
.elsif
== NULL
));
14394 if (forceCompoundStatement
|| ((hasIfAndNoElse (s
->elsifF
.then
)) && ((s
->elsifF
.else_
!= NULL
) || (s
->elsifF
.elsif
!= NULL
))))
14396 /* avoid dangling else. */
14397 p
= mcPretty_pushPretty (p
);
14398 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
14399 outText (p
, (const char *) "{\\n", 3);
14400 p
= mcPretty_pushPretty (p
);
14401 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
14402 outText (p
, (const char *) "/* avoid dangling else. */\\n", 29);
14403 doStatementSequenceC (p
, s
->elsifF
.then
);
14404 p
= mcPretty_popPretty (p
);
14405 outText (p
, (const char *) "}\\n", 3);
14406 p
= mcPretty_popPretty (p
);
14410 doCompoundStmt (p
, s
->elsifF
.then
);
14412 if (containsStatement (s
->elsifF
.else_
))
14414 outText (p
, (const char *) "else\\n", 6);
14415 if (forceCompoundStatement
)
14417 /* avoid dangling else. */
14418 p
= mcPretty_pushPretty (p
);
14419 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
14420 outText (p
, (const char *) "{\\n", 3);
14421 p
= mcPretty_pushPretty (p
);
14422 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
14423 outText (p
, (const char *) "/* avoid dangling else. */\\n", 29);
14424 doStatementSequenceC (p
, s
->elsifF
.else_
);
14425 p
= mcPretty_popPretty (p
);
14426 outText (p
, (const char *) "}\\n", 3);
14427 p
= mcPretty_popPretty (p
);
14431 doCompoundStmt (p
, s
->elsifF
.else_
);
14434 else if ((s
->elsifF
.elsif
!= NULL
) && (decl_isElsif (s
->elsifF
.elsif
)))
14436 /* avoid dangling else. */
14437 doElsifC (p
, s
->elsifF
.elsif
);
14446 static bool noIfElse (decl_node n
)
14448 return (((n
!= NULL
) && (decl_isIf (n
))) && (n
->ifF
.else_
== NULL
)) && (n
->ifF
.elsif
== NULL
);
14449 /* static analysis guarentees a RETURN statement will be used before here. */
14450 __builtin_unreachable ();
14455 noIfElseChained - returns TRUE if, n, is an IF statement which
14456 has no associated ELSE statement. An IF with an
14457 ELSIF is also checked for no ELSE and will result
14458 in a return value of TRUE.
14461 static bool noIfElseChained (decl_node n
)
14467 /* avoid gcc warning by using compound statement even if not strictly necessary. */
14470 if (n
->ifF
.else_
!= NULL
)
14472 /* we do have an else, continue to check this statement. */
14473 return hasIfAndNoElse (n
->ifF
.else_
);
14475 else if (n
->ifF
.elsif
== NULL
)
14477 /* avoid dangling else. */
14478 /* neither else or elsif. */
14483 /* avoid dangling else. */
14484 /* test elsif for lack of else. */
14486 mcDebug_assert (decl_isElsif (e
));
14487 return noIfElseChained (e
);
14490 else if (decl_isElsif (n
))
14492 /* avoid dangling else. */
14493 if (n
->elsifF
.else_
!= NULL
)
14495 /* we do have an else, continue to check this statement. */
14496 return hasIfAndNoElse (n
->elsifF
.else_
);
14498 else if (n
->elsifF
.elsif
== NULL
)
14500 /* avoid dangling else. */
14501 /* neither else or elsif. */
14506 /* avoid dangling else. */
14507 /* test elsif for lack of else. */
14508 e
= n
->elsifF
.elsif
;
14509 mcDebug_assert (decl_isElsif (e
));
14510 return noIfElseChained (e
);
14515 /* static analysis guarentees a RETURN statement will be used before here. */
14516 __builtin_unreachable ();
14524 static bool hasIfElse (decl_node n
)
14528 if (decl_isStatementSequence (n
))
14530 /* avoid gcc warning by using compound statement even if not strictly necessary. */
14531 if (isStatementSequenceEmpty (n
))
14535 else if (isSingleStatement (n
))
14537 /* avoid dangling else. */
14538 n
= static_cast<decl_node
> (Indexing_GetIndice (n
->stmtF
.statements
, 1));
14539 return isIfElse (n
);
14544 /* static analysis guarentees a RETURN statement will be used before here. */
14545 __builtin_unreachable ();
14553 static bool isIfElse (decl_node n
)
14555 return ((n
!= NULL
) && (decl_isIf (n
))) && ((n
->ifF
.else_
!= NULL
) || (n
->ifF
.elsif
!= NULL
));
14556 /* static analysis guarentees a RETURN statement will be used before here. */
14557 __builtin_unreachable ();
14562 hasIfAndNoElse - returns TRUE if statement, n, is a single statement
14563 which is an IF and it has no else statement.
14566 static bool hasIfAndNoElse (decl_node n
)
14570 /* avoid gcc warning by using compound statement even if not strictly necessary. */
14571 if (decl_isStatementSequence (n
))
14573 if (isStatementSequenceEmpty (n
))
14577 else if (isSingleStatement (n
))
14579 /* avoid dangling else. */
14580 n
= static_cast<decl_node
> (Indexing_GetIndice (n
->stmtF
.statements
, 1));
14581 return hasIfAndNoElse (n
);
14585 /* avoid dangling else. */
14586 n
= static_cast<decl_node
> (Indexing_GetIndice (n
->stmtF
.statements
, Indexing_HighIndice (n
->stmtF
.statements
)));
14587 return hasIfAndNoElse (n
);
14590 else if ((decl_isElsif (n
)) || (decl_isIf (n
)))
14592 /* avoid dangling else. */
14593 return noIfElseChained (n
);
14597 /* static analysis guarentees a RETURN statement will be used before here. */
14598 __builtin_unreachable ();
14603 doIfC - issue an if statement and also place in an after comment if one exists.
14604 The if statement might contain an else or elsif which are also handled.
14607 static void doIfC (mcPretty_pretty p
, decl_node s
)
14609 mcDebug_assert (decl_isIf (s
));
14610 doCommentC (p
, s
->ifF
.ifComment
.body
);
14611 outText (p
, (const char *) "if", 2);
14612 mcPretty_setNeedSpace (p
);
14613 outText (p
, (const char *) "(", 1);
14614 doExprC (p
, s
->ifF
.expr
);
14615 outText (p
, (const char *) ")", 1);
14616 doAfterCommentC (p
, s
->ifF
.ifComment
.after
);
14617 if ((hasIfAndNoElse (s
->ifF
.then
)) && ((s
->ifF
.else_
!= NULL
) || (s
->ifF
.elsif
!= NULL
)))
14619 /* avoid dangling else. */
14620 p
= mcPretty_pushPretty (p
);
14621 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
14622 outText (p
, (const char *) "{\\n", 3);
14623 p
= mcPretty_pushPretty (p
);
14624 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
14625 outText (p
, (const char *) "/* avoid dangling else. */\\n", 29);
14626 doStatementSequenceC (p
, s
->ifF
.then
);
14627 p
= mcPretty_popPretty (p
);
14628 outText (p
, (const char *) "}\\n", 3);
14629 p
= mcPretty_popPretty (p
);
14631 else if ((noIfElse (s
)) && (hasIfElse (s
->ifF
.then
)))
14633 /* avoid dangling else. */
14634 /* gcc does not like legal non dangling else, as it is poor style.
14635 So we will avoid getting a warning. */
14636 p
= mcPretty_pushPretty (p
);
14637 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
14638 outText (p
, (const char *) "{\\n", 3);
14639 p
= mcPretty_pushPretty (p
);
14640 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
14641 outText (p
, (const char *) "/* avoid gcc warning by using compound statement even if not strictly necessary. */\\n", 86);
14642 doStatementSequenceC (p
, s
->ifF
.then
);
14643 p
= mcPretty_popPretty (p
);
14644 outText (p
, (const char *) "}\\n", 3);
14645 p
= mcPretty_popPretty (p
);
14649 /* avoid dangling else. */
14650 doCompoundStmt (p
, s
->ifF
.then
);
14652 mcDebug_assert ((s
->ifF
.else_
== NULL
) || (s
->ifF
.elsif
== NULL
));
14653 if (containsStatement (s
->ifF
.else_
))
14655 doCommentC (p
, s
->ifF
.elseComment
.body
);
14656 outText (p
, (const char *) "else", 4);
14657 doAfterCommentC (p
, s
->ifF
.elseComment
.after
);
14658 doCompoundStmt (p
, s
->ifF
.else_
);
14660 else if ((s
->ifF
.elsif
!= NULL
) && (decl_isElsif (s
->ifF
.elsif
)))
14662 /* avoid dangling else. */
14663 doCommentC (p
, s
->ifF
.elseComment
.body
);
14664 doCommentC (p
, s
->ifF
.elseComment
.after
);
14665 doElsifC (p
, s
->ifF
.elsif
);
14667 doCommentC (p
, s
->ifF
.endComment
.after
);
14668 doCommentC (p
, s
->ifF
.endComment
.body
);
14676 static void doForIncCP (mcPretty_pretty p
, decl_node s
)
14680 mcDebug_assert (decl_isFor (s
));
14681 t
= decl_skipType (decl_getType (s
->forF
.des
));
14682 if (decl_isEnumeration (t
))
14684 if (s
->forF
.increment
== NULL
)
14686 doExprC (p
, s
->forF
.des
);
14687 outText (p
, (const char *) "= static_cast<", 14);
14688 doTypeNameC (p
, decl_getType (s
->forF
.des
));
14689 mcPretty_noSpace (p
);
14690 outText (p
, (const char *) ">(static_cast<int>(", 19);
14691 doExprC (p
, s
->forF
.des
);
14692 outText (p
, (const char *) "+1))", 4);
14696 doExprC (p
, s
->forF
.des
);
14697 outText (p
, (const char *) "= static_cast<", 14);
14698 doTypeNameC (p
, decl_getType (s
->forF
.des
));
14699 mcPretty_noSpace (p
);
14700 outText (p
, (const char *) ">(static_cast<int>(", 19);
14701 doExprC (p
, s
->forF
.des
);
14702 outText (p
, (const char *) "+", 1);
14703 doExprC (p
, s
->forF
.increment
);
14704 outText (p
, (const char *) "))", 2);
14718 static void doForIncC (mcPretty_pretty p
, decl_node s
)
14720 if (s
->forF
.increment
== NULL
)
14722 doExprC (p
, s
->forF
.des
);
14723 outText (p
, (const char *) "++", 2);
14727 doExprC (p
, s
->forF
.des
);
14728 outText (p
, (const char *) "=", 1);
14729 doExprC (p
, s
->forF
.des
);
14730 outText (p
, (const char *) "+", 1);
14731 doExprC (p
, s
->forF
.increment
);
14740 static void doForInc (mcPretty_pretty p
, decl_node s
)
14742 if (lang
== decl_ansiCP
)
14757 static void doForC (mcPretty_pretty p
, decl_node s
)
14759 mcDebug_assert (decl_isFor (s
));
14760 outText (p
, (const char *) "for (", 5);
14761 doExprC (p
, s
->forF
.des
);
14762 outText (p
, (const char *) "=", 1);
14763 doExprC (p
, s
->forF
.start
);
14764 outText (p
, (const char *) ";", 1);
14765 mcPretty_setNeedSpace (p
);
14766 doExprC (p
, s
->forF
.des
);
14767 outText (p
, (const char *) "<=", 2);
14768 doExprC (p
, s
->forF
.end
);
14769 outText (p
, (const char *) ";", 1);
14770 mcPretty_setNeedSpace (p
);
14772 outText (p
, (const char *) ")\\n", 3);
14773 doCompoundStmt (p
, s
->forF
.statements
);
14781 static void doRepeatC (mcPretty_pretty p
, decl_node s
)
14783 mcDebug_assert (decl_isRepeat (s
));
14784 doCommentC (p
, s
->repeatF
.repeatComment
.body
);
14785 outText (p
, (const char *) "do {", 4);
14786 doAfterCommentC (p
, s
->repeatF
.repeatComment
.after
);
14787 p
= mcPretty_pushPretty (p
);
14788 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
14789 doStatementSequenceC (p
, s
->repeatF
.statements
);
14790 doCommentC (p
, s
->repeatF
.untilComment
.body
);
14791 p
= mcPretty_popPretty (p
);
14792 outText (p
, (const char *) "} while (! (", 12);
14793 doExprC (p
, s
->repeatF
.expr
);
14794 outText (p
, (const char *) "));", 3);
14795 doAfterCommentC (p
, s
->repeatF
.untilComment
.after
);
14803 static void doWhileC (mcPretty_pretty p
, decl_node s
)
14805 mcDebug_assert (decl_isWhile (s
));
14806 doCommentC (p
, s
->whileF
.doComment
.body
);
14807 outText (p
, (const char *) "while (", 7);
14808 doExprC (p
, s
->whileF
.expr
);
14809 outText (p
, (const char *) ")", 1);
14810 doAfterCommentC (p
, s
->whileF
.doComment
.after
);
14811 doCompoundStmt (p
, s
->whileF
.statements
);
14812 doCommentC (p
, s
->whileF
.endComment
.body
);
14813 doCommentC (p
, s
->whileF
.endComment
.after
);
14821 static void doFuncHighC (mcPretty_pretty p
, decl_node a
)
14826 if ((decl_isLiteral (a
)) && ((decl_getType (a
)) == charN
))
14830 else if (isString (a
))
14832 /* avoid dangling else. */
14833 outCard (p
, a
->stringF
.length
-2);
14835 else if ((decl_isConst (a
)) && (isString (a
->constF
.value
)))
14837 /* avoid dangling else. */
14838 doFuncHighC (p
, a
->constF
.value
);
14840 else if (decl_isUnbounded (decl_getType (a
)))
14842 /* avoid dangling else. */
14843 outText (p
, (const char *) "_", 1);
14844 outTextN (p
, decl_getSymName (a
));
14845 outText (p
, (const char *) "_high", 5);
14847 else if (decl_isArray (decl_skipType (decl_getType (a
))))
14849 /* avoid dangling else. */
14850 n
= decl_skipType (decl_getType (a
));
14851 s
= n
->arrayF
.subr
;
14852 if (isZero (getMin (s
)))
14854 doExprC (p
, getMax (s
));
14858 outText (p
, (const char *) "(", 1);
14859 doExprC (p
, getMax (s
));
14860 doSubtractC (p
, getMin (s
));
14861 outText (p
, (const char *) ")", 1);
14866 /* avoid dangling else. */
14867 /* output sizeof (a) in bytes for the high. */
14868 outText (p
, (const char *) "(sizeof", 7);
14869 mcPretty_setNeedSpace (p
);
14870 outText (p
, (const char *) "(", 1);
14872 outText (p
, (const char *) ")-1)", 4);
14881 static void doMultiplyBySize (mcPretty_pretty p
, decl_node a
)
14883 if (((a
!= charN
) && (a
!= byteN
)) && (a
!= locN
))
14885 mcPretty_setNeedSpace (p
);
14886 outText (p
, (const char *) "* sizeof (", 10);
14887 doTypeNameC (p
, a
);
14888 mcPretty_noSpace (p
);
14889 outText (p
, (const char *) ")", 1);
14898 static void doTotype (mcPretty_pretty p
, decl_node a
, decl_node t
)
14900 if ((! (isString (a
))) && (! (decl_isLiteral (a
))))
14902 if (decl_isVar (a
))
14904 if (((a
->varF
.isParameter
|| a
->varF
.isVarParameter
) && (decl_isUnbounded (decl_getType (a
)))) && ((decl_skipType (decl_getType (decl_getType (a
)))) == (decl_skipType (decl_getType (t
)))))
14906 /* do not multiply by size as the existing high value is correct. */
14909 a
= decl_getType (a
);
14910 if (decl_isArray (a
))
14912 doMultiplyBySize (p
, decl_skipType (decl_getType (a
)));
14918 mcPretty_setNeedSpace (p
);
14919 outText (p
, (const char *) "/ sizeof (", 10);
14920 doTypeNameC (p
, wordN
);
14921 mcPretty_noSpace (p
);
14922 outText (p
, (const char *) ")", 1);
14931 static void doFuncUnbounded (mcPretty_pretty p
, decl_node actual
, decl_node formalParam
, decl_node formal
, decl_node func
)
14934 DynamicStrings_String s
;
14936 mcDebug_assert (decl_isUnbounded (formal
));
14937 outText (p
, (const char *) "(", 1);
14938 if ((lang
== decl_ansiCP
) && (decl_isParam (formalParam
)))
14940 outText (p
, (const char *) "const", 5);
14941 mcPretty_setNeedSpace (p
);
14943 doTypeC (p
, decl_getType (formal
), &formal
);
14944 mcPretty_setNeedSpace (p
);
14945 outText (p
, (const char *) "*)", 2);
14946 mcPretty_setNeedSpace (p
);
14947 if ((decl_isLiteral (actual
)) && ((decl_getType (actual
)) == charN
))
14949 outText (p
, (const char *) "\"\\0", 3);
14950 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (actual
->literalF
.name
));
14951 s
= DynamicStrings_Slice (DynamicStrings_Mark (s
), 0, -1);
14953 outText (p
, (const char *) "\"", 1);
14954 s
= DynamicStrings_KillString (s
);
14956 else if (isString (actual
))
14958 /* avoid dangling else. */
14959 outCstring (p
, actual
, true);
14961 else if (decl_isConst (actual
))
14963 /* avoid dangling else. */
14964 actual
= resolveString (actual
);
14965 mcDebug_assert (isString (actual
));
14966 outCstring (p
, actual
, true);
14968 else if (isFuncCall (actual
))
14970 /* avoid dangling else. */
14971 if ((getExprType (actual
)) == NULL
)
14973 mcMetaError_metaError3 ((const char *) "there is no return type to the procedure function {%3ad} which is being passed as the parameter {%1ad} to {%2ad}", 112, (const unsigned char *) &formal
, (sizeof (formal
)-1), (const unsigned char *) &func
, (sizeof (func
)-1), (const unsigned char *) &actual
, (sizeof (actual
)-1));
14977 outText (p
, (const char *) "&", 1);
14978 doExprC (p
, actual
);
14981 else if (decl_isUnbounded (decl_getType (actual
)))
14983 /* avoid dangling else. */
14984 /* doExprC (p, actual). */
14985 doFQNameC (p
, actual
);
14989 /* avoid dangling else. */
14990 outText (p
, (const char *) "&", 1);
14991 doExprC (p
, actual
);
14992 if (decl_isArray (decl_skipType (decl_getType (actual
))))
14994 outText (p
, (const char *) ".array[0]", 9);
14997 if (! (enableDefForCStrings
&& (isDefForC (decl_getScope (func
)))))
14999 outText (p
, (const char *) ",", 1);
15000 mcPretty_setNeedSpace (p
);
15001 doFuncHighC (p
, actual
);
15002 doTotype (p
, actual
, formal
);
15008 doProcedureParamC -
15011 static void doProcedureParamC (mcPretty_pretty p
, decl_node actual
, decl_node formal
)
15013 if (isForC (formal
))
15015 outText (p
, (const char *) "(", 1);
15016 doFQNameC (p
, decl_getType (formal
));
15017 outText (p
, (const char *) "_C", 2);
15018 outText (p
, (const char *) ")", 1);
15019 mcPretty_setNeedSpace (p
);
15020 doExprC (p
, actual
);
15024 outText (p
, (const char *) "(", 1);
15025 doTypeNameC (p
, decl_getType (formal
));
15026 outText (p
, (const char *) ")", 1);
15027 mcPretty_setNeedSpace (p
);
15028 outText (p
, (const char *) "{", 1);
15029 outText (p
, (const char *) "(", 1);
15030 doFQNameC (p
, decl_getType (formal
));
15031 outText (p
, (const char *) "_t)", 3);
15032 mcPretty_setNeedSpace (p
);
15033 doExprC (p
, actual
);
15034 outText (p
, (const char *) "}", 1);
15043 static void doAdrExprC (mcPretty_pretty p
, decl_node n
)
15047 /* no point in issuing & ( * n ) */
15048 doExprC (p
, n
->unaryF
.arg
);
15050 else if ((decl_isVar (n
)) && n
->varF
.isVarParameter
)
15052 /* avoid dangling else. */
15053 /* no point in issuing & ( * n ) */
15058 /* avoid dangling else. */
15059 outText (p
, (const char *) "&", 1);
15069 static bool typePair (decl_node a
, decl_node b
, decl_node x
, decl_node y
)
15071 return ((a
== x
) && (b
== y
)) || ((a
== y
) && (b
== x
));
15072 /* static analysis guarentees a RETURN statement will be used before here. */
15073 __builtin_unreachable ();
15078 needsCast - return TRUE if the actual type parameter needs to be cast to
15082 static bool needsCast (decl_node at
, decl_node ft
)
15084 at
= decl_skipType (at
);
15085 ft
= decl_skipType (ft
);
15086 if (((((((((((((at
== nilN
) || (at
->kind
== decl_nil
)) || (at
== ft
)) || (typePair (at
, ft
, cardinalN
, wordN
))) || (typePair (at
, ft
, cardinalN
, ztypeN
))) || (typePair (at
, ft
, integerN
, ztypeN
))) || (typePair (at
, ft
, longcardN
, ztypeN
))) || (typePair (at
, ft
, shortcardN
, ztypeN
))) || (typePair (at
, ft
, longintN
, ztypeN
))) || (typePair (at
, ft
, shortintN
, ztypeN
))) || (typePair (at
, ft
, realN
, rtypeN
))) || (typePair (at
, ft
, longrealN
, rtypeN
))) || (typePair (at
, ft
, shortrealN
, rtypeN
)))
15094 /* static analysis guarentees a RETURN statement will be used before here. */
15095 __builtin_unreachable ();
15100 checkSystemCast - checks to see if we are passing to/from
15101 a system generic type (WORD, BYTE, ADDRESS)
15102 and if so emit a cast. It returns the number of
15106 static unsigned int checkSystemCast (mcPretty_pretty p
, decl_node actual
, decl_node formal
)
15111 at
= getExprType (actual
);
15112 ft
= decl_getType (formal
);
15113 if (needsCast (at
, ft
))
15115 /* avoid gcc warning by using compound statement even if not strictly necessary. */
15116 if (lang
== decl_ansiCP
)
15118 if ((isString (actual
)) && ((decl_skipType (ft
)) == addressN
))
15120 outText (p
, (const char *) "const_cast<void*> (reinterpret_cast<const void*> (", 50);
15123 else if ((decl_isPointer (decl_skipType (ft
))) || ((decl_skipType (ft
)) == addressN
))
15125 /* avoid dangling else. */
15126 if (actual
== nilN
)
15128 if (decl_isVarParam (formal
))
15130 mcMetaError_metaError1 ((const char *) "NIL is being passed to a VAR parameter {%1DMad}", 47, (const unsigned char *) &formal
, (sizeof (formal
)-1));
15132 /* NULL is compatible with pointers/address. */
15137 outText (p
, (const char *) "reinterpret_cast<", 17);
15138 doTypeNameC (p
, ft
);
15139 if (decl_isVarParam (formal
))
15141 outText (p
, (const char *) "*", 1);
15143 mcPretty_noSpace (p
);
15144 outText (p
, (const char *) "> (", 3);
15149 /* avoid dangling else. */
15150 outText (p
, (const char *) "static_cast<", 12);
15151 doTypeNameC (p
, ft
);
15152 if (decl_isVarParam (formal
))
15154 outText (p
, (const char *) "*", 1);
15156 mcPretty_noSpace (p
);
15157 outText (p
, (const char *) "> (", 3);
15163 outText (p
, (const char *) "(", 1);
15164 doTypeNameC (p
, ft
);
15165 if (decl_isVarParam (formal
))
15167 outText (p
, (const char *) "*", 1);
15169 mcPretty_noSpace (p
);
15170 outText (p
, (const char *) ")", 1);
15171 mcPretty_setNeedSpace (p
);
15175 /* static analysis guarentees a RETURN statement will be used before here. */
15176 __builtin_unreachable ();
15184 static void emitN (mcPretty_pretty p
, const char *a_
, unsigned int _a_high
, unsigned int n
)
15188 /* make a local copy of each unbounded array. */
15189 memcpy (a
, a_
, _a_high
+1);
15193 outText (p
, (const char *) a
, _a_high
);
15200 isForC - return true if node n is a varparam, param or procedure
15201 which was declared inside a definition module for "C".
15204 static bool isForC (decl_node n
)
15206 if (decl_isVarParam (n
))
15208 return n
->varparamF
.isForC
;
15210 else if (decl_isParam (n
))
15212 /* avoid dangling else. */
15213 return n
->paramF
.isForC
;
15215 else if (decl_isProcedure (n
))
15217 /* avoid dangling else. */
15218 return n
->procedureF
.isForC
;
15221 /* static analysis guarentees a RETURN statement will be used before here. */
15222 __builtin_unreachable ();
15227 isDefForCNode - return TRUE if node n was declared inside a definition module for "C".
15230 static bool isDefForCNode (decl_node n
)
15234 while ((n
!= NULL
) && (! (((decl_isImp (n
)) || (decl_isDef (n
))) || (decl_isModule (n
)))))
15236 n
= decl_getScope (n
);
15238 if ((n
!= NULL
) && (decl_isImp (n
)))
15240 name
= decl_getSymName (n
);
15241 n
= decl_lookupDef (name
);
15243 return ((n
!= NULL
) && (decl_isDef (n
))) && (isDefForC (n
));
15244 /* static analysis guarentees a RETURN statement will be used before here. */
15245 __builtin_unreachable ();
15253 static void doFuncParamC (mcPretty_pretty p
, decl_node actual
, decl_node formal
, decl_node func
)
15259 if (formal
== NULL
)
15261 doExprC (p
, actual
);
15265 ft
= decl_skipType (decl_getType (formal
));
15266 if (decl_isUnbounded (ft
))
15268 doFuncUnbounded (p
, actual
, formal
, ft
, func
);
15272 if ((isAProcType (ft
)) && (decl_isProcedure (actual
)))
15274 if (decl_isVarParam (formal
))
15276 mcMetaError_metaError1 ((const char *) "{%1MDad} cannot be passed as a VAR parameter", 44, (const unsigned char *) &actual
, (sizeof (actual
)-1));
15280 doProcedureParamC (p
, actual
, formal
);
15283 else if (((((decl_getType (actual
)) != NULL
) && (decl_isProcType (decl_skipType (decl_getType (actual
))))) && (isAProcType (ft
))) && (isForC (formal
)))
15285 /* avoid dangling else. */
15286 if (decl_isVarParam (formal
))
15288 mcMetaError_metaError2 ((const char *) "{%1MDad} cannot be passed as a VAR parameter to the definition for C module as the parameter requires a cast to the formal type {%2MDtad}", 137, (const unsigned char *) &actual
, (sizeof (actual
)-1), (const unsigned char *) &formal
, (sizeof (formal
)-1));
15292 outText (p
, (const char *) "(", 1);
15293 doFQNameC (p
, decl_getType (formal
));
15294 outText (p
, (const char *) "_C", 2);
15295 outText (p
, (const char *) ")", 1);
15296 mcPretty_setNeedSpace (p
);
15297 doExprC (p
, actual
);
15298 outText (p
, (const char *) ".proc", 5);
15301 else if ((((decl_getType (actual
)) != NULL
) && (decl_isProcType (decl_skipType (decl_getType (actual
))))) && ((decl_getType (actual
)) != (decl_getType (formal
))))
15303 /* avoid dangling else. */
15304 if (decl_isVarParam (formal
))
15306 mcMetaError_metaError2 ((const char *) "{%1MDad} cannot be passed as a VAR parameter as the parameter requires a cast to the formal type {%2MDtad}", 106, (const unsigned char *) &actual
, (sizeof (actual
)-1), (const unsigned char *) &formal
, (sizeof (formal
)-1));
15310 doCastC (p
, decl_getType (formal
), actual
);
15315 /* avoid dangling else. */
15316 lbr
= checkSystemCast (p
, actual
, formal
);
15317 if (decl_isVarParam (formal
))
15319 doAdrExprC (p
, actual
);
15323 doExprC (p
, actual
);
15325 emitN (p
, (const char *) ")", 1, lbr
);
15333 getNthParamType - return the type of parameter, i, in list, l.
15334 If the parameter is a vararg NIL is returned.
15337 static decl_node
getNthParamType (Indexing_Index l
, unsigned int i
)
15341 p
= getNthParam (l
, i
);
15344 return decl_getType (p
);
15347 /* static analysis guarentees a RETURN statement will be used before here. */
15348 __builtin_unreachable ();
15353 getNthParam - return the parameter, i, in list, l.
15354 If the parameter is a vararg NIL is returned.
15357 static decl_node
getNthParam (Indexing_Index l
, unsigned int i
)
15366 j
= Indexing_LowIndice (l
);
15367 h
= Indexing_HighIndice (l
);
15370 p
= static_cast<decl_node
> (Indexing_GetIndice (l
, j
));
15371 if (decl_isParam (p
))
15373 k
= identListLen (p
->paramF
.namelist
);
15375 else if (decl_isVarParam (p
))
15377 /* avoid dangling else. */
15378 k
= identListLen (p
->varparamF
.namelist
);
15382 /* avoid dangling else. */
15383 mcDebug_assert (decl_isVarargs (p
));
15398 /* static analysis guarentees a RETURN statement will be used before here. */
15399 __builtin_unreachable ();
15407 static void doFuncArgsC (mcPretty_pretty p
, decl_node s
, Indexing_Index l
, bool needParen
)
15416 outText (p
, (const char *) "(", 1);
15418 if (s
->funccallF
.args
!= NULL
)
15421 n
= expListLen (s
->funccallF
.args
);
15424 actual
= getExpList (s
->funccallF
.args
, i
);
15425 formal
= getNthParam (l
, i
);
15426 doFuncParamC (p
, actual
, formal
, s
->funccallF
.function
);
15429 outText (p
, (const char *) ",", 1);
15430 mcPretty_setNeedSpace (p
);
15437 mcPretty_noSpace (p
);
15438 outText (p
, (const char *) ")", 1);
15447 static void doProcTypeArgsC (mcPretty_pretty p
, decl_node s
, Indexing_Index args
, bool needParen
)
15456 outText (p
, (const char *) "(", 1);
15458 if (s
->funccallF
.args
!= NULL
)
15461 n
= expListLen (s
->funccallF
.args
);
15464 a
= getExpList (s
->funccallF
.args
, i
);
15465 b
= static_cast<decl_node
> (Indexing_GetIndice (args
, i
));
15466 doFuncParamC (p
, a
, b
, s
->funccallF
.function
);
15469 outText (p
, (const char *) ",", 1);
15470 mcPretty_setNeedSpace (p
);
15477 mcPretty_noSpace (p
);
15478 outText (p
, (const char *) ")", 1);
15487 static void doAdrArgC (mcPretty_pretty p
, decl_node n
)
15491 /* & and * cancel each other out. */
15492 doExprC (p
, n
->unaryF
.arg
);
15494 else if ((decl_isVar (n
)) && n
->varF
.isVarParameter
)
15496 /* avoid dangling else. */
15497 outTextN (p
, decl_getSymName (n
)); /* --fixme-- does the caller need to cast it? */
15501 /* avoid dangling else. */
15504 if (lang
== decl_ansiCP
)
15506 outText (p
, (const char *) "const_cast<void*> (reinterpret_cast<const void*>", 48);
15507 outText (p
, (const char *) "(", 1);
15509 outText (p
, (const char *) "))", 2);
15518 outText (p
, (const char *) "&", 1);
15529 static void doAdrC (mcPretty_pretty p
, decl_node n
)
15531 mcDebug_assert (isUnary (n
));
15532 doAdrArgC (p
, n
->unaryF
.arg
);
15540 static void doInc (mcPretty_pretty p
, decl_node n
)
15542 mcDebug_assert (isIntrinsic (n
));
15543 if (lang
== decl_ansiCP
)
15545 doIncDecCP (p
, n
, (const char *) "+", 1);
15549 doIncDecC (p
, n
, (const char *) "+=", 2);
15558 static void doDec (mcPretty_pretty p
, decl_node n
)
15560 mcDebug_assert (isIntrinsic (n
));
15561 if (lang
== decl_ansiCP
)
15563 doIncDecCP (p
, n
, (const char *) "-", 1);
15567 doIncDecC (p
, n
, (const char *) "-=", 2);
15576 static void doIncDecC (mcPretty_pretty p
, decl_node n
, const char *op_
, unsigned int _op_high
)
15578 char op
[_op_high
+1];
15580 /* make a local copy of each unbounded array. */
15581 memcpy (op
, op_
, _op_high
+1);
15583 mcDebug_assert (isIntrinsic (n
));
15584 if (n
->intrinsicF
.args
!= NULL
)
15586 doExprC (p
, getExpList (n
->intrinsicF
.args
, 1));
15587 mcPretty_setNeedSpace (p
);
15588 outText (p
, (const char *) op
, _op_high
);
15589 mcPretty_setNeedSpace (p
);
15590 if ((expListLen (n
->intrinsicF
.args
)) == 1)
15592 outText (p
, (const char *) "1", 1);
15596 doExprC (p
, getExpList (n
->intrinsicF
.args
, 2));
15606 static void doIncDecCP (mcPretty_pretty p
, decl_node n
, const char *op_
, unsigned int _op_high
)
15610 char op
[_op_high
+1];
15612 /* make a local copy of each unbounded array. */
15613 memcpy (op
, op_
, _op_high
+1);
15615 mcDebug_assert (isIntrinsic (n
));
15616 if (n
->intrinsicF
.args
!= NULL
)
15618 lhs
= getExpList (n
->intrinsicF
.args
, 1);
15620 mcPretty_setNeedSpace (p
);
15621 type
= decl_getType (lhs
);
15622 if ((decl_isPointer (type
)) || (type
== addressN
))
15624 /* cast to (char * ) and then back again after the arithmetic is complete. */
15625 outText (p
, (const char *) "=", 1);
15626 mcPretty_setNeedSpace (p
);
15627 outText (p
, (const char *) "reinterpret_cast<", 17);
15628 doTypeNameC (p
, type
);
15629 mcPretty_noSpace (p
);
15630 outText (p
, (const char *) "> (reinterpret_cast<char *> (", 29);
15632 mcPretty_noSpace (p
);
15633 outText (p
, (const char *) ")", 1);
15634 outText (p
, (const char *) op
, _op_high
);
15635 if ((expListLen (n
->intrinsicF
.args
)) == 1)
15637 outText (p
, (const char *) "1", 1);
15641 doExprC (p
, getExpList (n
->intrinsicF
.args
, 2));
15643 outText (p
, (const char *) ")", 1);
15645 else if (decl_isEnumeration (decl_skipType (type
)))
15647 /* avoid dangling else. */
15648 outText (p
, (const char *) "= static_cast<", 14);
15649 doTypeNameC (p
, type
);
15650 mcPretty_noSpace (p
);
15651 outText (p
, (const char *) ">(static_cast<int>(", 19);
15653 outText (p
, (const char *) ")", 1);
15654 outText (p
, (const char *) op
, _op_high
);
15655 if ((expListLen (n
->intrinsicF
.args
)) == 1)
15657 outText (p
, (const char *) "1", 1);
15661 doExprC (p
, getExpList (n
->intrinsicF
.args
, 2));
15663 outText (p
, (const char *) ")", 1);
15667 /* avoid dangling else. */
15668 outText (p
, (const char *) op
, _op_high
);
15669 outText (p
, (const char *) "=", 1);
15670 mcPretty_setNeedSpace (p
);
15671 if ((expListLen (n
->intrinsicF
.args
)) == 1)
15673 outText (p
, (const char *) "1", 1);
15677 doExprC (p
, getExpList (n
->intrinsicF
.args
, 2));
15688 static void doInclC (mcPretty_pretty p
, decl_node n
)
15692 mcDebug_assert (isIntrinsic (n
));
15693 if (n
->intrinsicF
.args
!= NULL
)
15695 /* avoid gcc warning by using compound statement even if not strictly necessary. */
15696 if ((expListLen (n
->intrinsicF
.args
)) == 2)
15698 doExprC (p
, getExpList (n
->intrinsicF
.args
, 1));
15699 lo
= getSetLow (getExpList (n
->intrinsicF
.args
, 1));
15700 mcPretty_setNeedSpace (p
);
15701 outText (p
, (const char *) "|=", 2);
15702 mcPretty_setNeedSpace (p
);
15703 outText (p
, (const char *) "(1", 2);
15704 mcPretty_setNeedSpace (p
);
15705 outText (p
, (const char *) "<<", 2);
15706 mcPretty_setNeedSpace (p
);
15707 outText (p
, (const char *) "(", 1);
15708 doExprC (p
, getExpList (n
->intrinsicF
.args
, 2));
15709 doSubtractC (p
, lo
);
15710 mcPretty_setNeedSpace (p
);
15711 outText (p
, (const char *) "))", 2);
15715 M2RTS_HALT (-1); /* metaError0 ('expecting two parameters to INCL') */
15716 __builtin_unreachable ();
15726 static void doExclC (mcPretty_pretty p
, decl_node n
)
15730 mcDebug_assert (isIntrinsic (n
));
15731 if (n
->intrinsicF
.args
!= NULL
)
15733 /* avoid gcc warning by using compound statement even if not strictly necessary. */
15734 if ((expListLen (n
->intrinsicF
.args
)) == 2)
15736 doExprC (p
, getExpList (n
->intrinsicF
.args
, 1));
15737 lo
= getSetLow (getExpList (n
->intrinsicF
.args
, 1));
15738 mcPretty_setNeedSpace (p
);
15739 outText (p
, (const char *) "&=", 2);
15740 mcPretty_setNeedSpace (p
);
15741 outText (p
, (const char *) "(~(1", 4);
15742 mcPretty_setNeedSpace (p
);
15743 outText (p
, (const char *) "<<", 2);
15744 mcPretty_setNeedSpace (p
);
15745 outText (p
, (const char *) "(", 1);
15746 doExprC (p
, getExpList (n
->intrinsicF
.args
, 2));
15747 doSubtractC (p
, lo
);
15748 mcPretty_setNeedSpace (p
);
15749 outText (p
, (const char *) ")))", 3);
15753 M2RTS_HALT (-1); /* metaError0 ('expecting two parameters to EXCL') */
15754 __builtin_unreachable ();
15764 static void doNewC (mcPretty_pretty p
, decl_node n
)
15768 mcDebug_assert (isIntrinsic (n
));
15769 if (n
->intrinsicF
.args
== NULL
)
15772 __builtin_unreachable ();
15776 if ((expListLen (n
->intrinsicF
.args
)) == 1)
15778 keyc_useStorage ();
15779 outText (p
, (const char *) "Storage_ALLOCATE", 16);
15780 mcPretty_setNeedSpace (p
);
15781 outText (p
, (const char *) "((void **)", 10);
15782 mcPretty_setNeedSpace (p
);
15783 outText (p
, (const char *) "&", 1);
15784 doExprC (p
, getExpList (n
->intrinsicF
.args
, 1));
15785 outText (p
, (const char *) ",", 1);
15786 mcPretty_setNeedSpace (p
);
15787 t
= decl_skipType (decl_getType (getExpList (n
->intrinsicF
.args
, 1)));
15788 if (decl_isPointer (t
))
15790 t
= decl_getType (t
);
15791 outText (p
, (const char *) "sizeof", 6);
15792 mcPretty_setNeedSpace (p
);
15793 outText (p
, (const char *) "(", 1);
15794 doTypeNameC (p
, t
);
15795 mcPretty_noSpace (p
);
15796 outText (p
, (const char *) "))", 2);
15800 mcMetaError_metaError1 ((const char *) "expecting a pointer type variable as the argument to NEW, rather than {%1ad}", 76, (const unsigned char *) &t
, (sizeof (t
)-1));
15811 static void doDisposeC (mcPretty_pretty p
, decl_node n
)
15815 mcDebug_assert (isIntrinsic (n
));
15816 if (n
->intrinsicF
.args
== NULL
)
15819 __builtin_unreachable ();
15823 if ((expListLen (n
->intrinsicF
.args
)) == 1)
15825 keyc_useStorage ();
15826 outText (p
, (const char *) "Storage_DEALLOCATE", 18);
15827 mcPretty_setNeedSpace (p
);
15828 outText (p
, (const char *) "((void **)", 10);
15829 mcPretty_setNeedSpace (p
);
15830 outText (p
, (const char *) "&", 1);
15831 doExprC (p
, getExpList (n
->intrinsicF
.args
, 1));
15832 outText (p
, (const char *) ",", 1);
15833 mcPretty_setNeedSpace (p
);
15834 t
= decl_skipType (decl_getType (getExpList (n
->intrinsicF
.args
, 1)));
15835 if (decl_isPointer (t
))
15837 t
= decl_getType (t
);
15838 outText (p
, (const char *) "sizeof", 6);
15839 mcPretty_setNeedSpace (p
);
15840 outText (p
, (const char *) "(", 1);
15841 doTypeNameC (p
, t
);
15842 mcPretty_noSpace (p
);
15843 outText (p
, (const char *) "))", 2);
15847 mcMetaError_metaError1 ((const char *) "expecting a pointer type variable as the argument to DISPOSE, rather than {%1ad}", 80, (const unsigned char *) &t
, (sizeof (t
)-1));
15852 M2RTS_HALT (-1); /* metaError0 ('expecting a single parameter to DISPOSE') */
15853 __builtin_unreachable ();
15863 static void doCapC (mcPretty_pretty p
, decl_node n
)
15865 mcDebug_assert (isUnary (n
));
15866 if (n
->unaryF
.arg
== NULL
)
15868 M2RTS_HALT (-1); /* metaError0 ('expecting a single parameter to CAP') */
15869 __builtin_unreachable ();
15874 if (mcOptions_getGccConfigSystem ())
15876 outText (p
, (const char *) "TOUPPER", 7);
15880 outText (p
, (const char *) "toupper", 7);
15882 mcPretty_setNeedSpace (p
);
15883 outText (p
, (const char *) "(", 1);
15884 doExprC (p
, n
->unaryF
.arg
);
15885 outText (p
, (const char *) ")", 1);
15894 static void doLengthC (mcPretty_pretty p
, decl_node n
)
15896 mcDebug_assert (isUnary (n
));
15897 if (n
->unaryF
.arg
== NULL
)
15899 M2RTS_HALT (-1); /* metaError0 ('expecting a single parameter to LENGTH') */
15900 __builtin_unreachable ();
15905 outText (p
, (const char *) "M2RTS_Length", 12);
15906 mcPretty_setNeedSpace (p
);
15907 outText (p
, (const char *) "(", 1);
15908 doExprC (p
, n
->unaryF
.arg
);
15909 outText (p
, (const char *) ",", 1);
15910 mcPretty_setNeedSpace (p
);
15911 doFuncHighC (p
, n
->unaryF
.arg
);
15912 outText (p
, (const char *) ")", 1);
15921 static void doAbsC (mcPretty_pretty p
, decl_node n
)
15925 mcDebug_assert (isUnary (n
));
15926 if (n
->unaryF
.arg
== NULL
)
15929 __builtin_unreachable ();
15933 t
= getExprType (n
);
15938 outText (p
, (const char *) "labs", 4);
15940 else if (t
== integerN
)
15942 /* avoid dangling else. */
15944 outText (p
, (const char *) "abs", 3);
15946 else if (t
== realN
)
15948 /* avoid dangling else. */
15950 outText (p
, (const char *) "fabs", 4);
15952 else if (t
== longrealN
)
15954 /* avoid dangling else. */
15956 outText (p
, (const char *) "fabsl", 5);
15958 else if (t
== cardinalN
)
15960 /* avoid dangling else. */
15964 /* avoid dangling else. */
15967 __builtin_unreachable ();
15969 mcPretty_setNeedSpace (p
);
15970 outText (p
, (const char *) "(", 1);
15971 doExprC (p
, n
->unaryF
.arg
);
15972 outText (p
, (const char *) ")", 1);
15980 static void doValC (mcPretty_pretty p
, decl_node n
)
15982 mcDebug_assert (isBinary (n
));
15983 outText (p
, (const char *) "(", 1);
15984 doTypeNameC (p
, n
->binaryF
.left
);
15985 outText (p
, (const char *) ")", 1);
15986 mcPretty_setNeedSpace (p
);
15987 outText (p
, (const char *) "(", 1);
15988 doExprC (p
, n
->binaryF
.right
);
15989 outText (p
, (const char *) ")", 1);
15997 static void doMinC (mcPretty_pretty p
, decl_node n
)
16001 mcDebug_assert (isUnary (n
));
16002 t
= getExprType (n
->unaryF
.arg
);
16003 doExprC (p
, getMin (t
));
16011 static void doMaxC (mcPretty_pretty p
, decl_node n
)
16015 mcDebug_assert (isUnary (n
));
16016 t
= getExprType (n
->unaryF
.arg
);
16017 doExprC (p
, getMax (t
));
16022 isIntrinsic - returns if, n, is an intrinsic procedure.
16023 The intrinsic functions are represented as unary and binary nodes.
16026 static bool isIntrinsic (decl_node n
)
16030 case decl_unreachable
:
16047 /* static analysis guarentees a RETURN statement will be used before here. */
16048 __builtin_unreachable ();
16056 static void doHalt (mcPretty_pretty p
, decl_node n
)
16058 mcDebug_assert (n
->kind
== decl_halt
);
16059 if ((n
->intrinsicF
.args
== NULL
) || ((expListLen (n
->intrinsicF
.args
)) == 0))
16061 outText (p
, (const char *) "M2RTS_HALT", 10);
16062 mcPretty_setNeedSpace (p
);
16063 outText (p
, (const char *) "(-1)", 4);
16065 else if ((expListLen (n
->intrinsicF
.args
)) == 1)
16067 /* avoid dangling else. */
16068 outText (p
, (const char *) "M2RTS_HALT", 10);
16069 mcPretty_setNeedSpace (p
);
16070 outText (p
, (const char *) "(", 1);
16071 doExprC (p
, getExpList (n
->intrinsicF
.args
, 1));
16072 outText (p
, (const char *) ")", 1);
16078 doCreal - emit the appropriate creal function.
16081 static void doCreal (mcPretty_pretty p
, decl_node t
)
16086 keyc_useComplex ();
16087 outText (p
, (const char *) "creal", 5);
16090 case decl_longcomplex
:
16091 keyc_useComplex ();
16092 outText (p
, (const char *) "creall", 6);
16095 case decl_shortcomplex
:
16096 keyc_useComplex ();
16097 outText (p
, (const char *) "crealf", 6);
16102 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
16103 __builtin_unreachable ();
16109 doCimag - emit the appropriate cimag function.
16112 static void doCimag (mcPretty_pretty p
, decl_node t
)
16117 keyc_useComplex ();
16118 outText (p
, (const char *) "cimag", 5);
16121 case decl_longcomplex
:
16122 keyc_useComplex ();
16123 outText (p
, (const char *) "cimagl", 6);
16126 case decl_shortcomplex
:
16127 keyc_useComplex ();
16128 outText (p
, (const char *) "cimagf", 6);
16133 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
16134 __builtin_unreachable ();
16143 static void doReC (mcPretty_pretty p
, decl_node n
)
16147 mcDebug_assert (n
->kind
== decl_re
);
16148 if (n
->unaryF
.arg
!= NULL
)
16150 t
= getExprType (n
->unaryF
.arg
);
16155 __builtin_unreachable ();
16158 mcPretty_setNeedSpace (p
);
16159 outText (p
, (const char *) "(", 1);
16160 doExprC (p
, n
->unaryF
.arg
);
16161 outText (p
, (const char *) ")", 1);
16169 static void doImC (mcPretty_pretty p
, decl_node n
)
16173 mcDebug_assert (n
->kind
== decl_im
);
16174 if (n
->unaryF
.arg
!= NULL
)
16176 t
= getExprType (n
->unaryF
.arg
);
16181 __builtin_unreachable ();
16184 mcPretty_setNeedSpace (p
);
16185 outText (p
, (const char *) "(", 1);
16186 doExprC (p
, n
->unaryF
.arg
);
16187 outText (p
, (const char *) ")", 1);
16195 static void doCmplx (mcPretty_pretty p
, decl_node n
)
16197 mcDebug_assert (isBinary (n
));
16198 keyc_useComplex ();
16199 mcPretty_setNeedSpace (p
);
16200 outText (p
, (const char *) "(", 1);
16201 doExprC (p
, n
->binaryF
.left
);
16202 outText (p
, (const char *) ")", 1);
16203 mcPretty_setNeedSpace (p
);
16204 outText (p
, (const char *) "+", 1);
16205 mcPretty_setNeedSpace (p
);
16206 outText (p
, (const char *) "(", 1);
16207 doExprC (p
, n
->binaryF
.right
);
16208 mcPretty_setNeedSpace (p
);
16209 outText (p
, (const char *) "*", 1);
16210 mcPretty_setNeedSpace (p
);
16211 outText (p
, (const char *) "I", 1);
16212 outText (p
, (const char *) ")", 1);
16220 static void doIntrinsicC (mcPretty_pretty p
, decl_node n
)
16222 mcDebug_assert (isIntrinsic (n
));
16223 doCommentC (p
, n
->intrinsicF
.intrinsicComment
.body
);
16226 case decl_unreachable
:
16227 doUnreachableC (p
, n
);
16264 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
16265 __builtin_unreachable ();
16267 outText (p
, (const char *) ";", 1);
16268 doAfterCommentC (p
, n
->intrinsicF
.intrinsicComment
.after
);
16273 isIntrinsicFunction - returns true if, n, is an instrinsic function.
16276 static bool isIntrinsicFunction (decl_node n
)
16305 /* static analysis guarentees a RETURN statement will be used before here. */
16306 __builtin_unreachable ();
16314 static void doSizeC (mcPretty_pretty p
, decl_node n
)
16316 mcDebug_assert (isUnary (n
));
16317 outText (p
, (const char *) "sizeof (", 8);
16318 doExprC (p
, n
->unaryF
.arg
);
16319 outText (p
, (const char *) ")", 1);
16327 static void doConvertC (mcPretty_pretty p
, decl_node n
, const char *conversion_
, unsigned int _conversion_high
)
16329 DynamicStrings_String s
;
16330 char conversion
[_conversion_high
+1];
16332 /* make a local copy of each unbounded array. */
16333 memcpy (conversion
, conversion_
, _conversion_high
+1);
16335 s
= DynamicStrings_InitString ((const char *) conversion
, _conversion_high
);
16336 doConvertSC (p
, n
, s
);
16337 s
= DynamicStrings_KillString (s
);
16345 static void doConvertSC (mcPretty_pretty p
, decl_node n
, DynamicStrings_String conversion
)
16347 mcDebug_assert (isUnary (n
));
16348 mcPretty_setNeedSpace (p
);
16349 outText (p
, (const char *) "((", 2);
16350 outTextS (p
, conversion
);
16351 outText (p
, (const char *) ")", 1);
16352 mcPretty_setNeedSpace (p
);
16353 outText (p
, (const char *) "(", 1);
16354 doExprC (p
, n
->unaryF
.arg
);
16355 outText (p
, (const char *) "))", 2);
16363 static decl_node
getFuncFromExpr (decl_node n
)
16365 n
= decl_skipType (decl_getType (n
));
16366 while ((n
!= procN
) && (! (decl_isProcType (n
))))
16368 n
= decl_skipType (decl_getType (n
));
16371 /* static analysis guarentees a RETURN statement will be used before here. */
16372 __builtin_unreachable ();
16380 static void doFuncExprC (mcPretty_pretty p
, decl_node n
)
16384 mcDebug_assert (isFuncCall (n
));
16385 if (decl_isProcedure (n
->funccallF
.function
))
16387 doFQDNameC (p
, n
->funccallF
.function
, true);
16388 mcPretty_setNeedSpace (p
);
16389 doFuncArgsC (p
, n
, n
->funccallF
.function
->procedureF
.parameters
, true);
16393 outText (p
, (const char *) "(*", 2);
16394 doExprC (p
, n
->funccallF
.function
);
16395 outText (p
, (const char *) ".proc", 5);
16396 outText (p
, (const char *) ")", 1);
16397 t
= getFuncFromExpr (n
->funccallF
.function
);
16398 mcPretty_setNeedSpace (p
);
16401 doProcTypeArgsC (p
, n
, NULL
, true);
16405 mcDebug_assert (decl_isProcType (t
));
16406 doProcTypeArgsC (p
, n
, t
->proctypeF
.parameters
, true);
16416 static void doFuncCallC (mcPretty_pretty p
, decl_node n
)
16418 doCommentC (p
, n
->funccallF
.funccallComment
.body
);
16419 doFuncExprC (p
, n
);
16420 outText (p
, (const char *) ";", 1);
16421 doAfterCommentC (p
, n
->funccallF
.funccallComment
.after
);
16429 static void doCaseStatementC (mcPretty_pretty p
, decl_node n
, bool needBreak
)
16431 p
= mcPretty_pushPretty (p
);
16432 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
16433 doStatementSequenceC (p
, n
);
16436 outText (p
, (const char *) "break;\\n", 8);
16438 p
= mcPretty_popPretty (p
);
16446 static void doExceptionC (mcPretty_pretty p
, const char *a_
, unsigned int _a_high
, decl_node n
)
16451 /* make a local copy of each unbounded array. */
16452 memcpy (a
, a_
, _a_high
+1);
16454 w
= decl_getDeclaredMod (n
);
16455 outText (p
, (const char *) a
, _a_high
);
16456 mcPretty_setNeedSpace (p
);
16457 outText (p
, (const char *) "(\"", 2);
16458 outTextS (p
, mcLexBuf_findFileNameFromToken (w
, 0));
16459 outText (p
, (const char *) "\",", 2);
16460 mcPretty_setNeedSpace (p
);
16461 outCard (p
, mcLexBuf_tokenToLineNo (w
, 0));
16462 outText (p
, (const char *) ",", 1);
16463 mcPretty_setNeedSpace (p
);
16464 outCard (p
, mcLexBuf_tokenToColumnNo (w
, 0));
16465 outText (p
, (const char *) ");\\n", 4);
16466 outText (p
, (const char *) "__builtin_unreachable ();\\n", 27);
16474 static void doExceptionCP (mcPretty_pretty p
, const char *a_
, unsigned int _a_high
, decl_node n
)
16479 /* make a local copy of each unbounded array. */
16480 memcpy (a
, a_
, _a_high
+1);
16482 w
= decl_getDeclaredMod (n
);
16483 outText (p
, (const char *) a
, _a_high
);
16484 mcPretty_setNeedSpace (p
);
16485 outText (p
, (const char *) "(\"", 2);
16486 outTextS (p
, mcLexBuf_findFileNameFromToken (w
, 0));
16487 outText (p
, (const char *) "\",", 2);
16488 mcPretty_setNeedSpace (p
);
16489 outCard (p
, mcLexBuf_tokenToLineNo (w
, 0));
16490 outText (p
, (const char *) ",", 1);
16491 mcPretty_setNeedSpace (p
);
16492 outCard (p
, mcLexBuf_tokenToColumnNo (w
, 0));
16493 outText (p
, (const char *) ");\\n", 4);
16494 outText (p
, (const char *) "__builtin_unreachable ();\\n", 27);
16502 static void doException (mcPretty_pretty p
, const char *a_
, unsigned int _a_high
, decl_node n
)
16506 /* make a local copy of each unbounded array. */
16507 memcpy (a
, a_
, _a_high
+1);
16509 keyc_useException ();
16510 if (lang
== decl_ansiCP
)
16512 doExceptionCP (p
, (const char *) a
, _a_high
, n
);
16516 doExceptionC (p
, (const char *) a
, _a_high
, n
);
16525 static void doRangeListC (mcPretty_pretty p
, decl_node c
)
16531 mcDebug_assert (decl_isCaseList (c
));
16533 h
= Indexing_HighIndice (c
->caselistF
.rangePairs
);
16536 r
= static_cast<decl_node
> (Indexing_GetIndice (c
->caselistF
.rangePairs
, i
));
16537 mcDebug_assert ((r
->rangeF
.hi
== NULL
) || (r
->rangeF
.lo
== r
->rangeF
.hi
));
16538 outText (p
, (const char *) "case", 4);
16539 mcPretty_setNeedSpace (p
);
16540 doExprC (p
, r
->rangeF
.lo
);
16541 outText (p
, (const char *) ":\\n", 3);
16551 static void doRangeIfListC (mcPretty_pretty p
, decl_node e
, decl_node c
)
16557 mcDebug_assert (decl_isCaseList (c
));
16559 h
= Indexing_HighIndice (c
->caselistF
.rangePairs
);
16562 r
= static_cast<decl_node
> (Indexing_GetIndice (c
->caselistF
.rangePairs
, i
));
16563 if ((r
->rangeF
.lo
!= r
->rangeF
.hi
) && (r
->rangeF
.hi
!= NULL
))
16565 outText (p
, (const char *) "((", 2);
16567 outText (p
, (const char *) ")", 1);
16568 mcPretty_setNeedSpace (p
);
16569 outText (p
, (const char *) ">=", 2);
16570 mcPretty_setNeedSpace (p
);
16571 doExprC (p
, r
->rangeF
.lo
);
16572 outText (p
, (const char *) ")", 1);
16573 mcPretty_setNeedSpace (p
);
16574 outText (p
, (const char *) "&&", 2);
16575 mcPretty_setNeedSpace (p
);
16576 outText (p
, (const char *) "((", 2);
16578 outText (p
, (const char *) ")", 1);
16579 mcPretty_setNeedSpace (p
);
16580 outText (p
, (const char *) "<=", 2);
16581 mcPretty_setNeedSpace (p
);
16582 doExprC (p
, r
->rangeF
.hi
);
16583 outText (p
, (const char *) ")", 1);
16587 outText (p
, (const char *) "((", 2);
16589 outText (p
, (const char *) ")", 1);
16590 mcPretty_setNeedSpace (p
);
16591 outText (p
, (const char *) "==", 2);
16592 mcPretty_setNeedSpace (p
);
16593 doExprC (p
, r
->rangeF
.lo
);
16594 outText (p
, (const char *) ")", 1);
16598 mcPretty_setNeedSpace (p
);
16599 outText (p
, (const char *) "||", 2);
16600 mcPretty_setNeedSpace (p
);
16611 static void doCaseLabels (mcPretty_pretty p
, decl_node n
, bool needBreak
)
16613 mcDebug_assert (decl_isCaseLabelList (n
));
16614 doRangeListC (p
, n
->caselabellistF
.caseList
);
16615 p
= mcPretty_pushPretty (p
);
16616 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
16617 doStatementSequenceC (p
, n
->caselabellistF
.statements
);
16620 outText (p
, (const char *) "break;\\n\\n", 10);
16622 p
= mcPretty_popPretty (p
);
16630 static void doCaseLabelListC (mcPretty_pretty p
, decl_node n
, bool haveElse
)
16636 mcDebug_assert (decl_isCase (n
));
16638 h
= Indexing_HighIndice (n
->caseF
.caseLabelList
);
16641 c
= static_cast<decl_node
> (Indexing_GetIndice (n
->caseF
.caseLabelList
, i
));
16642 doCaseLabels (p
, c
, ((i
< h
) || haveElse
) || caseException
);
16652 static void doCaseIfLabels (mcPretty_pretty p
, decl_node e
, decl_node n
, unsigned int i
, unsigned int h
)
16654 mcDebug_assert (decl_isCaseLabelList (n
));
16657 outText (p
, (const char *) "else", 4);
16658 mcPretty_setNeedSpace (p
);
16660 outText (p
, (const char *) "if", 2);
16661 mcPretty_setNeedSpace (p
);
16662 outText (p
, (const char *) "(", 1);
16663 doRangeIfListC (p
, e
, n
->caselabellistF
.caseList
);
16664 outText (p
, (const char *) ")\\n", 3);
16667 doCompoundStmt (p
, n
->caselabellistF
.statements
);
16671 outText (p
, (const char *) "{\\n", 3);
16672 doStatementSequenceC (p
, n
->caselabellistF
.statements
);
16673 outText (p
, (const char *) "}\\n", 3);
16679 doCaseIfLabelListC -
16682 static void doCaseIfLabelListC (mcPretty_pretty p
, decl_node n
)
16688 mcDebug_assert (decl_isCase (n
));
16690 h
= Indexing_HighIndice (n
->caseF
.caseLabelList
);
16693 c
= static_cast<decl_node
> (Indexing_GetIndice (n
->caseF
.caseLabelList
, i
));
16694 doCaseIfLabels (p
, n
->caseF
.expression
, c
, i
, h
);
16704 static void doCaseElseC (mcPretty_pretty p
, decl_node n
)
16706 mcDebug_assert (decl_isCase (n
));
16707 if (n
->caseF
.else_
== NULL
)
16709 /* avoid dangling else. */
16712 outText (p
, (const char *) "\\ndefault:\\n", 12);
16713 p
= mcPretty_pushPretty (p
);
16714 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
16715 doException (p
, (const char *) "CaseException", 13, n
);
16716 p
= mcPretty_popPretty (p
);
16721 outText (p
, (const char *) "\\ndefault:\\n", 12);
16722 doCaseStatementC (p
, n
->caseF
.else_
, true);
16731 static void doCaseIfElseC (mcPretty_pretty p
, decl_node n
)
16733 mcDebug_assert (decl_isCase (n
));
16734 if (n
->caseF
.else_
== NULL
)
16736 /* avoid dangling else. */
16739 outText (p
, (const char *) "\\n", 2);
16740 outText (p
, (const char *) "else {\\n", 8);
16741 p
= mcPretty_pushPretty (p
);
16742 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
16743 doException (p
, (const char *) "CaseException", 13, n
);
16744 p
= mcPretty_popPretty (p
);
16745 outText (p
, (const char *) "}\\n", 3);
16750 outText (p
, (const char *) "\\n", 2);
16751 outText (p
, (const char *) "else {\\n", 8);
16752 doCaseStatementC (p
, n
->caseF
.else_
, false);
16753 outText (p
, (const char *) "}\\n", 3);
16759 canUseSwitchCaseLabels - returns TRUE if all the case labels are
16760 single values and not ranges.
16763 static bool canUseSwitchCaseLabels (decl_node n
)
16770 mcDebug_assert (decl_isCaseLabelList (n
));
16771 l
= n
->caselabellistF
.caseList
;
16773 h
= Indexing_HighIndice (l
->caselistF
.rangePairs
);
16776 r
= static_cast<decl_node
> (Indexing_GetIndice (l
->caselistF
.rangePairs
, i
));
16777 if ((r
->rangeF
.hi
!= NULL
) && (r
->rangeF
.lo
!= r
->rangeF
.hi
))
16784 /* static analysis guarentees a RETURN statement will be used before here. */
16785 __builtin_unreachable ();
16790 canUseSwitch - returns TRUE if the case statement can be implement
16791 by a switch statement. This will be TRUE if all case
16792 selectors are single values rather than ranges.
16795 static bool canUseSwitch (decl_node n
)
16801 mcDebug_assert (decl_isCase (n
));
16803 h
= Indexing_HighIndice (n
->caseF
.caseLabelList
);
16806 c
= static_cast<decl_node
> (Indexing_GetIndice (n
->caseF
.caseLabelList
, i
));
16807 if (! (canUseSwitchCaseLabels (c
)))
16814 /* static analysis guarentees a RETURN statement will be used before here. */
16815 __builtin_unreachable ();
16823 static void doCaseC (mcPretty_pretty p
, decl_node n
)
16827 mcDebug_assert (decl_isCase (n
));
16828 if (canUseSwitch (n
))
16830 i
= mcPretty_getindent (p
);
16831 outText (p
, (const char *) "switch", 6);
16832 mcPretty_setNeedSpace (p
);
16833 outText (p
, (const char *) "(", 1);
16834 doExprC (p
, n
->caseF
.expression
);
16835 p
= mcPretty_pushPretty (p
);
16836 outText (p
, (const char *) ")", 1);
16837 mcPretty_setindent (p
, i
+indentationC
);
16838 outText (p
, (const char *) "\\n{\\n", 5);
16839 p
= mcPretty_pushPretty (p
);
16840 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
16841 doCaseLabelListC (p
, n
, n
->caseF
.else_
!= NULL
);
16842 doCaseElseC (p
, n
);
16843 p
= mcPretty_popPretty (p
);
16844 outText (p
, (const char *) "}\\n", 3);
16845 p
= mcPretty_popPretty (p
);
16849 doCaseIfLabelListC (p
, n
);
16850 doCaseIfElseC (p
, n
);
16859 static void doLoopC (mcPretty_pretty p
, decl_node s
)
16861 mcDebug_assert (decl_isLoop (s
));
16862 outText (p
, (const char *) "for (;;)\\n", 10);
16863 outText (p
, (const char *) "{\\n", 3);
16864 p
= mcPretty_pushPretty (p
);
16865 mcPretty_setindent (p
, (mcPretty_getindent (p
))+indentationC
);
16866 doStatementSequenceC (p
, s
->loopF
.statements
);
16867 p
= mcPretty_popPretty (p
);
16868 outText (p
, (const char *) "}\\n", 3);
16876 static void doExitC (mcPretty_pretty p
, decl_node s
)
16878 mcDebug_assert (decl_isExit (s
));
16879 outText (p
, (const char *) "/* exit. */\\n", 14);
16887 static void doStatementsC (mcPretty_pretty p
, decl_node s
)
16891 else if (decl_isStatementSequence (s
))
16893 /* avoid dangling else. */
16894 doStatementSequenceC (p
, s
);
16896 else if (isComment (s
))
16898 /* avoid dangling else. */
16901 else if (decl_isExit (s
))
16903 /* avoid dangling else. */
16906 else if (decl_isReturn (s
))
16908 /* avoid dangling else. */
16911 else if (isAssignment (s
))
16913 /* avoid dangling else. */
16914 doAssignmentC (p
, s
);
16916 else if (decl_isIf (s
))
16918 /* avoid dangling else. */
16921 else if (decl_isFor (s
))
16923 /* avoid dangling else. */
16926 else if (decl_isRepeat (s
))
16928 /* avoid dangling else. */
16931 else if (decl_isWhile (s
))
16933 /* avoid dangling else. */
16936 else if (isIntrinsic (s
))
16938 /* avoid dangling else. */
16939 doIntrinsicC (p
, s
);
16941 else if (isFuncCall (s
))
16943 /* avoid dangling else. */
16944 doFuncCallC (p
, s
);
16946 else if (decl_isCase (s
))
16948 /* avoid dangling else. */
16951 else if (decl_isLoop (s
))
16953 /* avoid dangling else. */
16956 else if (decl_isExit (s
))
16958 /* avoid dangling else. */
16963 /* avoid dangling else. */
16964 M2RTS_HALT (-1); /* need to handle another s^.kind. */
16965 __builtin_unreachable ();
16969 static void stop (void)
16978 static void doLocalVarC (mcPretty_pretty p
, decl_scopeT s
)
16980 includeVarProcedure (s
);
16982 topologicallyOut ((decl_nodeProcedure
) {(decl_nodeProcedure_t
) doConstC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doTypesC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doVarC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) outputPartial
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNone
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doCompletePartialC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNone
});
16987 doLocalConstTypesC -
16990 static void doLocalConstTypesC (mcPretty_pretty p
, decl_scopeT s
)
16993 includeConstType (s
);
16995 topologicallyOut ((decl_nodeProcedure
) {(decl_nodeProcedure_t
) doConstC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doTypesC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doVarC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) outputPartial
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNone
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doCompletePartialC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNone
});
17003 static void addParamDone (decl_node n
)
17005 if ((decl_isVar (n
)) && n
->varF
.isParameter
)
17008 addDone (decl_getType (n
));
17014 includeParameters -
17017 static void includeParameters (decl_node n
)
17019 mcDebug_assert (decl_isProcedure (n
));
17020 Indexing_ForeachIndiceInIndexDo (n
->procedureF
.decls
.variables
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) addParamDone
});
17028 static bool isHalt (decl_node n
)
17030 return n
->kind
== decl_halt
;
17031 /* static analysis guarentees a RETURN statement will be used before here. */
17032 __builtin_unreachable ();
17040 static bool isReturnOrHalt (decl_node n
)
17042 return (isHalt (n
)) || (decl_isReturn (n
));
17043 /* static analysis guarentees a RETURN statement will be used before here. */
17044 __builtin_unreachable ();
17049 isLastStatementReturn -
17052 static bool isLastStatementReturn (decl_node n
)
17054 return isLastStatement (n
, (decl_isNodeF
) {(decl_isNodeF_t
) isReturnOrHalt
});
17055 /* static analysis guarentees a RETURN statement will be used before here. */
17056 __builtin_unreachable ();
17061 isLastStatementSequence -
17064 static bool isLastStatementSequence (decl_node n
, decl_isNodeF q
)
17068 mcDebug_assert (decl_isStatementSequence (n
));
17069 h
= Indexing_HighIndice (n
->stmtF
.statements
);
17072 return isLastStatement (reinterpret_cast<decl_node
> (Indexing_GetIndice (n
->stmtF
.statements
, h
)), q
);
17075 /* static analysis guarentees a RETURN statement will be used before here. */
17076 __builtin_unreachable ();
17081 isLastStatementIf -
17084 static bool isLastStatementIf (decl_node n
, decl_isNodeF q
)
17088 mcDebug_assert (decl_isIf (n
));
17090 if ((n
->ifF
.elsif
!= NULL
) && ret
)
17092 ret
= isLastStatement (n
->ifF
.elsif
, q
);
17094 if ((n
->ifF
.then
!= NULL
) && ret
)
17096 ret
= isLastStatement (n
->ifF
.then
, q
);
17098 if ((n
->ifF
.else_
!= NULL
) && ret
)
17100 ret
= isLastStatement (n
->ifF
.else_
, q
);
17103 /* static analysis guarentees a RETURN statement will be used before here. */
17104 __builtin_unreachable ();
17109 isLastStatementElsif -
17112 static bool isLastStatementElsif (decl_node n
, decl_isNodeF q
)
17116 mcDebug_assert (decl_isElsif (n
));
17118 if ((n
->elsifF
.elsif
!= NULL
) && ret
)
17120 ret
= isLastStatement (n
->elsifF
.elsif
, q
);
17122 if ((n
->elsifF
.then
!= NULL
) && ret
)
17124 ret
= isLastStatement (n
->elsifF
.then
, q
);
17126 if ((n
->elsifF
.else_
!= NULL
) && ret
)
17128 ret
= isLastStatement (n
->elsifF
.else_
, q
);
17131 /* static analysis guarentees a RETURN statement will be used before here. */
17132 __builtin_unreachable ();
17137 isLastStatementCase -
17140 static bool isLastStatementCase (decl_node n
, decl_isNodeF q
)
17148 mcDebug_assert (decl_isCase (n
));
17150 h
= Indexing_HighIndice (n
->caseF
.caseLabelList
);
17153 c
= static_cast<decl_node
> (Indexing_GetIndice (n
->caseF
.caseLabelList
, i
));
17154 mcDebug_assert (decl_isCaseLabelList (c
));
17155 ret
= ret
&& (isLastStatement (c
->caselabellistF
.statements
, q
));
17158 if (n
->caseF
.else_
!= NULL
)
17160 ret
= ret
&& (isLastStatement (n
->caseF
.else_
, q
));
17163 /* static analysis guarentees a RETURN statement will be used before here. */
17164 __builtin_unreachable ();
17169 isLastStatement - returns TRUE if the last statement in, n, is, q.
17172 static bool isLastStatement (decl_node n
, decl_isNodeF q
)
17180 else if (decl_isStatementSequence (n
))
17182 /* avoid dangling else. */
17183 return isLastStatementSequence (n
, q
);
17185 else if (decl_isProcedure (n
))
17187 /* avoid dangling else. */
17188 mcDebug_assert (decl_isProcedure (n
));
17189 return isLastStatement (n
->procedureF
.beginStatements
, q
);
17191 else if (decl_isIf (n
))
17193 /* avoid dangling else. */
17194 return isLastStatementIf (n
, q
);
17196 else if (decl_isElsif (n
))
17198 /* avoid dangling else. */
17199 return isLastStatementElsif (n
, q
);
17201 else if (decl_isCase (n
))
17203 /* avoid dangling else. */
17204 return isLastStatementCase (n
, q
);
17206 else if ((*q
.proc
) (n
))
17208 /* avoid dangling else. */
17212 /* static analysis guarentees a RETURN statement will be used before here. */
17213 __builtin_unreachable ();
17221 static void doProcedureC (decl_node n
)
17225 outText (doP
, (const char *) "\\n", 2);
17226 includeParameters (n
);
17227 keyc_enterScope (n
);
17228 doProcedureHeadingC (n
, false);
17229 outText (doP
, (const char *) "\\n", 2);
17230 doP
= outKc (doP
, (const char *) "{\\n", 3);
17231 s
= mcPretty_getcurline (doP
);
17232 doLocalConstTypesC (doP
, n
->procedureF
.decls
);
17233 doLocalVarC (doP
, n
->procedureF
.decls
);
17234 doUnboundedParamCopyC (doP
, n
);
17235 if (s
!= (mcPretty_getcurline (doP
)))
17237 outText (doP
, (const char *) "\\n", 2);
17239 doStatementsC (doP
, n
->procedureF
.beginStatements
);
17240 if (n
->procedureF
.returnType
!= NULL
)
17242 if (returnException
)
17244 /* avoid gcc warning by using compound statement even if not strictly necessary. */
17245 if (isLastStatementReturn (n
))
17247 outText (doP
, (const char *) "/* static analysis guarentees a RETURN statement will be used before here. */\\n", 80);
17248 outText (doP
, (const char *) "__builtin_unreachable ();\\n", 27);
17252 doException (doP
, (const char *) "ReturnException", 15, n
);
17256 doP
= outKc (doP
, (const char *) "}\\n", 3);
17257 keyc_leaveScope (n
);
17265 static void outProceduresC (mcPretty_pretty p
, decl_scopeT s
)
17270 libc_printf ((const char *) "seen %d procedures\\n", 20, Indexing_HighIndice (s
.procedures
));
17272 Indexing_ForeachIndiceInIndexDo (s
.procedures
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) doProcedureC
});
17280 static void output (decl_node n
, decl_nodeProcedure c
, decl_nodeProcedure t
, decl_nodeProcedure v
)
17282 if (decl_isConst (n
))
17286 else if (decl_isVar (n
))
17288 /* avoid dangling else. */
17293 /* avoid dangling else. */
17303 static decl_dependentState
allDependants (decl_node n
)
17306 decl_dependentState s
;
17308 l
= alists_initList ();
17309 s
= walkDependants (l
, n
);
17310 alists_killList (&l
);
17312 /* static analysis guarentees a RETURN statement will be used before here. */
17313 __builtin_unreachable ();
17321 static decl_dependentState
walkDependants (alists_alist l
, decl_node n
)
17323 if ((n
== NULL
) || (alists_isItemInList (doneQ
, reinterpret_cast<void *> (n
))))
17325 return decl_completed
;
17327 else if (alists_isItemInList (l
, reinterpret_cast<void *> (n
)))
17329 /* avoid dangling else. */
17330 return decl_recursive
;
17334 /* avoid dangling else. */
17335 alists_includeItemIntoList (l
, reinterpret_cast<void *> (n
));
17336 return doDependants (l
, n
);
17338 /* static analysis guarentees a RETURN statement will be used before here. */
17339 __builtin_unreachable ();
17347 static decl_dependentState
walkType (alists_alist l
, decl_node n
)
17351 t
= decl_getType (n
);
17352 if (alists_isItemInList (doneQ
, reinterpret_cast<void *> (t
)))
17354 return decl_completed
;
17356 else if (alists_isItemInList (partialQ
, reinterpret_cast<void *> (t
)))
17358 /* avoid dangling else. */
17359 return decl_blocked
;
17363 /* avoid dangling else. */
17365 return decl_blocked
;
17367 /* static analysis guarentees a RETURN statement will be used before here. */
17368 __builtin_unreachable ();
17376 static void db (const char *a_
, unsigned int _a_high
, decl_node n
)
17380 /* make a local copy of each unbounded array. */
17381 memcpy (a
, a_
, _a_high
+1);
17383 if (mcOptions_getDebugTopological ())
17385 outText (doP
, (const char *) a
, _a_high
);
17388 outTextS (doP
, gen (n
));
17398 static void dbt (const char *a_
, unsigned int _a_high
)
17402 /* make a local copy of each unbounded array. */
17403 memcpy (a
, a_
, _a_high
+1);
17405 if (mcOptions_getDebugTopological ())
17407 outText (doP
, (const char *) a
, _a_high
);
17416 static void dbs (decl_dependentState s
, decl_node n
)
17418 if (mcOptions_getDebugTopological ())
17422 case decl_completed
:
17423 outText (doP
, (const char *) "{completed ", 11);
17427 outText (doP
, (const char *) "{blocked ", 9);
17431 outText (doP
, (const char *) "{partial ", 9);
17434 case decl_recursive
:
17435 outText (doP
, (const char *) "{recursive ", 11);
17440 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
17441 __builtin_unreachable ();
17445 outTextS (doP
, gen (n
));
17447 outText (doP
, (const char *) "}\\n", 3);
17456 static void dbq (decl_node n
)
17458 if (mcOptions_getDebugTopological ())
17460 /* avoid gcc warning by using compound statement even if not strictly necessary. */
17461 if (alists_isItemInList (todoQ
, reinterpret_cast<void *> (n
)))
17463 db ((const char *) "{T", 2, n
);
17464 outText (doP
, (const char *) "}", 1);
17466 else if (alists_isItemInList (partialQ
, reinterpret_cast<void *> (n
)))
17468 /* avoid dangling else. */
17469 db ((const char *) "{P", 2, n
);
17470 outText (doP
, (const char *) "}", 1);
17472 else if (alists_isItemInList (doneQ
, reinterpret_cast<void *> (n
)))
17474 /* avoid dangling else. */
17475 db ((const char *) "{D", 2, n
);
17476 outText (doP
, (const char *) "}", 1);
17486 static decl_dependentState
walkRecord (alists_alist l
, decl_node n
)
17488 decl_dependentState s
;
17494 i
= Indexing_LowIndice (n
->recordF
.listOfSons
);
17495 t
= Indexing_HighIndice (n
->recordF
.listOfSons
);
17496 db ((const char *) "\\nwalking ", 10, n
);
17497 o
= mcPretty_getindent (doP
);
17498 mcPretty_setindent (doP
, (mcPretty_getcurpos (doP
))+3);
17502 q
= static_cast<decl_node
> (Indexing_GetIndice (n
->recordF
.listOfSons
, i
));
17503 db ((const char *) "", 0, q
);
17504 if ((decl_isRecordField (q
)) && q
->recordfieldF
.tag
)
17508 /* do nothing as it is a tag selector processed in the varient. */
17509 s
= walkDependants (l
, q
);
17510 if (s
!= decl_completed
)
17515 db ((const char *) "\\n", 2, NULL
);
17516 mcPretty_setindent (doP
, o
);
17522 db ((const char *) "{completed", 10, n
);
17523 dbt ((const char *) "}\\n", 3);
17524 mcPretty_setindent (doP
, o
);
17525 return decl_completed
;
17526 /* static analysis guarentees a RETURN statement will be used before here. */
17527 __builtin_unreachable ();
17535 static decl_dependentState
walkVarient (alists_alist l
, decl_node n
)
17537 decl_dependentState s
;
17542 db ((const char *) "\\nwalking", 9, n
);
17543 s
= walkDependants (l
, n
->varientF
.tag
);
17544 if (s
!= decl_completed
)
17546 dbs (s
, n
->varientF
.tag
);
17547 dbq (n
->varientF
.tag
);
17548 db ((const char *) "\\n", 2, NULL
);
17551 i
= Indexing_LowIndice (n
->varientF
.listOfSons
);
17552 t
= Indexing_HighIndice (n
->varientF
.listOfSons
);
17555 q
= static_cast<decl_node
> (Indexing_GetIndice (n
->varientF
.listOfSons
, i
));
17556 db ((const char *) "", 0, q
);
17557 s
= walkDependants (l
, q
);
17558 if (s
!= decl_completed
)
17561 db ((const char *) "\\n", 2, NULL
);
17566 db ((const char *) "{completed", 10, n
);
17567 dbt ((const char *) "}\\n", 3);
17568 return decl_completed
;
17569 /* static analysis guarentees a RETURN statement will be used before here. */
17570 __builtin_unreachable ();
17578 static void queueBlocked (decl_node n
)
17580 if (! ((alists_isItemInList (doneQ
, reinterpret_cast<void *> (n
))) || (alists_isItemInList (partialQ
, reinterpret_cast<void *> (n
)))))
17591 static decl_dependentState
walkVar (alists_alist l
, decl_node n
)
17595 t
= decl_getType (n
);
17596 if (alists_isItemInList (doneQ
, reinterpret_cast<void *> (t
)))
17598 return decl_completed
;
17603 return decl_blocked
;
17605 /* static analysis guarentees a RETURN statement will be used before here. */
17606 __builtin_unreachable ();
17614 static decl_dependentState
walkEnumeration (alists_alist l
, decl_node n
)
17616 decl_dependentState s
;
17621 i
= Indexing_LowIndice (n
->enumerationF
.listOfSons
);
17622 t
= Indexing_HighIndice (n
->enumerationF
.listOfSons
);
17623 s
= decl_completed
;
17626 q
= static_cast<decl_node
> (Indexing_GetIndice (n
->enumerationF
.listOfSons
, i
));
17627 s
= walkDependants (l
, q
);
17628 if (s
!= decl_completed
)
17635 /* static analysis guarentees a RETURN statement will be used before here. */
17636 __builtin_unreachable ();
17644 static decl_dependentState
walkSubrange (alists_alist l
, decl_node n
)
17646 decl_dependentState s
;
17648 s
= walkDependants (l
, n
->subrangeF
.low
);
17649 if (s
!= decl_completed
)
17653 s
= walkDependants (l
, n
->subrangeF
.high
);
17654 if (s
!= decl_completed
)
17658 s
= walkDependants (l
, n
->subrangeF
.type
);
17659 if (s
!= decl_completed
)
17663 return decl_completed
;
17664 /* static analysis guarentees a RETURN statement will be used before here. */
17665 __builtin_unreachable ();
17673 static decl_dependentState
walkSubscript (alists_alist l
, decl_node n
)
17675 decl_dependentState s
;
17677 s
= walkDependants (l
, n
->subscriptF
.expr
);
17678 if (s
!= decl_completed
)
17682 s
= walkDependants (l
, n
->subscriptF
.type
);
17683 if (s
!= decl_completed
)
17687 return decl_completed
;
17688 /* static analysis guarentees a RETURN statement will be used before here. */
17689 __builtin_unreachable ();
17697 static decl_dependentState
walkPointer (alists_alist l
, decl_node n
)
17701 /* if the type of, n, is done or partial then we can output pointer. */
17702 t
= decl_getType (n
);
17703 if ((alists_isItemInList (partialQ
, reinterpret_cast<void *> (t
))) || (alists_isItemInList (doneQ
, reinterpret_cast<void *> (t
))))
17705 /* pointer to partial can always generate a complete type. */
17706 return decl_completed
;
17708 return walkType (l
, n
);
17709 /* static analysis guarentees a RETURN statement will be used before here. */
17710 __builtin_unreachable ();
17718 static decl_dependentState
walkArray (alists_alist l
, decl_node n
)
17720 decl_dependentState s
;
17722 /* an array can only be declared if its data type has already been emitted. */
17723 if (! (alists_isItemInList (doneQ
, reinterpret_cast<void *> (n
->arrayF
.type
))))
17725 s
= walkDependants (l
, n
->arrayF
.type
);
17726 queueBlocked (n
->arrayF
.type
);
17727 if (s
== decl_completed
)
17729 /* downgrade the completed to partial as it has not yet been written. */
17730 return decl_partial
;
17737 return walkDependants (l
, n
->arrayF
.subr
);
17738 /* static analysis guarentees a RETURN statement will be used before here. */
17739 __builtin_unreachable ();
17747 static decl_dependentState
walkConst (alists_alist l
, decl_node n
)
17749 decl_dependentState s
;
17751 s
= walkDependants (l
, n
->constF
.type
);
17752 if (s
!= decl_completed
)
17756 s
= walkDependants (l
, n
->constF
.value
);
17757 if (s
!= decl_completed
)
17761 return decl_completed
;
17762 /* static analysis guarentees a RETURN statement will be used before here. */
17763 __builtin_unreachable ();
17771 static decl_dependentState
walkVarParam (alists_alist l
, decl_node n
)
17775 t
= decl_getType (n
);
17776 if (alists_isItemInList (partialQ
, reinterpret_cast<void *> (t
)))
17778 /* parameter can be issued from a partial. */
17779 return decl_completed
;
17781 return walkDependants (l
, t
);
17782 /* static analysis guarentees a RETURN statement will be used before here. */
17783 __builtin_unreachable ();
17791 static decl_dependentState
walkParam (alists_alist l
, decl_node n
)
17795 t
= decl_getType (n
);
17796 if (alists_isItemInList (partialQ
, reinterpret_cast<void *> (t
)))
17798 /* parameter can be issued from a partial. */
17799 return decl_completed
;
17801 return walkDependants (l
, t
);
17802 /* static analysis guarentees a RETURN statement will be used before here. */
17803 __builtin_unreachable ();
17811 static decl_dependentState
walkOptarg (alists_alist l
, decl_node n
)
17815 t
= decl_getType (n
);
17816 if (alists_isItemInList (partialQ
, reinterpret_cast<void *> (t
)))
17818 /* parameter can be issued from a partial. */
17819 return decl_completed
;
17821 return walkDependants (l
, t
);
17822 /* static analysis guarentees a RETURN statement will be used before here. */
17823 __builtin_unreachable ();
17831 static decl_dependentState
walkRecordField (alists_alist l
, decl_node n
)
17834 decl_dependentState s
;
17836 mcDebug_assert (decl_isRecordField (n
));
17837 t
= decl_getType (n
);
17838 if (alists_isItemInList (partialQ
, reinterpret_cast<void *> (t
)))
17840 dbs (decl_partial
, n
);
17841 return decl_partial
;
17843 else if (alists_isItemInList (doneQ
, reinterpret_cast<void *> (t
)))
17845 /* avoid dangling else. */
17846 dbs (decl_completed
, n
);
17847 return decl_completed
;
17851 /* avoid dangling else. */
17853 dbs (decl_blocked
, n
);
17856 /* s := walkDependants (l, t) */
17857 return decl_blocked
;
17859 /* static analysis guarentees a RETURN statement will be used before here. */
17860 __builtin_unreachable ();
17868 static decl_dependentState
walkVarientField (alists_alist l
, decl_node n
)
17870 decl_dependentState s
;
17875 i
= Indexing_LowIndice (n
->varientfieldF
.listOfSons
);
17876 t
= Indexing_HighIndice (n
->varientfieldF
.listOfSons
);
17877 s
= decl_completed
;
17880 q
= static_cast<decl_node
> (Indexing_GetIndice (n
->varientfieldF
.listOfSons
, i
));
17881 s
= walkDependants (l
, q
);
17882 if (s
!= decl_completed
)
17889 n
->varientfieldF
.simple
= t
<= 1;
17892 /* static analysis guarentees a RETURN statement will be used before here. */
17893 __builtin_unreachable ();
17898 walkEnumerationField -
17901 static decl_dependentState
walkEnumerationField (alists_alist l
, decl_node n
)
17903 return decl_completed
;
17904 /* static analysis guarentees a RETURN statement will be used before here. */
17905 __builtin_unreachable ();
17913 static decl_dependentState
walkSet (alists_alist l
, decl_node n
)
17915 return walkDependants (l
, decl_getType (n
));
17916 /* static analysis guarentees a RETURN statement will be used before here. */
17917 __builtin_unreachable ();
17925 static decl_dependentState
walkProcType (alists_alist l
, decl_node n
)
17927 decl_dependentState s
;
17930 t
= decl_getType (n
);
17931 if (alists_isItemInList (partialQ
, reinterpret_cast<void *> (t
)))
17935 /* proctype can be generated from partial types. */
17936 s
= walkDependants (l
, t
);
17937 if (s
!= decl_completed
)
17942 return walkParameters (l
, n
->proctypeF
.parameters
);
17943 /* static analysis guarentees a RETURN statement will be used before here. */
17944 __builtin_unreachable ();
17952 static decl_dependentState
walkProcedure (alists_alist l
, decl_node n
)
17954 decl_dependentState s
;
17956 s
= walkDependants (l
, decl_getType (n
));
17957 if (s
!= decl_completed
)
17961 return walkParameters (l
, n
->procedureF
.parameters
);
17962 /* static analysis guarentees a RETURN statement will be used before here. */
17963 __builtin_unreachable ();
17971 static decl_dependentState
walkParameters (alists_alist l
, Indexing_Index p
)
17973 decl_dependentState s
;
17978 i
= Indexing_LowIndice (p
);
17979 h
= Indexing_HighIndice (p
);
17982 q
= static_cast<decl_node
> (Indexing_GetIndice (p
, i
));
17983 s
= walkDependants (l
, q
);
17984 if (s
!= decl_completed
)
17990 return decl_completed
;
17991 /* static analysis guarentees a RETURN statement will be used before here. */
17992 __builtin_unreachable ();
18000 static decl_dependentState
walkFuncCall (alists_alist l
, decl_node n
)
18002 return decl_completed
;
18003 /* static analysis guarentees a RETURN statement will be used before here. */
18004 __builtin_unreachable ();
18012 static decl_dependentState
walkUnary (alists_alist l
, decl_node n
)
18014 decl_dependentState s
;
18016 s
= walkDependants (l
, n
->unaryF
.arg
);
18017 if (s
!= decl_completed
)
18021 return walkDependants (l
, n
->unaryF
.resultType
);
18022 /* static analysis guarentees a RETURN statement will be used before here. */
18023 __builtin_unreachable ();
18031 static decl_dependentState
walkBinary (alists_alist l
, decl_node n
)
18033 decl_dependentState s
;
18035 s
= walkDependants (l
, n
->binaryF
.left
);
18036 if (s
!= decl_completed
)
18040 s
= walkDependants (l
, n
->binaryF
.right
);
18041 if (s
!= decl_completed
)
18045 return walkDependants (l
, n
->binaryF
.resultType
);
18046 /* static analysis guarentees a RETURN statement will be used before here. */
18047 __builtin_unreachable ();
18055 static decl_dependentState
walkComponentRef (alists_alist l
, decl_node n
)
18057 decl_dependentState s
;
18059 s
= walkDependants (l
, n
->componentrefF
.rec
);
18060 if (s
!= decl_completed
)
18064 s
= walkDependants (l
, n
->componentrefF
.field
);
18065 if (s
!= decl_completed
)
18069 return walkDependants (l
, n
->componentrefF
.resultType
);
18070 /* static analysis guarentees a RETURN statement will be used before here. */
18071 __builtin_unreachable ();
18079 static decl_dependentState
walkPointerRef (alists_alist l
, decl_node n
)
18081 decl_dependentState s
;
18083 s
= walkDependants (l
, n
->pointerrefF
.ptr
);
18084 if (s
!= decl_completed
)
18088 s
= walkDependants (l
, n
->pointerrefF
.field
);
18089 if (s
!= decl_completed
)
18093 return walkDependants (l
, n
->pointerrefF
.resultType
);
18094 /* static analysis guarentees a RETURN statement will be used before here. */
18095 __builtin_unreachable ();
18103 static decl_dependentState
walkSetValue (alists_alist l
, decl_node n
)
18105 decl_dependentState s
;
18109 mcDebug_assert (decl_isSetValue (n
));
18110 s
= walkDependants (l
, n
->setvalueF
.type
);
18111 if (s
!= decl_completed
)
18115 i
= Indexing_LowIndice (n
->setvalueF
.values
);
18116 j
= Indexing_HighIndice (n
->setvalueF
.values
);
18119 s
= walkDependants (l
, reinterpret_cast<decl_node
> (Indexing_GetIndice (n
->setvalueF
.values
, i
)));
18120 if (s
!= decl_completed
)
18126 return decl_completed
;
18127 /* static analysis guarentees a RETURN statement will be used before here. */
18128 __builtin_unreachable ();
18133 doDependants - return the dependentState depending upon whether
18134 all dependants have been declared.
18137 static decl_dependentState
doDependants (alists_alist l
, decl_node n
)
18151 case decl_cardinal
:
18152 case decl_longcard
:
18153 case decl_shortcard
:
18156 case decl_shortint
:
18158 case decl_longreal
:
18159 case decl_shortreal
:
18164 case decl_longcomplex
:
18165 case decl_shortcomplex
:
18168 return decl_completed
;
18172 /* language features and compound type attributes. */
18173 return walkType (l
, n
);
18177 return walkRecord (l
, n
);
18181 return walkVarient (l
, n
);
18185 return walkVar (l
, n
);
18188 case decl_enumeration
:
18189 return walkEnumeration (l
, n
);
18192 case decl_subrange
:
18193 return walkSubrange (l
, n
);
18197 return walkPointer (l
, n
);
18201 return walkArray (l
, n
);
18205 return decl_completed
;
18209 return walkConst (l
, n
);
18213 return decl_completed
;
18216 case decl_varparam
:
18217 return walkVarParam (l
, n
);
18221 return walkParam (l
, n
);
18225 return walkOptarg (l
, n
);
18228 case decl_recordfield
:
18229 return walkRecordField (l
, n
);
18232 case decl_varientfield
:
18233 return walkVarientField (l
, n
);
18236 case decl_enumerationfield
:
18237 return walkEnumerationField (l
, n
);
18241 return walkSet (l
, n
);
18244 case decl_proctype
:
18245 return walkProcType (l
, n
);
18248 case decl_subscript
:
18249 return walkSubscript (l
, n
);
18252 case decl_procedure
:
18254 return walkProcedure (l
, n
);
18266 case decl_assignment
:
18269 __builtin_unreachable ();
18272 case decl_componentref
:
18274 return walkComponentRef (l
, n
);
18277 case decl_pointerref
:
18278 return walkPointerRef (l
, n
);
18291 return walkUnary (l
, n
);
18302 return walkBinary (l
, n
);
18305 case decl_constexp
:
18311 return walkUnary (l
, n
);
18315 case decl_notequal
:
18318 case decl_greequal
:
18319 case decl_lessequal
:
18320 return walkBinary (l
, n
);
18323 case decl_funccall
:
18324 return walkFuncCall (l
, n
);
18327 case decl_setvalue
:
18328 return walkSetValue (l
, n
);
18333 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
18334 __builtin_unreachable ();
18336 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
18337 __builtin_unreachable ();
18342 tryComplete - returns TRUE if node, n, can be and was completed.
18345 static bool tryComplete (decl_node n
, decl_nodeProcedure c
, decl_nodeProcedure t
, decl_nodeProcedure v
)
18347 if (decl_isEnumeration (n
))
18349 /* can always emit enumerated types. */
18350 output (n
, c
, t
, v
);
18353 else if (((decl_isType (n
)) && (decl_isTypeHidden (n
))) && ((decl_getType (n
)) == NULL
))
18355 /* avoid dangling else. */
18356 /* can always emit hidden types. */
18360 else if ((allDependants (n
)) == decl_completed
)
18362 /* avoid dangling else. */
18363 output (n
, c
, t
, v
);
18367 /* static analysis guarentees a RETURN statement will be used before here. */
18368 __builtin_unreachable ();
18373 tryCompleteFromPartial -
18376 static bool tryCompleteFromPartial (decl_node n
, decl_nodeProcedure t
)
18378 if ((((decl_isType (n
)) && ((decl_getType (n
)) != NULL
)) && (decl_isPointer (decl_getType (n
)))) && ((allDependants (decl_getType (n
))) == decl_completed
))
18380 /* alists.includeItemIntoList (partialQ, getType (n)) ; */
18381 outputHiddenComplete (n
);
18384 else if ((allDependants (n
)) == decl_completed
)
18386 /* avoid dangling else. */
18391 /* static analysis guarentees a RETURN statement will be used before here. */
18392 __builtin_unreachable ();
18397 visitIntrinsicFunction -
18400 static void visitIntrinsicFunction (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18402 mcDebug_assert (isIntrinsicFunction (n
));
18407 visitNode (v
, n
->binaryF
.left
, p
);
18408 visitNode (v
, n
->binaryF
.right
, p
);
18409 visitNode (v
, n
->binaryF
.resultType
, p
);
18427 visitNode (v
, n
->unaryF
.arg
, p
);
18428 visitNode (v
, n
->unaryF
.resultType
, p
);
18433 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
18434 __builtin_unreachable ();
18443 static void visitUnary (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18445 mcDebug_assert (isUnary (n
));
18446 visitNode (v
, n
->unaryF
.arg
, p
);
18447 visitNode (v
, n
->unaryF
.resultType
, p
);
18455 static void visitBinary (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18457 visitNode (v
, n
->binaryF
.left
, p
);
18458 visitNode (v
, n
->binaryF
.right
, p
);
18459 visitNode (v
, n
->binaryF
.resultType
, p
);
18467 static void visitBoolean (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18469 visitNode (v
, falseN
, p
);
18470 visitNode (v
, trueN
, p
);
18478 static void visitScope (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18480 if (mustVisitScope
)
18482 visitNode (v
, n
, p
);
18491 static void visitType (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18493 mcDebug_assert (decl_isType (n
));
18494 visitNode (v
, n
->typeF
.type
, p
);
18495 visitScope (v
, n
->typeF
.scope
, p
);
18503 static void visitIndex (alists_alist v
, Indexing_Index i
, decl_nodeProcedure p
)
18509 h
= Indexing_HighIndice (i
);
18512 visitNode (v
, reinterpret_cast<decl_node
> (Indexing_GetIndice (i
, j
)), p
);
18522 static void visitRecord (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18524 mcDebug_assert (decl_isRecord (n
));
18525 visitScope (v
, n
->recordF
.scope
, p
);
18526 visitIndex (v
, n
->recordF
.listOfSons
, p
);
18534 static void visitVarient (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18536 mcDebug_assert (decl_isVarient (n
));
18537 visitIndex (v
, n
->varientF
.listOfSons
, p
);
18538 visitNode (v
, n
->varientF
.varient
, p
);
18539 visitNode (v
, n
->varientF
.tag
, p
);
18540 visitScope (v
, n
->varientF
.scope
, p
);
18548 static void visitVar (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18550 mcDebug_assert (decl_isVar (n
));
18551 visitNode (v
, n
->varF
.type
, p
);
18552 visitNode (v
, n
->varF
.decl
, p
);
18553 visitScope (v
, n
->varF
.scope
, p
);
18561 static void visitEnumeration (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18563 mcDebug_assert (decl_isEnumeration (n
));
18564 visitIndex (v
, n
->enumerationF
.listOfSons
, p
);
18565 visitScope (v
, n
->enumerationF
.scope
, p
);
18573 static void visitSubrange (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18575 mcDebug_assert (decl_isSubrange (n
));
18576 visitNode (v
, n
->subrangeF
.low
, p
);
18577 visitNode (v
, n
->subrangeF
.high
, p
);
18578 visitNode (v
, n
->subrangeF
.type
, p
);
18579 visitScope (v
, n
->subrangeF
.scope
, p
);
18587 static void visitPointer (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18589 mcDebug_assert (decl_isPointer (n
));
18590 visitNode (v
, n
->pointerF
.type
, p
);
18591 visitScope (v
, n
->pointerF
.scope
, p
);
18599 static void visitArray (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18601 mcDebug_assert (decl_isArray (n
));
18602 visitNode (v
, n
->arrayF
.subr
, p
);
18603 visitNode (v
, n
->arrayF
.type
, p
);
18604 visitScope (v
, n
->arrayF
.scope
, p
);
18612 static void visitConst (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18614 mcDebug_assert (decl_isConst (n
));
18615 visitNode (v
, n
->constF
.type
, p
);
18616 visitNode (v
, n
->constF
.value
, p
);
18617 visitScope (v
, n
->constF
.scope
, p
);
18625 static void visitVarParam (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18627 mcDebug_assert (decl_isVarParam (n
));
18628 visitNode (v
, n
->varparamF
.namelist
, p
);
18629 visitNode (v
, n
->varparamF
.type
, p
);
18630 visitScope (v
, n
->varparamF
.scope
, p
);
18638 static void visitParam (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18640 mcDebug_assert (decl_isParam (n
));
18641 visitNode (v
, n
->paramF
.namelist
, p
);
18642 visitNode (v
, n
->paramF
.type
, p
);
18643 visitScope (v
, n
->paramF
.scope
, p
);
18651 static void visitOptarg (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18653 mcDebug_assert (decl_isOptarg (n
));
18654 visitNode (v
, n
->optargF
.namelist
, p
);
18655 visitNode (v
, n
->optargF
.type
, p
);
18656 visitNode (v
, n
->optargF
.init
, p
);
18657 visitScope (v
, n
->optargF
.scope
, p
);
18665 static void visitRecordField (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18667 mcDebug_assert (decl_isRecordField (n
));
18668 visitNode (v
, n
->recordfieldF
.type
, p
);
18669 visitNode (v
, n
->recordfieldF
.parent
, p
);
18670 visitNode (v
, n
->recordfieldF
.varient
, p
);
18671 visitScope (v
, n
->recordfieldF
.scope
, p
);
18676 visitVarientField -
18679 static void visitVarientField (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18681 mcDebug_assert (decl_isVarientField (n
));
18682 visitNode (v
, n
->varientfieldF
.parent
, p
);
18683 visitNode (v
, n
->varientfieldF
.varient
, p
);
18684 visitIndex (v
, n
->varientfieldF
.listOfSons
, p
);
18685 visitScope (v
, n
->varientfieldF
.scope
, p
);
18690 visitEnumerationField -
18693 static void visitEnumerationField (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18695 mcDebug_assert (decl_isEnumerationField (n
));
18696 visitNode (v
, n
->enumerationfieldF
.type
, p
);
18697 visitScope (v
, n
->enumerationfieldF
.scope
, p
);
18705 static void visitSet (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18707 mcDebug_assert (decl_isSet (n
));
18708 visitNode (v
, n
->setF
.type
, p
);
18709 visitScope (v
, n
->setF
.scope
, p
);
18717 static void visitProcType (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18719 mcDebug_assert (decl_isProcType (n
));
18720 visitIndex (v
, n
->proctypeF
.parameters
, p
);
18721 visitNode (v
, n
->proctypeF
.optarg_
, p
);
18722 visitNode (v
, n
->proctypeF
.returnType
, p
);
18723 visitScope (v
, n
->proctypeF
.scope
, p
);
18731 static void visitSubscript (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18740 static void visitDecls (alists_alist v
, decl_scopeT s
, decl_nodeProcedure p
)
18742 visitIndex (v
, s
.constants
, p
);
18743 visitIndex (v
, s
.types
, p
);
18744 visitIndex (v
, s
.procedures
, p
);
18745 visitIndex (v
, s
.variables
, p
);
18753 static void visitProcedure (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18755 mcDebug_assert (decl_isProcedure (n
));
18756 visitDecls (v
, n
->procedureF
.decls
, p
);
18757 visitScope (v
, n
->procedureF
.scope
, p
);
18758 visitIndex (v
, n
->procedureF
.parameters
, p
);
18759 visitNode (v
, n
->procedureF
.optarg_
, p
);
18760 visitNode (v
, n
->procedureF
.returnType
, p
);
18761 visitNode (v
, n
->procedureF
.beginStatements
, p
);
18769 static void visitDef (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18771 mcDebug_assert (decl_isDef (n
));
18772 visitDecls (v
, n
->defF
.decls
, p
);
18780 static void visitImp (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18782 mcDebug_assert (decl_isImp (n
));
18783 visitDecls (v
, n
->impF
.decls
, p
);
18784 visitNode (v
, n
->impF
.beginStatements
, p
);
18785 /* --fixme-- do we need to visit definitionModule? */
18786 visitNode (v
, n
->impF
.finallyStatements
, p
);
18794 static void visitModule (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18796 mcDebug_assert (decl_isModule (n
));
18797 visitDecls (v
, n
->moduleF
.decls
, p
);
18798 visitNode (v
, n
->moduleF
.beginStatements
, p
);
18799 visitNode (v
, n
->moduleF
.finallyStatements
, p
);
18807 static void visitLoop (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18809 mcDebug_assert (decl_isLoop (n
));
18810 visitNode (v
, n
->loopF
.statements
, p
);
18818 static void visitWhile (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18820 mcDebug_assert (decl_isWhile (n
));
18821 visitNode (v
, n
->whileF
.expr
, p
);
18822 visitNode (v
, n
->whileF
.statements
, p
);
18830 static void visitRepeat (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18832 mcDebug_assert (decl_isRepeat (n
));
18833 visitNode (v
, n
->repeatF
.expr
, p
);
18834 visitNode (v
, n
->repeatF
.statements
, p
);
18842 static void visitCase (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18844 mcDebug_assert (decl_isCase (n
));
18845 visitNode (v
, n
->caseF
.expression
, p
);
18846 visitIndex (v
, n
->caseF
.caseLabelList
, p
);
18847 visitNode (v
, n
->caseF
.else_
, p
);
18852 visitCaseLabelList -
18855 static void visitCaseLabelList (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18857 mcDebug_assert (decl_isCaseLabelList (n
));
18858 visitNode (v
, n
->caselabellistF
.caseList
, p
);
18859 visitNode (v
, n
->caselabellistF
.statements
, p
);
18867 static void visitCaseList (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18869 mcDebug_assert (decl_isCaseList (n
));
18870 visitIndex (v
, n
->caselistF
.rangePairs
, p
);
18878 static void visitRange (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18880 mcDebug_assert (decl_isRange (n
));
18881 visitNode (v
, n
->rangeF
.lo
, p
);
18882 visitNode (v
, n
->rangeF
.hi
, p
);
18890 static void visitIf (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18892 mcDebug_assert (decl_isIf (n
));
18893 visitNode (v
, n
->ifF
.expr
, p
);
18894 visitNode (v
, n
->ifF
.elsif
, p
);
18895 visitNode (v
, n
->ifF
.then
, p
);
18896 visitNode (v
, n
->ifF
.else_
, p
);
18904 static void visitElsif (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18906 mcDebug_assert (decl_isElsif (n
));
18907 visitNode (v
, n
->elsifF
.expr
, p
);
18908 visitNode (v
, n
->elsifF
.elsif
, p
);
18909 visitNode (v
, n
->elsifF
.then
, p
);
18910 visitNode (v
, n
->elsifF
.else_
, p
);
18918 static void visitFor (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18920 mcDebug_assert (decl_isFor (n
));
18921 visitNode (v
, n
->forF
.des
, p
);
18922 visitNode (v
, n
->forF
.start
, p
);
18923 visitNode (v
, n
->forF
.end
, p
);
18924 visitNode (v
, n
->forF
.increment
, p
);
18925 visitNode (v
, n
->forF
.statements
, p
);
18933 static void visitAssignment (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18935 mcDebug_assert (isAssignment (n
));
18936 visitNode (v
, n
->assignmentF
.des
, p
);
18937 visitNode (v
, n
->assignmentF
.expr
, p
);
18942 visitComponentRef -
18945 static void visitComponentRef (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18947 mcDebug_assert (isComponentRef (n
));
18948 visitNode (v
, n
->componentrefF
.rec
, p
);
18949 visitNode (v
, n
->componentrefF
.field
, p
);
18950 visitNode (v
, n
->componentrefF
.resultType
, p
);
18958 static void visitPointerRef (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18960 mcDebug_assert (decl_isPointerRef (n
));
18961 visitNode (v
, n
->pointerrefF
.ptr
, p
);
18962 visitNode (v
, n
->pointerrefF
.field
, p
);
18963 visitNode (v
, n
->pointerrefF
.resultType
, p
);
18971 static void visitArrayRef (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18973 mcDebug_assert (isArrayRef (n
));
18974 visitNode (v
, n
->arrayrefF
.array
, p
);
18975 visitNode (v
, n
->arrayrefF
.index
, p
);
18976 visitNode (v
, n
->arrayrefF
.resultType
, p
);
18984 static void visitFunccall (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18986 mcDebug_assert (isFuncCall (n
));
18987 visitNode (v
, n
->funccallF
.function
, p
);
18988 visitNode (v
, n
->funccallF
.args
, p
);
18989 visitNode (v
, n
->funccallF
.type
, p
);
18997 static void visitVarDecl (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
18999 mcDebug_assert (isVarDecl (n
));
19000 visitNode (v
, n
->vardeclF
.type
, p
);
19001 visitScope (v
, n
->vardeclF
.scope
, p
);
19009 static void visitExplist (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
19011 mcDebug_assert (decl_isExpList (n
));
19012 visitIndex (v
, n
->explistF
.exp
, p
);
19020 static void visitExit (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
19022 mcDebug_assert (decl_isExit (n
));
19023 visitNode (v
, n
->exitF
.loop
, p
);
19031 static void visitReturn (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
19033 mcDebug_assert (decl_isReturn (n
));
19034 visitNode (v
, n
->returnF
.exp
, p
);
19042 static void visitStmtSeq (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
19044 mcDebug_assert (decl_isStatementSequence (n
));
19045 visitIndex (v
, n
->stmtF
.statements
, p
);
19053 static void visitVarargs (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
19055 mcDebug_assert (decl_isVarargs (n
));
19056 visitScope (v
, n
->varargsF
.scope
, p
);
19064 static void visitSetValue (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
19066 mcDebug_assert (decl_isSetValue (n
));
19067 visitNode (v
, n
->setvalueF
.type
, p
);
19068 visitIndex (v
, n
->setvalueF
.values
, p
);
19076 static void visitIntrinsic (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
19078 mcDebug_assert (isIntrinsic (n
));
19079 visitNode (v
, n
->intrinsicF
.args
, p
);
19084 visitDependants - helper procedure function called from visitNode.
19085 node n has just been visited, this procedure will
19086 visit node, n, dependants.
19089 static void visitDependants (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
19091 mcDebug_assert (n
!= NULL
);
19092 mcDebug_assert (alists_isItemInList (v
, reinterpret_cast<void *> (n
)));
19096 visitExplist (v
, n
, p
);
19099 case decl_funccall
:
19100 visitFunccall (v
, n
, p
);
19104 visitExit (v
, n
, p
);
19108 visitReturn (v
, n
, p
);
19112 visitStmtSeq (v
, n
, p
);
19119 visitIntrinsicFunction (v
, n
, p
);
19122 case decl_unreachable
:
19131 visitIntrinsic (v
, n
, p
);
19135 visitBoolean (v
, n
, p
);
19144 visitVarargs (v
, n
, p
);
19154 case decl_cardinal
:
19155 case decl_longcard
:
19156 case decl_shortcard
:
19159 case decl_shortint
:
19161 case decl_longreal
:
19162 case decl_shortreal
:
19167 case decl_longcomplex
:
19168 case decl_shortcomplex
:
19173 /* language features and compound type attributes. */
19174 visitType (v
, n
, p
);
19178 visitRecord (v
, n
, p
);
19182 visitVarient (v
, n
, p
);
19186 visitVar (v
, n
, p
);
19189 case decl_enumeration
:
19190 visitEnumeration (v
, n
, p
);
19193 case decl_subrange
:
19194 visitSubrange (v
, n
, p
);
19198 visitPointer (v
, n
, p
);
19202 visitArray (v
, n
, p
);
19209 visitConst (v
, n
, p
);
19215 case decl_varparam
:
19216 visitVarParam (v
, n
, p
);
19220 visitParam (v
, n
, p
);
19224 visitOptarg (v
, n
, p
);
19227 case decl_recordfield
:
19228 visitRecordField (v
, n
, p
);
19231 case decl_varientfield
:
19232 visitVarientField (v
, n
, p
);
19235 case decl_enumerationfield
:
19236 visitEnumerationField (v
, n
, p
);
19240 visitSet (v
, n
, p
);
19243 case decl_proctype
:
19244 visitProcType (v
, n
, p
);
19247 case decl_subscript
:
19248 visitSubscript (v
, n
, p
);
19251 case decl_procedure
:
19253 visitProcedure (v
, n
, p
);
19257 visitDef (v
, n
, p
);
19261 visitImp (v
, n
, p
);
19265 visitModule (v
, n
, p
);
19270 visitLoop (v
, n
, p
);
19274 visitWhile (v
, n
, p
);
19278 visitFor (v
, n
, p
);
19282 visitRepeat (v
, n
, p
);
19286 visitCase (v
, n
, p
);
19289 case decl_caselabellist
:
19290 visitCaseLabelList (v
, n
, p
);
19293 case decl_caselist
:
19294 visitCaseList (v
, n
, p
);
19298 visitRange (v
, n
, p
);
19306 visitElsif (v
, n
, p
);
19309 case decl_assignment
:
19310 visitAssignment (v
, n
, p
);
19313 case decl_componentref
:
19315 visitComponentRef (v
, n
, p
);
19318 case decl_pointerref
:
19319 visitPointerRef (v
, n
, p
);
19322 case decl_arrayref
:
19323 visitArrayRef (v
, n
, p
);
19328 case decl_notequal
:
19331 case decl_greequal
:
19332 case decl_lessequal
:
19344 visitBinary (v
, n
, p
);
19348 visitUnary (v
, n
, p
);
19352 visitUnary (v
, n
, p
);
19356 visitUnary (v
, n
, p
);
19360 visitUnary (v
, n
, p
);
19364 visitUnary (v
, n
, p
);
19368 visitUnary (v
, n
, p
);
19372 visitUnary (v
, n
, p
);
19376 visitUnary (v
, n
, p
);
19380 visitUnary (v
, n
, p
);
19384 visitUnary (v
, n
, p
);
19388 visitUnary (v
, n
, p
);
19392 visitUnary (v
, n
, p
);
19396 visitUnary (v
, n
, p
);
19400 visitUnary (v
, n
, p
);
19404 visitUnary (v
, n
, p
);
19408 visitUnary (v
, n
, p
);
19411 case decl_constexp
:
19412 visitUnary (v
, n
, p
);
19416 visitUnary (v
, n
, p
);
19419 case decl_identlist
:
19423 visitVarDecl (v
, n
, p
);
19426 case decl_setvalue
:
19427 visitSetValue (v
, n
, p
);
19432 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
19433 __builtin_unreachable ();
19439 visitNode - visits node, n, if it is not already in the alist, v.
19440 It calls p(n) if the node is unvisited.
19443 static void visitNode (alists_alist v
, decl_node n
, decl_nodeProcedure p
)
19445 if ((n
!= NULL
) && (! (alists_isItemInList (v
, reinterpret_cast<void *> (n
)))))
19447 alists_includeItemIntoList (v
, reinterpret_cast<void *> (n
));
19449 visitDependants (v
, n
, p
);
19455 genKind - returns a string depending upon the kind of node, n.
19458 static DynamicStrings_String
genKind (decl_node n
)
19472 case decl_cardinal
:
19473 case decl_longcard
:
19474 case decl_shortcard
:
19477 case decl_shortint
:
19479 case decl_longreal
:
19480 case decl_shortreal
:
19487 case decl_longcomplex
:
19488 case decl_shortcomplex
:
19489 /* types, no need to generate a kind string as it it contained in the name. */
19494 /* language features and compound type attributes. */
19495 return DynamicStrings_InitString ((const char *) "type", 4);
19499 return DynamicStrings_InitString ((const char *) "record", 6);
19503 return DynamicStrings_InitString ((const char *) "varient", 7);
19507 return DynamicStrings_InitString ((const char *) "var", 3);
19510 case decl_enumeration
:
19511 return DynamicStrings_InitString ((const char *) "enumeration", 11);
19514 case decl_subrange
:
19515 return DynamicStrings_InitString ((const char *) "subrange", 8);
19519 return DynamicStrings_InitString ((const char *) "array", 5);
19522 case decl_subscript
:
19523 return DynamicStrings_InitString ((const char *) "subscript", 9);
19527 return DynamicStrings_InitString ((const char *) "string", 6);
19531 return DynamicStrings_InitString ((const char *) "const", 5);
19535 return DynamicStrings_InitString ((const char *) "literal", 7);
19538 case decl_varparam
:
19539 return DynamicStrings_InitString ((const char *) "varparam", 8);
19543 return DynamicStrings_InitString ((const char *) "param", 5);
19547 return DynamicStrings_InitString ((const char *) "varargs", 7);
19551 return DynamicStrings_InitString ((const char *) "pointer", 7);
19554 case decl_recordfield
:
19555 return DynamicStrings_InitString ((const char *) "recordfield", 11);
19558 case decl_varientfield
:
19559 return DynamicStrings_InitString ((const char *) "varientfield", 12);
19562 case decl_enumerationfield
:
19563 return DynamicStrings_InitString ((const char *) "enumerationfield", 16);
19567 return DynamicStrings_InitString ((const char *) "set", 3);
19570 case decl_proctype
:
19571 return DynamicStrings_InitString ((const char *) "proctype", 8);
19574 case decl_procedure
:
19576 return DynamicStrings_InitString ((const char *) "procedure", 9);
19580 return DynamicStrings_InitString ((const char *) "def", 3);
19584 return DynamicStrings_InitString ((const char *) "imp", 3);
19588 return DynamicStrings_InitString ((const char *) "module", 6);
19593 return DynamicStrings_InitString ((const char *) "loop", 4);
19597 return DynamicStrings_InitString ((const char *) "while", 5);
19601 return DynamicStrings_InitString ((const char *) "for", 3);
19605 return DynamicStrings_InitString ((const char *) "repeat", 6);
19608 case decl_assignment
:
19609 return DynamicStrings_InitString ((const char *) "assignment", 10);
19613 return DynamicStrings_InitString ((const char *) "if", 2);
19617 return DynamicStrings_InitString ((const char *) "elsif", 5);
19620 case decl_constexp
:
19622 return DynamicStrings_InitString ((const char *) "constexp", 8);
19626 return DynamicStrings_InitString ((const char *) "neg", 3);
19630 return DynamicStrings_InitString ((const char *) "cast", 4);
19634 return DynamicStrings_InitString ((const char *) "val", 3);
19638 return DynamicStrings_InitString ((const char *) "plus", 4);
19642 return DynamicStrings_InitString ((const char *) "sub", 3);
19646 return DynamicStrings_InitString ((const char *) "div", 3);
19650 return DynamicStrings_InitString ((const char *) "mod", 3);
19654 return DynamicStrings_InitString ((const char *) "mult", 4);
19658 return DynamicStrings_InitString ((const char *) "divide", 6);
19662 return DynamicStrings_InitString ((const char *) "adr", 3);
19666 return DynamicStrings_InitString ((const char *) "size", 4);
19670 return DynamicStrings_InitString ((const char *) "tsize", 5);
19674 return DynamicStrings_InitString ((const char *) "chr", 3);
19678 return DynamicStrings_InitString ((const char *) "ord", 3);
19682 return DynamicStrings_InitString ((const char *) "float", 5);
19686 return DynamicStrings_InitString ((const char *) "trunc", 5);
19690 return DynamicStrings_InitString ((const char *) "high", 4);
19693 case decl_componentref
:
19694 return DynamicStrings_InitString ((const char *) "componentref", 12);
19697 case decl_pointerref
:
19698 return DynamicStrings_InitString ((const char *) "pointerref", 10);
19701 case decl_arrayref
:
19702 return DynamicStrings_InitString ((const char *) "arrayref", 8);
19706 return DynamicStrings_InitString ((const char *) "deref", 5);
19710 return DynamicStrings_InitString ((const char *) "equal", 5);
19713 case decl_notequal
:
19714 return DynamicStrings_InitString ((const char *) "notequal", 8);
19718 return DynamicStrings_InitString ((const char *) "less", 4);
19722 return DynamicStrings_InitString ((const char *) "greater", 7);
19725 case decl_greequal
:
19726 return DynamicStrings_InitString ((const char *) "greequal", 8);
19729 case decl_lessequal
:
19730 return DynamicStrings_InitString ((const char *) "lessequal", 9);
19734 return DynamicStrings_InitString ((const char *) "lsl", 3);
19738 return DynamicStrings_InitString ((const char *) "lsr", 3);
19742 return DynamicStrings_InitString ((const char *) "lor", 3);
19746 return DynamicStrings_InitString ((const char *) "land", 4);
19750 return DynamicStrings_InitString ((const char *) "lnot", 4);
19754 return DynamicStrings_InitString ((const char *) "lxor", 4);
19758 return DynamicStrings_InitString ((const char *) "and", 3);
19762 return DynamicStrings_InitString ((const char *) "or", 2);
19766 return DynamicStrings_InitString ((const char *) "not", 3);
19769 case decl_identlist
:
19770 return DynamicStrings_InitString ((const char *) "identlist", 9);
19774 return DynamicStrings_InitString ((const char *) "vardecl", 7);
19779 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
19780 __builtin_unreachable ();
19783 __builtin_unreachable ();
19784 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
19785 __builtin_unreachable ();
19790 gen - generate a small string describing node, n.
19793 static DynamicStrings_String
gen (decl_node n
)
19795 DynamicStrings_String s
;
19798 d
= (unsigned int ) ((long unsigned int ) (n
));
19799 s
= FormatStrings_Sprintf1 (DynamicStrings_InitString ((const char *) "< %d ", 5), (const unsigned char *) &d
, (sizeof (d
)-1)); /* use 0x%x once FormatStrings has been released. */
19800 s
= DynamicStrings_ConCat (s
, genKind (n
)); /* use 0x%x once FormatStrings has been released. */
19801 s
= DynamicStrings_ConCat (s
, DynamicStrings_InitString ((const char *) " ", 1));
19802 s
= DynamicStrings_ConCat (s
, getFQstring (n
));
19803 s
= DynamicStrings_ConCat (s
, DynamicStrings_InitString ((const char *) " >", 2));
19805 /* static analysis guarentees a RETURN statement will be used before here. */
19806 __builtin_unreachable ();
19814 static void dumpQ (const char *q_
, unsigned int _q_high
, alists_alist l
)
19816 DynamicStrings_String m
;
19823 /* make a local copy of each unbounded array. */
19824 memcpy (q
, q_
, _q_high
+1);
19826 m
= FormatStrings_Sprintf0 (DynamicStrings_InitString ((const char *) "Queue ", 6));
19827 m
= DynamicStrings_KillString (SFIO_WriteS (FIO_StdOut
, m
));
19828 m
= FormatStrings_Sprintf0 (DynamicStrings_InitString ((const char *) q
, _q_high
));
19829 m
= DynamicStrings_KillString (SFIO_WriteS (FIO_StdOut
, m
));
19830 m
= FormatStrings_Sprintf0 (DynamicStrings_InitString ((const char *) "\\n", 2));
19831 m
= DynamicStrings_KillString (SFIO_WriteS (FIO_StdOut
, m
));
19833 h
= alists_noOfItemsInList (l
);
19836 n
= static_cast<decl_node
> (alists_getItemFromList (l
, i
));
19837 m
= DynamicStrings_KillString (SFIO_WriteS (FIO_StdOut
, gen (n
)));
19840 m
= FormatStrings_Sprintf0 (DynamicStrings_InitString ((const char *) "\\n", 2));
19841 m
= DynamicStrings_KillString (SFIO_WriteS (FIO_StdOut
, m
));
19849 static void dumpLists (void)
19851 DynamicStrings_String m
;
19853 if (mcOptions_getDebugTopological ())
19855 m
= FormatStrings_Sprintf0 (DynamicStrings_InitString ((const char *) "\\n", 2));
19856 m
= DynamicStrings_KillString (SFIO_WriteS (FIO_StdOut
, m
));
19857 dumpQ ((const char *) "todo", 4, todoQ
);
19858 dumpQ ((const char *) "partial", 7, partialQ
);
19859 dumpQ ((const char *) "done", 4, doneQ
);
19868 static void outputHidden (decl_node n
)
19870 outText (doP
, (const char *) "#if !defined (", 14);
19871 doFQNameC (doP
, n
);
19872 outText (doP
, (const char *) "_D)\\n", 5);
19873 outText (doP
, (const char *) "# define ", 10);
19874 doFQNameC (doP
, n
);
19875 outText (doP
, (const char *) "_D\\n", 4);
19876 outText (doP
, (const char *) " typedef void *", 17);
19877 doFQNameC (doP
, n
);
19878 outText (doP
, (const char *) ";\\n", 3);
19879 outText (doP
, (const char *) "#endif\\n\\n", 10);
19884 outputHiddenComplete -
19887 static void outputHiddenComplete (decl_node n
)
19891 mcDebug_assert (decl_isType (n
));
19892 t
= decl_getType (n
);
19893 mcDebug_assert (decl_isPointer (t
));
19894 outText (doP
, (const char *) "#define ", 8);
19895 doFQNameC (doP
, n
);
19896 outText (doP
, (const char *) "_D\\n", 4);
19897 outText (doP
, (const char *) "typedef ", 8);
19898 doTypeNameC (doP
, decl_getType (t
));
19899 mcPretty_setNeedSpace (doP
);
19900 outText (doP
, (const char *) "*", 1);
19901 doFQNameC (doP
, n
);
19902 outText (doP
, (const char *) ";\\n", 3);
19910 static bool tryPartial (decl_node n
, decl_nodeProcedure pt
)
19914 if ((n
!= NULL
) && (decl_isType (n
)))
19916 q
= decl_getType (n
);
19917 while (decl_isPointer (q
))
19919 q
= decl_getType (q
);
19923 /* avoid gcc warning by using compound statement even if not strictly necessary. */
19924 if ((decl_isRecord (q
)) || (decl_isProcType (q
)))
19930 else if (decl_isArray (q
))
19932 /* avoid dangling else. */
19940 /* static analysis guarentees a RETURN statement will be used before here. */
19941 __builtin_unreachable ();
19946 outputPartialRecordArrayProcType -
19949 static void outputPartialRecordArrayProcType (decl_node n
, decl_node q
, unsigned int indirection
)
19951 DynamicStrings_String s
;
19953 outText (doP
, (const char *) "typedef struct", 14);
19954 mcPretty_setNeedSpace (doP
);
19955 s
= getFQstring (n
);
19956 if (decl_isRecord (q
))
19958 s
= DynamicStrings_ConCat (s
, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "_r", 2)));
19960 else if (decl_isArray (q
))
19962 /* avoid dangling else. */
19963 s
= DynamicStrings_ConCat (s
, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "_a", 2)));
19965 else if (decl_isProcType (q
))
19967 /* avoid dangling else. */
19968 s
= DynamicStrings_ConCat (s
, DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "_p", 2)));
19971 mcPretty_setNeedSpace (doP
);
19972 s
= DynamicStrings_KillString (s
);
19973 while (indirection
> 0)
19975 outText (doP
, (const char *) "*", 1);
19978 doFQNameC (doP
, n
);
19979 outText (doP
, (const char *) ";\\n\\n", 5);
19987 static void outputPartial (decl_node n
)
19990 unsigned int indirection
;
19992 q
= decl_getType (n
);
19994 while (decl_isPointer (q
))
19996 q
= decl_getType (q
);
19999 outputPartialRecordArrayProcType (n
, q
, indirection
);
20007 static void tryOutputTodo (decl_nodeProcedure c
, decl_nodeProcedure t
, decl_nodeProcedure v
, decl_nodeProcedure pt
)
20014 n
= alists_noOfItemsInList (todoQ
);
20017 d
= static_cast<decl_node
> (alists_getItemFromList (todoQ
, i
));
20018 if (tryComplete (d
, c
, t
, v
))
20020 alists_removeItemFromList (todoQ
, reinterpret_cast<void *> (d
));
20021 alists_includeItemIntoList (doneQ
, reinterpret_cast<void *> (d
));
20024 else if (tryPartial (d
, pt
))
20026 /* avoid dangling else. */
20027 alists_removeItemFromList (todoQ
, reinterpret_cast<void *> (d
));
20028 alists_includeItemIntoList (partialQ
, reinterpret_cast<void *> (d
));
20033 /* avoid dangling else. */
20036 n
= alists_noOfItemsInList (todoQ
);
20045 static void tryOutputPartial (decl_nodeProcedure t
)
20052 n
= alists_noOfItemsInList (partialQ
);
20055 d
= static_cast<decl_node
> (alists_getItemFromList (partialQ
, i
));
20056 if (tryCompleteFromPartial (d
, t
))
20058 alists_removeItemFromList (partialQ
, reinterpret_cast<void *> (d
));
20059 alists_includeItemIntoList (doneQ
, reinterpret_cast<void *> (d
));
20075 static void debugList (const char *a_
, unsigned int _a_high
, alists_alist l
)
20082 /* make a local copy of each unbounded array. */
20083 memcpy (a
, a_
, _a_high
+1);
20085 h
= alists_noOfItemsInList (l
);
20088 outText (doP
, (const char *) a
, _a_high
);
20089 outText (doP
, (const char *) " still contains node(s)\\n", 25);
20092 n
= static_cast<decl_node
> (alists_getItemFromList (l
, i
));
20095 } while (! (i
> h
));
20104 static void debugLists (void)
20106 if (mcOptions_getDebugTopological ())
20108 debugList ((const char *) "todo", 4, todoQ
);
20109 debugList ((const char *) "partial", 7, partialQ
);
20118 static void addEnumConst (decl_node n
)
20120 DynamicStrings_String s
;
20122 if ((decl_isConst (n
)) || (decl_isEnumeration (n
)))
20133 static void populateTodo (decl_nodeProcedure p
)
20140 h
= alists_noOfItemsInList (todoQ
);
20144 n
= static_cast<decl_node
> (alists_getItemFromList (todoQ
, i
));
20145 l
= alists_initList ();
20146 visitNode (l
, n
, p
);
20147 alists_killList (&l
);
20148 h
= alists_noOfItemsInList (todoQ
);
20158 static void topologicallyOut (decl_nodeProcedure c
, decl_nodeProcedure t
, decl_nodeProcedure v
, decl_nodeProcedure tp
, decl_nodeProcedure pc
, decl_nodeProcedure pt
, decl_nodeProcedure pv
)
20165 populateTodo ((decl_nodeProcedure
) {(decl_nodeProcedure_t
) addEnumConst
});
20168 to
= alists_noOfItemsInList (todoQ
);
20169 pa
= alists_noOfItemsInList (partialQ
);
20170 while ((tol
!= to
) || (pal
!= pa
))
20173 tryOutputTodo (c
, t
, v
, tp
);
20175 tryOutputPartial (pt
);
20178 to
= alists_noOfItemsInList (todoQ
);
20179 pa
= alists_noOfItemsInList (partialQ
);
20190 static void scaffoldStatic (mcPretty_pretty p
, decl_node n
)
20192 outText (p
, (const char *) "\\n", 2);
20194 outText (p
, (const char *) "void", 4);
20195 mcPretty_setNeedSpace (p
);
20196 outText (p
, (const char *) "_M2_", 4);
20198 outText (p
, (const char *) "_init", 5);
20199 mcPretty_setNeedSpace (p
);
20200 outText (p
, (const char *) "(__attribute__((unused)) int argc", 33);
20201 outText (p
, (const char *) ",__attribute__((unused)) char *argv[]", 37);
20202 outText (p
, (const char *) ",__attribute__((unused)) char *envp[])\\n", 40);
20203 p
= outKc (p
, (const char *) "{\\n", 3);
20204 doStatementsC (p
, n
->impF
.beginStatements
);
20205 p
= outKc (p
, (const char *) "}\\n", 3);
20206 outText (p
, (const char *) "\\n", 2);
20208 outText (p
, (const char *) "void", 4);
20209 mcPretty_setNeedSpace (p
);
20210 outText (p
, (const char *) "_M2_", 4);
20212 outText (p
, (const char *) "_fini", 5);
20213 mcPretty_setNeedSpace (p
);
20214 outText (p
, (const char *) "(__attribute__((unused)) int argc", 33);
20215 outText (p
, (const char *) ",__attribute__((unused)) char *argv[]", 37);
20216 outText (p
, (const char *) ",__attribute__((unused)) char *envp[])\\n", 40);
20217 p
= outKc (p
, (const char *) "{\\n", 3);
20218 doStatementsC (p
, n
->impF
.finallyStatements
);
20219 p
= outKc (p
, (const char *) "}\\n", 3);
20227 static void emitCtor (mcPretty_pretty p
, decl_node n
)
20229 DynamicStrings_String s
;
20231 outText (p
, (const char *) "\\n", 2);
20232 outText (p
, (const char *) "static void", 11);
20233 mcPretty_setNeedSpace (p
);
20234 outText (p
, (const char *) "ctorFunction ()\\n", 17);
20236 p
= outKc (p
, (const char *) "{\\n", 3);
20237 outText (p
, (const char *) "M2RTS_RegisterModule (\"", 23);
20238 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
)));
20239 mcPretty_prints (p
, s
);
20240 outText (p
, (const char *) "\",\\n", 4);
20241 outText (p
, (const char *) "init, fini, dependencies);\\n", 28);
20242 p
= outKc (p
, (const char *) "}\\n\\n", 5);
20243 p
= outKc (p
, (const char *) "struct ", 7);
20244 mcPretty_prints (p
, s
);
20245 p
= outKc (p
, (const char *) "_module_m2 { ", 13);
20246 mcPretty_prints (p
, s
);
20247 p
= outKc (p
, (const char *) "_module_m2 (); ~", 16);
20248 mcPretty_prints (p
, s
);
20249 p
= outKc (p
, (const char *) "_module_m2 (); } global_module_", 31);
20250 mcPretty_prints (p
, s
);
20251 outText (p
, (const char *) ";\\n\\n", 5);
20252 mcPretty_prints (p
, s
);
20253 p
= outKc (p
, (const char *) "_module_m2::", 12);
20254 mcPretty_prints (p
, s
);
20255 p
= outKc (p
, (const char *) "_module_m2 ()\\n", 15);
20256 p
= outKc (p
, (const char *) "{\\n", 3);
20257 outText (p
, (const char *) "M2RTS_RegisterModule (\"", 23);
20258 mcPretty_prints (p
, s
);
20259 outText (p
, (const char *) "\", init, fini, dependencies);", 29);
20260 p
= outKc (p
, (const char *) "}\\n", 3);
20261 mcPretty_prints (p
, s
);
20262 p
= outKc (p
, (const char *) "_module_m2::~", 13);
20263 mcPretty_prints (p
, s
);
20264 p
= outKc (p
, (const char *) "_module_m2 ()\\n", 15);
20265 p
= outKc (p
, (const char *) "{\\n", 3);
20266 p
= outKc (p
, (const char *) "}\\n", 3);
20267 s
= DynamicStrings_KillString (s
);
20275 static void scaffoldDynamic (mcPretty_pretty p
, decl_node n
)
20277 outText (p
, (const char *) "\\n", 2);
20279 outText (p
, (const char *) "void", 4);
20280 mcPretty_setNeedSpace (p
);
20281 outText (p
, (const char *) "_M2_", 4);
20283 outText (p
, (const char *) "_init", 5);
20284 mcPretty_setNeedSpace (p
);
20285 outText (p
, (const char *) "(__attribute__((unused)) int argc,", 34);
20286 outText (p
, (const char *) " __attribute__((unused)) char *argv[]", 37);
20287 outText (p
, (const char *) " __attribute__((unused)) char *envp[])\\n", 40);
20288 p
= outKc (p
, (const char *) "{\\n", 3);
20289 doStatementsC (p
, n
->impF
.beginStatements
);
20290 p
= outKc (p
, (const char *) "}\\n", 3);
20291 outText (p
, (const char *) "\\n", 2);
20293 outText (p
, (const char *) "void", 4);
20294 mcPretty_setNeedSpace (p
);
20295 outText (p
, (const char *) "_M2_", 4);
20297 outText (p
, (const char *) "_fini", 5);
20298 mcPretty_setNeedSpace (p
);
20299 outText (p
, (const char *) "(__attribute__((unused)) int argc,", 34);
20300 outText (p
, (const char *) " __attribute__((unused)) char *argv[]", 37);
20301 outText (p
, (const char *) " __attribute__((unused)) char *envp[])\\n", 40);
20302 p
= outKc (p
, (const char *) "{\\n", 3);
20303 doStatementsC (p
, n
->impF
.finallyStatements
);
20304 p
= outKc (p
, (const char *) "}\\n", 3);
20313 static void scaffoldMain (mcPretty_pretty p
, decl_node n
)
20315 DynamicStrings_String s
;
20317 outText (p
, (const char *) "int\\n", 5);
20318 outText (p
, (const char *) "main", 4);
20319 mcPretty_setNeedSpace (p
);
20320 outText (p
, (const char *) "(int argc, char *argv[], char *envp[])\\n", 40);
20321 p
= outKc (p
, (const char *) "{\\n", 3);
20322 outText (p
, (const char *) "M2RTS_ConstructModules (", 24);
20323 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
)));
20324 mcPretty_prints (p
, s
);
20325 outText (p
, (const char *) ", argc, argv, envp);\\n", 22);
20326 outText (p
, (const char *) "M2RTS_DeconstructModules (", 26);
20327 mcPretty_prints (p
, s
);
20328 outText (p
, (const char *) ", argc, argv, envp);\\n", 22);
20329 outText (p
, (const char *) "return 0;", 9);
20330 p
= outKc (p
, (const char *) "}\\n", 3);
20331 s
= DynamicStrings_KillString (s
);
20336 outImpInitC - emit the init/fini functions and main function if required.
20339 static void outImpInitC (mcPretty_pretty p
, decl_node n
)
20341 if (mcOptions_getScaffoldDynamic ())
20343 scaffoldDynamic (p
, n
);
20347 scaffoldStatic (p
, n
);
20349 if (mcOptions_getScaffoldMain ())
20351 scaffoldMain (p
, n
);
20360 static void runSimplifyTypes (decl_node n
)
20362 if (decl_isImp (n
))
20364 simplifyTypes (n
->impF
.decls
);
20366 else if (decl_isModule (n
))
20368 /* avoid dangling else. */
20369 simplifyTypes (n
->moduleF
.decls
);
20371 else if (decl_isDef (n
))
20373 /* avoid dangling else. */
20374 simplifyTypes (n
->defF
.decls
);
20383 static void outDefC (mcPretty_pretty p
, decl_node n
)
20385 DynamicStrings_String s
;
20387 mcDebug_assert (decl_isDef (n
));
20388 outputFile
= mcStream_openFrag (1); /* first fragment. */
20389 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
))); /* first fragment. */
20390 mcPretty_print (p
, (const char *) "/* do not edit automatically generated by mc from ", 50);
20391 mcPretty_prints (p
, s
);
20392 mcPretty_print (p
, (const char *) ". */\\n", 7);
20393 mcOptions_writeGPLheader (outputFile
);
20394 doCommentC (p
, n
->defF
.com
.body
);
20395 mcPretty_print (p
, (const char *) "\\n\\n#if !defined (_", 19);
20396 mcPretty_prints (p
, s
);
20397 mcPretty_print (p
, (const char *) "_H)\\n", 5);
20398 mcPretty_print (p
, (const char *) "# define _", 12);
20399 mcPretty_prints (p
, s
);
20400 mcPretty_print (p
, (const char *) "_H\\n\\n", 6);
20401 keyc_genConfigSystem (p
);
20402 mcPretty_print (p
, (const char *) "# ifdef __cplusplus\\n", 23);
20403 mcPretty_print (p
, (const char *) "extern \"C\" {\\n", 14);
20404 mcPretty_print (p
, (const char *) "# endif\\n", 11);
20405 outputFile
= mcStream_openFrag (3); /* third fragment. */
20406 doP
= p
; /* third fragment. */
20407 Indexing_ForeachIndiceInIndexDo (n
->defF
.importedModules
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) doIncludeC
});
20408 mcPretty_print (p
, (const char *) "\\n", 2);
20409 mcPretty_print (p
, (const char *) "# if defined (_", 17);
20410 mcPretty_prints (p
, s
);
20411 mcPretty_print (p
, (const char *) "_C)\\n", 5);
20412 mcPretty_print (p
, (const char *) "# define EXTERN\\n", 22);
20413 mcPretty_print (p
, (const char *) "# else\\n", 10);
20414 mcPretty_print (p
, (const char *) "# define EXTERN extern\\n", 29);
20415 mcPretty_print (p
, (const char *) "# endif\\n\\n", 13);
20416 outDeclsDefC (p
, n
);
20417 runPrototypeDefC (n
);
20418 mcPretty_print (p
, (const char *) "# ifdef __cplusplus\\n", 23);
20419 mcPretty_print (p
, (const char *) "}\\n", 3);
20420 mcPretty_print (p
, (const char *) "# endif\\n", 11);
20421 mcPretty_print (p
, (const char *) "\\n", 2);
20422 mcPretty_print (p
, (const char *) "# undef EXTERN\\n", 18);
20423 mcPretty_print (p
, (const char *) "#endif\\n", 8);
20424 outputFile
= mcStream_openFrag (2); /* second fragment. */
20425 keyc_genDefs (p
); /* second fragment. */
20426 s
= DynamicStrings_KillString (s
);
20431 runPrototypeExported -
20434 static void runPrototypeExported (decl_node n
)
20436 if (decl_isExported (n
))
20438 keyc_enterScope (n
);
20439 doProcedureHeadingC (n
, true);
20440 mcPretty_print (doP
, (const char *) ";\\n", 3);
20441 keyc_leaveScope (n
);
20450 static void runPrototypeDefC (decl_node n
)
20452 if (decl_isDef (n
))
20454 Indexing_ForeachIndiceInIndexDo (n
->defF
.decls
.procedures
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) runPrototypeExported
});
20463 static void outImpC (mcPretty_pretty p
, decl_node n
)
20465 DynamicStrings_String s
;
20466 decl_node defModule
;
20468 mcDebug_assert (decl_isImp (n
));
20469 outputFile
= mcStream_openFrag (1); /* first fragment. */
20470 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
))); /* first fragment. */
20471 mcPretty_print (p
, (const char *) "/* do not edit automatically generated by mc from ", 50);
20472 mcPretty_prints (p
, s
);
20473 mcPretty_print (p
, (const char *) ". */\\n", 7);
20474 mcOptions_writeGPLheader (outputFile
);
20475 doCommentC (p
, n
->impF
.com
.body
);
20476 outText (p
, (const char *) "\\n", 2);
20477 outputFile
= mcStream_openFrag (3); /* third fragment. */
20478 if (mcOptions_getExtendedOpaque ()) /* third fragment. */
20481 /* ForeachIndiceInIndexDo (n^.impF.importedModules, doIncludeC) ; */
20482 includeExternals (n
);
20483 foreachModuleDo (n
, (symbolKey_performOperation
) {(symbolKey_performOperation_t
) runSimplifyTypes
});
20484 libc_printf ((const char *) "/* --extended-opaque seen therefore no #include will be used and everything will be declared in full. */\\n", 108);
20485 decl_foreachDefModuleDo ((symbolKey_performOperation
) {(symbolKey_performOperation_t
) runIncludeDefConstType
});
20486 includeDefVarProcedure (n
);
20487 outDeclsImpC (p
, n
->impF
.decls
);
20488 decl_foreachDefModuleDo ((symbolKey_performOperation
) {(symbolKey_performOperation_t
) runPrototypeDefC
});
20492 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
)));
20493 /* we don't want to include the .h file for this implementation module. */
20494 mcPretty_print (p
, (const char *) "#define _", 9);
20495 mcPretty_prints (p
, s
);
20496 mcPretty_print (p
, (const char *) "_H\\n", 4);
20497 mcPretty_print (p
, (const char *) "#define _", 9);
20498 mcPretty_prints (p
, s
);
20499 mcPretty_print (p
, (const char *) "_C\\n\\n", 6);
20500 s
= DynamicStrings_KillString (s
);
20502 Indexing_ForeachIndiceInIndexDo (n
->impF
.importedModules
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) doIncludeC
});
20503 mcPretty_print (p
, (const char *) "\\n", 2);
20504 includeDefConstType (n
);
20505 includeDefVarProcedure (n
);
20506 outDeclsImpC (p
, n
->impF
.decls
);
20507 defModule
= decl_lookupDef (decl_getSymName (n
));
20508 if (defModule
!= NULL
)
20510 runPrototypeDefC (defModule
);
20513 Indexing_ForeachIndiceInIndexDo (n
->impF
.decls
.procedures
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) doPrototypeC
});
20514 outProceduresC (p
, n
->impF
.decls
);
20515 outImpInitC (p
, n
);
20516 outputFile
= mcStream_openFrag (2); /* second fragment. */
20517 keyc_genConfigSystem (p
); /* second fragment. */
20526 static void outDeclsModuleC (mcPretty_pretty p
, decl_scopeT s
)
20529 includeConstType (s
);
20531 topologicallyOut ((decl_nodeProcedure
) {(decl_nodeProcedure_t
) doConstC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doTypesC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doVarC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) outputPartial
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNone
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doCompletePartialC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNone
});
20532 /* try and output types, constants before variables and procedures. */
20533 includeVarProcedure (s
);
20534 topologicallyOut ((decl_nodeProcedure
) {(decl_nodeProcedure_t
) doConstC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doTypesC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doVarC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) outputPartial
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNone
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doCompletePartialC
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNone
});
20535 Indexing_ForeachIndiceInIndexDo (s
.procedures
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) doPrototypeC
});
20543 static void outModuleInitC (mcPretty_pretty p
, decl_node n
)
20545 outText (p
, (const char *) "\\n", 2);
20547 outText (p
, (const char *) "void", 4);
20548 mcPretty_setNeedSpace (p
);
20549 outText (p
, (const char *) "_M2_", 4);
20551 outText (p
, (const char *) "_init", 5);
20552 mcPretty_setNeedSpace (p
);
20553 outText (p
, (const char *) "(__attribute__((unused)) int argc", 33);
20554 outText (p
, (const char *) ",__attribute__((unused)) char *argv[]", 37);
20555 outText (p
, (const char *) ",__attribute__((unused)) char *envp[])\\n", 40);
20556 p
= outKc (p
, (const char *) "{\\n", 3);
20557 doStatementsC (p
, n
->moduleF
.beginStatements
);
20558 p
= outKc (p
, (const char *) "}\\n", 3);
20559 outText (p
, (const char *) "\\n", 2);
20561 outText (p
, (const char *) "void", 4);
20562 mcPretty_setNeedSpace (p
);
20563 outText (p
, (const char *) "_M2_", 4);
20565 outText (p
, (const char *) "_fini", 5);
20566 mcPretty_setNeedSpace (p
);
20567 outText (p
, (const char *) "(__attribute__((unused)) int argc", 33);
20568 outText (p
, (const char *) ",__attribute__((unused)) char *argv[]", 37);
20569 outText (p
, (const char *) ",__attribute__((unused)) char *envp[])\\n", 40);
20570 p
= outKc (p
, (const char *) "{\\n", 3);
20571 doStatementsC (p
, n
->moduleF
.finallyStatements
);
20572 p
= outKc (p
, (const char *) "}\\n", 3);
20580 static void outModuleC (mcPretty_pretty p
, decl_node n
)
20582 DynamicStrings_String s
;
20584 mcDebug_assert (decl_isModule (n
));
20585 outputFile
= mcStream_openFrag (1); /* first fragment. */
20586 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
))); /* first fragment. */
20587 mcPretty_print (p
, (const char *) "/* do not edit automatically generated by mc from ", 50);
20588 mcPretty_prints (p
, s
);
20589 mcPretty_print (p
, (const char *) ". */\\n", 7);
20590 mcOptions_writeGPLheader (outputFile
);
20591 doCommentC (p
, n
->moduleF
.com
.body
);
20592 outText (p
, (const char *) "\\n", 2);
20593 outputFile
= mcStream_openFrag (3); /* third fragment. */
20594 if (mcOptions_getExtendedOpaque ()) /* third fragment. */
20597 includeExternals (n
);
20598 foreachModuleDo (n
, (symbolKey_performOperation
) {(symbolKey_performOperation_t
) runSimplifyTypes
});
20599 libc_printf ((const char *) "/* --extended-opaque seen therefore no #include will be used and everything will be declared in full. */\\n", 108);
20600 decl_foreachDefModuleDo ((symbolKey_performOperation
) {(symbolKey_performOperation_t
) runIncludeDefConstType
});
20601 outDeclsModuleC (p
, n
->moduleF
.decls
);
20602 decl_foreachDefModuleDo ((symbolKey_performOperation
) {(symbolKey_performOperation_t
) runPrototypeDefC
});
20607 Indexing_ForeachIndiceInIndexDo (n
->moduleF
.importedModules
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) doIncludeC
});
20608 mcPretty_print (p
, (const char *) "\\n", 2);
20609 outDeclsModuleC (p
, n
->moduleF
.decls
);
20611 Indexing_ForeachIndiceInIndexDo (n
->moduleF
.decls
.procedures
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) doPrototypeC
});
20612 outProceduresC (p
, n
->moduleF
.decls
);
20613 outModuleInitC (p
, n
);
20614 outputFile
= mcStream_openFrag (2); /* second fragment. */
20615 keyc_genConfigSystem (p
); /* second fragment. */
20624 static void outC (mcPretty_pretty p
, decl_node n
)
20626 keyc_enterScope (n
);
20627 if (decl_isDef (n
))
20631 else if (decl_isImp (n
))
20633 /* avoid dangling else. */
20636 else if (decl_isModule (n
))
20638 /* avoid dangling else. */
20643 /* avoid dangling else. */
20645 __builtin_unreachable ();
20647 keyc_leaveScope (n
);
20652 doIncludeM2 - include modules in module, n.
20655 static void doIncludeM2 (decl_node n
)
20657 DynamicStrings_String s
;
20659 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
)));
20660 mcPretty_print (doP
, (const char *) "IMPORT ", 7);
20661 mcPretty_prints (doP
, s
);
20662 mcPretty_print (doP
, (const char *) " ;\\n", 4);
20663 s
= DynamicStrings_KillString (s
);
20664 if (decl_isDef (n
))
20666 symbolKey_foreachNodeDo (n
->defF
.decls
.symbols
, (symbolKey_performOperation
) {(symbolKey_performOperation_t
) addDone
});
20668 else if (decl_isImp (n
))
20670 /* avoid dangling else. */
20671 symbolKey_foreachNodeDo (n
->impF
.decls
.symbols
, (symbolKey_performOperation
) {(symbolKey_performOperation_t
) addDone
});
20673 else if (decl_isModule (n
))
20675 /* avoid dangling else. */
20676 symbolKey_foreachNodeDo (n
->moduleF
.decls
.symbols
, (symbolKey_performOperation
) {(symbolKey_performOperation_t
) addDone
});
20685 static void doConstM2 (decl_node n
)
20687 mcPretty_print (doP
, (const char *) "CONST\\n", 7);
20688 doFQNameC (doP
, n
);
20689 mcPretty_setNeedSpace (doP
);
20690 doExprC (doP
, n
->constF
.value
);
20691 mcPretty_print (doP
, (const char *) "\\n", 2);
20699 static void doProcTypeM2 (mcPretty_pretty p
, decl_node n
)
20701 outText (p
, (const char *) "proc type to do..", 17);
20709 static void doRecordFieldM2 (mcPretty_pretty p
, decl_node f
)
20712 outText (p
, (const char *) ":", 1);
20713 mcPretty_setNeedSpace (p
);
20714 doTypeM2 (p
, decl_getType (f
));
20715 mcPretty_setNeedSpace (p
);
20723 static void doVarientFieldM2 (mcPretty_pretty p
, decl_node n
)
20729 mcDebug_assert (decl_isVarientField (n
));
20731 outText (p
, (const char *) ":", 1);
20732 mcPretty_setNeedSpace (p
);
20733 i
= Indexing_LowIndice (n
->varientfieldF
.listOfSons
);
20734 t
= Indexing_HighIndice (n
->varientfieldF
.listOfSons
);
20737 q
= static_cast<decl_node
> (Indexing_GetIndice (n
->varientfieldF
.listOfSons
, i
));
20738 if (decl_isRecordField (q
))
20740 doRecordFieldM2 (p
, q
);
20741 outText (p
, (const char *) ";\\n", 3);
20743 else if (decl_isVarient (q
))
20745 /* avoid dangling else. */
20746 doVarientM2 (p
, q
);
20747 outText (p
, (const char *) ";\\n", 3);
20751 /* avoid dangling else. */
20753 __builtin_unreachable ();
20764 static void doVarientM2 (mcPretty_pretty p
, decl_node n
)
20770 mcDebug_assert (decl_isVarient (n
));
20771 outText (p
, (const char *) "CASE", 4);
20772 mcPretty_setNeedSpace (p
);
20773 if (n
->varientF
.tag
!= NULL
)
20775 /* avoid gcc warning by using compound statement even if not strictly necessary. */
20776 if (decl_isRecordField (n
->varientF
.tag
))
20778 doRecordFieldM2 (p
, n
->varientF
.tag
);
20780 else if (decl_isVarientField (n
->varientF
.tag
))
20782 /* avoid dangling else. */
20783 doVarientFieldM2 (p
, n
->varientF
.tag
);
20787 /* avoid dangling else. */
20789 __builtin_unreachable ();
20792 mcPretty_setNeedSpace (p
);
20793 outText (p
, (const char *) "OF\\n", 4);
20794 i
= Indexing_LowIndice (n
->varientF
.listOfSons
);
20795 t
= Indexing_HighIndice (n
->varientF
.listOfSons
);
20798 q
= static_cast<decl_node
> (Indexing_GetIndice (n
->varientF
.listOfSons
, i
));
20799 if (decl_isRecordField (q
))
20801 /* avoid dangling else. */
20802 if (! q
->recordfieldF
.tag
)
20804 doRecordFieldM2 (p
, q
);
20805 outText (p
, (const char *) ";\\n", 3);
20808 else if (decl_isVarientField (q
))
20810 /* avoid dangling else. */
20811 doVarientFieldM2 (p
, q
);
20815 /* avoid dangling else. */
20817 __builtin_unreachable ();
20821 outText (p
, (const char *) "END", 3);
20822 mcPretty_setNeedSpace (p
);
20830 static void doRecordM2 (mcPretty_pretty p
, decl_node n
)
20836 mcDebug_assert (decl_isRecord (n
));
20837 p
= outKm2 (p
, (const char *) "RECORD", 6);
20838 i
= Indexing_LowIndice (n
->recordF
.listOfSons
);
20839 h
= Indexing_HighIndice (n
->recordF
.listOfSons
);
20840 outText (p
, (const char *) "\\n", 2);
20843 f
= static_cast<decl_node
> (Indexing_GetIndice (n
->recordF
.listOfSons
, i
));
20844 if (decl_isRecordField (f
))
20846 /* avoid dangling else. */
20847 if (! f
->recordfieldF
.tag
)
20849 doRecordFieldM2 (p
, f
);
20850 outText (p
, (const char *) ";\\n", 3);
20853 else if (decl_isVarient (f
))
20855 /* avoid dangling else. */
20856 doVarientM2 (p
, f
);
20857 outText (p
, (const char *) ";\\n", 3);
20859 else if (decl_isVarientField (f
))
20861 /* avoid dangling else. */
20862 doVarientFieldM2 (p
, f
);
20866 p
= outKm2 (p
, (const char *) "END", 3);
20867 mcPretty_setNeedSpace (p
);
20875 static void doPointerM2 (mcPretty_pretty p
, decl_node n
)
20877 outText (p
, (const char *) "POINTER TO", 10);
20878 mcPretty_setNeedSpace (doP
);
20879 doTypeM2 (p
, decl_getType (n
));
20880 mcPretty_setNeedSpace (p
);
20881 outText (p
, (const char *) ";\\n", 3);
20889 static void doTypeAliasM2 (mcPretty_pretty p
, decl_node n
)
20891 doTypeNameC (p
, n
);
20892 mcPretty_setNeedSpace (p
);
20893 outText (doP
, (const char *) "=", 1);
20894 mcPretty_setNeedSpace (p
);
20895 doTypeM2 (p
, decl_getType (n
));
20896 mcPretty_setNeedSpace (p
);
20897 outText (p
, (const char *) "\\n", 2);
20905 static void doEnumerationM2 (mcPretty_pretty p
, decl_node n
)
20910 DynamicStrings_String t
;
20912 outText (p
, (const char *) "(", 1);
20913 i
= Indexing_LowIndice (n
->enumerationF
.listOfSons
);
20914 h
= Indexing_HighIndice (n
->enumerationF
.listOfSons
);
20917 s
= static_cast<decl_node
> (Indexing_GetIndice (n
->enumerationF
.listOfSons
, i
));
20921 outText (p
, (const char *) ",", 1);
20922 mcPretty_setNeedSpace (p
);
20926 outText (p
, (const char *) ")", 1);
20934 static void doBaseM2 (mcPretty_pretty p
, decl_node n
)
20939 case decl_cardinal
:
20940 case decl_longcard
:
20941 case decl_shortcard
:
20944 case decl_shortint
:
20946 case decl_longcomplex
:
20947 case decl_shortcomplex
:
20949 case decl_longreal
:
20950 case decl_shortreal
:
20959 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
20960 __builtin_unreachable ();
20962 mcPretty_setNeedSpace (p
);
20970 static void doSystemM2 (mcPretty_pretty p
, decl_node n
)
20985 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
20986 __builtin_unreachable ();
20995 static void doTypeM2 (mcPretty_pretty p
, decl_node n
)
21001 else if (isSystem (n
))
21003 /* avoid dangling else. */
21006 else if (decl_isType (n
))
21008 /* avoid dangling else. */
21009 doTypeAliasM2 (p
, n
);
21011 else if (decl_isProcType (n
))
21013 /* avoid dangling else. */
21014 doProcTypeM2 (p
, n
);
21016 else if (decl_isPointer (n
))
21018 /* avoid dangling else. */
21019 doPointerM2 (p
, n
);
21021 else if (decl_isEnumeration (n
))
21023 /* avoid dangling else. */
21024 doEnumerationM2 (p
, n
);
21026 else if (decl_isRecord (n
))
21028 /* avoid dangling else. */
21038 static void doTypesM2 (decl_node n
)
21042 outText (doP
, (const char *) "TYPE\\n", 6);
21051 static void doVarM2 (decl_node n
)
21053 mcDebug_assert (decl_isVar (n
));
21055 outText (doP
, (const char *) ":", 1);
21056 mcPretty_setNeedSpace (doP
);
21057 doTypeM2 (doP
, decl_getType (n
));
21058 mcPretty_setNeedSpace (doP
);
21059 outText (doP
, (const char *) ";\\n", 3);
21067 static void doVarsM2 (decl_node n
)
21071 outText (doP
, (const char *) "VAR\\n", 5);
21080 static void doTypeNameM2 (mcPretty_pretty p
, decl_node n
)
21090 static void doParamM2 (mcPretty_pretty p
, decl_node n
)
21098 mcDebug_assert (decl_isParam (n
));
21099 ptype
= decl_getType (n
);
21100 if (n
->paramF
.namelist
== NULL
)
21102 doTypeNameM2 (p
, ptype
);
21106 mcDebug_assert (isIdentList (n
->paramF
.namelist
));
21107 l
= n
->paramF
.namelist
->identlistF
.names
;
21110 doTypeNameM2 (p
, ptype
);
21114 t
= wlists_noOfItemsInList (l
);
21118 i
= static_cast<nameKey_Name
> (wlists_getItemFromList (l
, c
));
21119 mcPretty_setNeedSpace (p
);
21123 outText (p
, (const char *) ",", 1);
21124 mcPretty_setNeedSpace (p
);
21128 outText (p
, (const char *) ":", 1);
21129 mcPretty_setNeedSpace (p
);
21130 doTypeNameM2 (p
, ptype
);
21140 static void doVarParamM2 (mcPretty_pretty p
, decl_node n
)
21148 mcDebug_assert (decl_isVarParam (n
));
21149 outText (p
, (const char *) "VAR", 3);
21150 mcPretty_setNeedSpace (p
);
21151 ptype
= decl_getType (n
);
21152 if (n
->varparamF
.namelist
== NULL
)
21154 doTypeNameM2 (p
, ptype
);
21158 mcDebug_assert (isIdentList (n
->varparamF
.namelist
));
21159 l
= n
->varparamF
.namelist
->identlistF
.names
;
21162 doTypeNameM2 (p
, ptype
);
21166 t
= wlists_noOfItemsInList (l
);
21170 i
= static_cast<nameKey_Name
> (wlists_getItemFromList (l
, c
));
21171 mcPretty_setNeedSpace (p
);
21175 outText (p
, (const char *) ",", 1);
21176 mcPretty_setNeedSpace (p
);
21180 outText (p
, (const char *) ":", 1);
21181 mcPretty_setNeedSpace (p
);
21182 doTypeNameM2 (p
, ptype
);
21192 static void doParameterM2 (mcPretty_pretty p
, decl_node n
)
21194 if (decl_isParam (n
))
21198 else if (decl_isVarParam (n
))
21200 /* avoid dangling else. */
21201 doVarParamM2 (p
, n
);
21203 else if (decl_isVarargs (n
))
21205 /* avoid dangling else. */
21206 mcPretty_print (p
, (const char *) "...", 3);
21215 static void doPrototypeM2 (decl_node n
)
21221 mcDebug_assert (decl_isProcedure (n
));
21222 mcPretty_noSpace (doP
);
21224 mcPretty_setNeedSpace (doP
);
21225 outText (doP
, (const char *) "(", 1);
21226 i
= Indexing_LowIndice (n
->procedureF
.parameters
);
21227 h
= Indexing_HighIndice (n
->procedureF
.parameters
);
21230 p
= static_cast<decl_node
> (Indexing_GetIndice (n
->procedureF
.parameters
, i
));
21231 doParameterM2 (doP
, p
);
21232 mcPretty_noSpace (doP
);
21235 mcPretty_print (doP
, (const char *) ";", 1);
21236 mcPretty_setNeedSpace (doP
);
21240 outText (doP
, (const char *) ")", 1);
21241 if (n
->procedureF
.returnType
!= NULL
)
21243 mcPretty_setNeedSpace (doP
);
21244 outText (doP
, (const char *) ":", 1);
21245 doTypeM2 (doP
, n
->procedureF
.returnType
);
21246 mcPretty_setNeedSpace (doP
);
21248 outText (doP
, (const char *) ";\\n", 3);
21253 outputPartialM2 - just writes out record, array, and proctypes.
21254 No need for forward declarations in Modula-2
21255 but we need to keep topological sort happy.
21256 So when asked to output partial we emit the
21257 full type for these types and then do nothing
21258 when trying to complete partial to full.
21261 static void outputPartialM2 (decl_node n
)
21265 q
= decl_getType (n
);
21266 if (decl_isRecord (q
))
21270 else if (decl_isArray (q
))
21272 /* avoid dangling else. */
21275 else if (decl_isProcType (q
))
21277 /* avoid dangling else. */
21287 static void outDeclsDefM2 (mcPretty_pretty p
, decl_scopeT s
)
21290 includeConstType (s
);
21292 topologicallyOut ((decl_nodeProcedure
) {(decl_nodeProcedure_t
) doConstM2
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doTypesM2
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doVarsM2
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) outputPartialM2
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNothing
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNothing
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNothing
});
21293 includeVarProcedure (s
);
21294 topologicallyOut ((decl_nodeProcedure
) {(decl_nodeProcedure_t
) doConstM2
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doTypesM2
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doVarsM2
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) outputPartialM2
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNothing
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNothing
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNothing
});
21295 Indexing_ForeachIndiceInIndexDo (s
.procedures
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) doPrototypeM2
});
21303 static void outDefM2 (mcPretty_pretty p
, decl_node n
)
21305 DynamicStrings_String s
;
21307 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSource (n
)));
21308 mcPretty_print (p
, (const char *) "(* automatically created by mc from ", 36);
21309 mcPretty_prints (p
, s
);
21310 mcPretty_print (p
, (const char *) ". *)\\n\\n", 9);
21311 s
= DynamicStrings_KillString (s
);
21312 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSymName (n
)));
21313 mcPretty_print (p
, (const char *) "DEFINITION MODULE ", 18);
21314 mcPretty_prints (p
, s
);
21315 mcPretty_print (p
, (const char *) " ;\\n\\n", 6);
21317 Indexing_ForeachIndiceInIndexDo (n
->defF
.importedModules
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) doIncludeM2
});
21318 mcPretty_print (p
, (const char *) "\\n", 2);
21319 outDeclsDefM2 (p
, n
->defF
.decls
);
21320 mcPretty_print (p
, (const char *) "\\n", 2);
21321 mcPretty_print (p
, (const char *) "END ", 4);
21322 mcPretty_prints (p
, s
);
21323 mcPretty_print (p
, (const char *) ".\\n", 3);
21324 s
= DynamicStrings_KillString (s
);
21332 static void outDeclsImpM2 (mcPretty_pretty p
, decl_scopeT s
)
21335 includeConstType (s
);
21337 topologicallyOut ((decl_nodeProcedure
) {(decl_nodeProcedure_t
) doConstM2
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doTypesM2
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doVarM2
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) outputPartialM2
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNothing
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNothing
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNothing
});
21338 includeVarProcedure (s
);
21339 topologicallyOut ((decl_nodeProcedure
) {(decl_nodeProcedure_t
) doConstM2
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doTypesM2
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doVarsM2
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) outputPartialM2
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNothing
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNothing
}, (decl_nodeProcedure
) {(decl_nodeProcedure_t
) doNothing
});
21340 outText (p
, (const char *) "\\n", 2);
21341 Indexing_ForeachIndiceInIndexDo (s
.procedures
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) doPrototypeC
});
21349 static void outImpM2 (mcPretty_pretty p
, decl_node n
)
21351 DynamicStrings_String s
;
21353 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (decl_getSource (n
)));
21354 mcPretty_print (p
, (const char *) "(* automatically created by mc from ", 36);
21355 mcPretty_prints (p
, s
);
21356 mcPretty_print (p
, (const char *) ". *)\\n\\n", 9);
21357 mcPretty_print (p
, (const char *) "IMPLEMENTATION MODULE ", 22);
21358 mcPretty_prints (p
, s
);
21359 mcPretty_print (p
, (const char *) " ;\\n\\n", 6);
21361 Indexing_ForeachIndiceInIndexDo (n
->impF
.importedModules
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) doIncludeM2
});
21362 mcPretty_print (p
, (const char *) "\\n", 2);
21363 includeDefConstType (n
);
21364 outDeclsImpM2 (p
, n
->impF
.decls
);
21365 mcPretty_print (p
, (const char *) "\\n", 2);
21366 mcPretty_print (p
, (const char *) "END ", 4);
21367 mcPretty_prints (p
, s
);
21368 mcPretty_print (p
, (const char *) ".\\n", 3);
21369 s
= DynamicStrings_KillString (s
);
21377 static void outModuleM2 (mcPretty_pretty p
, decl_node n
)
21386 static void outM2 (mcPretty_pretty p
, decl_node n
)
21388 if (decl_isDef (n
))
21392 else if (decl_isImp (n
))
21394 /* avoid dangling else. */
21397 else if (decl_isModule (n
))
21399 /* avoid dangling else. */
21400 outModuleM2 (p
, n
);
21404 /* avoid dangling else. */
21406 __builtin_unreachable ();
21412 addDone - adds node, n, to the doneQ.
21415 static void addDone (decl_node n
)
21417 alists_includeItemIntoList (doneQ
, reinterpret_cast<void *> (n
));
21422 addDoneDef - adds node, n, to the doneQ providing
21423 it is not an opaque of the main module we are compiling.
21426 static void addDoneDef (decl_node n
)
21428 if (decl_isDef (n
))
21433 if ((! (decl_isDef (n
))) && ((decl_lookupImp (decl_getSymName (decl_getScope (n
)))) == (decl_getMainModule ())))
21435 mcMetaError_metaError1 ((const char *) "cyclic dependancy found between another module using {%1ad} from the definition module of the implementation main being compiled, use the --extended-opaque option to compile", 173, (const unsigned char *) &n
, (sizeof (n
)-1));
21436 mcError_flushErrors ();
21437 mcError_errorAbort0 ((const char *) "terminating compilation", 23);
21450 static decl_node
dbgAdd (alists_alist l
, decl_node n
)
21454 alists_includeItemIntoList (l
, reinterpret_cast<void *> (n
));
21457 /* static analysis guarentees a RETURN statement will be used before here. */
21458 __builtin_unreachable ();
21466 static void dbgType (alists_alist l
, decl_node n
)
21470 t
= dbgAdd (l
, decl_getType (n
));
21471 out1 ((const char *) "<%s type", 8, n
);
21474 out0 ((const char *) ", type = NIL\\n", 14);
21478 out1 ((const char *) ", type = %s>\\n", 14, t
);
21487 static void dbgPointer (alists_alist l
, decl_node n
)
21491 t
= dbgAdd (l
, decl_getType (n
));
21492 out1 ((const char *) "<%s pointer", 11, n
);
21493 out1 ((const char *) " to %s>\\n", 9, t
);
21501 static void dbgRecord (alists_alist l
, decl_node n
)
21507 out1 ((const char *) "<%s record:\\n", 13, n
);
21508 i
= Indexing_LowIndice (n
->recordF
.listOfSons
);
21509 t
= Indexing_HighIndice (n
->recordF
.listOfSons
);
21512 q
= static_cast<decl_node
> (Indexing_GetIndice (n
->recordF
.listOfSons
, i
));
21513 if (decl_isRecordField (q
))
21515 out1 ((const char *) " <recordfield %s", 16, q
);
21517 else if (decl_isVarientField (q
))
21519 /* avoid dangling else. */
21520 out1 ((const char *) " <varientfield %s", 17, q
);
21522 else if (decl_isVarient (q
))
21524 /* avoid dangling else. */
21525 out1 ((const char *) " <varient %s", 12, q
);
21529 /* avoid dangling else. */
21531 __builtin_unreachable ();
21533 q
= dbgAdd (l
, decl_getType (q
));
21534 out1 ((const char *) ": %s>\\n", 7, q
);
21537 outText (doP
, (const char *) ">\\n", 3);
21545 static void dbgVarient (alists_alist l
, decl_node n
)
21551 out1 ((const char *) "<%s varient: ", 13, n
);
21552 out1 ((const char *) "tag %s", 6, n
->varientF
.tag
);
21553 q
= decl_getType (n
->varientF
.tag
);
21556 outText (doP
, (const char *) "\\n", 2);
21560 out1 ((const char *) ": %s\\n", 6, q
);
21563 i
= Indexing_LowIndice (n
->varientF
.listOfSons
);
21564 t
= Indexing_HighIndice (n
->varientF
.listOfSons
);
21567 q
= static_cast<decl_node
> (Indexing_GetIndice (n
->varientF
.listOfSons
, i
));
21568 if (decl_isRecordField (q
))
21570 out1 ((const char *) " <recordfield %s", 16, q
);
21572 else if (decl_isVarientField (q
))
21574 /* avoid dangling else. */
21575 out1 ((const char *) " <varientfield %s", 17, q
);
21577 else if (decl_isVarient (q
))
21579 /* avoid dangling else. */
21580 out1 ((const char *) " <varient %s", 12, q
);
21584 /* avoid dangling else. */
21586 __builtin_unreachable ();
21588 q
= dbgAdd (l
, decl_getType (q
));
21589 out1 ((const char *) ": %s>\\n", 7, q
);
21592 outText (doP
, (const char *) ">\\n", 3);
21600 static void dbgEnumeration (alists_alist l
, decl_node n
)
21606 outText (doP
, (const char *) "< enumeration ", 14);
21607 i
= Indexing_LowIndice (n
->enumerationF
.listOfSons
);
21608 h
= Indexing_HighIndice (n
->enumerationF
.listOfSons
);
21611 e
= static_cast<decl_node
> (Indexing_GetIndice (n
->enumerationF
.listOfSons
, i
));
21612 out1 ((const char *) "%s, ", 4, e
);
21615 outText (doP
, (const char *) ">\\n", 3);
21623 static void dbgVar (alists_alist l
, decl_node n
)
21627 t
= dbgAdd (l
, decl_getType (n
));
21628 out1 ((const char *) "<%s var", 7, n
);
21629 out1 ((const char *) ", type = %s>\\n", 14, t
);
21637 static void dbgSubrange (alists_alist l
, decl_node n
)
21639 if (n
->subrangeF
.low
== NULL
)
21641 out1 ((const char *) "%s", 2, n
->subrangeF
.type
);
21645 out1 ((const char *) "[%s", 3, n
->subrangeF
.low
);
21646 out1 ((const char *) "..%s]", 5, n
->subrangeF
.high
);
21655 static void dbgArray (alists_alist l
, decl_node n
)
21659 t
= dbgAdd (l
, decl_getType (n
));
21660 out1 ((const char *) "<%s array ", 10, n
);
21661 if (n
->arrayF
.subr
!= NULL
)
21663 dbgSubrange (l
, n
->arrayF
.subr
);
21665 out1 ((const char *) " of %s>\\n", 9, t
);
21673 static void doDbg (alists_alist l
, decl_node n
)
21677 else if (decl_isSubrange (n
))
21679 /* avoid dangling else. */
21680 dbgSubrange (l
, n
);
21682 else if (decl_isType (n
))
21684 /* avoid dangling else. */
21687 else if (decl_isRecord (n
))
21689 /* avoid dangling else. */
21692 else if (decl_isVarient (n
))
21694 /* avoid dangling else. */
21697 else if (decl_isEnumeration (n
))
21699 /* avoid dangling else. */
21700 dbgEnumeration (l
, n
);
21702 else if (decl_isPointer (n
))
21704 /* avoid dangling else. */
21707 else if (decl_isArray (n
))
21709 /* avoid dangling else. */
21712 else if (decl_isVar (n
))
21714 /* avoid dangling else. */
21724 static void dbg (decl_node n
)
21729 DynamicStrings_String s
;
21734 outputFile
= FIO_StdOut
;
21735 doP
= mcPretty_initPretty ((mcPretty_writeProc
) {(mcPretty_writeProc_t
) write_
}, (mcPretty_writeLnProc
) {(mcPretty_writeLnProc_t
) writeln
});
21736 l
= alists_initList ();
21737 alists_includeItemIntoList (l
, reinterpret_cast<void *> (n
));
21739 out1 ((const char *) "dbg (%s)\\n", 10, n
);
21741 n
= static_cast<decl_node
> (alists_getItemFromList (l
, i
));
21744 } while (! (i
> (alists_noOfItemsInList (l
))));
21751 addGenericBody - adds comment node to funccall, return, assignment
21755 static void addGenericBody (decl_node n
, decl_node c
)
21759 case decl_unreachable
:
21768 n
->intrinsicF
.intrinsicComment
.body
= c
;
21771 case decl_funccall
:
21772 n
->funccallF
.funccallComment
.body
= c
;
21776 n
->returnF
.returnComment
.body
= c
;
21779 case decl_assignment
:
21780 n
->assignmentF
.assignComment
.body
= c
;
21784 n
->moduleF
.com
.body
= c
;
21788 n
->defF
.com
.body
= c
;
21792 n
->impF
.com
.body
= c
;
21803 addGenericAfter - adds comment node to funccall, return, assignment
21807 static void addGenericAfter (decl_node n
, decl_node c
)
21811 case decl_unreachable
:
21820 n
->intrinsicF
.intrinsicComment
.after
= c
;
21823 case decl_funccall
:
21824 n
->funccallF
.funccallComment
.after
= c
;
21828 n
->returnF
.returnComment
.after
= c
;
21831 case decl_assignment
:
21832 n
->assignmentF
.assignComment
.after
= c
;
21836 n
->moduleF
.com
.after
= c
;
21840 n
->defF
.com
.after
= c
;
21844 n
->impF
.com
.after
= c
;
21858 static bool isAssignment (decl_node n
)
21860 return n
->kind
== decl_assignment
;
21861 /* static analysis guarentees a RETURN statement will be used before here. */
21862 __builtin_unreachable ();
21867 isComment - returns TRUE if node, n, is a comment.
21870 static bool isComment (decl_node n
)
21872 mcDebug_assert (n
!= NULL
);
21873 return n
->kind
== decl_comment
;
21874 /* static analysis guarentees a RETURN statement will be used before here. */
21875 __builtin_unreachable ();
21880 initPair - initialise the commentPair, c.
21883 static void initPair (decl_commentPair
*c
)
21894 static decl_node
dupExplist (decl_node n
)
21899 mcDebug_assert (decl_isExpList (n
));
21900 m
= decl_makeExpList ();
21901 i
= Indexing_LowIndice (n
->explistF
.exp
);
21902 while (i
<= (Indexing_HighIndice (n
->explistF
.exp
)))
21904 decl_putExpList (m
, decl_dupExpr (reinterpret_cast<decl_node
> (Indexing_GetIndice (n
->explistF
.exp
, i
))));
21908 /* static analysis guarentees a RETURN statement will be used before here. */
21909 __builtin_unreachable ();
21917 static decl_node
dupArrayref (decl_node n
)
21919 mcDebug_assert (isArrayRef (n
));
21920 return decl_makeArrayRef (decl_dupExpr (n
->arrayrefF
.array
), decl_dupExpr (n
->arrayrefF
.index
));
21921 /* static analysis guarentees a RETURN statement will be used before here. */
21922 __builtin_unreachable ();
21930 static decl_node
dupPointerref (decl_node n
)
21932 mcDebug_assert (decl_isPointerRef (n
));
21933 return decl_makePointerRef (decl_dupExpr (n
->pointerrefF
.ptr
), decl_dupExpr (n
->pointerrefF
.field
));
21934 /* static analysis guarentees a RETURN statement will be used before here. */
21935 __builtin_unreachable ();
21943 static decl_node
dupComponentref (decl_node n
)
21945 mcDebug_assert (isComponentRef (n
));
21946 return doMakeComponentRef (decl_dupExpr (n
->componentrefF
.rec
), decl_dupExpr (n
->componentrefF
.field
));
21947 /* static analysis guarentees a RETURN statement will be used before here. */
21948 __builtin_unreachable ();
21956 static decl_node
dupBinary (decl_node n
)
21958 /* assert (isBinary (n)) ; */
21959 return makeBinary (n
->kind
, decl_dupExpr (n
->binaryF
.left
), decl_dupExpr (n
->binaryF
.right
), n
->binaryF
.resultType
);
21960 /* static analysis guarentees a RETURN statement will be used before here. */
21961 __builtin_unreachable ();
21969 static decl_node
dupUnary (decl_node n
)
21971 /* assert (isUnary (n)) ; */
21972 return makeUnary (n
->kind
, decl_dupExpr (n
->unaryF
.arg
), n
->unaryF
.resultType
);
21973 /* static analysis guarentees a RETURN statement will be used before here. */
21974 __builtin_unreachable ();
21982 static decl_node
dupFunccall (decl_node n
)
21986 mcDebug_assert (isFuncCall (n
));
21987 m
= decl_makeFuncCall (decl_dupExpr (n
->funccallF
.function
), decl_dupExpr (n
->funccallF
.args
));
21988 m
->funccallF
.type
= n
->funccallF
.type
;
21990 /* static analysis guarentees a RETURN statement will be used before here. */
21991 __builtin_unreachable ();
21999 static decl_node
dupSetValue (decl_node n
)
22004 m
= newNode (decl_setvalue
);
22005 m
->setvalueF
.type
= n
->setvalueF
.type
;
22006 i
= Indexing_LowIndice (n
->setvalueF
.values
);
22007 while (i
<= (Indexing_HighIndice (n
->setvalueF
.values
)))
22009 m
= decl_putSetValue (m
, decl_dupExpr (reinterpret_cast<decl_node
> (Indexing_GetIndice (n
->setvalueF
.values
, i
))));
22013 /* static analysis guarentees a RETURN statement will be used before here. */
22014 __builtin_unreachable ();
22022 static decl_node
doDupExpr (decl_node n
)
22024 mcDebug_assert (n
!= NULL
);
22028 return dupExplist (n
);
22035 M2RTS_HALT (-1); /* should not be duplicating code. */
22036 __builtin_unreachable ();
22040 M2RTS_HALT (-1); /* length should have been converted into unary. */
22041 __builtin_unreachable ();
22057 case decl_cardinal
:
22058 case decl_longcard
:
22059 case decl_shortcard
:
22061 case decl_shortint
:
22063 case decl_longreal
:
22064 case decl_shortreal
:
22069 case decl_longcomplex
:
22070 case decl_shortcomplex
:
22079 case decl_enumeration
:
22080 case decl_subrange
:
22081 case decl_subscript
:
22086 case decl_varparam
:
22091 case decl_recordfield
:
22092 case decl_varientfield
:
22093 case decl_enumerationfield
:
22095 case decl_proctype
:
22096 /* language features and compound type attributes. */
22100 case decl_procedure
:
22113 case decl_caselabellist
:
22114 case decl_caselist
:
22118 case decl_assignment
:
22123 case decl_arrayref
:
22125 return dupArrayref (n
);
22128 case decl_pointerref
:
22129 return dupPointerref (n
);
22132 case decl_componentref
:
22133 return dupComponentref (n
);
22140 case decl_notequal
:
22143 case decl_greequal
:
22144 case decl_lessequal
:
22154 return dupBinary (n
);
22159 case decl_constexp
:
22175 return dupUnary (n
);
22178 case decl_identlist
:
22186 case decl_funccall
:
22187 return dupFunccall (n
);
22190 case decl_setvalue
:
22191 return dupSetValue (n
);
22196 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
22197 __builtin_unreachable ();
22199 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
22200 __builtin_unreachable ();
22208 static void makeSystem (void)
22210 systemN
= decl_lookupDef (nameKey_makeKey ((const char *) "SYSTEM", 6));
22211 addressN
= makeBase (decl_address
);
22212 locN
= makeBase (decl_loc
);
22213 byteN
= makeBase (decl_byte
);
22214 wordN
= makeBase (decl_word
);
22215 csizetN
= makeBase (decl_csizet
);
22216 cssizetN
= makeBase (decl_cssizet
);
22217 adrN
= makeBase (decl_adr
);
22218 tsizeN
= makeBase (decl_tsize
);
22219 throwN
= makeBase (decl_throw
);
22220 decl_enterScope (systemN
);
22221 addressN
= addToScope (addressN
);
22222 locN
= addToScope (locN
);
22223 byteN
= addToScope (byteN
);
22224 wordN
= addToScope (wordN
);
22225 csizetN
= addToScope (csizetN
);
22226 cssizetN
= addToScope (cssizetN
);
22227 adrN
= addToScope (adrN
);
22228 tsizeN
= addToScope (tsizeN
);
22229 throwN
= addToScope (throwN
);
22230 mcDebug_assert (sizeN
!= NULL
); /* assumed to be built already. */
22231 sizeN
= addToScope (sizeN
); /* also export size from system. */
22232 decl_leaveScope (); /* also export size from system. */
22233 addDone (addressN
);
22238 addDone (cssizetN
);
22246 static void makeM2rts (void)
22248 m2rtsN
= decl_lookupDef (nameKey_makeKey ((const char *) "M2RTS", 5));
22256 static decl_node
makeBitnum (void)
22260 b
= newNode (decl_subrange
);
22261 b
->subrangeF
.type
= NULL
;
22262 b
->subrangeF
.scope
= NULL
;
22263 b
->subrangeF
.low
= lookupConst (b
, nameKey_makeKey ((const char *) "0", 1));
22264 b
->subrangeF
.high
= lookupConst (b
, nameKey_makeKey ((const char *) "31", 2));
22266 /* static analysis guarentees a RETURN statement will be used before here. */
22267 __builtin_unreachable ();
22275 static void makeBaseSymbols (void)
22277 baseSymbols
= symbolKey_initTree ();
22278 booleanN
= makeBase (decl_boolean
);
22279 charN
= makeBase (decl_char
);
22280 procN
= makeBase (decl_proc
);
22281 cardinalN
= makeBase (decl_cardinal
);
22282 longcardN
= makeBase (decl_longcard
);
22283 shortcardN
= makeBase (decl_shortcard
);
22284 integerN
= makeBase (decl_integer
);
22285 longintN
= makeBase (decl_longint
);
22286 shortintN
= makeBase (decl_shortint
);
22287 bitsetN
= makeBase (decl_bitset
);
22288 bitnumN
= makeBitnum ();
22289 ztypeN
= makeBase (decl_ztype
);
22290 rtypeN
= makeBase (decl_rtype
);
22291 complexN
= makeBase (decl_complex
);
22292 longcomplexN
= makeBase (decl_longcomplex
);
22293 shortcomplexN
= makeBase (decl_shortcomplex
);
22294 realN
= makeBase (decl_real
);
22295 longrealN
= makeBase (decl_longreal
);
22296 shortrealN
= makeBase (decl_shortreal
);
22297 nilN
= makeBase (decl_nil
);
22298 trueN
= makeBase (decl_true
);
22299 falseN
= makeBase (decl_false
);
22300 sizeN
= makeBase (decl_size
);
22301 minN
= makeBase (decl_min
);
22302 maxN
= makeBase (decl_max
);
22303 floatN
= makeBase (decl_float
);
22304 truncN
= makeBase (decl_trunc
);
22305 ordN
= makeBase (decl_ord
);
22306 valN
= makeBase (decl_val
);
22307 chrN
= makeBase (decl_chr
);
22308 capN
= makeBase (decl_cap
);
22309 absN
= makeBase (decl_abs
);
22310 newN
= makeBase (decl_new
);
22311 disposeN
= makeBase (decl_dispose
);
22312 lengthN
= makeBase (decl_length
);
22313 incN
= makeBase (decl_inc
);
22314 decN
= makeBase (decl_dec
);
22315 inclN
= makeBase (decl_incl
);
22316 exclN
= makeBase (decl_excl
);
22317 highN
= makeBase (decl_high
);
22318 imN
= makeBase (decl_im
);
22319 reN
= makeBase (decl_re
);
22320 cmplxN
= makeBase (decl_cmplx
);
22321 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "BOOLEAN", 7), reinterpret_cast<void *> (booleanN
));
22322 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "PROC", 4), reinterpret_cast<void *> (procN
));
22323 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "CHAR", 4), reinterpret_cast<void *> (charN
));
22324 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "CARDINAL", 8), reinterpret_cast<void *> (cardinalN
));
22325 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "SHORTCARD", 9), reinterpret_cast<void *> (shortcardN
));
22326 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "LONGCARD", 8), reinterpret_cast<void *> (longcardN
));
22327 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "INTEGER", 7), reinterpret_cast<void *> (integerN
));
22328 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "LONGINT", 7), reinterpret_cast<void *> (longintN
));
22329 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "SHORTINT", 8), reinterpret_cast<void *> (shortintN
));
22330 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "BITSET", 6), reinterpret_cast<void *> (bitsetN
));
22331 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "REAL", 4), reinterpret_cast<void *> (realN
));
22332 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "SHORTREAL", 9), reinterpret_cast<void *> (shortrealN
));
22333 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "LONGREAL", 8), reinterpret_cast<void *> (longrealN
));
22334 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "COMPLEX", 7), reinterpret_cast<void *> (complexN
));
22335 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "LONGCOMPLEX", 11), reinterpret_cast<void *> (longcomplexN
));
22336 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "SHORTCOMPLEX", 12), reinterpret_cast<void *> (shortcomplexN
));
22337 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "NIL", 3), reinterpret_cast<void *> (nilN
));
22338 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "TRUE", 4), reinterpret_cast<void *> (trueN
));
22339 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "FALSE", 5), reinterpret_cast<void *> (falseN
));
22340 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "SIZE", 4), reinterpret_cast<void *> (sizeN
));
22341 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "MIN", 3), reinterpret_cast<void *> (minN
));
22342 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "MAX", 3), reinterpret_cast<void *> (maxN
));
22343 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "FLOAT", 5), reinterpret_cast<void *> (floatN
));
22344 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "TRUNC", 5), reinterpret_cast<void *> (truncN
));
22345 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "ORD", 3), reinterpret_cast<void *> (ordN
));
22346 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "VAL", 3), reinterpret_cast<void *> (valN
));
22347 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "CHR", 3), reinterpret_cast<void *> (chrN
));
22348 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "CAP", 3), reinterpret_cast<void *> (capN
));
22349 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "ABS", 3), reinterpret_cast<void *> (absN
));
22350 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "NEW", 3), reinterpret_cast<void *> (newN
));
22351 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "DISPOSE", 7), reinterpret_cast<void *> (disposeN
));
22352 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "LENGTH", 6), reinterpret_cast<void *> (lengthN
));
22353 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "INC", 3), reinterpret_cast<void *> (incN
));
22354 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "DEC", 3), reinterpret_cast<void *> (decN
));
22355 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "INCL", 4), reinterpret_cast<void *> (inclN
));
22356 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "EXCL", 4), reinterpret_cast<void *> (exclN
));
22357 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "HIGH", 4), reinterpret_cast<void *> (highN
));
22358 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "CMPLX", 5), reinterpret_cast<void *> (cmplxN
));
22359 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "RE", 2), reinterpret_cast<void *> (reN
));
22360 symbolKey_putSymKey (baseSymbols
, nameKey_makeKey ((const char *) "IM", 2), reinterpret_cast<void *> (imN
));
22361 addDone (booleanN
);
22363 addDone (cardinalN
);
22364 addDone (longcardN
);
22365 addDone (shortcardN
);
22366 addDone (integerN
);
22367 addDone (longintN
);
22368 addDone (shortintN
);
22374 addDone (longrealN
);
22375 addDone (shortrealN
);
22376 addDone (complexN
);
22377 addDone (longcomplexN
);
22378 addDone (shortcomplexN
);
22390 static void makeBuiltins (void)
22392 bitsperunitN
= decl_makeLiteralInt (nameKey_makeKey ((const char *) "8", 1));
22393 bitsperwordN
= decl_makeLiteralInt (nameKey_makeKey ((const char *) "32", 2));
22394 bitspercharN
= decl_makeLiteralInt (nameKey_makeKey ((const char *) "8", 1));
22395 unitsperwordN
= decl_makeLiteralInt (nameKey_makeKey ((const char *) "4", 1));
22396 addDone (bitsperunitN
);
22397 addDone (bitsperwordN
);
22398 addDone (bitspercharN
);
22399 addDone (unitsperwordN
);
22407 static void init (void)
22410 outputFile
= FIO_StdOut
;
22411 doP
= mcPretty_initPretty ((mcPretty_writeProc
) {(mcPretty_writeProc_t
) write_
}, (mcPretty_writeLnProc
) {(mcPretty_writeLnProc_t
) writeln
});
22412 todoQ
= alists_initList ();
22413 partialQ
= alists_initList ();
22414 doneQ
= alists_initList ();
22415 modUniverse
= symbolKey_initTree ();
22416 defUniverse
= symbolKey_initTree ();
22417 modUniverseI
= Indexing_InitIndex (1);
22418 defUniverseI
= Indexing_InitIndex (1);
22419 scopeStack
= Indexing_InitIndex (1);
22420 makeBaseSymbols ();
22424 outputState
= decl_punct
;
22426 mustVisitScope
= false;
22431 getDeclaredMod - returns the token number associated with the nodes declaration
22432 in the implementation or program module.
22435 extern "C" unsigned int decl_getDeclaredMod (decl_node n
)
22437 return n
->at
.modDeclared
;
22438 /* static analysis guarentees a RETURN statement will be used before here. */
22439 __builtin_unreachable ();
22444 getDeclaredDef - returns the token number associated with the nodes declaration
22445 in the definition module.
22448 extern "C" unsigned int decl_getDeclaredDef (decl_node n
)
22450 return n
->at
.defDeclared
;
22451 /* static analysis guarentees a RETURN statement will be used before here. */
22452 __builtin_unreachable ();
22457 getFirstUsed - returns the token number associated with the first use of
22461 extern "C" unsigned int decl_getFirstUsed (decl_node n
)
22463 return n
->at
.firstUsed
;
22464 /* static analysis guarentees a RETURN statement will be used before here. */
22465 __builtin_unreachable ();
22470 isDef - return TRUE if node, n, is a definition module.
22473 extern "C" bool decl_isDef (decl_node n
)
22475 mcDebug_assert (n
!= NULL
);
22476 return n
->kind
== decl_def
;
22477 /* static analysis guarentees a RETURN statement will be used before here. */
22478 __builtin_unreachable ();
22483 isImp - return TRUE if node, n, is an implementation module.
22486 extern "C" bool decl_isImp (decl_node n
)
22488 mcDebug_assert (n
!= NULL
);
22489 return n
->kind
== decl_imp
;
22490 /* static analysis guarentees a RETURN statement will be used before here. */
22491 __builtin_unreachable ();
22496 isImpOrModule - returns TRUE if, n, is a program module or implementation module.
22499 extern "C" bool decl_isImpOrModule (decl_node n
)
22501 return (decl_isImp (n
)) || (decl_isModule (n
));
22502 /* static analysis guarentees a RETURN statement will be used before here. */
22503 __builtin_unreachable ();
22508 isVisited - returns TRUE if the node was visited.
22511 extern "C" bool decl_isVisited (decl_node n
)
22516 return n
->defF
.visited
;
22520 return n
->impF
.visited
;
22524 return n
->moduleF
.visited
;
22529 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
22530 __builtin_unreachable ();
22532 /* static analysis guarentees a RETURN statement will be used before here. */
22533 __builtin_unreachable ();
22538 unsetVisited - unset the visited flag on a def/imp/module node.
22541 extern "C" void decl_unsetVisited (decl_node n
)
22546 n
->defF
.visited
= false;
22550 n
->impF
.visited
= false;
22554 n
->moduleF
.visited
= false;
22559 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
22560 __builtin_unreachable ();
22566 setVisited - set the visited flag on a def/imp/module node.
22569 extern "C" void decl_setVisited (decl_node n
)
22574 n
->defF
.visited
= true;
22578 n
->impF
.visited
= true;
22582 n
->moduleF
.visited
= true;
22587 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
22588 __builtin_unreachable ();
22594 setEnumsComplete - sets the field inside the def or imp or module, n.
22597 extern "C" void decl_setEnumsComplete (decl_node n
)
22602 n
->defF
.enumsComplete
= true;
22606 n
->impF
.enumsComplete
= true;
22610 n
->moduleF
.enumsComplete
= true;
22615 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
22616 __builtin_unreachable ();
22622 getEnumsComplete - gets the field from the def or imp or module, n.
22625 extern "C" bool decl_getEnumsComplete (decl_node n
)
22630 return n
->defF
.enumsComplete
;
22634 return n
->impF
.enumsComplete
;
22638 return n
->moduleF
.enumsComplete
;
22643 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
22644 __builtin_unreachable ();
22646 /* static analysis guarentees a RETURN statement will be used before here. */
22647 __builtin_unreachable ();
22652 resetEnumPos - resets the index into the saved list of enums inside
22656 extern "C" void decl_resetEnumPos (decl_node n
)
22658 mcDebug_assert (((decl_isDef (n
)) || (decl_isImp (n
))) || (decl_isModule (n
)));
22659 if (decl_isDef (n
))
22661 n
->defF
.enumFixup
.count
= 0;
22663 else if (decl_isImp (n
))
22665 /* avoid dangling else. */
22666 n
->impF
.enumFixup
.count
= 0;
22668 else if (decl_isModule (n
))
22670 /* avoid dangling else. */
22671 n
->moduleF
.enumFixup
.count
= 0;
22677 getNextEnum - returns the next enumeration node.
22680 extern "C" decl_node
decl_getNextEnum (void)
22685 mcDebug_assert (((decl_isDef (currentModule
)) || (decl_isImp (currentModule
))) || (decl_isModule (currentModule
)));
22686 if (decl_isDef (currentModule
))
22688 n
= getNextFixup (¤tModule
->defF
.enumFixup
);
22690 else if (decl_isImp (currentModule
))
22692 /* avoid dangling else. */
22693 n
= getNextFixup (¤tModule
->impF
.enumFixup
);
22695 else if (decl_isModule (currentModule
))
22697 /* avoid dangling else. */
22698 n
= getNextFixup (¤tModule
->moduleF
.enumFixup
);
22700 mcDebug_assert (n
!= NULL
);
22701 mcDebug_assert ((decl_isEnumeration (n
)) || (decl_isEnumerationField (n
)));
22703 /* static analysis guarentees a RETURN statement will be used before here. */
22704 __builtin_unreachable ();
22709 isModule - return TRUE if node, n, is a program module.
22712 extern "C" bool decl_isModule (decl_node n
)
22714 mcDebug_assert (n
!= NULL
);
22715 return n
->kind
== decl_module
;
22716 /* static analysis guarentees a RETURN statement will be used before here. */
22717 __builtin_unreachable ();
22722 isMainModule - return TRUE if node, n, is the main module specified
22723 by the source file. This might be a definition,
22724 implementation or program module.
22727 extern "C" bool decl_isMainModule (decl_node n
)
22729 mcDebug_assert (n
!= NULL
);
22730 return n
== mainModule
;
22731 /* static analysis guarentees a RETURN statement will be used before here. */
22732 __builtin_unreachable ();
22737 setMainModule - sets node, n, as the main module to be compiled.
22740 extern "C" void decl_setMainModule (decl_node n
)
22742 mcDebug_assert (n
!= NULL
);
22748 setCurrentModule - sets node, n, as the current module being compiled.
22751 extern "C" void decl_setCurrentModule (decl_node n
)
22753 mcDebug_assert (n
!= NULL
);
22759 lookupDef - returns a definition module node named, n.
22762 extern "C" decl_node
decl_lookupDef (nameKey_Name n
)
22766 d
= static_cast<decl_node
> (symbolKey_getSymKey (defUniverse
, n
));
22770 symbolKey_putSymKey (defUniverse
, n
, reinterpret_cast<void *> (d
));
22771 Indexing_IncludeIndiceIntoIndex (defUniverseI
, reinterpret_cast<void *> (d
));
22774 /* static analysis guarentees a RETURN statement will be used before here. */
22775 __builtin_unreachable ();
22780 lookupImp - returns an implementation module node named, n.
22783 extern "C" decl_node
decl_lookupImp (nameKey_Name n
)
22787 m
= static_cast<decl_node
> (symbolKey_getSymKey (modUniverse
, n
));
22791 symbolKey_putSymKey (modUniverse
, n
, reinterpret_cast<void *> (m
));
22792 Indexing_IncludeIndiceIntoIndex (modUniverseI
, reinterpret_cast<void *> (m
));
22794 mcDebug_assert (! (decl_isModule (m
)));
22796 /* static analysis guarentees a RETURN statement will be used before here. */
22797 __builtin_unreachable ();
22802 lookupModule - returns a module node named, n.
22805 extern "C" decl_node
decl_lookupModule (nameKey_Name n
)
22809 m
= static_cast<decl_node
> (symbolKey_getSymKey (modUniverse
, n
));
22812 m
= makeModule (n
);
22813 symbolKey_putSymKey (modUniverse
, n
, reinterpret_cast<void *> (m
));
22814 Indexing_IncludeIndiceIntoIndex (modUniverseI
, reinterpret_cast<void *> (m
));
22816 mcDebug_assert (! (decl_isImp (m
)));
22818 /* static analysis guarentees a RETURN statement will be used before here. */
22819 __builtin_unreachable ();
22824 putDefForC - the definition module was defined FOR "C".
22827 extern "C" void decl_putDefForC (decl_node n
)
22829 mcDebug_assert (decl_isDef (n
));
22830 n
->defF
.forC
= true;
22835 lookupInScope - looks up a symbol named, n, from, scope.
22838 extern "C" decl_node
decl_lookupInScope (decl_node scope
, nameKey_Name n
)
22840 switch (scope
->kind
)
22843 return static_cast<decl_node
> (symbolKey_getSymKey (scope
->defF
.decls
.symbols
, n
));
22847 return static_cast<decl_node
> (symbolKey_getSymKey (scope
->moduleF
.decls
.symbols
, n
));
22851 return static_cast<decl_node
> (symbolKey_getSymKey (scope
->impF
.decls
.symbols
, n
));
22854 case decl_procedure
:
22855 return static_cast<decl_node
> (symbolKey_getSymKey (scope
->procedureF
.decls
.symbols
, n
));
22859 return static_cast<decl_node
> (symbolKey_getSymKey (scope
->recordF
.localSymbols
, n
));
22864 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
22865 __builtin_unreachable ();
22867 /* static analysis guarentees a RETURN statement will be used before here. */
22868 __builtin_unreachable ();
22873 isConst - returns TRUE if node, n, is a const.
22876 extern "C" bool decl_isConst (decl_node n
)
22878 mcDebug_assert (n
!= NULL
);
22879 return n
->kind
== decl_const
;
22880 /* static analysis guarentees a RETURN statement will be used before here. */
22881 __builtin_unreachable ();
22886 isType - returns TRUE if node, n, is a type.
22889 extern "C" bool decl_isType (decl_node n
)
22891 mcDebug_assert (n
!= NULL
);
22892 return n
->kind
== decl_type
;
22893 /* static analysis guarentees a RETURN statement will be used before here. */
22894 __builtin_unreachable ();
22899 putType - places, exp, as the type alias to des.
22903 extern "C" void decl_putType (decl_node des
, decl_node exp
)
22905 mcDebug_assert (des
!= NULL
);
22906 mcDebug_assert (decl_isType (des
));
22907 des
->typeF
.type
= exp
;
22912 getType - returns the type associated with node, n.
22915 extern "C" decl_node
decl_getType (decl_node n
)
22981 case decl_cardinal
:
22985 case decl_longcard
:
22989 case decl_shortcard
:
23001 case decl_shortint
:
23009 case decl_longreal
:
23013 case decl_shortreal
:
23033 case decl_longcomplex
:
23037 case decl_shortcomplex
:
23042 /* language features and compound type attributes. */
23043 return n
->typeF
.type
;
23055 return n
->varF
.type
;
23058 case decl_enumeration
:
23062 case decl_subrange
:
23063 return n
->subrangeF
.type
;
23067 return n
->arrayF
.type
;
23075 return n
->constF
.type
;
23079 return n
->literalF
.type
;
23082 case decl_varparam
:
23083 return n
->varparamF
.type
;
23087 return n
->paramF
.type
;
23091 return n
->optargF
.type
;
23095 return n
->pointerF
.type
;
23098 case decl_recordfield
:
23099 return n
->recordfieldF
.type
;
23102 case decl_varientfield
:
23106 case decl_enumerationfield
:
23107 return n
->enumerationfieldF
.type
;
23111 return n
->setF
.type
;
23114 case decl_proctype
:
23115 return n
->proctypeF
.returnType
;
23118 case decl_subscript
:
23119 return n
->subscriptF
.type
;
23122 case decl_procedure
:
23124 return n
->procedureF
.returnType
;
23131 case decl_unreachable
:
23144 case decl_assignment
:
23147 __builtin_unreachable ();
23160 return n
->binaryF
.resultType
;
23172 case decl_constexp
:
23178 return n
->unaryF
.resultType
;
23185 case decl_notequal
:
23188 case decl_greequal
:
23189 case decl_lessequal
:
23217 case decl_arrayref
:
23218 return n
->arrayrefF
.resultType
;
23221 case decl_componentref
:
23222 return n
->componentrefF
.resultType
;
23225 case decl_pointerref
:
23226 return n
->pointerrefF
.resultType
;
23229 case decl_funccall
:
23230 return n
->funccallF
.type
;
23233 case decl_setvalue
:
23234 return n
->setvalueF
.type
;
23239 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
23240 __builtin_unreachable ();
23243 __builtin_unreachable ();
23244 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
23245 __builtin_unreachable ();
23250 skipType - skips over type aliases.
23253 extern "C" decl_node
decl_skipType (decl_node n
)
23255 while ((n
!= NULL
) && (decl_isType (n
)))
23257 if ((decl_getType (n
)) == NULL
)
23259 /* this will occur if, n, is an opaque type. */
23262 n
= decl_getType (n
);
23265 /* static analysis guarentees a RETURN statement will be used before here. */
23266 __builtin_unreachable ();
23271 putTypeHidden - marks type, des, as being a hidden type.
23275 extern "C" void decl_putTypeHidden (decl_node des
)
23279 mcDebug_assert (des
!= NULL
);
23280 mcDebug_assert (decl_isType (des
));
23281 des
->typeF
.isHidden
= true;
23282 s
= decl_getScope (des
);
23283 mcDebug_assert (decl_isDef (s
));
23284 s
->defF
.hasHidden
= true;
23289 isTypeHidden - returns TRUE if type, n, is hidden.
23292 extern "C" bool decl_isTypeHidden (decl_node n
)
23294 mcDebug_assert (n
!= NULL
);
23295 mcDebug_assert (decl_isType (n
));
23296 return n
->typeF
.isHidden
;
23297 /* static analysis guarentees a RETURN statement will be used before here. */
23298 __builtin_unreachable ();
23303 hasHidden - returns TRUE if module, n, has a hidden type.
23306 extern "C" bool decl_hasHidden (decl_node n
)
23308 mcDebug_assert (decl_isDef (n
));
23309 return n
->defF
.hasHidden
;
23310 /* static analysis guarentees a RETURN statement will be used before here. */
23311 __builtin_unreachable ();
23316 isVar - returns TRUE if node, n, is a type.
23319 extern "C" bool decl_isVar (decl_node n
)
23321 mcDebug_assert (n
!= NULL
);
23322 return n
->kind
== decl_var
;
23323 /* static analysis guarentees a RETURN statement will be used before here. */
23324 __builtin_unreachable ();
23329 isTemporary - returns TRUE if node, n, is a variable and temporary.
23332 extern "C" bool decl_isTemporary (decl_node n
)
23335 /* static analysis guarentees a RETURN statement will be used before here. */
23336 __builtin_unreachable ();
23341 isExported - returns TRUE if symbol, n, is exported from
23342 the definition module.
23345 extern "C" bool decl_isExported (decl_node n
)
23349 s
= decl_getScope (n
);
23355 return Indexing_IsIndiceInIndex (s
->defF
.exported
, reinterpret_cast<void *> (n
));
23365 /* static analysis guarentees a RETURN statement will be used before here. */
23366 __builtin_unreachable ();
23371 getDeclScope - returns the node representing the
23372 current declaration scope.
23375 extern "C" decl_node
decl_getDeclScope (void)
23379 i
= Indexing_HighIndice (scopeStack
);
23380 return static_cast<decl_node
> (Indexing_GetIndice (scopeStack
, i
));
23381 /* static analysis guarentees a RETURN statement will be used before here. */
23382 __builtin_unreachable ();
23387 getScope - returns the scope associated with node, n.
23390 extern "C" decl_node
decl_getScope (decl_node n
)
23398 case decl_identlist
:
23399 case decl_setvalue
:
23426 case decl_cardinal
:
23427 case decl_longcard
:
23428 case decl_shortcard
:
23431 case decl_shortint
:
23433 case decl_longreal
:
23434 case decl_shortreal
:
23439 case decl_longcomplex
:
23440 case decl_shortcomplex
:
23446 /* language features and compound type attributes. */
23447 return n
->typeF
.scope
;
23451 return n
->recordF
.scope
;
23455 return n
->varientF
.scope
;
23459 return n
->varF
.scope
;
23462 case decl_enumeration
:
23463 return n
->enumerationF
.scope
;
23466 case decl_subrange
:
23467 return n
->subrangeF
.scope
;
23471 return n
->arrayF
.scope
;
23479 return n
->constF
.scope
;
23486 case decl_varparam
:
23487 return n
->varparamF
.scope
;
23491 return n
->paramF
.scope
;
23495 return n
->optargF
.scope
;
23499 return n
->pointerF
.scope
;
23502 case decl_recordfield
:
23503 return n
->recordfieldF
.scope
;
23506 case decl_varientfield
:
23507 return n
->varientfieldF
.scope
;
23510 case decl_enumerationfield
:
23511 return n
->enumerationfieldF
.scope
;
23515 return n
->setF
.scope
;
23518 case decl_proctype
:
23519 return n
->proctypeF
.scope
;
23522 case decl_subscript
:
23526 case decl_procedure
:
23528 return n
->procedureF
.scope
;
23541 case decl_assignment
:
23546 case decl_componentref
:
23547 case decl_pointerref
:
23548 case decl_arrayref
:
23581 case decl_constexp
:
23584 case decl_notequal
:
23587 case decl_greequal
:
23588 case decl_lessequal
:
23599 case decl_unreachable
:
23609 return n
->vardeclF
.scope
;
23612 case decl_funccall
:
23620 case decl_caselabellist
:
23624 case decl_caselist
:
23633 return n
->varargsF
.scope
;
23638 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
23639 __builtin_unreachable ();
23641 /* static analysis guarentees a RETURN statement will be used before here. */
23642 __builtin_unreachable ();
23647 isLiteral - returns TRUE if, n, is a literal.
23650 extern "C" bool decl_isLiteral (decl_node n
)
23652 mcDebug_assert (n
!= NULL
);
23653 return n
->kind
== decl_literal
;
23654 /* static analysis guarentees a RETURN statement will be used before here. */
23655 __builtin_unreachable ();
23660 isConstSet - returns TRUE if, n, is a constant set.
23663 extern "C" bool decl_isConstSet (decl_node n
)
23665 mcDebug_assert (n
!= NULL
);
23666 if ((decl_isLiteral (n
)) || (decl_isConst (n
)))
23668 return decl_isSet (decl_skipType (decl_getType (n
)));
23671 /* static analysis guarentees a RETURN statement will be used before here. */
23672 __builtin_unreachable ();
23677 isEnumerationField - returns TRUE if, n, is an enumeration field.
23680 extern "C" bool decl_isEnumerationField (decl_node n
)
23682 mcDebug_assert (n
!= NULL
);
23683 return n
->kind
== decl_enumerationfield
;
23684 /* static analysis guarentees a RETURN statement will be used before here. */
23685 __builtin_unreachable ();
23690 isEnumeration - returns TRUE if node, n, is an enumeration type.
23693 extern "C" bool decl_isEnumeration (decl_node n
)
23695 mcDebug_assert (n
!= NULL
);
23696 return n
->kind
== decl_enumeration
;
23697 /* static analysis guarentees a RETURN statement will be used before here. */
23698 __builtin_unreachable ();
23703 isUnbounded - returns TRUE if, n, is an unbounded array.
23706 extern "C" bool decl_isUnbounded (decl_node n
)
23708 mcDebug_assert (n
!= NULL
);
23709 return (n
->kind
== decl_array
) && n
->arrayF
.isUnbounded
;
23710 /* static analysis guarentees a RETURN statement will be used before here. */
23711 __builtin_unreachable ();
23716 isParameter - returns TRUE if, n, is a parameter.
23719 extern "C" bool decl_isParameter (decl_node n
)
23721 mcDebug_assert (n
!= NULL
);
23722 return (n
->kind
== decl_param
) || (n
->kind
== decl_varparam
);
23723 /* static analysis guarentees a RETURN statement will be used before here. */
23724 __builtin_unreachable ();
23729 isVarParam - returns TRUE if, n, is a var parameter.
23732 extern "C" bool decl_isVarParam (decl_node n
)
23734 mcDebug_assert (n
!= NULL
);
23735 return n
->kind
== decl_varparam
;
23736 /* static analysis guarentees a RETURN statement will be used before here. */
23737 __builtin_unreachable ();
23742 isParam - returns TRUE if, n, is a non var parameter.
23745 extern "C" bool decl_isParam (decl_node n
)
23747 mcDebug_assert (n
!= NULL
);
23748 return n
->kind
== decl_param
;
23749 /* static analysis guarentees a RETURN statement will be used before here. */
23750 __builtin_unreachable ();
23755 isNonVarParam - is an alias to isParam.
23758 extern "C" bool decl_isNonVarParam (decl_node n
)
23760 return decl_isParam (n
);
23761 /* static analysis guarentees a RETURN statement will be used before here. */
23762 __builtin_unreachable ();
23767 addOptParameter - returns an optarg which has been created and added to
23768 procedure node, proc. It has a name, id, and, type,
23769 and an initial value, init.
23772 extern "C" decl_node
decl_addOptParameter (decl_node proc
, nameKey_Name id
, decl_node type
, decl_node init
)
23777 mcDebug_assert (decl_isProcedure (proc
));
23778 l
= decl_makeIdentList ();
23779 mcDebug_assert (decl_putIdent (l
, id
));
23780 checkMakeVariables (proc
, l
, type
, false, true);
23781 if (! proc
->procedureF
.checking
)
23783 p
= makeOptParameter (l
, type
, init
);
23784 decl_addParameter (proc
, p
);
23787 /* static analysis guarentees a RETURN statement will be used before here. */
23788 __builtin_unreachable ();
23793 isOptarg - returns TRUE if, n, is an optarg.
23796 extern "C" bool decl_isOptarg (decl_node n
)
23798 return n
->kind
== decl_optarg
;
23799 /* static analysis guarentees a RETURN statement will be used before here. */
23800 __builtin_unreachable ();
23805 isRecord - returns TRUE if, n, is a record.
23808 extern "C" bool decl_isRecord (decl_node n
)
23810 mcDebug_assert (n
!= NULL
);
23811 return n
->kind
== decl_record
;
23812 /* static analysis guarentees a RETURN statement will be used before here. */
23813 __builtin_unreachable ();
23818 isRecordField - returns TRUE if, n, is a record field.
23821 extern "C" bool decl_isRecordField (decl_node n
)
23823 mcDebug_assert (n
!= NULL
);
23824 return n
->kind
== decl_recordfield
;
23825 /* static analysis guarentees a RETURN statement will be used before here. */
23826 __builtin_unreachable ();
23831 isVarientField - returns TRUE if, n, is a varient field.
23834 extern "C" bool decl_isVarientField (decl_node n
)
23836 mcDebug_assert (n
!= NULL
);
23837 return n
->kind
== decl_varientfield
;
23838 /* static analysis guarentees a RETURN statement will be used before here. */
23839 __builtin_unreachable ();
23844 isArray - returns TRUE if, n, is an array.
23847 extern "C" bool decl_isArray (decl_node n
)
23849 mcDebug_assert (n
!= NULL
);
23850 return n
->kind
== decl_array
;
23851 /* static analysis guarentees a RETURN statement will be used before here. */
23852 __builtin_unreachable ();
23857 isProcType - returns TRUE if, n, is a procedure type.
23860 extern "C" bool decl_isProcType (decl_node n
)
23862 mcDebug_assert (n
!= NULL
);
23863 return n
->kind
== decl_proctype
;
23864 /* static analysis guarentees a RETURN statement will be used before here. */
23865 __builtin_unreachable ();
23870 isPointer - returns TRUE if, n, is a pointer.
23873 extern "C" bool decl_isPointer (decl_node n
)
23875 mcDebug_assert (n
!= NULL
);
23876 return n
->kind
== decl_pointer
;
23877 /* static analysis guarentees a RETURN statement will be used before here. */
23878 __builtin_unreachable ();
23883 isProcedure - returns TRUE if, n, is a procedure.
23886 extern "C" bool decl_isProcedure (decl_node n
)
23888 mcDebug_assert (n
!= NULL
);
23889 return n
->kind
== decl_procedure
;
23890 /* static analysis guarentees a RETURN statement will be used before here. */
23891 __builtin_unreachable ();
23896 isVarient - returns TRUE if, n, is a varient record.
23899 extern "C" bool decl_isVarient (decl_node n
)
23901 mcDebug_assert (n
!= NULL
);
23902 return n
->kind
== decl_varient
;
23903 /* static analysis guarentees a RETURN statement will be used before here. */
23904 __builtin_unreachable ();
23909 isSet - returns TRUE if, n, is a set type.
23912 extern "C" bool decl_isSet (decl_node n
)
23914 mcDebug_assert (n
!= NULL
);
23915 return n
->kind
== decl_set
;
23916 /* static analysis guarentees a RETURN statement will be used before here. */
23917 __builtin_unreachable ();
23922 isSubrange - returns TRUE if, n, is a subrange type.
23925 extern "C" bool decl_isSubrange (decl_node n
)
23927 mcDebug_assert (n
!= NULL
);
23928 return n
->kind
== decl_subrange
;
23929 /* static analysis guarentees a RETURN statement will be used before here. */
23930 __builtin_unreachable ();
23935 isZtype - returns TRUE if, n, is the Z type.
23938 extern "C" bool decl_isZtype (decl_node n
)
23940 return n
== ztypeN
;
23941 /* static analysis guarentees a RETURN statement will be used before here. */
23942 __builtin_unreachable ();
23947 isRtype - returns TRUE if, n, is the R type.
23950 extern "C" bool decl_isRtype (decl_node n
)
23952 return n
== rtypeN
;
23953 /* static analysis guarentees a RETURN statement will be used before here. */
23954 __builtin_unreachable ();
23959 makeConst - create, initialise and return a const node.
23962 extern "C" decl_node
decl_makeConst (nameKey_Name n
)
23966 d
= newNode (decl_const
);
23967 d
->constF
.name
= n
;
23968 d
->constF
.type
= NULL
;
23969 d
->constF
.scope
= decl_getDeclScope ();
23970 d
->constF
.value
= NULL
;
23971 return addToScope (d
);
23972 /* static analysis guarentees a RETURN statement will be used before here. */
23973 __builtin_unreachable ();
23978 putConst - places value, v, into node, n.
23981 extern "C" void decl_putConst (decl_node n
, decl_node v
)
23983 mcDebug_assert (decl_isConst (n
));
23984 n
->constF
.value
= v
;
23989 makeType - create, initialise and return a type node.
23992 extern "C" decl_node
decl_makeType (nameKey_Name n
)
23996 d
= newNode (decl_type
);
23998 d
->typeF
.type
= NULL
;
23999 d
->typeF
.scope
= decl_getDeclScope ();
24000 d
->typeF
.isHidden
= false;
24001 d
->typeF
.isInternal
= false;
24002 return addToScope (d
);
24003 /* static analysis guarentees a RETURN statement will be used before here. */
24004 __builtin_unreachable ();
24009 makeTypeImp - lookup a type in the definition module
24010 and return it. Otherwise create a new type.
24013 extern "C" decl_node
decl_makeTypeImp (nameKey_Name n
)
24017 d
= decl_lookupSym (n
);
24020 d
->typeF
.isHidden
= false;
24021 return addToScope (d
);
24025 d
= newNode (decl_type
);
24027 d
->typeF
.type
= NULL
;
24028 d
->typeF
.scope
= decl_getDeclScope ();
24029 d
->typeF
.isHidden
= false;
24030 return addToScope (d
);
24032 /* static analysis guarentees a RETURN statement will be used before here. */
24033 __builtin_unreachable ();
24038 makeVar - create, initialise and return a var node.
24041 extern "C" decl_node
decl_makeVar (nameKey_Name n
)
24045 d
= newNode (decl_var
);
24047 d
->varF
.type
= NULL
;
24048 d
->varF
.decl
= NULL
;
24049 d
->varF
.scope
= decl_getDeclScope ();
24050 d
->varF
.isInitialised
= false;
24051 d
->varF
.isParameter
= false;
24052 d
->varF
.isVarParameter
= false;
24053 initCname (&d
->varF
.cname
);
24054 return addToScope (d
);
24055 /* static analysis guarentees a RETURN statement will be used before here. */
24056 __builtin_unreachable ();
24061 putVar - places, type, as the type for var.
24064 extern "C" void decl_putVar (decl_node var
, decl_node type
, decl_node decl
)
24066 mcDebug_assert (var
!= NULL
);
24067 mcDebug_assert (decl_isVar (var
));
24068 var
->varF
.type
= type
;
24069 var
->varF
.decl
= decl
;
24074 makeVarDecl - create a vardecl node and create a shadow variable in the
24078 extern "C" decl_node
decl_makeVarDecl (decl_node i
, decl_node type
)
24085 type
= checkPtr (type
);
24086 d
= newNode (decl_vardecl
);
24087 d
->vardeclF
.names
= i
->identlistF
.names
;
24088 d
->vardeclF
.type
= type
;
24089 d
->vardeclF
.scope
= decl_getDeclScope ();
24090 n
= wlists_noOfItemsInList (d
->vardeclF
.names
);
24094 v
= decl_lookupSym (wlists_getItemFromList (d
->vardeclF
.names
, j
));
24095 mcDebug_assert (decl_isVar (v
));
24096 decl_putVar (v
, type
, d
);
24100 /* static analysis guarentees a RETURN statement will be used before here. */
24101 __builtin_unreachable ();
24106 makeEnum - creates an enumerated type and returns the node.
24109 extern "C" decl_node
decl_makeEnum (void)
24111 if ((currentModule
!= NULL
) && (decl_getEnumsComplete (currentModule
)))
24113 return decl_getNextEnum ();
24117 return doMakeEnum ();
24119 /* static analysis guarentees a RETURN statement will be used before here. */
24120 __builtin_unreachable ();
24125 makeEnumField - returns an enumeration field, named, n.
24128 extern "C" decl_node
decl_makeEnumField (decl_node e
, nameKey_Name n
)
24130 if ((currentModule
!= NULL
) && (decl_getEnumsComplete (currentModule
)))
24132 return decl_getNextEnum ();
24136 return doMakeEnumField (e
, n
);
24138 /* static analysis guarentees a RETURN statement will be used before here. */
24139 __builtin_unreachable ();
24144 makeSubrange - returns a subrange node, built from range: low..high.
24147 extern "C" decl_node
decl_makeSubrange (decl_node low
, decl_node high
)
24151 n
= newNode (decl_subrange
);
24152 n
->subrangeF
.low
= low
;
24153 n
->subrangeF
.high
= high
;
24154 n
->subrangeF
.type
= NULL
;
24155 n
->subrangeF
.scope
= decl_getDeclScope ();
24157 /* static analysis guarentees a RETURN statement will be used before here. */
24158 __builtin_unreachable ();
24163 putSubrangeType - assigns, type, to the subrange type, sub.
24166 extern "C" void decl_putSubrangeType (decl_node sub
, decl_node type
)
24168 mcDebug_assert (decl_isSubrange (sub
));
24169 sub
->subrangeF
.type
= type
;
24174 makePointer - returns a pointer of, type, node.
24177 extern "C" decl_node
decl_makePointer (decl_node type
)
24181 n
= newNode (decl_pointer
);
24182 n
->pointerF
.type
= type
;
24183 n
->pointerF
.scope
= decl_getDeclScope ();
24185 /* static analysis guarentees a RETURN statement will be used before here. */
24186 __builtin_unreachable ();
24191 makeSet - returns a set of, type, node.
24194 extern "C" decl_node
decl_makeSet (decl_node type
)
24198 n
= newNode (decl_set
);
24199 n
->setF
.type
= type
;
24200 n
->setF
.scope
= decl_getDeclScope ();
24202 /* static analysis guarentees a RETURN statement will be used before here. */
24203 __builtin_unreachable ();
24208 makeArray - returns a node representing ARRAY subr OF type.
24211 extern "C" decl_node
decl_makeArray (decl_node subr
, decl_node type
)
24216 s
= decl_skipType (subr
);
24217 mcDebug_assert (((decl_isSubrange (s
)) || (isOrdinal (s
))) || (decl_isEnumeration (s
)));
24218 n
= newNode (decl_array
);
24219 n
->arrayF
.subr
= subr
;
24220 n
->arrayF
.type
= type
;
24221 n
->arrayF
.scope
= decl_getDeclScope ();
24222 n
->arrayF
.isUnbounded
= false;
24224 /* static analysis guarentees a RETURN statement will be used before here. */
24225 __builtin_unreachable ();
24230 putUnbounded - sets array, n, as unbounded.
24233 extern "C" void decl_putUnbounded (decl_node n
)
24235 mcDebug_assert (n
->kind
== decl_array
);
24236 n
->arrayF
.isUnbounded
= true;
24241 makeRecord - creates and returns a record node.
24244 extern "C" decl_node
decl_makeRecord (void)
24248 n
= newNode (decl_record
);
24249 n
->recordF
.localSymbols
= symbolKey_initTree ();
24250 n
->recordF
.listOfSons
= Indexing_InitIndex (1);
24251 n
->recordF
.scope
= decl_getDeclScope ();
24253 /* static analysis guarentees a RETURN statement will be used before here. */
24254 __builtin_unreachable ();
24259 makeVarient - creates a new symbol, a varient symbol for record or varient field
24263 extern "C" decl_node
decl_makeVarient (decl_node r
)
24267 n
= newNode (decl_varient
);
24268 n
->varientF
.listOfSons
= Indexing_InitIndex (1);
24269 /* if so use this n^.varientF.parent := r */
24270 if (decl_isRecord (r
))
24272 n
->varientF
.varient
= NULL
;
24276 n
->varientF
.varient
= r
;
24278 n
->varientF
.tag
= NULL
;
24279 n
->varientF
.scope
= decl_getDeclScope ();
24283 /* now add, n, to the record/varient, r, field list */
24284 Indexing_IncludeIndiceIntoIndex (r
->recordF
.listOfSons
, reinterpret_cast<void *> (n
));
24287 case decl_varientfield
:
24288 Indexing_IncludeIndiceIntoIndex (r
->varientfieldF
.listOfSons
, reinterpret_cast<void *> (n
));
24293 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
24294 __builtin_unreachable ();
24297 /* static analysis guarentees a RETURN statement will be used before here. */
24298 __builtin_unreachable ();
24303 addFieldsToRecord - adds fields, i, of type, t, into a record, r.
24307 extern "C" decl_node
decl_addFieldsToRecord (decl_node r
, decl_node v
, decl_node i
, decl_node t
)
24315 if (decl_isRecord (r
))
24322 p
= getRecord (getParent (r
));
24323 mcDebug_assert (decl_isVarientField (r
));
24324 mcDebug_assert (decl_isVarient (v
));
24325 putFieldVarient (r
, v
);
24327 n
= wlists_noOfItemsInList (i
->identlistF
.names
);
24331 fn
= static_cast<nameKey_Name
> (wlists_getItemFromList (i
->identlistF
.names
, j
));
24332 fj
= static_cast<decl_node
> (symbolKey_getSymKey (p
->recordF
.localSymbols
, n
));
24335 fj
= putFieldRecord (r
, fn
, t
, v
);
24339 mcMetaError_metaErrors2 ((const char *) "record field {%1ad} has already been declared inside a {%2Dd} {%2a}", 67, (const char *) "attempting to declare a duplicate record field", 46, (const unsigned char *) &fj
, (sizeof (fj
)-1), (const unsigned char *) &p
, (sizeof (p
)-1));
24344 /* static analysis guarentees a RETURN statement will be used before here. */
24345 __builtin_unreachable ();
24350 buildVarientSelector - builds a field of name, tag, of, type onto:
24351 record or varient field, r.
24355 extern "C" void decl_buildVarientSelector (decl_node r
, decl_node v
, nameKey_Name tag
, decl_node type
)
24359 mcDebug_assert ((decl_isRecord (r
)) || (decl_isVarientField (r
)));
24360 if ((decl_isRecord (r
)) || (decl_isVarientField (r
)))
24362 /* avoid gcc warning by using compound statement even if not strictly necessary. */
24363 if ((type
== NULL
) && (tag
== nameKey_NulName
))
24365 mcMetaError_metaError1 ((const char *) "expecting a tag field in the declaration of a varient record {%1Ua}", 67, (const unsigned char *) &r
, (sizeof (r
)-1));
24367 else if (type
== NULL
)
24369 /* avoid dangling else. */
24370 f
= decl_lookupSym (tag
);
24371 putVarientTag (v
, f
);
24375 /* avoid dangling else. */
24376 f
= putFieldRecord (r
, tag
, type
, v
);
24377 mcDebug_assert (decl_isRecordField (f
));
24378 f
->recordfieldF
.tag
= true;
24379 putVarientTag (v
, f
);
24386 buildVarientFieldRecord - builds a varient field into a varient symbol, v.
24387 The varient field is returned.
24390 extern "C" decl_node
decl_buildVarientFieldRecord (decl_node v
, decl_node p
)
24394 mcDebug_assert (decl_isVarient (v
));
24395 f
= makeVarientField (v
, p
);
24396 mcDebug_assert (decl_isVarientField (f
));
24397 putFieldVarient (f
, v
);
24399 /* static analysis guarentees a RETURN statement will be used before here. */
24400 __builtin_unreachable ();
24405 getSymName - returns the name of symbol, n.
24408 extern "C" nameKey_Name
decl_getSymName (decl_node n
)
24413 return nameKey_makeKey ((const char *) "NEW", 3);
24417 return nameKey_makeKey ((const char *) "DISPOSE", 7);
24421 return nameKey_makeKey ((const char *) "LENGTH", 6);
24425 return nameKey_makeKey ((const char *) "INC", 3);
24429 return nameKey_makeKey ((const char *) "DEC", 3);
24433 return nameKey_makeKey ((const char *) "INCL", 4);
24437 return nameKey_makeKey ((const char *) "EXCL", 4);
24441 return nameKey_makeKey ((const char *) "NIL", 3);
24445 return nameKey_makeKey ((const char *) "TRUE", 4);
24449 return nameKey_makeKey ((const char *) "FALSE", 5);
24453 return nameKey_makeKey ((const char *) "ADDRESS", 7);
24457 return nameKey_makeKey ((const char *) "LOC", 3);
24461 return nameKey_makeKey ((const char *) "BYTE", 4);
24465 return nameKey_makeKey ((const char *) "WORD", 4);
24469 return nameKey_makeKey ((const char *) "CSIZE_T", 7);
24473 return nameKey_makeKey ((const char *) "CSSIZE_T", 8);
24478 return nameKey_makeKey ((const char *) "BOOLEAN", 7);
24482 return nameKey_makeKey ((const char *) "PROC", 4);
24486 return nameKey_makeKey ((const char *) "CHAR", 4);
24489 case decl_cardinal
:
24490 return nameKey_makeKey ((const char *) "CARDINAL", 8);
24493 case decl_longcard
:
24494 return nameKey_makeKey ((const char *) "LONGCARD", 8);
24497 case decl_shortcard
:
24498 return nameKey_makeKey ((const char *) "SHORTCARD", 9);
24502 return nameKey_makeKey ((const char *) "INTEGER", 7);
24506 return nameKey_makeKey ((const char *) "LONGINT", 7);
24509 case decl_shortint
:
24510 return nameKey_makeKey ((const char *) "SHORTINT", 8);
24514 return nameKey_makeKey ((const char *) "REAL", 4);
24517 case decl_longreal
:
24518 return nameKey_makeKey ((const char *) "LONGREAL", 8);
24521 case decl_shortreal
:
24522 return nameKey_makeKey ((const char *) "SHORTREAL", 9);
24526 return nameKey_makeKey ((const char *) "BITSET", 6);
24530 return nameKey_makeKey ((const char *) "_ZTYPE", 6);
24534 return nameKey_makeKey ((const char *) "_RTYPE", 6);
24538 return nameKey_makeKey ((const char *) "COMPLEX", 7);
24541 case decl_longcomplex
:
24542 return nameKey_makeKey ((const char *) "LONGCOMPLEX", 11);
24545 case decl_shortcomplex
:
24546 return nameKey_makeKey ((const char *) "SHORTCOMPLEX", 12);
24550 /* language features and compound type attributes. */
24551 return n
->typeF
.name
;
24555 return nameKey_NulName
;
24559 return nameKey_NulName
;
24563 return n
->varF
.name
;
24566 case decl_enumeration
:
24567 return nameKey_NulName
;
24570 case decl_subrange
:
24571 return nameKey_NulName
;
24575 return nameKey_NulName
;
24579 return nameKey_NulName
;
24583 return n
->stringF
.name
;
24587 return n
->constF
.name
;
24591 return n
->literalF
.name
;
24594 case decl_varparam
:
24595 return nameKey_NulName
;
24599 return nameKey_NulName
;
24603 return nameKey_NulName
;
24606 case decl_recordfield
:
24607 return n
->recordfieldF
.name
;
24610 case decl_varientfield
:
24611 return n
->varientfieldF
.name
;
24614 case decl_enumerationfield
:
24615 return n
->enumerationfieldF
.name
;
24619 return nameKey_NulName
;
24622 case decl_proctype
:
24623 return nameKey_NulName
;
24626 case decl_subscript
:
24627 return nameKey_NulName
;
24630 case decl_procedure
:
24632 return n
->procedureF
.name
;
24636 return n
->defF
.name
;
24640 return n
->impF
.name
;
24644 return n
->moduleF
.name
;
24653 case decl_assignment
:
24655 return nameKey_NulName
;
24658 case decl_constexp
:
24660 case decl_arrayref
:
24661 case decl_componentref
:
24673 case decl_notequal
:
24676 case decl_greequal
:
24677 case decl_lessequal
:
24679 return nameKey_NulName
;
24683 return nameKey_makeKey ((const char *) "ADR", 3);
24687 return nameKey_makeKey ((const char *) "SIZE", 4);
24691 return nameKey_makeKey ((const char *) "TSIZE", 5);
24695 return nameKey_makeKey ((const char *) "CHR", 3);
24699 return nameKey_makeKey ((const char *) "ABS", 3);
24703 return nameKey_makeKey ((const char *) "ORD", 3);
24707 return nameKey_makeKey ((const char *) "FLOAT", 5);
24711 return nameKey_makeKey ((const char *) "TRUNC", 5);
24715 return nameKey_makeKey ((const char *) "HIGH", 4);
24719 return nameKey_makeKey ((const char *) "THROW", 5);
24722 case decl_unreachable
:
24723 return nameKey_makeKey ((const char *) "builtin_unreachable", 19);
24727 return nameKey_makeKey ((const char *) "CMPLX", 5);
24731 return nameKey_makeKey ((const char *) "RE", 2);
24735 return nameKey_makeKey ((const char *) "IM", 2);
24739 return nameKey_makeKey ((const char *) "MAX", 3);
24743 return nameKey_makeKey ((const char *) "MIN", 3);
24746 case decl_funccall
:
24747 return nameKey_NulName
;
24750 case decl_identlist
:
24751 return nameKey_NulName
;
24757 __builtin_unreachable ();
24760 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
24761 __builtin_unreachable ();
24766 import - attempts to add node, n, into the scope of module, m.
24767 It might fail due to a name clash in which case the
24768 previous named symbol is returned. On success, n,
24772 extern "C" decl_node
decl_import (decl_node m
, decl_node n
)
24777 mcDebug_assert (((decl_isDef (m
)) || (decl_isModule (m
))) || (decl_isImp (m
)));
24778 name
= decl_getSymName (n
);
24779 r
= decl_lookupInScope (m
, name
);
24785 symbolKey_putSymKey (m
->defF
.decls
.symbols
, name
, reinterpret_cast<void *> (n
));
24789 symbolKey_putSymKey (m
->impF
.decls
.symbols
, name
, reinterpret_cast<void *> (n
));
24793 symbolKey_putSymKey (m
->moduleF
.decls
.symbols
, name
, reinterpret_cast<void *> (n
));
24798 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
24799 __builtin_unreachable ();
24801 importEnumFields (m
, n
);
24805 /* static analysis guarentees a RETURN statement will be used before here. */
24806 __builtin_unreachable ();
24811 lookupExported - attempts to lookup a node named, i, from definition
24812 module, n. The node is returned if found.
24813 NIL is returned if not found.
24816 extern "C" decl_node
decl_lookupExported (decl_node n
, nameKey_Name i
)
24820 mcDebug_assert (decl_isDef (n
));
24821 r
= static_cast<decl_node
> (symbolKey_getSymKey (n
->defF
.decls
.symbols
, i
));
24822 if ((r
!= NULL
) && (decl_isExported (r
)))
24827 /* static analysis guarentees a RETURN statement will be used before here. */
24828 __builtin_unreachable ();
24833 lookupSym - returns the symbol named, n, from the scope stack.
24836 extern "C" decl_node
decl_lookupSym (nameKey_Name n
)
24843 l
= Indexing_LowIndice (scopeStack
);
24844 h
= Indexing_HighIndice (scopeStack
);
24847 s
= static_cast<decl_node
> (Indexing_GetIndice (scopeStack
, h
));
24848 m
= decl_lookupInScope (s
, n
);
24849 if (debugScopes
&& (m
== NULL
))
24851 out3 ((const char *) " [%d] search for symbol name %s in scope %s\\n", 45, h
, n
, s
);
24857 out3 ((const char *) " [%d] search for symbol name %s in scope %s (found)\\n", 53, h
, n
, s
);
24863 return lookupBase (n
);
24864 /* static analysis guarentees a RETURN statement will be used before here. */
24865 __builtin_unreachable ();
24870 addImportedModule - add module, i, to be imported by, m.
24871 If scoped then module, i, is added to the
24875 extern "C" void decl_addImportedModule (decl_node m
, decl_node i
, bool scoped
)
24877 mcDebug_assert ((decl_isDef (i
)) || (decl_isModule (i
)));
24878 if (decl_isDef (m
))
24880 Indexing_IncludeIndiceIntoIndex (m
->defF
.importedModules
, reinterpret_cast<void *> (i
));
24882 else if (decl_isImp (m
))
24884 /* avoid dangling else. */
24885 Indexing_IncludeIndiceIntoIndex (m
->impF
.importedModules
, reinterpret_cast<void *> (i
));
24887 else if (decl_isModule (m
))
24889 /* avoid dangling else. */
24890 Indexing_IncludeIndiceIntoIndex (m
->moduleF
.importedModules
, reinterpret_cast<void *> (i
));
24894 /* avoid dangling else. */
24896 __builtin_unreachable ();
24900 addModuleToScope (m
, i
);
24906 setSource - sets the source filename for module, n, to s.
24909 extern "C" void decl_setSource (decl_node n
, nameKey_Name s
)
24914 n
->defF
.source
= s
;
24918 n
->moduleF
.source
= s
;
24922 n
->impF
.source
= s
;
24927 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
24928 __builtin_unreachable ();
24934 getSource - returns the source filename for module, n.
24937 extern "C" nameKey_Name
decl_getSource (decl_node n
)
24942 return n
->defF
.source
;
24946 return n
->moduleF
.source
;
24950 return n
->impF
.source
;
24955 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
24956 __builtin_unreachable ();
24958 /* static analysis guarentees a RETURN statement will be used before here. */
24959 __builtin_unreachable ();
24964 getMainModule - returns the main module node.
24967 extern "C" decl_node
decl_getMainModule (void)
24970 /* static analysis guarentees a RETURN statement will be used before here. */
24971 __builtin_unreachable ();
24976 getCurrentModule - returns the current module being compiled.
24979 extern "C" decl_node
decl_getCurrentModule (void)
24981 return currentModule
;
24982 /* static analysis guarentees a RETURN statement will be used before here. */
24983 __builtin_unreachable ();
24988 foreachDefModuleDo - foreach definition node, n, in the module universe,
24992 extern "C" void decl_foreachDefModuleDo (symbolKey_performOperation p
)
24994 Indexing_ForeachIndiceInIndexDo (defUniverseI
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) p
.proc
});
24999 foreachModModuleDo - foreach implementation or module node, n, in the module universe,
25003 extern "C" void decl_foreachModModuleDo (symbolKey_performOperation p
)
25005 Indexing_ForeachIndiceInIndexDo (modUniverseI
, (Indexing_IndexProcedure
) {(Indexing_IndexProcedure_t
) p
.proc
});
25010 enterScope - pushes symbol, n, to the scope stack.
25013 extern "C" void decl_enterScope (decl_node n
)
25015 if (Indexing_IsIndiceInIndex (scopeStack
, reinterpret_cast<void *> (n
)))
25018 __builtin_unreachable ();
25022 Indexing_IncludeIndiceIntoIndex (scopeStack
, reinterpret_cast<void *> (n
));
25026 libc_printf ((const char *) "enter scope\\n", 13);
25033 leaveScope - removes the top level scope.
25036 extern "C" void decl_leaveScope (void)
25041 i
= Indexing_HighIndice (scopeStack
);
25042 n
= static_cast<decl_node
> (Indexing_GetIndice (scopeStack
, i
));
25043 Indexing_RemoveIndiceFromIndex (scopeStack
, reinterpret_cast<void *> (n
));
25046 libc_printf ((const char *) "leave scope\\n", 13);
25053 makeProcedure - create, initialise and return a procedure node.
25056 extern "C" decl_node
decl_makeProcedure (nameKey_Name n
)
25060 d
= decl_lookupSym (n
);
25063 d
= newNode (decl_procedure
);
25064 d
->procedureF
.name
= n
;
25065 initDecls (&d
->procedureF
.decls
);
25066 d
->procedureF
.scope
= decl_getDeclScope ();
25067 d
->procedureF
.parameters
= Indexing_InitIndex (1);
25068 d
->procedureF
.isForC
= isDefForCNode (decl_getDeclScope ());
25069 d
->procedureF
.built
= false;
25070 d
->procedureF
.returnopt
= false;
25071 d
->procedureF
.optarg_
= NULL
;
25072 d
->procedureF
.noreturnused
= false;
25073 d
->procedureF
.noreturn
= false;
25074 d
->procedureF
.vararg
= false;
25075 d
->procedureF
.checking
= false;
25076 d
->procedureF
.paramcount
= 0;
25077 d
->procedureF
.returnType
= NULL
;
25078 d
->procedureF
.beginStatements
= NULL
;
25079 initCname (&d
->procedureF
.cname
);
25080 d
->procedureF
.defComment
= NULL
;
25081 d
->procedureF
.modComment
= NULL
;
25083 return addProcedureToScope (d
, n
);
25084 /* static analysis guarentees a RETURN statement will be used before here. */
25085 __builtin_unreachable ();
25090 putCommentDefProcedure - remembers the procedure comment (if it exists) as a
25091 definition module procedure heading. NIL is placed
25092 if there is no procedure comment available.
25095 extern "C" void decl_putCommentDefProcedure (decl_node n
)
25097 mcDebug_assert (decl_isProcedure (n
));
25098 if (mcComment_isProcedureComment (mcLexBuf_lastcomment
))
25100 n
->procedureF
.defComment
= mcLexBuf_lastcomment
;
25106 putCommentModProcedure - remembers the procedure comment (if it exists) as an
25107 implementation/program module procedure heading. NIL is placed
25108 if there is no procedure comment available.
25111 extern "C" void decl_putCommentModProcedure (decl_node n
)
25113 mcDebug_assert (decl_isProcedure (n
));
25114 if (mcComment_isProcedureComment (mcLexBuf_lastcomment
))
25116 n
->procedureF
.modComment
= mcLexBuf_lastcomment
;
25122 makeProcType - returns a proctype node.
25125 extern "C" decl_node
decl_makeProcType (void)
25129 d
= newNode (decl_proctype
);
25130 d
->proctypeF
.scope
= decl_getDeclScope ();
25131 d
->proctypeF
.parameters
= Indexing_InitIndex (1);
25132 d
->proctypeF
.returnopt
= false;
25133 d
->proctypeF
.optarg_
= NULL
;
25134 d
->proctypeF
.vararg
= false;
25135 d
->proctypeF
.returnType
= NULL
;
25137 /* static analysis guarentees a RETURN statement will be used before here. */
25138 __builtin_unreachable ();
25143 putReturnType - sets the return type of procedure or proctype, proc, to, type.
25146 extern "C" void decl_putReturnType (decl_node proc
, decl_node type
)
25148 mcDebug_assert ((decl_isProcedure (proc
)) || (decl_isProcType (proc
)));
25149 if (decl_isProcedure (proc
))
25151 proc
->procedureF
.returnType
= type
;
25155 proc
->proctypeF
.returnType
= type
;
25161 putOptReturn - sets, proctype or procedure, proc, to have an optional return type.
25164 extern "C" void decl_putOptReturn (decl_node proc
)
25166 mcDebug_assert ((decl_isProcedure (proc
)) || (decl_isProcType (proc
)));
25167 if (decl_isProcedure (proc
))
25169 proc
->procedureF
.returnopt
= true;
25173 proc
->proctypeF
.returnopt
= true;
25179 makeVarParameter - returns a var parameter node with, name: type.
25182 extern "C" decl_node
decl_makeVarParameter (decl_node l
, decl_node type
, decl_node proc
, bool isused
)
25186 mcDebug_assert ((l
== NULL
) || (isIdentList (l
)));
25187 d
= newNode (decl_varparam
);
25188 d
->varparamF
.namelist
= l
;
25189 d
->varparamF
.type
= type
;
25190 d
->varparamF
.scope
= proc
;
25191 d
->varparamF
.isUnbounded
= false;
25192 d
->varparamF
.isForC
= isDefForCNode (proc
);
25193 d
->varparamF
.isUsed
= isused
;
25195 /* static analysis guarentees a RETURN statement will be used before here. */
25196 __builtin_unreachable ();
25201 makeNonVarParameter - returns a non var parameter node with, name: type.
25204 extern "C" decl_node
decl_makeNonVarParameter (decl_node l
, decl_node type
, decl_node proc
, bool isused
)
25208 mcDebug_assert ((l
== NULL
) || (isIdentList (l
)));
25209 d
= newNode (decl_param
);
25210 d
->paramF
.namelist
= l
;
25211 d
->paramF
.type
= type
;
25212 d
->paramF
.scope
= proc
;
25213 d
->paramF
.isUnbounded
= false;
25214 d
->paramF
.isForC
= isDefForCNode (proc
);
25215 d
->paramF
.isUsed
= isused
;
25217 /* static analysis guarentees a RETURN statement will be used before here. */
25218 __builtin_unreachable ();
25223 paramEnter - reset the parameter count.
25226 extern "C" void decl_paramEnter (decl_node n
)
25228 mcDebug_assert (decl_isProcedure (n
));
25229 n
->procedureF
.paramcount
= 0;
25234 paramLeave - set paramater checking to TRUE from now onwards.
25237 extern "C" void decl_paramLeave (decl_node n
)
25239 mcDebug_assert (decl_isProcedure (n
));
25240 n
->procedureF
.checking
= true;
25241 if ((decl_isImp (currentModule
)) || (decl_isModule (currentModule
)))
25243 n
->procedureF
.built
= true;
25249 makeIdentList - returns a node which will be used to maintain an ident list.
25252 extern "C" decl_node
decl_makeIdentList (void)
25256 n
= newNode (decl_identlist
);
25257 n
->identlistF
.names
= wlists_initList ();
25258 n
->identlistF
.cnamed
= false;
25260 /* static analysis guarentees a RETURN statement will be used before here. */
25261 __builtin_unreachable ();
25266 putIdent - places ident, i, into identlist, n. It returns TRUE if
25267 ident, i, is unique.
25270 extern "C" bool decl_putIdent (decl_node n
, nameKey_Name i
)
25272 mcDebug_assert (isIdentList (n
));
25273 if (wlists_isItemInList (n
->identlistF
.names
, i
))
25279 wlists_putItemIntoList (n
->identlistF
.names
, i
);
25282 /* static analysis guarentees a RETURN statement will be used before here. */
25283 __builtin_unreachable ();
25288 addVarParameters - adds the identlist, i, of, type, to be VAR parameters
25292 extern "C" void decl_addVarParameters (decl_node n
, decl_node i
, decl_node type
, bool isused
)
25296 mcDebug_assert (isIdentList (i
));
25297 mcDebug_assert (decl_isProcedure (n
));
25298 checkMakeVariables (n
, i
, type
, true, isused
);
25299 if (n
->procedureF
.checking
)
25301 checkParameters (n
, i
, type
, true, isused
); /* will destroy, i. */
25305 p
= decl_makeVarParameter (i
, type
, n
, isused
);
25306 Indexing_IncludeIndiceIntoIndex (n
->procedureF
.parameters
, reinterpret_cast<void *> (p
));
25312 addNonVarParameters - adds the identlist, i, of, type, to be parameters
25316 extern "C" void decl_addNonVarParameters (decl_node n
, decl_node i
, decl_node type
, bool isused
)
25320 mcDebug_assert (isIdentList (i
));
25321 mcDebug_assert (decl_isProcedure (n
));
25322 checkMakeVariables (n
, i
, type
, false, isused
);
25323 if (n
->procedureF
.checking
)
25325 checkParameters (n
, i
, type
, false, isused
); /* will destroy, i. */
25329 p
= decl_makeNonVarParameter (i
, type
, n
, isused
);
25330 Indexing_IncludeIndiceIntoIndex (n
->procedureF
.parameters
, reinterpret_cast<void *> (p
));
25336 makeVarargs - returns a varargs node.
25339 extern "C" decl_node
decl_makeVarargs (void)
25343 d
= newNode (decl_varargs
);
25344 d
->varargsF
.scope
= NULL
;
25346 /* static analysis guarentees a RETURN statement will be used before here. */
25347 __builtin_unreachable ();
25352 isVarargs - returns TRUE if, n, is a varargs node.
25355 extern "C" bool decl_isVarargs (decl_node n
)
25357 return n
->kind
== decl_varargs
;
25358 /* static analysis guarentees a RETURN statement will be used before here. */
25359 __builtin_unreachable ();
25364 addParameter - adds a parameter, param, to procedure or proctype, proc.
25367 extern "C" void decl_addParameter (decl_node proc
, decl_node param
)
25369 mcDebug_assert ((((decl_isVarargs (param
)) || (decl_isParam (param
))) || (decl_isVarParam (param
))) || (decl_isOptarg (param
)));
25370 switch (proc
->kind
)
25372 case decl_procedure
:
25373 Indexing_IncludeIndiceIntoIndex (proc
->procedureF
.parameters
, reinterpret_cast<void *> (param
));
25374 if (decl_isVarargs (param
))
25376 proc
->procedureF
.vararg
= true;
25378 if (decl_isOptarg (param
))
25380 proc
->procedureF
.optarg_
= param
;
25384 case decl_proctype
:
25385 Indexing_IncludeIndiceIntoIndex (proc
->proctypeF
.parameters
, reinterpret_cast<void *> (param
));
25386 if (decl_isVarargs (param
))
25388 proc
->proctypeF
.vararg
= true;
25390 if (decl_isOptarg (param
))
25392 proc
->proctypeF
.optarg_
= param
;
25398 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
25399 __builtin_unreachable ();
25405 makeBinaryTok - creates and returns a boolean type node with,
25409 extern "C" decl_node
decl_makeBinaryTok (mcReserved_toktype op
, decl_node l
, decl_node r
)
25411 if (op
== mcReserved_equaltok
)
25413 return makeBinary (decl_equal
, l
, r
, booleanN
);
25415 else if ((op
== mcReserved_hashtok
) || (op
== mcReserved_lessgreatertok
))
25417 /* avoid dangling else. */
25418 return makeBinary (decl_notequal
, l
, r
, booleanN
);
25420 else if (op
== mcReserved_lesstok
)
25422 /* avoid dangling else. */
25423 return makeBinary (decl_less
, l
, r
, booleanN
);
25425 else if (op
== mcReserved_greatertok
)
25427 /* avoid dangling else. */
25428 return makeBinary (decl_greater
, l
, r
, booleanN
);
25430 else if (op
== mcReserved_greaterequaltok
)
25432 /* avoid dangling else. */
25433 return makeBinary (decl_greequal
, l
, r
, booleanN
);
25435 else if (op
== mcReserved_lessequaltok
)
25437 /* avoid dangling else. */
25438 return makeBinary (decl_lessequal
, l
, r
, booleanN
);
25440 else if (op
== mcReserved_andtok
)
25442 /* avoid dangling else. */
25443 return makeBinary (decl_and
, l
, r
, booleanN
);
25445 else if (op
== mcReserved_ortok
)
25447 /* avoid dangling else. */
25448 return makeBinary (decl_or
, l
, r
, booleanN
);
25450 else if (op
== mcReserved_plustok
)
25452 /* avoid dangling else. */
25453 return makeBinary (decl_plus
, l
, r
, NULL
);
25455 else if (op
== mcReserved_minustok
)
25457 /* avoid dangling else. */
25458 return makeBinary (decl_sub
, l
, r
, NULL
);
25460 else if (op
== mcReserved_divtok
)
25462 /* avoid dangling else. */
25463 return makeBinary (decl_div
, l
, r
, NULL
);
25465 else if (op
== mcReserved_timestok
)
25467 /* avoid dangling else. */
25468 return makeBinary (decl_mult
, l
, r
, NULL
);
25470 else if (op
== mcReserved_modtok
)
25472 /* avoid dangling else. */
25473 return makeBinary (decl_mod
, l
, r
, NULL
);
25475 else if (op
== mcReserved_intok
)
25477 /* avoid dangling else. */
25478 return makeBinary (decl_in
, l
, r
, NULL
);
25480 else if (op
== mcReserved_dividetok
)
25482 /* avoid dangling else. */
25483 return makeBinary (decl_divide
, l
, r
, NULL
);
25487 /* avoid dangling else. */
25488 M2RTS_HALT (-1); /* most likely op needs a clause as above. */
25489 __builtin_unreachable ();
25491 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
25492 __builtin_unreachable ();
25497 makeUnaryTok - creates and returns a boolean type node with,
25501 extern "C" decl_node
decl_makeUnaryTok (mcReserved_toktype op
, decl_node e
)
25503 if (op
== mcReserved_nottok
)
25505 return makeUnary (decl_not
, e
, booleanN
);
25507 else if (op
== mcReserved_plustok
)
25509 /* avoid dangling else. */
25510 return makeUnary (decl_plus
, e
, NULL
);
25512 else if (op
== mcReserved_minustok
)
25514 /* avoid dangling else. */
25515 return makeUnary (decl_neg
, e
, NULL
);
25519 /* avoid dangling else. */
25520 M2RTS_HALT (-1); /* most likely op needs a clause as above. */
25521 __builtin_unreachable ();
25523 ReturnException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
25524 __builtin_unreachable ();
25529 makeComponentRef - build a componentref node which accesses, field,
25530 within, record, rec.
25533 extern "C" decl_node
decl_makeComponentRef (decl_node rec
, decl_node field
)
25539 n := getLastOp (rec) ;
25540 IF (n#NIL) AND (isDeref (n) OR isPointerRef (n)) AND
25541 (skipType (getType (rec)) = skipType (getType (n)))
25543 a := n^.unaryF.arg ;
25544 n^.kind := pointerref ;
25545 n^.pointerrefF.ptr := a ;
25546 n^.pointerrefF.field := field ;
25547 n^.pointerrefF.resultType := getType (field) ;
25550 RETURN doMakeComponentRef (rec, field)
25555 a
= rec
->unaryF
.arg
;
25556 rec
->kind
= decl_pointerref
;
25557 rec
->pointerrefF
.ptr
= a
;
25558 rec
->pointerrefF
.field
= field
;
25559 rec
->pointerrefF
.resultType
= decl_getType (field
);
25564 return doMakeComponentRef (rec
, field
);
25566 /* static analysis guarentees a RETURN statement will be used before here. */
25567 __builtin_unreachable ();
25572 makePointerRef - build a pointerref node which accesses, field,
25573 within, pointer to record, ptr.
25576 extern "C" decl_node
decl_makePointerRef (decl_node ptr
, decl_node field
)
25580 n
= newNode (decl_pointerref
);
25581 n
->pointerrefF
.ptr
= ptr
;
25582 n
->pointerrefF
.field
= field
;
25583 n
->pointerrefF
.resultType
= decl_getType (field
);
25585 /* static analysis guarentees a RETURN statement will be used before here. */
25586 __builtin_unreachable ();
25591 isPointerRef - returns TRUE if, n, is a pointerref node.
25594 extern "C" bool decl_isPointerRef (decl_node n
)
25596 mcDebug_assert (n
!= NULL
);
25597 return n
->kind
== decl_pointerref
;
25598 /* static analysis guarentees a RETURN statement will be used before here. */
25599 __builtin_unreachable ();
25604 makeDeRef - dereferences the pointer defined by, n.
25607 extern "C" decl_node
decl_makeDeRef (decl_node n
)
25611 t
= decl_skipType (decl_getType (n
));
25612 mcDebug_assert (decl_isPointer (t
));
25613 return makeUnary (decl_deref
, n
, decl_getType (t
));
25614 /* static analysis guarentees a RETURN statement will be used before here. */
25615 __builtin_unreachable ();
25620 makeArrayRef - build an arrayref node which access element,
25621 index, in, array. array is a variable/expression/constant
25622 which has a type array.
25625 extern "C" decl_node
decl_makeArrayRef (decl_node array
, decl_node index
)
25632 n
= newNode (decl_arrayref
);
25633 n
->arrayrefF
.array
= array
;
25634 n
->arrayrefF
.index
= index
;
25636 j
= expListLen (index
);
25638 t
= decl_skipType (decl_getType (t
));
25640 if (decl_isArray (t
))
25642 t
= decl_skipType (decl_getType (t
));
25646 mcMetaError_metaError2 ((const char *) "cannot access {%1N} dimension of array {%2a}", 44, (const unsigned char *) &i
, (sizeof (i
)-1), (const unsigned char *) &t
, (sizeof (t
)-1));
25649 } while (! (i
> j
));
25650 n
->arrayrefF
.resultType
= t
;
25652 /* static analysis guarentees a RETURN statement will be used before here. */
25653 __builtin_unreachable ();
25658 getLastOp - return the right most non leaf node.
25661 extern "C" decl_node
decl_getLastOp (decl_node n
)
25663 return doGetLastOp (n
, n
);
25664 /* static analysis guarentees a RETURN statement will be used before here. */
25665 __builtin_unreachable ();
25670 getCardinal - returns the cardinal type node.
25673 extern "C" decl_node
decl_getCardinal (void)
25676 /* static analysis guarentees a RETURN statement will be used before here. */
25677 __builtin_unreachable ();
25682 makeLiteralInt - creates and returns a literal node based on an integer type.
25685 extern "C" decl_node
decl_makeLiteralInt (nameKey_Name n
)
25688 DynamicStrings_String s
;
25690 m
= newNode (decl_literal
);
25691 s
= DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
));
25692 m
->literalF
.name
= n
;
25693 if ((DynamicStrings_char (s
, -1)) == 'C')
25695 m
->literalF
.type
= charN
;
25699 m
->literalF
.type
= ztypeN
;
25701 s
= DynamicStrings_KillString (s
);
25703 /* static analysis guarentees a RETURN statement will be used before here. */
25704 __builtin_unreachable ();
25709 makeLiteralReal - creates and returns a literal node based on a real type.
25712 extern "C" decl_node
decl_makeLiteralReal (nameKey_Name n
)
25716 m
= newNode (decl_literal
);
25717 m
->literalF
.name
= n
;
25718 m
->literalF
.type
= rtypeN
;
25720 /* static analysis guarentees a RETURN statement will be used before here. */
25721 __builtin_unreachable ();
25726 makeString - creates and returns a node containing string, n.
25729 extern "C" decl_node
decl_makeString (nameKey_Name n
)
25733 m
= newNode (decl_string
);
25734 m
->stringF
.name
= n
;
25735 m
->stringF
.length
= nameKey_lengthKey (n
);
25736 m
->stringF
.isCharCompatible
= m
->stringF
.length
<= 3;
25737 m
->stringF
.cstring
= toCstring (n
);
25738 m
->stringF
.clength
= lenCstring (m
->stringF
.cstring
);
25739 if (m
->stringF
.isCharCompatible
)
25741 m
->stringF
.cchar
= toCchar (n
);
25745 m
->stringF
.cchar
= NULL
;
25748 /* static analysis guarentees a RETURN statement will be used before here. */
25749 __builtin_unreachable ();
25754 makeSetValue - creates and returns a setvalue node.
25757 extern "C" decl_node
decl_makeSetValue (void)
25761 n
= newNode (decl_setvalue
);
25762 n
->setvalueF
.type
= bitsetN
;
25763 n
->setvalueF
.values
= Indexing_InitIndex (1);
25765 /* static analysis guarentees a RETURN statement will be used before here. */
25766 __builtin_unreachable ();
25771 isSetValue - returns TRUE if, n, is a setvalue node.
25774 extern "C" bool decl_isSetValue (decl_node n
)
25776 mcDebug_assert (n
!= NULL
);
25777 return n
->kind
== decl_setvalue
;
25778 /* static analysis guarentees a RETURN statement will be used before here. */
25779 __builtin_unreachable ();
25784 putSetValue - assigns the type, t, to the set value, n. The
25785 node, n, is returned.
25788 extern "C" decl_node
decl_putSetValue (decl_node n
, decl_node t
)
25790 mcDebug_assert (decl_isSetValue (n
));
25791 n
->setvalueF
.type
= t
;
25793 /* static analysis guarentees a RETURN statement will be used before here. */
25794 __builtin_unreachable ();
25799 includeSetValue - includes the range l..h into the setvalue.
25800 h might be NIL indicating that a single element
25801 is to be included into the set.
25805 extern "C" decl_node
decl_includeSetValue (decl_node n
, decl_node l
, decl_node h
)
25807 mcDebug_assert (decl_isSetValue (n
));
25808 Indexing_IncludeIndiceIntoIndex (n
->setvalueF
.values
, reinterpret_cast<void *> (l
));
25810 /* static analysis guarentees a RETURN statement will be used before here. */
25811 __builtin_unreachable ();
25816 getBuiltinConst - creates and returns a builtin const if available.
25819 extern "C" decl_node
decl_getBuiltinConst (nameKey_Name n
)
25821 if (n
== (nameKey_makeKey ((const char *) "BITS_PER_UNIT", 13)))
25823 return bitsperunitN
;
25825 else if (n
== (nameKey_makeKey ((const char *) "BITS_PER_WORD", 13)))
25827 /* avoid dangling else. */
25828 return bitsperwordN
;
25830 else if (n
== (nameKey_makeKey ((const char *) "BITS_PER_CHAR", 13)))
25832 /* avoid dangling else. */
25833 return bitspercharN
;
25835 else if (n
== (nameKey_makeKey ((const char *) "UNITS_PER_WORD", 14)))
25837 /* avoid dangling else. */
25838 return unitsperwordN
;
25842 /* avoid dangling else. */
25845 /* static analysis guarentees a RETURN statement will be used before here. */
25846 __builtin_unreachable ();
25851 makeExpList - creates and returns an expList node.
25854 extern "C" decl_node
decl_makeExpList (void)
25858 n
= newNode (decl_explist
);
25859 n
->explistF
.exp
= Indexing_InitIndex (1);
25861 /* static analysis guarentees a RETURN statement will be used before here. */
25862 __builtin_unreachable ();
25867 isExpList - returns TRUE if, n, is an explist node.
25870 extern "C" bool decl_isExpList (decl_node n
)
25872 mcDebug_assert (n
!= NULL
);
25873 return n
->kind
== decl_explist
;
25874 /* static analysis guarentees a RETURN statement will be used before here. */
25875 __builtin_unreachable ();
25880 putExpList - places, expression, e, within the explist, n.
25883 extern "C" void decl_putExpList (decl_node n
, decl_node e
)
25885 mcDebug_assert (n
!= NULL
);
25886 mcDebug_assert (decl_isExpList (n
));
25887 Indexing_PutIndice (n
->explistF
.exp
, (Indexing_HighIndice (n
->explistF
.exp
))+1, reinterpret_cast<void *> (e
));
25892 makeConstExp - returns a constexp node.
25895 extern "C" decl_node
decl_makeConstExp (void)
25897 if ((currentModule
!= NULL
) && (getConstExpComplete (currentModule
)))
25899 return decl_getNextConstExp ();
25903 return doMakeConstExp ();
25905 /* static analysis guarentees a RETURN statement will be used before here. */
25906 __builtin_unreachable ();
25911 getNextConstExp - returns the next constexp node.
25914 extern "C" decl_node
decl_getNextConstExp (void)
25918 mcDebug_assert (((decl_isDef (currentModule
)) || (decl_isImp (currentModule
))) || (decl_isModule (currentModule
)));
25919 if (decl_isDef (currentModule
))
25921 return getNextFixup (¤tModule
->defF
.constFixup
);
25923 else if (decl_isImp (currentModule
))
25925 /* avoid dangling else. */
25926 return getNextFixup (¤tModule
->impF
.constFixup
);
25928 else if (decl_isModule (currentModule
))
25930 /* avoid dangling else. */
25931 return getNextFixup (¤tModule
->moduleF
.constFixup
);
25934 /* static analysis guarentees a RETURN statement will be used before here. */
25935 __builtin_unreachable ();
25940 setConstExpComplete - sets the field inside the def or imp or module, n.
25943 extern "C" void decl_setConstExpComplete (decl_node n
)
25948 n
->defF
.constsComplete
= true;
25952 n
->impF
.constsComplete
= true;
25956 n
->moduleF
.constsComplete
= true;
25961 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
25962 __builtin_unreachable ();
25968 fixupConstExp - assign fixup expression, e, into the argument of, c.
25971 extern "C" decl_node
decl_fixupConstExp (decl_node c
, decl_node e
)
25973 mcDebug_assert (isConstExp (c
));
25976 /* static analysis guarentees a RETURN statement will be used before here. */
25977 __builtin_unreachable ();
25982 resetConstExpPos - resets the index into the saved list of constexps inside
25986 extern "C" void decl_resetConstExpPos (decl_node n
)
25988 mcDebug_assert (((decl_isDef (n
)) || (decl_isImp (n
))) || (decl_isModule (n
)));
25989 if (decl_isDef (n
))
25991 n
->defF
.constFixup
.count
= 0;
25993 else if (decl_isImp (n
))
25995 /* avoid dangling else. */
25996 n
->impF
.constFixup
.count
= 0;
25998 else if (decl_isModule (n
))
26000 /* avoid dangling else. */
26001 n
->moduleF
.constFixup
.count
= 0;
26007 makeFuncCall - builds a function call to c with param list, n.
26010 extern "C" decl_node
decl_makeFuncCall (decl_node c
, decl_node n
)
26014 mcDebug_assert ((n
== NULL
) || (decl_isExpList (n
)));
26015 if (((c
== haltN
) && ((decl_getMainModule ()) != (decl_lookupDef (nameKey_makeKey ((const char *) "M2RTS", 5))))) && ((decl_getMainModule ()) != (decl_lookupImp (nameKey_makeKey ((const char *) "M2RTS", 5)))))
26017 decl_addImportedModule (decl_getMainModule (), decl_lookupDef (nameKey_makeKey ((const char *) "M2RTS", 5)), false);
26019 f
= checkIntrinsic (c
, n
);
26023 f
= newNode (decl_funccall
);
26024 f
->funccallF
.function
= c
;
26025 f
->funccallF
.args
= n
;
26026 f
->funccallF
.type
= NULL
;
26027 initPair (&f
->funccallF
.funccallComment
);
26030 /* static analysis guarentees a RETURN statement will be used before here. */
26031 __builtin_unreachable ();
26036 makeStatementSequence - create and return a statement sequence node.
26039 extern "C" decl_node
decl_makeStatementSequence (void)
26043 n
= newNode (decl_stmtseq
);
26044 n
->stmtF
.statements
= Indexing_InitIndex (1);
26046 /* static analysis guarentees a RETURN statement will be used before here. */
26047 __builtin_unreachable ();
26052 isStatementSequence - returns TRUE if node, n, is a statement sequence.
26055 extern "C" bool decl_isStatementSequence (decl_node n
)
26057 return n
->kind
== decl_stmtseq
;
26058 /* static analysis guarentees a RETURN statement will be used before here. */
26059 __builtin_unreachable ();
26064 addStatement - adds node, n, as a statement to statememt sequence, s.
26067 extern "C" void decl_addStatement (decl_node s
, decl_node n
)
26071 mcDebug_assert (decl_isStatementSequence (s
));
26072 Indexing_PutIndice (s
->stmtF
.statements
, (Indexing_HighIndice (s
->stmtF
.statements
))+1, reinterpret_cast<void *> (n
));
26073 if ((isIntrinsic (n
)) && n
->intrinsicF
.postUnreachable
)
26075 n
->intrinsicF
.postUnreachable
= false;
26076 decl_addStatement (s
, makeIntrinsicProc (decl_unreachable
, 0, NULL
));
26083 addCommentBody - adds a body comment to a statement sequence node.
26086 extern "C" void decl_addCommentBody (decl_node n
)
26088 mcComment_commentDesc b
;
26092 b
= mcLexBuf_getBodyComment ();
26095 addGenericBody (n
, decl_makeCommentS (b
));
26102 addCommentAfter - adds an after comment to a statement sequence node.
26105 extern "C" void decl_addCommentAfter (decl_node n
)
26107 mcComment_commentDesc a
;
26111 a
= mcLexBuf_getAfterComment ();
26114 addGenericAfter (n
, decl_makeCommentS (a
));
26121 addIfComments - adds the, body, and, after, comments to if node, n.
26124 extern "C" void decl_addIfComments (decl_node n
, decl_node body
, decl_node after
)
26126 mcDebug_assert (decl_isIf (n
));
26127 n
->ifF
.ifComment
.after
= after
;
26128 n
->ifF
.ifComment
.body
= body
;
26133 addElseComments - adds the, body, and, after, comments to an, if, or an elsif, node, n.
26136 extern "C" void decl_addElseComments (decl_node n
, decl_node body
, decl_node after
)
26138 mcDebug_assert ((decl_isIf (n
)) || (decl_isElsif (n
)));
26141 n
->ifF
.elseComment
.after
= after
;
26142 n
->ifF
.elseComment
.body
= body
;
26146 n
->elsifF
.elseComment
.after
= after
;
26147 n
->elsifF
.elseComment
.body
= body
;
26153 addIfEndComments - adds the, body, and, after, comments to an, if, node, n.
26156 extern "C" void decl_addIfEndComments (decl_node n
, decl_node body
, decl_node after
)
26158 mcDebug_assert (decl_isIf (n
));
26159 n
->ifF
.endComment
.after
= after
;
26160 n
->ifF
.endComment
.body
= body
;
26165 makeReturn - creates and returns a return node.
26168 extern "C" decl_node
decl_makeReturn (void)
26173 n
= newNode (decl_return
);
26174 n
->returnF
.exp
= NULL
;
26175 if (decl_isProcedure (decl_getDeclScope ()))
26177 n
->returnF
.scope
= decl_getDeclScope ();
26181 n
->returnF
.scope
= NULL
;
26183 initPair (&n
->returnF
.returnComment
);
26185 /* static analysis guarentees a RETURN statement will be used before here. */
26186 __builtin_unreachable ();
26191 isReturn - returns TRUE if node, n, is a return.
26194 extern "C" bool decl_isReturn (decl_node n
)
26196 mcDebug_assert (n
!= NULL
);
26197 return n
->kind
== decl_return
;
26198 /* static analysis guarentees a RETURN statement will be used before here. */
26199 __builtin_unreachable ();
26204 putReturn - assigns node, e, as the expression on the return node.
26207 extern "C" void decl_putReturn (decl_node n
, decl_node e
)
26209 mcDebug_assert (decl_isReturn (n
));
26210 n
->returnF
.exp
= e
;
26215 makeWhile - creates and returns a while node.
26218 extern "C" decl_node
decl_makeWhile (void)
26222 n
= newNode (decl_while
);
26223 n
->whileF
.expr
= NULL
;
26224 n
->whileF
.statements
= NULL
;
26225 initPair (&n
->whileF
.doComment
);
26226 initPair (&n
->whileF
.endComment
);
26228 /* static analysis guarentees a RETURN statement will be used before here. */
26229 __builtin_unreachable ();
26234 putWhile - places an expression, e, and statement sequence, s, into the while
26238 extern "C" void decl_putWhile (decl_node n
, decl_node e
, decl_node s
)
26240 mcDebug_assert (decl_isWhile (n
));
26241 n
->whileF
.expr
= e
;
26242 n
->whileF
.statements
= s
;
26247 isWhile - returns TRUE if node, n, is a while.
26250 extern "C" bool decl_isWhile (decl_node n
)
26252 return n
->kind
== decl_while
;
26253 /* static analysis guarentees a RETURN statement will be used before here. */
26254 __builtin_unreachable ();
26259 addWhileDoComment - adds body and after comments to while node, w.
26262 extern "C" void decl_addWhileDoComment (decl_node w
, decl_node body
, decl_node after
)
26264 mcDebug_assert (decl_isWhile (w
));
26265 w
->whileF
.doComment
.after
= after
;
26266 w
->whileF
.doComment
.body
= body
;
26271 addWhileEndComment - adds body and after comments to the end of a while node, w.
26274 extern "C" void decl_addWhileEndComment (decl_node w
, decl_node body
, decl_node after
)
26276 mcDebug_assert (decl_isWhile (w
));
26277 w
->whileF
.endComment
.after
= after
;
26278 w
->whileF
.endComment
.body
= body
;
26283 makeAssignment - creates and returns an assignment node.
26284 The designator is, d, and expression, e.
26287 extern "C" decl_node
decl_makeAssignment (decl_node d
, decl_node e
)
26291 n
= newNode (decl_assignment
);
26292 n
->assignmentF
.des
= d
;
26293 n
->assignmentF
.expr
= e
;
26294 initPair (&n
->assignmentF
.assignComment
);
26296 /* static analysis guarentees a RETURN statement will be used before here. */
26297 __builtin_unreachable ();
26302 putBegin - assigns statements, s, to be the normal part in
26303 block, b. The block may be a procedure or module,
26304 or implementation node.
26307 extern "C" void decl_putBegin (decl_node b
, decl_node s
)
26309 mcDebug_assert (((decl_isImp (b
)) || (decl_isProcedure (b
))) || (decl_isModule (b
)));
26313 b
->impF
.beginStatements
= s
;
26317 b
->moduleF
.beginStatements
= s
;
26320 case decl_procedure
:
26321 b
->procedureF
.beginStatements
= s
;
26326 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
26327 __builtin_unreachable ();
26333 putFinally - assigns statements, s, to be the final part in
26334 block, b. The block may be a module
26335 or implementation node.
26338 extern "C" void decl_putFinally (decl_node b
, decl_node s
)
26340 mcDebug_assert (((decl_isImp (b
)) || (decl_isProcedure (b
))) || (decl_isModule (b
)));
26344 b
->impF
.finallyStatements
= s
;
26348 b
->moduleF
.finallyStatements
= s
;
26353 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
26354 __builtin_unreachable ();
26360 makeExit - creates and returns an exit node.
26363 extern "C" decl_node
decl_makeExit (decl_node l
, unsigned int n
)
26367 mcDebug_assert (decl_isLoop (l
));
26368 e
= newNode (decl_exit
);
26370 l
->loopF
.labelno
= n
;
26372 /* static analysis guarentees a RETURN statement will be used before here. */
26373 __builtin_unreachable ();
26378 isExit - returns TRUE if node, n, is an exit.
26381 extern "C" bool decl_isExit (decl_node n
)
26383 mcDebug_assert (n
!= NULL
);
26384 return n
->kind
== decl_exit
;
26385 /* static analysis guarentees a RETURN statement will be used before here. */
26386 __builtin_unreachable ();
26391 makeLoop - creates and returns a loop node.
26394 extern "C" decl_node
decl_makeLoop (void)
26398 l
= newNode (decl_loop
);
26399 l
->loopF
.statements
= NULL
;
26400 l
->loopF
.labelno
= 0;
26402 /* static analysis guarentees a RETURN statement will be used before here. */
26403 __builtin_unreachable ();
26408 isLoop - returns TRUE if, n, is a loop node.
26411 extern "C" bool decl_isLoop (decl_node n
)
26413 mcDebug_assert (n
!= NULL
);
26414 return n
->kind
== decl_loop
;
26415 /* static analysis guarentees a RETURN statement will be used before here. */
26416 __builtin_unreachable ();
26421 putLoop - places statement sequence, s, into loop, l.
26424 extern "C" void decl_putLoop (decl_node l
, decl_node s
)
26426 mcDebug_assert (decl_isLoop (l
));
26427 l
->loopF
.statements
= s
;
26432 makeComment - creates and returns a comment node.
26435 extern "C" decl_node
decl_makeComment (const char *a_
, unsigned int _a_high
)
26437 mcComment_commentDesc c
;
26438 DynamicStrings_String s
;
26441 /* make a local copy of each unbounded array. */
26442 memcpy (a
, a_
, _a_high
+1);
26444 c
= mcComment_initComment (true);
26445 s
= DynamicStrings_InitString ((const char *) a
, _a_high
);
26446 mcComment_addText (c
, DynamicStrings_string (s
));
26447 s
= DynamicStrings_KillString (s
);
26448 return decl_makeCommentS (c
);
26449 /* static analysis guarentees a RETURN statement will be used before here. */
26450 __builtin_unreachable ();
26455 makeCommentS - creates and returns a comment node.
26458 extern "C" decl_node
decl_makeCommentS (mcComment_commentDesc c
)
26468 n
= newNode (decl_comment
);
26469 n
->commentF
.content
= c
;
26472 /* static analysis guarentees a RETURN statement will be used before here. */
26473 __builtin_unreachable ();
26478 makeIf - creates and returns an if node. The if node
26479 will have expression, e, and statement sequence, s,
26480 as the then component.
26483 extern "C" decl_node
decl_makeIf (decl_node e
, decl_node s
)
26487 n
= newNode (decl_if
);
26490 n
->ifF
.else_
= NULL
;
26491 n
->ifF
.elsif
= NULL
;
26492 initPair (&n
->ifF
.ifComment
);
26493 initPair (&n
->ifF
.elseComment
);
26494 initPair (&n
->ifF
.endComment
);
26496 /* static analysis guarentees a RETURN statement will be used before here. */
26497 __builtin_unreachable ();
26502 isIf - returns TRUE if, n, is an if node.
26505 extern "C" bool decl_isIf (decl_node n
)
26507 return n
->kind
== decl_if
;
26508 /* static analysis guarentees a RETURN statement will be used before here. */
26509 __builtin_unreachable ();
26514 makeElsif - creates and returns an elsif node.
26515 This node has an expression, e, and statement
26519 extern "C" decl_node
decl_makeElsif (decl_node i
, decl_node e
, decl_node s
)
26523 n
= newNode (decl_elsif
);
26524 n
->elsifF
.expr
= e
;
26525 n
->elsifF
.then
= s
;
26526 n
->elsifF
.elsif
= NULL
;
26527 n
->elsifF
.else_
= NULL
;
26528 initPair (&n
->elsifF
.elseComment
);
26529 mcDebug_assert ((decl_isIf (i
)) || (decl_isElsif (i
)));
26533 mcDebug_assert (i
->ifF
.else_
== NULL
);
26537 i
->elsifF
.elsif
= n
;
26538 mcDebug_assert (i
->elsifF
.else_
== NULL
);
26541 /* static analysis guarentees a RETURN statement will be used before here. */
26542 __builtin_unreachable ();
26547 isElsif - returns TRUE if node, n, is an elsif node.
26550 extern "C" bool decl_isElsif (decl_node n
)
26552 return n
->kind
== decl_elsif
;
26553 /* static analysis guarentees a RETURN statement will be used before here. */
26554 __builtin_unreachable ();
26559 putElse - the else is grafted onto the if/elsif node, i,
26560 and the statement sequence will be, s.
26563 extern "C" void decl_putElse (decl_node i
, decl_node s
)
26565 mcDebug_assert ((decl_isIf (i
)) || (decl_isElsif (i
)));
26568 mcDebug_assert (i
->ifF
.elsif
== NULL
);
26569 mcDebug_assert (i
->ifF
.else_
== NULL
);
26574 mcDebug_assert (i
->elsifF
.elsif
== NULL
);
26575 mcDebug_assert (i
->elsifF
.else_
== NULL
);
26576 i
->elsifF
.else_
= s
;
26582 makeFor - creates and returns a for node.
26585 extern "C" decl_node
decl_makeFor (void)
26589 n
= newNode (decl_for
);
26590 n
->forF
.des
= NULL
;
26591 n
->forF
.start
= NULL
;
26592 n
->forF
.end
= NULL
;
26593 n
->forF
.increment
= NULL
;
26594 n
->forF
.statements
= NULL
;
26596 /* static analysis guarentees a RETURN statement will be used before here. */
26597 __builtin_unreachable ();
26602 isFor - returns TRUE if node, n, is a for node.
26605 extern "C" bool decl_isFor (decl_node n
)
26607 mcDebug_assert (n
!= NULL
);
26608 return n
->kind
== decl_for
;
26609 /* static analysis guarentees a RETURN statement will be used before here. */
26610 __builtin_unreachable ();
26615 putFor - assigns the fields of the for node with
26623 extern "C" void decl_putFor (decl_node f
, decl_node i
, decl_node s
, decl_node e
, decl_node b
, decl_node sq
)
26625 mcDebug_assert (decl_isFor (f
));
26629 f
->forF
.increment
= b
;
26630 f
->forF
.statements
= sq
;
26635 makeRepeat - creates and returns a repeat node.
26638 extern "C" decl_node
decl_makeRepeat (void)
26642 n
= newNode (decl_repeat
);
26643 n
->repeatF
.expr
= NULL
;
26644 n
->repeatF
.statements
= NULL
;
26645 initPair (&n
->repeatF
.repeatComment
);
26646 initPair (&n
->repeatF
.untilComment
);
26648 /* static analysis guarentees a RETURN statement will be used before here. */
26649 __builtin_unreachable ();
26654 isRepeat - returns TRUE if node, n, is a repeat node.
26657 extern "C" bool decl_isRepeat (decl_node n
)
26659 mcDebug_assert (n
!= NULL
);
26660 return n
->kind
== decl_repeat
;
26661 /* static analysis guarentees a RETURN statement will be used before here. */
26662 __builtin_unreachable ();
26667 putRepeat - places statements, s, and expression, e, into
26668 repeat statement, n.
26671 extern "C" void decl_putRepeat (decl_node n
, decl_node s
, decl_node e
)
26673 n
->repeatF
.expr
= e
;
26674 n
->repeatF
.statements
= s
;
26679 addRepeatComment - adds body and after comments to repeat node, r.
26682 extern "C" void decl_addRepeatComment (decl_node r
, decl_node body
, decl_node after
)
26684 mcDebug_assert (decl_isRepeat (r
));
26685 r
->repeatF
.repeatComment
.after
= after
;
26686 r
->repeatF
.repeatComment
.body
= body
;
26691 addUntilComment - adds body and after comments to the until section of a repeat node, r.
26694 extern "C" void decl_addUntilComment (decl_node r
, decl_node body
, decl_node after
)
26696 mcDebug_assert (decl_isRepeat (r
));
26697 r
->repeatF
.untilComment
.after
= after
;
26698 r
->repeatF
.untilComment
.body
= body
;
26703 makeCase - builds and returns a case statement node.
26706 extern "C" decl_node
decl_makeCase (void)
26710 n
= newNode (decl_case
);
26711 n
->caseF
.expression
= NULL
;
26712 n
->caseF
.caseLabelList
= Indexing_InitIndex (1);
26713 n
->caseF
.else_
= NULL
;
26715 /* static analysis guarentees a RETURN statement will be used before here. */
26716 __builtin_unreachable ();
26721 isCase - returns TRUE if node, n, is a case statement.
26724 extern "C" bool decl_isCase (decl_node n
)
26726 mcDebug_assert (n
!= NULL
);
26727 return n
->kind
== decl_case
;
26728 /* static analysis guarentees a RETURN statement will be used before here. */
26729 __builtin_unreachable ();
26734 putCaseExpression - places expression, e, into case statement, n.
26738 extern "C" decl_node
decl_putCaseExpression (decl_node n
, decl_node e
)
26740 mcDebug_assert (decl_isCase (n
));
26741 n
->caseF
.expression
= e
;
26743 /* static analysis guarentees a RETURN statement will be used before here. */
26744 __builtin_unreachable ();
26749 putCaseElse - places else statement, e, into case statement, n.
26753 extern "C" decl_node
decl_putCaseElse (decl_node n
, decl_node e
)
26755 mcDebug_assert (decl_isCase (n
));
26756 n
->caseF
.else_
= e
;
26758 /* static analysis guarentees a RETURN statement will be used before here. */
26759 __builtin_unreachable ();
26764 putCaseStatement - places a caselist, l, and associated
26765 statement sequence, s, into case statement, n.
26769 extern "C" decl_node
decl_putCaseStatement (decl_node n
, decl_node l
, decl_node s
)
26771 mcDebug_assert (decl_isCase (n
));
26772 mcDebug_assert (decl_isCaseList (l
));
26773 Indexing_IncludeIndiceIntoIndex (n
->caseF
.caseLabelList
, reinterpret_cast<void *> (decl_makeCaseLabelList (l
, s
)));
26775 /* static analysis guarentees a RETURN statement will be used before here. */
26776 __builtin_unreachable ();
26781 makeCaseLabelList - creates and returns a caselabellist node.
26784 extern "C" decl_node
decl_makeCaseLabelList (decl_node l
, decl_node s
)
26788 n
= newNode (decl_caselabellist
);
26789 n
->caselabellistF
.caseList
= l
;
26790 n
->caselabellistF
.statements
= s
;
26792 /* static analysis guarentees a RETURN statement will be used before here. */
26793 __builtin_unreachable ();
26798 isCaseLabelList - returns TRUE if, n, is a caselabellist.
26801 extern "C" bool decl_isCaseLabelList (decl_node n
)
26803 mcDebug_assert (n
!= NULL
);
26804 return n
->kind
== decl_caselabellist
;
26805 /* static analysis guarentees a RETURN statement will be used before here. */
26806 __builtin_unreachable ();
26811 makeCaseList - creates and returns a case statement node.
26814 extern "C" decl_node
decl_makeCaseList (void)
26818 n
= newNode (decl_caselist
);
26819 n
->caselistF
.rangePairs
= Indexing_InitIndex (1);
26821 /* static analysis guarentees a RETURN statement will be used before here. */
26822 __builtin_unreachable ();
26827 isCaseList - returns TRUE if, n, is a case list.
26830 extern "C" bool decl_isCaseList (decl_node n
)
26832 mcDebug_assert (n
!= NULL
);
26833 return n
->kind
== decl_caselist
;
26834 /* static analysis guarentees a RETURN statement will be used before here. */
26835 __builtin_unreachable ();
26840 putCaseRange - places the case range lo..hi into caselist, n.
26843 extern "C" decl_node
decl_putCaseRange (decl_node n
, decl_node lo
, decl_node hi
)
26845 mcDebug_assert (decl_isCaseList (n
));
26846 Indexing_IncludeIndiceIntoIndex (n
->caselistF
.rangePairs
, reinterpret_cast<void *> (decl_makeRange (lo
, hi
)));
26848 /* static analysis guarentees a RETURN statement will be used before here. */
26849 __builtin_unreachable ();
26854 makeRange - creates and returns a case range.
26857 extern "C" decl_node
decl_makeRange (decl_node lo
, decl_node hi
)
26861 n
= newNode (decl_range
);
26865 /* static analysis guarentees a RETURN statement will be used before here. */
26866 __builtin_unreachable ();
26871 isRange - returns TRUE if node, n, is a range.
26874 extern "C" bool decl_isRange (decl_node n
)
26876 mcDebug_assert (n
!= NULL
);
26877 return n
->kind
== decl_range
;
26878 /* static analysis guarentees a RETURN statement will be used before here. */
26879 __builtin_unreachable ();
26884 setNoReturn - sets noreturn field inside procedure.
26887 extern "C" void decl_setNoReturn (decl_node n
, bool value
)
26889 mcDebug_assert (n
!= NULL
);
26890 mcDebug_assert (decl_isProcedure (n
));
26891 if (n
->procedureF
.noreturnused
&& (n
->procedureF
.noreturn
!= value
))
26893 mcMetaError_metaError1 ((const char *) "{%1DMad} definition module and implementation module have different <* noreturn *> attributes", 93, (const unsigned char *) &n
, (sizeof (n
)-1));
26895 n
->procedureF
.noreturn
= value
;
26896 n
->procedureF
.noreturnused
= true;
26901 dupExpr - duplicate the expression nodes, it does not duplicate
26902 variables, literals, constants but only the expression
26903 operators (including function calls and parameter lists).
26906 extern "C" decl_node
decl_dupExpr (decl_node n
)
26914 return doDupExpr (n
);
26916 /* static analysis guarentees a RETURN statement will be used before here. */
26917 __builtin_unreachable ();
26925 extern "C" void decl_setLangC (void)
26935 extern "C" void decl_setLangCP (void)
26937 lang
= decl_ansiCP
;
26946 extern "C" void decl_setLangM2 (void)
26953 out - walks the tree of node declarations for the main module
26954 and writes the output to the outputFile specified in
26955 mcOptions. It outputs the declarations in the language
26959 extern "C" void decl_out (void)
26964 p
= mcPretty_initPretty ((mcPretty_writeProc
) {(mcPretty_writeProc_t
) write_
}, (mcPretty_writeLnProc
) {(mcPretty_writeLnProc_t
) writeln
});
26968 outC (p
, decl_getMainModule ());
26972 outC (p
, decl_getMainModule ());
26976 outM2 (p
, decl_getMainModule ());
26981 CaseException ("../../gcc-read-write/gcc/m2/mc/decl.def", 20, 1);
26982 __builtin_unreachable ();
26987 extern "C" void _M2_decl_init (__attribute__((unused
)) int argc
,__attribute__((unused
)) char *argv
[],__attribute__((unused
)) char *envp
[])
26992 extern "C" void _M2_decl_fini (__attribute__((unused
)) int argc
,__attribute__((unused
)) char *argv
[],__attribute__((unused
)) char *envp
[])