INTERFACEM3CUnit ; IMPORT Rd, M3FindFile, OSError; IMPORT M3AST_AS, M3AST_FE; TYPE (* for convenience we alias the types that this interface uses from M3AST_FE. *) Uid = M3AST_FE.Unit_uid; State = M3AST_FE.Unit_state; Status = M3AST_FE.Unit_status; Type = M3AST_FE.Unit_type; TypeSet = SET OF Type; CONST Errors = M3AST_FE.Unit_Errors; AllPhases = M3AST_FE.Unit_AllPhases; AllTypes = TypeSet{FIRST(Type)..LAST(Type)}; Interfaces = TypeSet{Type.Interface, Type.Interface_gen_def, Type.Interface_gen_ins}; Modules = TypeSet{Type.Module, Type.Module_gen_def, Type.Module_gen_ins}; TYPE Form = {Source, Ast, DontCare}; PROCEDURE FindUnit( f: M3FindFile.T; name: TEXT; unitType: Type; VAR (*inout*) uf: Form; VAR (*out*) id: Uid) : Rd.T RAISES {OSError.E};
Given a name andunitType
, indicating whether an interface or a module is required,FindSource
attempts to open a stream to an file containing a representation of a compilation unit. The representation can be requested as: i) A source file; in this caseid
is set to be a unique id for the source and the returned stream can be used to parse the source. ii) A pickled graph; in this caseid
is set to a unique id for the pickle and the returned stream should be used tounpickle
the graph. iii) Dontcare. Either will do.If
FindUnit
fails to find a file containing the requested compilation unit, it returnsNIL
. If an errors occurs in opening a found file,OSError.E
is raised, as perFileRd.Open
.
PROCEDURE FindStandard( f: M3FindFile.T; VAR (*inout*) uf: Form; VAR (*out*) id: Uid): Rd.T RAISES {M3FindFile.Failed, OSError.E};
This procedure is a special case of FindUnit
. It attempts to open a
stream to the representation of the standard interface.
PROCEDURE TextName(id: Uid): TEXT;
Given a Uid
this procedure returns a text, suitable for use
in error messages
PROCEDURE TypeName(ut: Type): TEXT;
Returnsinterface
ormodule
based onut
.
PROCEDURE ToType(u: M3AST_AS.UNIT): Type;
u # NIL, maps from ISTYPE(u, ..) to Type
.
PROCEDURE ToGenIns( cu: M3AST_AS.Compilation_Unit; VAR (*inout*) ut: Type): M3AST_AS.Compilation_Unit;
Ifcu
is a generic instantiation, return the instantiated unit, (i.e. cu.as_root.sm_ins_comp_unit). The value ofut
is also updated.
PROCEDURE Equal(id1, id2: Uid): BOOLEAN;
TRUE ifid1
andid2
represent the same unit
<*INLINE*> PROCEDURE InclState(VAR status: Status; state: State);
status := status + Status{state};
<*INLINE*> PROCEDURE ExclState(VAR status: Status; state: State);
status := status - Status{state};
END M3CUnit.