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/test/data/pa2/student_contributed/bad_semantic.py.ast b/src/test/data/pa2/student_contributed/bad_semantic.py.ast index ca884e5..2b648b0 100644 --- a/src/test/data/pa2/student_contributed/bad_semantic.py.ast +++ b/src/test/data/pa2/student_contributed/bad_semantic.py.ast @@ -1,116 +1,1017 @@ { "kind" : "Program", - "location" : [ 1, 1, 13, 8 ], + "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" : [ 1, 1, 1, 9 ], + "location" : [ 28, 1, 28, 15 ], "var" : { "kind" : "TypedVar", - "location" : [ 1, 1, 1, 5 ], + "location" : [ 28, 1, 28, 7 ], "identifier" : { "kind" : "Identifier", - "location" : [ 1, 1, 1, 1 ], - "name" : "x" + "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" : [ 1, 3, 1, 5 ], + "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" : [ 1, 9, 1, 9 ], - "value" : 1 + "location" : [ 32, 11, 32, 11 ], + "value" : 0 } }, { "kind" : "VarDef", - "location" : [ 2, 1, 2, 9 ], + "location" : [ 33, 1, 33, 11 ], "var" : { "kind" : "TypedVar", - "location" : [ 2, 1, 2, 5 ], + "location" : [ 33, 1, 33, 7 ], "identifier" : { "kind" : "Identifier", - "location" : [ 2, 1, 2, 1 ], - "name" : "x" + "location" : [ 33, 1, 33, 3 ], + "name" : "b_i" }, "type" : { "kind" : "ClassType", - "location" : [ 2, 3, 2, 5 ], + "location" : [ 33, 5, 33, 7 ], "className" : "int" } }, "value" : { "kind" : "IntegerLiteral", - "location" : [ 2, 9, 2, 9 ], - "value" : 2 + "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" : [ 6, 1, 13, 0 ], + "location" : [ 58, 1, 64, 9 ], "name" : { "kind" : "Identifier", - "location" : [ 6, 5, 6, 9 ], - "name" : "fun_1" + "location" : [ 58, 5, 58, 7 ], + "name" : "f_2" }, "params" : [ ], "returnType" : { "kind" : "ClassType", - "location" : [ 6, 16, 6, 19 ], + "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" : [ ], + "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" : [ 7, 5, 13, 0 ], + "location" : [ 68, 5, 72, 4 ], "condition" : { - "kind" : "BooleanLiteral", - "location" : [ 7, 8, 7, 11 ], - "value" : true + "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" : "IfStmt", - "location" : [ 8, 9, 13, 0 ], - "condition" : { + "kind" : "ReturnStmt", + "location" : [ 69, 9, 69, 19 ], + "value" : { "kind" : "BooleanLiteral", - "location" : [ 8, 12, 8, 15 ], + "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" : "ReturnStmt", - "location" : [ 9, 13, 9, 23 ], - "value" : { - "kind" : "BooleanLiteral", - "location" : [ 9, 20, 9, 23 ], - "value" : true + "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" } ], - "elseBody" : [ ] + "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" + } } ] - } ], - "statements" : [ { - "kind" : "ExprStmt", - "location" : [ 13, 1, 13, 7 ], - "expr" : { - "kind" : "CallExpr", - "location" : [ 13, 1, 13, 7 ], - "function" : { + }, { + "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" : [ 13, 1, 13, 5 ], - "name" : "fun_1" + "location" : [ 89, 1, 89, 3 ], + "name" : "a_i" }, - "args" : [ ] + "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" : [ 6, 1, 6, 3 ], - "message" : "Parse error near token DEF: def", - "syntax" : true - } ], + "errors" : [ ], "kind" : "Errors", "location" : [ 0, 0, 0, 0 ] } 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 index bd84531..89bb0d3 100644 --- a/src/test/data/pa2/student_contributed/bad_semantic.py.ast.typed +++ b/src/test/data/pa2/student_contributed/bad_semantic.py.ast.typed @@ -3,7 +3,7 @@ "location" : [ 2, 1, 92, 11 ], "declarations" : [ { "kind" : "ClassDef", - "location" : [ 2, 1, 10, 16 ], + "location" : [ 2, 1, 12, 0 ], "name" : { "kind" : "Identifier", "location" : [ 2, 7, 2, 13 ], @@ -38,7 +38,7 @@ } }, { "kind" : "FuncDef", - "location" : [ 4, 5, 5, 18 ], + "location" : [ 4, 5, 5, 19 ], "name" : { "kind" : "Identifier", "location" : [ 4, 9, 4, 16 ], @@ -103,7 +103,7 @@ } ] }, { "kind" : "FuncDef", - "location" : [ 8, 5, 10, 16 ], + "location" : [ 8, 5, 10, 17 ], "name" : { "kind" : "Identifier", "location" : [ 8, 9, 8, 11 ], @@ -174,7 +174,7 @@ } ] }, { "kind" : "ClassDef", - "location" : [ 12, 1, 13, 21 ], + "location" : [ 12, 1, 13, 22 ], "name" : { "kind" : "Identifier", "location" : [ 12, 7, 12, 13 ], @@ -210,7 +210,7 @@ } ] }, { "kind" : "ClassDef", - "location" : [ 15, 1, 0, 0 ], + "location" : [ 15, 1, 16, 9 ], "name" : { "kind" : "Identifier", "location" : [ 15, 7, 15, 13 ], @@ -224,7 +224,7 @@ "declarations" : [ ] }, { "kind" : "ClassDef", - "location" : [ 19, 1, 0, 0 ], + "location" : [ 19, 1, 20, 9 ], "name" : { "kind" : "Identifier", "location" : [ 19, 7, 19, 13 ], @@ -239,7 +239,7 @@ "declarations" : [ ] }, { "kind" : "ClassDef", - "location" : [ 23, 1, 0, 0 ], + "location" : [ 23, 1, 24, 9 ], "name" : { "kind" : "Identifier", "location" : [ 23, 7, 23, 13 ], @@ -590,7 +590,7 @@ } }, { "kind" : "FuncDef", - "location" : [ 50, 1, 0, 0 ], + "location" : [ 50, 1, 56, 9 ], "name" : { "kind" : "Identifier", "location" : [ 50, 5, 50, 7 ], @@ -604,7 +604,7 @@ }, "declarations" : [ { "kind" : "FuncDef", - "location" : [ 51, 5, 54, 18 ], + "location" : [ 51, 5, 55, 13 ], "name" : { "kind" : "Identifier", "location" : [ 51, 9, 51, 13 ], @@ -647,7 +647,7 @@ "statements" : [ ] }, { "kind" : "FuncDef", - "location" : [ 58, 1, 0, 0 ], + "location" : [ 58, 1, 64, 9 ], "name" : { "kind" : "Identifier", "location" : [ 58, 5, 58, 7 ], @@ -683,7 +683,7 @@ } }, { "kind" : "FuncDef", - "location" : [ 60, 5, 62, 20 ], + "location" : [ 60, 5, 63, 13 ], "name" : { "kind" : "Identifier", "location" : [ 60, 9, 60, 13 ], @@ -726,7 +726,7 @@ "statements" : [ ] }, { "kind" : "FuncDef", - "location" : [ 66, 1, 72, 16 ], + "location" : [ 66, 1, 72, 17 ], "name" : { "kind" : "Identifier", "location" : [ 66, 5, 66, 7 ], @@ -776,7 +776,7 @@ } ], "statements" : [ { "kind" : "IfStmt", - "location" : [ 68, 5, 0, 0 ], + "location" : [ 68, 5, 72, 4 ], "condition" : { "kind" : "BinaryExpr", "location" : [ 68, 9, 68, 21 ], @@ -813,7 +813,7 @@ } ], "elseBody" : [ { "kind" : "IfStmt", - "location" : [ 70, 5, 0, 0 ], + "location" : [ 70, 5, 72, 4 ], "condition" : { "kind" : "BinaryExpr", "location" : [ 70, 11, 70, 24 ], @@ -870,7 +870,7 @@ } ] }, { "kind" : "FuncDef", - "location" : [ 74, 1, 77, 16 ], + "location" : [ 74, 1, 77, 17 ], "name" : { "kind" : "Identifier", "location" : [ 74, 5, 74, 7 ], @@ -939,7 +939,7 @@ } ] }, { "kind" : "FuncDef", - "location" : [ 81, 1, 0, 0 ], + "location" : [ 81, 1, 82, 9 ], "name" : { "kind" : "Identifier", "location" : [ 81, 5, 81, 7 ], @@ -956,7 +956,7 @@ "statements" : [ ] }, { "kind" : "FuncDef", - "location" : [ 85, 1, 0, 0 ], + "location" : [ 85, 1, 86, 9 ], "name" : { "kind" : "Identifier", "location" : [ 85, 5, 85, 9 ], diff --git a/src/test/data/pa2/student_contributed/bad_types.py.ast b/src/test/data/pa2/student_contributed/bad_types.py.ast index c85de99..508c754 100644 --- a/src/test/data/pa2/student_contributed/bad_types.py.ast +++ b/src/test/data/pa2/student_contributed/bad_types.py.ast @@ -1,93 +1,1301 @@ { "kind" : "Program", - "location" : [ 1, 1, 5, 20 ], + "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" : [ 1, 1, 1, 12 ], + "location" : [ 18, 1, 18, 15 ], "var" : { "kind" : "TypedVar", - "location" : [ 1, 1, 1, 5 ], + "location" : [ 18, 1, 18, 7 ], "identifier" : { "kind" : "Identifier", - "location" : [ 1, 1, 1, 1 ], - "name" : "x" + "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" : [ 1, 3, 1, 5 ], + "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" : [ 1, 9, 1, 12 ], - "value" : true + "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" : [ 2, 1, 2, 7 ], + "location" : [ 71, 1, 71, 9 ], "expr" : { "kind" : "BinaryExpr", - "location" : [ 2, 1, 2, 7 ], + "location" : [ 71, 1, 71, 9 ], "left" : { "kind" : "Identifier", - "location" : [ 2, 1, 2, 1 ], - "name" : "x" + "location" : [ 71, 1, 71, 3 ], + "name" : "c_i" }, "operator" : "+", "right" : { "kind" : "ListExpr", - "location" : [ 2, 5, 2, 7 ], + "location" : [ 71, 7, 71, 9 ], "elements" : [ { "kind" : "IntegerLiteral", - "location" : [ 2, 6, 2, 6 ], + "location" : [ 71, 8, 71, 8 ], "value" : 1 } ] } } }, { "kind" : "AssignStmt", - "location" : [ 4, 3, 4, 14 ], + "location" : [ 73, 1, 73, 23 ], "targets" : [ { "kind" : "Identifier", - "location" : [ 4, 3, 4, 6 ], - "name" : "bool" + "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" : "BooleanLiteral", - "location" : [ 4, 10, 4, 14 ], - "value" : false + "kind" : "StringLiteral", + "location" : [ 73, 17, 73, 23 ], + "value" : "Error" } }, { "kind" : "AssignStmt", - "location" : [ 5, 1, 5, 19 ], + "location" : [ 75, 1, 75, 13 ], "targets" : [ { "kind" : "Identifier", - "location" : [ 5, 1, 5, 1 ], - "name" : "x" - }, { + "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" : [ 5, 5, 5, 5 ], - "name" : "y" + "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" : [ 5, 9, 5, 9 ], + "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" : [ 5, 13, 5, 19 ], - "value" : "Error" + "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, 2, 4, 2 ], - "message" : "Parse error near token COLON: :", - "syntax" : true - } ], + "errors" : [ ], "kind" : "Errors", "location" : [ 0, 0, 0, 0 ] } 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 index b5c130f..a85b212 100644 --- a/src/test/data/pa2/student_contributed/bad_types.py.ast.typed +++ b/src/test/data/pa2/student_contributed/bad_types.py.ast.typed @@ -3,7 +3,7 @@ "location" : [ 2, 1, 105, 70 ], "declarations" : [ { "kind" : "ClassDef", - "location" : [ 2, 1, 9, 16 ], + "location" : [ 2, 1, 11, 0 ], "name" : { "kind" : "Identifier", "location" : [ 2, 7, 2, 13 ], @@ -38,7 +38,7 @@ } }, { "kind" : "FuncDef", - "location" : [ 4, 5, 5, 18 ], + "location" : [ 4, 5, 5, 19 ], "name" : { "kind" : "Identifier", "location" : [ 4, 9, 4, 16 ], @@ -103,7 +103,7 @@ } ] }, { "kind" : "FuncDef", - "location" : [ 7, 5, 9, 16 ], + "location" : [ 7, 5, 9, 17 ], "name" : { "kind" : "Identifier", "location" : [ 7, 9, 7, 11 ], @@ -186,7 +186,7 @@ } ] }, { "kind" : "ClassDef", - "location" : [ 11, 1, 12, 21 ], + "location" : [ 11, 1, 12, 22 ], "name" : { "kind" : "Identifier", "location" : [ 11, 7, 11, 13 ], @@ -222,7 +222,7 @@ } ] }, { "kind" : "ClassDef", - "location" : [ 14, 1, 0, 0 ], + "location" : [ 14, 1, 15, 9 ], "name" : { "kind" : "Identifier", "location" : [ 14, 7, 14, 13 ], @@ -572,7 +572,7 @@ } }, { "kind" : "FuncDef", - "location" : [ 40, 1, 0, 0 ], + "location" : [ 40, 1, 44, 9 ], "name" : { "kind" : "Identifier", "location" : [ 40, 5, 40, 7 ], @@ -586,7 +586,7 @@ }, "declarations" : [ { "kind" : "FuncDef", - "location" : [ 41, 5, 0, 0 ], + "location" : [ 41, 5, 43, 13 ], "name" : { "kind" : "Identifier", "location" : [ 41, 9, 41, 13 ], @@ -612,7 +612,7 @@ "statements" : [ ] }, { "kind" : "FuncDef", - "location" : [ 46, 1, 0, 0 ], + "location" : [ 46, 1, 51, 9 ], "name" : { "kind" : "Identifier", "location" : [ 46, 5, 46, 7 ], @@ -648,7 +648,7 @@ } }, { "kind" : "FuncDef", - "location" : [ 48, 5, 0, 0 ], + "location" : [ 48, 5, 50, 13 ], "name" : { "kind" : "Identifier", "location" : [ 48, 9, 48, 13 ], @@ -674,7 +674,7 @@ "statements" : [ ] }, { "kind" : "FuncDef", - "location" : [ 53, 1, 55, 18 ], + "location" : [ 53, 1, 55, 19 ], "name" : { "kind" : "Identifier", "location" : [ 53, 5, 53, 7 ], diff --git a/src/test/data/pa2/student_contributed/good.py.ast b/src/test/data/pa2/student_contributed/good.py.ast index b95160b..32b037c 100644 --- a/src/test/data/pa2/student_contributed/good.py.ast +++ b/src/test/data/pa2/student_contributed/good.py.ast @@ -1,44 +1,66 @@ { "kind" : "Program", - "location" : [ 2, 1, 83, 25 ], + "location" : [ 2, 1, 110, 11 ], "declarations" : [ { "kind" : "ClassDef", - "location" : [ 2, 1, 10, 14 ], + "location" : [ 2, 1, 12, 0 ], "name" : { "kind" : "Identifier", - "location" : [ 2, 7, 2, 9 ], - "name" : "Foo" + "location" : [ 2, 7, 2, 13 ], + "name" : "A_CLASS" }, "superClass" : { "kind" : "Identifier", - "location" : [ 2, 11, 2, 16 ], + "location" : [ 2, 15, 2, 20 ], "name" : "object" }, "declarations" : [ { "kind" : "VarDef", - "location" : [ 3, 5, 3, 13 ], + "location" : [ 3, 5, 3, 21 ], "var" : { "kind" : "TypedVar", - "location" : [ 3, 5, 3, 9 ], + "location" : [ 3, 5, 3, 17 ], "identifier" : { "kind" : "Identifier", - "location" : [ 3, 5, 3, 5 ], + "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" : [ 3, 7, 3, 9 ], + "location" : [ 4, 7, 4, 9 ], "className" : "int" } }, "value" : { "kind" : "IntegerLiteral", - "location" : [ 3, 13, 3, 13 ], + "location" : [ 4, 11, 4, 11 ], "value" : 0 } }, { "kind" : "FuncDef", - "location" : [ 5, 5, 6, 18 ], + "location" : [ 5, 5, 6, 19 ], "name" : { "kind" : "Identifier", "location" : [ 5, 9, 5, 16 ], @@ -46,7 +68,7 @@ }, "params" : [ { "kind" : "TypedVar", - "location" : [ 5, 18, 5, 27 ], + "location" : [ 5, 18, 5, 31 ], "identifier" : { "kind" : "Identifier", "location" : [ 5, 18, 5, 21 ], @@ -54,26 +76,13 @@ }, "type" : { "kind" : "ClassType", - "location" : [ 5, 23, 5, 27 ], - "className" : "Foo" - } - }, { - "kind" : "TypedVar", - "location" : [ 5, 30, 5, 34 ], - "identifier" : { - "kind" : "Identifier", - "location" : [ 5, 30, 5, 30 ], - "name" : "x" - }, - "type" : { - "kind" : "ClassType", - "location" : [ 5, 32, 5, 34 ], - "className" : "int" + "location" : [ 5, 23, 5, 31 ], + "className" : "A_CLASS" } } ], "returnType" : { "kind" : "ClassType", - "location" : [ 5, 36, 5, 36 ], + "location" : [ 5, 33, 5, 33 ], "className" : "" }, "declarations" : [ ], @@ -95,1092 +104,1192 @@ } } ], "value" : { - "kind" : "Identifier", + "kind" : "IntegerLiteral", "location" : [ 6, 18, 6, 18 ], - "name" : "x" + "value" : 0 } } ] }, { "kind" : "FuncDef", - "location" : [ 8, 5, 10, 14 ], + "location" : [ 8, 5, 10, 17 ], "name" : { "kind" : "Identifier", "location" : [ 8, 9, 8, 11 ], - "name" : "bar" + "name" : "add" }, "params" : [ { "kind" : "TypedVar", - "location" : [ 8, 13, 8, 17 ], + "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, 13, 8, 13 ], + "location" : [ 8, 29, 8, 29 ], "name" : "y" }, "type" : { "kind" : "ClassType", - "location" : [ 8, 15, 8, 17 ], + "location" : [ 8, 31, 8, 33 ], "className" : "int" } } ], "returnType" : { "kind" : "ClassType", - "location" : [ 8, 19, 8, 19 ], - "className" : "" + "location" : [ 8, 39, 8, 41 ], + "className" : "int" }, "declarations" : [ ], "statements" : [ { - "kind" : "ExprStmt", - "location" : [ 9, 9, 9, 38 ], - "expr" : { - "kind" : "CallExpr", - "location" : [ 9, 9, 9, 38 ], - "function" : { + "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, 9, 9, 13 ], - "name" : "print" + "location" : [ 9, 13, 9, 13 ], + "name" : "y" }, - "args" : [ { - "kind" : "StringLiteral", - "location" : [ 9, 15, 9, 28 ], - "value" : "Hello World!" - }, { - "kind" : "BinaryExpr", - "location" : [ 9, 30, 9, 37 ], - "left" : { - "kind" : "MemberExpr", - "location" : [ 9, 30, 9, 35 ], - "object" : { - "kind" : "Identifier", - "location" : [ 9, 30, 9, 33 ], - "name" : "self" - }, - "member" : { - "kind" : "Identifier", - "location" : [ 9, 35, 9, 35 ], - "name" : "x" - } + "operator" : "+", + "right" : { + "kind" : "MemberExpr", + "location" : [ 9, 15, 9, 20 ], + "object" : { + "kind" : "Identifier", + "location" : [ 9, 15, 9, 18 ], + "name" : "self" }, - "operator" : "+", - "right" : { + "member" : { "kind" : "Identifier", - "location" : [ 9, 37, 9, 37 ], - "name" : "y" + "location" : [ 9, 20, 9, 20 ], + "name" : "x" } - } ] + } } }, { - "kind" : "AssignStmt", - "location" : [ 10, 9, 10, 14 ], - "targets" : [ { + "kind" : "ReturnStmt", + "location" : [ 10, 9, 10, 16 ], + "value" : { "kind" : "Identifier", - "location" : [ 10, 9, 10, 9 ], + "location" : [ 10, 16, 10, 16 ], "name" : "y" - } ], - "value" : { - "kind" : "IntegerLiteral", - "location" : [ 10, 13, 10, 14 ], - "value" : 10 } } ] } ] }, { - "kind" : "FuncDef", - "location" : [ 12, 1, 17, 25 ], + "kind" : "ClassDef", + "location" : [ 12, 1, 13, 22 ], "name" : { "kind" : "Identifier", - "location" : [ 12, 5, 12, 14 ], - "name" : "get_stones" + "location" : [ 12, 7, 12, 13 ], + "name" : "B_CLASS" }, - "params" : [ { - "kind" : "TypedVar", - "location" : [ 12, 16, 12, 23 ], - "identifier" : { - "kind" : "Identifier", - "location" : [ 12, 16, 12, 19 ], - "name" : "name" - }, - "type" : { - "kind" : "ClassType", - "location" : [ 12, 21, 12, 23 ], - "className" : "str" - } - } ], - "returnType" : { - "kind" : "ClassType", - "location" : [ 12, 27, 12, 29 ], - "className" : "str" + "superClass" : { + "kind" : "Identifier", + "location" : [ 12, 15, 12, 20 ], + "name" : "object" }, "declarations" : [ { - "kind" : "FuncDef", - "location" : [ 13, 5, 14, 38 ], - "name" : { - "kind" : "Identifier", - "location" : [ 13, 9, 13, 16 ], - "name" : "map_name" - }, - "params" : [ { + "kind" : "VarDef", + "location" : [ 13, 5, 13, 21 ], + "var" : { "kind" : "TypedVar", - "location" : [ 13, 18, 13, 23 ], + "location" : [ 13, 5, 13, 17 ], "identifier" : { "kind" : "Identifier", - "location" : [ 13, 18, 13, 19 ], - "name" : "nm" + "location" : [ 13, 5, 13, 13 ], + "name" : "b_class_i" }, "type" : { "kind" : "ClassType", - "location" : [ 13, 21, 13, 23 ], - "className" : "str" + "location" : [ 13, 15, 13, 17 ], + "className" : "int" } - } ], - "returnType" : { - "kind" : "ClassType", - "location" : [ 13, 27, 13, 29 ], - "className" : "str" }, - "declarations" : [ ], - "statements" : [ { - "kind" : "ReturnStmt", - "location" : [ 14, 9, 14, 38 ], - "value" : { - "kind" : "IndexExpr", - "location" : [ 14, 16, 14, 38 ], - "list" : { - "kind" : "Identifier", - "location" : [ 14, 16, 14, 21 ], - "name" : "stones" - }, - "index" : { - "kind" : "MethodCallExpr", - "location" : [ 14, 23, 14, 37 ], - "method" : { - "kind" : "MemberExpr", - "location" : [ 14, 23, 14, 33 ], - "object" : { - "kind" : "Identifier", - "location" : [ 14, 23, 14, 27 ], - "name" : "color" - }, - "member" : { - "kind" : "Identifier", - "location" : [ 14, 29, 14, 33 ], - "name" : "index" - } - }, - "args" : [ { - "kind" : "Identifier", - "location" : [ 14, 35, 14, 36 ], - "name" : "nm" - } ] - } - } - } ] - } ], - "statements" : [ { - "kind" : "AssignStmt", - "location" : [ 15, 5, 15, 24 ], - "targets" : [ { - "kind" : "Identifier", - "location" : [ 15, 5, 15, 9 ], - "name" : "color" - } ], - "value" : { - "kind" : "ListExpr", - "location" : [ 15, 11, 15, 24 ], - "elements" : [ { - "kind" : "StringLiteral", - "location" : [ 15, 12, 15, 16 ], - "value" : "Red" - }, { - "kind" : "StringLiteral", - "location" : [ 15, 18, 15, 23 ], - "value" : "Blue" - } ] - } - }, { - "kind" : "AssignStmt", - "location" : [ 16, 5, 16, 26 ], - "targets" : [ { - "kind" : "Identifier", - "location" : [ 16, 5, 16, 10 ], - "name" : "stones" - } ], - "value" : { - "kind" : "ListExpr", - "location" : [ 16, 12, 16, 26 ], - "elements" : [ { - "kind" : "StringLiteral", - "location" : [ 16, 13, 16, 18 ], - "value" : "Mind" - }, { - "kind" : "StringLiteral", - "location" : [ 16, 20, 16, 25 ], - "value" : "Soul" - } ] - } - }, { - "kind" : "ReturnStmt", - "location" : [ 17, 5, 17, 25 ], "value" : { - "kind" : "CallExpr", - "location" : [ 17, 12, 17, 25 ], - "function" : { - "kind" : "Identifier", - "location" : [ 17, 12, 17, 19 ], - "name" : "map_name" - }, - "args" : [ { - "kind" : "Identifier", - "location" : [ 17, 21, 17, 24 ], - "name" : "name" - } ] + "kind" : "IntegerLiteral", + "location" : [ 13, 21, 13, 21 ], + "value" : 0 } } ] }, { - "kind" : "FuncDef", - "location" : [ 19, 1, 22, 10 ], + "kind" : "ClassDef", + "location" : [ 15, 1, 16, 9 ], "name" : { "kind" : "Identifier", - "location" : [ 19, 5, 19, 8 ], - "name" : "funa" + "location" : [ 15, 7, 15, 13 ], + "name" : "C_CLASS" }, - "params" : [ ], - "returnType" : { - "kind" : "ClassType", - "location" : [ 19, 11, 19, 11 ], - "className" : "" + "superClass" : { + "kind" : "Identifier", + "location" : [ 15, 15, 15, 21 ], + "name" : "B_CLASS" }, - "declarations" : [ { - "kind" : "FuncDef", - "location" : [ 20, 5, 21, 22 ], - "name" : { + "declarations" : [ ] + }, { + "kind" : "VarDef", + "location" : [ 19, 1, 19, 15 ], + "var" : { + "kind" : "TypedVar", + "location" : [ 19, 1, 19, 7 ], + "identifier" : { "kind" : "Identifier", - "location" : [ 20, 9, 20, 12 ], - "name" : "funb" + "location" : [ 19, 1, 19, 3 ], + "name" : "a_s" }, - "params" : [ ], - "returnType" : { + "type" : { "kind" : "ClassType", - "location" : [ 20, 15, 20, 15 ], - "className" : "" - }, - "declarations" : [ ], - "statements" : [ { - "kind" : "ExprStmt", - "location" : [ 21, 9, 21, 22 ], - "expr" : { - "kind" : "CallExpr", - "location" : [ 21, 9, 21, 22 ], - "function" : { - "kind" : "Identifier", - "location" : [ 21, 9, 21, 13 ], - "name" : "print" - }, - "args" : [ { - "kind" : "StringLiteral", - "location" : [ 21, 15, 21, 21 ], - "value" : "Hello" - } ] - } - } ] - } ], - "statements" : [ { - "kind" : "ExprStmt", - "location" : [ 22, 5, 22, 10 ], - "expr" : { - "kind" : "CallExpr", - "location" : [ 22, 5, 22, 10 ], - "function" : { - "kind" : "Identifier", - "location" : [ 22, 5, 22, 8 ], - "name" : "funb" - }, - "args" : [ ] + "location" : [ 19, 5, 19, 7 ], + "className" : "str" } - } ] - }, { - "kind" : "FuncDef", - "location" : [ 24, 1, 27, 13 ], - "name" : { - "kind" : "Identifier", - "location" : [ 24, 5, 24, 8 ], - "name" : "fund" - }, - "params" : [ ], - "returnType" : { - "kind" : "ClassType", - "location" : [ 24, 11, 24, 11 ], - "className" : "" }, - "declarations" : [ { - "kind" : "FuncDef", - "location" : [ 25, 5, 26, 22 ], - "name" : { + "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" : [ 25, 9, 25, 12 ], - "name" : "fune" + "location" : [ 20, 1, 20, 3 ], + "name" : "b_s" }, - "params" : [ ], - "returnType" : { + "type" : { "kind" : "ClassType", - "location" : [ 25, 15, 25, 15 ], - "className" : "" - }, - "declarations" : [ ], - "statements" : [ { - "kind" : "ExprStmt", - "location" : [ 26, 9, 26, 22 ], - "expr" : { - "kind" : "CallExpr", - "location" : [ 26, 9, 26, 22 ], - "function" : { - "kind" : "Identifier", - "location" : [ 26, 9, 26, 13 ], - "name" : "print" - }, - "args" : [ { - "kind" : "StringLiteral", - "location" : [ 26, 15, 26, 21 ], - "value" : "Hello" - } ] - } - } ] - } ], - "statements" : [ { - "kind" : "AssignStmt", - "location" : [ 27, 5, 27, 13 ], - "targets" : [ { - "kind" : "Identifier", - "location" : [ 27, 5, 27, 5 ], - "name" : "c" - } ], - "value" : { - "kind" : "BinaryExpr", - "location" : [ 27, 9, 27, 13 ], - "left" : { - "kind" : "IntegerLiteral", - "location" : [ 27, 9, 27, 9 ], - "value" : 4 - }, - "operator" : "+", - "right" : { - "kind" : "IntegerLiteral", - "location" : [ 27, 13, 27, 13 ], - "value" : 5 - } + "location" : [ 20, 5, 20, 7 ], + "className" : "str" } - } ] - }, { - "kind" : "FuncDef", - "location" : [ 29, 1, 33, 13 ], - "name" : { - "kind" : "Identifier", - "location" : [ 29, 5, 29, 8 ], - "name" : "funf" - }, - "params" : [ ], - "returnType" : { - "kind" : "ClassType", - "location" : [ 29, 11, 29, 11 ], - "className" : "" }, - "declarations" : [ { - "kind" : "FuncDef", - "location" : [ 30, 5, 31, 22 ], - "name" : { + "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" : [ 30, 9, 30, 12 ], - "name" : "fung" + "location" : [ 21, 1, 21, 3 ], + "name" : "c_s" }, - "params" : [ ], - "returnType" : { + "type" : { "kind" : "ClassType", - "location" : [ 30, 15, 30, 15 ], - "className" : "" + "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" }, - "declarations" : [ ], - "statements" : [ { - "kind" : "ExprStmt", - "location" : [ 31, 9, 31, 22 ], - "expr" : { - "kind" : "CallExpr", - "location" : [ 31, 9, 31, 22 ], - "function" : { + "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" : [ 31, 9, 31, 13 ], + "location" : [ 44, 9, 44, 13 ], "name" : "print" }, "args" : [ { - "kind" : "StringLiteral", - "location" : [ 31, 15, 31, 21 ], - "value" : "Hello" + "kind" : "Identifier", + "location" : [ 44, 15, 44, 17 ], + "name" : "a_s" } ] } } ] } ], - "statements" : [ { - "kind" : "AssignStmt", - "location" : [ 32, 5, 32, 9 ], - "targets" : [ { - "kind" : "Identifier", - "location" : [ 32, 5, 32, 5 ], - "name" : "c" - } ], + "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" : "IntegerLiteral", - "location" : [ 32, 9, 32, 9 ], - "value" : 6 + "kind" : "StringLiteral", + "location" : [ 49, 17, 49, 19 ], + "value" : "s" } }, { - "kind" : "AssignStmt", - "location" : [ 33, 5, 33, 13 ], - "targets" : [ { + "kind" : "FuncDef", + "location" : [ 50, 5, 53, 13 ], + "name" : { "kind" : "Identifier", - "location" : [ 33, 5, 33, 5 ], - "name" : "c" + "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" : [ 33, 9, 33, 13 ], + "location" : [ 85, 7, 85, 16 ], "left" : { - "kind" : "IntegerLiteral", - "location" : [ 33, 9, 33, 9 ], - "value" : 4 + "kind" : "Identifier", + "location" : [ 85, 7, 85, 9 ], + "name" : "a_i" }, - "operator" : "+", + "operator" : "==", "right" : { - "kind" : "IntegerLiteral", - "location" : [ 33, 13, 33, 13 ], - "value" : 5 + "kind" : "Identifier", + "location" : [ 85, 14, 85, 16 ], + "name" : "b_i" } - } - } ] - } ], - "statements" : [ { - "kind" : "IfStmt", - "location" : [ 36, 1, 0, 0 ], - "condition" : { - "kind" : "BooleanLiteral", - "location" : [ 36, 4, 36, 7 ], - "value" : true - }, - "thenBody" : [ { - "kind" : "IfStmt", - "location" : [ 37, 5, 0, 0 ], - "condition" : { - "kind" : "BooleanLiteral", - "location" : [ 37, 8, 37, 11 ], - "value" : true }, - "thenBody" : [ { - "kind" : "IfStmt", - "location" : [ 38, 9, 0, 0 ], - "condition" : { - "kind" : "BooleanLiteral", - "location" : [ 38, 12, 38, 15 ], - "value" : true - }, - "thenBody" : [ { - "kind" : "ExprStmt", - "location" : [ 39, 13, 39, 26 ], - "expr" : { - "kind" : "CallExpr", - "location" : [ 39, 13, 39, 26 ], - "function" : { - "kind" : "Identifier", - "location" : [ 39, 13, 39, 17 ], - "name" : "print" - }, - "args" : [ { - "kind" : "StringLiteral", - "location" : [ 39, 19, 39, 25 ], - "value" : "Hello" - } ] - } - } ], - "elseBody" : [ ] - } ], - "elseBody" : [ ] - } ], - "elseBody" : [ ] + "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" : [ 40, 1, 40, 14 ], + "location" : [ 86, 1, 86, 10 ], "expr" : { "kind" : "CallExpr", - "location" : [ 40, 1, 40, 14 ], + "location" : [ 86, 1, 86, 10 ], "function" : { "kind" : "Identifier", - "location" : [ 40, 1, 40, 5 ], + "location" : [ 86, 1, 86, 5 ], "name" : "print" }, "args" : [ { - "kind" : "StringLiteral", - "location" : [ 40, 7, 40, 13 ], - "value" : "World" + "kind" : "Identifier", + "location" : [ 86, 7, 86, 9 ], + "name" : "a_b" } ] } }, { - "kind" : "IfStmt", - "location" : [ 42, 1, 0, 0 ], - "condition" : { - "kind" : "BooleanLiteral", - "location" : [ 42, 4, 42, 7 ], - "value" : true - }, - "thenBody" : [ { - "kind" : "IfStmt", - "location" : [ 43, 5, 0, 0 ], - "condition" : { - "kind" : "BooleanLiteral", - "location" : [ 43, 8, 43, 11 ], - "value" : true - }, - "thenBody" : [ { - "kind" : "IfStmt", - "location" : [ 44, 9, 0, 0 ], - "condition" : { - "kind" : "BooleanLiteral", - "location" : [ 44, 12, 44, 15 ], - "value" : true - }, - "thenBody" : [ { - "kind" : "ExprStmt", - "location" : [ 45, 13, 45, 26 ], - "expr" : { - "kind" : "CallExpr", - "location" : [ 45, 13, 45, 26 ], - "function" : { - "kind" : "Identifier", - "location" : [ 45, 13, 45, 17 ], - "name" : "print" - }, - "args" : [ { - "kind" : "StringLiteral", - "location" : [ 45, 19, 45, 25 ], - "value" : "Hello" - } ] - } - } ], - "elseBody" : [ ] - }, { - "kind" : "ExprStmt", - "location" : [ 46, 9, 46, 22 ], - "expr" : { - "kind" : "CallExpr", - "location" : [ 46, 9, 46, 22 ], - "function" : { - "kind" : "Identifier", - "location" : [ 46, 9, 46, 13 ], - "name" : "print" - }, - "args" : [ { - "kind" : "StringLiteral", - "location" : [ 46, 15, 46, 21 ], - "value" : "World" - } ] - } - } ], - "elseBody" : [ ] + "kind" : "AssignStmt", + "location" : [ 91, 1, 91, 24 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 91, 1, 91, 6 ], + "name" : "a_list" } ], - "elseBody" : [ ] - }, { - "kind" : "IfStmt", - "location" : [ 48, 1, 0, 0 ], - "condition" : { - "kind" : "BooleanLiteral", - "location" : [ 48, 4, 48, 7 ], - "value" : true - }, - "thenBody" : [ { - "kind" : "IfStmt", - "location" : [ 49, 5, 0, 0 ], - "condition" : { - "kind" : "BooleanLiteral", - "location" : [ 49, 8, 49, 11 ], - "value" : true + "value" : { + "kind" : "BinaryExpr", + "location" : [ 91, 10, 91, 24 ], + "left" : { + "kind" : "Identifier", + "location" : [ 91, 10, 91, 15 ], + "name" : "a_list" }, - "thenBody" : [ { - "kind" : "IfStmt", - "location" : [ 50, 9, 0, 0 ], - "condition" : { - "kind" : "BooleanLiteral", - "location" : [ 50, 12, 50, 15 ], - "value" : true - }, - "thenBody" : [ { - "kind" : "ExprStmt", - "location" : [ 51, 13, 51, 26 ], - "expr" : { - "kind" : "CallExpr", - "location" : [ 51, 13, 51, 26 ], - "function" : { - "kind" : "Identifier", - "location" : [ 51, 13, 51, 17 ], - "name" : "print" - }, - "args" : [ { - "kind" : "StringLiteral", - "location" : [ 51, 19, 51, 25 ], - "value" : "Hello" - } ] - } - } ], - "elseBody" : [ ] - } ], - "elseBody" : [ ] - }, { - "kind" : "ExprStmt", - "location" : [ 52, 5, 52, 18 ], - "expr" : { - "kind" : "CallExpr", - "location" : [ 52, 5, 52, 18 ], - "function" : { - "kind" : "Identifier", - "location" : [ 52, 5, 52, 9 ], - "name" : "print" - }, - "args" : [ { - "kind" : "StringLiteral", - "location" : [ 52, 11, 52, 17 ], - "value" : "World" - } ] + "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" } ], - "elseBody" : [ ] + "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" : "IfStmt", - "location" : [ 54, 1, 0, 0 ], - "condition" : { - "kind" : "BooleanLiteral", - "location" : [ 54, 4, 54, 7 ], - "value" : true - }, - "thenBody" : [ { - "kind" : "IfStmt", - "location" : [ 55, 5, 59, 22 ], - "condition" : { - "kind" : "BooleanLiteral", - "location" : [ 55, 8, 55, 11 ], - "value" : true + "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" }, - "thenBody" : [ { - "kind" : "IfStmt", - "location" : [ 56, 9, 0, 0 ], - "condition" : { - "kind" : "BooleanLiteral", - "location" : [ 56, 12, 56, 15 ], - "value" : true - }, - "thenBody" : [ { - "kind" : "ExprStmt", - "location" : [ 57, 13, 57, 26 ], - "expr" : { - "kind" : "CallExpr", - "location" : [ 57, 13, 57, 26 ], - "function" : { - "kind" : "Identifier", - "location" : [ 57, 13, 57, 17 ], - "name" : "print" - }, - "args" : [ { - "kind" : "StringLiteral", - "location" : [ 57, 19, 57, 25 ], - "value" : "Hello" - } ] - } - } ], - "elseBody" : [ ] - } ], - "elseBody" : [ { - "kind" : "ExprStmt", - "location" : [ 59, 9, 59, 22 ], - "expr" : { - "kind" : "CallExpr", - "location" : [ 59, 9, 59, 22 ], - "function" : { - "kind" : "Identifier", - "location" : [ 59, 9, 59, 13 ], - "name" : "print" - }, - "args" : [ { - "kind" : "StringLiteral", - "location" : [ 59, 15, 59, 21 ], - "value" : "World" - } ] - } - } ] + "index" : { + "kind" : "IntegerLiteral", + "location" : [ 93, 8, 93, 8 ], + "value" : 1 + } } ], - "elseBody" : [ ] + "value" : { + "kind" : "IntegerLiteral", + "location" : [ 93, 13, 93, 13 ], + "value" : 2 + } }, { - "kind" : "IfStmt", - "location" : [ 61, 1, 66, 18 ], - "condition" : { - "kind" : "BooleanLiteral", - "location" : [ 61, 4, 61, 7 ], - "value" : true - }, - "thenBody" : [ { - "kind" : "IfStmt", - "location" : [ 62, 5, 0, 0 ], - "condition" : { - "kind" : "BooleanLiteral", - "location" : [ 62, 8, 62, 11 ], - "value" : true - }, - "thenBody" : [ { - "kind" : "IfStmt", - "location" : [ 63, 9, 0, 0 ], - "condition" : { - "kind" : "BooleanLiteral", - "location" : [ 63, 12, 63, 15 ], - "value" : true - }, - "thenBody" : [ { - "kind" : "ExprStmt", - "location" : [ 64, 13, 64, 26 ], - "expr" : { - "kind" : "CallExpr", - "location" : [ 64, 13, 64, 26 ], - "function" : { - "kind" : "Identifier", - "location" : [ 64, 13, 64, 17 ], - "name" : "print" - }, - "args" : [ { - "kind" : "StringLiteral", - "location" : [ 64, 19, 64, 25 ], - "value" : "Hello" - } ] - } - } ], - "elseBody" : [ ] - } ], - "elseBody" : [ ] + "kind" : "AssignStmt", + "location" : [ 98, 1, 98, 16 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 98, 1, 98, 3 ], + "name" : "a_i" } ], - "elseBody" : [ { - "kind" : "ExprStmt", - "location" : [ 66, 5, 66, 18 ], - "expr" : { + "value" : { + "kind" : "BinaryExpr", + "location" : [ 98, 7, 98, 16 ], + "left" : { "kind" : "CallExpr", - "location" : [ 66, 5, 66, 18 ], + "location" : [ 98, 7, 98, 12 ], "function" : { "kind" : "Identifier", - "location" : [ 66, 5, 66, 9 ], - "name" : "print" + "location" : [ 98, 7, 98, 9 ], + "name" : "f_3" }, "args" : [ { - "kind" : "StringLiteral", - "location" : [ 66, 11, 66, 17 ], - "value" : "World" + "kind" : "IntegerLiteral", + "location" : [ 98, 11, 98, 11 ], + "value" : 3 } ] + }, + "operator" : "+", + "right" : { + "kind" : "IntegerLiteral", + "location" : [ 98, 16, 98, 16 ], + "value" : 5 } - } ] + } }, { - "kind" : "AssignStmt", - "location" : [ 70, 1, 70, 10 ], - "targets" : [ { - "kind" : "Identifier", - "location" : [ 70, 1, 70, 1 ], - "name" : "f" - } ], - "value" : { + "kind" : "ExprStmt", + "location" : [ 99, 1, 99, 5 ], + "expr" : { "kind" : "CallExpr", - "location" : [ 70, 5, 70, 10 ], + "location" : [ 99, 1, 99, 5 ], "function" : { "kind" : "Identifier", - "location" : [ 70, 5, 70, 7 ], - "name" : "Foo" + "location" : [ 99, 1, 99, 3 ], + "name" : "f_1" }, - "args" : [ { - "kind" : "IntegerLiteral", - "location" : [ 70, 9, 70, 9 ], - "value" : 1 - } ] + "args" : [ ] } }, { "kind" : "ExprStmt", - "location" : [ 71, 1, 71, 10 ], + "location" : [ 100, 1, 100, 5 ], "expr" : { "kind" : "CallExpr", - "location" : [ 71, 1, 71, 10 ], + "location" : [ 100, 1, 100, 5 ], "function" : { "kind" : "Identifier", - "location" : [ 71, 1, 71, 5 ], - "name" : "print" + "location" : [ 100, 1, 100, 3 ], + "name" : "f_2" }, - "args" : [ { - "kind" : "MemberExpr", - "location" : [ 71, 7, 71, 9 ], - "object" : { - "kind" : "Identifier", - "location" : [ 71, 7, 71, 7 ], - "name" : "f" - }, - "member" : { - "kind" : "Identifier", - "location" : [ 71, 9, 71, 9 ], - "name" : "x" - } - } ] + "args" : [ ] } }, { - "kind" : "ExprStmt", - "location" : [ 72, 1, 72, 8 ], - "expr" : { + "kind" : "AssignStmt", + "location" : [ 105, 1, 105, 20 ], + "targets" : [ { + "kind" : "Identifier", + "location" : [ 105, 1, 105, 3 ], + "name" : "a_i" + } ], + "value" : { "kind" : "MethodCallExpr", - "location" : [ 72, 1, 72, 8 ], + "location" : [ 105, 7, 105, 20 ], "method" : { "kind" : "MemberExpr", - "location" : [ 72, 1, 72, 5 ], + "location" : [ 105, 7, 105, 17 ], "object" : { "kind" : "Identifier", - "location" : [ 72, 1, 72, 1 ], - "name" : "f" + "location" : [ 105, 7, 105, 13 ], + "name" : "a_class" }, "member" : { "kind" : "Identifier", - "location" : [ 72, 3, 72, 5 ], - "name" : "bar" + "location" : [ 105, 15, 105, 17 ], + "name" : "add" } }, "args" : [ { "kind" : "IntegerLiteral", - "location" : [ 72, 7, 72, 7 ], - "value" : 4 - } ] - } - }, { - "kind" : "AssignStmt", - "location" : [ 74, 1, 74, 23 ], - "targets" : [ { - "kind" : "Identifier", - "location" : [ 74, 1, 74, 1 ], - "name" : "a" - } ], - "value" : { - "kind" : "ListExpr", - "location" : [ 74, 3, 74, 23 ], - "elements" : [ { - "kind" : "ListExpr", - "location" : [ 74, 4, 74, 12 ], - "elements" : [ { - "kind" : "ListExpr", - "location" : [ 74, 5, 74, 7 ], - "elements" : [ { - "kind" : "IntegerLiteral", - "location" : [ 74, 6, 74, 6 ], - "value" : 1 - } ] - }, { - "kind" : "ListExpr", - "location" : [ 74, 9, 74, 11 ], - "elements" : [ { - "kind" : "IntegerLiteral", - "location" : [ 74, 10, 74, 10 ], - "value" : 2 - } ] - } ] - }, { - "kind" : "ListExpr", - "location" : [ 74, 14, 74, 22 ], - "elements" : [ { - "kind" : "ListExpr", - "location" : [ 74, 15, 74, 17 ], - "elements" : [ { - "kind" : "IntegerLiteral", - "location" : [ 74, 16, 74, 16 ], - "value" : 3 - } ] - }, { - "kind" : "ListExpr", - "location" : [ 74, 19, 74, 21 ], - "elements" : [ { - "kind" : "IntegerLiteral", - "location" : [ 74, 20, 74, 20 ], - "value" : 4 - } ] - } ] + "location" : [ 105, 19, 105, 19 ], + "value" : 2 } ] } }, { "kind" : "ExprStmt", - "location" : [ 75, 1, 75, 28 ], + "location" : [ 106, 1, 106, 10 ], "expr" : { "kind" : "CallExpr", - "location" : [ 75, 1, 75, 28 ], + "location" : [ 106, 1, 106, 10 ], "function" : { "kind" : "Identifier", - "location" : [ 75, 1, 75, 5 ], + "location" : [ 106, 1, 106, 5 ], "name" : "print" }, "args" : [ { - "kind" : "BinaryExpr", - "location" : [ 75, 7, 75, 27 ], - "left" : { - "kind" : "IndexExpr", - "location" : [ 75, 7, 75, 16 ], - "list" : { - "kind" : "IndexExpr", - "location" : [ 75, 7, 75, 13 ], - "list" : { - "kind" : "IndexExpr", - "location" : [ 75, 7, 75, 10 ], - "list" : { - "kind" : "Identifier", - "location" : [ 75, 7, 75, 7 ], - "name" : "a" - }, - "index" : { - "kind" : "IntegerLiteral", - "location" : [ 75, 9, 75, 9 ], - "value" : 0 - } - }, - "index" : { - "kind" : "IntegerLiteral", - "location" : [ 75, 12, 75, 12 ], - "value" : 0 - } - }, - "index" : { - "kind" : "IntegerLiteral", - "location" : [ 75, 15, 75, 15 ], - "value" : 1 - } - }, - "operator" : "*", - "right" : { - "kind" : "IndexExpr", - "location" : [ 75, 18, 75, 27 ], - "list" : { - "kind" : "IndexExpr", - "location" : [ 75, 18, 75, 24 ], - "list" : { - "kind" : "IndexExpr", - "location" : [ 75, 18, 75, 21 ], - "list" : { - "kind" : "Identifier", - "location" : [ 75, 18, 75, 18 ], - "name" : "a" - }, - "index" : { - "kind" : "IntegerLiteral", - "location" : [ 75, 20, 75, 20 ], - "value" : 1 - } - }, - "index" : { - "kind" : "IntegerLiteral", - "location" : [ 75, 23, 75, 23 ], - "value" : 1 - } - }, - "index" : { - "kind" : "IntegerLiteral", - "location" : [ 75, 26, 75, 26 ], - "value" : 0 - } - } + "kind" : "Identifier", + "location" : [ 106, 7, 106, 9 ], + "name" : "a_i" } ] } }, { "kind" : "AssignStmt", - "location" : [ 77, 1, 78, 10 ], - "targets" : [ { - "kind" : "Identifier", - "location" : [ 77, 1, 77, 16 ], - "name" : "multiline_string" - } ], - "value" : { - "kind" : "StringLiteral", - "location" : [ 77, 18, 78, 10 ], - "value" : "Hi World,\nHere I am" - } - }, { - "kind" : "AssignStmt", - "location" : [ 80, 1, 80, 34 ], + "location" : [ 109, 1, 109, 36 ], "targets" : [ { "kind" : "Identifier", - "location" : [ 80, 1, 80, 15 ], - "name" : "expr_precedence" + "location" : [ 109, 1, 109, 3 ], + "name" : "a_i" } ], "value" : { - "kind" : "BinaryExpr", - "location" : [ 80, 19, 80, 34 ], - "left" : { - "kind" : "UnaryExpr", - "location" : [ 80, 19, 80, 20 ], - "operator" : "-", - "operand" : { + "kind" : "MethodCallExpr", + "location" : [ 109, 7, 109, 36 ], + "method" : { + "kind" : "MemberExpr", + "location" : [ 109, 7, 109, 17 ], + "object" : { "kind" : "Identifier", - "location" : [ 80, 20, 80, 20 ], - "name" : "a" + "location" : [ 109, 7, 109, 13 ], + "name" : "a_class" + }, + "member" : { + "kind" : "Identifier", + "location" : [ 109, 15, 109, 17 ], + "name" : "add" } }, - "operator" : "+", - "right" : { - "kind" : "BinaryExpr", - "location" : [ 80, 24, 80, 34 ], - "left" : { + "args" : [ { + "kind" : "MemberExpr", + "location" : [ 109, 19, 109, 35 ], + "object" : { "kind" : "Identifier", - "location" : [ 80, 24, 80, 24 ], - "name" : "b" + "location" : [ 109, 19, 109, 25 ], + "name" : "c_class" }, - "operator" : "*", - "right" : { - "kind" : "BinaryExpr", - "location" : [ 80, 29, 80, 33 ], - "left" : { - "kind" : "Identifier", - "location" : [ 80, 29, 80, 29 ], - "name" : "c" - }, - "operator" : "+", - "right" : { - "kind" : "Identifier", - "location" : [ 80, 33, 80, 33 ], - "name" : "d" - } + "member" : { + "kind" : "Identifier", + "location" : [ 109, 27, 109, 35 ], + "name" : "b_class_i" } - } - } - }, { - "kind" : "AssignStmt", - "location" : [ 82, 1, 82, 12 ], - "targets" : [ { - "kind" : "Identifier", - "location" : [ 82, 1, 82, 5 ], - "name" : "stone" - } ], - "value" : { - "kind" : "StringLiteral", - "location" : [ 82, 7, 82, 12 ], - "value" : "Blue" + } ] } }, { "kind" : "ExprStmt", - "location" : [ 83, 1, 83, 24 ], + "location" : [ 110, 1, 110, 10 ], "expr" : { "kind" : "CallExpr", - "location" : [ 83, 1, 83, 24 ], + "location" : [ 110, 1, 110, 10 ], "function" : { "kind" : "Identifier", - "location" : [ 83, 1, 83, 5 ], + "location" : [ 110, 1, 110, 5 ], "name" : "print" }, "args" : [ { - "kind" : "CallExpr", - "location" : [ 83, 7, 83, 23 ], - "function" : { - "kind" : "Identifier", - "location" : [ 83, 7, 83, 16 ], - "name" : "get_stones" - }, - "args" : [ { - "kind" : "Identifier", - "location" : [ 83, 18, 83, 22 ], - "name" : "stone" - } ] + "kind" : "Identifier", + "location" : [ 110, 7, 110, 9 ], + "name" : "a_i" } ] } } ], diff --git a/src/test/data/pa2/student_contributed/good.py.ast.typed b/src/test/data/pa2/student_contributed/good.py.ast.typed index f6a2fc6..9401bb9 100644 --- a/src/test/data/pa2/student_contributed/good.py.ast.typed +++ b/src/test/data/pa2/student_contributed/good.py.ast.typed @@ -3,7 +3,7 @@ "location" : [ 2, 1, 110, 11 ], "declarations" : [ { "kind" : "ClassDef", - "location" : [ 2, 1, 10, 16 ], + "location" : [ 2, 1, 12, 0 ], "name" : { "kind" : "Identifier", "location" : [ 2, 7, 2, 13 ], @@ -68,7 +68,7 @@ } }, { "kind" : "FuncDef", - "location" : [ 5, 5, 6, 18 ], + "location" : [ 5, 5, 6, 19 ], "name" : { "kind" : "Identifier", "location" : [ 5, 9, 5, 16 ], @@ -131,7 +131,7 @@ } ] }, { "kind" : "FuncDef", - "location" : [ 8, 5, 10, 16 ], + "location" : [ 8, 5, 10, 17 ], "name" : { "kind" : "Identifier", "location" : [ 8, 9, 8, 11 ], @@ -238,7 +238,7 @@ } ] }, { "kind" : "ClassDef", - "location" : [ 12, 1, 13, 21 ], + "location" : [ 12, 1, 13, 22 ], "name" : { "kind" : "Identifier", "location" : [ 12, 7, 12, 13 ], @@ -278,7 +278,7 @@ } ] }, { "kind" : "ClassDef", - "location" : [ 15, 1, 0, 0 ], + "location" : [ 15, 1, 16, 9 ], "name" : { "kind" : "Identifier", "location" : [ 15, 7, 15, 13 ], @@ -688,7 +688,7 @@ } }, { "kind" : "FuncDef", - "location" : [ 41, 1, 0, 0 ], + "location" : [ 41, 1, 46, 9 ], "name" : { "kind" : "Identifier", "location" : [ 41, 5, 41, 7 ], @@ -702,7 +702,7 @@ }, "declarations" : [ { "kind" : "FuncDef", - "location" : [ 42, 5, 44, 18 ], + "location" : [ 42, 5, 45, 13 ], "name" : { "kind" : "Identifier", "location" : [ 42, 9, 42, 13 ], @@ -764,7 +764,7 @@ "statements" : [ ] }, { "kind" : "FuncDef", - "location" : [ 48, 1, 0, 0 ], + "location" : [ 48, 1, 54, 9 ], "name" : { "kind" : "Identifier", "location" : [ 48, 5, 48, 7 ], @@ -804,7 +804,7 @@ } }, { "kind" : "FuncDef", - "location" : [ 50, 5, 52, 20 ], + "location" : [ 50, 5, 53, 13 ], "name" : { "kind" : "Identifier", "location" : [ 50, 9, 50, 13 ], @@ -866,7 +866,7 @@ "statements" : [ ] }, { "kind" : "FuncDef", - "location" : [ 56, 1, 58, 18 ], + "location" : [ 56, 1, 58, 19 ], "name" : { "kind" : "Identifier", "location" : [ 56, 5, 56, 7 ],