1 /* $Id: scope.cc,v 1.4 1994/06/24 11:01:09 ceriel Exp $ */
17 p_scope PervasiveScope, CurrentScope, FileScope;
19 /* STATICALLOCDEF "scope" 10 */
21 static AVL_tree ScopeTree;
27 register p_scope c1 = (p_scope)s1, c2 = (p_scope)s2;
29 return c1->sc_start < c2->sc_start
31 : c1->sc_start == c2->sc_start
37 open_scope(name, has_activation)
41 register p_scope sc = new_scope();
43 sc->sc_has_activation_record = has_activation;
44 sc->sc_static_encl = CurrentScope;
45 sc->sc_definedby = name;
46 sc->sc_proclevel = CurrentScope->sc_proclevel;
47 /* sc_proclevel possibly reset by caller */
53 register p_scope sc = new_scope();
57 open_scope((p_symbol) 0, 0); /* this one will be closed at the
60 ScopeTree = create_avl_tree(cmp_starts);
65 register p_scope sc = CurrentScope;
68 CurrentScope = sc->sc_static_encl;
74 add_to_avl_tree(ScopeTree, (char *)scope);
77 /* extern p_scope get_scope_from_addr(t_addr a);
78 Returns the scope of the code at address 'a', or 0 if it could not be found.
81 get_scope_from_addr(a)
87 return (p_scope) find_ngt(ScopeTree, (char *) &sc);
90 /* extern p_scope get_next_scope_from_addr(t_addr a);
91 Returns the scope following the one of the code at address 'a',
92 and that has an activation record,
93 or 0 if it could not be found.
96 get_next_scope_from_addr(a)
103 p_scope psc = (p_scope) find_nlt(ScopeTree, (char *) &sc);
104 if (! psc || psc->sc_has_activation_record) return psc;
105 sc.sc_start = psc->sc_start+1;
110 /* extern int has_static_link(p_scope sc);
111 Returns 1 if the procedure of this scope takes a static link.
117 return sc->sc_proclevel > 1;
120 /* extern p_scope base_scope(p_scope sc);
121 Returns the closest enclosing scope of 'sc' that has an activation record.
127 while (sc && ! sc->sc_has_activation_record) {
128 sc = sc->sc_static_encl;
133 /* extern int scope_encloses(p_scope scope, from_scope);
134 Returns 1 if scope encloses from from_scope, 0 otherwise.
137 scope_encloses(scope, from_scope)
138 p_scope scope, from_scope;
140 register p_scope sc = from_scope;
143 if (sc == scope) return 1;
144 sc = sc->sc_static_encl;