1 /* do not edit automatically generated by mc from keyc. */
2 /* keyc maintains the C name scope and avoids C/C++ name conflicts.
3 Copyright (C) 2016-2024 Free Software Foundation, Inc.
5 This file is part of GNU Modula-2.
7 GNU Modula-2 is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
24 # if !defined (PROC_D)
26 typedef void (*PROC_t
) (void);
27 typedef struct { PROC_t proc
; } PROC
;
38 # include "GStorage.h"
40 #if defined(__cplusplus)
47 # include "GmcPretty.h"
48 # include "GStorage.h"
49 # include "GDynamicStrings.h"
50 # include "GsymbolKey.h"
51 # include "GnameKey.h"
52 # include "GmcOptions.h"
55 #if !defined (decl_node_D)
57 typedef void *decl_node
;
60 typedef struct keyc__T1_r keyc__T1
;
62 typedef keyc__T1
*keyc_scope
;
66 symbolKey_symbolTree symbols
;
70 static keyc_scope stack
;
71 static keyc_scope freeList
;
72 static symbolKey_symbolTree keywords
;
73 static symbolKey_symbolTree macros
;
74 static bool initializedCP
;
75 static bool initializedGCC
;
76 static bool seenGccTree
;
77 static bool seenGccLocation
;
78 static bool seenIntMin
;
79 static bool seenUIntMin
;
80 static bool seenLongMin
;
81 static bool seenULongMin
;
82 static bool seenCharMin
;
83 static bool seenUCharMin
;
84 static bool seenIntMax
;
85 static bool seenUIntMax
;
86 static bool seenLongMax
;
87 static bool seenULongMax
;
88 static bool seenCharMax
;
89 static bool seenUCharMax
;
93 static bool seenFabsl
;
94 static bool seenSize_t
;
95 static bool seenSSize_t
;
96 static bool seenUnistd
;
97 static bool seenSysTypes
;
98 static bool seenThrow
;
100 static bool seenMalloc
;
101 static bool seenStorage
;
102 static bool seenProc
;
103 static bool seenTrue
;
104 static bool seenFalse
;
105 static bool seenNull
;
106 static bool seenMemcpy
;
107 static bool seenException
;
108 static bool seenComplex
;
109 static bool seenM2RTS
;
110 static bool seenStrlen
;
111 static bool seenCtype
;
114 useGccTree - indicate we have imported tree from gcctypes.
117 extern "C" void keyc_useGccTree (void);
120 useGccLocation - indicate we have imported tree from gcctypes.
123 extern "C" void keyc_useGccLocation (void);
126 useUnistd - need to use unistd.h call using open/close/read/write require this header.
129 extern "C" void keyc_useUnistd (void);
132 useThrow - use the throw function.
135 extern "C" void keyc_useThrow (void);
138 useStorage - indicate we have used storage.
141 extern "C" void keyc_useStorage (void);
144 useFree - indicate we have used free.
147 extern "C" void keyc_useFree (void);
150 useMalloc - indicate we have used malloc.
153 extern "C" void keyc_useMalloc (void);
156 useProc - indicate we have used proc.
159 extern "C" void keyc_useProc (void);
162 useTrue - indicate we have used TRUE.
165 extern "C" void keyc_useTrue (void);
168 useFalse - indicate we have used FALSE.
171 extern "C" void keyc_useFalse (void);
174 useNull - indicate we have used NULL.
177 extern "C" void keyc_useNull (void);
180 useMemcpy - indicate we have used memcpy.
183 extern "C" void keyc_useMemcpy (void);
186 useIntMin - indicate we have used INT_MIN.
189 extern "C" void keyc_useIntMin (void);
192 useUIntMin - indicate we have used UINT_MIN.
195 extern "C" void keyc_useUIntMin (void);
198 useLongMin - indicate we have used LONG_MIN.
201 extern "C" void keyc_useLongMin (void);
204 useULongMin - indicate we have used ULONG_MIN.
207 extern "C" void keyc_useULongMin (void);
210 useCharMin - indicate we have used CHAR_MIN.
213 extern "C" void keyc_useCharMin (void);
216 useUCharMin - indicate we have used UCHAR_MIN.
219 extern "C" void keyc_useUCharMin (void);
222 useIntMax - indicate we have used INT_MAX.
225 extern "C" void keyc_useIntMax (void);
228 useUIntMax - indicate we have used UINT_MAX.
231 extern "C" void keyc_useUIntMax (void);
234 useLongMax - indicate we have used LONG_MAX.
237 extern "C" void keyc_useLongMax (void);
240 useULongMax - indicate we have used ULONG_MAX.
243 extern "C" void keyc_useULongMax (void);
246 useCharMax - indicate we have used CHAR_MAX.
249 extern "C" void keyc_useCharMax (void);
252 useUCharMax - indicate we have used UChar_MAX.
255 extern "C" void keyc_useUCharMax (void);
258 useSize_t - indicate we have used size_t.
261 extern "C" void keyc_useSize_t (void);
264 useSSize_t - indicate we have used ssize_t.
267 extern "C" void keyc_useSSize_t (void);
270 useLabs - indicate we have used labs.
273 extern "C" void keyc_useLabs (void);
276 useAbs - indicate we have used abs.
279 extern "C" void keyc_useAbs (void);
282 useFabs - indicate we have used fabs.
285 extern "C" void keyc_useFabs (void);
288 useFabsl - indicate we have used fabsl.
291 extern "C" void keyc_useFabsl (void);
294 useException - use the exceptions module, mcrts.
297 extern "C" void keyc_useException (void);
300 useComplex - use the complex data type.
303 extern "C" void keyc_useComplex (void);
306 useM2RTS - indicate we have used M2RTS in the converted code.
309 extern "C" void keyc_useM2RTS (void);
312 useStrlen - indicate we have used strlen in the converted code.
315 extern "C" void keyc_useStrlen (void);
318 useCtype - indicate we have used the toupper function.
321 extern "C" void keyc_useCtype (void);
324 genDefs - generate definitions or includes for all
325 macros and prototypes used.
328 extern "C" void keyc_genDefs (mcPretty_pretty p
);
331 genConfigSystem - generate include files for config.h and system.h
332 within the GCC framework.
335 extern "C" void keyc_genConfigSystem (mcPretty_pretty p
);
338 enterScope - enter a scope defined by, n.
341 extern "C" void keyc_enterScope (decl_node n
);
344 leaveScope - leave the scope defined by, n.
347 extern "C" void keyc_leaveScope (decl_node n
);
350 cname - attempts to declare a symbol with name, n, in the
351 current scope. If there is no conflict with the
352 target language then NIL is returned, otherwise
353 a mangled name is returned as a String.
354 If scopes is FALSE then only the keywords and
355 macros are detected for a clash (all scoping
359 extern "C" DynamicStrings_String
keyc_cname (nameKey_Name n
, bool scopes
);
362 cnamen - attempts to declare a symbol with name, n, in the
363 current scope. If there is no conflict with the
364 target language then NIL is returned, otherwise
365 a mangled name is returned as a Name
366 If scopes is FALSE then only the keywords and
367 macros are detected for a clash (all scoping
371 extern "C" nameKey_Name
keyc_cnamen (nameKey_Name n
, bool scopes
);
374 cp - include C++ keywords and standard declarations to avoid.
377 extern "C" void keyc_cp (void);
380 checkGccConfigSystem - issues the GCC include config.h, include system.h
381 instead of the standard host include.
384 static void checkGccConfigSystem (mcPretty_pretty p
);
387 checkGccTypes - if we have imported tree or location_t from gcctypes
388 then we include the gcc headers.
391 static void checkGccTypes (mcPretty_pretty p
);
397 static void checkCtype (mcPretty_pretty p
);
400 checkAbs - check to see if the abs family, size_t or ssize_t have been used.
403 static void checkAbs (mcPretty_pretty p
);
409 static void checkLimits (mcPretty_pretty p
);
415 static void checkFreeMalloc (mcPretty_pretty p
);
421 static void checkStorage (mcPretty_pretty p
);
427 static void checkProc (mcPretty_pretty p
);
433 static void checkTrue (mcPretty_pretty p
);
439 static void checkFalse (mcPretty_pretty p
);
445 static void checkNull (mcPretty_pretty p
);
451 static void checkMemcpy (mcPretty_pretty p
);
457 static void checkM2RTS (mcPretty_pretty p
);
460 checkException - check to see if exceptions were used.
463 static void checkException (mcPretty_pretty p
);
466 checkThrow - check to see if the throw function is used.
469 static void checkThrow (mcPretty_pretty p
);
472 checkUnistd - check to see if the unistd.h header file is required.
475 static void checkUnistd (mcPretty_pretty p
);
478 checkComplex - check to see if the type complex was used.
481 static void checkComplex (mcPretty_pretty p
);
484 checkSysTypes - emit header for sys/types.h if necessary.
487 static void checkSysTypes (mcPretty_pretty p
);
490 fixNullPointerConst - fixup for NULL on some C++11 systems.
493 static void fixNullPointerConst (mcPretty_pretty p
);
499 static void genBool (mcPretty_pretty p
);
505 static keyc_scope
new_ (decl_node n
);
508 mangle1 - returns TRUE if name is unique if we add _
512 static bool mangle1 (nameKey_Name n
, DynamicStrings_String
*m
, bool scopes
);
515 mangle2 - returns TRUE if name is unique if we prepend _
519 static bool mangle2 (nameKey_Name n
, DynamicStrings_String
*m
, bool scopes
);
522 mangleN - keep adding '_' to the end of n until it
526 static bool mangleN (nameKey_Name n
, DynamicStrings_String
*m
, bool scopes
);
529 clash - returns TRUE if there is a clash with name, n,
530 in the current scope or C keywords or C macros.
533 static bool clash (nameKey_Name n
, bool scopes
);
536 initCP - add the extra keywords and standard definitions used by C++.
539 static void initCP (void);
545 static void add (symbolKey_symbolTree s
, const char *a_
, unsigned int _a_high
);
548 initMacros - macros and library function names to avoid.
551 static void initMacros (void);
554 initKeywords - keywords to avoid.
557 static void initKeywords (void);
563 static void init (void);
567 checkGccConfigSystem - issues the GCC include config.h, include system.h
568 instead of the standard host include.
571 static void checkGccConfigSystem (mcPretty_pretty p
)
573 if (mcOptions_getGccConfigSystem ())
575 if (! initializedGCC
)
577 initializedGCC
= true;
578 mcPretty_print (p
, (const char *) "#include \"config.h\"\\n", 21);
579 mcPretty_print (p
, (const char *) "#include \"system.h\"\\n", 21);
587 checkGccTypes - if we have imported tree or location_t from gcctypes
588 then we include the gcc headers.
591 static void checkGccTypes (mcPretty_pretty p
)
593 if (seenGccTree
|| seenGccLocation
)
595 mcPretty_print (p
, (const char *) "#include \"gcc-consolidation.h\"\\n\\n", 34);
604 static void checkCtype (mcPretty_pretty p
)
608 checkGccConfigSystem (p
);
609 if (mcOptions_getGccConfigSystem ())
611 /* GCC header files use a safe variant. */
612 mcPretty_print (p
, (const char *) "#include <safe-ctype.h>\\n", 25);
616 mcPretty_print (p
, (const char *) "#include <ctype.h>\\n", 20);
623 checkAbs - check to see if the abs family, size_t or ssize_t have been used.
626 static void checkAbs (mcPretty_pretty p
)
628 if (((((seenLabs
|| seenAbs
) || seenFabs
) || seenFabsl
) || seenSize_t
) || seenSSize_t
)
630 checkGccConfigSystem (p
);
631 if (! (mcOptions_getGccConfigSystem ()))
633 mcPretty_print (p
, (const char *) "#include <stdlib.h>\\n", 21);
643 static void checkLimits (mcPretty_pretty p
)
645 if ((((((((((((seenMemcpy
|| seenIntMin
) || seenUIntMin
) || seenLongMin
) || seenULongMin
) || seenCharMin
) || seenUCharMin
) || seenIntMax
) || seenUIntMax
) || seenLongMax
) || seenULongMax
) || seenCharMax
) || seenUCharMax
) /* OR seenUIntMax */
647 checkGccConfigSystem (p
);
648 if (! (mcOptions_getGccConfigSystem ()))
650 mcPretty_print (p
, (const char *) "#include <limits.h>\\n", 21);
660 static void checkFreeMalloc (mcPretty_pretty p
)
662 if (seenFree
|| seenMalloc
)
664 checkGccConfigSystem (p
);
665 if (! (mcOptions_getGccConfigSystem ()))
667 mcPretty_print (p
, (const char *) "#include <stdlib.h>\\n", 21);
677 static void checkStorage (mcPretty_pretty p
)
681 mcPretty_print (p
, (const char *) "# include \"", 13);
682 mcPretty_prints (p
, mcOptions_getHPrefix ());
683 mcPretty_print (p
, (const char *) "Storage.h\"\\n", 12);
692 static void checkProc (mcPretty_pretty p
)
696 mcPretty_print (p
, (const char *) "# if !defined (PROC_D)\\n", 26);
697 mcPretty_print (p
, (const char *) "# define PROC_D\\n", 22);
698 mcPretty_print (p
, (const char *) " typedef void (*PROC_t) (void);\\n", 39);
699 mcPretty_print (p
, (const char *) " typedef struct { PROC_t proc; } PROC;\\n", 46);
700 mcPretty_print (p
, (const char *) "# endif\\n\\n", 13);
709 static void checkTrue (mcPretty_pretty p
)
713 mcPretty_print (p
, (const char *) "# if !defined (TRUE)\\n", 24);
714 mcPretty_print (p
, (const char *) "# define TRUE (1==1)\\n", 27);
715 mcPretty_print (p
, (const char *) "# endif\\n\\n", 13);
724 static void checkFalse (mcPretty_pretty p
)
728 mcPretty_print (p
, (const char *) "# if !defined (FALSE)\\n", 25);
729 mcPretty_print (p
, (const char *) "# define FALSE (1==0)\\n", 28);
730 mcPretty_print (p
, (const char *) "# endif\\n\\n", 13);
739 static void checkNull (mcPretty_pretty p
)
743 checkGccConfigSystem (p
);
744 if (! (mcOptions_getGccConfigSystem ()))
746 mcPretty_print (p
, (const char *) "#include <stddef.h>\\n", 21);
756 static void checkMemcpy (mcPretty_pretty p
)
758 if (seenMemcpy
|| seenStrlen
)
760 checkGccConfigSystem (p
);
761 if (! (mcOptions_getGccConfigSystem ()))
763 mcPretty_print (p
, (const char *) "#include <string.h>\\n", 21);
773 static void checkM2RTS (mcPretty_pretty p
)
777 mcPretty_print (p
, (const char *) "# include \"", 13);
778 mcPretty_prints (p
, mcOptions_getHPrefix ());
779 mcPretty_print (p
, (const char *) "M2RTS.h\"\\n", 10);
785 checkException - check to see if exceptions were used.
788 static void checkException (mcPretty_pretty p
)
792 mcPretty_print (p
, (const char *) "# include \"Gmcrts.h\"\\n", 24);
798 checkThrow - check to see if the throw function is used.
801 static void checkThrow (mcPretty_pretty p
)
805 /* print (p, '# include "sys/cdefs.h"
807 mcPretty_print (p
, (const char *) "#ifndef __cplusplus\\n", 21);
808 mcPretty_print (p
, (const char *) "extern void throw (unsigned int);\\n", 35);
809 mcPretty_print (p
, (const char *) "#endif\\n", 8);
815 checkUnistd - check to see if the unistd.h header file is required.
818 static void checkUnistd (mcPretty_pretty p
)
822 checkGccConfigSystem (p
);
823 if (! (mcOptions_getGccConfigSystem ()))
825 mcPretty_print (p
, (const char *) "#include <unistd.h>\\n", 21);
832 checkComplex - check to see if the type complex was used.
835 static void checkComplex (mcPretty_pretty p
)
839 checkGccConfigSystem (p
);
840 if (! (mcOptions_getGccConfigSystem ()))
842 mcPretty_print (p
, (const char *) "# include <complex.h>\\n", 25);
849 checkSysTypes - emit header for sys/types.h if necessary.
852 static void checkSysTypes (mcPretty_pretty p
)
856 checkGccConfigSystem (p
);
857 if (! (mcOptions_getGccConfigSystem ()))
859 mcPretty_print (p
, (const char *) "# include <sys/types.h>\\n", 27);
866 fixNullPointerConst - fixup for NULL on some C++11 systems.
869 static void fixNullPointerConst (mcPretty_pretty p
)
873 mcPretty_print (p
, (const char *) "#if defined(__cplusplus)\\n", 26);
874 mcPretty_print (p
, (const char *) "# undef NULL\\n", 16);
875 mcPretty_print (p
, (const char *) "# define NULL 0\\n", 19);
876 mcPretty_print (p
, (const char *) "#endif\\n", 8);
885 static void genBool (mcPretty_pretty p
)
887 if (mcOptions_useBool ())
889 mcPretty_print (p
, (const char *) "#include <stdbool.h>\\n", 22);
898 static keyc_scope
new_ (decl_node n
)
902 if (freeList
== NULL
)
904 Storage_ALLOCATE ((void **) &s
, sizeof (keyc__T1
));
909 freeList
= freeList
->next
;
912 /* static analysis guarentees a RETURN statement will be used before here. */
913 __builtin_unreachable ();
918 mangle1 - returns TRUE if name is unique if we add _
922 static bool mangle1 (nameKey_Name n
, DynamicStrings_String
*m
, bool scopes
)
924 (*m
) = DynamicStrings_KillString ((*m
));
925 (*m
) = DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
));
926 (*m
) = DynamicStrings_ConCatChar ((*m
), '_');
927 return ! (clash (nameKey_makekey (DynamicStrings_string ((*m
))), scopes
));
928 /* static analysis guarentees a RETURN statement will be used before here. */
929 __builtin_unreachable ();
934 mangle2 - returns TRUE if name is unique if we prepend _
938 static bool mangle2 (nameKey_Name n
, DynamicStrings_String
*m
, bool scopes
)
940 (*m
) = DynamicStrings_KillString ((*m
));
941 (*m
) = DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
));
942 (*m
) = DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "_", 1), DynamicStrings_Mark ((*m
)));
943 return ! (clash (nameKey_makekey (DynamicStrings_string ((*m
))), scopes
));
944 /* static analysis guarentees a RETURN statement will be used before here. */
945 __builtin_unreachable ();
950 mangleN - keep adding '_' to the end of n until it
954 static bool mangleN (nameKey_Name n
, DynamicStrings_String
*m
, bool scopes
)
956 (*m
) = DynamicStrings_KillString ((*m
));
957 (*m
) = DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
));
960 (*m
) = DynamicStrings_ConCatChar ((*m
), '_');
961 if (! (clash (nameKey_makekey (DynamicStrings_string ((*m
))), scopes
)))
966 ReturnException ("../../gcc/m2/mc/keyc.def", 20, 1);
967 __builtin_unreachable ();
972 clash - returns TRUE if there is a clash with name, n,
973 in the current scope or C keywords or C macros.
976 static bool clash (nameKey_Name n
, bool scopes
)
978 if (((symbolKey_getSymKey (macros
, n
)) != NULL
) || ((symbolKey_getSymKey (keywords
, n
)) != NULL
))
982 return scopes
&& ((symbolKey_getSymKey (stack
->symbols
, n
)) != NULL
);
983 /* static analysis guarentees a RETURN statement will be used before here. */
984 __builtin_unreachable ();
989 initCP - add the extra keywords and standard definitions used by C++.
992 static void initCP (void)
994 add (keywords
, (const char *) "delete", 6);
995 add (keywords
, (const char *) "try", 3);
996 add (keywords
, (const char *) "catch", 5);
997 add (keywords
, (const char *) "operator", 8);
998 add (keywords
, (const char *) "complex", 7);
999 add (keywords
, (const char *) "export", 6);
1000 add (keywords
, (const char *) "public", 6);
1008 static void add (symbolKey_symbolTree s
, const char *a_
, unsigned int _a_high
)
1012 /* make a local copy of each unbounded array. */
1013 memcpy (a
, a_
, _a_high
+1);
1015 symbolKey_putSymKey (s
, nameKey_makeKey ((const char *) a
, _a_high
), reinterpret_cast <void *> (DynamicStrings_InitString ((const char *) a
, _a_high
)));
1020 initMacros - macros and library function names to avoid.
1023 static void initMacros (void)
1025 macros
= symbolKey_initTree ();
1026 add (macros
, (const char *) "FILE", 4);
1027 add (macros
, (const char *) "EOF", 3);
1028 add (macros
, (const char *) "stdio", 5);
1029 add (macros
, (const char *) "stdout", 6);
1030 add (macros
, (const char *) "stderr", 6);
1031 add (macros
, (const char *) "write", 5);
1032 add (macros
, (const char *) "read", 4);
1033 add (macros
, (const char *) "exit", 4);
1034 add (macros
, (const char *) "abs", 3);
1035 add (macros
, (const char *) "optarg", 6);
1036 add (macros
, (const char *) "div", 3);
1037 add (macros
, (const char *) "sin", 3);
1038 add (macros
, (const char *) "cos", 3);
1039 add (macros
, (const char *) "tan", 3);
1040 add (macros
, (const char *) "log10", 5);
1041 add (macros
, (const char *) "trunc", 5);
1042 add (macros
, (const char *) "I", 1);
1043 add (macros
, (const char *) "csqrt", 5);
1044 add (macros
, (const char *) "strlen", 6);
1045 add (macros
, (const char *) "strcpy", 6);
1046 add (macros
, (const char *) "free", 4);
1047 add (macros
, (const char *) "malloc", 6);
1048 add (macros
, (const char *) "time", 4);
1049 add (macros
, (const char *) "main", 4);
1050 add (macros
, (const char *) "true", 4);
1051 add (macros
, (const char *) "false", 5);
1052 add (macros
, (const char *) "sigfpe", 6);
1057 initKeywords - keywords to avoid.
1060 static void initKeywords (void)
1062 keywords
= symbolKey_initTree ();
1063 add (keywords
, (const char *) "auto", 4);
1064 add (keywords
, (const char *) "break", 5);
1065 add (keywords
, (const char *) "case", 4);
1066 add (keywords
, (const char *) "char", 4);
1067 add (keywords
, (const char *) "const", 5);
1068 add (keywords
, (const char *) "continue", 8);
1069 add (keywords
, (const char *) "default", 7);
1070 add (keywords
, (const char *) "do", 2);
1071 add (keywords
, (const char *) "double", 6);
1072 add (keywords
, (const char *) "else", 4);
1073 add (keywords
, (const char *) "enum", 4);
1074 add (keywords
, (const char *) "extern", 6);
1075 add (keywords
, (const char *) "float", 5);
1076 add (keywords
, (const char *) "for", 3);
1077 add (keywords
, (const char *) "goto", 4);
1078 add (keywords
, (const char *) "if", 2);
1079 add (keywords
, (const char *) "int", 3);
1080 add (keywords
, (const char *) "long", 4);
1081 add (keywords
, (const char *) "register", 8);
1082 add (keywords
, (const char *) "return", 6);
1083 add (keywords
, (const char *) "short", 5);
1084 add (keywords
, (const char *) "signed", 6);
1085 add (keywords
, (const char *) "sizeof", 6);
1086 add (keywords
, (const char *) "static", 6);
1087 add (keywords
, (const char *) "struct", 6);
1088 add (keywords
, (const char *) "switch", 6);
1089 add (keywords
, (const char *) "typedef", 7);
1090 add (keywords
, (const char *) "union", 5);
1091 add (keywords
, (const char *) "unsigned", 8);
1092 add (keywords
, (const char *) "void", 4);
1093 add (keywords
, (const char *) "volatile", 8);
1094 add (keywords
, (const char *) "while", 5);
1095 add (keywords
, (const char *) "and", 3);
1096 add (keywords
, (const char *) "or", 2);
1097 add (keywords
, (const char *) "not", 3);
1098 add (keywords
, (const char *) "throw", 5);
1099 add (keywords
, (const char *) "new", 3);
1107 static void init (void)
1113 seenStorage
= false;
1120 seenUIntMin
= false;
1121 seenLongMin
= false;
1122 seenULongMin
= false;
1123 seenCharMin
= false;
1124 seenUCharMin
= false;
1126 seenUIntMax
= false;
1127 seenLongMax
= false;
1128 seenULongMax
= false;
1129 seenCharMax
= false;
1130 seenUCharMax
= false;
1135 seenException
= false;
1136 seenComplex
= false;
1141 seenSSize_t
= false;
1142 seenSysTypes
= false;
1143 seenGccTree
= false;
1144 seenGccLocation
= false;
1145 initializedCP
= false;
1146 initializedGCC
= false;
1155 useGccTree - indicate we have imported tree from gcctypes.
1158 extern "C" void keyc_useGccTree (void)
1165 useGccLocation - indicate we have imported tree from gcctypes.
1168 extern "C" void keyc_useGccLocation (void)
1170 seenGccLocation
= true;
1175 useUnistd - need to use unistd.h call using open/close/read/write require this header.
1178 extern "C" void keyc_useUnistd (void)
1185 useThrow - use the throw function.
1188 extern "C" void keyc_useThrow (void)
1195 useStorage - indicate we have used storage.
1198 extern "C" void keyc_useStorage (void)
1205 useFree - indicate we have used free.
1208 extern "C" void keyc_useFree (void)
1215 useMalloc - indicate we have used malloc.
1218 extern "C" void keyc_useMalloc (void)
1225 useProc - indicate we have used proc.
1228 extern "C" void keyc_useProc (void)
1235 useTrue - indicate we have used TRUE.
1238 extern "C" void keyc_useTrue (void)
1245 useFalse - indicate we have used FALSE.
1248 extern "C" void keyc_useFalse (void)
1255 useNull - indicate we have used NULL.
1258 extern "C" void keyc_useNull (void)
1265 useMemcpy - indicate we have used memcpy.
1268 extern "C" void keyc_useMemcpy (void)
1275 useIntMin - indicate we have used INT_MIN.
1278 extern "C" void keyc_useIntMin (void)
1285 useUIntMin - indicate we have used UINT_MIN.
1288 extern "C" void keyc_useUIntMin (void)
1295 useLongMin - indicate we have used LONG_MIN.
1298 extern "C" void keyc_useLongMin (void)
1305 useULongMin - indicate we have used ULONG_MIN.
1308 extern "C" void keyc_useULongMin (void)
1310 seenULongMin
= true;
1315 useCharMin - indicate we have used CHAR_MIN.
1318 extern "C" void keyc_useCharMin (void)
1325 useUCharMin - indicate we have used UCHAR_MIN.
1328 extern "C" void keyc_useUCharMin (void)
1330 seenUCharMin
= true;
1335 useIntMax - indicate we have used INT_MAX.
1338 extern "C" void keyc_useIntMax (void)
1345 useUIntMax - indicate we have used UINT_MAX.
1348 extern "C" void keyc_useUIntMax (void)
1355 useLongMax - indicate we have used LONG_MAX.
1358 extern "C" void keyc_useLongMax (void)
1365 useULongMax - indicate we have used ULONG_MAX.
1368 extern "C" void keyc_useULongMax (void)
1370 seenULongMax
= true;
1375 useCharMax - indicate we have used CHAR_MAX.
1378 extern "C" void keyc_useCharMax (void)
1385 useUCharMax - indicate we have used UChar_MAX.
1388 extern "C" void keyc_useUCharMax (void)
1390 seenUCharMax
= true;
1395 useSize_t - indicate we have used size_t.
1398 extern "C" void keyc_useSize_t (void)
1405 useSSize_t - indicate we have used ssize_t.
1408 extern "C" void keyc_useSSize_t (void)
1411 seenSysTypes
= true;
1416 useLabs - indicate we have used labs.
1419 extern "C" void keyc_useLabs (void)
1426 useAbs - indicate we have used abs.
1429 extern "C" void keyc_useAbs (void)
1436 useFabs - indicate we have used fabs.
1439 extern "C" void keyc_useFabs (void)
1446 useFabsl - indicate we have used fabsl.
1449 extern "C" void keyc_useFabsl (void)
1456 useException - use the exceptions module, mcrts.
1459 extern "C" void keyc_useException (void)
1461 seenException
= true;
1466 useComplex - use the complex data type.
1469 extern "C" void keyc_useComplex (void)
1476 useM2RTS - indicate we have used M2RTS in the converted code.
1479 extern "C" void keyc_useM2RTS (void)
1486 useStrlen - indicate we have used strlen in the converted code.
1489 extern "C" void keyc_useStrlen (void)
1496 useCtype - indicate we have used the toupper function.
1499 extern "C" void keyc_useCtype (void)
1506 genDefs - generate definitions or includes for all
1507 macros and prototypes used.
1510 extern "C" void keyc_genDefs (mcPretty_pretty p
)
1513 checkFreeMalloc (p
);
1529 fixNullPointerConst (p
);
1534 genConfigSystem - generate include files for config.h and system.h
1535 within the GCC framework.
1538 extern "C" void keyc_genConfigSystem (mcPretty_pretty p
)
1540 checkGccConfigSystem (p
);
1545 enterScope - enter a scope defined by, n.
1548 extern "C" void keyc_enterScope (decl_node n
)
1554 s
->symbols
= symbolKey_initTree ();
1561 leaveScope - leave the scope defined by, n.
1564 extern "C" void keyc_leaveScope (decl_node n
)
1568 if (n
== stack
->scoped
)
1571 stack
= stack
->next
;
1572 s
->scoped
= static_cast<decl_node
> (NULL
);
1573 symbolKey_killTree (&s
->symbols
);
1579 __builtin_unreachable ();
1585 cname - attempts to declare a symbol with name, n, in the
1586 current scope. If there is no conflict with the
1587 target language then NIL is returned, otherwise
1588 a mangled name is returned as a String.
1589 If scopes is FALSE then only the keywords and
1590 macros are detected for a clash (all scoping
1594 extern "C" DynamicStrings_String
keyc_cname (nameKey_Name n
, bool scopes
)
1596 DynamicStrings_String m
;
1598 m
= static_cast<DynamicStrings_String
> (NULL
);
1599 if (clash (n
, scopes
))
1601 if (((mangle1 (n
, &m
, scopes
)) || (mangle2 (n
, &m
, scopes
))) || (mangleN (n
, &m
, scopes
)))
1603 /* avoid dangling else. */
1606 /* no longer a clash with, m, so add it to the current scope. */
1607 n
= nameKey_makekey (DynamicStrings_string (m
));
1608 symbolKey_putSymKey (stack
->symbols
, n
, reinterpret_cast <void *> (m
));
1613 /* mangleN must always succeed. */
1615 __builtin_unreachable ();
1620 /* avoid dangling else. */
1621 /* no clash, add it to the current scope. */
1622 symbolKey_putSymKey (stack
->symbols
, n
, reinterpret_cast <void *> (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
))));
1625 /* static analysis guarentees a RETURN statement will be used before here. */
1626 __builtin_unreachable ();
1631 cnamen - attempts to declare a symbol with name, n, in the
1632 current scope. If there is no conflict with the
1633 target language then NIL is returned, otherwise
1634 a mangled name is returned as a Name
1635 If scopes is FALSE then only the keywords and
1636 macros are detected for a clash (all scoping
1640 extern "C" nameKey_Name
keyc_cnamen (nameKey_Name n
, bool scopes
)
1642 DynamicStrings_String m
;
1644 m
= static_cast<DynamicStrings_String
> (NULL
);
1645 if (clash (n
, scopes
))
1647 if (((mangle1 (n
, &m
, scopes
)) || (mangle2 (n
, &m
, scopes
))) || (mangleN (n
, &m
, scopes
)))
1649 /* avoid dangling else. */
1650 n
= nameKey_makekey (DynamicStrings_string (m
));
1653 /* no longer a clash with, m, so add it to the current scope. */
1654 symbolKey_putSymKey (stack
->symbols
, n
, reinterpret_cast <void *> (m
));
1659 /* mangleN must always succeed. */
1661 __builtin_unreachable ();
1666 /* avoid dangling else. */
1667 /* no clash, add it to the current scope. */
1668 symbolKey_putSymKey (stack
->symbols
, n
, reinterpret_cast <void *> (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
))));
1670 m
= DynamicStrings_KillString (m
);
1672 /* static analysis guarentees a RETURN statement will be used before here. */
1673 __builtin_unreachable ();
1678 cp - include C++ keywords and standard declarations to avoid.
1681 extern "C" void keyc_cp (void)
1683 if (! initializedCP
)
1685 initializedCP
= true;
1690 extern "C" void _M2_keyc_init (__attribute__((unused
)) int argc
, __attribute__((unused
)) char *argv
[], __attribute__((unused
)) char *envp
[])
1695 extern "C" void _M2_keyc_fini (__attribute__((unused
)) int argc
, __attribute__((unused
)) char *argv
[], __attribute__((unused
)) char *envp
[])