forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1407ca
commit 7ba9478
Showing
25 changed files
with
425 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
set(TEST_SOURCES | ||
test-parser.cpp | ||
) | ||
|
||
foreach(source IN LISTS TEST_SOURCES) | ||
serenity_test("${source}" LibGLSL LIBS LibGLSL) | ||
endforeach() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (c) 2021, Itamar S. <itamar8910@gmail.com> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#include <AK/LexicalPath.h> | ||
#include <AK/MemoryStream.h> | ||
#include <LibCore/Directory.h> | ||
#include <LibCore/File.h> | ||
#include <LibGLSL/Parser.h> | ||
#include <LibTest/TestCase.h> | ||
|
||
constexpr StringView TESTS_ROOT_DIR = "/home/anon/Tests/glsl-tests/parser"sv; | ||
|
||
static String read_all(String const& path) | ||
{ | ||
auto file = MUST(Core::File::open(path, Core::File::OpenMode::Read)); | ||
auto file_size = MUST(file->size()); | ||
return MUST(String::from_stream(*file, file_size)); | ||
} | ||
|
||
TEST_CASE(test_regression) | ||
{ | ||
MUST(Core::Directory::for_each_entry(TESTS_ROOT_DIR, Core::DirIterator::Flags::SkipDots, [](auto const& entry, auto const& directory) -> ErrorOr<IterationDecision> { | ||
auto path = LexicalPath::join(directory.path().string(), entry.name); | ||
if (!path.has_extension(".glsl"sv)) | ||
return IterationDecision::Continue; | ||
|
||
outln("Checking {}...", path.basename()); | ||
String file_path = MUST(String::from_deprecated_string(path.string())); | ||
|
||
auto ast_file_path = MUST(String::formatted("{}.ast", MUST(file_path.substring_from_byte_offset(0, file_path.bytes_as_string_view().length() - sizeof(".glsl") + 1)))); | ||
|
||
auto source = read_all(file_path); | ||
auto target_ast = read_all(ast_file_path); | ||
|
||
GLSL::Preprocessor preprocessor(file_path, source); | ||
GLSL::Parser parser(MUST(preprocessor.process_and_lex()), file_path); | ||
auto root = MUST(parser.parse()); | ||
|
||
EXPECT(parser.errors().is_empty()); | ||
|
||
Vector<uint8_t> memory; | ||
memory.resize(8 * 1024 * 1024); | ||
AK::FixedMemoryStream output_stream(memory.span()); | ||
|
||
MUST(root->dump(output_stream)); | ||
|
||
auto written_bytes = MUST(output_stream.tell()); | ||
MUST(output_stream.seek(0)); | ||
|
||
String content = MUST(String::from_stream(output_stream, written_bytes)); | ||
|
||
auto equal = content == target_ast; | ||
EXPECT(equal); | ||
if (!equal) | ||
outln("Failed on {}", path.basename()); | ||
return IterationDecision::Continue; | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
TranslationUnit[0:0->3:0] | ||
FunctionDeclaration[0:0->3:0] | ||
Type[0:0->0:3] | ||
void | ||
foo | ||
( | ||
) | ||
FunctionDefinition[1:0->3:0] | ||
{ | ||
DiscardStatement[2:4->2:11] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
void foo() | ||
{ | ||
discard; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
TranslationUnit[0:0->3:0] | ||
FunctionDeclaration[0:0->3:0] | ||
Type[0:0->0:3] | ||
void | ||
foo | ||
( | ||
) | ||
FunctionDefinition[1:0->3:0] | ||
{ | ||
VariableDeclaration[2:4->2:66] | ||
Type[2:4->2:6] | ||
int | ||
a | ||
BinaryExpression[2:12->2:66] | ||
BinaryExpression[2:12->2:57] | ||
BinaryExpression[2:12->2:48] | ||
BinaryExpression[2:12->2:36] | ||
BinaryExpression[2:12->2:22] | ||
NumericLiteral[2:12->2:12] | ||
1 | ||
+ | ||
BinaryExpression[2:16->2:22] | ||
NumericLiteral[2:16->2:16] | ||
2 | ||
* | ||
NumericLiteral[2:20->2:20] | ||
3 | ||
+ | ||
BinaryExpression[2:24->2:36] | ||
BinaryExpression[2:25->2:30] | ||
NumericLiteral[2:25->2:25] | ||
4 | ||
- | ||
NumericLiteral[2:29->2:29] | ||
2 | ||
/ | ||
NumericLiteral[2:34->2:34] | ||
2 | ||
+ | ||
FunctionCall[2:38->2:48] | ||
Name[2:38->2:40] | ||
max | ||
( | ||
NumericLiteral[2:42->2:42] | ||
7 | ||
NumericLiteral[2:45->2:45] | ||
8 | ||
) | ||
- | ||
MemberExpression[2:50->2:57] | ||
Name[2:50->2:52] | ||
bar | ||
Name[2:54->2:55] | ||
xy | ||
+ | ||
ArrayElementExpression[2:59->2:66] | ||
Name[2:59->2:61] | ||
abc | ||
[ | ||
NumericLiteral[2:63->2:64] | ||
13 | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
TranslationUnit[0:0->3:0] | ||
FunctionDeclaration[0:0->3:0] | ||
Type[0:0->0:3] | ||
void | ||
foo | ||
( | ||
) | ||
FunctionDefinition[1:0->3:0] | ||
{ | ||
VariableDeclaration[2:4->2:66] | ||
Type[2:4->2:6] | ||
int | ||
a | ||
BinaryExpression[2:12->2:66] | ||
BinaryExpression[2:12->2:57] | ||
BinaryExpression[2:12->2:48] | ||
BinaryExpression[2:12->2:36] | ||
BinaryExpression[2:12->2:22] | ||
NumericLiteral[2:12->2:12] | ||
1 | ||
+ | ||
BinaryExpression[2:16->2:22] | ||
NumericLiteral[2:16->2:16] | ||
2 | ||
* | ||
NumericLiteral[2:20->2:20] | ||
3 | ||
+ | ||
BinaryExpression[2:24->2:36] | ||
BinaryExpression[2:25->2:30] | ||
NumericLiteral[2:25->2:25] | ||
4 | ||
- | ||
NumericLiteral[2:29->2:29] | ||
2 | ||
/ | ||
NumericLiteral[2:34->2:34] | ||
2 | ||
+ | ||
FunctionCall[2:38->2:48] | ||
Name[2:38->2:40] | ||
max | ||
( | ||
NumericLiteral[2:42->2:42] | ||
7 | ||
NumericLiteral[2:45->2:45] | ||
8 | ||
) | ||
- | ||
MemberExpression[2:50->2:57] | ||
Name[2:50->2:52] | ||
bar | ||
Name[2:54->2:55] | ||
xy | ||
+ | ||
ArrayElementExpression[2:59->2:66] | ||
Name[2:59->2:61] | ||
abc | ||
[ | ||
NumericLiteral[2:63->2:64] | ||
13 | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
void foo() | ||
{ | ||
int a = 1 + 2 * 3 + (4 - 2) / 2 + max(7, 8) - bar.xy + abc[13]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
TranslationUnit[0:0->5:0] | ||
FunctionDeclaration[0:0->5:0] | ||
Type[0:0->0:3] | ||
void | ||
main | ||
( | ||
) | ||
FunctionDefinition[1:0->5:0] | ||
{ | ||
VariableDeclaration[2:4->2:13] | ||
Type[2:4->2:6] | ||
int | ||
b | ||
NumericLiteral[2:12->2:12] | ||
0 | ||
ForStatement[3:4->4:11] | ||
Initializer: | ||
VariableDeclaration[3:9->3:18] | ||
Type[3:9->3:11] | ||
int | ||
a | ||
NumericLiteral[3:17->3:17] | ||
0 | ||
Test expression: | ||
BooleanLiteral[3:20->3:23] | ||
true | ||
Update expression: | ||
UnaryExpression[3:26->3:29] | ||
postfix ++ | ||
Name[3:26->3:26] | ||
a | ||
Body: | ||
UnaryExpression[4:8->4:11] | ||
postfix ++ | ||
Name[4:8->4:8] | ||
b | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
void main() | ||
{ | ||
int b = 0; | ||
for (int a = 0; true; a++) | ||
b++; | ||
} | ||
|
15 changes: 15 additions & 0 deletions
15
Userland/Libraries/LibGLSL/Tests/parser/function-declaration.ast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
TranslationUnit[0:0->0:24] | ||
FunctionDeclaration[0:0->0:24] | ||
Type[0:0->0:2] | ||
int | ||
main | ||
( | ||
Parameter[0:9->0:13] | ||
a | ||
Type[0:9->0:11] | ||
int | ||
Parameter[0:16->0:22] | ||
b | ||
Type[0:16->0:20] | ||
float | ||
) |
2 changes: 2 additions & 0 deletions
2
Userland/Libraries/LibGLSL/Tests/parser/function-declaration.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
int main(int a, float b); | ||
|
13 changes: 13 additions & 0 deletions
13
Userland/Libraries/LibGLSL/Tests/parser/function-definition.ast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
TranslationUnit[0:0->3:0] | ||
FunctionDeclaration[0:0->3:0] | ||
Type[0:0->0:2] | ||
int | ||
main | ||
( | ||
) | ||
FunctionDefinition[1:0->3:0] | ||
{ | ||
ReturnStatement[2:1->2:9] | ||
NumericLiteral[2:8->2:8] | ||
1 | ||
} |
5 changes: 5 additions & 0 deletions
5
Userland/Libraries/LibGLSL/Tests/parser/function-definition.glsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
int main() | ||
{ | ||
return 1; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
TranslationUnit[0:0->6:0] | ||
FunctionDeclaration[0:0->6:0] | ||
Type[0:0->0:3] | ||
bool | ||
foo | ||
( | ||
) | ||
FunctionDefinition[1:0->6:0] | ||
{ | ||
IfStatement[2:4->5:20] | ||
Predicate: | ||
BinaryExpression[2:8->2:14] | ||
NumericLiteral[2:8->2:8] | ||
1 | ||
== | ||
NumericLiteral[2:13->2:13] | ||
2 | ||
Then: | ||
ReturnStatement[3:8->3:19] | ||
BooleanLiteral[3:15->3:18] | ||
true | ||
Else: | ||
ReturnStatement[5:8->5:20] | ||
BooleanLiteral[5:15->5:19] | ||
false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
bool foo() | ||
{ | ||
if (1 == 2) | ||
return true; | ||
else | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
TranslationUnit[0:0->8:0] | ||
FunctionDeclaration[0:0->3:0] | ||
Type[0:0->0:3] | ||
void | ||
foo | ||
( | ||
) | ||
FunctionDefinition[1:0->3:0] | ||
{ | ||
ReturnStatement[2:4->2:10] | ||
} | ||
FunctionDeclaration[5:0->8:0] | ||
Type[5:0->5:2] | ||
int | ||
bar | ||
( | ||
) | ||
FunctionDefinition[6:0->8:0] | ||
{ | ||
ReturnStatement[7:4->7:12] | ||
NumericLiteral[7:11->7:11] | ||
3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
void foo() | ||
{ | ||
return; | ||
} | ||
|
||
int bar() | ||
{ | ||
return 3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
TranslationUnit[0:0->3:1] | ||
StructDeclaration[0:7->3:1] | ||
foo | ||
VariableDeclaration[2:4->3:0] | ||
Type[2:4->2:6] | ||
int | ||
bar |
Oops, something went wrong.