diff --git a/WORKLOG.md b/WORKLOG.md index 18334d2..6f7068f 100644 --- a/WORKLOG.md +++ b/WORKLOG.md @@ -1,9 +1,11 @@ # Compiler Construction PA3 Worklog + ## Team: **Apoorva Ranade**(ar6496)   **Sanjar Ahmadov**(sa5640)   **Yinqi Sun**(ys3540)
+ ## Challenges: - Nested structures were a challenge. A function inside a function/class needs us to build correct scoping as well as dealing with dependencies. - This is dealt by the class:StackVarRuntimeInfo and function:getStackVar. diff --git a/full_test.sh b/full_test.sh new file mode 100755 index 0000000..bd0d27e --- /dev/null +++ b/full_test.sh @@ -0,0 +1,4 @@ +#!/bin/bash +./build.sh +./test_sample.sh +./test_benchmarks.sh diff --git a/grade.md b/grade.md new file mode 100644 index 0000000..ba656ff --- /dev/null +++ b/grade.md @@ -0,0 +1,32 @@ +## Grading + +Core Tests: 59/59 + +Extra: 21/21 + +========================= + +Standard tests: 80/80 + +Work Log: 10/10 + +Additional Tests: 10/10 + +Code style: 10/10 + +Improvements: +1 + +Overall: 111/110 + +Congratulations! Your analyzer has solved every test case correctly again. Your improvement is solid and easy to verify. The two-passes design is clear and direct. + +## Testing + +The additional test cases provided in the `student_contributed` directory are carefully selected and well structured. I am surprised that you managed to reproduce those error messages from reference-implementation. Some of them are weird and probably not worth reproducing, but thanks for reducing the workload on my end. + +## Miscellaneous +The Code structure is clear and consistent but could still be improved by removing commented codes (at least in the final version). + +The automatic test shell scripts are very helpful. It would be even better if you could organize them with CI tools like travis.ci or gitflow. It is totally optional but it would be fun to construct a CI pipeline. + +The worklog contains some typos that could be avoided by adding a spellchecker to the IDE or CI. diff --git a/pa1-tests/README.md b/pa1-tests/README.md new file mode 100644 index 0000000..b1395dd --- /dev/null +++ b/pa1-tests/README.md @@ -0,0 +1,24 @@ +# Tests for PA1: ChocoPy Parser + +Clone a student repository: +``` +TEAM="team" +git clone --branch=pa1final \ + https://github.com/nyu-compiler-construction/pa1-chocopy-parser-${TEAM} +``` + +Build it: +``` +cd pa1-chocopy-parser-${TEAM} +mvn clean package +``` + +Clone the tests _into_ the student repository: +``` +git clone https://github.com/nyu-compiler-construction/pa1-tests +``` + +Run the tests: +``` +./pa1-tests/run-tests.sh +``` \ No newline at end of file diff --git a/pa1-tests/chocopy-ref.jar b/pa1-tests/chocopy-ref.jar new file mode 100644 index 0000000..31646a6 Binary files /dev/null and b/pa1-tests/chocopy-ref.jar differ diff --git a/pa1-tests/core/bad_assign_expr1.py b/pa1-tests/core/bad_assign_expr1.py new file mode 100644 index 0000000..ccc8c3e --- /dev/null +++ b/pa1-tests/core/bad_assign_expr1.py @@ -0,0 +1 @@ +x = (y = 2) diff --git a/pa1-tests/core/bad_assign_expr1.py.ast b/pa1-tests/core/bad_assign_expr1.py.ast new file mode 100644 index 0000000..d134770 --- /dev/null +++ b/pa1-tests/core/bad_assign_expr1.py.ast @@ -0,0 +1,16 @@ +{ + "kind" : "Program", + "location" : [ 1, 6, 1, 6 ], + "declarations" : [ ], + "statements" : [ ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 8, 1, 8 ], + "message" : "Parse error near token EQ: =", + "syntax" : true + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/bad_assign_expr2.py b/pa1-tests/core/bad_assign_expr2.py new file mode 100644 index 0000000..444bc53 --- /dev/null +++ b/pa1-tests/core/bad_assign_expr2.py @@ -0,0 +1 @@ +print(x = 1) diff --git a/pa1-tests/core/bad_assign_expr2.py.ast b/pa1-tests/core/bad_assign_expr2.py.ast new file mode 100644 index 0000000..53e699c --- /dev/null +++ b/pa1-tests/core/bad_assign_expr2.py.ast @@ -0,0 +1,16 @@ +{ + "kind" : "Program", + "location" : [ 1, 7, 1, 7 ], + "declarations" : [ ], + "statements" : [ ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 9, 1, 9 ], + "message" : "Parse error near token EQ: =", + "syntax" : true + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/bad_func_def.py b/pa1-tests/core/bad_func_def.py new file mode 100644 index 0000000..ebd2373 --- /dev/null +++ b/pa1-tests/core/bad_func_def.py @@ -0,0 +1,6 @@ +def foo(a, b) -> 1: + x:int = a + return 1 + +print(1) +print(3**6) diff --git a/pa1-tests/core/bad_func_def.py.ast b/pa1-tests/core/bad_func_def.py.ast new file mode 100644 index 0000000..934bef0 --- /dev/null +++ b/pa1-tests/core/bad_func_def.py.ast @@ -0,0 +1,64 @@ +{ + "kind" : "Program", + "location" : [ 2, 13, 6, 8 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 2, 13, 2, 13 ], + "expr" : { + "kind" : "Identifier", + "location" : [ 2, 13, 2, 13 ], + "name" : "a" + } + }, { + "kind" : "ReturnStmt", + "location" : [ 3, 5, 3, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 12, 3, 12 ], + "value" : 1 + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 8 ], + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 5, 7, 5, 7 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 10, 1, 10 ], + "message" : "Parse error near token COMMA: ,", + "syntax" : true + }, { + "kind" : "CompilerError", + "location" : [ 2, 13, 2, 13 ], + "message" : "Parse error near token IDENTIFIER: a", + "syntax" : true + }, { + "kind" : "CompilerError", + "location" : [ 5, 1, 5, 0 ], + "message" : "Parse error near token DEDENT: ", + "syntax" : true + }, { + "kind" : "CompilerError", + "location" : [ 6, 9, 6, 9 ], + "message" : "Parse error near token TIMES: *", + "syntax" : true + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/bad_indentation.py b/pa1-tests/core/bad_indentation.py new file mode 100644 index 0000000..670b7ab --- /dev/null +++ b/pa1-tests/core/bad_indentation.py @@ -0,0 +1,3 @@ +x = 1 + y = 2 +z = 3 diff --git a/pa1-tests/core/bad_indentation.py.ast b/pa1-tests/core/bad_indentation.py.ast new file mode 100644 index 0000000..f37b92e --- /dev/null +++ b/pa1-tests/core/bad_indentation.py.ast @@ -0,0 +1,47 @@ +{ + "kind" : "Program", + "location" : [ 2, 3, 3, 6 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 2, 3, 2, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 2, 3, 2, 3 ], + "name" : "y" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 7, 2, 7 ], + "value" : 2 + } + }, { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 5, 3, 5 ], + "value" : 3 + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 2, 1, 2, 2 ], + "message" : "Parse error near token INDENT: ", + "syntax" : true + }, { + "kind" : "CompilerError", + "location" : [ 3, 1, 3, 0 ], + "message" : "Parse error near token DEDENT: ", + "syntax" : true + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/bad_stmt.py b/pa1-tests/core/bad_stmt.py new file mode 100644 index 0000000..8e8a4da --- /dev/null +++ b/pa1-tests/core/bad_stmt.py @@ -0,0 +1,4 @@ +1 + 2 +3 == 4 or (not False && True) +5 + 6 +7 << 8 diff --git a/pa1-tests/core/bad_stmt.py.ast b/pa1-tests/core/bad_stmt.py.ast new file mode 100644 index 0000000..afe9602 --- /dev/null +++ b/pa1-tests/core/bad_stmt.py.ast @@ -0,0 +1,65 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 7 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 5 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "value" : 2 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 5 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 1, 3, 1 ], + "value" : 5 + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 5, 3, 5 ], + "value" : 6 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 6, 4, 6 ], + "expr" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 6, 4, 6 ], + "value" : 8 + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 2, 22, 2, 22 ], + "message" : "Parse error near token UNRECOGNIZED: &", + "syntax" : true + }, { + "kind" : "CompilerError", + "location" : [ 4, 4, 4, 4 ], + "message" : "Parse error near token LT: <", + "syntax" : true + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/chained_mixed_assignments.py b/pa1-tests/core/chained_mixed_assignments.py new file mode 100644 index 0000000..46a230a --- /dev/null +++ b/pa1-tests/core/chained_mixed_assignments.py @@ -0,0 +1,2 @@ +x[0] = y = z.f = 1 +z.g = y = x[0] diff --git a/pa1-tests/core/chained_mixed_assignments.py.ast b/pa1-tests/core/chained_mixed_assignments.py.ast new file mode 100644 index 0000000..9654bf6 --- /dev/null +++ b/pa1-tests/core/chained_mixed_assignments.py.ast @@ -0,0 +1,85 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 2, 15 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 1, 1, 1, 18 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 1, 1, 1, 4 ], + "list" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 3, 1, 3 ], + "value" : 0 + } + }, { + "kind" : "Identifier", + "location" : [ 1, 8, 1, 8 ], + "name" : "y" + }, { + "kind" : "MemberExpr", + "location" : [ 1, 12, 1, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 1, 12, 1, 12 ], + "name" : "z" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 1, 14, 1, 14 ], + "name" : "f" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 18, 1, 18 ], + "value" : 1 + } + }, { + "kind" : "AssignStmt", + "location" : [ 2, 1, 2, 14 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 2, 1, 2, 3 ], + "object" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "z" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 2, 3, 2, 3 ], + "name" : "g" + } + }, { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 7 ], + "name" : "y" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 2, 11, 2, 14 ], + "list" : { + "kind" : "Identifier", + "location" : [ 2, 11, 2, 11 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 0 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/chained_var_assignments.py b/pa1-tests/core/chained_var_assignments.py new file mode 100644 index 0000000..b253c2a --- /dev/null +++ b/pa1-tests/core/chained_var_assignments.py @@ -0,0 +1 @@ +x = y = z = 1 diff --git a/pa1-tests/core/chained_var_assignments.py.ast b/pa1-tests/core/chained_var_assignments.py.ast new file mode 100644 index 0000000..28f0ea7 --- /dev/null +++ b/pa1-tests/core/chained_var_assignments.py.ast @@ -0,0 +1,32 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 14 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 1, 1, 1, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 5 ], + "name" : "y" + }, { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 13, 1, 13 ], + "value" : 1 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/class_attr.py b/pa1-tests/core/class_attr.py new file mode 100644 index 0000000..bb1e1cd --- /dev/null +++ b/pa1-tests/core/class_attr.py @@ -0,0 +1,4 @@ +class Foo(object): + x:int = 1 + +f = Foo() diff --git a/pa1-tests/core/class_attr.py.ast b/pa1-tests/core/class_attr.py.ast new file mode 100644 index 0000000..4fdab40 --- /dev/null +++ b/pa1-tests/core/class_attr.py.ast @@ -0,0 +1,65 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 10 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 9 ], + "name" : "Foo" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 11, 1, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "f" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 4, 5, 4, 9 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "Foo" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/class_attr_get.py b/pa1-tests/core/class_attr_get.py new file mode 100644 index 0000000..b4e6365 --- /dev/null +++ b/pa1-tests/core/class_attr_get.py @@ -0,0 +1,5 @@ +class Foo(object): + x:int = 1 + +f = Foo() +print(f.x) diff --git a/pa1-tests/core/class_attr_get.py.ast b/pa1-tests/core/class_attr_get.py.ast new file mode 100644 index 0000000..f286342 --- /dev/null +++ b/pa1-tests/core/class_attr_get.py.ast @@ -0,0 +1,91 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 9 ], + "name" : "Foo" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 11, 1, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "f" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 4, 5, 4, 9 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "Foo" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 10 ], + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 5, 7, 5, 9 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 7, 5, 7 ], + "name" : "f" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 9 ], + "name" : "x" + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/class_attr_set.py b/pa1-tests/core/class_attr_set.py new file mode 100644 index 0000000..ac94bf8 --- /dev/null +++ b/pa1-tests/core/class_attr_set.py @@ -0,0 +1,5 @@ +class Foo(object): + x:int = 1 + +f = Foo() +f.x = 2 diff --git a/pa1-tests/core/class_attr_set.py.ast b/pa1-tests/core/class_attr_set.py.ast new file mode 100644 index 0000000..03d6bba --- /dev/null +++ b/pa1-tests/core/class_attr_set.py.ast @@ -0,0 +1,87 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 8 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 9 ], + "name" : "Foo" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 11, 1, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "f" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 4, 5, 4, 9 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "Foo" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 7 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 5, 1, 5, 3 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "f" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 3, 5, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 7, 5, 7 ], + "value" : 2 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/class_constructor.py b/pa1-tests/core/class_constructor.py new file mode 100644 index 0000000..46d7ccb --- /dev/null +++ b/pa1-tests/core/class_constructor.py @@ -0,0 +1,8 @@ +class Foo(object): + x:int = 0 + + def __init__(self:"Foo", x:int): + self.x = x + +f = Foo(1) +print(f.x) diff --git a/pa1-tests/core/class_constructor.py.ast b/pa1-tests/core/class_constructor.py.ast new file mode 100644 index 0000000..6850e03 --- /dev/null +++ b/pa1-tests/core/class_constructor.py.ast @@ -0,0 +1,159 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 9 ], + "name" : "Foo" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 11, 1, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 18, 4, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 18, 4, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 23, 4, 27 ], + "className" : "Foo" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 30, 4, 34 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 30, 4, 30 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 32, 4, 34 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 36, 4, 36 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 9, 5, 18 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 5, 9, 5, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 14, 5, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 18 ], + "name" : "x" + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "f" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 7, 5, 7, 10 ], + "function" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 7 ], + "name" : "Foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 7, 9, 7, 9 ], + "value" : 1 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 10 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 8, 7, 8, 9 ], + "object" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "f" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "x" + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/class_method.py b/pa1-tests/core/class_method.py new file mode 100644 index 0000000..cc03ce2 --- /dev/null +++ b/pa1-tests/core/class_method.py @@ -0,0 +1,9 @@ +class Foo(object): + x:int = 0 + + def set(self:"Foo", x:int) -> object: + self.x = x + +f = Foo() +f.set(1) +print(f.x) diff --git a/pa1-tests/core/class_method.py.ast b/pa1-tests/core/class_method.py.ast new file mode 100644 index 0000000..66bc2e1 --- /dev/null +++ b/pa1-tests/core/class_method.py.ast @@ -0,0 +1,181 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 9 ], + "name" : "Foo" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 11, 1, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "set" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 22 ], + "className" : "Foo" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 25, 4, 29 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 25, 4, 25 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 27, 4, 29 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 35, 4, 40 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 9, 5, 18 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 5, 9, 5, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 14, 5, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 18 ], + "name" : "x" + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "f" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 7, 5, 7, 9 ], + "function" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 7 ], + "name" : "Foo" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 8 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 8, 1, 8, 8 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 8, 1, 8, 5 ], + "object" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "f" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 8, 3, 8, 5 ], + "name" : "set" + } + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 8, 7, 8, 7 ], + "value" : 1 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 9, 1, 9, 10 ], + "function" : { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 9, 7, 9, 9 ], + "object" : { + "kind" : "Identifier", + "location" : [ 9, 7, 9, 7 ], + "name" : "f" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 9 ], + "name" : "x" + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/coverage.py b/pa1-tests/core/coverage.py new file mode 100644 index 0000000..1da3446 --- /dev/null +++ b/pa1-tests/core/coverage.py @@ -0,0 +1,38 @@ +count:int = 0 + +def foo(s: str) -> int: + return len(s) + +class bar(object): + p: bool = True + + def baz(self:"bar", xx: [int]) -> str: + global count + x:int = 0 + y:int = 1 + + def qux(y: int) -> object: + nonlocal x + if x > y: + x = -1 + + for x in xx: + self.p = x == 2 + + qux(0) # Yay! ChocoPy + + count = count + 1 + + while x <= 0: + if self.p: + xx[0] = xx[1] + self.p = not self.p + x = x + 1 + elif foo("Long"[0]) == 1: + return self is None + + return "Nope" + +print(bar().baz([1,2])) + + diff --git a/pa1-tests/core/coverage.py.ast b/pa1-tests/core/coverage.py.ast new file mode 100644 index 0000000..c7bab9f --- /dev/null +++ b/pa1-tests/core/coverage.py.ast @@ -0,0 +1,613 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 36, 24 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "name" : "count" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 7, 1, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 13, 1, 13 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 4, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 3, 9, 3, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 12, 3, 14 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 20, 3, 22 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 4, 5, 4, 17 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 4, 12, 4, 17 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 12, 4, 14 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 4, 16, 4, 16 ], + "name" : "s" + } ] + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 6, 1, 36, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 6, 7, 6, 9 ], + "name" : "bar" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 6, 11, 6, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "p" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 8, 7, 11 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 15, 7, 18 ], + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 34, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 9, 13, 9, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 18, 9, 22 ], + "className" : "bar" + } + }, { + "kind" : "TypedVar", + "location" : [ 9, 25, 9, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 25, 9, 26 ], + "name" : "xx" + }, + "type" : { + "kind" : "ListType", + "location" : [ 9, 29, 9, 33 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 9, 30, 9, 32 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 39, 9, 41 ], + "className" : "str" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 10, 9, 10, 20 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 10, 16, 10, 20 ], + "name" : "count" + } + }, { + "kind" : "VarDef", + "location" : [ 11, 9, 11, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 9, 11, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 11, 11, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 17, 11, 17 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 12, 9, 12, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 9, 12, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 9, 12, 9 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 11, 12, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 17, 12, 17 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 14, 9, 19, 8 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 13, 14, 15 ], + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 17, 14, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 17, 14, 17 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 20, 14, 22 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 28, 14, 33 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 15, 13, 15, 22 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 15, 22, 15, 22 ], + "name" : "x" + } + } ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 16, 13, 19, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 16, 16, 16, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 16 ], + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "Identifier", + "location" : [ 16, 20, 16, 20 ], + "name" : "y" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 17, 17, 17, 22 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 17, 17, 17 ], + "name" : "x" + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 17, 21, 17, 22 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 17, 22, 17, 22 ], + "value" : 1 + } + } + } ], + "elseBody" : [ ] + } ] + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 19, 9, 22, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 13, 19, 13 ], + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 19, 18, 19, 19 ], + "name" : "xx" + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 20, 13, 20, 27 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 20, 13, 20, 18 ], + "object" : { + "kind" : "Identifier", + "location" : [ 20, 13, 20, 16 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 18, 20, 18 ], + "name" : "p" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 20, 22, 20, 27 ], + "left" : { + "kind" : "Identifier", + "location" : [ 20, 22, 20, 22 ], + "name" : "x" + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 20, 27, 20, 27 ], + "value" : 2 + } + } + } ] + }, { + "kind" : "ExprStmt", + "location" : [ 22, 9, 22, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 22, 9, 22, 14 ], + "function" : { + "kind" : "Identifier", + "location" : [ 22, 9, 22, 11 ], + "name" : "qux" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 22, 13, 22, 13 ], + "value" : 0 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 24, 9, 24, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 24, 9, 24, 13 ], + "name" : "count" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 24, 17, 24, 25 ], + "left" : { + "kind" : "Identifier", + "location" : [ 24, 17, 24, 21 ], + "name" : "count" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 25, 24, 25 ], + "value" : 1 + } + } + }, { + "kind" : "WhileStmt", + "location" : [ 26, 9, 34, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 26, 15, 26, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 26, 15, 26, 15 ], + "name" : "x" + }, + "operator" : "<=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 26, 20, 26, 20 ], + "value" : 0 + } + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 27, 13, 34, 8 ], + "condition" : { + "kind" : "MemberExpr", + "location" : [ 27, 16, 27, 21 ], + "object" : { + "kind" : "Identifier", + "location" : [ 27, 16, 27, 19 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 21, 27, 21 ], + "name" : "p" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 28, 17, 28, 29 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 28, 17, 28, 21 ], + "list" : { + "kind" : "Identifier", + "location" : [ 28, 17, 28, 18 ], + "name" : "xx" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 28, 20, 28, 20 ], + "value" : 0 + } + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 28, 25, 28, 29 ], + "list" : { + "kind" : "Identifier", + "location" : [ 28, 25, 28, 26 ], + "name" : "xx" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 28, 28, 28, 28 ], + "value" : 1 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 29, 17, 29, 35 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 29, 17, 29, 22 ], + "object" : { + "kind" : "Identifier", + "location" : [ 29, 17, 29, 20 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 22, 29, 22 ], + "name" : "p" + } + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 29, 26, 29, 35 ], + "operator" : "not", + "operand" : { + "kind" : "MemberExpr", + "location" : [ 29, 30, 29, 35 ], + "object" : { + "kind" : "Identifier", + "location" : [ 29, 30, 29, 33 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 35, 29, 35 ], + "name" : "p" + } + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 30, 17, 30, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 30, 17, 30, 17 ], + "name" : "x" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 30, 21, 30, 25 ], + "left" : { + "kind" : "Identifier", + "location" : [ 30, 21, 30, 21 ], + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 30, 25, 30, 25 ], + "value" : 1 + } + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 31, 13, 34, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 31, 18, 31, 36 ], + "left" : { + "kind" : "CallExpr", + "location" : [ 31, 18, 31, 31 ], + "function" : { + "kind" : "Identifier", + "location" : [ 31, 18, 31, 20 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 31, 22, 31, 30 ], + "list" : { + "kind" : "StringLiteral", + "location" : [ 31, 22, 31, 27 ], + "value" : "Long" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 31, 29, 31, 29 ], + "value" : 0 + } + } ] + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 31, 36, 31, 36 ], + "value" : 1 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 32, 17, 32, 35 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 32, 24, 32, 35 ], + "left" : { + "kind" : "Identifier", + "location" : [ 32, 24, 32, 27 ], + "name" : "self" + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 32, 32, 32, 35 ] + } + } + } ], + "elseBody" : [ ] + } ] + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 34, 9, 34, 21 ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 34, 16, 34, 21 ], + "value" : "Nope" + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 36, 1, 36, 23 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 36, 1, 36, 23 ], + "function" : { + "kind" : "Identifier", + "location" : [ 36, 1, 36, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 36, 7, 36, 22 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 36, 7, 36, 15 ], + "object" : { + "kind" : "CallExpr", + "location" : [ 36, 7, 36, 11 ], + "function" : { + "kind" : "Identifier", + "location" : [ 36, 7, 36, 9 ], + "name" : "bar" + }, + "args" : [ ] + }, + "member" : { + "kind" : "Identifier", + "location" : [ 36, 13, 36, 15 ], + "name" : "baz" + } + }, + "args" : [ { + "kind" : "ListExpr", + "location" : [ 36, 17, 36, 21 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 36, 18, 36, 18 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 36, 20, 36, 20 ], + "value" : 2 + } ] + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/def_func.py b/pa1-tests/core/def_func.py new file mode 100644 index 0000000..55e9c43 --- /dev/null +++ b/pa1-tests/core/def_func.py @@ -0,0 +1,4 @@ +def foo() -> int: + return 1 + +foo() diff --git a/pa1-tests/core/def_func.py.ast b/pa1-tests/core/def_func.py.ast new file mode 100644 index 0000000..00a7e65 --- /dev/null +++ b/pa1-tests/core/def_func.py.ast @@ -0,0 +1,48 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 6 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 14, 1, 16 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 12, 2, 12 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 3 ], + "name" : "foo" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/def_func_args.py b/pa1-tests/core/def_func_args.py new file mode 100644 index 0000000..196f504 --- /dev/null +++ b/pa1-tests/core/def_func_args.py @@ -0,0 +1,4 @@ +def foo(x:int, y:int) -> bool: + return x > y + +foo(1,2) diff --git a/pa1-tests/core/def_func_args.py.ast b/pa1-tests/core/def_func_args.py.ast new file mode 100644 index 0000000..77d9dc9 --- /dev/null +++ b/pa1-tests/core/def_func_args.py.ast @@ -0,0 +1,92 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 9 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 16, 1, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 16, 1, 16 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 18, 1, 20 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 26, 1, 29 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 16 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 2, 12, 2, 16 ], + "left" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 12 ], + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "Identifier", + "location" : [ 2, 16, 2, 16 ], + "name" : "y" + } + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 8 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 5, 4, 5 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 7, 4, 7 ], + "value" : 2 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/def_func_global.py b/pa1-tests/core/def_func_global.py new file mode 100644 index 0000000..12f9dfc --- /dev/null +++ b/pa1-tests/core/def_func_global.py @@ -0,0 +1,7 @@ +z:int = 0 + +def foo(x:int) -> bool: + global z + return x > z + +foo(1) diff --git a/pa1-tests/core/def_func_global.py.ast b/pa1-tests/core/def_func_global.py.ast new file mode 100644 index 0000000..736af77 --- /dev/null +++ b/pa1-tests/core/def_func_global.py.ast @@ -0,0 +1,105 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 7 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 3, 9, 3, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 11, 3, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 19, 3, 22 ], + "className" : "bool" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 4, 5, 4, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 4, 12, 4, 12 ], + "name" : "z" + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 16 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 5, 12, 5, 16 ], + "left" : { + "kind" : "Identifier", + "location" : [ 5, 12, 5, 12 ], + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 16 ], + "name" : "z" + } + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 6 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 1, 7, 6 ], + "function" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 7, 5, 7, 5 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/def_func_nested.py b/pa1-tests/core/def_func_nested.py new file mode 100644 index 0000000..835614e --- /dev/null +++ b/pa1-tests/core/def_func_nested.py @@ -0,0 +1,10 @@ + +def foo(x:int) -> bool: + a:int = 0 + b:int = 1 + def bar(y: int) -> int: + a:int = 2 + return y + return bar(x) > a + +foo(1) diff --git a/pa1-tests/core/def_func_nested.py.ast b/pa1-tests/core/def_func_nested.py.ast new file mode 100644 index 0000000..0024178 --- /dev/null +++ b/pa1-tests/core/def_func_nested.py.ast @@ -0,0 +1,187 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 10, 7 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 1, 8, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 9, 2, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 11, 2, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 19, 2, 22 ], + "className" : "bool" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 7, 3, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 13, 3, 13 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 7, 4, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 13, 4, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 5, 7, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 13, 5, 18 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 13, 5, 13 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 16, 5, 18 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 24, 5, 26 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 9, 6, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 9, 6, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 9, 6, 9 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 11, 6, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 17, 6, 17 ], + "value" : 2 + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 7, 9, 7, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 7, 16, 7, 16 ], + "name" : "y" + } + } ] + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 8, 5, 8, 21 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 8, 12, 8, 21 ], + "left" : { + "kind" : "CallExpr", + "location" : [ 8, 12, 8, 17 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 12, 8, 14 ], + "name" : "bar" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 8, 16, 8, 16 ], + "name" : "x" + } ] + }, + "operator" : ">", + "right" : { + "kind" : "Identifier", + "location" : [ 8, 21, 8, 21 ], + "name" : "a" + } + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 6 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 1, 10, 6 ], + "function" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 10, 5, 10, 5 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/def_func_nonlocal.py b/pa1-tests/core/def_func_nonlocal.py new file mode 100644 index 0000000..1304328 --- /dev/null +++ b/pa1-tests/core/def_func_nonlocal.py @@ -0,0 +1,11 @@ + +def foo(x:int) -> bool: + a:int = 0 + b:int = 1 + def bar(y: int) -> int: + nonlocal a + a = 2 + return y + return bar(x) > a + +foo(1) diff --git a/pa1-tests/core/def_func_nonlocal.py.ast b/pa1-tests/core/def_func_nonlocal.py.ast new file mode 100644 index 0000000..5c1e1de --- /dev/null +++ b/pa1-tests/core/def_func_nonlocal.py.ast @@ -0,0 +1,186 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 11, 7 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 1, 9, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 9, 2, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 11, 2, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 19, 2, 22 ], + "className" : "bool" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 7, 3, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 13, 3, 13 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 7, 4, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 13, 4, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 5, 8, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 13, 5, 18 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 13, 5, 13 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 16, 5, 18 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 24, 5, 26 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 6, 9, 6, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 6, 18, 6, 18 ], + "name" : "a" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 9, 7, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "a" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 13, 7, 13 ], + "value" : 2 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 8, 9, 8, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 8, 16, 8, 16 ], + "name" : "y" + } + } ] + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 9, 5, 9, 21 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 9, 12, 9, 21 ], + "left" : { + "kind" : "CallExpr", + "location" : [ 9, 12, 9, 17 ], + "function" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 14 ], + "name" : "bar" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 9, 16, 9, 16 ], + "name" : "x" + } ] + }, + "operator" : ">", + "right" : { + "kind" : "Identifier", + "location" : [ 9, 21, 9, 21 ], + "name" : "a" + } + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 6 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 1, 11, 6 ], + "function" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 11, 5, 11, 5 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/expr_if.py b/pa1-tests/core/expr_if.py new file mode 100644 index 0000000..e9e9c26 --- /dev/null +++ b/pa1-tests/core/expr_if.py @@ -0,0 +1 @@ +3 if 1 > 2 else 4 diff --git a/pa1-tests/core/expr_if.py.ast b/pa1-tests/core/expr_if.py.ast new file mode 100644 index 0000000..0ed9a55 --- /dev/null +++ b/pa1-tests/core/expr_if.py.ast @@ -0,0 +1,43 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 18 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 17 ], + "expr" : { + "kind" : "IfExpr", + "location" : [ 1, 1, 1, 17 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 1, 6, 1, 10 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 6, 1, 6 ], + "value" : 1 + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 10, 1, 10 ], + "value" : 2 + } + }, + "thenExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "value" : 3 + }, + "elseExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 17, 1, 17 ], + "value" : 4 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/expr_if_chained.py b/pa1-tests/core/expr_if_chained.py new file mode 100644 index 0000000..4a7837e --- /dev/null +++ b/pa1-tests/core/expr_if_chained.py @@ -0,0 +1 @@ +3 if 1 > 2 else 4 if 1 < 0 else 5 diff --git a/pa1-tests/core/expr_if_chained.py.ast b/pa1-tests/core/expr_if_chained.py.ast new file mode 100644 index 0000000..2776da9 --- /dev/null +++ b/pa1-tests/core/expr_if_chained.py.ast @@ -0,0 +1,67 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 34 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 33 ], + "expr" : { + "kind" : "IfExpr", + "location" : [ 1, 1, 1, 33 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 1, 6, 1, 10 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 6, 1, 6 ], + "value" : 1 + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 10, 1, 10 ], + "value" : 2 + } + }, + "thenExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "value" : 3 + }, + "elseExpr" : { + "kind" : "IfExpr", + "location" : [ 1, 17, 1, 33 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 1, 22, 1, 26 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 22, 1, 22 ], + "value" : 1 + }, + "operator" : "<", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 26, 1, 26 ], + "value" : 0 + } + }, + "thenExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 17, 1, 17 ], + "value" : 4 + }, + "elseExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 33, 1, 33 ], + "value" : 5 + } + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/expr_index.py b/pa1-tests/core/expr_index.py new file mode 100644 index 0000000..8e95ff2 --- /dev/null +++ b/pa1-tests/core/expr_index.py @@ -0,0 +1 @@ +a + b[i][j] diff --git a/pa1-tests/core/expr_index.py.ast b/pa1-tests/core/expr_index.py.ast new file mode 100644 index 0000000..a5f97ee --- /dev/null +++ b/pa1-tests/core/expr_index.py.ast @@ -0,0 +1,47 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 12 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 11 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 11 ], + "left" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "a" + }, + "operator" : "+", + "right" : { + "kind" : "IndexExpr", + "location" : [ 1, 5, 1, 11 ], + "list" : { + "kind" : "IndexExpr", + "location" : [ 1, 5, 1, 8 ], + "list" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 5 ], + "name" : "b" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "i" + } + }, + "index" : { + "kind" : "Identifier", + "location" : [ 1, 10, 1, 10 ], + "name" : "j" + } + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/expr_plus.py b/pa1-tests/core/expr_plus.py new file mode 100644 index 0000000..8138b36 --- /dev/null +++ b/pa1-tests/core/expr_plus.py @@ -0,0 +1 @@ +1 + 2 + 3 diff --git a/pa1-tests/core/expr_plus.py.ast b/pa1-tests/core/expr_plus.py.ast new file mode 100644 index 0000000..f924e67 --- /dev/null +++ b/pa1-tests/core/expr_plus.py.ast @@ -0,0 +1,39 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 10 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 9 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 9 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 5 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "value" : 2 + } + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 3 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/expr_unary.py b/pa1-tests/core/expr_unary.py new file mode 100644 index 0000000..3a2e3f4 --- /dev/null +++ b/pa1-tests/core/expr_unary.py @@ -0,0 +1 @@ +-1 diff --git a/pa1-tests/core/expr_unary.py.ast b/pa1-tests/core/expr_unary.py.ast new file mode 100644 index 0000000..e4ef8d2 --- /dev/null +++ b/pa1-tests/core/expr_unary.py.ast @@ -0,0 +1,24 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 3 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 2 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 1, 1, 1, 2 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 2, 1, 2 ], + "value" : 1 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/global.py b/pa1-tests/core/global.py new file mode 100644 index 0000000..779d3bb --- /dev/null +++ b/pa1-tests/core/global.py @@ -0,0 +1,5 @@ +x:int = 1 + +x = 2 + +print(x) diff --git a/pa1-tests/core/global.py.ast b/pa1-tests/core/global.py.ast new file mode 100644 index 0000000..84b42b1 --- /dev/null +++ b/pa1-tests/core/global.py.ast @@ -0,0 +1,63 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 5, 3, 5 ], + "value" : 2 + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 8 ], + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 5, 7, 5, 7 ], + "name" : "x" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/literals.py b/pa1-tests/core/literals.py new file mode 100644 index 0000000..081863e --- /dev/null +++ b/pa1-tests/core/literals.py @@ -0,0 +1,7 @@ +True +False +1 +None +"This is a string" +[1, 2, 3] + diff --git a/pa1-tests/core/literals.py.ast b/pa1-tests/core/literals.py.ast new file mode 100644 index 0000000..d6fd3bc --- /dev/null +++ b/pa1-tests/core/literals.py.ast @@ -0,0 +1,70 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 10 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 4 ], + "expr" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 1, 1, 4 ], + "value" : true + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 5 ], + "expr" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 1, 2, 5 ], + "value" : false + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 1 ], + "expr" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 1, 3, 1 ], + "value" : 1 + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 4 ], + "expr" : { + "kind" : "NoneLiteral", + "location" : [ 4, 1, 4, 4 ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 18 ], + "expr" : { + "kind" : "StringLiteral", + "location" : [ 5, 1, 5, 18 ], + "value" : "This is a string" + } + }, { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 9 ], + "expr" : { + "kind" : "ListExpr", + "location" : [ 6, 1, 6, 9 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 2, 6, 2 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 5, 6, 5 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 8, 6, 8 ], + "value" : 3 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/stmt_call.py b/pa1-tests/core/stmt_call.py new file mode 100644 index 0000000..b917a72 --- /dev/null +++ b/pa1-tests/core/stmt_call.py @@ -0,0 +1 @@ +print(1) diff --git a/pa1-tests/core/stmt_call.py.ast b/pa1-tests/core/stmt_call.py.ast new file mode 100644 index 0000000..4d0ef38 --- /dev/null +++ b/pa1-tests/core/stmt_call.py.ast @@ -0,0 +1,28 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 9 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 1, 1, 1, 8 ], + "function" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 1, 7, 1, 7 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/stmt_for.py b/pa1-tests/core/stmt_for.py new file mode 100644 index 0000000..6f65c5f --- /dev/null +++ b/pa1-tests/core/stmt_for.py @@ -0,0 +1,4 @@ +x:int = 0 +for x in [1, 2, 3]: + print(x) + diff --git a/pa1-tests/core/stmt_for.py.ast b/pa1-tests/core/stmt_for.py.ast new file mode 100644 index 0000000..ba0847b --- /dev/null +++ b/pa1-tests/core/stmt_for.py.ast @@ -0,0 +1,76 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 2, 1, 5, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "iterable" : { + "kind" : "ListExpr", + "location" : [ 2, 10, 2, 18 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 2, 11, 2, 11 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 2, 14, 2, 14 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 2, 17, 2, 17 ], + "value" : 3 + } ] + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 3, 5, 3, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 3, 5, 3, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 3, 11, 3, 11 ], + "name" : "x" + } ] + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/stmt_if.py b/pa1-tests/core/stmt_if.py new file mode 100644 index 0000000..b87c003 --- /dev/null +++ b/pa1-tests/core/stmt_if.py @@ -0,0 +1,3 @@ +if True: + False + diff --git a/pa1-tests/core/stmt_if.py.ast b/pa1-tests/core/stmt_if.py.ast new file mode 100644 index 0000000..2b08a8f --- /dev/null +++ b/pa1-tests/core/stmt_if.py.ast @@ -0,0 +1,29 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 1 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 1, 1, 4, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 4, 1, 7 ], + "value" : true + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 2, 5, 2, 9 ], + "expr" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 5, 2, 9 ], + "value" : false + } + } ], + "elseBody" : [ ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/stmt_if_elif.py b/pa1-tests/core/stmt_if_elif.py new file mode 100644 index 0000000..7fa86dd --- /dev/null +++ b/pa1-tests/core/stmt_if_elif.py @@ -0,0 +1,6 @@ +if 1 > 2: + print(1) +elif 3 == 4: + print(2) +elif True: + print(3) diff --git a/pa1-tests/core/stmt_if_elif.py.ast b/pa1-tests/core/stmt_if_elif.py.ast new file mode 100644 index 0000000..11dcd2e --- /dev/null +++ b/pa1-tests/core/stmt_if_elif.py.ast @@ -0,0 +1,112 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 1 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 1, 1, 7, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 1, 4, 1, 8 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 4, 1, 4 ], + "value" : 1 + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 8, 1, 8 ], + "value" : 2 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 2, 5, 2, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 2, 5, 2, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 2, 11, 2, 11 ], + "value" : 1 + } ] + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 3, 1, 7, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 3, 6, 3, 11 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "value" : 3 + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 11, 3, 11 ], + "value" : 4 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 5, 4, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 11, 4, 11 ], + "value" : 2 + } ] + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 5, 1, 7, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 6, 5, 9 ], + "value" : true + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 6, 5, 6, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 5, 6, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 11, 6, 11 ], + "value" : 3 + } ] + } + } ], + "elseBody" : [ ] + } ] + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/stmt_if_elif_else.py b/pa1-tests/core/stmt_if_elif_else.py new file mode 100644 index 0000000..161d9d9 --- /dev/null +++ b/pa1-tests/core/stmt_if_elif_else.py @@ -0,0 +1,8 @@ +if 1 > 2: + print(1) +elif 3 == 4: + print(2) +elif True: + print(3) +else: + print(4) diff --git a/pa1-tests/core/stmt_if_elif_else.py.ast b/pa1-tests/core/stmt_if_elif_else.py.ast new file mode 100644 index 0000000..dc25855 --- /dev/null +++ b/pa1-tests/core/stmt_if_elif_else.py.ast @@ -0,0 +1,129 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 1 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 1, 1, 9, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 1, 4, 1, 8 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 4, 1, 4 ], + "value" : 1 + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 8, 1, 8 ], + "value" : 2 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 2, 5, 2, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 2, 5, 2, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 2, 11, 2, 11 ], + "value" : 1 + } ] + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 3, 1, 9, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 3, 6, 3, 11 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "value" : 3 + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 11, 3, 11 ], + "value" : 4 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 5, 4, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 11, 4, 11 ], + "value" : 2 + } ] + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 5, 1, 9, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 6, 5, 9 ], + "value" : true + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 6, 5, 6, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 5, 6, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 11, 6, 11 ], + "value" : 3 + } ] + } + } ], + "elseBody" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 5, 8, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 5, 8, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 8, 11, 8, 11 ], + "value" : 4 + } ] + } + } ] + } ] + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/stmt_ifelse.py b/pa1-tests/core/stmt_ifelse.py new file mode 100644 index 0000000..f138957 --- /dev/null +++ b/pa1-tests/core/stmt_ifelse.py @@ -0,0 +1,5 @@ +if True: + False +else: + True + diff --git a/pa1-tests/core/stmt_ifelse.py.ast b/pa1-tests/core/stmt_ifelse.py.ast new file mode 100644 index 0000000..8e23d16 --- /dev/null +++ b/pa1-tests/core/stmt_ifelse.py.ast @@ -0,0 +1,37 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 1 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 1, 1, 6, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 4, 1, 7 ], + "value" : true + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 2, 5, 2, 9 ], + "expr" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 5, 2, 9 ], + "value" : false + } + } ], + "elseBody" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 8 ], + "expr" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 5, 4, 8 ], + "value" : true + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/stmt_list_assign.py b/pa1-tests/core/stmt_list_assign.py new file mode 100644 index 0000000..e9e31d9 --- /dev/null +++ b/pa1-tests/core/stmt_list_assign.py @@ -0,0 +1,4 @@ +x:int = None + +x = [1, 2, 3] +x[0] = x[1] diff --git a/pa1-tests/core/stmt_list_assign.py.ast b/pa1-tests/core/stmt_list_assign.py.ast new file mode 100644 index 0000000..b65848c --- /dev/null +++ b/pa1-tests/core/stmt_list_assign.py.ast @@ -0,0 +1,88 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 12 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 12 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 9, 1, 12 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 3, 5, 3, 13 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 12, 3, 12 ], + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 11 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 4, 1, 4, 4 ], + "list" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 3, 4, 3 ], + "value" : 0 + } + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 4, 8, 4, 11 ], + "list" : { + "kind" : "Identifier", + "location" : [ 4, 8, 4, 8 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 10, 4, 10 ], + "value" : 1 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/core/stmt_while.py b/pa1-tests/core/stmt_while.py new file mode 100644 index 0000000..1aaefd8 --- /dev/null +++ b/pa1-tests/core/stmt_while.py @@ -0,0 +1,3 @@ +while True: + pass + diff --git a/pa1-tests/core/stmt_while.py.ast b/pa1-tests/core/stmt_while.py.ast new file mode 100644 index 0000000..a564490 --- /dev/null +++ b/pa1-tests/core/stmt_while.py.ast @@ -0,0 +1,20 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 1 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 1, 1, 4, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 7, 1, 10 ], + "value" : true + }, + "body" : [ ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/extra/graph.py b/pa1-tests/extra/graph.py new file mode 100644 index 0000000..bb75943 --- /dev/null +++ b/pa1-tests/extra/graph.py @@ -0,0 +1,52 @@ +class weight(object): + value: int = 0 + + def __init__(self: "weight", value: int): + self.value = value + + def __repr__(self: "weight"): + return "weight(" + str(self.value) + ")" + + +class graph(object): + matrix: [[weight]] = None + + def __init__(self: "graph", num_vertices: int): + i: int = 0 + j: int = 0 + row: [weight] = None + + self.matrix = [] + while i < num_vertices: + j = 0 + row = [] + while j < num_vertices: + row = row + [weight(0)] + j = j + 1 + self.matrix = self.matrix + [row] + i = i + 1 + + def add_edge(self: "graph", from_vertex: int, to_vertex: int, edge_weight: int): + pass + + def print(self: "graph"): + for row in self.matrix: + print(row) + + +class undirectedgraph(graph): + def add_edge(self: "undirectedgraph", from_vertex: int, to_vertex: int, edge_weight: int): + self.matrix[from_vertex][to_vertex] = weight(edge_weight) + self.matrix[to_vertex][from_vertex] = weight(edge_weight) + + +class directedgraph(graph): + def add_edge(self: "undirectedgraph", from_vertex: int, to_vertex: int, edge_weight: int): + self.matrix[from_vertex][to_vertex] = weight(edge_weight) + + +g = undirectedgraph(3) +g.add_edge(0, 2, 100) +g.print() + +directedgraph(3).print() diff --git a/pa1-tests/extra/graph.py.ast b/pa1-tests/extra/graph.py.ast new file mode 100644 index 0000000..6332c1f --- /dev/null +++ b/pa1-tests/extra/graph.py.ast @@ -0,0 +1,1110 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 52, 25 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 11, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 12 ], + "name" : "weight" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 14, 1, 19 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 9 ], + "name" : "value" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 12, 2, 14 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 18, 2, 18 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 27 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 18, 4, 31 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 18, 4, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 24, 4, 31 ], + "className" : "weight" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 34, 4, 43 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 34, 4, 38 ], + "name" : "value" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 41, 4, 43 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 45, 4, 45 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 9, 5, 26 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 5, 9, 5, 18 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 14, 5, 18 ], + "name" : "value" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 22, 5, 26 ], + "name" : "value" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 7, 5, 8, 49 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 16 ], + "name" : "__repr__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 7, 18, 7, 31 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 18, 7, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 24, 7, 31 ], + "className" : "weight" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 33, 7, 33 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 8, 9, 8, 48 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 8, 16, 8, 48 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 8, 16, 8, 42 ], + "left" : { + "kind" : "StringLiteral", + "location" : [ 8, 16, 8, 24 ], + "value" : "weight(" + }, + "operator" : "+", + "right" : { + "kind" : "CallExpr", + "location" : [ 8, 28, 8, 42 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 28, 8, 30 ], + "name" : "str" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 8, 32, 8, 41 ], + "object" : { + "kind" : "Identifier", + "location" : [ 8, 32, 8, 35 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 8, 37, 8, 41 ], + "name" : "value" + } + } ] + } + }, + "operator" : "+", + "right" : { + "kind" : "StringLiteral", + "location" : [ 8, 46, 8, 48 ], + "value" : ")" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 11, 1, 37, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 11 ], + "name" : "graph" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 11, 13, 11, 18 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 12, 5, 12, 29 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 5, 12, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 10 ], + "name" : "matrix" + }, + "type" : { + "kind" : "ListType", + "location" : [ 12, 13, 12, 22 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 12, 14, 12, 21 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 12, 15, 12, 20 ], + "className" : "weight" + } + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 26, 12, 29 ] + } + }, { + "kind" : "FuncDef", + "location" : [ 14, 5, 29, 4 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 18, 14, 30 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 18, 14, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 24, 14, 30 ], + "className" : "graph" + } + }, { + "kind" : "TypedVar", + "location" : [ 14, 33, 14, 49 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 33, 14, 44 ], + "name" : "num_vertices" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 47, 14, 49 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 51, 14, 51 ], + "className" : "" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 15, 9, 15, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 15, 9, 15, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 9 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 15, 12, 15, 14 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 15, 18, 15, 18 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 16, 9, 16, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 16, 9, 16, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 9, 16, 9 ], + "name" : "j" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 12, 16, 14 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 16, 18, 16, 18 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 17, 9, 17, 28 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 17, 9, 17, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 9, 17, 11 ], + "name" : "row" + }, + "type" : { + "kind" : "ListType", + "location" : [ 17, 14, 17, 21 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 17, 15, 17, 20 ], + "className" : "weight" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 17, 25, 17, 28 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 19, 9, 19, 24 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 19, 9, 19, 19 ], + "object" : { + "kind" : "Identifier", + "location" : [ 19, 9, 19, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 19, 14, 19, 19 ], + "name" : "matrix" + } + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 19, 23, 19, 24 ], + "elements" : [ ] + } + }, { + "kind" : "WhileStmt", + "location" : [ 20, 9, 29, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 20, 15, 20, 30 ], + "left" : { + "kind" : "Identifier", + "location" : [ 20, 15, 20, 15 ], + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "Identifier", + "location" : [ 20, 19, 20, 30 ], + "name" : "num_vertices" + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 21, 13, 21, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 21, 13, 21, 13 ], + "name" : "j" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 21, 17, 21, 17 ], + "value" : 0 + } + }, { + "kind" : "AssignStmt", + "location" : [ 22, 13, 22, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 22, 13, 22, 15 ], + "name" : "row" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 22, 19, 22, 20 ], + "elements" : [ ] + } + }, { + "kind" : "WhileStmt", + "location" : [ 23, 13, 26, 12 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 23, 19, 23, 34 ], + "left" : { + "kind" : "Identifier", + "location" : [ 23, 19, 23, 19 ], + "name" : "j" + }, + "operator" : "<", + "right" : { + "kind" : "Identifier", + "location" : [ 23, 23, 23, 34 ], + "name" : "num_vertices" + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 24, 17, 24, 39 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 24, 17, 24, 19 ], + "name" : "row" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 24, 23, 24, 39 ], + "left" : { + "kind" : "Identifier", + "location" : [ 24, 23, 24, 25 ], + "name" : "row" + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 24, 29, 24, 39 ], + "elements" : [ { + "kind" : "CallExpr", + "location" : [ 24, 30, 24, 38 ], + "function" : { + "kind" : "Identifier", + "location" : [ 24, 30, 24, 35 ], + "name" : "weight" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 24, 37, 24, 37 ], + "value" : 0 + } ] + } ] + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 25, 17, 25, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 25, 17, 25, 17 ], + "name" : "j" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 25, 21, 25, 25 ], + "left" : { + "kind" : "Identifier", + "location" : [ 25, 21, 25, 21 ], + "name" : "j" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 25, 25, 25, 25 ], + "value" : 1 + } + } + } ] + }, { + "kind" : "AssignStmt", + "location" : [ 26, 13, 26, 45 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 26, 13, 26, 23 ], + "object" : { + "kind" : "Identifier", + "location" : [ 26, 13, 26, 16 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 26, 18, 26, 23 ], + "name" : "matrix" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 26, 27, 26, 45 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 26, 27, 26, 37 ], + "object" : { + "kind" : "Identifier", + "location" : [ 26, 27, 26, 30 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 26, 32, 26, 37 ], + "name" : "matrix" + } + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 26, 41, 26, 45 ], + "elements" : [ { + "kind" : "Identifier", + "location" : [ 26, 42, 26, 44 ], + "name" : "row" + } ] + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 27, 13, 27, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 27, 13, 27, 13 ], + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 27, 17, 27, 21 ], + "left" : { + "kind" : "Identifier", + "location" : [ 27, 17, 27, 17 ], + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 27, 21, 27, 21 ], + "value" : 1 + } + } + } ] + } ] + }, { + "kind" : "FuncDef", + "location" : [ 29, 5, 30, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 29, 9, 29, 16 ], + "name" : "add_edge" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 29, 18, 29, 30 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 18, 29, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 29, 24, 29, 30 ], + "className" : "graph" + } + }, { + "kind" : "TypedVar", + "location" : [ 29, 33, 29, 48 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 33, 29, 43 ], + "name" : "from_vertex" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 29, 46, 29, 48 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 29, 51, 29, 64 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 51, 29, 59 ], + "name" : "to_vertex" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 29, 62, 29, 64 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 29, 67, 29, 82 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 67, 29, 77 ], + "name" : "edge_weight" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 29, 80, 29, 82 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 29, 84, 29, 84 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 32, 5, 37, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 32, 9, 32, 13 ], + "name" : "print" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 32, 15, 32, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 32, 15, 32, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 32, 21, 32, 27 ], + "className" : "graph" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 32, 29, 32, 29 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 33, 9, 37, 0 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 33, 13, 33, 15 ], + "name" : "row" + }, + "iterable" : { + "kind" : "MemberExpr", + "location" : [ 33, 20, 33, 30 ], + "object" : { + "kind" : "Identifier", + "location" : [ 33, 20, 33, 23 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 33, 25, 33, 30 ], + "name" : "matrix" + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 34, 13, 34, 22 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 34, 13, 34, 22 ], + "function" : { + "kind" : "Identifier", + "location" : [ 34, 13, 34, 17 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 34, 19, 34, 21 ], + "name" : "row" + } ] + } + } ] + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 37, 1, 43, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 37, 7, 37, 21 ], + "name" : "undirectedgraph" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 37, 23, 37, 27 ], + "name" : "graph" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 38, 5, 40, 66 ], + "name" : { + "kind" : "Identifier", + "location" : [ 38, 9, 38, 16 ], + "name" : "add_edge" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 38, 18, 38, 40 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 38, 18, 38, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 38, 24, 38, 40 ], + "className" : "undirectedgraph" + } + }, { + "kind" : "TypedVar", + "location" : [ 38, 43, 38, 58 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 38, 43, 38, 53 ], + "name" : "from_vertex" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 38, 56, 38, 58 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 38, 61, 38, 74 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 38, 61, 38, 69 ], + "name" : "to_vertex" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 38, 72, 38, 74 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 38, 77, 38, 92 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 38, 77, 38, 87 ], + "name" : "edge_weight" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 38, 90, 38, 92 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 38, 94, 38, 94 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 39, 9, 39, 65 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 39, 9, 39, 43 ], + "list" : { + "kind" : "IndexExpr", + "location" : [ 39, 9, 39, 32 ], + "list" : { + "kind" : "MemberExpr", + "location" : [ 39, 9, 39, 19 ], + "object" : { + "kind" : "Identifier", + "location" : [ 39, 9, 39, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 39, 14, 39, 19 ], + "name" : "matrix" + } + }, + "index" : { + "kind" : "Identifier", + "location" : [ 39, 21, 39, 31 ], + "name" : "from_vertex" + } + }, + "index" : { + "kind" : "Identifier", + "location" : [ 39, 34, 39, 42 ], + "name" : "to_vertex" + } + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 39, 47, 39, 65 ], + "function" : { + "kind" : "Identifier", + "location" : [ 39, 47, 39, 52 ], + "name" : "weight" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 39, 54, 39, 64 ], + "name" : "edge_weight" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 40, 9, 40, 65 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 40, 9, 40, 43 ], + "list" : { + "kind" : "IndexExpr", + "location" : [ 40, 9, 40, 30 ], + "list" : { + "kind" : "MemberExpr", + "location" : [ 40, 9, 40, 19 ], + "object" : { + "kind" : "Identifier", + "location" : [ 40, 9, 40, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 40, 14, 40, 19 ], + "name" : "matrix" + } + }, + "index" : { + "kind" : "Identifier", + "location" : [ 40, 21, 40, 29 ], + "name" : "to_vertex" + } + }, + "index" : { + "kind" : "Identifier", + "location" : [ 40, 32, 40, 42 ], + "name" : "from_vertex" + } + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 40, 47, 40, 65 ], + "function" : { + "kind" : "Identifier", + "location" : [ 40, 47, 40, 52 ], + "name" : "weight" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 40, 54, 40, 64 ], + "name" : "edge_weight" + } ] + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 43, 1, 48, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 43, 7, 43, 19 ], + "name" : "directedgraph" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 43, 21, 43, 25 ], + "name" : "graph" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 44, 5, 45, 66 ], + "name" : { + "kind" : "Identifier", + "location" : [ 44, 9, 44, 16 ], + "name" : "add_edge" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 44, 18, 44, 40 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 44, 18, 44, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 44, 24, 44, 40 ], + "className" : "undirectedgraph" + } + }, { + "kind" : "TypedVar", + "location" : [ 44, 43, 44, 58 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 44, 43, 44, 53 ], + "name" : "from_vertex" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 44, 56, 44, 58 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 44, 61, 44, 74 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 44, 61, 44, 69 ], + "name" : "to_vertex" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 44, 72, 44, 74 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 44, 77, 44, 92 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 44, 77, 44, 87 ], + "name" : "edge_weight" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 44, 90, 44, 92 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 44, 94, 44, 94 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 45, 9, 45, 65 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 45, 9, 45, 43 ], + "list" : { + "kind" : "IndexExpr", + "location" : [ 45, 9, 45, 32 ], + "list" : { + "kind" : "MemberExpr", + "location" : [ 45, 9, 45, 19 ], + "object" : { + "kind" : "Identifier", + "location" : [ 45, 9, 45, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 45, 14, 45, 19 ], + "name" : "matrix" + } + }, + "index" : { + "kind" : "Identifier", + "location" : [ 45, 21, 45, 31 ], + "name" : "from_vertex" + } + }, + "index" : { + "kind" : "Identifier", + "location" : [ 45, 34, 45, 42 ], + "name" : "to_vertex" + } + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 45, 47, 45, 65 ], + "function" : { + "kind" : "Identifier", + "location" : [ 45, 47, 45, 52 ], + "name" : "weight" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 45, 54, 45, 64 ], + "name" : "edge_weight" + } ] + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 48, 1, 48, 22 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 48, 1, 48, 1 ], + "name" : "g" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 48, 5, 48, 22 ], + "function" : { + "kind" : "Identifier", + "location" : [ 48, 5, 48, 19 ], + "name" : "undirectedgraph" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 48, 21, 48, 21 ], + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 49, 1, 49, 21 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 49, 1, 49, 21 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 49, 1, 49, 10 ], + "object" : { + "kind" : "Identifier", + "location" : [ 49, 1, 49, 1 ], + "name" : "g" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 49, 3, 49, 10 ], + "name" : "add_edge" + } + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 49, 12, 49, 12 ], + "value" : 0 + }, { + "kind" : "IntegerLiteral", + "location" : [ 49, 15, 49, 15 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 49, 18, 49, 20 ], + "value" : 100 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 50, 1, 50, 9 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 50, 1, 50, 9 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 50, 1, 50, 7 ], + "object" : { + "kind" : "Identifier", + "location" : [ 50, 1, 50, 1 ], + "name" : "g" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 50, 3, 50, 7 ], + "name" : "print" + } + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 52, 1, 52, 24 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 52, 1, 52, 24 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 52, 1, 52, 22 ], + "object" : { + "kind" : "CallExpr", + "location" : [ 52, 1, 52, 16 ], + "function" : { + "kind" : "Identifier", + "location" : [ 52, 1, 52, 13 ], + "name" : "directedgraph" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 52, 15, 52, 15 ], + "value" : 3 + } ] + }, + "member" : { + "kind" : "Identifier", + "location" : [ 52, 18, 52, 22 ], + "name" : "print" + } + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/extra/mergesort.py b/pa1-tests/extra/mergesort.py new file mode 100644 index 0000000..096c2c8 --- /dev/null +++ b/pa1-tests/extra/mergesort.py @@ -0,0 +1,62 @@ +def append(a: [int], k: int) -> [int]: + return a + [k] + + +def extend(a: [int], b: [int], b_start: int, b_end: int) -> [int]: + extended: [int] = None + i: int = 0 + + extended = a + i = b_start + while i < b_end: + extended = append(extended, b[i]) + i = i + 1 + return extended + + +def merge(left: [int], right: [int]) -> [int]: + merged: [int] = None + i: int = 0 + j: int = 0 + + merged = [] + while i < len(left) and j < len(right): + if left[i] < right[j]: + merged = append(merged, left[i]) + i = i + 1 + else: + merged = append(merged, right[j]) + j = j + 1 + + if i < len(left): + merged = extend(merged, left, i, len(left)) + if j < len(right): + merged = extend(merged, right, j, len(right)) + + return merged + + +def mergesort(a: [int]) -> [int]: + mid: int = 0 + left: [int] = None + right: [int] = None + + if len(a) < 2: + return a + + mid = len(a) // 2 + left = extend([], a, 0, mid) + right = extend([], a, mid, len(a)) + + left = mergesort(left) + right = mergesort(right) + return merge(left, right) + + +initial: [int] = None +ordered: [int] = None + +initial = [2, 7, 3, 11, 5] +ordered = mergesort(initial) + +print(ordered) diff --git a/pa1-tests/extra/mergesort.py.ast b/pa1-tests/extra/mergesort.py.ast new file mode 100644 index 0000000..f11bb0f --- /dev/null +++ b/pa1-tests/extra/mergesort.py.ast @@ -0,0 +1,1262 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 62, 15 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 10 ], + "name" : "append" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 12, 1, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 12, 1, 12 ], + "name" : "a" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 15, 1, 19 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 16, 1, 18 ], + "className" : "int" + } + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 22, 1, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 22, 1, 22 ], + "name" : "k" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 25, 1, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ListType", + "location" : [ 1, 33, 1, 37 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 34, 1, 36 ], + "className" : "int" + } + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 18 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 2, 12, 2, 18 ], + "left" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 12 ], + "name" : "a" + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 2, 16, 2, 18 ], + "elements" : [ { + "kind" : "Identifier", + "location" : [ 2, 17, 2, 17 ], + "name" : "k" + } ] + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 14, 20 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 10 ], + "name" : "extend" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 12, 5, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 12, 5, 12 ], + "name" : "a" + }, + "type" : { + "kind" : "ListType", + "location" : [ 5, 15, 5, 19 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 5, 16, 5, 18 ], + "className" : "int" + } + } + }, { + "kind" : "TypedVar", + "location" : [ 5, 22, 5, 29 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 22, 5, 22 ], + "name" : "b" + }, + "type" : { + "kind" : "ListType", + "location" : [ 5, 25, 5, 29 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 5, 26, 5, 28 ], + "className" : "int" + } + } + }, { + "kind" : "TypedVar", + "location" : [ 5, 32, 5, 43 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 32, 5, 38 ], + "name" : "b_start" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 41, 5, 43 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 5, 46, 5, 55 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 46, 5, 50 ], + "name" : "b_end" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 53, 5, 55 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ListType", + "location" : [ 5, 61, 5, 65 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 5, 62, 5, 64 ], + "className" : "int" + } + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 26 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 12 ], + "name" : "extended" + }, + "type" : { + "kind" : "ListType", + "location" : [ 6, 15, 6, 19 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 6, 16, 6, 18 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 6, 23, 6, 26 ] + } + }, { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 8, 7, 10 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 14, 7, 14 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 9, 5, 9, 16 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 12 ], + "name" : "extended" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 9, 16, 9, 16 ], + "name" : "a" + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 5, 10, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 5, 10, 5 ], + "name" : "i" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 15 ], + "name" : "b_start" + } + }, { + "kind" : "WhileStmt", + "location" : [ 11, 5, 14, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 11, 11, 11, 19 ], + "left" : { + "kind" : "Identifier", + "location" : [ 11, 11, 11, 11 ], + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "Identifier", + "location" : [ 11, 15, 11, 19 ], + "name" : "b_end" + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 12, 9, 12, 41 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 12, 9, 12, 16 ], + "name" : "extended" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 12, 20, 12, 41 ], + "function" : { + "kind" : "Identifier", + "location" : [ 12, 20, 12, 25 ], + "name" : "append" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 12, 27, 12, 34 ], + "name" : "extended" + }, { + "kind" : "IndexExpr", + "location" : [ 12, 37, 12, 40 ], + "list" : { + "kind" : "Identifier", + "location" : [ 12, 37, 12, 37 ], + "name" : "b" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 12, 39, 12, 39 ], + "name" : "i" + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 13, 9, 13, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 13, 9, 13, 9 ], + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 13, 13, 13, 17 ], + "left" : { + "kind" : "Identifier", + "location" : [ 13, 13, 13, 13 ], + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 17, 13, 17 ], + "value" : 1 + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 14, 5, 14, 19 ], + "value" : { + "kind" : "Identifier", + "location" : [ 14, 12, 14, 19 ], + "name" : "extended" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 17, 1, 36, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 9 ], + "name" : "merge" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 17, 11, 17, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 11, 17, 14 ], + "name" : "left" + }, + "type" : { + "kind" : "ListType", + "location" : [ 17, 17, 17, 21 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 17, 18, 17, 20 ], + "className" : "int" + } + } + }, { + "kind" : "TypedVar", + "location" : [ 17, 24, 17, 35 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 24, 17, 28 ], + "name" : "right" + }, + "type" : { + "kind" : "ListType", + "location" : [ 17, 31, 17, 35 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 17, 32, 17, 34 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ListType", + "location" : [ 17, 41, 17, 45 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 17, 42, 17, 44 ], + "className" : "int" + } + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 18, 5, 18, 24 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 18, 5, 18, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 18, 5, 18, 10 ], + "name" : "merged" + }, + "type" : { + "kind" : "ListType", + "location" : [ 18, 13, 18, 17 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 18, 14, 18, 16 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 18, 21, 18, 24 ] + } + }, { + "kind" : "VarDef", + "location" : [ 19, 5, 19, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 19, 5, 19, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 5, 19, 5 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 8, 19, 10 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 19, 14, 19, 14 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 20, 5, 20, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 20, 5, 20, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 20, 5, 20, 5 ], + "name" : "j" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 20, 8, 20, 10 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 20, 14, 20, 14 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 22, 5, 22, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 10 ], + "name" : "merged" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 22, 14, 22, 15 ], + "elements" : [ ] + } + }, { + "kind" : "WhileStmt", + "location" : [ 23, 5, 31, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 23, 11, 23, 42 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 23, 11, 23, 23 ], + "left" : { + "kind" : "Identifier", + "location" : [ 23, 11, 23, 11 ], + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "CallExpr", + "location" : [ 23, 15, 23, 23 ], + "function" : { + "kind" : "Identifier", + "location" : [ 23, 15, 23, 17 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 23, 19, 23, 22 ], + "name" : "left" + } ] + } + }, + "operator" : "and", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 23, 29, 23, 42 ], + "left" : { + "kind" : "Identifier", + "location" : [ 23, 29, 23, 29 ], + "name" : "j" + }, + "operator" : "<", + "right" : { + "kind" : "CallExpr", + "location" : [ 23, 33, 23, 42 ], + "function" : { + "kind" : "Identifier", + "location" : [ 23, 33, 23, 35 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 23, 37, 23, 41 ], + "name" : "right" + } ] + } + } + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 24, 9, 31, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 24, 12, 24, 29 ], + "left" : { + "kind" : "IndexExpr", + "location" : [ 24, 12, 24, 18 ], + "list" : { + "kind" : "Identifier", + "location" : [ 24, 12, 24, 15 ], + "name" : "left" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 24, 17, 24, 17 ], + "name" : "i" + } + }, + "operator" : "<", + "right" : { + "kind" : "IndexExpr", + "location" : [ 24, 22, 24, 29 ], + "list" : { + "kind" : "Identifier", + "location" : [ 24, 22, 24, 26 ], + "name" : "right" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 24, 28, 24, 28 ], + "name" : "j" + } + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 25, 13, 25, 44 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 25, 13, 25, 18 ], + "name" : "merged" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 25, 22, 25, 44 ], + "function" : { + "kind" : "Identifier", + "location" : [ 25, 22, 25, 27 ], + "name" : "append" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 25, 29, 25, 34 ], + "name" : "merged" + }, { + "kind" : "IndexExpr", + "location" : [ 25, 37, 25, 43 ], + "list" : { + "kind" : "Identifier", + "location" : [ 25, 37, 25, 40 ], + "name" : "left" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 25, 42, 25, 42 ], + "name" : "i" + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 26, 13, 26, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 26, 13, 26, 13 ], + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 26, 17, 26, 21 ], + "left" : { + "kind" : "Identifier", + "location" : [ 26, 17, 26, 17 ], + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 26, 21, 26, 21 ], + "value" : 1 + } + } + } ], + "elseBody" : [ { + "kind" : "AssignStmt", + "location" : [ 28, 13, 28, 45 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 28, 13, 28, 18 ], + "name" : "merged" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 28, 22, 28, 45 ], + "function" : { + "kind" : "Identifier", + "location" : [ 28, 22, 28, 27 ], + "name" : "append" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 28, 29, 28, 34 ], + "name" : "merged" + }, { + "kind" : "IndexExpr", + "location" : [ 28, 37, 28, 44 ], + "list" : { + "kind" : "Identifier", + "location" : [ 28, 37, 28, 41 ], + "name" : "right" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 28, 43, 28, 43 ], + "name" : "j" + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 29, 13, 29, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 29, 13, 29, 13 ], + "name" : "j" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 29, 17, 29, 21 ], + "left" : { + "kind" : "Identifier", + "location" : [ 29, 17, 29, 17 ], + "name" : "j" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 29, 21, 29, 21 ], + "value" : 1 + } + } + } ] + } ] + }, { + "kind" : "IfStmt", + "location" : [ 31, 5, 33, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 31, 8, 31, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 31, 8, 31, 8 ], + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "CallExpr", + "location" : [ 31, 12, 31, 20 ], + "function" : { + "kind" : "Identifier", + "location" : [ 31, 12, 31, 14 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 31, 16, 31, 19 ], + "name" : "left" + } ] + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 32, 9, 32, 51 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 32, 9, 32, 14 ], + "name" : "merged" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 32, 18, 32, 51 ], + "function" : { + "kind" : "Identifier", + "location" : [ 32, 18, 32, 23 ], + "name" : "extend" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 32, 25, 32, 30 ], + "name" : "merged" + }, { + "kind" : "Identifier", + "location" : [ 32, 33, 32, 36 ], + "name" : "left" + }, { + "kind" : "Identifier", + "location" : [ 32, 39, 32, 39 ], + "name" : "i" + }, { + "kind" : "CallExpr", + "location" : [ 32, 42, 32, 50 ], + "function" : { + "kind" : "Identifier", + "location" : [ 32, 42, 32, 44 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 32, 46, 32, 49 ], + "name" : "left" + } ] + } ] + } + } ], + "elseBody" : [ ] + }, { + "kind" : "IfStmt", + "location" : [ 33, 5, 36, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 33, 8, 33, 21 ], + "left" : { + "kind" : "Identifier", + "location" : [ 33, 8, 33, 8 ], + "name" : "j" + }, + "operator" : "<", + "right" : { + "kind" : "CallExpr", + "location" : [ 33, 12, 33, 21 ], + "function" : { + "kind" : "Identifier", + "location" : [ 33, 12, 33, 14 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 33, 16, 33, 20 ], + "name" : "right" + } ] + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 34, 9, 34, 53 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 34, 9, 34, 14 ], + "name" : "merged" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 34, 18, 34, 53 ], + "function" : { + "kind" : "Identifier", + "location" : [ 34, 18, 34, 23 ], + "name" : "extend" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 34, 25, 34, 30 ], + "name" : "merged" + }, { + "kind" : "Identifier", + "location" : [ 34, 33, 34, 37 ], + "name" : "right" + }, { + "kind" : "Identifier", + "location" : [ 34, 40, 34, 40 ], + "name" : "j" + }, { + "kind" : "CallExpr", + "location" : [ 34, 43, 34, 52 ], + "function" : { + "kind" : "Identifier", + "location" : [ 34, 43, 34, 45 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 34, 47, 34, 51 ], + "name" : "right" + } ] + } ] + } + } ], + "elseBody" : [ ] + }, { + "kind" : "ReturnStmt", + "location" : [ 36, 5, 36, 17 ], + "value" : { + "kind" : "Identifier", + "location" : [ 36, 12, 36, 17 ], + "name" : "merged" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 39, 1, 53, 30 ], + "name" : { + "kind" : "Identifier", + "location" : [ 39, 5, 39, 13 ], + "name" : "mergesort" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 39, 15, 39, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 39, 15, 39, 15 ], + "name" : "a" + }, + "type" : { + "kind" : "ListType", + "location" : [ 39, 18, 39, 22 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 39, 19, 39, 21 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ListType", + "location" : [ 39, 28, 39, 32 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 39, 29, 39, 31 ], + "className" : "int" + } + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 40, 5, 40, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 40, 5, 40, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 40, 5, 40, 7 ], + "name" : "mid" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 40, 10, 40, 12 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 40, 16, 40, 16 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 41, 5, 41, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 41, 5, 41, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 41, 5, 41, 8 ], + "name" : "left" + }, + "type" : { + "kind" : "ListType", + "location" : [ 41, 11, 41, 15 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 41, 12, 41, 14 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 41, 19, 41, 22 ] + } + }, { + "kind" : "VarDef", + "location" : [ 42, 5, 42, 23 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 42, 5, 42, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 42, 5, 42, 9 ], + "name" : "right" + }, + "type" : { + "kind" : "ListType", + "location" : [ 42, 12, 42, 16 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 42, 13, 42, 15 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 42, 20, 42, 23 ] + } + } ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 44, 5, 47, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 44, 8, 44, 17 ], + "left" : { + "kind" : "CallExpr", + "location" : [ 44, 8, 44, 13 ], + "function" : { + "kind" : "Identifier", + "location" : [ 44, 8, 44, 10 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 44, 12, 44, 12 ], + "name" : "a" + } ] + }, + "operator" : "<", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 44, 17, 44, 17 ], + "value" : 2 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 45, 9, 45, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 45, 16, 45, 16 ], + "name" : "a" + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 47, 5, 47, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 47, 5, 47, 7 ], + "name" : "mid" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 47, 11, 47, 21 ], + "left" : { + "kind" : "CallExpr", + "location" : [ 47, 11, 47, 16 ], + "function" : { + "kind" : "Identifier", + "location" : [ 47, 11, 47, 13 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 47, 15, 47, 15 ], + "name" : "a" + } ] + }, + "operator" : "//", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 47, 21, 47, 21 ], + "value" : 2 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 48, 5, 48, 32 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 48, 5, 48, 8 ], + "name" : "left" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 48, 12, 48, 32 ], + "function" : { + "kind" : "Identifier", + "location" : [ 48, 12, 48, 17 ], + "name" : "extend" + }, + "args" : [ { + "kind" : "ListExpr", + "location" : [ 48, 19, 48, 20 ], + "elements" : [ ] + }, { + "kind" : "Identifier", + "location" : [ 48, 23, 48, 23 ], + "name" : "a" + }, { + "kind" : "IntegerLiteral", + "location" : [ 48, 26, 48, 26 ], + "value" : 0 + }, { + "kind" : "Identifier", + "location" : [ 48, 29, 48, 31 ], + "name" : "mid" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 49, 5, 49, 38 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 49, 5, 49, 9 ], + "name" : "right" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 49, 13, 49, 38 ], + "function" : { + "kind" : "Identifier", + "location" : [ 49, 13, 49, 18 ], + "name" : "extend" + }, + "args" : [ { + "kind" : "ListExpr", + "location" : [ 49, 20, 49, 21 ], + "elements" : [ ] + }, { + "kind" : "Identifier", + "location" : [ 49, 24, 49, 24 ], + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 49, 27, 49, 29 ], + "name" : "mid" + }, { + "kind" : "CallExpr", + "location" : [ 49, 32, 49, 37 ], + "function" : { + "kind" : "Identifier", + "location" : [ 49, 32, 49, 34 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 49, 36, 49, 36 ], + "name" : "a" + } ] + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 51, 5, 51, 26 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 51, 5, 51, 8 ], + "name" : "left" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 51, 12, 51, 26 ], + "function" : { + "kind" : "Identifier", + "location" : [ 51, 12, 51, 20 ], + "name" : "mergesort" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 51, 22, 51, 25 ], + "name" : "left" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 52, 5, 52, 28 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 52, 5, 52, 9 ], + "name" : "right" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 52, 13, 52, 28 ], + "function" : { + "kind" : "Identifier", + "location" : [ 52, 13, 52, 21 ], + "name" : "mergesort" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 52, 23, 52, 27 ], + "name" : "right" + } ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 53, 5, 53, 29 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 53, 12, 53, 29 ], + "function" : { + "kind" : "Identifier", + "location" : [ 53, 12, 53, 16 ], + "name" : "merge" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 53, 18, 53, 21 ], + "name" : "left" + }, { + "kind" : "Identifier", + "location" : [ 53, 24, 53, 28 ], + "name" : "right" + } ] + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 56, 1, 56, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 56, 1, 56, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 56, 1, 56, 7 ], + "name" : "initial" + }, + "type" : { + "kind" : "ListType", + "location" : [ 56, 10, 56, 14 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 56, 11, 56, 13 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 56, 18, 56, 21 ] + } + }, { + "kind" : "VarDef", + "location" : [ 57, 1, 57, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 57, 1, 57, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 57, 1, 57, 7 ], + "name" : "ordered" + }, + "type" : { + "kind" : "ListType", + "location" : [ 57, 10, 57, 14 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 57, 11, 57, 13 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 57, 18, 57, 21 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 59, 1, 59, 26 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 59, 1, 59, 7 ], + "name" : "initial" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 59, 11, 59, 26 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 59, 12, 59, 12 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 59, 15, 59, 15 ], + "value" : 7 + }, { + "kind" : "IntegerLiteral", + "location" : [ 59, 18, 59, 18 ], + "value" : 3 + }, { + "kind" : "IntegerLiteral", + "location" : [ 59, 21, 59, 22 ], + "value" : 11 + }, { + "kind" : "IntegerLiteral", + "location" : [ 59, 25, 59, 25 ], + "value" : 5 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 60, 1, 60, 28 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 60, 1, 60, 7 ], + "name" : "ordered" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 60, 11, 60, 28 ], + "function" : { + "kind" : "Identifier", + "location" : [ 60, 11, 60, 19 ], + "name" : "mergesort" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 60, 21, 60, 27 ], + "name" : "initial" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 62, 1, 62, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 62, 1, 62, 14 ], + "function" : { + "kind" : "Identifier", + "location" : [ 62, 1, 62, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 62, 7, 62, 13 ], + "name" : "ordered" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/extra/nesting.py b/pa1-tests/extra/nesting.py new file mode 100644 index 0000000..f82976a --- /dev/null +++ b/pa1-tests/extra/nesting.py @@ -0,0 +1,45 @@ +class s(object): + t: object = None + +class r(object): + sobj: s = None + +class q(object): + robj: r = None + +class p(q): + def f(self: "p") -> object: + return self.robj.sobj.t + +def a() -> int: + def b() -> int: + def c() -> int: + def d() -> int: + def e() -> int: + return 1 + return e() + return d() + return c() + return b() + +def w(): + def x(): + def y(): + def z(): + 4 + 3 + 2 + 1 + +xs: [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[int]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] = None +xs = [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[1]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]] + +if 1: + if 2: + if 3: + if 4: + True + elif -3: + False +else: + False diff --git a/pa1-tests/extra/nesting.py.ast b/pa1-tests/extra/nesting.py.ast new file mode 100644 index 0000000..d3157cb --- /dev/null +++ b/pa1-tests/extra/nesting.py.ast @@ -0,0 +1,799 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 46, 1 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "s" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 20 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "t" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 8, 2, 13 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 17, 2, 20 ] + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 5, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "r" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 5, 5, 5, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 5, 5, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 8 ], + "name" : "sobj" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 11, 5, 11 ], + "className" : "s" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 5, 15, 5, 18 ] + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 8, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "q" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 8, 5, 8, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 8, 5, 8, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 8 ], + "name" : "robj" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 11, 8, 11 ], + "className" : "r" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 8, 15, 8, 18 ] + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 10, 1, 14, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 10, 7, 10, 7 ], + "name" : "p" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 9 ], + "name" : "q" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 11, 5, 12, 32 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "f" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 11, 11, 11, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 11, 11, 14 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 17, 11, 19 ], + "className" : "p" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 11, 25, 11, 30 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 12, 9, 12, 31 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 12, 16, 12, 31 ], + "object" : { + "kind" : "MemberExpr", + "location" : [ 12, 16, 12, 29 ], + "object" : { + "kind" : "MemberExpr", + "location" : [ 12, 16, 12, 24 ], + "object" : { + "kind" : "Identifier", + "location" : [ 12, 16, 12, 19 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 12, 21, 12, 24 ], + "name" : "robj" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 12, 26, 12, 29 ], + "name" : "sobj" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 12, 31, 12, 31 ], + "name" : "t" + } + } + } ] + } ] + }, { + "kind" : "FuncDef", + "location" : [ 14, 1, 23, 15 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 5, 14, 5 ], + "name" : "a" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 12, 14, 14 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 15, 5, 22, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 9 ], + "name" : "b" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 15, 16, 15, 18 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 16, 9, 21, 23 ], + "name" : { + "kind" : "Identifier", + "location" : [ 16, 13, 16, 13 ], + "name" : "c" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 16, 20, 16, 22 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 17, 13, 20, 27 ], + "name" : { + "kind" : "Identifier", + "location" : [ 17, 17, 17, 17 ], + "name" : "d" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 17, 24, 17, 26 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 18, 17, 19, 29 ], + "name" : { + "kind" : "Identifier", + "location" : [ 18, 21, 18, 21 ], + "name" : "e" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 18, 28, 18, 30 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 19, 21, 19, 28 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 19, 28, 19, 28 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 20, 17, 20, 26 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 20, 24, 20, 26 ], + "function" : { + "kind" : "Identifier", + "location" : [ 20, 24, 20, 24 ], + "name" : "e" + }, + "args" : [ ] + } + } ] + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 21, 13, 21, 22 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 21, 20, 21, 22 ], + "function" : { + "kind" : "Identifier", + "location" : [ 21, 20, 21, 20 ], + "name" : "d" + }, + "args" : [ ] + } + } ] + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 22, 9, 22, 18 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 22, 16, 22, 18 ], + "function" : { + "kind" : "Identifier", + "location" : [ 22, 16, 22, 16 ], + "name" : "c" + }, + "args" : [ ] + } + } ] + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 23, 5, 23, 14 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 23, 12, 23, 14 ], + "function" : { + "kind" : "Identifier", + "location" : [ 23, 12, 23, 12 ], + "name" : "b" + }, + "args" : [ ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 25, 1, 32, 3 ], + "name" : { + "kind" : "Identifier", + "location" : [ 25, 5, 25, 5 ], + "name" : "w" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 25, 8, 25, 8 ], + "className" : "" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 26, 2, 31, 5 ], + "name" : { + "kind" : "Identifier", + "location" : [ 26, 6, 26, 6 ], + "name" : "x" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 26, 9, 26, 9 ], + "className" : "" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 27, 4, 30, 8 ], + "name" : { + "kind" : "Identifier", + "location" : [ 27, 8, 27, 8 ], + "name" : "y" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 27, 11, 27, 11 ], + "className" : "" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 28, 7, 29, 12 ], + "name" : { + "kind" : "Identifier", + "location" : [ 28, 11, 28, 11 ], + "name" : "z" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 28, 14, 28, 14 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 29, 11, 29, 11 ], + "expr" : { + "kind" : "IntegerLiteral", + "location" : [ 29, 11, 29, 11 ], + "value" : 4 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 30, 7, 30, 7 ], + "expr" : { + "kind" : "IntegerLiteral", + "location" : [ 30, 7, 30, 7 ], + "value" : 3 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 31, 4, 31, 4 ], + "expr" : { + "kind" : "IntegerLiteral", + "location" : [ 31, 4, 31, 4 ], + "value" : 2 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 32, 2, 32, 2 ], + "expr" : { + "kind" : "IntegerLiteral", + "location" : [ 32, 2, 32, 2 ], + "value" : 1 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 34, 1, 34, 78 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 34, 1, 34, 71 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 34, 1, 34, 2 ], + "name" : "xs" + }, + "type" : { + "kind" : "ListType", + "location" : [ 34, 5, 34, 71 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 6, 34, 70 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 7, 34, 69 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 8, 34, 68 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 9, 34, 67 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 10, 34, 66 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 11, 34, 65 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 12, 34, 64 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 13, 34, 63 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 14, 34, 62 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 15, 34, 61 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 16, 34, 60 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 17, 34, 59 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 18, 34, 58 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 19, 34, 57 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 20, 34, 56 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 21, 34, 55 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 22, 34, 54 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 23, 34, 53 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 24, 34, 52 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 25, 34, 51 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 26, 34, 50 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 27, 34, 49 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 28, 34, 48 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 29, 34, 47 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 30, 34, 46 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 31, 34, 45 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 32, 34, 44 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 33, 34, 43 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 34, 34, 42 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 35, 34, 41 ], + "elementType" : { + "kind" : "ListType", + "location" : [ 34, 36, 34, 40 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 34, 37, 34, 39 ], + "className" : "int" + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 34, 75, 34, 78 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 35, 1, 35, 70 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 35, 1, 35, 2 ], + "name" : "xs" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 35, 6, 35, 70 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 7, 35, 69 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 8, 35, 68 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 9, 35, 67 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 10, 35, 66 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 11, 35, 65 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 12, 35, 64 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 13, 35, 63 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 14, 35, 62 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 15, 35, 61 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 16, 35, 60 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 17, 35, 59 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 18, 35, 58 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 19, 35, 57 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 20, 35, 56 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 21, 35, 55 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 22, 35, 54 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 23, 35, 53 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 24, 35, 52 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 25, 35, 51 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 26, 35, 50 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 27, 35, 49 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 28, 35, 48 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 29, 35, 47 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 30, 35, 46 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 31, 35, 45 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 32, 35, 44 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 33, 35, 43 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 34, 35, 42 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 35, 35, 41 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 36, 35, 40 ], + "elements" : [ { + "kind" : "ListExpr", + "location" : [ 35, 37, 35, 39 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 35, 38, 35, 38 ], + "value" : 1 + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } + }, { + "kind" : "IfStmt", + "location" : [ 37, 1, 46, 1 ], + "condition" : { + "kind" : "IntegerLiteral", + "location" : [ 37, 4, 37, 4 ], + "value" : 1 + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 38, 5, 44, 0 ], + "condition" : { + "kind" : "IntegerLiteral", + "location" : [ 38, 8, 38, 8 ], + "value" : 2 + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 39, 9, 44, 0 ], + "condition" : { + "kind" : "IntegerLiteral", + "location" : [ 39, 12, 39, 12 ], + "value" : 3 + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 40, 13, 42, 8 ], + "condition" : { + "kind" : "IntegerLiteral", + "location" : [ 40, 16, 40, 16 ], + "value" : 4 + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 41, 17, 41, 20 ], + "expr" : { + "kind" : "BooleanLiteral", + "location" : [ 41, 17, 41, 20 ], + "value" : true + } + } ], + "elseBody" : [ ] + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 42, 9, 44, 0 ], + "condition" : { + "kind" : "UnaryExpr", + "location" : [ 42, 14, 42, 15 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 42, 15, 42, 15 ], + "value" : 3 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 43, 13, 43, 17 ], + "expr" : { + "kind" : "BooleanLiteral", + "location" : [ 43, 13, 43, 17 ], + "value" : false + } + } ], + "elseBody" : [ ] + } ] + } ], + "elseBody" : [ ] + } ], + "elseBody" : [ { + "kind" : "ExprStmt", + "location" : [ 45, 5, 45, 9 ], + "expr" : { + "kind" : "BooleanLiteral", + "location" : [ 45, 5, 45, 9 ], + "value" : false + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa1-tests/run-tests.sh b/pa1-tests/run-tests.sh new file mode 100755 index 0000000..84a9b70 --- /dev/null +++ b/pa1-tests/run-tests.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +JAVA="java -cp pa1-tests/chocopy-ref.jar:target/assignment.jar chocopy.ChocoPy" + +echo "# CORE TESTS" +${JAVA} --pass=s --test --dir pa1-tests/core + +echo +echo "# EXTRA TESTS" +${JAVA} --pass=s --test --dir pa1-tests/extra + +echo +echo "# STUDENT TESTS" +function regen_ast_and_test { + ${JAVA} --pass=r "${1}" --out "${1}.ast" 2>/dev/null 1>&2 + ${JAVA} --pass=s --test "${1}" +} +regen_ast_and_test src/test/data/pa1/student_contributed/good.py +regen_ast_and_test src/test/data/pa1/student_contributed/bad.py diff --git a/pa2-tests/README.md b/pa2-tests/README.md new file mode 100644 index 0000000..51f2eec --- /dev/null +++ b/pa2-tests/README.md @@ -0,0 +1,24 @@ +# Tests for PA2: ChocoPy Semantic Analysis + +Clone a student repository: +``` +TEAM="team" +git clone --branch=pa2final \ + https://github.com/nyu-compiler-construction/pa2-chocopy-semantic-analysis-${TEAM} +``` + +Build it: +``` +cd pa2-chocopy-semantic-analysis-${TEAM} +mvn clean package +``` + +Clone the tests _into_ the student repository: +``` +git clone https://github.com/nyu-compiler-construction/pa2-tests +``` + +Run the tests: +``` +./pa2-tests/run-tests.sh +``` diff --git a/pa2-tests/chocopy-ref.jar b/pa2-tests/chocopy-ref.jar new file mode 100644 index 0000000..a497f25 Binary files /dev/null and b/pa2-tests/chocopy-ref.jar differ diff --git a/pa2-tests/core/ast_coverage.py b/pa2-tests/core/ast_coverage.py new file mode 100644 index 0000000..a27e796 --- /dev/null +++ b/pa2-tests/core/ast_coverage.py @@ -0,0 +1,38 @@ +count:int = 0 + +def foo(s: str) -> int: + return len(s) + +class bar(object): + p: bool = True + + def baz(self:"bar", xx: [int]) -> str: + global count + x:int = 0 + y:int = 1 + + def qux(y: int) -> object: + nonlocal x + if x > y: + x = -1 + + for x in xx: + self.p = x == 2 + + qux(0) # Yay! ChocoPy + + count = count + 1 + + while x <= 0: + if self.p: + xx[0] = xx[1] + self.p = not self.p + x = x + 1 + elif foo("Long"[0]) == 1: + self.p = self is None + + return "Nope" + +print(bar().baz([1,2])) + + diff --git a/pa2-tests/core/ast_coverage.py.ast b/pa2-tests/core/ast_coverage.py.ast new file mode 100644 index 0000000..18d47cd --- /dev/null +++ b/pa2-tests/core/ast_coverage.py.ast @@ -0,0 +1,627 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 36, 24 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "name" : "count" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 7, 1, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 13, 1, 13 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 4, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 3, 9, 3, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 12, 3, 14 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 20, 3, 22 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 4, 5, 4, 17 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 4, 12, 4, 17 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 12, 4, 14 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 4, 16, 4, 16 ], + "name" : "s" + } ] + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 6, 1, 36, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 6, 7, 6, 9 ], + "name" : "bar" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 6, 11, 6, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "p" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 8, 7, 11 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 15, 7, 18 ], + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 34, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 9, 13, 9, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 18, 9, 22 ], + "className" : "bar" + } + }, { + "kind" : "TypedVar", + "location" : [ 9, 25, 9, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 25, 9, 26 ], + "name" : "xx" + }, + "type" : { + "kind" : "ListType", + "location" : [ 9, 29, 9, 33 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 9, 30, 9, 32 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 39, 9, 41 ], + "className" : "str" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 10, 9, 10, 20 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 10, 16, 10, 20 ], + "name" : "count" + } + }, { + "kind" : "VarDef", + "location" : [ 11, 9, 11, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 9, 11, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 11, 11, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 17, 11, 17 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 12, 9, 12, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 9, 12, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 9, 12, 9 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 11, 12, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 17, 12, 17 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 14, 9, 19, 8 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 13, 14, 15 ], + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 17, 14, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 17, 14, 17 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 20, 14, 22 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 28, 14, 33 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 15, 13, 15, 22 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 15, 22, 15, 22 ], + "name" : "x" + } + } ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 16, 13, 19, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 16, 16, 16, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 16 ], + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "Identifier", + "location" : [ 16, 20, 16, 20 ], + "name" : "y" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 17, 17, 17, 22 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 17, 17, 17 ], + "name" : "x" + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 17, 21, 17, 22 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 17, 22, 17, 22 ], + "value" : 1 + } + } + } ], + "elseBody" : [ ] + } ] + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 19, 9, 22, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 13, 19, 13 ], + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 19, 18, 19, 19 ], + "name" : "xx" + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 20, 13, 20, 27 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 20, 13, 20, 18 ], + "object" : { + "kind" : "Identifier", + "location" : [ 20, 13, 20, 16 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 18, 20, 18 ], + "name" : "p" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 20, 22, 20, 27 ], + "left" : { + "kind" : "Identifier", + "location" : [ 20, 22, 20, 22 ], + "name" : "x" + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 20, 27, 20, 27 ], + "value" : 2 + } + } + } ] + }, { + "kind" : "ExprStmt", + "location" : [ 22, 9, 22, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 22, 9, 22, 14 ], + "function" : { + "kind" : "Identifier", + "location" : [ 22, 9, 22, 11 ], + "name" : "qux" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 22, 13, 22, 13 ], + "value" : 0 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 24, 9, 24, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 24, 9, 24, 13 ], + "name" : "count" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 24, 17, 24, 25 ], + "left" : { + "kind" : "Identifier", + "location" : [ 24, 17, 24, 21 ], + "name" : "count" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 25, 24, 25 ], + "value" : 1 + } + } + }, { + "kind" : "WhileStmt", + "location" : [ 26, 9, 34, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 26, 15, 26, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 26, 15, 26, 15 ], + "name" : "x" + }, + "operator" : "<=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 26, 20, 26, 20 ], + "value" : 0 + } + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 27, 13, 34, 8 ], + "condition" : { + "kind" : "MemberExpr", + "location" : [ 27, 16, 27, 21 ], + "object" : { + "kind" : "Identifier", + "location" : [ 27, 16, 27, 19 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 21, 27, 21 ], + "name" : "p" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 28, 17, 28, 29 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 28, 17, 28, 21 ], + "list" : { + "kind" : "Identifier", + "location" : [ 28, 17, 28, 18 ], + "name" : "xx" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 28, 20, 28, 20 ], + "value" : 0 + } + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 28, 25, 28, 29 ], + "list" : { + "kind" : "Identifier", + "location" : [ 28, 25, 28, 26 ], + "name" : "xx" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 28, 28, 28, 28 ], + "value" : 1 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 29, 17, 29, 35 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 29, 17, 29, 22 ], + "object" : { + "kind" : "Identifier", + "location" : [ 29, 17, 29, 20 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 22, 29, 22 ], + "name" : "p" + } + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 29, 26, 29, 35 ], + "operator" : "not", + "operand" : { + "kind" : "MemberExpr", + "location" : [ 29, 30, 29, 35 ], + "object" : { + "kind" : "Identifier", + "location" : [ 29, 30, 29, 33 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 35, 29, 35 ], + "name" : "p" + } + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 30, 17, 30, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 30, 17, 30, 17 ], + "name" : "x" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 30, 21, 30, 25 ], + "left" : { + "kind" : "Identifier", + "location" : [ 30, 21, 30, 21 ], + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 30, 25, 30, 25 ], + "value" : 1 + } + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 31, 13, 34, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 31, 18, 31, 36 ], + "left" : { + "kind" : "CallExpr", + "location" : [ 31, 18, 31, 31 ], + "function" : { + "kind" : "Identifier", + "location" : [ 31, 18, 31, 20 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 31, 22, 31, 30 ], + "list" : { + "kind" : "StringLiteral", + "location" : [ 31, 22, 31, 27 ], + "value" : "Long" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 31, 29, 31, 29 ], + "value" : 0 + } + } ] + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 31, 36, 31, 36 ], + "value" : 1 + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 32, 17, 32, 37 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 32, 17, 32, 22 ], + "object" : { + "kind" : "Identifier", + "location" : [ 32, 17, 32, 20 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 32, 22, 32, 22 ], + "name" : "p" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 32, 26, 32, 37 ], + "left" : { + "kind" : "Identifier", + "location" : [ 32, 26, 32, 29 ], + "name" : "self" + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 32, 34, 32, 37 ] + } + } + } ], + "elseBody" : [ ] + } ] + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 34, 9, 34, 21 ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 34, 16, 34, 21 ], + "value" : "Nope" + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 36, 1, 36, 23 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 36, 1, 36, 23 ], + "function" : { + "kind" : "Identifier", + "location" : [ 36, 1, 36, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 36, 7, 36, 22 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 36, 7, 36, 15 ], + "object" : { + "kind" : "CallExpr", + "location" : [ 36, 7, 36, 11 ], + "function" : { + "kind" : "Identifier", + "location" : [ 36, 7, 36, 9 ], + "name" : "bar" + }, + "args" : [ ] + }, + "member" : { + "kind" : "Identifier", + "location" : [ 36, 13, 36, 15 ], + "name" : "baz" + } + }, + "args" : [ { + "kind" : "ListExpr", + "location" : [ 36, 17, 36, 21 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 36, 18, 36, 18 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 36, 20, 36, 20 ], + "value" : 2 + } ] + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/ast_coverage.py.ast.typed b/pa2-tests/core/ast_coverage.py.ast.typed new file mode 100644 index 0000000..709f895 --- /dev/null +++ b/pa2-tests/core/ast_coverage.py.ast.typed @@ -0,0 +1,952 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 36, 24 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "name" : "count" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 7, 1, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 13, 1, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 4, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 3, 9, 3, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 12, 3, 14 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 20, 3, 22 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 4, 5, 4, 17 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 4, 12, 4, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 12, 4, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 4, 16, 4, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + } ] + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 6, 1, 36, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 6, 7, 6, 9 ], + "name" : "bar" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 6, 11, 6, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "p" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 8, 7, 11 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 15, 7, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 34, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 9, 13, 9, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 18, 9, 22 ], + "className" : "bar" + } + }, { + "kind" : "TypedVar", + "location" : [ 9, 25, 9, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 25, 9, 26 ], + "name" : "xx" + }, + "type" : { + "kind" : "ListType", + "location" : [ 9, 29, 9, 33 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 9, 30, 9, 32 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 39, 9, 41 ], + "className" : "str" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 10, 9, 10, 20 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 10, 16, 10, 20 ], + "name" : "count" + } + }, { + "kind" : "VarDef", + "location" : [ 11, 9, 11, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 9, 11, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 11, 11, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 17, 11, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 12, 9, 12, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 9, 12, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 9, 12, 9 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 11, 12, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 17, 12, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 14, 9, 19, 8 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 13, 14, 15 ], + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 17, 14, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 17, 14, 17 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 20, 14, 22 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 28, 14, 33 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 15, 13, 15, 22 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 15, 22, 15, 22 ], + "name" : "x" + } + } ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 16, 13, 19, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 16, 16, 16, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "Identifier", + "location" : [ 16, 20, 16, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 17, 17, 17, 22 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 17, 17, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 17, 21, 17, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 17, 22, 17, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ], + "elseBody" : [ ] + } ] + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 19, 9, 22, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 13, 19, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 19, 18, 19, 19 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "xx" + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 20, 13, 20, 27 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 20, 13, 20, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 20, 13, 20, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bar" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 18, 20, 18 ], + "name" : "p" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 20, 22, 20, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 20, 22, 20, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 20, 27, 20, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } + } ] + }, { + "kind" : "ExprStmt", + "location" : [ 22, 9, 22, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 22, 9, 22, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 22, 9, 22, 11 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "qux" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 22, 13, 22, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 24, 9, 24, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 24, 9, 24, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "count" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 24, 17, 24, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 24, 17, 24, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "count" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 25, 24, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, { + "kind" : "WhileStmt", + "location" : [ 26, 9, 34, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 26, 15, 26, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 26, 15, 26, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "<=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 26, 20, 26, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 27, 13, 34, 8 ], + "condition" : { + "kind" : "MemberExpr", + "location" : [ 27, 16, 27, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 27, 16, 27, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bar" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 21, 27, 21 ], + "name" : "p" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 28, 17, 28, 29 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 28, 17, 28, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 28, 17, 28, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "xx" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 28, 20, 28, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 28, 25, 28, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 28, 25, 28, 26 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "xx" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 28, 28, 28, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 29, 17, 29, 35 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 29, 17, 29, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 29, 17, 29, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bar" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 22, 29, 22 ], + "name" : "p" + } + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 29, 26, 29, 35 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "operator" : "not", + "operand" : { + "kind" : "MemberExpr", + "location" : [ 29, 30, 29, 35 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 29, 30, 29, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bar" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 35, 29, 35 ], + "name" : "p" + } + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 30, 17, 30, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 30, 17, 30, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 30, 21, 30, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 30, 21, 30, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 30, 25, 30, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 31, 13, 34, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 31, 18, 31, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "CallExpr", + "location" : [ 31, 18, 31, 31 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 31, 18, 31, 20 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 31, 22, 31, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "StringLiteral", + "location" : [ 31, 22, 31, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Long" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 31, 29, 31, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 31, 36, 31, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 32, 17, 32, 37 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 32, 17, 32, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 32, 17, 32, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bar" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 32, 22, 32, 22 ], + "name" : "p" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 32, 26, 32, 37 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 32, 26, 32, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bar" + }, + "name" : "self" + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 32, 34, 32, 37 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } + } ], + "elseBody" : [ ] + } ] + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 34, 9, 34, 21 ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 34, 16, 34, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Nope" + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 36, 1, 36, 23 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 36, 1, 36, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 36, 1, 36, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 36, 7, 36, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 36, 7, 36, 15 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "bar" + }, { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "object" : { + "kind" : "CallExpr", + "location" : [ 36, 7, 36, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bar" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 36, 7, 36, 9 ], + "name" : "bar" + }, + "args" : [ ] + }, + "member" : { + "kind" : "Identifier", + "location" : [ 36, 13, 36, 15 ], + "name" : "baz" + } + }, + "args" : [ { + "kind" : "ListExpr", + "location" : [ 36, 17, 36, 21 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 36, 18, 36, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 36, 20, 36, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } ] + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_assign_expr.py b/pa2-tests/core/bad_assign_expr.py new file mode 100644 index 0000000..9e68917 --- /dev/null +++ b/pa2-tests/core/bad_assign_expr.py @@ -0,0 +1,11 @@ +x:int = 0 +y:int = 0 +z:bool = False + +x = z = 1 # Only one error here (assignment to `x = 1` should succeed) +x = y = None +x = y = [] +x = a = None +x = a = [] +x = y = True + diff --git a/pa2-tests/core/bad_assign_expr.py.ast b/pa2-tests/core/bad_assign_expr.py.ast new file mode 100644 index 0000000..6651bd2 --- /dev/null +++ b/pa2-tests/core/bad_assign_expr.py.ast @@ -0,0 +1,177 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 10, 13 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 6 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 10, 3, 14 ], + "value" : false + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 9, 5, 9 ], + "value" : 1 + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "y" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 6, 9, 6, 12 ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "y" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 9, 7, 10 ], + "elements" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "a" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 8, 9, 8, 12 ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "a" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 9, 9, 9, 10 ], + "elements" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 1, 10, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 10, 5, 10, 5 ], + "name" : "y" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 10, 9, 10, 12 ], + "value" : true + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_assign_expr.py.ast.typed b/pa2-tests/core/bad_assign_expr.py.ast.typed new file mode 100644 index 0000000..2f99fae --- /dev/null +++ b/pa2-tests/core/bad_assign_expr.py.ast.typed @@ -0,0 +1,301 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 10, 13 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 6 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 10, 3, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 9 ], + "errorMsg" : "Expected type `bool`; got type `int`", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 9, 5, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 12 ], + "errorMsg" : "Expected type `int`; got type ``", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 6, 9, 6, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 10 ], + "errorMsg" : "Expected type `int`; got type ``", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 9, 7, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 12 ], + "errorMsg" : "Expected type `int`; got type ``", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "errorMsg" : "Not a variable: a", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "a" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 8, 9, 8, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 10 ], + "errorMsg" : "Expected type `int`; got type ``", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "errorMsg" : "Not a variable: a", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "a" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 9, 9, 9, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 1, 10, 12 ], + "errorMsg" : "Expected type `int`; got type `bool`", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 10, 5, 10, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 10, 9, 10, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 5, 1, 5, 9 ], + "message" : "Expected type `bool`; got type `int`" + }, { + "kind" : "CompilerError", + "location" : [ 6, 1, 6, 12 ], + "message" : "Expected type `int`; got type ``" + }, { + "kind" : "CompilerError", + "location" : [ 7, 1, 7, 10 ], + "message" : "Expected type `int`; got type ``" + }, { + "kind" : "CompilerError", + "location" : [ 8, 1, 8, 12 ], + "message" : "Expected type `int`; got type ``" + }, { + "kind" : "CompilerError", + "location" : [ 8, 5, 8, 5 ], + "message" : "Not a variable: a" + }, { + "kind" : "CompilerError", + "location" : [ 9, 1, 9, 10 ], + "message" : "Expected type `int`; got type ``" + }, { + "kind" : "CompilerError", + "location" : [ 9, 5, 9, 5 ], + "message" : "Not a variable: a" + }, { + "kind" : "CompilerError", + "location" : [ 10, 1, 10, 12 ], + "message" : "Expected type `int`; got type `bool`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_attr.py b/pa2-tests/core/bad_class_attr.py new file mode 100644 index 0000000..b30eb7c --- /dev/null +++ b/pa2-tests/core/bad_class_attr.py @@ -0,0 +1,13 @@ +class A(object): + x:int = 1 + + def foo(self:"A") -> int: + return 0 + +class B(A): + x:int = 2 # Bad + foo:str = "" # Bad + +A() + + diff --git a/pa2-tests/core/bad_class_attr.py.ast b/pa2-tests/core/bad_class_attr.py.ast new file mode 100644 index 0000000..ec25404 --- /dev/null +++ b/pa2-tests/core/bad_class_attr.py.ast @@ -0,0 +1,155 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 11, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 26, 4, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 16, 5, 16 ], + "value" : 0 + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 9, 23 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 8, 5, 8, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 8, 5, 8, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 7, 8, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 13, 8, 13 ], + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 7 ], + "name" : "foo" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 9, 9, 11 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 9, 15, 9, 16 ], + "value" : "" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 1, 11, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_attr.py.ast.typed b/pa2-tests/core/bad_class_attr.py.ast.typed new file mode 100644 index 0000000..5ea1e74 --- /dev/null +++ b/pa2-tests/core/bad_class_attr.py.ast.typed @@ -0,0 +1,165 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 11, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 26, 4, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 16, 5, 16 ], + "value" : 0 + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 9, 23 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 8, 5, 8, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 8, 5, 8, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "errorMsg" : "Cannot re-define attribute: x", + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 7, 8, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 13, 8, 13 ], + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 7 ], + "errorMsg" : "Cannot re-define attribute: foo", + "name" : "foo" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 9, 9, 11 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 9, 15, 9, 16 ], + "value" : "" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 1, 11, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 8, 5, 8, 5 ], + "message" : "Cannot re-define attribute: x" + }, { + "kind" : "CompilerError", + "location" : [ 9, 5, 9, 7 ], + "message" : "Cannot re-define attribute: foo" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_attr_type.py b/pa2-tests/core/bad_class_attr_type.py new file mode 100644 index 0000000..5a7bee7 --- /dev/null +++ b/pa2-tests/core/bad_class_attr_type.py @@ -0,0 +1,4 @@ +class A(object): + x:int = True + +A() diff --git a/pa2-tests/core/bad_class_attr_type.py.ast b/pa2-tests/core/bad_class_attr_type.py.ast new file mode 100644 index 0000000..6b9d252 --- /dev/null +++ b/pa2-tests/core/bad_class_attr_type.py.ast @@ -0,0 +1,60 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 13, 2, 16 ], + "value" : true + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_attr_type.py.ast.typed b/pa2-tests/core/bad_class_attr_type.py.ast.typed new file mode 100644 index 0000000..f0a9461 --- /dev/null +++ b/pa2-tests/core/bad_class_attr_type.py.ast.typed @@ -0,0 +1,73 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 16 ], + "errorMsg" : "Expected type `int`; got type `bool`", + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 13, 2, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 2, 5, 2, 16 ], + "message" : "Expected type `int`; got type `bool`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_init_override.py b/pa2-tests/core/bad_class_init_override.py new file mode 100644 index 0000000..ceb612c --- /dev/null +++ b/pa2-tests/core/bad_class_init_override.py @@ -0,0 +1,8 @@ +class A(object): + x:int = 1 + + def __init__(self:"A", x:int): # Bad override + pass + +A(1) + diff --git a/pa2-tests/core/bad_class_init_override.py.ast b/pa2-tests/core/bad_class_init_override.py.ast new file mode 100644 index 0000000..bdd151d --- /dev/null +++ b/pa2-tests/core/bad_class_init_override.py.ast @@ -0,0 +1,106 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 5 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 18, 4, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 18, 4, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 23, 4, 25 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 28, 4, 32 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 28, 4, 28 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 30, 4, 32 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 34, 4, 34 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 4 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 1, 7, 4 ], + "function" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "A" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 7, 3, 7, 3 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_init_override.py.ast.typed b/pa2-tests/core/bad_class_init_override.py.ast.typed new file mode 100644 index 0000000..9daa89c --- /dev/null +++ b/pa2-tests/core/bad_class_init_override.py.ast.typed @@ -0,0 +1,111 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 5 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 16 ], + "errorMsg" : "Method overridden with different type signature: __init__", + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 18, 4, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 18, 4, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 23, 4, 25 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 28, 4, 32 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 28, 4, 28 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 30, 4, 32 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 34, 4, 34 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 4 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 1, 7, 4 ], + "function" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "A" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 7, 3, 7, 3 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 4, 9, 4, 16 ], + "message" : "Method overridden with different type signature: __init__" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_init_return.py b/pa2-tests/core/bad_class_init_return.py new file mode 100644 index 0000000..cc6eb34 --- /dev/null +++ b/pa2-tests/core/bad_class_init_return.py @@ -0,0 +1,5 @@ +class A(object): + def __init__(self:"A"): + return 1 # Bad + +A() diff --git a/pa2-tests/core/bad_class_init_return.py.ast b/pa2-tests/core/bad_class_init_return.py.ast new file mode 100644 index 0000000..24e972f --- /dev/null +++ b/pa2-tests/core/bad_class_init_return.py.ast @@ -0,0 +1,75 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 5, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 5, 3, 23 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 18, 2, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 18, 2, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 23, 2, 25 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 27, 2, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 9, 3, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 16, 3, 16 ], + "value" : 1 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_init_return.py.ast.typed b/pa2-tests/core/bad_class_init_return.py.ast.typed new file mode 100644 index 0000000..cf0cde2 --- /dev/null +++ b/pa2-tests/core/bad_class_init_return.py.ast.typed @@ -0,0 +1,88 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 5, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 5, 3, 23 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 18, 2, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 18, 2, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 23, 2, 25 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 27, 2, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 9, 3, 16 ], + "errorMsg" : "Expected type ``; got type `int`", + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 16, 3, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 3, 9, 3, 16 ], + "message" : "Expected type ``; got type `int`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_member_expr.py b/pa2-tests/core/bad_class_member_expr.py new file mode 100644 index 0000000..bbfa1c1 --- /dev/null +++ b/pa2-tests/core/bad_class_member_expr.py @@ -0,0 +1,6 @@ +x:int = 0 +o:object = None + +x.foo +o.bar +o.baz = 1 diff --git a/pa2-tests/core/bad_class_member_expr.py.ast b/pa2-tests/core/bad_class_member_expr.py.ast new file mode 100644 index 0000000..4949375 --- /dev/null +++ b/pa2-tests/core/bad_class_member_expr.py.ast @@ -0,0 +1,110 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 10 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 12, 2, 15 ] + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 5 ], + "expr" : { + "kind" : "MemberExpr", + "location" : [ 4, 1, 4, 5 ], + "object" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "x" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 4, 3, 4, 5 ], + "name" : "foo" + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 5 ], + "expr" : { + "kind" : "MemberExpr", + "location" : [ 5, 1, 5, 5 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "o" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 3, 5, 5 ], + "name" : "bar" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 9 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 6, 1, 6, 5 ], + "object" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "o" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 6, 3, 6, 5 ], + "name" : "baz" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "value" : 1 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_member_expr.py.ast.typed b/pa2-tests/core/bad_class_member_expr.py.ast.typed new file mode 100644 index 0000000..4e570c0 --- /dev/null +++ b/pa2-tests/core/bad_class_member_expr.py.ast.typed @@ -0,0 +1,161 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 10 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 12, 2, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 5 ], + "expr" : { + "kind" : "MemberExpr", + "location" : [ 4, 1, 4, 5 ], + "errorMsg" : "There is no attribute named `foo` in class `int`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 4, 3, 4, 5 ], + "name" : "foo" + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 5 ], + "expr" : { + "kind" : "MemberExpr", + "location" : [ 5, 1, 5, 5 ], + "errorMsg" : "There is no attribute named `bar` in class `object`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "o" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 3, 5, 5 ], + "name" : "bar" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 9 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 6, 1, 6, 5 ], + "errorMsg" : "There is no attribute named `baz` in class `object`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "o" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 6, 3, 6, 5 ], + "name" : "baz" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 4, 1, 4, 5 ], + "message" : "There is no attribute named `foo` in class `int`" + }, { + "kind" : "CompilerError", + "location" : [ 5, 1, 5, 5 ], + "message" : "There is no attribute named `bar` in class `object`" + }, { + "kind" : "CompilerError", + "location" : [ 6, 1, 6, 5 ], + "message" : "There is no attribute named `baz` in class `object`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_method.py b/pa2-tests/core/bad_class_method.py new file mode 100644 index 0000000..d5a10d8 --- /dev/null +++ b/pa2-tests/core/bad_class_method.py @@ -0,0 +1,14 @@ +class A(object): + x:int = 1 + + def foo(self:"A") -> int: # OK + return 0 + + def bar() -> int: # Needs self param + return 0 + + def baz(self:int) -> int: # Incorrect self type + return 0 + +A() + diff --git a/pa2-tests/core/bad_class_method.py.ast b/pa2-tests/core/bad_class_method.py.ast new file mode 100644 index 0000000..7c359ef --- /dev/null +++ b/pa2-tests/core/bad_class_method.py.ast @@ -0,0 +1,158 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 13, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 13, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 26, 4, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 16, 5, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 7, 5, 8, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 11 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 18, 7, 20 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 8, 9, 8, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 16, 8, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 10, 5, 11, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 11 ], + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 10, 13, 10, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 13, 10, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 18, 10, 20 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 10, 26, 10, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 11, 9, 11, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 16, 11, 16 ], + "value" : 0 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 13, 1, 13, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 13, 1, 13, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_method.py.ast.typed b/pa2-tests/core/bad_class_method.py.ast.typed new file mode 100644 index 0000000..9e08da8 --- /dev/null +++ b/pa2-tests/core/bad_class_method.py.ast.typed @@ -0,0 +1,168 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 13, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 13, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 26, 4, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 16, 5, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 7, 5, 8, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 11 ], + "errorMsg" : "First parameter of the following method must be of the enclosing class: bar", + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 18, 7, 20 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 8, 9, 8, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 16, 8, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 10, 5, 11, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 11 ], + "errorMsg" : "First parameter of the following method must be of the enclosing class: baz", + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 10, 13, 10, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 13, 10, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 18, 10, 20 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 10, 26, 10, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 11, 9, 11, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 16, 11, 16 ], + "value" : 0 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 13, 1, 13, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 13, 1, 13, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 7, 9, 7, 11 ], + "message" : "First parameter of the following method must be of the enclosing class: bar" + }, { + "kind" : "CompilerError", + "location" : [ 10, 9, 10, 11 ], + "message" : "First parameter of the following method must be of the enclosing class: baz" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_method_invoke.py b/pa2-tests/core/bad_class_method_invoke.py new file mode 100644 index 0000000..d5bb97c --- /dev/null +++ b/pa2-tests/core/bad_class_method_invoke.py @@ -0,0 +1,30 @@ +class A(object): + x:int = 1 + + def get_A(self: "A") -> int: + return self.x + +class B(A): + def __init__(self: "B"): + pass + +class C(B): + z:bool = True + + def set_A(self: "C", val: int) -> object: + self.x = val + +a:A = None +b:B = None +c:C = None + +a = A() +b = B() +c = C() + +a.get_A(1) +b.get_Z() +c.set_A() +c.set_A(False) +c.set_A(None) + diff --git a/pa2-tests/core/bad_class_method_invoke.py.ast b/pa2-tests/core/bad_class_method_invoke.py.ast new file mode 100644 index 0000000..e01db23 --- /dev/null +++ b/pa2-tests/core/bad_class_method_invoke.py.ast @@ -0,0 +1,474 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 29, 14 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 13 ], + "name" : "get_A" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 15, 4, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 15, 4, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 21, 4, 23 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 29, 4, 31 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 21 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 5, 16, 5, 21 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 19 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 21, 5, 21 ], + "name" : "x" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 11, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 8, 5, 9, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 18, 8, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 18, 8, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 24, 8, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 28, 8, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 11, 1, 17, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 12, 5, 12, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 5, 12, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 7, 12, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 12, 14, 12, 17 ], + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 14, 5, 15, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 13 ], + "name" : "set_A" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 15, 14, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 15, 14, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 21, 14, 23 ], + "className" : "C" + } + }, { + "kind" : "TypedVar", + "location" : [ 14, 26, 14, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 26, 14, 28 ], + "name" : "val" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 31, 14, 33 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 39, 14, 44 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 9, 15, 20 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 15, 9, 15, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 14, 15, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 15, 18, 15, 20 ], + "name" : "val" + } + } ] + } ] + }, { + "kind" : "VarDef", + "location" : [ 17, 1, 17, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 17, 1, 17, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 3, 17, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 17, 7, 17, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 18, 1, 18, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 18, 1, 18, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 18, 3, 18, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 18, 7, 18, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 19, 1, 19, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 19, 1, 19, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 3, 19, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 19, 7, 19, 10 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 21, 1, 21, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 21, 1, 21, 1 ], + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 21, 5, 21, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 21, 5, 21, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 22, 1, 22, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 1 ], + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 22, 5, 22, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 23, 1, 23, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 23, 1, 23, 1 ], + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 23, 5, 23, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 23, 5, 23, 5 ], + "name" : "C" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 25, 1, 25, 10 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 25, 1, 25, 10 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 25, 1, 25, 7 ], + "object" : { + "kind" : "Identifier", + "location" : [ 25, 1, 25, 1 ], + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 25, 3, 25, 7 ], + "name" : "get_A" + } + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 25, 9, 25, 9 ], + "value" : 1 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 26, 1, 26, 9 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 26, 1, 26, 9 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 26, 1, 26, 7 ], + "object" : { + "kind" : "Identifier", + "location" : [ 26, 1, 26, 1 ], + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 26, 3, 26, 7 ], + "name" : "get_Z" + } + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 27, 1, 27, 9 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 27, 1, 27, 9 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 27, 1, 27, 7 ], + "object" : { + "kind" : "Identifier", + "location" : [ 27, 1, 27, 1 ], + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 3, 27, 7 ], + "name" : "set_A" + } + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 28, 1, 28, 14 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 28, 1, 28, 14 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 28, 1, 28, 7 ], + "object" : { + "kind" : "Identifier", + "location" : [ 28, 1, 28, 1 ], + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 28, 3, 28, 7 ], + "name" : "set_A" + } + }, + "args" : [ { + "kind" : "BooleanLiteral", + "location" : [ 28, 9, 28, 13 ], + "value" : false + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 29, 1, 29, 13 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 29, 1, 29, 13 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 29, 1, 29, 7 ], + "object" : { + "kind" : "Identifier", + "location" : [ 29, 1, 29, 1 ], + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 3, 29, 7 ], + "name" : "set_A" + } + }, + "args" : [ { + "kind" : "NoneLiteral", + "location" : [ 29, 9, 29, 12 ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_method_invoke.py.ast.typed b/pa2-tests/core/bad_class_method_invoke.py.ast.typed new file mode 100644 index 0000000..77867db --- /dev/null +++ b/pa2-tests/core/bad_class_method_invoke.py.ast.typed @@ -0,0 +1,668 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 29, 14 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 13 ], + "name" : "get_A" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 15, 4, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 15, 4, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 21, 4, 23 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 29, 4, 31 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 21 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 5, 16, 5, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 21, 5, 21 ], + "name" : "x" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 11, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 8, 5, 9, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 18, 8, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 18, 8, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 24, 8, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 28, 8, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 11, 1, 17, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 12, 5, 12, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 5, 12, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 7, 12, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 12, 14, 12, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 14, 5, 15, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 13 ], + "name" : "set_A" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 15, 14, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 15, 14, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 21, 14, 23 ], + "className" : "C" + } + }, { + "kind" : "TypedVar", + "location" : [ 14, 26, 14, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 26, 14, 28 ], + "name" : "val" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 31, 14, 33 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 39, 14, 44 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 9, 15, 20 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 15, 9, 15, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 14, 15, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 15, 18, 15, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "val" + } + } ] + } ] + }, { + "kind" : "VarDef", + "location" : [ 17, 1, 17, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 17, 1, 17, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 3, 17, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 17, 7, 17, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 18, 1, 18, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 18, 1, 18, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 18, 3, 18, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 18, 7, 18, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 19, 1, 19, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 19, 1, 19, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 3, 19, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 19, 7, 19, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 21, 1, 21, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 21, 1, 21, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 21, 5, 21, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 21, 5, 21, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 22, 1, 22, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 22, 5, 22, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 23, 1, 23, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 23, 1, 23, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 23, 5, 23, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 23, 5, 23, 5 ], + "name" : "C" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 25, 1, 25, 10 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 25, 1, 25, 10 ], + "errorMsg" : "Expected 0 arguments; got 1", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 25, 1, 25, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "A" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 25, 1, 25, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 25, 3, 25, 7 ], + "name" : "get_A" + } + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 25, 9, 25, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 26, 1, 26, 9 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 26, 1, 26, 9 ], + "errorMsg" : "There is no method named `get_Z` in class `B`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 26, 1, 26, 7 ], + "object" : { + "kind" : "Identifier", + "location" : [ 26, 1, 26, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 26, 3, 26, 7 ], + "name" : "get_Z" + } + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 27, 1, 27, 9 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 27, 1, 27, 9 ], + "errorMsg" : "Expected 1 arguments; got 0", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 27, 1, 27, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "C" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 27, 1, 27, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 3, 27, 7 ], + "name" : "set_A" + } + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 28, 1, 28, 14 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 28, 1, 28, 14 ], + "errorMsg" : "Expected type `int`; got type `bool` in parameter 1", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 28, 1, 28, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "C" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 28, 1, 28, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 28, 3, 28, 7 ], + "name" : "set_A" + } + }, + "args" : [ { + "kind" : "BooleanLiteral", + "location" : [ 28, 9, 28, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 29, 1, 29, 13 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 29, 1, 29, 13 ], + "errorMsg" : "Expected type `int`; got type `` in parameter 1", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 29, 1, 29, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "C" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 29, 1, 29, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 3, 29, 7 ], + "name" : "set_A" + } + }, + "args" : [ { + "kind" : "NoneLiteral", + "location" : [ 29, 9, 29, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 25, 1, 25, 10 ], + "message" : "Expected 0 arguments; got 1" + }, { + "kind" : "CompilerError", + "location" : [ 26, 1, 26, 9 ], + "message" : "There is no method named `get_Z` in class `B`" + }, { + "kind" : "CompilerError", + "location" : [ 27, 1, 27, 9 ], + "message" : "Expected 1 arguments; got 0" + }, { + "kind" : "CompilerError", + "location" : [ 28, 1, 28, 14 ], + "message" : "Expected type `int`; got type `bool` in parameter 1" + }, { + "kind" : "CompilerError", + "location" : [ 29, 1, 29, 13 ], + "message" : "Expected type `int`; got type `` in parameter 1" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_method_override.py b/pa2-tests/core/bad_class_method_override.py new file mode 100644 index 0000000..3f76544 --- /dev/null +++ b/pa2-tests/core/bad_class_method_override.py @@ -0,0 +1,33 @@ +class A(object): + def foo(self:"A", x:int) -> int: + return x + + def bar(self:"A", x:int) -> int: + return x + + def baz(self:"A", x:int) -> int: + return x + + def qux(self:"A", x:int) -> int: + return x + +class B(A): + + # OK override + def foo(self:"B", x:int) -> int: + return 0 + + # Bad override + def bar(self:"B") -> int: + return 0 + + # Bad override + def baz(self:"B", x:int) -> bool: + return True + + # Bad override + def qux(self:"B", x:bool) -> int: + return 0 + +B() + diff --git a/pa2-tests/core/bad_class_method_override.py.ast b/pa2-tests/core/bad_class_method_override.py.ast new file mode 100644 index 0000000..e82a758 --- /dev/null +++ b/pa2-tests/core/bad_class_method_override.py.ast @@ -0,0 +1,439 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 32, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 14, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 5, 3, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 13, 2, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 13, 2, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 18, 2, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 2, 23, 2, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 23, 2, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 25, 2, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 33, 2, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 9, 3, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 3, 16, 3, 16 ], + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 13, 5, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 13, 5, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 18, 5, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 5, 23, 5, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 23, 5, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 25, 5, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 33, 5, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 6, 9, 6, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 6, 16, 6, 16 ], + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 8, 5, 9, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 11 ], + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 13, 8, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 13, 8, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 18, 8, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 8, 23, 8, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 23, 8, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 25, 8, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 33, 8, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 9, 9, 9, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 9, 16, 9, 16 ], + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 11, 5, 12, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 11 ], + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 11, 13, 11, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 13, 11, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 18, 11, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 11, 23, 11, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 23, 11, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 25, 11, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 11, 33, 11, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 12, 9, 12, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 12, 16, 12, 16 ], + "name" : "x" + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 14, 1, 32, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 7, 14, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 17, 5, 18, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 17, 9, 17, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 17, 13, 17, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 13, 17, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 18, 17, 20 ], + "className" : "B" + } + }, { + "kind" : "TypedVar", + "location" : [ 17, 23, 17, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 23, 17, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 25, 17, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 17, 33, 17, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 18, 9, 18, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 18, 16, 18, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 21, 5, 22, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 21, 9, 21, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 21, 13, 21, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 21, 13, 21, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 21, 18, 21, 20 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 21, 26, 21, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 22, 9, 22, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 22, 16, 22, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 25, 5, 26, 20 ], + "name" : { + "kind" : "Identifier", + "location" : [ 25, 9, 25, 11 ], + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 25, 13, 25, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 25, 13, 25, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 25, 18, 25, 20 ], + "className" : "B" + } + }, { + "kind" : "TypedVar", + "location" : [ 25, 23, 25, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 25, 23, 25, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 25, 25, 25, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 25, 33, 25, 36 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 26, 9, 26, 19 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 26, 16, 26, 19 ], + "value" : true + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 29, 5, 30, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 29, 9, 29, 11 ], + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 29, 13, 29, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 13, 29, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 29, 18, 29, 20 ], + "className" : "B" + } + }, { + "kind" : "TypedVar", + "location" : [ 29, 23, 29, 28 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 23, 29, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 29, 25, 29, 28 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 29, 34, 29, 36 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 30, 9, 30, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 30, 16, 30, 16 ], + "value" : 0 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 32, 1, 32, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 32, 1, 32, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 32, 1, 32, 1 ], + "name" : "B" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_method_override.py.ast.typed b/pa2-tests/core/bad_class_method_override.py.ast.typed new file mode 100644 index 0000000..68716c5 --- /dev/null +++ b/pa2-tests/core/bad_class_method_override.py.ast.typed @@ -0,0 +1,454 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 32, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 14, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 5, 3, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 13, 2, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 13, 2, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 18, 2, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 2, 23, 2, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 23, 2, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 25, 2, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 33, 2, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 9, 3, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 3, 16, 3, 16 ], + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 13, 5, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 13, 5, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 18, 5, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 5, 23, 5, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 23, 5, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 25, 5, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 33, 5, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 6, 9, 6, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 6, 16, 6, 16 ], + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 8, 5, 9, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 11 ], + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 13, 8, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 13, 8, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 18, 8, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 8, 23, 8, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 23, 8, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 25, 8, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 33, 8, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 9, 9, 9, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 9, 16, 9, 16 ], + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 11, 5, 12, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 11 ], + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 11, 13, 11, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 13, 11, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 18, 11, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 11, 23, 11, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 23, 11, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 25, 11, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 11, 33, 11, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 12, 9, 12, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 12, 16, 12, 16 ], + "name" : "x" + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 14, 1, 32, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 7, 14, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 17, 5, 18, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 17, 9, 17, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 17, 13, 17, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 13, 17, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 18, 17, 20 ], + "className" : "B" + } + }, { + "kind" : "TypedVar", + "location" : [ 17, 23, 17, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 23, 17, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 25, 17, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 17, 33, 17, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 18, 9, 18, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 18, 16, 18, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 21, 5, 22, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 21, 9, 21, 11 ], + "errorMsg" : "Method overridden with different type signature: bar", + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 21, 13, 21, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 21, 13, 21, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 21, 18, 21, 20 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 21, 26, 21, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 22, 9, 22, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 22, 16, 22, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 25, 5, 26, 20 ], + "name" : { + "kind" : "Identifier", + "location" : [ 25, 9, 25, 11 ], + "errorMsg" : "Method overridden with different type signature: baz", + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 25, 13, 25, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 25, 13, 25, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 25, 18, 25, 20 ], + "className" : "B" + } + }, { + "kind" : "TypedVar", + "location" : [ 25, 23, 25, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 25, 23, 25, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 25, 25, 25, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 25, 33, 25, 36 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 26, 9, 26, 19 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 26, 16, 26, 19 ], + "value" : true + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 29, 5, 30, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 29, 9, 29, 11 ], + "errorMsg" : "Method overridden with different type signature: qux", + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 29, 13, 29, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 13, 29, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 29, 18, 29, 20 ], + "className" : "B" + } + }, { + "kind" : "TypedVar", + "location" : [ 29, 23, 29, 28 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 23, 29, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 29, 25, 29, 28 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 29, 34, 29, 36 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 30, 9, 30, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 30, 16, 30, 16 ], + "value" : 0 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 32, 1, 32, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 32, 1, 32, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 32, 1, 32, 1 ], + "name" : "B" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 21, 9, 21, 11 ], + "message" : "Method overridden with different type signature: bar" + }, { + "kind" : "CompilerError", + "location" : [ 25, 9, 25, 11 ], + "message" : "Method overridden with different type signature: baz" + }, { + "kind" : "CompilerError", + "location" : [ 29, 9, 29, 11 ], + "message" : "Method overridden with different type signature: qux" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_method_override_attr.py b/pa2-tests/core/bad_class_method_override_attr.py new file mode 100644 index 0000000..52c01bd --- /dev/null +++ b/pa2-tests/core/bad_class_method_override_attr.py @@ -0,0 +1,8 @@ +class A(object): + f:int = 3 + +class B(A): + def f(self:B) -> int: + return 3 + +A() diff --git a/pa2-tests/core/bad_class_method_override_attr.py.ast b/pa2-tests/core/bad_class_method_override_attr.py.ast new file mode 100644 index 0000000..1574d53 --- /dev/null +++ b/pa2-tests/core/bad_class_method_override_attr.py.ast @@ -0,0 +1,111 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 2, 2, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 2, 2, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 2, 2, 2 ], + "name" : "f" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 6 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 10, 2, 10 ], + "value" : 3 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 5, 2, 6, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 6, 5, 6 ], + "name" : "f" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 8, 5, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 8, 5, 11 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 13, 5, 13 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 19, 5, 21 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 6, 3, 6, 10 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 10, 6, 10 ], + "value" : 3 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_method_override_attr.py.ast.typed b/pa2-tests/core/bad_class_method_override_attr.py.ast.typed new file mode 100644 index 0000000..fcfb779 --- /dev/null +++ b/pa2-tests/core/bad_class_method_override_attr.py.ast.typed @@ -0,0 +1,116 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 2, 2, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 2, 2, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 2, 2, 2 ], + "name" : "f" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 6 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 10, 2, 10 ], + "value" : 3 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 5, 2, 6, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 6, 5, 6 ], + "errorMsg" : "Cannot re-define attribute: f", + "name" : "f" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 8, 5, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 8, 5, 11 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 13, 5, 13 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 19, 5, 21 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 6, 3, 6, 10 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 10, 6, 10 ], + "value" : 3 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 5, 6, 5, 6 ], + "message" : "Cannot re-define attribute: f" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_super.py b/pa2-tests/core/bad_class_super.py new file mode 100644 index 0000000..9701776 --- /dev/null +++ b/pa2-tests/core/bad_class_super.py @@ -0,0 +1,15 @@ +# Super is not defined +class A(B): + x:int = 1 + +z:int = 2 + +# Super is not a class +class B(z): + x:int = 1 + +# Cannot extend special classes +class C(int): + x:int = 1 + +A() diff --git a/pa2-tests/core/bad_class_super.py.ast b/pa2-tests/core/bad_class_super.py.ast new file mode 100644 index 0000000..4aed62a --- /dev/null +++ b/pa2-tests/core/bad_class_super.py.ast @@ -0,0 +1,154 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 15, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 2, 1, 3, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 7, 3, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 13, 3, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 5, 1, 5, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 1, 5, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 3, 5, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 9, 5, 9 ], + "value" : 2 + } + }, { + "kind" : "ClassDef", + "location" : [ 8, 1, 9, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "z" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 7, 9, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 13, 9, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 12, 1, 13, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 12, 7, 12, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 12, 9, 12, 11 ], + "name" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 13, 5, 13, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 5, 13, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 7, 13, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 13, 13, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 15, 1, 15, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 15, 1, 15, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_class_super.py.ast.typed b/pa2-tests/core/bad_class_super.py.ast.typed new file mode 100644 index 0000000..128383f --- /dev/null +++ b/pa2-tests/core/bad_class_super.py.ast.typed @@ -0,0 +1,169 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 15, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 2, 1, 3, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 9 ], + "errorMsg" : "Super-class not defined: B", + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 7, 3, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 13, 3, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 5, 1, 5, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 1, 5, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 3, 5, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 9, 5, 9 ], + "value" : 2 + } + }, { + "kind" : "ClassDef", + "location" : [ 8, 1, 9, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "errorMsg" : "Super-class must be a class: z", + "name" : "z" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 7, 9, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 13, 9, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 12, 1, 13, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 12, 7, 12, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 12, 9, 12, 11 ], + "errorMsg" : "Cannot extend special class: int", + "name" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 13, 5, 13, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 5, 13, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 7, 13, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 13, 13, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 15, 1, 15, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 15, 1, 15, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 2, 9, 2, 9 ], + "message" : "Super-class not defined: B" + }, { + "kind" : "CompilerError", + "location" : [ 8, 9, 8, 9 ], + "message" : "Super-class must be a class: z" + }, { + "kind" : "CompilerError", + "location" : [ 12, 9, 12, 11 ], + "message" : "Cannot extend special class: int" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_concat.py b/pa2-tests/core/bad_concat.py new file mode 100644 index 0000000..56e7802 --- /dev/null +++ b/pa2-tests/core/bad_concat.py @@ -0,0 +1,3 @@ +"Hello" + ["World"] +1 + [2] +[] + [1] diff --git a/pa2-tests/core/bad_concat.py.ast b/pa2-tests/core/bad_concat.py.ast new file mode 100644 index 0000000..0fdfbd6 --- /dev/null +++ b/pa2-tests/core/bad_concat.py.ast @@ -0,0 +1,77 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 9 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 19 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 19 ], + "left" : { + "kind" : "StringLiteral", + "location" : [ 1, 1, 1, 7 ], + "value" : "Hello" + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 1, 11, 1, 19 ], + "elements" : [ { + "kind" : "StringLiteral", + "location" : [ 1, 12, 1, 18 ], + "value" : "World" + } ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 7 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 2, 1, 2, 7 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 1, 2, 1 ], + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 2, 5, 2, 7 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 2, 6, 2, 6 ], + "value" : 2 + } ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 8 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 8 ], + "left" : { + "kind" : "ListExpr", + "location" : [ 3, 1, 3, 2 ], + "elements" : [ ] + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 3, 6, 3, 8 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 7, 3, 7 ], + "value" : 1 + } ] + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_concat.py.ast.typed b/pa2-tests/core/bad_concat.py.ast.typed new file mode 100644 index 0000000..60f5b0c --- /dev/null +++ b/pa2-tests/core/bad_concat.py.ast.typed @@ -0,0 +1,149 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 9 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 19 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 19 ], + "errorMsg" : "Cannot apply operator `+` on types `str` and `[str]`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "left" : { + "kind" : "StringLiteral", + "location" : [ 1, 1, 1, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 1, 11, 1, 19 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "elements" : [ { + "kind" : "StringLiteral", + "location" : [ 1, 12, 1, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "World" + } ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 7 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 2, 1, 2, 7 ], + "errorMsg" : "Cannot apply operator `+` on types `int` and `[int]`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 1, 2, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 2, 5, 2, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 2, 6, 2, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 8 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 8 ], + "errorMsg" : "Cannot apply operator `+` on types `` and `[int]`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "left" : { + "kind" : "ListExpr", + "location" : [ 3, 1, 3, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 3, 6, 3, 8 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 7, 3, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } ] + } + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 1, 1, 19 ], + "message" : "Cannot apply operator `+` on types `str` and `[str]`" + }, { + "kind" : "CompilerError", + "location" : [ 2, 1, 2, 7 ], + "message" : "Cannot apply operator `+` on types `int` and `[int]`" + }, { + "kind" : "CompilerError", + "location" : [ 3, 1, 3, 8 ], + "message" : "Cannot apply operator `+` on types `` and `[int]`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_duplicate_class.py b/pa2-tests/core/bad_duplicate_class.py new file mode 100644 index 0000000..8f8dd05 --- /dev/null +++ b/pa2-tests/core/bad_duplicate_class.py @@ -0,0 +1,18 @@ +class A(object): + x:int = 1 + +z:bool = True + +# Duplicate +class A(object): + x:int = 1 + +# Duplicate +class str(object): + x:int = 1 + +# Duplicate +class z(object): + x:int = 1 + +A() diff --git a/pa2-tests/core/bad_duplicate_class.py.ast b/pa2-tests/core/bad_duplicate_class.py.ast new file mode 100644 index 0000000..547360b --- /dev/null +++ b/pa2-tests/core/bad_duplicate_class.py.ast @@ -0,0 +1,190 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 18, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 6 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 10, 4, 13 ], + "value" : true + } + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 8, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 8, 5, 8, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 8, 5, 8, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 7, 8, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 13, 8, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 11, 1, 12, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 9 ], + "name" : "str" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 11, 11, 11, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 12, 5, 12, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 5, 12, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 7, 12, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 13, 12, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 15, 1, 16, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 7 ], + "name" : "z" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 16, 5, 16, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 16, 5, 16, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 7, 16, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 16, 13, 16, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 18, 1, 18, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 18, 1, 18, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_duplicate_class.py.ast.typed b/pa2-tests/core/bad_duplicate_class.py.ast.typed new file mode 100644 index 0000000..3791ada --- /dev/null +++ b/pa2-tests/core/bad_duplicate_class.py.ast.typed @@ -0,0 +1,205 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 18, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 6 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 10, 4, 13 ], + "value" : true + } + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 8, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: A", + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 8, 5, 8, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 8, 5, 8, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 7, 8, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 13, 8, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 11, 1, 12, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 9 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: str", + "name" : "str" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 11, 11, 11, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 12, 5, 12, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 5, 12, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 7, 12, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 13, 12, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 15, 1, 16, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 7 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: z", + "name" : "z" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 16, 5, 16, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 16, 5, 16, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 7, 16, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 16, 13, 16, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 18, 1, 18, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 18, 1, 18, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 7, 7, 7, 7 ], + "message" : "Duplicate declaration of identifier in same scope: A" + }, { + "kind" : "CompilerError", + "location" : [ 11, 7, 11, 9 ], + "message" : "Duplicate declaration of identifier in same scope: str" + }, { + "kind" : "CompilerError", + "location" : [ 15, 7, 15, 7 ], + "message" : "Duplicate declaration of identifier in same scope: z" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_duplicate_class_member.py b/pa2-tests/core/bad_duplicate_class_member.py new file mode 100644 index 0000000..7a5026f --- /dev/null +++ b/pa2-tests/core/bad_duplicate_class_member.py @@ -0,0 +1,12 @@ +class A(object): + x:int = 1 # OK + + def foo(self: "A") -> int: # OK + return 0 + + x:int = 1 # Duplicate + + def foo(self: "A") -> int: # Duplicate + return 0 + +A() diff --git a/pa2-tests/core/bad_duplicate_class_member.py.ast b/pa2-tests/core/bad_duplicate_class_member.py.ast new file mode 100644 index 0000000..58b0ddb --- /dev/null +++ b/pa2-tests/core/bad_duplicate_class_member.py.ast @@ -0,0 +1,156 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 12, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 12, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 19, 4, 21 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 27, 4, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 16, 5, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 7, 7, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 13, 7, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 10, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 9, 13, 9, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 19, 9, 21 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 27, 9, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 10, 9, 10, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 16, 10, 16 ], + "value" : 0 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 12, 1, 12, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 12, 1, 12, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_duplicate_class_member.py.ast.typed b/pa2-tests/core/bad_duplicate_class_member.py.ast.typed new file mode 100644 index 0000000..cb97ac4 --- /dev/null +++ b/pa2-tests/core/bad_duplicate_class_member.py.ast.typed @@ -0,0 +1,166 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 12, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 12, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 19, 4, 21 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 27, 4, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 16, 5, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: x", + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 7, 7, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 13, 7, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 10, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: foo", + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 9, 13, 9, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 19, 9, 21 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 27, 9, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 10, 9, 10, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 16, 10, 16 ], + "value" : 0 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 12, 1, 12, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 12, 1, 12, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 7, 5, 7, 5 ], + "message" : "Duplicate declaration of identifier in same scope: x" + }, { + "kind" : "CompilerError", + "location" : [ 9, 9, 9, 11 ], + "message" : "Duplicate declaration of identifier in same scope: foo" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_duplicate_global.py b/pa2-tests/core/bad_duplicate_global.py new file mode 100644 index 0000000..4b293ea --- /dev/null +++ b/pa2-tests/core/bad_duplicate_global.py @@ -0,0 +1,18 @@ +x:int = 1 + +def foo() -> object: + pass + +# `foo` cannot be redefined in the same scope +def foo() -> object: + pass + +# `print` cannot be redefined in the same scope +def print(val:object) -> object: + pass + +# `x` cannot be redefined in the same scope +x:int = 2 + + +foo() diff --git a/pa2-tests/core/bad_duplicate_global.py.ast b/pa2-tests/core/bad_duplicate_global.py.ast new file mode 100644 index 0000000..76e6707 --- /dev/null +++ b/pa2-tests/core/bad_duplicate_global.py.ast @@ -0,0 +1,129 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 18, 6 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 4, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 7 ], + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 14, 3, 19 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 7, 1, 8, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 7 ], + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 14, 7, 19 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 11, 1, 12, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 9 ], + "name" : "print" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 11, 11, 11, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 11, 11, 13 ], + "name" : "val" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 15, 11, 20 ], + "className" : "object" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 11, 26, 11, 31 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 15, 1, 15, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 15, 1, 15, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 15, 3, 15, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 15, 9, 15, 9 ], + "value" : 2 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 18, 1, 18, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 18, 1, 18, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 3 ], + "name" : "foo" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_duplicate_global.py.ast.typed b/pa2-tests/core/bad_duplicate_global.py.ast.typed new file mode 100644 index 0000000..7d72792 --- /dev/null +++ b/pa2-tests/core/bad_duplicate_global.py.ast.typed @@ -0,0 +1,144 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 18, 6 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 4, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 7 ], + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 14, 3, 19 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 7, 1, 8, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 7 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: foo", + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 14, 7, 19 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 11, 1, 12, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 9 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: print", + "name" : "print" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 11, 11, 11, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 11, 11, 13 ], + "name" : "val" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 15, 11, 20 ], + "className" : "object" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 11, 26, 11, 31 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 15, 1, 15, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 15, 1, 15, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: x", + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 15, 3, 15, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 15, 9, 15, 9 ], + "value" : 2 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 18, 1, 18, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 18, 1, 18, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 3 ], + "name" : "foo" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 7, 5, 7, 7 ], + "message" : "Duplicate declaration of identifier in same scope: foo" + }, { + "kind" : "CompilerError", + "location" : [ 11, 5, 11, 9 ], + "message" : "Duplicate declaration of identifier in same scope: print" + }, { + "kind" : "CompilerError", + "location" : [ 15, 1, 15, 1 ], + "message" : "Duplicate declaration of identifier in same scope: x" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_duplicate_global_2.py b/pa2-tests/core/bad_duplicate_global_2.py new file mode 100644 index 0000000..62ee129 --- /dev/null +++ b/pa2-tests/core/bad_duplicate_global_2.py @@ -0,0 +1,6 @@ +class x(object): + pass + +x:int = 5 + +pass diff --git a/pa2-tests/core/bad_duplicate_global_2.py.ast b/pa2-tests/core/bad_duplicate_global_2.py.ast new file mode 100644 index 0000000..c3a5985 --- /dev/null +++ b/pa2-tests/core/bad_duplicate_global_2.py.ast @@ -0,0 +1,47 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 5 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "x" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "value" : 5 + } + } ], + "statements" : [ ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_duplicate_global_2.py.ast.typed b/pa2-tests/core/bad_duplicate_global_2.py.ast.typed new file mode 100644 index 0000000..506a6ca --- /dev/null +++ b/pa2-tests/core/bad_duplicate_global_2.py.ast.typed @@ -0,0 +1,52 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 5 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "x" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: x", + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "value" : 5 + } + } ], + "statements" : [ ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 4, 1, 4, 1 ], + "message" : "Duplicate declaration of identifier in same scope: x" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_duplicate_local.py b/pa2-tests/core/bad_duplicate_local.py new file mode 100644 index 0000000..bb25faf --- /dev/null +++ b/pa2-tests/core/bad_duplicate_local.py @@ -0,0 +1,21 @@ +x:int = 1 +y:int = 2 +z:int = 3 + +def foo(x:int) -> object: + y:int = 4 # OK + x:int = 5 # Duplicate declaration + global z # OK + global y # Duplicate declaration + + def x() -> int: # Duplicate declaration + return 0 + + pass + +def bar(x:int, x:int) -> int: # Duplicate params + return x + + +foo(1) + diff --git a/pa2-tests/core/bad_duplicate_local.py.ast b/pa2-tests/core/bad_duplicate_local.py.ast new file mode 100644 index 0000000..53f6fad --- /dev/null +++ b/pa2-tests/core/bad_duplicate_local.py.ast @@ -0,0 +1,257 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 20, 7 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "value" : 3 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 14, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 9, 5, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 11, 5, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 19, 5, 24 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "value" : 4 + } + }, { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 7, 7, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 13, 7, 13 ], + "value" : 5 + } + }, { + "kind" : "GlobalDecl", + "location" : [ 8, 5, 8, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 8, 12, 8, 12 ], + "name" : "z" + } + }, { + "kind" : "GlobalDecl", + "location" : [ 9, 5, 9, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 12 ], + "name" : "y" + } + }, { + "kind" : "FuncDef", + "location" : [ 11, 5, 12, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "x" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 11, 16, 11, 18 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 12, 9, 12, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 16, 12, 16 ], + "value" : 0 + } + } ] + } ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 16, 1, 17, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 7 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 16, 9, 16, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 9, 16, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 11, 16, 13 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 16, 16, 16, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 16 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 18, 16, 20 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 16, 26, 16, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 17, 5, 17, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 17, 12, 17, 12 ], + "name" : "x" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 20, 1, 20, 6 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 20, 1, 20, 6 ], + "function" : { + "kind" : "Identifier", + "location" : [ 20, 1, 20, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 20, 5, 20, 5 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_duplicate_local.py.ast.typed b/pa2-tests/core/bad_duplicate_local.py.ast.typed new file mode 100644 index 0000000..1559865 --- /dev/null +++ b/pa2-tests/core/bad_duplicate_local.py.ast.typed @@ -0,0 +1,277 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 20, 7 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "value" : 3 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 14, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 9, 5, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 11, 5, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 19, 5, 24 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "value" : 4 + } + }, { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: x", + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 7, 7, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 13, 7, 13 ], + "value" : 5 + } + }, { + "kind" : "GlobalDecl", + "location" : [ 8, 5, 8, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 8, 12, 8, 12 ], + "name" : "z" + } + }, { + "kind" : "GlobalDecl", + "location" : [ 9, 5, 9, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 12 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: y", + "name" : "y" + } + }, { + "kind" : "FuncDef", + "location" : [ 11, 5, 12, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: x", + "name" : "x" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 11, 16, 11, 18 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 12, 9, 12, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 16, 12, 16 ], + "value" : 0 + } + } ] + } ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 16, 1, 17, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 7 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 16, 9, 16, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 9, 16, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 11, 16, 13 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 16, 16, 16, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 16 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: x", + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 18, 16, 20 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 16, 26, 16, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 17, 5, 17, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 17, 12, 17, 12 ], + "name" : "x" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 20, 1, 20, 6 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 20, 1, 20, 6 ], + "function" : { + "kind" : "Identifier", + "location" : [ 20, 1, 20, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 20, 5, 20, 5 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 7, 5, 7, 5 ], + "message" : "Duplicate declaration of identifier in same scope: x" + }, { + "kind" : "CompilerError", + "location" : [ 9, 12, 9, 12 ], + "message" : "Duplicate declaration of identifier in same scope: y" + }, { + "kind" : "CompilerError", + "location" : [ 11, 9, 11, 9 ], + "message" : "Duplicate declaration of identifier in same scope: x" + }, { + "kind" : "CompilerError", + "location" : [ 16, 16, 16, 16 ], + "message" : "Duplicate declaration of identifier in same scope: x" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_expr_binary.py b/pa2-tests/core/bad_expr_binary.py new file mode 100644 index 0000000..1668849 --- /dev/null +++ b/pa2-tests/core/bad_expr_binary.py @@ -0,0 +1,13 @@ +1 and 2 +1 or 2 +True - False +True < False +1 + True +False + 0 +1 == True +False != 0 +1 is 1 +True is False +None + None +None == None +None is None diff --git a/pa2-tests/core/bad_expr_binary.py.ast b/pa2-tests/core/bad_expr_binary.py.ast new file mode 100644 index 0000000..c55893a --- /dev/null +++ b/pa2-tests/core/bad_expr_binary.py.ast @@ -0,0 +1,239 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 13, 13 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 7 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 7 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "value" : 1 + }, + "operator" : "and", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 7, 1, 7 ], + "value" : 2 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 6 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 2, 1, 2, 6 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 1, 2, 1 ], + "value" : 1 + }, + "operator" : "or", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 6, 2, 6 ], + "value" : 2 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 12 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 12 ], + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 1, 3, 4 ], + "value" : true + }, + "operator" : "-", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 8, 3, 12 ], + "value" : false + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 12 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 4, 1, 4, 12 ], + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 1, 4, 4 ], + "value" : true + }, + "operator" : "<", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 8, 4, 12 ], + "value" : false + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 8 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 5, 1, 5, 8 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 1, 5, 1 ], + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 5, 5, 8 ], + "value" : true + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 9 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 6, 1, 6, 9 ], + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 6, 1, 6, 5 ], + "value" : false + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "value" : 0 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 9 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 7, 1, 7, 9 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 1, 7, 1 ], + "value" : 1 + }, + "operator" : "==", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 6, 7, 9 ], + "value" : true + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 10 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 8, 1, 8, 10 ], + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 8, 1, 8, 5 ], + "value" : false + }, + "operator" : "!=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 10, 8, 10 ], + "value" : 0 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 6 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 9, 1, 9, 6 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 1, 9, 1 ], + "value" : 1 + }, + "operator" : "is", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 6, 9, 6 ], + "value" : 1 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 13 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 10, 1, 10, 13 ], + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 10, 1, 10, 4 ], + "value" : true + }, + "operator" : "is", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 10, 9, 10, 13 ], + "value" : false + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 11 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 11, 1, 11, 11 ], + "left" : { + "kind" : "NoneLiteral", + "location" : [ 11, 1, 11, 4 ] + }, + "operator" : "+", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 11, 8, 11, 11 ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 12, 1, 12, 12 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 12, 1, 12, 12 ], + "left" : { + "kind" : "NoneLiteral", + "location" : [ 12, 1, 12, 4 ] + }, + "operator" : "==", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 12, 9, 12, 12 ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 13, 1, 13, 12 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 13, 1, 13, 12 ], + "left" : { + "kind" : "NoneLiteral", + "location" : [ 13, 1, 13, 4 ] + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 13, 9, 13, 12 ] + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_expr_binary.py.ast.typed b/pa2-tests/core/bad_expr_binary.py.ast.typed new file mode 100644 index 0000000..851cc92 --- /dev/null +++ b/pa2-tests/core/bad_expr_binary.py.ast.typed @@ -0,0 +1,455 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 13, 13 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 7 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 7 ], + "errorMsg" : "Cannot apply operator `and` on types `int` and `int`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "and", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 7, 1, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 6 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 2, 1, 2, 6 ], + "errorMsg" : "Cannot apply operator `or` on types `int` and `int`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 1, 2, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "or", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 6, 2, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 12 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 12 ], + "errorMsg" : "Cannot apply operator `-` on types `bool` and `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 1, 3, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "operator" : "-", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 8, 3, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 12 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 4, 1, 4, 12 ], + "errorMsg" : "Cannot apply operator `<` on types `bool` and `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 1, 4, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "operator" : "<", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 8, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 8 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 5, 1, 5, 8 ], + "errorMsg" : "Cannot apply operator `+` on types `int` and `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 5, 5, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 9 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 6, 1, 6, 9 ], + "errorMsg" : "Cannot apply operator `+` on types `bool` and `int`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 6, 1, 6, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 9 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 7, 1, 7, 9 ], + "errorMsg" : "Cannot apply operator `==` on types `int` and `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "==", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 6, 7, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 10 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 8, 1, 8, 10 ], + "errorMsg" : "Cannot apply operator `!=` on types `bool` and `int`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 8, 1, 8, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, + "operator" : "!=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 10, 8, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 6 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 9, 1, 9, 6 ], + "errorMsg" : "Cannot apply operator `is` on types `int` and `int`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 1, 9, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "is", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 6, 9, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 13 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 10, 1, 10, 13 ], + "errorMsg" : "Cannot apply operator `is` on types `bool` and `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 10, 1, 10, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "operator" : "is", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 10, 9, 10, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 11 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 11, 1, 11, 11 ], + "errorMsg" : "Cannot apply operator `+` on types `` and ``", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "left" : { + "kind" : "NoneLiteral", + "location" : [ 11, 1, 11, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "operator" : "+", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 11, 8, 11, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 12, 1, 12, 12 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 12, 1, 12, 12 ], + "errorMsg" : "Cannot apply operator `==` on types `` and ``", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "NoneLiteral", + "location" : [ 12, 1, 12, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "operator" : "==", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 12, 9, 12, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 13, 1, 13, 12 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 13, 1, 13, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "NoneLiteral", + "location" : [ 13, 1, 13, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 13, 9, 13, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 1, 1, 7 ], + "message" : "Cannot apply operator `and` on types `int` and `int`" + }, { + "kind" : "CompilerError", + "location" : [ 2, 1, 2, 6 ], + "message" : "Cannot apply operator `or` on types `int` and `int`" + }, { + "kind" : "CompilerError", + "location" : [ 3, 1, 3, 12 ], + "message" : "Cannot apply operator `-` on types `bool` and `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 4, 1, 4, 12 ], + "message" : "Cannot apply operator `<` on types `bool` and `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 5, 1, 5, 8 ], + "message" : "Cannot apply operator `+` on types `int` and `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 6, 1, 6, 9 ], + "message" : "Cannot apply operator `+` on types `bool` and `int`" + }, { + "kind" : "CompilerError", + "location" : [ 7, 1, 7, 9 ], + "message" : "Cannot apply operator `==` on types `int` and `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 8, 1, 8, 10 ], + "message" : "Cannot apply operator `!=` on types `bool` and `int`" + }, { + "kind" : "CompilerError", + "location" : [ 9, 1, 9, 6 ], + "message" : "Cannot apply operator `is` on types `int` and `int`" + }, { + "kind" : "CompilerError", + "location" : [ 10, 1, 10, 13 ], + "message" : "Cannot apply operator `is` on types `bool` and `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 11, 1, 11, 11 ], + "message" : "Cannot apply operator `+` on types `` and ``" + }, { + "kind" : "CompilerError", + "location" : [ 12, 1, 12, 12 ], + "message" : "Cannot apply operator `==` on types `` and ``" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_expr_if.py b/pa2-tests/core/bad_expr_if.py new file mode 100644 index 0000000..4ae5fbe --- /dev/null +++ b/pa2-tests/core/bad_expr_if.py @@ -0,0 +1,2 @@ +x: int = 0 +x = "Hello" if 2 > 3 else 3 diff --git a/pa2-tests/core/bad_expr_if.py.ast b/pa2-tests/core/bad_expr_if.py.ast new file mode 100644 index 0000000..24d9ed3 --- /dev/null +++ b/pa2-tests/core/bad_expr_if.py.ast @@ -0,0 +1,70 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 2, 28 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 10, 1, 10 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 2, 1, 2, 27 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "IfExpr", + "location" : [ 2, 5, 2, 27 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 2, 16, 2, 20 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 16, 2, 16 ], + "value" : 2 + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 20, 2, 20 ], + "value" : 3 + } + }, + "thenExpr" : { + "kind" : "StringLiteral", + "location" : [ 2, 5, 2, 11 ], + "value" : "Hello" + }, + "elseExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 27, 2, 27 ], + "value" : 3 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_expr_if.py.ast.typed b/pa2-tests/core/bad_expr_if.py.ast.typed new file mode 100644 index 0000000..0da86f1 --- /dev/null +++ b/pa2-tests/core/bad_expr_if.py.ast.typed @@ -0,0 +1,107 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 2, 28 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 10, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 2, 1, 2, 27 ], + "errorMsg" : "Expected type `int`; got type `object`", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "IfExpr", + "location" : [ 2, 5, 2, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 2, 16, 2, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 16, 2, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 20, 2, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + }, + "thenExpr" : { + "kind" : "StringLiteral", + "location" : [ 2, 5, 2, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + }, + "elseExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 27, 2, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 2, 1, 2, 27 ], + "message" : "Expected type `int`; got type `object`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_expr_unary.py b/pa2-tests/core/bad_expr_unary.py new file mode 100644 index 0000000..0b113ac --- /dev/null +++ b/pa2-tests/core/bad_expr_unary.py @@ -0,0 +1,4 @@ +not "Bad" +-True +-None +not [] diff --git a/pa2-tests/core/bad_expr_unary.py.ast b/pa2-tests/core/bad_expr_unary.py.ast new file mode 100644 index 0000000..7632c06 --- /dev/null +++ b/pa2-tests/core/bad_expr_unary.py.ast @@ -0,0 +1,62 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 7 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 9 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 1, 1, 1, 9 ], + "operator" : "not", + "operand" : { + "kind" : "StringLiteral", + "location" : [ 1, 5, 1, 9 ], + "value" : "Bad" + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 5 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 2, 1, 2, 5 ], + "operator" : "-", + "operand" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 2, 2, 5 ], + "value" : true + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 5 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 3, 1, 3, 5 ], + "operator" : "-", + "operand" : { + "kind" : "NoneLiteral", + "location" : [ 3, 2, 3, 5 ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 6 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 4, 1, 4, 6 ], + "operator" : "not", + "operand" : { + "kind" : "ListExpr", + "location" : [ 4, 5, 4, 6 ], + "elements" : [ ] + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_expr_unary.py.ast.typed b/pa2-tests/core/bad_expr_unary.py.ast.typed new file mode 100644 index 0000000..f366c93 --- /dev/null +++ b/pa2-tests/core/bad_expr_unary.py.ast.typed @@ -0,0 +1,114 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 7 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 9 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 1, 1, 1, 9 ], + "errorMsg" : "Cannot apply operator `not` on type `str`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "operator" : "not", + "operand" : { + "kind" : "StringLiteral", + "location" : [ 1, 5, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Bad" + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 5 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 2, 1, 2, 5 ], + "errorMsg" : "Cannot apply operator `-` on type `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 2, 2, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 5 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 3, 1, 3, 5 ], + "errorMsg" : "Cannot apply operator `-` on type ``", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "NoneLiteral", + "location" : [ 3, 2, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 6 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 4, 1, 4, 6 ], + "errorMsg" : "Cannot apply operator `not` on type ``", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "operator" : "not", + "operand" : { + "kind" : "ListExpr", + "location" : [ 4, 5, 4, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + } + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 1, 1, 9 ], + "message" : "Cannot apply operator `not` on type `str`" + }, { + "kind" : "CompilerError", + "location" : [ 2, 1, 2, 5 ], + "message" : "Cannot apply operator `-` on type `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 3, 1, 3, 5 ], + "message" : "Cannot apply operator `-` on type ``" + }, { + "kind" : "CompilerError", + "location" : [ 4, 1, 4, 6 ], + "message" : "Cannot apply operator `not` on type ``" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_func_def_call.py b/pa2-tests/core/bad_func_def_call.py new file mode 100644 index 0000000..a929805 --- /dev/null +++ b/pa2-tests/core/bad_func_def_call.py @@ -0,0 +1,13 @@ +def foo(x:str, y:bool) -> int: + return bar() + +def bar() -> int: + return 1 + +# All of the below are bad calls +foo("Hello") +foo("Hello", False, 3) +foo("Hello", 3) +foo(1, "Hello") +baz() + diff --git a/pa2-tests/core/bad_func_def_call.py.ast b/pa2-tests/core/bad_func_def_call.py.ast new file mode 100644 index 0000000..64c0e9d --- /dev/null +++ b/pa2-tests/core/bad_func_def_call.py.ast @@ -0,0 +1,187 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 12, 6 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 16, 1, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 16, 1, 16 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 18, 1, 21 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 27, 1, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 16 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 2, 12, 2, 16 ], + "function" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 14 ], + "name" : "bar" + }, + "args" : [ ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 5, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 14, 4, 16 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 12, 5, 12 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 8, 5, 8, 11 ], + "value" : "Hello" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 22 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 9, 1, 9, 22 ], + "function" : { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 9, 5, 9, 11 ], + "value" : "Hello" + }, { + "kind" : "BooleanLiteral", + "location" : [ 9, 14, 9, 18 ], + "value" : false + }, { + "kind" : "IntegerLiteral", + "location" : [ 9, 21, 9, 21 ], + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 1, 10, 15 ], + "function" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 10, 5, 10, 11 ], + "value" : "Hello" + }, { + "kind" : "IntegerLiteral", + "location" : [ 10, 14, 10, 14 ], + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 1, 11, 15 ], + "function" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 11, 5, 11, 5 ], + "value" : 1 + }, { + "kind" : "StringLiteral", + "location" : [ 11, 8, 11, 14 ], + "value" : "Hello" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 12, 1, 12, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 12, 1, 12, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 3 ], + "name" : "baz" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_func_def_call.py.ast.typed b/pa2-tests/core/bad_func_def_call.py.ast.typed new file mode 100644 index 0000000..e9dc647 --- /dev/null +++ b/pa2-tests/core/bad_func_def_call.py.ast.typed @@ -0,0 +1,336 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 12, 6 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 16, 1, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 16, 1, 16 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 18, 1, 21 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 27, 1, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 16 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 2, 12, 2, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "bar" + }, + "args" : [ ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 5, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 14, 4, 16 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 12, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 12 ], + "errorMsg" : "Expected 2 arguments; got 1", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 3 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "bool" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 8, 5, 8, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 22 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 9, 1, 9, 22 ], + "errorMsg" : "Expected 2 arguments; got 3", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 3 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "bool" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 9, 5, 9, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + }, { + "kind" : "BooleanLiteral", + "location" : [ 9, 14, 9, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, { + "kind" : "IntegerLiteral", + "location" : [ 9, 21, 9, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 1, 10, 15 ], + "errorMsg" : "Expected type `bool`; got type `int` in parameter 1", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 3 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "bool" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 10, 5, 10, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + }, { + "kind" : "IntegerLiteral", + "location" : [ 10, 14, 10, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 1, 11, 15 ], + "errorMsg" : "Expected type `str`; got type `int` in parameter 0", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 3 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "bool" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 11, 5, 11, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "StringLiteral", + "location" : [ 11, 8, 11, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 12, 1, 12, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 12, 1, 12, 5 ], + "errorMsg" : "Not a function or class: baz", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 3 ], + "name" : "baz" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 8, 1, 8, 12 ], + "message" : "Expected 2 arguments; got 1" + }, { + "kind" : "CompilerError", + "location" : [ 9, 1, 9, 22 ], + "message" : "Expected 2 arguments; got 3" + }, { + "kind" : "CompilerError", + "location" : [ 10, 1, 10, 15 ], + "message" : "Expected type `bool`; got type `int` in parameter 1" + }, { + "kind" : "CompilerError", + "location" : [ 11, 1, 11, 15 ], + "message" : "Expected type `str`; got type `int` in parameter 0" + }, { + "kind" : "CompilerError", + "location" : [ 12, 1, 12, 5 ], + "message" : "Not a function or class: baz" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_func_def_return.py b/pa2-tests/core/bad_func_def_return.py new file mode 100644 index 0000000..efccffb --- /dev/null +++ b/pa2-tests/core/bad_func_def_return.py @@ -0,0 +1,10 @@ +def foo(x:str, y:bool) -> int: + return None + +def bar() -> bool: + return 1 + +def baz() -> str: + return + +foo("Hello", False) diff --git a/pa2-tests/core/bad_func_def_return.py.ast b/pa2-tests/core/bad_func_def_return.py.ast new file mode 100644 index 0000000..e7aaa31 --- /dev/null +++ b/pa2-tests/core/bad_func_def_return.py.ast @@ -0,0 +1,125 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 10, 20 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 16 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 16, 1, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 16, 1, 16 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 18, 1, 21 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 27, 1, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 15 ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 12, 2, 15 ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 5, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 14, 4, 17 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 12, 5, 12 ], + "value" : 1 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 7, 1, 8, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 7 ], + "name" : "baz" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 14, 7, 16 ], + "className" : "str" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 8, 5, 8, 10 ], + "value" : null + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 19 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 1, 10, 19 ], + "function" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 10, 5, 10, 11 ], + "value" : "Hello" + }, { + "kind" : "BooleanLiteral", + "location" : [ 10, 14, 10, 18 ], + "value" : false + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_func_def_return.py.ast.typed b/pa2-tests/core/bad_func_def_return.py.ast.typed new file mode 100644 index 0000000..8dafad8 --- /dev/null +++ b/pa2-tests/core/bad_func_def_return.py.ast.typed @@ -0,0 +1,174 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 10, 20 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 16 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 16, 1, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 16, 1, 16 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 18, 1, 21 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 27, 1, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 15 ], + "errorMsg" : "Expected type `int`; got type ``", + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 12, 2, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 5, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 14, 4, 17 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 12 ], + "errorMsg" : "Expected type `bool`; got type `int`", + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 12, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 7, 1, 8, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 7 ], + "name" : "baz" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 14, 7, 16 ], + "className" : "str" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 8, 5, 8, 10 ], + "errorMsg" : "Expected type `str`; got `None`", + "value" : null + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 19 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 1, 10, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 3 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "bool" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 10, 5, 10, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + }, { + "kind" : "BooleanLiteral", + "location" : [ 10, 14, 10, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 2, 5, 2, 15 ], + "message" : "Expected type `int`; got type ``" + }, { + "kind" : "CompilerError", + "location" : [ 5, 5, 5, 12 ], + "message" : "Expected type `bool`; got type `int`" + }, { + "kind" : "CompilerError", + "location" : [ 8, 5, 8, 10 ], + "message" : "Expected type `str`; got `None`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_list_assign.py b/pa2-tests/core/bad_list_assign.py new file mode 100644 index 0000000..f85c242 --- /dev/null +++ b/pa2-tests/core/bad_list_assign.py @@ -0,0 +1,6 @@ +x:[int] = None +y:[object] = None + +x = [1, 2, 3] +y = x +y = [1] diff --git a/pa2-tests/core/bad_list_assign.py.ast b/pa2-tests/core/bad_list_assign.py.ast new file mode 100644 index 0000000..5fa5dd5 --- /dev/null +++ b/pa2-tests/core/bad_list_assign.py.ast @@ -0,0 +1,116 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 8 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ] + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 10 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 9 ], + "className" : "object" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 14, 2, 17 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 4, 5, 4, 13 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 6, 4, 6 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 12, 4, 12 ], + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "y" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "x" + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "y" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 6, 5, 6, 7 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 6, 6, 6 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_list_assign.py.ast.typed b/pa2-tests/core/bad_list_assign.py.ast.typed new file mode 100644 index 0000000..b07e2b3 --- /dev/null +++ b/pa2-tests/core/bad_list_assign.py.ast.typed @@ -0,0 +1,192 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 8 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 10 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 9 ], + "className" : "object" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 14, 2, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 4, 5, 4, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 6, 4, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 12, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 5 ], + "errorMsg" : "Expected type `[object]`; got type `[int]`", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "y" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 7 ], + "errorMsg" : "Expected type `[object]`; got type `[int]`", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "y" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 6, 5, 6, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 6, 6, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 5, 1, 5, 5 ], + "message" : "Expected type `[object]`; got type `[int]`" + }, { + "kind" : "CompilerError", + "location" : [ 6, 1, 6, 7 ], + "message" : "Expected type `[object]`; got type `[int]`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_list_index.py b/pa2-tests/core/bad_list_index.py new file mode 100644 index 0000000..7b0c708 --- /dev/null +++ b/pa2-tests/core/bad_list_index.py @@ -0,0 +1,7 @@ +x:[int] = None + +x = [1, 2, 3] +x[True] # Bad +False[0] # Bad +[][0] # Bad +x[True] = x[False] = 1 diff --git a/pa2-tests/core/bad_list_index.py.ast b/pa2-tests/core/bad_list_index.py.ast new file mode 100644 index 0000000..b805e51 --- /dev/null +++ b/pa2-tests/core/bad_list_index.py.ast @@ -0,0 +1,147 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 23 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 3, 5, 3, 13 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 12, 3, 12 ], + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 7 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 4, 1, 4, 7 ], + "list" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 3, 4, 6 ], + "value" : true + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 8 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 5, 1, 5, 8 ], + "list" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 1, 5, 5 ], + "value" : false + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 7, 5, 7 ], + "value" : 0 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 5 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 6, 1, 6, 5 ], + "list" : { + "kind" : "ListExpr", + "location" : [ 6, 1, 6, 2 ], + "elements" : [ ] + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 4, 6, 4 ], + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 22 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 7, 1, 7, 7 ], + "list" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 3, 7, 6 ], + "value" : true + } + }, { + "kind" : "IndexExpr", + "location" : [ 7, 11, 7, 18 ], + "list" : { + "kind" : "Identifier", + "location" : [ 7, 11, 7, 11 ], + "name" : "x" + }, + "index" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 13, 7, 17 ], + "value" : false + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 22, 7, 22 ], + "value" : 1 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_list_index.py.ast.typed b/pa2-tests/core/bad_list_index.py.ast.typed new file mode 100644 index 0000000..fa390f3 --- /dev/null +++ b/pa2-tests/core/bad_list_index.py.ast.typed @@ -0,0 +1,275 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 23 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 3, 5, 3, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 12, 3, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 7 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 4, 1, 4, 7 ], + "errorMsg" : "Index is of non-integer type `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 3, 4, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 8 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 5, 1, 5, 8 ], + "errorMsg" : "Cannot index into type `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "list" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 1, 5, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 7, 5, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 5 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 6, 1, 6, 5 ], + "errorMsg" : "Cannot index into type ``", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "list" : { + "kind" : "ListExpr", + "location" : [ 6, 1, 6, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 4, 6, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 22 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 7, 1, 7, 7 ], + "errorMsg" : "Index is of non-integer type `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 3, 7, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "IndexExpr", + "location" : [ 7, 11, 7, 18 ], + "errorMsg" : "Index is of non-integer type `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 7, 11, 7, 11 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 13, 7, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 22, 7, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 4, 1, 4, 7 ], + "message" : "Index is of non-integer type `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 5, 1, 5, 8 ], + "message" : "Cannot index into type `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 6, 1, 6, 5 ], + "message" : "Cannot index into type ``" + }, { + "kind" : "CompilerError", + "location" : [ 7, 1, 7, 7 ], + "message" : "Index is of non-integer type `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 7, 11, 7, 18 ], + "message" : "Index is of non-integer type `bool`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_local_assign.py b/pa2-tests/core/bad_local_assign.py new file mode 100644 index 0000000..77f3420 --- /dev/null +++ b/pa2-tests/core/bad_local_assign.py @@ -0,0 +1,23 @@ +x:int = 1 +y:int = 2 +z:int = 3 + +def foo(x:int) -> object: + y:int = 4 # OK + global z # OK + + def qux() -> int: + y = 1 # Bad, nonlocal not declared + return 0 + + z = 1 # OK + + pass + +def bar(x:int) -> int: + z = 1 # Bad, global not declared + return x + + +foo(1) + diff --git a/pa2-tests/core/bad_local_assign.py.ast b/pa2-tests/core/bad_local_assign.py.ast new file mode 100644 index 0000000..ffac6b5 --- /dev/null +++ b/pa2-tests/core/bad_local_assign.py.ast @@ -0,0 +1,253 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 22, 7 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "value" : 3 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 15, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 9, 5, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 11, 5, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 19, 5, 24 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "value" : 4 + } + }, { + "kind" : "GlobalDecl", + "location" : [ 7, 5, 7, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 7, 12, 7, 12 ], + "name" : "z" + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 11, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "name" : "qux" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 18, 9, 20 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 10, 9, 10, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 9 ], + "name" : "y" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 13, 10, 13 ], + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 11, 9, 11, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 16, 11, 16 ], + "value" : 0 + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 13, 5, 13, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 5 ], + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 9, 13, 9 ], + "value" : 1 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 17, 1, 19, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 7 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 17, 9, 17, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 9, 17, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 11, 17, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 17, 19, 17, 21 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 18, 5, 18, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 18, 5, 18, 5 ], + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 18, 9, 18, 9 ], + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 19, 5, 19, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 19, 12, 19, 12 ], + "name" : "x" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 22, 1, 22, 6 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 22, 1, 22, 6 ], + "function" : { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 22, 5, 22, 5 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_local_assign.py.ast.typed b/pa2-tests/core/bad_local_assign.py.ast.typed new file mode 100644 index 0000000..ec39de4 --- /dev/null +++ b/pa2-tests/core/bad_local_assign.py.ast.typed @@ -0,0 +1,330 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 22, 7 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 15, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 9, 5, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 11, 5, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 19, 5, 24 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + }, { + "kind" : "GlobalDecl", + "location" : [ 7, 5, 7, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 7, 12, 7, 12 ], + "name" : "z" + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 11, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "name" : "qux" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 18, 9, 20 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 10, 9, 10, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 9 ], + "errorMsg" : "Cannot assign to variable that is not explicitly declared in this scope: y", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 13, 10, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 11, 9, 11, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 16, 11, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 13, 5, 13, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 9, 13, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 17, 1, 19, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 7 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 17, 9, 17, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 9, 17, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 11, 17, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 17, 19, 17, 21 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 18, 5, 18, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 18, 5, 18, 5 ], + "errorMsg" : "Cannot assign to variable that is not explicitly declared in this scope: z", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 18, 9, 18, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 19, 5, 19, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 19, 12, 19, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 22, 1, 22, 6 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 22, 1, 22, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 3 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 22, 5, 22, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 10, 9, 10, 9 ], + "message" : "Cannot assign to variable that is not explicitly declared in this scope: y" + }, { + "kind" : "CompilerError", + "location" : [ 18, 5, 18, 5 ], + "message" : "Cannot assign to variable that is not explicitly declared in this scope: z" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_none_assign.py b/pa2-tests/core/bad_none_assign.py new file mode 100644 index 0000000..fc0ec3f --- /dev/null +++ b/pa2-tests/core/bad_none_assign.py @@ -0,0 +1,14 @@ +class A(object): + x:int = 1 + +y:[bool] = None +z:str = "" +a:A = None + +a = A() + +# Cannot assign None to integer/bool/str types +z = None +a.x = None +y[0] = None + diff --git a/pa2-tests/core/bad_none_assign.py.ast b/pa2-tests/core/bad_none_assign.py.ast new file mode 100644 index 0000000..a0a1246 --- /dev/null +++ b/pa2-tests/core/bad_none_assign.py.ast @@ -0,0 +1,187 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 13, 12 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 4, 3, 4, 8 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 4, 4, 4, 7 ], + "className" : "bool" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 12, 4, 15 ] + } + }, { + "kind" : "VarDef", + "location" : [ 5, 1, 5, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 1, 5, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 3, 5, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 5, 9, 5, 10 ], + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 6, 1, 6, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 1, 6, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 3, 6, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 6, 7, 6, 10 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 8, 5, 8, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 11, 1, 11, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 5, 11, 8 ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 12, 1, 12, 10 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 12, 1, 12, 3 ], + "object" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 12, 3, 12, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 7, 12, 10 ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 13, 1, 13, 11 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 13, 1, 13, 4 ], + "list" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "y" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 3, 13, 3 ], + "value" : 0 + } + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 13, 8, 13, 11 ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_none_assign.py.ast.typed b/pa2-tests/core/bad_none_assign.py.ast.typed new file mode 100644 index 0000000..2edc3c2 --- /dev/null +++ b/pa2-tests/core/bad_none_assign.py.ast.typed @@ -0,0 +1,265 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 13, 12 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 4, 3, 4, 8 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 4, 4, 4, 7 ], + "className" : "bool" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 12, 4, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 5, 1, 5, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 1, 5, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 3, 5, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 5, 9, 5, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 6, 1, 6, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 1, 6, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 3, 6, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 6, 7, 6, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 8, 5, 8, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 11, 1, 11, 8 ], + "errorMsg" : "Expected type `str`; got type ``", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 5, 11, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 12, 1, 12, 10 ], + "errorMsg" : "Expected type `int`; got type ``", + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 12, 1, 12, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 12, 3, 12, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 7, 12, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 13, 1, 13, 11 ], + "errorMsg" : "Expected type `bool`; got type ``", + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 13, 1, 13, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "y" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 3, 13, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 13, 8, 13, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 11, 1, 11, 8 ], + "message" : "Expected type `str`; got type ``" + }, { + "kind" : "CompilerError", + "location" : [ 12, 1, 12, 10 ], + "message" : "Expected type `int`; got type ``" + }, { + "kind" : "CompilerError", + "location" : [ 13, 1, 13, 11 ], + "message" : "Expected type `bool`; got type ``" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_nonlocal_global.py b/pa2-tests/core/bad_nonlocal_global.py new file mode 100644 index 0000000..98eea5c --- /dev/null +++ b/pa2-tests/core/bad_nonlocal_global.py @@ -0,0 +1,25 @@ +x:int = 1 +y:int = 2 +z:int = 3 + +def foo() -> object: + global x # OK + nonlocal y # No such nonlocal var + global w # No such global var + global int # No such global var + + z:bool = True # OK + + def bar() -> object: + global x # OK + nonlocal z # OK + nonlocal y # No such nonlocal var + global foo # No such global var + nonlocal bar # No such nonlocal var + + pass + + bar() + +foo() + diff --git a/pa2-tests/core/bad_nonlocal_global.py.ast b/pa2-tests/core/bad_nonlocal_global.py.ast new file mode 100644 index 0000000..dce287d --- /dev/null +++ b/pa2-tests/core/bad_nonlocal_global.py.ast @@ -0,0 +1,229 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 24, 6 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "value" : 3 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 22, 10 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 7 ], + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 14, 5, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 6, 5, 6, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 6, 12, 6, 12 ], + "name" : "x" + } + }, { + "kind" : "NonLocalDecl", + "location" : [ 7, 5, 7, 14 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 7, 14, 7, 14 ], + "name" : "y" + } + }, { + "kind" : "GlobalDecl", + "location" : [ 8, 5, 8, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 8, 12, 8, 12 ], + "name" : "w" + } + }, { + "kind" : "GlobalDecl", + "location" : [ 9, 5, 9, 14 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 14 ], + "name" : "int" + } + }, { + "kind" : "VarDef", + "location" : [ 11, 5, 11, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 5, 11, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 7, 11, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 11, 14, 11, 17 ], + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 13, 5, 20, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 13, 9, 13, 11 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 13, 18, 13, 23 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 14, 9, 14, 16 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 14, 16, 14, 16 ], + "name" : "x" + } + }, { + "kind" : "NonLocalDecl", + "location" : [ 15, 9, 15, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 15, 18, 15, 18 ], + "name" : "z" + } + }, { + "kind" : "NonLocalDecl", + "location" : [ 16, 9, 16, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 16, 18, 16, 18 ], + "name" : "y" + } + }, { + "kind" : "GlobalDecl", + "location" : [ 17, 9, 17, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 17, 16, 17, 18 ], + "name" : "foo" + } + }, { + "kind" : "NonLocalDecl", + "location" : [ 18, 9, 18, 20 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 18, 18, 18, 20 ], + "name" : "bar" + } + } ], + "statements" : [ ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 22, 5, 22, 9 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 22, 5, 22, 9 ], + "function" : { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 7 ], + "name" : "bar" + }, + "args" : [ ] + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 24, 1, 24, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 24, 1, 24, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 24, 1, 24, 3 ], + "name" : "foo" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_nonlocal_global.py.ast.typed b/pa2-tests/core/bad_nonlocal_global.py.ast.typed new file mode 100644 index 0000000..3b80c08 --- /dev/null +++ b/pa2-tests/core/bad_nonlocal_global.py.ast.typed @@ -0,0 +1,259 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 24, 6 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "value" : 3 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 22, 10 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 7 ], + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 14, 5, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 6, 5, 6, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 6, 12, 6, 12 ], + "name" : "x" + } + }, { + "kind" : "NonLocalDecl", + "location" : [ 7, 5, 7, 14 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 7, 14, 7, 14 ], + "errorMsg" : "Not a nonlocal variable: y", + "name" : "y" + } + }, { + "kind" : "GlobalDecl", + "location" : [ 8, 5, 8, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 8, 12, 8, 12 ], + "errorMsg" : "Not a global variable: w", + "name" : "w" + } + }, { + "kind" : "GlobalDecl", + "location" : [ 9, 5, 9, 14 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 14 ], + "errorMsg" : "Not a global variable: int", + "name" : "int" + } + }, { + "kind" : "VarDef", + "location" : [ 11, 5, 11, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 5, 11, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 7, 11, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 11, 14, 11, 17 ], + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 13, 5, 20, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 13, 9, 13, 11 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 13, 18, 13, 23 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 14, 9, 14, 16 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 14, 16, 14, 16 ], + "name" : "x" + } + }, { + "kind" : "NonLocalDecl", + "location" : [ 15, 9, 15, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 15, 18, 15, 18 ], + "name" : "z" + } + }, { + "kind" : "NonLocalDecl", + "location" : [ 16, 9, 16, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 16, 18, 16, 18 ], + "errorMsg" : "Not a nonlocal variable: y", + "name" : "y" + } + }, { + "kind" : "GlobalDecl", + "location" : [ 17, 9, 17, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 17, 16, 17, 18 ], + "errorMsg" : "Not a global variable: foo", + "name" : "foo" + } + }, { + "kind" : "NonLocalDecl", + "location" : [ 18, 9, 18, 20 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 18, 18, 18, 20 ], + "errorMsg" : "Not a nonlocal variable: bar", + "name" : "bar" + } + } ], + "statements" : [ ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 22, 5, 22, 9 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 22, 5, 22, 9 ], + "function" : { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 7 ], + "name" : "bar" + }, + "args" : [ ] + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 24, 1, 24, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 24, 1, 24, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 24, 1, 24, 3 ], + "name" : "foo" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 7, 14, 7, 14 ], + "message" : "Not a nonlocal variable: y" + }, { + "kind" : "CompilerError", + "location" : [ 8, 12, 8, 12 ], + "message" : "Not a global variable: w" + }, { + "kind" : "CompilerError", + "location" : [ 9, 12, 9, 14 ], + "message" : "Not a global variable: int" + }, { + "kind" : "CompilerError", + "location" : [ 16, 18, 16, 18 ], + "message" : "Not a nonlocal variable: y" + }, { + "kind" : "CompilerError", + "location" : [ 17, 16, 17, 18 ], + "message" : "Not a global variable: foo" + }, { + "kind" : "CompilerError", + "location" : [ 18, 18, 18, 20 ], + "message" : "Not a nonlocal variable: bar" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_return_missing.py b/pa2-tests/core/bad_return_missing.py new file mode 100644 index 0000000..9200f93 --- /dev/null +++ b/pa2-tests/core/bad_return_missing.py @@ -0,0 +1,6 @@ +def foo() -> int: + if True: + return 1 + # Bad: all paths MUST return int + +foo() diff --git a/pa2-tests/core/bad_return_missing.py.ast b/pa2-tests/core/bad_return_missing.py.ast new file mode 100644 index 0000000..8efc035 --- /dev/null +++ b/pa2-tests/core/bad_return_missing.py.ast @@ -0,0 +1,58 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 6 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 6, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 14, 1, 16 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 2, 5, 6, 0 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 8, 2, 11 ], + "value" : true + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 9, 3, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 16, 3, 16 ], + "value" : 1 + } + } ], + "elseBody" : [ ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 1, 6, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 3 ], + "name" : "foo" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_return_missing.py.ast.typed b/pa2-tests/core/bad_return_missing.py.ast.typed new file mode 100644 index 0000000..627d4f3 --- /dev/null +++ b/pa2-tests/core/bad_return_missing.py.ast.typed @@ -0,0 +1,63 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 6 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 6, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "errorMsg" : "All paths in this function/method must have a return statement: foo", + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 14, 1, 16 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 2, 5, 6, 0 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 8, 2, 11 ], + "value" : true + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 9, 3, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 16, 3, 16 ], + "value" : 1 + } + } ], + "elseBody" : [ ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 1, 6, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 3 ], + "name" : "foo" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 5, 1, 7 ], + "message" : "All paths in this function/method must have a return statement: foo" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_return_top.py b/pa2-tests/core/bad_return_top.py new file mode 100644 index 0000000..ca0d0e0 --- /dev/null +++ b/pa2-tests/core/bad_return_top.py @@ -0,0 +1,3 @@ +x:int = 0 + +return x diff --git a/pa2-tests/core/bad_return_top.py.ast b/pa2-tests/core/bad_return_top.py.ast new file mode 100644 index 0000000..992907a --- /dev/null +++ b/pa2-tests/core/bad_return_top.py.ast @@ -0,0 +1,41 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 1, 3, 8 ], + "value" : { + "kind" : "Identifier", + "location" : [ 3, 8, 3, 8 ], + "name" : "x" + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_return_top.py.ast.typed b/pa2-tests/core/bad_return_top.py.ast.typed new file mode 100644 index 0000000..56df1de --- /dev/null +++ b/pa2-tests/core/bad_return_top.py.ast.typed @@ -0,0 +1,50 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 1, 3, 8 ], + "errorMsg" : "Return statement cannot appear at the top level", + "value" : { + "kind" : "Identifier", + "location" : [ 3, 8, 3, 8 ], + "name" : "x" + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 3, 1, 3, 8 ], + "message" : "Return statement cannot appear at the top level" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_shadow_local.py b/pa2-tests/core/bad_shadow_local.py new file mode 100644 index 0000000..9fc916b --- /dev/null +++ b/pa2-tests/core/bad_shadow_local.py @@ -0,0 +1,14 @@ +class A(object): + x:int = 1 + +def foo(x:int, bool:str) -> object: # Second param uses an invalid name + y:int = 4 # OK + A:int = 5 # Invalid name + object:str = "" # Invalid name + + def str() -> bool: # Invalid name + return False + + pass + +pass diff --git a/pa2-tests/core/bad_shadow_local.py.ast b/pa2-tests/core/bad_shadow_local.py.ast new file mode 100644 index 0000000..cff93dc --- /dev/null +++ b/pa2-tests/core/bad_shadow_local.py.ast @@ -0,0 +1,179 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 14, 5 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 12, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 9, 4, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 11, 4, 13 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 16, 4, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 16, 4, 19 ], + "name" : "bool" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 21, 4, 23 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 29, 4, 34 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 5, 5, 5, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 5, 5, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 7, 5, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 13, 5, 13 ], + "value" : 4 + } + }, { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "A" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "value" : 5 + } + }, { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 10 ], + "name" : "object" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 12, 7, 14 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 7, 18, 7, 19 ], + "value" : "" + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 10, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "name" : "str" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 18, 9, 21 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 10, 9, 10, 20 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 10, 16, 10, 20 ], + "value" : false + } + } ] + } ], + "statements" : [ ] + } ], + "statements" : [ ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_shadow_local.py.ast.typed b/pa2-tests/core/bad_shadow_local.py.ast.typed new file mode 100644 index 0000000..3cc9b9b --- /dev/null +++ b/pa2-tests/core/bad_shadow_local.py.ast.typed @@ -0,0 +1,199 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 14, 5 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 12, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 9, 4, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 11, 4, 13 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 16, 4, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 16, 4, 19 ], + "errorMsg" : "Cannot shadow class name: bool", + "name" : "bool" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 21, 4, 23 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 29, 4, 34 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 5, 5, 5, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 5, 5, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 7, 5, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 13, 5, 13 ], + "value" : 4 + } + }, { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "errorMsg" : "Cannot shadow class name: A", + "name" : "A" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "value" : 5 + } + }, { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 10 ], + "errorMsg" : "Cannot shadow class name: object", + "name" : "object" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 12, 7, 14 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 7, 18, 7, 19 ], + "value" : "" + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 10, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "errorMsg" : "Cannot shadow class name: str", + "name" : "str" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 18, 9, 21 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 10, 9, 10, 20 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 10, 16, 10, 20 ], + "value" : false + } + } ] + } ], + "statements" : [ ] + } ], + "statements" : [ ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 4, 16, 4, 19 ], + "message" : "Cannot shadow class name: bool" + }, { + "kind" : "CompilerError", + "location" : [ 6, 5, 6, 5 ], + "message" : "Cannot shadow class name: A" + }, { + "kind" : "CompilerError", + "location" : [ 7, 5, 7, 10 ], + "message" : "Cannot shadow class name: object" + }, { + "kind" : "CompilerError", + "location" : [ 9, 9, 9, 11 ], + "message" : "Cannot shadow class name: str" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_shadow_local_2.py b/pa2-tests/core/bad_shadow_local_2.py new file mode 100644 index 0000000..67a327e --- /dev/null +++ b/pa2-tests/core/bad_shadow_local_2.py @@ -0,0 +1,8 @@ +def foo(x:int) -> object: + A:int = 5 # Invalid name + pass + +class A(object): + x:int = 1 + +pass diff --git a/pa2-tests/core/bad_shadow_local_2.py.ast b/pa2-tests/core/bad_shadow_local_2.py.ast new file mode 100644 index 0000000..5eb5b2e --- /dev/null +++ b/pa2-tests/core/bad_shadow_local_2.py.ast @@ -0,0 +1,98 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 5 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 3, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 19, 1, 24 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "A" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 5 + } + } ], + "statements" : [ ] + }, { + "kind" : "ClassDef", + "location" : [ 5, 1, 6, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 7, 5, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_shadow_local_2.py.ast.typed b/pa2-tests/core/bad_shadow_local_2.py.ast.typed new file mode 100644 index 0000000..ff6ef1b --- /dev/null +++ b/pa2-tests/core/bad_shadow_local_2.py.ast.typed @@ -0,0 +1,103 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 5 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 3, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 19, 1, 24 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "errorMsg" : "Cannot shadow class name: A", + "name" : "A" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 5 + } + } ], + "statements" : [ ] + }, { + "kind" : "ClassDef", + "location" : [ 5, 1, 6, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 7, 5, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 2, 5, 2, 5 ], + "message" : "Cannot shadow class name: A" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_strings.py b/pa2-tests/core/bad_strings.py new file mode 100644 index 0000000..86e0e16 --- /dev/null +++ b/pa2-tests/core/bad_strings.py @@ -0,0 +1,10 @@ +x:str = "Hello" +y:str = "World" +z:str = "" + +1 + x +z = x + 1 +z = x[0] = y +x[1] = y +x[True] + diff --git a/pa2-tests/core/bad_strings.py.ast b/pa2-tests/core/bad_strings.py.ast new file mode 100644 index 0000000..04473bf --- /dev/null +++ b/pa2-tests/core/bad_strings.py.ast @@ -0,0 +1,183 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 8 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 15 ], + "value" : "Hello" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 15 ], + "value" : "World" + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 10 ], + "value" : "" + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 5, 1, 5, 5 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 1, 5, 1 ], + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "x" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 6, 5, 6, 9 ], + "left" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "value" : 1 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "z" + }, { + "kind" : "IndexExpr", + "location" : [ 7, 5, 7, 8 ], + "list" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 7, 7, 7 ], + "value" : 0 + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 7, 12, 7, 12 ], + "name" : "y" + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 8, 1, 8, 4 ], + "list" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 3, 8, 3 ], + "value" : 1 + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 8, 8, 8, 8 ], + "name" : "y" + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 7 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 9, 1, 9, 7 ], + "list" : { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "BooleanLiteral", + "location" : [ 9, 3, 9, 6 ], + "value" : true + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_strings.py.ast.typed b/pa2-tests/core/bad_strings.py.ast.typed new file mode 100644 index 0000000..f6f2fbe --- /dev/null +++ b/pa2-tests/core/bad_strings.py.ast.typed @@ -0,0 +1,301 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 8 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "World" + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 5, 1, 5, 5 ], + "errorMsg" : "Cannot apply operator `+` on types `int` and `str`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 9 ], + "errorMsg" : "Expected type `str`; got type `int`", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 6, 5, 6, 9 ], + "errorMsg" : "Cannot apply operator `+` on types `str` and `int`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + }, { + "kind" : "IndexExpr", + "location" : [ 7, 5, 7, 8 ], + "errorMsg" : "`str` is not a list type", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 7, 7, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 7, 12, 7, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "y" + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 8, 1, 8, 4 ], + "errorMsg" : "`str` is not a list type", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 3, 8, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 8, 8, 8, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "y" + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 7 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 9, 1, 9, 7 ], + "errorMsg" : "Index is of non-integer type `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "index" : { + "kind" : "BooleanLiteral", + "location" : [ 9, 3, 9, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 5, 1, 5, 5 ], + "message" : "Cannot apply operator `+` on types `int` and `str`" + }, { + "kind" : "CompilerError", + "location" : [ 6, 5, 6, 9 ], + "message" : "Cannot apply operator `+` on types `str` and `int`" + }, { + "kind" : "CompilerError", + "location" : [ 6, 1, 6, 9 ], + "message" : "Expected type `str`; got type `int`" + }, { + "kind" : "CompilerError", + "location" : [ 7, 5, 7, 8 ], + "message" : "`str` is not a list type" + }, { + "kind" : "CompilerError", + "location" : [ 8, 1, 8, 4 ], + "message" : "`str` is not a list type" + }, { + "kind" : "CompilerError", + "location" : [ 9, 1, 9, 7 ], + "message" : "Index is of non-integer type `bool`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_type_annotation.py b/pa2-tests/core/bad_type_annotation.py new file mode 100644 index 0000000..a25abb6 --- /dev/null +++ b/pa2-tests/core/bad_type_annotation.py @@ -0,0 +1,7 @@ +x:A = None + +def foo(x:B) -> C: + y:D = None + return + +pass diff --git a/pa2-tests/core/bad_type_annotation.py.ast b/pa2-tests/core/bad_type_annotation.py.ast new file mode 100644 index 0000000..e42cf91 --- /dev/null +++ b/pa2-tests/core/bad_type_annotation.py.ast @@ -0,0 +1,86 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 5 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 7, 1, 10 ] + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 5, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 3, 9, 3, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 11, 3, 11 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 17, 3, 17 ], + "className" : "C" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 7, 4, 7 ], + "className" : "D" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 11, 4, 14 ] + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 10 ], + "value" : null + } ] + } ], + "statements" : [ ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_type_annotation.py.ast.typed b/pa2-tests/core/bad_type_annotation.py.ast.typed new file mode 100644 index 0000000..221ad45 --- /dev/null +++ b/pa2-tests/core/bad_type_annotation.py.ast.typed @@ -0,0 +1,106 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 5 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 3 ], + "errorMsg" : "Invalid type annotation; there is no class named: A", + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 7, 1, 10 ] + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 5, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 3, 9, 3, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 11, 3, 11 ], + "errorMsg" : "Invalid type annotation; there is no class named: B", + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 17, 3, 17 ], + "errorMsg" : "Invalid type annotation; there is no class named: C", + "className" : "C" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 7, 4, 7 ], + "errorMsg" : "Invalid type annotation; there is no class named: D", + "className" : "D" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 11, 4, 14 ] + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 10 ], + "value" : null + } ] + } ], + "statements" : [ ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 3, 1, 3 ], + "message" : "Invalid type annotation; there is no class named: A" + }, { + "kind" : "CompilerError", + "location" : [ 3, 11, 3, 11 ], + "message" : "Invalid type annotation; there is no class named: B" + }, { + "kind" : "CompilerError", + "location" : [ 3, 17, 3, 17 ], + "message" : "Invalid type annotation; there is no class named: C" + }, { + "kind" : "CompilerError", + "location" : [ 4, 7, 4, 7 ], + "message" : "Invalid type annotation; there is no class named: D" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_type_id.py b/pa2-tests/core/bad_type_id.py new file mode 100644 index 0000000..0f931fb --- /dev/null +++ b/pa2-tests/core/bad_type_id.py @@ -0,0 +1 @@ +x - 1 diff --git a/pa2-tests/core/bad_type_id.py.ast b/pa2-tests/core/bad_type_id.py.ast new file mode 100644 index 0000000..ff5c46d --- /dev/null +++ b/pa2-tests/core/bad_type_id.py.ast @@ -0,0 +1,29 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 6 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 5 ], + "left" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "value" : 1 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_type_id.py.ast.typed b/pa2-tests/core/bad_type_id.py.ast.typed new file mode 100644 index 0000000..5200116 --- /dev/null +++ b/pa2-tests/core/bad_type_id.py.ast.typed @@ -0,0 +1,51 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 6 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 5 ], + "errorMsg" : "Cannot apply operator `-` on types `object` and `int`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "errorMsg" : "Not a variable: x", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "x" + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 1, 1, 1 ], + "message" : "Not a variable: x" + }, { + "kind" : "CompilerError", + "location" : [ 1, 1, 1, 5 ], + "message" : "Cannot apply operator `-` on types `object` and `int`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_var_assign.py b/pa2-tests/core/bad_var_assign.py new file mode 100644 index 0000000..a383775 --- /dev/null +++ b/pa2-tests/core/bad_var_assign.py @@ -0,0 +1,8 @@ +x:int = 1 +y:bool = True + +x = False +y = 2 +z = 3 +x = z = 4 +x = z = None diff --git a/pa2-tests/core/bad_var_assign.py.ast b/pa2-tests/core/bad_var_assign.py.ast new file mode 100644 index 0000000..6dabcbd --- /dev/null +++ b/pa2-tests/core/bad_var_assign.py.ast @@ -0,0 +1,127 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 13 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 6 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 10, 2, 13 ], + "value" : true + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 5, 4, 9 ], + "value" : false + } + }, { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "y" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 5, 5, 5 ], + "value" : 2 + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 5, 6, 5 ], + "value" : 3 + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 9, 7, 9 ], + "value" : 4 + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "z" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 8, 9, 8, 12 ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/bad_var_assign.py.ast.typed b/pa2-tests/core/bad_var_assign.py.ast.typed new file mode 100644 index 0000000..d8217b8 --- /dev/null +++ b/pa2-tests/core/bad_var_assign.py.ast.typed @@ -0,0 +1,213 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 13 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 6 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 10, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 9 ], + "errorMsg" : "Expected type `int`; got type `bool`", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 5, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + }, { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 5 ], + "errorMsg" : "Expected type `bool`; got type `int`", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "name" : "y" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 5, 5, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "errorMsg" : "Not a variable: z", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 5, 6, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "errorMsg" : "Not a variable: z", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 9, 7, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 12 ], + "errorMsg" : "Expected type `int`; got type ``", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "errorMsg" : "Not a variable: z", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "z" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 8, 9, 8, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 4, 1, 4, 9 ], + "message" : "Expected type `int`; got type `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 5, 1, 5, 5 ], + "message" : "Expected type `bool`; got type `int`" + }, { + "kind" : "CompilerError", + "location" : [ 6, 1, 6, 1 ], + "message" : "Not a variable: z" + }, { + "kind" : "CompilerError", + "location" : [ 7, 5, 7, 5 ], + "message" : "Not a variable: z" + }, { + "kind" : "CompilerError", + "location" : [ 8, 1, 8, 12 ], + "message" : "Expected type `int`; got type ``" + }, { + "kind" : "CompilerError", + "location" : [ 8, 5, 8, 5 ], + "message" : "Not a variable: z" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/class_def_assign.py b/pa2-tests/core/class_def_assign.py new file mode 100644 index 0000000..44459ff --- /dev/null +++ b/pa2-tests/core/class_def_assign.py @@ -0,0 +1,18 @@ +class A(object): + x:int = 1 + +class B(A): + def __init__(self: "B"): + pass + +class C(B): + z:bool = True + +a:A = None +b:B = None +c:C = None + +a = A() +a = B() +b = a = c = C() +c = None diff --git a/pa2-tests/core/class_def_assign.py.ast b/pa2-tests/core/class_def_assign.py.ast new file mode 100644 index 0000000..92ae3a1 --- /dev/null +++ b/pa2-tests/core/class_def_assign.py.ast @@ -0,0 +1,263 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 18, 9 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 18, 5, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 24, 5, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 28, 5, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 8, 1, 9, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 7, 9, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 9, 14, 9, 17 ], + "value" : true + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 12, 1, 12, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 1, 12, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 3, 12, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 7, 12, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 13, 1, 13, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 1, 13, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 3, 13, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 13, 7, 13, 10 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 1, 15, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 15, 5, 15, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 15, 5, 15, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 16, 1, 16, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 1 ], + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 5, 16, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 17, 1, 17, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "b" + }, { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 5 ], + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 17, 9, 17, 9 ], + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 17, 13, 17, 15 ], + "function" : { + "kind" : "Identifier", + "location" : [ 17, 13, 17, 13 ], + "name" : "C" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 18, 1, 18, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 1 ], + "name" : "c" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 18, 5, 18, 8 ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/class_def_assign.py.ast.typed b/pa2-tests/core/class_def_assign.py.ast.typed new file mode 100644 index 0000000..e012a95 --- /dev/null +++ b/pa2-tests/core/class_def_assign.py.ast.typed @@ -0,0 +1,323 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 18, 9 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 18, 5, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 24, 5, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 28, 5, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 8, 1, 9, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 7, 9, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 9, 14, 9, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 12, 1, 12, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 1, 12, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 3, 12, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 7, 12, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 13, 1, 13, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 1, 13, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 3, 13, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 13, 7, 13, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 1, 15, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 15, 5, 15, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 5, 15, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 16, 1, 16, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 5, 16, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 17, 1, 17, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 17, 9, 17, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 17, 13, 17, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 17, 13, 17, 13 ], + "name" : "C" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 18, 1, 18, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 18, 5, 18, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/class_def_attr.py b/pa2-tests/core/class_def_attr.py new file mode 100644 index 0000000..9a5d948 --- /dev/null +++ b/pa2-tests/core/class_def_attr.py @@ -0,0 +1,22 @@ +class A(object): + x:int = 1 + +class B(A): + def __init__(self: "B"): + pass + +class C(B): + z:bool = True + +a:A = None +b:B = None +c:C = None + +a = A() +b = B() +c = C() + +a.x = 1 +b.x = a.x +c.z = a.x == b.x + diff --git a/pa2-tests/core/class_def_attr.py.ast b/pa2-tests/core/class_def_attr.py.ast new file mode 100644 index 0000000..b4dcc19 --- /dev/null +++ b/pa2-tests/core/class_def_attr.py.ast @@ -0,0 +1,346 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 21, 17 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 18, 5, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 24, 5, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 28, 5, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 8, 1, 9, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 7, 9, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 9, 14, 9, 17 ], + "value" : true + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 12, 1, 12, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 1, 12, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 3, 12, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 7, 12, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 13, 1, 13, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 1, 13, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 3, 13, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 13, 7, 13, 10 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 1, 15, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 15, 5, 15, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 15, 5, 15, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 16, 1, 16, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 1 ], + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 5, 16, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 17, 1, 17, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 17, 5, 17, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 5 ], + "name" : "C" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 19, 1, 19, 7 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 19, 1, 19, 3 ], + "object" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 1 ], + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 19, 3, 19, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 19, 7, 19, 7 ], + "value" : 1 + } + }, { + "kind" : "AssignStmt", + "location" : [ 20, 1, 20, 9 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 20, 1, 20, 3 ], + "object" : { + "kind" : "Identifier", + "location" : [ 20, 1, 20, 1 ], + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 3, 20, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 20, 7, 20, 9 ], + "object" : { + "kind" : "Identifier", + "location" : [ 20, 7, 20, 7 ], + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 9, 20, 9 ], + "name" : "x" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 21, 1, 21, 16 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 21, 1, 21, 3 ], + "object" : { + "kind" : "Identifier", + "location" : [ 21, 1, 21, 1 ], + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 21, 3, 21, 3 ], + "name" : "z" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 21, 7, 21, 16 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 21, 7, 21, 9 ], + "object" : { + "kind" : "Identifier", + "location" : [ 21, 7, 21, 7 ], + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 21, 9, 21, 9 ], + "name" : "x" + } + }, + "operator" : "==", + "right" : { + "kind" : "MemberExpr", + "location" : [ 21, 14, 21, 16 ], + "object" : { + "kind" : "Identifier", + "location" : [ 21, 14, 21, 14 ], + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 21, 16, 21, 16 ], + "name" : "x" + } + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/class_def_attr.py.ast.typed b/pa2-tests/core/class_def_attr.py.ast.typed new file mode 100644 index 0000000..600032c --- /dev/null +++ b/pa2-tests/core/class_def_attr.py.ast.typed @@ -0,0 +1,446 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 21, 17 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 18, 5, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 24, 5, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 28, 5, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 8, 1, 9, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 7, 9, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 9, 14, 9, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 12, 1, 12, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 1, 12, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 3, 12, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 7, 12, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 13, 1, 13, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 1, 13, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 3, 13, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 13, 7, 13, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 1, 15, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 15, 5, 15, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 5, 15, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 16, 1, 16, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 5, 16, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 17, 1, 17, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 17, 5, 17, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 5 ], + "name" : "C" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 19, 1, 19, 7 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 19, 1, 19, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 19, 3, 19, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 19, 7, 19, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "AssignStmt", + "location" : [ 20, 1, 20, 9 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 20, 1, 20, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 20, 1, 20, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 3, 20, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 20, 7, 20, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 20, 7, 20, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 9, 20, 9 ], + "name" : "x" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 21, 1, 21, 16 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 21, 1, 21, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 21, 1, 21, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 21, 3, 21, 3 ], + "name" : "z" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 21, 7, 21, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 21, 7, 21, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 21, 7, 21, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 21, 9, 21, 9 ], + "name" : "x" + } + }, + "operator" : "==", + "right" : { + "kind" : "MemberExpr", + "location" : [ 21, 14, 21, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 21, 14, 21, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 21, 16, 21, 16 ], + "name" : "x" + } + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/class_def_init.py b/pa2-tests/core/class_def_init.py new file mode 100644 index 0000000..733f489 --- /dev/null +++ b/pa2-tests/core/class_def_init.py @@ -0,0 +1,17 @@ +class A(object): + x:int = 1 + +class B(A): + def __init__(self: "B"): + pass + +class C(B): + z:bool = True + +a:A = None +b:B = None +c:C = None + +a = A() +b = B() +c = C() diff --git a/pa2-tests/core/class_def_init.py.ast b/pa2-tests/core/class_def_init.py.ast new file mode 100644 index 0000000..2cf1bba --- /dev/null +++ b/pa2-tests/core/class_def_init.py.ast @@ -0,0 +1,243 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 17, 8 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 18, 5, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 24, 5, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 28, 5, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 8, 1, 9, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 7, 9, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 9, 14, 9, 17 ], + "value" : true + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 12, 1, 12, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 1, 12, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 3, 12, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 7, 12, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 13, 1, 13, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 1, 13, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 3, 13, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 13, 7, 13, 10 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 1, 15, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 15, 5, 15, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 15, 5, 15, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 16, 1, 16, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 1 ], + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 5, 16, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 17, 1, 17, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 17, 5, 17, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 5 ], + "name" : "C" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/class_def_init.py.ast.typed b/pa2-tests/core/class_def_init.py.ast.typed new file mode 100644 index 0000000..c2f9d72 --- /dev/null +++ b/pa2-tests/core/class_def_init.py.ast.typed @@ -0,0 +1,287 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 17, 8 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 18, 5, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 24, 5, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 28, 5, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 8, 1, 9, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 7, 9, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 9, 14, 9, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 12, 1, 12, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 1, 12, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 3, 12, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 7, 12, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 13, 1, 13, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 1, 13, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 3, 13, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 13, 7, 13, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 1, 15, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 15, 5, 15, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 5, 15, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 16, 1, 16, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 5, 16, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 17, 1, 17, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 17, 5, 17, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 5 ], + "name" : "C" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/class_def_methods.py b/pa2-tests/core/class_def_methods.py new file mode 100644 index 0000000..a8d70f1 --- /dev/null +++ b/pa2-tests/core/class_def_methods.py @@ -0,0 +1,28 @@ +class A(object): + x:int = 1 + + def get_A(self: "A") -> int: + return self.x + +class B(A): + def __init__(self: "B"): + pass + +class C(B): + z:bool = True + + def set_A(self: "C", val: int) -> object: + self.x = val + +a:A = None +b:B = None +c:C = None + +a = A() +b = B() +c = C() + +b.x = a.get_A() +a.x = b.get_A() +c.set_A(0) + diff --git a/pa2-tests/core/class_def_methods.py.ast b/pa2-tests/core/class_def_methods.py.ast new file mode 100644 index 0000000..2ddc48e --- /dev/null +++ b/pa2-tests/core/class_def_methods.py.ast @@ -0,0 +1,451 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 27, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 13 ], + "name" : "get_A" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 15, 4, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 15, 4, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 21, 4, 23 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 29, 4, 31 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 21 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 5, 16, 5, 21 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 19 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 21, 5, 21 ], + "name" : "x" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 11, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 8, 5, 9, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 18, 8, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 18, 8, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 24, 8, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 28, 8, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 11, 1, 17, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 12, 5, 12, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 5, 12, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 7, 12, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 12, 14, 12, 17 ], + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 14, 5, 15, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 13 ], + "name" : "set_A" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 15, 14, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 15, 14, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 21, 14, 23 ], + "className" : "C" + } + }, { + "kind" : "TypedVar", + "location" : [ 14, 26, 14, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 26, 14, 28 ], + "name" : "val" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 31, 14, 33 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 39, 14, 44 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 9, 15, 20 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 15, 9, 15, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 14, 15, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 15, 18, 15, 20 ], + "name" : "val" + } + } ] + } ] + }, { + "kind" : "VarDef", + "location" : [ 17, 1, 17, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 17, 1, 17, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 3, 17, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 17, 7, 17, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 18, 1, 18, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 18, 1, 18, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 18, 3, 18, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 18, 7, 18, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 19, 1, 19, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 19, 1, 19, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 3, 19, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 19, 7, 19, 10 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 21, 1, 21, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 21, 1, 21, 1 ], + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 21, 5, 21, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 21, 5, 21, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 22, 1, 22, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 1 ], + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 22, 5, 22, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 23, 1, 23, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 23, 1, 23, 1 ], + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 23, 5, 23, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 23, 5, 23, 5 ], + "name" : "C" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 25, 1, 25, 15 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 25, 1, 25, 3 ], + "object" : { + "kind" : "Identifier", + "location" : [ 25, 1, 25, 1 ], + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 25, 3, 25, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 25, 7, 25, 15 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 25, 7, 25, 13 ], + "object" : { + "kind" : "Identifier", + "location" : [ 25, 7, 25, 7 ], + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 25, 9, 25, 13 ], + "name" : "get_A" + } + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 26, 1, 26, 15 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 26, 1, 26, 3 ], + "object" : { + "kind" : "Identifier", + "location" : [ 26, 1, 26, 1 ], + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 26, 3, 26, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 26, 7, 26, 15 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 26, 7, 26, 13 ], + "object" : { + "kind" : "Identifier", + "location" : [ 26, 7, 26, 7 ], + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 26, 9, 26, 13 ], + "name" : "get_A" + } + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 27, 1, 27, 10 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 27, 1, 27, 10 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 27, 1, 27, 7 ], + "object" : { + "kind" : "Identifier", + "location" : [ 27, 1, 27, 1 ], + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 3, 27, 7 ], + "name" : "set_A" + } + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 27, 9, 27, 9 ], + "value" : 0 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/class_def_methods.py.ast.typed b/pa2-tests/core/class_def_methods.py.ast.typed new file mode 100644 index 0000000..1f58660 --- /dev/null +++ b/pa2-tests/core/class_def_methods.py.ast.typed @@ -0,0 +1,595 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 27, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 13 ], + "name" : "get_A" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 15, 4, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 15, 4, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 21, 4, 23 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 29, 4, 31 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 21 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 5, 16, 5, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 21, 5, 21 ], + "name" : "x" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 11, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 8, 5, 9, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 18, 8, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 18, 8, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 24, 8, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 28, 8, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 11, 1, 17, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 12, 5, 12, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 5, 12, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 7, 12, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 12, 14, 12, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 14, 5, 15, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 13 ], + "name" : "set_A" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 15, 14, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 15, 14, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 21, 14, 23 ], + "className" : "C" + } + }, { + "kind" : "TypedVar", + "location" : [ 14, 26, 14, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 26, 14, 28 ], + "name" : "val" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 31, 14, 33 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 39, 14, 44 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 9, 15, 20 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 15, 9, 15, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 14, 15, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 15, 18, 15, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "val" + } + } ] + } ] + }, { + "kind" : "VarDef", + "location" : [ 17, 1, 17, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 17, 1, 17, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 3, 17, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 17, 7, 17, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 18, 1, 18, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 18, 1, 18, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 18, 3, 18, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 18, 7, 18, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 19, 1, 19, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 19, 1, 19, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 3, 19, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 19, 7, 19, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 21, 1, 21, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 21, 1, 21, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 21, 5, 21, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 21, 5, 21, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 22, 1, 22, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 22, 5, 22, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 23, 1, 23, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 23, 1, 23, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 23, 5, 23, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 23, 5, 23, 5 ], + "name" : "C" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 25, 1, 25, 15 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 25, 1, 25, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 25, 1, 25, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 25, 3, 25, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 25, 7, 25, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 25, 7, 25, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "A" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 25, 7, 25, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 25, 9, 25, 13 ], + "name" : "get_A" + } + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 26, 1, 26, 15 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 26, 1, 26, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 26, 1, 26, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 26, 3, 26, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 26, 7, 26, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 26, 7, 26, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "A" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 26, 7, 26, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 26, 9, 26, 13 ], + "name" : "get_A" + } + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 27, 1, 27, 10 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 27, 1, 27, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 27, 1, 27, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "C" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 27, 1, 27, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 3, 27, 7 ], + "name" : "set_A" + } + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 27, 9, 27, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/decl_global_forward.py b/pa2-tests/core/decl_global_forward.py new file mode 100644 index 0000000..b364535 --- /dev/null +++ b/pa2-tests/core/decl_global_forward.py @@ -0,0 +1,9 @@ +def set_x() -> int: + global x + x = 1 + return x + +x:int = 0 + +set_x() +print(x) diff --git a/pa2-tests/core/decl_global_forward.py.ast b/pa2-tests/core/decl_global_forward.py.ast new file mode 100644 index 0000000..a450fe6 --- /dev/null +++ b/pa2-tests/core/decl_global_forward.py.ast @@ -0,0 +1,108 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 9 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 4, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 9 ], + "name" : "set_x" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 16, 1, 18 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 2, 5, 2, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 12 ], + "name" : "x" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 5, 3, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "x" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 4, 5, 4, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 4, 12, 4, 12 ], + "name" : "x" + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 6, 1, 6, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 1, 6, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 3, 6, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 7 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 5 ], + "name" : "set_x" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 9, 1, 9, 8 ], + "function" : { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 9, 7, 9, 7 ], + "name" : "x" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/decl_global_forward.py.ast.typed b/pa2-tests/core/decl_global_forward.py.ast.typed new file mode 100644 index 0000000..4d32ce7 --- /dev/null +++ b/pa2-tests/core/decl_global_forward.py.ast.typed @@ -0,0 +1,155 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 9 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 4, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 9 ], + "name" : "set_x" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 16, 1, 18 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 2, 5, 2, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 12 ], + "name" : "x" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 5, 3, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 4, 5, 4, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 4, 12, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 6, 1, 6, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 1, 6, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 3, 6, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 7 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "set_x" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 9, 1, 9, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 9, 7, 9, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/decl_nonlocal_forward.py b/pa2-tests/core/decl_nonlocal_forward.py new file mode 100644 index 0000000..b1ff307 --- /dev/null +++ b/pa2-tests/core/decl_nonlocal_forward.py @@ -0,0 +1,10 @@ +def outer() -> int: + def inner() -> int: + nonlocal x + x = 1 + return x + x:int = 0 + inner() + return x + +print(outer()) diff --git a/pa2-tests/core/decl_nonlocal_forward.py.ast b/pa2-tests/core/decl_nonlocal_forward.py.ast new file mode 100644 index 0000000..1b5f11b --- /dev/null +++ b/pa2-tests/core/decl_nonlocal_forward.py.ast @@ -0,0 +1,137 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 10, 15 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 8, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 9 ], + "name" : "outer" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 16, 1, 18 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 5, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 13 ], + "name" : "inner" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 20, 2, 22 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 3, 9, 3, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 3, 18, 3, 18 ], + "name" : "x" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 9, 4, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "x" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 13, 4, 13 ], + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 16 ], + "name" : "x" + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 5, 7, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 5, 7, 11 ], + "function" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 9 ], + "name" : "inner" + }, + "args" : [ ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 8, 5, 8, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 8, 12, 8, 12 ], + "name" : "x" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 1, 10, 14 ], + "function" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 10, 7, 10, 13 ], + "function" : { + "kind" : "Identifier", + "location" : [ 10, 7, 10, 11 ], + "name" : "outer" + }, + "args" : [ ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/decl_nonlocal_forward.py.ast.typed b/pa2-tests/core/decl_nonlocal_forward.py.ast.typed new file mode 100644 index 0000000..f5781a7 --- /dev/null +++ b/pa2-tests/core/decl_nonlocal_forward.py.ast.typed @@ -0,0 +1,196 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 10, 15 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 8, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 9 ], + "name" : "outer" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 16, 1, 18 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 5, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 13 ], + "name" : "inner" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 20, 2, 22 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 3, 9, 3, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 3, 18, 3, 18 ], + "name" : "x" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 9, 4, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 13, 4, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 5, 7, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 5, 7, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "inner" + }, + "args" : [ ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 8, 5, 8, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 8, 12, 8, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 1, 10, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 10, 7, 10, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 7, 10, 11 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "outer" + }, + "args" : [ ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_binary.py b/pa2-tests/core/expr_binary.py new file mode 100644 index 0000000..b35b22d --- /dev/null +++ b/pa2-tests/core/expr_binary.py @@ -0,0 +1,2 @@ +1 + 2 * 3 > 13 // 3 % 2 or 1 != 1 and False == False + diff --git a/pa2-tests/core/expr_binary.py.ast b/pa2-tests/core/expr_binary.py.ast new file mode 100644 index 0000000..3e59d31 --- /dev/null +++ b/pa2-tests/core/expr_binary.py.ast @@ -0,0 +1,109 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 53 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 52 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 52 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 23 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 9 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 1, 5, 1, 9 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "value" : 2 + }, + "operator" : "*", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 3 + } + } + }, + "operator" : ">", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 1, 13, 1, 23 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 13, 1, 19 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 13, 1, 14 ], + "value" : 13 + }, + "operator" : "//", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 19, 1, 19 ], + "value" : 3 + } + }, + "operator" : "%", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 23, 1, 23 ], + "value" : 2 + } + } + }, + "operator" : "or", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 1, 28, 1, 52 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 28, 1, 33 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 28, 1, 28 ], + "value" : 1 + }, + "operator" : "!=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 33, 1, 33 ], + "value" : 1 + } + }, + "operator" : "and", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 1, 39, 1, 52 ], + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 39, 1, 43 ], + "value" : false + }, + "operator" : "==", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 48, 1, 52 ], + "value" : false + } + } + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_binary.py.ast.typed b/pa2-tests/core/expr_binary.py.ast.typed new file mode 100644 index 0000000..146d277 --- /dev/null +++ b/pa2-tests/core/expr_binary.py.ast.typed @@ -0,0 +1,185 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 53 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 52 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 52 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 1, 5, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, + "operator" : "*", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + } + }, + "operator" : ">", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 1, 13, 1, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 13, 1, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 13, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 13 + }, + "operator" : "//", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 19, 1, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + }, + "operator" : "%", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 23, 1, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } + }, + "operator" : "or", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 1, 28, 1, 52 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 28, 1, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 28, 1, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "!=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 33, 1, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, + "operator" : "and", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 1, 39, 1, 52 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 39, 1, 43 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, + "operator" : "==", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 48, 1, 52 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_concat.py b/pa2-tests/core/expr_concat.py new file mode 100644 index 0000000..68c41a0 --- /dev/null +++ b/pa2-tests/core/expr_concat.py @@ -0,0 +1,3 @@ +[1, 2] + [3, 4] +"Hello " + "World" +[1, 2] + [True] diff --git a/pa2-tests/core/expr_concat.py.ast b/pa2-tests/core/expr_concat.py.ast new file mode 100644 index 0000000..064862b --- /dev/null +++ b/pa2-tests/core/expr_concat.py.ast @@ -0,0 +1,93 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 16 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 15 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 15 ], + "left" : { + "kind" : "ListExpr", + "location" : [ 1, 1, 1, 6 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 1, 2, 1, 2 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "value" : 2 + } ] + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 1, 10, 1, 15 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 1, 11, 1, 11 ], + "value" : 3 + }, { + "kind" : "IntegerLiteral", + "location" : [ 1, 14, 1, 14 ], + "value" : 4 + } ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 18 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 2, 1, 2, 18 ], + "left" : { + "kind" : "StringLiteral", + "location" : [ 2, 1, 2, 8 ], + "value" : "Hello " + }, + "operator" : "+", + "right" : { + "kind" : "StringLiteral", + "location" : [ 2, 12, 2, 18 ], + "value" : "World" + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 15 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 15 ], + "left" : { + "kind" : "ListExpr", + "location" : [ 3, 1, 3, 6 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 2, 3, 2 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 5, 3, 5 ], + "value" : 2 + } ] + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 3, 10, 3, 15 ], + "elements" : [ { + "kind" : "BooleanLiteral", + "location" : [ 3, 11, 3, 14 ], + "value" : true + } ] + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_concat.py.ast.typed b/pa2-tests/core/expr_concat.py.ast.typed new file mode 100644 index 0000000..4c61b0e --- /dev/null +++ b/pa2-tests/core/expr_concat.py.ast.typed @@ -0,0 +1,175 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 16 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 15 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 15 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "left" : { + "kind" : "ListExpr", + "location" : [ 1, 1, 1, 6 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 1, 2, 1, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } ] + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 1, 10, 1, 15 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 1, 11, 1, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + }, { + "kind" : "IntegerLiteral", + "location" : [ 1, 14, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 18 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 2, 1, 2, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "left" : { + "kind" : "StringLiteral", + "location" : [ 2, 1, 2, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello " + }, + "operator" : "+", + "right" : { + "kind" : "StringLiteral", + "location" : [ 2, 12, 2, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "World" + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 15 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 15 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "left" : { + "kind" : "ListExpr", + "location" : [ 3, 1, 3, 6 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 2, 3, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 5, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } ] + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 3, 10, 3, 15 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "elements" : [ { + "kind" : "BooleanLiteral", + "location" : [ 3, 11, 3, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } ] + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_id.py b/pa2-tests/core/expr_id.py new file mode 100644 index 0000000..c6fcd80 --- /dev/null +++ b/pa2-tests/core/expr_id.py @@ -0,0 +1,3 @@ +x:int = 1 + +x - 1 diff --git a/pa2-tests/core/expr_id.py.ast b/pa2-tests/core/expr_id.py.ast new file mode 100644 index 0000000..0f6ab04 --- /dev/null +++ b/pa2-tests/core/expr_id.py.ast @@ -0,0 +1,51 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 6 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 5 ], + "left" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "x" + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 5, 3, 5 ], + "value" : 1 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_id.py.ast.typed b/pa2-tests/core/expr_id.py.ast.typed new file mode 100644 index 0000000..cdefa39 --- /dev/null +++ b/pa2-tests/core/expr_id.py.ast.typed @@ -0,0 +1,67 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 6 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 5, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_if.py b/pa2-tests/core/expr_if.py new file mode 100644 index 0000000..e9e9c26 --- /dev/null +++ b/pa2-tests/core/expr_if.py @@ -0,0 +1 @@ +3 if 1 > 2 else 4 diff --git a/pa2-tests/core/expr_if.py.ast b/pa2-tests/core/expr_if.py.ast new file mode 100644 index 0000000..0ed9a55 --- /dev/null +++ b/pa2-tests/core/expr_if.py.ast @@ -0,0 +1,43 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 18 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 17 ], + "expr" : { + "kind" : "IfExpr", + "location" : [ 1, 1, 1, 17 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 1, 6, 1, 10 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 6, 1, 6 ], + "value" : 1 + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 10, 1, 10 ], + "value" : 2 + } + }, + "thenExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "value" : 3 + }, + "elseExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 17, 1, 17 ], + "value" : 4 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_if.py.ast.typed b/pa2-tests/core/expr_if.py.ast.typed new file mode 100644 index 0000000..3aa7a5f --- /dev/null +++ b/pa2-tests/core/expr_if.py.ast.typed @@ -0,0 +1,67 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 18 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 17 ], + "expr" : { + "kind" : "IfExpr", + "location" : [ 1, 1, 1, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 1, 6, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 6, 1, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 10, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + }, + "thenExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + }, + "elseExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 17, 1, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_int.py b/pa2-tests/core/expr_int.py new file mode 100644 index 0000000..f39d689 --- /dev/null +++ b/pa2-tests/core/expr_int.py @@ -0,0 +1 @@ +6 * 9 diff --git a/pa2-tests/core/expr_int.py.ast b/pa2-tests/core/expr_int.py.ast new file mode 100644 index 0000000..2eb3e50 --- /dev/null +++ b/pa2-tests/core/expr_int.py.ast @@ -0,0 +1,29 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 6 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 5 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "value" : 6 + }, + "operator" : "*", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "value" : 9 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_int.py.ast.typed b/pa2-tests/core/expr_int.py.ast.typed new file mode 100644 index 0000000..55a6721 --- /dev/null +++ b/pa2-tests/core/expr_int.py.ast.typed @@ -0,0 +1,41 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 6 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 6 + }, + "operator" : "*", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 9 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_list_index.py b/pa2-tests/core/expr_list_index.py new file mode 100644 index 0000000..b9d97e3 --- /dev/null +++ b/pa2-tests/core/expr_list_index.py @@ -0,0 +1,12 @@ +x:[int] = None +y:int = 0 +z:[bool] = None +o:object = None + +x = [1, 2, 3] +z = [False, True] + +y = x[0] +x[0] = 1 +z[1] = z[0] +o = x[1] diff --git a/pa2-tests/core/expr_list_index.py.ast b/pa2-tests/core/expr_list_index.py.ast new file mode 100644 index 0000000..5cb5c50 --- /dev/null +++ b/pa2-tests/core/expr_list_index.py.ast @@ -0,0 +1,247 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 12, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ] + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 3, 3, 8 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 4, 3, 7 ], + "className" : "bool" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 12, 3, 15 ] + } + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 12, 4, 15 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 6, 5, 6, 13 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 6, 6, 6 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 12, 6, 12 ], + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 5, 7, 17 ], + "elements" : [ { + "kind" : "BooleanLiteral", + "location" : [ 7, 6, 7, 10 ], + "value" : false + }, { + "kind" : "BooleanLiteral", + "location" : [ 7, 13, 7, 16 ], + "value" : true + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "name" : "y" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 9, 5, 9, 8 ], + "list" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 7, 9, 7 ], + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 1, 10, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 10, 1, 10, 4 ], + "list" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 3, 10, 3 ], + "value" : 0 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 8, 10, 8 ], + "value" : 1 + } + }, { + "kind" : "AssignStmt", + "location" : [ 11, 1, 11, 11 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 11, 1, 11, 4 ], + "list" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "z" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 3, 11, 3 ], + "value" : 1 + } + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 11, 8, 11, 11 ], + "list" : { + "kind" : "Identifier", + "location" : [ 11, 8, 11, 8 ], + "name" : "z" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 10, 11, 10 ], + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 12, 1, 12, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "o" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 12, 5, 12, 8 ], + "list" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 7, 12, 7 ], + "value" : 1 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_list_index.py.ast.typed b/pa2-tests/core/expr_list_index.py.ast.typed new file mode 100644 index 0000000..28fbe48 --- /dev/null +++ b/pa2-tests/core/expr_list_index.py.ast.typed @@ -0,0 +1,398 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 12, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 3, 3, 8 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 4, 3, 7 ], + "className" : "bool" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 12, 3, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 12, 4, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 6, 5, 6, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 6, 6, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 12, 6, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "z" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 5, 7, 17 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "elements" : [ { + "kind" : "BooleanLiteral", + "location" : [ 7, 6, 7, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, { + "kind" : "BooleanLiteral", + "location" : [ 7, 13, 7, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 9, 5, 9, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 7, 9, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 1, 10, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 10, 1, 10, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 3, 10, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 8, 10, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "AssignStmt", + "location" : [ 11, 1, 11, 11 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 11, 1, 11, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "z" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 3, 11, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 11, 8, 11, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 11, 8, 11, 8 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "z" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 10, 11, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 12, 1, 12, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "o" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 12, 5, 12, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 7, 12, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_lists.py b/pa2-tests/core/expr_lists.py new file mode 100644 index 0000000..2268a54 --- /dev/null +++ b/pa2-tests/core/expr_lists.py @@ -0,0 +1,12 @@ +x:[int] = None +y:[object] = None +z:[bool] = None +o:object = None + +x = [1, 2, 3] +x = [] +y = [1, True] +z = [False, True] +x = None +o = x +o = x = [1] diff --git a/pa2-tests/core/expr_lists.py.ast b/pa2-tests/core/expr_lists.py.ast new file mode 100644 index 0000000..5930b97 --- /dev/null +++ b/pa2-tests/core/expr_lists.py.ast @@ -0,0 +1,233 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 12, 12 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ] + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 10 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 9 ], + "className" : "object" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 14, 2, 17 ] + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 3, 3, 8 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 4, 3, 7 ], + "className" : "bool" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 12, 3, 15 ] + } + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 12, 4, 15 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 6, 5, 6, 13 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 6, 6, 6 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 12, 6, 12 ], + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 6 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 5, 7, 6 ], + "elements" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "y" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 8, 5, 8, 13 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 8, 6, 8, 6 ], + "value" : 1 + }, { + "kind" : "BooleanLiteral", + "location" : [ 8, 9, 8, 12 ], + "value" : true + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 9, 5, 9, 17 ], + "elements" : [ { + "kind" : "BooleanLiteral", + "location" : [ 9, 6, 9, 10 ], + "value" : false + }, { + "kind" : "BooleanLiteral", + "location" : [ 9, 13, 9, 16 ], + "value" : true + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 1, 10, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 10, 5, 10, 8 ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 11, 1, 11, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "o" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 5 ], + "name" : "x" + } + }, { + "kind" : "AssignStmt", + "location" : [ 12, 1, 12, 11 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "o" + }, { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 12, 9, 12, 11 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 12, 10, 12, 10 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_lists.py.ast.typed b/pa2-tests/core/expr_lists.py.ast.typed new file mode 100644 index 0000000..e8c37bd --- /dev/null +++ b/pa2-tests/core/expr_lists.py.ast.typed @@ -0,0 +1,374 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 12, 12 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 10 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 9 ], + "className" : "object" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 14, 2, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 3, 3, 8 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 4, 3, 7 ], + "className" : "bool" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 12, 3, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 12, 4, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 6, 5, 6, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 6, 6, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 12, 6, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 6 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 5, 7, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "y" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 8, 5, 8, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 8, 6, 8, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "BooleanLiteral", + "location" : [ 8, 9, 8, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "z" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 9, 5, 9, 17 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "elements" : [ { + "kind" : "BooleanLiteral", + "location" : [ 9, 6, 9, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, { + "kind" : "BooleanLiteral", + "location" : [ 9, 13, 9, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 1, 10, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 10, 5, 10, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 11, 1, 11, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "o" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 5 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } + }, { + "kind" : "AssignStmt", + "location" : [ 12, 1, 12, 11 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "o" + }, { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 12, 9, 12, 11 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 12, 10, 12, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_unary.py b/pa2-tests/core/expr_unary.py new file mode 100644 index 0000000..58d9627 --- /dev/null +++ b/pa2-tests/core/expr_unary.py @@ -0,0 +1,2 @@ +-1 +not False diff --git a/pa2-tests/core/expr_unary.py.ast b/pa2-tests/core/expr_unary.py.ast new file mode 100644 index 0000000..4f1abf3 --- /dev/null +++ b/pa2-tests/core/expr_unary.py.ast @@ -0,0 +1,37 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 2, 10 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 2 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 1, 1, 1, 2 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 2, 1, 2 ], + "value" : 1 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 9 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 2, 1, 2, 9 ], + "operator" : "not", + "operand" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 5, 2, 9 ], + "value" : false + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_unary.py.ast.typed b/pa2-tests/core/expr_unary.py.ast.typed new file mode 100644 index 0000000..77b0fd0 --- /dev/null +++ b/pa2-tests/core/expr_unary.py.ast.typed @@ -0,0 +1,53 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 2, 10 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 2 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 1, 1, 1, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 2, 1, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 9 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 2, 1, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "operator" : "not", + "operand" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 5, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_var_assign.py b/pa2-tests/core/expr_var_assign.py new file mode 100644 index 0000000..3b8ebfe --- /dev/null +++ b/pa2-tests/core/expr_var_assign.py @@ -0,0 +1,4 @@ +x:int = 1 +o:object = None + +x = o = 42 diff --git a/pa2-tests/core/expr_var_assign.py.ast b/pa2-tests/core/expr_var_assign.py.ast new file mode 100644 index 0000000..5b8093e --- /dev/null +++ b/pa2-tests/core/expr_var_assign.py.ast @@ -0,0 +1,71 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 11 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 12, 2, 15 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "name" : "o" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 10 ], + "value" : 42 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/expr_var_assign.py.ast.typed b/pa2-tests/core/expr_var_assign.py.ast.typed new file mode 100644 index 0000000..950866b --- /dev/null +++ b/pa2-tests/core/expr_var_assign.py.ast.typed @@ -0,0 +1,91 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 11 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 12, 2, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "o" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/func_def_call.py b/pa2-tests/core/func_def_call.py new file mode 100644 index 0000000..e5f4e8b --- /dev/null +++ b/pa2-tests/core/func_def_call.py @@ -0,0 +1,7 @@ +def foo(x:str, y:bool) -> int: + return bar() + +def bar() -> int: + return 1 + +foo("Hello", False) diff --git a/pa2-tests/core/func_def_call.py.ast b/pa2-tests/core/func_def_call.py.ast new file mode 100644 index 0000000..b6194bd --- /dev/null +++ b/pa2-tests/core/func_def_call.py.ast @@ -0,0 +1,111 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 20 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 16, 1, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 16, 1, 16 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 18, 1, 21 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 27, 1, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 16 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 2, 12, 2, 16 ], + "function" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 14 ], + "name" : "bar" + }, + "args" : [ ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 5, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 14, 4, 16 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 12, 5, 12 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 19 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 1, 7, 19 ], + "function" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 7, 5, 7, 11 ], + "value" : "Hello" + }, { + "kind" : "BooleanLiteral", + "location" : [ 7, 14, 7, 18 ], + "value" : false + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/func_def_call.py.ast.typed b/pa2-tests/core/func_def_call.py.ast.typed new file mode 100644 index 0000000..20e0bde --- /dev/null +++ b/pa2-tests/core/func_def_call.py.ast.typed @@ -0,0 +1,153 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 20 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 16, 1, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 16, 1, 16 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 18, 1, 21 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 27, 1, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 16 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 2, 12, 2, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "bar" + }, + "args" : [ ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 5, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 14, 4, 16 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 12, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 19 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 1, 7, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 3 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "bool" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 7, 5, 7, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + }, { + "kind" : "BooleanLiteral", + "location" : [ 7, 14, 7, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/stmt_for_lists.py b/pa2-tests/core/stmt_for_lists.py new file mode 100644 index 0000000..235fb2f --- /dev/null +++ b/pa2-tests/core/stmt_for_lists.py @@ -0,0 +1,4 @@ +x:int = 0 + +for x in [1, 2, 3]: + x + 1 diff --git a/pa2-tests/core/stmt_for_lists.py.ast b/pa2-tests/core/stmt_for_lists.py.ast new file mode 100644 index 0000000..3e6fb8f --- /dev/null +++ b/pa2-tests/core/stmt_for_lists.py.ast @@ -0,0 +1,77 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 3, 1, 5, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "x" + }, + "iterable" : { + "kind" : "ListExpr", + "location" : [ 3, 10, 3, 18 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 11, 3, 11 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 14, 3, 14 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 17, 3, 17 ], + "value" : 3 + } ] + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 9 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 4, 5, 4, 9 ], + "left" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/stmt_for_lists.py.ast.typed b/pa2-tests/core/stmt_for_lists.py.ast.typed new file mode 100644 index 0000000..9bd4123 --- /dev/null +++ b/pa2-tests/core/stmt_for_lists.py.ast.typed @@ -0,0 +1,116 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 3, 1, 5, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "ListExpr", + "location" : [ 3, 10, 3, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 11, 3, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 14, 3, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 17, 3, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 9 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 4, 5, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/stmt_for_strings.py b/pa2-tests/core/stmt_for_strings.py new file mode 100644 index 0000000..b135f8b --- /dev/null +++ b/pa2-tests/core/stmt_for_strings.py @@ -0,0 +1,4 @@ +s:str = "Hello" + +for s in s: + s[0] diff --git a/pa2-tests/core/stmt_for_strings.py.ast b/pa2-tests/core/stmt_for_strings.py.ast new file mode 100644 index 0000000..6e837a5 --- /dev/null +++ b/pa2-tests/core/stmt_for_strings.py.ast @@ -0,0 +1,64 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 15 ], + "value" : "Hello" + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 3, 1, 5, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "s" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 3, 10, 3, 10 ], + "name" : "s" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 8 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 4, 5, 4, 8 ], + "list" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "name" : "s" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 7, 4, 7 ], + "value" : 0 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/stmt_for_strings.py.ast.typed b/pa2-tests/core/stmt_for_strings.py.ast.typed new file mode 100644 index 0000000..0f36ad0 --- /dev/null +++ b/pa2-tests/core/stmt_for_strings.py.ast.typed @@ -0,0 +1,88 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 3, 1, 5, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 3, 10, 3, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 8 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 4, 5, 4, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 7, 4, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/stmt_if.py b/pa2-tests/core/stmt_if.py new file mode 100644 index 0000000..d5053bf --- /dev/null +++ b/pa2-tests/core/stmt_if.py @@ -0,0 +1,7 @@ +if False: + pass +elif True: + if 1 == 1: + pass +else: + pass diff --git a/pa2-tests/core/stmt_if.py.ast b/pa2-tests/core/stmt_if.py.ast new file mode 100644 index 0000000..48c33f3 --- /dev/null +++ b/pa2-tests/core/stmt_if.py.ast @@ -0,0 +1,51 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 1 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 1, 1, 8, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 4, 1, 8 ], + "value" : false + }, + "thenBody" : [ ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 3, 1, 8, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 6, 3, 9 ], + "value" : true + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 4, 5, 6, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 4, 8, 4, 13 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 8, 4, 8 ], + "value" : 1 + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 13, 4, 13 ], + "value" : 1 + } + }, + "thenBody" : [ ], + "elseBody" : [ ] + } ], + "elseBody" : [ ] + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/stmt_if.py.ast.typed b/pa2-tests/core/stmt_if.py.ast.typed new file mode 100644 index 0000000..3453f95 --- /dev/null +++ b/pa2-tests/core/stmt_if.py.ast.typed @@ -0,0 +1,71 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 1 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 1, 1, 8, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 4, 1, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, + "thenBody" : [ ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 3, 1, 8, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 6, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 4, 5, 6, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 4, 8, 4, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 8, 4, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 13, 4, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, + "thenBody" : [ ], + "elseBody" : [ ] + } ], + "elseBody" : [ ] + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/stmt_list_assign.py b/pa2-tests/core/stmt_list_assign.py new file mode 100644 index 0000000..34221dd --- /dev/null +++ b/pa2-tests/core/stmt_list_assign.py @@ -0,0 +1,7 @@ +x:[int] = None +y:[object] = None + +x = [1, 2] +y = [None] +x[0] = 3 +x[1] = y[0] = 4 diff --git a/pa2-tests/core/stmt_list_assign.py.ast b/pa2-tests/core/stmt_list_assign.py.ast new file mode 100644 index 0000000..cac7d91 --- /dev/null +++ b/pa2-tests/core/stmt_list_assign.py.ast @@ -0,0 +1,155 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 16 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ] + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 10 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 9 ], + "className" : "object" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 14, 2, 17 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 4, 5, 4, 10 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 6, 4, 6 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "value" : 2 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "y" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 5, 5, 5, 10 ], + "elements" : [ { + "kind" : "NoneLiteral", + "location" : [ 5, 6, 5, 9 ] + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 6, 1, 6, 4 ], + "list" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 3, 6, 3 ], + "value" : 0 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 8, 6, 8 ], + "value" : 3 + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 15 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 7, 1, 7, 4 ], + "list" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 3, 7, 3 ], + "value" : 1 + } + }, { + "kind" : "IndexExpr", + "location" : [ 7, 8, 7, 11 ], + "list" : { + "kind" : "Identifier", + "location" : [ 7, 8, 7, 8 ], + "name" : "y" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 10, 7, 10 ], + "value" : 0 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 15, 7, 15 ], + "value" : 4 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/stmt_list_assign.py.ast.typed b/pa2-tests/core/stmt_list_assign.py.ast.typed new file mode 100644 index 0000000..5fefc31 --- /dev/null +++ b/pa2-tests/core/stmt_list_assign.py.ast.typed @@ -0,0 +1,256 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 16 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 10 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 9 ], + "className" : "object" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 14, 2, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 4, 5, 4, 10 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 6, 4, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "y" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 5, 5, 5, 10 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "elements" : [ { + "kind" : "NoneLiteral", + "location" : [ 5, 6, 5, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 6, 1, 6, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 3, 6, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 8, 6, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 15 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 7, 1, 7, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 3, 7, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "IndexExpr", + "location" : [ 7, 8, 7, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 7, 8, 7, 8 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "y" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 10, 7, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 15, 7, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/stmt_var_assign.py b/pa2-tests/core/stmt_var_assign.py new file mode 100644 index 0000000..71e9795 --- /dev/null +++ b/pa2-tests/core/stmt_var_assign.py @@ -0,0 +1,9 @@ +x:int = 1 +y:bool = True +z:str = "" +o:object = None + +x = 2 +y = False +z = "Hello" +o = z diff --git a/pa2-tests/core/stmt_var_assign.py.ast b/pa2-tests/core/stmt_var_assign.py.ast new file mode 100644 index 0000000..4a474cd --- /dev/null +++ b/pa2-tests/core/stmt_var_assign.py.ast @@ -0,0 +1,150 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 6 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 6 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 10, 2, 13 ], + "value" : true + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 10 ], + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 12, 4, 15 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 5, 6, 5 ], + "value" : 2 + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "y" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 5, 7, 9 ], + "value" : false + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 11 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 8, 5, 8, 11 ], + "value" : "Hello" + } + }, { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "name" : "o" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "z" + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/stmt_var_assign.py.ast.typed b/pa2-tests/core/stmt_var_assign.py.ast.typed new file mode 100644 index 0000000..cb529c2 --- /dev/null +++ b/pa2-tests/core/stmt_var_assign.py.ast.typed @@ -0,0 +1,198 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 6 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 6 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 10, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 12, 4, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 5, 6, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "name" : "y" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 5, 7, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 11 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + } ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 8, 5, 8, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + } + }, { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "o" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/stmt_while.py b/pa2-tests/core/stmt_while.py new file mode 100644 index 0000000..d45a4fc --- /dev/null +++ b/pa2-tests/core/stmt_while.py @@ -0,0 +1,3 @@ +x:int = 0 +while x < 100: + x = x + 1 diff --git a/pa2-tests/core/stmt_while.py.ast b/pa2-tests/core/stmt_while.py.ast new file mode 100644 index 0000000..10ae361 --- /dev/null +++ b/pa2-tests/core/stmt_while.py.ast @@ -0,0 +1,75 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 2, 1, 4, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 2, 7, 2, 13 ], + "left" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 7 ], + "name" : "x" + }, + "operator" : "<", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 11, 2, 13 ], + "value" : 100 + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 5, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "x" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 3, 9, 3, 13 ], + "left" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 13, 3, 13 ], + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/stmt_while.py.ast.typed b/pa2-tests/core/stmt_while.py.ast.typed new file mode 100644 index 0000000..c928a9e --- /dev/null +++ b/pa2-tests/core/stmt_while.py.ast.typed @@ -0,0 +1,107 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 2, 1, 4, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 2, 7, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "<", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 11, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 100 + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 5, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 3, 9, 3, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 13, 3, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/strings.py b/pa2-tests/core/strings.py new file mode 100644 index 0000000..dd6a4ee --- /dev/null +++ b/pa2-tests/core/strings.py @@ -0,0 +1,8 @@ +x:str = "Hello" +y:str = "World" +z:str = "" + +z = x + y +z = x[0] +x = y = z + diff --git a/pa2-tests/core/strings.py.ast b/pa2-tests/core/strings.py.ast new file mode 100644 index 0000000..1ba2f58 --- /dev/null +++ b/pa2-tests/core/strings.py.ast @@ -0,0 +1,139 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 10 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 15 ], + "value" : "Hello" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 15 ], + "value" : "World" + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 10 ], + "value" : "" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 5, 5, 5, 9 ], + "left" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 9 ], + "name" : "y" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 6, 5, 6, 8 ], + "list" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 7, 6, 7 ], + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "y" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "z" + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/core/strings.py.ast.typed b/pa2-tests/core/strings.py.ast.typed new file mode 100644 index 0000000..acff3ae --- /dev/null +++ b/pa2-tests/core/strings.py.ast.typed @@ -0,0 +1,195 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 10 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "World" + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 5, 5, 5, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "y" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 6, 5, 6, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 7, 6, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "y" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/extra/exp.py b/pa2-tests/extra/exp.py new file mode 100644 index 0000000..3915517 --- /dev/null +++ b/pa2-tests/extra/exp.py @@ -0,0 +1,25 @@ +# Compute x**y +def exp(x: int, y: int) -> int: + a: int = 0 + def f(i: int) -> int: + nonlocal a + def geta() -> int: + return a + if i <= 0: + return geta() + else: + a = a * x + return f(i-1) + a = 1 + return f(y) + +# Input parameter +n:int = 42 + +# Run [0, n] +i:int = 0 + +# Crunch +while i <= n: + print(exp(2, i % 31)) + i = i + 1 \ No newline at end of file diff --git a/pa2-tests/extra/exp.py.ast b/pa2-tests/extra/exp.py.ast new file mode 100644 index 0000000..bc8786c --- /dev/null +++ b/pa2-tests/extra/exp.py.ast @@ -0,0 +1,375 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 26, 1 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 1, 14, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 7 ], + "name" : "exp" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 9, 2, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 12, 2, 14 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 2, 17, 2, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 17, 2, 17 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 20, 2, 22 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 28, 2, 30 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 2, 3, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 2, 3, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 2, 3, 2 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 5, 3, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 11, 3, 11 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 2, 13, 1 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 6, 4, 6 ], + "name" : "f" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 8, 4, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 8, 4, 8 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 11, 4, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 19, 4, 21 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 5, 3, 5, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 5, 12, 5, 12 ], + "name" : "a" + } + }, { + "kind" : "FuncDef", + "location" : [ 6, 3, 7, 12 ], + "name" : { + "kind" : "Identifier", + "location" : [ 6, 7, 6, 10 ], + "name" : "geta" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 6, 17, 6, 19 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 7, 4, 7, 11 ], + "value" : { + "kind" : "Identifier", + "location" : [ 7, 11, 7, 11 ], + "name" : "a" + } + } ] + } ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 8, 3, 13, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 8, 6, 8, 11 ], + "left" : { + "kind" : "Identifier", + "location" : [ 8, 6, 8, 6 ], + "name" : "i" + }, + "operator" : "<=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 11, 8, 11 ], + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 9, 4, 9, 16 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 9, 11, 9, 16 ], + "function" : { + "kind" : "Identifier", + "location" : [ 9, 11, 9, 14 ], + "name" : "geta" + }, + "args" : [ ] + } + } ], + "elseBody" : [ { + "kind" : "AssignStmt", + "location" : [ 11, 4, 11, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 4, 11, 4 ], + "name" : "a" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 11, 8, 11, 12 ], + "left" : { + "kind" : "Identifier", + "location" : [ 11, 8, 11, 8 ], + "name" : "a" + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 11, 12, 11, 12 ], + "name" : "x" + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 12, 4, 12, 16 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 12, 11, 12, 16 ], + "function" : { + "kind" : "Identifier", + "location" : [ 12, 11, 12, 11 ], + "name" : "f" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 12, 13, 12, 15 ], + "left" : { + "kind" : "Identifier", + "location" : [ 12, 13, 12, 13 ], + "name" : "i" + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 15, 12, 15 ], + "value" : 1 + } + } ] + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 13, 2, 13, 6 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 13, 2, 13, 2 ], + "name" : "a" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 6, 13, 6 ], + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 14, 2, 14, 12 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 14, 9, 14, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 9 ], + "name" : "f" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 14, 11, 14, 11 ], + "name" : "y" + } ] + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 17, 1, 17, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 17, 1, 17, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 3, 17, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 17, 9, 17, 10 ], + "value" : 42 + } + }, { + "kind" : "VarDef", + "location" : [ 20, 1, 20, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 20, 1, 20, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 20, 1, 20, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 20, 3, 20, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 20, 9, 20, 9 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 23, 1, 26, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 23, 7, 23, 12 ], + "left" : { + "kind" : "Identifier", + "location" : [ 23, 7, 23, 7 ], + "name" : "i" + }, + "operator" : "<=", + "right" : { + "kind" : "Identifier", + "location" : [ 23, 12, 23, 12 ], + "name" : "n" + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 24, 2, 24, 22 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 24, 2, 24, 22 ], + "function" : { + "kind" : "Identifier", + "location" : [ 24, 2, 24, 6 ], + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 24, 8, 24, 21 ], + "function" : { + "kind" : "Identifier", + "location" : [ 24, 8, 24, 10 ], + "name" : "exp" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 24, 12, 24, 12 ], + "value" : 2 + }, { + "kind" : "BinaryExpr", + "location" : [ 24, 15, 24, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 24, 15, 24, 15 ], + "name" : "i" + }, + "operator" : "%", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 19, 24, 20 ], + "value" : 31 + } + } ] + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 25, 2, 25, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 25, 2, 25, 2 ], + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 25, 6, 25, 10 ], + "left" : { + "kind" : "Identifier", + "location" : [ 25, 6, 25, 6 ], + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 25, 10, 25, 10 ], + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/extra/exp.py.ast.typed b/pa2-tests/extra/exp.py.ast.typed new file mode 100644 index 0000000..39a7fa1 --- /dev/null +++ b/pa2-tests/extra/exp.py.ast.typed @@ -0,0 +1,562 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 26, 1 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 1, 14, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 7 ], + "name" : "exp" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 9, 2, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 12, 2, 14 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 2, 17, 2, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 17, 2, 17 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 20, 2, 22 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 28, 2, 30 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 2, 3, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 2, 3, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 2, 3, 2 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 5, 3, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 11, 3, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 2, 13, 1 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 6, 4, 6 ], + "name" : "f" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 8, 4, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 8, 4, 8 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 11, 4, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 19, 4, 21 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 5, 3, 5, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 5, 12, 5, 12 ], + "name" : "a" + } + }, { + "kind" : "FuncDef", + "location" : [ 6, 3, 7, 12 ], + "name" : { + "kind" : "Identifier", + "location" : [ 6, 7, 6, 10 ], + "name" : "geta" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 6, 17, 6, 19 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 7, 4, 7, 11 ], + "value" : { + "kind" : "Identifier", + "location" : [ 7, 11, 7, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "a" + } + } ] + } ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 8, 3, 13, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 8, 6, 8, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 8, 6, 8, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 11, 8, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 9, 4, 9, 16 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 9, 11, 9, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 11, 9, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "geta" + }, + "args" : [ ] + } + } ], + "elseBody" : [ { + "kind" : "AssignStmt", + "location" : [ 11, 4, 11, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 4, 11, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "a" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 11, 8, 11, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 11, 8, 11, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "a" + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 11, 12, 11, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 12, 4, 12, 16 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 12, 11, 12, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 12, 11, 12, 11 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "f" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 12, 13, 12, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 12, 13, 12, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 15, 12, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 13, 2, 13, 6 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 13, 2, 13, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "a" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 6, 13, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 14, 2, 14, 12 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 14, 9, 14, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "f" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 14, 11, 14, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } ] + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 17, 1, 17, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 17, 1, 17, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 3, 17, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 17, 9, 17, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + }, { + "kind" : "VarDef", + "location" : [ 20, 1, 20, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 20, 1, 20, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 20, 1, 20, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 20, 3, 20, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 20, 9, 20, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 23, 1, 26, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 23, 7, 23, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 23, 7, 23, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<=", + "right" : { + "kind" : "Identifier", + "location" : [ 23, 12, 23, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "n" + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 24, 2, 24, 22 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 24, 2, 24, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 24, 2, 24, 6 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 24, 8, 24, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 24, 8, 24, 10 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "exp" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 24, 12, 24, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "BinaryExpr", + "location" : [ 24, 15, 24, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 24, 15, 24, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "%", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 19, 24, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 31 + } + } ] + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 25, 2, 25, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 25, 2, 25, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 25, 6, 25, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 25, 6, 25, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 25, 10, 25, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/extra/mergesort.py b/pa2-tests/extra/mergesort.py new file mode 100644 index 0000000..096c2c8 --- /dev/null +++ b/pa2-tests/extra/mergesort.py @@ -0,0 +1,62 @@ +def append(a: [int], k: int) -> [int]: + return a + [k] + + +def extend(a: [int], b: [int], b_start: int, b_end: int) -> [int]: + extended: [int] = None + i: int = 0 + + extended = a + i = b_start + while i < b_end: + extended = append(extended, b[i]) + i = i + 1 + return extended + + +def merge(left: [int], right: [int]) -> [int]: + merged: [int] = None + i: int = 0 + j: int = 0 + + merged = [] + while i < len(left) and j < len(right): + if left[i] < right[j]: + merged = append(merged, left[i]) + i = i + 1 + else: + merged = append(merged, right[j]) + j = j + 1 + + if i < len(left): + merged = extend(merged, left, i, len(left)) + if j < len(right): + merged = extend(merged, right, j, len(right)) + + return merged + + +def mergesort(a: [int]) -> [int]: + mid: int = 0 + left: [int] = None + right: [int] = None + + if len(a) < 2: + return a + + mid = len(a) // 2 + left = extend([], a, 0, mid) + right = extend([], a, mid, len(a)) + + left = mergesort(left) + right = mergesort(right) + return merge(left, right) + + +initial: [int] = None +ordered: [int] = None + +initial = [2, 7, 3, 11, 5] +ordered = mergesort(initial) + +print(ordered) diff --git a/pa2-tests/extra/mergesort.py.ast b/pa2-tests/extra/mergesort.py.ast new file mode 100644 index 0000000..f11bb0f --- /dev/null +++ b/pa2-tests/extra/mergesort.py.ast @@ -0,0 +1,1262 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 62, 15 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 10 ], + "name" : "append" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 12, 1, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 12, 1, 12 ], + "name" : "a" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 15, 1, 19 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 16, 1, 18 ], + "className" : "int" + } + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 22, 1, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 22, 1, 22 ], + "name" : "k" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 25, 1, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ListType", + "location" : [ 1, 33, 1, 37 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 34, 1, 36 ], + "className" : "int" + } + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 18 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 2, 12, 2, 18 ], + "left" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 12 ], + "name" : "a" + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 2, 16, 2, 18 ], + "elements" : [ { + "kind" : "Identifier", + "location" : [ 2, 17, 2, 17 ], + "name" : "k" + } ] + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 14, 20 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 10 ], + "name" : "extend" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 12, 5, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 12, 5, 12 ], + "name" : "a" + }, + "type" : { + "kind" : "ListType", + "location" : [ 5, 15, 5, 19 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 5, 16, 5, 18 ], + "className" : "int" + } + } + }, { + "kind" : "TypedVar", + "location" : [ 5, 22, 5, 29 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 22, 5, 22 ], + "name" : "b" + }, + "type" : { + "kind" : "ListType", + "location" : [ 5, 25, 5, 29 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 5, 26, 5, 28 ], + "className" : "int" + } + } + }, { + "kind" : "TypedVar", + "location" : [ 5, 32, 5, 43 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 32, 5, 38 ], + "name" : "b_start" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 41, 5, 43 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 5, 46, 5, 55 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 46, 5, 50 ], + "name" : "b_end" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 53, 5, 55 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ListType", + "location" : [ 5, 61, 5, 65 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 5, 62, 5, 64 ], + "className" : "int" + } + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 26 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 12 ], + "name" : "extended" + }, + "type" : { + "kind" : "ListType", + "location" : [ 6, 15, 6, 19 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 6, 16, 6, 18 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 6, 23, 6, 26 ] + } + }, { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 8, 7, 10 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 14, 7, 14 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 9, 5, 9, 16 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 12 ], + "name" : "extended" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 9, 16, 9, 16 ], + "name" : "a" + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 5, 10, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 5, 10, 5 ], + "name" : "i" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 15 ], + "name" : "b_start" + } + }, { + "kind" : "WhileStmt", + "location" : [ 11, 5, 14, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 11, 11, 11, 19 ], + "left" : { + "kind" : "Identifier", + "location" : [ 11, 11, 11, 11 ], + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "Identifier", + "location" : [ 11, 15, 11, 19 ], + "name" : "b_end" + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 12, 9, 12, 41 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 12, 9, 12, 16 ], + "name" : "extended" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 12, 20, 12, 41 ], + "function" : { + "kind" : "Identifier", + "location" : [ 12, 20, 12, 25 ], + "name" : "append" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 12, 27, 12, 34 ], + "name" : "extended" + }, { + "kind" : "IndexExpr", + "location" : [ 12, 37, 12, 40 ], + "list" : { + "kind" : "Identifier", + "location" : [ 12, 37, 12, 37 ], + "name" : "b" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 12, 39, 12, 39 ], + "name" : "i" + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 13, 9, 13, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 13, 9, 13, 9 ], + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 13, 13, 13, 17 ], + "left" : { + "kind" : "Identifier", + "location" : [ 13, 13, 13, 13 ], + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 17, 13, 17 ], + "value" : 1 + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 14, 5, 14, 19 ], + "value" : { + "kind" : "Identifier", + "location" : [ 14, 12, 14, 19 ], + "name" : "extended" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 17, 1, 36, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 9 ], + "name" : "merge" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 17, 11, 17, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 11, 17, 14 ], + "name" : "left" + }, + "type" : { + "kind" : "ListType", + "location" : [ 17, 17, 17, 21 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 17, 18, 17, 20 ], + "className" : "int" + } + } + }, { + "kind" : "TypedVar", + "location" : [ 17, 24, 17, 35 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 24, 17, 28 ], + "name" : "right" + }, + "type" : { + "kind" : "ListType", + "location" : [ 17, 31, 17, 35 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 17, 32, 17, 34 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ListType", + "location" : [ 17, 41, 17, 45 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 17, 42, 17, 44 ], + "className" : "int" + } + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 18, 5, 18, 24 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 18, 5, 18, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 18, 5, 18, 10 ], + "name" : "merged" + }, + "type" : { + "kind" : "ListType", + "location" : [ 18, 13, 18, 17 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 18, 14, 18, 16 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 18, 21, 18, 24 ] + } + }, { + "kind" : "VarDef", + "location" : [ 19, 5, 19, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 19, 5, 19, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 5, 19, 5 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 8, 19, 10 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 19, 14, 19, 14 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 20, 5, 20, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 20, 5, 20, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 20, 5, 20, 5 ], + "name" : "j" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 20, 8, 20, 10 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 20, 14, 20, 14 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 22, 5, 22, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 10 ], + "name" : "merged" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 22, 14, 22, 15 ], + "elements" : [ ] + } + }, { + "kind" : "WhileStmt", + "location" : [ 23, 5, 31, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 23, 11, 23, 42 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 23, 11, 23, 23 ], + "left" : { + "kind" : "Identifier", + "location" : [ 23, 11, 23, 11 ], + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "CallExpr", + "location" : [ 23, 15, 23, 23 ], + "function" : { + "kind" : "Identifier", + "location" : [ 23, 15, 23, 17 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 23, 19, 23, 22 ], + "name" : "left" + } ] + } + }, + "operator" : "and", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 23, 29, 23, 42 ], + "left" : { + "kind" : "Identifier", + "location" : [ 23, 29, 23, 29 ], + "name" : "j" + }, + "operator" : "<", + "right" : { + "kind" : "CallExpr", + "location" : [ 23, 33, 23, 42 ], + "function" : { + "kind" : "Identifier", + "location" : [ 23, 33, 23, 35 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 23, 37, 23, 41 ], + "name" : "right" + } ] + } + } + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 24, 9, 31, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 24, 12, 24, 29 ], + "left" : { + "kind" : "IndexExpr", + "location" : [ 24, 12, 24, 18 ], + "list" : { + "kind" : "Identifier", + "location" : [ 24, 12, 24, 15 ], + "name" : "left" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 24, 17, 24, 17 ], + "name" : "i" + } + }, + "operator" : "<", + "right" : { + "kind" : "IndexExpr", + "location" : [ 24, 22, 24, 29 ], + "list" : { + "kind" : "Identifier", + "location" : [ 24, 22, 24, 26 ], + "name" : "right" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 24, 28, 24, 28 ], + "name" : "j" + } + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 25, 13, 25, 44 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 25, 13, 25, 18 ], + "name" : "merged" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 25, 22, 25, 44 ], + "function" : { + "kind" : "Identifier", + "location" : [ 25, 22, 25, 27 ], + "name" : "append" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 25, 29, 25, 34 ], + "name" : "merged" + }, { + "kind" : "IndexExpr", + "location" : [ 25, 37, 25, 43 ], + "list" : { + "kind" : "Identifier", + "location" : [ 25, 37, 25, 40 ], + "name" : "left" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 25, 42, 25, 42 ], + "name" : "i" + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 26, 13, 26, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 26, 13, 26, 13 ], + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 26, 17, 26, 21 ], + "left" : { + "kind" : "Identifier", + "location" : [ 26, 17, 26, 17 ], + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 26, 21, 26, 21 ], + "value" : 1 + } + } + } ], + "elseBody" : [ { + "kind" : "AssignStmt", + "location" : [ 28, 13, 28, 45 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 28, 13, 28, 18 ], + "name" : "merged" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 28, 22, 28, 45 ], + "function" : { + "kind" : "Identifier", + "location" : [ 28, 22, 28, 27 ], + "name" : "append" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 28, 29, 28, 34 ], + "name" : "merged" + }, { + "kind" : "IndexExpr", + "location" : [ 28, 37, 28, 44 ], + "list" : { + "kind" : "Identifier", + "location" : [ 28, 37, 28, 41 ], + "name" : "right" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 28, 43, 28, 43 ], + "name" : "j" + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 29, 13, 29, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 29, 13, 29, 13 ], + "name" : "j" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 29, 17, 29, 21 ], + "left" : { + "kind" : "Identifier", + "location" : [ 29, 17, 29, 17 ], + "name" : "j" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 29, 21, 29, 21 ], + "value" : 1 + } + } + } ] + } ] + }, { + "kind" : "IfStmt", + "location" : [ 31, 5, 33, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 31, 8, 31, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 31, 8, 31, 8 ], + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "CallExpr", + "location" : [ 31, 12, 31, 20 ], + "function" : { + "kind" : "Identifier", + "location" : [ 31, 12, 31, 14 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 31, 16, 31, 19 ], + "name" : "left" + } ] + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 32, 9, 32, 51 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 32, 9, 32, 14 ], + "name" : "merged" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 32, 18, 32, 51 ], + "function" : { + "kind" : "Identifier", + "location" : [ 32, 18, 32, 23 ], + "name" : "extend" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 32, 25, 32, 30 ], + "name" : "merged" + }, { + "kind" : "Identifier", + "location" : [ 32, 33, 32, 36 ], + "name" : "left" + }, { + "kind" : "Identifier", + "location" : [ 32, 39, 32, 39 ], + "name" : "i" + }, { + "kind" : "CallExpr", + "location" : [ 32, 42, 32, 50 ], + "function" : { + "kind" : "Identifier", + "location" : [ 32, 42, 32, 44 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 32, 46, 32, 49 ], + "name" : "left" + } ] + } ] + } + } ], + "elseBody" : [ ] + }, { + "kind" : "IfStmt", + "location" : [ 33, 5, 36, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 33, 8, 33, 21 ], + "left" : { + "kind" : "Identifier", + "location" : [ 33, 8, 33, 8 ], + "name" : "j" + }, + "operator" : "<", + "right" : { + "kind" : "CallExpr", + "location" : [ 33, 12, 33, 21 ], + "function" : { + "kind" : "Identifier", + "location" : [ 33, 12, 33, 14 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 33, 16, 33, 20 ], + "name" : "right" + } ] + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 34, 9, 34, 53 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 34, 9, 34, 14 ], + "name" : "merged" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 34, 18, 34, 53 ], + "function" : { + "kind" : "Identifier", + "location" : [ 34, 18, 34, 23 ], + "name" : "extend" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 34, 25, 34, 30 ], + "name" : "merged" + }, { + "kind" : "Identifier", + "location" : [ 34, 33, 34, 37 ], + "name" : "right" + }, { + "kind" : "Identifier", + "location" : [ 34, 40, 34, 40 ], + "name" : "j" + }, { + "kind" : "CallExpr", + "location" : [ 34, 43, 34, 52 ], + "function" : { + "kind" : "Identifier", + "location" : [ 34, 43, 34, 45 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 34, 47, 34, 51 ], + "name" : "right" + } ] + } ] + } + } ], + "elseBody" : [ ] + }, { + "kind" : "ReturnStmt", + "location" : [ 36, 5, 36, 17 ], + "value" : { + "kind" : "Identifier", + "location" : [ 36, 12, 36, 17 ], + "name" : "merged" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 39, 1, 53, 30 ], + "name" : { + "kind" : "Identifier", + "location" : [ 39, 5, 39, 13 ], + "name" : "mergesort" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 39, 15, 39, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 39, 15, 39, 15 ], + "name" : "a" + }, + "type" : { + "kind" : "ListType", + "location" : [ 39, 18, 39, 22 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 39, 19, 39, 21 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ListType", + "location" : [ 39, 28, 39, 32 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 39, 29, 39, 31 ], + "className" : "int" + } + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 40, 5, 40, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 40, 5, 40, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 40, 5, 40, 7 ], + "name" : "mid" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 40, 10, 40, 12 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 40, 16, 40, 16 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 41, 5, 41, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 41, 5, 41, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 41, 5, 41, 8 ], + "name" : "left" + }, + "type" : { + "kind" : "ListType", + "location" : [ 41, 11, 41, 15 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 41, 12, 41, 14 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 41, 19, 41, 22 ] + } + }, { + "kind" : "VarDef", + "location" : [ 42, 5, 42, 23 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 42, 5, 42, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 42, 5, 42, 9 ], + "name" : "right" + }, + "type" : { + "kind" : "ListType", + "location" : [ 42, 12, 42, 16 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 42, 13, 42, 15 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 42, 20, 42, 23 ] + } + } ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 44, 5, 47, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 44, 8, 44, 17 ], + "left" : { + "kind" : "CallExpr", + "location" : [ 44, 8, 44, 13 ], + "function" : { + "kind" : "Identifier", + "location" : [ 44, 8, 44, 10 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 44, 12, 44, 12 ], + "name" : "a" + } ] + }, + "operator" : "<", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 44, 17, 44, 17 ], + "value" : 2 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 45, 9, 45, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 45, 16, 45, 16 ], + "name" : "a" + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 47, 5, 47, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 47, 5, 47, 7 ], + "name" : "mid" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 47, 11, 47, 21 ], + "left" : { + "kind" : "CallExpr", + "location" : [ 47, 11, 47, 16 ], + "function" : { + "kind" : "Identifier", + "location" : [ 47, 11, 47, 13 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 47, 15, 47, 15 ], + "name" : "a" + } ] + }, + "operator" : "//", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 47, 21, 47, 21 ], + "value" : 2 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 48, 5, 48, 32 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 48, 5, 48, 8 ], + "name" : "left" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 48, 12, 48, 32 ], + "function" : { + "kind" : "Identifier", + "location" : [ 48, 12, 48, 17 ], + "name" : "extend" + }, + "args" : [ { + "kind" : "ListExpr", + "location" : [ 48, 19, 48, 20 ], + "elements" : [ ] + }, { + "kind" : "Identifier", + "location" : [ 48, 23, 48, 23 ], + "name" : "a" + }, { + "kind" : "IntegerLiteral", + "location" : [ 48, 26, 48, 26 ], + "value" : 0 + }, { + "kind" : "Identifier", + "location" : [ 48, 29, 48, 31 ], + "name" : "mid" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 49, 5, 49, 38 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 49, 5, 49, 9 ], + "name" : "right" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 49, 13, 49, 38 ], + "function" : { + "kind" : "Identifier", + "location" : [ 49, 13, 49, 18 ], + "name" : "extend" + }, + "args" : [ { + "kind" : "ListExpr", + "location" : [ 49, 20, 49, 21 ], + "elements" : [ ] + }, { + "kind" : "Identifier", + "location" : [ 49, 24, 49, 24 ], + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 49, 27, 49, 29 ], + "name" : "mid" + }, { + "kind" : "CallExpr", + "location" : [ 49, 32, 49, 37 ], + "function" : { + "kind" : "Identifier", + "location" : [ 49, 32, 49, 34 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 49, 36, 49, 36 ], + "name" : "a" + } ] + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 51, 5, 51, 26 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 51, 5, 51, 8 ], + "name" : "left" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 51, 12, 51, 26 ], + "function" : { + "kind" : "Identifier", + "location" : [ 51, 12, 51, 20 ], + "name" : "mergesort" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 51, 22, 51, 25 ], + "name" : "left" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 52, 5, 52, 28 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 52, 5, 52, 9 ], + "name" : "right" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 52, 13, 52, 28 ], + "function" : { + "kind" : "Identifier", + "location" : [ 52, 13, 52, 21 ], + "name" : "mergesort" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 52, 23, 52, 27 ], + "name" : "right" + } ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 53, 5, 53, 29 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 53, 12, 53, 29 ], + "function" : { + "kind" : "Identifier", + "location" : [ 53, 12, 53, 16 ], + "name" : "merge" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 53, 18, 53, 21 ], + "name" : "left" + }, { + "kind" : "Identifier", + "location" : [ 53, 24, 53, 28 ], + "name" : "right" + } ] + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 56, 1, 56, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 56, 1, 56, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 56, 1, 56, 7 ], + "name" : "initial" + }, + "type" : { + "kind" : "ListType", + "location" : [ 56, 10, 56, 14 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 56, 11, 56, 13 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 56, 18, 56, 21 ] + } + }, { + "kind" : "VarDef", + "location" : [ 57, 1, 57, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 57, 1, 57, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 57, 1, 57, 7 ], + "name" : "ordered" + }, + "type" : { + "kind" : "ListType", + "location" : [ 57, 10, 57, 14 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 57, 11, 57, 13 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 57, 18, 57, 21 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 59, 1, 59, 26 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 59, 1, 59, 7 ], + "name" : "initial" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 59, 11, 59, 26 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 59, 12, 59, 12 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 59, 15, 59, 15 ], + "value" : 7 + }, { + "kind" : "IntegerLiteral", + "location" : [ 59, 18, 59, 18 ], + "value" : 3 + }, { + "kind" : "IntegerLiteral", + "location" : [ 59, 21, 59, 22 ], + "value" : 11 + }, { + "kind" : "IntegerLiteral", + "location" : [ 59, 25, 59, 25 ], + "value" : 5 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 60, 1, 60, 28 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 60, 1, 60, 7 ], + "name" : "ordered" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 60, 11, 60, 28 ], + "function" : { + "kind" : "Identifier", + "location" : [ 60, 11, 60, 19 ], + "name" : "mergesort" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 60, 21, 60, 27 ], + "name" : "initial" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 62, 1, 62, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 62, 1, 62, 14 ], + "function" : { + "kind" : "Identifier", + "location" : [ 62, 1, 62, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 62, 7, 62, 13 ], + "name" : "ordered" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/extra/mergesort.py.ast.typed b/pa2-tests/extra/mergesort.py.ast.typed new file mode 100644 index 0000000..734f0a2 --- /dev/null +++ b/pa2-tests/extra/mergesort.py.ast.typed @@ -0,0 +1,2353 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 62, 15 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 10 ], + "name" : "append" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 12, 1, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 12, 1, 12 ], + "name" : "a" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 15, 1, 19 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 16, 1, 18 ], + "className" : "int" + } + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 22, 1, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 22, 1, 22 ], + "name" : "k" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 25, 1, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ListType", + "location" : [ 1, 33, 1, 37 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 34, 1, 36 ], + "className" : "int" + } + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 18 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 2, 12, 2, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "left" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 12 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "a" + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 2, 16, 2, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "Identifier", + "location" : [ 2, 17, 2, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "k" + } ] + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 14, 20 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 10 ], + "name" : "extend" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 12, 5, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 12, 5, 12 ], + "name" : "a" + }, + "type" : { + "kind" : "ListType", + "location" : [ 5, 15, 5, 19 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 5, 16, 5, 18 ], + "className" : "int" + } + } + }, { + "kind" : "TypedVar", + "location" : [ 5, 22, 5, 29 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 22, 5, 22 ], + "name" : "b" + }, + "type" : { + "kind" : "ListType", + "location" : [ 5, 25, 5, 29 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 5, 26, 5, 28 ], + "className" : "int" + } + } + }, { + "kind" : "TypedVar", + "location" : [ 5, 32, 5, 43 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 32, 5, 38 ], + "name" : "b_start" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 41, 5, 43 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 5, 46, 5, 55 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 46, 5, 50 ], + "name" : "b_end" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 53, 5, 55 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ListType", + "location" : [ 5, 61, 5, 65 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 5, 62, 5, 64 ], + "className" : "int" + } + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 26 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 12 ], + "name" : "extended" + }, + "type" : { + "kind" : "ListType", + "location" : [ 6, 15, 6, 19 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 6, 16, 6, 18 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 6, 23, 6, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 8, 7, 10 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 14, 7, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 9, 5, 9, 16 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 12 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "extended" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 9, 16, 9, 16 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "a" + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 5, 10, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 5, 10, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "b_start" + } + }, { + "kind" : "WhileStmt", + "location" : [ 11, 5, 14, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 11, 11, 11, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 11, 11, 11, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "Identifier", + "location" : [ 11, 15, 11, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "b_end" + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 12, 9, 12, 41 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 12, 9, 12, 16 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "extended" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 12, 20, 12, 41 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "function" : { + "kind" : "Identifier", + "location" : [ 12, 20, 12, 25 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } + }, + "name" : "append" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 12, 27, 12, 34 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "extended" + }, { + "kind" : "IndexExpr", + "location" : [ 12, 37, 12, 40 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 12, 37, 12, 37 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "b" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 12, 39, 12, 39 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 13, 9, 13, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 13, 9, 13, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 13, 13, 13, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 13, 13, 13, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 17, 13, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 14, 5, 14, 19 ], + "value" : { + "kind" : "Identifier", + "location" : [ 14, 12, 14, 19 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "extended" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 17, 1, 36, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 9 ], + "name" : "merge" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 17, 11, 17, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 11, 17, 14 ], + "name" : "left" + }, + "type" : { + "kind" : "ListType", + "location" : [ 17, 17, 17, 21 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 17, 18, 17, 20 ], + "className" : "int" + } + } + }, { + "kind" : "TypedVar", + "location" : [ 17, 24, 17, 35 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 24, 17, 28 ], + "name" : "right" + }, + "type" : { + "kind" : "ListType", + "location" : [ 17, 31, 17, 35 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 17, 32, 17, 34 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ListType", + "location" : [ 17, 41, 17, 45 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 17, 42, 17, 44 ], + "className" : "int" + } + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 18, 5, 18, 24 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 18, 5, 18, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 18, 5, 18, 10 ], + "name" : "merged" + }, + "type" : { + "kind" : "ListType", + "location" : [ 18, 13, 18, 17 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 18, 14, 18, 16 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 18, 21, 18, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 19, 5, 19, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 19, 5, 19, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 5, 19, 5 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 8, 19, 10 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 19, 14, 19, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 20, 5, 20, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 20, 5, 20, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 20, 5, 20, 5 ], + "name" : "j" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 20, 8, 20, 10 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 20, 14, 20, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 22, 5, 22, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 10 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "merged" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 22, 14, 22, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + } + }, { + "kind" : "WhileStmt", + "location" : [ 23, 5, 31, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 23, 11, 23, 42 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 23, 11, 23, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 23, 11, 23, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "CallExpr", + "location" : [ 23, 15, 23, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 23, 15, 23, 17 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 23, 19, 23, 22 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "left" + } ] + } + }, + "operator" : "and", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 23, 29, 23, 42 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 23, 29, 23, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + }, + "operator" : "<", + "right" : { + "kind" : "CallExpr", + "location" : [ 23, 33, 23, 42 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 23, 33, 23, 35 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 23, 37, 23, 41 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "right" + } ] + } + } + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 24, 9, 31, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 24, 12, 24, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IndexExpr", + "location" : [ 24, 12, 24, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 24, 12, 24, 15 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "left" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 24, 17, 24, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } + }, + "operator" : "<", + "right" : { + "kind" : "IndexExpr", + "location" : [ 24, 22, 24, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 24, 22, 24, 26 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "right" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 24, 28, 24, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + } + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 25, 13, 25, 44 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 25, 13, 25, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "merged" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 25, 22, 25, 44 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "function" : { + "kind" : "Identifier", + "location" : [ 25, 22, 25, 27 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } + }, + "name" : "append" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 25, 29, 25, 34 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "merged" + }, { + "kind" : "IndexExpr", + "location" : [ 25, 37, 25, 43 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 25, 37, 25, 40 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "left" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 25, 42, 25, 42 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 26, 13, 26, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 26, 13, 26, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 26, 17, 26, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 26, 17, 26, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 26, 21, 26, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ], + "elseBody" : [ { + "kind" : "AssignStmt", + "location" : [ 28, 13, 28, 45 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 28, 13, 28, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "merged" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 28, 22, 28, 45 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "function" : { + "kind" : "Identifier", + "location" : [ 28, 22, 28, 27 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } + }, + "name" : "append" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 28, 29, 28, 34 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "merged" + }, { + "kind" : "IndexExpr", + "location" : [ 28, 37, 28, 44 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 28, 37, 28, 41 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "right" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 28, 43, 28, 43 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 29, 13, 29, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 29, 13, 29, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 29, 17, 29, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 29, 17, 29, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 29, 21, 29, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ] + }, { + "kind" : "IfStmt", + "location" : [ 31, 5, 33, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 31, 8, 31, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 31, 8, 31, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "CallExpr", + "location" : [ 31, 12, 31, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 31, 12, 31, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 31, 16, 31, 19 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "left" + } ] + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 32, 9, 32, 51 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 32, 9, 32, 14 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "merged" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 32, 18, 32, 51 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "function" : { + "kind" : "Identifier", + "location" : [ 32, 18, 32, 23 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, { + "kind" : "ClassValueType", + "className" : "int" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } + }, + "name" : "extend" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 32, 25, 32, 30 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "merged" + }, { + "kind" : "Identifier", + "location" : [ 32, 33, 32, 36 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "left" + }, { + "kind" : "Identifier", + "location" : [ 32, 39, 32, 39 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, { + "kind" : "CallExpr", + "location" : [ 32, 42, 32, 50 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 32, 42, 32, 44 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 32, 46, 32, 49 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "left" + } ] + } ] + } + } ], + "elseBody" : [ ] + }, { + "kind" : "IfStmt", + "location" : [ 33, 5, 36, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 33, 8, 33, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 33, 8, 33, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + }, + "operator" : "<", + "right" : { + "kind" : "CallExpr", + "location" : [ 33, 12, 33, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 33, 12, 33, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 33, 16, 33, 20 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "right" + } ] + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 34, 9, 34, 53 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 34, 9, 34, 14 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "merged" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 34, 18, 34, 53 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "function" : { + "kind" : "Identifier", + "location" : [ 34, 18, 34, 23 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, { + "kind" : "ClassValueType", + "className" : "int" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } + }, + "name" : "extend" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 34, 25, 34, 30 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "merged" + }, { + "kind" : "Identifier", + "location" : [ 34, 33, 34, 37 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "right" + }, { + "kind" : "Identifier", + "location" : [ 34, 40, 34, 40 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + }, { + "kind" : "CallExpr", + "location" : [ 34, 43, 34, 52 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 34, 43, 34, 45 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 34, 47, 34, 51 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "right" + } ] + } ] + } + } ], + "elseBody" : [ ] + }, { + "kind" : "ReturnStmt", + "location" : [ 36, 5, 36, 17 ], + "value" : { + "kind" : "Identifier", + "location" : [ 36, 12, 36, 17 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "merged" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 39, 1, 53, 30 ], + "name" : { + "kind" : "Identifier", + "location" : [ 39, 5, 39, 13 ], + "name" : "mergesort" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 39, 15, 39, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 39, 15, 39, 15 ], + "name" : "a" + }, + "type" : { + "kind" : "ListType", + "location" : [ 39, 18, 39, 22 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 39, 19, 39, 21 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ListType", + "location" : [ 39, 28, 39, 32 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 39, 29, 39, 31 ], + "className" : "int" + } + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 40, 5, 40, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 40, 5, 40, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 40, 5, 40, 7 ], + "name" : "mid" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 40, 10, 40, 12 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 40, 16, 40, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 41, 5, 41, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 41, 5, 41, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 41, 5, 41, 8 ], + "name" : "left" + }, + "type" : { + "kind" : "ListType", + "location" : [ 41, 11, 41, 15 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 41, 12, 41, 14 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 41, 19, 41, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 42, 5, 42, 23 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 42, 5, 42, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 42, 5, 42, 9 ], + "name" : "right" + }, + "type" : { + "kind" : "ListType", + "location" : [ 42, 12, 42, 16 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 42, 13, 42, 15 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 42, 20, 42, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 44, 5, 47, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 44, 8, 44, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "CallExpr", + "location" : [ 44, 8, 44, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 44, 8, 44, 10 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 44, 12, 44, 12 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "a" + } ] + }, + "operator" : "<", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 44, 17, 44, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 45, 9, 45, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 45, 16, 45, 16 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "a" + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 47, 5, 47, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 47, 5, 47, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "mid" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 47, 11, 47, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "CallExpr", + "location" : [ 47, 11, 47, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 47, 11, 47, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 47, 15, 47, 15 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "a" + } ] + }, + "operator" : "//", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 47, 21, 47, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 48, 5, 48, 32 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 48, 5, 48, 8 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "left" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 48, 12, 48, 32 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "function" : { + "kind" : "Identifier", + "location" : [ 48, 12, 48, 17 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, { + "kind" : "ClassValueType", + "className" : "int" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } + }, + "name" : "extend" + }, + "args" : [ { + "kind" : "ListExpr", + "location" : [ 48, 19, 48, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + }, { + "kind" : "Identifier", + "location" : [ 48, 23, 48, 23 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "a" + }, { + "kind" : "IntegerLiteral", + "location" : [ 48, 26, 48, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + }, { + "kind" : "Identifier", + "location" : [ 48, 29, 48, 31 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "mid" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 49, 5, 49, 38 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 49, 5, 49, 9 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "right" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 49, 13, 49, 38 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "function" : { + "kind" : "Identifier", + "location" : [ 49, 13, 49, 18 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, { + "kind" : "ClassValueType", + "className" : "int" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } + }, + "name" : "extend" + }, + "args" : [ { + "kind" : "ListExpr", + "location" : [ 49, 20, 49, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + }, { + "kind" : "Identifier", + "location" : [ 49, 24, 49, 24 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 49, 27, 49, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "mid" + }, { + "kind" : "CallExpr", + "location" : [ 49, 32, 49, 37 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 49, 32, 49, 34 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 49, 36, 49, 36 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "a" + } ] + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 51, 5, 51, 26 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 51, 5, 51, 8 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "left" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 51, 12, 51, 26 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "function" : { + "kind" : "Identifier", + "location" : [ 51, 12, 51, 20 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } + }, + "name" : "mergesort" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 51, 22, 51, 25 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "left" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 52, 5, 52, 28 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 52, 5, 52, 9 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "right" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 52, 13, 52, 28 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "function" : { + "kind" : "Identifier", + "location" : [ 52, 13, 52, 21 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } + }, + "name" : "mergesort" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 52, 23, 52, 27 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "right" + } ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 53, 5, 53, 29 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 53, 12, 53, 29 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "function" : { + "kind" : "Identifier", + "location" : [ 53, 12, 53, 16 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } + }, + "name" : "merge" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 53, 18, 53, 21 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "left" + }, { + "kind" : "Identifier", + "location" : [ 53, 24, 53, 28 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "right" + } ] + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 56, 1, 56, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 56, 1, 56, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 56, 1, 56, 7 ], + "name" : "initial" + }, + "type" : { + "kind" : "ListType", + "location" : [ 56, 10, 56, 14 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 56, 11, 56, 13 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 56, 18, 56, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 57, 1, 57, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 57, 1, 57, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 57, 1, 57, 7 ], + "name" : "ordered" + }, + "type" : { + "kind" : "ListType", + "location" : [ 57, 10, 57, 14 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 57, 11, 57, 13 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 57, 18, 57, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 59, 1, 59, 26 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 59, 1, 59, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "initial" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 59, 11, 59, 26 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 59, 12, 59, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 59, 15, 59, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 7 + }, { + "kind" : "IntegerLiteral", + "location" : [ 59, 18, 59, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + }, { + "kind" : "IntegerLiteral", + "location" : [ 59, 21, 59, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 11 + }, { + "kind" : "IntegerLiteral", + "location" : [ 59, 25, 59, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 5 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 60, 1, 60, 28 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 60, 1, 60, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "ordered" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 60, 11, 60, 28 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "function" : { + "kind" : "Identifier", + "location" : [ 60, 11, 60, 19 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } + }, + "name" : "mergesort" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 60, 21, 60, 27 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "initial" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 62, 1, 62, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 62, 1, 62, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 62, 1, 62, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 62, 7, 62, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "ordered" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/extra/nested.py b/pa2-tests/extra/nested.py new file mode 100644 index 0000000..b193ecd --- /dev/null +++ b/pa2-tests/extra/nested.py @@ -0,0 +1,18 @@ +class A(object): + a:int = 42 + + def foo(self:"A", ignore:object) -> int: + return self.a + +class B(A): + b:bool = True + + def __init__(self:"B"): + print("B") + + def bar(self:"B") -> int: + def qux(p: bool) -> int: + return self.foo(p) + return qux(True) + +print(B().bar()) diff --git a/pa2-tests/extra/nested.py.ast b/pa2-tests/extra/nested.py.ast new file mode 100644 index 0000000..4c8945a --- /dev/null +++ b/pa2-tests/extra/nested.py.ast @@ -0,0 +1,325 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 18, 17 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 14 ], + "value" : 42 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 23, 4, 35 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 23, 4, 28 ], + "name" : "ignore" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 30, 4, 35 ], + "className" : "object" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 41, 4, 43 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 21 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 5, 16, 5, 21 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 19 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 21, 5, 21 ], + "name" : "a" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 18, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 8, 5, 8, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 8, 5, 8, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 7, 8, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 8, 14, 8, 17 ], + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 10, 5, 11, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 10, 18, 10, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 18, 10, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 23, 10, 25 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 10, 27, 10, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 9, 11, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 9, 11, 18 ], + "function" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 13 ], + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 11, 15, 11, 17 ], + "value" : "B" + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 13, 5, 16, 25 ], + "name" : { + "kind" : "Identifier", + "location" : [ 13, 9, 13, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 13, 13, 13, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 13, 13, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 18, 13, 20 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 13, 26, 13, 28 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 14, 9, 15, 31 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 13, 14, 15 ], + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 17, 14, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 17, 14, 17 ], + "name" : "p" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 20, 14, 23 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 29, 14, 31 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 15, 13, 15, 30 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 15, 20, 15, 30 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 15, 20, 15, 27 ], + "object" : { + "kind" : "Identifier", + "location" : [ 15, 20, 15, 23 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 25, 15, 27 ], + "name" : "foo" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 15, 29, 15, 29 ], + "name" : "p" + } ] + } + } ] + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 16, 9, 16, 24 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 16, 16, 24 ], + "function" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 18 ], + "name" : "qux" + }, + "args" : [ { + "kind" : "BooleanLiteral", + "location" : [ 16, 20, 16, 23 ], + "value" : true + } ] + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 18, 1, 18, 16 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 18, 1, 18, 16 ], + "function" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 18, 7, 18, 15 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 18, 7, 18, 13 ], + "object" : { + "kind" : "CallExpr", + "location" : [ 18, 7, 18, 9 ], + "function" : { + "kind" : "Identifier", + "location" : [ 18, 7, 18, 7 ], + "name" : "B" + }, + "args" : [ ] + }, + "member" : { + "kind" : "Identifier", + "location" : [ 18, 11, 18, 13 ], + "name" : "bar" + } + }, + "args" : [ ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/extra/nested.py.ast.typed b/pa2-tests/extra/nested.py.ast.typed new file mode 100644 index 0000000..5480892 --- /dev/null +++ b/pa2-tests/extra/nested.py.ast.typed @@ -0,0 +1,439 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 18, 17 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 23, 4, 35 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 23, 4, 28 ], + "name" : "ignore" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 30, 4, 35 ], + "className" : "object" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 41, 4, 43 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 21 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 5, 16, 5, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 21, 5, 21 ], + "name" : "a" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 18, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 8, 5, 8, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 8, 5, 8, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 7, 8, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 8, 14, 8, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 10, 5, 11, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 10, 18, 10, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 18, 10, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 23, 10, 25 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 10, 27, 10, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 9, 11, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 9, 11, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 11, 15, 11, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "B" + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 13, 5, 16, 25 ], + "name" : { + "kind" : "Identifier", + "location" : [ 13, 9, 13, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 13, 13, 13, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 13, 13, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 18, 13, 20 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 13, 26, 13, 28 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 14, 9, 15, 31 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 13, 14, 15 ], + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 17, 14, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 17, 14, 17 ], + "name" : "p" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 20, 14, 23 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 29, 14, 31 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 15, 13, 15, 30 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 15, 20, 15, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 15, 20, 15, 27 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "A" + }, { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 20, 15, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 25, 15, 27 ], + "name" : "foo" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 15, 29, 15, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "name" : "p" + } ] + } + } ] + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 16, 9, 16, 24 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 16, 16, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 18 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "bool" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "qux" + }, + "args" : [ { + "kind" : "BooleanLiteral", + "location" : [ 16, 20, 16, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } ] + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 18, 1, 18, 16 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 18, 1, 18, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 18, 7, 18, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 18, 7, 18, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "B" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "CallExpr", + "location" : [ 18, 7, 18, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 18, 7, 18, 7 ], + "name" : "B" + }, + "args" : [ ] + }, + "member" : { + "kind" : "Identifier", + "location" : [ 18, 11, 18, 13 ], + "name" : "bar" + } + }, + "args" : [ ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/extra/prime.py b/pa2-tests/extra/prime.py new file mode 100644 index 0000000..7568705 --- /dev/null +++ b/pa2-tests/extra/prime.py @@ -0,0 +1,30 @@ +# Get the n-th prime starting from 2 +def get_prime(n:int) -> int: + candidate:int = 2 + found:int = 0 + while True: + if is_prime(candidate): + found = found + 1 + if found == n: + return candidate + candidate = candidate + 1 + return 0 # Never happens + +def is_prime(x:int) -> bool: + div:int = 2 + while div < x: + if x % div == 0: + return False + div = div + 1 + return True + +# Input parameter +n:int = 15 + +# Run [1, n] +i:int = 1 + +# Crunch +while i <= n: + print(get_prime(i)) + i = i + 1 diff --git a/pa2-tests/extra/prime.py.ast b/pa2-tests/extra/prime.py.ast new file mode 100644 index 0000000..209c50c --- /dev/null +++ b/pa2-tests/extra/prime.py.ast @@ -0,0 +1,445 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 31, 1 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 1, 11, 29 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 13 ], + "name" : "get_prime" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 15, 2, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 15, 2, 15 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 17, 2, 19 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 25, 2, 27 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 13 ], + "name" : "candidate" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 15, 3, 17 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 21, 3, 21 ], + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 9 ], + "name" : "found" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 11, 4, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 17, 4, 17 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 5, 5, 11, 4 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 11, 5, 14 ], + "value" : true + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 6, 9, 10, 8 ], + "condition" : { + "kind" : "CallExpr", + "location" : [ 6, 12, 6, 30 ], + "function" : { + "kind" : "Identifier", + "location" : [ 6, 12, 6, 19 ], + "name" : "is_prime" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 6, 21, 6, 29 ], + "name" : "candidate" + } ] + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 13, 7, 29 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 13, 7, 17 ], + "name" : "found" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 7, 21, 7, 29 ], + "left" : { + "kind" : "Identifier", + "location" : [ 7, 21, 7, 25 ], + "name" : "found" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 29, 7, 29 ], + "value" : 1 + } + } + }, { + "kind" : "IfStmt", + "location" : [ 8, 13, 10, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 8, 16, 8, 25 ], + "left" : { + "kind" : "Identifier", + "location" : [ 8, 16, 8, 20 ], + "name" : "found" + }, + "operator" : "==", + "right" : { + "kind" : "Identifier", + "location" : [ 8, 25, 8, 25 ], + "name" : "n" + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 9, 17, 9, 32 ], + "value" : { + "kind" : "Identifier", + "location" : [ 9, 24, 9, 32 ], + "name" : "candidate" + } + } ], + "elseBody" : [ ] + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 10, 9, 10, 33 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 17 ], + "name" : "candidate" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 10, 21, 10, 33 ], + "left" : { + "kind" : "Identifier", + "location" : [ 10, 21, 10, 29 ], + "name" : "candidate" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 33, 10, 33 ], + "value" : 1 + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 11, 5, 11, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 12, 11, 12 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 13, 1, 19, 16 ], + "name" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 12 ], + "name" : "is_prime" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 13, 14, 13, 18 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 14, 13, 14 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 16, 13, 18 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 13, 24, 13, 27 ], + "className" : "bool" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 14, 5, 14, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 14, 5, 14, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 5, 14, 7 ], + "name" : "div" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 9, 14, 11 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 14, 15, 14, 15 ], + "value" : 2 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 15, 5, 19, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 15, 11, 15, 17 ], + "left" : { + "kind" : "Identifier", + "location" : [ 15, 11, 15, 13 ], + "name" : "div" + }, + "operator" : "<", + "right" : { + "kind" : "Identifier", + "location" : [ 15, 17, 15, 17 ], + "name" : "x" + } + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 16, 9, 18, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 16, 12, 16, 23 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 16, 12, 16, 18 ], + "left" : { + "kind" : "Identifier", + "location" : [ 16, 12, 16, 12 ], + "name" : "x" + }, + "operator" : "%", + "right" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 18 ], + "name" : "div" + } + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 16, 23, 16, 23 ], + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 17, 13, 17, 24 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 17, 20, 17, 24 ], + "value" : false + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 18, 9, 18, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 18, 9, 18, 11 ], + "name" : "div" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 18, 15, 18, 21 ], + "left" : { + "kind" : "Identifier", + "location" : [ 18, 15, 18, 17 ], + "name" : "div" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 18, 21, 18, 21 ], + "value" : 1 + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 19, 5, 19, 15 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 19, 12, 19, 15 ], + "value" : true + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 22, 1, 22, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 22, 1, 22, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 1 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 22, 3, 22, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 22, 9, 22, 10 ], + "value" : 15 + } + }, { + "kind" : "VarDef", + "location" : [ 25, 1, 25, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 25, 1, 25, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 25, 1, 25, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 25, 3, 25, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 25, 9, 25, 9 ], + "value" : 1 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 28, 1, 31, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 28, 7, 28, 12 ], + "left" : { + "kind" : "Identifier", + "location" : [ 28, 7, 28, 7 ], + "name" : "i" + }, + "operator" : "<=", + "right" : { + "kind" : "Identifier", + "location" : [ 28, 12, 28, 12 ], + "name" : "n" + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 29, 5, 29, 23 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 29, 5, 29, 23 ], + "function" : { + "kind" : "Identifier", + "location" : [ 29, 5, 29, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 29, 11, 29, 22 ], + "function" : { + "kind" : "Identifier", + "location" : [ 29, 11, 29, 19 ], + "name" : "get_prime" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 29, 21, 29, 21 ], + "name" : "i" + } ] + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 30, 5, 30, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 30, 5, 30, 5 ], + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 30, 9, 30, 13 ], + "left" : { + "kind" : "Identifier", + "location" : [ 30, 9, 30, 9 ], + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 30, 13, 30, 13 ], + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/extra/prime.py.ast.typed b/pa2-tests/extra/prime.py.ast.typed new file mode 100644 index 0000000..a3062b6 --- /dev/null +++ b/pa2-tests/extra/prime.py.ast.typed @@ -0,0 +1,658 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 31, 1 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 1, 11, 29 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 13 ], + "name" : "get_prime" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 15, 2, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 15, 2, 15 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 17, 2, 19 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 25, 2, 27 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 13 ], + "name" : "candidate" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 15, 3, 17 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 21, 3, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 9 ], + "name" : "found" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 11, 4, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 17, 4, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 5, 5, 11, 4 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 11, 5, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 6, 9, 10, 8 ], + "condition" : { + "kind" : "CallExpr", + "location" : [ 6, 12, 6, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 6, 12, 6, 19 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "is_prime" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 6, 21, 6, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "candidate" + } ] + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 13, 7, 29 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 13, 7, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "found" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 7, 21, 7, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 7, 21, 7, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "found" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 29, 7, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, { + "kind" : "IfStmt", + "location" : [ 8, 13, 10, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 8, 16, 8, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 8, 16, 8, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "found" + }, + "operator" : "==", + "right" : { + "kind" : "Identifier", + "location" : [ 8, 25, 8, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "n" + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 9, 17, 9, 32 ], + "value" : { + "kind" : "Identifier", + "location" : [ 9, 24, 9, 32 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "candidate" + } + } ], + "elseBody" : [ ] + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 10, 9, 10, 33 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "candidate" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 10, 21, 10, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 10, 21, 10, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "candidate" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 33, 10, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 11, 5, 11, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 12, 11, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 13, 1, 19, 16 ], + "name" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 12 ], + "name" : "is_prime" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 13, 14, 13, 18 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 14, 13, 14 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 16, 13, 18 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 13, 24, 13, 27 ], + "className" : "bool" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 14, 5, 14, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 14, 5, 14, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 5, 14, 7 ], + "name" : "div" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 9, 14, 11 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 14, 15, 14, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 15, 5, 19, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 15, 11, 15, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 15, 11, 15, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "div" + }, + "operator" : "<", + "right" : { + "kind" : "Identifier", + "location" : [ 15, 17, 15, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 16, 9, 18, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 16, 12, 16, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 16, 12, 16, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 16, 12, 16, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "%", + "right" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "div" + } + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 16, 23, 16, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 17, 13, 17, 24 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 17, 20, 17, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 18, 9, 18, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 18, 9, 18, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "div" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 18, 15, 18, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 18, 15, 18, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "div" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 18, 21, 18, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 19, 5, 19, 15 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 19, 12, 19, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 22, 1, 22, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 22, 1, 22, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 1 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 22, 3, 22, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 22, 9, 22, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 15 + } + }, { + "kind" : "VarDef", + "location" : [ 25, 1, 25, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 25, 1, 25, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 25, 1, 25, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 25, 3, 25, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 25, 9, 25, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 28, 1, 31, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 28, 7, 28, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 28, 7, 28, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<=", + "right" : { + "kind" : "Identifier", + "location" : [ 28, 12, 28, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "n" + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 29, 5, 29, 23 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 29, 5, 29, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 29, 5, 29, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 29, 11, 29, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 29, 11, 29, 19 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "get_prime" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 29, 21, 29, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ] + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 30, 5, 30, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 30, 5, 30, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 30, 9, 30, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 30, 9, 30, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 30, 13, 30, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/extra/sieve.py b/pa2-tests/extra/sieve.py new file mode 100644 index 0000000..b6aa977 --- /dev/null +++ b/pa2-tests/extra/sieve.py @@ -0,0 +1,107 @@ +# A resizable list of integers +class Vector(object): + items: [int] = None + size: int = 0 + + def __init__(self:"Vector"): + self.items = [0] + + # Returns current capacity + def capacity(self:"Vector") -> int: + return len(self.items) + + # Increases capacity of vector by one element + def increase_capacity(self:"Vector") -> int: + self.items = self.items + [0] + return self.capacity() + + # Appends one item to end of vector + def append(self:"Vector", item: int) -> object: + if self.size == self.capacity(): + self.increase_capacity() + + self.items[self.size] = item + self.size = self.size + 1 + + # Appends many items to end of vector + def append_all(self:"Vector", new_items: [int]) -> object: + item:int = 0 + for item in new_items: + self.append(item) + + # Removes an item from the middle of vector + def remove_at(self:"Vector", idx: int) -> object: + if idx < 0: + return + + while idx < self.size - 1: + self.items[idx] = self.items[idx + 1] + idx = idx + 1 + + self.size = self.size - 1 + + # Retrieves an item at a given index + def get(self:"Vector", idx: int) -> int: + return self.items[idx] + + # Retrieves the current size of the vector + def length(self:"Vector") -> int: + return self.size + +# A faster (but more memory-consuming) implementation of vector +class DoublingVector(Vector): + doubling_limit:int = 1000 + + # Overriding to do fewer resizes + def increase_capacity(self:"DoublingVector") -> int: + if (self.capacity() <= self.doubling_limit // 2): + self.items = self.items + self.items + else: + # If doubling limit has been reached, fall back to + # standard capacity increases + self.items = self.items + [0] + return self.capacity() + +# Makes a vector in the range [i, j) +def vrange(i:int, j:int) -> Vector: + v:Vector = None + v = DoublingVector() + + while i < j: + v.append(i) + i = i + 1 + + return v + +# Sieve of Eratosthenes (not really) +def sieve(v:Vector) -> object: + i:int = 0 + j:int = 0 + k:int = 0 + + while i < v.length(): + k = v.get(i) + j = i + 1 + while j < v.length(): + if v.get(j) % k == 0: + v.remove_at(j) + else: + j = j + 1 + i = i + 1 + +# Input parameter +n:int = 50 + +# Data +v:Vector = None +i:int = 0 + +# Crunch +v = vrange(2, n) +sieve(v) + +# Print +while i < v.length(): + print(v.get(i)) + i = i + 1 + diff --git a/pa2-tests/extra/sieve.py.ast b/pa2-tests/extra/sieve.py.ast new file mode 100644 index 0000000..82bad46 --- /dev/null +++ b/pa2-tests/extra/sieve.py.ast @@ -0,0 +1,1841 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 108, 1 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 2, 1, 52, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 12 ], + "name" : "Vector" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 2, 14, 2, 19 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 23 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 9 ], + "name" : "items" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 12, 3, 16 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 13, 3, 15 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 20, 3, 23 ] + } + }, { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 8 ], + "name" : "size" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 11, 4, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 17, 4, 17 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 6, 5, 7, 25 ], + "name" : { + "kind" : "Identifier", + "location" : [ 6, 9, 6, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 6, 18, 6, 30 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 18, 6, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 23, 6, 30 ], + "className" : "Vector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 6, 32, 6, 32 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 9, 7, 24 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 7, 9, 7, 18 ], + "object" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 7, 14, 7, 18 ], + "name" : "items" + } + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 22, 7, 24 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 7, 23, 7, 23 ], + "value" : 0 + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 10, 5, 11, 31 ], + "name" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 16 ], + "name" : "capacity" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 10, 18, 10, 30 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 18, 10, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 23, 10, 30 ], + "className" : "Vector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 10, 36, 10, 38 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 11, 9, 11, 30 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 11, 16, 11, 30 ], + "function" : { + "kind" : "Identifier", + "location" : [ 11, 16, 11, 18 ], + "name" : "len" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 11, 20, 11, 29 ], + "object" : { + "kind" : "Identifier", + "location" : [ 11, 20, 11, 23 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 11, 25, 11, 29 ], + "name" : "items" + } + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 14, 5, 16, 31 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 25 ], + "name" : "increase_capacity" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 27, 14, 39 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 27, 14, 30 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 32, 14, 39 ], + "className" : "Vector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 45, 14, 47 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 9, 15, 37 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 15, 9, 15, 18 ], + "object" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 14, 15, 18 ], + "name" : "items" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 15, 22, 15, 37 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 15, 22, 15, 31 ], + "object" : { + "kind" : "Identifier", + "location" : [ 15, 22, 15, 25 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 27, 15, 31 ], + "name" : "items" + } + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 15, 35, 15, 37 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 15, 36, 15, 36 ], + "value" : 0 + } ] + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 16, 9, 16, 30 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 16, 16, 16, 30 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 16, 16, 16, 28 ], + "object" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 19 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 16, 21, 16, 28 ], + "name" : "capacity" + } + }, + "args" : [ ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 19, 5, 24, 34 ], + "name" : { + "kind" : "Identifier", + "location" : [ 19, 9, 19, 14 ], + "name" : "append" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 19, 16, 19, 28 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 16, 19, 19 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 21, 19, 28 ], + "className" : "Vector" + } + }, { + "kind" : "TypedVar", + "location" : [ 19, 31, 19, 39 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 31, 19, 34 ], + "name" : "item" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 37, 19, 39 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 19, 45, 19, 50 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 20, 9, 23, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 20, 12, 20, 39 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 20, 12, 20, 20 ], + "object" : { + "kind" : "Identifier", + "location" : [ 20, 12, 20, 15 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 17, 20, 20 ], + "name" : "size" + } + }, + "operator" : "==", + "right" : { + "kind" : "MethodCallExpr", + "location" : [ 20, 25, 20, 39 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 20, 25, 20, 37 ], + "object" : { + "kind" : "Identifier", + "location" : [ 20, 25, 20, 28 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 30, 20, 37 ], + "name" : "capacity" + } + }, + "args" : [ ] + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 21, 13, 21, 36 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 21, 13, 21, 36 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 21, 13, 21, 34 ], + "object" : { + "kind" : "Identifier", + "location" : [ 21, 13, 21, 16 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 21, 18, 21, 34 ], + "name" : "increase_capacity" + } + }, + "args" : [ ] + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 23, 9, 23, 36 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 23, 9, 23, 29 ], + "list" : { + "kind" : "MemberExpr", + "location" : [ 23, 9, 23, 18 ], + "object" : { + "kind" : "Identifier", + "location" : [ 23, 9, 23, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 23, 14, 23, 18 ], + "name" : "items" + } + }, + "index" : { + "kind" : "MemberExpr", + "location" : [ 23, 20, 23, 28 ], + "object" : { + "kind" : "Identifier", + "location" : [ 23, 20, 23, 23 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 23, 25, 23, 28 ], + "name" : "size" + } + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 23, 33, 23, 36 ], + "name" : "item" + } + }, { + "kind" : "AssignStmt", + "location" : [ 24, 9, 24, 33 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 24, 9, 24, 17 ], + "object" : { + "kind" : "Identifier", + "location" : [ 24, 9, 24, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 24, 14, 24, 17 ], + "name" : "size" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 24, 21, 24, 33 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 24, 21, 24, 29 ], + "object" : { + "kind" : "Identifier", + "location" : [ 24, 21, 24, 24 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 24, 26, 24, 29 ], + "name" : "size" + } + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 33, 24, 33 ], + "value" : 1 + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 27, 5, 33, 4 ], + "name" : { + "kind" : "Identifier", + "location" : [ 27, 9, 27, 18 ], + "name" : "append_all" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 27, 20, 27, 32 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 27, 20, 27, 23 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 27, 25, 27, 32 ], + "className" : "Vector" + } + }, { + "kind" : "TypedVar", + "location" : [ 27, 35, 27, 50 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 27, 35, 27, 43 ], + "name" : "new_items" + }, + "type" : { + "kind" : "ListType", + "location" : [ 27, 46, 27, 50 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 27, 47, 27, 49 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 27, 56, 27, 61 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 28, 9, 28, 20 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 28, 9, 28, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 28, 9, 28, 12 ], + "name" : "item" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 28, 14, 28, 16 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 28, 20, 28, 20 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 29, 9, 33, 4 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 13, 29, 16 ], + "name" : "item" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 29, 21, 29, 29 ], + "name" : "new_items" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 30, 13, 30, 29 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 30, 13, 30, 29 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 30, 13, 30, 23 ], + "object" : { + "kind" : "Identifier", + "location" : [ 30, 13, 30, 16 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 30, 18, 30, 23 ], + "name" : "append" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 30, 25, 30, 28 ], + "name" : "item" + } ] + } + } ] + } ] + }, { + "kind" : "FuncDef", + "location" : [ 33, 5, 41, 34 ], + "name" : { + "kind" : "Identifier", + "location" : [ 33, 9, 33, 17 ], + "name" : "remove_at" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 33, 19, 33, 31 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 33, 19, 33, 22 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 33, 24, 33, 31 ], + "className" : "Vector" + } + }, { + "kind" : "TypedVar", + "location" : [ 33, 34, 33, 41 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 33, 34, 33, 36 ], + "name" : "idx" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 33, 39, 33, 41 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 33, 47, 33, 52 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 34, 9, 37, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 34, 12, 34, 18 ], + "left" : { + "kind" : "Identifier", + "location" : [ 34, 12, 34, 14 ], + "name" : "idx" + }, + "operator" : "<", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 34, 18, 34, 18 ], + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 35, 13, 35, 18 ], + "value" : null + } ], + "elseBody" : [ ] + }, { + "kind" : "WhileStmt", + "location" : [ 37, 9, 41, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 37, 15, 37, 33 ], + "left" : { + "kind" : "Identifier", + "location" : [ 37, 15, 37, 17 ], + "name" : "idx" + }, + "operator" : "<", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 37, 21, 37, 33 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 37, 21, 37, 29 ], + "object" : { + "kind" : "Identifier", + "location" : [ 37, 21, 37, 24 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 37, 26, 37, 29 ], + "name" : "size" + } + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 37, 33, 37, 33 ], + "value" : 1 + } + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 38, 13, 38, 49 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 38, 13, 38, 27 ], + "list" : { + "kind" : "MemberExpr", + "location" : [ 38, 13, 38, 22 ], + "object" : { + "kind" : "Identifier", + "location" : [ 38, 13, 38, 16 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 38, 18, 38, 22 ], + "name" : "items" + } + }, + "index" : { + "kind" : "Identifier", + "location" : [ 38, 24, 38, 26 ], + "name" : "idx" + } + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 38, 31, 38, 49 ], + "list" : { + "kind" : "MemberExpr", + "location" : [ 38, 31, 38, 40 ], + "object" : { + "kind" : "Identifier", + "location" : [ 38, 31, 38, 34 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 38, 36, 38, 40 ], + "name" : "items" + } + }, + "index" : { + "kind" : "BinaryExpr", + "location" : [ 38, 42, 38, 48 ], + "left" : { + "kind" : "Identifier", + "location" : [ 38, 42, 38, 44 ], + "name" : "idx" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 38, 48, 38, 48 ], + "value" : 1 + } + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 39, 13, 39, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 39, 13, 39, 15 ], + "name" : "idx" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 39, 19, 39, 25 ], + "left" : { + "kind" : "Identifier", + "location" : [ 39, 19, 39, 21 ], + "name" : "idx" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 39, 25, 39, 25 ], + "value" : 1 + } + } + } ] + }, { + "kind" : "AssignStmt", + "location" : [ 41, 9, 41, 33 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 41, 9, 41, 17 ], + "object" : { + "kind" : "Identifier", + "location" : [ 41, 9, 41, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 41, 14, 41, 17 ], + "name" : "size" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 41, 21, 41, 33 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 41, 21, 41, 29 ], + "object" : { + "kind" : "Identifier", + "location" : [ 41, 21, 41, 24 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 41, 26, 41, 29 ], + "name" : "size" + } + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 41, 33, 41, 33 ], + "value" : 1 + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 44, 5, 45, 31 ], + "name" : { + "kind" : "Identifier", + "location" : [ 44, 9, 44, 11 ], + "name" : "get" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 44, 13, 44, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 44, 13, 44, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 44, 18, 44, 25 ], + "className" : "Vector" + } + }, { + "kind" : "TypedVar", + "location" : [ 44, 28, 44, 35 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 44, 28, 44, 30 ], + "name" : "idx" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 44, 33, 44, 35 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 44, 41, 44, 43 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 45, 9, 45, 30 ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 45, 16, 45, 30 ], + "list" : { + "kind" : "MemberExpr", + "location" : [ 45, 16, 45, 25 ], + "object" : { + "kind" : "Identifier", + "location" : [ 45, 16, 45, 19 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 45, 21, 45, 25 ], + "name" : "items" + } + }, + "index" : { + "kind" : "Identifier", + "location" : [ 45, 27, 45, 29 ], + "name" : "idx" + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 48, 5, 49, 25 ], + "name" : { + "kind" : "Identifier", + "location" : [ 48, 9, 48, 14 ], + "name" : "length" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 48, 16, 48, 28 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 48, 16, 48, 19 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 48, 21, 48, 28 ], + "className" : "Vector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 48, 34, 48, 36 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 49, 9, 49, 24 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 49, 16, 49, 24 ], + "object" : { + "kind" : "Identifier", + "location" : [ 49, 16, 49, 19 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 49, 21, 49, 24 ], + "name" : "size" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 52, 1, 66, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 52, 7, 52, 20 ], + "name" : "DoublingVector" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 52, 22, 52, 27 ], + "name" : "Vector" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 53, 5, 53, 29 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 53, 5, 53, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 53, 5, 53, 18 ], + "name" : "doubling_limit" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 53, 20, 53, 22 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 53, 26, 53, 29 ], + "value" : 1000 + } + }, { + "kind" : "FuncDef", + "location" : [ 56, 5, 63, 31 ], + "name" : { + "kind" : "Identifier", + "location" : [ 56, 9, 56, 25 ], + "name" : "increase_capacity" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 56, 27, 56, 47 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 56, 27, 56, 30 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 56, 32, 56, 47 ], + "className" : "DoublingVector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 56, 53, 56, 55 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 57, 9, 63, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 57, 13, 57, 55 ], + "left" : { + "kind" : "MethodCallExpr", + "location" : [ 57, 13, 57, 27 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 57, 13, 57, 25 ], + "object" : { + "kind" : "Identifier", + "location" : [ 57, 13, 57, 16 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 57, 18, 57, 25 ], + "name" : "capacity" + } + }, + "args" : [ ] + }, + "operator" : "<=", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 57, 32, 57, 55 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 57, 32, 57, 50 ], + "object" : { + "kind" : "Identifier", + "location" : [ 57, 32, 57, 35 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 57, 37, 57, 50 ], + "name" : "doubling_limit" + } + }, + "operator" : "//", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 57, 55, 57, 55 ], + "value" : 2 + } + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 58, 13, 58, 48 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 58, 13, 58, 22 ], + "object" : { + "kind" : "Identifier", + "location" : [ 58, 13, 58, 16 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 58, 18, 58, 22 ], + "name" : "items" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 58, 26, 58, 48 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 58, 26, 58, 35 ], + "object" : { + "kind" : "Identifier", + "location" : [ 58, 26, 58, 29 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 58, 31, 58, 35 ], + "name" : "items" + } + }, + "operator" : "+", + "right" : { + "kind" : "MemberExpr", + "location" : [ 58, 39, 58, 48 ], + "object" : { + "kind" : "Identifier", + "location" : [ 58, 39, 58, 42 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 58, 44, 58, 48 ], + "name" : "items" + } + } + } + } ], + "elseBody" : [ { + "kind" : "AssignStmt", + "location" : [ 62, 13, 62, 41 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 62, 13, 62, 22 ], + "object" : { + "kind" : "Identifier", + "location" : [ 62, 13, 62, 16 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 62, 18, 62, 22 ], + "name" : "items" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 62, 26, 62, 41 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 62, 26, 62, 35 ], + "object" : { + "kind" : "Identifier", + "location" : [ 62, 26, 62, 29 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 62, 31, 62, 35 ], + "name" : "items" + } + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 62, 39, 62, 41 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 62, 40, 62, 40 ], + "value" : 0 + } ] + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 63, 9, 63, 30 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 63, 16, 63, 30 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 63, 16, 63, 28 ], + "object" : { + "kind" : "Identifier", + "location" : [ 63, 16, 63, 19 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 63, 21, 63, 28 ], + "name" : "capacity" + } + }, + "args" : [ ] + } + } ] + } ] + }, { + "kind" : "FuncDef", + "location" : [ 66, 1, 74, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 66, 5, 66, 10 ], + "name" : "vrange" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 66, 12, 66, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 66, 12, 66, 12 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 66, 14, 66, 16 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 66, 19, 66, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 66, 19, 66, 19 ], + "name" : "j" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 66, 21, 66, 23 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 66, 29, 66, 34 ], + "className" : "Vector" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 67, 5, 67, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 67, 5, 67, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 67, 5, 67, 5 ], + "name" : "v" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 67, 7, 67, 12 ], + "className" : "Vector" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 67, 16, 67, 19 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 68, 5, 68, 24 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 68, 5, 68, 5 ], + "name" : "v" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 68, 9, 68, 24 ], + "function" : { + "kind" : "Identifier", + "location" : [ 68, 9, 68, 22 ], + "name" : "DoublingVector" + }, + "args" : [ ] + } + }, { + "kind" : "WhileStmt", + "location" : [ 70, 5, 74, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 70, 11, 70, 15 ], + "left" : { + "kind" : "Identifier", + "location" : [ 70, 11, 70, 11 ], + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "Identifier", + "location" : [ 70, 15, 70, 15 ], + "name" : "j" + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 71, 9, 71, 19 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 71, 9, 71, 19 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 71, 9, 71, 16 ], + "object" : { + "kind" : "Identifier", + "location" : [ 71, 9, 71, 9 ], + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 71, 11, 71, 16 ], + "name" : "append" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 71, 18, 71, 18 ], + "name" : "i" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 72, 9, 72, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 72, 9, 72, 9 ], + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 72, 13, 72, 17 ], + "left" : { + "kind" : "Identifier", + "location" : [ 72, 13, 72, 13 ], + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 72, 17, 72, 17 ], + "value" : 1 + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 74, 5, 74, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 74, 12, 74, 12 ], + "name" : "v" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 77, 1, 93, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 77, 5, 77, 9 ], + "name" : "sieve" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 77, 11, 77, 18 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 77, 11, 77, 11 ], + "name" : "v" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 77, 13, 77, 18 ], + "className" : "Vector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 77, 24, 77, 29 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 78, 5, 78, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 78, 5, 78, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 78, 5, 78, 5 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 78, 7, 78, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 78, 13, 78, 13 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 79, 5, 79, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 79, 5, 79, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 79, 5, 79, 5 ], + "name" : "j" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 79, 7, 79, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 79, 13, 79, 13 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 80, 5, 80, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 80, 5, 80, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 80, 5, 80, 5 ], + "name" : "k" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 80, 7, 80, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 80, 13, 80, 13 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 82, 5, 93, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 82, 11, 82, 24 ], + "left" : { + "kind" : "Identifier", + "location" : [ 82, 11, 82, 11 ], + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "MethodCallExpr", + "location" : [ 82, 15, 82, 24 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 82, 15, 82, 22 ], + "object" : { + "kind" : "Identifier", + "location" : [ 82, 15, 82, 15 ], + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 82, 17, 82, 22 ], + "name" : "length" + } + }, + "args" : [ ] + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 83, 9, 83, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 83, 9, 83, 9 ], + "name" : "k" + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 83, 13, 83, 20 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 83, 13, 83, 17 ], + "object" : { + "kind" : "Identifier", + "location" : [ 83, 13, 83, 13 ], + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 83, 15, 83, 17 ], + "name" : "get" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 83, 19, 83, 19 ], + "name" : "i" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 84, 9, 84, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 84, 9, 84, 9 ], + "name" : "j" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 84, 13, 84, 17 ], + "left" : { + "kind" : "Identifier", + "location" : [ 84, 13, 84, 13 ], + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 84, 17, 84, 17 ], + "value" : 1 + } + } + }, { + "kind" : "WhileStmt", + "location" : [ 85, 9, 90, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 85, 15, 85, 28 ], + "left" : { + "kind" : "Identifier", + "location" : [ 85, 15, 85, 15 ], + "name" : "j" + }, + "operator" : "<", + "right" : { + "kind" : "MethodCallExpr", + "location" : [ 85, 19, 85, 28 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 85, 19, 85, 26 ], + "object" : { + "kind" : "Identifier", + "location" : [ 85, 19, 85, 19 ], + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 85, 21, 85, 26 ], + "name" : "length" + } + }, + "args" : [ ] + } + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 86, 13, 90, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 86, 16, 86, 32 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 86, 16, 86, 27 ], + "left" : { + "kind" : "MethodCallExpr", + "location" : [ 86, 16, 86, 23 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 86, 16, 86, 20 ], + "object" : { + "kind" : "Identifier", + "location" : [ 86, 16, 86, 16 ], + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 86, 18, 86, 20 ], + "name" : "get" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 86, 22, 86, 22 ], + "name" : "j" + } ] + }, + "operator" : "%", + "right" : { + "kind" : "Identifier", + "location" : [ 86, 27, 86, 27 ], + "name" : "k" + } + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 86, 32, 86, 32 ], + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 87, 17, 87, 30 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 87, 17, 87, 30 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 87, 17, 87, 27 ], + "object" : { + "kind" : "Identifier", + "location" : [ 87, 17, 87, 17 ], + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 87, 19, 87, 27 ], + "name" : "remove_at" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 87, 29, 87, 29 ], + "name" : "j" + } ] + } + } ], + "elseBody" : [ { + "kind" : "AssignStmt", + "location" : [ 89, 17, 89, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 89, 17, 89, 17 ], + "name" : "j" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 89, 21, 89, 25 ], + "left" : { + "kind" : "Identifier", + "location" : [ 89, 21, 89, 21 ], + "name" : "j" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 89, 25, 89, 25 ], + "value" : 1 + } + } + } ] + } ] + }, { + "kind" : "AssignStmt", + "location" : [ 90, 9, 90, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 90, 9, 90, 9 ], + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 90, 13, 90, 17 ], + "left" : { + "kind" : "Identifier", + "location" : [ 90, 13, 90, 13 ], + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 90, 17, 90, 17 ], + "value" : 1 + } + } + } ] + } ] + }, { + "kind" : "VarDef", + "location" : [ 93, 1, 93, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 93, 1, 93, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 93, 1, 93, 1 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 93, 3, 93, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 93, 9, 93, 10 ], + "value" : 50 + } + }, { + "kind" : "VarDef", + "location" : [ 96, 1, 96, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 96, 1, 96, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 96, 1, 96, 1 ], + "name" : "v" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 96, 3, 96, 8 ], + "className" : "Vector" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 96, 12, 96, 15 ] + } + }, { + "kind" : "VarDef", + "location" : [ 97, 1, 97, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 97, 1, 97, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 97, 1, 97, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 97, 3, 97, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 97, 9, 97, 9 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 100, 1, 100, 16 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 100, 1, 100, 1 ], + "name" : "v" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 100, 5, 100, 16 ], + "function" : { + "kind" : "Identifier", + "location" : [ 100, 5, 100, 10 ], + "name" : "vrange" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 100, 12, 100, 12 ], + "value" : 2 + }, { + "kind" : "Identifier", + "location" : [ 100, 15, 100, 15 ], + "name" : "n" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 101, 1, 101, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 101, 1, 101, 8 ], + "function" : { + "kind" : "Identifier", + "location" : [ 101, 1, 101, 5 ], + "name" : "sieve" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 101, 7, 101, 7 ], + "name" : "v" + } ] + } + }, { + "kind" : "WhileStmt", + "location" : [ 104, 1, 108, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 104, 7, 104, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 104, 7, 104, 7 ], + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "MethodCallExpr", + "location" : [ 104, 11, 104, 20 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 104, 11, 104, 18 ], + "object" : { + "kind" : "Identifier", + "location" : [ 104, 11, 104, 11 ], + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 104, 13, 104, 18 ], + "name" : "length" + } + }, + "args" : [ ] + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 105, 5, 105, 19 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 105, 5, 105, 19 ], + "function" : { + "kind" : "Identifier", + "location" : [ 105, 5, 105, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 105, 11, 105, 18 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 105, 11, 105, 15 ], + "object" : { + "kind" : "Identifier", + "location" : [ 105, 11, 105, 11 ], + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 105, 13, 105, 15 ], + "name" : "get" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 105, 17, 105, 17 ], + "name" : "i" + } ] + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 106, 5, 106, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 106, 5, 106, 5 ], + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 106, 9, 106, 13 ], + "left" : { + "kind" : "Identifier", + "location" : [ 106, 9, 106, 9 ], + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 106, 13, 106, 13 ], + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/extra/sieve.py.ast.typed b/pa2-tests/extra/sieve.py.ast.typed new file mode 100644 index 0000000..1c0eb6c --- /dev/null +++ b/pa2-tests/extra/sieve.py.ast.typed @@ -0,0 +1,2816 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 108, 1 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 2, 1, 52, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 12 ], + "name" : "Vector" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 2, 14, 2, 19 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 23 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 9 ], + "name" : "items" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 12, 3, 16 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 13, 3, 15 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 20, 3, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 8 ], + "name" : "size" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 11, 4, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 17, 4, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 6, 5, 7, 25 ], + "name" : { + "kind" : "Identifier", + "location" : [ 6, 9, 6, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 6, 18, 6, 30 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 18, 6, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 23, 6, 30 ], + "className" : "Vector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 6, 32, 6, 32 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 9, 7, 24 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 7, 9, 7, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 7, 14, 7, 18 ], + "name" : "items" + } + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 22, 7, 24 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 7, 23, 7, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 10, 5, 11, 31 ], + "name" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 16 ], + "name" : "capacity" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 10, 18, 10, 30 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 18, 10, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 23, 10, 30 ], + "className" : "Vector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 10, 36, 10, 38 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 11, 9, 11, 30 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 11, 16, 11, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 16, 11, 18 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 11, 20, 11, 29 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 11, 20, 11, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 11, 25, 11, 29 ], + "name" : "items" + } + } ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 14, 5, 16, 31 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 25 ], + "name" : "increase_capacity" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 27, 14, 39 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 27, 14, 30 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 32, 14, 39 ], + "className" : "Vector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 45, 14, 47 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 9, 15, 37 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 15, 9, 15, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 14, 15, 18 ], + "name" : "items" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 15, 22, 15, 37 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 15, 22, 15, 31 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 22, 15, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 27, 15, 31 ], + "name" : "items" + } + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 15, 35, 15, 37 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 15, 36, 15, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } ] + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 16, 9, 16, 30 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 16, 16, 16, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 16, 16, 16, 28 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 16, 21, 16, 28 ], + "name" : "capacity" + } + }, + "args" : [ ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 19, 5, 24, 34 ], + "name" : { + "kind" : "Identifier", + "location" : [ 19, 9, 19, 14 ], + "name" : "append" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 19, 16, 19, 28 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 16, 19, 19 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 21, 19, 28 ], + "className" : "Vector" + } + }, { + "kind" : "TypedVar", + "location" : [ 19, 31, 19, 39 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 31, 19, 34 ], + "name" : "item" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 37, 19, 39 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 19, 45, 19, 50 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 20, 9, 23, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 20, 12, 20, 39 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 20, 12, 20, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 20, 12, 20, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 17, 20, 20 ], + "name" : "size" + } + }, + "operator" : "==", + "right" : { + "kind" : "MethodCallExpr", + "location" : [ 20, 25, 20, 39 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 20, 25, 20, 37 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 20, 25, 20, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 30, 20, 37 ], + "name" : "capacity" + } + }, + "args" : [ ] + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 21, 13, 21, 36 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 21, 13, 21, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 21, 13, 21, 34 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 21, 13, 21, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 21, 18, 21, 34 ], + "name" : "increase_capacity" + } + }, + "args" : [ ] + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 23, 9, 23, 36 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 23, 9, 23, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "MemberExpr", + "location" : [ 23, 9, 23, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 23, 9, 23, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 23, 14, 23, 18 ], + "name" : "items" + } + }, + "index" : { + "kind" : "MemberExpr", + "location" : [ 23, 20, 23, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 23, 20, 23, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 23, 25, 23, 28 ], + "name" : "size" + } + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 23, 33, 23, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "item" + } + }, { + "kind" : "AssignStmt", + "location" : [ 24, 9, 24, 33 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 24, 9, 24, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 24, 9, 24, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 24, 14, 24, 17 ], + "name" : "size" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 24, 21, 24, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 24, 21, 24, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 24, 21, 24, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 24, 26, 24, 29 ], + "name" : "size" + } + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 33, 24, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 27, 5, 33, 4 ], + "name" : { + "kind" : "Identifier", + "location" : [ 27, 9, 27, 18 ], + "name" : "append_all" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 27, 20, 27, 32 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 27, 20, 27, 23 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 27, 25, 27, 32 ], + "className" : "Vector" + } + }, { + "kind" : "TypedVar", + "location" : [ 27, 35, 27, 50 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 27, 35, 27, 43 ], + "name" : "new_items" + }, + "type" : { + "kind" : "ListType", + "location" : [ 27, 46, 27, 50 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 27, 47, 27, 49 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 27, 56, 27, 61 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 28, 9, 28, 20 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 28, 9, 28, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 28, 9, 28, 12 ], + "name" : "item" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 28, 14, 28, 16 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 28, 20, 28, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 29, 9, 33, 4 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 13, 29, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "item" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 29, 21, 29, 29 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "new_items" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 30, 13, 30, 29 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 30, 13, 30, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 30, 13, 30, 23 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 30, 13, 30, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 30, 18, 30, 23 ], + "name" : "append" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 30, 25, 30, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "item" + } ] + } + } ] + } ] + }, { + "kind" : "FuncDef", + "location" : [ 33, 5, 41, 34 ], + "name" : { + "kind" : "Identifier", + "location" : [ 33, 9, 33, 17 ], + "name" : "remove_at" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 33, 19, 33, 31 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 33, 19, 33, 22 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 33, 24, 33, 31 ], + "className" : "Vector" + } + }, { + "kind" : "TypedVar", + "location" : [ 33, 34, 33, 41 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 33, 34, 33, 36 ], + "name" : "idx" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 33, 39, 33, 41 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 33, 47, 33, 52 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 34, 9, 37, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 34, 12, 34, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 34, 12, 34, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "idx" + }, + "operator" : "<", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 34, 18, 34, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 35, 13, 35, 18 ], + "value" : null + } ], + "elseBody" : [ ] + }, { + "kind" : "WhileStmt", + "location" : [ 37, 9, 41, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 37, 15, 37, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 37, 15, 37, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "idx" + }, + "operator" : "<", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 37, 21, 37, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 37, 21, 37, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 37, 21, 37, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 37, 26, 37, 29 ], + "name" : "size" + } + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 37, 33, 37, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 38, 13, 38, 49 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 38, 13, 38, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "MemberExpr", + "location" : [ 38, 13, 38, 22 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 38, 13, 38, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 38, 18, 38, 22 ], + "name" : "items" + } + }, + "index" : { + "kind" : "Identifier", + "location" : [ 38, 24, 38, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "idx" + } + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 38, 31, 38, 49 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "MemberExpr", + "location" : [ 38, 31, 38, 40 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 38, 31, 38, 34 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 38, 36, 38, 40 ], + "name" : "items" + } + }, + "index" : { + "kind" : "BinaryExpr", + "location" : [ 38, 42, 38, 48 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 38, 42, 38, 44 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "idx" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 38, 48, 38, 48 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 39, 13, 39, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 39, 13, 39, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "idx" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 39, 19, 39, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 39, 19, 39, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "idx" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 39, 25, 39, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + }, { + "kind" : "AssignStmt", + "location" : [ 41, 9, 41, 33 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 41, 9, 41, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 41, 9, 41, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 41, 14, 41, 17 ], + "name" : "size" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 41, 21, 41, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 41, 21, 41, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 41, 21, 41, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 41, 26, 41, 29 ], + "name" : "size" + } + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 41, 33, 41, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 44, 5, 45, 31 ], + "name" : { + "kind" : "Identifier", + "location" : [ 44, 9, 44, 11 ], + "name" : "get" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 44, 13, 44, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 44, 13, 44, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 44, 18, 44, 25 ], + "className" : "Vector" + } + }, { + "kind" : "TypedVar", + "location" : [ 44, 28, 44, 35 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 44, 28, 44, 30 ], + "name" : "idx" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 44, 33, 44, 35 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 44, 41, 44, 43 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 45, 9, 45, 30 ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 45, 16, 45, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "MemberExpr", + "location" : [ 45, 16, 45, 25 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 45, 16, 45, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 45, 21, 45, 25 ], + "name" : "items" + } + }, + "index" : { + "kind" : "Identifier", + "location" : [ 45, 27, 45, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "idx" + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 48, 5, 49, 25 ], + "name" : { + "kind" : "Identifier", + "location" : [ 48, 9, 48, 14 ], + "name" : "length" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 48, 16, 48, 28 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 48, 16, 48, 19 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 48, 21, 48, 28 ], + "className" : "Vector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 48, 34, 48, 36 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 49, 9, 49, 24 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 49, 16, 49, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 49, 16, 49, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 49, 21, 49, 24 ], + "name" : "size" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 52, 1, 66, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 52, 7, 52, 20 ], + "name" : "DoublingVector" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 52, 22, 52, 27 ], + "name" : "Vector" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 53, 5, 53, 29 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 53, 5, 53, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 53, 5, 53, 18 ], + "name" : "doubling_limit" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 53, 20, 53, 22 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 53, 26, 53, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1000 + } + }, { + "kind" : "FuncDef", + "location" : [ 56, 5, 63, 31 ], + "name" : { + "kind" : "Identifier", + "location" : [ 56, 9, 56, 25 ], + "name" : "increase_capacity" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 56, 27, 56, 47 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 56, 27, 56, 30 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 56, 32, 56, 47 ], + "className" : "DoublingVector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 56, 53, 56, 55 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 57, 9, 63, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 57, 13, 57, 55 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MethodCallExpr", + "location" : [ 57, 13, 57, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 57, 13, 57, 25 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 57, 13, 57, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 57, 18, 57, 25 ], + "name" : "capacity" + } + }, + "args" : [ ] + }, + "operator" : "<=", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 57, 32, 57, 55 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 57, 32, 57, 50 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 57, 32, 57, 35 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 57, 37, 57, 50 ], + "name" : "doubling_limit" + } + }, + "operator" : "//", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 57, 55, 57, 55 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 58, 13, 58, 48 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 58, 13, 58, 22 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 58, 13, 58, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 58, 18, 58, 22 ], + "name" : "items" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 58, 26, 58, 48 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 58, 26, 58, 35 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 58, 26, 58, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 58, 31, 58, 35 ], + "name" : "items" + } + }, + "operator" : "+", + "right" : { + "kind" : "MemberExpr", + "location" : [ 58, 39, 58, 48 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 58, 39, 58, 42 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 58, 44, 58, 48 ], + "name" : "items" + } + } + } + } ], + "elseBody" : [ { + "kind" : "AssignStmt", + "location" : [ 62, 13, 62, 41 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 62, 13, 62, 22 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 62, 13, 62, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 62, 18, 62, 22 ], + "name" : "items" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 62, 26, 62, 41 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 62, 26, 62, 35 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 62, 26, 62, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 62, 31, 62, 35 ], + "name" : "items" + } + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 62, 39, 62, 41 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 62, 40, 62, 40 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } ] + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 63, 9, 63, 30 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 63, 16, 63, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 63, 16, 63, 28 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 63, 16, 63, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 63, 21, 63, 28 ], + "name" : "capacity" + } + }, + "args" : [ ] + } + } ] + } ] + }, { + "kind" : "FuncDef", + "location" : [ 66, 1, 74, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 66, 5, 66, 10 ], + "name" : "vrange" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 66, 12, 66, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 66, 12, 66, 12 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 66, 14, 66, 16 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 66, 19, 66, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 66, 19, 66, 19 ], + "name" : "j" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 66, 21, 66, 23 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 66, 29, 66, 34 ], + "className" : "Vector" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 67, 5, 67, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 67, 5, 67, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 67, 5, 67, 5 ], + "name" : "v" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 67, 7, 67, 12 ], + "className" : "Vector" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 67, 16, 67, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 68, 5, 68, 24 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 68, 5, 68, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 68, 9, 68, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "DoublingVector" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 68, 9, 68, 22 ], + "name" : "DoublingVector" + }, + "args" : [ ] + } + }, { + "kind" : "WhileStmt", + "location" : [ 70, 5, 74, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 70, 11, 70, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 70, 11, 70, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "Identifier", + "location" : [ 70, 15, 70, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 71, 9, 71, 19 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 71, 9, 71, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 71, 9, 71, 16 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 71, 9, 71, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 71, 11, 71, 16 ], + "name" : "append" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 71, 18, 71, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 72, 9, 72, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 72, 9, 72, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 72, 13, 72, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 72, 13, 72, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 72, 17, 72, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 74, 5, 74, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 74, 12, 74, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 77, 1, 93, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 77, 5, 77, 9 ], + "name" : "sieve" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 77, 11, 77, 18 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 77, 11, 77, 11 ], + "name" : "v" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 77, 13, 77, 18 ], + "className" : "Vector" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 77, 24, 77, 29 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 78, 5, 78, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 78, 5, 78, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 78, 5, 78, 5 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 78, 7, 78, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 78, 13, 78, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 79, 5, 79, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 79, 5, 79, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 79, 5, 79, 5 ], + "name" : "j" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 79, 7, 79, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 79, 13, 79, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 80, 5, 80, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 80, 5, 80, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 80, 5, 80, 5 ], + "name" : "k" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 80, 7, 80, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 80, 13, 80, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 82, 5, 93, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 82, 11, 82, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 82, 11, 82, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "MethodCallExpr", + "location" : [ 82, 15, 82, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 82, 15, 82, 22 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 82, 15, 82, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 82, 17, 82, 22 ], + "name" : "length" + } + }, + "args" : [ ] + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 83, 9, 83, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 83, 9, 83, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "k" + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 83, 13, 83, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 83, 13, 83, 17 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 83, 13, 83, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 83, 15, 83, 17 ], + "name" : "get" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 83, 19, 83, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 84, 9, 84, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 84, 9, 84, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 84, 13, 84, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 84, 13, 84, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 84, 17, 84, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, { + "kind" : "WhileStmt", + "location" : [ 85, 9, 90, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 85, 15, 85, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 85, 15, 85, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + }, + "operator" : "<", + "right" : { + "kind" : "MethodCallExpr", + "location" : [ 85, 19, 85, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 85, 19, 85, 26 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 85, 19, 85, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 85, 21, 85, 26 ], + "name" : "length" + } + }, + "args" : [ ] + } + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 86, 13, 90, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 86, 16, 86, 32 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 86, 16, 86, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "MethodCallExpr", + "location" : [ 86, 16, 86, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 86, 16, 86, 20 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 86, 16, 86, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 86, 18, 86, 20 ], + "name" : "get" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 86, 22, 86, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + } ] + }, + "operator" : "%", + "right" : { + "kind" : "Identifier", + "location" : [ 86, 27, 86, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "k" + } + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 86, 32, 86, 32 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 87, 17, 87, 30 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 87, 17, 87, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 87, 17, 87, 27 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 87, 17, 87, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 87, 19, 87, 27 ], + "name" : "remove_at" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 87, 29, 87, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + } ] + } + } ], + "elseBody" : [ { + "kind" : "AssignStmt", + "location" : [ 89, 17, 89, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 89, 17, 89, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 89, 21, 89, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 89, 21, 89, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "j" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 89, 25, 89, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ] + }, { + "kind" : "AssignStmt", + "location" : [ 90, 9, 90, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 90, 9, 90, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 90, 13, 90, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 90, 13, 90, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 90, 17, 90, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ] + }, { + "kind" : "VarDef", + "location" : [ 93, 1, 93, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 93, 1, 93, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 93, 1, 93, 1 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 93, 3, 93, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 93, 9, 93, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 50 + } + }, { + "kind" : "VarDef", + "location" : [ 96, 1, 96, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 96, 1, 96, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 96, 1, 96, 1 ], + "name" : "v" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 96, 3, 96, 8 ], + "className" : "Vector" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 96, 12, 96, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 97, 1, 97, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 97, 1, 97, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 97, 1, 97, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 97, 3, 97, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 97, 9, 97, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 100, 1, 100, 16 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 100, 1, 100, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 100, 5, 100, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 100, 5, 100, 10 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "Vector" + } + }, + "name" : "vrange" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 100, 12, 100, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "Identifier", + "location" : [ 100, 15, 100, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "n" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 101, 1, 101, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 101, 1, 101, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 101, 1, 101, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "sieve" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 101, 7, 101, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + } ] + } + }, { + "kind" : "WhileStmt", + "location" : [ 104, 1, 108, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 104, 7, 104, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 104, 7, 104, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "MethodCallExpr", + "location" : [ 104, 11, 104, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 104, 11, 104, 18 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 104, 11, 104, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 104, 13, 104, 18 ], + "name" : "length" + } + }, + "args" : [ ] + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 105, 5, 105, 19 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 105, 5, 105, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 105, 5, 105, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 105, 11, 105, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 105, 11, 105, 15 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Vector" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 105, 11, 105, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Vector" + }, + "name" : "v" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 105, 13, 105, 15 ], + "name" : "get" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 105, 17, 105, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ] + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 106, 5, 106, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 106, 5, 106, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 106, 9, 106, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 106, 9, 106, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 106, 13, 106, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/extra/stdlib.py b/pa2-tests/extra/stdlib.py new file mode 100644 index 0000000..e7323bd --- /dev/null +++ b/pa2-tests/extra/stdlib.py @@ -0,0 +1,77 @@ +# ChocoPy library functions +def int_to_str(x: int) -> str: + digits:[str] = None + result:str = "" + + # Set-up digit mapping + digits = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] + + # Write sign if necessary + if x < 0: + result = "-" + x = -x + + # Write digits using a recursive call + if x >= 10: + result = result + int_to_str(x // 10) + result = result + digits[x % 10] + return result + +def str_to_int(x: str) -> int: + result:int = 0 + digit:int = 0 + char:str = "" + sign:int = 1 + first_char:bool = True + + # Parse digits + for char in x: + if char == "-": + if not first_char: + return 0 # Error + sign = -1 + elif char == "0": + digit = 0 + elif char == "1": + digit = 1 + elif char == "2": + digit = 2 + elif char == "3": + digit = 3 + elif char == "3": + digit = 3 + elif char == "4": + digit = 4 + elif char == "5": + digit = 5 + elif char == "6": + digit = 6 + elif char == "7": + digit = 7 + elif char == "8": + digit = 8 + elif char == "9": + digit = 9 + else: + return 0 # On error + first_char = False + result = result * 10 + digit + + # Compute result + return result * sign + +# Input parameters +c:int = 42 +n:int = 10 + +# Run [-nc, nc] with step size c +s:str = "" +i:int = 0 +i = -n * c + +# Crunch +while i <= n * c: + s = int_to_str(i) + print(s) + i = str_to_int(s) + c + diff --git a/pa2-tests/extra/stdlib.py.ast b/pa2-tests/extra/stdlib.py.ast new file mode 100644 index 0000000..f08e906 --- /dev/null +++ b/pa2-tests/extra/stdlib.py.ast @@ -0,0 +1,1168 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 78, 1 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 1, 18, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 14 ], + "name" : "int_to_str" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 16, 2, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 16, 2, 16 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 19, 2, 21 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 27, 2, 29 ], + "className" : "str" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 23 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 10 ], + "name" : "digits" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 12, 3, 16 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 13, 3, 15 ], + "className" : "str" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 20, 3, 23 ] + } + }, { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 10 ], + "name" : "result" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 12, 4, 14 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 4, 18, 4, 19 ], + "value" : "" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 5, 7, 63 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 10 ], + "name" : "digits" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 14, 7, 63 ], + "elements" : [ { + "kind" : "StringLiteral", + "location" : [ 7, 15, 7, 17 ], + "value" : "0" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 20, 7, 22 ], + "value" : "1" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 25, 7, 27 ], + "value" : "2" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 30, 7, 32 ], + "value" : "3" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 35, 7, 37 ], + "value" : "4" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 40, 7, 42 ], + "value" : "5" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 45, 7, 47 ], + "value" : "6" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 50, 7, 52 ], + "value" : "7" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 55, 7, 57 ], + "value" : "8" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 60, 7, 62 ], + "value" : "9" + } ] + } + }, { + "kind" : "IfStmt", + "location" : [ 10, 5, 15, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 10, 8, 10, 12 ], + "left" : { + "kind" : "Identifier", + "location" : [ 10, 8, 10, 8 ], + "name" : "x" + }, + "operator" : "<", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 12, 10, 12 ], + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 11, 9, 11, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 14 ], + "name" : "result" + } ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 11, 18, 11, 20 ], + "value" : "-" + } + }, { + "kind" : "AssignStmt", + "location" : [ 12, 9, 12, 14 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 12, 9, 12, 9 ], + "name" : "x" + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 12, 13, 12, 14 ], + "operator" : "-", + "operand" : { + "kind" : "Identifier", + "location" : [ 12, 14, 12, 14 ], + "name" : "x" + } + } + } ], + "elseBody" : [ ] + }, { + "kind" : "IfStmt", + "location" : [ 15, 5, 17, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 15, 8, 15, 14 ], + "left" : { + "kind" : "Identifier", + "location" : [ 15, 8, 15, 8 ], + "name" : "x" + }, + "operator" : ">=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 15, 13, 15, 14 ], + "value" : 10 + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 16, 9, 16, 45 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 16, 9, 16, 14 ], + "name" : "result" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 16, 18, 16, 45 ], + "left" : { + "kind" : "Identifier", + "location" : [ 16, 18, 16, 23 ], + "name" : "result" + }, + "operator" : "+", + "right" : { + "kind" : "CallExpr", + "location" : [ 16, 27, 16, 45 ], + "function" : { + "kind" : "Identifier", + "location" : [ 16, 27, 16, 36 ], + "name" : "int_to_str" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 16, 38, 16, 44 ], + "left" : { + "kind" : "Identifier", + "location" : [ 16, 38, 16, 38 ], + "name" : "x" + }, + "operator" : "//", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 16, 43, 16, 44 ], + "value" : 10 + } + } ] + } + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 17, 5, 17, 36 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 10 ], + "name" : "result" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 17, 14, 17, 36 ], + "left" : { + "kind" : "Identifier", + "location" : [ 17, 14, 17, 19 ], + "name" : "result" + }, + "operator" : "+", + "right" : { + "kind" : "IndexExpr", + "location" : [ 17, 23, 17, 36 ], + "list" : { + "kind" : "Identifier", + "location" : [ 17, 23, 17, 28 ], + "name" : "digits" + }, + "index" : { + "kind" : "BinaryExpr", + "location" : [ 17, 30, 17, 35 ], + "left" : { + "kind" : "Identifier", + "location" : [ 17, 30, 17, 30 ], + "name" : "x" + }, + "operator" : "%", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 17, 34, 17, 35 ], + "value" : 10 + } + } + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 18, 5, 18, 17 ], + "value" : { + "kind" : "Identifier", + "location" : [ 18, 12, 18, 17 ], + "name" : "result" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 20, 1, 61, 25 ], + "name" : { + "kind" : "Identifier", + "location" : [ 20, 5, 20, 14 ], + "name" : "str_to_int" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 20, 16, 20, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 20, 16, 20, 16 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 20, 19, 20, 21 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 20, 27, 20, 29 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 21, 5, 21, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 21, 5, 21, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 21, 5, 21, 10 ], + "name" : "result" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 21, 12, 21, 14 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 21, 18, 21, 18 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 22, 5, 22, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 22, 5, 22, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 9 ], + "name" : "digit" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 22, 11, 22, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 22, 17, 22, 17 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 23, 5, 23, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 23, 5, 23, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 23, 5, 23, 8 ], + "name" : "char" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 23, 10, 23, 12 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 23, 16, 23, 17 ], + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 24, 5, 24, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 24, 5, 24, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 24, 5, 24, 8 ], + "name" : "sign" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 24, 10, 24, 12 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 16, 24, 16 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 25, 5, 25, 26 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 25, 5, 25, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 25, 5, 25, 14 ], + "name" : "first_char" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 25, 16, 25, 19 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 25, 23, 25, 26 ], + "value" : true + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 28, 5, 61, 4 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 28, 9, 28, 12 ], + "name" : "char" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 28, 17, 28, 17 ], + "name" : "x" + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 29, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 29, 12, 29, 22 ], + "left" : { + "kind" : "Identifier", + "location" : [ 29, 12, 29, 15 ], + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 29, 20, 29, 22 ], + "value" : "-" + } + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 30, 13, 32, 12 ], + "condition" : { + "kind" : "UnaryExpr", + "location" : [ 30, 16, 30, 29 ], + "operator" : "not", + "operand" : { + "kind" : "Identifier", + "location" : [ 30, 20, 30, 29 ], + "name" : "first_char" + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 31, 17, 31, 24 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 31, 24, 31, 24 ], + "value" : 0 + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 32, 13, 32, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 32, 13, 32, 16 ], + "name" : "sign" + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 32, 20, 32, 21 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 32, 21, 32, 21 ], + "value" : 1 + } + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 33, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 33, 14, 33, 24 ], + "left" : { + "kind" : "Identifier", + "location" : [ 33, 14, 33, 17 ], + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 33, 22, 33, 24 ], + "value" : "0" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 34, 13, 34, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 34, 13, 34, 17 ], + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 34, 21, 34, 21 ], + "value" : 0 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 35, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 35, 14, 35, 24 ], + "left" : { + "kind" : "Identifier", + "location" : [ 35, 14, 35, 17 ], + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 35, 22, 35, 24 ], + "value" : "1" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 36, 13, 36, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 36, 13, 36, 17 ], + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 36, 21, 36, 21 ], + "value" : 1 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 37, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 37, 14, 37, 24 ], + "left" : { + "kind" : "Identifier", + "location" : [ 37, 14, 37, 17 ], + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 37, 22, 37, 24 ], + "value" : "2" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 38, 13, 38, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 38, 13, 38, 17 ], + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 38, 21, 38, 21 ], + "value" : 2 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 39, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 39, 14, 39, 24 ], + "left" : { + "kind" : "Identifier", + "location" : [ 39, 14, 39, 17 ], + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 39, 22, 39, 24 ], + "value" : "3" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 40, 13, 40, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 40, 13, 40, 17 ], + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 40, 21, 40, 21 ], + "value" : 3 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 41, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 41, 14, 41, 24 ], + "left" : { + "kind" : "Identifier", + "location" : [ 41, 14, 41, 17 ], + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 41, 22, 41, 24 ], + "value" : "3" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 42, 13, 42, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 42, 13, 42, 17 ], + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 42, 21, 42, 21 ], + "value" : 3 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 43, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 43, 14, 43, 24 ], + "left" : { + "kind" : "Identifier", + "location" : [ 43, 14, 43, 17 ], + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 43, 22, 43, 24 ], + "value" : "4" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 44, 13, 44, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 44, 13, 44, 17 ], + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 44, 21, 44, 21 ], + "value" : 4 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 45, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 45, 14, 45, 24 ], + "left" : { + "kind" : "Identifier", + "location" : [ 45, 14, 45, 17 ], + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 45, 22, 45, 24 ], + "value" : "5" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 46, 13, 46, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 46, 13, 46, 17 ], + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 46, 21, 46, 21 ], + "value" : 5 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 47, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 47, 14, 47, 24 ], + "left" : { + "kind" : "Identifier", + "location" : [ 47, 14, 47, 17 ], + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 47, 22, 47, 24 ], + "value" : "6" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 48, 13, 48, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 48, 13, 48, 17 ], + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 48, 21, 48, 21 ], + "value" : 6 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 49, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 49, 14, 49, 24 ], + "left" : { + "kind" : "Identifier", + "location" : [ 49, 14, 49, 17 ], + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 49, 22, 49, 24 ], + "value" : "7" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 50, 13, 50, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 50, 13, 50, 17 ], + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 50, 21, 50, 21 ], + "value" : 7 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 51, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 51, 14, 51, 24 ], + "left" : { + "kind" : "Identifier", + "location" : [ 51, 14, 51, 17 ], + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 51, 22, 51, 24 ], + "value" : "8" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 52, 13, 52, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 52, 13, 52, 17 ], + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 52, 21, 52, 21 ], + "value" : 8 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 53, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 53, 14, 53, 24 ], + "left" : { + "kind" : "Identifier", + "location" : [ 53, 14, 53, 17 ], + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 53, 22, 53, 24 ], + "value" : "9" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 54, 13, 54, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 54, 13, 54, 17 ], + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 54, 21, 54, 21 ], + "value" : 9 + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 56, 13, 56, 20 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 56, 20, 56, 20 ], + "value" : 0 + } + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + }, { + "kind" : "AssignStmt", + "location" : [ 57, 9, 57, 26 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 57, 9, 57, 18 ], + "name" : "first_char" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 57, 22, 57, 26 ], + "value" : false + } + }, { + "kind" : "AssignStmt", + "location" : [ 58, 9, 58, 36 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 58, 9, 58, 14 ], + "name" : "result" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 58, 18, 58, 36 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 58, 18, 58, 28 ], + "left" : { + "kind" : "Identifier", + "location" : [ 58, 18, 58, 23 ], + "name" : "result" + }, + "operator" : "*", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 58, 27, 58, 28 ], + "value" : 10 + } + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 58, 32, 58, 36 ], + "name" : "digit" + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 61, 5, 61, 24 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 61, 12, 61, 24 ], + "left" : { + "kind" : "Identifier", + "location" : [ 61, 12, 61, 17 ], + "name" : "result" + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 61, 21, 61, 24 ], + "name" : "sign" + } + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 64, 1, 64, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 64, 1, 64, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 64, 1, 64, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 64, 3, 64, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 64, 9, 64, 10 ], + "value" : 42 + } + }, { + "kind" : "VarDef", + "location" : [ 65, 1, 65, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 65, 1, 65, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 65, 1, 65, 1 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 65, 3, 65, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 65, 9, 65, 10 ], + "value" : 10 + } + }, { + "kind" : "VarDef", + "location" : [ 68, 1, 68, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 68, 1, 68, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 68, 1, 68, 1 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 68, 3, 68, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 68, 9, 68, 10 ], + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 69, 1, 69, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 69, 1, 69, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 69, 1, 69, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 69, 3, 69, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 69, 9, 69, 9 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 70, 1, 70, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 70, 1, 70, 1 ], + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 70, 5, 70, 10 ], + "left" : { + "kind" : "UnaryExpr", + "location" : [ 70, 5, 70, 6 ], + "operator" : "-", + "operand" : { + "kind" : "Identifier", + "location" : [ 70, 6, 70, 6 ], + "name" : "n" + } + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 70, 10, 70, 10 ], + "name" : "c" + } + } + }, { + "kind" : "WhileStmt", + "location" : [ 73, 1, 78, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 73, 7, 73, 16 ], + "left" : { + "kind" : "Identifier", + "location" : [ 73, 7, 73, 7 ], + "name" : "i" + }, + "operator" : "<=", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 73, 12, 73, 16 ], + "left" : { + "kind" : "Identifier", + "location" : [ 73, 12, 73, 12 ], + "name" : "n" + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 73, 16, 73, 16 ], + "name" : "c" + } + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 74, 5, 74, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 74, 5, 74, 5 ], + "name" : "s" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 74, 9, 74, 21 ], + "function" : { + "kind" : "Identifier", + "location" : [ 74, 9, 74, 18 ], + "name" : "int_to_str" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 74, 20, 74, 20 ], + "name" : "i" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 75, 5, 75, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 75, 5, 75, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 75, 5, 75, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 75, 11, 75, 11 ], + "name" : "s" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 76, 5, 76, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 76, 5, 76, 5 ], + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 76, 9, 76, 25 ], + "left" : { + "kind" : "CallExpr", + "location" : [ 76, 9, 76, 21 ], + "function" : { + "kind" : "Identifier", + "location" : [ 76, 9, 76, 18 ], + "name" : "str_to_int" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 76, 20, 76, 20 ], + "name" : "s" + } ] + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 76, 25, 76, 25 ], + "name" : "c" + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/extra/stdlib.py.ast.typed b/pa2-tests/extra/stdlib.py.ast.typed new file mode 100644 index 0000000..72079ff --- /dev/null +++ b/pa2-tests/extra/stdlib.py.ast.typed @@ -0,0 +1,1813 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 78, 1 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 1, 18, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 14 ], + "name" : "int_to_str" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 16, 2, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 16, 2, 16 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 19, 2, 21 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 27, 2, 29 ], + "className" : "str" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 23 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 10 ], + "name" : "digits" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 12, 3, 16 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 13, 3, 15 ], + "className" : "str" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 20, 3, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 10 ], + "name" : "result" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 12, 4, 14 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 4, 18, 4, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 5, 7, 63 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 10 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "digits" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 14, 7, 63 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "elements" : [ { + "kind" : "StringLiteral", + "location" : [ 7, 15, 7, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "0" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 20, 7, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "1" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 25, 7, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "2" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 30, 7, 32 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "3" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 35, 7, 37 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "4" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 40, 7, 42 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "5" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 45, 7, 47 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "6" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 50, 7, 52 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "7" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 55, 7, 57 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "8" + }, { + "kind" : "StringLiteral", + "location" : [ 7, 60, 7, 62 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "9" + } ] + } + }, { + "kind" : "IfStmt", + "location" : [ 10, 5, 15, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 10, 8, 10, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 10, 8, 10, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "<", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 12, 10, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 11, 9, 11, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "result" + } ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 11, 18, 11, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "-" + } + }, { + "kind" : "AssignStmt", + "location" : [ 12, 9, 12, 14 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 12, 9, 12, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 12, 13, 12, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "Identifier", + "location" : [ 12, 14, 12, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } + } ], + "elseBody" : [ ] + }, { + "kind" : "IfStmt", + "location" : [ 15, 5, 17, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 15, 8, 15, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 15, 8, 15, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : ">=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 15, 13, 15, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 10 + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 16, 9, 16, 45 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 16, 9, 16, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "result" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 16, 18, 16, 45 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 16, 18, 16, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "result" + }, + "operator" : "+", + "right" : { + "kind" : "CallExpr", + "location" : [ 16, 27, 16, 45 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 27, 16, 36 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "int_to_str" + }, + "args" : [ { + "kind" : "BinaryExpr", + "location" : [ 16, 38, 16, 44 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 16, 38, 16, 38 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "//", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 16, 43, 16, 44 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 10 + } + } ] + } + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 17, 5, 17, 36 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "result" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 17, 14, 17, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 17, 14, 17, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "result" + }, + "operator" : "+", + "right" : { + "kind" : "IndexExpr", + "location" : [ 17, 23, 17, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 17, 23, 17, 28 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "digits" + }, + "index" : { + "kind" : "BinaryExpr", + "location" : [ 17, 30, 17, 35 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 17, 30, 17, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "%", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 17, 34, 17, 35 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 10 + } + } + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 18, 5, 18, 17 ], + "value" : { + "kind" : "Identifier", + "location" : [ 18, 12, 18, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "result" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 20, 1, 61, 25 ], + "name" : { + "kind" : "Identifier", + "location" : [ 20, 5, 20, 14 ], + "name" : "str_to_int" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 20, 16, 20, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 20, 16, 20, 16 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 20, 19, 20, 21 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 20, 27, 20, 29 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 21, 5, 21, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 21, 5, 21, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 21, 5, 21, 10 ], + "name" : "result" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 21, 12, 21, 14 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 21, 18, 21, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 22, 5, 22, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 22, 5, 22, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 9 ], + "name" : "digit" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 22, 11, 22, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 22, 17, 22, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 23, 5, 23, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 23, 5, 23, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 23, 5, 23, 8 ], + "name" : "char" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 23, 10, 23, 12 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 23, 16, 23, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 24, 5, 24, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 24, 5, 24, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 24, 5, 24, 8 ], + "name" : "sign" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 24, 10, 24, 12 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 16, 24, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 25, 5, 25, 26 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 25, 5, 25, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 25, 5, 25, 14 ], + "name" : "first_char" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 25, 16, 25, 19 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 25, 23, 25, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 28, 5, 61, 4 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 28, 9, 28, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 28, 17, 28, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 29, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 29, 12, 29, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 29, 12, 29, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 29, 20, 29, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "-" + } + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 30, 13, 32, 12 ], + "condition" : { + "kind" : "UnaryExpr", + "location" : [ 30, 16, 30, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "operator" : "not", + "operand" : { + "kind" : "Identifier", + "location" : [ 30, 20, 30, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "name" : "first_char" + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 31, 17, 31, 24 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 31, 24, 31, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 32, 13, 32, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 32, 13, 32, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "sign" + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 32, 20, 32, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 32, 21, 32, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 33, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 33, 14, 33, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 33, 14, 33, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 33, 22, 33, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "0" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 34, 13, 34, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 34, 13, 34, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 34, 21, 34, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 35, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 35, 14, 35, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 35, 14, 35, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 35, 22, 35, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "1" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 36, 13, 36, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 36, 13, 36, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 36, 21, 36, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 37, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 37, 14, 37, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 37, 14, 37, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 37, 22, 37, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "2" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 38, 13, 38, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 38, 13, 38, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 38, 21, 38, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 39, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 39, 14, 39, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 39, 14, 39, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 39, 22, 39, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "3" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 40, 13, 40, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 40, 13, 40, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 40, 21, 40, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 41, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 41, 14, 41, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 41, 14, 41, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 41, 22, 41, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "3" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 42, 13, 42, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 42, 13, 42, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 42, 21, 42, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 43, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 43, 14, 43, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 43, 14, 43, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 43, 22, 43, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "4" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 44, 13, 44, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 44, 13, 44, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 44, 21, 44, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 45, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 45, 14, 45, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 45, 14, 45, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 45, 22, 45, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "5" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 46, 13, 46, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 46, 13, 46, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 46, 21, 46, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 5 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 47, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 47, 14, 47, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 47, 14, 47, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 47, 22, 47, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "6" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 48, 13, 48, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 48, 13, 48, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 48, 21, 48, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 6 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 49, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 49, 14, 49, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 49, 14, 49, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 49, 22, 49, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "7" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 50, 13, 50, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 50, 13, 50, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 50, 21, 50, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 7 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 51, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 51, 14, 51, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 51, 14, 51, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 51, 22, 51, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "8" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 52, 13, 52, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 52, 13, 52, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 52, 21, 52, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 8 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 53, 9, 57, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 53, 14, 53, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 53, 14, 53, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "char" + }, + "operator" : "==", + "right" : { + "kind" : "StringLiteral", + "location" : [ 53, 22, 53, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "9" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 54, 13, 54, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 54, 13, 54, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 54, 21, 54, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 9 + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 56, 13, 56, 20 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 56, 20, 56, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + } ] + }, { + "kind" : "AssignStmt", + "location" : [ 57, 9, 57, 26 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 57, 9, 57, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "name" : "first_char" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 57, 22, 57, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + }, { + "kind" : "AssignStmt", + "location" : [ 58, 9, 58, 36 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 58, 9, 58, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "result" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 58, 18, 58, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 58, 18, 58, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 58, 18, 58, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "result" + }, + "operator" : "*", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 58, 27, 58, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 10 + } + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 58, 32, 58, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "digit" + } + } + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 61, 5, 61, 24 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 61, 12, 61, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 61, 12, 61, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "result" + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 61, 21, 61, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "sign" + } + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 64, 1, 64, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 64, 1, 64, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 64, 1, 64, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 64, 3, 64, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 64, 9, 64, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + }, { + "kind" : "VarDef", + "location" : [ 65, 1, 65, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 65, 1, 65, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 65, 1, 65, 1 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 65, 3, 65, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 65, 9, 65, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 10 + } + }, { + "kind" : "VarDef", + "location" : [ 68, 1, 68, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 68, 1, 68, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 68, 1, 68, 1 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 68, 3, 68, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 68, 9, 68, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 69, 1, 69, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 69, 1, 69, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 69, 1, 69, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 69, 3, 69, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 69, 9, 69, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 70, 1, 70, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 70, 1, 70, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 70, 5, 70, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "UnaryExpr", + "location" : [ 70, 5, 70, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "Identifier", + "location" : [ 70, 6, 70, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "n" + } + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 70, 10, 70, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "c" + } + } + }, { + "kind" : "WhileStmt", + "location" : [ 73, 1, 78, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 73, 7, 73, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 73, 7, 73, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<=", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 73, 12, 73, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 73, 12, 73, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "n" + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 73, 16, 73, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "c" + } + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 74, 5, 74, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 74, 5, 74, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 74, 9, 74, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 74, 9, 74, 18 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "name" : "int_to_str" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 74, 20, 74, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 75, 5, 75, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 75, 5, 75, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 75, 5, 75, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 75, 11, 75, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 76, 5, 76, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 76, 5, 76, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 76, 9, 76, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "CallExpr", + "location" : [ 76, 9, 76, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 76, 9, 76, 18 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "str_to_int" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 76, 20, 76, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + } ] + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 76, 25, 76, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "c" + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/extra/tree.py b/pa2-tests/extra/tree.py new file mode 100644 index 0000000..9f337fd --- /dev/null +++ b/pa2-tests/extra/tree.py @@ -0,0 +1,83 @@ +# Binary-search trees +class TreeNode(object): + value:int = 0 + left:"TreeNode" = None + right:"TreeNode" = None + + def insert(self:"TreeNode", x:int) -> bool: + if x < self.value: + if self.left is None: + self.left = makeNode(x) + return True + else: + return self.left.insert(x) + elif x > self.value: + if self.right is None: + self.right = makeNode(x) + return True + else: + return self.right.insert(x) + return False + + def contains(self:"TreeNode", x:int) -> bool: + if x < self.value: + if self.left is None: + return False + else: + return self.left.contains(x) + elif x > self.value: + if self.right is None: + return False + else: + return self.right.contains(x) + else: + return True + +class Tree(object): + root:TreeNode = None + size:int = 0 + + def insert(self:"Tree", x:int) -> object: + if self.root is None: + self.root = makeNode(x) + self.size = 1 + else: + if self.root.insert(x): + self.size = self.size + 1 + + def contains(self:"Tree", x:int) -> bool: + if self.root is None: + return False + else: + return self.root.contains(x) + +def makeNode(x: int) -> TreeNode: + b:TreeNode = None + b = TreeNode() + b.value = x + return b + + +# Input parameters +n:int = 100 +c:int = 4 + +# Data +t:Tree = None +i:int = 0 +k:int = 37813 + +# Crunch +t = Tree() +while i < n: + t.insert(k) + k = (k * 37813) % 37831 + if i % c != 0: + t.insert(i) + i = i + 1 + +print(t.size) + +for i in [4, 8, 15, 16, 23, 42]: + if t.contains(i): + print(i) diff --git a/pa2-tests/extra/tree.py.ast b/pa2-tests/extra/tree.py.ast new file mode 100644 index 0000000..bbee694 --- /dev/null +++ b/pa2-tests/extra/tree.py.ast @@ -0,0 +1,1513 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 84, 2 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 2, 1, 36, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 14 ], + "name" : "TreeNode" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 2, 16, 2, 21 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 2, 3, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 2, 3, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 2, 3, 6 ], + "name" : "value" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 8, 3, 10 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 14, 3, 14 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 4, 2, 4, 23 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 2, 4, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 2, 4, 5 ], + "name" : "left" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 7, 4, 16 ], + "className" : "TreeNode" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 20, 4, 23 ] + } + }, { + "kind" : "VarDef", + "location" : [ 5, 2, 5, 24 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 2, 5, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 2, 5, 6 ], + "name" : "right" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 8, 5, 17 ], + "className" : "TreeNode" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 5, 21, 5, 24 ] + } + }, { + "kind" : "FuncDef", + "location" : [ 7, 2, 20, 15 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 6, 7, 11 ], + "name" : "insert" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 7, 13, 7, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 13, 7, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 18, 7, 27 ], + "className" : "TreeNode" + } + }, { + "kind" : "TypedVar", + "location" : [ 7, 30, 7, 34 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 30, 7, 30 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 32, 7, 34 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 40, 7, 43 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 8, 3, 20, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 8, 6, 8, 19 ], + "left" : { + "kind" : "Identifier", + "location" : [ 8, 6, 8, 6 ], + "name" : "x" + }, + "operator" : "<", + "right" : { + "kind" : "MemberExpr", + "location" : [ 8, 10, 8, 19 ], + "object" : { + "kind" : "Identifier", + "location" : [ 8, 10, 8, 13 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 8, 15, 8, 19 ], + "name" : "value" + } + } + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 9, 4, 14, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 9, 7, 9, 23 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 9, 7, 9, 15 ], + "object" : { + "kind" : "Identifier", + "location" : [ 9, 7, 9, 10 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 15 ], + "name" : "left" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 9, 20, 9, 23 ] + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 10, 5, 10, 27 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 10, 5, 10, 13 ], + "object" : { + "kind" : "Identifier", + "location" : [ 10, 5, 10, 8 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 10, 10, 10, 13 ], + "name" : "left" + } + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 10, 17, 10, 27 ], + "function" : { + "kind" : "Identifier", + "location" : [ 10, 17, 10, 24 ], + "name" : "makeNode" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 10, 26, 10, 26 ], + "name" : "x" + } ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 11, 5, 11, 15 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 11, 12, 11, 15 ], + "value" : true + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 13, 5, 13, 30 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 13, 12, 13, 30 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 13, 12, 13, 27 ], + "object" : { + "kind" : "MemberExpr", + "location" : [ 13, 12, 13, 20 ], + "object" : { + "kind" : "Identifier", + "location" : [ 13, 12, 13, 15 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 13, 17, 13, 20 ], + "name" : "left" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 13, 22, 13, 27 ], + "name" : "insert" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 13, 29, 13, 29 ], + "name" : "x" + } ] + } + } ] + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 14, 3, 20, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 14, 8, 14, 21 ], + "left" : { + "kind" : "Identifier", + "location" : [ 14, 8, 14, 8 ], + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "MemberExpr", + "location" : [ 14, 12, 14, 21 ], + "object" : { + "kind" : "Identifier", + "location" : [ 14, 12, 14, 15 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 14, 17, 14, 21 ], + "name" : "value" + } + } + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 15, 4, 20, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 15, 7, 15, 24 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 15, 7, 15, 16 ], + "object" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 10 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 12, 15, 16 ], + "name" : "right" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 15, 21, 15, 24 ] + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 16, 5, 16, 28 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 16, 5, 16, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 8 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 16, 10, 16, 14 ], + "name" : "right" + } + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 18, 16, 28 ], + "function" : { + "kind" : "Identifier", + "location" : [ 16, 18, 16, 25 ], + "name" : "makeNode" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 16, 27, 16, 27 ], + "name" : "x" + } ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 17, 5, 17, 15 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 17, 12, 17, 15 ], + "value" : true + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 19, 5, 19, 31 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 19, 12, 19, 31 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 19, 12, 19, 28 ], + "object" : { + "kind" : "MemberExpr", + "location" : [ 19, 12, 19, 21 ], + "object" : { + "kind" : "Identifier", + "location" : [ 19, 12, 19, 15 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 19, 17, 19, 21 ], + "name" : "right" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 19, 23, 19, 28 ], + "name" : "insert" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 19, 30, 19, 30 ], + "name" : "x" + } ] + } + } ] + } ], + "elseBody" : [ ] + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 20, 3, 20, 14 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 20, 10, 20, 14 ], + "value" : false + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 22, 2, 36, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 22, 6, 22, 13 ], + "name" : "contains" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 22, 15, 22, 29 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 22, 15, 22, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 22, 20, 22, 29 ], + "className" : "TreeNode" + } + }, { + "kind" : "TypedVar", + "location" : [ 22, 32, 22, 36 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 22, 32, 22, 32 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 22, 34, 22, 36 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 22, 42, 22, 45 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 23, 3, 36, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 23, 6, 23, 19 ], + "left" : { + "kind" : "Identifier", + "location" : [ 23, 6, 23, 6 ], + "name" : "x" + }, + "operator" : "<", + "right" : { + "kind" : "MemberExpr", + "location" : [ 23, 10, 23, 19 ], + "object" : { + "kind" : "Identifier", + "location" : [ 23, 10, 23, 13 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 23, 15, 23, 19 ], + "name" : "value" + } + } + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 24, 4, 28, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 24, 7, 24, 23 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 24, 7, 24, 15 ], + "object" : { + "kind" : "Identifier", + "location" : [ 24, 7, 24, 10 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 24, 12, 24, 15 ], + "name" : "left" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 24, 20, 24, 23 ] + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 25, 5, 25, 16 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 25, 12, 25, 16 ], + "value" : false + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 27, 5, 27, 32 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 27, 12, 27, 32 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 27, 12, 27, 29 ], + "object" : { + "kind" : "MemberExpr", + "location" : [ 27, 12, 27, 20 ], + "object" : { + "kind" : "Identifier", + "location" : [ 27, 12, 27, 15 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 17, 27, 20 ], + "name" : "left" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 22, 27, 29 ], + "name" : "contains" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 27, 31, 27, 31 ], + "name" : "x" + } ] + } + } ] + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 28, 3, 36, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 28, 8, 28, 21 ], + "left" : { + "kind" : "Identifier", + "location" : [ 28, 8, 28, 8 ], + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "MemberExpr", + "location" : [ 28, 12, 28, 21 ], + "object" : { + "kind" : "Identifier", + "location" : [ 28, 12, 28, 15 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 28, 17, 28, 21 ], + "name" : "value" + } + } + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 29, 4, 33, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 29, 7, 29, 24 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 29, 7, 29, 16 ], + "object" : { + "kind" : "Identifier", + "location" : [ 29, 7, 29, 10 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 12, 29, 16 ], + "name" : "right" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 29, 21, 29, 24 ] + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 30, 5, 30, 16 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 30, 12, 30, 16 ], + "value" : false + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 32, 5, 32, 33 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 32, 12, 32, 33 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 32, 12, 32, 30 ], + "object" : { + "kind" : "MemberExpr", + "location" : [ 32, 12, 32, 21 ], + "object" : { + "kind" : "Identifier", + "location" : [ 32, 12, 32, 15 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 32, 17, 32, 21 ], + "name" : "right" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 32, 23, 32, 30 ], + "name" : "contains" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 32, 32, 32, 32 ], + "name" : "x" + } ] + } + } ] + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 34, 4, 34, 14 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 34, 11, 34, 14 ], + "value" : true + } + } ] + } ] + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 36, 1, 54, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 36, 7, 36, 10 ], + "name" : "Tree" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 36, 12, 36, 17 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 37, 2, 37, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 37, 2, 37, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 37, 2, 37, 5 ], + "name" : "root" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 37, 7, 37, 14 ], + "className" : "TreeNode" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 37, 18, 37, 21 ] + } + }, { + "kind" : "VarDef", + "location" : [ 38, 2, 38, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 38, 2, 38, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 38, 2, 38, 5 ], + "name" : "size" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 38, 7, 38, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 38, 13, 38, 13 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 40, 2, 48, 1 ], + "name" : { + "kind" : "Identifier", + "location" : [ 40, 6, 40, 11 ], + "name" : "insert" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 40, 13, 40, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 40, 13, 40, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 40, 18, 40, 23 ], + "className" : "Tree" + } + }, { + "kind" : "TypedVar", + "location" : [ 40, 26, 40, 30 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 40, 26, 40, 26 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 40, 28, 40, 30 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 40, 36, 40, 41 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 41, 3, 48, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 41, 6, 41, 22 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 41, 6, 41, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 41, 6, 41, 9 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 41, 11, 41, 14 ], + "name" : "root" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 41, 19, 41, 22 ] + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 42, 4, 42, 26 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 42, 4, 42, 12 ], + "object" : { + "kind" : "Identifier", + "location" : [ 42, 4, 42, 7 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 42, 9, 42, 12 ], + "name" : "root" + } + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 42, 16, 42, 26 ], + "function" : { + "kind" : "Identifier", + "location" : [ 42, 16, 42, 23 ], + "name" : "makeNode" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 42, 25, 42, 25 ], + "name" : "x" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 43, 4, 43, 16 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 43, 4, 43, 12 ], + "object" : { + "kind" : "Identifier", + "location" : [ 43, 4, 43, 7 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 43, 9, 43, 12 ], + "name" : "size" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 43, 16, 43, 16 ], + "value" : 1 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 45, 4, 48, 1 ], + "condition" : { + "kind" : "MethodCallExpr", + "location" : [ 45, 7, 45, 25 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 45, 7, 45, 22 ], + "object" : { + "kind" : "MemberExpr", + "location" : [ 45, 7, 45, 15 ], + "object" : { + "kind" : "Identifier", + "location" : [ 45, 7, 45, 10 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 45, 12, 45, 15 ], + "name" : "root" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 45, 17, 45, 22 ], + "name" : "insert" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 45, 24, 45, 24 ], + "name" : "x" + } ] + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 46, 5, 46, 29 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 46, 5, 46, 13 ], + "object" : { + "kind" : "Identifier", + "location" : [ 46, 5, 46, 8 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 46, 10, 46, 13 ], + "name" : "size" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 46, 17, 46, 29 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 46, 17, 46, 25 ], + "object" : { + "kind" : "Identifier", + "location" : [ 46, 17, 46, 20 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 46, 22, 46, 25 ], + "name" : "size" + } + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 46, 29, 46, 29 ], + "value" : 1 + } + } + } ], + "elseBody" : [ ] + } ] + } ] + }, { + "kind" : "FuncDef", + "location" : [ 48, 2, 54, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 48, 6, 48, 13 ], + "name" : "contains" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 48, 15, 48, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 48, 15, 48, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 48, 20, 48, 25 ], + "className" : "Tree" + } + }, { + "kind" : "TypedVar", + "location" : [ 48, 28, 48, 32 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 48, 28, 48, 28 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 48, 30, 48, 32 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 48, 38, 48, 41 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 49, 3, 54, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 49, 6, 49, 22 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 49, 6, 49, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 49, 6, 49, 9 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 49, 11, 49, 14 ], + "name" : "root" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 49, 19, 49, 22 ] + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 50, 4, 50, 15 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 50, 11, 50, 15 ], + "value" : false + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 52, 4, 52, 31 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 52, 11, 52, 31 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 52, 11, 52, 28 ], + "object" : { + "kind" : "MemberExpr", + "location" : [ 52, 11, 52, 19 ], + "object" : { + "kind" : "Identifier", + "location" : [ 52, 11, 52, 14 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 52, 16, 52, 19 ], + "name" : "root" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 52, 21, 52, 28 ], + "name" : "contains" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 52, 30, 52, 30 ], + "name" : "x" + } ] + } + } ] + } ] + } ] + }, { + "kind" : "FuncDef", + "location" : [ 54, 1, 58, 10 ], + "name" : { + "kind" : "Identifier", + "location" : [ 54, 5, 54, 12 ], + "name" : "makeNode" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 54, 14, 54, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 54, 14, 54, 14 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 54, 17, 54, 19 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 54, 25, 54, 32 ], + "className" : "TreeNode" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 55, 2, 55, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 55, 2, 55, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 55, 2, 55, 2 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 55, 4, 55, 11 ], + "className" : "TreeNode" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 55, 15, 55, 18 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 56, 2, 56, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 56, 2, 56, 2 ], + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 56, 6, 56, 15 ], + "function" : { + "kind" : "Identifier", + "location" : [ 56, 6, 56, 13 ], + "name" : "TreeNode" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 57, 2, 57, 12 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 57, 2, 57, 8 ], + "object" : { + "kind" : "Identifier", + "location" : [ 57, 2, 57, 2 ], + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 57, 4, 57, 8 ], + "name" : "value" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 57, 12, 57, 12 ], + "name" : "x" + } + }, { + "kind" : "ReturnStmt", + "location" : [ 58, 2, 58, 9 ], + "value" : { + "kind" : "Identifier", + "location" : [ 58, 9, 58, 9 ], + "name" : "b" + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 62, 1, 62, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 62, 1, 62, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 62, 1, 62, 1 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 62, 3, 62, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 62, 9, 62, 11 ], + "value" : 100 + } + }, { + "kind" : "VarDef", + "location" : [ 63, 1, 63, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 63, 1, 63, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 63, 1, 63, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 63, 3, 63, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 63, 9, 63, 9 ], + "value" : 4 + } + }, { + "kind" : "VarDef", + "location" : [ 66, 1, 66, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 66, 1, 66, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 66, 1, 66, 1 ], + "name" : "t" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 66, 3, 66, 6 ], + "className" : "Tree" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 66, 10, 66, 13 ] + } + }, { + "kind" : "VarDef", + "location" : [ 67, 1, 67, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 67, 1, 67, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 67, 1, 67, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 67, 3, 67, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 67, 9, 67, 9 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 68, 1, 68, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 68, 1, 68, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 68, 1, 68, 1 ], + "name" : "k" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 68, 3, 68, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 68, 9, 68, 13 ], + "value" : 37813 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 71, 1, 71, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 71, 1, 71, 1 ], + "name" : "t" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 71, 5, 71, 10 ], + "function" : { + "kind" : "Identifier", + "location" : [ 71, 5, 71, 8 ], + "name" : "Tree" + }, + "args" : [ ] + } + }, { + "kind" : "WhileStmt", + "location" : [ 72, 1, 79, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 72, 7, 72, 11 ], + "left" : { + "kind" : "Identifier", + "location" : [ 72, 7, 72, 7 ], + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "Identifier", + "location" : [ 72, 11, 72, 11 ], + "name" : "n" + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 73, 2, 73, 12 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 73, 2, 73, 12 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 73, 2, 73, 9 ], + "object" : { + "kind" : "Identifier", + "location" : [ 73, 2, 73, 2 ], + "name" : "t" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 73, 4, 73, 9 ], + "name" : "insert" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 73, 11, 73, 11 ], + "name" : "k" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 74, 2, 74, 24 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 74, 2, 74, 2 ], + "name" : "k" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 74, 6, 74, 24 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 74, 7, 74, 15 ], + "left" : { + "kind" : "Identifier", + "location" : [ 74, 7, 74, 7 ], + "name" : "k" + }, + "operator" : "*", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 74, 11, 74, 15 ], + "value" : 37813 + } + }, + "operator" : "%", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 74, 20, 74, 24 ], + "value" : 37831 + } + } + }, { + "kind" : "IfStmt", + "location" : [ 75, 2, 77, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 75, 5, 75, 14 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 75, 5, 75, 9 ], + "left" : { + "kind" : "Identifier", + "location" : [ 75, 5, 75, 5 ], + "name" : "i" + }, + "operator" : "%", + "right" : { + "kind" : "Identifier", + "location" : [ 75, 9, 75, 9 ], + "name" : "c" + } + }, + "operator" : "!=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 75, 14, 75, 14 ], + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 76, 3, 76, 13 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 76, 3, 76, 13 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 76, 3, 76, 10 ], + "object" : { + "kind" : "Identifier", + "location" : [ 76, 3, 76, 3 ], + "name" : "t" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 76, 5, 76, 10 ], + "name" : "insert" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 76, 12, 76, 12 ], + "name" : "i" + } ] + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 77, 2, 77, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 77, 2, 77, 2 ], + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 77, 6, 77, 10 ], + "left" : { + "kind" : "Identifier", + "location" : [ 77, 6, 77, 6 ], + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 77, 10, 77, 10 ], + "value" : 1 + } + } + } ] + }, { + "kind" : "ExprStmt", + "location" : [ 79, 1, 79, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 79, 1, 79, 13 ], + "function" : { + "kind" : "Identifier", + "location" : [ 79, 1, 79, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 79, 7, 79, 12 ], + "object" : { + "kind" : "Identifier", + "location" : [ 79, 7, 79, 7 ], + "name" : "t" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 79, 9, 79, 12 ], + "name" : "size" + } + } ] + } + }, { + "kind" : "ForStmt", + "location" : [ 81, 1, 84, 2 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 81, 5, 81, 5 ], + "name" : "i" + }, + "iterable" : { + "kind" : "ListExpr", + "location" : [ 81, 10, 81, 31 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 81, 11, 81, 11 ], + "value" : 4 + }, { + "kind" : "IntegerLiteral", + "location" : [ 81, 14, 81, 14 ], + "value" : 8 + }, { + "kind" : "IntegerLiteral", + "location" : [ 81, 17, 81, 18 ], + "value" : 15 + }, { + "kind" : "IntegerLiteral", + "location" : [ 81, 21, 81, 22 ], + "value" : 16 + }, { + "kind" : "IntegerLiteral", + "location" : [ 81, 25, 81, 26 ], + "value" : 23 + }, { + "kind" : "IntegerLiteral", + "location" : [ 81, 29, 81, 30 ], + "value" : 42 + } ] + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 82, 2, 84, 1 ], + "condition" : { + "kind" : "MethodCallExpr", + "location" : [ 82, 5, 82, 17 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 82, 5, 82, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 82, 5, 82, 5 ], + "name" : "t" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 82, 7, 82, 14 ], + "name" : "contains" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 82, 16, 82, 16 ], + "name" : "i" + } ] + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 83, 3, 83, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 83, 3, 83, 10 ], + "function" : { + "kind" : "Identifier", + "location" : [ 83, 3, 83, 7 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 83, 9, 83, 9 ], + "name" : "i" + } ] + } + } ], + "elseBody" : [ ] + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/extra/tree.py.ast.typed b/pa2-tests/extra/tree.py.ast.typed new file mode 100644 index 0000000..a8d3cb3 --- /dev/null +++ b/pa2-tests/extra/tree.py.ast.typed @@ -0,0 +1,2301 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 84, 2 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 2, 1, 36, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 14 ], + "name" : "TreeNode" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 2, 16, 2, 21 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 2, 3, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 2, 3, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 2, 3, 6 ], + "name" : "value" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 8, 3, 10 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 14, 3, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 4, 2, 4, 23 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 2, 4, 16 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 2, 4, 5 ], + "name" : "left" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 7, 4, 16 ], + "className" : "TreeNode" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 20, 4, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 5, 2, 5, 24 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 2, 5, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 2, 5, 6 ], + "name" : "right" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 8, 5, 17 ], + "className" : "TreeNode" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 5, 21, 5, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "FuncDef", + "location" : [ 7, 2, 20, 15 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 6, 7, 11 ], + "name" : "insert" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 7, 13, 7, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 13, 7, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 18, 7, 27 ], + "className" : "TreeNode" + } + }, { + "kind" : "TypedVar", + "location" : [ 7, 30, 7, 34 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 30, 7, 30 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 32, 7, 34 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 40, 7, 43 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 8, 3, 20, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 8, 6, 8, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 8, 6, 8, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "<", + "right" : { + "kind" : "MemberExpr", + "location" : [ 8, 10, 8, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 8, 10, 8, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 8, 15, 8, 19 ], + "name" : "value" + } + } + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 9, 4, 14, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 9, 7, 9, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 9, 7, 9, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 9, 7, 9, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 15 ], + "name" : "left" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 9, 20, 9, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 10, 5, 10, 27 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 10, 5, 10, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 10, 5, 10, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 10, 10, 10, 13 ], + "name" : "left" + } + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 10, 17, 10, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 17, 10, 24 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + } + }, + "name" : "makeNode" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 10, 26, 10, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 11, 5, 11, 15 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 11, 12, 11, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 13, 5, 13, 30 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 13, 12, 13, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 13, 12, 13, 27 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "object" : { + "kind" : "MemberExpr", + "location" : [ 13, 12, 13, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 13, 12, 13, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 13, 17, 13, 20 ], + "name" : "left" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 13, 22, 13, 27 ], + "name" : "insert" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 13, 29, 13, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ] + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 14, 3, 20, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 14, 8, 14, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 14, 8, 14, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "MemberExpr", + "location" : [ 14, 12, 14, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 14, 12, 14, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 14, 17, 14, 21 ], + "name" : "value" + } + } + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 15, 4, 20, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 15, 7, 15, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 15, 7, 15, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 12, 15, 16 ], + "name" : "right" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 15, 21, 15, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 16, 5, 16, 28 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 16, 5, 16, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 16, 10, 16, 14 ], + "name" : "right" + } + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 18, 16, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 18, 16, 25 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + } + }, + "name" : "makeNode" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 16, 27, 16, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 17, 5, 17, 15 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 17, 12, 17, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 19, 5, 19, 31 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 19, 12, 19, 31 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 19, 12, 19, 28 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "object" : { + "kind" : "MemberExpr", + "location" : [ 19, 12, 19, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 19, 12, 19, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 19, 17, 19, 21 ], + "name" : "right" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 19, 23, 19, 28 ], + "name" : "insert" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 19, 30, 19, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ] + } ], + "elseBody" : [ ] + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 20, 3, 20, 14 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 20, 10, 20, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 22, 2, 36, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 22, 6, 22, 13 ], + "name" : "contains" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 22, 15, 22, 29 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 22, 15, 22, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 22, 20, 22, 29 ], + "className" : "TreeNode" + } + }, { + "kind" : "TypedVar", + "location" : [ 22, 32, 22, 36 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 22, 32, 22, 32 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 22, 34, 22, 36 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 22, 42, 22, 45 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 23, 3, 36, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 23, 6, 23, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 23, 6, 23, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "<", + "right" : { + "kind" : "MemberExpr", + "location" : [ 23, 10, 23, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 23, 10, 23, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 23, 15, 23, 19 ], + "name" : "value" + } + } + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 24, 4, 28, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 24, 7, 24, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 24, 7, 24, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 24, 7, 24, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 24, 12, 24, 15 ], + "name" : "left" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 24, 20, 24, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 25, 5, 25, 16 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 25, 12, 25, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 27, 5, 27, 32 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 27, 12, 27, 32 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 27, 12, 27, 29 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "object" : { + "kind" : "MemberExpr", + "location" : [ 27, 12, 27, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 27, 12, 27, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 17, 27, 20 ], + "name" : "left" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 22, 27, 29 ], + "name" : "contains" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 27, 31, 27, 31 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ] + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 28, 3, 36, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 28, 8, 28, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 28, 8, 28, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "MemberExpr", + "location" : [ 28, 12, 28, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 28, 12, 28, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 28, 17, 28, 21 ], + "name" : "value" + } + } + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 29, 4, 33, 2 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 29, 7, 29, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 29, 7, 29, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 29, 7, 29, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 12, 29, 16 ], + "name" : "right" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 29, 21, 29, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 30, 5, 30, 16 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 30, 12, 30, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 32, 5, 32, 33 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 32, 12, 32, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 32, 12, 32, 30 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "object" : { + "kind" : "MemberExpr", + "location" : [ 32, 12, 32, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 32, 12, 32, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 32, 17, 32, 21 ], + "name" : "right" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 32, 23, 32, 30 ], + "name" : "contains" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 32, 32, 32, 32 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ] + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 34, 4, 34, 14 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 34, 11, 34, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + } ] + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 36, 1, 54, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 36, 7, 36, 10 ], + "name" : "Tree" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 36, 12, 36, 17 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 37, 2, 37, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 37, 2, 37, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 37, 2, 37, 5 ], + "name" : "root" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 37, 7, 37, 14 ], + "className" : "TreeNode" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 37, 18, 37, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 38, 2, 38, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 38, 2, 38, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 38, 2, 38, 5 ], + "name" : "size" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 38, 7, 38, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 38, 13, 38, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 40, 2, 48, 1 ], + "name" : { + "kind" : "Identifier", + "location" : [ 40, 6, 40, 11 ], + "name" : "insert" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 40, 13, 40, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 40, 13, 40, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 40, 18, 40, 23 ], + "className" : "Tree" + } + }, { + "kind" : "TypedVar", + "location" : [ 40, 26, 40, 30 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 40, 26, 40, 26 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 40, 28, 40, 30 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 40, 36, 40, 41 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 41, 3, 48, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 41, 6, 41, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 41, 6, 41, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 41, 6, 41, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 41, 11, 41, 14 ], + "name" : "root" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 41, 19, 41, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 42, 4, 42, 26 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 42, 4, 42, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 42, 4, 42, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 42, 9, 42, 12 ], + "name" : "root" + } + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 42, 16, 42, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 42, 16, 42, 23 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + } + }, + "name" : "makeNode" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 42, 25, 42, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 43, 4, 43, 16 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 43, 4, 43, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 43, 4, 43, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 43, 9, 43, 12 ], + "name" : "size" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 43, 16, 43, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 45, 4, 48, 1 ], + "condition" : { + "kind" : "MethodCallExpr", + "location" : [ 45, 7, 45, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 45, 7, 45, 22 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "object" : { + "kind" : "MemberExpr", + "location" : [ 45, 7, 45, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 45, 7, 45, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 45, 12, 45, 15 ], + "name" : "root" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 45, 17, 45, 22 ], + "name" : "insert" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 45, 24, 45, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 46, 5, 46, 29 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 46, 5, 46, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 46, 5, 46, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 46, 10, 46, 13 ], + "name" : "size" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 46, 17, 46, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 46, 17, 46, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 46, 17, 46, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 46, 22, 46, 25 ], + "name" : "size" + } + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 46, 29, 46, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ], + "elseBody" : [ ] + } ] + } ] + }, { + "kind" : "FuncDef", + "location" : [ 48, 2, 54, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 48, 6, 48, 13 ], + "name" : "contains" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 48, 15, 48, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 48, 15, 48, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 48, 20, 48, 25 ], + "className" : "Tree" + } + }, { + "kind" : "TypedVar", + "location" : [ 48, 28, 48, 32 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 48, 28, 48, 28 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 48, 30, 48, 32 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 48, 38, 48, 41 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 49, 3, 54, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 49, 6, 49, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 49, 6, 49, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 49, 6, 49, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 49, 11, 49, 14 ], + "name" : "root" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 49, 19, 49, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 50, 4, 50, 15 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 50, 11, 50, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ], + "elseBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 52, 4, 52, 31 ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 52, 11, 52, 31 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 52, 11, 52, 28 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "object" : { + "kind" : "MemberExpr", + "location" : [ 52, 11, 52, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 52, 11, 52, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 52, 16, 52, 19 ], + "name" : "root" + } + }, + "member" : { + "kind" : "Identifier", + "location" : [ 52, 21, 52, 28 ], + "name" : "contains" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 52, 30, 52, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ] + } ] + } ] + }, { + "kind" : "FuncDef", + "location" : [ 54, 1, 58, 10 ], + "name" : { + "kind" : "Identifier", + "location" : [ 54, 5, 54, 12 ], + "name" : "makeNode" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 54, 14, 54, 19 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 54, 14, 54, 14 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 54, 17, 54, 19 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 54, 25, 54, 32 ], + "className" : "TreeNode" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 55, 2, 55, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 55, 2, 55, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 55, 2, 55, 2 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 55, 4, 55, 11 ], + "className" : "TreeNode" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 55, 15, 55, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 56, 2, 56, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 56, 2, 56, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 56, 6, 56, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 56, 6, 56, 13 ], + "name" : "TreeNode" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 57, 2, 57, 12 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 57, 2, 57, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 57, 2, 57, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 57, 4, 57, 8 ], + "name" : "value" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 57, 12, 57, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + }, { + "kind" : "ReturnStmt", + "location" : [ 58, 2, 58, 9 ], + "value" : { + "kind" : "Identifier", + "location" : [ 58, 9, 58, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "TreeNode" + }, + "name" : "b" + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 62, 1, 62, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 62, 1, 62, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 62, 1, 62, 1 ], + "name" : "n" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 62, 3, 62, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 62, 9, 62, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 100 + } + }, { + "kind" : "VarDef", + "location" : [ 63, 1, 63, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 63, 1, 63, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 63, 1, 63, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 63, 3, 63, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 63, 9, 63, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + }, { + "kind" : "VarDef", + "location" : [ 66, 1, 66, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 66, 1, 66, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 66, 1, 66, 1 ], + "name" : "t" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 66, 3, 66, 6 ], + "className" : "Tree" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 66, 10, 66, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 67, 1, 67, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 67, 1, 67, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 67, 1, 67, 1 ], + "name" : "i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 67, 3, 67, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 67, 9, 67, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 68, 1, 68, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 68, 1, 68, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 68, 1, 68, 1 ], + "name" : "k" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 68, 3, 68, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 68, 9, 68, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 37813 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 71, 1, 71, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 71, 1, 71, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "t" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 71, 5, 71, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 71, 5, 71, 8 ], + "name" : "Tree" + }, + "args" : [ ] + } + }, { + "kind" : "WhileStmt", + "location" : [ 72, 1, 79, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 72, 7, 72, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 72, 7, 72, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "<", + "right" : { + "kind" : "Identifier", + "location" : [ 72, 11, 72, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "n" + } + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 73, 2, 73, 12 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 73, 2, 73, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 73, 2, 73, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Tree" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 73, 2, 73, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "t" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 73, 4, 73, 9 ], + "name" : "insert" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 73, 11, 73, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "k" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 74, 2, 74, 24 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 74, 2, 74, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "k" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 74, 6, 74, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 74, 7, 74, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 74, 7, 74, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "k" + }, + "operator" : "*", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 74, 11, 74, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 37813 + } + }, + "operator" : "%", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 74, 20, 74, 24 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 37831 + } + } + }, { + "kind" : "IfStmt", + "location" : [ 75, 2, 77, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 75, 5, 75, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 75, 5, 75, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 75, 5, 75, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "%", + "right" : { + "kind" : "Identifier", + "location" : [ 75, 9, 75, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "c" + } + }, + "operator" : "!=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 75, 14, 75, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 76, 3, 76, 13 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 76, 3, 76, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 76, 3, 76, 10 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Tree" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 76, 3, 76, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "t" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 76, 5, 76, 10 ], + "name" : "insert" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 76, 12, 76, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ] + } + } ], + "elseBody" : [ ] + }, { + "kind" : "AssignStmt", + "location" : [ 77, 2, 77, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 77, 2, 77, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 77, 6, 77, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 77, 6, 77, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 77, 10, 77, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + }, { + "kind" : "ExprStmt", + "location" : [ 79, 1, 79, 13 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 79, 1, 79, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 79, 1, 79, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 79, 7, 79, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 79, 7, 79, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "t" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 79, 9, 79, 12 ], + "name" : "size" + } + } ] + } + }, { + "kind" : "ForStmt", + "location" : [ 81, 1, 84, 2 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 81, 5, 81, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + }, + "iterable" : { + "kind" : "ListExpr", + "location" : [ 81, 10, 81, 31 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 81, 11, 81, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + }, { + "kind" : "IntegerLiteral", + "location" : [ 81, 14, 81, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 8 + }, { + "kind" : "IntegerLiteral", + "location" : [ 81, 17, 81, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 15 + }, { + "kind" : "IntegerLiteral", + "location" : [ 81, 21, 81, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 16 + }, { + "kind" : "IntegerLiteral", + "location" : [ 81, 25, 81, 26 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 23 + }, { + "kind" : "IntegerLiteral", + "location" : [ 81, 29, 81, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } ] + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 82, 2, 84, 1 ], + "condition" : { + "kind" : "MethodCallExpr", + "location" : [ 82, 5, 82, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 82, 5, 82, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "Tree" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 82, 5, 82, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "Tree" + }, + "name" : "t" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 82, 7, 82, 14 ], + "name" : "contains" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 82, 16, 82, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ] + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 83, 3, 83, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 83, 3, 83, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 83, 3, 83, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 83, 9, 83, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "i" + } ] + } + } ], + "elseBody" : [ ] + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/pa2-tests/run-tests.sh b/pa2-tests/run-tests.sh new file mode 100755 index 0000000..9dac916 --- /dev/null +++ b/pa2-tests/run-tests.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +JAVA="java -cp pa2-tests/chocopy-ref.jar:target/assignment.jar chocopy.ChocoPy" + +echo "# CORE TESTS" +${JAVA} --pass=.s --test --dir pa2-tests/core + +echo +echo "# EXTRA TESTS" +${JAVA} --pass=.s --test --dir pa2-tests/extra + +echo +echo "# STUDENT TESTS" +function regen_and_test { + ${JAVA} --pass=r "${1}" --out "${1}.ast" 2>/dev/null 1>&2 + ${JAVA} --pass=.r "${1}.ast" --out "${1}.ast.typed" 2>/dev/null 1>&2 + ${JAVA} --pass=.s --test "${1}.ast" +} +regen_and_test "src/test/data/pa2/student_contributed/bad_semantic.py" +regen_and_test "src/test/data/pa2/student_contributed/bad_types.py" +regen_and_test "src/test/data/pa2/student_contributed/good.py" diff --git a/src/main/cup/chocopy/pa1/ChocoPy.cup b/src/main/cup/chocopy/pa1/ChocoPy.cup new file mode 100644 index 0000000..44d7cfe --- /dev/null +++ b/src/main/cup/chocopy/pa1/ChocoPy.cup @@ -0,0 +1,516 @@ +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import java_cup.runtime.*; +import chocopy.common.astnodes.*; + +/* The following code section is copied verbatim to the generated + * parser class. */ +parser code {: + + /* The following fields and methods deal with error reporting + * Avoid changing these unless you know what you are doing. */ + + /** Node that accumulates error messages to be added to the Program + * node produced as a result. */ + public final Errors errors = new Errors(new ArrayList<>()); + + /** Return the Program node that results from parsing the stream of + * tokens produced by lexical analysis. In the case of syntax errors, + * the program may be empty, but will have error messages. */ + public Program parseProgram(boolean debug) { + try { + Symbol result = debug ? debug_parse() : parse(); + if (result == null || !(result.value instanceof Program)) { + return new Program(new Location(0, 0), new Location(0, 0), + new ArrayList(), + new ArrayList(), + errors); + } else { + return (Program) result.value; + } + } catch (RuntimeException excp) { + throw excp; + } catch (Exception excp) { + String msg = + String.format("Internal parser error detected: %s%n", excp); + throw new AssertionError(msg); + } + } + + @Override + public SymbolFactory getSymbolFactory() { + return ((ChocoPyLexer) getScanner()).symbolFactory; + } + + @Override + public void syntax_error(Symbol cur_token) { + String token = symbl_name_from_id(cur_token.sym); + String text = ((ChocoPyLexer) getScanner()).yytext(); + errors.syntaxError( + ((ComplexSymbolFactory.ComplexSymbol) cur_token).xleft, + ((ComplexSymbolFactory.ComplexSymbol) cur_token).xright, + "Parse error near token %s: %s", token, text); + } + + @Override + public void unrecovered_syntax_error(Symbol cur_token) { + /* Do not die */ + } +:} + + +/************************************************************************** + * FEEL FREE TO MODIFY ANYTHING BELOW THIS LINE + * + * The rules provided below parse expressions of the form + + ... + * You can re-use these rules or edit them as you wish. The start rule + * should return a node of type Program. + * + * Tips: Production rules are usually followed by action code that will be + * copied to the generated parser to be executed immediately after a reduce + * operation; that is, when a production rule has been matched. You can name + * a nonterminal or terminal symbol in a production rule using the colon + * notation, e.g. expr_stmt ::= expr:e, to get the AST node for the matched + * expression. In the action code, `e` will be a variable of whatever type + * has been declared for the corresponding nonterminal, such as `Expr`. + * Therefore, you can construct an AST Node of type `ExprStmt` with `e` in the + * constructor: `new ExprStmt(exleft, exright, e)` + * + * The variables `exleft` and `exright` are automatically generated by CUP + * and contain Location objects for the start and end of the expression `e`. + * You can collect start and line number info for AST nodes by taking the + * location of the left end of the leftmost symbol in a rule and the + * location of the right end of the rightmost symbol. The auto-generated + * variables have names `xleft` and `xright`, where is the + * name given to the symbol using the colon notation. + * + * When you have nonterminals that are lists of things, e.g. List or + * List, it is helpful to get the leftmost and rightmost + * source location from within this list; we have provided some utility + * functions below to do just that. + **************************************************************************/ + + +/* The following code section is copied verbatim to the class that performs + * production-rule actions. */ +action code {: + + /** Return a mutable list initially containing the single value ITEM. */ + List single(T item) { + List list = new ArrayList<>(); + if (item != null) { + list.add(item); + } + return list; + } + + /** If ITEM is non-null, appends it to the end of LIST. Then returns + * LIST. */ + List combine(List list, T item) { + if (item != null) { + list.add(item); + } + return list; + } + List combine(List list, List item) { + if (item != null) { + Iterator it = item.iterator(); + while(it.hasNext()) + list.add(it.next()); + } + return list; + } + /** Return a mutable empty list. */ + List empty() { + return new ArrayList(); + } + class FuncBody { + public List fbd; + public List sl; + public FuncBody(List fbd, List sl){ + this.fbd = fbd; + this.sl = sl; + } + } + /** Return the leftmost non-whitespace location in NODES, or null if NODES + * is empty. Assumes that the nodes of NODES are ordered in increasing + * order of location, from left to right. */ + ComplexSymbolFactory.Location getLeft(List nodes) { + if (nodes.isEmpty()) { + return null; + } + Node first = nodes.get(0); + return new ComplexSymbolFactory.Location(first.getLocation()[0], + first.getLocation()[1]); + } + + /** Return the rightmost non-whitespace location in NODES, or null if NODES + * is empty. Assumes that the nodes of NODES are ordered in increasing + * order of location, from left to right. */ + ComplexSymbolFactory.Location getRight(List nodes) { + if (nodes.isEmpty()) { + return null; + } + Node last = nodes.get(nodes.size()-1); + return new ComplexSymbolFactory.Location(last.getLocation()[2], + last.getLocation()[3]); + } + +:} + +/* Terminal symbols (tokens returned by the lexer). The declaration + * terminal , , ...; + * declares each as the denotation of a distinct type terminal + * symbol for use in the grammar. The declaration + * terminal , ...; + * does the same, and in addition indicates that the lexer supplies a + * semantic value of type for these symbols that may be referenced + * in actions ( {: ... :} ). + */ +terminal INDENT; +terminal DEDENT; +terminal String ID; +terminal String STRING; + + + +/* Terminal Delimiters */ +terminal NEWLINE; +terminal String COLON; +terminal String COMMA; + +/* Terminal Literals */ +terminal Integer NUMBER; +terminal Boolean BOOL; +terminal String NONE; + +/* Terminal Keywords */ +terminal String IF; +terminal String ELSE; +terminal String ELIF; +terminal String WHILE; +terminal String CLASS; +terminal String DEF; +terminal String LAMBDA; +terminal String AS; +terminal String FOR; +terminal String GLOBAL; +terminal String IN; +terminal String NONLOCAL; +terminal String PASS; +terminal String RETURN; +terminal String ASSERT; +terminal String AWAIT; +terminal String BREAK; +terminal String CONTINUE; +terminal String DEL; +terminal String EXCEPT; +terminal String FINALLY; +terminal String FROM; +terminal String IMPORT; +terminal String RAISE; +terminal String TRY; +terminal String WITH; +terminal String YIELD; + + +/* Terminal Operators */ +terminal String PLUS; +terminal String MINUS; +terminal String MUL; +terminal String DIV; +terminal String MOD; +terminal String GT; +terminal String LT; +terminal String EQUAL; +terminal String NEQ; +terminal String GEQ; +terminal String LEQ; +terminal String ASSIGN; +terminal String AND; +terminal String OR; +terminal String NOT; +terminal String DOT; +terminal String LPAR; +terminal String RPAR; +terminal String LBR; +terminal String RBR; +terminal String ARROW; +terminal String IS; +terminal String UMINUS; + + +/* Returned by the lexer for erroneous tokens. Since it does not appear in + * the grammar, it indicates a syntax error. */ +terminal String UNRECOGNIZED; + +/* Nonterminal symbols (defined in production rules below). + * As for terminal symbols, + * non terminal , ..., ; + * defines the listed nonterminal identifier symbols to have semantic values + * of type . */ +non terminal Program program; +non terminal List defs, program_head, opt_program_head, class_body, class_body_defs, fun_body_decs; +non terminal List stmt_list, opt_stmt_list, block, else_body; +non terminal Stmt stmt, simple_stmt; +non terminal Expr expr, pexpr, cexpr; +non terminal VarDef var_def; +non terminal ClassDef class_def; +non terminal FuncDef fun_def; +non terminal Literal literal; +non terminal StringLiteral bin_op, comp_op; +non terminal TypedVar typed_var; +non terminal TypeAnnotation type, ret_type; +non terminal Identifier identifier; +non terminal List typed_vars; +non terminal GlobalDecl global_decl; +non terminal NonLocalDecl nonlocal_decl; +non terminal List opt_target, expr_list; +non terminal Expr target; +non terminal MemberExpr member_expr; +non terminal IndexExpr index_expr; +non terminal FuncBody fun_body; + + + +/* Precedences (lowest to highest) for resolving what would otherwise be + * ambiguities in the form of shift/reduce conflicts.. */ +precedence left OR; +precedence left AND; +precedence left NOT; +precedence nonassoc EQUAL, NEQ, LT, GT, LEQ, GEQ, IS; +precedence left PLUS, MINUS; +precedence left MUL, DIV, MOD; +precedence left UMINUS; +precedence left DOT, COMMA, LBR, RBR; +precedence right IF, ELSE; + +/* The start symbol. */ +start with program; + + +/***** GRAMMAR RULES *****/ + +/* Rules are defined in the order given by the language reference */ + +/* program */ +program ::= program_head:d opt_stmt_list:s + {: + ComplexSymbolFactory.Location left = d.isEmpty() ? getLeft(s) : getLeft(d); + if(left == null) + left = new ComplexSymbolFactory.Location(1,1); + RESULT = new Program(left, sxright, d, s, errors); + :} + ; + +program_head ::= program_head:d var_def:vd {: RESULT = combine(d, vd); :} + | program_head:d class_def:cd {: RESULT = combine(d, cd); :} + | program_head:d fun_def:fd {: RESULT = combine(d, fd); :} + | program_head:d error:e {: RESULT = d; :} + | {: RESULT = empty(); :} + ; + +opt_stmt_list ::= {: RESULT = empty(); :} + | stmt_list:s {: RESULT = s; :} + ; + + +/* class_def */ +class_def ::= CLASS:c identifier:id LPAR identifier:parentId RPAR COLON NEWLINE INDENT class_body:cb DEDENT {: RESULT = new ClassDef(cxleft, getRight(cb), id, parentId, cb); :}; + + +/* class_body */ +class_body ::= PASS NEWLINE {: RESULT = empty(); :} + | class_body_defs:defs {: RESULT = defs; :} + ; + +class_body_defs ::= class_body_defs:defs var_def:vd {: RESULT = combine(defs, vd); :} + | class_body_defs:defs fun_def:fd {: RESULT = combine(defs, fd); :} + | class_body_defs:defs error {: RESULT = defs; :} + | var_def:vd {: RESULT = single(vd); :} + | fun_def:fd {: RESULT = single(fd); :} + ; + + +/* fun_def */ +fun_def ::= DEF:def identifier:id LPAR typed_vars:params RPAR ret_type:rt COLON:col NEWLINE INDENT fun_body_decs:fbd stmt_list:sl DEDENT + {: TypeAnnotation _rt = rt;if((rt instanceof ClassType) && ((ClassType)rt).className == "") _rt = new ClassType( colxright, colxright, "");RESULT = new FuncDef(defxleft, getRight(sl), id, params, _rt, fbd, sl); :} + ; + +ret_type ::= ARROW type:t {: RESULT= t; :} + | {: RESULT= new ClassType(null, null,""); :} + ; + +typed_vars ::= typed_var:tv {: RESULT= single(tv); :} + | typed_vars:tvs COMMA typed_var:tv {: RESULT= combine(tvs, tv); :} + | typed_vars:tvs COMMA error {: RESULT= tvs; :} + | {: RESULT= empty(); :} + ; + + +/* fun_body */ +fun_body ::= fun_body_decs:fbd stmt_list:sl {: RESULT = new FuncBody(fbd, sl);:} + | fun_body_decs:fbd {: RESULT = new FuncBody(fbd, new ArrayList());:} + ; + +fun_body_decs ::= fun_body_decs:fbd global_decl:gd {: RESULT= combine(fbd, gd); :} + | fun_body_decs:fbd nonlocal_decl:nd {: RESULT= combine(fbd, nd); :} + | fun_body_decs:fbd var_def:vd {: RESULT= combine(fbd, vd); :} + | fun_body_decs:fbd fun_def:fd {: RESULT= combine(fbd, fd); :} + | fun_body_decs:fbd error {: RESULT= fbd; :} + | {: RESULT= empty(); :} + ; + + +/* typed_var */ +typed_var ::= identifier:id COLON type:t {: RESULT = new TypedVar(idxleft, txright, id, t); :}; + + +/* type */ +type ::= identifier:id {: RESULT = new ClassType(idxleft, idxright, id.name); :} + | STRING:str {: RESULT = new ClassType(strxleft, strxright, str); :} + | LBR:lbr type:t RBR:rbr {: RESULT = new ListType(lbrxleft, rbrxright, t); :} + ; + + +/* global_decl */ +global_decl ::= GLOBAL:g identifier:id NEWLINE {: RESULT = new GlobalDecl(gxleft, idxright, id); :}; + + +/* nonlocal_decl */ +nonlocal_decl ::= NONLOCAL:n identifier:id NEWLINE {: RESULT = new NonLocalDecl(nxleft, idxright, id); :}; + + +/* var_def */ +var_def ::= typed_var:t ASSIGN literal:l NEWLINE {: RESULT = new VarDef(txleft, lxright, t, l); :}; + + +/* stmt */ +stmt ::= simple_stmt:s NEWLINE {: RESULT = s; :} + | IF:i expr:cond COLON block:b else_body:elb {: RESULT = new IfStmt(ixleft, getRight(elb), cond, b, elb); :} + | WHILE:wh expr:cond COLON block:b {: RESULT = new WhileStmt(whxleft, getRight(b), cond, b); :} + | FOR:f identifier:id IN expr:e COLON block:b {: RESULT = new ForStmt(fxleft, getRight(b), id, e, b); :} + ; + + +else_body ::= ELSE:el COLON block:b {: RESULT = b; :} + | ELIF:el expr:cond COLON block:b else_body:elb {: RESULT = single(new IfStmt(elxleft, getRight(elb), cond, b, elb)); :} + | {: RESULT = empty(); :} + ; + + +/* simple_stmt */ +simple_stmt ::= PASS:p {: RESULT = null; :} + | expr:e {: RESULT = new ExprStmt(exleft, exright, e); :} + | RETURN:r expr:e {: RESULT = new ReturnStmt(rxleft, exright, e); :} + | RETURN:r {: RESULT = new ReturnStmt(rxleft, rxright, null); :} + | opt_target:ot expr:e {: RESULT = new AssignStmt(getLeft(ot), exright, ot, e); :} + ; + + +opt_target ::= opt_target:ot target:t ASSIGN {: RESULT = combine(ot, t); :} + | target:t ASSIGN {: RESULT = single(t); :} + ; + + +/* block */ +block ::= NEWLINE INDENT stmt_list:sl DEDENT {: RESULT = sl; :}; + + +/* literal */ +literal ::= NONE:n {: RESULT = new NoneLiteral(nxleft, nxright); :} + | BOOL:b {: RESULT = new BooleanLiteral(bxleft, bxright, b); :} + | NUMBER:n {: RESULT = new IntegerLiteral(nxleft, nxright, n); :} + | STRING:s {: RESULT = new StringLiteral(sxleft, sxright, s); :} + ; + + +/* expr */ +expr ::= cexpr:ce {: RESULT = ce; :} + | NOT:n expr:exp {: RESULT = new UnaryExpr(nxleft, expxright, n, exp); :} + | expr:e1 AND:a expr:e2 {: RESULT = new BinaryExpr(e1xleft, e2xright, e1, a, e2); :} + | expr:e1 OR:o expr:e2 {: RESULT = new BinaryExpr(e1xleft, e2xright, e1, o, e2); :} + | expr:e1 IF expr:e2 ELSE expr:e3 {: RESULT = new IfExpr(e1xleft, e3xright, e2, e1, e3); :} + ; + + +/* cexpr */ +cexpr ::= pexpr:pe {: RESULT = pe; :} + | pexpr:p1 comp_op:co cexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, co.value, p2); :} + ; + + +/* pexpr */ +pexpr ::= identifier:id {: RESULT = id; :} + | literal:l {: RESULT = l; :} + | LBR:lbr expr_list:l RBR:rbr {: RESULT = new ListExpr(lbrxleft, rbrxright, l); :} + | LPAR:lpar expr:e RPAR:rpar {: RESULT = e; :} + | member_expr:m {: RESULT = m; :} + | index_expr:i {: RESULT = i; :} + | member_expr:m LPAR expr_list:l RPAR:rpar {: RESULT = new MethodCallExpr(mxleft, rparxright, m, l); :} + | identifier:id LPAR expr_list:l RPAR:rpar {: RESULT = new CallExpr(idxleft, rparxright, id, l); :} + | pexpr:p1 PLUS:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo, p2); :} + | pexpr:p1 MINUS:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo, p2); :} + | pexpr:p1 MUL:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo, p2); :} + | pexpr:p1 DIV:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo, p2); :} + | pexpr:p1 MOD:bo pexpr:p2 {: RESULT = new BinaryExpr(p1xleft, p2xright, p1, bo, p2); :} + | MINUS:m pexpr:p {: RESULT = new UnaryExpr(mxleft, pxright, m, p); :} %prec UMINUS + ; + +expr_list ::= expr:e {: RESULT = single(e); :} + | expr_list:el COMMA expr:e {: RESULT = combine(el, e); :} + | {: RESULT = new ArrayList(); :} + ; + +/* bin_op */ //We may still be able to use bin_op, so I left it here. +bin_op ::= PLUS:a {: RESULT = new StringLiteral(axleft, axright, "+"); :} + | MINUS:a {: RESULT = new StringLiteral(axleft, axright, "-"); :} + | MUL:a {: RESULT = new StringLiteral(axleft, axright, "*"); :} + | DIV:a {: RESULT = new StringLiteral(axleft, axright, "//"); :} //Section 2.6.3 in chocopy language reference + | MOD:a {: RESULT = new StringLiteral(axleft, axright, "%"); :} + ; + + +/* comp_op */ //this might also need some change in order not to break left associativity +comp_op ::= EQUAL:a {: RESULT = new StringLiteral(axleft, axright, "=="); :} + | NEQ:a {: RESULT = new StringLiteral(axleft, axright, "!="); :} + | LEQ:a {: RESULT = new StringLiteral(axleft, axright, "<="); :} + | GEQ:a {: RESULT = new StringLiteral(axleft, axright, ">="); :} + | LT:a {: RESULT = new StringLiteral(axleft, axright, "<"); :} + | GT:a {: RESULT = new StringLiteral(axleft, axright, ">"); :} + | IS:a {: RESULT = new StringLiteral(axleft, axright, "is"); :} + ; + + +/* member_expr */ +member_expr ::= pexpr:p DOT identifier:id {: RESULT = new MemberExpr(pxleft, idxright, p, id); :} + ; + + +/* index_expr */ +index_expr ::= pexpr:p LBR expr:e RBR:rbr {: RESULT = new IndexExpr(pxleft, rbrxright, p, e); :} + ; + + +/* target */ +target ::= identifier:id {: RESULT = id; :} + | member_expr:m {: RESULT = m; :} + | index_expr:i {: RESULT = i; :} + ; + + +/* Extras - rules below have not been given in language reference, we have them to ease implementation */ +identifier ::= ID:idStr {: RESULT = new Identifier(idStrxleft, idStrxright, idStr); :}; + + +stmt_list ::= stmt:s {: RESULT = single(s); :} + | stmt_list:l stmt:s {: RESULT = combine(l, s); :} + | stmt_list:l error {: RESULT = l; :} + /* If there is a syntax error in the source, this says to discard + * symbols from the parsing stack and perform reductions until + * there is a stmt_list on top of the stack, and then to discard + * input symbols until it is possible to shift again, reporting + * a syntax error. */ + ; \ No newline at end of file diff --git a/src/main/java/chocopy/common/Utils.java b/src/main/java/chocopy/common/Utils.java index 41360cc..f23a109 100644 --- a/src/main/java/chocopy/common/Utils.java +++ b/src/main/java/chocopy/common/Utils.java @@ -5,7 +5,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.util.stream.Collectors; - /** Utility functions for general use. */ public class Utils { diff --git a/src/main/java/chocopy/common/analysis/types/ClassVType.java b/src/main/java/chocopy/common/analysis/types/ClassVType.java new file mode 100644 index 0000000..af04de7 --- /dev/null +++ b/src/main/java/chocopy/common/analysis/types/ClassVType.java @@ -0,0 +1,56 @@ +package chocopy.common.analysis.types; + +import chocopy.common.astnodes.ClassType; +import chocopy.common.astnodes.Identifier; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import chocopy.common.analysis.SymbolTable; +import java.util.Objects; + +/** Represents the semantic value of a simple class reference. */ +public class ClassVType extends ValueType { + + /** The name of the class. */ + public final String className; + public SymbolTable scope; + public ClassVType super_class; + /** A class type for the class named CLASSNAME. */ + @JsonCreator + public ClassVType(@JsonProperty String className) { + this.className = className; + } + + /** A class type for the class referenced by CLASSTYPEANNOTATION. */ + public ClassVType(ClassType classTypeAnnotation) { + this.className = classTypeAnnotation.className; + } + + @Override + @JsonProperty + public String className() { + return className; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ClassVType classType = (ClassVType) o; + return Objects.equals(className, classType.className); + } + + @Override + public int hashCode() { + return Objects.hash(className); + } + + @Override + public String toString() { + return className; + } +} diff --git a/src/main/java/chocopy/common/analysis/types/FuncValueType.java b/src/main/java/chocopy/common/analysis/types/FuncValueType.java new file mode 100644 index 0000000..5e73b46 --- /dev/null +++ b/src/main/java/chocopy/common/analysis/types/FuncValueType.java @@ -0,0 +1,49 @@ +package chocopy.common.analysis.types; + +import com.fasterxml.jackson.annotation.JsonCreator; + +import java.util.ArrayList; +import java.util.List; + +/** Semantic information for a function or method. */ +public class FuncValueType extends Type { + + /** Function's name. */ + //public final String name; + + /** Types of parameters. */ + public List parameters; + /** Function's return type. */ + public final ValueType returnType; + + + /** Create a FuncType returning RETURNTYPE0, initially parameterless. */ + public FuncValueType(ValueType returnType0) { + this(new ArrayList<>(), returnType0); + } + + /** + * Create a FuncType for NAME0 with formal parameter types PARAMETERS0, returning type + * RETURNTYPE0. + */ + @JsonCreator + public FuncValueType(List parameters0, ValueType returnType0) { + this.parameters = parameters0; + this.returnType = returnType0; + } + + @Override + public boolean isFuncType() { + return true; + } + + /** Return the type of the K-th parameter. */ + public ValueType getParamType(int k) { + return parameters.get(k); + } + + @Override + public String toString() { + return ""; + } +} diff --git a/src/main/java/chocopy/common/astnodes/BooleanLiteral.java b/src/main/java/chocopy/common/astnodes/BooleanLiteral.java index ffce126..2d41a64 100644 --- a/src/main/java/chocopy/common/astnodes/BooleanLiteral.java +++ b/src/main/java/chocopy/common/astnodes/BooleanLiteral.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** Literals True or False. */ public final class BooleanLiteral extends Literal { diff --git a/src/main/java/chocopy/common/astnodes/CallExpr.java b/src/main/java/chocopy/common/astnodes/CallExpr.java index 84f13ae..74f7ab1 100644 --- a/src/main/java/chocopy/common/astnodes/CallExpr.java +++ b/src/main/java/chocopy/common/astnodes/CallExpr.java @@ -5,6 +5,7 @@ import java_cup.runtime.ComplexSymbolFactory.Location; import java.util.List; + /** A function call. */ public class CallExpr extends Expr { diff --git a/src/main/java/chocopy/common/astnodes/ClassDef.java b/src/main/java/chocopy/common/astnodes/ClassDef.java index 63531c8..02f43cc 100644 --- a/src/main/java/chocopy/common/astnodes/ClassDef.java +++ b/src/main/java/chocopy/common/astnodes/ClassDef.java @@ -5,6 +5,7 @@ import java_cup.runtime.ComplexSymbolFactory.Location; import java.util.List; + /** A class definition. */ public class ClassDef extends Declaration { diff --git a/src/main/java/chocopy/common/astnodes/ClassType.java b/src/main/java/chocopy/common/astnodes/ClassType.java index fd4cd4d..57117cb 100644 --- a/src/main/java/chocopy/common/astnodes/ClassType.java +++ b/src/main/java/chocopy/common/astnodes/ClassType.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** A simple class type name. */ public final class ClassType extends TypeAnnotation { diff --git a/src/main/java/chocopy/common/astnodes/CompilerError.java b/src/main/java/chocopy/common/astnodes/CompilerError.java index 81cc5bb..b33cf3f 100644 --- a/src/main/java/chocopy/common/astnodes/CompilerError.java +++ b/src/main/java/chocopy/common/astnodes/CompilerError.java @@ -7,6 +7,7 @@ import java_cup.runtime.ComplexSymbolFactory.Location; import java.util.Arrays; import java.util.Objects; + /** Represents a single error. Does not correspond to any Python source construct. */ public class CompilerError extends Node { diff --git a/src/main/java/chocopy/common/astnodes/Declaration.java b/src/main/java/chocopy/common/astnodes/Declaration.java index 0faa921..db660f7 100644 --- a/src/main/java/chocopy/common/astnodes/Declaration.java +++ b/src/main/java/chocopy/common/astnodes/Declaration.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import com.fasterxml.jackson.annotation.JsonIgnore; import java_cup.runtime.ComplexSymbolFactory.Location; + /** Base of all AST nodes representing definitions or declarations. */ public abstract class Declaration extends Node { @@ -11,6 +12,7 @@ public abstract class Declaration extends Node { super(left, right); } + /** Return the identifier defined by this Declaration. */ @JsonIgnore public abstract Identifier getIdentifier(); diff --git a/src/main/java/chocopy/common/astnodes/Errors.java b/src/main/java/chocopy/common/astnodes/Errors.java index 86240dd..ef03a8a 100644 --- a/src/main/java/chocopy/common/astnodes/Errors.java +++ b/src/main/java/chocopy/common/astnodes/Errors.java @@ -7,6 +7,7 @@ import java_cup.runtime.ComplexSymbolFactory.Location; import java.util.List; + /** Collects the error messages in a Program. There is exactly one per Program node. */ public class Errors extends Node { @@ -26,11 +27,13 @@ public class Errors extends Node { allowMultipleErrors = true; } + /** Return true iff there are any errors. */ public boolean hasErrors() { return !this.errors.isEmpty(); } + /** Prevent multiple semantic errors on the same node. */ public void suppressMultipleErrors() { allowMultipleErrors = false; diff --git a/src/main/java/chocopy/common/astnodes/Expr.java b/src/main/java/chocopy/common/astnodes/Expr.java index 7372d58..81270b7 100644 --- a/src/main/java/chocopy/common/astnodes/Expr.java +++ b/src/main/java/chocopy/common/astnodes/Expr.java @@ -1,5 +1,6 @@ package chocopy.common.astnodes; + import chocopy.common.analysis.types.Type; import com.fasterxml.jackson.annotation.JsonInclude; import java_cup.runtime.ComplexSymbolFactory.Location; diff --git a/src/main/java/chocopy/common/astnodes/ExprStmt.java b/src/main/java/chocopy/common/astnodes/ExprStmt.java index 5b921a0..3533db3 100644 --- a/src/main/java/chocopy/common/astnodes/ExprStmt.java +++ b/src/main/java/chocopy/common/astnodes/ExprStmt.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** Statements consisting of expressions. */ public final class ExprStmt extends Stmt { diff --git a/src/main/java/chocopy/common/astnodes/ForStmt.java b/src/main/java/chocopy/common/astnodes/ForStmt.java index 019b2d8..f7c9e46 100644 --- a/src/main/java/chocopy/common/astnodes/ForStmt.java +++ b/src/main/java/chocopy/common/astnodes/ForStmt.java @@ -5,6 +5,7 @@ import java_cup.runtime.ComplexSymbolFactory.Location; import java.util.List; + /** For statements. */ public class ForStmt extends Stmt { /** Control variable. */ diff --git a/src/main/java/chocopy/common/astnodes/FuncDef.java b/src/main/java/chocopy/common/astnodes/FuncDef.java index b3ca0f2..4800bd1 100644 --- a/src/main/java/chocopy/common/astnodes/FuncDef.java +++ b/src/main/java/chocopy/common/astnodes/FuncDef.java @@ -5,6 +5,7 @@ import java_cup.runtime.ComplexSymbolFactory.Location; import java.util.List; + /** Def statements. */ public class FuncDef extends Declaration { diff --git a/src/main/java/chocopy/common/astnodes/GlobalDecl.java b/src/main/java/chocopy/common/astnodes/GlobalDecl.java index b347d4d..f281347 100644 --- a/src/main/java/chocopy/common/astnodes/GlobalDecl.java +++ b/src/main/java/chocopy/common/astnodes/GlobalDecl.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** Declaration of global variable. */ public class GlobalDecl extends Declaration { diff --git a/src/main/java/chocopy/common/astnodes/Identifier.java b/src/main/java/chocopy/common/astnodes/Identifier.java index 7593126..f65ab06 100644 --- a/src/main/java/chocopy/common/astnodes/Identifier.java +++ b/src/main/java/chocopy/common/astnodes/Identifier.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** A simple identifier. */ public class Identifier extends Expr { diff --git a/src/main/java/chocopy/common/astnodes/IfExpr.java b/src/main/java/chocopy/common/astnodes/IfExpr.java index 3d3d809..b76cbcb 100644 --- a/src/main/java/chocopy/common/astnodes/IfExpr.java +++ b/src/main/java/chocopy/common/astnodes/IfExpr.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** Conditional expressions. */ public class IfExpr extends Expr { /** Boolean condition. */ diff --git a/src/main/java/chocopy/common/astnodes/IfStmt.java b/src/main/java/chocopy/common/astnodes/IfStmt.java index 185b8a1..d2b0bf4 100644 --- a/src/main/java/chocopy/common/astnodes/IfStmt.java +++ b/src/main/java/chocopy/common/astnodes/IfStmt.java @@ -5,6 +5,7 @@ import java_cup.runtime.ComplexSymbolFactory.Location; import java.util.List; + /** Conditional statement. */ public class IfStmt extends Stmt { /** Test condition. */ diff --git a/src/main/java/chocopy/common/astnodes/IndexExpr.java b/src/main/java/chocopy/common/astnodes/IndexExpr.java index ce788fa..28951c8 100644 --- a/src/main/java/chocopy/common/astnodes/IndexExpr.java +++ b/src/main/java/chocopy/common/astnodes/IndexExpr.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** List-indexing expression. */ public class IndexExpr extends Expr { diff --git a/src/main/java/chocopy/common/astnodes/IntegerLiteral.java b/src/main/java/chocopy/common/astnodes/IntegerLiteral.java index f2d165b..38f3df6 100644 --- a/src/main/java/chocopy/common/astnodes/IntegerLiteral.java +++ b/src/main/java/chocopy/common/astnodes/IntegerLiteral.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** Integer numerals. */ public final class IntegerLiteral extends Literal { diff --git a/src/main/java/chocopy/common/astnodes/ListExpr.java b/src/main/java/chocopy/common/astnodes/ListExpr.java index eab6045..1b76d44 100644 --- a/src/main/java/chocopy/common/astnodes/ListExpr.java +++ b/src/main/java/chocopy/common/astnodes/ListExpr.java @@ -5,6 +5,7 @@ import java_cup.runtime.ComplexSymbolFactory.Location; import java.util.List; + /** List displays. */ public final class ListExpr extends Expr { diff --git a/src/main/java/chocopy/common/astnodes/ListType.java b/src/main/java/chocopy/common/astnodes/ListType.java index 32782ad..d0715e7 100644 --- a/src/main/java/chocopy/common/astnodes/ListType.java +++ b/src/main/java/chocopy/common/astnodes/ListType.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** Type denotation for a list type. */ public final class ListType extends TypeAnnotation { diff --git a/src/main/java/chocopy/common/astnodes/MemberExpr.java b/src/main/java/chocopy/common/astnodes/MemberExpr.java index a9e0a4f..3889f20 100644 --- a/src/main/java/chocopy/common/astnodes/MemberExpr.java +++ b/src/main/java/chocopy/common/astnodes/MemberExpr.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** Attribute accessor. */ public class MemberExpr extends Expr { diff --git a/src/main/java/chocopy/common/astnodes/MethodCallExpr.java b/src/main/java/chocopy/common/astnodes/MethodCallExpr.java index ab3f424..64ddf61 100644 --- a/src/main/java/chocopy/common/astnodes/MethodCallExpr.java +++ b/src/main/java/chocopy/common/astnodes/MethodCallExpr.java @@ -5,6 +5,7 @@ import java_cup.runtime.ComplexSymbolFactory.Location; import java.util.List; + /** Method calls. */ public class MethodCallExpr extends Expr { diff --git a/src/main/java/chocopy/common/astnodes/Node.java b/src/main/java/chocopy/common/astnodes/Node.java index c95f3d6..a1403f7 100644 --- a/src/main/java/chocopy/common/astnodes/Node.java +++ b/src/main/java/chocopy/common/astnodes/Node.java @@ -78,6 +78,7 @@ public abstract class Node { @JsonInclude(JsonInclude.Include.NON_EMPTY) private String errorMsg; + /** A Node corresponding to source text between LEFT and RIGHT. */ public Node(Location left, Location right) { if (left != null) { @@ -100,6 +101,7 @@ public abstract class Node { return location; } + /** Copy LOCATION as getLocation(). */ public void setLocation(final int[] location) { System.arraycopy(location, 0, this.location, 0, 4); @@ -113,6 +115,7 @@ public abstract class Node { this.errorMsg = msg; } + /** Return true iff I have been marked with an error message. */ @JsonIgnore public boolean hasError() { @@ -135,11 +138,13 @@ public abstract class Node { } } + /** Return a serialization of this node in JSON format. */ public String toJSON() throws JsonProcessingException { return mapper.writeValueAsString(this); } + /** Mapper to-and-from serialized JSON. */ private static final ObjectMapper mapper = new ObjectMapper(); @@ -148,6 +153,7 @@ public abstract class Node { mapper.registerModule(new ParameterNamesModule()); } + /** Returns a T from JSON, a JSON-serialized T value with class CLAS. */ public static T fromJSON(String json, Class clas) throws IOException { return mapper.readValue(json, clas); diff --git a/src/main/java/chocopy/common/astnodes/NonLocalDecl.java b/src/main/java/chocopy/common/astnodes/NonLocalDecl.java index ebaf78d..5086deb 100644 --- a/src/main/java/chocopy/common/astnodes/NonLocalDecl.java +++ b/src/main/java/chocopy/common/astnodes/NonLocalDecl.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** Nonlocal declaration. */ public class NonLocalDecl extends Declaration { diff --git a/src/main/java/chocopy/common/astnodes/NoneLiteral.java b/src/main/java/chocopy/common/astnodes/NoneLiteral.java index b51a581..dc3a7a5 100644 --- a/src/main/java/chocopy/common/astnodes/NoneLiteral.java +++ b/src/main/java/chocopy/common/astnodes/NoneLiteral.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** The expression 'None'. */ public final class NoneLiteral extends Literal { diff --git a/src/main/java/chocopy/common/astnodes/Program.java b/src/main/java/chocopy/common/astnodes/Program.java index f2d7f75..75c44d8 100644 --- a/src/main/java/chocopy/common/astnodes/Program.java +++ b/src/main/java/chocopy/common/astnodes/Program.java @@ -7,7 +7,7 @@ import java_cup.runtime.ComplexSymbolFactory.Location; import java.util.ArrayList; import java.util.List; -/** An entire ChocoPy program. */ + public class Program extends Node { /** Initial variable, class, and function declarations. */ @@ -42,12 +42,14 @@ public class Program extends Node { return analyzer.analyze(this); } + /** Returns true iff there is at least one error in the program. */ @JsonIgnore public boolean hasErrors() { return errors.hasErrors(); } + /** A convenience method returning the list of all CompilerErrors for this program. */ @JsonIgnore public List getErrorList() { diff --git a/src/main/java/chocopy/common/astnodes/ReturnStmt.java b/src/main/java/chocopy/common/astnodes/ReturnStmt.java index e665042..8303dae 100644 --- a/src/main/java/chocopy/common/astnodes/ReturnStmt.java +++ b/src/main/java/chocopy/common/astnodes/ReturnStmt.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** Return from function. */ public class ReturnStmt extends Stmt { diff --git a/src/main/java/chocopy/common/astnodes/StringLiteral.java b/src/main/java/chocopy/common/astnodes/StringLiteral.java index 0eaf928..d8a5b31 100644 --- a/src/main/java/chocopy/common/astnodes/StringLiteral.java +++ b/src/main/java/chocopy/common/astnodes/StringLiteral.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** String constants. */ public final class StringLiteral extends Literal { diff --git a/src/main/java/chocopy/common/astnodes/TypeAnnotation.java b/src/main/java/chocopy/common/astnodes/TypeAnnotation.java index d90b59e..fec8c40 100644 --- a/src/main/java/chocopy/common/astnodes/TypeAnnotation.java +++ b/src/main/java/chocopy/common/astnodes/TypeAnnotation.java @@ -2,6 +2,7 @@ package chocopy.common.astnodes; import java_cup.runtime.ComplexSymbolFactory.Location; + /** Base of all AST nodes representing type annotations (list or class types. */ public abstract class TypeAnnotation extends Node { /** An annotation spanning source locations [LEFT..RIGHT]. */ diff --git a/src/main/java/chocopy/common/astnodes/TypedVar.java b/src/main/java/chocopy/common/astnodes/TypedVar.java index 98aae43..4f712e7 100644 --- a/src/main/java/chocopy/common/astnodes/TypedVar.java +++ b/src/main/java/chocopy/common/astnodes/TypedVar.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** An identifier with attached type annotation. */ public class TypedVar extends Node { diff --git a/src/main/java/chocopy/common/astnodes/UnaryExpr.java b/src/main/java/chocopy/common/astnodes/UnaryExpr.java index 199e701..af1ff3b 100644 --- a/src/main/java/chocopy/common/astnodes/UnaryExpr.java +++ b/src/main/java/chocopy/common/astnodes/UnaryExpr.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** An expression applying a unary operator. */ public class UnaryExpr extends Expr { diff --git a/src/main/java/chocopy/common/astnodes/VarDef.java b/src/main/java/chocopy/common/astnodes/VarDef.java index 61d261a..02380b0 100644 --- a/src/main/java/chocopy/common/astnodes/VarDef.java +++ b/src/main/java/chocopy/common/astnodes/VarDef.java @@ -3,6 +3,7 @@ package chocopy.common.astnodes; import chocopy.common.analysis.NodeAnalyzer; import java_cup.runtime.ComplexSymbolFactory.Location; + /** A declaration of a variable (i.e., with type annotation). */ public class VarDef extends Declaration { /** The variable and its assigned type. */ diff --git a/src/main/java/chocopy/common/astnodes/WhileStmt.java b/src/main/java/chocopy/common/astnodes/WhileStmt.java index 9a521e1..49c50b6 100644 --- a/src/main/java/chocopy/common/astnodes/WhileStmt.java +++ b/src/main/java/chocopy/common/astnodes/WhileStmt.java @@ -5,6 +5,7 @@ import java_cup.runtime.ComplexSymbolFactory.Location; import java.util.List; + /** Indefinite repetition construct. */ public class WhileStmt extends Stmt { /** Test for whether to continue. */ @@ -19,6 +20,7 @@ public class WhileStmt extends Stmt { this.body = body; } + public T dispatch(NodeAnalyzer analyzer) { return analyzer.analyze(this); } diff --git a/src/main/java/chocopy/pa1/StudentParser.java b/src/main/java/chocopy/pa1/StudentParser.java new file mode 100644 index 0000000..c29db68 --- /dev/null +++ b/src/main/java/chocopy/pa1/StudentParser.java @@ -0,0 +1,25 @@ +package chocopy.pa1; + +import chocopy.common.astnodes.Program; +import java_cup.runtime.ComplexSymbolFactory; + +import java.io.StringReader; + +/** + * Interface between driver and parser. + */ +public class StudentParser { + + /** + * Return the Program AST resulting from parsing INPUT. Turn on + * parser debugging iff DEBUG. + */ + public static Program process(String input, boolean debug) { + ChocoPyLexer lexer = new ChocoPyLexer(new StringReader(input)); + ChocoPyParser parser = + new ChocoPyParser(lexer, new ComplexSymbolFactory()); + return parser.parseProgram(debug); + } +} + + diff --git a/src/main/java/chocopy/pa2/DeclarationAnalyzer.java b/src/main/java/chocopy/pa2/DeclarationAnalyzer.java new file mode 100644 index 0000000..5ce7cd0 --- /dev/null +++ b/src/main/java/chocopy/pa2/DeclarationAnalyzer.java @@ -0,0 +1,377 @@ +package chocopy.pa2; + +import chocopy.common.analysis.AbstractNodeAnalyzer; +import chocopy.common.analysis.SymbolTable; +import chocopy.common.analysis.types.*; +import chocopy.common.astnodes.*; + +import java.util.*; + +/** Analyzes declarations to create a top-level symbol table. */ +public class DeclarationAnalyzer extends AbstractNodeAnalyzer +{ + + /** Current symbol table. Changes with new declarative region. */ + private SymbolTable sym = new SymbolTable<>(); + /** Global symbol table. */ + private final SymbolTable globals; + /** Receiver for semantic error messages. */ + + private final TypeChecker typeChecker; + private final Errors errors; + private final boolean firstPass; + // In the first pass declanalyzer will create the global symtable + // In the second pass, typeAnalyzer will call declanalyzer to + // analyze local vars/func/class defs and create sub-scope symtable. + private ClassVType current_class=null; + private boolean postCheck = false; + private String classDefError = null; + /** A new declaration analyzer sending errors to ERRORS0. */ + public void initScope(SymbolTable s){ + // Symbol table entry for object class + ClassVType cvt = new ClassVType("object"), obj = cvt; + s.put("object", cvt); + //Symbol table entry for int class + cvt = new ClassVType("int"); + cvt.super_class = obj; + s.put("int", cvt); + //Symbol table entry for str class + cvt = new ClassVType("str"); + cvt.super_class = obj; + s.put("str", cvt); + //Symbol table entry for bool class + cvt = new ClassVType("bool"); + cvt.super_class = obj; + s.put("bool", cvt); + //Symbol table entry for None return type + cvt = new ClassVType(""); + cvt.super_class = obj; + s.put("", cvt); + //Symbol table entry for inbuilt print function + ArrayList param = new ArrayList(); + param.add(Type.OBJECT_TYPE); + s.put("print", new FuncType(param, Type.NONE_TYPE)); + //Symbol table entry for inbuilt len function + param = new ArrayList(); + param.add(Type.OBJECT_TYPE); + s.put("len", new FuncType(param, Type.INT_TYPE)); + //Symbol table entry for inbuilt input function + s.put("input", new FuncType(new ArrayList<>(), Type.STR_TYPE)); + } + public SymbolTable createScope(SymbolTable s){ + SymbolTable newScope = new SymbolTable<>(s); + initScope(newScope); + return newScope; + } + //Initializer for the first pass. + public DeclarationAnalyzer(Errors errors0) + { + firstPass = true; + errors = errors0; + globals = sym; + initScope(sym); + typeChecker = new TypeChecker(globals, errors); + } + //Initializer for the second pass. + public DeclarationAnalyzer(Errors errors0, TypeChecker typeChecker, SymbolTable globals) + { + firstPass = false; + this.typeChecker = typeChecker; + errors = errors0; + this.globals = globals; + } + public SymbolTable getGlobals() + { + return globals; + } + private boolean putSymChecked(Node node, String name, Type ty) + { + if (ty == null) + return false; + + if (globals.get(name)!= null && !(ty instanceof ClassVType) && globals.get(name) instanceof ClassVType) //class names are only in global scope + errors.semError(node, "Cannot shadow class name: %s", name); + else if (sym.declares(name)) + errors.semError( + node, "Duplicate declaration of identifier in same scope: %s", name); + else + { + sym.put(name, ty); + return true; + } + return false; + } + @Override + public Type analyze(Program program) + { + for (Declaration decl : program.declarations) + { + Identifier id = decl.getIdentifier(); + String name = id.name; + Type type = decl.dispatch(this); + } + // Check for return statements at top + for (Stmt stmt : program.statements) + { + if (stmt instanceof ReturnStmt) + errors.semError( + stmt, "Return statement cannot appear at the top level"); + } + return null; + } + + @Override + public Type analyze(FuncDef node) + { + if(!postCheck){ + Type fTy = null; + if(sym.declares(node.name.name)) + fTy = sym.get(node.name.name); + + FuncType current_func=null; + + if(!(fTy instanceof FuncType)) + { + if(fTy == null) + { + current_func = new FuncType(new ArrayList(), + ValueType.annotationToValueType(node.returnType)); + + for (TypedVar param : node.params) + { + ValueType p = ValueType.annotationToValueType(param.type); + current_func.parameters.add(p); + if(classDefError != null && p.className().equals(classDefError)) + errors.semError(param.type, "Invalid type annotation; there is no class named: %s", classDefError); + } + sym.put(node.name.name, current_func); + if(!firstPass) + { + SymbolTable parent = sym.getParent(); + if(parent!=null && parent != globals){ + parent.put(node.name.name, current_func); + } + } + } + else if(fTy instanceof ClassVType) + errors.semError(node.name, "Cannot shadow class name: %s", node.name.name); + else + errors.semError( + node.name, "Duplicate declaration of identifier in same scope: %s", node.name.name); + + } + else if(firstPass || sym.declares(node.name.name)) + errors.semError( + node.name, "Duplicate declaration of identifier in same scope: %s", node.name.name); + if(!firstPass){ + + } + return current_func; + } else { + postCheck = false; + + ValueType returnType = ValueType.annotationToValueType(node.returnType); + if(returnType!=null && !returnType.isSpecialType() && !returnType.isListType() && !(globals.get(returnType.className()) instanceof ClassVType)) + errors.semError( + node.returnType, "Invalid type annotation; there is no class named: %s", returnType.className()); + + for(TypedVar param : node.params) + { + ValueType pTy = ValueType.annotationToValueType(param.type); + + if(!(pTy.isListType() && !pTy.elementType().equals(Type.EMPTY_TYPE))&&!pTy.isSpecialType() && !(globals.get(pTy.className()) instanceof ClassVType)) + errors.semError(param.type, "Invalid type annotation; there is no class named: %s", pTy.className()); + + putSymChecked(param.identifier, param.identifier.name, pTy); + } + ArrayList varDefs = new ArrayList<>(), otherDefs = new ArrayList<>(); + for (Declaration decl : node.declarations) + if(decl instanceof VarDef || decl instanceof GlobalDecl || decl instanceof NonLocalDecl) + varDefs.add(decl); + else + otherDefs.add(decl); + for (Declaration decl : varDefs) + if(decl instanceof VarDef||decl instanceof NonLocalDecl) + decl.dispatch(this); + else + decl.dispatch(typeChecker); + for(Declaration decl : otherDefs) + decl.dispatch(this); + for(Declaration decl : otherDefs) + if(decl instanceof FuncDef) + decl.dispatch(typeChecker); + return null; + + } + } + + public boolean compare_functions(FuncType fun1, FuncType fun2) + { + if (fun1.returnType.equals(fun2.returnType)==false) + return false; + if (fun1.parameters.size() != fun2.parameters.size()) + return false; + for (int i=1; i current_scope=createScope(sym); + sym=current_scope; + current_class=cvt; + Type super_class = sym.get(node.superClass.name); + if(super_class instanceof ClassVType) + cvt.super_class = (ClassVType)super_class;//new ClassVType(super_class.className()); + + SymbolTable super_scope=null; + Set super_syms=null; + if (super_class == null) + { + errors.semError( + node.superClass, "Super-class not defined: %s", node.superClass.name); + } + else if ((super_class instanceof ClassVType)==false) + { + errors.semError( + node.superClass, "Super-class must be a class: %s", node.superClass.name); + } + else if (node.superClass.name.equals("int") || node.superClass.name.equals("bool") || node.superClass.name.equals("str")) + { + errors.semError( + node.superClass, "Cannot extend special class: %s", node.superClass.name); + } + else + { + super_scope = cvt.super_class.scope; + if(cvt.super_class.scope != null) + super_syms = super_scope.getDeclaredSymbols(); + else + super_syms = new HashSet(); + HashSet curr_syms = new HashSet<>(); + for (Declaration decl : node.declarations) + { + Identifier id = decl.getIdentifier(); + String name = id.name; + + Type type = null;//decl.dispatch(this); + type = decl.dispatch(this); + if(type instanceof FuncType) + {//For function declarations + FuncType current_func = (FuncType) type; + List params = current_func.parameters; + if(name.equals("__init__") ) + if( params.size() != 1 || + !(params.get(0) instanceof ClassValueType)|| + !((ClassValueType)params.get(0)).className().equals(current_class.className)) + errors.semError(id, "Method overridden with different type signature: __init__"); + else + sym.put(name, current_func); + if(params.size() < 1 || !(params.get(0) instanceof ClassValueType) || !((ClassValueType)params.get(0)).className().equals(current_class.className)) + errors.semError( + id, "First parameter of the following method must be of the enclosing class: %s", name); + + if(curr_syms.contains(name)){ + errors.semError(id, "Duplicate declaration of identifier in same scope: %s", name); + } + else if (super_syms.contains(name)) + { + if ((super_scope.get(id.name) instanceof FuncType)==false) + errors.semError(id, "Cannot re-define attribute: %s", name); + else + { + FuncType super_func = (FuncType) super_scope.get(id.name); + if (compare_functions(super_func, current_func)) + sym.put(name, current_func); + else + errors.semError( + id, "Method overridden with different type signature: %s", name); + } + } + else + sym.put(name, current_func); + } + else if (name.equals("__init__") && !(type instanceof FuncType)) + errors.semError(id, "Cannot re-define attribute: %s", name); + else if (super_syms.contains(name)) + errors.semError(id, "Cannot re-define attribute: %s", name); + else + sym.put(name, type); + curr_syms.add(name); + } + } + if(super_syms != null) + for (String super_sym : super_syms) + { + if (sym.getDeclaredSymbols().contains(super_sym)==false) + sym.put(super_sym, super_scope.get(super_sym)); + } + sym = sym.getParent(); + current_class.scope = current_scope; + current_class=null; + classDefError = null; + return cvt; + } + boolean isVariableType(Type ty) + { + return ty.isSpecialType() || ty.equals(Type.OBJECT_TYPE)|| ty.isListType(); + } + @Override + public Type analyze(NonLocalDecl node) + { + SymbolTable parent=sym.getParent(); + if (parent.getParent()!=null && parent.declares(node.variable.name) && isVariableType(sym.get(node.variable.name))) + { + sym.put(node.variable.name, sym.get(node.variable.name)); + return sym.get(node.variable.name); + } + errors.semError( + node.variable, "Not a nonlocal variable: %s", node.variable.name); + return null; + } + @Override + public Type analyze(VarDef node) + { + Type var_type = sym.get(node.var.identifier.name); + if(firstPass || (sym != globals && (current_class==null || !sym.equals(current_class.scope)))){ + if (sym != globals && globals.get(node.var.identifier.name)!= null && globals.get(node.var.identifier.name) instanceof ClassVType) //class names are only in global scope + errors.semError(node.var.identifier, "Cannot shadow class name: %s", node.var.identifier.name); + else if(sym.getDeclaredSymbols().contains(node.var.identifier.name)) + errors.semError( + node.var.identifier, "Duplicate declaration of identifier in same scope: %s", node.var.identifier.name); + var_type = ValueType.annotationToValueType(node.var.type); + sym.put(node.var.identifier.name, var_type); + } + Type val_type = node.value.dispatch(typeChecker); + if( !firstPass && var_type instanceof ClassValueType) + { + String className = ((ClassValueType)var_type).className(); + Type varVType = sym.get(className); + if(!(className != null && varVType instanceof ClassVType)) + errors.semError(node.var.type, "Invalid type annotation; there is no class named: %s", (className!=null?className:"")); + else if((!val_type.equals(Type.NONE_TYPE) && !StudentAnalysis.subClassOf(varVType,val_type, sym))|| + val_type.equals(Type.NONE_TYPE) && var_type.isSpecialType()) + errors.semError(node, "Expected type `%s`; got type `%s`", varVType, val_type); + } + return var_type; + } + + public void setScope(SymbolTable currentScope) + { + sym = currentScope; + } + public void setCurrClass(ClassVType current_class) + { + this.current_class = current_class; + } + public void setPostCheck(){ + postCheck = true; + } +} diff --git a/src/main/java/chocopy/pa2/StudentAnalysis.java b/src/main/java/chocopy/pa2/StudentAnalysis.java new file mode 100644 index 0000000..3c78048 --- /dev/null +++ b/src/main/java/chocopy/pa2/StudentAnalysis.java @@ -0,0 +1,96 @@ +package chocopy.pa2; + +import chocopy.common.analysis.SymbolTable; +import chocopy.common.analysis.types.ClassVType; +import chocopy.common.analysis.types.ClassValueType; +import chocopy.common.analysis.types.Type; +import chocopy.common.analysis.types.ValueType; +import chocopy.common.astnodes.ClassType; +import chocopy.common.astnodes.Program; +import java.util.ArrayList; +/** Top-level class for performing semantic analysis. */ +public class StudentAnalysis { + + /** + * Perform semantic analysis on PROGRAM, adding error messages and type annotations. Provide + * debugging output iff DEBUG. Returns modified tree. + */ + + public static + boolean subClassOf(Type p, Type c, SymbolTable sym){ + String pName = p.className(); + if(pName!=null && pName.equals("object")) + return true; + if(c instanceof ClassValueType) + c = sym.get(c.className()); + if(c instanceof ClassVType){ + ClassVType child = (ClassVType) c; + + String typename = child.className; + while(typename!=null){ + if(typename.equals(pName)) + return true; + child = child.super_class; + if(child!=null) + typename = child.className; + else + return false; + } + return false; + } else return p.equals(c); + } + private static void extractInhPath(Type ty, ArrayList res){ + if(ty == null) + { + res.add(Type.OBJECT_TYPE); + return; + } + if(ty instanceof ClassVType){ + ClassVType t1 = (ClassVType) ty; + String typename = t1.className; + while(typename!=null){ + res.add(new ClassValueType(typename)); + t1 = t1.super_class; + if(t1 != null) + typename = t1.className(); + else break; + } + } else res.add(ty); + if(!res.get(res.size() - 1).equals(Type.OBJECT_TYPE)) + res.add(Type.OBJECT_TYPE); + } + public static Type lowestCommonType(Type p, Type c, SymbolTable sym){ + if(p instanceof ClassValueType) + p = sym.get(p.className()); + if(c instanceof ClassValueType) + c = sym.get(c.className()); + ArrayList inhPath1 = new ArrayList(), + inhPath2 = new ArrayList(); + extractInhPath(p, inhPath1); + extractInhPath(c, inhPath2); + int l1 = inhPath1.size(), l2 = inhPath2.size(), + len = l1 < l2 ? l1 : l2; + int i = 1; + for(; i <= len; ++ i){ + if(!inhPath1.get(l1 - i).equals(inhPath2.get(l2 - i))) + break; + } + return inhPath1.get(l1 - i + 1); + } + public static Program process(Program program, boolean debug) { + if (program.hasErrors()) { + return program; + } + + DeclarationAnalyzer declarationAnalyzer = new DeclarationAnalyzer(program.errors); + program.dispatch(declarationAnalyzer); + SymbolTable globalSym = declarationAnalyzer.getGlobals(); + + if (!program.hasErrors()) { + TypeChecker typeChecker = new TypeChecker(globalSym, program.errors); + program.dispatch(typeChecker); + } + // System.out.println(program); + return program; + } +} diff --git a/src/main/java/chocopy/pa2/TypeChecker.java b/src/main/java/chocopy/pa2/TypeChecker.java new file mode 100644 index 0000000..b5f1b0b --- /dev/null +++ b/src/main/java/chocopy/pa2/TypeChecker.java @@ -0,0 +1,549 @@ +package chocopy.pa2; + +import chocopy.common.analysis.AbstractNodeAnalyzer; +import chocopy.common.analysis.SymbolTable; +import chocopy.common.analysis.types.ClassVType; +import chocopy.common.analysis.types.ClassValueType; +import chocopy.common.analysis.types.FuncType; +import chocopy.common.analysis.types.FuncValueType; +import chocopy.common.analysis.types.ListValueType; +import chocopy.common.analysis.types.Type; +import chocopy.common.analysis.types.ValueType; +import chocopy.common.astnodes.*; + +import static chocopy.common.analysis.types.Type.INT_TYPE; +import static chocopy.common.analysis.types.Type.OBJECT_TYPE; + +import java.util.ArrayList; +import java.util.HashMap; + +import javax.swing.text.StyledEditorKit.BoldAction; + +import com.fasterxml.jackson.annotation.JacksonInject.Value; + +/** + * Analyzer that performs ChocoPy type checks on all nodes. Applied after collecting declarations. + */ +public class TypeChecker extends AbstractNodeAnalyzer { + // global scope + private final SymbolTable sym; + private final DeclarationAnalyzer declAnalyzer; + /** The current symbol table (changes depending on the function being analyzed). */ + private SymbolTable currentScope; + private Type currReturnType; + private boolean returned = false, member = false; + /** Collector for errors. */ + private final Errors errors; + private boolean assign = false; + private boolean declAnalyzed = false; + private final HashMap> funcScopes; + /** + * Creates a type checker using GLOBALSYMBOLS for the initial global symbol table and ERRORS0 to + * receive semantic errors. + */ + public TypeChecker(SymbolTable globalSymbols, Errors errors0) { + sym = globalSymbols; + currentScope = sym; + errors = errors0; + currReturnType = null; + declAnalyzer = new DeclarationAnalyzer(errors0, this, globalSymbols); + funcScopes = new HashMap<>(); + } + /** + * Inserts an error message in NODE if there isn't one already. The message is constructed with + * MESSAGE and ARGS as for String.format. + */ + private boolean isVariableType(Type ty){ + return ty.isSpecialType() || ty.equals(Type.OBJECT_TYPE); + } + public boolean pushDeclAnalyzed() { + boolean orig = declAnalyzed; + declAnalyzed = true; + return orig; + } + public void popDeclAnalyzed(boolean orig) { + declAnalyzed = orig; + } + private Type declAnalyze(Node node){ + //if(currentScope != sym) + declAnalyzer.setScope(currentScope); + return node.dispatch(declAnalyzer); + } + private void err(Node node, String message, Object... args) { + errors.semError(node, message, args); + } + + @Override + public Type analyze(Program program) { + for (Declaration decl : program.declarations) { + decl.dispatch(this); + } + for (Stmt stmt : program.statements) { + stmt.dispatch(this); + } + return null; + } + @Override + public Type analyze(ClassDef node){ + ClassVType t = (ClassVType) sym.get(node.name.name); + SymbolTable backScope = currentScope; + currentScope = t.scope; + declAnalyzer.setCurrClass(t); + for(Declaration decl : node.declarations){ + decl.dispatch(this); + } + declAnalyzer.setCurrClass(null); + currentScope = backScope; + return null; + } + @Override + public Type analyze(AssignStmt node) { + Type tr = node.value.dispatch(this); + Type tl; + boolean error = false; + assign=true; + for (Expr ex : node.targets) + { + tl = ex.dispatch(this); + if(error) continue; + else if(tl == null) + { + err(node, "Expression `%s` type inference error.", ex); + error = true; + } + else if (ex instanceof IndexExpr && + ((IndexExpr)ex).list.getInferredType().equals(Type.STR_TYPE)) + { + err(ex, "`str` is not a list type"); + error = true; + } + else if(tr!=null && tl.isListType() && tr.isListType()) + { + if(!((!tl.elementType().isSpecialType()&&tr.elementType().equals(Type.NONE_TYPE))|| + tl.equals(tr)||tr.elementType().equals(Type.EMPTY_TYPE))) + { + err(node, "Expected type `%s`; got type `%s`", tl, tr); + error = true; + } + } + else if(tl.isListType() && Type.EMPTY_TYPE.equals(tr)) ; //continue; + else if(tr != null && !(StudentAnalysis.subClassOf(tl, tr, currentScope) || !tl.isSpecialType() && tr.equals(Type.NONE_TYPE))) + { + err(node, "Expected type `%s`; got type `%s`", tl, tr); + error = true; + } + } + assign=false; + return null; + } + + @Override + public Type analyze(BooleanLiteral node) { + return node.setInferredType(Type.BOOL_TYPE); + } + public void dispatchFuncDef(FuncDef node, SymbolTable scope, boolean declAnalyzed){ + boolean prevDeclAnalyzed = this.declAnalyzed; + this.declAnalyzed = declAnalyzed; + SymbolTable origScope = currentScope; + currentScope = scope; + node.dispatch(this); + currentScope = origScope; + this.declAnalyzed = prevDeclAnalyzed; + } + @Override + public Type analyze(FuncDef node) { + SymbolTable origScope = currentScope; + if(funcScopes.get(node) != null) + System.out.println("error"); + { + currentScope = declAnalyzer.createScope(currentScope); + funcScopes.put(node, currentScope); + declAnalyzer.setPostCheck(); + declAnalyze(node); + //currentScope = funcScopes.get(node); + returned = false; + Type prevReturnType = this.currReturnType; + this.currReturnType = ValueType.annotationToValueType(node.returnType); + for(Stmt st : node.statements) + st.dispatch(this); + + if(currReturnType != null && currReturnType.isSpecialType() && !returned) + err(node.name, "All paths in this function/method must have a return statement: %s", node.name.name); + this.currReturnType = prevReturnType; + } + currentScope = origScope; + return null; + } + + @Override + public Type analyze(CallExpr node) { + Type f = currentScope.get(node.function.name); + ArrayList types = new ArrayList<>(); + for(Expr ex: node.args) + types.add(ex.dispatch(this)); + if(f != null && f.isFuncType()) + { + FuncType fty = (FuncType) f; + int lArgs = node.args.size(), lPars = fty.parameters.size(); + if(lArgs != lPars) + err(node, "Expected %d arguments; got %d", lPars, lArgs); + else{ + for(int i = 0; i < lArgs; ++i){ + Type p = fty.parameters.get(i); + Type c = types.get(i); + if(((p.isSpecialType()&&!p.equals(c)) || + (!p.isSpecialType()&&!StudentAnalysis.subClassOf(p, c, currentScope))) + &&!(p.isListType()&&c.equals(Type.EMPTY_TYPE)) + ) + err(node,"Expected type `%s`; got type `%s` in parameter %d", p, c, i); + } + } + node.function.setInferredType(new FuncType(fty.parameters, fty.returnType)); + return node.setInferredType(fty.returnType); + } + else if (f != null && f instanceof ClassVType){ + ClassVType cty = (ClassVType) f; + return node.setInferredType(new ClassValueType(f.className())); + } + else{ + err(node, "Not a function or class: %s", node.function.name); + return node.setInferredType(Type.NONE_TYPE); + } + } + + @Override + public Type analyze(ClassType node) { + return sym.get(node.className); + } + + @Override + public Type analyze(ForStmt node) { + Type iterableType = node.iterable.setInferredType( + node.iterable.dispatch(this)); + if(iterableType == null) + err(node, "Iterable `%s` type inference error.", node.iterable); + else if (iterableType.equals(Type.STR_TYPE)) + node.identifier.setInferredType(Type.STR_TYPE); + else if(iterableType.elementType() == null){ + err(node, "`%s` isn't iterable", iterableType); + } + else + node.identifier.setInferredType( + iterableType.elementType() + ); + for(Stmt st : node.body) + st.dispatch(this); + return null; + } + + @Override + public Type analyze(IfExpr node) { + Type condTy = node.condition.dispatch(this); + if(!condTy.equals(Type.BOOL_TYPE)){ + err(node, "Condition expression cannot be of type `%s`", condTy.className()); + } + + Type ifTy = node.thenExpr.dispatch(this), + elseTy = node.elseExpr.dispatch(this); + + + return node.setInferredType(StudentAnalysis.lowestCommonType(ifTy, elseTy, currentScope)); + } + + @Override + public Type analyze(IfStmt node) { + Type condTy = node.condition.dispatch(this); + if(!condTy.equals(Type.BOOL_TYPE)){ + err(node, "Condition expression cannot be of type `%s`", condTy.className()); + } + boolean prevReturned = returned, thenReturned; + for(Stmt st : node.thenBody) + st.dispatch(this); + thenReturned = prevReturned || returned; + returned = prevReturned; + for(Stmt st : node.elseBody) + st.dispatch(this); + returned = returned && thenReturned; + return null; + } + + @Override + public Type analyze(IndexExpr node) { + Type listTy = node.list.dispatch(this); + if(!(listTy.isListType() || listTy.equals(Type.STR_TYPE))) + err(node, "Cannot index into type `%s`", listTy); + if(!node.index.dispatch(this).equals(Type.INT_TYPE)) + err(node, "Index is of non-integer type `%s`", node.index.getInferredType()); + if(listTy.equals(Type.STR_TYPE)) + return node.setInferredType(Type.STR_TYPE); + else if(listTy.elementType() != null) + return node.setInferredType(listTy.elementType()); + else return node.setInferredType(Type.OBJECT_TYPE); + } + + @Override + public Type analyze(ListExpr node) { + Type t = null; + for(Expr ex : node.elements) + { + Type thisType = ex.dispatch(this); + if(t == null) + t = thisType; + t = StudentAnalysis.lowestCommonType(t, thisType, currentScope); + } + if(t == null) + return node.setInferredType(Type.EMPTY_TYPE); + return node.setInferredType(new ListValueType(t)); + } + + @Override + public Type analyze(MemberExpr node) { + boolean prevIsMember = member; + member = false; + Type ty = node.object.dispatch(this); + if(ty instanceof ClassValueType){ + ty = currentScope.get(((ClassValueType) ty).className()); + if(ty instanceof ClassVType){ + ClassVType classTy = (ClassVType) ty; + Type type = classTy.scope == null? null:classTy.scope.get(node.member.name); + if(type != null) + return node.setInferredType(type); + else + err(node, "There is no %s named `%s` in class `%s`", + prevIsMember?"method":"attribute", node.member.name, classTy); + } else + err(node, "Class `%s` undefined", ty.className()); + } + else + err(node, "`%s` isn't a class.", ty); + return node.setInferredType(ValueType.OBJECT_TYPE); + } + + @Override + public Type analyze(MethodCallExpr node) { + boolean prevIsMember = member; + member = true; + Type ty = node.method.dispatch(this); + member = prevIsMember; + Type thisTy = Type.OBJECT_TYPE; + if(ty instanceof FuncType){ + FuncType funcTy = (FuncType) ty; + int len = funcTy.parameters.size() - 1, largs = node.args.size(); + if(largs != len) + err(node, "Expected %d arguments; got %d", len, largs); + len = len<=largs?len:largs; + for(int i = 0; i < len; ++i){ + Expr thisArg = node.args.get(i); + Type thisArgTy = thisArg.setInferredType(thisArg.dispatch(this)), + thisParamTy = funcTy.parameters.get(i + 1); + + if(!thisParamTy.equals(thisArgTy) && !StudentAnalysis.subClassOf(thisParamTy, thisArgTy, currentScope) + &&!(thisParamTy.isListType()&&thisArgTy.equals(Type.EMPTY_TYPE))) + err(node, "Expected type `%s`; got type `%s` in parameter %d", + thisParamTy, thisArgTy, i + 1); + } + thisTy = funcTy.returnType; + } + // else + // err(node.method.member, "`%s` isn't a MemberFunction.", node.method.member.name); + + for(Expr args : node.args) + args.dispatch(this); + + return node.setInferredType(thisTy); + } + + @Override + public Type analyze(NoneLiteral node) { + return node.setInferredType(Type.NONE_TYPE); + } + /* + @Override + public Type analyze(NonLocalDecl node) { + SymbolTable parent = currentScope.getParent(); + if(parent == null || parent == sym || + !parent.getDeclaredSymbols().contains(node.variable.name)|| + !isVariableType(parent.get(node.variable.name)) + ){ + err(node.variable, "Not a nonlocal variable: %s", node.variable.name); + } else if(currentScope.getDeclaredSymbols().contains(node.variable.name)){ + errors.semError( + node.variable, "Duplicate declaration of identifier in same scope: %s", node.variable.name); + } + else + { + Type nonlocalVar = parent.get(node.variable.name); + currentScope.put(node.variable.name, nonlocalVar); + } + return null; + } + */ + @Override + public Type analyze(ReturnStmt node) { + if(node.value != null) + node.value.dispatch(this); + Type p = this.currReturnType; + Type c = (node.value == null ? Type.NONE_TYPE: node.value.getInferredType()); + if(node.value == null && p.isSpecialType()) + err(node, "Expected type `%s`; got `None`", p); + else if(p.isSpecialType()&&(c.equals(Type.NONE_TYPE)) || (!c.equals(Type.NONE_TYPE) && !StudentAnalysis.subClassOf(p, c, currentScope))) + err(node, "Expected type `%s`; got type `%s`", p, c); + returned = true; + return null; + } + + @Override + public Type analyze(StringLiteral node) { + return node.setInferredType(Type.STR_TYPE); + } + + @Override + public Type analyze(TypedVar node) { + return ValueType.annotationToValueType(node.type); + } + + @Override + public Type analyze(VarDef node) { + return declAnalyze(node); + } + + @Override + public Type analyze(UnaryExpr node) { + Type t = node.operand.dispatch(this); + switch (node.operator) { + case "-": + case "+": + if (INT_TYPE.equals(t)) { + return node.setInferredType(INT_TYPE); + } else { + err(node, "Cannot apply operator `%s` on type `%s`", node.operator, t); + return node.setInferredType(INT_TYPE); + } + case "not": + if (!(Type.BOOL_TYPE.equals(t))) + err(node, "Cannot apply operator `not` on type `%s`", t); + return node.setInferredType(Type.BOOL_TYPE); + default: + return node.setInferredType(OBJECT_TYPE); + } + } + + + @Override + public Type analyze(WhileStmt node) { + if(!node.condition.dispatch(this).equals(Type.BOOL_TYPE)) + err(node, "`%s` isn't a boolean expression.", node.condition); + for(Stmt st : node.body) + st.dispatch(this); + return null; + } + + + @Override + public Type analyze(ExprStmt s) { + s.expr.dispatch(this); + return null; + } + + @Override + public Type analyze(IntegerLiteral i) { + return i.setInferredType(Type.INT_TYPE); + } + + @Override + public Type analyze(BinaryExpr e) { + Type t1 = e.left.dispatch(this); + Type t2 = e.right.dispatch(this); + + switch (e.operator) { + case "-": + case "*": + case "//": + case "%": + if (INT_TYPE.equals(t1) && INT_TYPE.equals(t2)) { + return e.setInferredType(INT_TYPE); + } else { + err(e, "Cannot apply operator `%s` on types `%s` and `%s`", e.operator, t1, t2); + return e.setInferredType(INT_TYPE); + } + case "+": + if (INT_TYPE.equals(t1) && INT_TYPE.equals(t2)) { + return e.setInferredType(INT_TYPE); + } else if(Type.STR_TYPE.equals(t1) && Type.STR_TYPE.equals(t2)){ + return e.setInferredType(Type.STR_TYPE); + } else if (t1.isListType() && t2.isListType()){ + return e.setInferredType(new ListValueType(StudentAnalysis. + lowestCommonType(t1.elementType(), t2.elementType(), currentScope))); + }else if (t1.isListType() && t2.equals(Type.EMPTY_TYPE)) + return e.setInferredType(t1); + else { + err(e, "Cannot apply operator `+` on types `%s` and `%s`", t1, t2); + return e.setInferredType(INT_TYPE); + } + case "and": + case "or": + if (!(Type.BOOL_TYPE.equals(t1) && Type.BOOL_TYPE.equals(t2))) + err(e, "Cannot apply operator `%s` on types `%s` and `%s`", e.operator, t1, t2); + return e.setInferredType(Type.BOOL_TYPE); + case ">": + case "<": + case ">=": + case "<=": + if (!(INT_TYPE.equals(t1) && INT_TYPE.equals(t2))) + err(e, "Cannot apply operator `%s` on types `%s` and `%s`", e.operator, t1, t2); + return e.setInferredType(Type.BOOL_TYPE); + case "!=": + case "==": + if (!(INT_TYPE.equals(t1) && INT_TYPE.equals(t2) + || Type.BOOL_TYPE.equals(t1) && Type.BOOL_TYPE.equals(t2) + || Type.STR_TYPE.equals(t1) && Type.STR_TYPE.equals(t2))) + err(e, "Cannot apply operator `%s` on types `%s` and `%s`", e.operator, t1, t2); + return e.setInferredType(Type.BOOL_TYPE); + case "is": + if(t1.isSpecialType()||t2.isSpecialType()) + err(e, "Cannot apply operator `%s` on types `%s` and `%s`", e.operator, t1, t2); + return e.setInferredType(Type.BOOL_TYPE); + default: + return e.setInferredType(OBJECT_TYPE); + } + } + + @Override + public Type analyze(Identifier id) { + String varName = id.name; + Type varType = currentScope.get(varName); + if(varType!=null) + { + if(assign==true && !currentScope.getDeclaredSymbols().contains(varName)) + err(id, "Cannot assign to variable that is not explicitly declared in this scope: %s", varName); + else if(assign==false && currentScope.get(varName)==null) + err(id, "Variable not declared in scope: %s", varName); + } + if (varType != null && varType.isValueType()) { + return id.setInferredType(varType); + } + + err(id, "Not a variable: %s", varName); + return id.setInferredType(ValueType.OBJECT_TYPE); + } + + @Override + public Type analyze(GlobalDecl node) + { + Type ty = sym.get(node.variable.name); + if (sym.declares(node.variable.name)==false || !isVariableType(ty)) + { + err( + node.variable, "Not a global variable: %s", node.variable.name); + return null; + } + else if(currentScope.getDeclaredSymbols().contains(node.variable.name)){ + err( + node.variable, "Duplicate declaration of identifier in same scope: %s", node.variable.name); + } + else + currentScope.put(node.variable.name, ty); + return ty; + } + +} diff --git a/src/main/jflex/chocopy/pa1/ChocoPy.jflex b/src/main/jflex/chocopy/pa1/ChocoPy.jflex new file mode 100644 index 0000000..cbfb668 --- /dev/null +++ b/src/main/jflex/chocopy/pa1/ChocoPy.jflex @@ -0,0 +1,279 @@ +package chocopy.pa1; +import java_cup.runtime.*; +import java.util.ArrayList; +import java.util.Iterator; + +%% + +/*** Do not change the flags below unless you know what you are doing. ***/ + +%unicode +%line +%column +%states AFTER, STR +%class ChocoPyLexer +%public + +%cupsym ChocoPyTokens +%cup +%cupdebug + +%eofclose false + +/*** Do not change the flags above unless you know what you are doing. ***/ + +/* The following code section is copied verbatim to the + * generated lexer class. */ +%{ + /* The code below includes some convenience methods to create tokens + * of a given type and optionally a value that the CUP parser can + * understand. Specifically, a lot of the logic below deals with + * embedded information about where in the source code a given token + * was recognized, so that the parser can report errors accurately. + * (It need not be modified for this project.) */ + + /** Producer of token-related values for the parser. */ + final ComplexSymbolFactory symbolFactory = new ComplexSymbolFactory(); + private int currIndent = 0; //Current Indentation Level + private String currString = ""; + private int str_l = 0, str_c = 0; //Start location of a string. + /*A stack that keeps track of the spaces in each Indentation Level*/ + private ArrayList stack = new ArrayList(20); + private boolean indentErrorUnchecked = true; + /** Return a terminal symbol of syntactic category TYPE and no + * semantic value at the current source location. */ + private Symbol symbol(int type) { + return symbol(type, yytext()); + } + + /** Return a terminal symbol of syntactic category TYPE and semantic + * value VALUE at the current source location. */ + private Symbol symbol(int type, Object value) { + return symbolFactory.newSymbol(ChocoPyTokens.terminalNames[type], type, + new ComplexSymbolFactory.Location(yyline + 1, yycolumn + 1), + new ComplexSymbolFactory.Location(yyline + 1,yycolumn + yylength()), + value); + } + + private void push(int indent){ + stack.add(indent); + } + private int pop(){ + if(stack.isEmpty()) return 0; + return stack.remove(stack.size() - 1); + } + private int top(){ + if(stack.isEmpty()) return 0; + return stack.get(stack.size() - 1); + } + private boolean find(int indent){ + if(indent == 0) return true; + Iterator it = stack.iterator(); + while(it.hasNext()){ + if(it.next() == indent) + return true; + } + return false; + } +%} + +/* Macros (regexes used in rules below) */ + +WhiteSpace = [ \t] +LineBreak = \r|\n|\r\n + + +IntegerLiteral = 0|[1-9][0-9]* // Accroding to the manual, 00+ is illeagal +StringLiteral = ([^\"\\]|(\\\")|(\\t)|(\\r)|(\\n)|(\\\\))+ // \n, \r, \t, \\, \" and Anything except \ and " +Identifiers = (_|[a-z]|[A-Z])(_|[a-z]|[A-Z]|[0-9])* +Comments = #[^\r\n]* +%% +//YYINITIAL state is where we're dealing with indentations. +//We will set the state to YYINITIAL when starting a +//new line unless this line is within a string, e.g.: +/* +"this is \ +a string across \ +multiple lines\ +" +*/ +{ + {WhiteSpace} + { + /*Add indentation */ + if(yytext() == "\t") + currIndent += 8; //'\t' = 8 spaces + else + currIndent ++; + } +/* +# This python code will test if '\t' is 8 spaces +# It will run and print '1\n2' +# Please tell me if your Python reports an error +# Or you find documentations that says otherwise + +if True: + print(1) # \t + print(2) # 8 spaces +*/ + + {LineBreak} + { + /* + If this is a blank line, start over on the next line. + An empty line should just be ignored, therefore we don't + pass a NEWLINE to Cup. + */ + currIndent = 0; + } + {Comments} { /* ignored */ } //Ignore blank lines + + /*If it's not a blank line (Current character isn't a + Whitespace/linebreak/comment), deal with indentation here and + start accepting whatever is on this line in `AFTER' state*/ + [^ \t\r\n#] + { + //rewind the current character. + yypushback(1); + if(top() > currIndent) + { + /* + If the indentation of the line is less than number of + indents current level should have, + keep dedenting until it reaches the level with the same + number of indents. + It's like a loop, because we're not changing the state + and we rewinded the current character. So it will keep + going until top()<= currIndent and it will switch to + AFTER state. + */ + pop(); + if(top() < currIndent) + { + currIndent = top(); + return symbolFactory.newSymbol("", ChocoPyTokens.UNRECOGNIZED, + new ComplexSymbolFactory.Location(yyline + 1, yycolumn - 1), + new ComplexSymbolFactory.Location(yyline + 1,yycolumn + yylength()), + currIndent); + } + return symbolFactory.newSymbol(ChocoPyTokens.terminalNames[ChocoPyTokens.DEDENT], ChocoPyTokens.DEDENT, + new ComplexSymbolFactory.Location(yyline + 1, yycolumn - 1), + new ComplexSymbolFactory.Location(yyline + 1,yycolumn + yylength()), + currIndent); + } + /*Otherwise, we will start dealing with the rest + of the line after indentation in AFTER state. */ + yybegin(AFTER); + if(top()< currIndent) + { + /* + If current indentation is more than the number of indents + current level should have, start a new level which will have + `currIndent' indents. + */ + + push(currIndent); + return symbolFactory.newSymbol(ChocoPyTokens.terminalNames[ChocoPyTokens.INDENT], ChocoPyTokens.INDENT, + new ComplexSymbolFactory.Location(yyline + 1, yycolumn - 1), + new ComplexSymbolFactory.Location(yyline + 1,yycolumn + yylength()), + currIndent); + } + } +} + + + { + + /* Delimiters. */ + {LineBreak} { yybegin(YYINITIAL); currIndent = 0;indentErrorUnchecked = true; return symbol(ChocoPyTokens.NEWLINE);} + ":" { return symbol(ChocoPyTokens.COLON); } + "," { return symbol(ChocoPyTokens.COMMA); } + + /* Literals. */ + {IntegerLiteral} { return symbol(ChocoPyTokens.NUMBER, + Integer.parseInt(yytext())); } + + "\"" { yybegin(STR); str_l = yyline + 1; str_c = yycolumn + 1; currString = ""; } //Start taking a string when see a " + "False" { return symbol(ChocoPyTokens.BOOL, false); } + "True" { return symbol(ChocoPyTokens.BOOL, true); } + "None" { return symbol(ChocoPyTokens.NONE); } + + /*Keywords*/ + "if" { return symbol(ChocoPyTokens.IF); } + "else" { return symbol(ChocoPyTokens.ELSE); } + "elif" { return symbol(ChocoPyTokens.ELIF); } + "while" { return symbol(ChocoPyTokens.WHILE); } + "class" { return symbol(ChocoPyTokens.CLASS); } + "def" { return symbol(ChocoPyTokens.DEF); } + "lambda" { return symbol(ChocoPyTokens.LAMBDA); } + "as" { return symbol(ChocoPyTokens.AS); } + "for" { return symbol(ChocoPyTokens.FOR); } + "global" { return symbol(ChocoPyTokens.GLOBAL); } + "in" { return symbol(ChocoPyTokens.IN); } + "nonlocal" { return symbol(ChocoPyTokens.NONLOCAL); } + "pass" { return symbol(ChocoPyTokens.PASS); } + "return" { return symbol(ChocoPyTokens.RETURN); } + "assert" { return symbol(ChocoPyTokens.ASSERT); } + "await" { return symbol(ChocoPyTokens.AWAIT); } + "break" { return symbol(ChocoPyTokens.BREAK); } + "continue" { return symbol(ChocoPyTokens.CONTINUE); } + "del" { return symbol(ChocoPyTokens.DEL); } + "except" { return symbol(ChocoPyTokens.EXCEPT); } + "finally" { return symbol(ChocoPyTokens.FINALLY); } + "from" { return symbol(ChocoPyTokens.FROM); } + "import" { return symbol(ChocoPyTokens.IMPORT); } + "raise" { return symbol(ChocoPyTokens.RAISE); } + "try" { return symbol(ChocoPyTokens.TRY); } + "with" { return symbol(ChocoPyTokens.WITH); } + "yield" { return symbol(ChocoPyTokens.YIELD); } + + + /* Operators. */ + "+" { return symbol(ChocoPyTokens.PLUS); } + "-" { return symbol(ChocoPyTokens.MINUS); } + "*" { return symbol(ChocoPyTokens.MUL); } + "//" { return symbol(ChocoPyTokens.DIV); } + "/" { return symbol(ChocoPyTokens.DIV); } //Accroding to manual, chocopy don't have fp division, '/', '//' should be integr division + "%" { return symbol(ChocoPyTokens.MOD); } + ">" { return symbol(ChocoPyTokens.GT); } + "<" { return symbol(ChocoPyTokens.LT); } + "==" { return symbol(ChocoPyTokens.EQUAL); } + "!=" { return symbol(ChocoPyTokens.NEQ); } + ">=" { return symbol(ChocoPyTokens.GEQ); } + "<=" { return symbol(ChocoPyTokens.LEQ); } + "=" { return symbol(ChocoPyTokens.ASSIGN); } + "and" { return symbol(ChocoPyTokens.AND); } + "or" { return symbol(ChocoPyTokens.OR); } + "not" { return symbol(ChocoPyTokens.NOT); } + "." { return symbol(ChocoPyTokens.DOT); } + "(" { return symbol(ChocoPyTokens.LPAR); } + ")" { return symbol(ChocoPyTokens.RPAR); } + "[" { return symbol(ChocoPyTokens.LBR); } + "]" { return symbol(ChocoPyTokens.RBR); } + "->" { return symbol(ChocoPyTokens.ARROW); } + "is" { return symbol(ChocoPyTokens.IS); } + + + /*Identifiers*/ + {Identifiers} { return symbol(ChocoPyTokens.ID, yytext()); } + + /* Whitespace. */ + {WhiteSpace} { /* ignore */ } + + /* Comment. */ + {Comments} { /* ignore */ } +} +{ + {StringLiteral} { currString += yytext(); } + + \\$ { /*'\' at the end of line, do nothing.*/ } + + "\"" { yybegin(AFTER); return symbolFactory.newSymbol(ChocoPyTokens.terminalNames[ChocoPyTokens.STRING], ChocoPyTokens.STRING, + new ComplexSymbolFactory.Location(str_l, str_c), + new ComplexSymbolFactory.Location(yyline + 1,yycolumn + yylength()), + currString); } // accepted a ", return to AFTER state +} +<> { if(!stack.isEmpty()){ return symbol(ChocoPyTokens.DEDENT, pop());} return symbol(ChocoPyTokens.EOF); } + +/* Error fallback. */ +[^] { return symbol(ChocoPyTokens.UNRECOGNIZED); } diff --git a/src/test/data/pa1/sample/bad_assign_expr1.py b/src/test/data/pa1/sample/bad_assign_expr1.py new file mode 100644 index 0000000..ccc8c3e --- /dev/null +++ b/src/test/data/pa1/sample/bad_assign_expr1.py @@ -0,0 +1 @@ +x = (y = 2) diff --git a/src/test/data/pa1/sample/bad_assign_expr1.py.ast b/src/test/data/pa1/sample/bad_assign_expr1.py.ast new file mode 100644 index 0000000..d134770 --- /dev/null +++ b/src/test/data/pa1/sample/bad_assign_expr1.py.ast @@ -0,0 +1,16 @@ +{ + "kind" : "Program", + "location" : [ 1, 6, 1, 6 ], + "declarations" : [ ], + "statements" : [ ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 8, 1, 8 ], + "message" : "Parse error near token EQ: =", + "syntax" : true + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/bad_assign_expr2.py b/src/test/data/pa1/sample/bad_assign_expr2.py new file mode 100644 index 0000000..444bc53 --- /dev/null +++ b/src/test/data/pa1/sample/bad_assign_expr2.py @@ -0,0 +1 @@ +print(x = 1) diff --git a/src/test/data/pa1/sample/bad_assign_expr2.py.ast b/src/test/data/pa1/sample/bad_assign_expr2.py.ast new file mode 100644 index 0000000..53e699c --- /dev/null +++ b/src/test/data/pa1/sample/bad_assign_expr2.py.ast @@ -0,0 +1,16 @@ +{ + "kind" : "Program", + "location" : [ 1, 7, 1, 7 ], + "declarations" : [ ], + "statements" : [ ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 9, 1, 9 ], + "message" : "Parse error near token EQ: =", + "syntax" : true + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/bad_func_def.py b/src/test/data/pa1/sample/bad_func_def.py new file mode 100644 index 0000000..ebd2373 --- /dev/null +++ b/src/test/data/pa1/sample/bad_func_def.py @@ -0,0 +1,6 @@ +def foo(a, b) -> 1: + x:int = a + return 1 + +print(1) +print(3**6) diff --git a/src/test/data/pa1/sample/bad_func_def.py.ast b/src/test/data/pa1/sample/bad_func_def.py.ast new file mode 100644 index 0000000..934bef0 --- /dev/null +++ b/src/test/data/pa1/sample/bad_func_def.py.ast @@ -0,0 +1,64 @@ +{ + "kind" : "Program", + "location" : [ 2, 13, 6, 8 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 2, 13, 2, 13 ], + "expr" : { + "kind" : "Identifier", + "location" : [ 2, 13, 2, 13 ], + "name" : "a" + } + }, { + "kind" : "ReturnStmt", + "location" : [ 3, 5, 3, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 12, 3, 12 ], + "value" : 1 + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 8 ], + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 5, 7, 5, 7 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 10, 1, 10 ], + "message" : "Parse error near token COMMA: ,", + "syntax" : true + }, { + "kind" : "CompilerError", + "location" : [ 2, 13, 2, 13 ], + "message" : "Parse error near token IDENTIFIER: a", + "syntax" : true + }, { + "kind" : "CompilerError", + "location" : [ 5, 1, 5, 0 ], + "message" : "Parse error near token DEDENT: ", + "syntax" : true + }, { + "kind" : "CompilerError", + "location" : [ 6, 9, 6, 9 ], + "message" : "Parse error near token TIMES: *", + "syntax" : true + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/bad_indentation.py b/src/test/data/pa1/sample/bad_indentation.py new file mode 100644 index 0000000..670b7ab --- /dev/null +++ b/src/test/data/pa1/sample/bad_indentation.py @@ -0,0 +1,3 @@ +x = 1 + y = 2 +z = 3 diff --git a/src/test/data/pa1/sample/bad_indentation.py.ast b/src/test/data/pa1/sample/bad_indentation.py.ast new file mode 100644 index 0000000..f37b92e --- /dev/null +++ b/src/test/data/pa1/sample/bad_indentation.py.ast @@ -0,0 +1,47 @@ +{ + "kind" : "Program", + "location" : [ 2, 3, 3, 6 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 2, 3, 2, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 2, 3, 2, 3 ], + "name" : "y" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 7, 2, 7 ], + "value" : 2 + } + }, { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 5, 3, 5 ], + "value" : 3 + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 2, 1, 2, 2 ], + "message" : "Parse error near token INDENT: ", + "syntax" : true + }, { + "kind" : "CompilerError", + "location" : [ 3, 1, 3, 0 ], + "message" : "Parse error near token DEDENT: ", + "syntax" : true + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/bad_stmt.py b/src/test/data/pa1/sample/bad_stmt.py new file mode 100644 index 0000000..8e8a4da --- /dev/null +++ b/src/test/data/pa1/sample/bad_stmt.py @@ -0,0 +1,4 @@ +1 + 2 +3 == 4 or (not False && True) +5 + 6 +7 << 8 diff --git a/src/test/data/pa1/sample/bad_stmt.py.ast b/src/test/data/pa1/sample/bad_stmt.py.ast new file mode 100644 index 0000000..afe9602 --- /dev/null +++ b/src/test/data/pa1/sample/bad_stmt.py.ast @@ -0,0 +1,65 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 7 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 5 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "value" : 2 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 5 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 1, 3, 1 ], + "value" : 5 + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 5, 3, 5 ], + "value" : 6 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 6, 4, 6 ], + "expr" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 6, 4, 6 ], + "value" : 8 + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 2, 22, 2, 22 ], + "message" : "Parse error near token UNRECOGNIZED: &", + "syntax" : true + }, { + "kind" : "CompilerError", + "location" : [ 4, 4, 4, 4 ], + "message" : "Parse error near token LT: <", + "syntax" : true + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/chained_mixed_assignments.py b/src/test/data/pa1/sample/chained_mixed_assignments.py new file mode 100644 index 0000000..46a230a --- /dev/null +++ b/src/test/data/pa1/sample/chained_mixed_assignments.py @@ -0,0 +1,2 @@ +x[0] = y = z.f = 1 +z.g = y = x[0] diff --git a/src/test/data/pa1/sample/chained_mixed_assignments.py.ast b/src/test/data/pa1/sample/chained_mixed_assignments.py.ast new file mode 100644 index 0000000..9654bf6 --- /dev/null +++ b/src/test/data/pa1/sample/chained_mixed_assignments.py.ast @@ -0,0 +1,85 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 2, 15 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 1, 1, 1, 18 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 1, 1, 1, 4 ], + "list" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 3, 1, 3 ], + "value" : 0 + } + }, { + "kind" : "Identifier", + "location" : [ 1, 8, 1, 8 ], + "name" : "y" + }, { + "kind" : "MemberExpr", + "location" : [ 1, 12, 1, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 1, 12, 1, 12 ], + "name" : "z" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 1, 14, 1, 14 ], + "name" : "f" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 18, 1, 18 ], + "value" : 1 + } + }, { + "kind" : "AssignStmt", + "location" : [ 2, 1, 2, 14 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 2, 1, 2, 3 ], + "object" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "z" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 2, 3, 2, 3 ], + "name" : "g" + } + }, { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 7 ], + "name" : "y" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 2, 11, 2, 14 ], + "list" : { + "kind" : "Identifier", + "location" : [ 2, 11, 2, 11 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 0 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/chained_var_assignments.py b/src/test/data/pa1/sample/chained_var_assignments.py new file mode 100644 index 0000000..b253c2a --- /dev/null +++ b/src/test/data/pa1/sample/chained_var_assignments.py @@ -0,0 +1 @@ +x = y = z = 1 diff --git a/src/test/data/pa1/sample/chained_var_assignments.py.ast b/src/test/data/pa1/sample/chained_var_assignments.py.ast new file mode 100644 index 0000000..28f0ea7 --- /dev/null +++ b/src/test/data/pa1/sample/chained_var_assignments.py.ast @@ -0,0 +1,32 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 14 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 1, 1, 1, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 5 ], + "name" : "y" + }, { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 13, 1, 13 ], + "value" : 1 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/class_attr.py b/src/test/data/pa1/sample/class_attr.py new file mode 100644 index 0000000..bb1e1cd --- /dev/null +++ b/src/test/data/pa1/sample/class_attr.py @@ -0,0 +1,4 @@ +class Foo(object): + x:int = 1 + +f = Foo() diff --git a/src/test/data/pa1/sample/class_attr.py.ast b/src/test/data/pa1/sample/class_attr.py.ast new file mode 100644 index 0000000..4fdab40 --- /dev/null +++ b/src/test/data/pa1/sample/class_attr.py.ast @@ -0,0 +1,65 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 10 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 9 ], + "name" : "Foo" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 11, 1, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "f" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 4, 5, 4, 9 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "Foo" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/class_attr_get.py b/src/test/data/pa1/sample/class_attr_get.py new file mode 100644 index 0000000..b4e6365 --- /dev/null +++ b/src/test/data/pa1/sample/class_attr_get.py @@ -0,0 +1,5 @@ +class Foo(object): + x:int = 1 + +f = Foo() +print(f.x) diff --git a/src/test/data/pa1/sample/class_attr_get.py.ast b/src/test/data/pa1/sample/class_attr_get.py.ast new file mode 100644 index 0000000..f286342 --- /dev/null +++ b/src/test/data/pa1/sample/class_attr_get.py.ast @@ -0,0 +1,91 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 9 ], + "name" : "Foo" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 11, 1, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "f" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 4, 5, 4, 9 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "Foo" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 10 ], + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 5, 7, 5, 9 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 7, 5, 7 ], + "name" : "f" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 9 ], + "name" : "x" + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/class_attr_set.py b/src/test/data/pa1/sample/class_attr_set.py new file mode 100644 index 0000000..ac94bf8 --- /dev/null +++ b/src/test/data/pa1/sample/class_attr_set.py @@ -0,0 +1,5 @@ +class Foo(object): + x:int = 1 + +f = Foo() +f.x = 2 diff --git a/src/test/data/pa1/sample/class_attr_set.py.ast b/src/test/data/pa1/sample/class_attr_set.py.ast new file mode 100644 index 0000000..03d6bba --- /dev/null +++ b/src/test/data/pa1/sample/class_attr_set.py.ast @@ -0,0 +1,87 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 8 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 9 ], + "name" : "Foo" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 11, 1, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "f" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 4, 5, 4, 9 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "Foo" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 7 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 5, 1, 5, 3 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "f" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 3, 5, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 7, 5, 7 ], + "value" : 2 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/class_constructor.py b/src/test/data/pa1/sample/class_constructor.py new file mode 100644 index 0000000..46d7ccb --- /dev/null +++ b/src/test/data/pa1/sample/class_constructor.py @@ -0,0 +1,8 @@ +class Foo(object): + x:int = 0 + + def __init__(self:"Foo", x:int): + self.x = x + +f = Foo(1) +print(f.x) diff --git a/src/test/data/pa1/sample/class_constructor.py.ast b/src/test/data/pa1/sample/class_constructor.py.ast new file mode 100644 index 0000000..6850e03 --- /dev/null +++ b/src/test/data/pa1/sample/class_constructor.py.ast @@ -0,0 +1,159 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 9 ], + "name" : "Foo" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 11, 1, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 18, 4, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 18, 4, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 23, 4, 27 ], + "className" : "Foo" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 30, 4, 34 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 30, 4, 30 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 32, 4, 34 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 36, 4, 36 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 9, 5, 18 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 5, 9, 5, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 14, 5, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 18 ], + "name" : "x" + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "f" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 7, 5, 7, 10 ], + "function" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 7 ], + "name" : "Foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 7, 9, 7, 9 ], + "value" : 1 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 10 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 8, 7, 8, 9 ], + "object" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "f" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "x" + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/class_method.py b/src/test/data/pa1/sample/class_method.py new file mode 100644 index 0000000..cc03ce2 --- /dev/null +++ b/src/test/data/pa1/sample/class_method.py @@ -0,0 +1,9 @@ +class Foo(object): + x:int = 0 + + def set(self:"Foo", x:int) -> object: + self.x = x + +f = Foo() +f.set(1) +print(f.x) diff --git a/src/test/data/pa1/sample/class_method.py.ast b/src/test/data/pa1/sample/class_method.py.ast new file mode 100644 index 0000000..66bc2e1 --- /dev/null +++ b/src/test/data/pa1/sample/class_method.py.ast @@ -0,0 +1,181 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 9 ], + "name" : "Foo" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 11, 1, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "set" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 22 ], + "className" : "Foo" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 25, 4, 29 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 25, 4, 25 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 27, 4, 29 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 35, 4, 40 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 9, 5, 18 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 5, 9, 5, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 14, 5, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 18 ], + "name" : "x" + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "f" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 7, 5, 7, 9 ], + "function" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 7 ], + "name" : "Foo" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 8 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 8, 1, 8, 8 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 8, 1, 8, 5 ], + "object" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "f" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 8, 3, 8, 5 ], + "name" : "set" + } + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 8, 7, 8, 7 ], + "value" : 1 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 9, 1, 9, 10 ], + "function" : { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 9, 7, 9, 9 ], + "object" : { + "kind" : "Identifier", + "location" : [ 9, 7, 9, 7 ], + "name" : "f" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 9 ], + "name" : "x" + } + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/coverage.py b/src/test/data/pa1/sample/coverage.py new file mode 100644 index 0000000..1da3446 --- /dev/null +++ b/src/test/data/pa1/sample/coverage.py @@ -0,0 +1,38 @@ +count:int = 0 + +def foo(s: str) -> int: + return len(s) + +class bar(object): + p: bool = True + + def baz(self:"bar", xx: [int]) -> str: + global count + x:int = 0 + y:int = 1 + + def qux(y: int) -> object: + nonlocal x + if x > y: + x = -1 + + for x in xx: + self.p = x == 2 + + qux(0) # Yay! ChocoPy + + count = count + 1 + + while x <= 0: + if self.p: + xx[0] = xx[1] + self.p = not self.p + x = x + 1 + elif foo("Long"[0]) == 1: + return self is None + + return "Nope" + +print(bar().baz([1,2])) + + diff --git a/src/test/data/pa1/sample/coverage.py.ast b/src/test/data/pa1/sample/coverage.py.ast new file mode 100644 index 0000000..c7bab9f --- /dev/null +++ b/src/test/data/pa1/sample/coverage.py.ast @@ -0,0 +1,613 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 36, 24 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "name" : "count" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 7, 1, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 13, 1, 13 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 4, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 3, 9, 3, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 12, 3, 14 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 20, 3, 22 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 4, 5, 4, 17 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 4, 12, 4, 17 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 12, 4, 14 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 4, 16, 4, 16 ], + "name" : "s" + } ] + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 6, 1, 36, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 6, 7, 6, 9 ], + "name" : "bar" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 6, 11, 6, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "p" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 8, 7, 11 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 15, 7, 18 ], + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 34, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 9, 13, 9, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 18, 9, 22 ], + "className" : "bar" + } + }, { + "kind" : "TypedVar", + "location" : [ 9, 25, 9, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 25, 9, 26 ], + "name" : "xx" + }, + "type" : { + "kind" : "ListType", + "location" : [ 9, 29, 9, 33 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 9, 30, 9, 32 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 39, 9, 41 ], + "className" : "str" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 10, 9, 10, 20 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 10, 16, 10, 20 ], + "name" : "count" + } + }, { + "kind" : "VarDef", + "location" : [ 11, 9, 11, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 9, 11, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 11, 11, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 17, 11, 17 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 12, 9, 12, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 9, 12, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 9, 12, 9 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 11, 12, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 17, 12, 17 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 14, 9, 19, 8 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 13, 14, 15 ], + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 17, 14, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 17, 14, 17 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 20, 14, 22 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 28, 14, 33 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 15, 13, 15, 22 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 15, 22, 15, 22 ], + "name" : "x" + } + } ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 16, 13, 19, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 16, 16, 16, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 16 ], + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "Identifier", + "location" : [ 16, 20, 16, 20 ], + "name" : "y" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 17, 17, 17, 22 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 17, 17, 17 ], + "name" : "x" + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 17, 21, 17, 22 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 17, 22, 17, 22 ], + "value" : 1 + } + } + } ], + "elseBody" : [ ] + } ] + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 19, 9, 22, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 13, 19, 13 ], + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 19, 18, 19, 19 ], + "name" : "xx" + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 20, 13, 20, 27 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 20, 13, 20, 18 ], + "object" : { + "kind" : "Identifier", + "location" : [ 20, 13, 20, 16 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 18, 20, 18 ], + "name" : "p" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 20, 22, 20, 27 ], + "left" : { + "kind" : "Identifier", + "location" : [ 20, 22, 20, 22 ], + "name" : "x" + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 20, 27, 20, 27 ], + "value" : 2 + } + } + } ] + }, { + "kind" : "ExprStmt", + "location" : [ 22, 9, 22, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 22, 9, 22, 14 ], + "function" : { + "kind" : "Identifier", + "location" : [ 22, 9, 22, 11 ], + "name" : "qux" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 22, 13, 22, 13 ], + "value" : 0 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 24, 9, 24, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 24, 9, 24, 13 ], + "name" : "count" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 24, 17, 24, 25 ], + "left" : { + "kind" : "Identifier", + "location" : [ 24, 17, 24, 21 ], + "name" : "count" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 25, 24, 25 ], + "value" : 1 + } + } + }, { + "kind" : "WhileStmt", + "location" : [ 26, 9, 34, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 26, 15, 26, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 26, 15, 26, 15 ], + "name" : "x" + }, + "operator" : "<=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 26, 20, 26, 20 ], + "value" : 0 + } + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 27, 13, 34, 8 ], + "condition" : { + "kind" : "MemberExpr", + "location" : [ 27, 16, 27, 21 ], + "object" : { + "kind" : "Identifier", + "location" : [ 27, 16, 27, 19 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 21, 27, 21 ], + "name" : "p" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 28, 17, 28, 29 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 28, 17, 28, 21 ], + "list" : { + "kind" : "Identifier", + "location" : [ 28, 17, 28, 18 ], + "name" : "xx" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 28, 20, 28, 20 ], + "value" : 0 + } + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 28, 25, 28, 29 ], + "list" : { + "kind" : "Identifier", + "location" : [ 28, 25, 28, 26 ], + "name" : "xx" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 28, 28, 28, 28 ], + "value" : 1 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 29, 17, 29, 35 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 29, 17, 29, 22 ], + "object" : { + "kind" : "Identifier", + "location" : [ 29, 17, 29, 20 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 22, 29, 22 ], + "name" : "p" + } + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 29, 26, 29, 35 ], + "operator" : "not", + "operand" : { + "kind" : "MemberExpr", + "location" : [ 29, 30, 29, 35 ], + "object" : { + "kind" : "Identifier", + "location" : [ 29, 30, 29, 33 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 35, 29, 35 ], + "name" : "p" + } + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 30, 17, 30, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 30, 17, 30, 17 ], + "name" : "x" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 30, 21, 30, 25 ], + "left" : { + "kind" : "Identifier", + "location" : [ 30, 21, 30, 21 ], + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 30, 25, 30, 25 ], + "value" : 1 + } + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 31, 13, 34, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 31, 18, 31, 36 ], + "left" : { + "kind" : "CallExpr", + "location" : [ 31, 18, 31, 31 ], + "function" : { + "kind" : "Identifier", + "location" : [ 31, 18, 31, 20 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 31, 22, 31, 30 ], + "list" : { + "kind" : "StringLiteral", + "location" : [ 31, 22, 31, 27 ], + "value" : "Long" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 31, 29, 31, 29 ], + "value" : 0 + } + } ] + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 31, 36, 31, 36 ], + "value" : 1 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 32, 17, 32, 35 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 32, 24, 32, 35 ], + "left" : { + "kind" : "Identifier", + "location" : [ 32, 24, 32, 27 ], + "name" : "self" + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 32, 32, 32, 35 ] + } + } + } ], + "elseBody" : [ ] + } ] + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 34, 9, 34, 21 ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 34, 16, 34, 21 ], + "value" : "Nope" + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 36, 1, 36, 23 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 36, 1, 36, 23 ], + "function" : { + "kind" : "Identifier", + "location" : [ 36, 1, 36, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 36, 7, 36, 22 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 36, 7, 36, 15 ], + "object" : { + "kind" : "CallExpr", + "location" : [ 36, 7, 36, 11 ], + "function" : { + "kind" : "Identifier", + "location" : [ 36, 7, 36, 9 ], + "name" : "bar" + }, + "args" : [ ] + }, + "member" : { + "kind" : "Identifier", + "location" : [ 36, 13, 36, 15 ], + "name" : "baz" + } + }, + "args" : [ { + "kind" : "ListExpr", + "location" : [ 36, 17, 36, 21 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 36, 18, 36, 18 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 36, 20, 36, 20 ], + "value" : 2 + } ] + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/def_func.py b/src/test/data/pa1/sample/def_func.py new file mode 100644 index 0000000..55e9c43 --- /dev/null +++ b/src/test/data/pa1/sample/def_func.py @@ -0,0 +1,4 @@ +def foo() -> int: + return 1 + +foo() diff --git a/src/test/data/pa1/sample/def_func.py.ast b/src/test/data/pa1/sample/def_func.py.ast new file mode 100644 index 0000000..00a7e65 --- /dev/null +++ b/src/test/data/pa1/sample/def_func.py.ast @@ -0,0 +1,48 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 6 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 14, 1, 16 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 12, 2, 12 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 3 ], + "name" : "foo" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/def_func_args.py b/src/test/data/pa1/sample/def_func_args.py new file mode 100644 index 0000000..196f504 --- /dev/null +++ b/src/test/data/pa1/sample/def_func_args.py @@ -0,0 +1,4 @@ +def foo(x:int, y:int) -> bool: + return x > y + +foo(1,2) diff --git a/src/test/data/pa1/sample/def_func_args.py.ast b/src/test/data/pa1/sample/def_func_args.py.ast new file mode 100644 index 0000000..77d9dc9 --- /dev/null +++ b/src/test/data/pa1/sample/def_func_args.py.ast @@ -0,0 +1,92 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 9 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 16, 1, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 16, 1, 16 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 18, 1, 20 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 26, 1, 29 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 16 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 2, 12, 2, 16 ], + "left" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 12 ], + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "Identifier", + "location" : [ 2, 16, 2, 16 ], + "name" : "y" + } + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 8 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 5, 4, 5 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 7, 4, 7 ], + "value" : 2 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/def_func_global.py b/src/test/data/pa1/sample/def_func_global.py new file mode 100644 index 0000000..12f9dfc --- /dev/null +++ b/src/test/data/pa1/sample/def_func_global.py @@ -0,0 +1,7 @@ +z:int = 0 + +def foo(x:int) -> bool: + global z + return x > z + +foo(1) diff --git a/src/test/data/pa1/sample/def_func_global.py.ast b/src/test/data/pa1/sample/def_func_global.py.ast new file mode 100644 index 0000000..736af77 --- /dev/null +++ b/src/test/data/pa1/sample/def_func_global.py.ast @@ -0,0 +1,105 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 7 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 3, 9, 3, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 11, 3, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 19, 3, 22 ], + "className" : "bool" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 4, 5, 4, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 4, 12, 4, 12 ], + "name" : "z" + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 16 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 5, 12, 5, 16 ], + "left" : { + "kind" : "Identifier", + "location" : [ 5, 12, 5, 12 ], + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 16 ], + "name" : "z" + } + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 6 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 1, 7, 6 ], + "function" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 7, 5, 7, 5 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/def_func_nested.py b/src/test/data/pa1/sample/def_func_nested.py new file mode 100644 index 0000000..835614e --- /dev/null +++ b/src/test/data/pa1/sample/def_func_nested.py @@ -0,0 +1,10 @@ + +def foo(x:int) -> bool: + a:int = 0 + b:int = 1 + def bar(y: int) -> int: + a:int = 2 + return y + return bar(x) > a + +foo(1) diff --git a/src/test/data/pa1/sample/def_func_nested.py.ast b/src/test/data/pa1/sample/def_func_nested.py.ast new file mode 100644 index 0000000..0024178 --- /dev/null +++ b/src/test/data/pa1/sample/def_func_nested.py.ast @@ -0,0 +1,187 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 10, 7 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 1, 8, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 9, 2, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 11, 2, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 19, 2, 22 ], + "className" : "bool" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 7, 3, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 13, 3, 13 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 7, 4, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 13, 4, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 5, 7, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 13, 5, 18 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 13, 5, 13 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 16, 5, 18 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 24, 5, 26 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 9, 6, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 9, 6, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 9, 6, 9 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 11, 6, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 17, 6, 17 ], + "value" : 2 + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 7, 9, 7, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 7, 16, 7, 16 ], + "name" : "y" + } + } ] + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 8, 5, 8, 21 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 8, 12, 8, 21 ], + "left" : { + "kind" : "CallExpr", + "location" : [ 8, 12, 8, 17 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 12, 8, 14 ], + "name" : "bar" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 8, 16, 8, 16 ], + "name" : "x" + } ] + }, + "operator" : ">", + "right" : { + "kind" : "Identifier", + "location" : [ 8, 21, 8, 21 ], + "name" : "a" + } + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 6 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 1, 10, 6 ], + "function" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 10, 5, 10, 5 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/def_func_nonlocal.py b/src/test/data/pa1/sample/def_func_nonlocal.py new file mode 100644 index 0000000..1304328 --- /dev/null +++ b/src/test/data/pa1/sample/def_func_nonlocal.py @@ -0,0 +1,11 @@ + +def foo(x:int) -> bool: + a:int = 0 + b:int = 1 + def bar(y: int) -> int: + nonlocal a + a = 2 + return y + return bar(x) > a + +foo(1) diff --git a/src/test/data/pa1/sample/def_func_nonlocal.py.ast b/src/test/data/pa1/sample/def_func_nonlocal.py.ast new file mode 100644 index 0000000..5c1e1de --- /dev/null +++ b/src/test/data/pa1/sample/def_func_nonlocal.py.ast @@ -0,0 +1,186 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 11, 7 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 1, 9, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 9, 2, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 11, 2, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 19, 2, 22 ], + "className" : "bool" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 7, 3, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 13, 3, 13 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 7, 4, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 13, 4, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 5, 8, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 13, 5, 18 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 13, 5, 13 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 16, 5, 18 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 24, 5, 26 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 6, 9, 6, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 6, 18, 6, 18 ], + "name" : "a" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 7, 9, 7, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "a" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 13, 7, 13 ], + "value" : 2 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 8, 9, 8, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 8, 16, 8, 16 ], + "name" : "y" + } + } ] + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 9, 5, 9, 21 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 9, 12, 9, 21 ], + "left" : { + "kind" : "CallExpr", + "location" : [ 9, 12, 9, 17 ], + "function" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 14 ], + "name" : "bar" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 9, 16, 9, 16 ], + "name" : "x" + } ] + }, + "operator" : ">", + "right" : { + "kind" : "Identifier", + "location" : [ 9, 21, 9, 21 ], + "name" : "a" + } + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 6 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 1, 11, 6 ], + "function" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 11, 5, 11, 5 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/expr_if.py b/src/test/data/pa1/sample/expr_if.py new file mode 100644 index 0000000..e9e9c26 --- /dev/null +++ b/src/test/data/pa1/sample/expr_if.py @@ -0,0 +1 @@ +3 if 1 > 2 else 4 diff --git a/src/test/data/pa1/sample/expr_if.py.ast b/src/test/data/pa1/sample/expr_if.py.ast new file mode 100644 index 0000000..0ed9a55 --- /dev/null +++ b/src/test/data/pa1/sample/expr_if.py.ast @@ -0,0 +1,43 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 18 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 17 ], + "expr" : { + "kind" : "IfExpr", + "location" : [ 1, 1, 1, 17 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 1, 6, 1, 10 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 6, 1, 6 ], + "value" : 1 + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 10, 1, 10 ], + "value" : 2 + } + }, + "thenExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "value" : 3 + }, + "elseExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 17, 1, 17 ], + "value" : 4 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/expr_if_chained.py b/src/test/data/pa1/sample/expr_if_chained.py new file mode 100644 index 0000000..4a7837e --- /dev/null +++ b/src/test/data/pa1/sample/expr_if_chained.py @@ -0,0 +1 @@ +3 if 1 > 2 else 4 if 1 < 0 else 5 diff --git a/src/test/data/pa1/sample/expr_if_chained.py.ast b/src/test/data/pa1/sample/expr_if_chained.py.ast new file mode 100644 index 0000000..2776da9 --- /dev/null +++ b/src/test/data/pa1/sample/expr_if_chained.py.ast @@ -0,0 +1,67 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 34 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 33 ], + "expr" : { + "kind" : "IfExpr", + "location" : [ 1, 1, 1, 33 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 1, 6, 1, 10 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 6, 1, 6 ], + "value" : 1 + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 10, 1, 10 ], + "value" : 2 + } + }, + "thenExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "value" : 3 + }, + "elseExpr" : { + "kind" : "IfExpr", + "location" : [ 1, 17, 1, 33 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 1, 22, 1, 26 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 22, 1, 22 ], + "value" : 1 + }, + "operator" : "<", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 26, 1, 26 ], + "value" : 0 + } + }, + "thenExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 17, 1, 17 ], + "value" : 4 + }, + "elseExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 33, 1, 33 ], + "value" : 5 + } + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/expr_index.py b/src/test/data/pa1/sample/expr_index.py new file mode 100644 index 0000000..8e95ff2 --- /dev/null +++ b/src/test/data/pa1/sample/expr_index.py @@ -0,0 +1 @@ +a + b[i][j] diff --git a/src/test/data/pa1/sample/expr_index.py.ast b/src/test/data/pa1/sample/expr_index.py.ast new file mode 100644 index 0000000..a5f97ee --- /dev/null +++ b/src/test/data/pa1/sample/expr_index.py.ast @@ -0,0 +1,47 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 12 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 11 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 11 ], + "left" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "a" + }, + "operator" : "+", + "right" : { + "kind" : "IndexExpr", + "location" : [ 1, 5, 1, 11 ], + "list" : { + "kind" : "IndexExpr", + "location" : [ 1, 5, 1, 8 ], + "list" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 5 ], + "name" : "b" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "i" + } + }, + "index" : { + "kind" : "Identifier", + "location" : [ 1, 10, 1, 10 ], + "name" : "j" + } + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/expr_plus.py b/src/test/data/pa1/sample/expr_plus.py new file mode 100644 index 0000000..8138b36 --- /dev/null +++ b/src/test/data/pa1/sample/expr_plus.py @@ -0,0 +1 @@ +1 + 2 + 3 diff --git a/src/test/data/pa1/sample/expr_plus.py.ast b/src/test/data/pa1/sample/expr_plus.py.ast new file mode 100644 index 0000000..f924e67 --- /dev/null +++ b/src/test/data/pa1/sample/expr_plus.py.ast @@ -0,0 +1,39 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 10 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 9 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 9 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 5 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "value" : 2 + } + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 3 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/expr_unary.py b/src/test/data/pa1/sample/expr_unary.py new file mode 100644 index 0000000..3a2e3f4 --- /dev/null +++ b/src/test/data/pa1/sample/expr_unary.py @@ -0,0 +1 @@ +-1 diff --git a/src/test/data/pa1/sample/expr_unary.py.ast b/src/test/data/pa1/sample/expr_unary.py.ast new file mode 100644 index 0000000..e4ef8d2 --- /dev/null +++ b/src/test/data/pa1/sample/expr_unary.py.ast @@ -0,0 +1,24 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 3 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 2 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 1, 1, 1, 2 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 2, 1, 2 ], + "value" : 1 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/global.py b/src/test/data/pa1/sample/global.py new file mode 100644 index 0000000..779d3bb --- /dev/null +++ b/src/test/data/pa1/sample/global.py @@ -0,0 +1,5 @@ +x:int = 1 + +x = 2 + +print(x) diff --git a/src/test/data/pa1/sample/global.py.ast b/src/test/data/pa1/sample/global.py.ast new file mode 100644 index 0000000..84b42b1 --- /dev/null +++ b/src/test/data/pa1/sample/global.py.ast @@ -0,0 +1,63 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 5, 3, 5 ], + "value" : 2 + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 8 ], + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 5, 7, 5, 7 ], + "name" : "x" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/literals.py b/src/test/data/pa1/sample/literals.py new file mode 100644 index 0000000..081863e --- /dev/null +++ b/src/test/data/pa1/sample/literals.py @@ -0,0 +1,7 @@ +True +False +1 +None +"This is a string" +[1, 2, 3] + diff --git a/src/test/data/pa1/sample/literals.py.ast b/src/test/data/pa1/sample/literals.py.ast new file mode 100644 index 0000000..d6fd3bc --- /dev/null +++ b/src/test/data/pa1/sample/literals.py.ast @@ -0,0 +1,70 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 10 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 4 ], + "expr" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 1, 1, 4 ], + "value" : true + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 5 ], + "expr" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 1, 2, 5 ], + "value" : false + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 1 ], + "expr" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 1, 3, 1 ], + "value" : 1 + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 4 ], + "expr" : { + "kind" : "NoneLiteral", + "location" : [ 4, 1, 4, 4 ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 18 ], + "expr" : { + "kind" : "StringLiteral", + "location" : [ 5, 1, 5, 18 ], + "value" : "This is a string" + } + }, { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 9 ], + "expr" : { + "kind" : "ListExpr", + "location" : [ 6, 1, 6, 9 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 2, 6, 2 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 5, 6, 5 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 8, 6, 8 ], + "value" : 3 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/stmt_call.py b/src/test/data/pa1/sample/stmt_call.py new file mode 100644 index 0000000..b917a72 --- /dev/null +++ b/src/test/data/pa1/sample/stmt_call.py @@ -0,0 +1 @@ +print(1) diff --git a/src/test/data/pa1/sample/stmt_call.py.ast b/src/test/data/pa1/sample/stmt_call.py.ast new file mode 100644 index 0000000..4d0ef38 --- /dev/null +++ b/src/test/data/pa1/sample/stmt_call.py.ast @@ -0,0 +1,28 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 9 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 1, 1, 1, 8 ], + "function" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 1, 7, 1, 7 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/stmt_for.py b/src/test/data/pa1/sample/stmt_for.py new file mode 100644 index 0000000..6f65c5f --- /dev/null +++ b/src/test/data/pa1/sample/stmt_for.py @@ -0,0 +1,4 @@ +x:int = 0 +for x in [1, 2, 3]: + print(x) + diff --git a/src/test/data/pa1/sample/stmt_for.py.ast b/src/test/data/pa1/sample/stmt_for.py.ast new file mode 100644 index 0000000..ba0847b --- /dev/null +++ b/src/test/data/pa1/sample/stmt_for.py.ast @@ -0,0 +1,76 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 2, 1, 5, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "iterable" : { + "kind" : "ListExpr", + "location" : [ 2, 10, 2, 18 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 2, 11, 2, 11 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 2, 14, 2, 14 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 2, 17, 2, 17 ], + "value" : 3 + } ] + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 3, 5, 3, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 3, 5, 3, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 3, 11, 3, 11 ], + "name" : "x" + } ] + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/stmt_if.py b/src/test/data/pa1/sample/stmt_if.py new file mode 100644 index 0000000..b87c003 --- /dev/null +++ b/src/test/data/pa1/sample/stmt_if.py @@ -0,0 +1,3 @@ +if True: + False + diff --git a/src/test/data/pa1/sample/stmt_if.py.ast b/src/test/data/pa1/sample/stmt_if.py.ast new file mode 100644 index 0000000..2b08a8f --- /dev/null +++ b/src/test/data/pa1/sample/stmt_if.py.ast @@ -0,0 +1,29 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 1 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 1, 1, 4, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 4, 1, 7 ], + "value" : true + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 2, 5, 2, 9 ], + "expr" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 5, 2, 9 ], + "value" : false + } + } ], + "elseBody" : [ ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/stmt_if_elif.py b/src/test/data/pa1/sample/stmt_if_elif.py new file mode 100644 index 0000000..7fa86dd --- /dev/null +++ b/src/test/data/pa1/sample/stmt_if_elif.py @@ -0,0 +1,6 @@ +if 1 > 2: + print(1) +elif 3 == 4: + print(2) +elif True: + print(3) diff --git a/src/test/data/pa1/sample/stmt_if_elif.py.ast b/src/test/data/pa1/sample/stmt_if_elif.py.ast new file mode 100644 index 0000000..11dcd2e --- /dev/null +++ b/src/test/data/pa1/sample/stmt_if_elif.py.ast @@ -0,0 +1,112 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 1 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 1, 1, 7, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 1, 4, 1, 8 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 4, 1, 4 ], + "value" : 1 + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 8, 1, 8 ], + "value" : 2 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 2, 5, 2, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 2, 5, 2, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 2, 11, 2, 11 ], + "value" : 1 + } ] + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 3, 1, 7, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 3, 6, 3, 11 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "value" : 3 + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 11, 3, 11 ], + "value" : 4 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 5, 4, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 11, 4, 11 ], + "value" : 2 + } ] + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 5, 1, 7, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 6, 5, 9 ], + "value" : true + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 6, 5, 6, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 5, 6, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 11, 6, 11 ], + "value" : 3 + } ] + } + } ], + "elseBody" : [ ] + } ] + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/stmt_if_elif_else.py b/src/test/data/pa1/sample/stmt_if_elif_else.py new file mode 100644 index 0000000..161d9d9 --- /dev/null +++ b/src/test/data/pa1/sample/stmt_if_elif_else.py @@ -0,0 +1,8 @@ +if 1 > 2: + print(1) +elif 3 == 4: + print(2) +elif True: + print(3) +else: + print(4) diff --git a/src/test/data/pa1/sample/stmt_if_elif_else.py.ast b/src/test/data/pa1/sample/stmt_if_elif_else.py.ast new file mode 100644 index 0000000..dc25855 --- /dev/null +++ b/src/test/data/pa1/sample/stmt_if_elif_else.py.ast @@ -0,0 +1,129 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 1 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 1, 1, 9, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 1, 4, 1, 8 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 4, 1, 4 ], + "value" : 1 + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 8, 1, 8 ], + "value" : 2 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 2, 5, 2, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 2, 5, 2, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 2, 11, 2, 11 ], + "value" : 1 + } ] + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 3, 1, 9, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 3, 6, 3, 11 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "value" : 3 + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 11, 3, 11 ], + "value" : 4 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 5, 4, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 11, 4, 11 ], + "value" : 2 + } ] + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 5, 1, 9, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 6, 5, 9 ], + "value" : true + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 6, 5, 6, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 5, 6, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 11, 6, 11 ], + "value" : 3 + } ] + } + } ], + "elseBody" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 5, 8, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 5, 8, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 9 ], + "name" : "print" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 8, 11, 8, 11 ], + "value" : 4 + } ] + } + } ] + } ] + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/stmt_ifelse.py b/src/test/data/pa1/sample/stmt_ifelse.py new file mode 100644 index 0000000..f138957 --- /dev/null +++ b/src/test/data/pa1/sample/stmt_ifelse.py @@ -0,0 +1,5 @@ +if True: + False +else: + True + diff --git a/src/test/data/pa1/sample/stmt_ifelse.py.ast b/src/test/data/pa1/sample/stmt_ifelse.py.ast new file mode 100644 index 0000000..8e23d16 --- /dev/null +++ b/src/test/data/pa1/sample/stmt_ifelse.py.ast @@ -0,0 +1,37 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 1 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 1, 1, 6, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 4, 1, 7 ], + "value" : true + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 2, 5, 2, 9 ], + "expr" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 5, 2, 9 ], + "value" : false + } + } ], + "elseBody" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 8 ], + "expr" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 5, 4, 8 ], + "value" : true + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/stmt_list_assign.py b/src/test/data/pa1/sample/stmt_list_assign.py new file mode 100644 index 0000000..e9e31d9 --- /dev/null +++ b/src/test/data/pa1/sample/stmt_list_assign.py @@ -0,0 +1,4 @@ +x:int = None + +x = [1, 2, 3] +x[0] = x[1] diff --git a/src/test/data/pa1/sample/stmt_list_assign.py.ast b/src/test/data/pa1/sample/stmt_list_assign.py.ast new file mode 100644 index 0000000..b65848c --- /dev/null +++ b/src/test/data/pa1/sample/stmt_list_assign.py.ast @@ -0,0 +1,88 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 12 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 12 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 9, 1, 12 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 3, 5, 3, 13 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 12, 3, 12 ], + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 11 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 4, 1, 4, 4 ], + "list" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 3, 4, 3 ], + "value" : 0 + } + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 4, 8, 4, 11 ], + "list" : { + "kind" : "Identifier", + "location" : [ 4, 8, 4, 8 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 10, 4, 10 ], + "value" : 1 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/sample/stmt_while.py b/src/test/data/pa1/sample/stmt_while.py new file mode 100644 index 0000000..1aaefd8 --- /dev/null +++ b/src/test/data/pa1/sample/stmt_while.py @@ -0,0 +1,3 @@ +while True: + pass + diff --git a/src/test/data/pa1/sample/stmt_while.py.ast b/src/test/data/pa1/sample/stmt_while.py.ast new file mode 100644 index 0000000..a564490 --- /dev/null +++ b/src/test/data/pa1/sample/stmt_while.py.ast @@ -0,0 +1,20 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 1 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 1, 1, 4, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 7, 1, 10 ], + "value" : true + }, + "body" : [ ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa1/student_contributed/bad.py b/src/test/data/pa1/student_contributed/bad.py new file mode 100644 index 0000000..95bf0f0 --- /dev/null +++ b/src/test/data/pa1/student_contributed/bad.py @@ -0,0 +1,39 @@ +1 2 3 + +def fun5(): + c = 6 + def fun6(): + print("Hello") + c = 4 + 5 # Indentation error + +# Global statements in between definitions +# (not allowed in the language manual) +if True: + if True: + print("Hello") + if True: + print("Maybe") + else: + print("World") +else: + print("Again") +else: + print("And Again") # Unmatched Else + +class Thor(object): + y:int = 0 + print("Right place?") # Statement in class + +class Stones(object): + y:int = 0 + def fun(x:int): + print("Right place?") + def bar(): + return 2+3 + print("Wrong Place") + +# Functions without `statements' +# (not allowed in the language manual) +def fun1(): + def fun2(): + print("Hello") diff --git a/src/test/data/pa1/student_contributed/good.py b/src/test/data/pa1/student_contributed/good.py new file mode 100644 index 0000000..874fa40 --- /dev/null +++ b/src/test/data/pa1/student_contributed/good.py @@ -0,0 +1,82 @@ +class Foo(object): + x:int = 0 + + def __init__(self:"Foo", x:int): + self.x = x + + def bar(y:int): + print("Hello World!",self.x+y) + y = 10 + +def get_stones(name:str)->str: + def map_name(nm:str)->str: + return stones[color.index(nm)] + color=["Red","Blue"] + stones=["Mind","Soul"] + return map_name(name) + +def funa(): + def funb(): + print("Hello") + funb() + +def fund(): + def fune(): + print("Hello") + c = 4 + 5 + +def funf(): + def fung(): + print("Hello") + c = 6 + c = 4 + 5 + + +if True: + if True: + if True: + print("Hello") +print("World") + +if True: + if True: + if True: + print("Hello") + print("World") + +if True: + if True: + if True: + print("Hello") + print("World") + +if True: + if True: + if True: + print("Hello") + else: + print("World") + +if True: + if True: + if True: + print("Hello") +else: + print("World") + + + +f = Foo(1) +print(f.x) +f.bar(4) + +a=[[[1],[2]],[[3],[4]]] +print(a[0][0][1]*a[1][1][0]) + +multiline_string="Hi World,\ +Here I am" + +expr_precedence = -a + b * (c + d) + +stone="Blue" +print(get_stones(stone)) \ No newline at end of file diff --git a/src/test/data/pa2/sample/ast_coverage.py b/src/test/data/pa2/sample/ast_coverage.py new file mode 100644 index 0000000..a27e796 --- /dev/null +++ b/src/test/data/pa2/sample/ast_coverage.py @@ -0,0 +1,38 @@ +count:int = 0 + +def foo(s: str) -> int: + return len(s) + +class bar(object): + p: bool = True + + def baz(self:"bar", xx: [int]) -> str: + global count + x:int = 0 + y:int = 1 + + def qux(y: int) -> object: + nonlocal x + if x > y: + x = -1 + + for x in xx: + self.p = x == 2 + + qux(0) # Yay! ChocoPy + + count = count + 1 + + while x <= 0: + if self.p: + xx[0] = xx[1] + self.p = not self.p + x = x + 1 + elif foo("Long"[0]) == 1: + self.p = self is None + + return "Nope" + +print(bar().baz([1,2])) + + diff --git a/src/test/data/pa2/sample/ast_coverage.py.ast b/src/test/data/pa2/sample/ast_coverage.py.ast new file mode 100644 index 0000000..18d47cd --- /dev/null +++ b/src/test/data/pa2/sample/ast_coverage.py.ast @@ -0,0 +1,627 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 36, 24 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "name" : "count" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 7, 1, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 13, 1, 13 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 4, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 3, 9, 3, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 12, 3, 14 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 20, 3, 22 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 4, 5, 4, 17 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 4, 12, 4, 17 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 12, 4, 14 ], + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 4, 16, 4, 16 ], + "name" : "s" + } ] + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 6, 1, 36, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 6, 7, 6, 9 ], + "name" : "bar" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 6, 11, 6, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "p" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 8, 7, 11 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 15, 7, 18 ], + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 34, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 9, 13, 9, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 18, 9, 22 ], + "className" : "bar" + } + }, { + "kind" : "TypedVar", + "location" : [ 9, 25, 9, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 25, 9, 26 ], + "name" : "xx" + }, + "type" : { + "kind" : "ListType", + "location" : [ 9, 29, 9, 33 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 9, 30, 9, 32 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 39, 9, 41 ], + "className" : "str" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 10, 9, 10, 20 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 10, 16, 10, 20 ], + "name" : "count" + } + }, { + "kind" : "VarDef", + "location" : [ 11, 9, 11, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 9, 11, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 11, 11, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 17, 11, 17 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 12, 9, 12, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 9, 12, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 9, 12, 9 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 11, 12, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 17, 12, 17 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 14, 9, 19, 8 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 13, 14, 15 ], + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 17, 14, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 17, 14, 17 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 20, 14, 22 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 28, 14, 33 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 15, 13, 15, 22 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 15, 22, 15, 22 ], + "name" : "x" + } + } ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 16, 13, 19, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 16, 16, 16, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 16 ], + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "Identifier", + "location" : [ 16, 20, 16, 20 ], + "name" : "y" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 17, 17, 17, 22 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 17, 17, 17 ], + "name" : "x" + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 17, 21, 17, 22 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 17, 22, 17, 22 ], + "value" : 1 + } + } + } ], + "elseBody" : [ ] + } ] + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 19, 9, 22, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 13, 19, 13 ], + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 19, 18, 19, 19 ], + "name" : "xx" + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 20, 13, 20, 27 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 20, 13, 20, 18 ], + "object" : { + "kind" : "Identifier", + "location" : [ 20, 13, 20, 16 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 18, 20, 18 ], + "name" : "p" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 20, 22, 20, 27 ], + "left" : { + "kind" : "Identifier", + "location" : [ 20, 22, 20, 22 ], + "name" : "x" + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 20, 27, 20, 27 ], + "value" : 2 + } + } + } ] + }, { + "kind" : "ExprStmt", + "location" : [ 22, 9, 22, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 22, 9, 22, 14 ], + "function" : { + "kind" : "Identifier", + "location" : [ 22, 9, 22, 11 ], + "name" : "qux" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 22, 13, 22, 13 ], + "value" : 0 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 24, 9, 24, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 24, 9, 24, 13 ], + "name" : "count" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 24, 17, 24, 25 ], + "left" : { + "kind" : "Identifier", + "location" : [ 24, 17, 24, 21 ], + "name" : "count" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 25, 24, 25 ], + "value" : 1 + } + } + }, { + "kind" : "WhileStmt", + "location" : [ 26, 9, 34, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 26, 15, 26, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 26, 15, 26, 15 ], + "name" : "x" + }, + "operator" : "<=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 26, 20, 26, 20 ], + "value" : 0 + } + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 27, 13, 34, 8 ], + "condition" : { + "kind" : "MemberExpr", + "location" : [ 27, 16, 27, 21 ], + "object" : { + "kind" : "Identifier", + "location" : [ 27, 16, 27, 19 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 21, 27, 21 ], + "name" : "p" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 28, 17, 28, 29 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 28, 17, 28, 21 ], + "list" : { + "kind" : "Identifier", + "location" : [ 28, 17, 28, 18 ], + "name" : "xx" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 28, 20, 28, 20 ], + "value" : 0 + } + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 28, 25, 28, 29 ], + "list" : { + "kind" : "Identifier", + "location" : [ 28, 25, 28, 26 ], + "name" : "xx" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 28, 28, 28, 28 ], + "value" : 1 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 29, 17, 29, 35 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 29, 17, 29, 22 ], + "object" : { + "kind" : "Identifier", + "location" : [ 29, 17, 29, 20 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 22, 29, 22 ], + "name" : "p" + } + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 29, 26, 29, 35 ], + "operator" : "not", + "operand" : { + "kind" : "MemberExpr", + "location" : [ 29, 30, 29, 35 ], + "object" : { + "kind" : "Identifier", + "location" : [ 29, 30, 29, 33 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 35, 29, 35 ], + "name" : "p" + } + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 30, 17, 30, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 30, 17, 30, 17 ], + "name" : "x" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 30, 21, 30, 25 ], + "left" : { + "kind" : "Identifier", + "location" : [ 30, 21, 30, 21 ], + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 30, 25, 30, 25 ], + "value" : 1 + } + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 31, 13, 34, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 31, 18, 31, 36 ], + "left" : { + "kind" : "CallExpr", + "location" : [ 31, 18, 31, 31 ], + "function" : { + "kind" : "Identifier", + "location" : [ 31, 18, 31, 20 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 31, 22, 31, 30 ], + "list" : { + "kind" : "StringLiteral", + "location" : [ 31, 22, 31, 27 ], + "value" : "Long" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 31, 29, 31, 29 ], + "value" : 0 + } + } ] + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 31, 36, 31, 36 ], + "value" : 1 + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 32, 17, 32, 37 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 32, 17, 32, 22 ], + "object" : { + "kind" : "Identifier", + "location" : [ 32, 17, 32, 20 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 32, 22, 32, 22 ], + "name" : "p" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 32, 26, 32, 37 ], + "left" : { + "kind" : "Identifier", + "location" : [ 32, 26, 32, 29 ], + "name" : "self" + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 32, 34, 32, 37 ] + } + } + } ], + "elseBody" : [ ] + } ] + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 34, 9, 34, 21 ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 34, 16, 34, 21 ], + "value" : "Nope" + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 36, 1, 36, 23 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 36, 1, 36, 23 ], + "function" : { + "kind" : "Identifier", + "location" : [ 36, 1, 36, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 36, 7, 36, 22 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 36, 7, 36, 15 ], + "object" : { + "kind" : "CallExpr", + "location" : [ 36, 7, 36, 11 ], + "function" : { + "kind" : "Identifier", + "location" : [ 36, 7, 36, 9 ], + "name" : "bar" + }, + "args" : [ ] + }, + "member" : { + "kind" : "Identifier", + "location" : [ 36, 13, 36, 15 ], + "name" : "baz" + } + }, + "args" : [ { + "kind" : "ListExpr", + "location" : [ 36, 17, 36, 21 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 36, 18, 36, 18 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 36, 20, 36, 20 ], + "value" : 2 + } ] + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/ast_coverage.py.ast.typed b/src/test/data/pa2/sample/ast_coverage.py.ast.typed new file mode 100644 index 0000000..709f895 --- /dev/null +++ b/src/test/data/pa2/sample/ast_coverage.py.ast.typed @@ -0,0 +1,952 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 36, 24 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 5 ], + "name" : "count" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 7, 1, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 13, 1, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 4, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 3, 9, 3, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 12, 3, 14 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 20, 3, 22 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 4, 5, 4, 17 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 4, 12, 4, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 12, 4, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "len" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 4, 16, 4, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + } ] + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 6, 1, 36, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 6, 7, 6, 9 ], + "name" : "bar" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 6, 11, 6, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 18 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "p" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 8, 7, 11 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 15, 7, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 34, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 9, 13, 9, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 18, 9, 22 ], + "className" : "bar" + } + }, { + "kind" : "TypedVar", + "location" : [ 9, 25, 9, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 25, 9, 26 ], + "name" : "xx" + }, + "type" : { + "kind" : "ListType", + "location" : [ 9, 29, 9, 33 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 9, 30, 9, 32 ], + "className" : "int" + } + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 39, 9, 41 ], + "className" : "str" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 10, 9, 10, 20 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 10, 16, 10, 20 ], + "name" : "count" + } + }, { + "kind" : "VarDef", + "location" : [ 11, 9, 11, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 9, 11, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 11, 11, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 17, 11, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 12, 9, 12, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 9, 12, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 9, 12, 9 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 11, 12, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 17, 12, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 14, 9, 19, 8 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 13, 14, 15 ], + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 17, 14, 22 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 17, 14, 17 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 20, 14, 22 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 28, 14, 33 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 15, 13, 15, 22 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 15, 22, 15, 22 ], + "name" : "x" + } + } ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 16, 13, 19, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 16, 16, 16, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : ">", + "right" : { + "kind" : "Identifier", + "location" : [ 16, 20, 16, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 17, 17, 17, 22 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 17, 17, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 17, 21, 17, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 17, 22, 17, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ], + "elseBody" : [ ] + } ] + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 19, 9, 22, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 13, 19, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 19, 18, 19, 19 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "xx" + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 20, 13, 20, 27 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 20, 13, 20, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 20, 13, 20, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bar" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 18, 20, 18 ], + "name" : "p" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 20, 22, 20, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 20, 22, 20, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 20, 27, 20, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } + } ] + }, { + "kind" : "ExprStmt", + "location" : [ 22, 9, 22, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 22, 9, 22, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 22, 9, 22, 11 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "qux" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 22, 13, 22, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 24, 9, 24, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 24, 9, 24, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "count" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 24, 17, 24, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 24, 17, 24, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "count" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 25, 24, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, { + "kind" : "WhileStmt", + "location" : [ 26, 9, 34, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 26, 15, 26, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 26, 15, 26, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "<=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 26, 20, 26, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, + "body" : [ { + "kind" : "IfStmt", + "location" : [ 27, 13, 34, 8 ], + "condition" : { + "kind" : "MemberExpr", + "location" : [ 27, 16, 27, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 27, 16, 27, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bar" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 21, 27, 21 ], + "name" : "p" + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 28, 17, 28, 29 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 28, 17, 28, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 28, 17, 28, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "xx" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 28, 20, 28, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 28, 25, 28, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 28, 25, 28, 26 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "xx" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 28, 28, 28, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 29, 17, 29, 35 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 29, 17, 29, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 29, 17, 29, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bar" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 22, 29, 22 ], + "name" : "p" + } + } ], + "value" : { + "kind" : "UnaryExpr", + "location" : [ 29, 26, 29, 35 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "operator" : "not", + "operand" : { + "kind" : "MemberExpr", + "location" : [ 29, 30, 29, 35 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 29, 30, 29, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bar" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 35, 29, 35 ], + "name" : "p" + } + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 30, 17, 30, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 30, 17, 30, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 30, 21, 30, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 30, 21, 30, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 30, 25, 30, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 31, 13, 34, 8 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 31, 18, 31, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "CallExpr", + "location" : [ 31, 18, 31, 31 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 31, 18, 31, 20 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "IndexExpr", + "location" : [ 31, 22, 31, 30 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "StringLiteral", + "location" : [ 31, 22, 31, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Long" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 31, 29, 31, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 31, 36, 31, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, + "thenBody" : [ { + "kind" : "AssignStmt", + "location" : [ 32, 17, 32, 37 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 32, 17, 32, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 32, 17, 32, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bar" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 32, 22, 32, 22 ], + "name" : "p" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 32, 26, 32, 37 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 32, 26, 32, 29 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bar" + }, + "name" : "self" + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 32, 34, 32, 37 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } + } ], + "elseBody" : [ ] + } ] + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 34, 9, 34, 21 ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 34, 16, 34, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Nope" + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 36, 1, 36, 23 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 36, 1, 36, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 36, 1, 36, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "MethodCallExpr", + "location" : [ 36, 7, 36, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 36, 7, 36, 15 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "bar" + }, { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "object" : { + "kind" : "CallExpr", + "location" : [ 36, 7, 36, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bar" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 36, 7, 36, 9 ], + "name" : "bar" + }, + "args" : [ ] + }, + "member" : { + "kind" : "Identifier", + "location" : [ 36, 13, 36, 15 ], + "name" : "baz" + } + }, + "args" : [ { + "kind" : "ListExpr", + "location" : [ 36, 17, 36, 21 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 36, 18, 36, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 36, 20, 36, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } ] + } ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_assign_expr.py b/src/test/data/pa2/sample/bad_assign_expr.py new file mode 100644 index 0000000..9e68917 --- /dev/null +++ b/src/test/data/pa2/sample/bad_assign_expr.py @@ -0,0 +1,11 @@ +x:int = 0 +y:int = 0 +z:bool = False + +x = z = 1 # Only one error here (assignment to `x = 1` should succeed) +x = y = None +x = y = [] +x = a = None +x = a = [] +x = y = True + diff --git a/src/test/data/pa2/sample/bad_assign_expr.py.ast b/src/test/data/pa2/sample/bad_assign_expr.py.ast new file mode 100644 index 0000000..6651bd2 --- /dev/null +++ b/src/test/data/pa2/sample/bad_assign_expr.py.ast @@ -0,0 +1,177 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 10, 13 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 6 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 10, 3, 14 ], + "value" : false + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 9, 5, 9 ], + "value" : 1 + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "y" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 6, 9, 6, 12 ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "y" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 9, 7, 10 ], + "elements" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "a" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 8, 9, 8, 12 ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "a" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 9, 9, 9, 10 ], + "elements" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 1, 10, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 10, 5, 10, 5 ], + "name" : "y" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 10, 9, 10, 12 ], + "value" : true + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_assign_expr.py.ast.typed b/src/test/data/pa2/sample/bad_assign_expr.py.ast.typed new file mode 100644 index 0000000..2f99fae --- /dev/null +++ b/src/test/data/pa2/sample/bad_assign_expr.py.ast.typed @@ -0,0 +1,301 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 10, 13 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 6 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 10, 3, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 9 ], + "errorMsg" : "Expected type `bool`; got type `int`", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 9, 5, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 12 ], + "errorMsg" : "Expected type `int`; got type ``", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 6, 9, 6, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 10 ], + "errorMsg" : "Expected type `int`; got type ``", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 9, 7, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 12 ], + "errorMsg" : "Expected type `int`; got type ``", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "errorMsg" : "Not a variable: a", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "a" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 8, 9, 8, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 10 ], + "errorMsg" : "Expected type `int`; got type ``", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "errorMsg" : "Not a variable: a", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "a" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 9, 9, 9, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 1, 10, 12 ], + "errorMsg" : "Expected type `int`; got type `bool`", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 10, 5, 10, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 10, 9, 10, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 5, 1, 5, 9 ], + "message" : "Expected type `bool`; got type `int`" + }, { + "kind" : "CompilerError", + "location" : [ 6, 1, 6, 12 ], + "message" : "Expected type `int`; got type ``" + }, { + "kind" : "CompilerError", + "location" : [ 7, 1, 7, 10 ], + "message" : "Expected type `int`; got type ``" + }, { + "kind" : "CompilerError", + "location" : [ 8, 1, 8, 12 ], + "message" : "Expected type `int`; got type ``" + }, { + "kind" : "CompilerError", + "location" : [ 8, 5, 8, 5 ], + "message" : "Not a variable: a" + }, { + "kind" : "CompilerError", + "location" : [ 9, 1, 9, 10 ], + "message" : "Expected type `int`; got type ``" + }, { + "kind" : "CompilerError", + "location" : [ 9, 5, 9, 5 ], + "message" : "Not a variable: a" + }, { + "kind" : "CompilerError", + "location" : [ 10, 1, 10, 12 ], + "message" : "Expected type `int`; got type `bool`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_attr.py b/src/test/data/pa2/sample/bad_class_attr.py new file mode 100644 index 0000000..b30eb7c --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_attr.py @@ -0,0 +1,13 @@ +class A(object): + x:int = 1 + + def foo(self:"A") -> int: + return 0 + +class B(A): + x:int = 2 # Bad + foo:str = "" # Bad + +A() + + diff --git a/src/test/data/pa2/sample/bad_class_attr.py.ast b/src/test/data/pa2/sample/bad_class_attr.py.ast new file mode 100644 index 0000000..ec25404 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_attr.py.ast @@ -0,0 +1,155 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 11, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 26, 4, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 16, 5, 16 ], + "value" : 0 + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 9, 23 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 8, 5, 8, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 8, 5, 8, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 7, 8, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 13, 8, 13 ], + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 7 ], + "name" : "foo" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 9, 9, 11 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 9, 15, 9, 16 ], + "value" : "" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 1, 11, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_attr.py.ast.typed b/src/test/data/pa2/sample/bad_class_attr.py.ast.typed new file mode 100644 index 0000000..5ea1e74 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_attr.py.ast.typed @@ -0,0 +1,165 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 11, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 26, 4, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 16, 5, 16 ], + "value" : 0 + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 9, 23 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 8, 5, 8, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 8, 5, 8, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "errorMsg" : "Cannot re-define attribute: x", + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 7, 8, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 13, 8, 13 ], + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 7 ], + "errorMsg" : "Cannot re-define attribute: foo", + "name" : "foo" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 9, 9, 11 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 9, 15, 9, 16 ], + "value" : "" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 1, 11, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 8, 5, 8, 5 ], + "message" : "Cannot re-define attribute: x" + }, { + "kind" : "CompilerError", + "location" : [ 9, 5, 9, 7 ], + "message" : "Cannot re-define attribute: foo" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_attr_type.py b/src/test/data/pa2/sample/bad_class_attr_type.py new file mode 100644 index 0000000..5a7bee7 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_attr_type.py @@ -0,0 +1,4 @@ +class A(object): + x:int = True + +A() diff --git a/src/test/data/pa2/sample/bad_class_attr_type.py.ast b/src/test/data/pa2/sample/bad_class_attr_type.py.ast new file mode 100644 index 0000000..6b9d252 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_attr_type.py.ast @@ -0,0 +1,60 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 13, 2, 16 ], + "value" : true + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_attr_type.py.ast.typed b/src/test/data/pa2/sample/bad_class_attr_type.py.ast.typed new file mode 100644 index 0000000..f0a9461 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_attr_type.py.ast.typed @@ -0,0 +1,73 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 16 ], + "errorMsg" : "Expected type `int`; got type `bool`", + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 13, 2, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 4, 1, 4, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 2, 5, 2, 16 ], + "message" : "Expected type `int`; got type `bool`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_init_override.py b/src/test/data/pa2/sample/bad_class_init_override.py new file mode 100644 index 0000000..ceb612c --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_init_override.py @@ -0,0 +1,8 @@ +class A(object): + x:int = 1 + + def __init__(self:"A", x:int): # Bad override + pass + +A(1) + diff --git a/src/test/data/pa2/sample/bad_class_init_override.py.ast b/src/test/data/pa2/sample/bad_class_init_override.py.ast new file mode 100644 index 0000000..bdd151d --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_init_override.py.ast @@ -0,0 +1,106 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 5 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 18, 4, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 18, 4, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 23, 4, 25 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 28, 4, 32 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 28, 4, 28 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 30, 4, 32 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 34, 4, 34 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 4 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 1, 7, 4 ], + "function" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "A" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 7, 3, 7, 3 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_init_override.py.ast.typed b/src/test/data/pa2/sample/bad_class_init_override.py.ast.typed new file mode 100644 index 0000000..9daa89c --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_init_override.py.ast.typed @@ -0,0 +1,111 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 5 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 16 ], + "errorMsg" : "Method overridden with different type signature: __init__", + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 18, 4, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 18, 4, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 23, 4, 25 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 28, 4, 32 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 28, 4, 28 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 30, 4, 32 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 34, 4, 34 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 4 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 1, 7, 4 ], + "function" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "A" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 7, 3, 7, 3 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 4, 9, 4, 16 ], + "message" : "Method overridden with different type signature: __init__" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_init_return.py b/src/test/data/pa2/sample/bad_class_init_return.py new file mode 100644 index 0000000..cc6eb34 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_init_return.py @@ -0,0 +1,5 @@ +class A(object): + def __init__(self:"A"): + return 1 # Bad + +A() diff --git a/src/test/data/pa2/sample/bad_class_init_return.py.ast b/src/test/data/pa2/sample/bad_class_init_return.py.ast new file mode 100644 index 0000000..24e972f --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_init_return.py.ast @@ -0,0 +1,75 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 5, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 5, 3, 23 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 18, 2, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 18, 2, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 23, 2, 25 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 27, 2, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 9, 3, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 16, 3, 16 ], + "value" : 1 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_init_return.py.ast.typed b/src/test/data/pa2/sample/bad_class_init_return.py.ast.typed new file mode 100644 index 0000000..cf0cde2 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_init_return.py.ast.typed @@ -0,0 +1,88 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 5, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 5, 3, 23 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 18, 2, 25 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 18, 2, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 23, 2, 25 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 27, 2, 27 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 9, 3, 16 ], + "errorMsg" : "Expected type ``; got type `int`", + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 16, 3, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 5, 1, 5, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 3, 9, 3, 16 ], + "message" : "Expected type ``; got type `int`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_member_expr.py b/src/test/data/pa2/sample/bad_class_member_expr.py new file mode 100644 index 0000000..bbfa1c1 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_member_expr.py @@ -0,0 +1,6 @@ +x:int = 0 +o:object = None + +x.foo +o.bar +o.baz = 1 diff --git a/src/test/data/pa2/sample/bad_class_member_expr.py.ast b/src/test/data/pa2/sample/bad_class_member_expr.py.ast new file mode 100644 index 0000000..4949375 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_member_expr.py.ast @@ -0,0 +1,110 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 10 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 12, 2, 15 ] + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 5 ], + "expr" : { + "kind" : "MemberExpr", + "location" : [ 4, 1, 4, 5 ], + "object" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "x" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 4, 3, 4, 5 ], + "name" : "foo" + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 5 ], + "expr" : { + "kind" : "MemberExpr", + "location" : [ 5, 1, 5, 5 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "o" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 3, 5, 5 ], + "name" : "bar" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 9 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 6, 1, 6, 5 ], + "object" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "o" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 6, 3, 6, 5 ], + "name" : "baz" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "value" : 1 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_member_expr.py.ast.typed b/src/test/data/pa2/sample/bad_class_member_expr.py.ast.typed new file mode 100644 index 0000000..4e570c0 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_member_expr.py.ast.typed @@ -0,0 +1,161 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 10 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 12, 2, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 5 ], + "expr" : { + "kind" : "MemberExpr", + "location" : [ 4, 1, 4, 5 ], + "errorMsg" : "There is no attribute named `foo` in class `int`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 4, 3, 4, 5 ], + "name" : "foo" + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 5 ], + "expr" : { + "kind" : "MemberExpr", + "location" : [ 5, 1, 5, 5 ], + "errorMsg" : "There is no attribute named `bar` in class `object`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "o" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 3, 5, 5 ], + "name" : "bar" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 9 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 6, 1, 6, 5 ], + "errorMsg" : "There is no attribute named `baz` in class `object`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "o" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 6, 3, 6, 5 ], + "name" : "baz" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 4, 1, 4, 5 ], + "message" : "There is no attribute named `foo` in class `int`" + }, { + "kind" : "CompilerError", + "location" : [ 5, 1, 5, 5 ], + "message" : "There is no attribute named `bar` in class `object`" + }, { + "kind" : "CompilerError", + "location" : [ 6, 1, 6, 5 ], + "message" : "There is no attribute named `baz` in class `object`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_method.py b/src/test/data/pa2/sample/bad_class_method.py new file mode 100644 index 0000000..d5a10d8 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_method.py @@ -0,0 +1,14 @@ +class A(object): + x:int = 1 + + def foo(self:"A") -> int: # OK + return 0 + + def bar() -> int: # Needs self param + return 0 + + def baz(self:int) -> int: # Incorrect self type + return 0 + +A() + diff --git a/src/test/data/pa2/sample/bad_class_method.py.ast b/src/test/data/pa2/sample/bad_class_method.py.ast new file mode 100644 index 0000000..7c359ef --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_method.py.ast @@ -0,0 +1,158 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 13, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 13, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 26, 4, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 16, 5, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 7, 5, 8, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 11 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 18, 7, 20 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 8, 9, 8, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 16, 8, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 10, 5, 11, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 11 ], + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 10, 13, 10, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 13, 10, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 18, 10, 20 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 10, 26, 10, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 11, 9, 11, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 16, 11, 16 ], + "value" : 0 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 13, 1, 13, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 13, 1, 13, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_method.py.ast.typed b/src/test/data/pa2/sample/bad_class_method.py.ast.typed new file mode 100644 index 0000000..9e08da8 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_method.py.ast.typed @@ -0,0 +1,168 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 13, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 13, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 18, 4, 20 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 26, 4, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 16, 5, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 7, 5, 8, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 11 ], + "errorMsg" : "First parameter of the following method must be of the enclosing class: bar", + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 18, 7, 20 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 8, 9, 8, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 16, 8, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 10, 5, 11, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 11 ], + "errorMsg" : "First parameter of the following method must be of the enclosing class: baz", + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 10, 13, 10, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 10, 13, 10, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 10, 18, 10, 20 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 10, 26, 10, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 11, 9, 11, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 16, 11, 16 ], + "value" : 0 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 13, 1, 13, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 13, 1, 13, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 7, 9, 7, 11 ], + "message" : "First parameter of the following method must be of the enclosing class: bar" + }, { + "kind" : "CompilerError", + "location" : [ 10, 9, 10, 11 ], + "message" : "First parameter of the following method must be of the enclosing class: baz" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_method_invoke.py b/src/test/data/pa2/sample/bad_class_method_invoke.py new file mode 100644 index 0000000..d5bb97c --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_method_invoke.py @@ -0,0 +1,30 @@ +class A(object): + x:int = 1 + + def get_A(self: "A") -> int: + return self.x + +class B(A): + def __init__(self: "B"): + pass + +class C(B): + z:bool = True + + def set_A(self: "C", val: int) -> object: + self.x = val + +a:A = None +b:B = None +c:C = None + +a = A() +b = B() +c = C() + +a.get_A(1) +b.get_Z() +c.set_A() +c.set_A(False) +c.set_A(None) + diff --git a/src/test/data/pa2/sample/bad_class_method_invoke.py.ast b/src/test/data/pa2/sample/bad_class_method_invoke.py.ast new file mode 100644 index 0000000..e01db23 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_method_invoke.py.ast @@ -0,0 +1,474 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 29, 14 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 13 ], + "name" : "get_A" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 15, 4, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 15, 4, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 21, 4, 23 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 29, 4, 31 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 21 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 5, 16, 5, 21 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 19 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 21, 5, 21 ], + "name" : "x" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 11, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 8, 5, 9, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 18, 8, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 18, 8, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 24, 8, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 28, 8, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 11, 1, 17, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 12, 5, 12, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 5, 12, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 7, 12, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 12, 14, 12, 17 ], + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 14, 5, 15, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 13 ], + "name" : "set_A" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 15, 14, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 15, 14, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 21, 14, 23 ], + "className" : "C" + } + }, { + "kind" : "TypedVar", + "location" : [ 14, 26, 14, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 26, 14, 28 ], + "name" : "val" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 31, 14, 33 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 39, 14, 44 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 9, 15, 20 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 15, 9, 15, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 14, 15, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 15, 18, 15, 20 ], + "name" : "val" + } + } ] + } ] + }, { + "kind" : "VarDef", + "location" : [ 17, 1, 17, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 17, 1, 17, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 3, 17, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 17, 7, 17, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 18, 1, 18, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 18, 1, 18, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 18, 3, 18, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 18, 7, 18, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 19, 1, 19, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 19, 1, 19, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 3, 19, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 19, 7, 19, 10 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 21, 1, 21, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 21, 1, 21, 1 ], + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 21, 5, 21, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 21, 5, 21, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 22, 1, 22, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 1 ], + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 22, 5, 22, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 23, 1, 23, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 23, 1, 23, 1 ], + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 23, 5, 23, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 23, 5, 23, 5 ], + "name" : "C" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 25, 1, 25, 10 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 25, 1, 25, 10 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 25, 1, 25, 7 ], + "object" : { + "kind" : "Identifier", + "location" : [ 25, 1, 25, 1 ], + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 25, 3, 25, 7 ], + "name" : "get_A" + } + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 25, 9, 25, 9 ], + "value" : 1 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 26, 1, 26, 9 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 26, 1, 26, 9 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 26, 1, 26, 7 ], + "object" : { + "kind" : "Identifier", + "location" : [ 26, 1, 26, 1 ], + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 26, 3, 26, 7 ], + "name" : "get_Z" + } + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 27, 1, 27, 9 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 27, 1, 27, 9 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 27, 1, 27, 7 ], + "object" : { + "kind" : "Identifier", + "location" : [ 27, 1, 27, 1 ], + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 3, 27, 7 ], + "name" : "set_A" + } + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 28, 1, 28, 14 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 28, 1, 28, 14 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 28, 1, 28, 7 ], + "object" : { + "kind" : "Identifier", + "location" : [ 28, 1, 28, 1 ], + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 28, 3, 28, 7 ], + "name" : "set_A" + } + }, + "args" : [ { + "kind" : "BooleanLiteral", + "location" : [ 28, 9, 28, 13 ], + "value" : false + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 29, 1, 29, 13 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 29, 1, 29, 13 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 29, 1, 29, 7 ], + "object" : { + "kind" : "Identifier", + "location" : [ 29, 1, 29, 1 ], + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 3, 29, 7 ], + "name" : "set_A" + } + }, + "args" : [ { + "kind" : "NoneLiteral", + "location" : [ 29, 9, 29, 12 ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_method_invoke.py.ast.typed b/src/test/data/pa2/sample/bad_class_method_invoke.py.ast.typed new file mode 100644 index 0000000..77867db --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_method_invoke.py.ast.typed @@ -0,0 +1,668 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 29, 14 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 13 ], + "name" : "get_A" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 15, 4, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 15, 4, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 21, 4, 23 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 29, 4, 31 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 21 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 5, 16, 5, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 21, 5, 21 ], + "name" : "x" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 11, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 8, 5, 9, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 18, 8, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 18, 8, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 24, 8, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 28, 8, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 11, 1, 17, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 12, 5, 12, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 5, 12, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 7, 12, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 12, 14, 12, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 14, 5, 15, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 13 ], + "name" : "set_A" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 15, 14, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 15, 14, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 21, 14, 23 ], + "className" : "C" + } + }, { + "kind" : "TypedVar", + "location" : [ 14, 26, 14, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 26, 14, 28 ], + "name" : "val" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 31, 14, 33 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 39, 14, 44 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 9, 15, 20 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 15, 9, 15, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 14, 15, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 15, 18, 15, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "val" + } + } ] + } ] + }, { + "kind" : "VarDef", + "location" : [ 17, 1, 17, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 17, 1, 17, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 3, 17, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 17, 7, 17, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 18, 1, 18, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 18, 1, 18, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 18, 3, 18, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 18, 7, 18, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 19, 1, 19, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 19, 1, 19, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 3, 19, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 19, 7, 19, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 21, 1, 21, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 21, 1, 21, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 21, 5, 21, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 21, 5, 21, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 22, 1, 22, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 22, 5, 22, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 23, 1, 23, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 23, 1, 23, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 23, 5, 23, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 23, 5, 23, 5 ], + "name" : "C" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 25, 1, 25, 10 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 25, 1, 25, 10 ], + "errorMsg" : "Expected 0 arguments; got 1", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 25, 1, 25, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "A" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 25, 1, 25, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 25, 3, 25, 7 ], + "name" : "get_A" + } + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 25, 9, 25, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 26, 1, 26, 9 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 26, 1, 26, 9 ], + "errorMsg" : "There is no method named `get_Z` in class `B`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 26, 1, 26, 7 ], + "object" : { + "kind" : "Identifier", + "location" : [ 26, 1, 26, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 26, 3, 26, 7 ], + "name" : "get_Z" + } + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 27, 1, 27, 9 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 27, 1, 27, 9 ], + "errorMsg" : "Expected 1 arguments; got 0", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 27, 1, 27, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "C" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 27, 1, 27, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 3, 27, 7 ], + "name" : "set_A" + } + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 28, 1, 28, 14 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 28, 1, 28, 14 ], + "errorMsg" : "Expected type `int`; got type `bool` in parameter 1", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 28, 1, 28, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "C" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 28, 1, 28, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 28, 3, 28, 7 ], + "name" : "set_A" + } + }, + "args" : [ { + "kind" : "BooleanLiteral", + "location" : [ 28, 9, 28, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 29, 1, 29, 13 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 29, 1, 29, 13 ], + "errorMsg" : "Expected type `int`; got type `` in parameter 1", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 29, 1, 29, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "C" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 29, 1, 29, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 29, 3, 29, 7 ], + "name" : "set_A" + } + }, + "args" : [ { + "kind" : "NoneLiteral", + "location" : [ 29, 9, 29, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 25, 1, 25, 10 ], + "message" : "Expected 0 arguments; got 1" + }, { + "kind" : "CompilerError", + "location" : [ 26, 1, 26, 9 ], + "message" : "There is no method named `get_Z` in class `B`" + }, { + "kind" : "CompilerError", + "location" : [ 27, 1, 27, 9 ], + "message" : "Expected 1 arguments; got 0" + }, { + "kind" : "CompilerError", + "location" : [ 28, 1, 28, 14 ], + "message" : "Expected type `int`; got type `bool` in parameter 1" + }, { + "kind" : "CompilerError", + "location" : [ 29, 1, 29, 13 ], + "message" : "Expected type `int`; got type `` in parameter 1" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_method_override.py b/src/test/data/pa2/sample/bad_class_method_override.py new file mode 100644 index 0000000..3f76544 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_method_override.py @@ -0,0 +1,33 @@ +class A(object): + def foo(self:"A", x:int) -> int: + return x + + def bar(self:"A", x:int) -> int: + return x + + def baz(self:"A", x:int) -> int: + return x + + def qux(self:"A", x:int) -> int: + return x + +class B(A): + + # OK override + def foo(self:"B", x:int) -> int: + return 0 + + # Bad override + def bar(self:"B") -> int: + return 0 + + # Bad override + def baz(self:"B", x:int) -> bool: + return True + + # Bad override + def qux(self:"B", x:bool) -> int: + return 0 + +B() + diff --git a/src/test/data/pa2/sample/bad_class_method_override.py.ast b/src/test/data/pa2/sample/bad_class_method_override.py.ast new file mode 100644 index 0000000..e82a758 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_method_override.py.ast @@ -0,0 +1,439 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 32, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 14, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 5, 3, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 13, 2, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 13, 2, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 18, 2, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 2, 23, 2, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 23, 2, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 25, 2, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 33, 2, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 9, 3, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 3, 16, 3, 16 ], + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 13, 5, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 13, 5, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 18, 5, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 5, 23, 5, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 23, 5, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 25, 5, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 33, 5, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 6, 9, 6, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 6, 16, 6, 16 ], + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 8, 5, 9, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 11 ], + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 13, 8, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 13, 8, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 18, 8, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 8, 23, 8, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 23, 8, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 25, 8, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 33, 8, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 9, 9, 9, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 9, 16, 9, 16 ], + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 11, 5, 12, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 11 ], + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 11, 13, 11, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 13, 11, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 18, 11, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 11, 23, 11, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 23, 11, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 25, 11, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 11, 33, 11, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 12, 9, 12, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 12, 16, 12, 16 ], + "name" : "x" + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 14, 1, 32, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 7, 14, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 17, 5, 18, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 17, 9, 17, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 17, 13, 17, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 13, 17, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 18, 17, 20 ], + "className" : "B" + } + }, { + "kind" : "TypedVar", + "location" : [ 17, 23, 17, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 23, 17, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 25, 17, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 17, 33, 17, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 18, 9, 18, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 18, 16, 18, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 21, 5, 22, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 21, 9, 21, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 21, 13, 21, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 21, 13, 21, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 21, 18, 21, 20 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 21, 26, 21, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 22, 9, 22, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 22, 16, 22, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 25, 5, 26, 20 ], + "name" : { + "kind" : "Identifier", + "location" : [ 25, 9, 25, 11 ], + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 25, 13, 25, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 25, 13, 25, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 25, 18, 25, 20 ], + "className" : "B" + } + }, { + "kind" : "TypedVar", + "location" : [ 25, 23, 25, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 25, 23, 25, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 25, 25, 25, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 25, 33, 25, 36 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 26, 9, 26, 19 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 26, 16, 26, 19 ], + "value" : true + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 29, 5, 30, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 29, 9, 29, 11 ], + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 29, 13, 29, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 13, 29, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 29, 18, 29, 20 ], + "className" : "B" + } + }, { + "kind" : "TypedVar", + "location" : [ 29, 23, 29, 28 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 23, 29, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 29, 25, 29, 28 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 29, 34, 29, 36 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 30, 9, 30, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 30, 16, 30, 16 ], + "value" : 0 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 32, 1, 32, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 32, 1, 32, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 32, 1, 32, 1 ], + "name" : "B" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_method_override.py.ast.typed b/src/test/data/pa2/sample/bad_class_method_override.py.ast.typed new file mode 100644 index 0000000..68716c5 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_method_override.py.ast.typed @@ -0,0 +1,454 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 32, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 14, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 5, 3, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 2, 13, 2, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 13, 2, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 18, 2, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 2, 23, 2, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 23, 2, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 25, 2, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 33, 2, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 9, 3, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 3, 16, 3, 16 ], + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 11 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 13, 5, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 13, 5, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 18, 5, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 5, 23, 5, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 23, 5, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 25, 5, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 33, 5, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 6, 9, 6, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 6, 16, 6, 16 ], + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 8, 5, 9, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 11 ], + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 13, 8, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 13, 8, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 18, 8, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 8, 23, 8, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 23, 8, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 25, 8, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 33, 8, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 9, 9, 9, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 9, 16, 9, 16 ], + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 11, 5, 12, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 11 ], + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 11, 13, 11, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 13, 11, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 18, 11, 20 ], + "className" : "A" + } + }, { + "kind" : "TypedVar", + "location" : [ 11, 23, 11, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 23, 11, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 25, 11, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 11, 33, 11, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 12, 9, 12, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 12, 16, 12, 16 ], + "name" : "x" + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 14, 1, 32, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 7, 14, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 17, 5, 18, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 17, 9, 17, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 17, 13, 17, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 13, 17, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 18, 17, 20 ], + "className" : "B" + } + }, { + "kind" : "TypedVar", + "location" : [ 17, 23, 17, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 23, 17, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 25, 17, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 17, 33, 17, 35 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 18, 9, 18, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 18, 16, 18, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 21, 5, 22, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 21, 9, 21, 11 ], + "errorMsg" : "Method overridden with different type signature: bar", + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 21, 13, 21, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 21, 13, 21, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 21, 18, 21, 20 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 21, 26, 21, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 22, 9, 22, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 22, 16, 22, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 25, 5, 26, 20 ], + "name" : { + "kind" : "Identifier", + "location" : [ 25, 9, 25, 11 ], + "errorMsg" : "Method overridden with different type signature: baz", + "name" : "baz" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 25, 13, 25, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 25, 13, 25, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 25, 18, 25, 20 ], + "className" : "B" + } + }, { + "kind" : "TypedVar", + "location" : [ 25, 23, 25, 27 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 25, 23, 25, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 25, 25, 25, 27 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 25, 33, 25, 36 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 26, 9, 26, 19 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 26, 16, 26, 19 ], + "value" : true + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 29, 5, 30, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 29, 9, 29, 11 ], + "errorMsg" : "Method overridden with different type signature: qux", + "name" : "qux" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 29, 13, 29, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 13, 29, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 29, 18, 29, 20 ], + "className" : "B" + } + }, { + "kind" : "TypedVar", + "location" : [ 29, 23, 29, 28 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 23, 29, 23 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 29, 25, 29, 28 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 29, 34, 29, 36 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 30, 9, 30, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 30, 16, 30, 16 ], + "value" : 0 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 32, 1, 32, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 32, 1, 32, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 32, 1, 32, 1 ], + "name" : "B" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 21, 9, 21, 11 ], + "message" : "Method overridden with different type signature: bar" + }, { + "kind" : "CompilerError", + "location" : [ 25, 9, 25, 11 ], + "message" : "Method overridden with different type signature: baz" + }, { + "kind" : "CompilerError", + "location" : [ 29, 9, 29, 11 ], + "message" : "Method overridden with different type signature: qux" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_method_override_attr.py b/src/test/data/pa2/sample/bad_class_method_override_attr.py new file mode 100644 index 0000000..52c01bd --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_method_override_attr.py @@ -0,0 +1,8 @@ +class A(object): + f:int = 3 + +class B(A): + def f(self:B) -> int: + return 3 + +A() diff --git a/src/test/data/pa2/sample/bad_class_method_override_attr.py.ast b/src/test/data/pa2/sample/bad_class_method_override_attr.py.ast new file mode 100644 index 0000000..1574d53 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_method_override_attr.py.ast @@ -0,0 +1,111 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 2, 2, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 2, 2, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 2, 2, 2 ], + "name" : "f" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 6 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 10, 2, 10 ], + "value" : 3 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 5, 2, 6, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 6, 5, 6 ], + "name" : "f" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 8, 5, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 8, 5, 11 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 13, 5, 13 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 19, 5, 21 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 6, 3, 6, 10 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 10, 6, 10 ], + "value" : 3 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_method_override_attr.py.ast.typed b/src/test/data/pa2/sample/bad_class_method_override_attr.py.ast.typed new file mode 100644 index 0000000..fcfb779 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_method_override_attr.py.ast.typed @@ -0,0 +1,116 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 2, 2, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 2, 2, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 2, 2, 2 ], + "name" : "f" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 6 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 10, 2, 10 ], + "value" : 3 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 5, 2, 6, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 6, 5, 6 ], + "errorMsg" : "Cannot re-define attribute: f", + "name" : "f" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 8, 5, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 8, 5, 11 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 13, 5, 13 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 19, 5, 21 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 6, 3, 6, 10 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 10, 6, 10 ], + "value" : 3 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 5, 6, 5, 6 ], + "message" : "Cannot re-define attribute: f" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_super.py b/src/test/data/pa2/sample/bad_class_super.py new file mode 100644 index 0000000..9701776 --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_super.py @@ -0,0 +1,15 @@ +# Super is not defined +class A(B): + x:int = 1 + +z:int = 2 + +# Super is not a class +class B(z): + x:int = 1 + +# Cannot extend special classes +class C(int): + x:int = 1 + +A() diff --git a/src/test/data/pa2/sample/bad_class_super.py.ast b/src/test/data/pa2/sample/bad_class_super.py.ast new file mode 100644 index 0000000..4aed62a --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_super.py.ast @@ -0,0 +1,154 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 15, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 2, 1, 3, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 7, 3, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 13, 3, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 5, 1, 5, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 1, 5, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 3, 5, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 9, 5, 9 ], + "value" : 2 + } + }, { + "kind" : "ClassDef", + "location" : [ 8, 1, 9, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "z" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 7, 9, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 13, 9, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 12, 1, 13, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 12, 7, 12, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 12, 9, 12, 11 ], + "name" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 13, 5, 13, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 5, 13, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 7, 13, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 13, 13, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 15, 1, 15, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 15, 1, 15, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_class_super.py.ast.typed b/src/test/data/pa2/sample/bad_class_super.py.ast.typed new file mode 100644 index 0000000..128383f --- /dev/null +++ b/src/test/data/pa2/sample/bad_class_super.py.ast.typed @@ -0,0 +1,169 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 15, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 2, 1, 3, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 9 ], + "errorMsg" : "Super-class not defined: B", + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 7, 3, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 13, 3, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 5, 1, 5, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 1, 5, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 3, 5, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 9, 5, 9 ], + "value" : 2 + } + }, { + "kind" : "ClassDef", + "location" : [ 8, 1, 9, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "errorMsg" : "Super-class must be a class: z", + "name" : "z" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 7, 9, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 13, 9, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 12, 1, 13, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 12, 7, 12, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 12, 9, 12, 11 ], + "errorMsg" : "Cannot extend special class: int", + "name" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 13, 5, 13, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 5, 13, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 7, 13, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 13, 13, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 15, 1, 15, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 15, 1, 15, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 2, 9, 2, 9 ], + "message" : "Super-class not defined: B" + }, { + "kind" : "CompilerError", + "location" : [ 8, 9, 8, 9 ], + "message" : "Super-class must be a class: z" + }, { + "kind" : "CompilerError", + "location" : [ 12, 9, 12, 11 ], + "message" : "Cannot extend special class: int" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_concat.py b/src/test/data/pa2/sample/bad_concat.py new file mode 100644 index 0000000..56e7802 --- /dev/null +++ b/src/test/data/pa2/sample/bad_concat.py @@ -0,0 +1,3 @@ +"Hello" + ["World"] +1 + [2] +[] + [1] diff --git a/src/test/data/pa2/sample/bad_concat.py.ast b/src/test/data/pa2/sample/bad_concat.py.ast new file mode 100644 index 0000000..0fdfbd6 --- /dev/null +++ b/src/test/data/pa2/sample/bad_concat.py.ast @@ -0,0 +1,77 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 9 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 19 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 19 ], + "left" : { + "kind" : "StringLiteral", + "location" : [ 1, 1, 1, 7 ], + "value" : "Hello" + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 1, 11, 1, 19 ], + "elements" : [ { + "kind" : "StringLiteral", + "location" : [ 1, 12, 1, 18 ], + "value" : "World" + } ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 7 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 2, 1, 2, 7 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 1, 2, 1 ], + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 2, 5, 2, 7 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 2, 6, 2, 6 ], + "value" : 2 + } ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 8 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 8 ], + "left" : { + "kind" : "ListExpr", + "location" : [ 3, 1, 3, 2 ], + "elements" : [ ] + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 3, 6, 3, 8 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 7, 3, 7 ], + "value" : 1 + } ] + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_concat.py.ast.typed b/src/test/data/pa2/sample/bad_concat.py.ast.typed new file mode 100644 index 0000000..60f5b0c --- /dev/null +++ b/src/test/data/pa2/sample/bad_concat.py.ast.typed @@ -0,0 +1,149 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 9 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 19 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 19 ], + "errorMsg" : "Cannot apply operator `+` on types `str` and `[str]`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "left" : { + "kind" : "StringLiteral", + "location" : [ 1, 1, 1, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 1, 11, 1, 19 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "str" + } + }, + "elements" : [ { + "kind" : "StringLiteral", + "location" : [ 1, 12, 1, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "World" + } ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 7 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 2, 1, 2, 7 ], + "errorMsg" : "Cannot apply operator `+` on types `int` and `[int]`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 1, 2, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 2, 5, 2, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 2, 6, 2, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 8 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 8 ], + "errorMsg" : "Cannot apply operator `+` on types `` and `[int]`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "left" : { + "kind" : "ListExpr", + "location" : [ 3, 1, 3, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 3, 6, 3, 8 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 7, 3, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } ] + } + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 1, 1, 19 ], + "message" : "Cannot apply operator `+` on types `str` and `[str]`" + }, { + "kind" : "CompilerError", + "location" : [ 2, 1, 2, 7 ], + "message" : "Cannot apply operator `+` on types `int` and `[int]`" + }, { + "kind" : "CompilerError", + "location" : [ 3, 1, 3, 8 ], + "message" : "Cannot apply operator `+` on types `` and `[int]`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_duplicate_class.py b/src/test/data/pa2/sample/bad_duplicate_class.py new file mode 100644 index 0000000..8f8dd05 --- /dev/null +++ b/src/test/data/pa2/sample/bad_duplicate_class.py @@ -0,0 +1,18 @@ +class A(object): + x:int = 1 + +z:bool = True + +# Duplicate +class A(object): + x:int = 1 + +# Duplicate +class str(object): + x:int = 1 + +# Duplicate +class z(object): + x:int = 1 + +A() diff --git a/src/test/data/pa2/sample/bad_duplicate_class.py.ast b/src/test/data/pa2/sample/bad_duplicate_class.py.ast new file mode 100644 index 0000000..547360b --- /dev/null +++ b/src/test/data/pa2/sample/bad_duplicate_class.py.ast @@ -0,0 +1,190 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 18, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 6 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 10, 4, 13 ], + "value" : true + } + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 8, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 8, 5, 8, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 8, 5, 8, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 7, 8, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 13, 8, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 11, 1, 12, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 9 ], + "name" : "str" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 11, 11, 11, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 12, 5, 12, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 5, 12, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 7, 12, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 13, 12, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 15, 1, 16, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 7 ], + "name" : "z" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 16, 5, 16, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 16, 5, 16, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 7, 16, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 16, 13, 16, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 18, 1, 18, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 18, 1, 18, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_duplicate_class.py.ast.typed b/src/test/data/pa2/sample/bad_duplicate_class.py.ast.typed new file mode 100644 index 0000000..3791ada --- /dev/null +++ b/src/test/data/pa2/sample/bad_duplicate_class.py.ast.typed @@ -0,0 +1,205 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 18, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 6 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 10, 4, 13 ], + "value" : true + } + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 8, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: A", + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 8, 5, 8, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 8, 5, 8, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 7, 8, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 13, 8, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 11, 1, 12, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 9 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: str", + "name" : "str" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 11, 11, 11, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 12, 5, 12, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 5, 12, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 7, 12, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 13, 12, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 15, 1, 16, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 7 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: z", + "name" : "z" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 16, 5, 16, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 16, 5, 16, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 7, 16, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 16, 13, 16, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 18, 1, 18, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 18, 1, 18, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 7, 7, 7, 7 ], + "message" : "Duplicate declaration of identifier in same scope: A" + }, { + "kind" : "CompilerError", + "location" : [ 11, 7, 11, 9 ], + "message" : "Duplicate declaration of identifier in same scope: str" + }, { + "kind" : "CompilerError", + "location" : [ 15, 7, 15, 7 ], + "message" : "Duplicate declaration of identifier in same scope: z" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_duplicate_class_member.py b/src/test/data/pa2/sample/bad_duplicate_class_member.py new file mode 100644 index 0000000..7a5026f --- /dev/null +++ b/src/test/data/pa2/sample/bad_duplicate_class_member.py @@ -0,0 +1,12 @@ +class A(object): + x:int = 1 # OK + + def foo(self: "A") -> int: # OK + return 0 + + x:int = 1 # Duplicate + + def foo(self: "A") -> int: # Duplicate + return 0 + +A() diff --git a/src/test/data/pa2/sample/bad_duplicate_class_member.py.ast b/src/test/data/pa2/sample/bad_duplicate_class_member.py.ast new file mode 100644 index 0000000..58b0ddb --- /dev/null +++ b/src/test/data/pa2/sample/bad_duplicate_class_member.py.ast @@ -0,0 +1,156 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 12, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 12, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 19, 4, 21 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 27, 4, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 16, 5, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 7, 7, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 13, 7, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 10, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 9, 13, 9, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 19, 9, 21 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 27, 9, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 10, 9, 10, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 16, 10, 16 ], + "value" : 0 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 12, 1, 12, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 12, 1, 12, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_duplicate_class_member.py.ast.typed b/src/test/data/pa2/sample/bad_duplicate_class_member.py.ast.typed new file mode 100644 index 0000000..cb97ac4 --- /dev/null +++ b/src/test/data/pa2/sample/bad_duplicate_class_member.py.ast.typed @@ -0,0 +1,166 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 12, 4 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 12, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 11 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 13, 4, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 13, 4, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 19, 4, 21 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 27, 4, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 16, 5, 16 ], + "value" : 0 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: x", + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 7, 7, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 13, 7, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 10, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: foo", + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 9, 13, 9, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 19, 9, 21 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 27, 9, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 10, 9, 10, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 16, 10, 16 ], + "value" : 0 + } + } ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 12, 1, 12, 3 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 12, 1, 12, 3 ], + "function" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "A" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 7, 5, 7, 5 ], + "message" : "Duplicate declaration of identifier in same scope: x" + }, { + "kind" : "CompilerError", + "location" : [ 9, 9, 9, 11 ], + "message" : "Duplicate declaration of identifier in same scope: foo" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_duplicate_global.py b/src/test/data/pa2/sample/bad_duplicate_global.py new file mode 100644 index 0000000..4b293ea --- /dev/null +++ b/src/test/data/pa2/sample/bad_duplicate_global.py @@ -0,0 +1,18 @@ +x:int = 1 + +def foo() -> object: + pass + +# `foo` cannot be redefined in the same scope +def foo() -> object: + pass + +# `print` cannot be redefined in the same scope +def print(val:object) -> object: + pass + +# `x` cannot be redefined in the same scope +x:int = 2 + + +foo() diff --git a/src/test/data/pa2/sample/bad_duplicate_global.py.ast b/src/test/data/pa2/sample/bad_duplicate_global.py.ast new file mode 100644 index 0000000..76e6707 --- /dev/null +++ b/src/test/data/pa2/sample/bad_duplicate_global.py.ast @@ -0,0 +1,129 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 18, 6 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 4, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 7 ], + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 14, 3, 19 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 7, 1, 8, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 7 ], + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 14, 7, 19 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 11, 1, 12, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 9 ], + "name" : "print" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 11, 11, 11, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 11, 11, 13 ], + "name" : "val" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 15, 11, 20 ], + "className" : "object" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 11, 26, 11, 31 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 15, 1, 15, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 15, 1, 15, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 15, 3, 15, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 15, 9, 15, 9 ], + "value" : 2 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 18, 1, 18, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 18, 1, 18, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 3 ], + "name" : "foo" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_duplicate_global.py.ast.typed b/src/test/data/pa2/sample/bad_duplicate_global.py.ast.typed new file mode 100644 index 0000000..7d72792 --- /dev/null +++ b/src/test/data/pa2/sample/bad_duplicate_global.py.ast.typed @@ -0,0 +1,144 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 18, 6 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 4, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 7 ], + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 14, 3, 19 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 7, 1, 8, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 7 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: foo", + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 14, 7, 19 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 11, 1, 12, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 9 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: print", + "name" : "print" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 11, 11, 11, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 11, 11, 13 ], + "name" : "val" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 15, 11, 20 ], + "className" : "object" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 11, 26, 11, 31 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 15, 1, 15, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 15, 1, 15, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: x", + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 15, 3, 15, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 15, 9, 15, 9 ], + "value" : 2 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 18, 1, 18, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 18, 1, 18, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 3 ], + "name" : "foo" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 7, 5, 7, 7 ], + "message" : "Duplicate declaration of identifier in same scope: foo" + }, { + "kind" : "CompilerError", + "location" : [ 11, 5, 11, 9 ], + "message" : "Duplicate declaration of identifier in same scope: print" + }, { + "kind" : "CompilerError", + "location" : [ 15, 1, 15, 1 ], + "message" : "Duplicate declaration of identifier in same scope: x" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_duplicate_global_2.py b/src/test/data/pa2/sample/bad_duplicate_global_2.py new file mode 100644 index 0000000..62ee129 --- /dev/null +++ b/src/test/data/pa2/sample/bad_duplicate_global_2.py @@ -0,0 +1,6 @@ +class x(object): + pass + +x:int = 5 + +pass diff --git a/src/test/data/pa2/sample/bad_duplicate_global_2.py.ast b/src/test/data/pa2/sample/bad_duplicate_global_2.py.ast new file mode 100644 index 0000000..c3a5985 --- /dev/null +++ b/src/test/data/pa2/sample/bad_duplicate_global_2.py.ast @@ -0,0 +1,47 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 5 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "x" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "value" : 5 + } + } ], + "statements" : [ ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_duplicate_global_2.py.ast.typed b/src/test/data/pa2/sample/bad_duplicate_global_2.py.ast.typed new file mode 100644 index 0000000..506a6ca --- /dev/null +++ b/src/test/data/pa2/sample/bad_duplicate_global_2.py.ast.typed @@ -0,0 +1,52 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 5 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "x" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: x", + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "value" : 5 + } + } ], + "statements" : [ ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 4, 1, 4, 1 ], + "message" : "Duplicate declaration of identifier in same scope: x" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_duplicate_local.py b/src/test/data/pa2/sample/bad_duplicate_local.py new file mode 100644 index 0000000..bb25faf --- /dev/null +++ b/src/test/data/pa2/sample/bad_duplicate_local.py @@ -0,0 +1,21 @@ +x:int = 1 +y:int = 2 +z:int = 3 + +def foo(x:int) -> object: + y:int = 4 # OK + x:int = 5 # Duplicate declaration + global z # OK + global y # Duplicate declaration + + def x() -> int: # Duplicate declaration + return 0 + + pass + +def bar(x:int, x:int) -> int: # Duplicate params + return x + + +foo(1) + diff --git a/src/test/data/pa2/sample/bad_duplicate_local.py.ast b/src/test/data/pa2/sample/bad_duplicate_local.py.ast new file mode 100644 index 0000000..53f6fad --- /dev/null +++ b/src/test/data/pa2/sample/bad_duplicate_local.py.ast @@ -0,0 +1,257 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 20, 7 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "value" : 3 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 14, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 9, 5, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 11, 5, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 19, 5, 24 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "value" : 4 + } + }, { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 7, 7, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 13, 7, 13 ], + "value" : 5 + } + }, { + "kind" : "GlobalDecl", + "location" : [ 8, 5, 8, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 8, 12, 8, 12 ], + "name" : "z" + } + }, { + "kind" : "GlobalDecl", + "location" : [ 9, 5, 9, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 12 ], + "name" : "y" + } + }, { + "kind" : "FuncDef", + "location" : [ 11, 5, 12, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "x" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 11, 16, 11, 18 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 12, 9, 12, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 16, 12, 16 ], + "value" : 0 + } + } ] + } ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 16, 1, 17, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 7 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 16, 9, 16, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 9, 16, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 11, 16, 13 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 16, 16, 16, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 16 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 18, 16, 20 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 16, 26, 16, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 17, 5, 17, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 17, 12, 17, 12 ], + "name" : "x" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 20, 1, 20, 6 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 20, 1, 20, 6 ], + "function" : { + "kind" : "Identifier", + "location" : [ 20, 1, 20, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 20, 5, 20, 5 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_duplicate_local.py.ast.typed b/src/test/data/pa2/sample/bad_duplicate_local.py.ast.typed new file mode 100644 index 0000000..1559865 --- /dev/null +++ b/src/test/data/pa2/sample/bad_duplicate_local.py.ast.typed @@ -0,0 +1,277 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 20, 7 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "value" : 3 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 14, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 9, 5, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 11, 5, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 19, 5, 24 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "value" : 4 + } + }, { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: x", + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 7, 7, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 13, 7, 13 ], + "value" : 5 + } + }, { + "kind" : "GlobalDecl", + "location" : [ 8, 5, 8, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 8, 12, 8, 12 ], + "name" : "z" + } + }, { + "kind" : "GlobalDecl", + "location" : [ 9, 5, 9, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 12 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: y", + "name" : "y" + } + }, { + "kind" : "FuncDef", + "location" : [ 11, 5, 12, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: x", + "name" : "x" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 11, 16, 11, 18 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 12, 9, 12, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 16, 12, 16 ], + "value" : 0 + } + } ] + } ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 16, 1, 17, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 7 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 16, 9, 16, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 9, 16, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 11, 16, 13 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 16, 16, 16, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 16, 16, 16, 16 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: x", + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 16, 18, 16, 20 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 16, 26, 16, 28 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 17, 5, 17, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 17, 12, 17, 12 ], + "name" : "x" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 20, 1, 20, 6 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 20, 1, 20, 6 ], + "function" : { + "kind" : "Identifier", + "location" : [ 20, 1, 20, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 20, 5, 20, 5 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 7, 5, 7, 5 ], + "message" : "Duplicate declaration of identifier in same scope: x" + }, { + "kind" : "CompilerError", + "location" : [ 9, 12, 9, 12 ], + "message" : "Duplicate declaration of identifier in same scope: y" + }, { + "kind" : "CompilerError", + "location" : [ 11, 9, 11, 9 ], + "message" : "Duplicate declaration of identifier in same scope: x" + }, { + "kind" : "CompilerError", + "location" : [ 16, 16, 16, 16 ], + "message" : "Duplicate declaration of identifier in same scope: x" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_expr_binary.py b/src/test/data/pa2/sample/bad_expr_binary.py new file mode 100644 index 0000000..1668849 --- /dev/null +++ b/src/test/data/pa2/sample/bad_expr_binary.py @@ -0,0 +1,13 @@ +1 and 2 +1 or 2 +True - False +True < False +1 + True +False + 0 +1 == True +False != 0 +1 is 1 +True is False +None + None +None == None +None is None diff --git a/src/test/data/pa2/sample/bad_expr_binary.py.ast b/src/test/data/pa2/sample/bad_expr_binary.py.ast new file mode 100644 index 0000000..c55893a --- /dev/null +++ b/src/test/data/pa2/sample/bad_expr_binary.py.ast @@ -0,0 +1,239 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 13, 13 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 7 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 7 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "value" : 1 + }, + "operator" : "and", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 7, 1, 7 ], + "value" : 2 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 6 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 2, 1, 2, 6 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 1, 2, 1 ], + "value" : 1 + }, + "operator" : "or", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 6, 2, 6 ], + "value" : 2 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 12 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 12 ], + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 1, 3, 4 ], + "value" : true + }, + "operator" : "-", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 8, 3, 12 ], + "value" : false + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 12 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 4, 1, 4, 12 ], + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 1, 4, 4 ], + "value" : true + }, + "operator" : "<", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 8, 4, 12 ], + "value" : false + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 8 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 5, 1, 5, 8 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 1, 5, 1 ], + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 5, 5, 8 ], + "value" : true + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 9 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 6, 1, 6, 9 ], + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 6, 1, 6, 5 ], + "value" : false + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "value" : 0 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 9 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 7, 1, 7, 9 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 1, 7, 1 ], + "value" : 1 + }, + "operator" : "==", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 6, 7, 9 ], + "value" : true + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 10 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 8, 1, 8, 10 ], + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 8, 1, 8, 5 ], + "value" : false + }, + "operator" : "!=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 10, 8, 10 ], + "value" : 0 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 6 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 9, 1, 9, 6 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 1, 9, 1 ], + "value" : 1 + }, + "operator" : "is", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 6, 9, 6 ], + "value" : 1 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 13 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 10, 1, 10, 13 ], + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 10, 1, 10, 4 ], + "value" : true + }, + "operator" : "is", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 10, 9, 10, 13 ], + "value" : false + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 11 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 11, 1, 11, 11 ], + "left" : { + "kind" : "NoneLiteral", + "location" : [ 11, 1, 11, 4 ] + }, + "operator" : "+", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 11, 8, 11, 11 ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 12, 1, 12, 12 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 12, 1, 12, 12 ], + "left" : { + "kind" : "NoneLiteral", + "location" : [ 12, 1, 12, 4 ] + }, + "operator" : "==", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 12, 9, 12, 12 ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 13, 1, 13, 12 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 13, 1, 13, 12 ], + "left" : { + "kind" : "NoneLiteral", + "location" : [ 13, 1, 13, 4 ] + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 13, 9, 13, 12 ] + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_expr_binary.py.ast.typed b/src/test/data/pa2/sample/bad_expr_binary.py.ast.typed new file mode 100644 index 0000000..851cc92 --- /dev/null +++ b/src/test/data/pa2/sample/bad_expr_binary.py.ast.typed @@ -0,0 +1,455 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 13, 13 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 7 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 7 ], + "errorMsg" : "Cannot apply operator `and` on types `int` and `int`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "and", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 7, 1, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 6 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 2, 1, 2, 6 ], + "errorMsg" : "Cannot apply operator `or` on types `int` and `int`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 1, 2, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "or", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 6, 2, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 12 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 12 ], + "errorMsg" : "Cannot apply operator `-` on types `bool` and `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 1, 3, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "operator" : "-", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 8, 3, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 12 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 4, 1, 4, 12 ], + "errorMsg" : "Cannot apply operator `<` on types `bool` and `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 1, 4, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "operator" : "<", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 8, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 8 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 5, 1, 5, 8 ], + "errorMsg" : "Cannot apply operator `+` on types `int` and `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 5, 5, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 9 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 6, 1, 6, 9 ], + "errorMsg" : "Cannot apply operator `+` on types `bool` and `int`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 6, 1, 6, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 9 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 7, 1, 7, 9 ], + "errorMsg" : "Cannot apply operator `==` on types `int` and `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "==", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 6, 7, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 10 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 8, 1, 8, 10 ], + "errorMsg" : "Cannot apply operator `!=` on types `bool` and `int`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 8, 1, 8, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, + "operator" : "!=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 10, 8, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 6 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 9, 1, 9, 6 ], + "errorMsg" : "Cannot apply operator `is` on types `int` and `int`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 1, 9, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "is", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 6, 9, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 13 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 10, 1, 10, 13 ], + "errorMsg" : "Cannot apply operator `is` on types `bool` and `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 10, 1, 10, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "operator" : "is", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 10, 9, 10, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 11 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 11, 1, 11, 11 ], + "errorMsg" : "Cannot apply operator `+` on types `` and ``", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "left" : { + "kind" : "NoneLiteral", + "location" : [ 11, 1, 11, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "operator" : "+", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 11, 8, 11, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 12, 1, 12, 12 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 12, 1, 12, 12 ], + "errorMsg" : "Cannot apply operator `==` on types `` and ``", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "NoneLiteral", + "location" : [ 12, 1, 12, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "operator" : "==", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 12, 9, 12, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 13, 1, 13, 12 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 13, 1, 13, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "NoneLiteral", + "location" : [ 13, 1, 13, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "operator" : "is", + "right" : { + "kind" : "NoneLiteral", + "location" : [ 13, 9, 13, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 1, 1, 7 ], + "message" : "Cannot apply operator `and` on types `int` and `int`" + }, { + "kind" : "CompilerError", + "location" : [ 2, 1, 2, 6 ], + "message" : "Cannot apply operator `or` on types `int` and `int`" + }, { + "kind" : "CompilerError", + "location" : [ 3, 1, 3, 12 ], + "message" : "Cannot apply operator `-` on types `bool` and `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 4, 1, 4, 12 ], + "message" : "Cannot apply operator `<` on types `bool` and `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 5, 1, 5, 8 ], + "message" : "Cannot apply operator `+` on types `int` and `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 6, 1, 6, 9 ], + "message" : "Cannot apply operator `+` on types `bool` and `int`" + }, { + "kind" : "CompilerError", + "location" : [ 7, 1, 7, 9 ], + "message" : "Cannot apply operator `==` on types `int` and `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 8, 1, 8, 10 ], + "message" : "Cannot apply operator `!=` on types `bool` and `int`" + }, { + "kind" : "CompilerError", + "location" : [ 9, 1, 9, 6 ], + "message" : "Cannot apply operator `is` on types `int` and `int`" + }, { + "kind" : "CompilerError", + "location" : [ 10, 1, 10, 13 ], + "message" : "Cannot apply operator `is` on types `bool` and `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 11, 1, 11, 11 ], + "message" : "Cannot apply operator `+` on types `` and ``" + }, { + "kind" : "CompilerError", + "location" : [ 12, 1, 12, 12 ], + "message" : "Cannot apply operator `==` on types `` and ``" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_expr_if.py b/src/test/data/pa2/sample/bad_expr_if.py new file mode 100644 index 0000000..4ae5fbe --- /dev/null +++ b/src/test/data/pa2/sample/bad_expr_if.py @@ -0,0 +1,2 @@ +x: int = 0 +x = "Hello" if 2 > 3 else 3 diff --git a/src/test/data/pa2/sample/bad_expr_if.py.ast b/src/test/data/pa2/sample/bad_expr_if.py.ast new file mode 100644 index 0000000..24d9ed3 --- /dev/null +++ b/src/test/data/pa2/sample/bad_expr_if.py.ast @@ -0,0 +1,70 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 2, 28 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 10, 1, 10 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 2, 1, 2, 27 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "IfExpr", + "location" : [ 2, 5, 2, 27 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 2, 16, 2, 20 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 16, 2, 16 ], + "value" : 2 + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 20, 2, 20 ], + "value" : 3 + } + }, + "thenExpr" : { + "kind" : "StringLiteral", + "location" : [ 2, 5, 2, 11 ], + "value" : "Hello" + }, + "elseExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 27, 2, 27 ], + "value" : 3 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_expr_if.py.ast.typed b/src/test/data/pa2/sample/bad_expr_if.py.ast.typed new file mode 100644 index 0000000..0da86f1 --- /dev/null +++ b/src/test/data/pa2/sample/bad_expr_if.py.ast.typed @@ -0,0 +1,107 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 2, 28 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 10, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 2, 1, 2, 27 ], + "errorMsg" : "Expected type `int`; got type `object`", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "IfExpr", + "location" : [ 2, 5, 2, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 2, 16, 2, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 16, 2, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 20, 2, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + }, + "thenExpr" : { + "kind" : "StringLiteral", + "location" : [ 2, 5, 2, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + }, + "elseExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 27, 2, 27 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 2, 1, 2, 27 ], + "message" : "Expected type `int`; got type `object`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_expr_unary.py b/src/test/data/pa2/sample/bad_expr_unary.py new file mode 100644 index 0000000..0b113ac --- /dev/null +++ b/src/test/data/pa2/sample/bad_expr_unary.py @@ -0,0 +1,4 @@ +not "Bad" +-True +-None +not [] diff --git a/src/test/data/pa2/sample/bad_expr_unary.py.ast b/src/test/data/pa2/sample/bad_expr_unary.py.ast new file mode 100644 index 0000000..7632c06 --- /dev/null +++ b/src/test/data/pa2/sample/bad_expr_unary.py.ast @@ -0,0 +1,62 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 7 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 9 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 1, 1, 1, 9 ], + "operator" : "not", + "operand" : { + "kind" : "StringLiteral", + "location" : [ 1, 5, 1, 9 ], + "value" : "Bad" + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 5 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 2, 1, 2, 5 ], + "operator" : "-", + "operand" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 2, 2, 5 ], + "value" : true + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 5 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 3, 1, 3, 5 ], + "operator" : "-", + "operand" : { + "kind" : "NoneLiteral", + "location" : [ 3, 2, 3, 5 ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 6 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 4, 1, 4, 6 ], + "operator" : "not", + "operand" : { + "kind" : "ListExpr", + "location" : [ 4, 5, 4, 6 ], + "elements" : [ ] + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_expr_unary.py.ast.typed b/src/test/data/pa2/sample/bad_expr_unary.py.ast.typed new file mode 100644 index 0000000..f366c93 --- /dev/null +++ b/src/test/data/pa2/sample/bad_expr_unary.py.ast.typed @@ -0,0 +1,114 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 7 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 9 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 1, 1, 1, 9 ], + "errorMsg" : "Cannot apply operator `not` on type `str`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "operator" : "not", + "operand" : { + "kind" : "StringLiteral", + "location" : [ 1, 5, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Bad" + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 5 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 2, 1, 2, 5 ], + "errorMsg" : "Cannot apply operator `-` on type `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 2, 2, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 5 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 3, 1, 3, 5 ], + "errorMsg" : "Cannot apply operator `-` on type ``", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "NoneLiteral", + "location" : [ 3, 2, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 6 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 4, 1, 4, 6 ], + "errorMsg" : "Cannot apply operator `not` on type ``", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "operator" : "not", + "operand" : { + "kind" : "ListExpr", + "location" : [ 4, 5, 4, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + } + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 1, 1, 9 ], + "message" : "Cannot apply operator `not` on type `str`" + }, { + "kind" : "CompilerError", + "location" : [ 2, 1, 2, 5 ], + "message" : "Cannot apply operator `-` on type `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 3, 1, 3, 5 ], + "message" : "Cannot apply operator `-` on type ``" + }, { + "kind" : "CompilerError", + "location" : [ 4, 1, 4, 6 ], + "message" : "Cannot apply operator `not` on type ``" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_func_def_call.py b/src/test/data/pa2/sample/bad_func_def_call.py new file mode 100644 index 0000000..a929805 --- /dev/null +++ b/src/test/data/pa2/sample/bad_func_def_call.py @@ -0,0 +1,13 @@ +def foo(x:str, y:bool) -> int: + return bar() + +def bar() -> int: + return 1 + +# All of the below are bad calls +foo("Hello") +foo("Hello", False, 3) +foo("Hello", 3) +foo(1, "Hello") +baz() + diff --git a/src/test/data/pa2/sample/bad_func_def_call.py.ast b/src/test/data/pa2/sample/bad_func_def_call.py.ast new file mode 100644 index 0000000..64c0e9d --- /dev/null +++ b/src/test/data/pa2/sample/bad_func_def_call.py.ast @@ -0,0 +1,187 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 12, 6 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 16, 1, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 16, 1, 16 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 18, 1, 21 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 27, 1, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 16 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 2, 12, 2, 16 ], + "function" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 14 ], + "name" : "bar" + }, + "args" : [ ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 5, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 14, 4, 16 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 12, 5, 12 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 8, 5, 8, 11 ], + "value" : "Hello" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 22 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 9, 1, 9, 22 ], + "function" : { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 9, 5, 9, 11 ], + "value" : "Hello" + }, { + "kind" : "BooleanLiteral", + "location" : [ 9, 14, 9, 18 ], + "value" : false + }, { + "kind" : "IntegerLiteral", + "location" : [ 9, 21, 9, 21 ], + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 1, 10, 15 ], + "function" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 10, 5, 10, 11 ], + "value" : "Hello" + }, { + "kind" : "IntegerLiteral", + "location" : [ 10, 14, 10, 14 ], + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 1, 11, 15 ], + "function" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 11, 5, 11, 5 ], + "value" : 1 + }, { + "kind" : "StringLiteral", + "location" : [ 11, 8, 11, 14 ], + "value" : "Hello" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 12, 1, 12, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 12, 1, 12, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 3 ], + "name" : "baz" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_func_def_call.py.ast.typed b/src/test/data/pa2/sample/bad_func_def_call.py.ast.typed new file mode 100644 index 0000000..e9dc647 --- /dev/null +++ b/src/test/data/pa2/sample/bad_func_def_call.py.ast.typed @@ -0,0 +1,336 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 12, 6 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 16, 1, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 16, 1, 16 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 18, 1, 21 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 27, 1, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 16 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 2, 12, 2, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "bar" + }, + "args" : [ ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 5, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 14, 4, 16 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 12, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 12 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 12 ], + "errorMsg" : "Expected 2 arguments; got 1", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 3 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "bool" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 8, 5, 8, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 22 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 9, 1, 9, 22 ], + "errorMsg" : "Expected 2 arguments; got 3", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 3 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "bool" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 9, 5, 9, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + }, { + "kind" : "BooleanLiteral", + "location" : [ 9, 14, 9, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, { + "kind" : "IntegerLiteral", + "location" : [ 9, 21, 9, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 1, 10, 15 ], + "errorMsg" : "Expected type `bool`; got type `int` in parameter 1", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 3 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "bool" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 10, 5, 10, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + }, { + "kind" : "IntegerLiteral", + "location" : [ 10, 14, 10, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 11, 1, 11, 15 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 11, 1, 11, 15 ], + "errorMsg" : "Expected type `str`; got type `int` in parameter 0", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 3 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "bool" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 11, 5, 11, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "StringLiteral", + "location" : [ 11, 8, 11, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 12, 1, 12, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 12, 1, 12, 5 ], + "errorMsg" : "Not a function or class: baz", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 3 ], + "name" : "baz" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 8, 1, 8, 12 ], + "message" : "Expected 2 arguments; got 1" + }, { + "kind" : "CompilerError", + "location" : [ 9, 1, 9, 22 ], + "message" : "Expected 2 arguments; got 3" + }, { + "kind" : "CompilerError", + "location" : [ 10, 1, 10, 15 ], + "message" : "Expected type `bool`; got type `int` in parameter 1" + }, { + "kind" : "CompilerError", + "location" : [ 11, 1, 11, 15 ], + "message" : "Expected type `str`; got type `int` in parameter 0" + }, { + "kind" : "CompilerError", + "location" : [ 12, 1, 12, 5 ], + "message" : "Not a function or class: baz" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_func_def_return.py b/src/test/data/pa2/sample/bad_func_def_return.py new file mode 100644 index 0000000..efccffb --- /dev/null +++ b/src/test/data/pa2/sample/bad_func_def_return.py @@ -0,0 +1,10 @@ +def foo(x:str, y:bool) -> int: + return None + +def bar() -> bool: + return 1 + +def baz() -> str: + return + +foo("Hello", False) diff --git a/src/test/data/pa2/sample/bad_func_def_return.py.ast b/src/test/data/pa2/sample/bad_func_def_return.py.ast new file mode 100644 index 0000000..e7aaa31 --- /dev/null +++ b/src/test/data/pa2/sample/bad_func_def_return.py.ast @@ -0,0 +1,125 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 10, 20 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 16 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 16, 1, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 16, 1, 16 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 18, 1, 21 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 27, 1, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 15 ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 12, 2, 15 ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 5, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 14, 4, 17 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 12, 5, 12 ], + "value" : 1 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 7, 1, 8, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 7 ], + "name" : "baz" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 14, 7, 16 ], + "className" : "str" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 8, 5, 8, 10 ], + "value" : null + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 19 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 1, 10, 19 ], + "function" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 10, 5, 10, 11 ], + "value" : "Hello" + }, { + "kind" : "BooleanLiteral", + "location" : [ 10, 14, 10, 18 ], + "value" : false + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_func_def_return.py.ast.typed b/src/test/data/pa2/sample/bad_func_def_return.py.ast.typed new file mode 100644 index 0000000..8dafad8 --- /dev/null +++ b/src/test/data/pa2/sample/bad_func_def_return.py.ast.typed @@ -0,0 +1,174 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 10, 20 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 16 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 16, 1, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 16, 1, 16 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 18, 1, 21 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 27, 1, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 15 ], + "errorMsg" : "Expected type `int`; got type ``", + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 12, 2, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 5, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 14, 4, 17 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 12 ], + "errorMsg" : "Expected type `bool`; got type `int`", + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 12, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 7, 1, 8, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 7 ], + "name" : "baz" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 14, 7, 16 ], + "className" : "str" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 8, 5, 8, 10 ], + "errorMsg" : "Expected type `str`; got `None`", + "value" : null + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 19 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 1, 10, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 3 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "bool" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 10, 5, 10, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + }, { + "kind" : "BooleanLiteral", + "location" : [ 10, 14, 10, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 2, 5, 2, 15 ], + "message" : "Expected type `int`; got type ``" + }, { + "kind" : "CompilerError", + "location" : [ 5, 5, 5, 12 ], + "message" : "Expected type `bool`; got type `int`" + }, { + "kind" : "CompilerError", + "location" : [ 8, 5, 8, 10 ], + "message" : "Expected type `str`; got `None`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_list_assign.py b/src/test/data/pa2/sample/bad_list_assign.py new file mode 100644 index 0000000..f85c242 --- /dev/null +++ b/src/test/data/pa2/sample/bad_list_assign.py @@ -0,0 +1,6 @@ +x:[int] = None +y:[object] = None + +x = [1, 2, 3] +y = x +y = [1] diff --git a/src/test/data/pa2/sample/bad_list_assign.py.ast b/src/test/data/pa2/sample/bad_list_assign.py.ast new file mode 100644 index 0000000..5fa5dd5 --- /dev/null +++ b/src/test/data/pa2/sample/bad_list_assign.py.ast @@ -0,0 +1,116 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 8 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ] + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 10 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 9 ], + "className" : "object" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 14, 2, 17 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 4, 5, 4, 13 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 6, 4, 6 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 12, 4, 12 ], + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "y" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "x" + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "y" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 6, 5, 6, 7 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 6, 6, 6 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_list_assign.py.ast.typed b/src/test/data/pa2/sample/bad_list_assign.py.ast.typed new file mode 100644 index 0000000..b07e2b3 --- /dev/null +++ b/src/test/data/pa2/sample/bad_list_assign.py.ast.typed @@ -0,0 +1,192 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 8 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 10 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 9 ], + "className" : "object" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 14, 2, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 4, 5, 4, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 6, 4, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 12, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 5 ], + "errorMsg" : "Expected type `[object]`; got type `[int]`", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "y" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 7 ], + "errorMsg" : "Expected type `[object]`; got type `[int]`", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "y" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 6, 5, 6, 7 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 6, 6, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 5, 1, 5, 5 ], + "message" : "Expected type `[object]`; got type `[int]`" + }, { + "kind" : "CompilerError", + "location" : [ 6, 1, 6, 7 ], + "message" : "Expected type `[object]`; got type `[int]`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_list_index.py b/src/test/data/pa2/sample/bad_list_index.py new file mode 100644 index 0000000..7b0c708 --- /dev/null +++ b/src/test/data/pa2/sample/bad_list_index.py @@ -0,0 +1,7 @@ +x:[int] = None + +x = [1, 2, 3] +x[True] # Bad +False[0] # Bad +[][0] # Bad +x[True] = x[False] = 1 diff --git a/src/test/data/pa2/sample/bad_list_index.py.ast b/src/test/data/pa2/sample/bad_list_index.py.ast new file mode 100644 index 0000000..b805e51 --- /dev/null +++ b/src/test/data/pa2/sample/bad_list_index.py.ast @@ -0,0 +1,147 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 23 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 3, 5, 3, 13 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 12, 3, 12 ], + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 7 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 4, 1, 4, 7 ], + "list" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 3, 4, 6 ], + "value" : true + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 8 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 5, 1, 5, 8 ], + "list" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 1, 5, 5 ], + "value" : false + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 7, 5, 7 ], + "value" : 0 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 5 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 6, 1, 6, 5 ], + "list" : { + "kind" : "ListExpr", + "location" : [ 6, 1, 6, 2 ], + "elements" : [ ] + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 4, 6, 4 ], + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 22 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 7, 1, 7, 7 ], + "list" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 3, 7, 6 ], + "value" : true + } + }, { + "kind" : "IndexExpr", + "location" : [ 7, 11, 7, 18 ], + "list" : { + "kind" : "Identifier", + "location" : [ 7, 11, 7, 11 ], + "name" : "x" + }, + "index" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 13, 7, 17 ], + "value" : false + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 22, 7, 22 ], + "value" : 1 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_list_index.py.ast.typed b/src/test/data/pa2/sample/bad_list_index.py.ast.typed new file mode 100644 index 0000000..fa390f3 --- /dev/null +++ b/src/test/data/pa2/sample/bad_list_index.py.ast.typed @@ -0,0 +1,275 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 23 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 1, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 3, 5, 3, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 6, 3, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 12, 3, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 4, 1, 4, 7 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 4, 1, 4, 7 ], + "errorMsg" : "Index is of non-integer type `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 3, 4, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 8 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 5, 1, 5, 8 ], + "errorMsg" : "Cannot index into type `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "list" : { + "kind" : "BooleanLiteral", + "location" : [ 5, 1, 5, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 7, 5, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 5 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 6, 1, 6, 5 ], + "errorMsg" : "Cannot index into type ``", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "list" : { + "kind" : "ListExpr", + "location" : [ 6, 1, 6, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 4, 6, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 22 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 7, 1, 7, 7 ], + "errorMsg" : "Index is of non-integer type `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 3, 7, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "IndexExpr", + "location" : [ 7, 11, 7, 18 ], + "errorMsg" : "Index is of non-integer type `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 7, 11, 7, 11 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 13, 7, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 22, 7, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 4, 1, 4, 7 ], + "message" : "Index is of non-integer type `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 5, 1, 5, 8 ], + "message" : "Cannot index into type `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 6, 1, 6, 5 ], + "message" : "Cannot index into type ``" + }, { + "kind" : "CompilerError", + "location" : [ 7, 1, 7, 7 ], + "message" : "Index is of non-integer type `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 7, 11, 7, 18 ], + "message" : "Index is of non-integer type `bool`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_local_assign.py b/src/test/data/pa2/sample/bad_local_assign.py new file mode 100644 index 0000000..77f3420 --- /dev/null +++ b/src/test/data/pa2/sample/bad_local_assign.py @@ -0,0 +1,23 @@ +x:int = 1 +y:int = 2 +z:int = 3 + +def foo(x:int) -> object: + y:int = 4 # OK + global z # OK + + def qux() -> int: + y = 1 # Bad, nonlocal not declared + return 0 + + z = 1 # OK + + pass + +def bar(x:int) -> int: + z = 1 # Bad, global not declared + return x + + +foo(1) + diff --git a/src/test/data/pa2/sample/bad_local_assign.py.ast b/src/test/data/pa2/sample/bad_local_assign.py.ast new file mode 100644 index 0000000..ffac6b5 --- /dev/null +++ b/src/test/data/pa2/sample/bad_local_assign.py.ast @@ -0,0 +1,253 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 22, 7 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "value" : 3 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 15, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 9, 5, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 11, 5, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 19, 5, 24 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "value" : 4 + } + }, { + "kind" : "GlobalDecl", + "location" : [ 7, 5, 7, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 7, 12, 7, 12 ], + "name" : "z" + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 11, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "name" : "qux" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 18, 9, 20 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 10, 9, 10, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 9 ], + "name" : "y" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 13, 10, 13 ], + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 11, 9, 11, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 16, 11, 16 ], + "value" : 0 + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 13, 5, 13, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 5 ], + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 9, 13, 9 ], + "value" : 1 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 17, 1, 19, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 7 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 17, 9, 17, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 9, 17, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 11, 17, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 17, 19, 17, 21 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 18, 5, 18, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 18, 5, 18, 5 ], + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 18, 9, 18, 9 ], + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 19, 5, 19, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 19, 12, 19, 12 ], + "name" : "x" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 22, 1, 22, 6 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 22, 1, 22, 6 ], + "function" : { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 22, 5, 22, 5 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_local_assign.py.ast.typed b/src/test/data/pa2/sample/bad_local_assign.py.ast.typed new file mode 100644 index 0000000..ec39de4 --- /dev/null +++ b/src/test/data/pa2/sample/bad_local_assign.py.ast.typed @@ -0,0 +1,330 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 22, 7 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 15, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 9, 5, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 11, 5, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 19, 5, 24 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + }, { + "kind" : "GlobalDecl", + "location" : [ 7, 5, 7, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 7, 12, 7, 12 ], + "name" : "z" + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 11, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "name" : "qux" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 18, 9, 20 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 10, 9, 10, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 9, 10, 9 ], + "errorMsg" : "Cannot assign to variable that is not explicitly declared in this scope: y", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 13, 10, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 11, 9, 11, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 16, 11, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 13, 5, 13, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 9, 13, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 17, 1, 19, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 7 ], + "name" : "bar" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 17, 9, 17, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 9, 17, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 11, 17, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 17, 19, 17, 21 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 18, 5, 18, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 18, 5, 18, 5 ], + "errorMsg" : "Cannot assign to variable that is not explicitly declared in this scope: z", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 18, 9, 18, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 19, 5, 19, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 19, 12, 19, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 22, 1, 22, 6 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 22, 1, 22, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 3 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 22, 5, 22, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 10, 9, 10, 9 ], + "message" : "Cannot assign to variable that is not explicitly declared in this scope: y" + }, { + "kind" : "CompilerError", + "location" : [ 18, 5, 18, 5 ], + "message" : "Cannot assign to variable that is not explicitly declared in this scope: z" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_none_assign.py b/src/test/data/pa2/sample/bad_none_assign.py new file mode 100644 index 0000000..fc0ec3f --- /dev/null +++ b/src/test/data/pa2/sample/bad_none_assign.py @@ -0,0 +1,14 @@ +class A(object): + x:int = 1 + +y:[bool] = None +z:str = "" +a:A = None + +a = A() + +# Cannot assign None to integer/bool/str types +z = None +a.x = None +y[0] = None + diff --git a/src/test/data/pa2/sample/bad_none_assign.py.ast b/src/test/data/pa2/sample/bad_none_assign.py.ast new file mode 100644 index 0000000..a0a1246 --- /dev/null +++ b/src/test/data/pa2/sample/bad_none_assign.py.ast @@ -0,0 +1,187 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 13, 12 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 4, 3, 4, 8 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 4, 4, 4, 7 ], + "className" : "bool" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 12, 4, 15 ] + } + }, { + "kind" : "VarDef", + "location" : [ 5, 1, 5, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 1, 5, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 3, 5, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 5, 9, 5, 10 ], + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 6, 1, 6, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 1, 6, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 3, 6, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 6, 7, 6, 10 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 8, 5, 8, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 11, 1, 11, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 5, 11, 8 ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 12, 1, 12, 10 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 12, 1, 12, 3 ], + "object" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 12, 3, 12, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 7, 12, 10 ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 13, 1, 13, 11 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 13, 1, 13, 4 ], + "list" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "y" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 3, 13, 3 ], + "value" : 0 + } + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 13, 8, 13, 11 ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_none_assign.py.ast.typed b/src/test/data/pa2/sample/bad_none_assign.py.ast.typed new file mode 100644 index 0000000..2edc3c2 --- /dev/null +++ b/src/test/data/pa2/sample/bad_none_assign.py.ast.typed @@ -0,0 +1,265 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 13, 12 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 4, 3, 4, 8 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 4, 4, 4, 7 ], + "className" : "bool" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 12, 4, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 5, 1, 5, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 1, 5, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 3, 5, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 5, 9, 5, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 6, 1, 6, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 1, 6, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 3, 6, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 6, 7, 6, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 8, 5, 8, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 11, 1, 11, 8 ], + "errorMsg" : "Expected type `str`; got type ``", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 5, 11, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 12, 1, 12, 10 ], + "errorMsg" : "Expected type `int`; got type ``", + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 12, 1, 12, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 12, 3, 12, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 7, 12, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 13, 1, 13, 11 ], + "errorMsg" : "Expected type `bool`; got type ``", + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 13, 1, 13, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "y" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 3, 13, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 13, 8, 13, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 11, 1, 11, 8 ], + "message" : "Expected type `str`; got type ``" + }, { + "kind" : "CompilerError", + "location" : [ 12, 1, 12, 10 ], + "message" : "Expected type `int`; got type ``" + }, { + "kind" : "CompilerError", + "location" : [ 13, 1, 13, 11 ], + "message" : "Expected type `bool`; got type ``" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_nonlocal_global.py b/src/test/data/pa2/sample/bad_nonlocal_global.py new file mode 100644 index 0000000..98eea5c --- /dev/null +++ b/src/test/data/pa2/sample/bad_nonlocal_global.py @@ -0,0 +1,25 @@ +x:int = 1 +y:int = 2 +z:int = 3 + +def foo() -> object: + global x # OK + nonlocal y # No such nonlocal var + global w # No such global var + global int # No such global var + + z:bool = True # OK + + def bar() -> object: + global x # OK + nonlocal z # OK + nonlocal y # No such nonlocal var + global foo # No such global var + nonlocal bar # No such nonlocal var + + pass + + bar() + +foo() + diff --git a/src/test/data/pa2/sample/bad_nonlocal_global.py.ast b/src/test/data/pa2/sample/bad_nonlocal_global.py.ast new file mode 100644 index 0000000..dce287d --- /dev/null +++ b/src/test/data/pa2/sample/bad_nonlocal_global.py.ast @@ -0,0 +1,229 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 24, 6 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "value" : 3 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 22, 10 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 7 ], + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 14, 5, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 6, 5, 6, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 6, 12, 6, 12 ], + "name" : "x" + } + }, { + "kind" : "NonLocalDecl", + "location" : [ 7, 5, 7, 14 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 7, 14, 7, 14 ], + "name" : "y" + } + }, { + "kind" : "GlobalDecl", + "location" : [ 8, 5, 8, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 8, 12, 8, 12 ], + "name" : "w" + } + }, { + "kind" : "GlobalDecl", + "location" : [ 9, 5, 9, 14 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 14 ], + "name" : "int" + } + }, { + "kind" : "VarDef", + "location" : [ 11, 5, 11, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 5, 11, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 7, 11, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 11, 14, 11, 17 ], + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 13, 5, 20, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 13, 9, 13, 11 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 13, 18, 13, 23 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 14, 9, 14, 16 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 14, 16, 14, 16 ], + "name" : "x" + } + }, { + "kind" : "NonLocalDecl", + "location" : [ 15, 9, 15, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 15, 18, 15, 18 ], + "name" : "z" + } + }, { + "kind" : "NonLocalDecl", + "location" : [ 16, 9, 16, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 16, 18, 16, 18 ], + "name" : "y" + } + }, { + "kind" : "GlobalDecl", + "location" : [ 17, 9, 17, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 17, 16, 17, 18 ], + "name" : "foo" + } + }, { + "kind" : "NonLocalDecl", + "location" : [ 18, 9, 18, 20 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 18, 18, 18, 20 ], + "name" : "bar" + } + } ], + "statements" : [ ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 22, 5, 22, 9 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 22, 5, 22, 9 ], + "function" : { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 7 ], + "name" : "bar" + }, + "args" : [ ] + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 24, 1, 24, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 24, 1, 24, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 24, 1, 24, 3 ], + "name" : "foo" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_nonlocal_global.py.ast.typed b/src/test/data/pa2/sample/bad_nonlocal_global.py.ast.typed new file mode 100644 index 0000000..3b80c08 --- /dev/null +++ b/src/test/data/pa2/sample/bad_nonlocal_global.py.ast.typed @@ -0,0 +1,259 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 24, 6 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "value" : 2 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "value" : 3 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 1, 22, 10 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 7 ], + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 14, 5, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 6, 5, 6, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 6, 12, 6, 12 ], + "name" : "x" + } + }, { + "kind" : "NonLocalDecl", + "location" : [ 7, 5, 7, 14 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 7, 14, 7, 14 ], + "errorMsg" : "Not a nonlocal variable: y", + "name" : "y" + } + }, { + "kind" : "GlobalDecl", + "location" : [ 8, 5, 8, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 8, 12, 8, 12 ], + "errorMsg" : "Not a global variable: w", + "name" : "w" + } + }, { + "kind" : "GlobalDecl", + "location" : [ 9, 5, 9, 14 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 9, 12, 9, 14 ], + "errorMsg" : "Not a global variable: int", + "name" : "int" + } + }, { + "kind" : "VarDef", + "location" : [ 11, 5, 11, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 5, 11, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 7, 11, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 11, 14, 11, 17 ], + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 13, 5, 20, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 13, 9, 13, 11 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 13, 18, 13, 23 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 14, 9, 14, 16 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 14, 16, 14, 16 ], + "name" : "x" + } + }, { + "kind" : "NonLocalDecl", + "location" : [ 15, 9, 15, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 15, 18, 15, 18 ], + "name" : "z" + } + }, { + "kind" : "NonLocalDecl", + "location" : [ 16, 9, 16, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 16, 18, 16, 18 ], + "errorMsg" : "Not a nonlocal variable: y", + "name" : "y" + } + }, { + "kind" : "GlobalDecl", + "location" : [ 17, 9, 17, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 17, 16, 17, 18 ], + "errorMsg" : "Not a global variable: foo", + "name" : "foo" + } + }, { + "kind" : "NonLocalDecl", + "location" : [ 18, 9, 18, 20 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 18, 18, 18, 20 ], + "errorMsg" : "Not a nonlocal variable: bar", + "name" : "bar" + } + } ], + "statements" : [ ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 22, 5, 22, 9 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 22, 5, 22, 9 ], + "function" : { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 7 ], + "name" : "bar" + }, + "args" : [ ] + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 24, 1, 24, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 24, 1, 24, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 24, 1, 24, 3 ], + "name" : "foo" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 7, 14, 7, 14 ], + "message" : "Not a nonlocal variable: y" + }, { + "kind" : "CompilerError", + "location" : [ 8, 12, 8, 12 ], + "message" : "Not a global variable: w" + }, { + "kind" : "CompilerError", + "location" : [ 9, 12, 9, 14 ], + "message" : "Not a global variable: int" + }, { + "kind" : "CompilerError", + "location" : [ 16, 18, 16, 18 ], + "message" : "Not a nonlocal variable: y" + }, { + "kind" : "CompilerError", + "location" : [ 17, 16, 17, 18 ], + "message" : "Not a global variable: foo" + }, { + "kind" : "CompilerError", + "location" : [ 18, 18, 18, 20 ], + "message" : "Not a nonlocal variable: bar" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_return_missing.py b/src/test/data/pa2/sample/bad_return_missing.py new file mode 100644 index 0000000..9200f93 --- /dev/null +++ b/src/test/data/pa2/sample/bad_return_missing.py @@ -0,0 +1,6 @@ +def foo() -> int: + if True: + return 1 + # Bad: all paths MUST return int + +foo() diff --git a/src/test/data/pa2/sample/bad_return_missing.py.ast b/src/test/data/pa2/sample/bad_return_missing.py.ast new file mode 100644 index 0000000..8efc035 --- /dev/null +++ b/src/test/data/pa2/sample/bad_return_missing.py.ast @@ -0,0 +1,58 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 6 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 6, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 14, 1, 16 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 2, 5, 6, 0 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 8, 2, 11 ], + "value" : true + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 9, 3, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 16, 3, 16 ], + "value" : 1 + } + } ], + "elseBody" : [ ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 1, 6, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 3 ], + "name" : "foo" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_return_missing.py.ast.typed b/src/test/data/pa2/sample/bad_return_missing.py.ast.typed new file mode 100644 index 0000000..627d4f3 --- /dev/null +++ b/src/test/data/pa2/sample/bad_return_missing.py.ast.typed @@ -0,0 +1,63 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 6, 6 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 6, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "errorMsg" : "All paths in this function/method must have a return statement: foo", + "name" : "foo" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 14, 1, 16 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 2, 5, 6, 0 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 8, 2, 11 ], + "value" : true + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 9, 3, 16 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 16, 3, 16 ], + "value" : 1 + } + } ], + "elseBody" : [ ] + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 6, 1, 6, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 6, 1, 6, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 3 ], + "name" : "foo" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 5, 1, 7 ], + "message" : "All paths in this function/method must have a return statement: foo" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_return_top.py b/src/test/data/pa2/sample/bad_return_top.py new file mode 100644 index 0000000..ca0d0e0 --- /dev/null +++ b/src/test/data/pa2/sample/bad_return_top.py @@ -0,0 +1,3 @@ +x:int = 0 + +return x diff --git a/src/test/data/pa2/sample/bad_return_top.py.ast b/src/test/data/pa2/sample/bad_return_top.py.ast new file mode 100644 index 0000000..992907a --- /dev/null +++ b/src/test/data/pa2/sample/bad_return_top.py.ast @@ -0,0 +1,41 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 1, 3, 8 ], + "value" : { + "kind" : "Identifier", + "location" : [ 3, 8, 3, 8 ], + "name" : "x" + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_return_top.py.ast.typed b/src/test/data/pa2/sample/bad_return_top.py.ast.typed new file mode 100644 index 0000000..56df1de --- /dev/null +++ b/src/test/data/pa2/sample/bad_return_top.py.ast.typed @@ -0,0 +1,50 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 3, 1, 3, 8 ], + "errorMsg" : "Return statement cannot appear at the top level", + "value" : { + "kind" : "Identifier", + "location" : [ 3, 8, 3, 8 ], + "name" : "x" + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 3, 1, 3, 8 ], + "message" : "Return statement cannot appear at the top level" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_shadow_local.py b/src/test/data/pa2/sample/bad_shadow_local.py new file mode 100644 index 0000000..9fc916b --- /dev/null +++ b/src/test/data/pa2/sample/bad_shadow_local.py @@ -0,0 +1,14 @@ +class A(object): + x:int = 1 + +def foo(x:int, bool:str) -> object: # Second param uses an invalid name + y:int = 4 # OK + A:int = 5 # Invalid name + object:str = "" # Invalid name + + def str() -> bool: # Invalid name + return False + + pass + +pass diff --git a/src/test/data/pa2/sample/bad_shadow_local.py.ast b/src/test/data/pa2/sample/bad_shadow_local.py.ast new file mode 100644 index 0000000..cff93dc --- /dev/null +++ b/src/test/data/pa2/sample/bad_shadow_local.py.ast @@ -0,0 +1,179 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 14, 5 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 12, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 9, 4, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 11, 4, 13 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 16, 4, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 16, 4, 19 ], + "name" : "bool" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 21, 4, 23 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 29, 4, 34 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 5, 5, 5, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 5, 5, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 7, 5, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 13, 5, 13 ], + "value" : 4 + } + }, { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "A" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "value" : 5 + } + }, { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 10 ], + "name" : "object" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 12, 7, 14 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 7, 18, 7, 19 ], + "value" : "" + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 10, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "name" : "str" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 18, 9, 21 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 10, 9, 10, 20 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 10, 16, 10, 20 ], + "value" : false + } + } ] + } ], + "statements" : [ ] + } ], + "statements" : [ ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_shadow_local.py.ast.typed b/src/test/data/pa2/sample/bad_shadow_local.py.ast.typed new file mode 100644 index 0000000..3cc9b9b --- /dev/null +++ b/src/test/data/pa2/sample/bad_shadow_local.py.ast.typed @@ -0,0 +1,199 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 14, 5 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 12, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 9, 4, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 11, 4, 13 ], + "className" : "int" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 16, 4, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 16, 4, 19 ], + "errorMsg" : "Cannot shadow class name: bool", + "name" : "bool" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 21, 4, 23 ], + "className" : "str" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 29, 4, 34 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 5, 5, 5, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 5, 5, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 7, 5, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 13, 5, 13 ], + "value" : 4 + } + }, { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "errorMsg" : "Cannot shadow class name: A", + "name" : "A" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "value" : 5 + } + }, { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 14 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 10 ], + "errorMsg" : "Cannot shadow class name: object", + "name" : "object" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 12, 7, 14 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 7, 18, 7, 19 ], + "value" : "" + } + }, { + "kind" : "FuncDef", + "location" : [ 9, 5, 10, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 11 ], + "errorMsg" : "Cannot shadow class name: str", + "name" : "str" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 9, 18, 9, 21 ], + "className" : "bool" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 10, 9, 10, 20 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 10, 16, 10, 20 ], + "value" : false + } + } ] + } ], + "statements" : [ ] + } ], + "statements" : [ ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 4, 16, 4, 19 ], + "message" : "Cannot shadow class name: bool" + }, { + "kind" : "CompilerError", + "location" : [ 6, 5, 6, 5 ], + "message" : "Cannot shadow class name: A" + }, { + "kind" : "CompilerError", + "location" : [ 7, 5, 7, 10 ], + "message" : "Cannot shadow class name: object" + }, { + "kind" : "CompilerError", + "location" : [ 9, 9, 9, 11 ], + "message" : "Cannot shadow class name: str" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_shadow_local_2.py b/src/test/data/pa2/sample/bad_shadow_local_2.py new file mode 100644 index 0000000..67a327e --- /dev/null +++ b/src/test/data/pa2/sample/bad_shadow_local_2.py @@ -0,0 +1,8 @@ +def foo(x:int) -> object: + A:int = 5 # Invalid name + pass + +class A(object): + x:int = 1 + +pass diff --git a/src/test/data/pa2/sample/bad_shadow_local_2.py.ast b/src/test/data/pa2/sample/bad_shadow_local_2.py.ast new file mode 100644 index 0000000..5eb5b2e --- /dev/null +++ b/src/test/data/pa2/sample/bad_shadow_local_2.py.ast @@ -0,0 +1,98 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 5 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 3, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 19, 1, 24 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "A" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 5 + } + } ], + "statements" : [ ] + }, { + "kind" : "ClassDef", + "location" : [ 5, 1, 6, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 7, 5, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_shadow_local_2.py.ast.typed b/src/test/data/pa2/sample/bad_shadow_local_2.py.ast.typed new file mode 100644 index 0000000..ff6ef1b --- /dev/null +++ b/src/test/data/pa2/sample/bad_shadow_local_2.py.ast.typed @@ -0,0 +1,103 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 5 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 3, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 19, 1, 24 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "errorMsg" : "Cannot shadow class name: A", + "name" : "A" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 5 + } + } ], + "statements" : [ ] + }, { + "kind" : "ClassDef", + "location" : [ 5, 1, 6, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 7, 5, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "value" : 1 + } + } ] + } ], + "statements" : [ ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 2, 5, 2, 5 ], + "message" : "Cannot shadow class name: A" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_strings.py b/src/test/data/pa2/sample/bad_strings.py new file mode 100644 index 0000000..86e0e16 --- /dev/null +++ b/src/test/data/pa2/sample/bad_strings.py @@ -0,0 +1,10 @@ +x:str = "Hello" +y:str = "World" +z:str = "" + +1 + x +z = x + 1 +z = x[0] = y +x[1] = y +x[True] + diff --git a/src/test/data/pa2/sample/bad_strings.py.ast b/src/test/data/pa2/sample/bad_strings.py.ast new file mode 100644 index 0000000..04473bf --- /dev/null +++ b/src/test/data/pa2/sample/bad_strings.py.ast @@ -0,0 +1,183 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 8 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 15 ], + "value" : "Hello" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 15 ], + "value" : "World" + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 10 ], + "value" : "" + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 5, 1, 5, 5 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 1, 5, 1 ], + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "x" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 6, 5, 6, 9 ], + "left" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "value" : 1 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "z" + }, { + "kind" : "IndexExpr", + "location" : [ 7, 5, 7, 8 ], + "list" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 7, 7, 7 ], + "value" : 0 + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 7, 12, 7, 12 ], + "name" : "y" + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 8, 1, 8, 4 ], + "list" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 3, 8, 3 ], + "value" : 1 + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 8, 8, 8, 8 ], + "name" : "y" + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 7 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 9, 1, 9, 7 ], + "list" : { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "BooleanLiteral", + "location" : [ 9, 3, 9, 6 ], + "value" : true + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_strings.py.ast.typed b/src/test/data/pa2/sample/bad_strings.py.ast.typed new file mode 100644 index 0000000..f6f2fbe --- /dev/null +++ b/src/test/data/pa2/sample/bad_strings.py.ast.typed @@ -0,0 +1,301 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 8 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "World" + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 5, 1, 5, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 5, 1, 5, 5 ], + "errorMsg" : "Cannot apply operator `+` on types `int` and `str`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 9 ], + "errorMsg" : "Expected type `str`; got type `int`", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 6, 5, 6, 9 ], + "errorMsg" : "Cannot apply operator `+` on types `str` and `int`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + }, { + "kind" : "IndexExpr", + "location" : [ 7, 5, 7, 8 ], + "errorMsg" : "`str` is not a list type", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 7, 7, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 7, 12, 7, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "y" + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 8, 1, 8, 4 ], + "errorMsg" : "`str` is not a list type", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 8, 3, 8, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 8, 8, 8, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "y" + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 7 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 9, 1, 9, 7 ], + "errorMsg" : "Index is of non-integer type `bool`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "index" : { + "kind" : "BooleanLiteral", + "location" : [ 9, 3, 9, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 5, 1, 5, 5 ], + "message" : "Cannot apply operator `+` on types `int` and `str`" + }, { + "kind" : "CompilerError", + "location" : [ 6, 5, 6, 9 ], + "message" : "Cannot apply operator `+` on types `str` and `int`" + }, { + "kind" : "CompilerError", + "location" : [ 6, 1, 6, 9 ], + "message" : "Expected type `str`; got type `int`" + }, { + "kind" : "CompilerError", + "location" : [ 7, 5, 7, 8 ], + "message" : "`str` is not a list type" + }, { + "kind" : "CompilerError", + "location" : [ 8, 1, 8, 4 ], + "message" : "`str` is not a list type" + }, { + "kind" : "CompilerError", + "location" : [ 9, 1, 9, 7 ], + "message" : "Index is of non-integer type `bool`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_type_annotation.py b/src/test/data/pa2/sample/bad_type_annotation.py new file mode 100644 index 0000000..a25abb6 --- /dev/null +++ b/src/test/data/pa2/sample/bad_type_annotation.py @@ -0,0 +1,7 @@ +x:A = None + +def foo(x:B) -> C: + y:D = None + return + +pass diff --git a/src/test/data/pa2/sample/bad_type_annotation.py.ast b/src/test/data/pa2/sample/bad_type_annotation.py.ast new file mode 100644 index 0000000..e42cf91 --- /dev/null +++ b/src/test/data/pa2/sample/bad_type_annotation.py.ast @@ -0,0 +1,86 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 5 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 7, 1, 10 ] + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 5, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 3, 9, 3, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 11, 3, 11 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 17, 3, 17 ], + "className" : "C" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 7, 4, 7 ], + "className" : "D" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 11, 4, 14 ] + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 10 ], + "value" : null + } ] + } ], + "statements" : [ ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_type_annotation.py.ast.typed b/src/test/data/pa2/sample/bad_type_annotation.py.ast.typed new file mode 100644 index 0000000..221ad45 --- /dev/null +++ b/src/test/data/pa2/sample/bad_type_annotation.py.ast.typed @@ -0,0 +1,106 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 5 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 3 ], + "errorMsg" : "Invalid type annotation; there is no class named: A", + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 7, 1, 10 ] + } + }, { + "kind" : "FuncDef", + "location" : [ 3, 1, 5, 11 ], + "name" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 3, 9, 3, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 11, 3, 11 ], + "errorMsg" : "Invalid type annotation; there is no class named: B", + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 3, 17, 3, 17 ], + "errorMsg" : "Invalid type annotation; there is no class named: C", + "className" : "C" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 7, 4, 7 ], + "errorMsg" : "Invalid type annotation; there is no class named: D", + "className" : "D" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 11, 4, 14 ] + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 10 ], + "value" : null + } ] + } ], + "statements" : [ ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 3, 1, 3 ], + "message" : "Invalid type annotation; there is no class named: A" + }, { + "kind" : "CompilerError", + "location" : [ 3, 11, 3, 11 ], + "message" : "Invalid type annotation; there is no class named: B" + }, { + "kind" : "CompilerError", + "location" : [ 3, 17, 3, 17 ], + "message" : "Invalid type annotation; there is no class named: C" + }, { + "kind" : "CompilerError", + "location" : [ 4, 7, 4, 7 ], + "message" : "Invalid type annotation; there is no class named: D" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_type_id.py b/src/test/data/pa2/sample/bad_type_id.py new file mode 100644 index 0000000..0f931fb --- /dev/null +++ b/src/test/data/pa2/sample/bad_type_id.py @@ -0,0 +1 @@ +x - 1 diff --git a/src/test/data/pa2/sample/bad_type_id.py.ast b/src/test/data/pa2/sample/bad_type_id.py.ast new file mode 100644 index 0000000..ff5c46d --- /dev/null +++ b/src/test/data/pa2/sample/bad_type_id.py.ast @@ -0,0 +1,29 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 6 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 5 ], + "left" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "value" : 1 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_type_id.py.ast.typed b/src/test/data/pa2/sample/bad_type_id.py.ast.typed new file mode 100644 index 0000000..5200116 --- /dev/null +++ b/src/test/data/pa2/sample/bad_type_id.py.ast.typed @@ -0,0 +1,51 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 6 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 5 ], + "errorMsg" : "Cannot apply operator `-` on types `object` and `int`", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "errorMsg" : "Not a variable: x", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "x" + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 1, 1, 1, 1 ], + "message" : "Not a variable: x" + }, { + "kind" : "CompilerError", + "location" : [ 1, 1, 1, 5 ], + "message" : "Cannot apply operator `-` on types `object` and `int`" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_var_assign.py b/src/test/data/pa2/sample/bad_var_assign.py new file mode 100644 index 0000000..a383775 --- /dev/null +++ b/src/test/data/pa2/sample/bad_var_assign.py @@ -0,0 +1,8 @@ +x:int = 1 +y:bool = True + +x = False +y = 2 +z = 3 +x = z = 4 +x = z = None diff --git a/src/test/data/pa2/sample/bad_var_assign.py.ast b/src/test/data/pa2/sample/bad_var_assign.py.ast new file mode 100644 index 0000000..6dabcbd --- /dev/null +++ b/src/test/data/pa2/sample/bad_var_assign.py.ast @@ -0,0 +1,127 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 13 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 6 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 10, 2, 13 ], + "value" : true + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 5, 4, 9 ], + "value" : false + } + }, { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "y" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 5, 5, 5 ], + "value" : 2 + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 5, 6, 5 ], + "value" : 3 + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 9, 7, 9 ], + "value" : 4 + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "name" : "z" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 8, 9, 8, 12 ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/bad_var_assign.py.ast.typed b/src/test/data/pa2/sample/bad_var_assign.py.ast.typed new file mode 100644 index 0000000..d8217b8 --- /dev/null +++ b/src/test/data/pa2/sample/bad_var_assign.py.ast.typed @@ -0,0 +1,213 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 13 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 6 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 10, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 9 ], + "errorMsg" : "Expected type `int`; got type `bool`", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 4, 5, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + }, { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 5 ], + "errorMsg" : "Expected type `bool`; got type `int`", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "name" : "y" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 5, 5, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "errorMsg" : "Not a variable: z", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 5, 6, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "errorMsg" : "Not a variable: z", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 9, 7, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 12 ], + "errorMsg" : "Expected type `int`; got type ``", + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 8, 5, 8, 5 ], + "errorMsg" : "Not a variable: z", + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "z" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 8, 9, 8, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 4, 1, 4, 9 ], + "message" : "Expected type `int`; got type `bool`" + }, { + "kind" : "CompilerError", + "location" : [ 5, 1, 5, 5 ], + "message" : "Expected type `bool`; got type `int`" + }, { + "kind" : "CompilerError", + "location" : [ 6, 1, 6, 1 ], + "message" : "Not a variable: z" + }, { + "kind" : "CompilerError", + "location" : [ 7, 5, 7, 5 ], + "message" : "Not a variable: z" + }, { + "kind" : "CompilerError", + "location" : [ 8, 1, 8, 12 ], + "message" : "Expected type `int`; got type ``" + }, { + "kind" : "CompilerError", + "location" : [ 8, 5, 8, 5 ], + "message" : "Not a variable: z" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/class_def_assign.py b/src/test/data/pa2/sample/class_def_assign.py new file mode 100644 index 0000000..44459ff --- /dev/null +++ b/src/test/data/pa2/sample/class_def_assign.py @@ -0,0 +1,18 @@ +class A(object): + x:int = 1 + +class B(A): + def __init__(self: "B"): + pass + +class C(B): + z:bool = True + +a:A = None +b:B = None +c:C = None + +a = A() +a = B() +b = a = c = C() +c = None diff --git a/src/test/data/pa2/sample/class_def_assign.py.ast b/src/test/data/pa2/sample/class_def_assign.py.ast new file mode 100644 index 0000000..92ae3a1 --- /dev/null +++ b/src/test/data/pa2/sample/class_def_assign.py.ast @@ -0,0 +1,263 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 18, 9 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 18, 5, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 24, 5, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 28, 5, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 8, 1, 9, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 7, 9, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 9, 14, 9, 17 ], + "value" : true + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 12, 1, 12, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 1, 12, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 3, 12, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 7, 12, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 13, 1, 13, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 1, 13, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 3, 13, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 13, 7, 13, 10 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 1, 15, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 15, 5, 15, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 15, 5, 15, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 16, 1, 16, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 1 ], + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 5, 16, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 17, 1, 17, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "b" + }, { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 5 ], + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 17, 9, 17, 9 ], + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 17, 13, 17, 15 ], + "function" : { + "kind" : "Identifier", + "location" : [ 17, 13, 17, 13 ], + "name" : "C" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 18, 1, 18, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 1 ], + "name" : "c" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 18, 5, 18, 8 ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/class_def_assign.py.ast.typed b/src/test/data/pa2/sample/class_def_assign.py.ast.typed new file mode 100644 index 0000000..e012a95 --- /dev/null +++ b/src/test/data/pa2/sample/class_def_assign.py.ast.typed @@ -0,0 +1,323 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 18, 9 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 18, 5, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 24, 5, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 28, 5, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 8, 1, 9, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 7, 9, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 9, 14, 9, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 12, 1, 12, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 1, 12, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 3, 12, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 7, 12, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 13, 1, 13, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 1, 13, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 3, 13, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 13, 7, 13, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 1, 15, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 15, 5, 15, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 5, 15, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 16, 1, 16, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 5, 16, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 17, 1, 17, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, { + "kind" : "Identifier", + "location" : [ 17, 9, 17, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 17, 13, 17, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 17, 13, 17, 13 ], + "name" : "C" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 18, 1, 18, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 18, 5, 18, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/class_def_attr.py b/src/test/data/pa2/sample/class_def_attr.py new file mode 100644 index 0000000..9a5d948 --- /dev/null +++ b/src/test/data/pa2/sample/class_def_attr.py @@ -0,0 +1,22 @@ +class A(object): + x:int = 1 + +class B(A): + def __init__(self: "B"): + pass + +class C(B): + z:bool = True + +a:A = None +b:B = None +c:C = None + +a = A() +b = B() +c = C() + +a.x = 1 +b.x = a.x +c.z = a.x == b.x + diff --git a/src/test/data/pa2/sample/class_def_attr.py.ast b/src/test/data/pa2/sample/class_def_attr.py.ast new file mode 100644 index 0000000..b4dcc19 --- /dev/null +++ b/src/test/data/pa2/sample/class_def_attr.py.ast @@ -0,0 +1,346 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 21, 17 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 18, 5, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 24, 5, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 28, 5, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 8, 1, 9, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 7, 9, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 9, 14, 9, 17 ], + "value" : true + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 12, 1, 12, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 1, 12, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 3, 12, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 7, 12, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 13, 1, 13, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 1, 13, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 3, 13, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 13, 7, 13, 10 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 1, 15, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 15, 5, 15, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 15, 5, 15, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 16, 1, 16, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 1 ], + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 5, 16, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 17, 1, 17, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 17, 5, 17, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 5 ], + "name" : "C" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 19, 1, 19, 7 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 19, 1, 19, 3 ], + "object" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 1 ], + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 19, 3, 19, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 19, 7, 19, 7 ], + "value" : 1 + } + }, { + "kind" : "AssignStmt", + "location" : [ 20, 1, 20, 9 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 20, 1, 20, 3 ], + "object" : { + "kind" : "Identifier", + "location" : [ 20, 1, 20, 1 ], + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 3, 20, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 20, 7, 20, 9 ], + "object" : { + "kind" : "Identifier", + "location" : [ 20, 7, 20, 7 ], + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 9, 20, 9 ], + "name" : "x" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 21, 1, 21, 16 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 21, 1, 21, 3 ], + "object" : { + "kind" : "Identifier", + "location" : [ 21, 1, 21, 1 ], + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 21, 3, 21, 3 ], + "name" : "z" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 21, 7, 21, 16 ], + "left" : { + "kind" : "MemberExpr", + "location" : [ 21, 7, 21, 9 ], + "object" : { + "kind" : "Identifier", + "location" : [ 21, 7, 21, 7 ], + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 21, 9, 21, 9 ], + "name" : "x" + } + }, + "operator" : "==", + "right" : { + "kind" : "MemberExpr", + "location" : [ 21, 14, 21, 16 ], + "object" : { + "kind" : "Identifier", + "location" : [ 21, 14, 21, 14 ], + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 21, 16, 21, 16 ], + "name" : "x" + } + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/class_def_attr.py.ast.typed b/src/test/data/pa2/sample/class_def_attr.py.ast.typed new file mode 100644 index 0000000..600032c --- /dev/null +++ b/src/test/data/pa2/sample/class_def_attr.py.ast.typed @@ -0,0 +1,446 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 21, 17 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 18, 5, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 24, 5, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 28, 5, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 8, 1, 9, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 7, 9, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 9, 14, 9, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 12, 1, 12, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 1, 12, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 3, 12, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 7, 12, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 13, 1, 13, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 1, 13, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 3, 13, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 13, 7, 13, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 1, 15, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 15, 5, 15, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 5, 15, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 16, 1, 16, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 5, 16, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 17, 1, 17, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 17, 5, 17, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 5 ], + "name" : "C" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 19, 1, 19, 7 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 19, 1, 19, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 19, 3, 19, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 19, 7, 19, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "AssignStmt", + "location" : [ 20, 1, 20, 9 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 20, 1, 20, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 20, 1, 20, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 3, 20, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 20, 7, 20, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 20, 7, 20, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 20, 9, 20, 9 ], + "name" : "x" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 21, 1, 21, 16 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 21, 1, 21, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 21, 1, 21, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 21, 3, 21, 3 ], + "name" : "z" + } + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 21, 7, 21, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "MemberExpr", + "location" : [ 21, 7, 21, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 21, 7, 21, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 21, 9, 21, 9 ], + "name" : "x" + } + }, + "operator" : "==", + "right" : { + "kind" : "MemberExpr", + "location" : [ 21, 14, 21, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 21, 14, 21, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 21, 16, 21, 16 ], + "name" : "x" + } + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/class_def_init.py b/src/test/data/pa2/sample/class_def_init.py new file mode 100644 index 0000000..733f489 --- /dev/null +++ b/src/test/data/pa2/sample/class_def_init.py @@ -0,0 +1,17 @@ +class A(object): + x:int = 1 + +class B(A): + def __init__(self: "B"): + pass + +class C(B): + z:bool = True + +a:A = None +b:B = None +c:C = None + +a = A() +b = B() +c = C() diff --git a/src/test/data/pa2/sample/class_def_init.py.ast b/src/test/data/pa2/sample/class_def_init.py.ast new file mode 100644 index 0000000..2cf1bba --- /dev/null +++ b/src/test/data/pa2/sample/class_def_init.py.ast @@ -0,0 +1,243 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 17, 8 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 18, 5, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 24, 5, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 28, 5, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 8, 1, 9, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 7, 9, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 9, 14, 9, 17 ], + "value" : true + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 12, 1, 12, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 1, 12, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 3, 12, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 7, 12, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 13, 1, 13, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 1, 13, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 3, 13, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 13, 7, 13, 10 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 1, 15, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 15, 5, 15, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 15, 5, 15, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 16, 1, 16, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 1 ], + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 5, 16, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 17, 1, 17, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 17, 5, 17, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 5 ], + "name" : "C" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/class_def_init.py.ast.typed b/src/test/data/pa2/sample/class_def_init.py.ast.typed new file mode 100644 index 0000000..c2f9d72 --- /dev/null +++ b/src/test/data/pa2/sample/class_def_init.py.ast.typed @@ -0,0 +1,287 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 17, 8 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 2, 14 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 8, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 18, 5, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 24, 5, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 28, 5, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 8, 1, 9, 18 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 7, 8, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 9, 5, 9, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 9, 5, 9, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 9, 7, 9, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 9, 14, 9, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 11, 1, 11, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 11, 1, 11, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 11, 3, 11, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 11, 7, 11, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 12, 1, 12, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 1, 12, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 3, 12, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 12, 7, 12, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 13, 1, 13, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 1, 13, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 1, 13, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 3, 13, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 13, 7, 13, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 1, 15, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 15, 1, 15, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 15, 5, 15, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 15, 5, 15, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 16, 1, 16, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 16, 5, 16, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 16, 5, 16, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 17, 1, 17, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 17, 5, 17, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 5 ], + "name" : "C" + }, + "args" : [ ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/class_def_methods.py b/src/test/data/pa2/sample/class_def_methods.py new file mode 100644 index 0000000..a8d70f1 --- /dev/null +++ b/src/test/data/pa2/sample/class_def_methods.py @@ -0,0 +1,28 @@ +class A(object): + x:int = 1 + + def get_A(self: "A") -> int: + return self.x + +class B(A): + def __init__(self: "B"): + pass + +class C(B): + z:bool = True + + def set_A(self: "C", val: int) -> object: + self.x = val + +a:A = None +b:B = None +c:C = None + +a = A() +b = B() +c = C() + +b.x = a.get_A() +a.x = b.get_A() +c.set_A(0) + diff --git a/src/test/data/pa2/sample/class_def_methods.py.ast b/src/test/data/pa2/sample/class_def_methods.py.ast new file mode 100644 index 0000000..2ddc48e --- /dev/null +++ b/src/test/data/pa2/sample/class_def_methods.py.ast @@ -0,0 +1,451 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 27, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 13 ], + "name" : "get_A" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 15, 4, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 15, 4, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 21, 4, 23 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 29, 4, 31 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 21 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 5, 16, 5, 21 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 19 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 21, 5, 21 ], + "name" : "x" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 11, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 8, 5, 9, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 18, 8, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 18, 8, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 24, 8, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 28, 8, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 11, 1, 17, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 12, 5, 12, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 5, 12, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 7, 12, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 12, 14, 12, 17 ], + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 14, 5, 15, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 13 ], + "name" : "set_A" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 15, 14, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 15, 14, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 21, 14, 23 ], + "className" : "C" + } + }, { + "kind" : "TypedVar", + "location" : [ 14, 26, 14, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 26, 14, 28 ], + "name" : "val" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 31, 14, 33 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 39, 14, 44 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 9, 15, 20 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 15, 9, 15, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 14, 15, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 15, 18, 15, 20 ], + "name" : "val" + } + } ] + } ] + }, { + "kind" : "VarDef", + "location" : [ 17, 1, 17, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 17, 1, 17, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 3, 17, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 17, 7, 17, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 18, 1, 18, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 18, 1, 18, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 18, 3, 18, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 18, 7, 18, 10 ] + } + }, { + "kind" : "VarDef", + "location" : [ 19, 1, 19, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 19, 1, 19, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 3, 19, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 19, 7, 19, 10 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 21, 1, 21, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 21, 1, 21, 1 ], + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 21, 5, 21, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 21, 5, 21, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 22, 1, 22, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 1 ], + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 22, 5, 22, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 23, 1, 23, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 23, 1, 23, 1 ], + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 23, 5, 23, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 23, 5, 23, 5 ], + "name" : "C" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 25, 1, 25, 15 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 25, 1, 25, 3 ], + "object" : { + "kind" : "Identifier", + "location" : [ 25, 1, 25, 1 ], + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 25, 3, 25, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 25, 7, 25, 15 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 25, 7, 25, 13 ], + "object" : { + "kind" : "Identifier", + "location" : [ 25, 7, 25, 7 ], + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 25, 9, 25, 13 ], + "name" : "get_A" + } + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 26, 1, 26, 15 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 26, 1, 26, 3 ], + "object" : { + "kind" : "Identifier", + "location" : [ 26, 1, 26, 1 ], + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 26, 3, 26, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 26, 7, 26, 15 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 26, 7, 26, 13 ], + "object" : { + "kind" : "Identifier", + "location" : [ 26, 7, 26, 7 ], + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 26, 9, 26, 13 ], + "name" : "get_A" + } + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 27, 1, 27, 10 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 27, 1, 27, 10 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 27, 1, 27, 7 ], + "object" : { + "kind" : "Identifier", + "location" : [ 27, 1, 27, 1 ], + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 3, 27, 7 ], + "name" : "set_A" + } + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 27, 9, 27, 9 ], + "value" : 0 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/class_def_methods.py.ast.typed b/src/test/data/pa2/sample/class_def_methods.py.ast.typed new file mode 100644 index 0000000..1f58660 --- /dev/null +++ b/src/test/data/pa2/sample/class_def_methods.py.ast.typed @@ -0,0 +1,595 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 27, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 1, 1, 7, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 7, 1, 7 ], + "name" : "A" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 14 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 2, 5, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 5, 2, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 5, 2, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 7, 2, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 13, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 13 ], + "name" : "get_A" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 15, 4, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 15, 4, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 21, 4, 23 ], + "className" : "A" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 29, 4, 31 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 21 ], + "value" : { + "kind" : "MemberExpr", + "location" : [ 5, 16, 5, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 21, 5, 21 ], + "name" : "x" + } + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 7, 1, 11, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 7, 7, 7 ], + "name" : "B" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "A" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 8, 5, 9, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 18, 8, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 18, 8, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 24, 8, 26 ], + "className" : "B" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 28, 8, 28 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 11, 1, 17, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 7 ], + "name" : "C" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 11, 9, 11, 9 ], + "name" : "B" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 12, 5, 12, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 5, 12, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 7, 12, 10 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 12, 14, 12, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "FuncDef", + "location" : [ 14, 5, 15, 21 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 9, 14, 13 ], + "name" : "set_A" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 14, 15, 14, 23 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 15, 14, 18 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 21, 14, 23 ], + "className" : "C" + } + }, { + "kind" : "TypedVar", + "location" : [ 14, 26, 14, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 14, 26, 14, 28 ], + "name" : "val" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 14, 31, 14, 33 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 14, 39, 14, 44 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 15, 9, 15, 20 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 15, 9, 15, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 15, 9, 15, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 15, 14, 15, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 15, 18, 15, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "val" + } + } ] + } ] + }, { + "kind" : "VarDef", + "location" : [ 17, 1, 17, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 17, 1, 17, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 1 ], + "name" : "a" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 17, 3, 17, 3 ], + "className" : "A" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 17, 7, 17, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 18, 1, 18, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 18, 1, 18, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 1 ], + "name" : "b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 18, 3, 18, 3 ], + "className" : "B" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 18, 7, 18, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 19, 1, 19, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 19, 1, 19, 3 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 1 ], + "name" : "c" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 3, 19, 3 ], + "className" : "C" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 19, 7, 19, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 21, 1, 21, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 21, 1, 21, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 21, 5, 21, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 21, 5, 21, 5 ], + "name" : "A" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 22, 1, 22, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 22, 5, 22, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 22, 5, 22, 5 ], + "name" : "B" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 23, 1, 23, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 23, 1, 23, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 23, 5, 23, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 23, 5, 23, 5 ], + "name" : "C" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 25, 1, 25, 15 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 25, 1, 25, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 25, 1, 25, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 25, 3, 25, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 25, 7, 25, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 25, 7, 25, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "A" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 25, 7, 25, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 25, 9, 25, 13 ], + "name" : "get_A" + } + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 26, 1, 26, 15 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 26, 1, 26, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 26, 1, 26, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A" + }, + "name" : "a" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 26, 3, 26, 3 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 26, 7, 26, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 26, 7, 26, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "A" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 26, 7, 26, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B" + }, + "name" : "b" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 26, 9, 26, 13 ], + "name" : "get_A" + } + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 27, 1, 27, 10 ], + "expr" : { + "kind" : "MethodCallExpr", + "location" : [ 27, 1, 27, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 27, 1, 27, 7 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "C" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 27, 1, 27, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C" + }, + "name" : "c" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 27, 3, 27, 7 ], + "name" : "set_A" + } + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 27, 9, 27, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/decl_global_forward.py b/src/test/data/pa2/sample/decl_global_forward.py new file mode 100644 index 0000000..b364535 --- /dev/null +++ b/src/test/data/pa2/sample/decl_global_forward.py @@ -0,0 +1,9 @@ +def set_x() -> int: + global x + x = 1 + return x + +x:int = 0 + +set_x() +print(x) diff --git a/src/test/data/pa2/sample/decl_global_forward.py.ast b/src/test/data/pa2/sample/decl_global_forward.py.ast new file mode 100644 index 0000000..a450fe6 --- /dev/null +++ b/src/test/data/pa2/sample/decl_global_forward.py.ast @@ -0,0 +1,108 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 9 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 4, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 9 ], + "name" : "set_x" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 16, 1, 18 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 2, 5, 2, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 12 ], + "name" : "x" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 5, 3, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "x" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 4, 5, 4, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 4, 12, 4, 12 ], + "name" : "x" + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 6, 1, 6, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 1, 6, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 3, 6, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 7 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 7 ], + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 5 ], + "name" : "set_x" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 9, 1, 9, 8 ], + "function" : { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 9, 7, 9, 7 ], + "name" : "x" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/decl_global_forward.py.ast.typed b/src/test/data/pa2/sample/decl_global_forward.py.ast.typed new file mode 100644 index 0000000..4d32ce7 --- /dev/null +++ b/src/test/data/pa2/sample/decl_global_forward.py.ast.typed @@ -0,0 +1,155 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 9 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 4, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 9 ], + "name" : "set_x" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 16, 1, 18 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 2, 5, 2, 12 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 12 ], + "name" : "x" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 5, 3, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 4, 5, 4, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 4, 12, 4, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 6, 1, 6, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 1, 6, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 3, 6, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 8, 1, 8, 7 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 8, 1, 8, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "set_x" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 9, 1, 9, 8 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 9, 1, 9, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 9, 7, 9, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/decl_nonlocal_forward.py b/src/test/data/pa2/sample/decl_nonlocal_forward.py new file mode 100644 index 0000000..b1ff307 --- /dev/null +++ b/src/test/data/pa2/sample/decl_nonlocal_forward.py @@ -0,0 +1,10 @@ +def outer() -> int: + def inner() -> int: + nonlocal x + x = 1 + return x + x:int = 0 + inner() + return x + +print(outer()) diff --git a/src/test/data/pa2/sample/decl_nonlocal_forward.py.ast b/src/test/data/pa2/sample/decl_nonlocal_forward.py.ast new file mode 100644 index 0000000..1b5f11b --- /dev/null +++ b/src/test/data/pa2/sample/decl_nonlocal_forward.py.ast @@ -0,0 +1,137 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 10, 15 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 8, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 9 ], + "name" : "outer" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 16, 1, 18 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 5, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 13 ], + "name" : "inner" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 20, 2, 22 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 3, 9, 3, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 3, 18, 3, 18 ], + "name" : "x" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 9, 4, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "name" : "x" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 13, 4, 13 ], + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 16 ], + "name" : "x" + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 5, 7, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 5, 7, 11 ], + "function" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 9 ], + "name" : "inner" + }, + "args" : [ ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 8, 5, 8, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 8, 12, 8, 12 ], + "name" : "x" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 1, 10, 14 ], + "function" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 10, 7, 10, 13 ], + "function" : { + "kind" : "Identifier", + "location" : [ 10, 7, 10, 11 ], + "name" : "outer" + }, + "args" : [ ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/decl_nonlocal_forward.py.ast.typed b/src/test/data/pa2/sample/decl_nonlocal_forward.py.ast.typed new file mode 100644 index 0000000..f5781a7 --- /dev/null +++ b/src/test/data/pa2/sample/decl_nonlocal_forward.py.ast.typed @@ -0,0 +1,196 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 10, 15 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 8, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 9 ], + "name" : "outer" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 16, 1, 18 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 2, 5, 5, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 9, 2, 13 ], + "name" : "inner" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 2, 20, 2, 22 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 3, 9, 3, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 3, 18, 3, 18 ], + "name" : "x" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 9, 4, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 13, 4, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "ReturnStmt", + "location" : [ 5, 9, 5, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 16, 5, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + }, { + "kind" : "VarDef", + "location" : [ 6, 5, 6, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 6, 5, 6, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 7, 6, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 13, 6, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 5, 7, 11 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 5, 7, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "inner" + }, + "args" : [ ] + } + }, { + "kind" : "ReturnStmt", + "location" : [ 8, 5, 8, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 8, 12, 8, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 10, 1, 10, 14 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 10, 1, 10, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "CallExpr", + "location" : [ 10, 7, 10, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 10, 7, 10, 11 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "outer" + }, + "args" : [ ] + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_binary.py b/src/test/data/pa2/sample/expr_binary.py new file mode 100644 index 0000000..b35b22d --- /dev/null +++ b/src/test/data/pa2/sample/expr_binary.py @@ -0,0 +1,2 @@ +1 + 2 * 3 > 13 // 3 % 2 or 1 != 1 and False == False + diff --git a/src/test/data/pa2/sample/expr_binary.py.ast b/src/test/data/pa2/sample/expr_binary.py.ast new file mode 100644 index 0000000..3e59d31 --- /dev/null +++ b/src/test/data/pa2/sample/expr_binary.py.ast @@ -0,0 +1,109 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 53 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 52 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 52 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 23 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 9 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 1, 5, 1, 9 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "value" : 2 + }, + "operator" : "*", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 3 + } + } + }, + "operator" : ">", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 1, 13, 1, 23 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 13, 1, 19 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 13, 1, 14 ], + "value" : 13 + }, + "operator" : "//", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 19, 1, 19 ], + "value" : 3 + } + }, + "operator" : "%", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 23, 1, 23 ], + "value" : 2 + } + } + }, + "operator" : "or", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 1, 28, 1, 52 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 28, 1, 33 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 28, 1, 28 ], + "value" : 1 + }, + "operator" : "!=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 33, 1, 33 ], + "value" : 1 + } + }, + "operator" : "and", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 1, 39, 1, 52 ], + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 39, 1, 43 ], + "value" : false + }, + "operator" : "==", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 48, 1, 52 ], + "value" : false + } + } + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_binary.py.ast.typed b/src/test/data/pa2/sample/expr_binary.py.ast.typed new file mode 100644 index 0000000..146d277 --- /dev/null +++ b/src/test/data/pa2/sample/expr_binary.py.ast.typed @@ -0,0 +1,185 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 53 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 52 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 52 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "+", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 1, 5, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, + "operator" : "*", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + } + }, + "operator" : ">", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 1, 13, 1, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 13, 1, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 13, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 13 + }, + "operator" : "//", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 19, 1, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + }, + "operator" : "%", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 23, 1, 23 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + } + }, + "operator" : "or", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 1, 28, 1, 52 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 1, 28, 1, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 28, 1, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "!=", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 33, 1, 33 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, + "operator" : "and", + "right" : { + "kind" : "BinaryExpr", + "location" : [ 1, 39, 1, 52 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 39, 1, 43 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, + "operator" : "==", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 48, 1, 52 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_concat.py b/src/test/data/pa2/sample/expr_concat.py new file mode 100644 index 0000000..68c41a0 --- /dev/null +++ b/src/test/data/pa2/sample/expr_concat.py @@ -0,0 +1,3 @@ +[1, 2] + [3, 4] +"Hello " + "World" +[1, 2] + [True] diff --git a/src/test/data/pa2/sample/expr_concat.py.ast b/src/test/data/pa2/sample/expr_concat.py.ast new file mode 100644 index 0000000..064862b --- /dev/null +++ b/src/test/data/pa2/sample/expr_concat.py.ast @@ -0,0 +1,93 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 16 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 15 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 15 ], + "left" : { + "kind" : "ListExpr", + "location" : [ 1, 1, 1, 6 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 1, 2, 1, 2 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "value" : 2 + } ] + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 1, 10, 1, 15 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 1, 11, 1, 11 ], + "value" : 3 + }, { + "kind" : "IntegerLiteral", + "location" : [ 1, 14, 1, 14 ], + "value" : 4 + } ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 18 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 2, 1, 2, 18 ], + "left" : { + "kind" : "StringLiteral", + "location" : [ 2, 1, 2, 8 ], + "value" : "Hello " + }, + "operator" : "+", + "right" : { + "kind" : "StringLiteral", + "location" : [ 2, 12, 2, 18 ], + "value" : "World" + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 15 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 15 ], + "left" : { + "kind" : "ListExpr", + "location" : [ 3, 1, 3, 6 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 2, 3, 2 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 5, 3, 5 ], + "value" : 2 + } ] + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 3, 10, 3, 15 ], + "elements" : [ { + "kind" : "BooleanLiteral", + "location" : [ 3, 11, 3, 14 ], + "value" : true + } ] + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_concat.py.ast.typed b/src/test/data/pa2/sample/expr_concat.py.ast.typed new file mode 100644 index 0000000..4c61b0e --- /dev/null +++ b/src/test/data/pa2/sample/expr_concat.py.ast.typed @@ -0,0 +1,175 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 16 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 15 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 15 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "left" : { + "kind" : "ListExpr", + "location" : [ 1, 1, 1, 6 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 1, 2, 1, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } ] + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 1, 10, 1, 15 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 1, 11, 1, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + }, { + "kind" : "IntegerLiteral", + "location" : [ 1, 14, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } ] + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 18 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 2, 1, 2, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "left" : { + "kind" : "StringLiteral", + "location" : [ 2, 1, 2, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello " + }, + "operator" : "+", + "right" : { + "kind" : "StringLiteral", + "location" : [ 2, 12, 2, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "World" + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 15 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 15 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "left" : { + "kind" : "ListExpr", + "location" : [ 3, 1, 3, 6 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 2, 3, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 5, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } ] + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 3, 10, 3, 15 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "elements" : [ { + "kind" : "BooleanLiteral", + "location" : [ 3, 11, 3, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } ] + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_id.py b/src/test/data/pa2/sample/expr_id.py new file mode 100644 index 0000000..c6fcd80 --- /dev/null +++ b/src/test/data/pa2/sample/expr_id.py @@ -0,0 +1,3 @@ +x:int = 1 + +x - 1 diff --git a/src/test/data/pa2/sample/expr_id.py.ast b/src/test/data/pa2/sample/expr_id.py.ast new file mode 100644 index 0000000..0f6ab04 --- /dev/null +++ b/src/test/data/pa2/sample/expr_id.py.ast @@ -0,0 +1,51 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 6 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 5 ], + "left" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "x" + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 5, 3, 5 ], + "value" : 1 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_id.py.ast.typed b/src/test/data/pa2/sample/expr_id.py.ast.typed new file mode 100644 index 0000000..cdefa39 --- /dev/null +++ b/src/test/data/pa2/sample/expr_id.py.ast.typed @@ -0,0 +1,67 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 3, 6 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 3, 1, 3, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 3, 1, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "-", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 5, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_if.py b/src/test/data/pa2/sample/expr_if.py new file mode 100644 index 0000000..e9e9c26 --- /dev/null +++ b/src/test/data/pa2/sample/expr_if.py @@ -0,0 +1 @@ +3 if 1 > 2 else 4 diff --git a/src/test/data/pa2/sample/expr_if.py.ast b/src/test/data/pa2/sample/expr_if.py.ast new file mode 100644 index 0000000..0ed9a55 --- /dev/null +++ b/src/test/data/pa2/sample/expr_if.py.ast @@ -0,0 +1,43 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 18 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 17 ], + "expr" : { + "kind" : "IfExpr", + "location" : [ 1, 1, 1, 17 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 1, 6, 1, 10 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 6, 1, 6 ], + "value" : 1 + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 10, 1, 10 ], + "value" : 2 + } + }, + "thenExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "value" : 3 + }, + "elseExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 17, 1, 17 ], + "value" : 4 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_if.py.ast.typed b/src/test/data/pa2/sample/expr_if.py.ast.typed new file mode 100644 index 0000000..3aa7a5f --- /dev/null +++ b/src/test/data/pa2/sample/expr_if.py.ast.typed @@ -0,0 +1,67 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 18 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 17 ], + "expr" : { + "kind" : "IfExpr", + "location" : [ 1, 1, 1, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 1, 6, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 6, 1, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 10, 1, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + }, + "thenExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + }, + "elseExpr" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 17, 1, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_int.py b/src/test/data/pa2/sample/expr_int.py new file mode 100644 index 0000000..f39d689 --- /dev/null +++ b/src/test/data/pa2/sample/expr_int.py @@ -0,0 +1 @@ +6 * 9 diff --git a/src/test/data/pa2/sample/expr_int.py.ast b/src/test/data/pa2/sample/expr_int.py.ast new file mode 100644 index 0000000..2eb3e50 --- /dev/null +++ b/src/test/data/pa2/sample/expr_int.py.ast @@ -0,0 +1,29 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 6 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 5 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "value" : 6 + }, + "operator" : "*", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "value" : 9 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_int.py.ast.typed b/src/test/data/pa2/sample/expr_int.py.ast.typed new file mode 100644 index 0000000..55a6721 --- /dev/null +++ b/src/test/data/pa2/sample/expr_int.py.ast.typed @@ -0,0 +1,41 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 1, 6 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 5 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 1, 1, 1, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 1, 1, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 6 + }, + "operator" : "*", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 5, 1, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 9 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_list_index.py b/src/test/data/pa2/sample/expr_list_index.py new file mode 100644 index 0000000..b9d97e3 --- /dev/null +++ b/src/test/data/pa2/sample/expr_list_index.py @@ -0,0 +1,12 @@ +x:[int] = None +y:int = 0 +z:[bool] = None +o:object = None + +x = [1, 2, 3] +z = [False, True] + +y = x[0] +x[0] = 1 +z[1] = z[0] +o = x[1] diff --git a/src/test/data/pa2/sample/expr_list_index.py.ast b/src/test/data/pa2/sample/expr_list_index.py.ast new file mode 100644 index 0000000..5cb5c50 --- /dev/null +++ b/src/test/data/pa2/sample/expr_list_index.py.ast @@ -0,0 +1,247 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 12, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ] + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 3, 3, 8 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 4, 3, 7 ], + "className" : "bool" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 12, 3, 15 ] + } + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 12, 4, 15 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 6, 5, 6, 13 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 6, 6, 6 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 12, 6, 12 ], + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 5, 7, 17 ], + "elements" : [ { + "kind" : "BooleanLiteral", + "location" : [ 7, 6, 7, 10 ], + "value" : false + }, { + "kind" : "BooleanLiteral", + "location" : [ 7, 13, 7, 16 ], + "value" : true + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "name" : "y" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 9, 5, 9, 8 ], + "list" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 7, 9, 7 ], + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 1, 10, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 10, 1, 10, 4 ], + "list" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 3, 10, 3 ], + "value" : 0 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 8, 10, 8 ], + "value" : 1 + } + }, { + "kind" : "AssignStmt", + "location" : [ 11, 1, 11, 11 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 11, 1, 11, 4 ], + "list" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "z" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 3, 11, 3 ], + "value" : 1 + } + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 11, 8, 11, 11 ], + "list" : { + "kind" : "Identifier", + "location" : [ 11, 8, 11, 8 ], + "name" : "z" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 10, 11, 10 ], + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 12, 1, 12, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "o" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 12, 5, 12, 8 ], + "list" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 7, 12, 7 ], + "value" : 1 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_list_index.py.ast.typed b/src/test/data/pa2/sample/expr_list_index.py.ast.typed new file mode 100644 index 0000000..28fbe48 --- /dev/null +++ b/src/test/data/pa2/sample/expr_list_index.py.ast.typed @@ -0,0 +1,398 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 12, 9 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 9, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 3, 3, 8 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 4, 3, 7 ], + "className" : "bool" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 12, 3, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 12, 4, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 6, 5, 6, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 6, 6, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 12, 6, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "z" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 5, 7, 17 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "elements" : [ { + "kind" : "BooleanLiteral", + "location" : [ 7, 6, 7, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, { + "kind" : "BooleanLiteral", + "location" : [ 7, 13, 7, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 9, 5, 9, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 9, 7, 9, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 1, 10, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 10, 1, 10, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 3, 10, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 10, 8, 10, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "AssignStmt", + "location" : [ 11, 1, 11, 11 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 11, 1, 11, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "z" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 3, 11, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 11, 8, 11, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 11, 8, 11, 8 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "z" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 11, 10, 11, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 12, 1, 12, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "o" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 12, 5, 12, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 7, 12, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_lists.py b/src/test/data/pa2/sample/expr_lists.py new file mode 100644 index 0000000..2268a54 --- /dev/null +++ b/src/test/data/pa2/sample/expr_lists.py @@ -0,0 +1,12 @@ +x:[int] = None +y:[object] = None +z:[bool] = None +o:object = None + +x = [1, 2, 3] +x = [] +y = [1, True] +z = [False, True] +x = None +o = x +o = x = [1] diff --git a/src/test/data/pa2/sample/expr_lists.py.ast b/src/test/data/pa2/sample/expr_lists.py.ast new file mode 100644 index 0000000..5930b97 --- /dev/null +++ b/src/test/data/pa2/sample/expr_lists.py.ast @@ -0,0 +1,233 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 12, 12 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ] + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 10 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 9 ], + "className" : "object" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 14, 2, 17 ] + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 3, 3, 8 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 4, 3, 7 ], + "className" : "bool" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 12, 3, 15 ] + } + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 12, 4, 15 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 6, 5, 6, 13 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 6, 6, 6 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 12, 6, 12 ], + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 6 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 5, 7, 6 ], + "elements" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "y" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 8, 5, 8, 13 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 8, 6, 8, 6 ], + "value" : 1 + }, { + "kind" : "BooleanLiteral", + "location" : [ 8, 9, 8, 12 ], + "value" : true + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 9, 5, 9, 17 ], + "elements" : [ { + "kind" : "BooleanLiteral", + "location" : [ 9, 6, 9, 10 ], + "value" : false + }, { + "kind" : "BooleanLiteral", + "location" : [ 9, 13, 9, 16 ], + "value" : true + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 1, 10, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 10, 5, 10, 8 ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 11, 1, 11, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "name" : "o" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 5 ], + "name" : "x" + } + }, { + "kind" : "AssignStmt", + "location" : [ 12, 1, 12, 11 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "name" : "o" + }, { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 12, 9, 12, 11 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 12, 10, 12, 10 ], + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_lists.py.ast.typed b/src/test/data/pa2/sample/expr_lists.py.ast.typed new file mode 100644 index 0000000..e8c37bd --- /dev/null +++ b/src/test/data/pa2/sample/expr_lists.py.ast.typed @@ -0,0 +1,374 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 12, 12 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 10 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 9 ], + "className" : "object" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 14, 2, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ListType", + "location" : [ 3, 3, 3, 8 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 3, 4, 3, 7 ], + "className" : "bool" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 12, 3, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 12, 4, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 6, 5, 6, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 6, 6, 6, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 9, 6, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 6, 12, 6, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 6 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 7, 5, 7, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "elements" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "y" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 8, 5, 8, 13 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 8, 6, 8, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "BooleanLiteral", + "location" : [ 8, 9, 8, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "name" : "z" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 9, 5, 9, 17 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "bool" + } + }, + "elements" : [ { + "kind" : "BooleanLiteral", + "location" : [ 9, 6, 9, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, { + "kind" : "BooleanLiteral", + "location" : [ 9, 13, 9, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 10, 1, 10, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 10, 1, 10, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "NoneLiteral", + "location" : [ 10, 5, 10, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 11, 1, 11, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 11, 1, 11, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "o" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 11, 5, 11, 5 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } + }, { + "kind" : "AssignStmt", + "location" : [ 12, 1, 12, 11 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 12, 1, 12, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "o" + }, { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 5 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 12, 9, 12, 11 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 12, 10, 12, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_unary.py b/src/test/data/pa2/sample/expr_unary.py new file mode 100644 index 0000000..58d9627 --- /dev/null +++ b/src/test/data/pa2/sample/expr_unary.py @@ -0,0 +1,2 @@ +-1 +not False diff --git a/src/test/data/pa2/sample/expr_unary.py.ast b/src/test/data/pa2/sample/expr_unary.py.ast new file mode 100644 index 0000000..4f1abf3 --- /dev/null +++ b/src/test/data/pa2/sample/expr_unary.py.ast @@ -0,0 +1,37 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 2, 10 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 2 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 1, 1, 1, 2 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 2, 1, 2 ], + "value" : 1 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 9 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 2, 1, 2, 9 ], + "operator" : "not", + "operand" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 5, 2, 9 ], + "value" : false + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_unary.py.ast.typed b/src/test/data/pa2/sample/expr_unary.py.ast.typed new file mode 100644 index 0000000..77b0fd0 --- /dev/null +++ b/src/test/data/pa2/sample/expr_unary.py.ast.typed @@ -0,0 +1,53 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 2, 10 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 1, 1, 1, 2 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 1, 1, 1, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 2, 1, 2 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 2, 1, 2, 9 ], + "expr" : { + "kind" : "UnaryExpr", + "location" : [ 2, 1, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "operator" : "not", + "operand" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 5, 2, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_var_assign.py b/src/test/data/pa2/sample/expr_var_assign.py new file mode 100644 index 0000000..3b8ebfe --- /dev/null +++ b/src/test/data/pa2/sample/expr_var_assign.py @@ -0,0 +1,4 @@ +x:int = 1 +o:object = None + +x = o = 42 diff --git a/src/test/data/pa2/sample/expr_var_assign.py.ast b/src/test/data/pa2/sample/expr_var_assign.py.ast new file mode 100644 index 0000000..5b8093e --- /dev/null +++ b/src/test/data/pa2/sample/expr_var_assign.py.ast @@ -0,0 +1,71 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 11 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 12, 2, 15 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "name" : "o" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 10 ], + "value" : 42 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/expr_var_assign.py.ast.typed b/src/test/data/pa2/sample/expr_var_assign.py.ast.typed new file mode 100644 index 0000000..950866b --- /dev/null +++ b/src/test/data/pa2/sample/expr_var_assign.py.ast.typed @@ -0,0 +1,91 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 11 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 12, 2, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "o" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 42 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/func_def_call.py b/src/test/data/pa2/sample/func_def_call.py new file mode 100644 index 0000000..e5f4e8b --- /dev/null +++ b/src/test/data/pa2/sample/func_def_call.py @@ -0,0 +1,7 @@ +def foo(x:str, y:bool) -> int: + return bar() + +def bar() -> int: + return 1 + +foo("Hello", False) diff --git a/src/test/data/pa2/sample/func_def_call.py.ast b/src/test/data/pa2/sample/func_def_call.py.ast new file mode 100644 index 0000000..b6194bd --- /dev/null +++ b/src/test/data/pa2/sample/func_def_call.py.ast @@ -0,0 +1,111 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 20 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 16, 1, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 16, 1, 16 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 18, 1, 21 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 27, 1, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 16 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 2, 12, 2, 16 ], + "function" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 14 ], + "name" : "bar" + }, + "args" : [ ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 5, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 14, 4, 16 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 12, 5, 12 ], + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 19 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 1, 7, 19 ], + "function" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 7, 5, 7, 11 ], + "value" : "Hello" + }, { + "kind" : "BooleanLiteral", + "location" : [ 7, 14, 7, 18 ], + "value" : false + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/func_def_call.py.ast.typed b/src/test/data/pa2/sample/func_def_call.py.ast.typed new file mode 100644 index 0000000..20e0bde --- /dev/null +++ b/src/test/data/pa2/sample/func_def_call.py.ast.typed @@ -0,0 +1,153 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 20 ], + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 1, 1, 2, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 1, 5, 1, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 1, 9, 1, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 9, 1, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 11, 1, 13 ], + "className" : "str" + } + }, { + "kind" : "TypedVar", + "location" : [ 1, 16, 1, 21 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 16, 1, 16 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 18, 1, 21 ], + "className" : "bool" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 1, 27, 1, 29 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 2, 5, 2, 16 ], + "value" : { + "kind" : "CallExpr", + "location" : [ 2, 12, 2, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 2, 12, 2, 14 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "bar" + }, + "args" : [ ] + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 4, 1, 5, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 7 ], + "name" : "bar" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 14, 4, 16 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 5, 5, 5, 12 ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 12, 5, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ] + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 7, 1, 7, 19 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 7, 1, 7, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 3 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "str" + }, { + "kind" : "ClassValueType", + "className" : "bool" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "foo" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 7, 5, 7, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + }, { + "kind" : "BooleanLiteral", + "location" : [ 7, 14, 7, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/stmt_for_lists.py b/src/test/data/pa2/sample/stmt_for_lists.py new file mode 100644 index 0000000..235fb2f --- /dev/null +++ b/src/test/data/pa2/sample/stmt_for_lists.py @@ -0,0 +1,4 @@ +x:int = 0 + +for x in [1, 2, 3]: + x + 1 diff --git a/src/test/data/pa2/sample/stmt_for_lists.py.ast b/src/test/data/pa2/sample/stmt_for_lists.py.ast new file mode 100644 index 0000000..3e6fb8f --- /dev/null +++ b/src/test/data/pa2/sample/stmt_for_lists.py.ast @@ -0,0 +1,77 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 3, 1, 5, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "x" + }, + "iterable" : { + "kind" : "ListExpr", + "location" : [ 3, 10, 3, 18 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 11, 3, 11 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 14, 3, 14 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 17, 3, 17 ], + "value" : 3 + } ] + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 9 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 4, 5, 4, 9 ], + "left" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/stmt_for_lists.py.ast.typed b/src/test/data/pa2/sample/stmt_for_lists.py.ast.typed new file mode 100644 index 0000000..9bd4123 --- /dev/null +++ b/src/test/data/pa2/sample/stmt_for_lists.py.ast.typed @@ -0,0 +1,116 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 3, 1, 5, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "iterable" : { + "kind" : "ListExpr", + "location" : [ 3, 10, 3, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 3, 11, 3, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 14, 3, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 3, 17, 3, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 9 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 4, 5, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/stmt_for_strings.py b/src/test/data/pa2/sample/stmt_for_strings.py new file mode 100644 index 0000000..b135f8b --- /dev/null +++ b/src/test/data/pa2/sample/stmt_for_strings.py @@ -0,0 +1,4 @@ +s:str = "Hello" + +for s in s: + s[0] diff --git a/src/test/data/pa2/sample/stmt_for_strings.py.ast b/src/test/data/pa2/sample/stmt_for_strings.py.ast new file mode 100644 index 0000000..6e837a5 --- /dev/null +++ b/src/test/data/pa2/sample/stmt_for_strings.py.ast @@ -0,0 +1,64 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 15 ], + "value" : "Hello" + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 3, 1, 5, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "s" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 3, 10, 3, 10 ], + "name" : "s" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 8 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 4, 5, 4, 8 ], + "list" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "name" : "s" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 7, 4, 7 ], + "value" : 0 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/stmt_for_strings.py.ast.typed b/src/test/data/pa2/sample/stmt_for_strings.py.ast.typed new file mode 100644 index 0000000..0f36ad0 --- /dev/null +++ b/src/test/data/pa2/sample/stmt_for_strings.py.ast.typed @@ -0,0 +1,88 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 5, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + } + } ], + "statements" : [ { + "kind" : "ForStmt", + "location" : [ 3, 1, 5, 1 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + }, + "iterable" : { + "kind" : "Identifier", + "location" : [ 3, 10, 3, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + }, + "body" : [ { + "kind" : "ExprStmt", + "location" : [ 4, 5, 4, 8 ], + "expr" : { + "kind" : "IndexExpr", + "location" : [ 4, 5, 4, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "s" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 7, 4, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/stmt_if.py b/src/test/data/pa2/sample/stmt_if.py new file mode 100644 index 0000000..d5053bf --- /dev/null +++ b/src/test/data/pa2/sample/stmt_if.py @@ -0,0 +1,7 @@ +if False: + pass +elif True: + if 1 == 1: + pass +else: + pass diff --git a/src/test/data/pa2/sample/stmt_if.py.ast b/src/test/data/pa2/sample/stmt_if.py.ast new file mode 100644 index 0000000..48c33f3 --- /dev/null +++ b/src/test/data/pa2/sample/stmt_if.py.ast @@ -0,0 +1,51 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 1 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 1, 1, 8, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 4, 1, 8 ], + "value" : false + }, + "thenBody" : [ ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 3, 1, 8, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 6, 3, 9 ], + "value" : true + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 4, 5, 6, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 4, 8, 4, 13 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 8, 4, 8 ], + "value" : 1 + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 13, 4, 13 ], + "value" : 1 + } + }, + "thenBody" : [ ], + "elseBody" : [ ] + } ], + "elseBody" : [ ] + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/stmt_if.py.ast.typed b/src/test/data/pa2/sample/stmt_if.py.ast.typed new file mode 100644 index 0000000..3453f95 --- /dev/null +++ b/src/test/data/pa2/sample/stmt_if.py.ast.typed @@ -0,0 +1,71 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 8, 1 ], + "declarations" : [ ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 1, 1, 8, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 1, 4, 1, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + }, + "thenBody" : [ ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 3, 1, 8, 1 ], + "condition" : { + "kind" : "BooleanLiteral", + "location" : [ 3, 6, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + }, + "thenBody" : [ { + "kind" : "IfStmt", + "location" : [ 4, 5, 6, 0 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 4, 8, 4, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 8, 4, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 13, 4, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, + "thenBody" : [ ], + "elseBody" : [ ] + } ], + "elseBody" : [ ] + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/stmt_list_assign.py b/src/test/data/pa2/sample/stmt_list_assign.py new file mode 100644 index 0000000..34221dd --- /dev/null +++ b/src/test/data/pa2/sample/stmt_list_assign.py @@ -0,0 +1,7 @@ +x:[int] = None +y:[object] = None + +x = [1, 2] +y = [None] +x[0] = 3 +x[1] = y[0] = 4 diff --git a/src/test/data/pa2/sample/stmt_list_assign.py.ast b/src/test/data/pa2/sample/stmt_list_assign.py.ast new file mode 100644 index 0000000..cac7d91 --- /dev/null +++ b/src/test/data/pa2/sample/stmt_list_assign.py.ast @@ -0,0 +1,155 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 16 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ] + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 10 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 9 ], + "className" : "object" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 14, 2, 17 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 4, 5, 4, 10 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 6, 4, 6 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "value" : 2 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "y" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 5, 5, 5, 10 ], + "elements" : [ { + "kind" : "NoneLiteral", + "location" : [ 5, 6, 5, 9 ] + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 6, 1, 6, 4 ], + "list" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 3, 6, 3 ], + "value" : 0 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 8, 6, 8 ], + "value" : 3 + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 15 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 7, 1, 7, 4 ], + "list" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 3, 7, 3 ], + "value" : 1 + } + }, { + "kind" : "IndexExpr", + "location" : [ 7, 8, 7, 11 ], + "list" : { + "kind" : "Identifier", + "location" : [ 7, 8, 7, 8 ], + "name" : "y" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 10, 7, 10 ], + "value" : 0 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 15, 7, 15 ], + "value" : 4 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/stmt_list_assign.py.ast.typed b/src/test/data/pa2/sample/stmt_list_assign.py.ast.typed new file mode 100644 index 0000000..5fefc31 --- /dev/null +++ b/src/test/data/pa2/sample/stmt_list_assign.py.ast.typed @@ -0,0 +1,256 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 16 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ListType", + "location" : [ 1, 3, 1, 7 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 1, 4, 1, 6 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 1, 11, 1, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 10 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ListType", + "location" : [ 2, 3, 2, 10 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 2, 4, 2, 9 ], + "className" : "object" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 2, 14, 2, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 4, 1, 4, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 4, 5, 4, 10 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 4, 6, 4, 6 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 4, 9, 4, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "y" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 5, 5, 5, 10 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "elements" : [ { + "kind" : "NoneLiteral", + "location" : [ 5, 6, 5, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 8 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 6, 1, 6, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 3, 6, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 8, 6, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 15 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 7, 1, 7, 4 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 3, 7, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "IndexExpr", + "location" : [ 7, 8, 7, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 7, 8, 7, 8 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "y" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 10, 7, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 7, 15, 7, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 4 + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/stmt_var_assign.py b/src/test/data/pa2/sample/stmt_var_assign.py new file mode 100644 index 0000000..71e9795 --- /dev/null +++ b/src/test/data/pa2/sample/stmt_var_assign.py @@ -0,0 +1,9 @@ +x:int = 1 +y:bool = True +z:str = "" +o:object = None + +x = 2 +y = False +z = "Hello" +o = z diff --git a/src/test/data/pa2/sample/stmt_var_assign.py.ast b/src/test/data/pa2/sample/stmt_var_assign.py.ast new file mode 100644 index 0000000..4a474cd --- /dev/null +++ b/src/test/data/pa2/sample/stmt_var_assign.py.ast @@ -0,0 +1,150 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 6 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 6 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 10, 2, 13 ], + "value" : true + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 10 ], + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 12, 4, 15 ] + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 5, 6, 5 ], + "value" : 2 + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "y" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 5, 7, 9 ], + "value" : false + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 11 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 8, 5, 8, 11 ], + "value" : "Hello" + } + }, { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "name" : "o" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "name" : "z" + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/stmt_var_assign.py.ast.typed b/src/test/data/pa2/sample/stmt_var_assign.py.ast.typed new file mode 100644 index 0000000..cb529c2 --- /dev/null +++ b/src/test/data/pa2/sample/stmt_var_assign.py.ast.typed @@ -0,0 +1,198 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 9, 6 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 13 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 6 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 6 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 2, 10, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : true + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + }, { + "kind" : "VarDef", + "location" : [ 4, 1, 4, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 1, 4, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 1, 4, 1 ], + "name" : "o" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 3, 4, 8 ], + "className" : "object" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 4, 12, 4, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 5, 6, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "name" : "y" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 7, 5, 7, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + }, { + "kind" : "AssignStmt", + "location" : [ 8, 1, 8, 11 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 1, 8, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + } ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 8, 5, 8, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + } + }, { + "kind" : "AssignStmt", + "location" : [ 9, 1, 9, 5 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 1, 9, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "name" : "o" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 9, 5, 9, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/stmt_while.py b/src/test/data/pa2/sample/stmt_while.py new file mode 100644 index 0000000..d45a4fc --- /dev/null +++ b/src/test/data/pa2/sample/stmt_while.py @@ -0,0 +1,3 @@ +x:int = 0 +while x < 100: + x = x + 1 diff --git a/src/test/data/pa2/sample/stmt_while.py.ast b/src/test/data/pa2/sample/stmt_while.py.ast new file mode 100644 index 0000000..10ae361 --- /dev/null +++ b/src/test/data/pa2/sample/stmt_while.py.ast @@ -0,0 +1,75 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 2, 1, 4, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 2, 7, 2, 13 ], + "left" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 7 ], + "name" : "x" + }, + "operator" : "<", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 11, 2, 13 ], + "value" : 100 + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 5, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "name" : "x" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 3, 9, 3, 13 ], + "left" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 13, 3, 13 ], + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/stmt_while.py.ast.typed b/src/test/data/pa2/sample/stmt_while.py.ast.typed new file mode 100644 index 0000000..c928a9e --- /dev/null +++ b/src/test/data/pa2/sample/stmt_while.py.ast.typed @@ -0,0 +1,107 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 4, 1 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 9 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 9, 1, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ], + "statements" : [ { + "kind" : "WhileStmt", + "location" : [ 2, 1, 4, 1 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 2, 7, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "<", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 11, 2, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 100 + } + }, + "body" : [ { + "kind" : "AssignStmt", + "location" : [ 3, 5, 3, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 3, 9, 3, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 3, 9, 3, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 13, 3, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } + } ] + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/strings.py b/src/test/data/pa2/sample/strings.py new file mode 100644 index 0000000..dd6a4ee --- /dev/null +++ b/src/test/data/pa2/sample/strings.py @@ -0,0 +1,8 @@ +x:str = "Hello" +y:str = "World" +z:str = "" + +z = x + y +z = x[0] +x = y = z + diff --git a/src/test/data/pa2/sample/strings.py.ast b/src/test/data/pa2/sample/strings.py.ast new file mode 100644 index 0000000..1ba2f58 --- /dev/null +++ b/src/test/data/pa2/sample/strings.py.ast @@ -0,0 +1,139 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 10 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 15 ], + "value" : "Hello" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 15 ], + "value" : "World" + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 10 ], + "value" : "" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 5, 5, 5, 9 ], + "left" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 9 ], + "name" : "y" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "name" : "z" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 6, 5, 6, 8 ], + "list" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 7, 6, 7 ], + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "y" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "name" : "z" + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/sample/strings.py.ast.typed b/src/test/data/pa2/sample/strings.py.ast.typed new file mode 100644 index 0000000..acff3ae --- /dev/null +++ b/src/test/data/pa2/sample/strings.py.ast.typed @@ -0,0 +1,195 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 7, 10 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 3, 1, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 1, 9, 1, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "Hello" + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 3, 2, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 2, 9, 2, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "World" + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 10 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 5 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 3, 3, 5 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 3, 9, 3, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "" + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 1, 5, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 5, 1, 5, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 5, 5, 5, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "y" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 6, 1, 6, 8 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 6, 1, 6, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 6, 5, 6, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 7, 6, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 7, 1, 7, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 7, 1, 7, 1 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "x" + }, { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "y" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "z" + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/student_contributed/bad_semantic.py b/src/test/data/pa2/student_contributed/bad_semantic.py new file mode 100644 index 0000000..c18142b --- /dev/null +++ b/src/test/data/pa2/student_contributed/bad_semantic.py @@ -0,0 +1,93 @@ +# class defs +class A_CLASS(object): + a_class_i:int = 0 + def __init__(self:"A_CLASS", x:int): + self.x = x + + # Bad, self param is missing + def add(y:int) -> int: + y = y+self.x + return y + +class B_CLASS(object): + b_class_i:int = 0 + +class C_CLASS(B_CLASS): + pass + +# Bad, duplicate class def +class A_CLASS(object): + pass + +# Bad, E_CLASS is not declared +class D_CLASS(E_CLASS): + pass + + +# var defs +a_s:str = "a_s" +b_s:str = "b_s" +c_s:str = "c_s" + +a_i:int = 0 +b_i:int = 0 +c_i:int = 0 + +a_b:bool = False +b_b:bool = False +c_b:bool = False + +a_list:[int] = None +b_list:[int] = None +c_list:[int] = None + +a_class:A_CLASS = None +b_class:B_CLASS = None +c_class:C_CLASS = None + + +# fun defs +def f_1() -> object: + def f_f_1() -> object: + # a_s:int = 0 Fails if we uncomment this line + global a_s # Bad, duplicate declarion + print(a_s) + pass + pass + +def f_2() -> object: + f_a_s:str = "s" + def f_f_2() -> object: + nonlocal f_a_s + print(f_a_s) + pass + pass + +def f_3(x:int) -> bool: + f_b_s:int = 3 + if (x + f_b_s > 3): + return True + elif (x + f_b_s == 3): + print("Equal") # Bad, this path should return + return False + +def f_4() -> object: + f_a_i:int = 2 + a_i = f_a_i + 1 # Bad, cant assign to a_i without declaring it as global or nonlocal + return f_a_i + +# NEGATIVE TEST CASES - SEMANTIC +# Bad, f_2 cannot be redefined in the same scope +def f_2() -> object: + pass + +# Bad, print cannot be redefined in the same scope +def print(val:object) -> object: + pass + +# Bad, a_i cannot be redefined in the same scope +a_i:int = 2 + +# Bad return +return a_i + diff --git a/src/test/data/pa2/student_contributed/bad_semantic.py.ast b/src/test/data/pa2/student_contributed/bad_semantic.py.ast new file mode 100644 index 0000000..2b648b0 --- /dev/null +++ b/src/test/data/pa2/student_contributed/bad_semantic.py.ast @@ -0,0 +1,1018 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 92, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 2, 1, 12, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 13 ], + "name" : "A_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 2, 15, 2, 20 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 13 ], + "name" : "a_class_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 15, 3, 17 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 21, 3, 21 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 18, 4, 31 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 18, 4, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 23, 4, 31 ], + "className" : "A_CLASS" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 34, 4, 38 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 34, 4, 34 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 36, 4, 38 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 40, 4, 40 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 9, 5, 18 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 5, 9, 5, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 14, 5, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 18 ], + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 8, 5, 10, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 11 ], + "name" : "add" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 13, 8, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 13, 8, 13 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 15, 8, 17 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 23, 8, 25 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 9, 9, 9, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 9 ], + "name" : "y" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 9, 13, 9, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 13 ], + "name" : "y" + }, + "operator" : "+", + "right" : { + "kind" : "MemberExpr", + "location" : [ 9, 15, 9, 20 ], + "object" : { + "kind" : "Identifier", + "location" : [ 9, 15, 9, 18 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 9, 20, 9, 20 ], + "name" : "x" + } + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 10, 9, 10, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 10, 16, 10, 16 ], + "name" : "y" + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 12, 1, 13, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 12, 7, 12, 13 ], + "name" : "B_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 12, 15, 12, 20 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 13, 5, 13, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 5, 13, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 13 ], + "name" : "b_class_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 15, 13, 17 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 21, 13, 21 ], + "value" : 0 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 15, 1, 16, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 13 ], + "name" : "C_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 15, 15, 15, 21 ], + "name" : "B_CLASS" + }, + "declarations" : [ ] + }, { + "kind" : "ClassDef", + "location" : [ 19, 1, 20, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 19, 7, 19, 13 ], + "name" : "A_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 19, 15, 19, 20 ], + "name" : "object" + }, + "declarations" : [ ] + }, { + "kind" : "ClassDef", + "location" : [ 23, 1, 24, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 23, 7, 23, 13 ], + "name" : "D_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 23, 15, 23, 21 ], + "name" : "E_CLASS" + }, + "declarations" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 28, 1, 28, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 28, 1, 28, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 28, 1, 28, 3 ], + "name" : "a_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 28, 5, 28, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 28, 11, 28, 15 ], + "value" : "a_s" + } + }, { + "kind" : "VarDef", + "location" : [ 29, 1, 29, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 29, 1, 29, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 1, 29, 3 ], + "name" : "b_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 29, 5, 29, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 29, 11, 29, 15 ], + "value" : "b_s" + } + }, { + "kind" : "VarDef", + "location" : [ 30, 1, 30, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 30, 1, 30, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 30, 1, 30, 3 ], + "name" : "c_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 30, 5, 30, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 30, 11, 30, 15 ], + "value" : "c_s" + } + }, { + "kind" : "VarDef", + "location" : [ 32, 1, 32, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 32, 1, 32, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 32, 1, 32, 3 ], + "name" : "a_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 32, 5, 32, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 32, 11, 32, 11 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 33, 1, 33, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 33, 1, 33, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 33, 1, 33, 3 ], + "name" : "b_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 33, 5, 33, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 33, 11, 33, 11 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 34, 1, 34, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 34, 1, 34, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 34, 1, 34, 3 ], + "name" : "c_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 34, 5, 34, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 34, 11, 34, 11 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 36, 1, 36, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 36, 1, 36, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 36, 1, 36, 3 ], + "name" : "a_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 36, 5, 36, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 36, 12, 36, 16 ], + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 37, 1, 37, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 37, 1, 37, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 37, 1, 37, 3 ], + "name" : "b_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 37, 5, 37, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 37, 12, 37, 16 ], + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 38, 1, 38, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 38, 1, 38, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 38, 1, 38, 3 ], + "name" : "c_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 38, 5, 38, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 38, 12, 38, 16 ], + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 40, 1, 40, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 40, 1, 40, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 40, 1, 40, 6 ], + "name" : "a_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 40, 8, 40, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 40, 9, 40, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 40, 16, 40, 19 ] + } + }, { + "kind" : "VarDef", + "location" : [ 41, 1, 41, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 41, 1, 41, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 41, 1, 41, 6 ], + "name" : "b_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 41, 8, 41, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 41, 9, 41, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 41, 16, 41, 19 ] + } + }, { + "kind" : "VarDef", + "location" : [ 42, 1, 42, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 42, 1, 42, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 42, 1, 42, 6 ], + "name" : "c_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 42, 8, 42, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 42, 9, 42, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 42, 16, 42, 19 ] + } + }, { + "kind" : "VarDef", + "location" : [ 44, 1, 44, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 44, 1, 44, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 44, 1, 44, 7 ], + "name" : "a_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 44, 9, 44, 15 ], + "className" : "A_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 44, 19, 44, 22 ] + } + }, { + "kind" : "VarDef", + "location" : [ 45, 1, 45, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 45, 1, 45, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 45, 1, 45, 7 ], + "name" : "b_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 45, 9, 45, 15 ], + "className" : "B_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 45, 19, 45, 22 ] + } + }, { + "kind" : "VarDef", + "location" : [ 46, 1, 46, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 46, 1, 46, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 46, 1, 46, 7 ], + "name" : "c_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 46, 9, 46, 15 ], + "className" : "C_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 46, 19, 46, 22 ] + } + }, { + "kind" : "FuncDef", + "location" : [ 50, 1, 56, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 50, 5, 50, 7 ], + "name" : "f_1" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 50, 14, 50, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 51, 5, 55, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 51, 9, 51, 13 ], + "name" : "f_f_1" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 51, 20, 51, 25 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 53, 9, 53, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 53, 16, 53, 18 ], + "name" : "a_s" + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 54, 9, 54, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 54, 9, 54, 18 ], + "function" : { + "kind" : "Identifier", + "location" : [ 54, 9, 54, 13 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 54, 15, 54, 17 ], + "name" : "a_s" + } ] + } + } ] + } ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 58, 1, 64, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 58, 5, 58, 7 ], + "name" : "f_2" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 58, 14, 58, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 59, 5, 59, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 59, 5, 59, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 59, 5, 59, 9 ], + "name" : "f_a_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 59, 11, 59, 13 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 59, 17, 59, 19 ], + "value" : "s" + } + }, { + "kind" : "FuncDef", + "location" : [ 60, 5, 63, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 60, 9, 60, 13 ], + "name" : "f_f_2" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 60, 20, 60, 25 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 61, 9, 61, 22 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 61, 18, 61, 22 ], + "name" : "f_a_s" + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 62, 9, 62, 20 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 62, 9, 62, 20 ], + "function" : { + "kind" : "Identifier", + "location" : [ 62, 9, 62, 13 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 62, 15, 62, 19 ], + "name" : "f_a_s" + } ] + } + } ] + } ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 66, 1, 72, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 66, 5, 66, 7 ], + "name" : "f_3" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 66, 9, 66, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 66, 9, 66, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 66, 11, 66, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 66, 19, 66, 22 ], + "className" : "bool" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 67, 5, 67, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 67, 5, 67, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 67, 5, 67, 9 ], + "name" : "f_b_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 67, 11, 67, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 67, 17, 67, 17 ], + "value" : 3 + } + } ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 68, 5, 72, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 68, 9, 68, 21 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 68, 9, 68, 17 ], + "left" : { + "kind" : "Identifier", + "location" : [ 68, 9, 68, 9 ], + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 68, 13, 68, 17 ], + "name" : "f_b_s" + } + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 68, 21, 68, 21 ], + "value" : 3 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 69, 9, 69, 19 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 69, 16, 69, 19 ], + "value" : true + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 70, 5, 72, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 70, 11, 70, 24 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 70, 11, 70, 19 ], + "left" : { + "kind" : "Identifier", + "location" : [ 70, 11, 70, 11 ], + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 70, 15, 70, 19 ], + "name" : "f_b_s" + } + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 70, 24, 70, 24 ], + "value" : 3 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 71, 9, 71, 22 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 71, 9, 71, 22 ], + "function" : { + "kind" : "Identifier", + "location" : [ 71, 9, 71, 13 ], + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 71, 15, 71, 21 ], + "value" : "Equal" + } ] + } + } ], + "elseBody" : [ ] + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 72, 5, 72, 16 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 72, 12, 72, 16 ], + "value" : false + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 74, 1, 77, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 74, 5, 74, 7 ], + "name" : "f_4" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 74, 14, 74, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 75, 5, 75, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 75, 5, 75, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 75, 5, 75, 9 ], + "name" : "f_a_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 75, 11, 75, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 75, 17, 75, 17 ], + "value" : 2 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 76, 5, 76, 19 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 76, 5, 76, 7 ], + "name" : "a_i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 76, 11, 76, 19 ], + "left" : { + "kind" : "Identifier", + "location" : [ 76, 11, 76, 15 ], + "name" : "f_a_i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 76, 19, 76, 19 ], + "value" : 1 + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 77, 5, 77, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 77, 12, 77, 16 ], + "name" : "f_a_i" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 81, 1, 82, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 81, 5, 81, 7 ], + "name" : "f_2" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 81, 14, 81, 19 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 85, 1, 86, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 85, 5, 85, 9 ], + "name" : "print" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 85, 11, 85, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 85, 11, 85, 13 ], + "name" : "val" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 85, 15, 85, 20 ], + "className" : "object" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 85, 26, 85, 31 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 89, 1, 89, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 89, 1, 89, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 89, 1, 89, 3 ], + "name" : "a_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 89, 5, 89, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 89, 11, 89, 11 ], + "value" : 2 + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 92, 1, 92, 10 ], + "value" : { + "kind" : "Identifier", + "location" : [ 92, 8, 92, 10 ], + "name" : "a_i" + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/student_contributed/bad_semantic.py.ast.typed b/src/test/data/pa2/student_contributed/bad_semantic.py.ast.typed new file mode 100644 index 0000000..89bb0d3 --- /dev/null +++ b/src/test/data/pa2/student_contributed/bad_semantic.py.ast.typed @@ -0,0 +1,1053 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 92, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 2, 1, 12, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 13 ], + "name" : "A_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 2, 15, 2, 20 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 13 ], + "name" : "a_class_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 15, 3, 17 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 21, 3, 21 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 16 ], + "errorMsg" : "Method overridden with different type signature: __init__", + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 18, 4, 31 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 18, 4, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 23, 4, 31 ], + "className" : "A_CLASS" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 34, 4, 38 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 34, 4, 34 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 36, 4, 38 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 40, 4, 40 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 9, 5, 18 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 5, 9, 5, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 14, 5, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 18 ], + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 8, 5, 10, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 11 ], + "errorMsg" : "First parameter of the following method must be of the enclosing class: add", + "name" : "add" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 13, 8, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 13, 8, 13 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 15, 8, 17 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 23, 8, 25 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 9, 9, 9, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 9 ], + "name" : "y" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 9, 13, 9, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 13 ], + "name" : "y" + }, + "operator" : "+", + "right" : { + "kind" : "MemberExpr", + "location" : [ 9, 15, 9, 20 ], + "object" : { + "kind" : "Identifier", + "location" : [ 9, 15, 9, 18 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 9, 20, 9, 20 ], + "name" : "x" + } + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 10, 9, 10, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 10, 16, 10, 16 ], + "name" : "y" + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 12, 1, 13, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 12, 7, 12, 13 ], + "name" : "B_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 12, 15, 12, 20 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 13, 5, 13, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 5, 13, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 13 ], + "name" : "b_class_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 15, 13, 17 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 21, 13, 21 ], + "value" : 0 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 15, 1, 16, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 13 ], + "name" : "C_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 15, 15, 15, 21 ], + "name" : "B_CLASS" + }, + "declarations" : [ ] + }, { + "kind" : "ClassDef", + "location" : [ 19, 1, 20, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 19, 7, 19, 13 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: A_CLASS", + "name" : "A_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 19, 15, 19, 20 ], + "name" : "object" + }, + "declarations" : [ ] + }, { + "kind" : "ClassDef", + "location" : [ 23, 1, 24, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 23, 7, 23, 13 ], + "name" : "D_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 23, 15, 23, 21 ], + "errorMsg" : "Super-class not defined: E_CLASS", + "name" : "E_CLASS" + }, + "declarations" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 28, 1, 28, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 28, 1, 28, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 28, 1, 28, 3 ], + "name" : "a_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 28, 5, 28, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 28, 11, 28, 15 ], + "value" : "a_s" + } + }, { + "kind" : "VarDef", + "location" : [ 29, 1, 29, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 29, 1, 29, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 1, 29, 3 ], + "name" : "b_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 29, 5, 29, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 29, 11, 29, 15 ], + "value" : "b_s" + } + }, { + "kind" : "VarDef", + "location" : [ 30, 1, 30, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 30, 1, 30, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 30, 1, 30, 3 ], + "name" : "c_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 30, 5, 30, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 30, 11, 30, 15 ], + "value" : "c_s" + } + }, { + "kind" : "VarDef", + "location" : [ 32, 1, 32, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 32, 1, 32, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 32, 1, 32, 3 ], + "name" : "a_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 32, 5, 32, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 32, 11, 32, 11 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 33, 1, 33, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 33, 1, 33, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 33, 1, 33, 3 ], + "name" : "b_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 33, 5, 33, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 33, 11, 33, 11 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 34, 1, 34, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 34, 1, 34, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 34, 1, 34, 3 ], + "name" : "c_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 34, 5, 34, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 34, 11, 34, 11 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 36, 1, 36, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 36, 1, 36, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 36, 1, 36, 3 ], + "name" : "a_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 36, 5, 36, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 36, 12, 36, 16 ], + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 37, 1, 37, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 37, 1, 37, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 37, 1, 37, 3 ], + "name" : "b_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 37, 5, 37, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 37, 12, 37, 16 ], + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 38, 1, 38, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 38, 1, 38, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 38, 1, 38, 3 ], + "name" : "c_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 38, 5, 38, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 38, 12, 38, 16 ], + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 40, 1, 40, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 40, 1, 40, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 40, 1, 40, 6 ], + "name" : "a_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 40, 8, 40, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 40, 9, 40, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 40, 16, 40, 19 ] + } + }, { + "kind" : "VarDef", + "location" : [ 41, 1, 41, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 41, 1, 41, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 41, 1, 41, 6 ], + "name" : "b_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 41, 8, 41, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 41, 9, 41, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 41, 16, 41, 19 ] + } + }, { + "kind" : "VarDef", + "location" : [ 42, 1, 42, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 42, 1, 42, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 42, 1, 42, 6 ], + "name" : "c_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 42, 8, 42, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 42, 9, 42, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 42, 16, 42, 19 ] + } + }, { + "kind" : "VarDef", + "location" : [ 44, 1, 44, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 44, 1, 44, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 44, 1, 44, 7 ], + "name" : "a_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 44, 9, 44, 15 ], + "className" : "A_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 44, 19, 44, 22 ] + } + }, { + "kind" : "VarDef", + "location" : [ 45, 1, 45, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 45, 1, 45, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 45, 1, 45, 7 ], + "name" : "b_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 45, 9, 45, 15 ], + "className" : "B_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 45, 19, 45, 22 ] + } + }, { + "kind" : "VarDef", + "location" : [ 46, 1, 46, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 46, 1, 46, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 46, 1, 46, 7 ], + "name" : "c_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 46, 9, 46, 15 ], + "className" : "C_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 46, 19, 46, 22 ] + } + }, { + "kind" : "FuncDef", + "location" : [ 50, 1, 56, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 50, 5, 50, 7 ], + "name" : "f_1" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 50, 14, 50, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 51, 5, 55, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 51, 9, 51, 13 ], + "name" : "f_f_1" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 51, 20, 51, 25 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 53, 9, 53, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 53, 16, 53, 18 ], + "name" : "a_s" + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 54, 9, 54, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 54, 9, 54, 18 ], + "function" : { + "kind" : "Identifier", + "location" : [ 54, 9, 54, 13 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 54, 15, 54, 17 ], + "name" : "a_s" + } ] + } + } ] + } ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 58, 1, 64, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 58, 5, 58, 7 ], + "name" : "f_2" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 58, 14, 58, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 59, 5, 59, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 59, 5, 59, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 59, 5, 59, 9 ], + "name" : "f_a_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 59, 11, 59, 13 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 59, 17, 59, 19 ], + "value" : "s" + } + }, { + "kind" : "FuncDef", + "location" : [ 60, 5, 63, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 60, 9, 60, 13 ], + "name" : "f_f_2" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 60, 20, 60, 25 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 61, 9, 61, 22 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 61, 18, 61, 22 ], + "name" : "f_a_s" + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 62, 9, 62, 20 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 62, 9, 62, 20 ], + "function" : { + "kind" : "Identifier", + "location" : [ 62, 9, 62, 13 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 62, 15, 62, 19 ], + "name" : "f_a_s" + } ] + } + } ] + } ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 66, 1, 72, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 66, 5, 66, 7 ], + "name" : "f_3" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 66, 9, 66, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 66, 9, 66, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 66, 11, 66, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 66, 19, 66, 22 ], + "className" : "bool" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 67, 5, 67, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 67, 5, 67, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 67, 5, 67, 9 ], + "name" : "f_b_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 67, 11, 67, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 67, 17, 67, 17 ], + "value" : 3 + } + } ], + "statements" : [ { + "kind" : "IfStmt", + "location" : [ 68, 5, 72, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 68, 9, 68, 21 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 68, 9, 68, 17 ], + "left" : { + "kind" : "Identifier", + "location" : [ 68, 9, 68, 9 ], + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 68, 13, 68, 17 ], + "name" : "f_b_s" + } + }, + "operator" : ">", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 68, 21, 68, 21 ], + "value" : 3 + } + }, + "thenBody" : [ { + "kind" : "ReturnStmt", + "location" : [ 69, 9, 69, 19 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 69, 16, 69, 19 ], + "value" : true + } + } ], + "elseBody" : [ { + "kind" : "IfStmt", + "location" : [ 70, 5, 72, 4 ], + "condition" : { + "kind" : "BinaryExpr", + "location" : [ 70, 11, 70, 24 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 70, 11, 70, 19 ], + "left" : { + "kind" : "Identifier", + "location" : [ 70, 11, 70, 11 ], + "name" : "x" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 70, 15, 70, 19 ], + "name" : "f_b_s" + } + }, + "operator" : "==", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 70, 24, 70, 24 ], + "value" : 3 + } + }, + "thenBody" : [ { + "kind" : "ExprStmt", + "location" : [ 71, 9, 71, 22 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 71, 9, 71, 22 ], + "function" : { + "kind" : "Identifier", + "location" : [ 71, 9, 71, 13 ], + "name" : "print" + }, + "args" : [ { + "kind" : "StringLiteral", + "location" : [ 71, 15, 71, 21 ], + "value" : "Equal" + } ] + } + } ], + "elseBody" : [ ] + } ] + }, { + "kind" : "ReturnStmt", + "location" : [ 72, 5, 72, 16 ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 72, 12, 72, 16 ], + "value" : false + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 74, 1, 77, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 74, 5, 74, 7 ], + "name" : "f_4" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 74, 14, 74, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 75, 5, 75, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 75, 5, 75, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 75, 5, 75, 9 ], + "name" : "f_a_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 75, 11, 75, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 75, 17, 75, 17 ], + "value" : 2 + } + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 76, 5, 76, 19 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 76, 5, 76, 7 ], + "name" : "a_i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 76, 11, 76, 19 ], + "left" : { + "kind" : "Identifier", + "location" : [ 76, 11, 76, 15 ], + "name" : "f_a_i" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 76, 19, 76, 19 ], + "value" : 1 + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 77, 5, 77, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 77, 12, 77, 16 ], + "name" : "f_a_i" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 81, 1, 82, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 81, 5, 81, 7 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: f_2", + "name" : "f_2" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 81, 14, 81, 19 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 85, 1, 86, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 85, 5, 85, 9 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: print", + "name" : "print" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 85, 11, 85, 20 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 85, 11, 85, 13 ], + "name" : "val" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 85, 15, 85, 20 ], + "className" : "object" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 85, 26, 85, 31 ], + "className" : "object" + }, + "declarations" : [ ], + "statements" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 89, 1, 89, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 89, 1, 89, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 89, 1, 89, 3 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: a_i", + "name" : "a_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 89, 5, 89, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 89, 11, 89, 11 ], + "value" : 2 + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 92, 1, 92, 10 ], + "value" : { + "kind" : "Identifier", + "location" : [ 92, 8, 92, 10 ], + "name" : "a_i" + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 19, 7, 19, 13 ], + "message" : "Duplicate declaration of identifier in same scope: A_CLASS" + }, { + "kind" : "CompilerError", + "location" : [ 23, 15, 23, 21 ], + "message" : "Super-class not defined: E_CLASS" + }, { + "kind" : "CompilerError", + "location" : [ 81, 5, 81, 7 ], + "message" : "Duplicate declaration of identifier in same scope: f_2" + }, { + "kind" : "CompilerError", + "location" : [ 85, 5, 85, 9 ], + "message" : "Duplicate declaration of identifier in same scope: print" + }, { + "kind" : "CompilerError", + "location" : [ 89, 1, 89, 3 ], + "message" : "Duplicate declaration of identifier in same scope: a_i" + }, { + "kind" : "CompilerError", + "location" : [ 4, 9, 4, 16 ], + "message" : "Method overridden with different type signature: __init__" + }, { + "kind" : "CompilerError", + "location" : [ 8, 9, 8, 11 ], + "message" : "First parameter of the following method must be of the enclosing class: add" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/student_contributed/bad_types.py b/src/test/data/pa2/student_contributed/bad_types.py new file mode 100644 index 0000000..262c0ea --- /dev/null +++ b/src/test/data/pa2/student_contributed/bad_types.py @@ -0,0 +1,111 @@ +# class defs +class A_CLASS(object): + a_class_i:int = 0 + def __init__(self:"A_CLASS", x:int): + self.x = x + + def add(self:"A_CLASS", y:int) -> int: + y = y+self.x + return y + +class B_CLASS(object): + b_class_i:int = 0 + +class C_CLASS(B_CLASS): + pass + +# var defs +a_s:str = "a_s" +b_s:str = "b_s" +c_s:str = "c_s" + +a_i:int = 0 +b_i:int = 0 +c_i:int = 0 + +a_b:bool = False +b_b:bool = False +c_b:bool = False + +a_list:[int] = None +b_list:[int] = None +c_list:[int] = None + +a_class:A_CLASS = None +b_class:B_CLASS = None +c_class:C_CLASS = None + + +# fun defs +def f_1() -> object: + def f_f_1() -> object: + global a_s # Fails if we change it to z, which doesnt exist in global scope + pass + pass + +def f_2() -> object: + f_a_s:str = "s" + def f_f_2() -> object: + nonlocal f_a_s # Fails if we change this to a_s which is in global scope but not in upper scope + pass + pass + +def f_3(x:int) -> str: + f_b_s:int = 3 + return x*f_b_s + + +# Declarations +a_list = [1, 2, 3] +b_list = [0, 0, 0] +c_list = [-1, -2, -3] + +a_class = A_CLASS(5) +b_class = B_CLASS() +c_class = C_CLASS() + + +# NEGATIVE TEST CASES - TYPES +c_i = True + +c_i + [1] # Bad, addint list to an int + +a_i = a_b = z = "Error" # Bad, z is not defined and a_b is boolean + +a_s = a_s + 1 # Bad, adding integer to a string + +c_s = a_s[a_s] # Bad, indexing with a string variable + +b_class.b_class_i = 2 # Bad, object attribute is not assignable + +f_1 = 5 # Bad, function is not assignable + +f_2 = f_1 # Bad, function is not storable + +a_i = b_class.b_class_i = z = 5 # Bad, b_class.b_class_i is not assignable and z is not declared + +x_i = "ss" # Bad assignment + +a_s = a_i + b_i # Bad, assigning integer to a variable with string type + +a_s = a_i == b_i and True # Bad, assigning boolean to a variable with string type + +a_list = a_list + a_s # Bad, adding string and list + +a_s = a_list[a_s] # Bad, indexing with a string variable and assigning int to str + +a_list[1] = "a" # Bad, assigning str to int + +a_i = f_3(3) + 5 # Bad, f_3 has string return type but it actually returns an int + +f_1() + +f_2() + +a_i = a_class.add(a_s) # Bad, passing string where method expects int + + + + + + diff --git a/src/test/data/pa2/student_contributed/bad_types.py.ast b/src/test/data/pa2/student_contributed/bad_types.py.ast new file mode 100644 index 0000000..508c754 --- /dev/null +++ b/src/test/data/pa2/student_contributed/bad_types.py.ast @@ -0,0 +1,1302 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 105, 70 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 2, 1, 11, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 13 ], + "name" : "A_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 2, 15, 2, 20 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 13 ], + "name" : "a_class_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 15, 3, 17 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 21, 3, 21 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 18, 4, 31 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 18, 4, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 23, 4, 31 ], + "className" : "A_CLASS" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 34, 4, 38 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 34, 4, 34 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 36, 4, 38 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 40, 4, 40 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 9, 5, 18 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 5, 9, 5, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 14, 5, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 18 ], + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 7, 5, 9, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 11 ], + "name" : "add" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 7, 13, 7, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 13, 7, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 18, 7, 26 ], + "className" : "A_CLASS" + } + }, { + "kind" : "TypedVar", + "location" : [ 7, 29, 7, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 29, 7, 29 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 31, 7, 33 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 39, 7, 41 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 8, 9, 8, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "y" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 8, 13, 8, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 8, 13, 8, 13 ], + "name" : "y" + }, + "operator" : "+", + "right" : { + "kind" : "MemberExpr", + "location" : [ 8, 15, 8, 20 ], + "object" : { + "kind" : "Identifier", + "location" : [ 8, 15, 8, 18 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 8, 20, 8, 20 ], + "name" : "x" + } + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 9, 9, 9, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 9, 16, 9, 16 ], + "name" : "y" + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 11, 1, 12, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 13 ], + "name" : "B_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 11, 15, 11, 20 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 12, 5, 12, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 5, 12, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 13 ], + "name" : "b_class_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 15, 12, 17 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 21, 12, 21 ], + "value" : 0 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 14, 1, 15, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 7, 14, 13 ], + "name" : "C_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 14, 15, 14, 21 ], + "name" : "B_CLASS" + }, + "declarations" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 18, 1, 18, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 18, 1, 18, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 3 ], + "name" : "a_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 18, 5, 18, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 18, 11, 18, 15 ], + "value" : "a_s" + } + }, { + "kind" : "VarDef", + "location" : [ 19, 1, 19, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 19, 1, 19, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 3 ], + "name" : "b_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 5, 19, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 19, 11, 19, 15 ], + "value" : "b_s" + } + }, { + "kind" : "VarDef", + "location" : [ 20, 1, 20, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 20, 1, 20, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 20, 1, 20, 3 ], + "name" : "c_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 20, 5, 20, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 20, 11, 20, 15 ], + "value" : "c_s" + } + }, { + "kind" : "VarDef", + "location" : [ 22, 1, 22, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 22, 1, 22, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 3 ], + "name" : "a_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 22, 5, 22, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 22, 11, 22, 11 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 23, 1, 23, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 23, 1, 23, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 23, 1, 23, 3 ], + "name" : "b_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 23, 5, 23, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 23, 11, 23, 11 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 24, 1, 24, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 24, 1, 24, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 24, 1, 24, 3 ], + "name" : "c_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 24, 5, 24, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 11, 24, 11 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 26, 1, 26, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 26, 1, 26, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 26, 1, 26, 3 ], + "name" : "a_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 26, 5, 26, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 26, 12, 26, 16 ], + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 27, 1, 27, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 27, 1, 27, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 27, 1, 27, 3 ], + "name" : "b_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 27, 5, 27, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 27, 12, 27, 16 ], + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 28, 1, 28, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 28, 1, 28, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 28, 1, 28, 3 ], + "name" : "c_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 28, 5, 28, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 28, 12, 28, 16 ], + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 30, 1, 30, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 30, 1, 30, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 30, 1, 30, 6 ], + "name" : "a_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 30, 8, 30, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 30, 9, 30, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 30, 16, 30, 19 ] + } + }, { + "kind" : "VarDef", + "location" : [ 31, 1, 31, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 31, 1, 31, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 31, 1, 31, 6 ], + "name" : "b_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 31, 8, 31, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 31, 9, 31, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 31, 16, 31, 19 ] + } + }, { + "kind" : "VarDef", + "location" : [ 32, 1, 32, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 32, 1, 32, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 32, 1, 32, 6 ], + "name" : "c_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 32, 8, 32, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 32, 9, 32, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 32, 16, 32, 19 ] + } + }, { + "kind" : "VarDef", + "location" : [ 34, 1, 34, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 34, 1, 34, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 34, 1, 34, 7 ], + "name" : "a_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 34, 9, 34, 15 ], + "className" : "A_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 34, 19, 34, 22 ] + } + }, { + "kind" : "VarDef", + "location" : [ 35, 1, 35, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 35, 1, 35, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 35, 1, 35, 7 ], + "name" : "b_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 35, 9, 35, 15 ], + "className" : "B_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 35, 19, 35, 22 ] + } + }, { + "kind" : "VarDef", + "location" : [ 36, 1, 36, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 36, 1, 36, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 36, 1, 36, 7 ], + "name" : "c_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 36, 9, 36, 15 ], + "className" : "C_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 36, 19, 36, 22 ] + } + }, { + "kind" : "FuncDef", + "location" : [ 40, 1, 44, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 40, 5, 40, 7 ], + "name" : "f_1" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 40, 14, 40, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 41, 5, 43, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 41, 9, 41, 13 ], + "name" : "f_f_1" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 41, 20, 41, 25 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 42, 9, 42, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 42, 16, 42, 18 ], + "name" : "a_s" + } + } ], + "statements" : [ ] + } ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 46, 1, 51, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 46, 5, 46, 7 ], + "name" : "f_2" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 46, 14, 46, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 47, 5, 47, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 47, 5, 47, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 47, 5, 47, 9 ], + "name" : "f_a_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 47, 11, 47, 13 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 47, 17, 47, 19 ], + "value" : "s" + } + }, { + "kind" : "FuncDef", + "location" : [ 48, 5, 50, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 48, 9, 48, 13 ], + "name" : "f_f_2" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 48, 20, 48, 25 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 49, 9, 49, 22 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 49, 18, 49, 22 ], + "name" : "f_a_s" + } + } ], + "statements" : [ ] + } ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 53, 1, 55, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 53, 5, 53, 7 ], + "name" : "f_3" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 53, 9, 53, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 53, 9, 53, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 53, 11, 53, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 53, 19, 53, 21 ], + "className" : "str" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 54, 5, 54, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 54, 5, 54, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 54, 5, 54, 9 ], + "name" : "f_b_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 54, 11, 54, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 54, 17, 54, 17 ], + "value" : 3 + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 55, 5, 55, 18 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 55, 12, 55, 18 ], + "left" : { + "kind" : "Identifier", + "location" : [ 55, 12, 55, 12 ], + "name" : "x" + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 55, 14, 55, 18 ], + "name" : "f_b_s" + } + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 59, 1, 59, 18 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 59, 1, 59, 6 ], + "name" : "a_list" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 59, 10, 59, 18 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 59, 11, 59, 11 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 59, 14, 59, 14 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 59, 17, 59, 17 ], + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 60, 1, 60, 18 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 60, 1, 60, 6 ], + "name" : "b_list" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 60, 10, 60, 18 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 60, 11, 60, 11 ], + "value" : 0 + }, { + "kind" : "IntegerLiteral", + "location" : [ 60, 14, 60, 14 ], + "value" : 0 + }, { + "kind" : "IntegerLiteral", + "location" : [ 60, 17, 60, 17 ], + "value" : 0 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 61, 1, 61, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 61, 1, 61, 6 ], + "name" : "c_list" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 61, 10, 61, 21 ], + "elements" : [ { + "kind" : "UnaryExpr", + "location" : [ 61, 11, 61, 12 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 61, 12, 61, 12 ], + "value" : 1 + } + }, { + "kind" : "UnaryExpr", + "location" : [ 61, 15, 61, 16 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 61, 16, 61, 16 ], + "value" : 2 + } + }, { + "kind" : "UnaryExpr", + "location" : [ 61, 19, 61, 20 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 61, 20, 61, 20 ], + "value" : 3 + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 63, 1, 63, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 63, 1, 63, 7 ], + "name" : "a_class" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 63, 11, 63, 20 ], + "function" : { + "kind" : "Identifier", + "location" : [ 63, 11, 63, 17 ], + "name" : "A_CLASS" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 63, 19, 63, 19 ], + "value" : 5 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 64, 1, 64, 19 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 64, 1, 64, 7 ], + "name" : "b_class" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 64, 11, 64, 19 ], + "function" : { + "kind" : "Identifier", + "location" : [ 64, 11, 64, 17 ], + "name" : "B_CLASS" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 65, 1, 65, 19 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 65, 1, 65, 7 ], + "name" : "c_class" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 65, 11, 65, 19 ], + "function" : { + "kind" : "Identifier", + "location" : [ 65, 11, 65, 17 ], + "name" : "C_CLASS" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 69, 1, 69, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 69, 1, 69, 3 ], + "name" : "c_i" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 69, 7, 69, 10 ], + "value" : true + } + }, { + "kind" : "ExprStmt", + "location" : [ 71, 1, 71, 9 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 71, 1, 71, 9 ], + "left" : { + "kind" : "Identifier", + "location" : [ 71, 1, 71, 3 ], + "name" : "c_i" + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 71, 7, 71, 9 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 71, 8, 71, 8 ], + "value" : 1 + } ] + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 73, 1, 73, 23 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 73, 1, 73, 3 ], + "name" : "a_i" + }, { + "kind" : "Identifier", + "location" : [ 73, 7, 73, 9 ], + "name" : "a_b" + }, { + "kind" : "Identifier", + "location" : [ 73, 13, 73, 13 ], + "name" : "z" + } ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 73, 17, 73, 23 ], + "value" : "Error" + } + }, { + "kind" : "AssignStmt", + "location" : [ 75, 1, 75, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 75, 1, 75, 3 ], + "name" : "a_s" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 75, 7, 75, 13 ], + "left" : { + "kind" : "Identifier", + "location" : [ 75, 7, 75, 9 ], + "name" : "a_s" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 75, 13, 75, 13 ], + "value" : 1 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 77, 1, 77, 14 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 77, 1, 77, 3 ], + "name" : "c_s" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 77, 7, 77, 14 ], + "list" : { + "kind" : "Identifier", + "location" : [ 77, 7, 77, 9 ], + "name" : "a_s" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 77, 11, 77, 13 ], + "name" : "a_s" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 79, 1, 79, 21 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 79, 1, 79, 17 ], + "object" : { + "kind" : "Identifier", + "location" : [ 79, 1, 79, 7 ], + "name" : "b_class" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 79, 9, 79, 17 ], + "name" : "b_class_i" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 79, 21, 79, 21 ], + "value" : 2 + } + }, { + "kind" : "AssignStmt", + "location" : [ 81, 1, 81, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 81, 1, 81, 3 ], + "name" : "f_1" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 81, 7, 81, 7 ], + "value" : 5 + } + }, { + "kind" : "AssignStmt", + "location" : [ 83, 1, 83, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 83, 1, 83, 3 ], + "name" : "f_2" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 83, 7, 83, 9 ], + "name" : "f_1" + } + }, { + "kind" : "AssignStmt", + "location" : [ 85, 1, 85, 31 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 85, 1, 85, 3 ], + "name" : "a_i" + }, { + "kind" : "MemberExpr", + "location" : [ 85, 7, 85, 23 ], + "object" : { + "kind" : "Identifier", + "location" : [ 85, 7, 85, 13 ], + "name" : "b_class" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 85, 15, 85, 23 ], + "name" : "b_class_i" + } + }, { + "kind" : "Identifier", + "location" : [ 85, 27, 85, 27 ], + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 85, 31, 85, 31 ], + "value" : 5 + } + }, { + "kind" : "AssignStmt", + "location" : [ 87, 1, 87, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 87, 1, 87, 3 ], + "name" : "x_i" + } ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 87, 7, 87, 10 ], + "value" : "ss" + } + }, { + "kind" : "AssignStmt", + "location" : [ 89, 1, 89, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 89, 1, 89, 3 ], + "name" : "a_s" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 89, 7, 89, 15 ], + "left" : { + "kind" : "Identifier", + "location" : [ 89, 7, 89, 9 ], + "name" : "a_i" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 89, 13, 89, 15 ], + "name" : "b_i" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 91, 1, 91, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 91, 1, 91, 3 ], + "name" : "a_s" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 91, 7, 91, 25 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 91, 7, 91, 16 ], + "left" : { + "kind" : "Identifier", + "location" : [ 91, 7, 91, 9 ], + "name" : "a_i" + }, + "operator" : "==", + "right" : { + "kind" : "Identifier", + "location" : [ 91, 14, 91, 16 ], + "name" : "b_i" + } + }, + "operator" : "and", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 91, 22, 91, 25 ], + "value" : true + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 93, 1, 93, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 93, 1, 93, 6 ], + "name" : "a_list" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 93, 10, 93, 21 ], + "left" : { + "kind" : "Identifier", + "location" : [ 93, 10, 93, 15 ], + "name" : "a_list" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 93, 19, 93, 21 ], + "name" : "a_s" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 95, 1, 95, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 95, 1, 95, 3 ], + "name" : "a_s" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 95, 7, 95, 17 ], + "list" : { + "kind" : "Identifier", + "location" : [ 95, 7, 95, 12 ], + "name" : "a_list" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 95, 14, 95, 16 ], + "name" : "a_s" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 97, 1, 97, 15 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 97, 1, 97, 9 ], + "list" : { + "kind" : "Identifier", + "location" : [ 97, 1, 97, 6 ], + "name" : "a_list" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 97, 8, 97, 8 ], + "value" : 1 + } + } ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 97, 13, 97, 15 ], + "value" : "a" + } + }, { + "kind" : "AssignStmt", + "location" : [ 99, 1, 99, 16 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 99, 1, 99, 3 ], + "name" : "a_i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 99, 7, 99, 16 ], + "left" : { + "kind" : "CallExpr", + "location" : [ 99, 7, 99, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 99, 7, 99, 9 ], + "name" : "f_3" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 99, 11, 99, 11 ], + "value" : 3 + } ] + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 99, 16, 99, 16 ], + "value" : 5 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 101, 1, 101, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 101, 1, 101, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 101, 1, 101, 3 ], + "name" : "f_1" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 103, 1, 103, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 103, 1, 103, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 103, 1, 103, 3 ], + "name" : "f_2" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 105, 1, 105, 22 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 105, 1, 105, 3 ], + "name" : "a_i" + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 105, 7, 105, 22 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 105, 7, 105, 17 ], + "object" : { + "kind" : "Identifier", + "location" : [ 105, 7, 105, 13 ], + "name" : "a_class" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 105, 15, 105, 17 ], + "name" : "add" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 105, 19, 105, 21 ], + "name" : "a_s" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/student_contributed/bad_types.py.ast.typed b/src/test/data/pa2/student_contributed/bad_types.py.ast.typed new file mode 100644 index 0000000..a85b212 --- /dev/null +++ b/src/test/data/pa2/student_contributed/bad_types.py.ast.typed @@ -0,0 +1,1307 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 105, 70 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 2, 1, 11, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 13 ], + "name" : "A_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 2, 15, 2, 20 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 13 ], + "name" : "a_class_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 15, 3, 17 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 21, 3, 21 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 4, 5, 5, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 9, 4, 16 ], + "errorMsg" : "Method overridden with different type signature: __init__", + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 4, 18, 4, 31 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 18, 4, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 23, 4, 31 ], + "className" : "A_CLASS" + } + }, { + "kind" : "TypedVar", + "location" : [ 4, 34, 4, 38 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 34, 4, 34 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 36, 4, 38 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 4, 40, 4, 40 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 5, 9, 5, 18 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 5, 9, 5, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 5, 14, 5, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 18 ], + "name" : "x" + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 7, 5, 9, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 7, 9, 7, 11 ], + "name" : "add" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 7, 13, 7, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 13, 7, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 18, 7, 26 ], + "className" : "A_CLASS" + } + }, { + "kind" : "TypedVar", + "location" : [ 7, 29, 7, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 29, 7, 29 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 31, 7, 33 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 7, 39, 7, 41 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 8, 9, 8, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 9 ], + "name" : "y" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 8, 13, 8, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 8, 13, 8, 13 ], + "name" : "y" + }, + "operator" : "+", + "right" : { + "kind" : "MemberExpr", + "location" : [ 8, 15, 8, 20 ], + "object" : { + "kind" : "Identifier", + "location" : [ 8, 15, 8, 18 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 8, 20, 8, 20 ], + "name" : "x" + } + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 9, 9, 9, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 9, 16, 9, 16 ], + "name" : "y" + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 11, 1, 12, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 11, 7, 11, 13 ], + "name" : "B_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 11, 15, 11, 20 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 12, 5, 12, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 12, 5, 12, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 12, 5, 12, 13 ], + "name" : "b_class_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 12, 15, 12, 17 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 12, 21, 12, 21 ], + "value" : 0 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 14, 1, 15, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 14, 7, 14, 13 ], + "name" : "C_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 14, 15, 14, 21 ], + "name" : "B_CLASS" + }, + "declarations" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 18, 1, 18, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 18, 1, 18, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 18, 1, 18, 3 ], + "name" : "a_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 18, 5, 18, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 18, 11, 18, 15 ], + "value" : "a_s" + } + }, { + "kind" : "VarDef", + "location" : [ 19, 1, 19, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 19, 1, 19, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 3 ], + "name" : "b_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 5, 19, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 19, 11, 19, 15 ], + "value" : "b_s" + } + }, { + "kind" : "VarDef", + "location" : [ 20, 1, 20, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 20, 1, 20, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 20, 1, 20, 3 ], + "name" : "c_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 20, 5, 20, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 20, 11, 20, 15 ], + "value" : "c_s" + } + }, { + "kind" : "VarDef", + "location" : [ 22, 1, 22, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 22, 1, 22, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 22, 1, 22, 3 ], + "name" : "a_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 22, 5, 22, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 22, 11, 22, 11 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 23, 1, 23, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 23, 1, 23, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 23, 1, 23, 3 ], + "name" : "b_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 23, 5, 23, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 23, 11, 23, 11 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 24, 1, 24, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 24, 1, 24, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 24, 1, 24, 3 ], + "name" : "c_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 24, 5, 24, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 11, 24, 11 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 26, 1, 26, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 26, 1, 26, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 26, 1, 26, 3 ], + "name" : "a_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 26, 5, 26, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 26, 12, 26, 16 ], + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 27, 1, 27, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 27, 1, 27, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 27, 1, 27, 3 ], + "name" : "b_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 27, 5, 27, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 27, 12, 27, 16 ], + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 28, 1, 28, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 28, 1, 28, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 28, 1, 28, 3 ], + "name" : "c_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 28, 5, 28, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 28, 12, 28, 16 ], + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 30, 1, 30, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 30, 1, 30, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 30, 1, 30, 6 ], + "name" : "a_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 30, 8, 30, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 30, 9, 30, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 30, 16, 30, 19 ] + } + }, { + "kind" : "VarDef", + "location" : [ 31, 1, 31, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 31, 1, 31, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 31, 1, 31, 6 ], + "name" : "b_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 31, 8, 31, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 31, 9, 31, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 31, 16, 31, 19 ] + } + }, { + "kind" : "VarDef", + "location" : [ 32, 1, 32, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 32, 1, 32, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 32, 1, 32, 6 ], + "name" : "c_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 32, 8, 32, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 32, 9, 32, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 32, 16, 32, 19 ] + } + }, { + "kind" : "VarDef", + "location" : [ 34, 1, 34, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 34, 1, 34, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 34, 1, 34, 7 ], + "name" : "a_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 34, 9, 34, 15 ], + "className" : "A_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 34, 19, 34, 22 ] + } + }, { + "kind" : "VarDef", + "location" : [ 35, 1, 35, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 35, 1, 35, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 35, 1, 35, 7 ], + "name" : "b_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 35, 9, 35, 15 ], + "className" : "B_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 35, 19, 35, 22 ] + } + }, { + "kind" : "VarDef", + "location" : [ 36, 1, 36, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 36, 1, 36, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 36, 1, 36, 7 ], + "name" : "c_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 36, 9, 36, 15 ], + "className" : "C_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 36, 19, 36, 22 ] + } + }, { + "kind" : "FuncDef", + "location" : [ 40, 1, 44, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 40, 5, 40, 7 ], + "name" : "f_1" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 40, 14, 40, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 41, 5, 43, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 41, 9, 41, 13 ], + "name" : "f_f_1" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 41, 20, 41, 25 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 42, 9, 42, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 42, 16, 42, 18 ], + "name" : "a_s" + } + } ], + "statements" : [ ] + } ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 46, 1, 51, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 46, 5, 46, 7 ], + "name" : "f_2" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 46, 14, 46, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 47, 5, 47, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 47, 5, 47, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 47, 5, 47, 9 ], + "name" : "f_a_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 47, 11, 47, 13 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 47, 17, 47, 19 ], + "value" : "s" + } + }, { + "kind" : "FuncDef", + "location" : [ 48, 5, 50, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 48, 9, 48, 13 ], + "name" : "f_f_2" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 48, 20, 48, 25 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 49, 9, 49, 22 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 49, 18, 49, 22 ], + "name" : "f_a_s" + } + } ], + "statements" : [ ] + } ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 53, 1, 55, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 53, 5, 53, 7 ], + "name" : "f_3" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 53, 9, 53, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 53, 9, 53, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 53, 11, 53, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 53, 19, 53, 21 ], + "className" : "str" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 54, 5, 54, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 54, 5, 54, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 54, 5, 54, 9 ], + "name" : "f_b_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 54, 11, 54, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 54, 17, 54, 17 ], + "value" : 3 + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 55, 5, 55, 18 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 55, 12, 55, 18 ], + "left" : { + "kind" : "Identifier", + "location" : [ 55, 12, 55, 12 ], + "name" : "x" + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 55, 14, 55, 18 ], + "name" : "f_b_s" + } + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 59, 1, 59, 18 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 59, 1, 59, 6 ], + "name" : "a_list" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 59, 10, 59, 18 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 59, 11, 59, 11 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 59, 14, 59, 14 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 59, 17, 59, 17 ], + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 60, 1, 60, 18 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 60, 1, 60, 6 ], + "name" : "b_list" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 60, 10, 60, 18 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 60, 11, 60, 11 ], + "value" : 0 + }, { + "kind" : "IntegerLiteral", + "location" : [ 60, 14, 60, 14 ], + "value" : 0 + }, { + "kind" : "IntegerLiteral", + "location" : [ 60, 17, 60, 17 ], + "value" : 0 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 61, 1, 61, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 61, 1, 61, 6 ], + "name" : "c_list" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 61, 10, 61, 21 ], + "elements" : [ { + "kind" : "UnaryExpr", + "location" : [ 61, 11, 61, 12 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 61, 12, 61, 12 ], + "value" : 1 + } + }, { + "kind" : "UnaryExpr", + "location" : [ 61, 15, 61, 16 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 61, 16, 61, 16 ], + "value" : 2 + } + }, { + "kind" : "UnaryExpr", + "location" : [ 61, 19, 61, 20 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 61, 20, 61, 20 ], + "value" : 3 + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 63, 1, 63, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 63, 1, 63, 7 ], + "name" : "a_class" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 63, 11, 63, 20 ], + "function" : { + "kind" : "Identifier", + "location" : [ 63, 11, 63, 17 ], + "name" : "A_CLASS" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 63, 19, 63, 19 ], + "value" : 5 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 64, 1, 64, 19 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 64, 1, 64, 7 ], + "name" : "b_class" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 64, 11, 64, 19 ], + "function" : { + "kind" : "Identifier", + "location" : [ 64, 11, 64, 17 ], + "name" : "B_CLASS" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 65, 1, 65, 19 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 65, 1, 65, 7 ], + "name" : "c_class" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 65, 11, 65, 19 ], + "function" : { + "kind" : "Identifier", + "location" : [ 65, 11, 65, 17 ], + "name" : "C_CLASS" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 69, 1, 69, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 69, 1, 69, 3 ], + "name" : "c_i" + } ], + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 69, 7, 69, 10 ], + "value" : true + } + }, { + "kind" : "ExprStmt", + "location" : [ 71, 1, 71, 9 ], + "expr" : { + "kind" : "BinaryExpr", + "location" : [ 71, 1, 71, 9 ], + "left" : { + "kind" : "Identifier", + "location" : [ 71, 1, 71, 3 ], + "name" : "c_i" + }, + "operator" : "+", + "right" : { + "kind" : "ListExpr", + "location" : [ 71, 7, 71, 9 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 71, 8, 71, 8 ], + "value" : 1 + } ] + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 73, 1, 73, 23 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 73, 1, 73, 3 ], + "name" : "a_i" + }, { + "kind" : "Identifier", + "location" : [ 73, 7, 73, 9 ], + "name" : "a_b" + }, { + "kind" : "Identifier", + "location" : [ 73, 13, 73, 13 ], + "name" : "z" + } ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 73, 17, 73, 23 ], + "value" : "Error" + } + }, { + "kind" : "AssignStmt", + "location" : [ 75, 1, 75, 13 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 75, 1, 75, 3 ], + "name" : "a_s" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 75, 7, 75, 13 ], + "left" : { + "kind" : "Identifier", + "location" : [ 75, 7, 75, 9 ], + "name" : "a_s" + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 75, 13, 75, 13 ], + "value" : 1 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 77, 1, 77, 14 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 77, 1, 77, 3 ], + "name" : "c_s" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 77, 7, 77, 14 ], + "list" : { + "kind" : "Identifier", + "location" : [ 77, 7, 77, 9 ], + "name" : "a_s" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 77, 11, 77, 13 ], + "name" : "a_s" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 79, 1, 79, 21 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 79, 1, 79, 17 ], + "object" : { + "kind" : "Identifier", + "location" : [ 79, 1, 79, 7 ], + "name" : "b_class" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 79, 9, 79, 17 ], + "name" : "b_class_i" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 79, 21, 79, 21 ], + "value" : 2 + } + }, { + "kind" : "AssignStmt", + "location" : [ 81, 1, 81, 7 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 81, 1, 81, 3 ], + "name" : "f_1" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 81, 7, 81, 7 ], + "value" : 5 + } + }, { + "kind" : "AssignStmt", + "location" : [ 83, 1, 83, 9 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 83, 1, 83, 3 ], + "name" : "f_2" + } ], + "value" : { + "kind" : "Identifier", + "location" : [ 83, 7, 83, 9 ], + "name" : "f_1" + } + }, { + "kind" : "AssignStmt", + "location" : [ 85, 1, 85, 31 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 85, 1, 85, 3 ], + "name" : "a_i" + }, { + "kind" : "MemberExpr", + "location" : [ 85, 7, 85, 23 ], + "object" : { + "kind" : "Identifier", + "location" : [ 85, 7, 85, 13 ], + "name" : "b_class" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 85, 15, 85, 23 ], + "name" : "b_class_i" + } + }, { + "kind" : "Identifier", + "location" : [ 85, 27, 85, 27 ], + "name" : "z" + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 85, 31, 85, 31 ], + "value" : 5 + } + }, { + "kind" : "AssignStmt", + "location" : [ 87, 1, 87, 10 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 87, 1, 87, 3 ], + "name" : "x_i" + } ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 87, 7, 87, 10 ], + "value" : "ss" + } + }, { + "kind" : "AssignStmt", + "location" : [ 89, 1, 89, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 89, 1, 89, 3 ], + "name" : "a_s" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 89, 7, 89, 15 ], + "left" : { + "kind" : "Identifier", + "location" : [ 89, 7, 89, 9 ], + "name" : "a_i" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 89, 13, 89, 15 ], + "name" : "b_i" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 91, 1, 91, 25 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 91, 1, 91, 3 ], + "name" : "a_s" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 91, 7, 91, 25 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 91, 7, 91, 16 ], + "left" : { + "kind" : "Identifier", + "location" : [ 91, 7, 91, 9 ], + "name" : "a_i" + }, + "operator" : "==", + "right" : { + "kind" : "Identifier", + "location" : [ 91, 14, 91, 16 ], + "name" : "b_i" + } + }, + "operator" : "and", + "right" : { + "kind" : "BooleanLiteral", + "location" : [ 91, 22, 91, 25 ], + "value" : true + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 93, 1, 93, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 93, 1, 93, 6 ], + "name" : "a_list" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 93, 10, 93, 21 ], + "left" : { + "kind" : "Identifier", + "location" : [ 93, 10, 93, 15 ], + "name" : "a_list" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 93, 19, 93, 21 ], + "name" : "a_s" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 95, 1, 95, 17 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 95, 1, 95, 3 ], + "name" : "a_s" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 95, 7, 95, 17 ], + "list" : { + "kind" : "Identifier", + "location" : [ 95, 7, 95, 12 ], + "name" : "a_list" + }, + "index" : { + "kind" : "Identifier", + "location" : [ 95, 14, 95, 16 ], + "name" : "a_s" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 97, 1, 97, 15 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 97, 1, 97, 9 ], + "list" : { + "kind" : "Identifier", + "location" : [ 97, 1, 97, 6 ], + "name" : "a_list" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 97, 8, 97, 8 ], + "value" : 1 + } + } ], + "value" : { + "kind" : "StringLiteral", + "location" : [ 97, 13, 97, 15 ], + "value" : "a" + } + }, { + "kind" : "AssignStmt", + "location" : [ 99, 1, 99, 16 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 99, 1, 99, 3 ], + "name" : "a_i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 99, 7, 99, 16 ], + "left" : { + "kind" : "CallExpr", + "location" : [ 99, 7, 99, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 99, 7, 99, 9 ], + "name" : "f_3" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 99, 11, 99, 11 ], + "value" : 3 + } ] + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 99, 16, 99, 16 ], + "value" : 5 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 101, 1, 101, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 101, 1, 101, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 101, 1, 101, 3 ], + "name" : "f_1" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 103, 1, 103, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 103, 1, 103, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 103, 1, 103, 3 ], + "name" : "f_2" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 105, 1, 105, 22 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 105, 1, 105, 3 ], + "name" : "a_i" + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 105, 7, 105, 22 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 105, 7, 105, 17 ], + "object" : { + "kind" : "Identifier", + "location" : [ 105, 7, 105, 13 ], + "name" : "a_class" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 105, 15, 105, 17 ], + "name" : "add" + } + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 105, 19, 105, 21 ], + "name" : "a_s" + } ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 4, 9, 4, 16 ], + "message" : "Method overridden with different type signature: __init__" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/student_contributed/diff.py b/src/test/data/pa2/student_contributed/diff.py new file mode 100644 index 0000000..5204996 --- /dev/null +++ b/src/test/data/pa2/student_contributed/diff.py @@ -0,0 +1,17 @@ +x : int = 0 +y : int = 5 +z : Foo = None +class Foo(object): + x : int = 3 +def foo(x : int) -> int: + y : str = "test" + def foo2() -> str: + nonlocal y + return y + nonlocal x # The reference compiler prioritized for duplicate declaration + # error and stopped compilation. + # But our implementation prioritized this for an invalid nonlocal + # and recovered the complation process. + return x +x = 1 and 2 +foo(y, 5) \ No newline at end of file diff --git a/src/test/data/pa2/student_contributed/diff.py.ast.typed b/src/test/data/pa2/student_contributed/diff.py.ast.typed new file mode 100644 index 0000000..fc12776 --- /dev/null +++ b/src/test/data/pa2/student_contributed/diff.py.ast.typed @@ -0,0 +1,260 @@ +{ + "kind" : "Program", + "location" : [ 1, 1, 17, 10 ], + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 1, 1, 1, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 1, 1, 1, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 1, 1, 1, 1 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 1, 5, 1, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 1, 11, 1, 11 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 2, 1, 2, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 2, 1, 2, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 2, 1, 2, 1 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 2, 5, 2, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 2, 11, 2, 11 ], + "value" : 5 + } + }, { + "kind" : "VarDef", + "location" : [ 3, 1, 3, 14 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 1, 3, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 1, 3, 1 ], + "name" : "z" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 5, 3, 7 ], + "className" : "Foo" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 3, 11, 3, 14 ] + } + }, { + "kind" : "ClassDef", + "location" : [ 4, 1, 5, 16 ], + "name" : { + "kind" : "Identifier", + "location" : [ 4, 7, 4, 9 ], + "name" : "Foo" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 4, 11, 4, 16 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 5, 5, 5, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 5, 5, 5, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 5, 5, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 9, 5, 11 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 5, 15, 5, 15 ], + "value" : 3 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 6, 1, 15, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 6, 5, 6, 7 ], + "name" : "foo" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 6, 9, 6, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 6, 9, 6, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 6, 13, 6, 15 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 6, 21, 6, 23 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 7, 5, 7, 20 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 7, 5, 7, 11 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 7, 5, 7, 5 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 7, 9, 7, 11 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 7, 15, 7, 20 ], + "value" : "test" + } + }, { + "kind" : "FuncDef", + "location" : [ 8, 5, 10, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 12 ], + "name" : "foo2" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 19, 8, 21 ], + "className" : "str" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 9, 9, 9, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 9, 18, 9, 18 ], + "name" : "y" + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 10, 9, 10, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 10, 16, 10, 16 ], + "name" : "y" + } + } ] + }, { + "kind" : "NonLocalDecl", + "location" : [ 11, 5, 11, 14 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 11, 14, 11, 14 ], + "errorMsg" : "Duplicate declaration of identifier in same scope: x", + "name" : "x" + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 15, 5, 15, 12 ], + "value" : { + "kind" : "Identifier", + "location" : [ 15, 12, 15, 12 ], + "name" : "x" + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 16, 1, 16, 11 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 16, 1, 16, 1 ], + "name" : "x" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 16, 5, 16, 11 ], + "left" : { + "kind" : "IntegerLiteral", + "location" : [ 16, 5, 16, 5 ], + "value" : 1 + }, + "operator" : "and", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 16, 11, 16, 11 ], + "value" : 2 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 17, 1, 17, 9 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 17, 1, 17, 9 ], + "function" : { + "kind" : "Identifier", + "location" : [ 17, 1, 17, 3 ], + "name" : "foo" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 17, 5, 17, 5 ], + "name" : "y" + }, { + "kind" : "IntegerLiteral", + "location" : [ 17, 8, 17, 8 ], + "value" : 5 + } ] + } + } ], + "errors" : { + "errors" : [ { + "kind" : "CompilerError", + "location" : [ 11, 14, 11, 14 ], + "message" : "Duplicate declaration of identifier in same scope: x" + } ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/student_contributed/good.py b/src/test/data/pa2/student_contributed/good.py new file mode 100644 index 0000000..f6ae4b9 --- /dev/null +++ b/src/test/data/pa2/student_contributed/good.py @@ -0,0 +1,110 @@ +# class defs +class A_CLASS(object): + a_class_i:int = 0 + x:int=0 + def __init__(self:"A_CLASS"): + self.x = 0 + + def add(self:"A_CLASS", y:int) -> int: + y = y+self.x + return y + +class B_CLASS(object): + b_class_i:int = 0 + +class C_CLASS(B_CLASS): + pass + +# var defs +a_s:str = "a_s" +b_s:str = "b_s" +c_s:str = "c_s" + +a_i:int = 0 +b_i:int = 0 +c_i:int = 0 + +a_b:bool = False +b_b:bool = False +c_b:bool = False + +a_list:[int] = None +b_list:[int] = None +c_list:[int] = None + +a_class:A_CLASS = None +b_class:B_CLASS = None +c_class:C_CLASS = None + + +# fun defs +def f_1() -> object: + def f_f_1() -> object: + global a_s + print(a_s) + pass + pass + +def f_2() -> object: + f_a_s:str = "s" + def f_f_2() -> object: + nonlocal f_a_s + print(f_a_s) + pass + pass + +def f_3(x:int) -> int: + f_b_s:int = 3 + return x*f_b_s + +# Declarations +a_list = [1, 2, 3] +b_list = [0, 0, 0] +c_list = [-1, -2, -3] + +a_class = A_CLASS() +b_class = B_CLASS() +c_class = C_CLASS() + + +# POSITIVE TEST CASES + +#------------------- +# String operations +# String addition and assignment operations +a_s = a_s + b_s +print(a_s) + +# Assigning to a string with string indexing operation +c_s = a_s[0] +print(c_s) + + +# -------------------- +# Boolean operations +a_b = a_i == b_i and not b_b +print(a_b) + + +# -------------------- +# List operations +a_list = a_list + b_list +c_i = a_list[0] +a_list[1] = 2 + + +# -------------------- +# function operations +a_i = f_3(3) + 5 +f_1() +f_2() + + +# -------------------- +# class operations +a_i = a_class.add(2) +print(a_i) + + +a_i = a_class.add(c_class.b_class_i) +print(a_i) diff --git a/src/test/data/pa2/student_contributed/good.py.ast b/src/test/data/pa2/student_contributed/good.py.ast new file mode 100644 index 0000000..32b037c --- /dev/null +++ b/src/test/data/pa2/student_contributed/good.py.ast @@ -0,0 +1,1301 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 110, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 2, 1, 12, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 13 ], + "name" : "A_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 2, 15, 2, 20 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 13 ], + "name" : "a_class_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 15, 3, 17 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 21, 3, 21 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 7, 4, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 11, 4, 11 ], + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 18, 5, 31 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 23, 5, 31 ], + "className" : "A_CLASS" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 33, 5, 33 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 6, 9, 6, 18 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 6, 9, 6, 14 ], + "object" : { + "kind" : "Identifier", + "location" : [ 6, 9, 6, 12 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 6, 14, 6, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 18, 6, 18 ], + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 8, 5, 10, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 11 ], + "name" : "add" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 13, 8, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 13, 8, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 18, 8, 26 ], + "className" : "A_CLASS" + } + }, { + "kind" : "TypedVar", + "location" : [ 8, 29, 8, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 29, 8, 29 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 31, 8, 33 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 39, 8, 41 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 9, 9, 9, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 9 ], + "name" : "y" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 9, 13, 9, 20 ], + "left" : { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 13 ], + "name" : "y" + }, + "operator" : "+", + "right" : { + "kind" : "MemberExpr", + "location" : [ 9, 15, 9, 20 ], + "object" : { + "kind" : "Identifier", + "location" : [ 9, 15, 9, 18 ], + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 9, 20, 9, 20 ], + "name" : "x" + } + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 10, 9, 10, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 10, 16, 10, 16 ], + "name" : "y" + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 12, 1, 13, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 12, 7, 12, 13 ], + "name" : "B_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 12, 15, 12, 20 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 13, 5, 13, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 5, 13, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 13 ], + "name" : "b_class_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 15, 13, 17 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 21, 13, 21 ], + "value" : 0 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 15, 1, 16, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 13 ], + "name" : "C_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 15, 15, 15, 21 ], + "name" : "B_CLASS" + }, + "declarations" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 19, 1, 19, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 19, 1, 19, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 3 ], + "name" : "a_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 5, 19, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 19, 11, 19, 15 ], + "value" : "a_s" + } + }, { + "kind" : "VarDef", + "location" : [ 20, 1, 20, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 20, 1, 20, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 20, 1, 20, 3 ], + "name" : "b_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 20, 5, 20, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 20, 11, 20, 15 ], + "value" : "b_s" + } + }, { + "kind" : "VarDef", + "location" : [ 21, 1, 21, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 21, 1, 21, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 21, 1, 21, 3 ], + "name" : "c_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 21, 5, 21, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 21, 11, 21, 15 ], + "value" : "c_s" + } + }, { + "kind" : "VarDef", + "location" : [ 23, 1, 23, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 23, 1, 23, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 23, 1, 23, 3 ], + "name" : "a_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 23, 5, 23, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 23, 11, 23, 11 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 24, 1, 24, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 24, 1, 24, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 24, 1, 24, 3 ], + "name" : "b_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 24, 5, 24, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 11, 24, 11 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 25, 1, 25, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 25, 1, 25, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 25, 1, 25, 3 ], + "name" : "c_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 25, 5, 25, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 25, 11, 25, 11 ], + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 27, 1, 27, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 27, 1, 27, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 27, 1, 27, 3 ], + "name" : "a_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 27, 5, 27, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 27, 12, 27, 16 ], + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 28, 1, 28, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 28, 1, 28, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 28, 1, 28, 3 ], + "name" : "b_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 28, 5, 28, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 28, 12, 28, 16 ], + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 29, 1, 29, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 29, 1, 29, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 1, 29, 3 ], + "name" : "c_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 29, 5, 29, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 29, 12, 29, 16 ], + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 31, 1, 31, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 31, 1, 31, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 31, 1, 31, 6 ], + "name" : "a_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 31, 8, 31, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 31, 9, 31, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 31, 16, 31, 19 ] + } + }, { + "kind" : "VarDef", + "location" : [ 32, 1, 32, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 32, 1, 32, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 32, 1, 32, 6 ], + "name" : "b_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 32, 8, 32, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 32, 9, 32, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 32, 16, 32, 19 ] + } + }, { + "kind" : "VarDef", + "location" : [ 33, 1, 33, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 33, 1, 33, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 33, 1, 33, 6 ], + "name" : "c_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 33, 8, 33, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 33, 9, 33, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 33, 16, 33, 19 ] + } + }, { + "kind" : "VarDef", + "location" : [ 35, 1, 35, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 35, 1, 35, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 35, 1, 35, 7 ], + "name" : "a_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 35, 9, 35, 15 ], + "className" : "A_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 35, 19, 35, 22 ] + } + }, { + "kind" : "VarDef", + "location" : [ 36, 1, 36, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 36, 1, 36, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 36, 1, 36, 7 ], + "name" : "b_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 36, 9, 36, 15 ], + "className" : "B_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 36, 19, 36, 22 ] + } + }, { + "kind" : "VarDef", + "location" : [ 37, 1, 37, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 37, 1, 37, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 37, 1, 37, 7 ], + "name" : "c_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 37, 9, 37, 15 ], + "className" : "C_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 37, 19, 37, 22 ] + } + }, { + "kind" : "FuncDef", + "location" : [ 41, 1, 46, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 41, 5, 41, 7 ], + "name" : "f_1" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 41, 14, 41, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 42, 5, 45, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 42, 9, 42, 13 ], + "name" : "f_f_1" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 42, 20, 42, 25 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 43, 9, 43, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 43, 16, 43, 18 ], + "name" : "a_s" + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 44, 9, 44, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 44, 9, 44, 18 ], + "function" : { + "kind" : "Identifier", + "location" : [ 44, 9, 44, 13 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 44, 15, 44, 17 ], + "name" : "a_s" + } ] + } + } ] + } ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 48, 1, 54, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 48, 5, 48, 7 ], + "name" : "f_2" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 48, 14, 48, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 49, 5, 49, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 49, 5, 49, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 49, 5, 49, 9 ], + "name" : "f_a_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 49, 11, 49, 13 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 49, 17, 49, 19 ], + "value" : "s" + } + }, { + "kind" : "FuncDef", + "location" : [ 50, 5, 53, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 50, 9, 50, 13 ], + "name" : "f_f_2" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 50, 20, 50, 25 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 51, 9, 51, 22 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 51, 18, 51, 22 ], + "name" : "f_a_s" + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 52, 9, 52, 20 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 52, 9, 52, 20 ], + "function" : { + "kind" : "Identifier", + "location" : [ 52, 9, 52, 13 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 52, 15, 52, 19 ], + "name" : "f_a_s" + } ] + } + } ] + } ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 56, 1, 58, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 56, 5, 56, 7 ], + "name" : "f_3" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 56, 9, 56, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 56, 9, 56, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 56, 11, 56, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 56, 19, 56, 21 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 57, 5, 57, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 57, 5, 57, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 57, 5, 57, 9 ], + "name" : "f_b_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 57, 11, 57, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 57, 17, 57, 17 ], + "value" : 3 + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 58, 5, 58, 18 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 58, 12, 58, 18 ], + "left" : { + "kind" : "Identifier", + "location" : [ 58, 12, 58, 12 ], + "name" : "x" + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 58, 14, 58, 18 ], + "name" : "f_b_s" + } + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 61, 1, 61, 18 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 61, 1, 61, 6 ], + "name" : "a_list" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 61, 10, 61, 18 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 61, 11, 61, 11 ], + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 61, 14, 61, 14 ], + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 61, 17, 61, 17 ], + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 62, 1, 62, 18 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 62, 1, 62, 6 ], + "name" : "b_list" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 62, 10, 62, 18 ], + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 62, 11, 62, 11 ], + "value" : 0 + }, { + "kind" : "IntegerLiteral", + "location" : [ 62, 14, 62, 14 ], + "value" : 0 + }, { + "kind" : "IntegerLiteral", + "location" : [ 62, 17, 62, 17 ], + "value" : 0 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 63, 1, 63, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 63, 1, 63, 6 ], + "name" : "c_list" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 63, 10, 63, 21 ], + "elements" : [ { + "kind" : "UnaryExpr", + "location" : [ 63, 11, 63, 12 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 63, 12, 63, 12 ], + "value" : 1 + } + }, { + "kind" : "UnaryExpr", + "location" : [ 63, 15, 63, 16 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 63, 16, 63, 16 ], + "value" : 2 + } + }, { + "kind" : "UnaryExpr", + "location" : [ 63, 19, 63, 20 ], + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 63, 20, 63, 20 ], + "value" : 3 + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 65, 1, 65, 19 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 65, 1, 65, 7 ], + "name" : "a_class" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 65, 11, 65, 19 ], + "function" : { + "kind" : "Identifier", + "location" : [ 65, 11, 65, 17 ], + "name" : "A_CLASS" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 66, 1, 66, 19 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 66, 1, 66, 7 ], + "name" : "b_class" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 66, 11, 66, 19 ], + "function" : { + "kind" : "Identifier", + "location" : [ 66, 11, 66, 17 ], + "name" : "B_CLASS" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 67, 1, 67, 19 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 67, 1, 67, 7 ], + "name" : "c_class" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 67, 11, 67, 19 ], + "function" : { + "kind" : "Identifier", + "location" : [ 67, 11, 67, 17 ], + "name" : "C_CLASS" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 75, 1, 75, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 75, 1, 75, 3 ], + "name" : "a_s" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 75, 7, 75, 15 ], + "left" : { + "kind" : "Identifier", + "location" : [ 75, 7, 75, 9 ], + "name" : "a_s" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 75, 13, 75, 15 ], + "name" : "b_s" + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 76, 1, 76, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 76, 1, 76, 10 ], + "function" : { + "kind" : "Identifier", + "location" : [ 76, 1, 76, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 76, 7, 76, 9 ], + "name" : "a_s" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 79, 1, 79, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 79, 1, 79, 3 ], + "name" : "c_s" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 79, 7, 79, 12 ], + "list" : { + "kind" : "Identifier", + "location" : [ 79, 7, 79, 9 ], + "name" : "a_s" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 79, 11, 79, 11 ], + "value" : 0 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 80, 1, 80, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 80, 1, 80, 10 ], + "function" : { + "kind" : "Identifier", + "location" : [ 80, 1, 80, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 80, 7, 80, 9 ], + "name" : "c_s" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 85, 1, 85, 28 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 85, 1, 85, 3 ], + "name" : "a_b" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 85, 7, 85, 28 ], + "left" : { + "kind" : "BinaryExpr", + "location" : [ 85, 7, 85, 16 ], + "left" : { + "kind" : "Identifier", + "location" : [ 85, 7, 85, 9 ], + "name" : "a_i" + }, + "operator" : "==", + "right" : { + "kind" : "Identifier", + "location" : [ 85, 14, 85, 16 ], + "name" : "b_i" + } + }, + "operator" : "and", + "right" : { + "kind" : "UnaryExpr", + "location" : [ 85, 22, 85, 28 ], + "operator" : "not", + "operand" : { + "kind" : "Identifier", + "location" : [ 85, 26, 85, 28 ], + "name" : "b_b" + } + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 86, 1, 86, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 86, 1, 86, 10 ], + "function" : { + "kind" : "Identifier", + "location" : [ 86, 1, 86, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 86, 7, 86, 9 ], + "name" : "a_b" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 91, 1, 91, 24 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 91, 1, 91, 6 ], + "name" : "a_list" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 91, 10, 91, 24 ], + "left" : { + "kind" : "Identifier", + "location" : [ 91, 10, 91, 15 ], + "name" : "a_list" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 91, 19, 91, 24 ], + "name" : "b_list" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 92, 1, 92, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 92, 1, 92, 3 ], + "name" : "c_i" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 92, 7, 92, 15 ], + "list" : { + "kind" : "Identifier", + "location" : [ 92, 7, 92, 12 ], + "name" : "a_list" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 92, 14, 92, 14 ], + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 93, 1, 93, 13 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 93, 1, 93, 9 ], + "list" : { + "kind" : "Identifier", + "location" : [ 93, 1, 93, 6 ], + "name" : "a_list" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 93, 8, 93, 8 ], + "value" : 1 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 93, 13, 93, 13 ], + "value" : 2 + } + }, { + "kind" : "AssignStmt", + "location" : [ 98, 1, 98, 16 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 98, 1, 98, 3 ], + "name" : "a_i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 98, 7, 98, 16 ], + "left" : { + "kind" : "CallExpr", + "location" : [ 98, 7, 98, 12 ], + "function" : { + "kind" : "Identifier", + "location" : [ 98, 7, 98, 9 ], + "name" : "f_3" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 98, 11, 98, 11 ], + "value" : 3 + } ] + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 98, 16, 98, 16 ], + "value" : 5 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 99, 1, 99, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 99, 1, 99, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 99, 1, 99, 3 ], + "name" : "f_1" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 100, 1, 100, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 100, 1, 100, 5 ], + "function" : { + "kind" : "Identifier", + "location" : [ 100, 1, 100, 3 ], + "name" : "f_2" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 105, 1, 105, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 105, 1, 105, 3 ], + "name" : "a_i" + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 105, 7, 105, 20 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 105, 7, 105, 17 ], + "object" : { + "kind" : "Identifier", + "location" : [ 105, 7, 105, 13 ], + "name" : "a_class" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 105, 15, 105, 17 ], + "name" : "add" + } + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 105, 19, 105, 19 ], + "value" : 2 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 106, 1, 106, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 106, 1, 106, 10 ], + "function" : { + "kind" : "Identifier", + "location" : [ 106, 1, 106, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 106, 7, 106, 9 ], + "name" : "a_i" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 109, 1, 109, 36 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 109, 1, 109, 3 ], + "name" : "a_i" + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 109, 7, 109, 36 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 109, 7, 109, 17 ], + "object" : { + "kind" : "Identifier", + "location" : [ 109, 7, 109, 13 ], + "name" : "a_class" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 109, 15, 109, 17 ], + "name" : "add" + } + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 109, 19, 109, 35 ], + "object" : { + "kind" : "Identifier", + "location" : [ 109, 19, 109, 25 ], + "name" : "c_class" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 109, 27, 109, 35 ], + "name" : "b_class_i" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 110, 1, 110, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 110, 1, 110, 10 ], + "function" : { + "kind" : "Identifier", + "location" : [ 110, 1, 110, 5 ], + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 110, 7, 110, 9 ], + "name" : "a_i" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/src/test/data/pa2/student_contributed/good.py.ast.typed b/src/test/data/pa2/student_contributed/good.py.ast.typed new file mode 100644 index 0000000..9401bb9 --- /dev/null +++ b/src/test/data/pa2/student_contributed/good.py.ast.typed @@ -0,0 +1,1921 @@ +{ + "kind" : "Program", + "location" : [ 2, 1, 110, 11 ], + "declarations" : [ { + "kind" : "ClassDef", + "location" : [ 2, 1, 12, 0 ], + "name" : { + "kind" : "Identifier", + "location" : [ 2, 7, 2, 13 ], + "name" : "A_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 2, 15, 2, 20 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 3, 5, 3, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 3, 5, 3, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 3, 5, 3, 13 ], + "name" : "a_class_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 3, 15, 3, 17 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 3, 21, 3, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 4, 5, 4, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 4, 5, 4, 9 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 4, 5, 4, 5 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 4, 7, 4, 9 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 4, 11, 4, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "FuncDef", + "location" : [ 5, 5, 6, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 5, 9, 5, 16 ], + "name" : "__init__" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 5, 18, 5, 31 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 5, 18, 5, 21 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 5, 23, 5, 31 ], + "className" : "A_CLASS" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 5, 33, 5, 33 ], + "className" : "" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 6, 9, 6, 18 ], + "targets" : [ { + "kind" : "MemberExpr", + "location" : [ 6, 9, 6, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 6, 9, 6, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A_CLASS" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 6, 14, 6, 14 ], + "name" : "x" + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 6, 18, 6, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + }, { + "kind" : "FuncDef", + "location" : [ 8, 5, 10, 17 ], + "name" : { + "kind" : "Identifier", + "location" : [ 8, 9, 8, 11 ], + "name" : "add" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 8, 13, 8, 26 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 13, 8, 16 ], + "name" : "self" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 18, 8, 26 ], + "className" : "A_CLASS" + } + }, { + "kind" : "TypedVar", + "location" : [ 8, 29, 8, 33 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 8, 29, 8, 29 ], + "name" : "y" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 8, 31, 8, 33 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 8, 39, 8, 41 ], + "className" : "int" + }, + "declarations" : [ ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 9, 9, 9, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 9, 9, 9, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 9, 13, 9, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 9, 13, 9, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + }, + "operator" : "+", + "right" : { + "kind" : "MemberExpr", + "location" : [ 9, 15, 9, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 9, 15, 9, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A_CLASS" + }, + "name" : "self" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 9, 20, 9, 20 ], + "name" : "x" + } + } + } + }, { + "kind" : "ReturnStmt", + "location" : [ 10, 9, 10, 16 ], + "value" : { + "kind" : "Identifier", + "location" : [ 10, 16, 10, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "y" + } + } ] + } ] + }, { + "kind" : "ClassDef", + "location" : [ 12, 1, 13, 22 ], + "name" : { + "kind" : "Identifier", + "location" : [ 12, 7, 12, 13 ], + "name" : "B_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 12, 15, 12, 20 ], + "name" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 13, 5, 13, 21 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 13, 5, 13, 17 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 13, 5, 13, 13 ], + "name" : "b_class_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 13, 15, 13, 17 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 13, 21, 13, 21 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } ] + }, { + "kind" : "ClassDef", + "location" : [ 15, 1, 16, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 15, 7, 15, 13 ], + "name" : "C_CLASS" + }, + "superClass" : { + "kind" : "Identifier", + "location" : [ 15, 15, 15, 21 ], + "name" : "B_CLASS" + }, + "declarations" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 19, 1, 19, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 19, 1, 19, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 19, 1, 19, 3 ], + "name" : "a_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 19, 5, 19, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 19, 11, 19, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "a_s" + } + }, { + "kind" : "VarDef", + "location" : [ 20, 1, 20, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 20, 1, 20, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 20, 1, 20, 3 ], + "name" : "b_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 20, 5, 20, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 20, 11, 20, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "b_s" + } + }, { + "kind" : "VarDef", + "location" : [ 21, 1, 21, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 21, 1, 21, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 21, 1, 21, 3 ], + "name" : "c_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 21, 5, 21, 7 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 21, 11, 21, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "c_s" + } + }, { + "kind" : "VarDef", + "location" : [ 23, 1, 23, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 23, 1, 23, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 23, 1, 23, 3 ], + "name" : "a_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 23, 5, 23, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 23, 11, 23, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 24, 1, 24, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 24, 1, 24, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 24, 1, 24, 3 ], + "name" : "b_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 24, 5, 24, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 24, 11, 24, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 25, 1, 25, 11 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 25, 1, 25, 7 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 25, 1, 25, 3 ], + "name" : "c_i" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 25, 5, 25, 7 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 25, 11, 25, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + }, { + "kind" : "VarDef", + "location" : [ 27, 1, 27, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 27, 1, 27, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 27, 1, 27, 3 ], + "name" : "a_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 27, 5, 27, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 27, 12, 27, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 28, 1, 28, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 28, 1, 28, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 28, 1, 28, 3 ], + "name" : "b_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 28, 5, 28, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 28, 12, 28, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 29, 1, 29, 16 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 29, 1, 29, 8 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 29, 1, 29, 3 ], + "name" : "c_b" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 29, 5, 29, 8 ], + "className" : "bool" + } + }, + "value" : { + "kind" : "BooleanLiteral", + "location" : [ 29, 12, 29, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "value" : false + } + }, { + "kind" : "VarDef", + "location" : [ 31, 1, 31, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 31, 1, 31, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 31, 1, 31, 6 ], + "name" : "a_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 31, 8, 31, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 31, 9, 31, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 31, 16, 31, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 32, 1, 32, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 32, 1, 32, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 32, 1, 32, 6 ], + "name" : "b_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 32, 8, 32, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 32, 9, 32, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 32, 16, 32, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 33, 1, 33, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 33, 1, 33, 12 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 33, 1, 33, 6 ], + "name" : "c_list" + }, + "type" : { + "kind" : "ListType", + "location" : [ 33, 8, 33, 12 ], + "elementType" : { + "kind" : "ClassType", + "location" : [ 33, 9, 33, 11 ], + "className" : "int" + } + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 33, 16, 33, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 35, 1, 35, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 35, 1, 35, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 35, 1, 35, 7 ], + "name" : "a_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 35, 9, 35, 15 ], + "className" : "A_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 35, 19, 35, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 36, 1, 36, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 36, 1, 36, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 36, 1, 36, 7 ], + "name" : "b_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 36, 9, 36, 15 ], + "className" : "B_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 36, 19, 36, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "VarDef", + "location" : [ 37, 1, 37, 22 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 37, 1, 37, 15 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 37, 1, 37, 7 ], + "name" : "c_class" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 37, 9, 37, 15 ], + "className" : "C_CLASS" + } + }, + "value" : { + "kind" : "NoneLiteral", + "location" : [ 37, 19, 37, 22 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + } + } + }, { + "kind" : "FuncDef", + "location" : [ 41, 1, 46, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 41, 5, 41, 7 ], + "name" : "f_1" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 41, 14, 41, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "FuncDef", + "location" : [ 42, 5, 45, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 42, 9, 42, 13 ], + "name" : "f_f_1" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 42, 20, 42, 25 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "GlobalDecl", + "location" : [ 43, 9, 43, 18 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 43, 16, 43, 18 ], + "name" : "a_s" + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 44, 9, 44, 18 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 44, 9, 44, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 44, 9, 44, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 44, 15, 44, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a_s" + } ] + } + } ] + } ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 48, 1, 54, 9 ], + "name" : { + "kind" : "Identifier", + "location" : [ 48, 5, 48, 7 ], + "name" : "f_2" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 48, 14, 48, 19 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 49, 5, 49, 19 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 49, 5, 49, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 49, 5, 49, 9 ], + "name" : "f_a_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 49, 11, 49, 13 ], + "className" : "str" + } + }, + "value" : { + "kind" : "StringLiteral", + "location" : [ 49, 17, 49, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "value" : "s" + } + }, { + "kind" : "FuncDef", + "location" : [ 50, 5, 53, 13 ], + "name" : { + "kind" : "Identifier", + "location" : [ 50, 9, 50, 13 ], + "name" : "f_f_2" + }, + "params" : [ ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 50, 20, 50, 25 ], + "className" : "object" + }, + "declarations" : [ { + "kind" : "NonLocalDecl", + "location" : [ 51, 9, 51, 22 ], + "variable" : { + "kind" : "Identifier", + "location" : [ 51, 18, 51, 22 ], + "name" : "f_a_s" + } + } ], + "statements" : [ { + "kind" : "ExprStmt", + "location" : [ 52, 9, 52, 20 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 52, 9, 52, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 52, 9, 52, 13 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 52, 15, 52, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "f_a_s" + } ] + } + } ] + } ], + "statements" : [ ] + }, { + "kind" : "FuncDef", + "location" : [ 56, 1, 58, 19 ], + "name" : { + "kind" : "Identifier", + "location" : [ 56, 5, 56, 7 ], + "name" : "f_3" + }, + "params" : [ { + "kind" : "TypedVar", + "location" : [ 56, 9, 56, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 56, 9, 56, 9 ], + "name" : "x" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 56, 11, 56, 13 ], + "className" : "int" + } + } ], + "returnType" : { + "kind" : "ClassType", + "location" : [ 56, 19, 56, 21 ], + "className" : "int" + }, + "declarations" : [ { + "kind" : "VarDef", + "location" : [ 57, 5, 57, 17 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 57, 5, 57, 13 ], + "identifier" : { + "kind" : "Identifier", + "location" : [ 57, 5, 57, 9 ], + "name" : "f_b_s" + }, + "type" : { + "kind" : "ClassType", + "location" : [ 57, 11, 57, 13 ], + "className" : "int" + } + }, + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 57, 17, 57, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + } ], + "statements" : [ { + "kind" : "ReturnStmt", + "location" : [ 58, 5, 58, 18 ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 58, 12, 58, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 58, 12, 58, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "x" + }, + "operator" : "*", + "right" : { + "kind" : "Identifier", + "location" : [ 58, 14, 58, 18 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "f_b_s" + } + } + } ] + } ], + "statements" : [ { + "kind" : "AssignStmt", + "location" : [ 61, 1, 61, 18 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 61, 1, 61, 6 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "a_list" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 61, 10, 61, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 61, 11, 61, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + }, { + "kind" : "IntegerLiteral", + "location" : [ 61, 14, 61, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + }, { + "kind" : "IntegerLiteral", + "location" : [ 61, 17, 61, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 62, 1, 62, 18 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 62, 1, 62, 6 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "b_list" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 62, 10, 62, 18 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "IntegerLiteral", + "location" : [ 62, 11, 62, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + }, { + "kind" : "IntegerLiteral", + "location" : [ 62, 14, 62, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + }, { + "kind" : "IntegerLiteral", + "location" : [ 62, 17, 62, 17 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 63, 1, 63, 21 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 63, 1, 63, 6 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "c_list" + } ], + "value" : { + "kind" : "ListExpr", + "location" : [ 63, 10, 63, 21 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "elements" : [ { + "kind" : "UnaryExpr", + "location" : [ 63, 11, 63, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 63, 12, 63, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + }, { + "kind" : "UnaryExpr", + "location" : [ 63, 15, 63, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 63, 16, 63, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + }, { + "kind" : "UnaryExpr", + "location" : [ 63, 19, 63, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "operator" : "-", + "operand" : { + "kind" : "IntegerLiteral", + "location" : [ 63, 20, 63, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 65, 1, 65, 19 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 65, 1, 65, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A_CLASS" + }, + "name" : "a_class" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 65, 11, 65, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A_CLASS" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 65, 11, 65, 17 ], + "name" : "A_CLASS" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 66, 1, 66, 19 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 66, 1, 66, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B_CLASS" + }, + "name" : "b_class" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 66, 11, 66, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "B_CLASS" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 66, 11, 66, 17 ], + "name" : "B_CLASS" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 67, 1, 67, 19 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 67, 1, 67, 7 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C_CLASS" + }, + "name" : "c_class" + } ], + "value" : { + "kind" : "CallExpr", + "location" : [ 67, 11, 67, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C_CLASS" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 67, 11, 67, 17 ], + "name" : "C_CLASS" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 75, 1, 75, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 75, 1, 75, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a_s" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 75, 7, 75, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 75, 7, 75, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a_s" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 75, 13, 75, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "b_s" + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 76, 1, 76, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 76, 1, 76, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 76, 1, 76, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 76, 7, 76, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a_s" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 79, 1, 79, 12 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 79, 1, 79, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "c_s" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 79, 7, 79, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 79, 7, 79, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "a_s" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 79, 11, 79, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 80, 1, 80, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 80, 1, 80, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 80, 1, 80, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 80, 7, 80, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "str" + }, + "name" : "c_s" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 85, 1, 85, 28 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 85, 1, 85, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "name" : "a_b" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 85, 7, 85, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "BinaryExpr", + "location" : [ 85, 7, 85, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "left" : { + "kind" : "Identifier", + "location" : [ 85, 7, 85, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "a_i" + }, + "operator" : "==", + "right" : { + "kind" : "Identifier", + "location" : [ 85, 14, 85, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "b_i" + } + }, + "operator" : "and", + "right" : { + "kind" : "UnaryExpr", + "location" : [ 85, 22, 85, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "operator" : "not", + "operand" : { + "kind" : "Identifier", + "location" : [ 85, 26, 85, 28 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "name" : "b_b" + } + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 86, 1, 86, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 86, 1, 86, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 86, 1, 86, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 86, 7, 86, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "bool" + }, + "name" : "a_b" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 91, 1, 91, 24 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 91, 1, 91, 6 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "a_list" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 91, 10, 91, 24 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "left" : { + "kind" : "Identifier", + "location" : [ 91, 10, 91, 15 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "a_list" + }, + "operator" : "+", + "right" : { + "kind" : "Identifier", + "location" : [ 91, 19, 91, 24 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "b_list" + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 92, 1, 92, 15 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 92, 1, 92, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "c_i" + } ], + "value" : { + "kind" : "IndexExpr", + "location" : [ 92, 7, 92, 15 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 92, 7, 92, 12 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "a_list" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 92, 14, 92, 14 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 0 + } + } + }, { + "kind" : "AssignStmt", + "location" : [ 93, 1, 93, 13 ], + "targets" : [ { + "kind" : "IndexExpr", + "location" : [ 93, 1, 93, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "list" : { + "kind" : "Identifier", + "location" : [ 93, 1, 93, 6 ], + "inferredType" : { + "kind" : "ListValueType", + "elementType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "a_list" + }, + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 93, 8, 93, 8 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 1 + } + } ], + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 93, 13, 93, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } + }, { + "kind" : "AssignStmt", + "location" : [ 98, 1, 98, 16 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 98, 1, 98, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "a_i" + } ], + "value" : { + "kind" : "BinaryExpr", + "location" : [ 98, 7, 98, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "left" : { + "kind" : "CallExpr", + "location" : [ 98, 7, 98, 12 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 98, 7, 98, 9 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "name" : "f_3" + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 98, 11, 98, 11 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 3 + } ] + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 98, 16, 98, 16 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 5 + } + } + }, { + "kind" : "ExprStmt", + "location" : [ 99, 1, 99, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 99, 1, 99, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 99, 1, 99, 3 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "f_1" + }, + "args" : [ ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 100, 1, 100, 5 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 100, 1, 100, 5 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "object" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 100, 1, 100, 3 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "object" + } + }, + "name" : "f_2" + }, + "args" : [ ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 105, 1, 105, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 105, 1, 105, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "a_i" + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 105, 7, 105, 20 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 105, 7, 105, 17 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "A_CLASS" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 105, 7, 105, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A_CLASS" + }, + "name" : "a_class" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 105, 15, 105, 17 ], + "name" : "add" + } + }, + "args" : [ { + "kind" : "IntegerLiteral", + "location" : [ 105, 19, 105, 19 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "value" : 2 + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 106, 1, 106, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 106, 1, 106, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 106, 1, 106, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 106, 7, 106, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "a_i" + } ] + } + }, { + "kind" : "AssignStmt", + "location" : [ 109, 1, 109, 36 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 109, 1, 109, 3 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "a_i" + } ], + "value" : { + "kind" : "MethodCallExpr", + "location" : [ 109, 7, 109, 36 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "method" : { + "kind" : "MemberExpr", + "location" : [ 109, 7, 109, 17 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "A_CLASS" + }, { + "kind" : "ClassValueType", + "className" : "int" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "int" + } + }, + "object" : { + "kind" : "Identifier", + "location" : [ 109, 7, 109, 13 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "A_CLASS" + }, + "name" : "a_class" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 109, 15, 109, 17 ], + "name" : "add" + } + }, + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 109, 19, 109, 35 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "object" : { + "kind" : "Identifier", + "location" : [ 109, 19, 109, 25 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "C_CLASS" + }, + "name" : "c_class" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 109, 27, 109, 35 ], + "name" : "b_class_i" + } + } ] + } + }, { + "kind" : "ExprStmt", + "location" : [ 110, 1, 110, 10 ], + "expr" : { + "kind" : "CallExpr", + "location" : [ 110, 1, 110, 10 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "" + }, + "function" : { + "kind" : "Identifier", + "location" : [ 110, 1, 110, 5 ], + "inferredType" : { + "kind" : "FuncType", + "parameters" : [ { + "kind" : "ClassValueType", + "className" : "object" + } ], + "returnType" : { + "kind" : "ClassValueType", + "className" : "" + } + }, + "name" : "print" + }, + "args" : [ { + "kind" : "Identifier", + "location" : [ 110, 7, 110, 9 ], + "inferredType" : { + "kind" : "ClassValueType", + "className" : "int" + }, + "name" : "a_i" + } ] + } + } ], + "errors" : { + "errors" : [ ], + "kind" : "Errors", + "location" : [ 0, 0, 0, 0 ] + } +} \ No newline at end of file diff --git a/test_benchmarks.sh b/test_benchmarks.sh new file mode 100755 index 0000000..ccbb526 --- /dev/null +++ b/test_benchmarks.sh @@ -0,0 +1,5 @@ +#!/bin/bash + + +echo "Running all test cases inside src/test/data/pa3/sample/ folder)" +java -cp "chocopy-ref.jar:target/assignment.jar" chocopy.ChocoPy --pass=sss --test --run --dir src/test/data/pa3/benchmarks/ diff --git a/test_gen.sh b/test_gen.sh new file mode 100755 index 0000000..ae3c2ea --- /dev/null +++ b/test_gen.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +echo "Running all test cases inside src/test/data/pa2/sample/ folder)" +java -cp "chocopy-ref.jar:target/assignment.jar" chocopy.ChocoPy --pass=rr --reset --dir src/test/data/pa2/ +# good.py can't be parsed by reference compiler, because it contains our improvements in PA1. Therefore, we generate the ast with our parser and then use the reference semantic checker to generate the reference type information for testing. +java -cp "chocopy-ref.jar:target/assignment.jar" chocopy.ChocoPy --pass=s --reset --dir src/test/data/pa2/student_contributed/good.py +java -cp "chocopy-ref.jar:target/assignment.jar" chocopy.ChocoPy --pass=.r --reset --dir src/test/data/pa2/student_contributed/good.py.ast + diff --git a/test_py_file.sh b/test_py_file.sh new file mode 100755 index 0000000..8334e48 --- /dev/null +++ b/test_py_file.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +FILENAME=$1 + +if [ -z "$1" ] ; then + echo "Usage for individual test cases: test.sh FILEPATH, where FILEPATH is the location of the python file" + exit 1 +fi + +echo "Testing file ${FILENAME}" + +echo "Generating .ast.typed file using student parser and reference analyzer" +java -cp "chocopy-ref.jar:target/assignment.jar" chocopy.ChocoPy --pass=sr \ + ${FILENAME} --out=${FILENAME}.ast.typed + +echo "Comparing the pervious output with student parser and student analyzer" +java -cp "chocopy-ref.jar:target/assignment.jar" chocopy.ChocoPy \ + --pass=ss --test ${FILENAME} diff --git a/test_sample.sh b/test_sample.sh index b6da460..83d419a 100755 --- a/test_sample.sh +++ b/test_sample.sh @@ -1,5 +1,6 @@ #!/bin/bash + echo "Running all test cases inside src/test/data/pa3/sample/ folder)" -java -cp "chocopy-ref.jar:target/assignment.jar" chocopy.ChocoPy --pass=rrs --test --run --dir src/test/data/pa3/sample/ --maxCycles 65536 +java -cp "chocopy-ref.jar:target/assignment.jar" chocopy.ChocoPy --pass=sss --test --run --dir src/test/data/pa3/sample/ diff --git a/test_student_contributed.sh b/test_student_contributed.sh new file mode 100755 index 0000000..34a9693 --- /dev/null +++ b/test_student_contributed.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +echo "Running all test cases inside src/test/data/pa2/sample/ folder)" +java -cp "chocopy-ref.jar:target/assignment.jar" chocopy.ChocoPy --pass=ss --test --dir src/test/data/pa2/student_contributed/