diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/simple.cpp b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/simple.cpp new file mode 100644 index 00000000000..a166e436f19 --- /dev/null +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/simple.cpp @@ -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; +} diff --git a/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/simple.cpp.expectation b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/simple.cpp.expectation new file mode 100644 index 00000000000..517370400da --- /dev/null +++ b/Meta/Lagom/Tools/CodeGenerators/JSSpecCompiler/Tests/simple.cpp.expectation @@ -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 + diff --git a/Meta/check-style.py b/Meta/check-style.py index ff3a9f88a5d..1e1b6904f45 100755 --- a/Meta/check-style.py +++ b/Meta/check-style.py @@ -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/', diff --git a/Tests/JSSpecCompiler/test-runner.cpp b/Tests/JSSpecCompiler/test-runner.cpp index 6eb6c50b589..1c193e3e322 100644 --- a/Tests/JSSpecCompiler/test-runner.cpp +++ b/Tests/JSSpecCompiler/test-runner.cpp @@ -29,7 +29,17 @@ constexpr StringView stderr_capture_filename = "stderr"sv; constexpr StringView compiler_binary_name = "JSSpecCompiler"sv; constexpr StringView relative_path_to_test = "Tests"sv; -Array const regression_tests = {}; +constexpr TestDescription::Flag always_dump_ast = { + .name = "all"sv, + .dump_ast = true, +}; + +const Array regression_tests = { + TestDescription { + .sources = { "simple.cpp"sv }, + .flags = { always_dump_ast }, + }, +}; static const LexicalPath path_to_compiler_binary = [] { auto path_to_self = LexicalPath(MUST(Core::System::current_executable_path())).parent();