Now detects use before declaration, f.i. in
VAR k: REAL; REAL : INTEGER;
This commit is contained in:
parent
032e9ebda5
commit
5cd95d47b2
|
@ -1 +1 @@
|
||||||
static char Version[] = "ACK Modula-2 compiler Version 0.24";
|
static char Version[] = "ACK Modula-2 compiler Version 0.25";
|
||||||
|
|
|
@ -98,9 +98,11 @@ struct def { /* list of definitions for a name */
|
||||||
#define D_ERROR 0x4000 /* a compiler generated definition for an
|
#define D_ERROR 0x4000 /* a compiler generated definition for an
|
||||||
undefined variable
|
undefined variable
|
||||||
*/
|
*/
|
||||||
|
#define D_INUSE 0x8000 /* identification in this scope (like D_IMPORT)
|
||||||
|
*/
|
||||||
#define D_VALUE (D_PROCEDURE|D_VARIABLE|D_FIELD|D_ENUM|D_CONST|D_PROCHEAD)
|
#define D_VALUE (D_PROCEDURE|D_VARIABLE|D_FIELD|D_ENUM|D_CONST|D_PROCHEAD)
|
||||||
#define D_ISTYPE (D_HIDDEN|D_TYPE|D_FTYPE)
|
#define D_ISTYPE (D_HIDDEN|D_TYPE|D_FTYPE)
|
||||||
#define D_IMPORTED (D_IMPORT)
|
#define D_IMPORTED (D_IMPORT|D_INUSE)
|
||||||
#define is_type(dfx) ((dfx)->df_kind & D_ISTYPE)
|
#define is_type(dfx) ((dfx)->df_kind & D_ISTYPE)
|
||||||
unsigned short df_flags;
|
unsigned short df_flags;
|
||||||
#define D_NOREG 0x01 /* set if it may not reside in a register */
|
#define D_NOREG 0x01 /* set if it may not reside in a register */
|
||||||
|
|
|
@ -96,16 +96,22 @@ define(id, scope, kind)
|
||||||
*/
|
*/
|
||||||
register t_def *df;
|
register t_def *df;
|
||||||
|
|
||||||
df = lookup(id, scope, 1, 0);
|
df = lookup(id, scope, 2, 0);
|
||||||
if ( /* Already in this scope */
|
if ( /* Already in this scope */
|
||||||
df
|
df
|
||||||
|| /* A closed scope, and id defined in the pervasive scope */
|
|| /* A closed scope, and id defined in the pervasive scope */
|
||||||
(
|
(
|
||||||
scopeclosed(scope)
|
scopeclosed(scope)
|
||||||
&&
|
&&
|
||||||
(df = lookup(id, PervasiveScope, 1, 0)))
|
(df = lookup(id, PervasiveScope, 2, 0)))
|
||||||
) {
|
) {
|
||||||
switch(df->df_kind) {
|
switch(df->df_kind) {
|
||||||
|
case D_INUSE:
|
||||||
|
if (kind != D_INUSE) {
|
||||||
|
error("identifier \"%s\" already used; may not be redefined in this scope", df->df_idf->id_text);
|
||||||
|
}
|
||||||
|
return df;
|
||||||
|
|
||||||
case D_HIDDEN:
|
case D_HIDDEN:
|
||||||
/* An opaque type. We may now have found the
|
/* An opaque type. We may now have found the
|
||||||
definition of this type.
|
definition of this type.
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include "type.h"
|
#include "type.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
|
extern int pass_1;
|
||||||
|
|
||||||
t_def *
|
t_def *
|
||||||
lookup(id, scope, import, flags)
|
lookup(id, scope, import, flags)
|
||||||
register t_idf *id;
|
register t_idf *id;
|
||||||
|
@ -55,6 +57,7 @@ lookup(id, scope, import, flags)
|
||||||
df->df_flags |= flags;
|
df->df_flags |= flags;
|
||||||
if (import) {
|
if (import) {
|
||||||
while (df->df_kind & D_IMPORTED) {
|
while (df->df_kind & D_IMPORTED) {
|
||||||
|
if (df->df_kind == D_INUSE && import != 1) break;
|
||||||
assert(df->imp_def != 0);
|
assert(df->imp_def != 0);
|
||||||
df = df->imp_def;
|
df = df->imp_def;
|
||||||
}
|
}
|
||||||
|
@ -66,23 +69,31 @@ lookup(id, scope, import, flags)
|
||||||
t_def *
|
t_def *
|
||||||
lookfor(id, vis, message, flags)
|
lookfor(id, vis, message, flags)
|
||||||
register t_node *id;
|
register t_node *id;
|
||||||
t_scopelist *vis;
|
register t_scopelist *vis;
|
||||||
{
|
{
|
||||||
/* Look for an identifier in the visibility range started by "vis".
|
/* Look for an identifier in the visibility range started by "vis".
|
||||||
If it is not defined create a dummy definition and,
|
If it is not defined create a dummy definition and,
|
||||||
if message is set, give an error message
|
if message is set, give an error message
|
||||||
*/
|
*/
|
||||||
register t_def *df;
|
|
||||||
register t_scopelist *sc = vis;
|
register t_scopelist *sc = vis;
|
||||||
|
t_def *df;
|
||||||
|
|
||||||
while (sc) {
|
while (sc) {
|
||||||
df = lookup(id->nd_IDF, sc->sc_scope, 1, flags);
|
df = lookup(id->nd_IDF, sc->sc_scope, 1, flags);
|
||||||
if (df) return df;
|
if (df) {
|
||||||
|
if (pass_1 &&
|
||||||
|
message &&
|
||||||
|
sc->sc_scope->sc_level < vis->sc_scope->sc_level &&
|
||||||
|
! scopeclosed(vis->sc_scope)) {
|
||||||
|
define(id->nd_IDF, vis->sc_scope, D_INUSE)->
|
||||||
|
imp_def = df;
|
||||||
|
}
|
||||||
|
return df;
|
||||||
|
}
|
||||||
sc = nextvisible(sc);
|
sc = nextvisible(sc);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message) id_not_declared(id);
|
if (message) id_not_declared(id);
|
||||||
|
|
||||||
df = MkDef(id->nd_IDF, vis->sc_scope, D_ERROR);
|
return MkDef(id->nd_IDF, vis->sc_scope, D_ERROR);
|
||||||
return df;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,7 @@ Reverse(pdf)
|
||||||
from this list.
|
from this list.
|
||||||
*/
|
*/
|
||||||
register t_def *df, *df1;
|
register t_def *df, *df1;
|
||||||
#define INTERESTING D_MODULE|D_PROCEDURE|D_PROCHEAD|D_VARIABLE
|
#define INTERESTING (D_MODULE|D_PROCEDURE|D_PROCHEAD|D_VARIABLE|D_IMPORTED)
|
||||||
|
|
||||||
df = 0;
|
df = 0;
|
||||||
df1 = *pdf;
|
df1 = *pdf;
|
||||||
|
|
|
@ -860,8 +860,8 @@ UseWarnings(df)
|
||||||
register t_def *df1 = df->imp_def;
|
register t_def *df1 = df->imp_def;
|
||||||
|
|
||||||
df1->df_flags |= df->df_flags & (D_USED|D_DEFINED);
|
df1->df_flags |= df->df_flags & (D_USED|D_DEFINED);
|
||||||
if (df->df_kind == D_IMPORT &&
|
if (df->df_kind == D_INUSE) return;
|
||||||
!(df->df_flags & D_IMP_BY_EXP)) {
|
if ( !(df->df_flags & D_IMP_BY_EXP)) {
|
||||||
if (! (df->df_flags & (D_USED | D_DEFINED))) {
|
if (! (df->df_flags & (D_USED | D_DEFINED))) {
|
||||||
node_warning(
|
node_warning(
|
||||||
df->df_scope->sc_end,
|
df->df_scope->sc_end,
|
||||||
|
|
Loading…
Reference in a new issue