[Oberon] Unreferenced/unused code in Project Oberon 2013

Chris Burrows cfbsoftware at gmail.com
Tue Sep 28 07:13:40 CEST 2021


> > -----Original Message-----
> > From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
> > Michael Schierl
> > Sent: Sunday, 28 April 2019 6:13 AM
> > To: ETH Oberon and related systems
> > Subject: [Oberon] Unreferenced/unused code in Project Oberon 2013
> >
> > I used some scripts to identify unreferenced code (after stumbling
> > upon some unused variables in TextFrames)
>

I previously objected to removing unreferenced code in a reply to this
message but the mention of unused variables did grab my attention. The
latest (v8) versions of my ARM Cortex-M Oberon-07 compilers now warn
of unused imports, consts, types and variables. Most of the time these
are harmless but every now and then they can usefully indicate a
potential source of problems that has been overlooked.

I am working on a similar change to the Astrobe for RISC5 compiler.
Other compilers based on the Project Oberon RISC5 compiler can be
modified to do the same. The changes might be something like this:

1. Introduce a new field into ORB.ObjDesc:

    used: BOOLEAN

2. Initialise 'new.used' to FALSE in ORB.NewObj after 'new' is created.

3. Set 'new.used', if the object is found, in ORB.ThisObj:
    ....
    UNTIL (x # NIL) OR (s = NIL);
    IF x # NIL THEN x.used := TRUE END;

4. Set 'obj.used' for pointers in ORP.Declarations
   ...
   IF obj.name = ptbase.name THEN ptbase.type.base := obj.type;
obj.used := TRUE END ;

5. Introduce a new procedure in ORP to report the unused objects:

  PROCEDURE CheckUnused();
    VAR x: ORB.Object;
  BEGIN x := ORB.topScope.next;
    WHILE (x # NIL) DO
      IF ~x.used & ~x.expo & ((x.class # ORB.Mod) OR x.rdo) THEN
        ORS.Mark("!" + x.name + " is not used")
      END;
      x := x.next
    END
  END CheckUnused;

6. Allow for warnings (message beginning with '!') as well as error
messages in ORS.Mark:

  IF msg[0] # "!" THEN INC(errcnt); errpos := p + 4 END

7. Call CheckUnused in ORP.Module, after the statement sequence has
been processed, to warn about unused globals:
      ...
      IF sym = ORS.begin THEN ORS.Get(sym); StatSequence END ;
      CheckUnused();

8. Call CheckUnused in ORP.ProcedureDecl after the RETURN has been
processed to warn about unused locals:
      ...
      ORG.Return(type.base.form, x, locblksize, int);
      CheckUnused();

Unused locals warnings will appear when each procedure has been
compiled. Unused global warnings will appear after the whole module
has been compiled.

Regards,
Chris Burrows
CFB Software
https://www.astrobe.com/RISC5


More information about the Oberon mailing list