public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/modula-2] Bugfix the scope name when generating constants.
@ 2022-12-04 19:13 Gaius Mulley
  0 siblings, 0 replies; only message in thread
From: Gaius Mulley @ 2022-12-04 19:13 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:071c72a9e43609501648c7c6170329724b0eca39

commit 071c72a9e43609501648c7c6170329724b0eca39
Author: Gaius Mulley <gaius.mulley@southwales.ac.uk>
Date:   Sun Dec 4 19:12:53 2022 +0000

    Bugfix the scope name when generating constants.
    
    A bug occurs when generating an error while constructing constants.
    The scope name is incorrect.  Fixed by changing GetGlobalQuads
    and moving StartBuildInit after Declaration.
    
    gcc/m2/ChangeLog:
    
            * gm2-compiler/M2Scope.mod (GetGlobalQuads): Use prev to remember
            previous block and assign the scope characteristics of the next
            block with the same as the previous.
            * gm2-compiler/P0SymBuild.mod (FlushImport): Remove unused
            variable modname.
            * gm2-compiler/P3Build.bnf (Block): Move StartBuildInit after
            the Declaration.
    
    Signed-off-by: Gaius Mulley <gaius.mulley@southwales.ac.uk>

Diff:
---
 gcc/m2/gm2-compiler/M2Quads.mod    | 60 +++++++++++++++++------------------
 gcc/m2/gm2-compiler/M2Scope.mod    | 64 ++++++++++++++++++++++----------------
 gcc/m2/gm2-compiler/P0SymBuild.mod |  5 ++-
 gcc/m2/gm2-compiler/P3Build.bnf    |  3 +-
 4 files changed, 70 insertions(+), 62 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index 5de7ddb5281..88a7e7a6aeb 100644
--- a/gcc/m2/gm2-compiler/M2Quads.mod
+++ b/gcc/m2/gm2-compiler/M2Quads.mod
@@ -1767,17 +1767,17 @@ VAR
    f: QuadFrame ;
 BEGIN
    QuadNo := FreeList ;
-   IF InBounds(QuadArray, QuadNo) AND (GetIndice(QuadArray, QuadNo)#NIL)
+   IF InBounds (QuadArray, QuadNo) AND (GetIndice (QuadArray, QuadNo) # NIL)
    THEN
-      f := GetIndice(QuadArray, QuadNo)
+      f := GetIndice (QuadArray, QuadNo)
    ELSE
-      NEW(f) ;
+      NEW (f) ;
       IF f=NIL
       THEN
          InternalError ('out of memory error trying to allocate a quadruple')
       ELSE
-         INC(NoOfQuads) ;
-         PutIndice(QuadArray, QuadNo, f) ;
+         INC (NoOfQuads) ;
+         PutIndice (QuadArray, QuadNo, f) ;
          f^.NoOfTimesReferenced := 0
       END
    END ;
@@ -1786,8 +1786,8 @@ BEGIN
       Operand3 := 0 ;
       Next := 0
    END ;
-   INC(FreeList) ;
-   IF GrowInitialization<FreeList
+   INC (FreeList) ;
+   IF GrowInitialization < FreeList
    THEN
       GrowInitialization := FreeList
    END
@@ -1800,13 +1800,13 @@ END NewQuad ;
 
 PROCEDURE CheckVariableAt (sym: CARDINAL) ;
 BEGIN
-   IF IsVar(sym) AND IsVariableAtAddress(sym)
+   IF IsVar (sym) AND IsVariableAtAddress (sym)
    THEN
-      IF GetMode(sym)=LeftValue
+      IF GetMode (sym) = LeftValue
       THEN
-         GenQuad(InitAddressOp, sym, NulSym, GetVariableAtAddress(sym))
+         GenQuad (InitAddressOp, sym, NulSym, GetVariableAtAddress (sym))
       ELSE
-         InternalError('expecting lvalue for this variable which is declared at an explicit address')
+         InternalError ('expecting lvalue for this variable which is declared at an explicit address')
       END
    END
 END CheckVariableAt ;
@@ -1819,7 +1819,7 @@ END CheckVariableAt ;
 
 PROCEDURE CheckVariablesAt (scope: CARDINAL) ;
 BEGIN
-   ForeachLocalSymDo(scope, CheckVariableAt)
+   ForeachLocalSymDo (scope, CheckVariableAt)
 END CheckVariablesAt ;
 
 
@@ -1832,10 +1832,10 @@ BEGIN
    IF Iso
    THEN
       RETURN GetQualidentImport (tok,
-                                 MakeKey('TurnInterrupts'), MakeKey('COROUTINES'))
+                                 MakeKey ('TurnInterrupts'), MakeKey ('COROUTINES'))
    ELSE
       RETURN GetQualidentImport (tok,
-                                 MakeKey('TurnInterrupts'), MakeKey('SYSTEM'))
+                                 MakeKey ('TurnInterrupts'), MakeKey ('SYSTEM'))
    END
 END GetTurnInterrupts ;
 
