https://gcc.gnu.org/g:5902ea4a341419d243725e7a52800e297159ff9d

commit r14-11060-g5902ea4a341419d243725e7a52800e297159ff9d
Author: Gaius Mulley <gaiusm...@gmail.com>
Date:   Wed Dec 4 09:03:36 2024 +0000

    [PATCH] PR modula2/117660: Errors referring to variables of type array 
could display full declaration
    
    This patch ensures that the tokens defining the full declaration of an
    ARRAY type is stored in the symbol table and used during production of
    error messages.
    
    gcc/m2/ChangeLog:
    
            PR modula2/117660
            * gm2-compiler/P2Build.bnf (ArrayType): Update tok with the
            composite token produced during array type declaration.
            * gm2-compiler/P2SymBuild.mod (EndBuildArray): Create the
            combinedtok and store it into the symbol table.
            Also ensure combinedtok is pushed to the quad stack.
            (BuildFieldArray): Preserve typetok.
            * gm2-compiler/SymbolTable.def (PutArray): Rename parameters.
            * gm2-compiler/SymbolTable.mod (PutArray): Rename parameters.
    
    gcc/testsuite/ChangeLog:
    
            PR modula2/117660
            * gm2/iso/fail/arraymismatch.mod: New test.
    
    (cherry picked from commit ab7abf1db09519a92f4a02af30ed6b834264c45e)
    
    Signed-off-by: Gaius Mulley <gaiusm...@gmail.com>

Diff:
---
 gcc/m2/gm2-compiler/P2Build.bnf              |  4 ++-
 gcc/m2/gm2-compiler/P2SymBuild.mod           | 41 ++++++++++++++++------------
 gcc/m2/gm2-compiler/SymbolTable.def          |  4 +--
 gcc/m2/gm2-compiler/SymbolTable.mod          |  8 +++---
 gcc/testsuite/gm2/iso/fail/arraymismatch.mod |  8 ++++++
 5 files changed, 41 insertions(+), 24 deletions(-)

diff --git a/gcc/m2/gm2-compiler/P2Build.bnf b/gcc/m2/gm2-compiler/P2Build.bnf
index 9e1145e3f815..e3db5f077dc6 100644
--- a/gcc/m2/gm2-compiler/P2Build.bnf
+++ b/gcc/m2/gm2-compiler/P2Build.bnf
@@ -54,6 +54,7 @@ FROM M2Printf IMPORT printf0 ;
 FROM M2Debug IMPORT Assert ;
 
 FROM M2Quads IMPORT PushT, PopT, PushTF, PopTF, PopNothing, OperandT, PushTFA, 
Top, Annotate,
+                    OperandTok,
                     PushTFtok, PopTFtok, PushTFAtok, PopTtok, PushTtok,
                     StartBuildInit,
                     EndBuildInit,
@@ -783,8 +784,9 @@ ArrayType := "ARRAY"                                        
               % VAR
                 SimpleType                                                 % 
BuildFieldArray ; %
               } "OF"                                                       % 
BuildNulName ; %
              Type                                                          % 
EndBuildArray ;
+                                                                             
tok := OperandTok (1) ;
                                                                              
PopNothing ;
-                                                                             
PushTtok(arrayType, tok) %
+                                                                             
PushTtok (arrayType, tok) %
            =:
 
 RecordType := "RECORD"                                                     % 
BuildRecord %
diff --git a/gcc/m2/gm2-compiler/P2SymBuild.mod 
b/gcc/m2/gm2-compiler/P2SymBuild.mod
index 70492705129b..288d0cac03bd 100644
--- a/gcc/m2/gm2-compiler/P2SymBuild.mod
+++ b/gcc/m2/gm2-compiler/P2SymBuild.mod
@@ -1281,7 +1281,7 @@ BEGIN
             THEN
                IF isunknown
                THEN
