command line option. This in turn invokes @samp{cpp} with the
following arguments @samp{-traditional -lang-asm}. These options
preserve comments and all quotations. @samp{gm2} treats a @samp{#}
-character in the first column as a preprocessor directive.
+character in the first column as a preprocessor directive unless
+@samp{-fno-cpp} is supplied.
For example here is a module which calls @code{FatalError}
via the macro @code{ERROR}.
PROCEDURE GetObj () : ADDRESS ;
+(*
+ SetCpp - enables the source to be preprocessed and enables the
+ recognition of C preprocessor line directives.
+*)
+
+PROCEDURE SetCpp (value: BOOLEAN) : BOOLEAN ;
+
+
+(*
+ GetCpp - returns TRUE if the C preprocessor was used.
+*)
+
+PROCEDURE GetCpp () : BOOLEAN ;
+
+
+(*
+ GetLineDirectives - returns TRUE if line directives are allowed.
+*)
+
+PROCEDURE GetLineDirectives () : BOOLEAN ;
+
+
(*
SetScaffoldDynamic - set the -fscaffold-dynamic flag.
*)
PROCEDURE SetCC1Quiet (value: BOOLEAN) ;
-(*
- SetCpp -
-*)
-
-PROCEDURE SetCpp (value: BOOLEAN) : BOOLEAN ;
-
-
-(*
- GetCpp - returns TRUE if the C preprocessor was used.
-*)
-
-PROCEDURE GetCpp () : BOOLEAN ;
-
-
(*
SetM2g - set the -fm2-g flag.
*)
END GetCpp ;
+(*
+ GetLineDirectives - returns TRUE if line directives are allowed.
+*)
+
+PROCEDURE GetLineDirectives () : BOOLEAN ;
+BEGIN
+ RETURN LineDirectives
+END GetLineDirectives ;
+
+
(*
SetPPOnly - set the PPonly (preprocess only) to value.
*)
EXTERN void M2Options_SetDebugFunctionLineNumbers (bool value);
EXTERN void M2Options_SetGenerateStatementNote (bool value);
EXTERN bool M2Options_GetCpp (void);
+EXTERN bool M2Options_GetLineDirectives (void);
EXTERN bool M2Options_GetM2g (void);
EXTERN bool M2Options_SetM2g (bool value);
EXTERN bool M2Options_SetLowerCaseKeywords (bool value);
switch (code)
{
case OPT_fcpp:
- gcc_checking_assert (building_cpp_command);
+ if (value)
+ gcc_checking_assert (building_cpp_command);
break;
case OPT_fcpp_begin:
in_cpp_args = true;
<COMMENTC>. { updatepos(); skippos(); }
<COMMENTC>\n.* { consumeLine(); }
<COMMENTC>"*/" { endOfCComment(); }
-^\#.* { consumeLine(); /* printf("found: %s\n", currentLine->linebuf); */ BEGIN LINE0; }
-\n\#.* { consumeLine(); /* printf("found: %s\n", currentLine->linebuf); */ BEGIN LINE0; }
+^\#.* { consumeLine(); /* printf("found: %s\n", currentLine->linebuf); */
+ if (M2Options_GetLineDirectives ())
+ BEGIN LINE0;
+ }
+\n\#.* { consumeLine(); /* printf("found: %s\n", currentLine->linebuf); */
+ if (M2Options_GetLineDirectives ())
+ BEGIN LINE0;
+ }
<LINE0>\#[ \t]* { updatepos(); }
<LINE0>[0-9]+[ \t]*\" { updatepos(); lineno=atoi(yytext); BEGIN LINE1; }
<LINE0>\n { m2flex_M2Error("missing initial quote after #line directive"); resetpos(); BEGIN INITIAL; }
--- /dev/null
+MODULE hashfirstcolumn2 ;
+
+FROM libc IMPORT printf, exit ;
+
+VAR
+ x, y: CARDINAL ;
+BEGIN
+ x := 1 ;
+ y := 2 ;
+ IF x
+# y
+ THEN
+ printf ("success\n");
+ ELSE
+ printf ("failure\n");
+ exit (1)
+ END
+END hashfirstcolumn2.
--- /dev/null
+# Copyright (C) 2024 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+# This file was written by Gaius Mulley (gaius.mulley@southwales.ac.uk)
+# for GNU Modula-2.
+
+if $tracelevel then {
+ strace $tracelevel
+}
+
+# load support procs
+load_lib gm2-torture.exp
+
+gm2_init_pim "${srcdir}/gm2/pim/fail ${srcdir}/gm2/imports/fail"
+
+foreach testcase [lsort [glob -nocomplain $srcdir/$subdir/*.mod]] {
+ # If we're only testing specific files and this isn't one of them, skip it.
+ if ![runtest_file_p $runtests $testcase] then {
+ continue
+ }
+
+ gm2-torture-fail $testcase
+}
--- /dev/null
+MODULE localmodule2 ;
+
+FROM libc IMPORT printf ;
+
+PROCEDURE mult2 (n: CARDINAL) : CARDINAL ;
+BEGIN
+ RETURN 2*n
+END mult2 ;
+
+MODULE local ;
+
+ EXPORT mysqr ;
+ IMPORT mult2 ;
+
+ PROCEDURE mysqr (n: CARDINAL) : CARDINAL ;
+ BEGIN
+ RETURN mult2 (n) * mult2 (n)
+ END mysqr ;
+
+END local ;
+
+VAR
+ d: CARDINAL ;
+BEGIN
+ d := mysqr (3) ;
+ printf ("sqr (3 * 2) = %d\n", d)
+END localmodule2.
--- /dev/null
+MODULE localmodule ;
+
+FROM libc IMPORT printf ;
+
+PROCEDURE mult2 (n: CARDINAL) : CARDINAL ;
+BEGIN
+ RETURN 2*n
+END mult2 ;
+
+MODULE local ;
+
+ IMPORT mult2 ;
+ EXPORT mysqr ;
+
+ PROCEDURE mysqr (n: CARDINAL) : CARDINAL ;
+ BEGIN
+ RETURN mult2 (n) * mult2 (n)
+ END mysqr ;
+
+END local ;
+
+VAR
+ d: CARDINAL ;
+BEGIN
+ d := mysqr (3) ;
+ printf ("sqr (3 * 2) = %d\n", d)
+END localmodule.