@@ -1848,11 +1848,11 @@ PROCEDURE GetProtection (tok: CARDINAL) : CARDINAL ;
 BEGIN
    IF Iso
    THEN
-      RETURN GetQualidentImport(tok,
-                                MakeKey('PROTECTION'), MakeKey('COROUTINES'))
+      RETURN GetQualidentImport (tok,
+                                 MakeKey ('PROTECTION'), MakeKey ('COROUTINES'))
    ELSE
-      RETURN GetQualidentImport(tok,
-                                MakeKey('PROTECTION'), MakeKey('SYSTEM'))
+      RETURN GetQualidentImport (tok,
+                                 MakeKey ('PROTECTION'), MakeKey ('SYSTEM'))
    END
 END GetProtection ;
 
@@ -1870,17 +1870,17 @@ PROCEDURE CheckNeedPriorityBegin (tok: CARDINAL; scope, module: CARDINAL) ;
 VAR
    ProcSym, old: CARDINAL ;
 BEGIN
-   IF GetPriority(module)#NulSym
+   IF GetPriority (module) # NulSym
    THEN
       (* module has been given a priority *)
-      ProcSym := GetTurnInterrupts(tok) ;
-      IF ProcSym#NulSym
+      ProcSym := GetTurnInterrupts (tok) ;
+      IF ProcSym # NulSym
       THEN
          old := MakeTemporary (tok, RightValue) ;
-         PutVar(old, GetProtection(tok)) ;
+         PutVar (old, GetProtection (tok)) ;
 
          GenQuadO (tok, SavePriorityOp, old, scope, ProcSym, FALSE) ;
-         PushWord(PriorityStack, old)
+         PushWord (PriorityStack, old)
       END
    END
 END CheckNeedPriorityBegin ;