-                  MetaError2('attempting to declare a type {%1ad} to a type 
which is itself unknown {%2ad}',
+                  MetaError2('attempting to declare a type {%1ad} to a type 
which is itself and also unknown {%2ad}',
                              Sym, Type)
                ELSE
                   MetaError1('attempting to declare a type {%1ad} as itself', 
Sym)
@@ -2896,15 +2896,20 @@ END StartBuildArray ;
 
 PROCEDURE EndBuildArray ;
 VAR
+   typetok,
+   arraytok,
+   combinedtok: CARDINAL ;
    TypeSym,
-   ArraySym: CARDINAL ;
-BEGIN
-   PopT(TypeSym) ;
-   PopT(ArraySym) ;
-   Assert(IsArray(ArraySym)) ;
-   PutArray(ArraySym, TypeSym) ;
-   PushT(ArraySym) ;
-   Annotate("%1s(%1d)||array type")
+   ArraySym   : CARDINAL ;
+BEGIN
+   PopTtok (TypeSym, typetok) ;
+   PopTtok (ArraySym, arraytok) ;
+   Assert (IsArray (ArraySym)) ;
+   combinedtok := MakeVirtual2Tok (arraytok, typetok) ;
+   PutArray (ArraySym, TypeSym) ;
+   PutDeclared (combinedtok, ArraySym) ;
+   PushTtok (ArraySym, combinedtok) ;
+   Annotate ("%1s(%1d)||array type")
 END EndBuildArray ;
 
 
@@ -2928,15 +2933,17 @@ END EndBuildArray ;
 
 PROCEDURE BuildFieldArray ;
 VAR
+   typetok,
+   arraytok  : CARDINAL ;
    Subscript,
    Type,
    Array     : CARDINAL ;
    name      : Name ;
 BEGIN
-   PopTF(Type, name) ;
-   PopT(Array) ;
-   Assert(IsArray(Array)) ;
-   Subscript := MakeSubscript() ;
+   PopTFtok (Type, name, typetok) ;
+   PopTtok (Array, arraytok) ;
+   Assert (IsArray (Array)) ;
+   Subscript := MakeSubscript () ;
    (*
       We cannot Assert(IsSubrange(Type)) as the subrange type might be
       declared later on in the file.
@@ -2946,10 +2953,10 @@ BEGIN
       However this works to our advantage as it preserves the
       actual declaration as specified by the source file.
    *)
-   PutSubscript(Subscript, Type) ;
-   PutArraySubscript(Array, Subscript) ;
-   PushT(Array) ;
-   Annotate("%1s(%1d)||array type")
+   PutSubscript (Subscript, Type) ;
+   PutArraySubscript (Array, Subscript) ;
+   PushTtok (Array, arraytok) ;
+   Annotate ("%1s(%1d)||array type")
 (* ; WriteString('Field Placed in Array') ; WriteLn *)
 END BuildFieldArray ;
 
diff --git a/gcc/m2/gm2-compiler/SymbolTable.def 
b/gcc/m2/gm2-compiler/SymbolTable.def
index 506444f5859e..0a0ce64b401b 100644
--- a/gcc/m2/gm2-compiler/SymbolTable.def
+++ b/gcc/m2/gm2-compiler/SymbolTable.def
@@ -2551,10 +2551,10 @@ PROCEDURE NoOfElements (Sym: CARDINAL) : CARDINAL ;
 
 
 (*
-   PutArray - places a type symbol into an Array.
+   PutArray - places a type symbol into an arraysym.
 *)
 
-PROCEDURE PutArray (Sym, TypeSymbol: CARDINAL) ;
+PROCEDURE PutArray (arraysym, typesym: CARDINAL) ;
 
 
 (*
diff --git a/gcc/m2/gm2-compiler/SymbolTable.mod 
b/gcc/m2/gm2-compiler/SymbolTable.mod
index 5ef71ea9bad5..a502fb576411 100644
--- a/gcc/m2/gm2-compiler/SymbolTable.mod
+++ b/gcc/m2/gm2-compiler/SymbolTable.mod
@@ -12397,20 +12397,20 @@ END GetDimension ;
 
 
 (*
-   PutArray - places a type symbol into an Array.
+   PutArray - places a type symbol into an arraysym.
 *)
 
-PROCEDURE PutArray (Sym, TypeSymbol: CARDINAL) ;
+PROCEDURE PutArray (arraysym, typesym: CARDINAL) ;
 VAR
    pSym: PtrToSymbol ;
 BEGIN
-   pSym := GetPsym(Sym) ;
+   pSym := GetPsym (arraysym) ;
    WITH pSym^ DO
       CASE SymbolType OF
 
       ErrorSym: |
       ArraySym: WITH Array DO
-                   Type := TypeSymbol (* The Array Type. ARRAY OF Type.      *)
+                   Type := typesym  (* The ARRAY OF typesym.  *)
                 END
       ELSE
          InternalError ('expecting an Array symbol')
diff --git a/gcc/testsuite/gm2/iso/fail/arraymismatch.mod 
b/gcc/testsuite/gm2/iso/fail/arraymismatch.mod
new file mode 100644
index 000000000000..543ff29f7dae
--- /dev/null
+++ b/gcc/testsuite/gm2/iso/fail/arraymismatch.mod
@@ -0,0 +1,8 @@
+MODULE arraymismatch ;
+
+VAR
+   a: ARRAY [0..3] OF REAL ;
+   b: ARRAY [0..4] OF REAL ;
+BEGIN
+   a := b
+END arraymismatch.

Reply via email to