(* Copyright (C) 1990, Digital Equipment Corporation. *) (* All rights reserved. *) (* See the file COPYRIGHT for a full description. *) (* Last modified on Wed Mar 21 01:32:00 1990 by muller *) INTERFACE M3Scope; (* A Scope.T consists of two parts: (1) a mapping that associates names with constants, types, variables, interfaces, modules, procedures, operators, or exceptions (that is, with any of the things that a name can denote in Modula-3), and (2) a collection of revelations about opaque types. When an abstract syntax tree (or AST) is decorated by the type checker, each node of the AST that introduces a scope is labelled with a Scope.T that records the bindings of the names introduced at that scope level, together with the revelations that are visible at that level. Scopes are arranged in a tree structure that reflects their nesting in the program text; if a look-up on an identifier fails in a scope, the implementation continues by looking up the identifier in the parent scope, the parent's parent, and so on, until the lookup succeeds or finally fails on the root scope. *) IMPORT M3Type, Atom, M3Entity, Property; TYPE T <: Property.Set; PROCEDURE New(scp: T): T; (* Return a new scope with parent scp in which no names are bound. If s is NIL, the new scope is a root scope. *) PROCEDURE Parent(scp: T): T; (* Return the parent of scp, or NIL if s is a root scope. *) PROCEDURE Lookup(scp: T; id: Atom.T; localOnly := FALSE): M3Entity.T; (* Return the entity associated with the name id in the scope scp. Returns NIL if id is unbound. If localOnly is FALSE, then all scopes on the path from scp to scp's root are searched in order; otherwise only s is searched. *) PROCEDURE KnownSuperType(scp: T; t1: M3Type.Opaque): M3Type.Reference; (* Return the minimal (under <:) type t such that the revelations and declarations in the scope scp and its parent scopes imply that t1 <: t. *) PROCEDURE Names(scp: T): REF ARRAY OF Atom.T; (* Return the list of names bound in scp. *) PROCEDURE Bind(scp: T; id: Atom.T; e: M3Entity.T); (* Bind id to e in scp. This creates a new binding in scp; it never affects scp's ancestors. It is a checked runtime error if id is already bound to something in scp. *) PROCEDURE RevealSame(scp: T; t1: M3Type.Opaque; t2: M3Type.Reference); (* Add the revelation t1 = t2 to the scope scp. *) PROCEDURE RevealSubtype(scp: T; t1: M3Type.Opaque; t2: M3Type.Reference); (* Add the revelation t1 <: t2 to the scope scp. *) PROCEDURE Minimize (scp: T; t: M3Type.T): M3Type.T; (* Computes the minimum representative for type t in scope scp. *) PROCEDURE IsEqual (scp: T; a, b: M3Type.T): BOOLEAN; (* TRUE iff a and b are known to be the same in scope scp. *) PROCEDURE IsSubtype (scp: T; a, b: M3Type.T): BOOLEAN; (* TRUE iff a is known to be a subtype of b in scope scp. *) PROCEDURE IsAssignable (scp: T; a, b: M3Type.T): BOOLEAN; (* TRUE iff b is known to be assignable to a in scope scp. *) END M3Scope.