[Oberon] Unreferenced/unused code in Project Oberon 2013

Luca Boasso luke.boasso at gmail.com
Tue Sep 28 07:28:22 CEST 2021


I made a similar change about 3 years ago in oberonc:
https://github.com/lboasso/oberonc/commit/8dba655050a8ef6531a33aac2d025283efc221e1

"Unused imported modules or local/global variables are now regarded as a
compilation error. Exported global variables are considered always used.
Parameters are excluded because procedure variables might have multiple
implementations, and we do not want to force one particular
implementation to use all the formal parameters.
This change uncovered many unused objects in tests and the compiler
sources."

Cheers,
Luca



On Tue, Sep 28, 2021, 00:14 Chris Burrows <cfbsoftware at gmail.com> wrote:

> > > -----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
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.inf.ethz.ch/pipermail/oberon/attachments/20210928/d405fced/attachment.html>


More information about the Oberon mailing list