Commit 4beac998 authored by Russ Cox's avatar Russ Cox

simplifying grammar: delete LBASETYPE and LACONST.

take 2

R=ken
OCL=29304
CL=29306
parent ca2fe5d8
...@@ -213,7 +213,7 @@ typeinit(int lex) ...@@ -213,7 +213,7 @@ typeinit(int lex)
int i, etype, sameas; int i, etype, sameas;
Type *t; Type *t;
Sym *s; Sym *s;
if(widthptr == 0) if(widthptr == 0)
fatal("typeinit before betypeinit"); fatal("typeinit before betypeinit");
......
...@@ -1056,7 +1056,7 @@ addconst(Node *n, Node *e, int ctxt) ...@@ -1056,7 +1056,7 @@ addconst(Node *n, Node *e, int ctxt)
redeclare("constant", s); redeclare("constant", s);
s->oconst = e; s->oconst = e;
s->lexical = LACONST; s->lexical = LNAME;
d = dcl(); d = dcl();
d->dsym = s; d->dsym = s;
...@@ -1136,6 +1136,14 @@ oldname(Sym *s) ...@@ -1136,6 +1136,14 @@ oldname(Sym *s)
Node *n; Node *n;
Node *c; Node *c;
if(s->oconst) {
n = nod(OLITERAL, N, N);
n->sym = s;
n->val = s->oconst->val;
n->type = s->oconst->type;
return n;
}
n = s->oname; n = s->oname;
if(n == N) { if(n == N) {
n = nod(ONONAME, N, N); n = nod(ONONAME, N, N);
...@@ -1205,11 +1213,11 @@ nametoanondcl(Node *na) ...@@ -1205,11 +1213,11 @@ nametoanondcl(Node *na)
for(l=&na; (n=*l)->op == OLIST; l=&n->left) for(l=&na; (n=*l)->op == OLIST; l=&n->left)
n->right = nametoanondcl(n->right); n->right = nametoanondcl(n->right);
if(n->sym->lexical != LATYPE && n->sym->lexical != LBASETYPE) { t = n->sym->otype;
if(t == T) {
yyerror("%s is not a type", n->sym->name); yyerror("%s is not a type", n->sym->name);
t = typ(TINT32); t = typ(TINT32);
} else }
t = oldtype(n->sym);
n = nod(ODCLFIELD, N, N); n = nod(ODCLFIELD, N, N);
n->type = t; n->type = t;
*l = n; *l = n;
......
...@@ -190,7 +190,6 @@ dumpsym(Sym *s) ...@@ -190,7 +190,6 @@ dumpsym(Sym *s)
yyerror("package export symbol: %S", s); yyerror("package export symbol: %S", s);
break; break;
case LATYPE: case LATYPE:
case LBASETYPE:
// TODO(rsc): sort methods by name // TODO(rsc): sort methods by name
for(f=s->otype->method; f!=T; f=f->down) for(f=s->otype->method; f!=T; f=f->down)
dumpprereq(f); dumpprereq(f);
...@@ -201,10 +200,10 @@ dumpsym(Sym *s) ...@@ -201,10 +200,10 @@ dumpsym(Sym *s)
f->type->type->type, f->sym, f->type); f->type->type->type, f->sym, f->type);
break; break;
case LNAME: case LNAME:
dumpexportvar(s); if(s->oconst)
break; dumpexportconst(s);
case LACONST: else
dumpexportconst(s); dumpexportvar(s);
break; break;
} }
} }
...@@ -344,7 +343,7 @@ importconst(Node *ss, Type *t, Node *n) ...@@ -344,7 +343,7 @@ importconst(Node *ss, Type *t, Node *n)
return; return;
convlit(n, t); convlit(n, t);
s = importsym(ss, LACONST); s = importsym(ss, LNAME);
if(s->oconst != N) { if(s->oconst != N) {
// TODO: check if already the same. // TODO: check if already the same.
return; return;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
} }
%token <val> LLITERAL %token <val> LLITERAL
%token <lint> LASOP %token <lint> LASOP
%token <sym> LNAME LBASETYPE LATYPE LPACK LACONST %token <sym> LNAME LATYPE LPACK
%token <sym> LPACKAGE LIMPORT LDEFER LCLOSE LCLOSED %token <sym> LPACKAGE LIMPORT LDEFER LCLOSE LCLOSED
%token <sym> LMAP LCHAN LINTERFACE LFUNC LSTRUCT %token <sym> LMAP LCHAN LINTERFACE LFUNC LSTRUCT
%token <sym> LCOLAS LFALL LRETURN LDDD %token <sym> LCOLAS LFALL LRETURN LDDD
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
* names like Bstmt, Bvardcl, etc. can't. * names like Bstmt, Bvardcl, etc. can't.
*/ */
%type <sym> sym sym1 sym2 sym3 keyword laconst lname latype lpackatype %type <sym> sym sym1 sym2 sym3 keyword lname latype lpackatype
%type <node> xdcl xdcl_list_r oxdcl_list %type <node> xdcl xdcl_list_r oxdcl_list
%type <node> common_dcl Acommon_dcl Bcommon_dcl %type <node> common_dcl Acommon_dcl Bcommon_dcl
%type <node> oarg_type_list arg_type_list_r arg_chunk arg_chunk_list_r arg_type_list %type <node> oarg_type_list arg_type_list_r arg_chunk arg_chunk_list_r arg_type_list
...@@ -913,13 +913,6 @@ pexpr: ...@@ -913,13 +913,6 @@ pexpr:
{ {
$$ = nodbool(0); $$ = nodbool(0);
} }
| laconst
{
$$ = nod(OLITERAL, N, N);
$$->sym = $1;
$$->val = $1->oconst->val;
$$->type = $1->oconst->type;
}
| LIOTA | LIOTA
{ {
$$ = nodintconst(iota); $$ = nodintconst(iota);
...@@ -1023,14 +1016,6 @@ lpack: ...@@ -1023,14 +1016,6 @@ lpack:
} }
*/ */
laconst:
LACONST
| lpack '.' LACONST
{
$$ = $3;
context = nil;
}
lname: lname:
LNAME LNAME
| lpack '.' LNAME | lpack '.' LNAME
...@@ -1082,7 +1067,6 @@ onew_name: ...@@ -1082,7 +1067,6 @@ onew_name:
sym: sym:
LATYPE LATYPE
| LNAME | LNAME
| LACONST
| LPACK | LPACK
sym1: sym1:
...@@ -1112,7 +1096,6 @@ sym3: ...@@ -1112,7 +1096,6 @@ sym3:
| LPRINTN | LPRINTN
| LNEW | LNEW
| LMAKE | LMAKE
| LBASETYPE
/* /*
* keywords that we can * keywords that we can
...@@ -2129,20 +2112,8 @@ lpack: ...@@ -2129,20 +2112,8 @@ lpack:
YYERROR; YYERROR;
} }
laconst:
LATYPE
{
yyerror("%s is type, not var", $1->name);
YYERROR;
}
latype: latype:
LACONST LPACK
{
yyerror("%s is const, not type", $1->name);
YYERROR;
}
| LPACK
{ {
yyerror("%s is package, not type", $1->name); yyerror("%s is package, not type", $1->name);
YYERROR; YYERROR;
......
...@@ -64,7 +64,7 @@ main(int argc, char *argv[]) ...@@ -64,7 +64,7 @@ main(int argc, char *argv[])
fatal("betypeinit failed"); fatal("betypeinit failed");
lexinit(); lexinit();
typeinit(LBASETYPE); typeinit(LATYPE);
lineno = 1; lineno = 1;
block = 1; block = 1;
...@@ -775,8 +775,6 @@ talph: ...@@ -775,8 +775,6 @@ talph:
DBG("lex: %S %s\n", s, lexname(s->lexical)); DBG("lex: %S %s\n", s, lexname(s->lexical));
yylval.sym = s; yylval.sym = s;
if(s->lexical == LBASETYPE)
return LATYPE;
return s->lexical; return s->lexical;
tnum: tnum:
...@@ -1111,25 +1109,25 @@ static struct ...@@ -1111,25 +1109,25 @@ static struct
/* name lexical etype /* name lexical etype
*/ */
/* basic types */ /* basic types */
"int8", LBASETYPE, TINT8, "int8", LATYPE, TINT8,
"int16", LBASETYPE, TINT16, "int16", LATYPE, TINT16,
"int32", LBASETYPE, TINT32, "int32", LATYPE, TINT32,
"int64", LBASETYPE, TINT64, "int64", LATYPE, TINT64,
"uint8", LBASETYPE, TUINT8, "uint8", LATYPE, TUINT8,
"uint16", LBASETYPE, TUINT16, "uint16", LATYPE, TUINT16,
"uint32", LBASETYPE, TUINT32, "uint32", LATYPE, TUINT32,
"uint64", LBASETYPE, TUINT64, "uint64", LATYPE, TUINT64,
"float32", LBASETYPE, TFLOAT32, "float32", LATYPE, TFLOAT32,
"float64", LBASETYPE, TFLOAT64, "float64", LATYPE, TFLOAT64,
"float80", LBASETYPE, TFLOAT80, "float80", LATYPE, TFLOAT80,
"bool", LBASETYPE, TBOOL, "bool", LATYPE, TBOOL,
"byte", LBASETYPE, TUINT8, "byte", LATYPE, TUINT8,
"string", LBASETYPE, TSTRING, "string", LATYPE, TSTRING,
"any", LBASETYPE, TANY, "any", LATYPE, TANY,
"break", LBREAK, Txxx, "break", LBREAK, Txxx,
"case", LCASE, Txxx, "case", LCASE, Txxx,
...@@ -1197,10 +1195,10 @@ lexinit(void) ...@@ -1197,10 +1195,10 @@ lexinit(void)
s->lexical = lex; s->lexical = lex;
s->package = package; s->package = package;
if(lex != LBASETYPE) etype = syms[i].etype;
if(etype == Txxx)
continue; continue;
etype = syms[i].etype;
if(etype < 0 || etype >= nelem(types)) if(etype < 0 || etype >= nelem(types))
fatal("lexinit: %s bad etype", s->name); fatal("lexinit: %s bad etype", s->name);
...@@ -1234,9 +1232,6 @@ struct ...@@ -1234,9 +1232,6 @@ struct
{ {
LANDAND, "ANDAND", LANDAND, "ANDAND",
LASOP, "ASOP", LASOP, "ASOP",
LACONST, "ACONST",
LATYPE, "ATYPE",
LBASETYPE, "BASETYPE",
LBREAK, "BREAK", LBREAK, "BREAK",
LCASE, "CASE", LCASE, "CASE",
LCHAN, "CHAN", LCHAN, "CHAN",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment