From 6217293e2324137f7a06d815fac752fe7c9f574d Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 9 Feb 1988 11:41:08 +0000 Subject: [PATCH] some fixes: - always remove imports from definition modules - minor improvement in error messages --- lang/m2/comp/chk_expr.c | 30 +++++++++++++++--------------- lang/m2/comp/def.c | 8 +++++++- lang/m2/comp/program.g | 8 +------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lang/m2/comp/chk_expr.c b/lang/m2/comp/chk_expr.c index c5674874a..3331acb72 100644 --- a/lang/m2/comp/chk_expr.c +++ b/lang/m2/comp/chk_expr.c @@ -53,6 +53,15 @@ df_error(nd, mess, edf) return 0; } +STATIC int +ex_error(nd, mess) + t_node *nd; + char *mess; +{ + node_error(nd, "\"%s\": %s", symbol2str(nd->nd_symb), mess); + return 0; +} + MkCoercion(pnd, tp) t_node **pnd; register t_type *tp; @@ -160,8 +169,7 @@ ChkArrow(expp) tp = expp->nd_right->nd_type; if (tp->tp_fund != T_POINTER) { - node_error(expp, "\"^\": illegal operand"); - return 0; + return ex_error(expp, "illegal operand type"); } expp->nd_type = RemoveEqual(PointedtoType(tp)); @@ -837,8 +845,7 @@ ChkBinOper(expp) */ if (expp->nd_symb == IN) { if (tpr->tp_fund != T_SET) { - node_error(expp, "\"IN\": right operand must be a set"); - return 0; + return ex_error(expp, "right operand must be a set"); } if (!TstAssCompat(ElementType(tpr), tpl)) { /* Assignment compatible ??? @@ -863,9 +870,7 @@ ChkBinOper(expp) if (!(tpr->tp_fund & allowed) || !(tpl->tp_fund & allowed)) { if (!((T_CARDINAL & allowed) && ChkAddress(tpl, tpr))) { - node_error(expp, "\"%s\": illegal operand type(s)", - symbol2str(expp->nd_symb)); - return 0; + return ex_error(expp, "illegal operand type(s)"); } if (expp->nd_type->tp_fund & T_CARDINAL) { expp->nd_type = address_type; @@ -873,17 +878,13 @@ ChkBinOper(expp) } if (Boolean(expp->nd_symb) && tpl != bool_type) { - node_error(expp, "\"%s\": illegal operand type(s)", - symbol2str(expp->nd_symb)); - return 0; + return ex_error(expp, "illegal operand type(s)"); } /* Operands must be compatible (distilled from Def 8.2) */ if (!TstCompat(tpr, tpl)) { - node_error(expp,"\"%s\": incompatible types", - symbol2str(expp->nd_symb)); - return 0; + return ex_error(expp, "incompatible operand types"); } MkCoercion(&(expp->nd_left), tpl); @@ -968,8 +969,7 @@ ChkUnOper(expp) default: crash("ChkUnOper"); } - node_error(expp, "\"%s\": illegal operand", symbol2str(expp->nd_symb)); - return 0; + return ex_error(expp, "illegal operand type"); } STATIC t_node * diff --git a/lang/m2/comp/def.c b/lang/m2/comp/def.c index e8d10c15f..f2db9823f 100644 --- a/lang/m2/comp/def.c +++ b/lang/m2/comp/def.c @@ -25,6 +25,7 @@ #include "scope.h" #include "node.h" #include "Lpars.h" +#include "warning.h" STATIC DefInFront(df) @@ -185,22 +186,27 @@ define(id, scope, kind) return MkDef(id, scope, kind); } -RemoveImports(pdf) +end_definition_list(pdf) register t_def **pdf; { /* Remove all imports from a definition module. This is neccesary because the implementation module might import them again. + Also, mark all other definitions "QUALIFIED EXPORT". */ register t_def *df = *pdf; while (df) { if (df->df_kind & D_IMPORTED) { + if (! (df->df_flags & D_USED)) { + warning(W_ORDINARY, "identifier \"%s\" imported but not used", df->df_idf->id_text); + } RemoveFromIdList(df); *pdf = df->df_nextinscope; free_def(df); } else { + df->df_flags |= D_QEXPORTED; pdf = &(df->df_nextinscope); } df = *pdf; diff --git a/lang/m2/comp/program.g b/lang/m2/comp/program.g index 0f4672c42..3571120d7 100644 --- a/lang/m2/comp/program.g +++ b/lang/m2/comp/program.g @@ -167,12 +167,7 @@ node_warning(exportlist, W_OLDFASHIONED, "export list in definition module ignor /* empty */ ] definition* END IDENT - { register t_def *df1 = CurrentScope->sc_def; - while (df1) { - /* Make all definitions "QUALIFIED EXPORT" */ - df1->df_flags |= D_QEXPORTED; - df1 = df1->df_nextinscope; - } + { end_definition_list(&(CurrentScope->sc_def)); DefinitionModule--; match_id(df->df_idf, dot.TOK_IDF); df->df_flags &= ~D_BUSY; @@ -219,7 +214,6 @@ ProgramModule IDENT { if (state == IMPLEMENTATION) { df = GetDefinitionModule(dot.TOK_IDF, 0); CurrVis = df->mod_vis; - RemoveImports(&(CurrentScope->sc_def)); } else { Defined = df = define(dot.TOK_IDF, GlobalScope, D_MODULE); -- 2.34.1