From 5bedccc36d0602dc2e20d11221ea90a156e7df88 Mon Sep 17 00:00:00 2001 From: Zeex Date: Sun, 22 Jan 2017 01:16:54 +0600 Subject: [PATCH] Force a reparse if function is used before declared Fixes #131. --- source/compiler/sc1.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/source/compiler/sc1.c b/source/compiler/sc1.c index b5070de..af736bd 100644 --- a/source/compiler/sc1.c +++ b/source/compiler/sc1.c @@ -3324,19 +3324,21 @@ SC_FUNC char *funcdisplayname(char *dest,char *funcname) static void check_reparse(symbol *sym) { - /* if the function was used before being declared, and it has a tag for the - * result, add a third pass (as second "skimming" parse) because the function - * result may have been used with user-defined operators, which have now - * been incorrectly flagged (as the return tag was unknown at the time of - * the call) + /* if the function was used before being declared, add a third pass (as + * second "skimming" parse) because: + * + * - the function result may have been used with user-defined operators, + * which have now been incorrectly flagged (as the return tag was unknown + * at the time of the call) + * + * - one or more of the function's arguments involve global variables that + * have been declared before the function; in this situation the arguments + * are uknown at the time the funtion is called, so the variable may not + * be marked as read (uREAD) and may therefore be omitted from the + * resulting P-code */ - if ((sym->usage & (uPROTOTYPED | uREAD))==uREAD && sym->tag!=0) { - int curstatus=sc_status; - sc_status=statWRITE; /* temporarily set status to WRITE, so the warning isn't blocked */ - error(208); - sc_status=curstatus; - sc_reparse=TRUE; /* must add another pass to "initial scan" phase */ - } /* if */ + if ((sym->usage & (uPROTOTYPED | uREAD))==uREAD) + sc_reparse=TRUE; /* must add another pass to "initial scan" phase */ } static void funcstub(int fnative) @@ -3739,7 +3741,7 @@ static int declargs(symbol *sym,int chkshadow) ident=iVARIABLE; numtags=0; fconst=FALSE; - fpublic= (sym->usage & uPUBLIC)!=0; + fpublic=(sym->usage & uPUBLIC)!=0; /* the '(' parantheses has already been parsed */ if (!matchtoken(')')){ do { /* there are arguments; process them */