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-2022 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 along
18 with gm2; see the file COPYING. If not, write to the Free Software
19 Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
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 unsigned int initializedCP
;
75 static unsigned int initializedGCC
;
76 static unsigned int seenIntMin
;
77 static unsigned int seenUIntMin
;
78 static unsigned int seenLongMin
;
79 static unsigned int seenULongMin
;
80 static unsigned int seenCharMin
;
81 static unsigned int seenUCharMin
;
82 static unsigned int seenIntMax
;
83 static unsigned int seenUIntMax
;
84 static unsigned int seenLongMax
;
85 static unsigned int seenULongMax
;
86 static unsigned int seenCharMax
;
87 static unsigned int seenUCharMax
;
88 static unsigned int seenLabs
;
89 static unsigned int seenAbs
;
90 static unsigned int seenFabs
;
91 static unsigned int seenFabsl
;
92 static unsigned int seenSize_t
;
93 static unsigned int seenSSize_t
;
94 static unsigned int seenUnistd
;
95 static unsigned int seenSysTypes
;
96 static unsigned int seenThrow
;
97 static unsigned int seenFree
;
98 static unsigned int seenMalloc
;
99 static unsigned int seenStorage
;
100 static unsigned int seenProc
;
101 static unsigned int seenTrue
;
102 static unsigned int seenFalse
;
103 static unsigned int seenNull
;
104 static unsigned int seenMemcpy
;
105 static unsigned int seenException
;
106 static unsigned int seenComplex
;
107 static unsigned int seenM2RTS
;
108 static unsigned int seenStrlen
;
109 static unsigned int seenCtype
;
112 useUnistd - need to use unistd.h call using open/close/read/write require this header.
115 extern "C" void keyc_useUnistd (void);
118 useThrow - use the throw function.
121 extern "C" void keyc_useThrow (void);
124 useStorage - indicate we have used storage.
127 extern "C" void keyc_useStorage (void);
130 useFree - indicate we have used free.
133 extern "C" void keyc_useFree (void);
136 useMalloc - indicate we have used malloc.
139 extern "C" void keyc_useMalloc (void);
142 useProc - indicate we have used proc.
145 extern "C" void keyc_useProc (void);
148 useTrue - indicate we have used TRUE.
151 extern "C" void keyc_useTrue (void);
154 useFalse - indicate we have used FALSE.
157 extern "C" void keyc_useFalse (void);
160 useNull - indicate we have used NULL.
163 extern "C" void keyc_useNull (void);
166 useMemcpy - indicate we have used memcpy.
169 extern "C" void keyc_useMemcpy (void);
172 useIntMin - indicate we have used INT_MIN.
175 extern "C" void keyc_useIntMin (void);
178 useUIntMin - indicate we have used UINT_MIN.
181 extern "C" void keyc_useUIntMin (void);
184 useLongMin - indicate we have used LONG_MIN.
187 extern "C" void keyc_useLongMin (void);
190 useULongMin - indicate we have used ULONG_MIN.
193 extern "C" void keyc_useULongMin (void);
196 useCharMin - indicate we have used CHAR_MIN.
199 extern "C" void keyc_useCharMin (void);
202 useUCharMin - indicate we have used UCHAR_MIN.
205 extern "C" void keyc_useUCharMin (void);
208 useIntMax - indicate we have used INT_MAX.
211 extern "C" void keyc_useIntMax (void);
214 useUIntMax - indicate we have used UINT_MAX.
217 extern "C" void keyc_useUIntMax (void);
220 useLongMax - indicate we have used LONG_MAX.
223 extern "C" void keyc_useLongMax (void);
226 useULongMax - indicate we have used ULONG_MAX.
229 extern "C" void keyc_useULongMax (void);
232 useCharMax - indicate we have used CHAR_MAX.
235 extern "C" void keyc_useCharMax (void);
238 useUCharMax - indicate we have used UChar_MAX.
241 extern "C" void keyc_useUCharMax (void);
244 useSize_t - indicate we have used size_t.
247 extern "C" void keyc_useSize_t (void);
250 useSSize_t - indicate we have used ssize_t.
253 extern "C" void keyc_useSSize_t (void);
256 useLabs - indicate we have used labs.
259 extern "C" void keyc_useLabs (void);
262 useAbs - indicate we have used abs.
265 extern "C" void keyc_useAbs (void);
268 useFabs - indicate we have used fabs.
271 extern "C" void keyc_useFabs (void);
274 useFabsl - indicate we have used fabsl.
277 extern "C" void keyc_useFabsl (void);
280 useException - use the exceptions module, mcrts.
283 extern "C" void keyc_useException (void);
286 useComplex - use the complex data type.
289 extern "C" void keyc_useComplex (void);
292 useM2RTS - indicate we have used M2RTS in the converted code.
295 extern "C" void keyc_useM2RTS (void);
298 useStrlen - indicate we have used strlen in the converted code.
301 extern "C" void keyc_useStrlen (void);
304 useCtype - indicate we have used the toupper function.
307 extern "C" void keyc_useCtype (void);
310 genDefs - generate definitions or includes for all
311 macros and prototypes used.
314 extern "C" void keyc_genDefs (mcPretty_pretty p
);
317 genConfigSystem - generate include files for config.h and system.h
318 within the GCC framework.
321 extern "C" void keyc_genConfigSystem (mcPretty_pretty p
);
324 enterScope - enter a scope defined by, n.
327 extern "C" void keyc_enterScope (decl_node n
);
330 leaveScope - leave the scope defined by, n.
333 extern "C" void keyc_leaveScope (decl_node n
);
336 cname - attempts to declare a symbol with name, n, in the
337 current scope. If there is no conflict with the
338 target language then NIL is returned, otherwise
339 a mangled name is returned as a String.
340 If scopes is FALSE then only the keywords and
341 macros are detected for a clash (all scoping
345 extern "C" DynamicStrings_String
keyc_cname (nameKey_Name n
, unsigned int scopes
);
348 cnamen - attempts to declare a symbol with name, n, in the
349 current scope. If there is no conflict with the
350 target language then NIL is returned, otherwise
351 a mangled name is returned as a Name
352 If scopes is FALSE then only the keywords and
353 macros are detected for a clash (all scoping
357 extern "C" nameKey_Name
keyc_cnamen (nameKey_Name n
, unsigned int scopes
);
360 cp - include C++ keywords and standard declarations to avoid.
363 extern "C" void keyc_cp (void);
366 checkGccConfigSystem - issues the GCC include config.h, include system.h
367 instead of the standard host include.
370 static void checkGccConfigSystem (mcPretty_pretty p
);
376 static void checkCtype (mcPretty_pretty p
);
379 checkAbs - check to see if the abs family, size_t or ssize_t have been used.
382 static void checkAbs (mcPretty_pretty p
);
388 static void checkLimits (mcPretty_pretty p
);
394 static void checkFreeMalloc (mcPretty_pretty p
);
400 static void checkStorage (mcPretty_pretty p
);
406 static void checkProc (mcPretty_pretty p
);
412 static void checkTrue (mcPretty_pretty p
);
418 static void checkFalse (mcPretty_pretty p
);
424 static void checkNull (mcPretty_pretty p
);
430 static void checkMemcpy (mcPretty_pretty p
);
436 static void checkM2RTS (mcPretty_pretty p
);
439 checkException - check to see if exceptions were used.
442 static void checkException (mcPretty_pretty p
);
445 checkThrow - check to see if the throw function is used.
448 static void checkThrow (mcPretty_pretty p
);
451 checkUnistd - check to see if the unistd.h header file is required.
454 static void checkUnistd (mcPretty_pretty p
);
457 checkComplex - check to see if the type complex was used.
460 static void checkComplex (mcPretty_pretty p
);
463 checkSysTypes - emit header for sys/types.h if necessary.
466 static void checkSysTypes (mcPretty_pretty p
);
469 fixNullPointerConst - fixup for NULL on some C++11 systems.
472 static void fixNullPointerConst (mcPretty_pretty p
);
478 static keyc_scope
new_ (decl_node n
);
481 mangle1 - returns TRUE if name is unique if we add _
485 static unsigned int mangle1 (nameKey_Name n
, DynamicStrings_String
*m
, unsigned int scopes
);
488 mangle2 - returns TRUE if name is unique if we prepend _
492 static unsigned int mangle2 (nameKey_Name n
, DynamicStrings_String
*m
, unsigned int scopes
);
495 mangleN - keep adding '_' to the end of n until it
499 static unsigned int mangleN (nameKey_Name n
, DynamicStrings_String
*m
, unsigned int scopes
);
502 clash - returns TRUE if there is a clash with name, n,
503 in the current scope or C keywords or C macros.
506 static unsigned int clash (nameKey_Name n
, unsigned int scopes
);
509 initCP - add the extra keywords and standard definitions used by C++.
512 static void initCP (void);
518 static void add (symbolKey_symbolTree s
, const char *a_
, unsigned int _a_high
);
521 initMacros - macros and library function names to avoid.
524 static void initMacros (void);
527 initKeywords - keywords to avoid.
530 static void initKeywords (void);
536 static void init (void);
540 checkGccConfigSystem - issues the GCC include config.h, include system.h
541 instead of the standard host include.
544 static void checkGccConfigSystem (mcPretty_pretty p
)
546 if (mcOptions_getGccConfigSystem ())
548 if (! initializedGCC
)
550 initializedGCC
= TRUE
;
551 mcPretty_print (p
, (const char *) "#include \"config.h\"\\n", 21);
552 mcPretty_print (p
, (const char *) "#include \"system.h\"\\n", 21);
562 static void checkCtype (mcPretty_pretty p
)
566 checkGccConfigSystem (p
);
567 if (mcOptions_getGccConfigSystem ())
569 /* GCC header files use a safe variant. */
570 mcPretty_print (p
, (const char *) "#include <safe-ctype.h>\\n", 25);
574 mcPretty_print (p
, (const char *) "#include <ctype.h>\\n", 20);
581 checkAbs - check to see if the abs family, size_t or ssize_t have been used.
584 static void checkAbs (mcPretty_pretty p
)
586 if (((((seenLabs
|| seenAbs
) || seenFabs
) || seenFabsl
) || seenSize_t
) || seenSSize_t
)
588 checkGccConfigSystem (p
);
589 if (! (mcOptions_getGccConfigSystem ()))
591 mcPretty_print (p
, (const char *) "#include <stdlib.h>\\n", 21);
601 static void checkLimits (mcPretty_pretty p
)
603 if ((((((((((((((seenMemcpy
|| seenIntMin
) || seenUIntMin
) || seenLongMin
) || seenULongMin
) || seenCharMin
) || seenUCharMin
) || seenUIntMin
) || seenIntMax
) || seenUIntMax
) || seenLongMax
) || seenULongMax
) || seenCharMax
) || seenUCharMax
) || seenUIntMax
)
605 checkGccConfigSystem (p
);
606 if (! (mcOptions_getGccConfigSystem ()))
608 mcPretty_print (p
, (const char *) "#include <limits.h>\\n", 21);
618 static void checkFreeMalloc (mcPretty_pretty p
)
620 if (seenFree
|| seenMalloc
)
622 checkGccConfigSystem (p
);
623 if (! (mcOptions_getGccConfigSystem ()))
625 mcPretty_print (p
, (const char *) "#include <stdlib.h>\\n", 21);
635 static void checkStorage (mcPretty_pretty p
)
639 mcPretty_print (p
, (const char *) "# include \"", 13);
640 mcPretty_prints (p
, mcOptions_getHPrefix ());
641 mcPretty_print (p
, (const char *) "Storage.h\"\\n", 12);
650 static void checkProc (mcPretty_pretty p
)
654 mcPretty_print (p
, (const char *) "# if !defined (PROC_D)\\n", 26);
655 mcPretty_print (p
, (const char *) "# define PROC_D\\n", 22);
656 mcPretty_print (p
, (const char *) " typedef void (*PROC_t) (void);\\n", 39);
657 mcPretty_print (p
, (const char *) " typedef struct { PROC_t proc; } PROC;\\n", 46);
658 mcPretty_print (p
, (const char *) "# endif\\n\\n", 13);
667 static void checkTrue (mcPretty_pretty p
)
671 mcPretty_print (p
, (const char *) "# if !defined (TRUE)\\n", 24);
672 mcPretty_print (p
, (const char *) "# define TRUE (1==1)\\n", 27);
673 mcPretty_print (p
, (const char *) "# endif\\n\\n", 13);
682 static void checkFalse (mcPretty_pretty p
)
686 mcPretty_print (p
, (const char *) "# if !defined (FALSE)\\n", 25);
687 mcPretty_print (p
, (const char *) "# define FALSE (1==0)\\n", 28);
688 mcPretty_print (p
, (const char *) "# endif\\n\\n", 13);
697 static void checkNull (mcPretty_pretty p
)
701 checkGccConfigSystem (p
);
702 if (! (mcOptions_getGccConfigSystem ()))
704 mcPretty_print (p
, (const char *) "#include <stddef.h>\\n", 21);
714 static void checkMemcpy (mcPretty_pretty p
)
716 if (seenMemcpy
|| seenStrlen
)
718 checkGccConfigSystem (p
);
719 if (! (mcOptions_getGccConfigSystem ()))
721 mcPretty_print (p
, (const char *) "#include <string.h>\\n", 21);
731 static void checkM2RTS (mcPretty_pretty p
)
735 mcPretty_print (p
, (const char *) "# include \"", 13);
736 mcPretty_prints (p
, mcOptions_getHPrefix ());
737 mcPretty_print (p
, (const char *) "M2RTS.h\"\\n", 10);
743 checkException - check to see if exceptions were used.
746 static void checkException (mcPretty_pretty p
)
750 mcPretty_print (p
, (const char *) "# include \"Gmcrts.h\"\\n", 24);
756 checkThrow - check to see if the throw function is used.
759 static void checkThrow (mcPretty_pretty p
)
763 /* print (p, '# include "sys/cdefs.h"
765 mcPretty_print (p
, (const char *) "#ifndef __cplusplus\\n", 21);
766 mcPretty_print (p
, (const char *) "extern void throw (unsigned int);\\n", 35);
767 mcPretty_print (p
, (const char *) "#endif\\n", 8);
773 checkUnistd - check to see if the unistd.h header file is required.
776 static void checkUnistd (mcPretty_pretty p
)
780 checkGccConfigSystem (p
);
781 if (! (mcOptions_getGccConfigSystem ()))
783 mcPretty_print (p
, (const char *) "#include <unistd.h>\\n", 21);
790 checkComplex - check to see if the type complex was used.
793 static void checkComplex (mcPretty_pretty p
)
797 checkGccConfigSystem (p
);
798 if (! (mcOptions_getGccConfigSystem ()))
800 mcPretty_print (p
, (const char *) "# include <complex.h>\\n", 25);
807 checkSysTypes - emit header for sys/types.h if necessary.
810 static void checkSysTypes (mcPretty_pretty p
)
814 checkGccConfigSystem (p
);
815 if (! (mcOptions_getGccConfigSystem ()))
817 mcPretty_print (p
, (const char *) "# include <sys/types.h>\\n", 27);
824 fixNullPointerConst - fixup for NULL on some C++11 systems.
827 static void fixNullPointerConst (mcPretty_pretty p
)
831 mcPretty_print (p
, (const char *) "#if defined(__cplusplus)\\n", 26);
832 mcPretty_print (p
, (const char *) "# undef NULL\\n", 16);
833 mcPretty_print (p
, (const char *) "# define NULL 0\\n", 19);
834 mcPretty_print (p
, (const char *) "#endif\\n", 8);
843 static keyc_scope
new_ (decl_node n
)
847 if (freeList
== NULL
)
849 Storage_ALLOCATE ((void **) &s
, sizeof (keyc__T1
));
854 freeList
= freeList
->next
;
857 /* static analysis guarentees a RETURN statement will be used before here. */
858 __builtin_unreachable ();
863 mangle1 - returns TRUE if name is unique if we add _
867 static unsigned int mangle1 (nameKey_Name n
, DynamicStrings_String
*m
, unsigned int scopes
)
869 (*m
) = DynamicStrings_KillString ((*m
));
870 (*m
) = DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
));
871 (*m
) = DynamicStrings_ConCatChar ((*m
), '_');
872 return ! (clash (nameKey_makekey (DynamicStrings_string ((*m
))), scopes
));
873 /* static analysis guarentees a RETURN statement will be used before here. */
874 __builtin_unreachable ();
879 mangle2 - returns TRUE if name is unique if we prepend _
883 static unsigned int mangle2 (nameKey_Name n
, DynamicStrings_String
*m
, unsigned int scopes
)
885 (*m
) = DynamicStrings_KillString ((*m
));
886 (*m
) = DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
));
887 (*m
) = DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "_", 1), DynamicStrings_Mark ((*m
)));
888 return ! (clash (nameKey_makekey (DynamicStrings_string ((*m
))), scopes
));
889 /* static analysis guarentees a RETURN statement will be used before here. */
890 __builtin_unreachable ();
895 mangleN - keep adding '_' to the end of n until it
899 static unsigned int mangleN (nameKey_Name n
, DynamicStrings_String
*m
, unsigned int scopes
)
901 (*m
) = DynamicStrings_KillString ((*m
));
902 (*m
) = DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
));
905 (*m
) = DynamicStrings_ConCatChar ((*m
), '_');
906 if (! (clash (nameKey_makekey (DynamicStrings_string ((*m
))), scopes
)))
911 ReturnException ("../../gcc-git-devel-modula2/gcc/m2/mc/keyc.def", 20, 1);
912 __builtin_unreachable ();
917 clash - returns TRUE if there is a clash with name, n,
918 in the current scope or C keywords or C macros.
921 static unsigned int clash (nameKey_Name n
, unsigned int scopes
)
923 if (((symbolKey_getSymKey (macros
, n
)) != NULL
) || ((symbolKey_getSymKey (keywords
, n
)) != NULL
))
927 return scopes
&& ((symbolKey_getSymKey (stack
->symbols
, n
)) != NULL
);
928 /* static analysis guarentees a RETURN statement will be used before here. */
929 __builtin_unreachable ();
934 initCP - add the extra keywords and standard definitions used by C++.
937 static void initCP (void)
939 add (keywords
, (const char *) "delete", 6);
940 add (keywords
, (const char *) "try", 3);
941 add (keywords
, (const char *) "catch", 5);
942 add (keywords
, (const char *) "operator", 8);
943 add (keywords
, (const char *) "complex", 7);
944 add (keywords
, (const char *) "export", 6);
945 add (keywords
, (const char *) "public", 6);
953 static void add (symbolKey_symbolTree s
, const char *a_
, unsigned int _a_high
)
957 /* make a local copy of each unbounded array. */
958 memcpy (a
, a_
, _a_high
+1);
960 symbolKey_putSymKey (s
, nameKey_makeKey ((const char *) a
, _a_high
), reinterpret_cast<void *> (DynamicStrings_InitString ((const char *) a
, _a_high
)));
965 initMacros - macros and library function names to avoid.
968 static void initMacros (void)
970 macros
= symbolKey_initTree ();
971 add (macros
, (const char *) "FILE", 4);
972 add (macros
, (const char *) "EOF", 3);
973 add (macros
, (const char *) "stdio", 5);
974 add (macros
, (const char *) "stdout", 6);
975 add (macros
, (const char *) "stderr", 6);
976 add (macros
, (const char *) "write", 5);
977 add (macros
, (const char *) "read", 4);
978 add (macros
, (const char *) "exit", 4);
979 add (macros
, (const char *) "abs", 3);
980 add (macros
, (const char *) "optarg", 6);
981 add (macros
, (const char *) "div", 3);
982 add (macros
, (const char *) "sin", 3);
983 add (macros
, (const char *) "cos", 3);
984 add (macros
, (const char *) "tan", 3);
985 add (macros
, (const char *) "log10", 5);
986 add (macros
, (const char *) "trunc", 5);
987 add (macros
, (const char *) "I", 1);
988 add (macros
, (const char *) "csqrt", 5);
989 add (macros
, (const char *) "strlen", 6);
990 add (macros
, (const char *) "strcpy", 6);
991 add (macros
, (const char *) "free", 4);
992 add (macros
, (const char *) "malloc", 6);
993 add (macros
, (const char *) "time", 4);
994 add (macros
, (const char *) "main", 4);
995 add (macros
, (const char *) "true", 4);
996 add (macros
, (const char *) "false", 5);
997 add (macros
, (const char *) "sigfpe", 6);
1002 initKeywords - keywords to avoid.
1005 static void initKeywords (void)
1007 keywords
= symbolKey_initTree ();
1008 add (keywords
, (const char *) "auto", 4);
1009 add (keywords
, (const char *) "break", 5);
1010 add (keywords
, (const char *) "case", 4);
1011 add (keywords
, (const char *) "char", 4);
1012 add (keywords
, (const char *) "const", 5);
1013 add (keywords
, (const char *) "continue", 8);
1014 add (keywords
, (const char *) "default", 7);
1015 add (keywords
, (const char *) "do", 2);
1016 add (keywords
, (const char *) "double", 6);
1017 add (keywords
, (const char *) "else", 4);
1018 add (keywords
, (const char *) "enum", 4);
1019 add (keywords
, (const char *) "extern", 6);
1020 add (keywords
, (const char *) "float", 5);
1021 add (keywords
, (const char *) "for", 3);
1022 add (keywords
, (const char *) "goto", 4);
1023 add (keywords
, (const char *) "if", 2);
1024 add (keywords
, (const char *) "int", 3);
1025 add (keywords
, (const char *) "long", 4);
1026 add (keywords
, (const char *) "register", 8);
1027 add (keywords
, (const char *) "return", 6);
1028 add (keywords
, (const char *) "short", 5);
1029 add (keywords
, (const char *) "signed", 6);
1030 add (keywords
, (const char *) "sizeof", 6);
1031 add (keywords
, (const char *) "static", 6);
1032 add (keywords
, (const char *) "struct", 6);
1033 add (keywords
, (const char *) "switch", 6);
1034 add (keywords
, (const char *) "typedef", 7);
1035 add (keywords
, (const char *) "union", 5);
1036 add (keywords
, (const char *) "unsigned", 8);
1037 add (keywords
, (const char *) "void", 4);
1038 add (keywords
, (const char *) "volatile", 8);
1039 add (keywords
, (const char *) "while", 5);
1040 add (keywords
, (const char *) "and", 3);
1041 add (keywords
, (const char *) "or", 2);
1042 add (keywords
, (const char *) "not", 3);
1043 add (keywords
, (const char *) "throw", 5);
1044 add (keywords
, (const char *) "new", 3);
1052 static void init (void)
1058 seenStorage
= FALSE
;
1065 seenUIntMin
= FALSE
;
1066 seenLongMin
= FALSE
;
1067 seenULongMin
= FALSE
;
1068 seenCharMin
= FALSE
;
1069 seenUCharMin
= FALSE
;
1070 seenUIntMin
= FALSE
;
1072 seenUIntMax
= FALSE
;
1073 seenLongMax
= FALSE
;
1074 seenULongMax
= FALSE
;
1075 seenCharMax
= FALSE
;
1076 seenUCharMax
= FALSE
;
1077 seenUIntMax
= FALSE
;
1082 seenException
= FALSE
;
1083 seenComplex
= FALSE
;
1088 seenSSize_t
= FALSE
;
1089 seenSysTypes
= FALSE
;
1090 initializedCP
= FALSE
;
1091 initializedGCC
= FALSE
;
1100 useUnistd - need to use unistd.h call using open/close/read/write require this header.
1103 extern "C" void keyc_useUnistd (void)
1110 useThrow - use the throw function.
1113 extern "C" void keyc_useThrow (void)
1120 useStorage - indicate we have used storage.
1123 extern "C" void keyc_useStorage (void)
1130 useFree - indicate we have used free.
1133 extern "C" void keyc_useFree (void)
1140 useMalloc - indicate we have used malloc.
1143 extern "C" void keyc_useMalloc (void)
1150 useProc - indicate we have used proc.
1153 extern "C" void keyc_useProc (void)
1160 useTrue - indicate we have used TRUE.
1163 extern "C" void keyc_useTrue (void)
1170 useFalse - indicate we have used FALSE.
1173 extern "C" void keyc_useFalse (void)
1180 useNull - indicate we have used NULL.
1183 extern "C" void keyc_useNull (void)
1190 useMemcpy - indicate we have used memcpy.
1193 extern "C" void keyc_useMemcpy (void)
1200 useIntMin - indicate we have used INT_MIN.
1203 extern "C" void keyc_useIntMin (void)
1210 useUIntMin - indicate we have used UINT_MIN.
1213 extern "C" void keyc_useUIntMin (void)
1220 useLongMin - indicate we have used LONG_MIN.
1223 extern "C" void keyc_useLongMin (void)
1230 useULongMin - indicate we have used ULONG_MIN.
1233 extern "C" void keyc_useULongMin (void)
1235 seenULongMin
= TRUE
;
1240 useCharMin - indicate we have used CHAR_MIN.
1243 extern "C" void keyc_useCharMin (void)
1250 useUCharMin - indicate we have used UCHAR_MIN.
1253 extern "C" void keyc_useUCharMin (void)
1255 seenUCharMin
= TRUE
;
1260 useIntMax - indicate we have used INT_MAX.
1263 extern "C" void keyc_useIntMax (void)
1270 useUIntMax - indicate we have used UINT_MAX.
1273 extern "C" void keyc_useUIntMax (void)
1280 useLongMax - indicate we have used LONG_MAX.
1283 extern "C" void keyc_useLongMax (void)
1290 useULongMax - indicate we have used ULONG_MAX.
1293 extern "C" void keyc_useULongMax (void)
1295 seenULongMax
= TRUE
;
1300 useCharMax - indicate we have used CHAR_MAX.
1303 extern "C" void keyc_useCharMax (void)
1310 useUCharMax - indicate we have used UChar_MAX.
1313 extern "C" void keyc_useUCharMax (void)
1315 seenUCharMax
= TRUE
;
1320 useSize_t - indicate we have used size_t.
1323 extern "C" void keyc_useSize_t (void)
1330 useSSize_t - indicate we have used ssize_t.
1333 extern "C" void keyc_useSSize_t (void)
1336 seenSysTypes
= TRUE
;
1341 useLabs - indicate we have used labs.
1344 extern "C" void keyc_useLabs (void)
1351 useAbs - indicate we have used abs.
1354 extern "C" void keyc_useAbs (void)
1361 useFabs - indicate we have used fabs.
1364 extern "C" void keyc_useFabs (void)
1371 useFabsl - indicate we have used fabsl.
1374 extern "C" void keyc_useFabsl (void)
1381 useException - use the exceptions module, mcrts.
1384 extern "C" void keyc_useException (void)
1386 seenException
= TRUE
;
1391 useComplex - use the complex data type.
1394 extern "C" void keyc_useComplex (void)
1401 useM2RTS - indicate we have used M2RTS in the converted code.
1404 extern "C" void keyc_useM2RTS (void)
1411 useStrlen - indicate we have used strlen in the converted code.
1414 extern "C" void keyc_useStrlen (void)
1421 useCtype - indicate we have used the toupper function.
1424 extern "C" void keyc_useCtype (void)
1431 genDefs - generate definitions or includes for all
1432 macros and prototypes used.
1435 extern "C" void keyc_genDefs (mcPretty_pretty p
)
1437 checkFreeMalloc (p
);
1453 fixNullPointerConst (p
);
1458 genConfigSystem - generate include files for config.h and system.h
1459 within the GCC framework.
1462 extern "C" void keyc_genConfigSystem (mcPretty_pretty p
)
1464 checkGccConfigSystem (p
);
1469 enterScope - enter a scope defined by, n.
1472 extern "C" void keyc_enterScope (decl_node n
)
1478 s
->symbols
= symbolKey_initTree ();
1485 leaveScope - leave the scope defined by, n.
1488 extern "C" void keyc_leaveScope (decl_node n
)
1492 if (n
== stack
->scoped
)
1495 stack
= stack
->next
;
1496 s
->scoped
= static_cast<decl_node
> (NULL
);
1497 symbolKey_killTree (&s
->symbols
);
1503 __builtin_unreachable ();
1509 cname - attempts to declare a symbol with name, n, in the
1510 current scope. If there is no conflict with the
1511 target language then NIL is returned, otherwise
1512 a mangled name is returned as a String.
1513 If scopes is FALSE then only the keywords and
1514 macros are detected for a clash (all scoping
1518 extern "C" DynamicStrings_String
keyc_cname (nameKey_Name n
, unsigned int scopes
)
1520 DynamicStrings_String m
;
1522 m
= static_cast<DynamicStrings_String
> (NULL
);
1523 if (clash (n
, scopes
))
1525 if (((mangle1 (n
, &m
, scopes
)) || (mangle2 (n
, &m
, scopes
))) || (mangleN (n
, &m
, scopes
)))
1527 /* avoid dangling else. */
1530 /* no longer a clash with, m, so add it to the current scope. */
1531 n
= nameKey_makekey (DynamicStrings_string (m
));
1532 symbolKey_putSymKey (stack
->symbols
, n
, reinterpret_cast<void *> (m
));
1537 /* mangleN must always succeed. */
1539 __builtin_unreachable ();
1544 /* avoid dangling else. */
1545 /* no clash, add it to the current scope. */
1546 symbolKey_putSymKey (stack
->symbols
, n
, reinterpret_cast<void *> (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
))));
1549 /* static analysis guarentees a RETURN statement will be used before here. */
1550 __builtin_unreachable ();
1555 cnamen - attempts to declare a symbol with name, n, in the
1556 current scope. If there is no conflict with the
1557 target language then NIL is returned, otherwise
1558 a mangled name is returned as a Name
1559 If scopes is FALSE then only the keywords and
1560 macros are detected for a clash (all scoping
1564 extern "C" nameKey_Name
keyc_cnamen (nameKey_Name n
, unsigned int scopes
)
1566 DynamicStrings_String m
;
1568 m
= static_cast<DynamicStrings_String
> (NULL
);
1569 if (clash (n
, scopes
))
1571 if (((mangle1 (n
, &m
, scopes
)) || (mangle2 (n
, &m
, scopes
))) || (mangleN (n
, &m
, scopes
)))
1573 /* avoid dangling else. */
1574 n
= nameKey_makekey (DynamicStrings_string (m
));
1577 /* no longer a clash with, m, so add it to the current scope. */
1578 symbolKey_putSymKey (stack
->symbols
, n
, reinterpret_cast<void *> (m
));
1583 /* mangleN must always succeed. */
1585 __builtin_unreachable ();
1590 /* avoid dangling else. */
1591 /* no clash, add it to the current scope. */
1592 symbolKey_putSymKey (stack
->symbols
, n
, reinterpret_cast<void *> (DynamicStrings_InitStringCharStar (nameKey_keyToCharStar (n
))));
1594 m
= DynamicStrings_KillString (m
);
1596 /* static analysis guarentees a RETURN statement will be used before here. */
1597 __builtin_unreachable ();
1602 cp - include C++ keywords and standard declarations to avoid.
1605 extern "C" void keyc_cp (void)
1607 if (! initializedCP
)
1609 initializedCP
= TRUE
;
1614 extern "C" void _M2_keyc_init (__attribute__((unused
)) int argc
,__attribute__((unused
)) char *argv
[],__attribute__((unused
)) char *envp
[])
1619 extern "C" void _M2_keyc_finish (__attribute__((unused
)) int argc
,__attribute__((unused
)) char *argv
[],__attribute__((unused
)) char *envp
[])