From 84b8c8a6ca3120292595eb18247541730501acb7 Mon Sep 17 00:00:00 2001 From: eck Date: Mon, 2 Apr 1990 15:57:51 +0000 Subject: [PATCH] improved volatiles, added warning for possibly nested comments --- lang/cem/cemcom.ansi/LLlex.c | 6 +++++- lang/cem/cemcom.ansi/ch3.c | 23 ++++++++++------------- lang/cem/cemcom.ansi/code.c | 4 ---- lang/cem/cemcom.ansi/eval.c | 12 ++++++++---- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/lang/cem/cemcom.ansi/LLlex.c b/lang/cem/cemcom.ansi/LLlex.c index 9f6dfb8eb..4ba1edff8 100644 --- a/lang/cem/cemcom.ansi/LLlex.c +++ b/lang/cem/cemcom.ansi/LLlex.c @@ -449,7 +449,7 @@ skipcomment() EOI is returned by LoadChar only on encountering EOF of the top-level file... */ - register int c; + register int c, oldc = '\0'; NoUnstack++; c = GetChar(); @@ -468,12 +468,16 @@ skipcomment() #endif LINT return; } + oldc = c; c = GetChar(); #ifdef LINT lint_comment_char(c); #endif LINT } /* last Character seen was '*' */ c = GetChar(); + if ( c != '/' && oldc == '/') + lexwarning("comment inside comment ?"); + oldc = '*'; #ifdef LINT lint_comment_char(c); #endif LINT diff --git a/lang/cem/cemcom.ansi/ch3.c b/lang/cem/cemcom.ansi/ch3.c index 24d7f71fe..6803fc8a6 100644 --- a/lang/cem/cemcom.ansi/ch3.c +++ b/lang/cem/cemcom.ansi/ch3.c @@ -154,6 +154,9 @@ ch3sel(expp, oper, idf) if (oper == '.' && exp->ex_flags & EX_READONLY) { 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; } @@ -558,18 +561,19 @@ equal_proto(pl, opl) return !(pl || opl); } -/* check if a type has a const declared member */ -recurconst(tp) +/* check if a type has a consqualified member */ +recurqual(tp, qual) struct type *tp; +int qual; { register struct sdef *sdf; ASSERT(tp); - if (tp->tp_typequal & TQ_CONST) return 1; + if (tp->tp_typequal & qual) return 1; sdf = tp->tp_sdef; while (sdf) { - if (recurconst(sdf->sd_type)) + if (recurqual(sdf->sd_type, qual)) return 1; sdf = sdf->sd_sdef; } @@ -595,7 +599,6 @@ ch3asgn(expp, oper, expr) */ register struct expr *exp = *expp; int fund = exp->ex_type->tp_fund; - int vol = 0; struct type *tp; char *oper_string = symbol2str(oper); @@ -608,17 +611,11 @@ ch3asgn(expp, oper, expr) } else if (exp->ex_flags & EX_READONLY) { expr_error(exp, "operand of %s is read-only", oper_string); } 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", 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 == '=') { ch3cast(&expr, oper, exp->ex_type); tp = expr->ex_type; @@ -654,7 +651,7 @@ ch3asgn(expp, oper, expr) exp = new_oper(exp->ex_type, exp, oper, expr); #endif NOBITFIELD exp->OP_TYPE = tp; /* for EVAL() */ - exp->ex_flags |= vol ? (EX_SIDEEFFECTS|EX_VOLATILE) : EX_SIDEEFFECTS; + exp->ex_flags |= EX_SIDEEFFECTS; *expp = exp; } diff --git a/lang/cem/cemcom.ansi/code.c b/lang/cem/cemcom.ansi/code.c index b0e02f1ae..30a1939f3 100644 --- a/lang/cem/cemcom.ansi/code.c +++ b/lang/cem/cemcom.ansi/code.c @@ -575,10 +575,6 @@ code_expr(expr, val, code, tlbl, flbl) if (! options['L']) /* profiling */ 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); #else LINT lint_expr(expr, code ? USED : IGNORED); diff --git a/lang/cem/cemcom.ansi/eval.c b/lang/cem/cemcom.ansi/eval.c index e51ff91b1..54134b298 100644 --- a/lang/cem/cemcom.ansi/eval.c +++ b/lang/cem/cemcom.ansi/eval.c @@ -70,9 +70,11 @@ EVAL(expr, val, code, true_label, false_label) int val, code; label true_label, false_label; { - register int gencode = (code == TRUE - && (expr->ex_type->tp_size > 0 - || expr->ex_type->tp_fund == FUNCTION)); + int vol = (code != TRUE && recurqual(expr->ex_type, TQ_VOLATILE)); + register int gencode = ((code == TRUE + && (expr->ex_type->tp_size > 0 + || expr->ex_type->tp_fund == FUNCTION)) + || vol); switch (expr->ex_class) { case Value: /* just a simple value */ @@ -661,7 +663,9 @@ EVAL(expr, val, code, true_label, false_label) default: 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 */ -- 2.34.1