diff options
author | Gaius Mulley <gaiusmod2@gmail.com> | 2023-06-07 01:21:19 +0100 |
---|---|---|
committer | Gaius Mulley <gaiusmod2@gmail.com> | 2023-06-07 01:21:19 +0100 |
commit | 29c82c6ca929e0f5eccfe038dea71177d814c6b7 (patch) | |
tree | 6b65112e9a6715a0a417e0c01c1517a914c8335b | |
parent | 4f0d4825fa489cc1875c94ab405a800a8d76e506 (diff) | |
download | gcc-29c82c6ca929e0f5eccfe038dea71177d814c6b7.zip gcc-29c82c6ca929e0f5eccfe038dea71177d814c6b7.tar.gz gcc-29c82c6ca929e0f5eccfe038dea71177d814c6b7.tar.bz2 |
PR modula2/110019 Reported line numbers off by 1 when cpp invoked.
Fix off by one in m2.flex when the line number is set via cpp.
gcc/m2/ChangeLog:
PR modula2/110019
* gm2-compiler/SymbolKey.mod (SearchAndDo): Reformatted.
(ForeachNodeDo): Reformatted.
* gm2-compiler/SymbolTable.mod (AddListify): Join list
with "," or "and" if more than one word is in the list.
* m2.flex: Remove -1 from atoi(yytext) line number.
gcc/testsuite/ChangeLog:
PR modula2/110019
* gm2/cpp/fail/cpp-fail.exp: New test.
* gm2/cpp/fail/foocpp.mod: New test.
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
-rw-r--r-- | gcc/m2/gm2-compiler/SymbolKey.mod | 8 | ||||
-rw-r--r-- | gcc/m2/gm2-compiler/SymbolTable.mod | 14 | ||||
-rw-r--r-- | gcc/m2/m2.flex | 2 | ||||
-rw-r--r-- | gcc/testsuite/gm2/cpp/fail/cpp-fail.exp | 37 | ||||
-rw-r--r-- | gcc/testsuite/gm2/cpp/fail/foocpp.mod | 5 |
5 files changed, 56 insertions, 10 deletions
diff --git a/gcc/m2/gm2-compiler/SymbolKey.mod b/gcc/m2/gm2-compiler/SymbolKey.mod index b9fa87f..fa11266 100644 --- a/gcc/m2/gm2-compiler/SymbolKey.mod +++ b/gcc/m2/gm2-compiler/SymbolKey.mod @@ -312,7 +312,7 @@ END SearchForAny ; PROCEDURE ForeachNodeDo (t: SymbolTree; P: PerformOperation) ; BEGIN - SearchAndDo(t^.Left, P) + SearchAndDo (t^.Left, P) END ForeachNodeDo ; @@ -327,9 +327,9 @@ BEGIN IF t#NIL THEN WITH t^ DO - SearchAndDo(Right, P) ; - P(KeySym) ; - SearchAndDo(Left, P) + SearchAndDo (Right, P) ; + P (KeySym) ; + SearchAndDo (Left, P) END END END SearchAndDo ; diff --git a/gcc/m2/gm2-compiler/SymbolTable.mod b/gcc/m2/gm2-compiler/SymbolTable.mod index f43a734..1ea5fee 100644 --- a/gcc/m2/gm2-compiler/SymbolTable.mod +++ b/gcc/m2/gm2-compiler/SymbolTable.mod @@ -9028,12 +9028,16 @@ VAR PROCEDURE AddListify (sym: CARDINAL) ; BEGIN INC (ListifyWordCount) ; - IF ListifyWordCount = ListifyTotal + (* printf ("AddListify: ListifyWordCount = %d, ListifyTotal = %d\n", + ListifyWordCount, ListifyTotal) ; *) + IF ListifyWordCount > 1 THEN - ListifySentance := ConCat (ListifySentance, Mark (InitString (" and "))) - ELSIF ListifyWordCount > 1 - THEN - ListifySentance := ConCat (ListifySentance, Mark (InitString (", "))) + IF ListifyWordCount = ListifyTotal + THEN + ListifySentance := ConCat (ListifySentance, Mark (InitString (" and "))) + ELSE + ListifySentance := ConCat (ListifySentance, Mark (InitString (", "))) + END END ; ListifySentance := ConCat (ListifySentance, Mark (InitStringCharStar (KeyToCharStar (GetSymName (sym))))) diff --git a/gcc/m2/m2.flex b/gcc/m2/m2.flex index 0f23a35..0e6b52c 100644 --- a/gcc/m2/m2.flex +++ b/gcc/m2/m2.flex @@ -163,7 +163,7 @@ extern void yylex (void); ^\#.* { consumeLine(); /* printf("found: %s\n", currentLine->linebuf); */ BEGIN LINE0; } \n\#.* { consumeLine(); /* printf("found: %s\n", currentLine->linebuf); */ BEGIN LINE0; } <LINE0>\#[ \t]* { updatepos(); } -<LINE0>[0-9]+[ \t]*\" { updatepos(); lineno=atoi(yytext)-1; BEGIN LINE1; } +<LINE0>[0-9]+[ \t]*\" { updatepos(); lineno=atoi(yytext); BEGIN LINE1; } <LINE0>\n { m2flex_M2Error("missing initial quote after #line directive"); resetpos(); BEGIN INITIAL; } <LINE0>[^\n] <LINE1>[^\"\n]+ { m2flex_M2Error("missing final quote after #line directive"); resetpos(); BEGIN INITIAL; } diff --git a/gcc/testsuite/gm2/cpp/fail/cpp-fail.exp b/gcc/testsuite/gm2/cpp/fail/cpp-fail.exp new file mode 100644 index 0000000..343a396 --- /dev/null +++ b/gcc/testsuite/gm2/cpp/fail/cpp-fail.exp @@ -0,0 +1,37 @@ +# Expect driver script for GCC Regression Tests +# Copyright (C) 2003-2023 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" -fcpp + +foreach testcase [lsort [glob -nocomplain $srcdir/$subdir/foocpp.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 +} diff --git a/gcc/testsuite/gm2/cpp/fail/foocpp.mod b/gcc/testsuite/gm2/cpp/fail/foocpp.mod new file mode 100644 index 0000000..8d95fc0 --- /dev/null +++ b/gcc/testsuite/gm2/cpp/fail/foocpp.mod @@ -0,0 +1,5 @@ +MODULE foo; + +BEGIN + i := 0; +END foo. |