Newer version, safety commit

This commit is contained in:
ceriel
1986-04-03 00:44:39 +00:00
parent 5bf6f42cd7
commit a4e3f3b499
13 changed files with 261 additions and 134 deletions

View File

@@ -15,41 +15,44 @@ static char *RcsId = "$Header$";
static int maxscope; /* maximum assigned scope number */
struct scope *currscope;
struct scope *CurrentScope, *GlobalScope;
/* STATICALLOCDEF "scope" */
/* Open a scope that is either open (automatic imports) or closed.
A closed scope is handled by adding an extra entry to the list
with scope number 0. This has two purposes: it makes scope 0
visible, and it marks the end of a visibility list.
Scope 0 is the pervasive scope, the one that is always visible.
A disadvantage of this method is that we cannot open scope 0
explicitly.
*/
open_scope(scopetype, scopenr)
open_scope(scopetype, scope)
{
/* Open a scope that is either open (automatic imports) or closed.
A closed scope is handled by adding an extra entry to the list
with scope number 0. This has two purposes: it makes scope 0
visible, and it marks the end of a visibility list.
Scope 0 is the pervasive scope, the one that is always visible.
A disadvantage of this method is that we cannot open scope 0
explicitly.
*/
register struct scope *sc = new_scope();
register struct scope *sc1;
sc->sc_scope = scopenr == 0 ? ++maxscope : scopenr;
sc->sc_scope = scope == 0 ? ++maxscope : scope;
sc->sc_forw = 0; sc->sc_def = 0;
assert(scopetype == OPENSCOPE || scopetype == CLOSEDSCOPE);
DO_DEBUG(debug(1, "Opening a %s scope", scopetype == OPENSCOPE ? "open" : "closed"));
sc1 = currscope;
DO_DEBUG(debug(1, "Opening a %s scope",
scopetype == OPENSCOPE ? "open" : "closed"));
sc1 = CurrentScope;
if (scopetype == CLOSEDSCOPE) {
sc1 = new_scope();
sc1->sc_scope = 0; /* Pervasive scope nr */
sc1->next = currscope;
sc1->sc_forw = 0; sc1->sc_def = 0;
sc1->next = CurrentScope;
}
sc->next = sc1;
currscope = sc;
CurrentScope = sc;
}
static rem_forwards();
close_scope()
{
register struct scope *sc = currscope;
register struct scope *sc = CurrentScope;
assert(sc != 0);
DO_DEBUG(debug(1, "Closing a scope"));
@@ -60,7 +63,7 @@ close_scope()
sc = sc->next;
free_scope(sc1);
}
currscope = sc->next;
CurrentScope = sc->next;
free_scope(sc);
}
@@ -69,8 +72,9 @@ init_scope()
register struct scope *sc = new_scope();
sc->sc_scope = 0;
sc->next = 0;
currscope = sc;
sc->sc_forw = 0;
sc->sc_def = 0;
CurrentScope = sc;
}
int
@@ -87,29 +91,29 @@ struct forwards {
/* STATICALLOCDEF "forwards" */
/* Enter a forward reference into a list belonging to the
current scope. This is used for POINTER declarations, which
may have forward references that must howewer be declared in the
same scope.
*/
Forward(tk, ptp)
struct token *tk;
struct type **ptp;
{
/* Enter a forward reference into a list belonging to the
current scope. This is used for POINTER declarations, which
may have forward references that must howewer be declared in the
same scope.
*/
register struct forwards *f = new_forwards();
f->fo_tok = *tk;
f->fo_ptyp = ptp;
f->next = currscope->sc_forw;
currscope->sc_forw = f;
f->next = CurrentScope->sc_forw;
CurrentScope->sc_forw = f;
}
/* When closing a scope, all forward references must be resolved
*/
static
rem_forwards(fo)
struct forwards *fo;
{
/* When closing a scope, all forward references must be resolved
*/
register struct forwards *f;
struct token savetok;
register struct def *df;
@@ -118,9 +122,10 @@ rem_forwards(fo)
savetok = dot;
while (f = fo) {
dot = f->fo_tok;
df = lookfor(dot.TOK_IDF, currscope, 1);
df = lookfor(dot.TOK_IDF, CurrentScope, 1);
if (!(df->df_kind & (D_TYPE | D_HTYPE | D_ERROR))) {
error("identifier \"%s\" not a type", df->df_idf->id_text);
error("identifier \"%s\" not a type",
df->df_idf->id_text);
}
*(f->fo_ptyp) = df->df_type;
fo = f->next;