From a92c8bf067d0e428dd3ec8539230fefe9d0b660e Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 16 Dec 1986 15:22:33 +0000 Subject: [PATCH] D_BUSY added, to check recursive deps in def modules --- lang/m2/comp/def.H | 5 ++--- lang/m2/comp/defmodule.c | 6 +++++- lang/m2/comp/program.g | 2 ++ lang/m2/comp/type.c | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lang/m2/comp/def.H b/lang/m2/comp/def.H index d27f32c72..3462d4b25 100644 --- a/lang/m2/comp/def.H +++ b/lang/m2/comp/def.H @@ -97,7 +97,7 @@ struct def { /* list of definitions for a name */ #define D_VALUE (D_PROCEDURE|D_VARIABLE|D_FIELD|D_ENUM|D_CONST|D_PROCHEAD) #define D_ISTYPE (D_HIDDEN|D_TYPE|D_FTYPE) #define is_type(dfx) ((dfx)->df_kind & D_ISTYPE) - char df_flags; + unsigned short df_flags; #define D_NOREG 0x01 /* set if it may not reside in a register */ #define D_USED 0x02 /* set if used (future use ???) */ #define D_DEFINED 0x04 /* set if it is assigned a value (future use ???) */ @@ -105,6 +105,7 @@ struct def { /* list of definitions for a name */ #define D_VALPAR 0x10 /* set if it is a value parameter */ #define D_EXPORTED 0x20 /* set if exported */ #define D_QEXPORTED 0x40 /* set if qualified exported */ +#define D_BUSY 0x80 /* set if busy reading this definition module */ struct type *df_type; union { struct module df_module; @@ -120,8 +121,6 @@ struct def { /* list of definitions for a name */ } df_value; }; -#define SetUsed(df) ((df)->df_flags |= D_USED) - /* ALLOCDEF "def" 50 */ extern struct def diff --git a/lang/m2/comp/defmodule.c b/lang/m2/comp/defmodule.c index 2fe30eadc..d5f68767e 100644 --- a/lang/m2/comp/defmodule.c +++ b/lang/m2/comp/defmodule.c @@ -55,7 +55,7 @@ GetDefinitionModule(id, incr) We may have to read the definition module itself. Also increment level by "incr". */ - struct def *df; + register struct def *df; static int level; struct scopelist *vis; @@ -101,6 +101,10 @@ GetDefinitionModule(id, incr) df->mod_vis = vis; } } + else if (df->df_flags & D_BUSY) { + error("definition module \"%s\" depends on itself", + id->id_text); + } else if (df == Defined && level == 1) { error("cannot import from currently defined module"); df->df_kind = D_ERROR; diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 6867279d0..40d8113a2 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -121,6 +121,7 @@ DefinitionModule } : DEFINITION MODULE IDENT { df = define(dot.TOK_IDF, GlobalScope, D_MODULE); + df->df_flags |= D_BUSY; if (!Defined) Defined = df; if (df->df_idf != DefId) { error("DEFINITION MODULE name is not \"%s\"", @@ -155,6 +156,7 @@ node_warning(exportlist, W_OLDFASHIONED, "export list in definition module ignor } DefinitionModule--; match_id(df->df_idf, dot.TOK_IDF); + df->df_flags &= ~D_BUSY; } '.' ; diff --git a/lang/m2/comp/type.c b/lang/m2/comp/type.c index a7003717c..cea61145a 100644 --- a/lang/m2/comp/type.c +++ b/lang/m2/comp/type.c @@ -383,7 +383,7 @@ set_type(tp) } tp = construct_type(T_SET, tp); - tp->tp_size = WA(((ub - lb) + 8) >> 3); + tp->tp_size = WA((ub - lb + 8) >> 3); return tp; }