@@ -1898,14 +1898,14 @@ PROCEDURE CheckNeedPriorityEnd (tok: CARDINAL;
 VAR
    ProcSym, old: CARDINAL ;
 BEGIN
-   IF GetPriority(module)#NulSym
+   IF GetPriority (module) # NulSym
    THEN
       (* module has been given a priority *)
-      ProcSym := GetTurnInterrupts(tok) ;
-      IF ProcSym#NulSym
+      ProcSym := GetTurnInterrupts (tok) ;
+      IF ProcSym # NulSym
       THEN
-         old := PopWord(PriorityStack) ;
-         GenQuad(RestorePriorityOp, old, scope, ProcSym)
+         old := PopWord (PriorityStack) ;
+         GenQuad (RestorePriorityOp, old, scope, ProcSym)
       END
    END
 END CheckNeedPriorityEnd ;
@@ -11020,7 +11020,6 @@ VAR
    combinedTok,
    arrayTok,
    exprTok    : CARDINAL ;
-   s          : String ;
    e, d, error,
    Sym,
    Type       : CARDINAL ;
@@ -11060,7 +11059,6 @@ VAR
    combinedTok,
    arrayTok,
    exprTok    : CARDINAL ;
-   s          : String ;
    e, t, d,
    Sym,
    Type       : CARDINAL ;
@@ -12038,7 +12036,7 @@ END BuildConstructorStart ;
 
 PROCEDURE BuildConstructorEnd (cbratokpos: CARDINAL) ;
 VAR
-   type, typetok,
+   typetok,
    value, valtok: CARDINAL ;
 BEGIN
    PopTtok (value, valtok) ;
diff --git a/gcc/m2/gm2-compiler/M2Scope.mod b/gcc/m2/gm2-compiler/M2Scope.mod
index 146ecd12522..ee878971252 100644
--- a/gcc/m2/gm2-compiler/M2Scope.mod
+++ b/gcc/m2/gm2-compiler/M2Scope.mod
@@ -126,6 +126,7 @@ END AddToRange ;
 
 PROCEDURE GetGlobalQuads (sb: ScopeBlock; scope: CARDINAL) : ScopeBlock ;
 VAR
+   prev,
    nb           : ScopeBlock ;
    NestedLevel,
    i            : CARDINAL ;
@@ -135,6 +136,7 @@ VAR
    start, end   : CARDINAL ;
 BEGIN
    NestedLevel := 0 ;
+   prev := NIL ;
    First := FALSE ;
    IF (GetScope(scope)#NulSym) AND
       (IsProcedure(GetScope(scope)) OR
@@ -162,6 +164,10 @@ BEGIN
    LOOP
       IF i=0
       THEN
+         IF Debugging
+         THEN
+            DisplayScope (sb)
+         END ;
          RETURN sb
       END ;
       GetQuad (i, op, op1, op2, op3) ;
@@ -178,44 +184,48 @@ BEGIN
          THEN
             First := TRUE
          END
-      ELSE
-         IF NestedLevel=0
+      ELSIF NestedLevel=0
+      THEN
+         IF op=StartDefFileOp
+         THEN
+            nb := AddToRange (nb, TRUE, i) ;
+            SetScope (nb, op3, definitionscope) ;
+            prev := nb
+         ELSIF (op=StartModFileOp) OR (op=InitStartOp)
          THEN
-            IF op=StartDefFileOp
+            nb := AddToRange (nb, TRUE, i) ;
+            IF IsDefImp (op3)
             THEN
-               nb := AddToRange (nb, TRUE, i) ;
-               SetScope (nb, op3, definitionscope)
-            ELSIF op=StartModFileOp
+               SetScope (nb, op3, implementationscope)
+            ELSE
+               SetScope (nb, op3, programscope)
+            END ;
+            prev := nb
+         ELSE
+            nb := AddToRange (nb, First, i) ;
+            IF op = InitEndOp
             THEN
-               nb := AddToRange (nb, TRUE, i) ;
                IF IsDefImp (op3)
                THEN
                   SetScope (nb, op3, implementationscope)
                ELSE
                   SetScope (nb, op3, programscope)
-               END
-            ELSIF op=InitStartOp
+               END ;
+               prev := nb
+            ELSIF First
             THEN
-               nb := AddToRange (nb, TRUE, i) ;
-               IF IsDefImp (op3)
-               THEN
-                  SetScope (nb, op3, implementationscope)
-               ELSE
-                  SetScope (nb, op3, programscope)
-               END
-            ELSE
-               nb := AddToRange (nb, First, i) ;
-               IF First
-               THEN
-                  SetScope (nb, NulSym, unsetscope)  (* is this reachable?  *)
-               END
-            END ;
-            First := FALSE
-         END
+               Assert (prev # NIL) ;
+               SetScope (nb, prev^.scopeSym, prev^.kindScope)
+            END
+         END ;
+         First := FALSE
       END ;
-      (* IF (i=end) *)
-      IF (i=end) (*  OR (op=EndFileOp) *)
+      IF i=end
       THEN
+         IF Debugging
+         THEN
+            DisplayScope (sb)
+         END ;
          RETURN sb
       END ;
       i := GetNextQuad (i)
diff --git a/gcc/m2/gm2-compiler/P0SymBuild.mod b/gcc/m2/gm2-compiler/P0SymBuild.mod
index fa44d889f1c..00aac85f6a1 100644
--- a/gcc/m2/gm2-compiler/P0SymBuild.mod
+++ b/gcc/m2/gm2-compiler/P0SymBuild.mod
@@ -258,9 +258,8 @@ END InitUniverse ;
 
 PROCEDURE FlushImports (b: BlockInfoPtr) ;
 VAR
-   i, n   : CARDINAL ;
-   modname: Name ;
-   desc   : ModuleDesc ;
+   i, n: CARDINAL ;
+   desc: ModuleDesc ;
 BEGIN
    WITH b^ DO
       i := LowIndice (ImportedModules) ;
diff --git a/gcc/m2/gm2-compiler/P3Build.bnf b/gcc/m2/gm2-compiler/P3Build.bnf
index 42d369449e7..8ccc4d604a3 100644
--- a/gcc/m2/gm2-compiler/P3Build.bnf
+++ b/gcc/m2/gm2-compiler/P3Build.bnf
@@ -1324,7 +1324,8 @@ ProcedureBlock :=                                                          % Bui
                                                                  "END"
                 =:
 
-Block := { Declaration }                                                   % StartBuildInit (GetTokenNo ()) %
+Block := { Declaration }
+                                                                           % StartBuildInit (GetTokenNo ()) %
                          InitialBlock                                      % EndBuildInit (GetTokenNo ()) ;
                                                                              StartBuildFinally (GetTokenNo ()) %
                                       FinalBlock                           % EndBuildFinally (GetTokenNo ()) %

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-04 19:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-04 19:13 [gcc/devel/modula-2] Bugfix the scope name when generating constants Gaius Mulley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).