#!/usr/bin/env rexx /******************************************************************************/ /* */ /* astcheck.rex - Does every class of the AST have a compiler? */ /* =========================================================== */ /* */ /* Usage: rexx astcheck.rex */ /* */ /* The compiler is bound to the parser's AST by class names: each class it */ /* compiles has an "rcompile" method (RVM.Compiler.cls, installed by */ /* Load.Parser.Module). A node whose class has none compiles to ERR 93.900 */ /* "RVM: is not supported yet", raised only if that code runs, so a */ /* new class of the parser goes unnoticed until a program executes it (see */ /* doc/20-maintaining.md, "How a parser change breaks the RVM"). */ /* */ /* This looks at every class of the parser that is a clause (Rexx.Clause), */ /* an expression (Rexx.Expression) or a term (Rexx.Term), and compares the */ /* ones with no rcompile with the list below, where each has its reason. A */ /* class missing from the list ("NEW") needs an rcompile, or a place in the */ /* list with its reason; one in the list that the parser no longer has, or */ /* that now has an rcompile ("GONE"), leaves the list. One line per */ /* difference; the last line is "astcheck: OK, ..." or the count, which is */ /* also the return code. About a second. smoke.rex runs it first. */ /* */ /* This file is part of the RVM, the Rexx Virtual Machine */ /* [See https://rexx.epbcn.com/rexx-parser/] */ /* */ /* Copyright (c) 2026 Josep Maria Blasco */ /* */ /* License: Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0) */ /* */ /******************************************************************************/ known = .Directory~new -- Bases: only their subclasses are nodes. Call Known known, "base", - "REXX.CLAUSE REXX.INSTRUCTION REXX.DIRECTIVE BLOCK.INSTRUCTION", "ITERATIVE.INSTRUCTION ITERATIVE.CLAUSE OPTIONAL.EXPRESSION.INSTRUCTION", "OPTIONAL.TEMPLATE.LIST NULL.CLAUSE REXX.EXPRESSION REXX.TERM", "NARY.EXPRESSION DO.CLAUSE LOOP.CLAUSE" -- Parts of an instruction, compiled by the instruction (DO, LOOP, IF, -- SELECT, a body, labels) or by the expression they belong to. Call Known known, "part", - "CODE.BODY DO.CONTROLLED.CLAUSE DO.FOREVER.CLAUSE DO.OVER.CLAUSE", "DO.UNTIL.CLAUSE DO.WHILE.CLAUSE DO.WITH.CLAUSE SIMPLE.DO.CLAUSE", "SIMPLE.REPETITIVE.DO.CLAUSE LOOP.CONTROLLED.CLAUSE LOOP.FOREVER.CLAUSE", "LOOP.OVER.CLAUSE LOOP.UNTIL.CLAUSE LOOP.WHILE.CLAUSE LOOP.WITH.CLAUSE", "SIMPLE.LOOP.CLAUSE SIMPLE.REPETITIVE.LOOP.CLAUSE IF.CLAUSE THEN.CLAUSE", "ELSE.CLAUSE SELECT.CLAUSE WHEN.CLAUSE OTHERWISE.CLAUSE END.CLAUSE", "LABEL.CLAUSE END.OF.SOURCE SOURCE.LITERAL.END SOURCE.LITERAL ARGUMENTS", "EXPRESSION.LIST INITIALIZER" -- Directives: compiled by CompileDirectives (and CompileOptions, -- CompileAnnotations), each by its class. Call Known known, "directive", - "ANNOTATE.DIRECTIVE ATTRIBUTE.DIRECTIVE CLASS.DIRECTIVE", "COACTIVITY.DIRECTIVE CONSTANT.DIRECTIVE EXTENSION.DIRECTIVE", "METHOD.DIRECTIVE OPTIONS.DIRECTIVE R.DIRECTIVE REQUIRES.DIRECTIVE", "RESOURCE.DIRECTIVE ROUTINE.DIRECTIVE" -- Not compiled on purpose: ERR 93.900 when it runs (doc/18, "Parser forms -- that native ooRexx 5 does not have"). Call Known known, "unsupported", "UPPER.INSTRUCTION" seen = .Set~new found = .Directory~new -- class id -> has rcompile (0/1) Call Walk .context~package bad = 0 checked = 0 Do id Over found~allIndexes~sort checked += 1 If found[id] Then Do If known~hasIndex( id ) Then Do Say "GONE" id": it has an rcompile now (listed as" known[id]")" bad += 1 End Iterate End If \ known~hasIndex( id ) Then Do Say "NEW " id": no rcompile (ERR 93.900 when it runs)" bad += 1 End End Do id Over known~allIndexes~sort If \ found~hasIndex( id ) Then Do Say "GONE" id": the parser has no such class (listed as" known[id]")" bad += 1 End End If bad == 0 Then Say "astcheck: OK," checked "classes of the AST" Else Say "astcheck:" bad "difference(s) in" checked "classes of the AST" Exit bad Known: Procedure Use Arg known, reason, words Do w Over words~space~makeArray( " " ) known[w] = reason End Return -- The classes of a package and of those it requires. Walk: Procedure Expose seen found Use Arg p If seen~hasIndex( p ) Then Return seen~put( p ) Do c Over p~classes~allItems If \ IsNode( c ) Then Iterate found[ c~id ] = HasRCompile( c ) End Do q Over p~importedPackages Call Walk q End Return IsNode: Procedure Use Arg c Do base Over .Array~of( .Rexx.Clause, .Rexx.Expression, .Rexx.Term ) If c == base | c~isSubclassOf( base ) Then Return 1 End Return 0 -- (Class~method raises an error when the class has no such method.) HasRCompile: Procedure Signal On Syntax Name NoRCompile m = Arg(1)~method( "RCOMPILE" ) Return 1 NoRCompile: Return 0 ::Requires "modules/rvm/RVM.Compiler.cls"