[Oberon] Module aliases - what is the correct way to handle them
Andreas Pirklbauer
andreas_pirklbauer at yahoo.com
Sat Mar 7 11:21:53 CET 2020
Here is one possible way to handle import aliases, as currently used in Extended Oberon.
Other possible variants (either more or less restrictive) do exist, of course.
PROCEDURE ThisModule(name, orgname: ORS.Ident; decl: BOOLEAN; key: LONGINT): Object;
VAR mod: Module; obj, obj1: Object;
BEGIN obj1 := topScope; obj := obj1.next; (*search for module*)
WHILE (obj # NIL) & (obj(Module).orgname # orgname) DO obj1 := obj; obj := obj1.next END ;
IF obj = NIL THEN (*new module, search for alias*)
obj := topScope.next;
WHILE (obj # NIL) & (obj.name # name) DO obj := obj.next END ;
IF obj = NIL THEN (*insert new module*)
NEW(mod); mod.class := Mod; mod.rdo := FALSE;
mod.name := name; mod.orgname := orgname; mod.val := key;
mod.lev := nofmod; INC(nofmod); mod.type := noType; mod.dsc := NIL; mod.next := NIL;
obj1.next := mod; obj := mod
ELSIF decl THEN
IF obj.rdo THEN ORS.Mark("mult def") ELSE ORS.Mark("invalid import order") END
ELSE ORS.Mark("conflict with alias")
END
ELSIF decl THEN (*module already present, explicit import by declaration*)
IF obj.rdo THEN ORS.Mark("mult def") ELSE ORS.Mark("invalid import order") END
END ;
RETURN obj
END ThisModule;
Sample test suite with the expected error messages in a set of possible usage scenarios:
http://github.com/andreaspirklbauer/Oberon-test-module-aliases/blob/master/Sources/TestAliases.Mod
More information about the Oberon
mailing list