aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaius Mulley <gaiusmod2@gmail.com>2024-03-28 16:49:44 +0000
committerGaius Mulley <gaiusmod2@gmail.com>2024-03-28 16:49:44 +0000
commitaeee63ffbf4f4fbc4d90d8aae808d6b67f0148a3 (patch)
treea71ed1e4ac49dd8c3501832b193fe5d6aebe88c3
parent04799f03e8d01b903295ef3a100a0117b7ddbf5e (diff)
downloadgcc-aeee63ffbf4f4fbc4d90d8aae808d6b67f0148a3.zip
gcc-aeee63ffbf4f4fbc4d90d8aae808d6b67f0148a3.tar.gz
gcc-aeee63ffbf4f4fbc4d90d8aae808d6b67f0148a3.tar.bz2
PR modula2/114520 Incorrect ordering of import/export statements cause confusion
The error recovery causes misleading error messages to appear if an EXPORT and IMPORT statement are in the wrong order. This patch detects the incorrect order and issues an error message and prevents error recovery. The fix should be improved and made more general if another similar case is required. gcc/m2/ChangeLog: PR modula2/114520 * gm2-compiler/P0SyntaxCheck.bnf (DetectImport): New procedure. (EnableImportCheck): New boolean. (Expect): Call DetectImport. (Export): Set EnableImportCheck TRUE before ';' and FALSE afterwards. Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
-rw-r--r--gcc/m2/gm2-compiler/P0SyntaxCheck.bnf31
1 files changed, 27 insertions, 4 deletions
diff --git a/gcc/m2/gm2-compiler/P0SyntaxCheck.bnf b/gcc/m2/gm2-compiler/P0SyntaxCheck.bnf
index c1c86c1..07f861a 100644
--- a/gcc/m2/gm2-compiler/P0SyntaxCheck.bnf
+++ b/gcc/m2/gm2-compiler/P0SyntaxCheck.bnf
@@ -82,9 +82,10 @@ CONST
(* giving up. *)
VAR
- seenError : BOOLEAN ;
- LastIdent : Name ;
- InsertCount: CARDINAL ;
+ EnableImportCheck,
+ seenError : BOOLEAN ;
+ LastIdent : Name ;
+ InsertCount : CARDINAL ;
PROCEDURE ErrorString (s: String) ;
@@ -320,6 +321,21 @@ END PeepToken ;
(*
+ DetectImport - checks whether the next token is an import or from and if so
+ generates an error message. This is called after an export
+ statement to notify the user that the ordering is incorrect.
+*)
+
+PROCEDURE DetectImport ;
+BEGIN
+ IF (currenttoken = importtok) OR (currenttoken = fromtok)
+ THEN
+ ErrorArray ('an {%AkIMPORT} statement must preceed an {%kEXPORT} statement')
+ END
+END DetectImport ;
+
+
+(*
Expect -
*)
@@ -328,6 +344,10 @@ BEGIN
IF currenttoken=t
THEN
GetToken ;
+ IF EnableImportCheck
+ THEN
+ DetectImport
+ END ;
IF Pass0
THEN
PeepToken (stopset0, stopset1, stopset2)
@@ -347,6 +367,7 @@ END Expect ;
PROCEDURE CompilationUnit () : BOOLEAN ;
BEGIN
seenError := FALSE ;
+ EnableImportCheck := FALSE ;
InsertCount := 0 ;
FileUnit (SetOfStop0{eoftok}, SetOfStop1{}, SetOfStop2{}) ;
RETURN NOT seenError
@@ -883,7 +904,9 @@ Priority := "[" ConstExpression "]" =:
Export := "EXPORT" ( "QUALIFIED" IdentList |
"UNQUALIFIED" IdentList |
IdentList
- ) ";" =:
+ ) % EnableImportCheck := TRUE %
+ ";" % EnableImportCheck := FALSE %
+ =:
Import := "FROM" Ident "IMPORT" IdentList ";" |
"IMPORT" % PushTtok (ImportTok, GetTokenNo () -1)