1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:47:45 +00:00

js: Make it a little easier to add new AST builder functions

This commit is contained in:
Andreas Kling 2020-03-09 21:58:27 +01:00
parent 0d6be2cac2
commit 70a3e738f5

View file

@ -31,14 +31,14 @@
#include <LibJS/Value.h> #include <LibJS/Value.h>
#include <stdio.h> #include <stdio.h>
//static void build_program_1(JS::Program&); #define PROGRAM 2
//static void build_program_2(JS::Program&);
static void build_program_3(JS::Program&); static void build_program(JS::Program&);
int main() int main()
{ {
auto program = make<JS::Program>(); auto program = make<JS::Program>();
build_program_3(*program); build_program(*program);
program->dump(0); program->dump(0);
@ -53,8 +53,8 @@ int main()
return 0; return 0;
} }
#if 0 #if PROGRAM == 1
void build_program_1(JS::Program& program) void build_program(JS::Program& program)
{ {
// function foo() { return (1 + 2) + 3; } // function foo() { return (1 + 2) + 3; }
// foo(); // foo();
@ -72,10 +72,8 @@ void build_program_1(JS::Program& program)
program.append<JS::FunctionDeclaration>("foo", move(block)); program.append<JS::FunctionDeclaration>("foo", move(block));
program.append<JS::CallExpression>("foo"); program.append<JS::CallExpression>("foo");
} }
#endif #elif PROGRAM == 2
void build_program(JS::Program& program)
#if 0
void build_program_2(JS::Program& program)
{ {
// c = 1; // c = 1;
// function foo() { // function foo() {
@ -109,9 +107,8 @@ void build_program_2(JS::Program& program)
program.append<JS::FunctionDeclaration>("foo", move(block)); program.append<JS::FunctionDeclaration>("foo", move(block));
program.append<JS::CallExpression>("foo"); program.append<JS::CallExpression>("foo");
} }
#endif #elif PROGRAM == 3
void build_program(JS::Program& program)
void build_program_3(JS::Program& program)
{ {
// function foo() { // function foo() {
// var x = {}; // var x = {};
@ -128,3 +125,4 @@ void build_program_3(JS::Program& program)
program.append<JS::FunctionDeclaration>("foo", move(block)); program.append<JS::FunctionDeclaration>("foo", move(block));
program.append<JS::CallExpression>("foo"); program.append<JS::CallExpression>("foo");
} }
#endif