2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 * Author: Ceriel J.H. Jacobs
8 /* L O O K U P R O U T I N E S */
10 /* $Id: lookup.c,v 1.19 1994/06/24 12:41:18 ceriel Exp $ */
28 extern char options[];
32 lookup(id, scope, import, flags)
36 /* Look up a definition of an identifier in scope "scope".
37 Make the "def" list self-organizing.
38 Return a pointer to its "def" structure if it exists,
41 register t_def *df, *df1;
43 /* Look in the chain of definitions of this "id" for one with scope
46 for (df = id->id_def, df1 = 0;
47 df && df->df_scope != scope;
48 df1 = df, df = df->df_next) { /* nothing */ }
50 if (! df && import && scopeclosed(scope)) {
51 for (df = id->id_def, df1 = 0;
52 df && df->df_scope != PervasiveScope;
53 df1 = df, df = df->df_next) { /* nothing */ }
60 /* Put the definition in front
62 df1->df_next = df->df_next;
63 df->df_next = id->id_def;
66 df->df_flags |= flags;
67 while (df->df_kind & import) {
68 assert(df->imp_def != 0);
71 DO_DEBUG(options['S'], print("lookup %s, %x\n", id->id_text, df->df_kind));
77 lookfor(id, vis, message, flags)
79 register t_scopelist *vis;
81 /* Look for an identifier in the visibility range started by "vis".
82 If it is not defined create a dummy definition and,
83 if message is set, give an error message
85 register t_scopelist *sc;
89 for (sc = vis; sc; sc = nextvisible(sc)) {
90 df = lookup(id->nd_IDF, sc->sc_scope, D_IMPORTED, flags);
92 if (message && df->df_kind == D_FORWARD) {
94 while (sc && sc->sc_scope != df->df_scope) {
100 if (pass_1 && message) {
102 while (vis->sc_scope->sc_level >
103 sc->sc_scope->sc_level ||
105 vis->sc_scope->sc_level >=
106 sc->sc_scope->sc_level)) {
109 D_INUSE)-> imp_def = df;
110 vis = enclosing(vis);
117 if (message) id_not_declared(id);
119 return MkDef(id->nd_IDF, vis->sc_scope, D_ERROR);