Run through clang-format.

This commit is contained in:
David Given 2017-01-08 11:23:56 +01:00
parent 62022c6f6b
commit ee5ef73dfb

View file

@ -76,7 +76,8 @@ void DoAssign();
int int
LblWalkNode(lbl, nd, exit, reach) LblWalkNode(lbl, nd, exit, reach)
label lbl, exit; label lbl,
exit;
t_node* nd; t_node* nd;
{ {
/* Generate code for node "nd", after generating instruction /* Generate code for node "nd", after generating instruction
@ -96,7 +97,8 @@ DoPriority()
/* For the time being (???), handle priorities by calls to /* For the time being (???), handle priorities by calls to
the runtime system the runtime system
*/ */
if (priority) { if (priority)
{
tmpprio = NewInt(); tmpprio = NewInt();
C_loc(priority->nd_INT); C_loc(priority->nd_INT);
CAL("stackprio", (int)word_size); CAL("stackprio", (int)word_size);
@ -108,7 +110,8 @@ DoPriority()
STATIC STATIC
EndPriority() EndPriority()
{ {
if (priority) { if (priority)
{
C_lol(tmpprio); C_lol(tmpprio);
CAL("unstackprio", (int)word_size); CAL("unstackprio", (int)word_size);
FreeInt(tmpprio); FreeInt(tmpprio);
@ -124,8 +127,7 @@ def_ilb(l)
oldlineno = 0; oldlineno = 0;
} }
DoLineno(nd) DoLineno(nd) register t_node* nd;
register t_node *nd;
{ {
/* Generate line number information, if necessary. /* Generate line number information, if necessary.
*/ */
@ -133,16 +135,19 @@ DoLineno(nd)
#ifdef DBSYMTAB #ifdef DBSYMTAB
|| options['g'] || options['g']
#endif /* DBSYMTAB */ #endif /* DBSYMTAB */
) && )
nd->nd_lineno && && nd->nd_lineno && nd->nd_lineno != oldlineno)
nd->nd_lineno != oldlineno) { {
oldlineno = nd->nd_lineno; oldlineno = nd->nd_lineno;
if (! options['L']) C_lin((arith) nd->nd_lineno); if (!options['L'])
C_lin((arith)nd->nd_lineno);
#ifdef DBSYMTAB #ifdef DBSYMTAB
if ( options['g']) { if (options['g'])
{
static int ms_lineno; static int ms_lineno;
if (ms_lineno != nd->nd_lineno) { if (ms_lineno != nd->nd_lineno)
{
ms_lineno = nd->nd_lineno; ms_lineno = nd->nd_lineno;
C_ms_std((char*)0, N_SLINE, ms_lineno); C_ms_std((char*)0, N_SLINE, ms_lineno);
} }
@ -161,9 +166,11 @@ DoFilename(needed)
static label filename_label = 0; static label filename_label = 0;
oldlineno = 0; /* always invalidate remembered line number */ oldlineno = 0; /* always invalidate remembered line number */
if (needed && ! options['L']) { if (needed && !options['L'])
{
if (! filename_label) { if (!filename_label)
{
filename_label = 1; filename_label = 1;
C_df_dlb((label)1); C_df_dlb((label)1);
C_rom_scon(FileName, (arith)(strlen(FileName) + 1)); C_rom_scon(FileName, (arith)(strlen(FileName) + 1));
@ -173,8 +180,7 @@ DoFilename(needed)
} }
} }
WalkModule(module) WalkModule(module) register t_def* module;
register t_def *module;
{ {
/* Walk through a module, and all its local definitions. /* Walk through a module, and all its local definitions.
Also generate code for its body. Also generate code for its body.
@ -200,10 +206,12 @@ WalkModule(module)
TmpOpen(sc); /* Initialize for temporaries */ TmpOpen(sc); /* Initialize for temporaries */
C_pro_narg(sc->sc_name); C_pro_narg(sc->sc_name);
#ifdef DBSYMTAB #ifdef DBSYMTAB
if (options['g']) { if (options['g'])
{
stb_string(module, D_MODULE); stb_string(module, D_MODULE);
WalkDefList(sc->sc_def, stabdef); WalkDefList(sc->sc_def, stabdef);
if (state == PROGRAM && module == Defined) { if (state == PROGRAM && module == Defined)
{
C_ms_stb_cst(module->df_idf->id_text, C_ms_stb_cst(module->df_idf->id_text,
N_MAIN, N_MAIN,
0, 0,
@ -213,14 +221,16 @@ WalkModule(module)
} }
#endif #endif
DoPriority(); DoPriority();
if (module == Defined) { if (module == Defined)
{
/* Body of implementation or program module. /* Body of implementation or program module.
Call initialization routines of imported modules. Call initialization routines of imported modules.
Also prevent recursive calls of this one. Also prevent recursive calls of this one.
*/ */
register t_node* nd = Modules; register t_node* nd = Modules;
if (state == IMPLEMENTATION) { if (state == IMPLEMENTATION)
{
/* We don't actually prevent recursive calls, /* We don't actually prevent recursive calls,
but do nothing if called recursively but do nothing if called recursively
*/ */
@ -233,14 +243,16 @@ WalkModule(module)
C_zne(RETURN_LABEL); C_zne(RETURN_LABEL);
C_ine_dlb(data_label, (arith)0); C_ine_dlb(data_label, (arith)0);
} }
else if (! options['R']) { else if (!options['R'])
{
/* put funny value in BSS, in an attempt to detect /* put funny value in BSS, in an attempt to detect
uninitialized variables uninitialized variables
*/ */
C_cal("killbss"); C_cal("killbss");
} }
for (; nd; nd = nd->nd_NEXT) { for (; nd; nd = nd->nd_NEXT)
{
C_cal(nd->nd_def->mod_vis->sc_scope->sc_name); C_cal(nd->nd_def->mod_vis->sc_scope->sc_name);
} }
DoFilename(1); DoFilename(1);
@ -248,7 +260,8 @@ WalkModule(module)
WalkDefList(sc->sc_def, MkCalls); WalkDefList(sc->sc_def, MkCalls);
proclevel++; proclevel++;
#ifdef DBSYMTAB #ifdef DBSYMTAB
if (options['g']) { if (options['g'])
{
C_ms_std((char*)0, N_LBRAC, gdb_flag ? 0 : proclevel); C_ms_std((char*)0, N_LBRAC, gdb_flag ? 0 : proclevel);
} }
#endif /* DBSYMTAB */ #endif /* DBSYMTAB */
@ -258,7 +271,8 @@ WalkModule(module)
EndPriority(); EndPriority();
C_ret((arith)0); C_ret((arith)0);
#ifdef DBSYMTAB #ifdef DBSYMTAB
if (options['g']) { if (options['g'])
{
C_ms_std((char*)0, N_RBRAC, gdb_flag ? 0 : proclevel); C_ms_std((char*)0, N_RBRAC, gdb_flag ? 0 : proclevel);
} }
#endif /* DBSYMTAB */ #endif /* DBSYMTAB */
@ -270,8 +284,7 @@ WalkModule(module)
WalkDefList(sc->sc_def, UseWarnings); WalkDefList(sc->sc_def, UseWarnings);
} }
WalkProcedure(procedure) WalkProcedure(procedure) register t_def* procedure;
register t_def *procedure;
{ {
/* Walk through the definition of a procedure and all its /* Walk through the definition of a procedure and all its
local definitions, checking and generating code. local definitions, checking and generating code.
@ -301,9 +314,11 @@ WalkProcedure(procedure)
func_type = tp = RemoveEqual(ResultType(procedure->df_type)); func_type = tp = RemoveEqual(ResultType(procedure->df_type));
if (tp) { if (tp)
{
func_res_size = WA(tp->tp_size); func_res_size = WA(tp->tp_size);
if (TooBigForReturnArea(tp)) { if (TooBigForReturnArea(tp))
{
#ifdef BIG_RESULT_ON_STACK #ifdef BIG_RESULT_ON_STACK
/* The result type of this procedure is too big. /* The result type of this procedure is too big.
The caller will have reserved space on its stack, The caller will have reserved space on its stack,
@ -334,7 +349,8 @@ WalkProcedure(procedure)
#else #else
C_pro_narg(procedure->prc_name); C_pro_narg(procedure->prc_name);
#ifdef DBSYMTAB #ifdef DBSYMTAB
if (options['g']) { if (options['g'])
{
stb_string(procedure, D_PROCEDURE); stb_string(procedure, D_PROCEDURE);
WalkDefList(procscope->sc_def, stabdef); WalkDefList(procscope->sc_def, stabdef);
stb_string(procedure, D_PEND); stb_string(procedure, D_PEND);
@ -360,14 +376,18 @@ WalkProcedure(procedure)
/* Check if we must save the stack pointer */ /* Check if we must save the stack pointer */
for (param = ParamList(procedure->df_type); for (param = ParamList(procedure->df_type);
param; param;
param = param->par_next) { param = param->par_next)
if (! IsVarParam(param)) { {
if (!IsVarParam(param))
{
tp = TypeOfParam(param); tp = TypeOfParam(param);
if ( IsConformantArray(tp)) { if (IsConformantArray(tp))
{
/* First time we get here /* First time we get here
*/ */
if (func_type && !too_big) { if (func_type && !too_big)
{
/* Some local space, only /* Some local space, only
needed if the value itself needed if the value itself
is returned is returned
@ -390,8 +410,10 @@ WalkProcedure(procedure)
def_ilb(cd_body); def_ilb(cd_body);
#endif #endif
if ((WalkNode(procedure->prc_body, NO_EXIT_LABEL, REACH_FLAG) & REACH_FLAG)) { if ((WalkNode(procedure->prc_body, NO_EXIT_LABEL, REACH_FLAG) & REACH_FLAG))
if (func_res_size) { {
if (func_res_size)
{
node_warning(procscope->sc_end, node_warning(procscope->sc_end,
W_ORDINARY, W_ORDINARY,
"function procedure \"%s\" does not always return a value", "function procedure \"%s\" does not always return a value",
@ -422,13 +444,16 @@ WalkProcedure(procedure)
*/ */
for (param = ParamList(procedure->df_type); for (param = ParamList(procedure->df_type);
param; param;
param = param->par_next) { param = param->par_next)
if (! IsVarParam(param)) { {
if (!IsVarParam(param))
{
tp = TypeOfParam(param); tp = TypeOfParam(param);
if (! IsConformantArray(tp)) { if (!IsConformantArray(tp))
if (tp->tp_size < word_size && {
(int) word_size % (int) tp->tp_size == 0) { if (tp->tp_size < word_size && (int)word_size % (int)tp->tp_size == 0)
{
C_lol(param->par_def->var_off); C_lol(param->par_def->var_off);
STL(param->par_def->var_off, STL(param->par_def->var_off,
tp->tp_size); tp->tp_size);
@ -464,7 +489,8 @@ WalkProcedure(procedure)
#endif #endif
DO_DEBUG(options['X'], PrNode(procedure->prc_body, 0)); DO_DEBUG(options['X'], PrNode(procedure->prc_body, 0));
def_ilb(RETURN_LABEL); /* label at end */ def_ilb(RETURN_LABEL); /* label at end */
if (too_big) { if (too_big)
{
/* Fill the data area reserved for the function result /* Fill the data area reserved for the function result
with the result with the result
*/ */
@ -474,7 +500,8 @@ WalkProcedure(procedure)
c_lae_dlb(too_big); c_lae_dlb(too_big);
#endif /* BIG_RESULT_ON_STACK */ #endif /* BIG_RESULT_ON_STACK */
C_sti(func_res_size); C_sti(func_res_size);
if (StackAdjustment) { if (StackAdjustment)
{
/* Remove copies of conformant arrays /* Remove copies of conformant arrays
*/ */
LOL(StackAdjustment, pointer_size); LOL(StackAdjustment, pointer_size);
@ -487,17 +514,20 @@ WalkProcedure(procedure)
func_res_size = pointer_size; func_res_size = pointer_size;
#endif /* BIG_RESULT_ON_STACK */ #endif /* BIG_RESULT_ON_STACK */
} }
else if (StackAdjustment) { else if (StackAdjustment)
{
/* First save the function result in a safe place. /* First save the function result in a safe place.
Then remove copies of conformant arrays, Then remove copies of conformant arrays,
and put function result back on the stack and put function result back on the stack
*/ */
if (func_type) { if (func_type)
{
STL(retsav, func_res_size); STL(retsav, func_res_size);
} }
LOL(StackAdjustment, pointer_size); LOL(StackAdjustment, pointer_size);
C_str((arith)1); C_str((arith)1);
if (func_type) { if (func_type)
{
LOL(retsav, func_res_size); LOL(retsav, func_res_size);
} }
} }
@ -507,7 +537,8 @@ WalkProcedure(procedure)
C_beginpart(partno2); C_beginpart(partno2);
C_pro(procedure->prc_name, -procscope->sc_off); C_pro(procedure->prc_name, -procscope->sc_off);
#ifdef DBSYMTAB #ifdef DBSYMTAB
if (options['g']) { if (options['g'])
{
stb_string(procedure, D_PROCEDURE); stb_string(procedure, D_PROCEDURE);
WalkDefList(procscope->sc_def, stabdef); WalkDefList(procscope->sc_def, stabdef);
stb_string(procedure, D_PEND); stb_string(procedure, D_PEND);
@ -520,17 +551,20 @@ WalkProcedure(procedure)
#endif #endif
); );
#endif #endif
if (! options['n']) WalkDefList(procscope->sc_def, RegisterMessage); if (!options['n'])
WalkDefList(procscope->sc_def, RegisterMessage);
#ifdef USE_INSERT #ifdef USE_INSERT
C_endpart(partno2); C_endpart(partno2);
#endif #endif
#ifdef DBSYMTAB #ifdef DBSYMTAB
if (options['g']) { if (options['g'])
{
C_ms_std((char*)0, N_RBRAC, gdb_flag ? 0 : proclevel); C_ms_std((char*)0, N_RBRAC, gdb_flag ? 0 : proclevel);
} }
#endif /* DBSYMTAB */ #endif /* DBSYMTAB */
C_end(-procscope->sc_off); C_end(-procscope->sc_off);
if (! fit(procscope->sc_off, (int) word_size)) { if (!fit(procscope->sc_off, (int)word_size))
{
node_error(procedure->prc_body, node_error(procedure->prc_body,
"maximum local byte count exceeded"); "maximum local byte count exceeded");
} }
@ -540,14 +574,13 @@ WalkProcedure(procedure)
WalkDefList(procscope->sc_def, UseWarnings); WalkDefList(procscope->sc_def, UseWarnings);
} }
static static WalkDef(df) register t_def* df;
WalkDef(df)
register t_def *df;
{ {
/* Walk through a list of definitions /* Walk through a list of definitions
*/ */
switch(df->df_kind) { switch (df->df_kind)
{
case D_MODULE: case D_MODULE:
WalkModule(df); WalkModule(df);
break; break;
@ -555,7 +588,8 @@ WalkDef(df)
WalkProcedure(df); WalkProcedure(df);
break; break;
case D_VARIABLE: case D_VARIABLE:
if (!proclevel && !(df->df_flags & D_ADDRGIVEN)) { if (!proclevel && !(df->df_flags & D_ADDRGIVEN))
{
C_df_dnam(df->var_name); C_df_dnam(df->var_name);
C_bss_cst( C_bss_cst(
WA(df->df_type->tp_size), WA(df->df_type->tp_size),
@ -568,21 +602,19 @@ WalkDef(df)
} }
} }
static static MkCalls(df) register t_def* df;
MkCalls(df)
register t_def *df;
{ {
/* Generate calls to initialization routines of modules /* Generate calls to initialization routines of modules
*/ */
if (df->df_kind == D_MODULE) { if (df->df_kind == D_MODULE)
{
C_lxl((arith)0); C_lxl((arith)0);
CAL(df->mod_vis->sc_scope->sc_name, (int)pointer_size); CAL(df->mod_vis->sc_scope->sc_name, (int)pointer_size);
} }
} }
WalkLink(nd, exit_label, end_reached) WalkLink(nd, exit_label, end_reached) register t_node* nd;
register t_node *nd;
label exit_label; label exit_label;
{ {
/* Walk node "nd", which is a link. /* Walk node "nd", which is a link.
@ -591,7 +623,8 @@ WalkLink(nd, exit_label, end_reached)
and whether an EXIT statement was seen (EXIT_FLAG). and whether an EXIT statement was seen (EXIT_FLAG).
*/ */
while (nd && nd->nd_class == Link) { /* statement list */ while (nd && nd->nd_class == Link)
{ /* statement list */
end_reached = WalkNode(nd->nd_LEFT, exit_label, end_reached); end_reached = WalkNode(nd->nd_LEFT, exit_label, end_reached);
nd = nd->nd_RIGHT; nd = nd->nd_RIGHT;
} }
@ -600,8 +633,7 @@ WalkLink(nd, exit_label, end_reached)
} }
STATIC STATIC
ForLoopVarExpr(nd) ForLoopVarExpr(nd) register t_node* nd;
register t_node *nd;
{ {
register t_type* tp = nd->nd_type; register t_type* tp = nd->nd_type;
@ -610,8 +642,7 @@ ForLoopVarExpr(nd)
} }
int int
WalkStat(nd, exit_label, end_reached) WalkStat(nd, exit_label, end_reached) register t_node* nd;
register t_node *nd;
label exit_label; label exit_label;
{ {
/* Walk through a statement, generating code for it. /* Walk through a statement, generating code for it.
@ -621,24 +652,30 @@ WalkStat(nd, exit_label, end_reached)
assert(nd->nd_class == Stat); assert(nd->nd_class == Stat);
if (nd->nd_symb == ';') return 1; if (nd->nd_symb == ';')
return 1;
if (! end_reached & REACH_FLAG) { if (!end_reached & REACH_FLAG)
{
node_warning(nd, W_ORDINARY, "statement not reached"); node_warning(nd, W_ORDINARY, "statement not reached");
} }
if (nd->nd_symb != WHILE || if (nd->nd_symb != WHILE || nd->nd_lineno != left->nd_lineno)
nd->nd_lineno != left->nd_lineno) { {
/* Avoid double linenumber generation in while statements */ /* Avoid double linenumber generation in while statements */
DoLineno(nd); DoLineno(nd);
} }
options['R'] = (nd->nd_flags & ROPTION); options['R'] = (nd->nd_flags & ROPTION);
options['A'] = (nd->nd_flags & AOPTION); options['A'] = (nd->nd_flags & AOPTION);
switch(nd->nd_symb) { switch (nd->nd_symb)
case '(': { {
case '(':
{
t_node* nd1 = nd; t_node* nd1 = nd;
if (ChkCall(&nd1)) { if (ChkCall(&nd1))
{
assert(nd == nd1); assert(nd == nd1);
if (nd->nd_type != 0) { if (nd->nd_type != 0)
{
node_error(nd, "procedure call expected instead of function call"); node_error(nd, "procedure call expected instead of function call");
break; break;
} }
@ -652,21 +689,24 @@ WalkStat(nd, exit_label, end_reached)
break; break;
case IF: case IF:
{ label l1 = ++text_label, l3 = ++text_label; {
label l1 = ++text_label, l3 = ++text_label;
int end_r; int end_r;
ExpectBool(&(nd->nd_LEFT), l3, l1); ExpectBool(&(nd->nd_LEFT), l3, l1);
assert(right->nd_symb == THEN); assert(right->nd_symb == THEN);
end_r = LblWalkNode(l3, right->nd_LEFT, exit_label, end_reached); end_r = LblWalkNode(l3, right->nd_LEFT, exit_label, end_reached);
if (right->nd_RIGHT) { /* ELSE part */ if (right->nd_RIGHT)
{ /* ELSE part */
label l2 = ++text_label; label l2 = ++text_label;
c_bra(l2); c_bra(l2);
end_reached = end_r | LblWalkNode(l1, right->nd_RIGHT, exit_label, end_reached); end_reached = end_r | LblWalkNode(l1, right->nd_RIGHT, exit_label, end_reached);
l1 = l2; l1 = l2;
} }
else end_reached |= end_r; else
end_reached |= end_r;
def_ilb(l1); def_ilb(l1);
break; break;
} }
@ -676,7 +716,8 @@ WalkStat(nd, exit_label, end_reached)
break; break;
case WHILE: case WHILE:
{ label loop = ++text_label, {
label loop = ++text_label,
exit = ++text_label, exit = ++text_label,
dummy = ++text_label; dummy = ++text_label;
@ -689,7 +730,8 @@ WalkStat(nd, exit_label, end_reached)
} }
case REPEAT: case REPEAT:
{ label loop = ++text_label, exit = ++text_label; {
label loop = ++text_label, exit = ++text_label;
end_reached = LblWalkNode(loop, left, exit_label, end_reached); end_reached = LblWalkNode(loop, left, exit_label, end_reached);
ExpectBool(&(nd->nd_RIGHT), exit, loop); ExpectBool(&(nd->nd_RIGHT), exit, loop);
@ -698,12 +740,15 @@ WalkStat(nd, exit_label, end_reached)
} }
case LOOP: case LOOP:
{ label loop = ++text_label, exit = ++text_label; {
label loop = ++text_label, exit = ++text_label;
if (LblWalkNode(loop, right, exit, end_reached) & EXIT_FLAG) { if (LblWalkNode(loop, right, exit, end_reached) & EXIT_FLAG)
{
end_reached &= REACH_FLAG; end_reached &= REACH_FLAG;
} }
else end_reached = 0; else
end_reached = 0;
c_bra(loop); c_bra(loop);
def_ilb(exit); def_ilb(exit);
break; break;
@ -723,12 +768,14 @@ WalkStat(nd, exit_label, end_reached)
good_forvar = DoForInit(left); good_forvar = DoForInit(left);
loopid = left->nd_LEFT; loopid = left->nd_LEFT;
if ((stepsize = right->nd_LEFT->nd_INT) == 0) { if ((stepsize = right->nd_LEFT->nd_INT) == 0)
{
node_warning(right->nd_LEFT, node_warning(right->nd_LEFT,
W_ORDINARY, W_ORDINARY,
"zero stepsize in FOR loop"); "zero stepsize in FOR loop");
} }
if (good_forvar) { if (good_forvar)
{
bstp = BaseType(loopid->nd_type); bstp = BaseType(loopid->nd_type);
uns = bstp->tp_fund != T_INTEGER; uns = bstp->tp_fund != T_INTEGER;
CodePExpr(left->nd_RIGHT->nd_RIGHT); CodePExpr(left->nd_RIGHT->nd_RIGHT);
@ -737,37 +784,46 @@ WalkStat(nd, exit_label, end_reached)
C_dup(int_size); C_dup(int_size);
C_stl(tmp2); C_stl(tmp2);
C_lol(tmp); C_lol(tmp);
if (uns) C_cmu(int_size); if (uns)
else C_cmi(int_size); C_cmu(int_size);
if (stepsize >= 0) C_zgt(l2); else
else C_zlt(l2); C_cmi(int_size);
if (stepsize >= 0)
C_zgt(l2);
else
C_zlt(l2);
C_lol(tmp2); C_lol(tmp2);
RangeCheck(loopid->nd_type, RangeCheck(loopid->nd_type,
left->nd_RIGHT->nd_LEFT->nd_type); left->nd_RIGHT->nd_LEFT->nd_type);
CodeDStore(loopid); CodeDStore(loopid);
if (stepsize >= 0) { if (stepsize >= 0)
{
C_lol(tmp); C_lol(tmp);
ForLoopVarExpr(loopid); ForLoopVarExpr(loopid);
} }
else { else
{
stepsize = -stepsize; stepsize = -stepsize;
ForLoopVarExpr(loopid); ForLoopVarExpr(loopid);
C_lol(tmp); C_lol(tmp);
} }
C_sbu(int_size); C_sbu(int_size);
if (stepsize) { if (stepsize)
{
C_loc(stepsize); C_loc(stepsize);
C_dvu(int_size); C_dvu(int_size);
} }
C_stl(tmp); C_stl(tmp);
loopid->nd_def->df_flags |= D_FORLOOP; loopid->nd_def->df_flags |= D_FORLOOP;
def_ilb(l1); def_ilb(l1);
if (! options['R']) { if (!options['R'])
{
ForLoopVarExpr(loopid); ForLoopVarExpr(loopid);
C_stl(tmp2); C_stl(tmp2);
} }
end_reached |= WalkNode(right->nd_RIGHT, exit_label, end_reached); end_reached |= WalkNode(right->nd_RIGHT, exit_label, end_reached);
if (! options['R']) { if (!options['R'])
{
label x = ++text_label; label x = ++text_label;
C_lol(tmp2); C_lol(tmp2);
ForLoopVarExpr(loopid); ForLoopVarExpr(loopid);
@ -778,7 +834,8 @@ WalkStat(nd, exit_label, end_reached)
} }
loopid->nd_def->df_flags &= ~D_FORLOOP; loopid->nd_def->df_flags &= ~D_FORLOOP;
FreeInt(tmp2); FreeInt(tmp2);
if (stepsize) { if (stepsize)
{
C_lol(tmp); C_lol(tmp);
C_zeq(l2); C_zeq(l2);
C_lol(tmp); C_lol(tmp);
@ -792,7 +849,8 @@ WalkStat(nd, exit_label, end_reached)
CodeDStore(loopid); CodeDStore(loopid);
} }
} }
else { else
{
end_reached |= WalkNode(right->nd_RIGHT, exit_label, end_reached); end_reached |= WalkNode(right->nd_RIGHT, exit_label, end_reached);
loopid->nd_def->df_flags &= ~D_FORLOOP; loopid->nd_def->df_flags &= ~D_FORLOOP;
} }
@ -808,9 +866,11 @@ WalkStat(nd, exit_label, end_reached)
struct withdesig wds; struct withdesig wds;
t_desig ds; t_desig ds;
if (! WalkDesignator(&(nd->nd_LEFT), &ds, D_USED)) break; if (!WalkDesignator(&(nd->nd_LEFT), &ds, D_USED))
break;
left = nd->nd_LEFT; left = nd->nd_LEFT;
if (left->nd_type->tp_fund != T_RECORD) { if (left->nd_type->tp_fund != T_RECORD)
{
node_error(left, "record variable expected"); node_error(left, "record variable expected");
break; break;
} }
@ -843,26 +903,32 @@ WalkStat(nd, exit_label, end_reached)
case EXIT: case EXIT:
assert(exit_label != 0); assert(exit_label != 0);
if (end_reached & REACH_FLAG) end_reached = EXIT_FLAG; if (end_reached & REACH_FLAG)
end_reached = EXIT_FLAG;
c_bra(exit_label); c_bra(exit_label);
break; break;
case RETURN: case RETURN:
end_reached &= ~REACH_FLAG; end_reached &= ~REACH_FLAG;
if (right) { if (right)
if (! ChkExpression(&(nd->nd_RIGHT))) break; {
if (!ChkExpression(&(nd->nd_RIGHT)))
break;
/* The type of the return-expression must be /* The type of the return-expression must be
assignment compatible with the result type of the assignment compatible with the result type of the
function procedure (See Rep. 9.11). function procedure (See Rep. 9.11).
*/ */
if (!ChkAssCompat(&(nd->nd_RIGHT), func_type, "RETURN")) { if (!ChkAssCompat(&(nd->nd_RIGHT), func_type, "RETURN"))
{
break; break;
} }
right = nd->nd_RIGHT; right = nd->nd_RIGHT;
if (right->nd_type->tp_fund == T_STRING) { if (right->nd_type->tp_fund == T_STRING)
{
CodePString(right, func_type); CodePString(right, func_type);
} }
else CodePExpr(right); else
CodePExpr(right);
} }
c_bra(RETURN_LABEL); c_bra(RETURN_LABEL);
break; break;
@ -893,8 +959,7 @@ int (*WalkTable[])() = {
extern t_desig null_desig; extern t_desig null_desig;
ExpectBool(pnd, true_label, false_label) ExpectBool(pnd, true_label, false_label) register t_node** pnd;
register t_node **pnd;
label true_label, false_label; label true_label, false_label;
{ {
/* "pnd" must indicate a boolean expression. Check this and /* "pnd" must indicate a boolean expression. Check this and
@ -903,9 +968,10 @@ ExpectBool(pnd, true_label, false_label)
t_desig ds; t_desig ds;
ds = null_desig; ds = null_desig;
if (ChkExpression(pnd)) { if (ChkExpression(pnd))
if ((*pnd)->nd_type != bool_type && {
(*pnd)->nd_type != error_type) { if ((*pnd)->nd_type != bool_type && (*pnd)->nd_type != error_type)
{
node_error(*pnd, "boolean expression expected"); node_error(*pnd, "boolean expression expected");
} }
@ -921,7 +987,8 @@ WalkDesignator(pnd, ds, flags)
/* Check designator and generate code for it /* Check designator and generate code for it
*/ */
if (! ChkVariable(pnd, flags)) return 0; if (!ChkVariable(pnd, flags))
return 0;
*ds = null_desig; *ds = null_desig;
CodeDesig(*pnd, ds); CodeDesig(*pnd, ds);
@ -940,36 +1007,43 @@ DoForInit(nd)
r = ChkVariable(&(nd->nd_LEFT), D_USED | D_DEFINED); r = ChkVariable(&(nd->nd_LEFT), D_USED | D_DEFINED);
r &= ChkExpression(&(right->nd_LEFT)); r &= ChkExpression(&(right->nd_LEFT));
r &= ChkExpression(&(right->nd_RIGHT)); r &= ChkExpression(&(right->nd_RIGHT));
if (!r) return 0; if (!r)
return 0;
df = nd->nd_LEFT->nd_def; df = nd->nd_LEFT->nd_def;
if (df->df_kind == D_FIELD) { if (df->df_kind == D_FIELD)
{
node_error(nd, node_error(nd,
"FOR-loop variable may not be a field of a record"); "FOR-loop variable may not be a field of a record");
return 1; return 1;
} }
if (!df->var_name && df->var_off >= 0) { if (!df->var_name && df->var_off >= 0)
{
node_error(nd, "FOR-loop variable may not be a parameter"); node_error(nd, "FOR-loop variable may not be a parameter");
return 1; return 1;
} }
if (df->df_scope != CurrentScope) { if (df->df_scope != CurrentScope)
{
register t_scopelist* sc = CurrVis; register t_scopelist* sc = CurrVis;
for (;;) { for (;;)
if (!sc) { {
if (!sc)
{
node_error(nd, node_error(nd,
"FOR-loop variable may not be imported"); "FOR-loop variable may not be imported");
return 1; return 1;
} }
if (sc->sc_scope == df->df_scope) break; if (sc->sc_scope == df->df_scope)
break;
sc = nextvisible(sc); sc = nextvisible(sc);
} }
} }
if (df->df_type->tp_size > word_size || if (df->df_type->tp_size > word_size || !(df->df_type->tp_fund & T_DISCRETE))
!(df->df_type->tp_fund & T_DISCRETE)) { {
node_error(nd, "illegal type of FOR loop variable"); node_error(nd, "illegal type of FOR loop variable");
return 1; return 1;
} }
@ -978,19 +1052,21 @@ DoForInit(nd)
tpl = right->nd_LEFT->nd_type; tpl = right->nd_LEFT->nd_type;
tpr = right->nd_RIGHT->nd_type; tpr = right->nd_RIGHT->nd_type;
#ifndef STRICT_3RD_ED #ifndef STRICT_3RD_ED
if (! options['3']) { if (!options['3'])
if (!ChkAssCompat(&(right->nd_LEFT), base_tp, "FOR statement") || {
!ChkAssCompat(&(right->nd_RIGHT), base_tp, "FOR statement")) { if (!ChkAssCompat(&(right->nd_LEFT), base_tp, "FOR statement") || !ChkAssCompat(&(right->nd_RIGHT), base_tp, "FOR statement"))
{
return 1; return 1;
} }
if (!TstCompat(df->df_type, tpl) || if (!TstCompat(df->df_type, tpl) || !TstCompat(df->df_type, tpr))
!TstCompat(df->df_type, tpr)) { {
node_warning(nd, W_OLDFASHIONED, "compatibility required in FOR statement"); node_warning(nd, W_OLDFASHIONED, "compatibility required in FOR statement");
} }
} else }
else
#endif #endif
if (!ChkCompat(&(right->nd_LEFT), base_tp, "FOR statement") || if (!ChkCompat(&(right->nd_LEFT), base_tp, "FOR statement") || !ChkCompat(&(right->nd_RIGHT), base_tp, "FOR statement"))
!ChkCompat(&(right->nd_RIGHT), base_tp, "FOR statement")) { {
return 1; return 1;
} }
@ -998,8 +1074,7 @@ node_warning(nd, W_OLDFASHIONED, "compatibility required in FOR statement");
} }
void void
DoAssign(nd) DoAssign(nd) register t_node* nd;
register t_node *nd;
{ {
/* May we do it in this order (expression first) ??? /* May we do it in this order (expression first) ???
The reference manual sais nothing about it, but the book does: The reference manual sais nothing about it, but the book does:
@ -1009,11 +1084,12 @@ DoAssign(nd)
t_desig dsr; t_desig dsr;
register t_type* tp; register t_type* tp;
if (! (ChkExpression(&(nd->nd_RIGHT)) & if (!(ChkExpression(&(nd->nd_RIGHT)) & ChkVariable(&(nd->nd_LEFT), D_DEFINED)))
ChkVariable(&(nd->nd_LEFT), D_DEFINED))) return; return;
tp = nd->nd_LEFT->nd_type; tp = nd->nd_LEFT->nd_type;
if (! ChkAssCompat(&(nd->nd_RIGHT), tp, "assignment")) { if (!ChkAssCompat(&(nd->nd_RIGHT), tp, "assignment"))
{
return; return;
} }
dsr = null_desig; dsr = null_desig;
@ -1022,38 +1098,41 @@ DoAssign(nd)
|| (ds).dsg_kind == DSG_INDEXED) || (ds).dsg_kind == DSG_INDEXED)
CodeExpr(nd->nd_RIGHT, &dsr, NO_LABEL, NO_LABEL); CodeExpr(nd->nd_RIGHT, &dsr, NO_LABEL, NO_LABEL);
tp = nd->nd_RIGHT->nd_type; tp = nd->nd_RIGHT->nd_type;
if (complex(tp)) { if (complex(tp))
if (StackNeededFor(dsr)) CodeAddress(&dsr); {
if (StackNeededFor(dsr))
CodeAddress(&dsr);
} }
else { else
{
CodeValue(&dsr, tp); CodeValue(&dsr, tp);
} }
CodeMove(&dsr, nd->nd_LEFT, tp); CodeMove(&dsr, nd->nd_LEFT, tp);
} }
static static RegisterMessage(df) register t_def* df;
RegisterMessage(df)
register t_def *df;
{ {
register t_type* tp; register t_type* tp;
if (df->df_kind == D_VARIABLE) { if (df->df_kind == D_VARIABLE)
if ( !(df->df_flags & D_NOREG)) { {
if (!(df->df_flags & D_NOREG))
{
/* Examine type and size /* Examine type and size
*/ */
tp = BaseType(df->df_type); tp = BaseType(df->df_type);
if ((df->df_flags & D_VARPAR) || if ((df->df_flags & D_VARPAR) || (tp->tp_fund & (T_POINTER | T_HIDDEN | T_EQUAL)))
(tp->tp_fund&(T_POINTER|T_HIDDEN|T_EQUAL))) { {
C_ms_reg(df->var_off, C_ms_reg(df->var_off,
pointer_size, pointer_size,
reg_pointer, reg_pointer,
0); 0);
} }
else if (tp->tp_fund & T_NUMERIC) { else if (tp->tp_fund & T_NUMERIC)
{
C_ms_reg(df->var_off, C_ms_reg(df->var_off,
tp->tp_size, tp->tp_size,
tp->tp_fund == T_REAL ? tp->tp_fund == T_REAL ? reg_float : reg_any,
reg_float : reg_any,
0); 0);
} }
} }
@ -1066,55 +1145,53 @@ df_warning(nd, df, warning)
t_def* df; t_def* df;
char* warning; char* warning;
{ {
if (! (df->df_kind & (D_VARIABLE|D_PROCEDURE|D_TYPE|D_CONST|D_PROCHEAD))) { if (!(df->df_kind & (D_VARIABLE | D_PROCEDURE | D_TYPE | D_CONST | D_PROCHEAD)))
{
return; return;
} }
if (warning) { if (warning)
{
node_warning(nd, node_warning(nd,
W_ORDINARY, W_ORDINARY,
"%s \"%s\" %s", "%s \"%s\" %s",
(df->df_flags & D_VALPAR) ? "value parameter" : (df->df_flags & D_VALPAR) ? "value parameter" : (df->df_flags & D_VARPAR) ? "variable parameter" : (df->df_kind == D_VARIABLE) ? "variable" : (df->df_kind == D_TYPE) ? "type" : (df->df_kind == D_CONST) ? "constant" : "procedure",
(df->df_flags & D_VARPAR) ? "variable parameter" :
(df->df_kind == D_VARIABLE) ? "variable" :
(df->df_kind == D_TYPE) ? "type" :
(df->df_kind == D_CONST) ? "constant" :
"procedure",
df->df_idf->id_text, warning); df->df_idf->id_text, warning);
} }
} }
static void static void
UseWarnings(df) UseWarnings(df) register t_def* df;
register t_def *df;
{ {
t_node* nd = df->df_scope->sc_end; t_node* nd = df->df_scope->sc_end;
if (is_anon_idf(df->df_idf) || if (is_anon_idf(df->df_idf) || !(df->df_kind & (D_IMPORTED | D_VARIABLE | D_PROCEDURE | D_CONST | D_TYPE)) || (df->df_flags & (D_EXPORTED | D_QEXPORTED)))
!(df->df_kind&(D_IMPORTED|D_VARIABLE|D_PROCEDURE|D_CONST|D_TYPE)) || {
(df->df_flags&(D_EXPORTED|D_QEXPORTED))) {
return; return;
} }
if (df->df_kind & D_IMPORTED) { if (df->df_kind & D_IMPORTED)
{
register t_def* df1 = df->imp_def; register t_def* df1 = df->imp_def;
df1->df_flags |= df->df_flags & (D_USED | D_DEFINED); df1->df_flags |= df->df_flags & (D_USED | D_DEFINED);
if (df->df_kind == D_INUSE) return; if (df->df_kind == D_INUSE)
if ( !(df->df_flags & D_IMP_BY_EXP)) { return;
if (df->df_flags & (D_USED | D_DEFINED)) { if (!(df->df_flags & D_IMP_BY_EXP))
{
if (df->df_flags & (D_USED | D_DEFINED))
{
return; return;
} }
df_warning(nd, df_warning(nd,
df1, df1,
df1->df_kind == D_VARIABLE ? df1->df_kind == D_VARIABLE ? "imported but not used/assigned" : "imported but not used");
"imported but not used/assigned" :
"imported but not used");
return; return;
} }
df = df1; df = df1;
nd = df->df_scope->sc_end; nd = df->df_scope->sc_end;
} }
switch(df->df_flags & (D_USED|D_DEFINED|D_VALPAR|D_VARPAR)) { switch (df->df_flags & (D_USED | D_DEFINED | D_VALPAR | D_VARPAR))
{
case 0: case 0:
case D_VARPAR: case D_VARPAR:
df_warning(nd, df, "never used/assigned"); df_warning(nd, df, "never used/assigned");
@ -1130,11 +1207,11 @@ UseWarnings(df)
} }
} }
WalkDefList(df, proc) WalkDefList(df, proc) register t_def* df;
register t_def *df;
int (*proc)(); int (*proc)();
{ {
for (; df; df = df->df_nextinscope) { for (; df; df = df->df_nextinscope)
{
(*proc)(df); (*proc)(df);
} }
} }
@ -1144,7 +1221,8 @@ static int
stabdef(df) stabdef(df)
t_def* df; t_def* df;
{ {
switch(df->df_kind) { switch (df->df_kind)
{
case D_CONST: case D_CONST:
case D_VARIABLE: case D_VARIABLE:
stb_string(df, df->df_kind); stb_string(df, df->df_kind);