Separate generic AST_IDENTIFIER and EXP_IDENTIFIER.

Use EXP_IDENTIFIER for the primary expression, and AST_IDENTIFIER for
non-expression uses.
This commit is contained in:
Tor Andersson
2014-02-10 15:44:40 +01:00
parent ab5236f243
commit e39e0bdcd1
4 changed files with 40 additions and 37 deletions
+13 -13
View File
@@ -194,10 +194,10 @@ static void cobject(JF, js_Ast *list)
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 @@ static void cobject(JF, js_Ast *list)
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 int cargs(JF, js_Ast *list)
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 @@ static void cassignforin(JF, js_Ast *stm)
}
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 cassignforin(JF, js_Ast *stm)
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 cassignop1(JF, js_Ast *lhs, int dup)
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 cassignop(JF, js_Ast *lhs, js_Ast *rhs, int opcode)
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,15 +401,15 @@ static void cexp(JF, js_Ast *exp)
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;
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 @@ static void cexp(JF, js_Ast *exp)
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;
+12 -11
View File
@@ -34,10 +34,10 @@ const char *jsC_opcodestring(int opcode)
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 @@ static void pexpi(int d, int p, js_Ast *exp)
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 @@ static void snode(int d, js_Ast *node)
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;
+10 -9
View File
@@ -236,10 +236,10 @@ static js_Ast *propname(js_State *J)
{
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 @@ static js_Ast *primary(js_State *J)
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 @@ static js_Ast *statement(js_State *J)
/* 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 inline unsigned int touint32(double d)
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 @@ static int jsP_foldconst(js_Ast *node)
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;
+5 -4
View File
@@ -7,11 +7,12 @@ enum js_AstType
{
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 */