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

JSSpecCompiler: Add our first test :^)

This commit is contained in:
Dan Klishch 2023-09-30 12:13:13 -04:00 committed by Andrew Kaster
parent 107a3b44fa
commit 00928764e9
4 changed files with 138 additions and 1 deletions

View file

@ -0,0 +1,18 @@
auto f(auto cond1, auto cond2)
{
int a;
int b;
if (cond1) {
a = 1;
if (cond2) {
b = a;
} else {
b = 3;
}
} else {
b = 4;
}
return b;
}

View file

@ -0,0 +1,108 @@
===== AST after parser =====
f():
TreeList
IfBranch
UnresolvedReference cond1
TreeList
BinaryOperation Declaration
UnresolvedReference a
MathematicalConstant 1
IfBranch
UnresolvedReference cond2
TreeList
BinaryOperation Declaration
UnresolvedReference b
UnresolvedReference a
ElseIfBranch Else
TreeList
BinaryOperation Declaration
UnresolvedReference b
MathematicalConstant 3
ElseIfBranch Else
TreeList
BinaryOperation Declaration
UnresolvedReference b
MathematicalConstant 4
ReturnNode
UnresolvedReference b
===== AST after function-call-canonicalization =====
f():
TreeList
IfBranch
UnresolvedReference cond1
TreeList
BinaryOperation Declaration
UnresolvedReference a
MathematicalConstant 1
IfBranch
UnresolvedReference cond2
TreeList
BinaryOperation Declaration
UnresolvedReference b
UnresolvedReference a
ElseIfBranch Else
TreeList
BinaryOperation Declaration
UnresolvedReference b
MathematicalConstant 3
ElseIfBranch Else
TreeList
BinaryOperation Declaration
UnresolvedReference b
MathematicalConstant 4
ReturnNode
UnresolvedReference b
===== AST after if-branch-merging =====
f():
TreeList
IfElseIfChain
UnresolvedReference cond1
TreeList
BinaryOperation Declaration
UnresolvedReference a
MathematicalConstant 1
IfElseIfChain
UnresolvedReference cond2
TreeList
BinaryOperation Declaration
UnresolvedReference b
UnresolvedReference a
TreeList
BinaryOperation Declaration
UnresolvedReference b
MathematicalConstant 3
TreeList
BinaryOperation Declaration
UnresolvedReference b
MathematicalConstant 4
ReturnNode
UnresolvedReference b
===== AST after reference-resolving =====
f():
TreeList
IfElseIfChain
UnresolvedReference cond1
TreeList
BinaryOperation Declaration
Var a
MathematicalConstant 1
IfElseIfChain
UnresolvedReference cond2
TreeList
BinaryOperation Declaration
Var b
Var a
TreeList
BinaryOperation Declaration
Var b
MathematicalConstant 3
TreeList
BinaryOperation Declaration
Var b
MathematicalConstant 4
ReturnNode
Var b

View file

@ -23,6 +23,7 @@ GOOD_LICENSE_HEADER_PATTERN = re.compile(
LICENSE_HEADER_CHECK_EXCLUDES = {
'AK/Checked.h',
'AK/Function.h',
'Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/',
'Userland/Libraries/LibJS/SafeFunction.h',
'Userland/Libraries/LibELF/ELFABI.h',
'Userland/Libraries/LibCodeComprehension/Cpp/Tests/',