PR modula2/117948: Forward procedure declaration should only be available in ISO

This patch restricts the forward procedure declaration to the ISO dialect.

gcc/m2/ChangeLog:

	PR modula2/117948
	* gm2-compiler/P1Build.bnf (ForwardDeclaration): Pass token
	position of the FORWARD keyword to EndBuildForward.
	* gm2-compiler/P1SymBuild.def (EndBuildForward): New parameter
	forwardPos.
	* gm2-compiler/P1SymBuild.mod (EndBuildForward): Issue an error at
	forwardPos if the Iso boolean is false.

gcc/testsuite/ChangeLog:

	PR modula2/117948
	* gm2/pim/fail/forward.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
This commit is contained in:
Gaius Mulley 2024-12-07 14:04:44 +00:00
parent 4abcf4ad38
commit 4180037214
4 changed files with 26 additions and 4 deletions

View file

@ -878,7 +878,7 @@ ProcedureDeclaration := % VAR
PostProcedureHeading := ProperProcedure | ForwardDeclaration =:
ForwardDeclaration := "FORWARD" % EndBuildForward %
ForwardDeclaration := "FORWARD" % EndBuildForward (GetTokenNo ()-1) %
=:
ProperProcedure := ProcedureBlock % PushAutoOn %

View file

@ -489,7 +489,7 @@ PROCEDURE BuildProcedureHeading ;
Empty
*)
PROCEDURE EndBuildForward ;
PROCEDURE EndBuildForward (forwardPos: CARDINAL) ;
(*

View file

@ -26,7 +26,10 @@ FROM ASCII IMPORT nul ;
FROM NameKey IMPORT Name, WriteKey, MakeKey, KeyToCharStar, NulName ;
FROM M2Debug IMPORT Assert, WriteDebug ;
FROM M2LexBuf IMPORT GetFileName, GetTokenNo, UnknownTokenNo ;
FROM M2MetaError IMPORT MetaErrorString2, MetaError0, MetaError1, MetaError2, MetaErrorT1, MetaErrorT2 ;
FROM M2MetaError IMPORT MetaErrorString2, MetaError0, MetaError1,
MetaError2, MetaErrorT0, MetaErrorT1, MetaErrorT2 ;
FROM DynamicStrings IMPORT String, Slice, InitString, KillString, EqualCharStar, RIndex, Mark, ConCat ;
FROM M2Printf IMPORT printf0, printf1, printf2 ;
FROM M2Options IMPORT Iso ;
@ -1064,13 +1067,18 @@ END EndBuildProcedure ;
Empty
*)
PROCEDURE EndBuildForward ;
PROCEDURE EndBuildForward (forwardPos: CARDINAL) ;
VAR
ProcSym: CARDINAL ;
tok : CARDINAL ;
BEGIN
ProcSym := OperandT (1) ;
tok := OperandTok (1) ;
IF NOT Iso
THEN
MetaErrorT0 (forwardPos,
'forward declaration is only allowed in the ISO dialect of Modula-2')
END ;
IF GetProcedureDefined (ProcSym, ForwardProcedure)
THEN
MetaErrorT1 (GetProcedureDeclaredTok (ProcSym, ForwardProcedure),

View file

@ -0,0 +1,14 @@
MODULE forward ;
PROCEDURE foo (a: CARDINAL) ; FORWARD ;
PROCEDURE foo (a: CARDINAL) ;
BEGIN
END foo ;
BEGIN
foo (1)
END forward.