improved volatiles, added warning for possibly nested comments

This commit is contained in:
eck 1990-04-02 15:57:51 +00:00
parent 2782412b59
commit 84b8c8a6ca
4 changed files with 23 additions and 22 deletions

View file

@ -449,7 +449,7 @@ skipcomment()
EOI is returned by LoadChar only on encountering EOF of the EOI is returned by LoadChar only on encountering EOF of the
top-level file... top-level file...
*/ */
register int c; register int c, oldc = '\0';
NoUnstack++; NoUnstack++;
c = GetChar(); c = GetChar();
@ -468,12 +468,16 @@ skipcomment()
#endif LINT #endif LINT
return; return;
} }
oldc = c;
c = GetChar(); c = GetChar();
#ifdef LINT #ifdef LINT
lint_comment_char(c); lint_comment_char(c);
#endif LINT #endif LINT
} /* last Character seen was '*' */ } /* last Character seen was '*' */
c = GetChar(); c = GetChar();
if ( c != '/' && oldc == '/')
lexwarning("comment inside comment ?");
oldc = '*';
#ifdef LINT #ifdef LINT
lint_comment_char(c); lint_comment_char(c);
#endif LINT #endif LINT

View file

@ -154,6 +154,9 @@ ch3sel(expp, oper, idf)
if (oper == '.' && exp->ex_flags & EX_READONLY) { if (oper == '.' && exp->ex_flags & EX_READONLY) {
exp->ex_type = qualifier_type(exp->ex_type, TQ_CONST); exp->ex_type = qualifier_type(exp->ex_type, TQ_CONST);
} }
if (exp->ex_flags & EX_VOLATILE) {
exp->ex_type = qualifier_type(exp->ex_type, TQ_VOLATILE);
}
*expp = exp; *expp = exp;
} }
@ -558,18 +561,19 @@ equal_proto(pl, opl)
return !(pl || opl); return !(pl || opl);
} }
/* check if a type has a const declared member */ /* check if a type has a consqualified member */
recurconst(tp) recurqual(tp, qual)
struct type *tp; struct type *tp;
int qual;
{ {
register struct sdef *sdf; register struct sdef *sdf;
ASSERT(tp); ASSERT(tp);
if (tp->tp_typequal & TQ_CONST) return 1; if (tp->tp_typequal & qual) return 1;
sdf = tp->tp_sdef; sdf = tp->tp_sdef;
while (sdf) { while (sdf) {
if (recurconst(sdf->sd_type)) if (recurqual(sdf->sd_type, qual))
return 1; return 1;
sdf = sdf->sd_sdef; sdf = sdf->sd_sdef;
} }
@ -595,7 +599,6 @@ ch3asgn(expp, oper, expr)
*/ */
register struct expr *exp = *expp; register struct expr *exp = *expp;
int fund = exp->ex_type->tp_fund; int fund = exp->ex_type->tp_fund;
int vol = 0;
struct type *tp; struct type *tp;
char *oper_string = symbol2str(oper); char *oper_string = symbol2str(oper);
@ -608,17 +611,11 @@ ch3asgn(expp, oper, expr)
} else if (exp->ex_flags & EX_READONLY) { } else if (exp->ex_flags & EX_READONLY) {
expr_error(exp, "operand of %s is read-only", oper_string); expr_error(exp, "operand of %s is read-only", oper_string);
} else if (fund == STRUCT || fund == UNION) { } else if (fund == STRUCT || fund == UNION) {
if (recurconst(exp->ex_type)) if (recurqual(exp->ex_type, TQ_CONST))
expr_error(expr,"operand of %s contains a const-qualified member", expr_error(expr,"operand of %s contains a const-qualified member",
oper_string); oper_string);
} }
/* Preserve volatile markers across the tree.
This is questionable, depending on the way the optimizer
wants this information.
*/
vol = (exp->ex_flags & EX_VOLATILE) || (expr->ex_flags & EX_VOLATILE);
if (oper == '=') { if (oper == '=') {
ch3cast(&expr, oper, exp->ex_type); ch3cast(&expr, oper, exp->ex_type);
tp = expr->ex_type; tp = expr->ex_type;
@ -654,7 +651,7 @@ ch3asgn(expp, oper, expr)
exp = new_oper(exp->ex_type, exp, oper, expr); exp = new_oper(exp->ex_type, exp, oper, expr);
#endif NOBITFIELD #endif NOBITFIELD
exp->OP_TYPE = tp; /* for EVAL() */ exp->OP_TYPE = tp; /* for EVAL() */
exp->ex_flags |= vol ? (EX_SIDEEFFECTS|EX_VOLATILE) : EX_SIDEEFFECTS; exp->ex_flags |= EX_SIDEEFFECTS;
*expp = exp; *expp = exp;
} }

View file

@ -575,10 +575,6 @@ code_expr(expr, val, code, tlbl, flbl)
if (! options['L']) /* profiling */ if (! options['L']) /* profiling */
C_lin((arith)(expr->ex_line)); C_lin((arith)(expr->ex_line));
/* HERE WE SHOULD GENERATE A MESSAGE:
if (expr->ex_flags & EX_VOLATILE)
HANDS_OFF
*/
EVAL(expr, val, code, tlbl, flbl); EVAL(expr, val, code, tlbl, flbl);
#else LINT #else LINT
lint_expr(expr, code ? USED : IGNORED); lint_expr(expr, code ? USED : IGNORED);

View file

@ -70,9 +70,11 @@ EVAL(expr, val, code, true_label, false_label)
int val, code; int val, code;
label true_label, false_label; label true_label, false_label;
{ {
register int gencode = (code == TRUE int vol = (code != TRUE && recurqual(expr->ex_type, TQ_VOLATILE));
&& (expr->ex_type->tp_size > 0 register int gencode = ((code == TRUE
|| expr->ex_type->tp_fund == FUNCTION)); && (expr->ex_type->tp_size > 0
|| expr->ex_type->tp_fund == FUNCTION))
|| vol);
switch (expr->ex_class) { switch (expr->ex_class) {
case Value: /* just a simple value */ case Value: /* just a simple value */
@ -661,7 +663,9 @@ EVAL(expr, val, code, true_label, false_label)
default: default:
crash("(EVAL) bad expression class"); crash("(EVAL) bad expression class");
} }
if (expr->ex_flags & EX_VOLATILE) C_nop(); if (expr->ex_flags & EX_VOLATILE || vol) C_nop();
if (vol) C_asp(expr->ex_type->tp_size);
} }
/* compare() serves as an auxiliary function of EVAL */ /* compare() serves as an auxiliary function of EVAL */