<div dir="ltr"><div dir="auto">I made a similar change about 3 years ago in oberonc: <a href="https://github.com/lboasso/oberonc/commit/8dba655050a8ef6531a33aac2d025283efc221e1" rel="noreferrer" target="_blank">https://github.com/lboasso/oberonc/commit/8dba655050a8ef6531a33aac2d025283efc221e1</a><div dir="auto"><br></div><div dir="auto"><div dir="auto">"Unused imported modules or local/global variables are now regarded as a<br>compilation error. Exported global variables are considered always used.<br>Parameters are excluded because procedure variables might have multiple<br>implementations, and we do not want to force one particular<br>implementation to use all the formal parameters.<br>This change uncovered many unused objects in tests and the compiler<br>sources."<br><br>Cheers,<br>Luca<pre></pre><pre><br></pre></div>

  <div dir="auto">
  

    <div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 28, 2021, 00:14 Chris Burrows <<a href="mailto:cfbsoftware@gmail.com" rel="noreferrer" target="_blank">cfbsoftware@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> > -----Original Message-----<br>
> > From: Oberon [mailto:<a href="mailto:oberon-bounces@lists.inf.ethz.ch" rel="noreferrer noreferrer" target="_blank">oberon-bounces@lists.inf.ethz.ch</a>] On Behalf Of<br>
> > Michael Schierl<br>
> > Sent: Sunday, 28 April 2019 6:13 AM<br>
> > To: ETH Oberon and related systems<br>
> > Subject: [Oberon] Unreferenced/unused code in Project Oberon 2013<br>
> ><br>
> > I used some scripts to identify unreferenced code (after stumbling<br>
> > upon some unused variables in TextFrames)<br>
><br>
<br>
I previously objected to removing unreferenced code in a reply to this<br>
message but the mention of unused variables did grab my attention. The<br>
latest (v8) versions of my ARM Cortex-M Oberon-07 compilers now warn<br>
of unused imports, consts, types and variables. Most of the time these<br>
are harmless but every now and then they can usefully indicate a<br>
potential source of problems that has been overlooked.<br>
<br>
I am working on a similar change to the Astrobe for RISC5 compiler.<br>
Other compilers based on the Project Oberon RISC5 compiler can be<br>
modified to do the same. The changes might be something like this:<br>
<br>
1. Introduce a new field into ORB.ObjDesc:<br>
<br>
    used: BOOLEAN<br>
<br>
2. Initialise 'new.used' to FALSE in ORB.NewObj after 'new' is created.<br>
<br>
3. Set 'new.used', if the object is found, in ORB.ThisObj:<br>
    ....<br>
    UNTIL (x # NIL) OR (s = NIL);<br>
    IF x # NIL THEN x.used := TRUE END;<br>
<br>
4. Set 'obj.used' for pointers in ORP.Declarations<br>
   ...<br>
   IF <a href="http://obj.name" rel="noreferrer noreferrer noreferrer" target="_blank">obj.name</a> = <a href="http://ptbase.name" rel="noreferrer noreferrer noreferrer" target="_blank">ptbase.name</a> THEN ptbase.type.base := obj.type;<br>
obj.used := TRUE END ;<br>
<br>
5. Introduce a new procedure in ORP to report the unused objects:<br>
<br>
  PROCEDURE CheckUnused();<br>
    VAR x: ORB.Object;<br>
  BEGIN x := ORB.topScope.next;<br>
    WHILE (x # NIL) DO<br>
      IF ~x.used & ~x.expo & ((x.class # ORB.Mod) OR x.rdo) THEN<br>
        ORS.Mark("!" + <a href="http://x.name" rel="noreferrer noreferrer noreferrer" target="_blank">x.name</a> + " is not used")<br>
      END;<br>
      x := x.next<br>
    END<br>
  END CheckUnused;<br>
<br>
6. Allow for warnings (message beginning with '!') as well as error<br>
messages in ORS.Mark:<br>
<br>
  IF msg[0] # "!" THEN INC(errcnt); errpos := p + 4 END<br>
<br>
7. Call CheckUnused in ORP.Module, after the statement sequence has<br>
been processed, to warn about unused globals:<br>
      ...<br>
      IF sym = ORS.begin THEN ORS.Get(sym); StatSequence END ;<br>
      CheckUnused();<br>
<br>
8. Call CheckUnused in ORP.ProcedureDecl after the RETURN has been<br>
processed to warn about unused locals:<br>
      ...<br>
      ORG.Return(type.base.form, x, locblksize, int);<br>
      CheckUnused();<br>
<br>
Unused locals warnings will appear when each procedure has been<br>
compiled. Unused global warnings will appear after the whole module<br>
has been compiled.<br>
<br>
Regards,<br>
Chris Burrows<br>
CFB Software<br>
<a href="https://www.astrobe.com/RISC5" rel="noreferrer noreferrer noreferrer" target="_blank">https://www.astrobe.com/RISC5</a><br>
--<br>
<a href="mailto:Oberon@lists.inf.ethz.ch" rel="noreferrer noreferrer" target="_blank">Oberon@lists.inf.ethz.ch</a> mailing list for ETH Oberon and related systems<br>
<a href="https://lists.inf.ethz.ch/mailman/listinfo/oberon" rel="noreferrer noreferrer noreferrer" target="_blank">https://lists.inf.ethz.ch/mailman/listinfo/oberon</a><br>
</blockquote></div>