ref: e39e0bdcd1bab3e9f07bab9b106fa7f9b97093e5
parent: ab5236f243874178ac55207301a6d9a3ca0eeade
author: Tor Andersson <tor@ccxvii.net>
date: Mon Feb 10 10:44:40 EST 2014
Separate generic AST_IDENTIFIER and EXP_IDENTIFIER. Use EXP_IDENTIFIER for the primary expression, and AST_IDENTIFIER for non-expression uses.
--- a/jscompile.c
+++ b/jscompile.c
@@ -194,10 +194,10 @@
js_Ast *kv = list->a;
js_Ast *prop = kv->a;
if (kv->type == EXP_PROP_VAL) {
- if (prop->type == AST_IDENTIFIER || prop->type == AST_STRING) {
+ if (prop->type == AST_IDENTIFIER || prop->type == EXP_STRING) {
cexp(J, F, kv->b);
emitstring(J, F, OP_INITPROP_S, prop->string);
- } else if (prop->type == AST_NUMBER) {
+ } else if (prop->type == EXP_NUMBER) {
if (prop->number == (short)prop->number) {
cexp(J, F, kv->b);
emit(J, F, OP_INITPROP_N);
@@ -211,9 +211,9 @@
jsC_error(J, list, "illegal property name in object initializer");
}
} else {
- if (prop->type == AST_IDENTIFIER || prop->type == AST_STRING)
+ if (prop->type == AST_IDENTIFIER || prop->type == EXP_STRING)
emitstring(J, F, OP_STRING, prop->string);
- if (prop->type == AST_NUMBER)
+ if (prop->type == EXP_NUMBER)
emitnumber(J, F, prop->number);
emitfunction(J, F, newfun(J, NULL, kv->b, kv->c, 0));
if (kv->type == EXP_PROP_GET)
@@ -239,7 +239,7 @@
static void cassign(JF, js_Ast *lhs, js_Ast *rhs)
{
switch (lhs->type) {
- case AST_IDENTIFIER:
+ case EXP_IDENTIFIER:
cexp(J, F, rhs);
emitstring(J, F, OP_SETVAR, lhs->string);
break;
@@ -273,7 +273,7 @@
}
switch (lhs->type) {
- case AST_IDENTIFIER:
+ case EXP_IDENTIFIER:
emitstring(J, F, OP_SETVAR, lhs->string);
emit(J, F, OP_POP);
break;
@@ -299,7 +299,7 @@
static void cassignop1(JF, js_Ast *lhs, int dup)
{
switch (lhs->type) {
- case AST_IDENTIFIER:
+ case EXP_IDENTIFIER:
emitstring(J, F, OP_GETVAR, lhs->string);
if (dup) emit(J, F, OP_DUP);
break;
@@ -325,7 +325,7 @@
static void cassignop2(JF, js_Ast *lhs)
{
switch (lhs->type) {
- case AST_IDENTIFIER:
+ case EXP_IDENTIFIER:
emitstring(J, F, OP_SETVAR, lhs->string);
break;
case EXP_INDEX:
@@ -350,7 +350,7 @@
static void cdelete(JF, js_Ast *exp)
{
switch (exp->type) {
- case AST_IDENTIFIER:
+ case EXP_IDENTIFIER:
emitstring(J, F, OP_DELVAR, exp->string);
break;
case EXP_INDEX:
@@ -401,8 +401,8 @@
int n;
switch (exp->type) {
- case AST_STRING: emitstring(J, F, OP_STRING, exp->string); break;
- case AST_NUMBER: emitnumber(J, F, exp->number); break;
+ case EXP_STRING: emitstring(J, F, OP_STRING, exp->string); break;
+ case EXP_NUMBER: emitnumber(J, F, exp->number); break;
case EXP_UNDEF: emit(J, F, OP_UNDEF); break;
case EXP_NULL: emit(J, F, OP_NULL); break;
case EXP_TRUE: emit(J, F, OP_TRUE); break;
@@ -409,7 +409,7 @@
case EXP_FALSE: emit(J, F, OP_FALSE); break;
case EXP_THIS: emit(J, F, OP_THIS); break;
- case AST_REGEXP:
+ case EXP_REGEXP:
emit(J, F, OP_NEWREGEXP);
emitraw(J, F, addstring(J, F, exp->string));
emitraw(J, F, exp->number);
@@ -429,7 +429,7 @@
emitfunction(J, F, newfun(J, exp->a, exp->b, exp->c, 0));
break;
- case AST_IDENTIFIER:
+ case EXP_IDENTIFIER:
emitstring(J, F, OP_GETVAR, exp->string);
break;
--- a/jsdump.c
+++ b/jsdump.c
@@ -34,10 +34,10 @@
static int prec(js_AstType type)
{
switch (type) {
- case AST_IDENTIFIER:
- case AST_NUMBER:
- case AST_STRING:
- case AST_REGEXP:
+ case EXP_IDENTIFIER:
+ case EXP_NUMBER:
+ case EXP_STRING:
+ case EXP_REGEXP:
case EXP_UNDEF:
case EXP_NULL:
case EXP_TRUE:
@@ -284,10 +284,10 @@
p = tp;
switch (exp->type) {
- case AST_IDENTIFIER: ps(exp->string); break;
- case AST_NUMBER: printf("%.9g", exp->number); break;
- case AST_STRING: pstr(exp->string); break;
- case AST_REGEXP: pregexp(exp->string, exp->number); break;
+ case EXP_IDENTIFIER: ps(exp->string); break;
+ case EXP_NUMBER: printf("%.9g", exp->number); break;
+ case EXP_STRING: pstr(exp->string); break;
+ case EXP_REGEXP: pregexp(exp->string, exp->number); break;
case EXP_UNDEF: break;
case EXP_NULL: ps("null"); break;
@@ -651,9 +651,10 @@
ps(astname[node->type]);
switch (node->type) {
case AST_IDENTIFIER: pc(' '); ps(node->string); break;
- case AST_STRING: pc(' '); pstr(node->string); break;
- case AST_REGEXP: pc(' '); pregexp(node->string, node->number); break;
- case AST_NUMBER: printf(" %.9g", node->number); break;
+ case EXP_IDENTIFIER: pc(' '); ps(node->string); break;
+ case EXP_STRING: pc(' '); pstr(node->string); break;
+ case EXP_REGEXP: pc(' '); pregexp(node->string, node->number); break;
+ case EXP_NUMBER: printf(" %.9g", node->number); break;
case STM_BLOCK: afun = sblock; break;
case AST_FUNDEC: case EXP_FUN: cfun = sblock; break;
case EXP_PROP_GET: cfun = sblock; break;
--- a/jsparse.c
+++ b/jsparse.c
@@ -236,10 +236,10 @@
{
js_Ast *name;
if (J->lookahead == TK_NUMBER) {
- name = jsP_newnumnode(J, AST_NUMBER, J->number);
+ name = jsP_newnumnode(J, EXP_NUMBER, J->number);
next(J);
} else if (J->lookahead == TK_STRING) {
- name = jsP_newstrnode(J, AST_STRING, J->text);
+ name = jsP_newstrnode(J, EXP_STRING, J->text);
next(J);
} else {
name = identifiername(J);
@@ -346,23 +346,23 @@
if (J->lookahead == TK_IDENTIFIER) {
checkfutureword(J, J->text);
- a = jsP_newstrnode(J, AST_IDENTIFIER, J->text);
+ a = jsP_newstrnode(J, EXP_IDENTIFIER, J->text);
next(J);
return a;
}
if (J->lookahead == TK_STRING) {
- a = jsP_newstrnode(J, AST_STRING, J->text);
+ a = jsP_newstrnode(J, EXP_STRING, J->text);
next(J);
return a;
}
if (J->lookahead == TK_REGEXP) {
- a = jsP_newstrnode(J, AST_REGEXP, J->text);
+ a = jsP_newstrnode(J, EXP_REGEXP, J->text);
a->number = J->number;
next(J);
return a;
}
if (J->lookahead == TK_NUMBER) {
- a = jsP_newnumnode(J, AST_NUMBER, J->number);
+ a = jsP_newnumnode(J, EXP_NUMBER, J->number);
next(J);
return a;
}
@@ -834,7 +834,8 @@
/* labelled statement or expression statement */
if (J->lookahead == TK_IDENTIFIER) {
a = expression(J, 0);
- if (a->type == AST_IDENTIFIER && accept(J, ':')) {
+ if (a->type == EXP_IDENTIFIER && accept(J, ':')) {
+ a->type = AST_IDENTIFIER;
b = statement(J);
return STM2(LABEL, a, b);
}
@@ -905,7 +906,7 @@
static int jsP_setnumnode(js_Ast *node, double x)
{
- node->type = AST_NUMBER;
+ node->type = EXP_NUMBER;
node->number = x;
node->a = node->b = node->c = node->d = NULL;
return 1;
@@ -916,7 +917,7 @@
double x, y;
int a, b;
- if (node->type == AST_NUMBER)
+ if (node->type == EXP_NUMBER)
return 1;
a = node->a ? jsP_foldconst(node->a) : 0;
--- a/jsparse.h
+++ b/jsparse.h
@@ -7,11 +7,12 @@
{
AST_LIST,
AST_FUNDEC,
-
AST_IDENTIFIER,
- AST_NUMBER,
- AST_STRING,
- AST_REGEXP,
+
+ EXP_IDENTIFIER,
+ EXP_NUMBER,
+ EXP_STRING,
+ EXP_REGEXP,
/* literals */
EXP_UNDEF, /* for array elisions */