From 0601a21c66c50884b7030e1e1baf021f10743ae0 Mon Sep 17 00:00:00 2001 From: "benjamin.franksen" <benjamin.franksen@helmholtz-berlin.de> Date: Fri, 4 Oct 2013 00:12:51 +0000 Subject: [PATCH] snc: deprecated foreign declarations Foreign declarations have been a bad idea. This became clear after implementing indirect calls, because as a consequence you get 'used but not declared' warnings for calls to foreign functions, too. I could 'fix' that with a bit of effort, but that would be misplaced. The C compiler will warn about undeclared variables and functions anyway, so why bother? If you really want to know, perhaps for debugging, use -W option for extra warnings. If you do, you'll now get the more precise waring 'treating undeclared object xxx as foreign'. --- src/snc/analysis.c | 10 ++++++++-- src/snc/snl.lem | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/snc/analysis.c b/src/snc/analysis.c index 62220498..8451795a 100644 --- a/src/snc/analysis.c +++ b/src/snc/analysis.c @@ -283,6 +283,7 @@ static void analyse_declaration(SymTable st, Expr *scope, Expr *defn) { Var *vp; VarList *var_list; + static uint seen_foreign = FALSE; assert(scope); /* precondition */ assert(defn); /* precondition */ @@ -294,7 +295,12 @@ static void analyse_declaration(SymTable st, Expr *scope, Expr *defn) #ifdef DEBUG report("declaration: %s\n", vp->name); #endif - + if (vp->type->tag == T_NONE && !seen_foreign) + { + warning_at_expr(defn, + "foreign declarations are deprecated\n"); + seen_foreign = TRUE; + } if (scope->type != D_PROG && (vp->type->tag == T_NONE || vp->type->tag == T_EVFLAG)) { @@ -1119,7 +1125,7 @@ static int connect_variable(Expr *ep, Expr *scope, void *parg) return FALSE; } - extra_warning_at_expr(ep, "variable '%s' used but not declared\n", + extra_warning_at_expr(ep, "treating undeclared object '%s' as foreign\n", ep->value); /* create a pseudo declaration so we can finish the analysis phase */ vp = new(Var); diff --git a/src/snc/snl.lem b/src/snc/snl.lem index 89b93887..c9101ad4 100644 --- a/src/snc/snl.lem +++ b/src/snc/snl.lem @@ -197,6 +197,7 @@ direct_declarator(p) ::= LPAREN declarator(x) RPAREN. direct_declarator(p) ::= direct_declarator(x) subscript(s). { p = decl_postfix_array(x, s.str); } +// deprecated declaration(p) ::= FOREIGN declarators(ds) SEMICOLON. { p = decl_add_base_type(ds, mk_no_type()); } -- GitLab