shithub: libmujs

Download patch

ref: ca3c7e43416b28d3b58a455e0a4068fa845fdfba
parent: 591ea21f8fd3940ed69c8b1cb4513c831a15176c
author: Tor Andersson <tor@ccxvii.net>
date: Thu Feb 6 08:39:13 EST 2014

Auto-generate the AST name list.

--- a/Makefile
+++ b/Makefile
@@ -15,10 +15,13 @@
 build/libjs.a: $(OBJS)
 	ar cru $@ $^
 
+astnames.h : jsparse.h
+	grep '\(AST\|EXP\|STM\)_' jsparse.h | sed 's/^[ \t]*\(AST_\)\?/"/;s/,.*/",/' | tr A-Z a-z > $@
+
 opnames.h : jscompile.h
-	grep 'OP_' jscompile.h | sed 's/OP_/"/;s/,.*/",/' | tr A-Z a-z > opnames.h
+	grep 'OP_' jscompile.h | sed 's/^[ \t]*OP_/"/;s/,.*/",/' | tr A-Z a-z > $@
 
-jsdump.c : opnames.h
+jsdump.c : astnames.h opnames.h
 
 js: build/main.o build/libjs.a
 	$(CC) -o $@ $^ -lm
@@ -30,6 +33,6 @@
 	python tests/sputniktests/tools/sputnik.py --tests=tests/sputniktests --command ./js --summary
 
 clean:
-	rm -f opnames.h build/* js
+	rm -f astnames.h opnames.h build/* js
 
 .PHONY: default test clean
--- a/jsdump.c
+++ b/jsdump.c
@@ -8,19 +8,7 @@
 #define nelem(a) (sizeof (a) / sizeof (a)[0])
 
 static const char *astname[] = {
-	"list", "fundec", "ident", "number", "string", "regexp", "undef",
-	"null", "true", "false", "this", "fun", "array", "object", "prop_val",
-	"prop_get", "prop_set", "index", "member", "call", "new", "delete",
-	"void", "typeof", "preinc", "predec", "postinc", "postdec", "pos",
-	"neg", "bitnot", "lognot", "logor", "logand", "bitor", "bitxor",
-	"bitand", "eq", "ne", "eq3", "ne3", "lt", "gt", "le", "ge",
-	"instanceof", "in", "shl", "shr", "ushr", "add", "sub", "mul", "div",
-	"mod", "cond", "ass", "ass_mul", "ass_div", "ass_mod", "ass_add",
-	"ass_sub", "ass_shl", "ass_shr", "ass_ushr", "ass_bitand",
-	"ass_bitxor", "ass_bitor", "comma", "varexp", "block", "nop", "var",
-	"if", "do_while", "while", "for", "for_var", "for_in", "for_in_var",
-	"continue", "break", "return", "with", "switch", "throw", "try",
-	"debugger", "label", "case", "default",
+#include "astnames.h"
 };
 
 static const char *opname[] = {