int return_occurred; /* set if a return occurs in a block */
#define needs_static_link() (proclevel > 1)
-
+extern struct node *EmptyStatement;
}
/* inline in declaration: need space
[ %persistent
declaration
]*
- { return_occurred = 0; *pnd = 0; }
- [ %persistent
+ { return_occurred = 0; }
+ [ %default
BEGIN
StatementSequence(pnd)
- ]?
+ |
+ { *pnd = EmptyStatement; }
+ ]
END
;
register struct node *nd;
}:
IDENT { df = define(dot.TOK_IDF, CurrentScope, D_TYPE);
- nd = MkLeaf(Name, &dot);
+ nd = dot2leaf(Name);
}
'=' type(&tp)
{ DeclareType(nd, df, tp);
{
register struct node *q;
} :
- IDENT { *p = q = MkLeaf(Value, &dot); }
+ IDENT { *p = q = dot2leaf(Value); }
[ %persistent
',' IDENT
- { q->nd_left = MkLeaf(Value, &dot);
+ { q->nd_left = dot2leaf(Value);
q = q->nd_left;
}
]*
CaseLabelList(struct type **ptp; struct node **pnd;):
CaseLabels(ptp, pnd)
[
- { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); }
+ { *pnd = dot2node(Link, *pnd, NULLNODE); }
',' CaseLabels(ptp, &((*pnd)->nd_right))
{ pnd = &((*pnd)->nd_right); }
]*
nd = *pnd;
}
[
- UPTO { *pnd = MkNode(Link,nd,NULLNODE,&dot); }
+ UPTO { *pnd = dot2node(Link,nd,NULLNODE); }
ConstExpression(&(*pnd)->nd_right)
{ if (!ChkCompat(&((*pnd)->nd_right), nd->nd_type,
"case label")) {
{
register struct node *nd;
} :
- IDENT { nd = MkLeaf(Name, &dot); }
+ IDENT { nd = dot2leaf(Name); }
[ '['
ConstExpression(&(nd->nd_left))
']'
/* In a definition module
*/
df = define(id, CurrentScope, type);
- df->for_node = MkLeaf(Name, &dot);
+ df->for_node = dot2leaf(Name);
if (CurrentScope->sc_definedby->df_flags & D_FOREIGN) {
df->for_name = id->id_text;
}
register struct node *n;
extern struct node *Modules;
- n = MkLeaf(Name, &dot);
+ n = dot2leaf(Name);
n->nd_IDF = id;
n->nd_symb = IDENT;
if (nd_end) nd_end->nd_left = n;
if (! idlist) {
/* Can only happen when a procedure type is defined */
- dummy = Idlist = idlist = MkLeaf(Name, &dot);
+ dummy = Idlist = idlist = dot2leaf(Name);
}
for ( ; idlist; idlist = idlist->nd_left) {
pr = new_paramlist();
INTEGER
|
REAL
-] { *p = MkLeaf(Value, &dot);
+] { *p = dot2leaf(Value);
(*p)->nd_type = toktype;
}
;
qualident(struct node **p;)
{
} :
- IDENT { *p = MkLeaf(Name, &dot); }
+ IDENT { *p = dot2leaf(Name); }
[
selector(p)
]*
;
selector(struct node **pnd;):
- '.' { *pnd = MkNode(Link,*pnd,NULLNODE,&dot); }
+ '.' { *pnd = dot2node(Link,*pnd,NULLNODE); }
IDENT { (*pnd)->nd_IDF = dot.TOK_IDF; }
;
{
register struct node *nd;
} :
- expression(pnd) { *pnd = nd = MkNode(Link,*pnd,NULLNODE,&dot);
+ expression(pnd) { *pnd = nd = dot2node(Link,*pnd,NULLNODE);
nd->nd_symb = ',';
}
[
- ',' { nd->nd_right = MkLeaf(Link, &dot);
+ ',' { nd->nd_right = dot2leaf(Link);
nd = nd->nd_right;
}
expression(&(nd->nd_left))
[
/* relation */
[ '=' | '#' | '<' | LESSEQUAL | '>' | GREATEREQUAL | IN ]
- { *pnd = MkNode(Oper, *pnd, NULLNODE, &dot); }
+ { *pnd = dot2node(Oper, *pnd, NULLNODE); }
SimpleExpression(&((*pnd)->nd_right))
]?
;
} :
[
[ '+' | '-' ]
- { nd = MkLeaf(Uoper, &dot);
+ { nd = dot2leaf(Uoper);
/* priority of unary operator ??? */
}
]?
[
/* AddOperator */
[ '+' | '-' | OR ]
- { nd = MkNode(Oper, nd, NULLNODE, &dot); }
+ { nd = dot2node(Oper, nd, NULLNODE); }
term(&(nd->nd_right))
]*
{ *pnd = nd; }
[
/* MulOperator */
[ '*' | '/' | DIV | MOD | AND ]
- { nd = MkNode(Oper, nd, NULLNODE, &dot); }
+ { nd = dot2node(Oper, nd, NULLNODE); }
factor(&(nd->nd_right))
]*
{ *pnd = nd; }
[
designator_tail(p)?
[
- { *p = MkNode(Call, *p, NULLNODE, &dot); }
+ { *p = dot2node(Call, *p, NULLNODE); }
ActualParameters(&((*p)->nd_right))
]?
|
REAL
|
STRING
- ] { *p = MkLeaf(Value, &dot);
+ ] { *p = dot2leaf(Value);
(*p)->nd_type = toktype;
}
|
- '(' { nd = MkLeaf(Uoper, &dot); }
+ '(' { nd = dot2leaf(Uoper); }
expression(p)
{ /* In some cases we must leave the '(' as an unary
operator, because otherwise we cannot see that the
}
')'
|
- NOT { *p = MkLeaf(Uoper, &dot); }
+ NOT { *p = dot2leaf(Uoper); }
factor(&((*p)->nd_right))
;
register struct node *nd;
} :
'{' { dot.tk_symb = SET;
- *pnd = nd = MkLeaf(Xset, &dot);
+ *pnd = nd = dot2leaf(Xset);
nd->nd_type = bitset_type;
}
[
expression(&nd1)
[
UPTO
- { nd1 = MkNode(Link, nd1, NULLNODE, &dot);}
+ { nd1 = dot2node(Link, nd1, NULLNODE);}
expression(&(nd1->nd_right))
]?
- { nd->nd_right = MkNode(Link, nd1, NULLNODE, &dot);
+ { nd->nd_right = dot2node(Link, nd1, NULLNODE);
nd->nd_right->nd_symb = ',';
}
;
register struct node *nd = *pnd;
}:
[
- '[' { nd = MkNode(Arrsel, nd, NULLNODE, &dot); }
+ '[' { nd = dot2node(Arrsel, nd, NULLNODE); }
expression(&(nd->nd_right))
[
','
- { nd = MkNode(Arrsel, nd, NULLNODE, &dot);
+ { nd = dot2node(Arrsel, nd, NULLNODE);
nd->nd_symb = '[';
}
expression(&(nd->nd_right))
]*
']'
|
- '^' { nd = MkNode(Arrow, NULLNODE, nd, &dot); }
+ '^' { nd = dot2node(Arrow, NULLNODE, nd); }
]
{ *pnd = nd; }
;
struct def *Defined;
extern int err_occurred;
extern int fp_used; /* set if floating point used */
+struct node *EmptyStatement;
main(argc, argv)
register char **argv;
InitScope();
InitTypes();
AddStandards();
+ EmptyStatement = dot2leaf(Stat);
+ EmptyStatement->nd_symb = ';';
#ifdef DEBUG
if (options['l']) {
LexScan();
/* ALLOCDEF "node" 50 */
-extern struct node *MkNode(), *MkLeaf();
+extern struct node *MkNode(), *MkLeaf(), *dot2node(), *dot2leaf();
#define NULLNODE ((struct node *) 0)
return nd;
}
+struct node *
+dot2node(class, left, right)
+ struct node *left, *right;
+{
+ return MkNode(class, left, right, &dot);
+}
+
struct node *
MkLeaf(class, token)
struct token *token;
{
register struct node *nd = new_node();
- nd->nd_left = nd->nd_right = 0;
nd->nd_token = *token;
nd->nd_class = class;
return nd;
}
+struct node *
+dot2leaf(class)
+{
+ return MkLeaf(class, &dot);
+}
+
FreeNode(nd)
register struct node *nd;
{
extern struct def *GetDefinitionModule();
} :
[ FROM
- IDENT { FromId = MkLeaf(Name, &dot);
+ IDENT { FromId = dot2leaf(Name);
if (local) df = lookfor(FromId,enclosing(CurrVis),0);
else df = GetDefinitionModule(dot.TOK_IDF, 1);
}
#include "node.h"
static int loopcount = 0; /* Count nested loops */
+extern struct node *EmptyStatement;
}
statement(register struct node **pnd;)
* but this gives LL(1) conflicts
*/
designator(pnd)
- [ { nd = MkNode(Call, *pnd, NULLNODE, &dot);
+ [ { nd = dot2node(Call, *pnd, NULLNODE);
nd->nd_symb = '(';
}
ActualParameters(&(nd->nd_right))?
DOT = BECOMES;
}
]
- { nd = MkNode(Stat, *pnd, NULLNODE, &dot); }
+ { nd = dot2node(Stat, *pnd, NULLNODE); }
expression(&(nd->nd_right))
]
{ *pnd = nd; }
|
CaseStatement(pnd)
|
- WHILE { *pnd = nd = MkLeaf(Stat, &dot); }
+ WHILE { *pnd = nd = dot2leaf(Stat); }
expression(&(nd->nd_left))
DO
StatementSequence(&(nd->nd_right))
END
|
- REPEAT { *pnd = nd = MkLeaf(Stat, &dot); }
+ REPEAT { *pnd = nd = dot2leaf(Stat); }
StatementSequence(&(nd->nd_left))
UNTIL
expression(&(nd->nd_right))
|
{ loopcount++; }
- LOOP { *pnd = nd = MkLeaf(Stat, &dot); }
+ LOOP { *pnd = nd = dot2leaf(Stat); }
StatementSequence(&((*pnd)->nd_right))
END
{ loopcount--; }
|
EXIT
{ if (!loopcount) error("EXIT not in a LOOP");
- *pnd = MkLeaf(Stat, &dot);
+ *pnd = dot2leaf(Stat);
}
|
ReturnStatement(pnd)
{ return_occurred = 1; }
|
- /* empty */ { *pnd = 0; }
+ /* empty */ { *pnd = EmptyStatement; }
;
/*
statement(pnd)
[ %persistent
';' statement(&nd)
- { if (nd) {
- register struct node *nd1 =
- MkNode(Link, *pnd, nd, &dot);
+ { register struct node *nd1 = dot2node(Link, *pnd, nd);
- *pnd = nd1;
- nd1->nd_symb = ';';
- pnd = &(nd1->nd_right);
- }
+ *pnd = nd1;
+ nd1->nd_symb = ';';
+ pnd = &(nd1->nd_right);
}
]*
;
{
register struct node *nd;
} :
- IF { nd = MkLeaf(Stat, &dot);
+ IF { nd = dot2leaf(Stat);
*pnd = nd;
}
expression(&(nd->nd_left))
- THEN { nd->nd_right = MkLeaf(Link, &dot);
+ THEN { nd->nd_right = dot2leaf(Link);
nd = nd->nd_right;
}
StatementSequence(&(nd->nd_left))
[
- ELSIF { nd->nd_right = MkLeaf(Stat, &dot);
+ ELSIF { nd->nd_right = dot2leaf(Stat);
nd = nd->nd_right;
nd->nd_symb = IF;
}
expression(&(nd->nd_left))
- THEN { nd->nd_right = MkLeaf(Link, &dot);
+ THEN { nd->nd_right = dot2leaf(Link);
nd = nd->nd_right;
}
StatementSequence(&(nd->nd_left))
register struct node *nd;
struct type *tp = 0;
} :
- CASE { *pnd = nd = MkLeaf(Stat, &dot); }
+ CASE { *pnd = nd = dot2leaf(Stat); }
expression(&(nd->nd_left))
OF
case(&(nd->nd_right), &tp)
{ nd = nd->nd_right; }
]*
[ ELSE StatementSequence(&(nd->nd_right))
- { if (! nd->nd_right) {
- nd->nd_right = MkLeaf(Stat, &dot);
- nd->nd_right->nd_symb = ';';
- }
- }
]?
END
;
case(struct node **pnd; struct type **ptp;) :
[ CaseLabelList(ptp, pnd)
- ':' { *pnd = MkNode(Link, *pnd, NULLNODE, &dot); }
+ ':' { *pnd = dot2node(Link, *pnd, NULLNODE); }
StatementSequence(&((*pnd)->nd_right))
]?
- { *pnd = MkNode(Link, *pnd, NULLNODE, &dot);
+ { *pnd = dot2node(Link, *pnd, NULLNODE);
(*pnd)->nd_symb = '|';
}
;
{
register struct node *nd;
}:
- WHILE { *pnd = nd = MkLeaf(Stat, &dot); }
+ WHILE { *pnd = nd = dot2leaf(Stat); }
expression(&(nd->nd_left))
DO
StatementSequence(&(nd->nd_right))
{
register struct node *nd;
}:
- REPEAT { *pnd = nd = MkLeaf(Stat, &dot); }
+ REPEAT { *pnd = nd = dot2leaf(Stat); }
StatementSequence(&(nd->nd_left))
UNTIL
expression(&(nd->nd_right))
register struct node *nd, *nd1;
struct node *dummy;
}:
- FOR { *pnd = nd = MkLeaf(Stat, &dot); }
+ FOR { *pnd = nd = dot2leaf(Stat); }
IDENT { nd->nd_IDF = dot.TOK_IDF; }
- BECOMES { nd->nd_left = nd1 = MkLeaf(Stat, &dot); }
+ BECOMES { nd->nd_left = nd1 = dot2leaf(Stat); }
expression(&(nd1->nd_left))
TO
expression(&(nd1->nd_right))
/* inline in Statement; lack of space
LoopStatement(struct node **pnd;):
- LOOP { *pnd = MkLeaf(Stat, &dot); }
+ LOOP { *pnd = dot2leaf(Stat); }
StatementSequence(&((*pnd)->nd_right))
END
;
{
register struct node *nd;
}:
- WITH { *pnd = nd = MkLeaf(Stat, &dot); }
+ WITH { *pnd = nd = dot2leaf(Stat); }
designator(&(nd->nd_left))
DO
StatementSequence(&(nd->nd_right))
register struct node *nd;
} :
- RETURN { *pnd = nd = MkLeaf(Stat, &dot); }
+ RETURN { *pnd = nd = dot2leaf(Stat); }
[
expression(&(nd->nd_right))
{ if (scopeclosed(CurrentScope)) {
}
}
+STATIC
+ForLoopVarExpr(nd)
+ register struct node *nd;
+{
+ register struct type *tp;
+
+ CodePExpr(nd);
+ CodeCoercion(tp, BaseType(tp));
+}
+
WalkStat(nd, exit_label)
register struct node *nd;
label exit_label;
C_bra(l2);
C_df_ilb(l1);
WalkNode(right->nd_right, exit_label);
- C_df_ilb(l2);
+ l1 = l2;
}
- else C_df_ilb(l1);
+ C_df_ilb(l1);
break;
}
label l2 = ++text_label;
int uns = 0;
arith stepsize;
+ struct type *bstp;
good_forvar = DoForInit(nd);
if ((stepsize = left->nd_INT) == 0) {
- node_warning(left,
- W_ORDINARY,
- "zero stepsize in FOR loop");
+ node_warning(left,
+ W_ORDINARY,
+ "zero stepsize in FOR loop");
}
if (stepsize < 0) {
stepsize = -stepsize;
}
fnd = left->nd_right;
if (good_forvar) {
- uns = BaseType(nd->nd_type)->tp_fund !=
- T_INTEGER;
+ bstp = BaseType(nd->nd_type);
+ uns = bstp->tp_fund != T_INTEGER;
C_dup(int_size);
CodePExpr(fnd);
tmp = NewInt();
C_lol(tmp);
if (uns) C_cmu(int_size);
else C_cmi(int_size);
+ RangeCheck(bstp, nd->nd_type);
if (left->nd_INT >= 0) {
C_zgt(l2);
CodeDStore(nd);
C_lol(tmp);
- CodePExpr(nd);
+ ForLoopVarExpr(nd);
}
else {
C_zlt(l2);
+ C_dup(int_size);
CodeDStore(nd);
- CodePExpr(nd);
C_lol(tmp);
}
C_sbu(int_size);
C_dup(int_size);
C_zeq(l2);
C_loc(left->nd_INT);
- CodePExpr(nd);
+ ForLoopVarExpr(nd);
C_adu(int_size);
+ RangeCheck(bstp, nd->nd_type);
CodeDStore(nd);
}
C_bra(l1);
extern int (*WalkTable[])();
-#define WalkNode(xnd, xlab) if (! xnd) ; else (*WalkTable[(xnd)->nd_class])((xnd), (xlab))
+#define WalkNode(xnd, xlab) (*WalkTable[(xnd)->nd_class])((xnd), (xlab))
extern label text_label;
extern label data_label;