typedef unsigned int nameKey_Name;
# define nameKey_NulName 0
-typedef struct mcPretty_writeProc_p mcPretty_writeProc;
-
typedef struct symbolKey__T8_r symbolKey__T8;
typedef symbolKey__T8 *symbolKey_symbolTree;
+typedef struct mcPretty_writeProc_p mcPretty_writeProc;
+
typedef struct mcPretty_writeLnProc_p mcPretty_writeLnProc;
typedef unsigned int FIO_File;
typedef struct symbolKey_performOperation_p symbolKey_performOperation;
# define ASCII_tab ASCII_ht
-typedef struct alists__T13_r alists__T13;
-
-typedef alists__T13 *alists_alist;
-
-typedef struct alists__T14_a alists__T14;
-
# define ASCII_ht (char) 011
# define ASCII_lf ASCII_nl
# define ASCII_nl (char) 012
typedef struct decl_cnameT_r decl_cnameT;
+typedef struct decl__T15_r decl__T15;
+
+typedef decl__T15 *decl_group;
+
# define MaxBuf 127
# define maxNoOfElements 5
typedef enum {decl_explist, decl_funccall, decl_exit, decl_return, decl_stmtseq, decl_comment, decl_halt, decl_new, decl_dispose, decl_inc, decl_dec, decl_incl, decl_excl, decl_length, decl_nil, decl_true, decl_false, decl_address, decl_loc, decl_byte, decl_word, decl_csizet, decl_cssizet, decl_char, decl_cardinal, decl_longcard, decl_shortcard, decl_integer, decl_longint, decl_shortint, decl_real, decl_longreal, decl_shortreal, decl_bitset, decl_boolean, decl_proc, decl_ztype, decl_rtype, decl_complex, decl_longcomplex, decl_shortcomplex, decl_type, decl_record, decl_varient, decl_var, decl_enumeration, decl_subrange, decl_array, decl_subscript, decl_string, decl_const, decl_literal, decl_varparam, decl_param, decl_varargs, decl_optarg, decl_pointer, decl_recordfield, decl_varientfield, decl_enumerationfield, decl_set, decl_proctype, decl_procedure, decl_def, decl_imp, decl_module, decl_loop, decl_while, decl_for, decl_repeat, decl_case, decl_caselabellist, decl_caselist, decl_range, decl_assignment, decl_if, decl_elsif, decl_constexp, decl_neg, decl_cast, decl_val, decl_plus, decl_sub, decl_div, decl_mod, decl_mult, decl_divide, decl_in, decl_adr, decl_size, decl_tsize, decl_ord, decl_float, decl_trunc, decl_chr, decl_abs, decl_cap, decl_high, decl_throw, decl_unreachable, decl_cmplx, decl_re, decl_im, decl_min, decl_max, decl_componentref, decl_pointerref, decl_arrayref, decl_deref, decl_equal, decl_notequal, decl_less, decl_greater, decl_greequal, decl_lessequal, decl_lsl, decl_lsr, decl_lor, decl_land, decl_lnot, decl_lxor, decl_and, decl_or, decl_not, decl_identlist, decl_vardecl, decl_setvalue} decl_nodeT;
typedef struct wlists__T9_r wlists__T9;
+typedef struct alists__T13_r alists__T13;
+
typedef struct mcPretty__T12_r mcPretty__T12;
typedef struct wlists__T10_a wlists__T10;
+typedef Indexing__T5 *Indexing_Index;
+
typedef struct DynamicStrings__T7_a DynamicStrings__T7;
-typedef Indexing__T5 *Indexing_Index;
+typedef struct alists__T14_a alists__T14;
typedef mcComment__T6 *mcComment_commentDesc;
typedef wlists__T9 *wlists_wlist;
-typedef mcPretty__T12 *mcPretty_pretty;
+typedef alists__T13 *alists_alist;
-typedef void (*mcPretty_writeProc_t) (char);
-struct mcPretty_writeProc_p { mcPretty_writeProc_t proc; };
+typedef mcPretty__T12 *mcPretty_pretty;
struct symbolKey__T8_r {
nameKey_Name name;
symbolKey_symbolTree right;
};
+typedef void (*mcPretty_writeProc_t) (char);
+struct mcPretty_writeProc_p { mcPretty_writeProc_t proc; };
+
typedef void (*mcPretty_writeLnProc_t) (void);
struct mcPretty_writeLnProc_p { mcPretty_writeLnProc_t proc; };
typedef void (*symbolKey_performOperation_t) (void *);
struct symbolKey_performOperation_p { symbolKey_performOperation_t proc; };
-struct alists__T14_a { void * array[MaxnoOfelements-1+1]; };
typedef void (*Indexing_IndexProcedure_t) (void *);
struct Indexing_IndexProcedure_p { Indexing_IndexProcedure_t proc; };
bool init;
};
+struct decl__T15_r {
+ alists_alist todoQ;
+ alists_alist partialQ;
+ alists_alist doneQ;
+ decl_group next;
+ };
+
struct Indexing__T5_r {
void *ArrayStart;
unsigned int ArraySize;
struct wlists__T10_a { unsigned int array[maxNoOfElements-1+1]; };
struct DynamicStrings__T7_a { char array[(MaxBuf-1)+1]; };
-struct alists__T13_r {
- unsigned int noOfelements;
- alists__T14 elements;
- alists_alist next;
- };
-
+struct alists__T14_a { void * array[MaxnoOfelements-1+1]; };
struct decl_intrinsicT_r {
decl_node args;
unsigned int noArgs;
wlists_wlist next;
};
+struct alists__T13_r {
+ unsigned int noOfelements;
+ alists__T14 elements;
+ alists_alist next;
+ };
+
struct mcPretty__T12_r {
mcPretty_writeProc write_;
mcPretty_writeLnProc writeln;
DynamicStrings_DebugInfo debug;
};
+static decl_group freeGroup;
+static decl_group globalGroup;
static FIO_File outputFile;
static decl_language lang;
static decl_node bitsperunitN;
static symbolKey_symbolTree baseSymbols;
static decl_outputStates outputState;
static mcPretty_pretty doP;
-static alists_alist todoQ;
-static alists_alist partialQ;
-static alists_alist doneQ;
static bool mustVisitScope;
static bool simplified;
static unsigned int tempCount;
/*
RIndex - returns the indice of the last occurance of, ch,
- in String, s. The search starts at position, o.
- -1 is returned if, ch, is not found.
+ in String, s. The search starts at position, o.
+ -1 is returned if, ch, is not found. The search
+ is performed left to right.
*/
extern "C" int DynamicStrings_RIndex (DynamicStrings_String s, char ch, unsigned int o);
+/*
+ ReverseIndex - returns the indice of the last occurance of ch
+ in String s. The search starts at position o
+ and searches from right to left. The start position
+ may be indexed negatively from the right (-1 is the
+ last index).
+ The return value if ch is found will always be positive.
+ -1 is returned if ch is not found.
+*/
+
+extern "C" int DynamicStrings_ReverseIndex (DynamicStrings_String s, char ch, int o);
+
/*
RemoveComment - assuming that, comment, is a comment delimiter
which indicates anything to its right is a comment
extern "C" alists_alist alists_duplicateList (alists_alist l);
+/*
+ equalList - returns TRUE if left contains the same information as right.
+*/
+
+extern "C" bool alists_equalList (alists_alist left, alists_alist right);
+
/*
initList - creates a new wlist, l.
*/
static void disposeNode (decl_node *n);
+/*
+ newGroup -
+*/
+
+static void newGroup (decl_group *g);
+
+/*
+ initGroup - returns a group which with all lists initialized.
+*/
+
+static decl_group initGroup (void);
+
+/*
+ killGroup - deallocate the group and place the group record into the freeGroup list.
+*/
+
+static void killGroup (decl_group *g);
+
+/*
+ dupGroup - If g is not NIL then destroy g.
+ Return a duplicate of GlobalGroup (not g).
+*/
+
+static decl_group dupGroup (decl_group g);
+
+/*
+ equalGroup - return TRUE if group left = right.
+*/
+
+static bool equalGroup (decl_group left, decl_group right);
+
/*
isLocal - returns TRUE if symbol, n, is locally declared in a procedure.
*/
static void populateTodo (decl_nodeProcedure p);
/*
- topologicallyOut -
+ topologicallyOut - keep trying to resolve the todoQ and partialQ
+ until there is no change from the global group.
*/
static void topologicallyOut (decl_nodeProcedure c, decl_nodeProcedure t, decl_nodeProcedure v, decl_nodeProcedure tp, decl_nodeProcedure pc, decl_nodeProcedure pt, decl_nodeProcedure pv);
}
+/*
+ newGroup -
+*/
+
+static void newGroup (decl_group *g)
+{
+ if (freeGroup == NULL)
+ {
+ Storage_ALLOCATE ((void **) &(*g), sizeof (decl__T15));
+ }
+ else
+ {
+ (*g) = freeGroup;
+ freeGroup = freeGroup->next;
+ }
+}
+
+
+/*
+ initGroup - returns a group which with all lists initialized.
+*/
+
+static decl_group initGroup (void)
+{
+ decl_group g;
+
+ newGroup (&g);
+ g->todoQ = alists_initList ();
+ g->partialQ = alists_initList ();
+ g->doneQ = alists_initList ();
+ g->next = NULL;
+ return g;
+ /* static analysis guarentees a RETURN statement will be used before here. */
+ __builtin_unreachable ();
+}
+
+
+/*
+ killGroup - deallocate the group and place the group record into the freeGroup list.
+*/
+
+static void killGroup (decl_group *g)
+{
+ alists_killList (&(*g)->todoQ);
+ alists_killList (&(*g)->partialQ);
+ alists_killList (&(*g)->doneQ);
+ (*g)->next = freeGroup;
+ freeGroup = (*g);
+}
+
+
+/*
+ dupGroup - If g is not NIL then destroy g.
+ Return a duplicate of GlobalGroup (not g).
+*/
+
+static decl_group dupGroup (decl_group g)
+{
+ if (g != NULL)
+ {
+ /* Kill old group. */
+ killGroup (&g);
+ }
+ newGroup (&g);
+ /* Copy all lists. */
+ g->todoQ = alists_duplicateList (globalGroup->todoQ);
+ g->partialQ = alists_duplicateList (globalGroup->partialQ);
+ g->doneQ = alists_duplicateList (globalGroup->doneQ);
+ g->next = NULL;
+ return g;
+ /* static analysis guarentees a RETURN statement will be used before here. */
+ __builtin_unreachable ();
+}
+
+
+/*
+ equalGroup - return TRUE if group left = right.
+*/
+
+static bool equalGroup (decl_group left, decl_group right)
+{
+ return (left == right) || (((alists_equalList (left->todoQ, right->todoQ)) && (alists_equalList (left->partialQ, right->partialQ))) && (alists_equalList (left->doneQ, right->doneQ)));
+ /* static analysis guarentees a RETURN statement will be used before here. */
+ __builtin_unreachable ();
+}
+
+
/*
isLocal - returns TRUE if symbol, n, is locally declared in a procedure.
*/
static void doConstC (decl_node n)
{
- if (! (alists_isItemInList (doneQ, reinterpret_cast<void *> (n))))
+ if (! (alists_isItemInList (globalGroup->doneQ, reinterpret_cast<void *> (n))))
{
mcPretty_print (doP, (const char *) "# define ", 11);
doFQNameC (doP, n);
mcPretty_setNeedSpace (doP);
doExprC (doP, n->constF.value);
mcPretty_print (doP, (const char *) "\\n", 2);
- alists_includeItemIntoList (doneQ, reinterpret_cast<void *> (n));
+ alists_includeItemIntoList (globalGroup->doneQ, reinterpret_cast<void *> (n));
}
}
static void addTodo (decl_node n)
{
- if (((n != NULL) && (! (alists_isItemInList (partialQ, reinterpret_cast<void *> (n))))) && (! (alists_isItemInList (doneQ, reinterpret_cast<void *> (n)))))
+ if (((n != NULL) && (! (alists_isItemInList (globalGroup->partialQ, reinterpret_cast<void *> (n))))) && (! (alists_isItemInList (globalGroup->doneQ, reinterpret_cast<void *> (n)))))
{
mcDebug_assert (! (decl_isVarient (n)));
mcDebug_assert (! (decl_isVarientField (n)));
mcDebug_assert (! (decl_isDef (n)));
- alists_includeItemIntoList (todoQ, reinterpret_cast<void *> (n));
+ alists_includeItemIntoList (globalGroup->todoQ, reinterpret_cast<void *> (n));
}
}
static decl_dependentState walkDependants (alists_alist l, decl_node n)
{
- if ((n == NULL) || (alists_isItemInList (doneQ, reinterpret_cast<void *> (n))))
+ if ((n == NULL) || (alists_isItemInList (globalGroup->doneQ, reinterpret_cast<void *> (n))))
{
return decl_completed;
}
decl_node t;
t = decl_getType (n);
- if (alists_isItemInList (doneQ, reinterpret_cast<void *> (t)))
+ if (alists_isItemInList (globalGroup->doneQ, reinterpret_cast<void *> (t)))
{
return decl_completed;
}
- else if (alists_isItemInList (partialQ, reinterpret_cast<void *> (t)))
+ else if (alists_isItemInList (globalGroup->partialQ, reinterpret_cast<void *> (t)))
{
/* avoid dangling else. */
return decl_blocked;
if (mcOptions_getDebugTopological ())
{
/* avoid gcc warning by using compound statement even if not strictly necessary. */
- if (alists_isItemInList (todoQ, reinterpret_cast<void *> (n)))
+ if (alists_isItemInList (globalGroup->todoQ, reinterpret_cast<void *> (n)))
{
db ((const char *) "{T", 2, n);
outText (doP, (const char *) "}", 1);
}
- else if (alists_isItemInList (partialQ, reinterpret_cast<void *> (n)))
+ else if (alists_isItemInList (globalGroup->partialQ, reinterpret_cast<void *> (n)))
{
/* avoid dangling else. */
db ((const char *) "{P", 2, n);
outText (doP, (const char *) "}", 1);
}
- else if (alists_isItemInList (doneQ, reinterpret_cast<void *> (n)))
+ else if (alists_isItemInList (globalGroup->doneQ, reinterpret_cast<void *> (n)))
{
/* avoid dangling else. */
db ((const char *) "{D", 2, n);
static void queueBlocked (decl_node n)
{
- if (! ((alists_isItemInList (doneQ, reinterpret_cast<void *> (n))) || (alists_isItemInList (partialQ, reinterpret_cast<void *> (n)))))
+ if (! ((alists_isItemInList (globalGroup->doneQ, reinterpret_cast<void *> (n))) || (alists_isItemInList (globalGroup->partialQ, reinterpret_cast<void *> (n)))))
{
addTodo (n);
}
decl_node t;
t = decl_getType (n);
- if (alists_isItemInList (doneQ, reinterpret_cast<void *> (t)))
+ if (alists_isItemInList (globalGroup->doneQ, reinterpret_cast<void *> (t)))
{
return decl_completed;
}
/* if the type of, n, is done or partial then we can output pointer. */
t = decl_getType (n);
- if ((alists_isItemInList (partialQ, reinterpret_cast<void *> (t))) || (alists_isItemInList (doneQ, reinterpret_cast<void *> (t))))
+ if ((alists_isItemInList (globalGroup->partialQ, reinterpret_cast<void *> (t))) || (alists_isItemInList (globalGroup->doneQ, reinterpret_cast<void *> (t))))
{
/* pointer to partial can always generate a complete type. */
return decl_completed;
decl_dependentState s;
/* an array can only be declared if its data type has already been emitted. */
- if (! (alists_isItemInList (doneQ, reinterpret_cast<void *> (n->arrayF.type))))
+ if (! (alists_isItemInList (globalGroup->doneQ, reinterpret_cast<void *> (n->arrayF.type))))
{
s = walkDependants (l, n->arrayF.type);
queueBlocked (n->arrayF.type);
decl_node t;
t = decl_getType (n);
- if (alists_isItemInList (partialQ, reinterpret_cast<void *> (t)))
+ if (alists_isItemInList (globalGroup->partialQ, reinterpret_cast<void *> (t)))
{
/* parameter can be issued from a partial. */
return decl_completed;
decl_node t;
t = decl_getType (n);
- if (alists_isItemInList (partialQ, reinterpret_cast<void *> (t)))
+ if (alists_isItemInList (globalGroup->partialQ, reinterpret_cast<void *> (t)))
{
/* parameter can be issued from a partial. */
return decl_completed;
decl_node t;
t = decl_getType (n);
- if (alists_isItemInList (partialQ, reinterpret_cast<void *> (t)))
+ if (alists_isItemInList (globalGroup->partialQ, reinterpret_cast<void *> (t)))
{
/* parameter can be issued from a partial. */
return decl_completed;
mcDebug_assert (decl_isRecordField (n));
t = decl_getType (n);
- if (alists_isItemInList (partialQ, reinterpret_cast<void *> (t)))
+ if (alists_isItemInList (globalGroup->partialQ, reinterpret_cast<void *> (t)))
{
dbs (decl_partial, n);
return decl_partial;
}
- else if (alists_isItemInList (doneQ, reinterpret_cast<void *> (t)))
+ else if (alists_isItemInList (globalGroup->doneQ, reinterpret_cast<void *> (t)))
{
/* avoid dangling else. */
dbs (decl_completed, n);
decl_node t;
t = decl_getType (n);
- if (alists_isItemInList (partialQ, reinterpret_cast<void *> (t)))
+ if (alists_isItemInList (globalGroup->partialQ, reinterpret_cast<void *> (t)))
{} /* empty. */
else
{
{
if ((((decl_isType (n)) && ((decl_getType (n)) != NULL)) && (decl_isPointer (decl_getType (n)))) && ((allDependants (decl_getType (n))) == decl_completed))
{
- /* alists.includeItemIntoList (partialQ, getType (n)) ; */
+ /* alists.includeItemIntoList (globalGroup^.partialQ, getType (n)) ; */
outputHiddenComplete (n);
return true;
}
{
m = FormatStrings_Sprintf0 (DynamicStrings_InitString ((const char *) "\\n", 2));
m = DynamicStrings_KillString (SFIO_WriteS (FIO_StdOut, m));
- dumpQ ((const char *) "todo", 4, todoQ);
- dumpQ ((const char *) "partial", 7, partialQ);
- dumpQ ((const char *) "done", 4, doneQ);
+ dumpQ ((const char *) "todo", 4, globalGroup->todoQ);
+ dumpQ ((const char *) "partial", 7, globalGroup->partialQ);
+ dumpQ ((const char *) "done", 4, globalGroup->doneQ);
}
}
decl_node d;
i = 1;
- n = alists_noOfItemsInList (todoQ);
+ n = alists_noOfItemsInList (globalGroup->todoQ);
while (i <= n)
{
- d = static_cast<decl_node> (alists_getItemFromList (todoQ, i));
+ d = static_cast<decl_node> (alists_getItemFromList (globalGroup->todoQ, i));
if (tryComplete (d, c, t, v))
{
- alists_removeItemFromList (todoQ, reinterpret_cast<void *> (d));
- alists_includeItemIntoList (doneQ, reinterpret_cast<void *> (d));
+ alists_removeItemFromList (globalGroup->todoQ, reinterpret_cast<void *> (d));
+ alists_includeItemIntoList (globalGroup->doneQ, reinterpret_cast<void *> (d));
i = 1;
}
else if (tryPartial (d, pt))
{
/* avoid dangling else. */
- alists_removeItemFromList (todoQ, reinterpret_cast<void *> (d));
- alists_includeItemIntoList (partialQ, reinterpret_cast<void *> (d));
+ alists_removeItemFromList (globalGroup->todoQ, reinterpret_cast<void *> (d));
+ alists_includeItemIntoList (globalGroup->partialQ, reinterpret_cast<void *> (d));
i = 1;
}
else
/* avoid dangling else. */
i += 1;
}
- n = alists_noOfItemsInList (todoQ);
+ n = alists_noOfItemsInList (globalGroup->todoQ);
}
}
decl_node d;
i = 1;
- n = alists_noOfItemsInList (partialQ);
+ n = alists_noOfItemsInList (globalGroup->partialQ);
while (i <= n)
{
- d = static_cast<decl_node> (alists_getItemFromList (partialQ, i));
+ d = static_cast<decl_node> (alists_getItemFromList (globalGroup->partialQ, i));
if (tryCompleteFromPartial (d, t))
{
- alists_removeItemFromList (partialQ, reinterpret_cast<void *> (d));
- alists_includeItemIntoList (doneQ, reinterpret_cast<void *> (d));
+ alists_removeItemFromList (globalGroup->partialQ, reinterpret_cast<void *> (d));
+ alists_includeItemIntoList (globalGroup->doneQ, reinterpret_cast<void *> (d));
i = 1;
n -= 1;
}
{
if (mcOptions_getDebugTopological ())
{
- debugList ((const char *) "todo", 4, todoQ);
- debugList ((const char *) "partial", 7, partialQ);
+ debugList ((const char *) "todo", 4, globalGroup->todoQ);
+ debugList ((const char *) "partial", 7, globalGroup->partialQ);
}
}
unsigned int h;
alists_alist l;
- h = alists_noOfItemsInList (todoQ);
+ h = alists_noOfItemsInList (globalGroup->todoQ);
i = 1;
while (i <= h)
{
- n = static_cast<decl_node> (alists_getItemFromList (todoQ, i));
+ n = static_cast<decl_node> (alists_getItemFromList (globalGroup->todoQ, i));
l = alists_initList ();
visitNode (l, n, p);
alists_killList (&l);
- h = alists_noOfItemsInList (todoQ);
+ h = alists_noOfItemsInList (globalGroup->todoQ);
i += 1;
}
}
/*
- topologicallyOut -
+ topologicallyOut - keep trying to resolve the todoQ and partialQ
+ until there is no change from the global group.
*/
static void topologicallyOut (decl_nodeProcedure c, decl_nodeProcedure t, decl_nodeProcedure v, decl_nodeProcedure tp, decl_nodeProcedure pc, decl_nodeProcedure pt, decl_nodeProcedure pv)
{
- unsigned int tol;
- unsigned int pal;
- unsigned int to;
- unsigned int pa;
+ decl_group before;
populateTodo ((decl_nodeProcedure) {(decl_nodeProcedure_t) addEnumConst});
- tol = 0;
- pal = 0;
- to = alists_noOfItemsInList (todoQ);
- pa = alists_noOfItemsInList (partialQ);
- while ((tol != to) || (pal != pa))
- {
- dumpLists ();
- tryOutputTodo (c, t, v, tp);
- dumpLists ();
- tryOutputPartial (pt);
- tol = to;
- pal = pa;
- to = alists_noOfItemsInList (todoQ);
- pa = alists_noOfItemsInList (partialQ);
- }
+ before = NULL;
+ do {
+ before = dupGroup (before); /* Get a copy of the globalGroup and free before. */
+ dumpLists (); /* Get a copy of the globalGroup and free before. */
+ tryOutputTodo (c, t, v, tp);
+ dumpLists ();
+ tryOutputPartial (pt);
+ } while (! (equalGroup (before, globalGroup)));
+ killGroup (&before);
dumpLists ();
debugLists ();
}
static void addDone (decl_node n)
{
- alists_includeItemIntoList (doneQ, reinterpret_cast<void *> (n));
+ alists_includeItemIntoList (globalGroup->doneQ, reinterpret_cast<void *> (n));
}
addDone (n);
return ;
}
- if ((! (decl_isDef (n))) && ((decl_lookupImp (decl_getSymName (decl_getScope (n)))) == (decl_getMainModule ())))
+ if (false && ((decl_lookupImp (decl_getSymName (decl_getScope (n)))) == (decl_getMainModule ())))
{
mcMetaError_metaError1 ((const char *) "cyclic dependancy found between another module using {%1ad} from the definition module of the implementation main being compiled, use the --extended-opaque option to compile", 173, (const unsigned char *) &n, (sizeof (n)-1));
mcError_flushErrors ();
lang = decl_ansiC;
outputFile = FIO_StdOut;
doP = mcPretty_initPretty ((mcPretty_writeProc) {(mcPretty_writeProc_t) write_}, (mcPretty_writeLnProc) {(mcPretty_writeLnProc_t) writeln});
- todoQ = alists_initList ();
- partialQ = alists_initList ();
- doneQ = alists_initList ();
+ freeGroup = NULL;
+ globalGroup = initGroup ();
modUniverse = symbolKey_initTree ();
defUniverse = symbolKey_initTree ();
modUniverseI = Indexing_InitIndex (1);
init : BOOLEAN ;
END ;
+ group = POINTER TO RECORD
+ todoQ,
+ partialQ,
+ doneQ : alist ;
+ next : group ;
+ END ;
+
+
VAR
+ freeGroup,
+ globalGroup : group ; (* The global group of all alists. *)
outputFile : File ;
lang : language ;
bitsperunitN,
baseSymbols : symbolTree ;
outputState : outputStates ;
doP : pretty ;
- todoQ,
- partialQ,
- doneQ : alist ;
mustVisitScope,
simplified : BOOLEAN ;
tempCount : CARDINAL ;
END disposeNode ;
+(*
+ newGroup -
+*)
+
+PROCEDURE newGroup (VAR g: group) ;
+BEGIN
+ IF freeGroup = NIL
+ THEN
+ NEW (g)
+ ELSE
+ g := freeGroup ;
+ freeGroup := freeGroup^.next
+ END
+END newGroup ;
+
+
+(*
+ initGroup - returns a group which with all lists initialized.
+*)
+
+PROCEDURE initGroup () : group ;
+VAR
+ g: group ;
+BEGIN
+ newGroup (g) ;
+ WITH g^ DO
+ todoQ := alists.initList () ;
+ partialQ := alists.initList () ;
+ doneQ := alists.initList () ;
+ next := NIL
+ END ;
+ RETURN g
+END initGroup ;
+
+
+(*
+ killGroup - deallocate the group and place the group record into the freeGroup list.
+*)
+
+PROCEDURE killGroup (VAR g: group) ;
+BEGIN
+ alists.killList (g^.todoQ) ;
+ alists.killList (g^.partialQ) ;
+ alists.killList (g^.doneQ) ;
+ g^.next := freeGroup ;
+ freeGroup := g ;
+END killGroup ;
+
+
+(*
+ dupGroup - If g is not NIL then destroy g.
+ Return a duplicate of GlobalGroup (not g).
+*)
+
+PROCEDURE dupGroup (g: group) : group ;
+BEGIN
+ IF g # NIL
+ THEN
+ (* Kill old group. *)
+ killGroup (g)
+ END ;
+ newGroup (g) ;
+ WITH g^ DO
+ (* Copy all lists. *)
+ todoQ := alists.duplicateList (globalGroup^.todoQ) ;
+ partialQ := alists.duplicateList (globalGroup^.partialQ) ;
+ doneQ := alists.duplicateList (globalGroup^.doneQ) ;
+ next := NIL
+ END ;
+ RETURN g
+END dupGroup ;
+
+
+(*
+ equalGroup - return TRUE if group left = right.
+*)
+
+PROCEDURE equalGroup (left, right: group) : BOOLEAN ;
+BEGIN
+ RETURN ((left = right) OR
+ (alists.equalList (left^.todoQ, right^.todoQ) AND
+ alists.equalList (left^.partialQ, right^.partialQ) AND
+ alists.equalList (left^.doneQ, right^.doneQ)))
+END equalGroup ;
+
+
(*
getDeclaredDef - returns the token number associated with the nodes declaration
in the definition module.
PROCEDURE doConstC (n: node) ;
BEGIN
- IF NOT alists.isItemInList (doneQ, n)
+ IF NOT alists.isItemInList (globalGroup^.doneQ, n)
THEN
print (doP, "# define ") ;
doFQNameC (doP, n) ;
setNeedSpace (doP) ;
doExprC (doP, n^.constF.value) ;
print (doP, '\n') ;
- alists.includeItemIntoList (doneQ, n)
+ alists.includeItemIntoList (globalGroup^.doneQ, n)
END
END doConstC ;
PROCEDURE addTodo (n: node) ;
BEGIN
IF (n#NIL) AND
- (NOT alists.isItemInList (partialQ, n)) AND
- (NOT alists.isItemInList (doneQ, n))
+ (NOT alists.isItemInList (globalGroup^.partialQ, n)) AND
+ (NOT alists.isItemInList (globalGroup^.doneQ, n))
THEN
assert (NOT isVarient (n)) ;
assert (NOT isVarientField (n)) ;
assert (NOT isDef (n)) ;
- alists.includeItemIntoList (todoQ, n)
+ alists.includeItemIntoList (globalGroup^.todoQ, n)
END
END addTodo ;
PROCEDURE walkDependants (l: alist; n: node) : dependentState ;
BEGIN
- IF (n=NIL) OR alists.isItemInList (doneQ, n)
+ IF (n=NIL) OR alists.isItemInList (globalGroup^.doneQ, n)
THEN
RETURN completed
ELSIF alists.isItemInList (l, n)
t: node ;
BEGIN
t := getType (n) ;
- IF alists.isItemInList (doneQ, t)
+ IF alists.isItemInList (globalGroup^.doneQ, t)
THEN
RETURN completed
- ELSIF alists.isItemInList (partialQ, t)
+ ELSIF alists.isItemInList (globalGroup^.partialQ, t)
THEN
RETURN blocked
ELSE
BEGIN
IF getDebugTopological ()
THEN
- IF alists.isItemInList (todoQ, n)
+ IF alists.isItemInList (globalGroup^.todoQ, n)
THEN
db ('{T', n) ; outText (doP, '}')
- ELSIF alists.isItemInList (partialQ, n)
+ ELSIF alists.isItemInList (globalGroup^.partialQ, n)
THEN
db ('{P', n) ; outText (doP, '}')
- ELSIF alists.isItemInList (doneQ, n)
+ ELSIF alists.isItemInList (globalGroup^.doneQ, n)
THEN
db ('{D', n) ; outText (doP, '}')
END
PROCEDURE queueBlocked (n: node) ;
BEGIN
- IF NOT (alists.isItemInList (doneQ, n) OR alists.isItemInList (partialQ, n))
+ IF NOT (alists.isItemInList (globalGroup^.doneQ, n) OR
+ alists.isItemInList (globalGroup^.partialQ, n))
THEN
addTodo (n)
END
t: node ;
BEGIN
t := getType (n) ;
- IF alists.isItemInList (doneQ, t)
+ IF alists.isItemInList (globalGroup^.doneQ, t)
THEN
RETURN completed
ELSE
BEGIN
(* if the type of, n, is done or partial then we can output pointer. *)
t := getType (n) ;
- IF alists.isItemInList (partialQ, t) OR alists.isItemInList (doneQ, t)
+ IF alists.isItemInList (globalGroup^.partialQ, t) OR
+ alists.isItemInList (globalGroup^.doneQ, t)
THEN
(* pointer to partial can always generate a complete type. *)
RETURN completed
END ;
*)
(* an array can only be declared if its data type has already been emitted. *)
- IF NOT alists.isItemInList (doneQ, type)
+ IF NOT alists.isItemInList (globalGroup^.doneQ, type)
THEN
s := walkDependants (l, type) ;
queueBlocked (type) ;
t: node ;
BEGIN
t := getType (n) ;
- IF alists.isItemInList (partialQ, t)
+ IF alists.isItemInList (globalGroup^.partialQ, t)
THEN
(* parameter can be issued from a partial. *)
RETURN completed
t: node ;
BEGIN
t := getType (n) ;
- IF alists.isItemInList (partialQ, t)
+ IF alists.isItemInList (globalGroup^.partialQ, t)
THEN
(* parameter can be issued from a partial. *)
RETURN completed
t: node ;
BEGIN
t := getType (n) ;
- IF alists.isItemInList (partialQ, t)
+ IF alists.isItemInList (globalGroup^.partialQ, t)
THEN
(* parameter can be issued from a partial. *)
RETURN completed
BEGIN
assert (isRecordField (n)) ;
t := getType (n) ;
- IF alists.isItemInList (partialQ, t)
+ IF alists.isItemInList (globalGroup^.partialQ, t)
THEN
dbs (partial, n) ;
RETURN partial
- ELSIF alists.isItemInList (doneQ, t)
+ ELSIF alists.isItemInList (globalGroup^.doneQ, t)
THEN
dbs (completed, n) ;
RETURN completed
t: node ;
BEGIN
t := getType (n) ;
- IF alists.isItemInList (partialQ, t)
+ IF alists.isItemInList (globalGroup^.partialQ, t)
THEN
(* proctype can be generated from partial types. *)
ELSE
BEGIN
IF isType (n) AND (getType (n)#NIL) AND isPointer (getType (n)) AND (allDependants (getType (n)) = completed)
THEN
- (* alists.includeItemIntoList (partialQ, getType (n)) ; *)
+ (* alists.includeItemIntoList (globalGroup^.partialQ, getType (n)) ; *)
outputHiddenComplete (n) ;
RETURN TRUE
ELSIF allDependants (n) = completed
THEN
m := Sprintf0 (InitString ('\n')) ;
m := KillString (WriteS (StdOut, m)) ;
- dumpQ ('todo', todoQ) ;
- dumpQ ('partial', partialQ) ;
- dumpQ ('done', doneQ)
+ dumpQ ('todo', globalGroup^.todoQ) ;
+ dumpQ ('partial', globalGroup^.partialQ) ;
+ dumpQ ('done', globalGroup^.doneQ)
END
END dumpLists ;
pt (n) ;
addTodo (q) ;
RETURN TRUE
- ELSIF isArray (q) AND (seenPointer OR alists.isItemInList (doneQ, getType (q)))
+ ELSIF isArray (q) AND (seenPointer OR
+ alists.isItemInList (globalGroup^.doneQ, getType (q)))
THEN
pt (n) ;
addTodo (q) ;
d : node ;
BEGIN
i := 1 ;
- n := alists.noOfItemsInList (todoQ) ;
+ n := alists.noOfItemsInList (globalGroup^.todoQ) ;
WHILE i<=n DO
- d := alists.getItemFromList (todoQ, i) ;
+ d := alists.getItemFromList (globalGroup^.todoQ, i) ;
IF tryComplete (d, c, t, v)
THEN
- alists.removeItemFromList (todoQ, d) ;
- alists.includeItemIntoList (doneQ, d) ;
+ alists.removeItemFromList (globalGroup^.todoQ, d) ;
+ alists.includeItemIntoList (globalGroup^.doneQ, d) ;
i := 1
ELSIF tryPartial (d, pt)
THEN
- alists.removeItemFromList (todoQ, d) ;
- alists.includeItemIntoList (partialQ, d) ;
+ alists.removeItemFromList (globalGroup^.todoQ, d) ;
+ alists.includeItemIntoList (globalGroup^.partialQ, d) ;
i := 1
ELSE
INC (i)
END ;
- n := alists.noOfItemsInList (todoQ)
+ n := alists.noOfItemsInList (globalGroup^.todoQ)
END
END tryOutputTodo ;
d : node ;
BEGIN
i := 1 ;
- n := alists.noOfItemsInList (partialQ) ;
+ n := alists.noOfItemsInList (globalGroup^.partialQ) ;
WHILE i<=n DO
- d := alists.getItemFromList (partialQ, i) ;
+ d := alists.getItemFromList (globalGroup^.partialQ, i) ;
IF tryCompleteFromPartial (d, t)
THEN
- alists.removeItemFromList (partialQ, d) ;
- alists.includeItemIntoList (doneQ, d) ;
+ alists.removeItemFromList (globalGroup^.partialQ, d) ;
+ alists.includeItemIntoList (globalGroup^.doneQ, d) ;
i := 1 ;
DEC (n)
ELSE
BEGIN
IF getDebugTopological ()
THEN
- debugList ('todo', todoQ) ;
- debugList ('partial', partialQ)
+ debugList ('todo', globalGroup^.todoQ) ;
+ debugList ('partial', globalGroup^.partialQ)
END
END debugLists ;
i, h: CARDINAL ;
l : alist ;
BEGIN
- h := alists.noOfItemsInList (todoQ) ;
+ h := alists.noOfItemsInList (globalGroup^.todoQ) ;
i := 1 ;
WHILE i <= h DO
- n := alists.getItemFromList (todoQ, i) ;
+ n := alists.getItemFromList (globalGroup^.todoQ, i) ;
l := alists.initList () ;
visitNode (l, n, p) ;
alists.killList (l) ;
- h := alists.noOfItemsInList (todoQ) ;
+ h := alists.noOfItemsInList (globalGroup^.todoQ) ;
INC (i)
END
END populateTodo ;
(*
- topologicallyOut -
+ topologicallyOut - keep trying to resolve the todoQ and partialQ
+ until there is no change from the global group.
*)
PROCEDURE topologicallyOut (c, t, v, tp,
pc, pt, pv: nodeProcedure) ;
VAR
- tol, pal,
- to, pa : CARDINAL ;
+ before: group ;
BEGIN
populateTodo (addEnumConst) ;
- tol := 0 ;
- pal := 0 ;
- to := alists.noOfItemsInList (todoQ) ;
- pa := alists.noOfItemsInList (partialQ) ;
- WHILE (tol#to) OR (pal#pa) DO
+ before := NIL ;
+ REPEAT
+ before := dupGroup (before) ; (* Get a copy of the globalGroup and free before. *)
dumpLists ;
tryOutputTodo (c, t, v, tp) ;
dumpLists ;
- tryOutputPartial (pt) ;
- tol := to ;
- pal := pa ;
- to := alists.noOfItemsInList (todoQ) ;
- pa := alists.noOfItemsInList (partialQ)
- END ;
+ tryOutputPartial (pt)
+ UNTIL equalGroup (before, globalGroup) ;
+ killGroup (before) ;
dumpLists ;
debugLists
END topologicallyOut ;
PROCEDURE addDone (n: node) ;
BEGIN
- alists.includeItemIntoList (doneQ, n)
+ alists.includeItemIntoList (globalGroup^.doneQ, n)
END addDone ;
addDone (n) ;
RETURN
END ;
- IF (NOT isDef (n)) AND (lookupImp (getSymName (getScope (n))) = getMainModule ())
+ IF FALSE AND (lookupImp (getSymName (getScope (n))) = getMainModule ())
THEN
metaError1 ('cyclic dependancy found between another module using {%1ad} from the definition module of the implementation main being compiled, use the --extended-opaque option to compile', n) ;
flushErrors ;
lang := ansiC ;
outputFile := StdOut ;
doP := initPretty (write, writeln) ;
- todoQ := alists.initList () ;
- partialQ := alists.initList () ;
- doneQ := alists.initList () ;
+ freeGroup := NIL ;
+ globalGroup := initGroup () ;
modUniverse := initTree () ;
defUniverse := initTree () ;
modUniverseI := InitIndex (1) ;