// if n has been forward declared,
// use the Type* created then
s = n->sym;
- if(s->tblock == block) {
+ if(s->block == block) {
switch(s->otype->etype) {
case TFORWSTRUCT:
case TFORWINTER:
a->lexical = b->lexical;
a->undef = b->undef;
a->vargen = b->vargen;
- a->vblock = b->vblock;
- a->tblock = b->tblock;
+ a->block = b->block;
+ a->lastlineno = b->lastlineno;
a->local = b->local;
a->offset = b->offset;
}
if(d == S)
fatal("popdcl: no mark");
dclstack = d->link;
- block = d->vblock;
+ block = d->block;
}
void
d = push();
d->name = nil; // used as a mark in fifo
- d->vblock = block;
+ d->block = block;
blockgen++;
block = blockgen;
}
}
+static void
+redeclare(char *str, Sym *s)
+{
+ if(s->block != block) {
+ s->block = block;
+ s->lastlineno = lineno;
+ return;
+ }
+ yyerror("%s %S redeclared in this block %d", str, s, block);
+ print(" previous declaration at %L\n", s->lastlineno);
+}
+
void
addvar(Node *n, Type *t, int ctxt)
{
s = n->sym;
- if(s->vblock == block) {
- if(s->oname != N) {
- yyerror("var %S redeclared in this block"
- "\n\tprevious declaration at %L",
- s, s->oname->lineno);
- } else
- yyerror("var %S redeclared in this block", s);
- }
-
if(ctxt == PEXTERN) {
r = externdcl;
gen = 0;
pushdcl(s);
}
+ redeclare("variable", s);
s->vargen = gen;
s->oname = n;
s->offset = 0;
- s->vblock = block;
s->lexical = LNAME;
n->type = t;
n->vargen = ++typgen;
}
- if(s->tblock == block)
- yyerror("type %S redeclared in this block %d", s, block);
-
+ redeclare("type", s);
s->otype = n;
s->lexical = LATYPE;
- s->tblock = block;
d = dcl();
d->dsym = s;
pushdcl(s);
}
+ redeclare("constant", s);
s->oconst = e;
s->lexical = LACONST;
struct Sym
{
- ushort tblock; // blocknumber for type
- ushort vblock; // blocknumber for variable
+ ushort block; // blocknumber to catch redeclaration
uchar undef; // a diagnostic has been generated
uchar export; // marked as export
vlong offset; // stack location if automatic
int32 lexical;
int32 vargen; // unique variable number
+ int32 lastlineno; // last declaration for diagnostic
Sym* link;
};
#define S ((Sym*)0)
// SYS_NOSYS = 296; // { int nosys(void); } { old load_shared_file }
// SYS_NOSYS = 297; // { int nosys(void); } { old reset_shared_file }
// SYS_NOSYS = 298; // { int nosys(void); } { old new_system_shared_regions }
- SYS_ENOSYS = 299; // { int enosys(void); } { old shared_region_map_file_np }
+ // SYS_ENOSYS = 299; // { int enosys(void); } { old shared_region_map_file_np }
SYS_ENOSYS = 300; // { int enosys(void); } { old shared_region_make_private_np }
SYS___PTHREAD_MUTEX_DESTROY = 301; // { int __pthread_mutex_destroy(int mutexid); }
SYS___PTHREAD_MUTEX_INIT = 302; // { int __pthread_mutex_init(user_addr_t mutex, user_addr_t attr); }