Debian Codegraph @

gcc/m2/mc-boot/GmcOptions.cc

raw
1 /* do not edit automatically generated by mc from mcOptions. */
2 /* This file is part of GNU Modula-2.
3
4 GNU Modula-2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 3, or (at your option) any later
7 version.
8
9 GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with GCC; see the file COPYING3. If not see
16 <http://www.gnu.org/licenses/>. */
17
18 #include "config.h"
19 #include "system.h"
20 #include <stdbool.h>
21 # if !defined (PROC_D)
22 # define PROC_D
23 typedef void (*PROC_t) (void);
24 typedef struct { PROC_t proc; } PROC;
25 # endif
26
27 # if !defined (TRUE)
28 # define TRUE (1==1)
29 # endif
30
31 # if !defined (FALSE)
32 # define FALSE (1==0)
33 # endif
34
35 #if defined(__cplusplus)
36 # undef NULL
37 # define NULL 0
38 #endif
39 #define _mcOptions_C
40
41 #include "GmcOptions.h"
42 # include "GSArgs.h"
43 # include "GmcSearch.h"
44 # include "Glibc.h"
45 # include "GmcPrintf.h"
46 # include "GDebug.h"
47 # include "GStrLib.h"
48 # include "Gdecl.h"
49 # include "GDynamicStrings.h"
50 # include "GFIO.h"
51 # include "GSFIO.h"
52
53 static bool langC;
54 static bool langCPP;
55 static bool langM2;
56 static bool gplHeader;
57 static bool glplHeader;
58 static bool summary;
59 static bool contributed;
60 static bool scaffoldMain;
61 static bool scaffoldDynamic;
62 static bool caseRuntime;
63 static bool arrayRuntime;
64 static bool returnRuntime;
65 static bool suppressNoReturn;
66 static bool useBoolType;
67 static bool gccConfigSystem;
68 static bool ignoreFQ;
69 static bool debugTopological;
70 static bool extendedOpaque;
71 static bool internalDebugging;
72 static bool verbose;
73 static bool quiet;
74 static DynamicStrings_String CReal;
75 static DynamicStrings_String CLongReal;
76 static DynamicStrings_String CShortReal;
77 static DynamicStrings_String projectContents;
78 static DynamicStrings_String summaryContents;
79 static DynamicStrings_String contributedContents;
80 static DynamicStrings_String hPrefix;
81 static DynamicStrings_String outputFile;
82 static DynamicStrings_String cppArgs;
83 static DynamicStrings_String cppProgram;
84
85 /*
86 handleOptions - iterates over all options setting appropriate
87 values and returns the single source file
88 if found at the end of the arguments.
89 */
90
91 extern "C" DynamicStrings_String mcOptions_handleOptions (void);
92
93 /*
94 getQuiet - return the value of quiet.
95 */
96
97 extern "C" bool mcOptions_getQuiet (void);
98
99 /*
100 getVerbose - return the value of verbose.
101 */
102
103 extern "C" bool mcOptions_getVerbose (void);
104
105 /*
106 getInternalDebugging - return the value of internalDebugging.
107 */
108
109 extern "C" bool mcOptions_getInternalDebugging (void);
110
111 /*
112 getCppCommandLine - returns the Cpp command line and all arguments.
113 */
114
115 extern "C" DynamicStrings_String mcOptions_getCppCommandLine (void);
116
117 /*
118 getOutputFile - sets the output filename to output.
119 */
120
121 extern "C" DynamicStrings_String mcOptions_getOutputFile (void);
122
123 /*
124 getExtendedOpaque - return the extendedOpaque value.
125 */
126
127 extern "C" bool mcOptions_getExtendedOpaque (void);
128
129 /*
130 setDebugTopological - sets the flag debugTopological to value.
131 */
132
133 extern "C" void mcOptions_setDebugTopological (bool value);
134
135 /*
136 getDebugTopological - returns the flag value of the command
137 line option --debug-top.
138 */
139
140 extern "C" bool mcOptions_getDebugTopological (void);
141
142 /*
143 getHPrefix - saves the H file prefix.
144 */
145
146 extern "C" DynamicStrings_String mcOptions_getHPrefix (void);
147
148 /*
149 getIgnoreFQ - returns the ignorefq flag.
150 */
151
152 extern "C" bool mcOptions_getIgnoreFQ (void);
153
154 /*
155 getGccConfigSystem - return the value of the gccConfigSystem flag.
156 */
157
158 extern "C" bool mcOptions_getGccConfigSystem (void);
159
160 /*
161 getScaffoldDynamic - return true if the --scaffold-dynamic option was present.
162 */
163
164 extern "C" bool mcOptions_getScaffoldDynamic (void);
165
166 /*
167 getScaffoldMain - return true if the --scaffold-main option was present.
168 */
169
170 extern "C" bool mcOptions_getScaffoldMain (void);
171
172 /*
173 writeGPLheader - writes out the GPL or the LGPL as a comment.
174 */
175
176 extern "C" void mcOptions_writeGPLheader (FIO_File f);
177
178 /*
179 setSuppressNoReturn - set suppressNoReturn to value.
180 */
181
182 extern "C" void mcOptions_setSuppressNoReturn (bool value);
183
184 /*
185 getSuppressNoReturn - return the suppressNoReturn value.
186 */
187
188 extern "C" bool mcOptions_getSuppressNoReturn (void);
189
190 /*
191 useBool - should mc use the bool type instead of int.
192 */
193
194 extern "C" bool mcOptions_useBool (void);
195
196 /*
197 getCRealType - returns the string representing the REAL type
198 used by C. By default this is "double".
199 */
200
201 extern "C" DynamicStrings_String mcOptions_getCRealType (void);
202
203 /*
204 getCLongRealType - returns the string representing the REAL type
205 used by C. By default this is "long double".
206 */
207
208 extern "C" DynamicStrings_String mcOptions_getCLongRealType (void);
209
210 /*
211 getCShortRealType - returns the string representing the REAL type
212 used by C. By default this is "float".
213 */
214
215 extern "C" DynamicStrings_String mcOptions_getCShortRealType (void);
216
217 /*
218 getYear - return the year.
219 */
220
221 static unsigned int getYear (void);
222
223 /*
224 displayVersion - displays the version of the compiler.
225 */
226
227 static void displayVersion (bool mustExit);
228
229 /*
230 displayHelp - display the mc help summary.
231 */
232
233 static void displayHelp (void);
234
235 /*
236 commentBegin - issue a start of comment for the appropriate language.
237 */
238
239 static void commentBegin (FIO_File f);
240
241 /*
242 commentEnd - issue an end of comment for the appropriate language.
243 */
244
245 static void commentEnd (FIO_File f);
246
247 /*
248 comment - write a comment to file, f, and also a newline.
249 */
250
251 static void comment (FIO_File f, const char *a_, unsigned int _a_high);
252
253 /*
254 commentS - write a comment to file, f, and also a newline.
255 */
256
257 static void commentS (FIO_File f, DynamicStrings_String s);
258
259 /*
260 gplBody -
261 */
262
263 static void gplBody (FIO_File f);
264
265 /*
266 glplBody -
267 */
268
269 static void glplBody (FIO_File f);
270
271 /*
272 issueGPL - writes out the summary, GPL/LGPL and/or contributed as a single comment.
273 */
274
275 static void issueGPL (FIO_File f);
276
277 /*
278 setOutputFile - sets the output filename to output.
279 */
280
281 static void setOutputFile (DynamicStrings_String output);
282
283 /*
284 setQuiet - sets the quiet flag to, value.
285 */
286
287 static void setQuiet (bool value);
288
289 /*
290 setVerbose - sets the verbose flag to, value.
291 */
292
293 static void setVerbose (bool value);
294
295 /*
296 setExtendedOpaque - set extendedOpaque to value.
297 */
298
299 static void setExtendedOpaque (bool value);
300
301 /*
302 setSearchPath - set the search path for the module sources.
303 */
304
305 static void setSearchPath (DynamicStrings_String arg);
306
307 /*
308 setInternalDebugging - turn on/off internal debugging.
309 */
310
311 static void setInternalDebugging (bool value);
312
313 /*
314 setHPrefix - saves the H file prefix.
315 */
316
317 static void setHPrefix (DynamicStrings_String s);
318
319 /*
320 setIgnoreFQ - sets the ignorefq flag.
321 */
322
323 static void setIgnoreFQ (bool value);
324
325 /*
326 toCType - returns a new string which has all occurences of '-'
327 replaced by ' '.
328 */
329
330 static DynamicStrings_String toCType (DynamicStrings_String namedType);
331
332 /*
333 setCReal - assigns CReal to namedType after it has been transformed by
334 toCType.
335 */
336
337 static void setCReal (DynamicStrings_String namedType);
338
339 /*
340 setCShortReal - assigns CShortReal to namedType after it has been
341 transformed by toCType.
342 */
343
344 static void setCShortReal (DynamicStrings_String namedType);
345
346 /*
347 setCLongReal - assigns CLongReal to namedType after it has been
348 transformed by toCType.
349 */
350
351 static void setCLongReal (DynamicStrings_String namedType);
352
353 /*
354 optionIs - returns TRUE if the first len (right) characters
355 match left.
356 */
357
358 static bool optionIs (const char *left_, unsigned int _left_high, DynamicStrings_String right);
359
360 /*
361 setLang - set the appropriate output language.
362 */
363
364 static void setLang (DynamicStrings_String arg);
365
366 /*
367 handleOption -
368 */
369
370 static void handleOption (DynamicStrings_String arg);
371
372
373 /*
374 getYear - return the year.
375 */
376
377 static unsigned int getYear (void)
378 {
379 libc_time_t epoch;
380 libc_ptrToTM localTime;
381
382 epoch = libc_time (NULL);
383 localTime = static_cast<libc_ptrToTM> (libc_localtime (&epoch));
384 return localTime->tm_year+1900;
385 /* static analysis guarentees a RETURN statement will be used before here. */
386 __builtin_unreachable ();
387 }
388
389
390 /*
391 displayVersion - displays the version of the compiler.
392 */
393
394 static void displayVersion (bool mustExit)
395 {
396 unsigned int year;
397
398 year = getYear ();
399 /* These first three calls to printf hide the first line of text away from the year change script. */
400 mcPrintf_printf0 ((const char *) "Copyright ", 10);
401 mcPrintf_printf0 ((const char *) "(C)", 3); /* A unicode char here would be good. */
402 mcPrintf_printf1 ((const char *) " %d Free Software Foundation, Inc.\\n", 36, (const unsigned char *) &year, (sizeof (year)-1)); /* A unicode char here would be good. */
403 mcPrintf_printf0 ((const char *) "License GPLv3: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\\n", 78);
404 mcPrintf_printf0 ((const char *) "This is free software: you are free to change and redistribute it.\\n", 68);
405 mcPrintf_printf0 ((const char *) "There is NO WARRANTY, to the extent permitted by law.\\n", 55);
406 if (mustExit)
407 {
408 libc_exit (0);
409 }
410 }
411
412
413 /*
414 displayHelp - display the mc help summary.
415 */
416
417 static void displayHelp (void)
418 {
419 mcPrintf_printf0 ((const char *) "usage: mc [--cpp] [-g] [--quiet] [--extended-opaque] [-q] [-v]", 62);
420 mcPrintf_printf0 ((const char *) " [--verbose] [--version] [--help] [-h] [-Ipath] [--olang=c]", 59);
421 mcPrintf_printf0 ((const char *) " [--olang=c++] [--olang=m2] [--debug-top]", 41);
422 mcPrintf_printf0 ((const char *) " [--gpl-header] [--glpl-header] [--summary=\"foo\"]", 49);
423 mcPrintf_printf0 ((const char *) " [--contributed=\"foo\"] [--project=\"foo\"]", 40);
424 mcPrintf_printf0 ((const char *) " [--h-file-prefix=foo] [--automatic] [-o=foo] filename\\n", 56);
425 mcPrintf_printf0 ((const char *) " --cpp preprocess through the C preprocessor\\n", 61);
426 mcPrintf_printf0 ((const char *) " -g emit debugging directives in the output language", 70);
427 mcPrintf_printf0 ((const char *) " so that the debugger will refer to the source\\n", 69);
428 mcPrintf_printf0 ((const char *) " -q --quiet no output unless an error occurs\\n", 56);
429 mcPrintf_printf0 ((const char *) " -v --verbose display preprocessor if invoked\\n", 55);
430 mcPrintf_printf0 ((const char *) " --version display version and exit\\n", 48);
431 mcPrintf_printf0 ((const char *) " -h --help display this help message\\n", 49);
432 mcPrintf_printf0 ((const char *) " -Ipath set the module search path\\n", 50);
433 mcPrintf_printf0 ((const char *) " --olang=c generate ansi C output\\n", 46);
434 mcPrintf_printf0 ((const char *) " --olang=c++ generate ansi C++ output\\n", 48);
435 mcPrintf_printf0 ((const char *) " --olang=m2 generate PIM4 output\\n", 44);
436 mcPrintf_printf0 ((const char *) " --extended-opaque parse definition and implementation modules to\\n", 70);
437 mcPrintf_printf0 ((const char *) " generate full type debugging of opaque types\\n", 68);
438 mcPrintf_printf0 ((const char *) " --debug-top debug topological data structure resolving (internal)\\n", 77);
439 mcPrintf_printf0 ((const char *) " --h-file-prefix=foo set the h file prefix to foo\\n", 52);
440 mcPrintf_printf0 ((const char *) " -o=foo set the output file to foo\\n", 50);
441 mcPrintf_printf0 ((const char *) " --ignore-fq do not generate fully qualified idents\\n", 62);
442 mcPrintf_printf0 ((const char *) " --gcc-config-system do not use standard host include files, use gcc config and system instead\\n", 97);
443 mcPrintf_printf0 ((const char *) " --gpl-header generate a GPL3 header comment at the top of the file\\n", 77);
444 mcPrintf_printf0 ((const char *) " --glpl-header generate a GLPL3 header comment at the top of the file\\n", 78);
445 mcPrintf_printf0 ((const char *) " --summary=\"foo\" generate a one line summary comment at the top of the file\\n", 82);
446 mcPrintf_printf0 ((const char *) " --contributed=\"foo\" generate a one line contribution comment near the top of the file\\n", 89);
447 mcPrintf_printf0 ((const char *) " --project=\"foo\" include the project name within the GPL3 or GLPL3 header\\n", 80);
448 mcPrintf_printf0 ((const char *) " --automatic generate a comment at the start of the file warning not to edit as it was automatically generated\\n", 121);
449 mcPrintf_printf0 ((const char *) " --scaffold-dynamic generate dynamic module initialization code for C++\\n", 75);
450 mcPrintf_printf0 ((const char *) " --scaffold-main generate main function which calls upon the dynamic initialization support in M2RTS\\n", 107);
451 mcPrintf_printf0 ((const char *) " --suppress-noreturn suppress the emission of any attribute noreturn\\n", 71);
452 mcPrintf_printf0 ((const char *) " filename the source file must be the last option\\n", 63);
453 libc_exit (0);
454 }
455
456
457 /*
458 commentBegin - issue a start of comment for the appropriate language.
459 */
460
461 static void commentBegin (FIO_File f)
462 {
463 if (langC || langCPP)
464 {
465 FIO_WriteString (f, (const char *) "/* ", 3);
466 }
467 else if (langM2)
468 {
469 /* avoid dangling else. */
470 FIO_WriteString (f, (const char *) "(* ", 3);
471 }
472 }
473
474
475 /*
476 commentEnd - issue an end of comment for the appropriate language.
477 */
478
479 static void commentEnd (FIO_File f)
480 {
481 if (langC || langCPP)
482 {
483 FIO_WriteString (f, (const char *) " */", 3);
484 FIO_WriteLine (f);
485 }
486 else if (langM2)
487 {
488 /* avoid dangling else. */
489 FIO_WriteString (f, (const char *) " *)", 3);
490 FIO_WriteLine (f);
491 }
492 }
493
494
495 /*
496 comment - write a comment to file, f, and also a newline.
497 */
498
499 static void comment (FIO_File f, const char *a_, unsigned int _a_high)
500 {
501 char a[_a_high+1];
502
503 /* make a local copy of each unbounded array. */
504 memcpy (a, a_, _a_high+1);
505
506 FIO_WriteString (f, (const char *) a, _a_high);
507 FIO_WriteLine (f);
508 }
509
510
511 /*
512 commentS - write a comment to file, f, and also a newline.
513 */
514
515 static void commentS (FIO_File f, DynamicStrings_String s)
516 {
517 s = SFIO_WriteS (f, s);
518 FIO_WriteLine (f);
519 }
520
521
522 /*
523 gplBody -
524 */
525
526 static void gplBody (FIO_File f)
527 {
528 unsigned int year;
529
530 year = getYear ();
531 mcPrintf_printf1 ((const char *) "Copyright (C) %d Free Software Foundation, Inc.\\n", 49, (const unsigned char *) &year, (sizeof (year)-1));
532 if (contributed)
533 {
534 FIO_WriteString (f, (const char *) "Contributed by ", 15);
535 contributedContents = SFIO_WriteS (f, contributedContents);
536 FIO_WriteString (f, (const char *) ".", 1);
537 FIO_WriteLine (f);
538 }
539 FIO_WriteLine (f);
540 FIO_WriteString (f, (const char *) "This file is part of ", 21);
541 projectContents = SFIO_WriteS (f, projectContents);
542 FIO_WriteString (f, (const char *) ".", 1);
543 FIO_WriteLine (f);
544 FIO_WriteLine (f);
545 projectContents = SFIO_WriteS (f, projectContents);
546 comment (f, (const char *) " is software; you can redistribute it and/or modify", 51);
547 comment (f, (const char *) "it under the terms of the GNU General Public License as published by", 68);
548 comment (f, (const char *) "the Free Software Foundation; either version 3, or (at your option)", 67);
549 comment (f, (const char *) "any later version.", 18);
550 FIO_WriteLine (f);
551 projectContents = SFIO_WriteS (f, projectContents);
552 comment (f, (const char *) " is distributed in the hope that it will be useful, but", 55);
553 comment (f, (const char *) "WITHOUT ANY WARRANTY; without even the implied warranty of", 58);
554 comment (f, (const char *) "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU", 65);
555 comment (f, (const char *) "General Public License for more details.", 40);
556 FIO_WriteLine (f);
557 comment (f, (const char *) "You should have received a copy of the GNU General Public License", 65);
558 FIO_WriteString (f, (const char *) "along with ", 11);
559 projectContents = SFIO_WriteS (f, projectContents);
560 comment (f, (const char *) "; see the file COPYING. If not,", 32);
561 FIO_WriteString (f, (const char *) "see <https://www.gnu.org/licenses/>. ", 37);
562 }
563
564
565 /*
566 glplBody -
567 */
568
569 static void glplBody (FIO_File f)
570 {
571 unsigned int year;
572
573 year = getYear ();
574 mcPrintf_printf1 ((const char *) "Copyright (C) %d Free Software Foundation, Inc.\\n", 49, (const unsigned char *) &year, (sizeof (year)-1));
575 if (contributed)
576 {
577 FIO_WriteString (f, (const char *) "Contributed by ", 15);
578 contributedContents = SFIO_WriteS (f, contributedContents);
579 FIO_WriteString (f, (const char *) ".", 1);
580 FIO_WriteLine (f);
581 }
582 FIO_WriteLine (f);
583 FIO_WriteString (f, (const char *) "This file is part of ", 21);
584 projectContents = SFIO_WriteS (f, projectContents);
585 FIO_WriteString (f, (const char *) ".", 1);
586 FIO_WriteLine (f);
587 FIO_WriteLine (f);
588 projectContents = SFIO_WriteS (f, projectContents);
589 comment (f, (const char *) " is free software; you can redistribute it and/or modify", 56);
590 comment (f, (const char *) "it under the terms of the GNU General Public License as published by", 68);
591 comment (f, (const char *) "the Free Software Foundation; either version 3, or (at your option)", 67);
592 comment (f, (const char *) "any later version.", 18);
593 FIO_WriteLine (f);
594 projectContents = SFIO_WriteS (f, projectContents);
595 comment (f, (const char *) " is software; you can redistribute it and/or modify", 51);
596 comment (f, (const char *) "it under the terms of the GNU Lesser General Public License", 59);
597 comment (f, (const char *) "as published by the Free Software Foundation; either version 3,", 63);
598 comment (f, (const char *) "or (at your option) any later version.", 38);
599 FIO_WriteLine (f);
600 projectContents = SFIO_WriteS (f, projectContents);
601 comment (f, (const char *) " is distributed in the hope that it will be useful, but", 55);
602 comment (f, (const char *) "WITHOUT ANY WARRANTY; without even the implied warranty of", 58);
603 comment (f, (const char *) "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU", 65);
604 comment (f, (const char *) "General Public License for more details.", 40);
605 FIO_WriteLine (f);
606 comment (f, (const char *) "You should have received a copy of the GNU General Public License", 65);
607 FIO_WriteString (f, (const char *) "along with ", 11);
608 projectContents = SFIO_WriteS (f, projectContents);
609 comment (f, (const char *) "; see the file COPYING3. If not see", 36);
610 comment (f, (const char *) "<http://www.gnu.org/licenses/>.", 31);
611 FIO_WriteLine (f);
612 comment (f, (const char *) "You should have received a copy of the GNU Lesser General Public License", 72);
613 FIO_WriteString (f, (const char *) "along with ", 11);
614 projectContents = SFIO_WriteS (f, projectContents);
615 comment (f, (const char *) "; see the file COPYING. If not,", 32);
616 FIO_WriteString (f, (const char *) "see <https://www.gnu.org/licenses/>. ", 37);
617 }
618
619
620 /*
621 issueGPL - writes out the summary, GPL/LGPL and/or contributed as a single comment.
622 */
623
624 static void issueGPL (FIO_File f)
625 {
626 if (((summary || contributed) || gplHeader) || glplHeader)
627 {
628 commentBegin (f);
629 if (summary)
630 {
631 commentS (f, summaryContents);
632 FIO_WriteLine (f);
633 }
634 if (gplHeader)
635 {
636 gplBody (f);
637 }
638 if (glplHeader)
639 {
640 glplBody (f);
641 }
642 commentEnd (f);
643 FIO_WriteLine (f);
644 }
645 }
646
647
648 /*
649 setOutputFile - sets the output filename to output.
650 */
651
652 static void setOutputFile (DynamicStrings_String output)
653 {
654 outputFile = output;
655 }
656
657
658 /*
659 setQuiet - sets the quiet flag to, value.
660 */
661
662 static void setQuiet (bool value)
663 {
664 quiet = value;
665 }
666
667
668 /*
669 setVerbose - sets the verbose flag to, value.
670 */
671
672 static void setVerbose (bool value)
673 {
674 verbose = value;
675 }
676
677
678 /*
679 setExtendedOpaque - set extendedOpaque to value.
680 */
681
682 static void setExtendedOpaque (bool value)
683 {
684 extendedOpaque = value;
685 }
686
687
688 /*
689 setSearchPath - set the search path for the module sources.
690 */
691
692 static void setSearchPath (DynamicStrings_String arg)
693 {
694 mcSearch_prependSearchPath (arg);
695 }
696
697
698 /*
699 setInternalDebugging - turn on/off internal debugging.
700 */
701
702 static void setInternalDebugging (bool value)
703 {
704 internalDebugging = value;
705 }
706
707
708 /*
709 setHPrefix - saves the H file prefix.
710 */
711
712 static void setHPrefix (DynamicStrings_String s)
713 {
714 hPrefix = s;
715 }
716
717
718 /*
719 setIgnoreFQ - sets the ignorefq flag.
720 */
721
722 static void setIgnoreFQ (bool value)
723 {
724 ignoreFQ = value;
725 }
726
727
728 /*
729 toCType - returns a new string which has all occurences of '-'
730 replaced by ' '.
731 */
732
733 static DynamicStrings_String toCType (DynamicStrings_String namedType)
734 {
735 return DynamicStrings_ReplaceChar (DynamicStrings_Dup (namedType), '-', ' ');
736 /* static analysis guarentees a RETURN statement will be used before here. */
737 __builtin_unreachable ();
738 }
739
740
741 /*
742 setCReal - assigns CReal to namedType after it has been transformed by
743 toCType.
744 */
745
746 static void setCReal (DynamicStrings_String namedType)
747 {
748 CReal = toCType (namedType);
749 }
750
751
752 /*
753 setCShortReal - assigns CShortReal to namedType after it has been
754 transformed by toCType.
755 */
756
757 static void setCShortReal (DynamicStrings_String namedType)
758 {
759 CShortReal = toCType (namedType);
760 }
761
762
763 /*
764 setCLongReal - assigns CLongReal to namedType after it has been
765 transformed by toCType.
766 */
767
768 static void setCLongReal (DynamicStrings_String namedType)
769 {
770 CLongReal = toCType (namedType);
771 }
772
773
774 /*
775 optionIs - returns TRUE if the first len (right) characters
776 match left.
777 */
778
779 static bool optionIs (const char *left_, unsigned int _left_high, DynamicStrings_String right)
780 {
781 DynamicStrings_String s;
782 char left[_left_high+1];
783
784 /* make a local copy of each unbounded array. */
785 memcpy (left, left_, _left_high+1);
786
787 if ((DynamicStrings_Length (right)) == (StrLib_StrLen ((const char *) left, _left_high)))
788 {
789 return DynamicStrings_EqualArray (right, (const char *) left, _left_high);
790 }
791 else if ((DynamicStrings_Length (right)) > (StrLib_StrLen ((const char *) left, _left_high)))
792 {
793 /* avoid dangling else. */
794 s = DynamicStrings_Mark (DynamicStrings_Slice (right, 0, static_cast<int> (StrLib_StrLen ((const char *) left, _left_high))));
795 return DynamicStrings_EqualArray (s, (const char *) left, _left_high);
796 }
797 else
798 {
799 /* avoid dangling else. */
800 return false;
801 }
802 /* static analysis guarentees a RETURN statement will be used before here. */
803 __builtin_unreachable ();
804 }
805
806
807 /*
808 setLang - set the appropriate output language.
809 */
810
811 static void setLang (DynamicStrings_String arg)
812 {
813 /* must check the longest distinctive string first. */
814 if (optionIs ((const char *) "c++", 3, arg))
815 {
816 decl_setLangCP ();
817 langCPP = true;
818 }
819 else if (optionIs ((const char *) "c", 1, arg))
820 {
821 /* avoid dangling else. */
822 decl_setLangC ();
823 langC = true;
824 }
825 else if (optionIs ((const char *) "m2", 2, arg))
826 {
827 /* avoid dangling else. */
828 decl_setLangM2 ();
829 langM2 = true;
830 }
831 else
832 {
833 /* avoid dangling else. */
834 displayHelp ();
835 }
836 }
837
838
839 /*
840 handleOption -
841 */
842
843 static void handleOption (DynamicStrings_String arg)
844 {
845 if ((optionIs ((const char *) "--quiet", 7, arg)) || (optionIs ((const char *) "-q", 2, arg)))
846 {
847 setQuiet (true);
848 }
849 else if ((optionIs ((const char *) "--verbose", 9, arg)) || (optionIs ((const char *) "-v", 2, arg)))
850 {
851 /* avoid dangling else. */
852 setVerbose (true);
853 }
854 else if (optionIs ((const char *) "--version", 9, arg))
855 {
856 /* avoid dangling else. */
857 displayVersion (true);
858 }
859 else if (optionIs ((const char *) "--olang=", 8, arg))
860 {
861 /* avoid dangling else. */
862 setLang (DynamicStrings_Slice (arg, 8, 0));
863 }
864 else if (optionIs ((const char *) "-I", 2, arg))
865 {
866 /* avoid dangling else. */
867 setSearchPath (DynamicStrings_Slice (arg, 2, 0));
868 }
869 else if ((optionIs ((const char *) "--help", 6, arg)) || (optionIs ((const char *) "-h", 2, arg)))
870 {
871 /* avoid dangling else. */
872 displayHelp ();
873 }
874 else if (optionIs ((const char *) "--cpp", 5, arg))
875 {
876 /* avoid dangling else. */
877 cppProgram = DynamicStrings_InitString ((const char *) "cpp", 3);
878 }
879 else if (optionIs ((const char *) "-o=", 3, arg))
880 {
881 /* avoid dangling else. */
882 setOutputFile (DynamicStrings_Slice (arg, 3, 0));
883 }
884 else if (optionIs ((const char *) "--extended-opaque", 17, arg))
885 {
886 /* avoid dangling else. */
887 /* setExtendedOpaque (TRUE) */
888 mcPrintf_printf0 ((const char *) "IGNORING --extended-opaque - this option is no longer implemented - please adjust the call to mc\\n", 98);
889 }
890 else if (optionIs ((const char *) "--debug-top", 11, arg))
891 {
892 /* avoid dangling else. */
893 mcOptions_setDebugTopological (true);
894 }
895 else if (optionIs ((const char *) "--h-file-prefix=", 16, arg))
896 {
897 /* avoid dangling else. */
898 setHPrefix (DynamicStrings_Slice (arg, 16, 0));
899 }
900 else if (optionIs ((const char *) "--ignore-fq", 11, arg))
901 {
902 /* avoid dangling else. */
903 setIgnoreFQ (true);
904 }
905 else if (optionIs ((const char *) "--gpl-header", 12, arg))
906 {
907 /* avoid dangling else. */
908 gplHeader = true;
909 }
910 else if (optionIs ((const char *) "--glpl-header", 13, arg))
911 {
912 /* avoid dangling else. */
913 glplHeader = true;
914 }
915 else if (optionIs ((const char *) "--summary=\"", 11, arg))
916 {
917 /* avoid dangling else. */
918 summary = true;
919 summaryContents = DynamicStrings_Slice (arg, 11, -1);
920 }
921 else if (optionIs ((const char *) "--contributed=\"", 15, arg))
922 {
923 /* avoid dangling else. */
924 contributed = true;
925 contributedContents = DynamicStrings_Slice (arg, 13, -1);
926 }
927 else if (optionIs ((const char *) "--project=\"", 11, arg))
928 {
929 /* avoid dangling else. */
930 projectContents = DynamicStrings_Slice (arg, 10, -1);
931 }
932 else if (optionIs ((const char *) "--gcc-config-system", 19, arg))
933 {
934 /* avoid dangling else. */
935 gccConfigSystem = true;
936 }
937 else if (optionIs ((const char *) "--scaffold-main", 15, arg))
938 {
939 /* avoid dangling else. */
940 scaffoldMain = true;
941 }
942 else if (optionIs ((const char *) "--scaffold-dynamic", 18, arg))
943 {
944 /* avoid dangling else. */
945 scaffoldDynamic = true;
946 }
947 else if (optionIs ((const char *) "--suppress-noreturn", 19, arg))
948 {
949 /* avoid dangling else. */
950 suppressNoReturn = true;
951 }
952 else if (optionIs ((const char *) "--real=", 7, arg))
953 {
954 /* avoid dangling else. */
955 setCReal (DynamicStrings_Slice (arg, 7, 0));
956 }
957 else if (optionIs ((const char *) "--longreal=", 11, arg))
958 {
959 /* avoid dangling else. */
960 setCLongReal (DynamicStrings_Slice (arg, 11, 0));
961 }
962 else if (optionIs ((const char *) "--shortreal=", 12, arg))
963 {
964 /* avoid dangling else. */
965 setCShortReal (DynamicStrings_Slice (arg, 12, 0));
966 }
967 }
968
969
970 /*
971 handleOptions - iterates over all options setting appropriate
972 values and returns the single source file
973 if found at the end of the arguments.
974 */
975
976 extern "C" DynamicStrings_String mcOptions_handleOptions (void)
977 {
978 unsigned int i;
979 DynamicStrings_String arg;
980
981 i = 1;
982 while (SArgs_GetArg (&arg, i))
983 {
984 if ((DynamicStrings_Length (arg)) > 0)
985 {
986 /* avoid gcc warning by using compound statement even if not strictly necessary. */
987 if ((DynamicStrings_char (arg, 0)) == '-')
988 {
989 handleOption (arg);
990 }
991 else
992 {
993 if (! summary)
994 {
995 summaryContents = DynamicStrings_ConCatChar (DynamicStrings_ConCat (DynamicStrings_InitString ((const char *) "automatically created by mc from ", 33), arg), '.');
996 summary = false;
997 }
998 return arg;
999 }
1000 }
1001 i += 1;
1002 }
1003 return static_cast<DynamicStrings_String> (NULL);
1004 /* static analysis guarentees a RETURN statement will be used before here. */
1005 __builtin_unreachable ();
1006 }
1007
1008
1009 /*
1010 getQuiet - return the value of quiet.
1011 */
1012
1013 extern "C" bool mcOptions_getQuiet (void)
1014 {
1015 return quiet;
1016 /* static analysis guarentees a RETURN statement will be used before here. */
1017 __builtin_unreachable ();
1018 }
1019
1020
1021 /*
1022 getVerbose - return the value of verbose.
1023 */
1024
1025 extern "C" bool mcOptions_getVerbose (void)
1026 {
1027 return verbose;
1028 /* static analysis guarentees a RETURN statement will be used before here. */
1029 __builtin_unreachable ();
1030 }
1031
1032
1033 /*
1034 getInternalDebugging - return the value of internalDebugging.
1035 */
1036
1037 extern "C" bool mcOptions_getInternalDebugging (void)
1038 {
1039 return internalDebugging;
1040 /* static analysis guarentees a RETURN statement will be used before here. */
1041 __builtin_unreachable ();
1042 }
1043
1044
1045 /*
1046 getCppCommandLine - returns the Cpp command line and all arguments.
1047 */
1048
1049 extern "C" DynamicStrings_String mcOptions_getCppCommandLine (void)
1050 {
1051 DynamicStrings_String s;
1052
1053 if (DynamicStrings_EqualArray (cppProgram, (const char *) "", 0))
1054 {
1055 return static_cast<DynamicStrings_String> (NULL);
1056 }
1057 else
1058 {
1059 s = DynamicStrings_Dup (cppProgram);
1060 s = DynamicStrings_ConCat (DynamicStrings_ConCatChar (s, ' '), cppArgs);
1061 if (mcOptions_getQuiet ())
1062 {
1063 s = DynamicStrings_ConCat (DynamicStrings_ConCatChar (s, ' '), DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "-quiet", 6)));
1064 }
1065 return s;
1066 }
1067 /* static analysis guarentees a RETURN statement will be used before here. */
1068 __builtin_unreachable ();
1069 }
1070
1071
1072 /*
1073 getOutputFile - sets the output filename to output.
1074 */
1075
1076 extern "C" DynamicStrings_String mcOptions_getOutputFile (void)
1077 {
1078 return outputFile;
1079 /* static analysis guarentees a RETURN statement will be used before here. */
1080 __builtin_unreachable ();
1081 }
1082
1083
1084 /*
1085 getExtendedOpaque - return the extendedOpaque value.
1086 */
1087
1088 extern "C" bool mcOptions_getExtendedOpaque (void)
1089 {
1090 return extendedOpaque;
1091 /* static analysis guarentees a RETURN statement will be used before here. */
1092 __builtin_unreachable ();
1093 }
1094
1095
1096 /*
1097 setDebugTopological - sets the flag debugTopological to value.
1098 */
1099
1100 extern "C" void mcOptions_setDebugTopological (bool value)
1101 {
1102 debugTopological = value;
1103 }
1104
1105
1106 /*
1107 getDebugTopological - returns the flag value of the command
1108 line option --debug-top.
1109 */
1110
1111 extern "C" bool mcOptions_getDebugTopological (void)
1112 {
1113 return debugTopological;
1114 /* static analysis guarentees a RETURN statement will be used before here. */
1115 __builtin_unreachable ();
1116 }
1117
1118
1119 /*
1120 getHPrefix - saves the H file prefix.
1121 */
1122
1123 extern "C" DynamicStrings_String mcOptions_getHPrefix (void)
1124 {
1125 return hPrefix;
1126 /* static analysis guarentees a RETURN statement will be used before here. */
1127 __builtin_unreachable ();
1128 }
1129
1130
1131 /*
1132 getIgnoreFQ - returns the ignorefq flag.
1133 */
1134
1135 extern "C" bool mcOptions_getIgnoreFQ (void)
1136 {
1137 return ignoreFQ;
1138 /* static analysis guarentees a RETURN statement will be used before here. */
1139 __builtin_unreachable ();
1140 }
1141
1142
1143 /*
1144 getGccConfigSystem - return the value of the gccConfigSystem flag.
1145 */
1146
1147 extern "C" bool mcOptions_getGccConfigSystem (void)
1148 {
1149 return gccConfigSystem;
1150 /* static analysis guarentees a RETURN statement will be used before here. */
1151 __builtin_unreachable ();
1152 }
1153
1154
1155 /*
1156 getScaffoldDynamic - return true if the --scaffold-dynamic option was present.
1157 */
1158
1159 extern "C" bool mcOptions_getScaffoldDynamic (void)
1160 {
1161 return scaffoldDynamic;
1162 /* static analysis guarentees a RETURN statement will be used before here. */
1163 __builtin_unreachable ();
1164 }
1165
1166
1167 /*
1168 getScaffoldMain - return true if the --scaffold-main option was present.
1169 */
1170
1171 extern "C" bool mcOptions_getScaffoldMain (void)
1172 {
1173 return scaffoldMain;
1174 /* static analysis guarentees a RETURN statement will be used before here. */
1175 __builtin_unreachable ();
1176 }
1177
1178
1179 /*
1180 writeGPLheader - writes out the GPL or the LGPL as a comment.
1181 */
1182
1183 extern "C" void mcOptions_writeGPLheader (FIO_File f)
1184 {
1185 issueGPL (f);
1186 }
1187
1188
1189 /*
1190 setSuppressNoReturn - set suppressNoReturn to value.
1191 */
1192
1193 extern "C" void mcOptions_setSuppressNoReturn (bool value)
1194 {
1195 suppressNoReturn = value;
1196 }
1197
1198
1199 /*
1200 getSuppressNoReturn - return the suppressNoReturn value.
1201 */
1202
1203 extern "C" bool mcOptions_getSuppressNoReturn (void)
1204 {
1205 return suppressNoReturn;
1206 /* static analysis guarentees a RETURN statement will be used before here. */
1207 __builtin_unreachable ();
1208 }
1209
1210
1211 /*
1212 useBool - should mc use the bool type instead of int.
1213 */
1214
1215 extern "C" bool mcOptions_useBool (void)
1216 {
1217 return useBoolType;
1218 /* static analysis guarentees a RETURN statement will be used before here. */
1219 __builtin_unreachable ();
1220 }
1221
1222
1223 /*
1224 getCRealType - returns the string representing the REAL type
1225 used by C. By default this is "double".
1226 */
1227
1228 extern "C" DynamicStrings_String mcOptions_getCRealType (void)
1229 {
1230 return CReal;
1231 /* static analysis guarentees a RETURN statement will be used before here. */
1232 __builtin_unreachable ();
1233 }
1234
1235
1236 /*
1237 getCLongRealType - returns the string representing the REAL type
1238 used by C. By default this is "long double".
1239 */
1240
1241 extern "C" DynamicStrings_String mcOptions_getCLongRealType (void)
1242 {
1243 return CLongReal;
1244 /* static analysis guarentees a RETURN statement will be used before here. */
1245 __builtin_unreachable ();
1246 }
1247
1248
1249 /*
1250 getCShortRealType - returns the string representing the REAL type
1251 used by C. By default this is "float".
1252 */
1253
1254 extern "C" DynamicStrings_String mcOptions_getCShortRealType (void)
1255 {
1256 return CShortReal;
1257 /* static analysis guarentees a RETURN statement will be used before here. */
1258 __builtin_unreachable ();
1259 }
1260
1261 extern "C" void _M2_mcOptions_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
1262 {
1263 langC = true;
1264 langCPP = false;
1265 langM2 = false;
1266 gplHeader = false;
1267 glplHeader = false;
1268 summary = false;
1269 contributed = false;
1270 caseRuntime = false;
1271 arrayRuntime = false;
1272 returnRuntime = false;
1273 internalDebugging = false;
1274 quiet = false;
1275 verbose = false;
1276 extendedOpaque = false;
1277 debugTopological = false;
1278 ignoreFQ = false;
1279 gccConfigSystem = false;
1280 scaffoldMain = false;
1281 scaffoldDynamic = false;
1282 suppressNoReturn = false;
1283 useBoolType = true;
1284 hPrefix = DynamicStrings_InitString ((const char *) "", 0);
1285 cppArgs = DynamicStrings_InitString ((const char *) "", 0);
1286 cppProgram = DynamicStrings_InitString ((const char *) "", 0);
1287 outputFile = DynamicStrings_InitString ((const char *) "-", 1);
1288 summaryContents = DynamicStrings_InitString ((const char *) "", 0);
1289 contributedContents = DynamicStrings_InitString ((const char *) "", 0);
1290 projectContents = DynamicStrings_InitString ((const char *) "GNU Modula-2", 12);
1291 CReal = DynamicStrings_InitString ((const char *) "double", 6);
1292 CLongReal = DynamicStrings_InitString ((const char *) "long double", 11);
1293 CShortReal = DynamicStrings_InitString ((const char *) "float", 5);
1294 }
1295
1296 extern "C" void _M2_mcOptions_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
1297 {
1298 }