Compare commits
83 Commits
07552e704e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22d925810f | ||
|
|
b4f59ce5c3 | ||
|
|
5239e608bc | ||
|
|
079668b9f8 | ||
|
|
58f6dc74e4 | ||
|
|
88ce2a985c | ||
|
|
a2fa6f55d4 | ||
|
|
8d4e8a9269 | ||
| c2c0c0b442 | |||
|
|
ec400479bb | ||
| 167b8e80b5 | |||
|
|
0baac36f35 | ||
|
|
da53e5d6dc | ||
|
|
0593d988b4 | ||
|
|
8e55eaca93 | ||
|
|
31ac237ffd | ||
|
|
e56139080f | ||
|
|
f807721293 | ||
|
|
271bbf4b4b | ||
|
|
5b4d08ba01 | ||
|
|
3b5f157bb5 | ||
|
|
59183f5b44 | ||
|
|
302b907d36 | ||
|
|
32353b9a37 | ||
|
|
3e908293ee | ||
|
|
aed7af7c68 | ||
|
|
3a8b9ea9cd | ||
|
|
aa8a647fa1 | ||
|
|
51240806b9 | ||
|
|
8f55a15aef | ||
| edfaa93980 | |||
|
|
4b36453ff3 | ||
|
|
78d6d402a2 | ||
|
|
0533ddbc5d | ||
|
|
920fa2fa48 | ||
|
|
dbb61e2a81 | ||
|
|
7fb7cea2f7 | ||
|
|
7e8c297d9a | ||
|
|
c9ce9e02db | ||
|
|
4dfea0d69d | ||
|
|
e801717444 | ||
|
|
6a56f51050 | ||
| 403b31c550 | |||
|
|
82384886c6 | ||
|
|
1dd405a00f | ||
| 6948797001 | |||
|
|
d7016df1ba | ||
|
|
384a5e9066 | ||
|
|
5d75c23f49 | ||
|
|
ba9760fe43 | ||
|
|
888534955a | ||
|
|
f6358867f0 | ||
|
|
0711028dc3 | ||
|
|
97ab66122e | ||
|
|
1100cef668 | ||
|
|
3c863aafde | ||
|
|
41d5cd428c | ||
|
|
5dd3821ecb | ||
|
|
c5752df15e | ||
|
|
88bcfa5fa3 | ||
|
|
5dae167443 | ||
|
|
47a8d50185 | ||
|
|
94b3830561 | ||
|
|
3dcaad62f9 | ||
|
|
62060462a9 | ||
|
|
d5b526b8fc | ||
|
|
10f5dc692d | ||
|
|
e46cede8d5 | ||
|
|
38aeaa657d | ||
|
|
cabbbdcaf3 | ||
|
|
192dfae94b | ||
|
|
c24a483880 | ||
|
|
aa7d82b9ac | ||
|
|
94ea539fab | ||
|
|
6bf2c75e02 | ||
|
|
d2b307f86f | ||
|
|
5b0dc04bd7 | ||
| 6c015e72d5 | |||
|
|
cd9fc46a1f | ||
|
|
9b0d8147db | ||
|
|
21ece58cc9 | ||
| 8e0b215140 | |||
| 3fa8400b72 |
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding">
|
||||
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
||||
8
.idea/misc.xml
generated
8
.idea/misc.xml
generated
@@ -24,7 +24,11 @@
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
<component name="PWA">
|
||||
<option name="enabled" value="true" />
|
||||
<option name="wasEnabledAtLeastOnce" value="true" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_22" default="true" project-jdk-name="openjdk-22" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/target" />
|
||||
</component>
|
||||
</project>
|
||||
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
@@ -3,7 +3,6 @@
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/NichtHaskell.iml" filepath="$PROJECT_DIR$/NichtHaskell.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/src/NichtHaskell1.iml" filepath="$PROJECT_DIR$/src/NichtHaskell1.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
BIN
Documentation/DokumentationNichtHaskell.pdf
Normal file
BIN
Documentation/DokumentationNichtHaskell.pdf
Normal file
Binary file not shown.
BIN
Documentation/KlassendiagrammFields.jpg
Normal file
BIN
Documentation/KlassendiagrammFields.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 766 KiB |
BIN
Documentation/KlassendiagrammUML.jpg
Normal file
BIN
Documentation/KlassendiagrammUML.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.7 MiB |
BIN
Documentation/PraesentationNichtHaskell.pdf
Normal file
BIN
Documentation/PraesentationNichtHaskell.pdf
Normal file
Binary file not shown.
20
Examples/Fakultaet.java
Normal file
20
Examples/Fakultaet.java
Normal file
@@ -0,0 +1,20 @@
|
||||
class Fakultaet {
|
||||
public int fak(int number) {
|
||||
if (number < 0) {
|
||||
return 1;
|
||||
}
|
||||
int factorial = 1;
|
||||
int i = 1;
|
||||
while(i <= number){
|
||||
factorial = factorial * i;
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
return factorial;
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
Fakultaet f = new Fakultaet();
|
||||
int result = f.fak(5);
|
||||
print(result);
|
||||
}
|
||||
}
|
||||
40
Examples/FieldAccessAndMethodCalls.java
Normal file
40
Examples/FieldAccessAndMethodCalls.java
Normal file
@@ -0,0 +1,40 @@
|
||||
class FieldAccessAndMethodCalls {
|
||||
public static void main(String[] args) {
|
||||
Class1 c1 = new Class1();
|
||||
int i = c1.c2.c3.m3(1).m2().m1();
|
||||
print(i);
|
||||
}
|
||||
}
|
||||
|
||||
class Class1{
|
||||
int i1;
|
||||
Class2 c2;
|
||||
public Class1() {
|
||||
this.c2 = new Class2();
|
||||
}
|
||||
public int m1(){
|
||||
return i1;
|
||||
}
|
||||
}
|
||||
|
||||
class Class2{
|
||||
int i2;
|
||||
Class3 c3;
|
||||
public Class2(){
|
||||
this.c3 = new Class3();
|
||||
}
|
||||
public Class1 m2(){
|
||||
Class1 c1 = new Class1();
|
||||
c1.i1 = i2;
|
||||
return c1;
|
||||
}
|
||||
}
|
||||
|
||||
class Class3{
|
||||
int i3;
|
||||
public Class2 m3(int i){
|
||||
Class2 c2 = new Class2();
|
||||
c2.i2 = i;
|
||||
return c2;
|
||||
}
|
||||
}
|
||||
166
Grammatik.txt
166
Grammatik.txt
@@ -1,166 +0,0 @@
|
||||
Grammatik:
|
||||
|
||||
1. Ausdrücke
|
||||
|
||||
Primary:
|
||||
Literal
|
||||
Variable
|
||||
IncDecExpression
|
||||
( Expression )
|
||||
MethodInvocation
|
||||
|
||||
Variable:
|
||||
Identifier { [ Expression ] }
|
||||
|
||||
Identifier:
|
||||
[ Identifier . ] Name
|
||||
|
||||
IncDecExpression:
|
||||
Variable IncDec
|
||||
IncDec Variable
|
||||
|
||||
IncDec:
|
||||
++ | --
|
||||
|
||||
Expression:
|
||||
UnaryExpression
|
||||
BinaryExpression
|
||||
AssignmentExpression
|
||||
MethodInvocation
|
||||
CreationExpression
|
||||
|
||||
UnaryExpression:
|
||||
Primary
|
||||
UnaryExpression
|
||||
UnaryOperator
|
||||
+ | - | ! | ...
|
||||
|
||||
BinaryExpression:
|
||||
Expression BinaryOperator Expression
|
||||
|
||||
BinaryOperator:
|
||||
== | + | - | * | / | & | && | | | || |
|
||||
|
||||
|
||||
AssignmentExpression:
|
||||
Variable = Expression
|
||||
|
||||
MethodInvocation:
|
||||
Method ( [ ActualArguments ] )
|
||||
|
||||
Method:
|
||||
Identifier
|
||||
|
||||
ActualArguments:
|
||||
Expression { , Expression }
|
||||
|
||||
CreationExpression:
|
||||
new ClassIdentifier ( [ ActualArguments ] )
|
||||
|
||||
|
||||
|
||||
2. Anweisungen
|
||||
|
||||
Statement:
|
||||
SimpleStatement
|
||||
CompositeStatement
|
||||
Label : Statement
|
||||
|
||||
SimpleStatement:
|
||||
EmptyStatement
|
||||
StatementExpression
|
||||
EmptyStatement ;
|
||||
ReturnStatement
|
||||
|
||||
StatementExpression:
|
||||
AssignmentExpression
|
||||
IncDecExpression
|
||||
MethodInvocation
|
||||
CreationExpression
|
||||
|
||||
ContinueStatement:
|
||||
continue [ Name ] ;
|
||||
|
||||
ReturnStatement.
|
||||
return [ Expression ] ;
|
||||
|
||||
|
||||
CompositeStatement:
|
||||
Block
|
||||
CaseStatement
|
||||
|
||||
Block:
|
||||
"{" { VariableDeclaration | Statement } "}"
|
||||
|
||||
VariableDeclaration:
|
||||
Type VariableDeclarator ;
|
||||
|
||||
VariableDeclarator:
|
||||
Name [ = Expression ]
|
||||
|
||||
Type:
|
||||
Name # konkrete Typen hinzufügen
|
||||
Identifier
|
||||
|
||||
CaseStatement: # Andere CaseStatements heraussuchen. Assign, MethodCall,
|
||||
ConditionalStatement
|
||||
WhileStatement
|
||||
|
||||
|
||||
ConditionalStatement:
|
||||
if ( Expression ) Statement [ else Statement ]
|
||||
|
||||
ConstantExpression:
|
||||
Expression
|
||||
|
||||
WhileStatement:
|
||||
while ( Expression ) Statement
|
||||
|
||||
Initialization:
|
||||
StatementExpression { , StatementExpression }
|
||||
VariableDeclaration
|
||||
|
||||
|
||||
3. Methoden
|
||||
|
||||
MethodDeclaration:
|
||||
MethodHeader Block
|
||||
|
||||
MethodHeader:
|
||||
{ Modifier } ResultType MethodDeclarator
|
||||
|
||||
Modifier:
|
||||
public | static | ...
|
||||
|
||||
ResultType:
|
||||
Type | void
|
||||
|
||||
MethodDeclarator:
|
||||
Identifier "(" [ FormalArguments ] ")"
|
||||
|
||||
FormalArguments:
|
||||
FormalArgument { , FormalArgument }
|
||||
|
||||
FormalArgument:
|
||||
Type Name
|
||||
|
||||
|
||||
|
||||
4. Klassen
|
||||
|
||||
Start:
|
||||
ClassDeclaration {ClassDeclaration}
|
||||
|
||||
ClassDeclaration:
|
||||
[ public ] class Name ClassBody
|
||||
|
||||
ClassBody:
|
||||
"{" { { Modifier } Declaration } "}"
|
||||
|
||||
Declaration:
|
||||
VariableDeclaration
|
||||
MethodDeclaration
|
||||
ConstructorDeclaration
|
||||
|
||||
ConstructorDeclaration:
|
||||
[ public ] Name ( [ FormalArguments ] ) Block
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="AdditionalModuleElements">
|
||||
<content url="file://$MODULE_DIR$" dumb="true">
|
||||
<sourceFolder url="file://$MODULE_DIR$/Source" isTestSource="false" />
|
||||
</content>
|
||||
</component>
|
||||
</module>
|
||||
@@ -1 +1,3 @@
|
||||
Please move your stuff from "Source" to "src".
|
||||
Dies ist das Repository des Mini-Java-Compiler-Bauprojekt der Gruppe NichtHaskell für das 4. Semester Informatik der Dualen Hochschule Baden-Württemberg in Stuttgart (Horb).
|
||||
|
||||
Alles weitere ist in der Dokumentation DokumentationNichtHaskell.pdf unter `/Documentation/DokumentationNichtHaskell.pdf` zu finden.
|
||||
Binary file not shown.
BIN
emptyClass.class
BIN
emptyClass.class
Binary file not shown.
BIN
jar/NichtHaskell.jar
Normal file
BIN
jar/NichtHaskell.jar
Normal file
Binary file not shown.
BIN
jar/NichtHaskellCompiler-jar-with-dependencies.jar
Normal file
BIN
jar/NichtHaskellCompiler-jar-with-dependencies.jar
Normal file
Binary file not shown.
35
pom.xml
35
pom.xml
@@ -4,25 +4,46 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>Clippit.org</groupId>
|
||||
<artifactId>NichtHaskell</artifactId>
|
||||
<version>1</version>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>20</maven.compiler.source>
|
||||
<maven.compiler.target>20</maven.compiler.target>
|
||||
<java.version>22</java.version>
|
||||
<maven.compiler.source>22</maven.compiler.source>
|
||||
<maven.compiler.target>22</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.7.1</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>Compiler</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<finalName>NichtHaskellCompiler</finalName>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
||||
33
src/main/java/CodeGen/CodeGenHelper.java
Normal file
33
src/main/java/CodeGen/CodeGenHelper.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package CodeGen;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class CodeGenHelper {
|
||||
|
||||
public static String getFieldDescriptor(String type) {
|
||||
switch (type) {
|
||||
case "int":
|
||||
return "I";
|
||||
case "boolean":
|
||||
return "Z";
|
||||
case "char":
|
||||
return "C";
|
||||
default:
|
||||
return "L" + type + ";";
|
||||
}
|
||||
}
|
||||
|
||||
public static int GetLocalVarIndex(LinkedHashMap<String, String> localVars, String varToSearchFor) {
|
||||
int index = -1;
|
||||
int counter = 0;
|
||||
for (String key : localVars.keySet()) {
|
||||
if (key.equals(varToSearchFor)) {
|
||||
index = counter + 1; // +1 because the first local variable is at index 1, 0 is used for "this"
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import TypeCheck.TypeCheckException;
|
||||
import abstractSyntaxTree.Program;
|
||||
import astGenerator.ASTGenerator;
|
||||
import gen.DecafLexer;
|
||||
@@ -9,6 +9,7 @@ import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
@@ -18,41 +19,53 @@ public class Compiler {
|
||||
|
||||
public static void main(String[] args) throws Exception{
|
||||
|
||||
Path filePath = Paths.get("src/main/java/TestClass.java");
|
||||
|
||||
if (args.length < 1) {
|
||||
System.out.println("Usage: java -jar Compiler.jar <file_path> [--suppress-details]");
|
||||
return;
|
||||
}
|
||||
|
||||
// todo remove this debug info
|
||||
Path absolutePath = filePath.toAbsolutePath();
|
||||
System.out.println("Processing input: " + absolutePath);
|
||||
String filePath = args[0];
|
||||
|
||||
String content;
|
||||
try {
|
||||
content = Files.readString(filePath);
|
||||
}catch (java.nio.file.NoSuchFileException e){
|
||||
System.out.println("File not found");
|
||||
boolean suppressDetails = false;
|
||||
|
||||
if (args.length > 1 && args[1].equals("--suppress-details")) {
|
||||
suppressDetails = true;
|
||||
}
|
||||
|
||||
Path path = Paths.get(filePath);
|
||||
|
||||
if (!Files.exists(path)) {
|
||||
System.out.println("Your input file was not found: " + path);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!suppressDetails)
|
||||
System.out.println("Processing input: " + path);
|
||||
|
||||
System.out.println("--- print content ---");
|
||||
System.out.println(content);
|
||||
String content = Files.readString(path);
|
||||
|
||||
if(!suppressDetails)
|
||||
System.out.println("The content of your input file is: \n" + content);
|
||||
|
||||
CharStream codeCharStream = CharStreams.fromString(content);
|
||||
DecafLexer lexer = new DecafLexer(codeCharStream);
|
||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
|
||||
System.out.println("--- print tokens ---");
|
||||
tokens.fill();
|
||||
|
||||
List<Token> tokenList = tokens.getTokens();
|
||||
if(!suppressDetails) {
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (Token token : tokenList) {
|
||||
stringBuilder.append(token.getText()).append(" ");
|
||||
List<Token> tokenList = tokens.getTokens();
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (Token token : tokenList) {
|
||||
stringBuilder.append(token.getText()).append(" ");
|
||||
}
|
||||
String readableTokens = stringBuilder.toString().trim();
|
||||
|
||||
System.out.println("The tokens of your input are: \n" + readableTokens + "\n");
|
||||
}
|
||||
String readableTokens = stringBuilder.toString().trim();
|
||||
|
||||
System.out.println(readableTokens);
|
||||
|
||||
|
||||
DecafParser parser = new DecafParser(tokens);
|
||||
@@ -63,14 +76,44 @@ public class Compiler {
|
||||
Program abstractSyntaxTree =(Program) generator.visit(tree);
|
||||
|
||||
|
||||
System.out.println("--- AST generator ---");
|
||||
System.out.println("Parsed " + abstractSyntaxTree.classes.size() + " classes with names:");
|
||||
for (RefType refType : abstractSyntaxTree.classes) {
|
||||
System.out.println(refType.name);
|
||||
|
||||
if(!suppressDetails) {
|
||||
System.out.println("Parsed " + abstractSyntaxTree.classes.size() + " classes: ");
|
||||
abstractSyntaxTree.classes.forEach(refType -> {
|
||||
System.out.println("\t" + refType.name);
|
||||
});
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
abstractSyntaxTree.typeCheck();
|
||||
try {
|
||||
abstractSyntaxTree.typeCheck();
|
||||
}catch(TypeCheckException e){
|
||||
System.out.println("A TypeCheck error was found in you input. Your input was not compiled.");
|
||||
System.out.println(e);
|
||||
return;
|
||||
}catch (Exception e){
|
||||
System.out.println("A unexpected error occurred in TypeCheck.");
|
||||
System.out.println(e);
|
||||
return;
|
||||
}
|
||||
|
||||
abstractSyntaxTree.codeGen();
|
||||
if(!suppressDetails)
|
||||
System.out.println("No TypeCheck errors found.");
|
||||
|
||||
abstractSyntaxTree.codeGen();//todo remove
|
||||
|
||||
try {
|
||||
abstractSyntaxTree.codeGen();
|
||||
}catch (Exception e){
|
||||
System.out.println("A error occurred during code generation. Your input was not compiled.");
|
||||
System.out.println(e);
|
||||
return;
|
||||
}
|
||||
|
||||
File outputJarFile = new File("output.jar");
|
||||
if (outputJarFile.exists())
|
||||
outputJarFile.delete();
|
||||
|
||||
System.out.println("Your input was compiled. You can find the output in your current working directory.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ AccessModifierPublic : 'public' ;
|
||||
MainMethodDecl : 'public static void main(String[] args)';
|
||||
|
||||
//Print Statement print(VariableA);
|
||||
print: 'print('Identifier');';
|
||||
print: 'print' OpenRoundBracket Identifier ClosedRoundBracket Semicolon;
|
||||
|
||||
//Types
|
||||
Void : 'void';
|
||||
@@ -114,7 +114,7 @@ New : 'new';
|
||||
|
||||
|
||||
//Values
|
||||
IntValue : ('+'|'-')*[0-9]+;
|
||||
IntValue : ('+'|'-')?[0-9]+;
|
||||
CharValue: '\''~[\r\n]?'\'';
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
class EmptyClass {
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
class Example1 {
|
||||
public int fak(int number){
|
||||
if(number < 0){
|
||||
return 1;
|
||||
}
|
||||
int factorial = 1;
|
||||
int i = 0;
|
||||
while(i < number){
|
||||
factorial = factorial * i;
|
||||
}
|
||||
return factorial;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,65 @@
|
||||
public class TestClass {
|
||||
class FourClasses {
|
||||
|
||||
public int notmain(int i) {
|
||||
Test t = new Test(i);
|
||||
Test2 t2 = new Test2(t.y);
|
||||
return t2.test.test3.getX();
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Test {
|
||||
public int x;
|
||||
public int y;
|
||||
public Test3 test3;
|
||||
|
||||
public Test(int i) {
|
||||
this.x = i;
|
||||
this.y = 10;
|
||||
this.test3 = new Test3(i * 2);
|
||||
}
|
||||
|
||||
public Test3 getTest3() {
|
||||
return this.test3;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
}
|
||||
|
||||
class Test2 {
|
||||
public Test test;
|
||||
|
||||
public Test2(int i) {
|
||||
this.test = new Test(i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Test3 {
|
||||
public int x;
|
||||
|
||||
public int y;
|
||||
|
||||
public Test3(int i) {
|
||||
this.x = i;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,17 +8,18 @@ public class TypeCheckHelper {
|
||||
boolean type1Primitiv = Objects.equals(type1, "boolean") || Objects.equals(type1, "int") || Objects.equals(type1, "char");
|
||||
boolean type2Primitiv = Objects.equals(type2, "boolean") || Objects.equals(type2, "int") || Objects.equals(type2, "char");
|
||||
|
||||
String result;
|
||||
String result = "class";
|
||||
if(type1Primitiv && type2Primitiv){
|
||||
if(Objects.equals(type1, type2)){
|
||||
result = type1;
|
||||
}else{
|
||||
throw new TypeCheckException("There is no upper bound between " + type1 + " and " + type2 + ".");
|
||||
}
|
||||
}else if(type1Primitiv || type2Primitiv){
|
||||
}else if(type1Primitiv ^ type2Primitiv){
|
||||
throw new TypeCheckException("There is no upper bound between " + type1 + " and " + type2 + ".");
|
||||
}else{
|
||||
result = "class";
|
||||
if(Objects.equals(type1, type2))
|
||||
result = type1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,27 @@
|
||||
package TypeCheck;
|
||||
|
||||
import abstractSyntaxTree.StatementExpression.ReceivingMethod;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class TypeCheckResult {
|
||||
|
||||
public TypeCheckResult(){}
|
||||
public TypeCheckResult(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String type;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
TypeCheckResult typeCheckResult = (TypeCheckResult) o;
|
||||
boolean result = (Objects.equals(type, typeCheckResult.type)
|
||||
);
|
||||
System.out.println("In TypeCheckResult: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package abstractSyntaxTree.Class;
|
||||
|
||||
import CodeGen.CodeGenHelper;
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckHelper;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Expression.IExpression;
|
||||
import abstractSyntaxTree.Node;
|
||||
import abstractSyntaxTree.Program;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.FieldVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
@@ -18,9 +18,9 @@ import java.util.Objects;
|
||||
|
||||
public class FieldDecl extends AbstractType implements Node {
|
||||
|
||||
public String type; // from parser
|
||||
public String identifier;// from parser
|
||||
public IExpression expression; // value of the field
|
||||
public String type;
|
||||
public String identifier;
|
||||
public IExpression expression;
|
||||
|
||||
public FieldDecl(String type, String identifier, IExpression expression){
|
||||
this.type = type;
|
||||
@@ -44,35 +44,22 @@ public class FieldDecl extends AbstractType implements Node {
|
||||
setTypeCheckResult(result);
|
||||
|
||||
return result;
|
||||
|
||||
//write field table
|
||||
}
|
||||
|
||||
public void codeGen(ClassWriter cw) {
|
||||
FieldVisitor fv = cw.visitField(Opcodes.ACC_PUBLIC, identifier, getFieldDescriptor(), null, null);
|
||||
String descriptor = CodeGenHelper.getFieldDescriptor(type);
|
||||
FieldVisitor fv = cw.visitField(Opcodes.ACC_PUBLIC, identifier, descriptor, null, null);
|
||||
fv.visitEnd();
|
||||
}
|
||||
|
||||
private String getFieldDescriptor() {
|
||||
switch (type) {
|
||||
case "int":
|
||||
return "I";
|
||||
case "boolean":
|
||||
return "Z";
|
||||
case "char":
|
||||
return "C";
|
||||
default:
|
||||
return "L" + type + ";";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
FieldDecl fieldDecl = (FieldDecl) o;
|
||||
boolean result = Objects.equals(type, fieldDecl.type)
|
||||
&& Objects.equals(identifier, fieldDecl.identifier);
|
||||
&& Objects.equals(identifier, fieldDecl.identifier)
|
||||
&& Objects.equals(expression, fieldDecl.expression);
|
||||
|
||||
System.out.println("In FieldDecl: " + result);
|
||||
return result;
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package abstractSyntaxTree.Class;
|
||||
|
||||
import CodeGen.CodeGenHelper;
|
||||
import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Node;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
import abstractSyntaxTree.Statement.IStatement;
|
||||
import org.objectweb.asm.*;
|
||||
|
||||
import java.util.*;
|
||||
@@ -35,7 +34,6 @@ public class MethodDecl implements Node {
|
||||
}
|
||||
|
||||
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext) throws TypeCheckException {
|
||||
// jede methode als block statement aufrufen und jede neue locale varibale in localvars schreiben
|
||||
List<Parameter> parametersList = parameters.parameterList;
|
||||
for(Parameter parameter : parametersList){
|
||||
localVars.put(parameter.identifier, parameter.type);
|
||||
@@ -49,13 +47,14 @@ public class MethodDecl implements Node {
|
||||
|
||||
if(!Objects.equals(this.returnType, codeBlockType))
|
||||
throw new TypeCheckException("Method returns " + codeBlockType + ", but should return " + this.returnType + ". ");
|
||||
|
||||
result.type = codeBlock.returnType;
|
||||
return result;
|
||||
}
|
||||
|
||||
//Need to get the returnType of the method if it is an object
|
||||
// methodContext (class, (identifier, (returnType, parameter)))
|
||||
// typeContext (class, (type, identifier))
|
||||
// typeContext (class, (identifier, type))
|
||||
public void codeGen(ClassWriter cw, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, List<FieldDecl> fieldDecls) throws Exception {
|
||||
|
||||
localVars.put("this", classThatContainsMethod);
|
||||
@@ -65,7 +64,7 @@ public class MethodDecl implements Node {
|
||||
|
||||
// check if the method is a constructor
|
||||
if (classThatContainsMethod.equals(name) && returnType == null) {
|
||||
String descriptor = getMethodDescriptor(methodContext);
|
||||
String descriptor = getMethodDescriptor(methodContext, typeContext);
|
||||
|
||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", descriptor, null, null);
|
||||
|
||||
@@ -76,18 +75,31 @@ public class MethodDecl implements Node {
|
||||
HashMap<String, String> classFields = typeContext.get(classThatContainsMethod);
|
||||
|
||||
//Set the fields of the class
|
||||
boolean fieldFound = false;
|
||||
for (Map.Entry<String, String> entry : classFields.entrySet()) {
|
||||
String fieldName = entry.getKey();
|
||||
for (FieldDecl field : fieldDecls) {
|
||||
if (field.identifier.equals(fieldName)) {
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
field.expression.codeGen(mv, localVars, typeContext, methodContext);
|
||||
descriptor = getFieldDescriptor(field.type);
|
||||
if (field.expression != null) {
|
||||
field.expression.codeGen(mv, localVars, typeContext, methodContext);
|
||||
} else {
|
||||
// If the field is not initialized, we need to load a default value onto the stack
|
||||
switch (field.type) {
|
||||
case "int", "boolean", "char" -> mv.visitInsn(Opcodes.ICONST_0);
|
||||
default -> mv.visitInsn(Opcodes.ACONST_NULL);
|
||||
}
|
||||
}
|
||||
descriptor = CodeGenHelper.getFieldDescriptor(field.type);
|
||||
mv.visitFieldInsn(Opcodes.PUTFIELD, classThatContainsMethod, fieldName, descriptor);
|
||||
} else {
|
||||
throw new Exception("Field " + fieldName + " not found");
|
||||
fieldFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!fieldFound){
|
||||
throw new Exception("Field " + fieldName + " not found");
|
||||
}
|
||||
}
|
||||
|
||||
//Load the parameters onto the stack
|
||||
@@ -127,7 +139,7 @@ public class MethodDecl implements Node {
|
||||
mv.visitEnd();
|
||||
|
||||
} else {
|
||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, name, getMethodDescriptor(methodContext), null, null);
|
||||
MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, name, getMethodDescriptor(methodContext, typeContext), null, null);
|
||||
|
||||
mv.visitCode();
|
||||
codeBlock.codeGen(mv, localVars, typeContext, methodContext);
|
||||
@@ -142,7 +154,7 @@ public class MethodDecl implements Node {
|
||||
}
|
||||
}
|
||||
|
||||
private String getMethodDescriptor(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext) {
|
||||
private String getMethodDescriptor(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext) {
|
||||
// get the method descriptor
|
||||
StringBuilder descriptor = new StringBuilder("(");
|
||||
|
||||
@@ -155,8 +167,18 @@ public class MethodDecl implements Node {
|
||||
case "void" -> descriptor.append("V");
|
||||
default -> {
|
||||
// object
|
||||
//TODO: This is not finished for objects --> classes and methods
|
||||
if (returnType != null) descriptor.append("L").append(returnType).append(";");
|
||||
if (param.type != null) {
|
||||
String paramType = param.type;
|
||||
// If it is a class reference replace the "." with "/" and return it
|
||||
HashMap<String, String> classTypes = typeContext.get(classThatContainsMethod);
|
||||
if (classTypes != null) {
|
||||
if (classTypes.containsKey(paramType)) {
|
||||
paramType = classTypes.get(paramType);
|
||||
paramType.replaceAll("\\.", "/");
|
||||
}
|
||||
}
|
||||
descriptor.append("L").append(paramType).append(";");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,19 +214,6 @@ public class MethodDecl implements Node {
|
||||
return descriptor.toString();
|
||||
}
|
||||
|
||||
private String getFieldDescriptor(String type) {
|
||||
switch (type) {
|
||||
case "int":
|
||||
return "I";
|
||||
case "boolean":
|
||||
return "Z";
|
||||
case "char":
|
||||
return "C";
|
||||
default:
|
||||
return "L" + type + ";";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
@@ -3,7 +3,6 @@ package abstractSyntaxTree.Class;
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Expression.IExpression;
|
||||
import abstractSyntaxTree.Node;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
@@ -68,7 +67,6 @@ public class RefType extends AbstractType implements Node {
|
||||
|
||||
// type check each method
|
||||
for (MethodDecl methodDecl : methodDecls) {
|
||||
// methodDecl.classThatContainsMethod = this.name;
|
||||
methodDecl.typeCheck(methodContext, typeContext);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package abstractSyntaxTree.Datatype;
|
||||
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import org.objectweb.asm.*;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -3,6 +3,7 @@ package abstractSyntaxTree.Datatype;
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -21,11 +22,13 @@ public class CharDatatype extends AbstractType implements IDatatype{
|
||||
|
||||
@Override
|
||||
public void codeGen(MethodVisitor mv) throws Exception {
|
||||
|
||||
// Possible use of BIPUSH and SIPUSH if the value is small enough
|
||||
//This saves space in the bytecode which is not very relevant at this point, but could be implemented anyway
|
||||
|
||||
mv.visitLdcInsn((int)value);
|
||||
if (value <= 5) {
|
||||
mv.visitInsn(Opcodes.ICONST_0 + value);
|
||||
} else if (value <= Byte.MAX_VALUE) {
|
||||
mv.visitIntInsn(Opcodes.BIPUSH, value);
|
||||
} else {
|
||||
mv.visitIntInsn(Opcodes.SIPUSH, value);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
||||
@@ -5,14 +5,9 @@ import TypeCheck.TypeCheckResult;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
|
||||
public interface IDatatype {
|
||||
// typeCheck method
|
||||
TypeCheckResult typeCheck() throws TypeCheckException;
|
||||
|
||||
// visit method for code generation
|
||||
|
||||
void codeGen(MethodVisitor mv) throws Exception;
|
||||
|
||||
TypeCheckResult getTypeCheckResult();
|
||||
}
|
||||
|
||||
//TODO: Check if we need to differentiate between primitive types and reference types --> for example in "=="
|
||||
@@ -21,8 +21,6 @@ public class IntDatatype extends AbstractType implements IDatatype{
|
||||
|
||||
@Override
|
||||
public void codeGen(MethodVisitor mv) throws Exception {
|
||||
|
||||
//Example of using BIPUSH and SIPUSH for optimizing bytecode size
|
||||
if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE)
|
||||
mv.visitIntInsn(Opcodes.BIPUSH, value);
|
||||
else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE)
|
||||
|
||||
@@ -7,7 +7,6 @@ import TypeCheck.AbstractType;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import org.objectweb.asm.*;
|
||||
|
||||
import java.beans.Expression;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Objects;
|
||||
@@ -17,6 +16,7 @@ public class BinaryExpression extends AbstractType implements IExpression{
|
||||
public String operator;
|
||||
public IExpression left;
|
||||
public IExpression right;
|
||||
public String thisClass;
|
||||
|
||||
public BinaryExpression(String operator, IExpression left, IExpression right) {
|
||||
this.operator = operator;
|
||||
@@ -28,6 +28,10 @@ public class BinaryExpression extends AbstractType implements IExpression{
|
||||
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws TypeCheckException {
|
||||
TypeCheckResult result = new TypeCheckResult();
|
||||
|
||||
if(left instanceof LocalVarIdentifier localVarIdentifier)
|
||||
localVarIdentifier.thisClass = this.thisClass;
|
||||
if(right instanceof LocalVarIdentifier localVarIdentifier)
|
||||
localVarIdentifier.thisClass = this.thisClass;
|
||||
TypeCheckResult leftType = left.typeCheck(methodContext, typeContext, localVars);
|
||||
TypeCheckResult rightType = right.typeCheck(methodContext, typeContext, localVars);
|
||||
|
||||
@@ -58,9 +62,6 @@ public class BinaryExpression extends AbstractType implements IExpression{
|
||||
result.type = "int";
|
||||
}
|
||||
break;
|
||||
|
||||
//case "&" ist für logisches und auf bit level
|
||||
//case "|" ist für logisches oder auf bit level
|
||||
}
|
||||
|
||||
setTypeCheckResult(result);
|
||||
@@ -118,12 +119,14 @@ public class BinaryExpression extends AbstractType implements IExpression{
|
||||
mv.visitJumpInsn(Opcodes.IFNE, operationTrue);
|
||||
}
|
||||
case "==" -> {
|
||||
// Keep in mind that only primitive types are allowed in this case (at this time)
|
||||
|
||||
left.codeGen(mv, localVars, typeContext, methodContext);
|
||||
right.codeGen(mv, localVars, typeContext, methodContext);
|
||||
|
||||
mv.visitJumpInsn(Opcodes.IF_ICMPEQ, operationTrue); // If the two values are equal, jump to the end of the expression
|
||||
switch (left.getTypeCheckResult().type) {
|
||||
case "int", "boolean", "char" -> mv.visitJumpInsn(Opcodes.IF_ICMPEQ, operationTrue);
|
||||
|
||||
default -> mv.visitJumpInsn(Opcodes.IF_ACMPEQ, operationTrue);
|
||||
}
|
||||
}
|
||||
case "<" -> {
|
||||
left.codeGen(mv, localVars, typeContext, methodContext);
|
||||
@@ -176,6 +179,7 @@ public class BinaryExpression extends AbstractType implements IExpression{
|
||||
boolean result = (Objects.equals(operator, binaryExpression.operator)
|
||||
&& Objects.equals(left, binaryExpression.left)
|
||||
&& Objects.equals(right, binaryExpression.right)
|
||||
&& Objects.equals(left.getTypeCheckResult(), binaryExpression.left.getTypeCheckResult())
|
||||
);
|
||||
System.out.println("In BinaryExpression: " + result);
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package abstractSyntaxTree.Expression;
|
||||
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Datatype.BoolDatatype;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
@@ -27,7 +27,13 @@ public class CharConstantExpression extends AbstractType implements IExpression{
|
||||
|
||||
@Override
|
||||
public void codeGen(MethodVisitor mv, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext) throws Exception {
|
||||
mv.visitIntInsn(Opcodes.BIPUSH, (int) value);
|
||||
if (value <= 5) {
|
||||
mv.visitInsn(Opcodes.ICONST_0 + value);
|
||||
} else if (value <= Byte.MAX_VALUE) {
|
||||
mv.visitIntInsn(Opcodes.BIPUSH, value);
|
||||
} else {
|
||||
mv.visitIntInsn(Opcodes.SIPUSH, value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -10,11 +10,7 @@ import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public interface IExpression extends Node {
|
||||
// typeCheck method
|
||||
//TypeCheckResult typeCheck() throws Exception;
|
||||
TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws TypeCheckException;
|
||||
|
||||
// visit method for code generation
|
||||
void codeGen(MethodVisitor mv, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext) throws Exception;
|
||||
|
||||
TypeCheckResult getTypeCheckResult();
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package abstractSyntaxTree.Expression;
|
||||
|
||||
import CodeGen.CodeGenHelper;
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.StatementExpression.ReceivingMethod;
|
||||
import gen.DecafParser;
|
||||
import jdk.jshell.spi.ExecutionControl;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
@@ -16,14 +14,14 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class InstVarExpression extends AbstractType implements IExpression{
|
||||
public class InstVarExpression extends AbstractType implements IExpression {
|
||||
|
||||
public String thisClass;
|
||||
public List<SubReceiver> receivers;
|
||||
public List<ReceivingMethod> receivingMethods;
|
||||
public String fieldName;
|
||||
|
||||
public InstVarExpression(List<SubReceiver> receivers, List<ReceivingMethod> receivingMethods, String fieldName){
|
||||
public InstVarExpression(List<SubReceiver> receivers, List<ReceivingMethod> receivingMethods, String fieldName) {
|
||||
this.receivers = receivers;
|
||||
this.receivingMethods = receivingMethods;
|
||||
this.fieldName = fieldName;
|
||||
@@ -31,12 +29,31 @@ public class InstVarExpression extends AbstractType implements IExpression{
|
||||
|
||||
@Override
|
||||
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws TypeCheckException {
|
||||
String varType = typeContext.get(thisClass).get(fieldName);
|
||||
String typeOfSubreceiver = "";
|
||||
if (receivers.get(0).identifier != null) {
|
||||
String subreceiver = receivers.get(0).identifier;
|
||||
typeOfSubreceiver = localVars.get(subreceiver);
|
||||
if (typeOfSubreceiver == null)
|
||||
typeContext.get(thisClass).get(subreceiver);
|
||||
|
||||
if (receivers.size() > 1) {
|
||||
for (int i = 1; i < receivers.size(); i++) {
|
||||
subreceiver = receivers.get(i).identifier;
|
||||
typeOfSubreceiver = typeContext.get(typeOfSubreceiver).get(subreceiver);
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
typeOfSubreceiver = thisClass;
|
||||
}
|
||||
|
||||
String varType = typeContext.get(typeOfSubreceiver).get(fieldName);
|
||||
if (varType == null) {
|
||||
throw new TypeCheckException("Field " + fieldName + " was not found in class " + thisClass + ".");
|
||||
}
|
||||
TypeCheckResult result = new TypeCheckResult();
|
||||
result.type = varType;
|
||||
setTypeCheckResult(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -44,11 +61,123 @@ public class InstVarExpression extends AbstractType implements IExpression{
|
||||
// typeContext: (ClassName, (FieldName, FieldType))
|
||||
public void codeGen(MethodVisitor mv, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext) throws Exception {
|
||||
// Load "this" onto the stack
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
String typeOfReciever = "";
|
||||
String descriptor = "";
|
||||
String classOfField = "";
|
||||
|
||||
//Get the field information
|
||||
String fieldType = typeContext.get(thisClass).get(fieldName);
|
||||
// Determine if the reference is this or not
|
||||
if (this.receivers.get(0).identifier != null) {
|
||||
|
||||
for (int i = 0; i < receivers.size(); i++) {
|
||||
|
||||
if (i == 0) {
|
||||
// Load the local variable onto the stack
|
||||
int index = CodeGenHelper.GetLocalVarIndex(localVars, this.receivers.get(i).identifier);
|
||||
|
||||
if (index == -1) {
|
||||
if (typeContext.get(thisClass).get(this.receivers.get(i).identifier) != null) {
|
||||
|
||||
classOfField = typeOfReciever;
|
||||
|
||||
typeOfReciever = typeContext.get(typeOfReciever).get(this.receivers.get(i).identifier);
|
||||
|
||||
descriptor = getFieldDescriptor(typeOfReciever);
|
||||
|
||||
// Load the variable onto the stack
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, classOfField, receivers.get(i).identifier, descriptor);
|
||||
continue;
|
||||
|
||||
} else {
|
||||
throw new Exception("Variable " + this.receivers.get(i).identifier + " not found");
|
||||
}
|
||||
|
||||
} else {
|
||||
mv.visitVarInsn(Opcodes.ALOAD, index);
|
||||
|
||||
|
||||
// Get the class of the receiver
|
||||
typeOfReciever = localVars.get(this.receivers.get(i).identifier);
|
||||
}
|
||||
}
|
||||
// Not the first receiver
|
||||
else {
|
||||
|
||||
// Load the local variable onto the stack
|
||||
int index = CodeGenHelper.GetLocalVarIndex(localVars, this.receivers.get(i).identifier);
|
||||
|
||||
if (index == -1) {
|
||||
if (typeContext.get(typeOfReciever).get(this.receivers.get(i).identifier) != null) {
|
||||
|
||||
classOfField = typeOfReciever;
|
||||
|
||||
typeOfReciever = typeContext.get(typeOfReciever).get(this.receivers.get(i).identifier);
|
||||
|
||||
descriptor = getFieldDescriptor(typeOfReciever);
|
||||
|
||||
// Load the variable onto the stack
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, classOfField, receivers.get(i).identifier, descriptor);
|
||||
continue;
|
||||
|
||||
} else {
|
||||
throw new Exception("Variable " + this.receivers.get(i).identifier + " not found");
|
||||
}
|
||||
} else {
|
||||
typeOfReciever = localVars.get(this.receivers.get(i).identifier);
|
||||
|
||||
descriptor = getFieldDescriptor(typeOfReciever);
|
||||
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, typeOfReciever, fieldName, descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Load the field in fieldName
|
||||
|
||||
// Load the local variable onto the stack
|
||||
int index = CodeGenHelper.GetLocalVarIndex(localVars, fieldName);
|
||||
|
||||
if (index == -1) {
|
||||
if (typeContext.get(typeOfReciever).get(fieldName) != null) {
|
||||
|
||||
classOfField = typeOfReciever;
|
||||
|
||||
typeOfReciever = typeContext.get(typeOfReciever).get(fieldName);
|
||||
|
||||
descriptor = getFieldDescriptor(typeOfReciever);
|
||||
|
||||
// Load the variable onto the stack
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, classOfField, fieldName, descriptor);
|
||||
|
||||
} else {
|
||||
throw new Exception("Variable " + fieldName + " not found");
|
||||
}
|
||||
|
||||
} else {
|
||||
typeOfReciever = localVars.get(fieldName);
|
||||
|
||||
descriptor = getFieldDescriptor(typeOfReciever);
|
||||
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, typeOfReciever, fieldName, descriptor);
|
||||
}
|
||||
} else if (receivers.get(0).thisExpression) {
|
||||
// Load the local variable or instVar of this onto the stack
|
||||
int index = CodeGenHelper.GetLocalVarIndex(localVars, fieldName);
|
||||
|
||||
if (index == -1) {
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
|
||||
} else {
|
||||
mv.visitVarInsn(Opcodes.ALOAD, index);
|
||||
}
|
||||
|
||||
String fieldType = typeContext.get(thisClass).get(fieldName);
|
||||
descriptor = getFieldDescriptor(fieldType);
|
||||
|
||||
//Load the field onto the stack
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, thisClass, fieldName, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
private String getFieldDescriptor(String fieldType) {
|
||||
StringBuilder descriptor = new StringBuilder();
|
||||
|
||||
|
||||
@@ -63,16 +192,13 @@ public class InstVarExpression extends AbstractType implements IExpression{
|
||||
descriptor.append("C");
|
||||
break;
|
||||
default:
|
||||
String fullReturnType = typeContext.get(thisClass).get(fieldName);
|
||||
|
||||
String fullReturnType = fieldType;
|
||||
// If it is a class reference replace the "." with "/" and return it
|
||||
if (fieldType.contains(".")) fullReturnType = fullReturnType.replaceAll("\\.", "/");
|
||||
if (fullReturnType != null) descriptor.append("L").append(fullReturnType).append(";");
|
||||
break;
|
||||
}
|
||||
|
||||
// Load the variable onto the stack
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, thisClass, fieldName, descriptor.toString());
|
||||
return descriptor.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,8 +206,10 @@ public class InstVarExpression extends AbstractType implements IExpression{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
InstVarExpression instVarExpression = (InstVarExpression) o;
|
||||
boolean result = (Objects.equals(thisClass, instVarExpression.thisClass)
|
||||
boolean result = (Objects.equals(receivers, instVarExpression.receivers)
|
||||
&& Objects.equals(fieldName, instVarExpression.fieldName)
|
||||
&& Objects.equals(receivingMethods, instVarExpression.receivingMethods)
|
||||
&& Objects.equals(thisClass, instVarExpression.thisClass)
|
||||
);
|
||||
System.out.println("In InstVarExpression: " + result);
|
||||
|
||||
@@ -92,4 +220,4 @@ public class InstVarExpression extends AbstractType implements IExpression{
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,8 +28,15 @@ public class IntConstantExpression extends AbstractType implements IExpression{
|
||||
|
||||
@Override
|
||||
public void codeGen(MethodVisitor mv, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext) throws Exception {
|
||||
//TODO: When we are finished this can be done more efficiently
|
||||
mv.visitLdcInsn(value);
|
||||
if (value >= -1 && value <= 5) {
|
||||
mv.visitInsn(Opcodes.ICONST_0 + value);
|
||||
} else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
|
||||
mv.visitIntInsn(Opcodes.BIPUSH, value);
|
||||
} else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) {
|
||||
mv.visitIntInsn(Opcodes.SIPUSH, value);
|
||||
} else {
|
||||
mv.visitLdcInsn(value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package abstractSyntaxTree.Expression;
|
||||
|
||||
import CodeGen.CodeGenHelper;
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckHelper;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import org.objectweb.asm.*;
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.util.LinkedHashMap;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public class LocalVarIdentifier extends AbstractType implements IExpression{
|
||||
@@ -52,15 +51,7 @@ public class LocalVarIdentifier extends AbstractType implements IExpression{
|
||||
if (localVars.containsKey(identifier)) {
|
||||
type = localVars.get(identifier);
|
||||
// Find the index of the variable
|
||||
int index = -1;
|
||||
int counter = 0;
|
||||
for (String key : localVars.keySet()) {
|
||||
if (key.equals(identifier)) {
|
||||
index = counter + 1; // +1 because the first local variable is at index 1, 0 is used for "this"
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
int index = CodeGenHelper.GetLocalVarIndex(localVars, identifier);
|
||||
|
||||
if (index == -1) {
|
||||
throw new Exception("Variable " + identifier + " not found");
|
||||
@@ -84,25 +75,13 @@ public class LocalVarIdentifier extends AbstractType implements IExpression{
|
||||
// Load "this" onto the stack
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
// Get the field from "this"
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, thisClass, identifier, getFieldDescriptor(type));
|
||||
String descriptor = CodeGenHelper.getFieldDescriptor(type);
|
||||
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, thisClass, identifier, descriptor);
|
||||
} else
|
||||
throw new Exception("Variable " + identifier + " not found");
|
||||
}
|
||||
|
||||
//TODO move this to a helper class and remove the doubled code in MethodDecl and in other places
|
||||
private String getFieldDescriptor(String type) {
|
||||
switch (type) {
|
||||
case "int":
|
||||
return "I";
|
||||
case "boolean":
|
||||
return "Z";
|
||||
case "char":
|
||||
return "C";
|
||||
default:
|
||||
return "L" + type + ";";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return super.getTypeCheckResult();
|
||||
|
||||
@@ -3,8 +3,10 @@ package abstractSyntaxTree.Expression;
|
||||
import abstractSyntaxTree.Node;
|
||||
import abstractSyntaxTree.StatementExpression.NewStatementExpression;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class SubReceiver implements Node {
|
||||
boolean thisExpression;
|
||||
public boolean thisExpression;
|
||||
public NewStatementExpression newStatementExpression;
|
||||
public String identifier;
|
||||
|
||||
@@ -19,4 +21,16 @@ public class SubReceiver implements Node {
|
||||
public SubReceiver(String identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
SubReceiver subReceiver = (SubReceiver) o;
|
||||
boolean result = (Objects.equals(thisExpression, subReceiver.thisExpression)
|
||||
);
|
||||
System.out.println("In SubReceiver: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@ package abstractSyntaxTree.Expression;
|
||||
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckHelper;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Datatype.IDatatype;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
@@ -77,9 +75,12 @@ public class UnaryExpression extends AbstractType implements IExpression{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
UnaryExpression unaryExpression = (UnaryExpression) o;
|
||||
return (Objects.equals(operator, unaryExpression.operator)
|
||||
boolean result = (Objects.equals(operator, unaryExpression.operator)
|
||||
&& Objects.equals(operand, unaryExpression.operand)
|
||||
);
|
||||
System.out.println("In UnaryExpression: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,8 +19,11 @@ public class Parameter implements Node {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Parameter parameter = (Parameter) o;
|
||||
return (Objects.equals(type, parameter.type)
|
||||
boolean result = (Objects.equals(type, parameter.type)
|
||||
&& Objects.equals(identifier, parameter.identifier)
|
||||
);
|
||||
System.out.println("In Parameter: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,10 @@ public class ParameterList implements Node {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ParameterList parameterListObj = (ParameterList) o;
|
||||
return (Objects.equals(parameterList, parameterListObj.parameterList)
|
||||
boolean result = (Objects.equals(parameterList, parameterListObj.parameterList)
|
||||
);
|
||||
System.out.println("In ParameterList: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.*;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -27,8 +29,7 @@ public class Program implements Node {
|
||||
this.classes = classes;
|
||||
}
|
||||
|
||||
|
||||
public TypeCheckResult typeCheck() throws TypeCheckException {
|
||||
public TypeCheckResult typeCheckWithoutMain() throws TypeCheckException {
|
||||
this.typeContext = new HashMap<>();
|
||||
this.methodContext = new HashMap<>();
|
||||
|
||||
@@ -59,6 +60,49 @@ public class Program implements Node {
|
||||
if(oneClass.hasMain)
|
||||
mainCounter++;
|
||||
}
|
||||
if(mainCounter != 1) {
|
||||
//throw new TypeCheckException("There is not 1 Main method.");
|
||||
}
|
||||
|
||||
// typecheck each class
|
||||
TypeCheckResult result = new TypeCheckResult();
|
||||
for(RefType oneClass : classes){
|
||||
oneClass.typeCheck(methodContext, typeContext);
|
||||
}
|
||||
result.type = "program";
|
||||
return result;
|
||||
}
|
||||
|
||||
public TypeCheckResult typeCheck() throws TypeCheckException {
|
||||
this.typeContext = new HashMap<>();
|
||||
this.methodContext = new HashMap<>();
|
||||
|
||||
for(RefType oneClass : classes){
|
||||
|
||||
// build type context
|
||||
HashMap<String, String> classVars = new HashMap<>();
|
||||
for (FieldDecl fieldDecl: oneClass.fieldDecls){
|
||||
classVars.put(fieldDecl.identifier, fieldDecl.type);
|
||||
}
|
||||
typeContext.put(oneClass.name, classVars);
|
||||
|
||||
// build method context
|
||||
HashMap<String, HashMap<String, ParameterList>> identifierAndMethod = new HashMap<>();
|
||||
for (MethodDecl methodDecl : oneClass.methodDecls){
|
||||
if(methodDecl.returnType == null) continue;
|
||||
HashMap<String, ParameterList> returnTypeAndParameter = new HashMap<>();
|
||||
returnTypeAndParameter.put(methodDecl.returnType, methodDecl.parameters);
|
||||
identifierAndMethod.put(methodDecl.name, returnTypeAndParameter);
|
||||
}
|
||||
methodContext.put(oneClass.name, identifierAndMethod);
|
||||
}
|
||||
|
||||
// check if main exists
|
||||
int mainCounter = 0;
|
||||
for(RefType oneClass : classes){
|
||||
if(oneClass.hasMain)
|
||||
mainCounter++;
|
||||
}
|
||||
if(mainCounter != 1)
|
||||
throw new TypeCheckException("There is not 1 Main method.");
|
||||
|
||||
@@ -71,28 +115,60 @@ public class Program implements Node {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void codeGen() throws Exception{
|
||||
public void codeGen() throws Exception {
|
||||
// Store the names of the generated class files
|
||||
List<String> classFileNames = new ArrayList<>();
|
||||
|
||||
try {
|
||||
for (RefType oneClass : classes) {
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, oneClass.name, null, "java/lang/Object", null);
|
||||
|
||||
oneClass.codeGen(cw, methodContext, typeContext);
|
||||
oneClass.codeGen(cw, methodContext, typeContext);
|
||||
|
||||
cw.visitEnd();
|
||||
byte[] bytecode = cw.toByteArray();
|
||||
|
||||
try (FileOutputStream fos = new FileOutputStream(oneClass.name + ".class")) {
|
||||
String classFileName = oneClass.name + ".class";
|
||||
classFileNames.add(classFileName);
|
||||
|
||||
try (FileOutputStream fos = new FileOutputStream(classFileName)) {
|
||||
fos.write(bytecode);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// Now create the JAR file
|
||||
try (FileOutputStream fos = new FileOutputStream("output.jar");
|
||||
JarOutputStream jos = new JarOutputStream(fos)) {
|
||||
|
||||
for (String classFileName : classFileNames) {
|
||||
addFileToJar(jos, classFileName);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void addFileToJar(JarOutputStream jos, String fileName) throws IOException {
|
||||
File file = new File(fileName);
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
JarEntry entry = new JarEntry(fileName);
|
||||
jos.putNextEntry(entry);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||
jos.write(buffer, 0, bytesRead);
|
||||
}
|
||||
jos.closeEntry();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
@@ -3,11 +3,10 @@ package abstractSyntaxTree.Statement;
|
||||
import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import TypeCheck.AbstractType;
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
|
||||
import abstractSyntaxTree.StatementExpression.MethodCallStatementExpression;
|
||||
import abstractSyntaxTree.StatementExpression.NewStatementExpression;
|
||||
import org.objectweb.asm.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -16,13 +15,10 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class BlockStatement extends AbstractType implements IStatement {
|
||||
|
||||
//We will need a parameter which holds the symbol table
|
||||
HashMap<String, String> localVars;
|
||||
public String returnType; // "not" --> not void
|
||||
public String returnType;
|
||||
public List<IStatement> statements;
|
||||
public String thisClass;
|
||||
// do we need expression, statementexpression
|
||||
|
||||
public BlockStatement(List<IStatement> statements, String returnType) {
|
||||
this.statements = statements;
|
||||
@@ -63,14 +59,23 @@ public class BlockStatement extends AbstractType implements IStatement {
|
||||
if (statement instanceof PrintStatement printStatement) {
|
||||
printStatement.thisClass = thisClass;
|
||||
}
|
||||
if (statement instanceof ReturnStatement returnStatement) {
|
||||
returnStatement.thisClass = thisClass;
|
||||
}
|
||||
if (statement instanceof NewStatementExpression newStatementExpression) {
|
||||
newStatementExpression.thisClass = thisClass;
|
||||
}
|
||||
|
||||
TypeCheckResult typeOfCurrentStatement = statement.typeCheck(methodContext, typeContext, localVars);
|
||||
if(statement instanceof MethodCallStatementExpression methodCall){
|
||||
typeOfCurrentStatement.type = "void";
|
||||
}
|
||||
if(statement instanceof LocalVarDecl localVarDecl){
|
||||
localVars.put(localVarDecl.identifier, localVarDecl.type);
|
||||
}
|
||||
|
||||
if (typeOfCurrentStatement.type.contains(",")) {
|
||||
// else if has 2 returns, all code paths must retrun a value.
|
||||
// else if has 2 returns, all code paths must return a value.
|
||||
String[] substrings = typeOfCurrentStatement.type.split(",");
|
||||
|
||||
String firstType = substrings[0];
|
||||
@@ -106,6 +111,7 @@ public class BlockStatement extends AbstractType implements IStatement {
|
||||
}
|
||||
if(this.returnType == null)
|
||||
this.returnType = "void";
|
||||
|
||||
result.type = this.returnType;
|
||||
setTypeCheckResult(result);
|
||||
return result;
|
||||
@@ -116,7 +122,6 @@ public class BlockStatement extends AbstractType implements IStatement {
|
||||
// Create a new HashMap for the local variables of the block
|
||||
// It has every variable of the parent block
|
||||
// This Map is discarded at the end of the block
|
||||
//TODO: Do this for every block --> if, while, ...
|
||||
LinkedHashMap<String, String> blockLocalVars = new LinkedHashMap<>(localVars);
|
||||
|
||||
for (IStatement statement : statements) {
|
||||
@@ -129,10 +134,13 @@ public class BlockStatement extends AbstractType implements IStatement {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
BlockStatement blockStatement = (BlockStatement) o;
|
||||
return (Objects.equals(localVars, blockStatement.localVars)
|
||||
&& Objects.equals(returnType, blockStatement.returnType)
|
||||
&& Objects.equals(statements, blockStatement.statements)
|
||||
boolean result = Objects.equals(returnType, blockStatement.returnType)
|
||||
&& Objects.equals(statements, blockStatement.statements
|
||||
/*&& (Objects.equals(localVars, blockStatement.localVars)*/
|
||||
);
|
||||
System.out.println("In BlockStatement: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,8 +7,7 @@ import org.objectweb.asm.MethodVisitor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class EmptyStatement extends AbstractType implements IStatement{
|
||||
|
||||
@@ -24,13 +23,16 @@ public class EmptyStatement extends AbstractType implements IStatement{
|
||||
//An empty statement does not generate any code
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.objectweb.asm.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class IfElseStatement extends AbstractType implements IStatement{
|
||||
@@ -54,7 +53,6 @@ public class IfElseStatement extends AbstractType implements IStatement{
|
||||
}
|
||||
|
||||
|
||||
//TODO: There are 2 NOPs and one athrow on the stack between the if-Block and else-Block execution --> I have no idea why
|
||||
@Override
|
||||
public void codeGen(MethodVisitor mv, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext) throws Exception {
|
||||
|
||||
@@ -82,10 +80,13 @@ public class IfElseStatement extends AbstractType implements IStatement{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
IfElseStatement ifElseStatement = (IfElseStatement) o;
|
||||
return (Objects.equals(condition, ifElseStatement.condition)
|
||||
boolean result = (Objects.equals(condition, ifElseStatement.condition)
|
||||
&& Objects.equals(ifStatement, ifElseStatement.ifStatement)
|
||||
&& Objects.equals(elseStatement, ifElseStatement.elseStatement)
|
||||
);
|
||||
System.out.println("In PrintStatement: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,13 +9,10 @@ import org.objectweb.asm.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class IfStatement extends AbstractType implements IStatement{
|
||||
public IExpression condition;
|
||||
|
||||
//Do we need a block statement here?
|
||||
IStatement ifStatement;
|
||||
public String thisClass;
|
||||
|
||||
@@ -62,9 +59,12 @@ public class IfStatement extends AbstractType implements IStatement{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
IfStatement ifStatementObj = (IfStatement) o;
|
||||
return (Objects.equals(condition, ifStatementObj.condition)
|
||||
boolean result = (Objects.equals(condition, ifStatementObj.condition)
|
||||
&& Objects.equals(ifStatement, ifStatementObj.ifStatement)
|
||||
);
|
||||
System.out.println("In IfStatement: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package abstractSyntaxTree.Statement;
|
||||
|
||||
import CodeGen.CodeGenHelper;
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckHelper;
|
||||
@@ -7,8 +8,8 @@ import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Expression.IExpression;
|
||||
import abstractSyntaxTree.Expression.LocalVarIdentifier;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
|
||||
import abstractSyntaxTree.StatementExpression.MethodCallStatementExpression;
|
||||
import abstractSyntaxTree.StatementExpression.NewStatementExpression;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
@@ -36,11 +37,14 @@ public class LocalVarDecl extends AbstractType implements IStatement{
|
||||
if(expression instanceof MethodCallStatementExpression){
|
||||
MethodCallStatementExpression methodCall = (MethodCallStatementExpression) expression;
|
||||
methodCall.thisClass = this.thisClass;
|
||||
|
||||
}
|
||||
if(expression instanceof LocalVarIdentifier localVarIdentifier){
|
||||
localVarIdentifier.thisClass = thisClass;
|
||||
}
|
||||
if (expression instanceof NewStatementExpression newStatementExpression){
|
||||
newStatementExpression.thisClass = thisClass;
|
||||
}
|
||||
|
||||
expression.typeCheck(methodContext, typeContext, localVars);
|
||||
}
|
||||
|
||||
@@ -55,15 +59,8 @@ public class LocalVarDecl extends AbstractType implements IStatement{
|
||||
public void codeGen(MethodVisitor mv, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext) throws Exception {
|
||||
localVars.put(identifier, type);
|
||||
|
||||
int index = -1;
|
||||
int counter = 0;
|
||||
for (String key : localVars.keySet()){
|
||||
if (key.equals(identifier)){
|
||||
index = counter+1; // +1 because the first local variable is at index 1, 0 is used for "this"
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
|
||||
int index = CodeGenHelper.GetLocalVarIndex(localVars, identifier);
|
||||
|
||||
if (index == -1){
|
||||
throw new Exception("Variable " + identifier + " not found");
|
||||
@@ -82,7 +79,7 @@ public class LocalVarDecl extends AbstractType implements IStatement{
|
||||
}
|
||||
} else {
|
||||
|
||||
// Set a default value for the variable --> less problems
|
||||
// Set a default value for the variable --> fewer problems
|
||||
switch (type) {
|
||||
case "int", "boolean", "char":
|
||||
mv.visitInsn(Opcodes.ICONST_0);
|
||||
@@ -102,9 +99,12 @@ public class LocalVarDecl extends AbstractType implements IStatement{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
LocalVarDecl localVarDecl = (LocalVarDecl) o;
|
||||
return (Objects.equals(type, localVarDecl.type)
|
||||
boolean result = (Objects.equals(type, localVarDecl.type)
|
||||
&& Objects.equals(identifier, localVarDecl.identifier)
|
||||
);
|
||||
System.out.println("In LocalVarDecl: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package abstractSyntaxTree.Statement;
|
||||
|
||||
import CodeGen.CodeGenHelper;
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
@@ -15,6 +16,18 @@ public class PrintStatement extends AbstractType implements IStatement {
|
||||
String variableName;
|
||||
public String thisClass;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
PrintStatement printStatement = (PrintStatement) o;
|
||||
boolean result = (Objects.equals(variableName, printStatement.variableName)
|
||||
);
|
||||
System.out.println("In PrintStatement: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public PrintStatement(String variableName) {
|
||||
this.variableName = variableName;
|
||||
}
|
||||
@@ -28,7 +41,7 @@ public class PrintStatement extends AbstractType implements IStatement {
|
||||
}
|
||||
if (!Objects.equals(typeOfVar, "int"))
|
||||
throw new TypeCheckException("The variable to be printed is " + typeOfVar + " but should be int.");
|
||||
result.type = typeOfVar;
|
||||
result.type = "void";
|
||||
setTypeCheckResult(result);
|
||||
return result;
|
||||
}
|
||||
@@ -39,18 +52,15 @@ public class PrintStatement extends AbstractType implements IStatement {
|
||||
mv.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
|
||||
|
||||
// Load the value of the variable onto the stack
|
||||
int index = -1;
|
||||
int counter = 0;
|
||||
for (String key : localVars.keySet()){
|
||||
if (key.equals(variableName)){
|
||||
index = counter+1; // +1 because the first local variable is at index 1, 0 is used for "this"
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
int index = CodeGenHelper.GetLocalVarIndex(localVars, variableName);
|
||||
|
||||
// If not a localVar, maybe a class field of this class
|
||||
if (index == -1){
|
||||
throw new Exception("Variable " + variableName + " not found");
|
||||
String typeOfField = typeContext.get(thisClass).get(variableName);
|
||||
if (typeOfField == null){
|
||||
throw new Exception("Variable " + variableName + " not found in local variables or class fields.");
|
||||
}
|
||||
mv.visitFieldInsn(Opcodes.GETSTATIC, thisClass, variableName, "I");
|
||||
}
|
||||
|
||||
mv.visitVarInsn(Opcodes.ILOAD, index);
|
||||
|
||||
@@ -4,16 +4,19 @@ import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import TypeCheck.AbstractType;
|
||||
import abstractSyntaxTree.Expression.IExpression;
|
||||
import abstractSyntaxTree.Expression.InstVarExpression;
|
||||
import abstractSyntaxTree.Expression.LocalVarIdentifier;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.StatementExpression.MethodCallStatementExpression;
|
||||
import org.objectweb.asm.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ReturnStatement extends AbstractType implements IStatement{
|
||||
IExpression expression;
|
||||
IExpression expression; // Needs typeCheckResult
|
||||
public String thisClass;
|
||||
|
||||
public ReturnStatement(IExpression expression) {
|
||||
this.expression = expression;
|
||||
@@ -26,6 +29,12 @@ public class ReturnStatement extends AbstractType implements IStatement{
|
||||
if (expression == null) {
|
||||
result.type = "void";
|
||||
} else {
|
||||
if(expression instanceof MethodCallStatementExpression methodCallStatementExpression)
|
||||
methodCallStatementExpression.thisClass = this.thisClass;
|
||||
else if(expression instanceof InstVarExpression instVarExpression)
|
||||
instVarExpression.thisClass = this.thisClass;
|
||||
else if(expression instanceof LocalVarIdentifier localVarIdentifier)
|
||||
localVarIdentifier.thisClass = this.thisClass;
|
||||
TypeCheckResult typedExpression = expression.typeCheck(methodContext, typeContext, localVars);
|
||||
result.type = typedExpression.type;
|
||||
}
|
||||
@@ -34,9 +43,7 @@ public class ReturnStatement extends AbstractType implements IStatement{
|
||||
return result;
|
||||
}
|
||||
|
||||
//TODO: We do not differentiate between primitive types and reference types
|
||||
// This is a problem at "BinaryExpression" and here because we need to know the type to return
|
||||
// At this point in time we can either return reference types or have an error message
|
||||
|
||||
@Override
|
||||
public void codeGen(MethodVisitor mv, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext) throws Exception {
|
||||
|
||||
@@ -60,8 +67,12 @@ public class ReturnStatement extends AbstractType implements IStatement{
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ReturnStatement returnStatement = (ReturnStatement) o;
|
||||
return (Objects.equals(expression, returnStatement.expression)
|
||||
boolean result = (Objects.equals(expression, returnStatement.expression)
|
||||
&& Objects.equals(expression.getTypeCheckResult(), returnStatement.expression.getTypeCheckResult())
|
||||
);
|
||||
System.out.println("In ReturnStatement: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,7 +9,6 @@ import org.objectweb.asm.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class WhileStatement extends AbstractType implements IStatement {
|
||||
@@ -29,7 +28,7 @@ public class WhileStatement extends AbstractType implements IStatement {
|
||||
// check condition
|
||||
TypeCheckResult conditionType = condition.typeCheck(methodContext, typeContext, localVars);
|
||||
if (!conditionType.type.equals("boolean")) {
|
||||
throw new IllegalArgumentException("Expected boolean");
|
||||
throw new TypeCheckException("Condition of while-statement is of type " + conditionType.type + " but should be boolean.");
|
||||
}
|
||||
|
||||
// check code block
|
||||
@@ -55,8 +54,7 @@ public class WhileStatement extends AbstractType implements IStatement {
|
||||
mv.visitJumpInsn(Opcodes.IFEQ, conditionFalse); // Checks if the condition is false (0)
|
||||
|
||||
statement.codeGen(mv, blockLocalVars, typeContext, methodContext);
|
||||
//TODO: If the block ends with a return statement, we might have to pop it from the stack
|
||||
// So the next iteration starts with a clean stack
|
||||
|
||||
mv.visitJumpInsn(Opcodes.GOTO, LoopStart); // Jump to the start of the while loop
|
||||
|
||||
mv.visitLabel(conditionFalse);
|
||||
@@ -67,9 +65,13 @@ public class WhileStatement extends AbstractType implements IStatement {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
WhileStatement whileStatement = (WhileStatement) o;
|
||||
return (Objects.equals(condition, whileStatement.condition)
|
||||
boolean result = (Objects.equals(condition, whileStatement.condition)
|
||||
&& Objects.equals(statement, whileStatement.statement)
|
||||
);
|
||||
System.out.println("In PrintStatement: " + result);
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package abstractSyntaxTree.StatementExpression;
|
||||
|
||||
import CodeGen.CodeGenHelper;
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckHelper;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Expression.BinaryExpression;
|
||||
import abstractSyntaxTree.Expression.IExpression;
|
||||
import abstractSyntaxTree.Expression.InstVarExpression;
|
||||
import abstractSyntaxTree.Expression.LocalVarIdentifier;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Statement.IStatement;
|
||||
import abstractSyntaxTree.Statement.WhileStatement;
|
||||
import org.objectweb.asm.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -36,17 +37,27 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
|
||||
TypeCheckResult leftType;
|
||||
|
||||
if (left instanceof LocalVarIdentifier localVarIdentifier) {
|
||||
localVarIdentifier.thisClass = thisClass;
|
||||
leftType = new TypeCheckResult();
|
||||
String identifier = localVarIdentifier.getIdentifier();
|
||||
leftType.type = localVars.get(identifier);
|
||||
|
||||
// local var may be actually instvar of this
|
||||
// local var may be actually instVar of this
|
||||
if(leftType.type == null){
|
||||
leftType.type = typeContext.get(thisClass).get(identifier);
|
||||
}
|
||||
}else{
|
||||
}else {
|
||||
if(left instanceof InstVarExpression instVarExpression)
|
||||
instVarExpression.thisClass = this.thisClass;
|
||||
leftType = left.typeCheck(methodContext, typeContext, localVars);
|
||||
}
|
||||
if(right instanceof MethodCallStatementExpression methodCallStatementExpression)
|
||||
methodCallStatementExpression.thisClass = this.thisClass;
|
||||
if(right instanceof LocalVarIdentifier localVarIdentifierRight)
|
||||
localVarIdentifierRight.thisClass = this.thisClass;
|
||||
if(right instanceof BinaryExpression binaryExpression)
|
||||
binaryExpression.thisClass = this.thisClass;
|
||||
|
||||
TypeCheckResult rightType = right.typeCheck(methodContext, typeContext, localVars);
|
||||
|
||||
String upperbound = TypeCheckHelper.upperBound(leftType.type, rightType.type);
|
||||
@@ -67,32 +78,34 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
|
||||
|
||||
@Override
|
||||
public void codeGen(MethodVisitor mv, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext) throws Exception {
|
||||
//TODO: Do we need the value on the stack after assigning it?
|
||||
//TODO: WE do not differentiate between InstanceVar and FieldVar
|
||||
|
||||
// Call the codeGen on the right expression which will push the value of the right expression onto the stack
|
||||
right.codeGen(mv, localVars, typeContext, methodContext);
|
||||
|
||||
if (left instanceof LocalVarIdentifier) {
|
||||
LocalVarIdentifier localVar = (LocalVarIdentifier) left;
|
||||
String varName = localVar.getIdentifier();
|
||||
|
||||
//Get the index of the local variable
|
||||
int index = -1;
|
||||
int counter = 0;
|
||||
for (String key : localVars.keySet()) {
|
||||
if (key.equals(varName)) {
|
||||
index = counter+1;
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
int index = CodeGenHelper.GetLocalVarIndex(localVars, varName);
|
||||
|
||||
if (index == -1) {
|
||||
throw new Exception("Variable " + varName + " not found");
|
||||
String fieldType = typeContext.get(thisClass).get(varName);
|
||||
if (fieldType != null) {
|
||||
// Load "this" onto the stack
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
// Call the codeGen on the right expression which will push the value of the right expression onto the stack
|
||||
right.codeGen(mv, localVars, typeContext, methodContext);
|
||||
// Get the field descriptor
|
||||
String descriptor = getFieldDescriptor(fieldType, typeContext, varName, thisClass);
|
||||
// Store the value in the field
|
||||
mv.visitFieldInsn(Opcodes.PUTFIELD, thisClass, varName, descriptor);
|
||||
return;
|
||||
} else {
|
||||
throw new Exception("Variable " + varName + " not found");
|
||||
}
|
||||
}
|
||||
|
||||
String type = localVars.get(localVar.getIdentifier());
|
||||
// Call the codeGen on the right expression which will push the value of the right expression onto the stack
|
||||
right.codeGen(mv, localVars, typeContext, methodContext);
|
||||
switch (type) {
|
||||
case "int", "char", "boolean":
|
||||
mv.visitVarInsn(Opcodes.ISTORE, index);
|
||||
@@ -105,38 +118,129 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
|
||||
} else if (left instanceof InstVarExpression) {
|
||||
instVar = (InstVarExpression) left;
|
||||
|
||||
// Load "this" onto the stack
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
boolean isLocal = false;
|
||||
|
||||
// Duplicate the top of the stack as we'll need it for both the PUTFIELD and subsequent expressions
|
||||
mv.visitInsn(Opcodes.DUP_X1);
|
||||
// Load the reference onto the stack
|
||||
// Determine if the reference is this or another object
|
||||
if (instVar.receivers.get(0).identifier != null) {
|
||||
// Load the local variable (another object) onto the stack
|
||||
int index = CodeGenHelper.GetLocalVarIndex(localVars, instVar.receivers.get(0).identifier);
|
||||
|
||||
// Get the field information
|
||||
String fieldType = typeContext.get(instVar.thisClass).get(instVar.fieldName);
|
||||
if (index == -1) {
|
||||
throw new Exception("Variable " + instVar.receivers.get(0).identifier + " not found");
|
||||
}
|
||||
mv.visitVarInsn(Opcodes.ALOAD, index);
|
||||
isLocal = true;
|
||||
} else {
|
||||
// Load "this" onto the stack
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
|
||||
StringBuilder descriptor = new StringBuilder();
|
||||
|
||||
switch (fieldType) {
|
||||
case "int":
|
||||
descriptor.append("I");
|
||||
break;
|
||||
case "boolean":
|
||||
descriptor.append("Z");
|
||||
break;
|
||||
default:
|
||||
String fullReturnType = typeContext.get(instVar.thisClass).get(instVar.fieldName);
|
||||
|
||||
// If it is a class reference replace the "." with "/" and return it
|
||||
if (fieldType.contains(".")) fullReturnType = fullReturnType.replaceAll("\\.", "/");
|
||||
if (fullReturnType != null) descriptor.append("L").append(fullReturnType).append(";");
|
||||
break;
|
||||
}
|
||||
|
||||
// Store the value in the field
|
||||
mv.visitFieldInsn(Opcodes.PUTFIELD, instVar.thisClass, instVar.fieldName, descriptor.toString());
|
||||
//Now that the base ref is on the stack, I need to get the next field(s) and store the value in the last field
|
||||
|
||||
String typeOfPrevious = "";
|
||||
String currentType = "";
|
||||
if (instVar.receivers.size() > 0) {
|
||||
for (int i = 0; i < instVar.receivers.size(); i++) {
|
||||
|
||||
if (i == 0) {
|
||||
|
||||
//Check if the chain is longer than 1
|
||||
// If it is not, then we can directly store the value in the field
|
||||
// If not we have to load the reference of the field on the stack
|
||||
if (instVar.receivers.size() < 2) {
|
||||
// Chain is only 1 long, so we can call PUTFIELD directly
|
||||
|
||||
//Load the value of the right expression on the stack
|
||||
right.codeGen(mv, localVars, typeContext, methodContext);
|
||||
|
||||
if (isLocal) {
|
||||
typeOfPrevious = localVars.get(instVar.receivers.get(i).identifier);
|
||||
} else {
|
||||
typeOfPrevious = typeContext.get(thisClass).get(instVar.receivers.get(i).identifier);
|
||||
if (typeOfPrevious == null) {
|
||||
typeOfPrevious = thisClass;
|
||||
}
|
||||
}
|
||||
|
||||
currentType = typeContext.get(typeOfPrevious).get(instVar.fieldName);
|
||||
|
||||
String descriptor = getFieldDescriptor(currentType, typeContext, instVar.fieldName, typeOfPrevious);
|
||||
mv.visitFieldInsn(Opcodes.PUTFIELD, typeOfPrevious, instVar.fieldName, descriptor);
|
||||
continue;
|
||||
} else {
|
||||
|
||||
if (isLocal) {
|
||||
currentType = localVars.get(instVar.receivers.get(i).identifier);
|
||||
} else {
|
||||
currentType = typeContext.get(thisClass).get(instVar.receivers.get(i).identifier);
|
||||
}
|
||||
|
||||
String descriptor = getFieldDescriptor(currentType, typeContext, instVar.receivers.get(i).identifier, thisClass);
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, thisClass, instVar.receivers.get(i).identifier, descriptor);
|
||||
typeOfPrevious = currentType;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
//Now we have to implement the logic for the following fields in the chain as the above code
|
||||
// only handles the first field in the chain
|
||||
|
||||
currentType = typeContext.get(typeOfPrevious).get(instVar.receivers.get(i).identifier);
|
||||
String descriptor = getFieldDescriptor(currentType, typeContext, instVar.receivers.get(i).identifier, typeOfPrevious);
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, typeOfPrevious, instVar.receivers.get(i).identifier, descriptor);
|
||||
typeOfPrevious = currentType;
|
||||
}
|
||||
|
||||
// Now we have the reference of the last field in the chain on the stack
|
||||
if (instVar.receivers.size() > 1) {
|
||||
// We can store the value of the right expression in this field
|
||||
right.codeGen(mv, localVars, typeContext, methodContext);
|
||||
|
||||
currentType = typeContext.get(typeOfPrevious).get(instVar.fieldName);
|
||||
String descriptor = getFieldDescriptor(currentType, typeContext, instVar.fieldName, typeOfPrevious);
|
||||
mv.visitFieldInsn(Opcodes.PUTFIELD, typeOfPrevious, instVar.fieldName, descriptor);
|
||||
}
|
||||
|
||||
} else {
|
||||
// When a field is accessed directly and without a "this."
|
||||
|
||||
//Load the value of the right expression on the stack
|
||||
right.codeGen(mv, localVars, typeContext, methodContext);
|
||||
|
||||
// Get the field information
|
||||
String fieldType = typeContext.get(instVar.thisClass).get(instVar.fieldName);
|
||||
|
||||
// Get the field descriptor
|
||||
String descriptor = getFieldDescriptor(fieldType, typeContext, instVar.fieldName, instVar.thisClass);
|
||||
|
||||
// Store the value in the field
|
||||
mv.visitFieldInsn(Opcodes.PUTFIELD, instVar.thisClass, instVar.fieldName, descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getFieldDescriptor(String type, HashMap<String, HashMap<String, String>> typeContext, String varName, String classToSearchFieldIn) {
|
||||
StringBuilder descriptor = new StringBuilder();
|
||||
switch (type) {
|
||||
case "int":
|
||||
return "I";
|
||||
case "boolean":
|
||||
return "Z";
|
||||
case "char":
|
||||
return "C";
|
||||
default: {
|
||||
String fullReturnType = typeContext.get(classToSearchFieldIn).get(varName);
|
||||
|
||||
// If it is a class reference replace the "." with "/" and return it
|
||||
if (type.contains(".")) fullReturnType = fullReturnType.replaceAll("\\.", "/");
|
||||
if (fullReturnType != null) descriptor.append("L").append(fullReturnType).append(";");
|
||||
return descriptor.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
@@ -3,13 +3,10 @@ package abstractSyntaxTree.StatementExpression;
|
||||
import TypeCheck.AbstractType;
|
||||
import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Expression.IExpression;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Statement.IStatement;
|
||||
import jdk.jshell.spi.ExecutionControl;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
@@ -34,7 +31,6 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
||||
|
||||
String classToSearchMethodIn = thisClass;
|
||||
|
||||
//method is called on something that is not this ???
|
||||
if (this.receiver != null) {
|
||||
if (!receiver.thisExpression) {
|
||||
classToSearchMethodIn = localVars.get(receiver.identifier);
|
||||
@@ -45,26 +41,20 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
||||
|
||||
String currentType = "";
|
||||
|
||||
// receiver is instvar
|
||||
// receiver is instVar
|
||||
if (receiver != null) {
|
||||
if (receiver.instVarExpression != null) {
|
||||
String Subreceiver = receiver.instVarExpression.receivers.get(0).identifier; // e
|
||||
String mostLeftField = receiver.instVarExpression.fieldName; // example1
|
||||
receiver.instVarExpression.thisClass = this.thisClass;
|
||||
String typeOfSubreceiver = receiver.instVarExpression.typeCheck(methodContext, typeContext, localVars).type;
|
||||
|
||||
String typeOfSubreceiver = typeContext.get(thisClass).get(Subreceiver);
|
||||
|
||||
receiver.instVarExpression.thisClass = typeOfSubreceiver;
|
||||
receiver.instVarExpression.typeCheck(methodContext, typeContext, localVars);
|
||||
currentType = typeContext.get(typeOfSubreceiver).get(mostLeftField);
|
||||
currentType = typeOfSubreceiver;
|
||||
} else {
|
||||
currentType = thisClass;
|
||||
currentType = classToSearchMethodIn;
|
||||
}
|
||||
} else {
|
||||
currentType = thisClass;
|
||||
}
|
||||
|
||||
//if classToSearchMethodIn does not contain method, throw exception. go through list and check each
|
||||
|
||||
for (int i = 0; i < receivingMethods.size(); i++) {
|
||||
currentType = (String) methodContext.get(currentType).get(receivingMethods.get(i).methodName).keySet().toArray()[0];
|
||||
if (currentType == null)
|
||||
@@ -74,6 +64,9 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
||||
}
|
||||
currentType = (String) methodContext.get(currentType).get(methodName).keySet().toArray()[0];
|
||||
|
||||
for (IExpression argument : arguments) {
|
||||
argument.typeCheck(methodContext, typeContext, localVars);
|
||||
}
|
||||
TypeCheckResult result = new TypeCheckResult();
|
||||
result.type = currentType;
|
||||
setTypeCheckResult(result);
|
||||
@@ -105,7 +98,7 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, thisClass, receiver.identifier, "L" + type + ";"); // Load the field onto the stack
|
||||
} else {
|
||||
// It's a local variable
|
||||
int index = localVars.keySet().stream().toList().indexOf(receiver.identifier)+1; // +1 because the first local variable is at index 1, 0 is used for "this"
|
||||
int index = localVars.keySet().stream().toList().indexOf(receiver.identifier) + 1; // +1 because the first local variable is at index 1, 0 is used for "this"
|
||||
int opcode = type.equals("int") ? Opcodes.ILOAD : Opcodes.ALOAD;
|
||||
mv.visitVarInsn(opcode, index); // Load local variable onto the stack
|
||||
}
|
||||
@@ -114,32 +107,47 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
||||
throw new ExecutionControl.NotImplementedException("Receiver type not supported.");
|
||||
}
|
||||
} else {
|
||||
throw new ExecutionControl.NotImplementedException("Receiver is null.");
|
||||
}
|
||||
/*
|
||||
else {
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 0);
|
||||
owner = thisClass;
|
||||
|
||||
String type = localVars.get(receiver.identifier);
|
||||
if (type == null) {
|
||||
type = typeContext.get(thisClass).get(receiver.identifier);
|
||||
}
|
||||
mv.visitVarInsn(Opcodes.ALOAD, 1);
|
||||
mv.visitFieldInsn(Opcodes.GETFIELD, thisClass, receiver.identifier, "L" + type + ";");
|
||||
}
|
||||
String returnOfPreviousMethod = null;
|
||||
// Invoke the method for each receiving method in the chain
|
||||
for (ReceivingMethod receivingMethod : receivingMethods) {
|
||||
// Get the owner class for the current method in the chain
|
||||
if (returnOfPreviousMethod != null) {
|
||||
// If the return of the previous method is not null, use it as the owner class for the current method in the chain
|
||||
owner = returnOfPreviousMethod;
|
||||
}
|
||||
*/
|
||||
|
||||
// Generate the code for each argument expression for the current method
|
||||
for (IExpression argument : receivingMethod.arguments) {
|
||||
argument.codeGen(mv, localVars, typeContext, methodContext);
|
||||
}
|
||||
|
||||
// Invoke the current method
|
||||
String descriptor = getMethodDescriptor(receivingMethod.methodName, localVars, methodContext, receivingMethod.arguments, returnOfPreviousMethod, owner);
|
||||
returnOfPreviousMethod = methodContext.get(owner).get(receivingMethod.methodName).keySet().toArray()[0].toString();
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, owner, receivingMethod.methodName, descriptor, false);
|
||||
}
|
||||
|
||||
// Invoke the final method
|
||||
|
||||
// Generate the code for each argument expression
|
||||
for (IExpression argument : arguments) {
|
||||
argument.codeGen(mv, localVars, typeContext, methodContext);
|
||||
}
|
||||
|
||||
// Invoke the method
|
||||
String descriptor = getMethodDescriptor(localVars, methodContext);
|
||||
if (returnOfPreviousMethod != null) {
|
||||
owner = returnOfPreviousMethod;
|
||||
}
|
||||
|
||||
String descriptor = getMethodDescriptor(methodName, localVars, methodContext, arguments, returnOfPreviousMethod, owner);
|
||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, owner, methodName, descriptor, false);
|
||||
|
||||
}
|
||||
// ()I
|
||||
private String getMethodDescriptor(LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext) {
|
||||
|
||||
private String getMethodDescriptor(String methodName, LinkedHashMap<String, String> localVars, HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, List<IExpression> arguments, String returnOfPreviousMethod, String owner) {
|
||||
StringBuilder descriptor = new StringBuilder("(");
|
||||
|
||||
for (IExpression argument : arguments) {
|
||||
@@ -168,10 +176,28 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
||||
}
|
||||
descriptor.append(")");
|
||||
|
||||
String classToSearchMethodIn;
|
||||
//Return Type
|
||||
String classToSearchMethodIn = localVars.get(receiver.identifier);
|
||||
if (classToSearchMethodIn == null)
|
||||
if (receiver != null) {
|
||||
if (receiver.identifier != null) {
|
||||
classToSearchMethodIn = localVars.get(receiver.identifier);
|
||||
if (classToSearchMethodIn == null) {
|
||||
classToSearchMethodIn = returnOfPreviousMethod;
|
||||
}
|
||||
if (classToSearchMethodIn == null) {
|
||||
classToSearchMethodIn = thisClass;
|
||||
}
|
||||
} else {
|
||||
if (receiver.instVarExpression != null && returnOfPreviousMethod != null) {
|
||||
classToSearchMethodIn = returnOfPreviousMethod;
|
||||
} else {
|
||||
classToSearchMethodIn = owner;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
classToSearchMethodIn = thisClass;
|
||||
}
|
||||
|
||||
|
||||
String returnType = methodContext.get(classToSearchMethodIn).get(methodName).keySet().toArray()[0].toString();
|
||||
|
||||
@@ -194,8 +220,6 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
||||
descriptor.append("L").append(returnType).append(";");
|
||||
break;
|
||||
}
|
||||
System.out.println("Descriptor: " + descriptor.toString());
|
||||
|
||||
return descriptor.toString();
|
||||
}
|
||||
|
||||
@@ -205,13 +229,84 @@ public class MethodCallStatementExpression extends AbstractType implements IExpr
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
MethodCallStatementExpression methodCallStatementExpression = (MethodCallStatementExpression) o;
|
||||
return (Objects.equals(methodName, methodCallStatementExpression.methodName)
|
||||
boolean typeCheckResults = testTypeChecks(this, methodCallStatementExpression);
|
||||
|
||||
boolean result = (Objects.equals(methodName, methodCallStatementExpression.methodName)
|
||||
&& Objects.equals(arguments, methodCallStatementExpression.arguments)
|
||||
);
|
||||
&& Objects.equals(thisClass, methodCallStatementExpression.thisClass));
|
||||
return result && typeCheckResults;
|
||||
|
||||
}
|
||||
|
||||
public boolean testTypeChecks(MethodCallStatementExpression class1, MethodCallStatementExpression class2) {
|
||||
|
||||
boolean resultArguments = true;
|
||||
|
||||
for (int i = 0; i < class1.arguments.size(); i++){
|
||||
resultArguments = resultArguments && Objects.equals(class1.arguments.get(i).getTypeCheckResult(), class2.arguments.get(i).getTypeCheckResult());
|
||||
}
|
||||
|
||||
boolean exception1 = false;
|
||||
boolean exception2 = false;
|
||||
|
||||
try {
|
||||
class1.receiver.instVarExpression.getTypeCheckResult();
|
||||
} catch (NullPointerException e) {
|
||||
exception1 = true;
|
||||
}
|
||||
|
||||
try {
|
||||
class2.receiver.instVarExpression.getTypeCheckResult();
|
||||
} catch (NullPointerException e) {
|
||||
exception2 = true;
|
||||
}
|
||||
|
||||
if(exception1 != exception2) {
|
||||
System.out.println("Only one of the InstVarTypeChecks is null in MethodCallStatementExpression");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!exception1) {
|
||||
boolean resultInstVar = Objects.equals(receiver.instVarExpression.getTypeCheckResult(), class2.receiver.instVarExpression.getTypeCheckResult());
|
||||
if(!resultInstVar) {
|
||||
System.out.println("TypeCheckResult of receiver.instVarExpression.getTypeCheckResult() in MethodCallStatementExpression do not match");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
try {
|
||||
class1.receiver.newStatementExpression.getTypeCheckResult();
|
||||
} catch (NullPointerException e) {
|
||||
exception1 = true;
|
||||
}
|
||||
|
||||
try {
|
||||
class2.receiver.newStatementExpression.getTypeCheckResult();
|
||||
} catch (NullPointerException e) {
|
||||
exception2 = true;
|
||||
}
|
||||
|
||||
if(exception1 != exception2) {
|
||||
System.out.println("Only one of the newStatementExpression Typechecks is null in MethodCallStatementExpression");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!exception1) {
|
||||
boolean resultNewStatementExpression = Objects.equals(receiver.newStatementExpression.getTypeCheckResult().type, class2.receiver.newStatementExpression.getTypeCheckResult().type);
|
||||
if(!resultNewStatementExpression) {
|
||||
System.out.println("TypeCheckResult of receiver.newStatementExpression.getTypeCheckResult().type in MethodCallStatementExpression do not match");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult getTypeCheckResult() {
|
||||
return super.getTypeCheckResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,19 +5,17 @@ import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckHelper;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Expression.IExpression;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Expression.InstVarExpression;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Statement.IStatement;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class NewStatementExpression extends AbstractType implements IExpression, IStatement {
|
||||
|
||||
public String thisClass;
|
||||
private String className;
|
||||
private List<IExpression> arguments;
|
||||
|
||||
@@ -26,12 +24,38 @@ public class NewStatementExpression extends AbstractType implements IExpression,
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
NewStatementExpression newStatementExpression = (NewStatementExpression) o;
|
||||
boolean resultTypeCheckArguments = true;
|
||||
for (int i = 0; i < newStatementExpression.arguments.size(); i++){
|
||||
resultTypeCheckArguments = resultTypeCheckArguments && Objects.equals(this.arguments.get(i).getTypeCheckResult(), newStatementExpression.arguments.get(i).getTypeCheckResult());
|
||||
}
|
||||
boolean result = (Objects.equals(className, newStatementExpression.className)
|
||||
&& Objects.equals(arguments, newStatementExpression.arguments)
|
||||
);
|
||||
System.out.println("In newStatementExpression: " + result);
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeCheckResult typeCheck(HashMap<String, HashMap<String, HashMap<String, ParameterList>>> methodContext, HashMap<String, HashMap<String, String>> typeContext, HashMap<String, String> localVars) throws TypeCheckException {
|
||||
if(!TypeCheckHelper.typeExists(className, new ArrayList<>(typeContext.keySet()))){
|
||||
throw new TypeCheckException("An instance of " + className + " is created, but the type does not exist.");
|
||||
}
|
||||
for (IExpression argument : arguments) {
|
||||
if (argument instanceof InstVarExpression instVarExpression) {
|
||||
instVarExpression.thisClass = this.thisClass;
|
||||
}
|
||||
argument.typeCheck(methodContext, typeContext, localVars);
|
||||
}
|
||||
|
||||
TypeCheckResult result = new TypeCheckResult();
|
||||
|
||||
result.type = className;
|
||||
setTypeCheckResult(result);
|
||||
return result;
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
package abstractSyntaxTree.StatementExpression;
|
||||
|
||||
import TypeCheck.TypeCheckException;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Expression.IExpression;
|
||||
|
||||
import abstractSyntaxTree.Expression.InstVarExpression;
|
||||
import abstractSyntaxTree.Node;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Statement.IStatement;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Receiver implements Node {
|
||||
boolean thisExpression;
|
||||
@@ -18,6 +12,22 @@ public class Receiver implements Node {
|
||||
NewStatementExpression newStatementExpression;
|
||||
String identifier;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Receiver receiver = (Receiver) o;
|
||||
boolean result = (Objects.equals(thisExpression, receiver.thisExpression)
|
||||
&& Objects.equals(instVarExpression, receiver.instVarExpression)
|
||||
&& Objects.equals(newStatementExpression, receiver.newStatementExpression)
|
||||
&& Objects.equals(identifier, receiver.identifier)
|
||||
);
|
||||
System.out.println("In receiver: " + result);
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public Receiver(boolean thisExpression) {
|
||||
this.thisExpression = thisExpression;
|
||||
}
|
||||
|
||||
@@ -5,16 +5,29 @@ import abstractSyntaxTree.Expression.IExpression;
|
||||
import abstractSyntaxTree.Expression.LocalVarIdentifier;
|
||||
import abstractSyntaxTree.Node;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Statement.LocalVarDecl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ReceivingMethod implements Node {
|
||||
public String methodName;
|
||||
public List<IExpression> arguments;
|
||||
public String thisClass;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ReceivingMethod receivingMethod = (ReceivingMethod) o;
|
||||
boolean result = (Objects.equals(methodName, receivingMethod.methodName)
|
||||
&& Objects.equals(arguments, receivingMethod.arguments)
|
||||
);
|
||||
System.out.println("In ReceivingMethod: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public ReceivingMethod(String methodName, List<IExpression> arguments) {
|
||||
this.methodName = methodName;
|
||||
this.arguments = arguments;
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package abstractSyntaxTree.StatementExpression;
|
||||
|
||||
import abstractSyntaxTree.Expression.IExpression;
|
||||
import java.util.List;
|
||||
|
||||
public class SuperStatementExpression extends MethodCallStatementExpression{
|
||||
public SuperStatementExpression(String methodName, List<IExpression> arguments, List<ReceivingMethod> receivingMethods, Receiver receiver) {
|
||||
super(methodName, receiver, receivingMethods, arguments);
|
||||
}
|
||||
}
|
||||
@@ -32,27 +32,27 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
List<FieldDecl> fieldDecls = new ArrayList<>();
|
||||
List<MethodDecl> methodDecls = new ArrayList<>();
|
||||
boolean hasMain;
|
||||
if(ctx.MainMethodDecl() != null) {
|
||||
if (ctx.MainMethodDecl() != null) {
|
||||
hasMain = true;
|
||||
MethodDecl mainMethod = new MethodDecl(name, "void", "main", new ParameterList(new ArrayList<>()),(BlockStatement) visitBlock(ctx.block()));
|
||||
MethodDecl mainMethod = new MethodDecl(name, "void", "main", new ParameterList(new ArrayList<>()), (BlockStatement) visitBlock(ctx.block()));
|
||||
methodDecls.add(mainMethod);
|
||||
} else {
|
||||
hasMain = false;
|
||||
}
|
||||
for (DecafParser.LocalVarDeclContext fieldDecl: ctx.localVarDecl()) {
|
||||
for (DecafParser.LocalVarDeclContext fieldDecl : ctx.localVarDecl()) {
|
||||
fieldDecls.add((FieldDecl) generateFieldDecl(fieldDecl));
|
||||
}
|
||||
for (DecafParser.ConstuctorDeclContext constDecl: ctx.constuctorDecl()) {
|
||||
for (DecafParser.ConstuctorDeclContext constDecl : ctx.constuctorDecl()) {
|
||||
MethodDecl constructor = ((MethodDecl) visit(constDecl));
|
||||
constructor.classThatContainsMethod = name;
|
||||
methodDecls.add(constructor);
|
||||
}
|
||||
for (DecafParser.MethodDeclContext methodDecl: ctx.methodDecl()) {
|
||||
for (DecafParser.MethodDeclContext methodDecl : ctx.methodDecl()) {
|
||||
MethodDecl method = (MethodDecl) visit(methodDecl);
|
||||
method.classThatContainsMethod = name;
|
||||
methodDecls.add(method);
|
||||
}
|
||||
return new RefType(name,fieldDecls, methodDecls, hasMain);
|
||||
return new RefType(name, fieldDecls, methodDecls, hasMain);
|
||||
}
|
||||
|
||||
public Node generateFieldDecl(DecafParser.LocalVarDeclContext ctx) {
|
||||
@@ -68,10 +68,10 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
public Node visitLocalVarDecl(DecafParser.LocalVarDeclContext ctx) {
|
||||
if (ctx.expression() != null) {
|
||||
IExpression expression = (IExpression) visit(ctx.expression());
|
||||
return new LocalVarDecl(ctx.type().getText(), ctx.Identifier().getText(), expression);
|
||||
return new LocalVarDecl(ctx.type().getText(), ctx.Identifier().getText(), expression);
|
||||
} else {
|
||||
return new LocalVarDecl(ctx.type().getText(), ctx.Identifier().getText(), null);
|
||||
}
|
||||
return new LocalVarDecl(ctx.type().getText(), ctx.Identifier().getText(), null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,7 +99,7 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
} else {
|
||||
type = ctx.type().getText();
|
||||
}
|
||||
return new MethodDecl("", type , name, parameterList, block);
|
||||
return new MethodDecl("", type, name, parameterList, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,7 +110,7 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
@Override
|
||||
public Node visitParameterList(DecafParser.ParameterListContext ctx) {
|
||||
List<Parameter> parameters = new ArrayList<>();
|
||||
for (DecafParser.ParameterContext parameter: ctx.parameter()) {
|
||||
for (DecafParser.ParameterContext parameter : ctx.parameter()) {
|
||||
parameters.add((Parameter) visit(parameter));
|
||||
}
|
||||
return new ParameterList(parameters);
|
||||
@@ -140,14 +140,18 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
|
||||
@Override
|
||||
public Node visitReturnStmt(DecafParser.ReturnStmtContext ctx) {
|
||||
Node expression = visitExpression(ctx.expression());
|
||||
return new ReturnStatement((IExpression) expression);
|
||||
if (ctx.expression() != null) {
|
||||
Node expression = visitExpression(ctx.expression());
|
||||
return new ReturnStatement((IExpression) expression);
|
||||
} else {
|
||||
return new ReturnStatement(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node visitBlock(DecafParser.BlockContext ctx) {
|
||||
List<IStatement> stmts = new ArrayList<>();
|
||||
for (DecafParser.StatementContext stmt: ctx.statement()) {
|
||||
for (DecafParser.StatementContext stmt : ctx.statement()) {
|
||||
Node statement = visitStatement(stmt);
|
||||
stmts.add((IStatement) statement);
|
||||
}
|
||||
@@ -195,7 +199,7 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
} else if (ctx.newDecl() != null) {
|
||||
return visitNewDecl(ctx.newDecl());
|
||||
}
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -207,7 +211,7 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
public Node visitAssign(DecafParser.AssignContext ctx) {
|
||||
Node right = visitExpression(ctx.expression());
|
||||
Node left = visitAssignableExpr(ctx.assignableExpr());
|
||||
return new AssignStatementExpression(ctx.Assign().getText(),(IExpression) left, (IExpression) right);
|
||||
return new AssignStatementExpression(ctx.Assign().getText(), (IExpression) left, (IExpression) right);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -215,7 +219,7 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
String methodName = ctx.Identifier().getText();
|
||||
List<IExpression> arguments = generateExpressions(ctx.argumentList());
|
||||
List<ReceivingMethod> receivingMethods = new ArrayList<>();
|
||||
for(DecafParser.ReceivingMethodContext receivingMethod: ctx.receivingMethod()) {
|
||||
for (DecafParser.ReceivingMethodContext receivingMethod : ctx.receivingMethod()) {
|
||||
receivingMethods.add((ReceivingMethod) visit(receivingMethod));
|
||||
}
|
||||
if (ctx.receiver() != null) {
|
||||
@@ -316,14 +320,14 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
if (ctx.IntValue() != null) {
|
||||
int value = Integer.parseInt(ctx.IntValue().getText());
|
||||
return new IntConstantExpression(value);
|
||||
} else if(ctx.Identifier() != null) {
|
||||
} else if (ctx.Identifier() != null) {
|
||||
String identifier = ctx.Identifier().getText();
|
||||
return new LocalVarIdentifier(identifier);
|
||||
} else if(ctx.instVar() != null) {
|
||||
} else if (ctx.instVar() != null) {
|
||||
return visitInstVar(ctx.instVar());
|
||||
} else if(ctx.methodCall() != null) {
|
||||
} else if (ctx.methodCall() != null) {
|
||||
return visitMethodCall(ctx.methodCall());
|
||||
} else if(ctx.calcExpr() != null) {
|
||||
} else if (ctx.calcExpr() != null) {
|
||||
return visitCalcExpr(ctx.calcExpr());
|
||||
}
|
||||
return null;
|
||||
@@ -332,7 +336,7 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
@Override
|
||||
public Node visitNonCalcExpr(DecafParser.NonCalcExprContext ctx) {
|
||||
String operator;
|
||||
if(ctx.nonCalcOperator().LogicalOpertor() != null) {
|
||||
if (ctx.nonCalcOperator().LogicalOpertor() != null) {
|
||||
operator = ctx.nonCalcOperator().LogicalOpertor().getText();
|
||||
} else {
|
||||
operator = ctx.nonCalcOperator().ComparisonOperator().getText();
|
||||
@@ -369,10 +373,10 @@ public class ASTGenerator extends DecafBaseVisitor<Node> {
|
||||
List<SubReceiver> receivers = new ArrayList<>();
|
||||
List<ReceivingMethod> receivingMethods = new ArrayList<>();
|
||||
String fieldName = ctx.Identifier().getText();
|
||||
for(DecafParser.SubReceiverContext subReceiver : ctx.subReceiver()) {
|
||||
for (DecafParser.SubReceiverContext subReceiver : ctx.subReceiver()) {
|
||||
receivers.add((SubReceiver) visit(subReceiver));
|
||||
}
|
||||
for(DecafParser.ReceivingMethodContext receivingMethod: ctx.receivingMethod()) {
|
||||
for (DecafParser.ReceivingMethodContext receivingMethod : ctx.receivingMethod()) {
|
||||
receivingMethods.add((ReceivingMethod) visit(receivingMethod));
|
||||
}
|
||||
return new InstVarExpression(receivers, receivingMethods, fieldName);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,85 +1,83 @@
|
||||
T__0=1
|
||||
T__1=2
|
||||
BooleanValue=3
|
||||
NullValue=4
|
||||
AccessModifierPublic=5
|
||||
MainMethodDecl=6
|
||||
Void=7
|
||||
Int=8
|
||||
Boolean=9
|
||||
Char=10
|
||||
DotOperator=11
|
||||
LineOperator=12
|
||||
ComparisonOperator=13
|
||||
LogicalOpertor=14
|
||||
Assign=15
|
||||
Minus=16
|
||||
Plus=17
|
||||
Multipilkation=18
|
||||
Division=19
|
||||
Modulo=20
|
||||
Greater=21
|
||||
Less=22
|
||||
GreaterEqual=23
|
||||
LessEqual=24
|
||||
Equal=25
|
||||
NotEqual=26
|
||||
Not=27
|
||||
And=28
|
||||
Or=29
|
||||
Dot=30
|
||||
OpenRoundBracket=31
|
||||
ClosedRoundBracket=32
|
||||
OpenCurlyBracket=33
|
||||
ClosedCurlyBracket=34
|
||||
Semicolon=35
|
||||
Comma=36
|
||||
Class=37
|
||||
This=38
|
||||
While=39
|
||||
If=40
|
||||
Else=41
|
||||
Return=42
|
||||
New=43
|
||||
IntValue=44
|
||||
CharValue=45
|
||||
Identifier=46
|
||||
WS=47
|
||||
'print('=1
|
||||
');'=2
|
||||
'null'=4
|
||||
'public'=5
|
||||
'public static void main(String[] args)'=6
|
||||
'void'=7
|
||||
'int'=8
|
||||
'boolean'=9
|
||||
'char'=10
|
||||
'='=15
|
||||
'-'=16
|
||||
'+'=17
|
||||
'*'=18
|
||||
'/'=19
|
||||
'%'=20
|
||||
'>'=21
|
||||
'<'=22
|
||||
'>='=23
|
||||
'<='=24
|
||||
'=='=25
|
||||
'!='=26
|
||||
'!'=27
|
||||
'&&'=28
|
||||
'||'=29
|
||||
'.'=30
|
||||
'('=31
|
||||
')'=32
|
||||
'{'=33
|
||||
'}'=34
|
||||
';'=35
|
||||
','=36
|
||||
'class'=37
|
||||
'this'=38
|
||||
'while'=39
|
||||
'if'=40
|
||||
'else'=41
|
||||
'return'=42
|
||||
'new'=43
|
||||
BooleanValue=2
|
||||
NullValue=3
|
||||
AccessModifierPublic=4
|
||||
MainMethodDecl=5
|
||||
Void=6
|
||||
Int=7
|
||||
Boolean=8
|
||||
Char=9
|
||||
DotOperator=10
|
||||
LineOperator=11
|
||||
ComparisonOperator=12
|
||||
LogicalOpertor=13
|
||||
Assign=14
|
||||
Minus=15
|
||||
Plus=16
|
||||
Multipilkation=17
|
||||
Division=18
|
||||
Modulo=19
|
||||
Greater=20
|
||||
Less=21
|
||||
GreaterEqual=22
|
||||
LessEqual=23
|
||||
Equal=24
|
||||
NotEqual=25
|
||||
Not=26
|
||||
And=27
|
||||
Or=28
|
||||
Dot=29
|
||||
OpenRoundBracket=30
|
||||
ClosedRoundBracket=31
|
||||
OpenCurlyBracket=32
|
||||
ClosedCurlyBracket=33
|
||||
Semicolon=34
|
||||
Comma=35
|
||||
Class=36
|
||||
This=37
|
||||
While=38
|
||||
If=39
|
||||
Else=40
|
||||
Return=41
|
||||
New=42
|
||||
IntValue=43
|
||||
CharValue=44
|
||||
Identifier=45
|
||||
WS=46
|
||||
'print'=1
|
||||
'null'=3
|
||||
'public'=4
|
||||
'public static void main(String[] args)'=5
|
||||
'void'=6
|
||||
'int'=7
|
||||
'boolean'=8
|
||||
'char'=9
|
||||
'='=14
|
||||
'-'=15
|
||||
'+'=16
|
||||
'*'=17
|
||||
'/'=18
|
||||
'%'=19
|
||||
'>'=20
|
||||
'<'=21
|
||||
'>='=22
|
||||
'<='=23
|
||||
'=='=24
|
||||
'!='=25
|
||||
'!'=26
|
||||
'&&'=27
|
||||
'||'=28
|
||||
'.'=29
|
||||
'('=30
|
||||
')'=31
|
||||
'{'=32
|
||||
'}'=33
|
||||
';'=34
|
||||
','=35
|
||||
'class'=36
|
||||
'this'=37
|
||||
'while'=38
|
||||
'if'=39
|
||||
'else'=40
|
||||
'return'=41
|
||||
'new'=42
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -17,14 +17,14 @@ public class DecafLexer extends Lexer {
|
||||
protected static final PredictionContextCache _sharedContextCache =
|
||||
new PredictionContextCache();
|
||||
public static final int
|
||||
T__0=1, T__1=2, BooleanValue=3, NullValue=4, AccessModifierPublic=5, MainMethodDecl=6,
|
||||
Void=7, Int=8, Boolean=9, Char=10, DotOperator=11, LineOperator=12, ComparisonOperator=13,
|
||||
LogicalOpertor=14, Assign=15, Minus=16, Plus=17, Multipilkation=18, Division=19,
|
||||
Modulo=20, Greater=21, Less=22, GreaterEqual=23, LessEqual=24, Equal=25,
|
||||
NotEqual=26, Not=27, And=28, Or=29, Dot=30, OpenRoundBracket=31, ClosedRoundBracket=32,
|
||||
OpenCurlyBracket=33, ClosedCurlyBracket=34, Semicolon=35, Comma=36, Class=37,
|
||||
This=38, While=39, If=40, Else=41, Return=42, New=43, IntValue=44, CharValue=45,
|
||||
Identifier=46, WS=47;
|
||||
T__0=1, BooleanValue=2, NullValue=3, AccessModifierPublic=4, MainMethodDecl=5,
|
||||
Void=6, Int=7, Boolean=8, Char=9, DotOperator=10, LineOperator=11, ComparisonOperator=12,
|
||||
LogicalOpertor=13, Assign=14, Minus=15, Plus=16, Multipilkation=17, Division=18,
|
||||
Modulo=19, Greater=20, Less=21, GreaterEqual=22, LessEqual=23, Equal=24,
|
||||
NotEqual=25, Not=26, And=27, Or=28, Dot=29, OpenRoundBracket=30, ClosedRoundBracket=31,
|
||||
OpenCurlyBracket=32, ClosedCurlyBracket=33, Semicolon=34, Comma=35, Class=36,
|
||||
This=37, While=38, If=39, Else=40, Return=41, New=42, IntValue=43, CharValue=44,
|
||||
Identifier=45, WS=46;
|
||||
public static String[] channelNames = {
|
||||
"DEFAULT_TOKEN_CHANNEL", "HIDDEN"
|
||||
};
|
||||
@@ -35,11 +35,11 @@ public class DecafLexer extends Lexer {
|
||||
|
||||
private static String[] makeRuleNames() {
|
||||
return new String[] {
|
||||
"T__0", "T__1", "BooleanValue", "NullValue", "AccessModifierPublic",
|
||||
"MainMethodDecl", "Void", "Int", "Boolean", "Char", "DotOperator", "LineOperator",
|
||||
"ComparisonOperator", "LogicalOpertor", "Assign", "Minus", "Plus", "Multipilkation",
|
||||
"Division", "Modulo", "Greater", "Less", "GreaterEqual", "LessEqual",
|
||||
"Equal", "NotEqual", "Not", "And", "Or", "Dot", "OpenRoundBracket", "ClosedRoundBracket",
|
||||
"T__0", "BooleanValue", "NullValue", "AccessModifierPublic", "MainMethodDecl",
|
||||
"Void", "Int", "Boolean", "Char", "DotOperator", "LineOperator", "ComparisonOperator",
|
||||
"LogicalOpertor", "Assign", "Minus", "Plus", "Multipilkation", "Division",
|
||||
"Modulo", "Greater", "Less", "GreaterEqual", "LessEqual", "Equal", "NotEqual",
|
||||
"Not", "And", "Or", "Dot", "OpenRoundBracket", "ClosedRoundBracket",
|
||||
"OpenCurlyBracket", "ClosedCurlyBracket", "Semicolon", "Comma", "Class",
|
||||
"This", "While", "If", "Else", "Return", "New", "IntValue", "CharValue",
|
||||
"Alpabetic", "Numeric", "ValidIdentSymbols", "Identifier", "WS"
|
||||
@@ -49,7 +49,7 @@ public class DecafLexer extends Lexer {
|
||||
|
||||
private static String[] makeLiteralNames() {
|
||||
return new String[] {
|
||||
null, "'print('", "');'", null, "'null'", "'public'", "'public static void main(String[] args)'",
|
||||
null, "'print'", null, "'null'", "'public'", "'public static void main(String[] args)'",
|
||||
"'void'", "'int'", "'boolean'", "'char'", null, null, null, null, "'='",
|
||||
"'-'", "'+'", "'*'", "'/'", "'%'", "'>'", "'<'", "'>='", "'<='", "'=='",
|
||||
"'!='", "'!'", "'&&'", "'||'", "'.'", "'('", "')'", "'{'", "'}'", "';'",
|
||||
@@ -60,11 +60,11 @@ public class DecafLexer extends Lexer {
|
||||
private static final String[] _LITERAL_NAMES = makeLiteralNames();
|
||||
private static String[] makeSymbolicNames() {
|
||||
return new String[] {
|
||||
null, null, null, "BooleanValue", "NullValue", "AccessModifierPublic",
|
||||
"MainMethodDecl", "Void", "Int", "Boolean", "Char", "DotOperator", "LineOperator",
|
||||
"ComparisonOperator", "LogicalOpertor", "Assign", "Minus", "Plus", "Multipilkation",
|
||||
"Division", "Modulo", "Greater", "Less", "GreaterEqual", "LessEqual",
|
||||
"Equal", "NotEqual", "Not", "And", "Or", "Dot", "OpenRoundBracket", "ClosedRoundBracket",
|
||||
null, null, "BooleanValue", "NullValue", "AccessModifierPublic", "MainMethodDecl",
|
||||
"Void", "Int", "Boolean", "Char", "DotOperator", "LineOperator", "ComparisonOperator",
|
||||
"LogicalOpertor", "Assign", "Minus", "Plus", "Multipilkation", "Division",
|
||||
"Modulo", "Greater", "Less", "GreaterEqual", "LessEqual", "Equal", "NotEqual",
|
||||
"Not", "And", "Or", "Dot", "OpenRoundBracket", "ClosedRoundBracket",
|
||||
"OpenCurlyBracket", "ClosedCurlyBracket", "Semicolon", "Comma", "Class",
|
||||
"This", "While", "If", "Else", "Return", "New", "IntValue", "CharValue",
|
||||
"Identifier", "WS"
|
||||
@@ -129,7 +129,7 @@ public class DecafLexer extends Lexer {
|
||||
public ATN getATN() { return _ATN; }
|
||||
|
||||
public static final String _serializedATN =
|
||||
"\u0004\u0000/\u0153\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002\u0001"+
|
||||
"\u0004\u0000.\u014d\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002\u0001"+
|
||||
"\u0007\u0001\u0002\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004"+
|
||||
"\u0007\u0004\u0002\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002\u0007"+
|
||||
"\u0007\u0007\u0002\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0002\u000b"+
|
||||
@@ -143,46 +143,46 @@ public class DecafLexer extends Lexer {
|
||||
"!\u0002\"\u0007\"\u0002#\u0007#\u0002$\u0007$\u0002%\u0007%\u0002&\u0007"+
|
||||
"&\u0002\'\u0007\'\u0002(\u0007(\u0002)\u0007)\u0002*\u0007*\u0002+\u0007"+
|
||||
"+\u0002,\u0007,\u0002-\u0007-\u0002.\u0007.\u0002/\u0007/\u00020\u0007"+
|
||||
"0\u00021\u00071\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001"+
|
||||
"\u0000\u0001\u0000\u0001\u0000\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
|
||||
"\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001"+
|
||||
"\u0002\u0001\u0002\u0001\u0002\u0003\u0002y\b\u0002\u0001\u0003\u0001"+
|
||||
"\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0004\u0001\u0004\u0001"+
|
||||
"\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0005\u0001"+
|
||||
"\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001"+
|
||||
"\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001"+
|
||||
"\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001"+
|
||||
"\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001"+
|
||||
"\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001"+
|
||||
"\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005\u0001"+
|
||||
"\u0005\u0001\u0005\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001"+
|
||||
"\u0006\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\b\u0001\b"+
|
||||
"\u0001\b\u0001\b\u0001\b\u0001\b\u0001\b\u0001\b\u0001\t\u0001\t\u0001"+
|
||||
"\t\u0001\t\u0001\t\u0001\n\u0001\n\u0001\n\u0003\n\u00c7\b\n\u0001\u000b"+
|
||||
"\u0001\u000b\u0003\u000b\u00cb\b\u000b\u0001\f\u0001\f\u0001\f\u0001\f"+
|
||||
"\u0001\f\u0001\f\u0003\f\u00d3\b\f\u0001\r\u0001\r\u0003\r\u00d7\b\r\u0001"+
|
||||
"\u000e\u0001\u000e\u0001\u000f\u0001\u000f\u0001\u0010\u0001\u0010\u0001"+
|
||||
"\u0011\u0001\u0011\u0001\u0012\u0001\u0012\u0001\u0013\u0001\u0013\u0001"+
|
||||
"\u0014\u0001\u0014\u0001\u0015\u0001\u0015\u0001\u0016\u0001\u0016\u0001"+
|
||||
"\u0016\u0001\u0017\u0001\u0017\u0001\u0017\u0001\u0018\u0001\u0018\u0001"+
|
||||
"\u0018\u0001\u0019\u0001\u0019\u0001\u0019\u0001\u001a\u0001\u001a\u0001"+
|
||||
"\u001b\u0001\u001b\u0001\u001b\u0001\u001c\u0001\u001c\u0001\u001c\u0001"+
|
||||
"\u001d\u0001\u001d\u0001\u001e\u0001\u001e\u0001\u001f\u0001\u001f\u0001"+
|
||||
" \u0001 \u0001!\u0001!\u0001\"\u0001\"\u0001#\u0001#\u0001$\u0001$\u0001"+
|
||||
"$\u0001$\u0001$\u0001$\u0001%\u0001%\u0001%\u0001%\u0001%\u0001&\u0001"+
|
||||
"&\u0001&\u0001&\u0001&\u0001&\u0001\'\u0001\'\u0001\'\u0001(\u0001(\u0001"+
|
||||
"(\u0001(\u0001(\u0001)\u0001)\u0001)\u0001)\u0001)\u0001)\u0001)\u0001"+
|
||||
"*\u0001*\u0001*\u0001*\u0001+\u0005+\u0130\b+\n+\f+\u0133\t+\u0001+\u0004"+
|
||||
"+\u0136\b+\u000b+\f+\u0137\u0001,\u0001,\u0003,\u013c\b,\u0001,\u0001"+
|
||||
",\u0001-\u0001-\u0001.\u0001.\u0001/\u0001/\u0001/\u0003/\u0147\b/\u0001"+
|
||||
"0\u00010\u00050\u014b\b0\n0\f0\u014e\t0\u00011\u00011\u00011\u00011\u0000"+
|
||||
"\u00002\u0001\u0001\u0003\u0002\u0005\u0003\u0007\u0004\t\u0005\u000b"+
|
||||
"\u0006\r\u0007\u000f\b\u0011\t\u0013\n\u0015\u000b\u0017\f\u0019\r\u001b"+
|
||||
"\u000e\u001d\u000f\u001f\u0010!\u0011#\u0012%\u0013\'\u0014)\u0015+\u0016"+
|
||||
"-\u0017/\u00181\u00193\u001a5\u001b7\u001c9\u001d;\u001e=\u001f? A!C\""+
|
||||
"E#G$I%K&M\'O(Q)S*U+W,Y-[\u0000]\u0000_\u0000a.c/\u0001\u0000\u0006\u0002"+
|
||||
"\u0000++--\u0001\u000009\u0002\u0000\n\n\r\r\u0002\u0000AZaz\u0002\u0000"+
|
||||
"$$__\u0003\u0000\t\n\r\r \u015f\u0000\u0001\u0001\u0000\u0000\u0000\u0000"+
|
||||
"0\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000\u0001\u0000"+
|
||||
"\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001"+
|
||||
"\u0001\u0001\u0001\u0001\u0001\u0001\u0003\u0001s\b\u0001\u0001\u0002"+
|
||||
"\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0002\u0001\u0003\u0001\u0003"+
|
||||
"\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0003\u0001\u0004"+
|
||||
"\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004"+
|
||||
"\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004"+
|
||||
"\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004"+
|
||||
"\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004"+
|
||||
"\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004"+
|
||||
"\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004"+
|
||||
"\u0001\u0004\u0001\u0004\u0001\u0005\u0001\u0005\u0001\u0005\u0001\u0005"+
|
||||
"\u0001\u0005\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0007"+
|
||||
"\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007\u0001\u0007"+
|
||||
"\u0001\u0007\u0001\b\u0001\b\u0001\b\u0001\b\u0001\b\u0001\t\u0001\t\u0001"+
|
||||
"\t\u0003\t\u00c1\b\t\u0001\n\u0001\n\u0003\n\u00c5\b\n\u0001\u000b\u0001"+
|
||||
"\u000b\u0001\u000b\u0001\u000b\u0001\u000b\u0001\u000b\u0003\u000b\u00cd"+
|
||||
"\b\u000b\u0001\f\u0001\f\u0003\f\u00d1\b\f\u0001\r\u0001\r\u0001\u000e"+
|
||||
"\u0001\u000e\u0001\u000f\u0001\u000f\u0001\u0010\u0001\u0010\u0001\u0011"+
|
||||
"\u0001\u0011\u0001\u0012\u0001\u0012\u0001\u0013\u0001\u0013\u0001\u0014"+
|
||||
"\u0001\u0014\u0001\u0015\u0001\u0015\u0001\u0015\u0001\u0016\u0001\u0016"+
|
||||
"\u0001\u0016\u0001\u0017\u0001\u0017\u0001\u0017\u0001\u0018\u0001\u0018"+
|
||||
"\u0001\u0018\u0001\u0019\u0001\u0019\u0001\u001a\u0001\u001a\u0001\u001a"+
|
||||
"\u0001\u001b\u0001\u001b\u0001\u001b\u0001\u001c\u0001\u001c\u0001\u001d"+
|
||||
"\u0001\u001d\u0001\u001e\u0001\u001e\u0001\u001f\u0001\u001f\u0001 \u0001"+
|
||||
" \u0001!\u0001!\u0001\"\u0001\"\u0001#\u0001#\u0001#\u0001#\u0001#\u0001"+
|
||||
"#\u0001$\u0001$\u0001$\u0001$\u0001$\u0001%\u0001%\u0001%\u0001%\u0001"+
|
||||
"%\u0001%\u0001&\u0001&\u0001&\u0001\'\u0001\'\u0001\'\u0001\'\u0001\'"+
|
||||
"\u0001(\u0001(\u0001(\u0001(\u0001(\u0001(\u0001(\u0001)\u0001)\u0001"+
|
||||
")\u0001)\u0001*\u0005*\u012a\b*\n*\f*\u012d\t*\u0001*\u0004*\u0130\b*"+
|
||||
"\u000b*\f*\u0131\u0001+\u0001+\u0003+\u0136\b+\u0001+\u0001+\u0001,\u0001"+
|
||||
",\u0001-\u0001-\u0001.\u0001.\u0001.\u0003.\u0141\b.\u0001/\u0001/\u0005"+
|
||||
"/\u0145\b/\n/\f/\u0148\t/\u00010\u00010\u00010\u00010\u0000\u00001\u0001"+
|
||||
"\u0001\u0003\u0002\u0005\u0003\u0007\u0004\t\u0005\u000b\u0006\r\u0007"+
|
||||
"\u000f\b\u0011\t\u0013\n\u0015\u000b\u0017\f\u0019\r\u001b\u000e\u001d"+
|
||||
"\u000f\u001f\u0010!\u0011#\u0012%\u0013\'\u0014)\u0015+\u0016-\u0017/"+
|
||||
"\u00181\u00193\u001a5\u001b7\u001c9\u001d;\u001e=\u001f? A!C\"E#G$I%K"+
|
||||
"&M\'O(Q)S*U+W,Y\u0000[\u0000]\u0000_-a.\u0001\u0000\u0006\u0002\u0000"+
|
||||
"++--\u0001\u000009\u0002\u0000\n\n\r\r\u0002\u0000AZaz\u0002\u0000$$_"+
|
||||
"_\u0003\u0000\t\n\r\r \u0159\u0000\u0001\u0001\u0000\u0000\u0000\u0000"+
|
||||
"\u0003\u0001\u0000\u0000\u0000\u0000\u0005\u0001\u0000\u0000\u0000\u0000"+
|
||||
"\u0007\u0001\u0000\u0000\u0000\u0000\t\u0001\u0000\u0000\u0000\u0000\u000b"+
|
||||
"\u0001\u0000\u0000\u0000\u0000\r\u0001\u0000\u0000\u0000\u0000\u000f\u0001"+
|
||||
@@ -202,141 +202,138 @@ public class DecafLexer extends Lexer {
|
||||
"\u0001\u0000\u0000\u0000\u0000K\u0001\u0000\u0000\u0000\u0000M\u0001\u0000"+
|
||||
"\u0000\u0000\u0000O\u0001\u0000\u0000\u0000\u0000Q\u0001\u0000\u0000\u0000"+
|
||||
"\u0000S\u0001\u0000\u0000\u0000\u0000U\u0001\u0000\u0000\u0000\u0000W"+
|
||||
"\u0001\u0000\u0000\u0000\u0000Y\u0001\u0000\u0000\u0000\u0000a\u0001\u0000"+
|
||||
"\u0000\u0000\u0000c\u0001\u0000\u0000\u0000\u0001e\u0001\u0000\u0000\u0000"+
|
||||
"\u0003l\u0001\u0000\u0000\u0000\u0005x\u0001\u0000\u0000\u0000\u0007z"+
|
||||
"\u0001\u0000\u0000\u0000\t\u007f\u0001\u0000\u0000\u0000\u000b\u0086\u0001"+
|
||||
"\u0000\u0000\u0000\r\u00ad\u0001\u0000\u0000\u0000\u000f\u00b2\u0001\u0000"+
|
||||
"\u0000\u0000\u0011\u00b6\u0001\u0000\u0000\u0000\u0013\u00be\u0001\u0000"+
|
||||
"\u0000\u0000\u0015\u00c6\u0001\u0000\u0000\u0000\u0017\u00ca\u0001\u0000"+
|
||||
"\u0000\u0000\u0019\u00d2\u0001\u0000\u0000\u0000\u001b\u00d6\u0001\u0000"+
|
||||
"\u0000\u0000\u001d\u00d8\u0001\u0000\u0000\u0000\u001f\u00da\u0001\u0000"+
|
||||
"\u0000\u0000!\u00dc\u0001\u0000\u0000\u0000#\u00de\u0001\u0000\u0000\u0000"+
|
||||
"%\u00e0\u0001\u0000\u0000\u0000\'\u00e2\u0001\u0000\u0000\u0000)\u00e4"+
|
||||
"\u0001\u0000\u0000\u0000+\u00e6\u0001\u0000\u0000\u0000-\u00e8\u0001\u0000"+
|
||||
"\u0000\u0000/\u00eb\u0001\u0000\u0000\u00001\u00ee\u0001\u0000\u0000\u0000"+
|
||||
"3\u00f1\u0001\u0000\u0000\u00005\u00f4\u0001\u0000\u0000\u00007\u00f6"+
|
||||
"\u0001\u0000\u0000\u00009\u00f9\u0001\u0000\u0000\u0000;\u00fc\u0001\u0000"+
|
||||
"\u0000\u0000=\u00fe\u0001\u0000\u0000\u0000?\u0100\u0001\u0000\u0000\u0000"+
|
||||
"A\u0102\u0001\u0000\u0000\u0000C\u0104\u0001\u0000\u0000\u0000E\u0106"+
|
||||
"\u0001\u0000\u0000\u0000G\u0108\u0001\u0000\u0000\u0000I\u010a\u0001\u0000"+
|
||||
"\u0000\u0000K\u0110\u0001\u0000\u0000\u0000M\u0115\u0001\u0000\u0000\u0000"+
|
||||
"O\u011b\u0001\u0000\u0000\u0000Q\u011e\u0001\u0000\u0000\u0000S\u0123"+
|
||||
"\u0001\u0000\u0000\u0000U\u012a\u0001\u0000\u0000\u0000W\u0131\u0001\u0000"+
|
||||
"\u0000\u0000Y\u0139\u0001\u0000\u0000\u0000[\u013f\u0001\u0000\u0000\u0000"+
|
||||
"]\u0141\u0001\u0000\u0000\u0000_\u0146\u0001\u0000\u0000\u0000a\u0148"+
|
||||
"\u0001\u0000\u0000\u0000c\u014f\u0001\u0000\u0000\u0000ef\u0005p\u0000"+
|
||||
"\u0000fg\u0005r\u0000\u0000gh\u0005i\u0000\u0000hi\u0005n\u0000\u0000"+
|
||||
"ij\u0005t\u0000\u0000jk\u0005(\u0000\u0000k\u0002\u0001\u0000\u0000\u0000"+
|
||||
"lm\u0005)\u0000\u0000mn\u0005;\u0000\u0000n\u0004\u0001\u0000\u0000\u0000"+
|
||||
"op\u0005t\u0000\u0000pq\u0005r\u0000\u0000qr\u0005u\u0000\u0000ry\u0005"+
|
||||
"e\u0000\u0000st\u0005f\u0000\u0000tu\u0005a\u0000\u0000uv\u0005l\u0000"+
|
||||
"\u0000vw\u0005s\u0000\u0000wy\u0005e\u0000\u0000xo\u0001\u0000\u0000\u0000"+
|
||||
"xs\u0001\u0000\u0000\u0000y\u0006\u0001\u0000\u0000\u0000z{\u0005n\u0000"+
|
||||
"\u0000{|\u0005u\u0000\u0000|}\u0005l\u0000\u0000}~\u0005l\u0000\u0000"+
|
||||
"~\b\u0001\u0000\u0000\u0000\u007f\u0080\u0005p\u0000\u0000\u0080\u0081"+
|
||||
"\u0005u\u0000\u0000\u0081\u0082\u0005b\u0000\u0000\u0082\u0083\u0005l"+
|
||||
"\u0000\u0000\u0083\u0084\u0005i\u0000\u0000\u0084\u0085\u0005c\u0000\u0000"+
|
||||
"\u0085\n\u0001\u0000\u0000\u0000\u0086\u0087\u0005p\u0000\u0000\u0087"+
|
||||
"\u0088\u0005u\u0000\u0000\u0088\u0089\u0005b\u0000\u0000\u0089\u008a\u0005"+
|
||||
"l\u0000\u0000\u008a\u008b\u0005i\u0000\u0000\u008b\u008c\u0005c\u0000"+
|
||||
"\u0000\u008c\u008d\u0005 \u0000\u0000\u008d\u008e\u0005s\u0000\u0000\u008e"+
|
||||
"\u008f\u0005t\u0000\u0000\u008f\u0090\u0005a\u0000\u0000\u0090\u0091\u0005"+
|
||||
"t\u0000\u0000\u0091\u0092\u0005i\u0000\u0000\u0092\u0093\u0005c\u0000"+
|
||||
"\u0000\u0093\u0094\u0005 \u0000\u0000\u0094\u0095\u0005v\u0000\u0000\u0095"+
|
||||
"\u0096\u0005o\u0000\u0000\u0096\u0097\u0005i\u0000\u0000\u0097\u0098\u0005"+
|
||||
"d\u0000\u0000\u0098\u0099\u0005 \u0000\u0000\u0099\u009a\u0005m\u0000"+
|
||||
"\u0000\u009a\u009b\u0005a\u0000\u0000\u009b\u009c\u0005i\u0000\u0000\u009c"+
|
||||
"\u009d\u0005n\u0000\u0000\u009d\u009e\u0005(\u0000\u0000\u009e\u009f\u0005"+
|
||||
"S\u0000\u0000\u009f\u00a0\u0005t\u0000\u0000\u00a0\u00a1\u0005r\u0000"+
|
||||
"\u0000\u00a1\u00a2\u0005i\u0000\u0000\u00a2\u00a3\u0005n\u0000\u0000\u00a3"+
|
||||
"\u00a4\u0005g\u0000\u0000\u00a4\u00a5\u0005[\u0000\u0000\u00a5\u00a6\u0005"+
|
||||
"]\u0000\u0000\u00a6\u00a7\u0005 \u0000\u0000\u00a7\u00a8\u0005a\u0000"+
|
||||
"\u0000\u00a8\u00a9\u0005r\u0000\u0000\u00a9\u00aa\u0005g\u0000\u0000\u00aa"+
|
||||
"\u00ab\u0005s\u0000\u0000\u00ab\u00ac\u0005)\u0000\u0000\u00ac\f\u0001"+
|
||||
"\u0000\u0000\u0000\u00ad\u00ae\u0005v\u0000\u0000\u00ae\u00af\u0005o\u0000"+
|
||||
"\u0000\u00af\u00b0\u0005i\u0000\u0000\u00b0\u00b1\u0005d\u0000\u0000\u00b1"+
|
||||
"\u000e\u0001\u0000\u0000\u0000\u00b2\u00b3\u0005i\u0000\u0000\u00b3\u00b4"+
|
||||
"\u0005n\u0000\u0000\u00b4\u00b5\u0005t\u0000\u0000\u00b5\u0010\u0001\u0000"+
|
||||
"\u0000\u0000\u00b6\u00b7\u0005b\u0000\u0000\u00b7\u00b8\u0005o\u0000\u0000"+
|
||||
"\u00b8\u00b9\u0005o\u0000\u0000\u00b9\u00ba\u0005l\u0000\u0000\u00ba\u00bb"+
|
||||
"\u0005e\u0000\u0000\u00bb\u00bc\u0005a\u0000\u0000\u00bc\u00bd\u0005n"+
|
||||
"\u0000\u0000\u00bd\u0012\u0001\u0000\u0000\u0000\u00be\u00bf\u0005c\u0000"+
|
||||
"\u0000\u00bf\u00c0\u0005h\u0000\u0000\u00c0\u00c1\u0005a\u0000\u0000\u00c1"+
|
||||
"\u00c2\u0005r\u0000\u0000\u00c2\u0014\u0001\u0000\u0000\u0000\u00c3\u00c7"+
|
||||
"\u0003#\u0011\u0000\u00c4\u00c7\u0003%\u0012\u0000\u00c5\u00c7\u0003\'"+
|
||||
"\u0013\u0000\u00c6\u00c3\u0001\u0000\u0000\u0000\u00c6\u00c4\u0001\u0000"+
|
||||
"\u0000\u0000\u00c6\u00c5\u0001\u0000\u0000\u0000\u00c7\u0016\u0001\u0000"+
|
||||
"\u0000\u0000\u00c8\u00cb\u0003!\u0010\u0000\u00c9\u00cb\u0003\u001f\u000f"+
|
||||
"\u0000\u00ca\u00c8\u0001\u0000\u0000\u0000\u00ca\u00c9\u0001\u0000\u0000"+
|
||||
"\u0000\u00cb\u0018\u0001\u0000\u0000\u0000\u00cc\u00d3\u0003)\u0014\u0000"+
|
||||
"\u00cd\u00d3\u0003+\u0015\u0000\u00ce\u00d3\u0003-\u0016\u0000\u00cf\u00d3"+
|
||||
"\u0003/\u0017\u0000\u00d0\u00d3\u00031\u0018\u0000\u00d1\u00d3\u00033"+
|
||||
"\u0019\u0000\u00d2\u00cc\u0001\u0000\u0000\u0000\u00d2\u00cd\u0001\u0000"+
|
||||
"\u0000\u0000\u00d2\u00ce\u0001\u0000\u0000\u0000\u00d2\u00cf\u0001\u0000"+
|
||||
"\u0000\u0000\u00d2\u00d0\u0001\u0000\u0000\u0000\u00d2\u00d1\u0001\u0000"+
|
||||
"\u0000\u0000\u00d3\u001a\u0001\u0000\u0000\u0000\u00d4\u00d7\u00037\u001b"+
|
||||
"\u0000\u00d5\u00d7\u00039\u001c\u0000\u00d6\u00d4\u0001\u0000\u0000\u0000"+
|
||||
"\u00d6\u00d5\u0001\u0000\u0000\u0000\u00d7\u001c\u0001\u0000\u0000\u0000"+
|
||||
"\u00d8\u00d9\u0005=\u0000\u0000\u00d9\u001e\u0001\u0000\u0000\u0000\u00da"+
|
||||
"\u00db\u0005-\u0000\u0000\u00db \u0001\u0000\u0000\u0000\u00dc\u00dd\u0005"+
|
||||
"+\u0000\u0000\u00dd\"\u0001\u0000\u0000\u0000\u00de\u00df\u0005*\u0000"+
|
||||
"\u0000\u00df$\u0001\u0000\u0000\u0000\u00e0\u00e1\u0005/\u0000\u0000\u00e1"+
|
||||
"&\u0001\u0000\u0000\u0000\u00e2\u00e3\u0005%\u0000\u0000\u00e3(\u0001"+
|
||||
"\u0000\u0000\u0000\u00e4\u00e5\u0005>\u0000\u0000\u00e5*\u0001\u0000\u0000"+
|
||||
"\u0000\u00e6\u00e7\u0005<\u0000\u0000\u00e7,\u0001\u0000\u0000\u0000\u00e8"+
|
||||
"\u00e9\u0005>\u0000\u0000\u00e9\u00ea\u0005=\u0000\u0000\u00ea.\u0001"+
|
||||
"\u0000\u0000\u0000\u00eb\u00ec\u0005<\u0000\u0000\u00ec\u00ed\u0005=\u0000"+
|
||||
"\u0000\u00ed0\u0001\u0000\u0000\u0000\u00ee\u00ef\u0005=\u0000\u0000\u00ef"+
|
||||
"\u00f0\u0005=\u0000\u0000\u00f02\u0001\u0000\u0000\u0000\u00f1\u00f2\u0005"+
|
||||
"!\u0000\u0000\u00f2\u00f3\u0005=\u0000\u0000\u00f34\u0001\u0000\u0000"+
|
||||
"\u0000\u00f4\u00f5\u0005!\u0000\u0000\u00f56\u0001\u0000\u0000\u0000\u00f6"+
|
||||
"\u00f7\u0005&\u0000\u0000\u00f7\u00f8\u0005&\u0000\u0000\u00f88\u0001"+
|
||||
"\u0000\u0000\u0000\u00f9\u00fa\u0005|\u0000\u0000\u00fa\u00fb\u0005|\u0000"+
|
||||
"\u0000\u00fb:\u0001\u0000\u0000\u0000\u00fc\u00fd\u0005.\u0000\u0000\u00fd"+
|
||||
"<\u0001\u0000\u0000\u0000\u00fe\u00ff\u0005(\u0000\u0000\u00ff>\u0001"+
|
||||
"\u0000\u0000\u0000\u0100\u0101\u0005)\u0000\u0000\u0101@\u0001\u0000\u0000"+
|
||||
"\u0000\u0102\u0103\u0005{\u0000\u0000\u0103B\u0001\u0000\u0000\u0000\u0104"+
|
||||
"\u0105\u0005}\u0000\u0000\u0105D\u0001\u0000\u0000\u0000\u0106\u0107\u0005"+
|
||||
";\u0000\u0000\u0107F\u0001\u0000\u0000\u0000\u0108\u0109\u0005,\u0000"+
|
||||
"\u0000\u0109H\u0001\u0000\u0000\u0000\u010a\u010b\u0005c\u0000\u0000\u010b"+
|
||||
"\u010c\u0005l\u0000\u0000\u010c\u010d\u0005a\u0000\u0000\u010d\u010e\u0005"+
|
||||
"s\u0000\u0000\u010e\u010f\u0005s\u0000\u0000\u010fJ\u0001\u0000\u0000"+
|
||||
"\u0000\u0110\u0111\u0005t\u0000\u0000\u0111\u0112\u0005h\u0000\u0000\u0112"+
|
||||
"\u0113\u0005i\u0000\u0000\u0113\u0114\u0005s\u0000\u0000\u0114L\u0001"+
|
||||
"\u0000\u0000\u0000\u0115\u0116\u0005w\u0000\u0000\u0116\u0117\u0005h\u0000"+
|
||||
"\u0000\u0117\u0118\u0005i\u0000\u0000\u0118\u0119\u0005l\u0000\u0000\u0119"+
|
||||
"\u011a\u0005e\u0000\u0000\u011aN\u0001\u0000\u0000\u0000\u011b\u011c\u0005"+
|
||||
"i\u0000\u0000\u011c\u011d\u0005f\u0000\u0000\u011dP\u0001\u0000\u0000"+
|
||||
"\u0000\u011e\u011f\u0005e\u0000\u0000\u011f\u0120\u0005l\u0000\u0000\u0120"+
|
||||
"\u0121\u0005s\u0000\u0000\u0121\u0122\u0005e\u0000\u0000\u0122R\u0001"+
|
||||
"\u0000\u0000\u0000\u0123\u0124\u0005r\u0000\u0000\u0124\u0125\u0005e\u0000"+
|
||||
"\u0000\u0125\u0126\u0005t\u0000\u0000\u0126\u0127\u0005u\u0000\u0000\u0127"+
|
||||
"\u0128\u0005r\u0000\u0000\u0128\u0129\u0005n\u0000\u0000\u0129T\u0001"+
|
||||
"\u0000\u0000\u0000\u012a\u012b\u0005n\u0000\u0000\u012b\u012c\u0005e\u0000"+
|
||||
"\u0000\u012c\u012d\u0005w\u0000\u0000\u012dV\u0001\u0000\u0000\u0000\u012e"+
|
||||
"\u0130\u0007\u0000\u0000\u0000\u012f\u012e\u0001\u0000\u0000\u0000\u0130"+
|
||||
"\u0133\u0001\u0000\u0000\u0000\u0131\u012f\u0001\u0000\u0000\u0000\u0131"+
|
||||
"\u0132\u0001\u0000\u0000\u0000\u0132\u0135\u0001\u0000\u0000\u0000\u0133"+
|
||||
"\u0131\u0001\u0000\u0000\u0000\u0134\u0136\u0007\u0001\u0000\u0000\u0135"+
|
||||
"\u0134\u0001\u0000\u0000\u0000\u0136\u0137\u0001\u0000\u0000\u0000\u0137"+
|
||||
"\u0135\u0001\u0000\u0000\u0000\u0137\u0138\u0001\u0000\u0000\u0000\u0138"+
|
||||
"X\u0001\u0000\u0000\u0000\u0139\u013b\u0005\'\u0000\u0000\u013a\u013c"+
|
||||
"\b\u0002\u0000\u0000\u013b\u013a\u0001\u0000\u0000\u0000\u013b\u013c\u0001"+
|
||||
"\u0000\u0000\u0000\u013c\u013d\u0001\u0000\u0000\u0000\u013d\u013e\u0005"+
|
||||
"\'\u0000\u0000\u013eZ\u0001\u0000\u0000\u0000\u013f\u0140\u0007\u0003"+
|
||||
"\u0000\u0000\u0140\\\u0001\u0000\u0000\u0000\u0141\u0142\u0007\u0001\u0000"+
|
||||
"\u0000\u0142^\u0001\u0000\u0000\u0000\u0143\u0147\u0003[-\u0000\u0144"+
|
||||
"\u0147\u0003].\u0000\u0145\u0147\u0007\u0004\u0000\u0000\u0146\u0143\u0001"+
|
||||
"\u0000\u0000\u0000\u0146\u0144\u0001\u0000\u0000\u0000\u0146\u0145\u0001"+
|
||||
"\u0000\u0000\u0000\u0147`\u0001\u0000\u0000\u0000\u0148\u014c\u0003[-"+
|
||||
"\u0000\u0149\u014b\u0003_/\u0000\u014a\u0149\u0001\u0000\u0000\u0000\u014b"+
|
||||
"\u014e\u0001\u0000\u0000\u0000\u014c\u014a\u0001\u0000\u0000\u0000\u014c"+
|
||||
"\u014d\u0001\u0000\u0000\u0000\u014db\u0001\u0000\u0000\u0000\u014e\u014c"+
|
||||
"\u0001\u0000\u0000\u0000\u014f\u0150\u0007\u0005\u0000\u0000\u0150\u0151"+
|
||||
"\u0001\u0000\u0000\u0000\u0151\u0152\u00061\u0000\u0000\u0152d\u0001\u0000"+
|
||||
"\u0000\u0000\u000b\u0000x\u00c6\u00ca\u00d2\u00d6\u0131\u0137\u013b\u0146"+
|
||||
"\u014c\u0001\u0006\u0000\u0000";
|
||||
"\u0001\u0000\u0000\u0000\u0000_\u0001\u0000\u0000\u0000\u0000a\u0001\u0000"+
|
||||
"\u0000\u0000\u0001c\u0001\u0000\u0000\u0000\u0003r\u0001\u0000\u0000\u0000"+
|
||||
"\u0005t\u0001\u0000\u0000\u0000\u0007y\u0001\u0000\u0000\u0000\t\u0080"+
|
||||
"\u0001\u0000\u0000\u0000\u000b\u00a7\u0001\u0000\u0000\u0000\r\u00ac\u0001"+
|
||||
"\u0000\u0000\u0000\u000f\u00b0\u0001\u0000\u0000\u0000\u0011\u00b8\u0001"+
|
||||
"\u0000\u0000\u0000\u0013\u00c0\u0001\u0000\u0000\u0000\u0015\u00c4\u0001"+
|
||||
"\u0000\u0000\u0000\u0017\u00cc\u0001\u0000\u0000\u0000\u0019\u00d0\u0001"+
|
||||
"\u0000\u0000\u0000\u001b\u00d2\u0001\u0000\u0000\u0000\u001d\u00d4\u0001"+
|
||||
"\u0000\u0000\u0000\u001f\u00d6\u0001\u0000\u0000\u0000!\u00d8\u0001\u0000"+
|
||||
"\u0000\u0000#\u00da\u0001\u0000\u0000\u0000%\u00dc\u0001\u0000\u0000\u0000"+
|
||||
"\'\u00de\u0001\u0000\u0000\u0000)\u00e0\u0001\u0000\u0000\u0000+\u00e2"+
|
||||
"\u0001\u0000\u0000\u0000-\u00e5\u0001\u0000\u0000\u0000/\u00e8\u0001\u0000"+
|
||||
"\u0000\u00001\u00eb\u0001\u0000\u0000\u00003\u00ee\u0001\u0000\u0000\u0000"+
|
||||
"5\u00f0\u0001\u0000\u0000\u00007\u00f3\u0001\u0000\u0000\u00009\u00f6"+
|
||||
"\u0001\u0000\u0000\u0000;\u00f8\u0001\u0000\u0000\u0000=\u00fa\u0001\u0000"+
|
||||
"\u0000\u0000?\u00fc\u0001\u0000\u0000\u0000A\u00fe\u0001\u0000\u0000\u0000"+
|
||||
"C\u0100\u0001\u0000\u0000\u0000E\u0102\u0001\u0000\u0000\u0000G\u0104"+
|
||||
"\u0001\u0000\u0000\u0000I\u010a\u0001\u0000\u0000\u0000K\u010f\u0001\u0000"+
|
||||
"\u0000\u0000M\u0115\u0001\u0000\u0000\u0000O\u0118\u0001\u0000\u0000\u0000"+
|
||||
"Q\u011d\u0001\u0000\u0000\u0000S\u0124\u0001\u0000\u0000\u0000U\u012b"+
|
||||
"\u0001\u0000\u0000\u0000W\u0133\u0001\u0000\u0000\u0000Y\u0139\u0001\u0000"+
|
||||
"\u0000\u0000[\u013b\u0001\u0000\u0000\u0000]\u0140\u0001\u0000\u0000\u0000"+
|
||||
"_\u0142\u0001\u0000\u0000\u0000a\u0149\u0001\u0000\u0000\u0000cd\u0005"+
|
||||
"p\u0000\u0000de\u0005r\u0000\u0000ef\u0005i\u0000\u0000fg\u0005n\u0000"+
|
||||
"\u0000gh\u0005t\u0000\u0000h\u0002\u0001\u0000\u0000\u0000ij\u0005t\u0000"+
|
||||
"\u0000jk\u0005r\u0000\u0000kl\u0005u\u0000\u0000ls\u0005e\u0000\u0000"+
|
||||
"mn\u0005f\u0000\u0000no\u0005a\u0000\u0000op\u0005l\u0000\u0000pq\u0005"+
|
||||
"s\u0000\u0000qs\u0005e\u0000\u0000ri\u0001\u0000\u0000\u0000rm\u0001\u0000"+
|
||||
"\u0000\u0000s\u0004\u0001\u0000\u0000\u0000tu\u0005n\u0000\u0000uv\u0005"+
|
||||
"u\u0000\u0000vw\u0005l\u0000\u0000wx\u0005l\u0000\u0000x\u0006\u0001\u0000"+
|
||||
"\u0000\u0000yz\u0005p\u0000\u0000z{\u0005u\u0000\u0000{|\u0005b\u0000"+
|
||||
"\u0000|}\u0005l\u0000\u0000}~\u0005i\u0000\u0000~\u007f\u0005c\u0000\u0000"+
|
||||
"\u007f\b\u0001\u0000\u0000\u0000\u0080\u0081\u0005p\u0000\u0000\u0081"+
|
||||
"\u0082\u0005u\u0000\u0000\u0082\u0083\u0005b\u0000\u0000\u0083\u0084\u0005"+
|
||||
"l\u0000\u0000\u0084\u0085\u0005i\u0000\u0000\u0085\u0086\u0005c\u0000"+
|
||||
"\u0000\u0086\u0087\u0005 \u0000\u0000\u0087\u0088\u0005s\u0000\u0000\u0088"+
|
||||
"\u0089\u0005t\u0000\u0000\u0089\u008a\u0005a\u0000\u0000\u008a\u008b\u0005"+
|
||||
"t\u0000\u0000\u008b\u008c\u0005i\u0000\u0000\u008c\u008d\u0005c\u0000"+
|
||||
"\u0000\u008d\u008e\u0005 \u0000\u0000\u008e\u008f\u0005v\u0000\u0000\u008f"+
|
||||
"\u0090\u0005o\u0000\u0000\u0090\u0091\u0005i\u0000\u0000\u0091\u0092\u0005"+
|
||||
"d\u0000\u0000\u0092\u0093\u0005 \u0000\u0000\u0093\u0094\u0005m\u0000"+
|
||||
"\u0000\u0094\u0095\u0005a\u0000\u0000\u0095\u0096\u0005i\u0000\u0000\u0096"+
|
||||
"\u0097\u0005n\u0000\u0000\u0097\u0098\u0005(\u0000\u0000\u0098\u0099\u0005"+
|
||||
"S\u0000\u0000\u0099\u009a\u0005t\u0000\u0000\u009a\u009b\u0005r\u0000"+
|
||||
"\u0000\u009b\u009c\u0005i\u0000\u0000\u009c\u009d\u0005n\u0000\u0000\u009d"+
|
||||
"\u009e\u0005g\u0000\u0000\u009e\u009f\u0005[\u0000\u0000\u009f\u00a0\u0005"+
|
||||
"]\u0000\u0000\u00a0\u00a1\u0005 \u0000\u0000\u00a1\u00a2\u0005a\u0000"+
|
||||
"\u0000\u00a2\u00a3\u0005r\u0000\u0000\u00a3\u00a4\u0005g\u0000\u0000\u00a4"+
|
||||
"\u00a5\u0005s\u0000\u0000\u00a5\u00a6\u0005)\u0000\u0000\u00a6\n\u0001"+
|
||||
"\u0000\u0000\u0000\u00a7\u00a8\u0005v\u0000\u0000\u00a8\u00a9\u0005o\u0000"+
|
||||
"\u0000\u00a9\u00aa\u0005i\u0000\u0000\u00aa\u00ab\u0005d\u0000\u0000\u00ab"+
|
||||
"\f\u0001\u0000\u0000\u0000\u00ac\u00ad\u0005i\u0000\u0000\u00ad\u00ae"+
|
||||
"\u0005n\u0000\u0000\u00ae\u00af\u0005t\u0000\u0000\u00af\u000e\u0001\u0000"+
|
||||
"\u0000\u0000\u00b0\u00b1\u0005b\u0000\u0000\u00b1\u00b2\u0005o\u0000\u0000"+
|
||||
"\u00b2\u00b3\u0005o\u0000\u0000\u00b3\u00b4\u0005l\u0000\u0000\u00b4\u00b5"+
|
||||
"\u0005e\u0000\u0000\u00b5\u00b6\u0005a\u0000\u0000\u00b6\u00b7\u0005n"+
|
||||
"\u0000\u0000\u00b7\u0010\u0001\u0000\u0000\u0000\u00b8\u00b9\u0005c\u0000"+
|
||||
"\u0000\u00b9\u00ba\u0005h\u0000\u0000\u00ba\u00bb\u0005a\u0000\u0000\u00bb"+
|
||||
"\u00bc\u0005r\u0000\u0000\u00bc\u0012\u0001\u0000\u0000\u0000\u00bd\u00c1"+
|
||||
"\u0003!\u0010\u0000\u00be\u00c1\u0003#\u0011\u0000\u00bf\u00c1\u0003%"+
|
||||
"\u0012\u0000\u00c0\u00bd\u0001\u0000\u0000\u0000\u00c0\u00be\u0001\u0000"+
|
||||
"\u0000\u0000\u00c0\u00bf\u0001\u0000\u0000\u0000\u00c1\u0014\u0001\u0000"+
|
||||
"\u0000\u0000\u00c2\u00c5\u0003\u001f\u000f\u0000\u00c3\u00c5\u0003\u001d"+
|
||||
"\u000e\u0000\u00c4\u00c2\u0001\u0000\u0000\u0000\u00c4\u00c3\u0001\u0000"+
|
||||
"\u0000\u0000\u00c5\u0016\u0001\u0000\u0000\u0000\u00c6\u00cd\u0003\'\u0013"+
|
||||
"\u0000\u00c7\u00cd\u0003)\u0014\u0000\u00c8\u00cd\u0003+\u0015\u0000\u00c9"+
|
||||
"\u00cd\u0003-\u0016\u0000\u00ca\u00cd\u0003/\u0017\u0000\u00cb\u00cd\u0003"+
|
||||
"1\u0018\u0000\u00cc\u00c6\u0001\u0000\u0000\u0000\u00cc\u00c7\u0001\u0000"+
|
||||
"\u0000\u0000\u00cc\u00c8\u0001\u0000\u0000\u0000\u00cc\u00c9\u0001\u0000"+
|
||||
"\u0000\u0000\u00cc\u00ca\u0001\u0000\u0000\u0000\u00cc\u00cb\u0001\u0000"+
|
||||
"\u0000\u0000\u00cd\u0018\u0001\u0000\u0000\u0000\u00ce\u00d1\u00035\u001a"+
|
||||
"\u0000\u00cf\u00d1\u00037\u001b\u0000\u00d0\u00ce\u0001\u0000\u0000\u0000"+
|
||||
"\u00d0\u00cf\u0001\u0000\u0000\u0000\u00d1\u001a\u0001\u0000\u0000\u0000"+
|
||||
"\u00d2\u00d3\u0005=\u0000\u0000\u00d3\u001c\u0001\u0000\u0000\u0000\u00d4"+
|
||||
"\u00d5\u0005-\u0000\u0000\u00d5\u001e\u0001\u0000\u0000\u0000\u00d6\u00d7"+
|
||||
"\u0005+\u0000\u0000\u00d7 \u0001\u0000\u0000\u0000\u00d8\u00d9\u0005*"+
|
||||
"\u0000\u0000\u00d9\"\u0001\u0000\u0000\u0000\u00da\u00db\u0005/\u0000"+
|
||||
"\u0000\u00db$\u0001\u0000\u0000\u0000\u00dc\u00dd\u0005%\u0000\u0000\u00dd"+
|
||||
"&\u0001\u0000\u0000\u0000\u00de\u00df\u0005>\u0000\u0000\u00df(\u0001"+
|
||||
"\u0000\u0000\u0000\u00e0\u00e1\u0005<\u0000\u0000\u00e1*\u0001\u0000\u0000"+
|
||||
"\u0000\u00e2\u00e3\u0005>\u0000\u0000\u00e3\u00e4\u0005=\u0000\u0000\u00e4"+
|
||||
",\u0001\u0000\u0000\u0000\u00e5\u00e6\u0005<\u0000\u0000\u00e6\u00e7\u0005"+
|
||||
"=\u0000\u0000\u00e7.\u0001\u0000\u0000\u0000\u00e8\u00e9\u0005=\u0000"+
|
||||
"\u0000\u00e9\u00ea\u0005=\u0000\u0000\u00ea0\u0001\u0000\u0000\u0000\u00eb"+
|
||||
"\u00ec\u0005!\u0000\u0000\u00ec\u00ed\u0005=\u0000\u0000\u00ed2\u0001"+
|
||||
"\u0000\u0000\u0000\u00ee\u00ef\u0005!\u0000\u0000\u00ef4\u0001\u0000\u0000"+
|
||||
"\u0000\u00f0\u00f1\u0005&\u0000\u0000\u00f1\u00f2\u0005&\u0000\u0000\u00f2"+
|
||||
"6\u0001\u0000\u0000\u0000\u00f3\u00f4\u0005|\u0000\u0000\u00f4\u00f5\u0005"+
|
||||
"|\u0000\u0000\u00f58\u0001\u0000\u0000\u0000\u00f6\u00f7\u0005.\u0000"+
|
||||
"\u0000\u00f7:\u0001\u0000\u0000\u0000\u00f8\u00f9\u0005(\u0000\u0000\u00f9"+
|
||||
"<\u0001\u0000\u0000\u0000\u00fa\u00fb\u0005)\u0000\u0000\u00fb>\u0001"+
|
||||
"\u0000\u0000\u0000\u00fc\u00fd\u0005{\u0000\u0000\u00fd@\u0001\u0000\u0000"+
|
||||
"\u0000\u00fe\u00ff\u0005}\u0000\u0000\u00ffB\u0001\u0000\u0000\u0000\u0100"+
|
||||
"\u0101\u0005;\u0000\u0000\u0101D\u0001\u0000\u0000\u0000\u0102\u0103\u0005"+
|
||||
",\u0000\u0000\u0103F\u0001\u0000\u0000\u0000\u0104\u0105\u0005c\u0000"+
|
||||
"\u0000\u0105\u0106\u0005l\u0000\u0000\u0106\u0107\u0005a\u0000\u0000\u0107"+
|
||||
"\u0108\u0005s\u0000\u0000\u0108\u0109\u0005s\u0000\u0000\u0109H\u0001"+
|
||||
"\u0000\u0000\u0000\u010a\u010b\u0005t\u0000\u0000\u010b\u010c\u0005h\u0000"+
|
||||
"\u0000\u010c\u010d\u0005i\u0000\u0000\u010d\u010e\u0005s\u0000\u0000\u010e"+
|
||||
"J\u0001\u0000\u0000\u0000\u010f\u0110\u0005w\u0000\u0000\u0110\u0111\u0005"+
|
||||
"h\u0000\u0000\u0111\u0112\u0005i\u0000\u0000\u0112\u0113\u0005l\u0000"+
|
||||
"\u0000\u0113\u0114\u0005e\u0000\u0000\u0114L\u0001\u0000\u0000\u0000\u0115"+
|
||||
"\u0116\u0005i\u0000\u0000\u0116\u0117\u0005f\u0000\u0000\u0117N\u0001"+
|
||||
"\u0000\u0000\u0000\u0118\u0119\u0005e\u0000\u0000\u0119\u011a\u0005l\u0000"+
|
||||
"\u0000\u011a\u011b\u0005s\u0000\u0000\u011b\u011c\u0005e\u0000\u0000\u011c"+
|
||||
"P\u0001\u0000\u0000\u0000\u011d\u011e\u0005r\u0000\u0000\u011e\u011f\u0005"+
|
||||
"e\u0000\u0000\u011f\u0120\u0005t\u0000\u0000\u0120\u0121\u0005u\u0000"+
|
||||
"\u0000\u0121\u0122\u0005r\u0000\u0000\u0122\u0123\u0005n\u0000\u0000\u0123"+
|
||||
"R\u0001\u0000\u0000\u0000\u0124\u0125\u0005n\u0000\u0000\u0125\u0126\u0005"+
|
||||
"e\u0000\u0000\u0126\u0127\u0005w\u0000\u0000\u0127T\u0001\u0000\u0000"+
|
||||
"\u0000\u0128\u012a\u0007\u0000\u0000\u0000\u0129\u0128\u0001\u0000\u0000"+
|
||||
"\u0000\u012a\u012d\u0001\u0000\u0000\u0000\u012b\u0129\u0001\u0000\u0000"+
|
||||
"\u0000\u012b\u012c\u0001\u0000\u0000\u0000\u012c\u012f\u0001\u0000\u0000"+
|
||||
"\u0000\u012d\u012b\u0001\u0000\u0000\u0000\u012e\u0130\u0007\u0001\u0000"+
|
||||
"\u0000\u012f\u012e\u0001\u0000\u0000\u0000\u0130\u0131\u0001\u0000\u0000"+
|
||||
"\u0000\u0131\u012f\u0001\u0000\u0000\u0000\u0131\u0132\u0001\u0000\u0000"+
|
||||
"\u0000\u0132V\u0001\u0000\u0000\u0000\u0133\u0135\u0005\'\u0000\u0000"+
|
||||
"\u0134\u0136\b\u0002\u0000\u0000\u0135\u0134\u0001\u0000\u0000\u0000\u0135"+
|
||||
"\u0136\u0001\u0000\u0000\u0000\u0136\u0137\u0001\u0000\u0000\u0000\u0137"+
|
||||
"\u0138\u0005\'\u0000\u0000\u0138X\u0001\u0000\u0000\u0000\u0139\u013a"+
|
||||
"\u0007\u0003\u0000\u0000\u013aZ\u0001\u0000\u0000\u0000\u013b\u013c\u0007"+
|
||||
"\u0001\u0000\u0000\u013c\\\u0001\u0000\u0000\u0000\u013d\u0141\u0003Y"+
|
||||
",\u0000\u013e\u0141\u0003[-\u0000\u013f\u0141\u0007\u0004\u0000\u0000"+
|
||||
"\u0140\u013d\u0001\u0000\u0000\u0000\u0140\u013e\u0001\u0000\u0000\u0000"+
|
||||
"\u0140\u013f\u0001\u0000\u0000\u0000\u0141^\u0001\u0000\u0000\u0000\u0142"+
|
||||
"\u0146\u0003Y,\u0000\u0143\u0145\u0003].\u0000\u0144\u0143\u0001\u0000"+
|
||||
"\u0000\u0000\u0145\u0148\u0001\u0000\u0000\u0000\u0146\u0144\u0001\u0000"+
|
||||
"\u0000\u0000\u0146\u0147\u0001\u0000\u0000\u0000\u0147`\u0001\u0000\u0000"+
|
||||
"\u0000\u0148\u0146\u0001\u0000\u0000\u0000\u0149\u014a\u0007\u0005\u0000"+
|
||||
"\u0000\u014a\u014b\u0001\u0000\u0000\u0000\u014b\u014c\u00060\u0000\u0000"+
|
||||
"\u014cb\u0001\u0000\u0000\u0000\u000b\u0000r\u00c0\u00c4\u00cc\u00d0\u012b"+
|
||||
"\u0131\u0135\u0140\u0146\u0001\u0006\u0000\u0000";
|
||||
public static final ATN _ATN =
|
||||
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
|
||||
static {
|
||||
|
||||
@@ -1,85 +1,83 @@
|
||||
T__0=1
|
||||
T__1=2
|
||||
BooleanValue=3
|
||||
NullValue=4
|
||||
AccessModifierPublic=5
|
||||
MainMethodDecl=6
|
||||
Void=7
|
||||
Int=8
|
||||
Boolean=9
|
||||
Char=10
|
||||
DotOperator=11
|
||||
LineOperator=12
|
||||
ComparisonOperator=13
|
||||
LogicalOpertor=14
|
||||
Assign=15
|
||||
Minus=16
|
||||
Plus=17
|
||||
Multipilkation=18
|
||||
Division=19
|
||||
Modulo=20
|
||||
Greater=21
|
||||
Less=22
|
||||
GreaterEqual=23
|
||||
LessEqual=24
|
||||
Equal=25
|
||||
NotEqual=26
|
||||
Not=27
|
||||
And=28
|
||||
Or=29
|
||||
Dot=30
|
||||
OpenRoundBracket=31
|
||||
ClosedRoundBracket=32
|
||||
OpenCurlyBracket=33
|
||||
ClosedCurlyBracket=34
|
||||
Semicolon=35
|
||||
Comma=36
|
||||
Class=37
|
||||
This=38
|
||||
While=39
|
||||
If=40
|
||||
Else=41
|
||||
Return=42
|
||||
New=43
|
||||
IntValue=44
|
||||
CharValue=45
|
||||
Identifier=46
|
||||
WS=47
|
||||
'print('=1
|
||||
');'=2
|
||||
'null'=4
|
||||
'public'=5
|
||||
'public static void main(String[] args)'=6
|
||||
'void'=7
|
||||
'int'=8
|
||||
'boolean'=9
|
||||
'char'=10
|
||||
'='=15
|
||||
'-'=16
|
||||
'+'=17
|
||||
'*'=18
|
||||
'/'=19
|
||||
'%'=20
|
||||
'>'=21
|
||||
'<'=22
|
||||
'>='=23
|
||||
'<='=24
|
||||
'=='=25
|
||||
'!='=26
|
||||
'!'=27
|
||||
'&&'=28
|
||||
'||'=29
|
||||
'.'=30
|
||||
'('=31
|
||||
')'=32
|
||||
'{'=33
|
||||
'}'=34
|
||||
';'=35
|
||||
','=36
|
||||
'class'=37
|
||||
'this'=38
|
||||
'while'=39
|
||||
'if'=40
|
||||
'else'=41
|
||||
'return'=42
|
||||
'new'=43
|
||||
BooleanValue=2
|
||||
NullValue=3
|
||||
AccessModifierPublic=4
|
||||
MainMethodDecl=5
|
||||
Void=6
|
||||
Int=7
|
||||
Boolean=8
|
||||
Char=9
|
||||
DotOperator=10
|
||||
LineOperator=11
|
||||
ComparisonOperator=12
|
||||
LogicalOpertor=13
|
||||
Assign=14
|
||||
Minus=15
|
||||
Plus=16
|
||||
Multipilkation=17
|
||||
Division=18
|
||||
Modulo=19
|
||||
Greater=20
|
||||
Less=21
|
||||
GreaterEqual=22
|
||||
LessEqual=23
|
||||
Equal=24
|
||||
NotEqual=25
|
||||
Not=26
|
||||
And=27
|
||||
Or=28
|
||||
Dot=29
|
||||
OpenRoundBracket=30
|
||||
ClosedRoundBracket=31
|
||||
OpenCurlyBracket=32
|
||||
ClosedCurlyBracket=33
|
||||
Semicolon=34
|
||||
Comma=35
|
||||
Class=36
|
||||
This=37
|
||||
While=38
|
||||
If=39
|
||||
Else=40
|
||||
Return=41
|
||||
New=42
|
||||
IntValue=43
|
||||
CharValue=44
|
||||
Identifier=45
|
||||
WS=46
|
||||
'print'=1
|
||||
'null'=3
|
||||
'public'=4
|
||||
'public static void main(String[] args)'=5
|
||||
'void'=6
|
||||
'int'=7
|
||||
'boolean'=8
|
||||
'char'=9
|
||||
'='=14
|
||||
'-'=15
|
||||
'+'=16
|
||||
'*'=17
|
||||
'/'=18
|
||||
'%'=19
|
||||
'>'=20
|
||||
'<'=21
|
||||
'>='=22
|
||||
'<='=23
|
||||
'=='=24
|
||||
'!='=25
|
||||
'!'=26
|
||||
'&&'=27
|
||||
'||'=28
|
||||
'.'=29
|
||||
'('=30
|
||||
')'=31
|
||||
'{'=32
|
||||
'}'=33
|
||||
';'=34
|
||||
','=35
|
||||
'class'=36
|
||||
'this'=37
|
||||
'while'=38
|
||||
'if'=39
|
||||
'else'=40
|
||||
'return'=41
|
||||
'new'=42
|
||||
|
||||
@@ -17,14 +17,14 @@ public class DecafParser extends Parser {
|
||||
protected static final PredictionContextCache _sharedContextCache =
|
||||
new PredictionContextCache();
|
||||
public static final int
|
||||
T__0=1, T__1=2, BooleanValue=3, NullValue=4, AccessModifierPublic=5, MainMethodDecl=6,
|
||||
Void=7, Int=8, Boolean=9, Char=10, DotOperator=11, LineOperator=12, ComparisonOperator=13,
|
||||
LogicalOpertor=14, Assign=15, Minus=16, Plus=17, Multipilkation=18, Division=19,
|
||||
Modulo=20, Greater=21, Less=22, GreaterEqual=23, LessEqual=24, Equal=25,
|
||||
NotEqual=26, Not=27, And=28, Or=29, Dot=30, OpenRoundBracket=31, ClosedRoundBracket=32,
|
||||
OpenCurlyBracket=33, ClosedCurlyBracket=34, Semicolon=35, Comma=36, Class=37,
|
||||
This=38, While=39, If=40, Else=41, Return=42, New=43, IntValue=44, CharValue=45,
|
||||
Identifier=46, WS=47;
|
||||
T__0=1, BooleanValue=2, NullValue=3, AccessModifierPublic=4, MainMethodDecl=5,
|
||||
Void=6, Int=7, Boolean=8, Char=9, DotOperator=10, LineOperator=11, ComparisonOperator=12,
|
||||
LogicalOpertor=13, Assign=14, Minus=15, Plus=16, Multipilkation=17, Division=18,
|
||||
Modulo=19, Greater=20, Less=21, GreaterEqual=22, LessEqual=23, Equal=24,
|
||||
NotEqual=25, Not=26, And=27, Or=28, Dot=29, OpenRoundBracket=30, ClosedRoundBracket=31,
|
||||
OpenCurlyBracket=32, ClosedCurlyBracket=33, Semicolon=34, Comma=35, Class=36,
|
||||
This=37, While=38, If=39, Else=40, Return=41, New=42, IntValue=43, CharValue=44,
|
||||
Identifier=45, WS=46;
|
||||
public static final int
|
||||
RULE_program = 0, RULE_classdecl = 1, RULE_constuctorDecl = 2, RULE_methodDecl = 3,
|
||||
RULE_parameterList = 4, RULE_parameter = 5, RULE_argumentList = 6, RULE_expression = 7,
|
||||
@@ -51,7 +51,7 @@ public class DecafParser extends Parser {
|
||||
|
||||
private static String[] makeLiteralNames() {
|
||||
return new String[] {
|
||||
null, "'print('", "');'", null, "'null'", "'public'", "'public static void main(String[] args)'",
|
||||
null, "'print'", null, "'null'", "'public'", "'public static void main(String[] args)'",
|
||||
"'void'", "'int'", "'boolean'", "'char'", null, null, null, null, "'='",
|
||||
"'-'", "'+'", "'*'", "'/'", "'%'", "'>'", "'<'", "'>='", "'<='", "'=='",
|
||||
"'!='", "'!'", "'&&'", "'||'", "'.'", "'('", "')'", "'{'", "'}'", "';'",
|
||||
@@ -62,11 +62,11 @@ public class DecafParser extends Parser {
|
||||
private static final String[] _LITERAL_NAMES = makeLiteralNames();
|
||||
private static String[] makeSymbolicNames() {
|
||||
return new String[] {
|
||||
null, null, null, "BooleanValue", "NullValue", "AccessModifierPublic",
|
||||
"MainMethodDecl", "Void", "Int", "Boolean", "Char", "DotOperator", "LineOperator",
|
||||
"ComparisonOperator", "LogicalOpertor", "Assign", "Minus", "Plus", "Multipilkation",
|
||||
"Division", "Modulo", "Greater", "Less", "GreaterEqual", "LessEqual",
|
||||
"Equal", "NotEqual", "Not", "And", "Or", "Dot", "OpenRoundBracket", "ClosedRoundBracket",
|
||||
null, null, "BooleanValue", "NullValue", "AccessModifierPublic", "MainMethodDecl",
|
||||
"Void", "Int", "Boolean", "Char", "DotOperator", "LineOperator", "ComparisonOperator",
|
||||
"LogicalOpertor", "Assign", "Minus", "Plus", "Multipilkation", "Division",
|
||||
"Modulo", "Greater", "Less", "GreaterEqual", "LessEqual", "Equal", "NotEqual",
|
||||
"Not", "And", "Or", "Dot", "OpenRoundBracket", "ClosedRoundBracket",
|
||||
"OpenCurlyBracket", "ClosedCurlyBracket", "Semicolon", "Comma", "Class",
|
||||
"This", "While", "If", "Else", "Return", "New", "IntValue", "CharValue",
|
||||
"Identifier", "WS"
|
||||
@@ -258,7 +258,7 @@ public class DecafParser extends Parser {
|
||||
setState(88);
|
||||
_errHandler.sync(this);
|
||||
_la = _input.LA(1);
|
||||
while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 70368744179616L) != 0)) {
|
||||
while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 35184372089808L) != 0)) {
|
||||
{
|
||||
setState(86);
|
||||
_errHandler.sync(this);
|
||||
@@ -369,7 +369,7 @@ public class DecafParser extends Parser {
|
||||
setState(103);
|
||||
_errHandler.sync(this);
|
||||
_la = _input.LA(1);
|
||||
if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 70368744179456L) != 0)) {
|
||||
if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 35184372089728L) != 0)) {
|
||||
{
|
||||
setState(102);
|
||||
parameterList();
|
||||
@@ -473,7 +473,7 @@ public class DecafParser extends Parser {
|
||||
setState(118);
|
||||
_errHandler.sync(this);
|
||||
_la = _input.LA(1);
|
||||
if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 70368744179456L) != 0)) {
|
||||
if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 35184372089728L) != 0)) {
|
||||
{
|
||||
setState(117);
|
||||
parameterList();
|
||||
@@ -659,7 +659,7 @@ public class DecafParser extends Parser {
|
||||
setState(135);
|
||||
_errHandler.sync(this);
|
||||
_la = _input.LA(1);
|
||||
if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 132218554941464L) != 0)) {
|
||||
if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 66109277470732L) != 0)) {
|
||||
{
|
||||
setState(134);
|
||||
expression();
|
||||
@@ -1854,7 +1854,7 @@ public class DecafParser extends Parser {
|
||||
setState(263);
|
||||
_errHandler.sync(this);
|
||||
_la = _input.LA(1);
|
||||
if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 132218554941464L) != 0)) {
|
||||
if ((((_la) & ~0x3f) == 0 && ((1L << _la) & 66109277470732L) != 0)) {
|
||||
{
|
||||
setState(262);
|
||||
expression();
|
||||
@@ -1994,7 +1994,7 @@ public class DecafParser extends Parser {
|
||||
setState(280);
|
||||
_errHandler.sync(this);
|
||||
_la = _input.LA(1);
|
||||
while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 85529978734370L) != 0)) {
|
||||
while ((((_la) & ~0x3f) == 0 && ((1L << _la) & 42764989367186L) != 0)) {
|
||||
{
|
||||
{
|
||||
setState(277);
|
||||
@@ -2569,7 +2569,7 @@ public class DecafParser extends Parser {
|
||||
{
|
||||
setState(330);
|
||||
_la = _input.LA(1);
|
||||
if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & 70368744179456L) != 0)) ) {
|
||||
if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & 35184372089728L) != 0)) ) {
|
||||
_errHandler.recoverInline(this);
|
||||
}
|
||||
else {
|
||||
@@ -2624,7 +2624,7 @@ public class DecafParser extends Parser {
|
||||
{
|
||||
setState(332);
|
||||
_la = _input.LA(1);
|
||||
if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & 52776558133272L) != 0)) ) {
|
||||
if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & 26388279066636L) != 0)) ) {
|
||||
_errHandler.recoverInline(this);
|
||||
}
|
||||
else {
|
||||
@@ -2647,7 +2647,10 @@ public class DecafParser extends Parser {
|
||||
|
||||
@SuppressWarnings("CheckReturnValue")
|
||||
public static class PrintContext extends ParserRuleContext {
|
||||
public TerminalNode OpenRoundBracket() { return getToken(DecafParser.OpenRoundBracket, 0); }
|
||||
public TerminalNode Identifier() { return getToken(DecafParser.Identifier, 0); }
|
||||
public TerminalNode ClosedRoundBracket() { return getToken(DecafParser.ClosedRoundBracket, 0); }
|
||||
public TerminalNode Semicolon() { return getToken(DecafParser.Semicolon, 0); }
|
||||
public PrintContext(ParserRuleContext parent, int invokingState) {
|
||||
super(parent, invokingState);
|
||||
}
|
||||
@@ -2676,9 +2679,13 @@ public class DecafParser extends Parser {
|
||||
setState(334);
|
||||
match(T__0);
|
||||
setState(335);
|
||||
match(Identifier);
|
||||
match(OpenRoundBracket);
|
||||
setState(336);
|
||||
match(T__1);
|
||||
match(Identifier);
|
||||
setState(337);
|
||||
match(ClosedRoundBracket);
|
||||
setState(338);
|
||||
match(Semicolon);
|
||||
}
|
||||
}
|
||||
catch (RecognitionException re) {
|
||||
@@ -2717,7 +2724,7 @@ public class DecafParser extends Parser {
|
||||
}
|
||||
|
||||
public static final String _serializedATN =
|
||||
"\u0004\u0001/\u0153\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001\u0002"+
|
||||
"\u0004\u0001.\u0155\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001\u0002"+
|
||||
"\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004\u0007\u0004\u0002"+
|
||||
"\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002\u0007\u0007\u0007\u0002"+
|
||||
"\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0002\u000b\u0007\u000b\u0002"+
|
||||
@@ -2768,170 +2775,172 @@ public class DecafParser extends Parser {
|
||||
"\u0001\u001d\u0001\u001d\u0001\u001d\u0001\u001e\u0001\u001e\u0001\u001e"+
|
||||
"\u0001\u001e\u0003\u001e\u013f\b\u001e\u0001\u001e\u0001\u001e\u0001\u001f"+
|
||||
"\u0001\u001f\u0001\u001f\u0001\u001f\u0001\u001f\u0001\u001f\u0001 \u0001"+
|
||||
" \u0001!\u0001!\u0001\"\u0001\"\u0001#\u0001#\u0001#\u0001#\u0001#\u0000"+
|
||||
"\u0002 \"$\u0000\u0002\u0004\u0006\b\n\f\u000e\u0010\u0012\u0014\u0016"+
|
||||
"\u0018\u001a\u001c\u001e \"$&(*,.02468:<>@BDF\u0000\u0003\u0001\u0000"+
|
||||
"\r\u000e\u0002\u0000\b\n..\u0002\u0000\u0003\u0004,-\u0162\u0000I\u0001"+
|
||||
"\u0000\u0000\u0000\u0002N\u0001\u0000\u0000\u0000\u0004b\u0001\u0000\u0000"+
|
||||
"\u0000\u0006m\u0001\u0000\u0000\u0000\b{\u0001\u0000\u0000\u0000\n\u0083"+
|
||||
"\u0001\u0000\u0000\u0000\f\u0090\u0001\u0000\u0000\u0000\u000e\u0094\u0001"+
|
||||
"\u0000\u0000\u0000\u0010\u009d\u0001\u0000\u0000\u0000\u0012\u00a0\u0001"+
|
||||
"\u0000\u0000\u0000\u0014\u00b9\u0001\u0000\u0000\u0000\u0016\u00be\u0001"+
|
||||
"\u0000\u0000\u0000\u0018\u00c2\u0001\u0000\u0000\u0000\u001a\u00c7\u0001"+
|
||||
"\u0000\u0000\u0000\u001c\u00cc\u0001\u0000\u0000\u0000\u001e\u00dd\u0001"+
|
||||
"\u0000\u0000\u0000 \u00df\u0001\u0000\u0000\u0000\"\u00ea\u0001\u0000"+
|
||||
"\u0000\u0000$\u00fd\u0001\u0000\u0000\u0000&\u00ff\u0001\u0000\u0000\u0000"+
|
||||
"(\u0103\u0001\u0000\u0000\u0000*\u0105\u0001\u0000\u0000\u0000,\u010a"+
|
||||
"\u0001\u0000\u0000\u0000.\u0114\u0001\u0000\u0000\u00000\u011d\u0001\u0000"+
|
||||
"\u0000\u00002\u0123\u0001\u0000\u0000\u00004\u0127\u0001\u0000\u0000\u0000"+
|
||||
"6\u012d\u0001\u0000\u0000\u00008\u0130\u0001\u0000\u0000\u0000:\u0134"+
|
||||
"\u0001\u0000\u0000\u0000<\u013e\u0001\u0000\u0000\u0000>\u0142\u0001\u0000"+
|
||||
"\u0000\u0000@\u0148\u0001\u0000\u0000\u0000B\u014a\u0001\u0000\u0000\u0000"+
|
||||
"D\u014c\u0001\u0000\u0000\u0000F\u014e\u0001\u0000\u0000\u0000HJ\u0003"+
|
||||
"\u0002\u0001\u0000IH\u0001\u0000\u0000\u0000JK\u0001\u0000\u0000\u0000"+
|
||||
"KI\u0001\u0000\u0000\u0000KL\u0001\u0000\u0000\u0000L\u0001\u0001\u0000"+
|
||||
"\u0000\u0000MO\u0005\u0005\u0000\u0000NM\u0001\u0000\u0000\u0000NO\u0001"+
|
||||
"\u0000\u0000\u0000OP\u0001\u0000\u0000\u0000PQ\u0005%\u0000\u0000QR\u0005"+
|
||||
".\u0000\u0000RX\u0005!\u0000\u0000SW\u0003\u0004\u0002\u0000TW\u0003,"+
|
||||
"\u0016\u0000UW\u0003\u0006\u0003\u0000VS\u0001\u0000\u0000\u0000VT\u0001"+
|
||||
"\u0000\u0000\u0000VU\u0001\u0000\u0000\u0000WZ\u0001\u0000\u0000\u0000"+
|
||||
"XV\u0001\u0000\u0000\u0000XY\u0001\u0000\u0000\u0000Y]\u0001\u0000\u0000"+
|
||||
"\u0000ZX\u0001\u0000\u0000\u0000[\\\u0005\u0006\u0000\u0000\\^\u0003."+
|
||||
"\u0017\u0000][\u0001\u0000\u0000\u0000]^\u0001\u0000\u0000\u0000^_\u0001"+
|
||||
"\u0000\u0000\u0000_`\u0005\"\u0000\u0000`\u0003\u0001\u0000\u0000\u0000"+
|
||||
"ac\u0005\u0005\u0000\u0000ba\u0001\u0000\u0000\u0000bc\u0001\u0000\u0000"+
|
||||
"\u0000cd\u0001\u0000\u0000\u0000de\u0005.\u0000\u0000eg\u0005\u001f\u0000"+
|
||||
"\u0000fh\u0003\b\u0004\u0000gf\u0001\u0000\u0000\u0000gh\u0001\u0000\u0000"+
|
||||
"\u0000hi\u0001\u0000\u0000\u0000ij\u0005 \u0000\u0000jk\u0003.\u0017\u0000"+
|
||||
"k\u0005\u0001\u0000\u0000\u0000ln\u0005\u0005\u0000\u0000ml\u0001\u0000"+
|
||||
"\u0000\u0000mn\u0001\u0000\u0000\u0000nq\u0001\u0000\u0000\u0000or\u0003"+
|
||||
"B!\u0000pr\u0005\u0007\u0000\u0000qo\u0001\u0000\u0000\u0000qp\u0001\u0000"+
|
||||
"\u0000\u0000rs\u0001\u0000\u0000\u0000st\u0005.\u0000\u0000tv\u0005\u001f"+
|
||||
"\u0000\u0000uw\u0003\b\u0004\u0000vu\u0001\u0000\u0000\u0000vw\u0001\u0000"+
|
||||
"\u0000\u0000wx\u0001\u0000\u0000\u0000xy\u0005 \u0000\u0000yz\u0003.\u0017"+
|
||||
"\u0000z\u0007\u0001\u0000\u0000\u0000{\u0080\u0003\n\u0005\u0000|}\u0005"+
|
||||
"$\u0000\u0000}\u007f\u0003\n\u0005\u0000~|\u0001\u0000\u0000\u0000\u007f"+
|
||||
"\u0082\u0001\u0000\u0000\u0000\u0080~\u0001\u0000\u0000\u0000\u0080\u0081"+
|
||||
"\u0001\u0000\u0000\u0000\u0081\t\u0001\u0000\u0000\u0000\u0082\u0080\u0001"+
|
||||
"\u0000\u0000\u0000\u0083\u0084\u0003B!\u0000\u0084\u0085\u0005.\u0000"+
|
||||
"\u0000\u0085\u000b\u0001\u0000\u0000\u0000\u0086\u0088\u0003\u000e\u0007"+
|
||||
"\u0000\u0087\u0086\u0001\u0000\u0000\u0000\u0087\u0088\u0001\u0000\u0000"+
|
||||
"\u0000\u0088\u0091\u0001\u0000\u0000\u0000\u0089\u008c\u0003\u000e\u0007"+
|
||||
"\u0000\u008a\u008b\u0005$\u0000\u0000\u008b\u008d\u0003\u000e\u0007\u0000"+
|
||||
"\u008c\u008a\u0001\u0000\u0000\u0000\u008d\u008e\u0001\u0000\u0000\u0000"+
|
||||
"\u008e\u008c\u0001\u0000\u0000\u0000\u008e\u008f\u0001\u0000\u0000\u0000"+
|
||||
"\u008f\u0091\u0001\u0000\u0000\u0000\u0090\u0087\u0001\u0000\u0000\u0000"+
|
||||
"\u0090\u0089\u0001\u0000\u0000\u0000\u0091\r\u0001\u0000\u0000\u0000\u0092"+
|
||||
"\u0095\u0003\u0010\b\u0000\u0093\u0095\u0003\u001e\u000f\u0000\u0094\u0092"+
|
||||
"\u0001\u0000\u0000\u0000\u0094\u0093\u0001\u0000\u0000\u0000\u0095\u000f"+
|
||||
"\u0001\u0000\u0000\u0000\u0096\u009e\u0005&\u0000\u0000\u0097\u009e\u0003"+
|
||||
"\u0018\f\u0000\u0098\u009e\u0003\u0016\u000b\u0000\u0099\u009a\u0005\u001f"+
|
||||
"\u0000\u0000\u009a\u009b\u0003\u0010\b\u0000\u009b\u009c\u0005 \u0000"+
|
||||
"\u0000\u009c\u009e\u0001\u0000\u0000\u0000\u009d\u0096\u0001\u0000\u0000"+
|
||||
"\u0000\u009d\u0097\u0001\u0000\u0000\u0000\u009d\u0098\u0001\u0000\u0000"+
|
||||
"\u0000\u009d\u0099\u0001\u0000\u0000\u0000\u009e\u0011\u0001\u0000\u0000"+
|
||||
"\u0000\u009f\u00a1\u0003<\u001e\u0000\u00a0\u009f\u0001\u0000\u0000\u0000"+
|
||||
"\u00a0\u00a1\u0001\u0000\u0000\u0000\u00a1\u00a5\u0001\u0000\u0000\u0000"+
|
||||
"\u00a2\u00a4\u0003>\u001f\u0000\u00a3\u00a2\u0001\u0000\u0000\u0000\u00a4"+
|
||||
"\u00a7\u0001\u0000\u0000\u0000\u00a5\u00a3\u0001\u0000\u0000\u0000\u00a5"+
|
||||
"\u00a6\u0001\u0000\u0000\u0000\u00a6\u00a8\u0001\u0000\u0000\u0000\u00a7"+
|
||||
"\u00a5\u0001\u0000\u0000\u0000\u00a8\u00a9\u0005.\u0000\u0000\u00a9\u00aa"+
|
||||
"\u0005\u001f\u0000\u0000\u00aa\u00ab\u0003\f\u0006\u0000\u00ab\u00ac\u0005"+
|
||||
" \u0000\u0000\u00ac\u0013\u0001\u0000\u0000\u0000\u00ad\u00ae\u0003*\u0015"+
|
||||
"\u0000\u00ae\u00af\u0005#\u0000\u0000\u00af\u00ba\u0001\u0000\u0000\u0000"+
|
||||
"\u00b0\u00ba\u0003,\u0016\u0000\u00b1\u00ba\u0003.\u0017\u0000\u00b2\u00ba"+
|
||||
"\u00030\u0018\u0000\u00b3\u00ba\u00032\u0019\u0000\u00b4\u00ba\u0003F"+
|
||||
"#\u0000\u00b5\u00b6\u0003\u0016\u000b\u0000\u00b6\u00b7\u0005#\u0000\u0000"+
|
||||
"\u00b7\u00ba\u0001\u0000\u0000\u0000\u00b8\u00ba\u0003@ \u0000\u00b9\u00ad"+
|
||||
"\u0001\u0000\u0000\u0000\u00b9\u00b0\u0001\u0000\u0000\u0000\u00b9\u00b1"+
|
||||
"\u0001\u0000\u0000\u0000\u00b9\u00b2\u0001\u0000\u0000\u0000\u00b9\u00b3"+
|
||||
"\u0001\u0000\u0000\u0000\u00b9\u00b4\u0001\u0000\u0000\u0000\u00b9\u00b5"+
|
||||
"\u0001\u0000\u0000\u0000\u00b9\u00b8\u0001\u0000\u0000\u0000\u00ba\u0015"+
|
||||
"\u0001\u0000\u0000\u0000\u00bb\u00bf\u00038\u001c\u0000\u00bc\u00bf\u0003"+
|
||||
":\u001d\u0000\u00bd\u00bf\u0003\u0012\t\u0000\u00be\u00bb\u0001\u0000"+
|
||||
"\u0000\u0000\u00be\u00bc\u0001\u0000\u0000\u0000\u00be\u00bd\u0001\u0000"+
|
||||
"\u0000\u0000\u00bf\u0017\u0001\u0000\u0000\u0000\u00c0\u00c3\u0005.\u0000"+
|
||||
"\u0000\u00c1\u00c3\u0003\u001c\u000e\u0000\u00c2\u00c0\u0001\u0000\u0000"+
|
||||
"\u0000\u00c2\u00c1\u0001\u0000\u0000\u0000\u00c3\u0019\u0001\u0000\u0000"+
|
||||
"\u0000\u00c4\u00c8\u0005&\u0000\u0000\u00c5\u00c8\u0003:\u001d\u0000\u00c6"+
|
||||
"\u00c8\u0005.\u0000\u0000\u00c7\u00c4\u0001\u0000\u0000\u0000\u00c7\u00c5"+
|
||||
"\u0001\u0000\u0000\u0000\u00c7\u00c6\u0001\u0000\u0000\u0000\u00c8\u00c9"+
|
||||
"\u0001\u0000\u0000\u0000\u00c9\u00ca\u0005\u001e\u0000\u0000\u00ca\u001b"+
|
||||
"\u0001\u0000\u0000\u0000\u00cb\u00cd\u0003\u001a\r\u0000\u00cc\u00cb\u0001"+
|
||||
"\u0000\u0000\u0000\u00cd\u00ce\u0001\u0000\u0000\u0000\u00ce\u00cc\u0001"+
|
||||
"\u0000\u0000\u0000\u00ce\u00cf\u0001\u0000\u0000\u0000\u00cf\u00d3\u0001"+
|
||||
"\u0000\u0000\u0000\u00d0\u00d2\u0003>\u001f\u0000\u00d1\u00d0\u0001\u0000"+
|
||||
"\u0000\u0000\u00d2\u00d5\u0001\u0000\u0000\u0000\u00d3\u00d1\u0001\u0000"+
|
||||
"\u0000\u0000\u00d3\u00d4\u0001\u0000\u0000\u0000\u00d4\u00d6\u0001\u0000"+
|
||||
"\u0000\u0000\u00d5\u00d3\u0001\u0000\u0000\u0000\u00d6\u00d7\u0005.\u0000"+
|
||||
"\u0000\u00d7\u001d\u0001\u0000\u0000\u0000\u00d8\u00de\u0003 \u0010\u0000"+
|
||||
"\u00d9\u00de\u0003&\u0013\u0000\u00da\u00de\u0003D\"\u0000\u00db\u00dc"+
|
||||
"\u0005\u001b\u0000\u0000\u00dc\u00de\u0003\u001e\u000f\u0000\u00dd\u00d8"+
|
||||
"\u0001\u0000\u0000\u0000\u00dd\u00d9\u0001\u0000\u0000\u0000\u00dd\u00da"+
|
||||
"\u0001\u0000\u0000\u0000\u00dd\u00db\u0001\u0000\u0000\u0000\u00de\u001f"+
|
||||
"\u0001\u0000\u0000\u0000\u00df\u00e0\u0006\u0010\uffff\uffff\u0000\u00e0"+
|
||||
"\u00e1\u0003\"\u0011\u0000\u00e1\u00e7\u0001\u0000\u0000\u0000\u00e2\u00e3"+
|
||||
"\n\u0002\u0000\u0000\u00e3\u00e4\u0005\f\u0000\u0000\u00e4\u00e6\u0003"+
|
||||
"\"\u0011\u0000\u00e5\u00e2\u0001\u0000\u0000\u0000\u00e6\u00e9\u0001\u0000"+
|
||||
"\u0000\u0000\u00e7\u00e5\u0001\u0000\u0000\u0000\u00e7\u00e8\u0001\u0000"+
|
||||
"\u0000\u0000\u00e8!\u0001\u0000\u0000\u0000\u00e9\u00e7\u0001\u0000\u0000"+
|
||||
"\u0000\u00ea\u00eb\u0006\u0011\uffff\uffff\u0000\u00eb\u00ec\u0003$\u0012"+
|
||||
"\u0000\u00ec\u00f2\u0001\u0000\u0000\u0000\u00ed\u00ee\n\u0002\u0000\u0000"+
|
||||
"\u00ee\u00ef\u0005\u000b\u0000\u0000\u00ef\u00f1\u0003$\u0012\u0000\u00f0"+
|
||||
"\u00ed\u0001\u0000\u0000\u0000\u00f1\u00f4\u0001\u0000\u0000\u0000\u00f2"+
|
||||
"\u00f0\u0001\u0000\u0000\u0000\u00f2\u00f3\u0001\u0000\u0000\u0000\u00f3"+
|
||||
"#\u0001\u0000\u0000\u0000\u00f4\u00f2\u0001\u0000\u0000\u0000\u00f5\u00fe"+
|
||||
"\u0005,\u0000\u0000\u00f6\u00fe\u0005.\u0000\u0000\u00f7\u00fe\u0003\u001c"+
|
||||
"\u000e\u0000\u00f8\u00fe\u0003\u0012\t\u0000\u00f9\u00fa\u0005\u001f\u0000"+
|
||||
"\u0000\u00fa\u00fb\u0003 \u0010\u0000\u00fb\u00fc\u0005 \u0000\u0000\u00fc"+
|
||||
"\u00fe\u0001\u0000\u0000\u0000\u00fd\u00f5\u0001\u0000\u0000\u0000\u00fd"+
|
||||
"\u00f6\u0001\u0000\u0000\u0000\u00fd\u00f7\u0001\u0000\u0000\u0000\u00fd"+
|
||||
"\u00f8\u0001\u0000\u0000\u0000\u00fd\u00f9\u0001\u0000\u0000\u0000\u00fe"+
|
||||
"%\u0001\u0000\u0000\u0000\u00ff\u0100\u0003\u0010\b\u0000\u0100\u0101"+
|
||||
"\u0003(\u0014\u0000\u0101\u0102\u0003\u000e\u0007\u0000\u0102\'\u0001"+
|
||||
"\u0000\u0000\u0000\u0103\u0104\u0007\u0000\u0000\u0000\u0104)\u0001\u0000"+
|
||||
"\u0000\u0000\u0105\u0107\u0005*\u0000\u0000\u0106\u0108\u0003\u000e\u0007"+
|
||||
"\u0000\u0107\u0106\u0001\u0000\u0000\u0000\u0107\u0108\u0001\u0000\u0000"+
|
||||
"\u0000\u0108+\u0001\u0000\u0000\u0000\u0109\u010b\u0005\u0005\u0000\u0000"+
|
||||
"\u010a\u0109\u0001\u0000\u0000\u0000\u010a\u010b\u0001\u0000\u0000\u0000"+
|
||||
"\u010b\u010c\u0001\u0000\u0000\u0000\u010c\u010d\u0003B!\u0000\u010d\u0110"+
|
||||
"\u0005.\u0000\u0000\u010e\u010f\u0005\u000f\u0000\u0000\u010f\u0111\u0003"+
|
||||
"\u000e\u0007\u0000\u0110\u010e\u0001\u0000\u0000\u0000\u0110\u0111\u0001"+
|
||||
"\u0000\u0000\u0000\u0111\u0112\u0001\u0000\u0000\u0000\u0112\u0113\u0005"+
|
||||
"#\u0000\u0000\u0113-\u0001\u0000\u0000\u0000\u0114\u0118\u0005!\u0000"+
|
||||
"\u0000\u0115\u0117\u0003\u0014\n\u0000\u0116\u0115\u0001\u0000\u0000\u0000"+
|
||||
"\u0117\u011a\u0001\u0000\u0000\u0000\u0118\u0116\u0001\u0000\u0000\u0000"+
|
||||
"\u0118\u0119\u0001\u0000\u0000\u0000\u0119\u011b\u0001\u0000\u0000\u0000"+
|
||||
"\u011a\u0118\u0001\u0000\u0000\u0000\u011b\u011c\u0005\"\u0000\u0000\u011c"+
|
||||
"/\u0001\u0000\u0000\u0000\u011d\u011e\u0005\'\u0000\u0000\u011e\u011f"+
|
||||
"\u0005\u001f\u0000\u0000\u011f\u0120\u0003\u000e\u0007\u0000\u0120\u0121"+
|
||||
"\u0005 \u0000\u0000\u0121\u0122\u0003\u0014\n\u0000\u01221\u0001\u0000"+
|
||||
"\u0000\u0000\u0123\u0125\u00034\u001a\u0000\u0124\u0126\u00036\u001b\u0000"+
|
||||
"\u0125\u0124\u0001\u0000\u0000\u0000\u0125\u0126\u0001\u0000\u0000\u0000"+
|
||||
"\u01263\u0001\u0000\u0000\u0000\u0127\u0128\u0005(\u0000\u0000\u0128\u0129"+
|
||||
"\u0005\u001f\u0000\u0000\u0129\u012a\u0003\u000e\u0007\u0000\u012a\u012b"+
|
||||
"\u0005 \u0000\u0000\u012b\u012c\u0003\u0014\n\u0000\u012c5\u0001\u0000"+
|
||||
"\u0000\u0000\u012d\u012e\u0005)\u0000\u0000\u012e\u012f\u0003\u0014\n"+
|
||||
"\u0000\u012f7\u0001\u0000\u0000\u0000\u0130\u0131\u0003\u0018\f\u0000"+
|
||||
"\u0131\u0132\u0005\u000f\u0000\u0000\u0132\u0133\u0003\u000e\u0007\u0000"+
|
||||
"\u01339\u0001\u0000\u0000\u0000\u0134\u0135\u0005+\u0000\u0000\u0135\u0136"+
|
||||
"\u0005.\u0000\u0000\u0136\u0137\u0005\u001f\u0000\u0000\u0137\u0138\u0003"+
|
||||
"\f\u0006\u0000\u0138\u0139\u0005 \u0000\u0000\u0139;\u0001\u0000\u0000"+
|
||||
"\u0000\u013a\u013f\u0005&\u0000\u0000\u013b\u013f\u0003\u001c\u000e\u0000"+
|
||||
"\u013c\u013f\u0003:\u001d\u0000\u013d\u013f\u0005.\u0000\u0000\u013e\u013a"+
|
||||
"\u0001\u0000\u0000\u0000\u013e\u013b\u0001\u0000\u0000\u0000\u013e\u013c"+
|
||||
"\u0001\u0000\u0000\u0000\u013e\u013d\u0001\u0000\u0000\u0000\u013f\u0140"+
|
||||
"\u0001\u0000\u0000\u0000\u0140\u0141\u0005\u001e\u0000\u0000\u0141=\u0001"+
|
||||
"\u0000\u0000\u0000\u0142\u0143\u0005.\u0000\u0000\u0143\u0144\u0005\u001f"+
|
||||
"\u0000\u0000\u0144\u0145\u0003\f\u0006\u0000\u0145\u0146\u0005 \u0000"+
|
||||
"\u0000\u0146\u0147\u0005\u001e\u0000\u0000\u0147?\u0001\u0000\u0000\u0000"+
|
||||
"\u0148\u0149\u0005#\u0000\u0000\u0149A\u0001\u0000\u0000\u0000\u014a\u014b"+
|
||||
"\u0007\u0001\u0000\u0000\u014bC\u0001\u0000\u0000\u0000\u014c\u014d\u0007"+
|
||||
"\u0002\u0000\u0000\u014dE\u0001\u0000\u0000\u0000\u014e\u014f\u0005\u0001"+
|
||||
"\u0000\u0000\u014f\u0150\u0005.\u0000\u0000\u0150\u0151\u0005\u0002\u0000"+
|
||||
"\u0000\u0151G\u0001\u0000\u0000\u0000\"KNVX]bgmqv\u0080\u0087\u008e\u0090"+
|
||||
"\u0094\u009d\u00a0\u00a5\u00b9\u00be\u00c2\u00c7\u00ce\u00d3\u00dd\u00e7"+
|
||||
"\u00f2\u00fd\u0107\u010a\u0110\u0118\u0125\u013e";
|
||||
" \u0001!\u0001!\u0001\"\u0001\"\u0001#\u0001#\u0001#\u0001#\u0001#\u0001"+
|
||||
"#\u0001#\u0000\u0002 \"$\u0000\u0002\u0004\u0006\b\n\f\u000e\u0010\u0012"+
|
||||
"\u0014\u0016\u0018\u001a\u001c\u001e \"$&(*,.02468:<>@BDF\u0000\u0003"+
|
||||
"\u0001\u0000\f\r\u0002\u0000\u0007\t--\u0002\u0000\u0002\u0003+,\u0164"+
|
||||
"\u0000I\u0001\u0000\u0000\u0000\u0002N\u0001\u0000\u0000\u0000\u0004b"+
|
||||
"\u0001\u0000\u0000\u0000\u0006m\u0001\u0000\u0000\u0000\b{\u0001\u0000"+
|
||||
"\u0000\u0000\n\u0083\u0001\u0000\u0000\u0000\f\u0090\u0001\u0000\u0000"+
|
||||
"\u0000\u000e\u0094\u0001\u0000\u0000\u0000\u0010\u009d\u0001\u0000\u0000"+
|
||||
"\u0000\u0012\u00a0\u0001\u0000\u0000\u0000\u0014\u00b9\u0001\u0000\u0000"+
|
||||
"\u0000\u0016\u00be\u0001\u0000\u0000\u0000\u0018\u00c2\u0001\u0000\u0000"+
|
||||
"\u0000\u001a\u00c7\u0001\u0000\u0000\u0000\u001c\u00cc\u0001\u0000\u0000"+
|
||||
"\u0000\u001e\u00dd\u0001\u0000\u0000\u0000 \u00df\u0001\u0000\u0000\u0000"+
|
||||
"\"\u00ea\u0001\u0000\u0000\u0000$\u00fd\u0001\u0000\u0000\u0000&\u00ff"+
|
||||
"\u0001\u0000\u0000\u0000(\u0103\u0001\u0000\u0000\u0000*\u0105\u0001\u0000"+
|
||||
"\u0000\u0000,\u010a\u0001\u0000\u0000\u0000.\u0114\u0001\u0000\u0000\u0000"+
|
||||
"0\u011d\u0001\u0000\u0000\u00002\u0123\u0001\u0000\u0000\u00004\u0127"+
|
||||
"\u0001\u0000\u0000\u00006\u012d\u0001\u0000\u0000\u00008\u0130\u0001\u0000"+
|
||||
"\u0000\u0000:\u0134\u0001\u0000\u0000\u0000<\u013e\u0001\u0000\u0000\u0000"+
|
||||
">\u0142\u0001\u0000\u0000\u0000@\u0148\u0001\u0000\u0000\u0000B\u014a"+
|
||||
"\u0001\u0000\u0000\u0000D\u014c\u0001\u0000\u0000\u0000F\u014e\u0001\u0000"+
|
||||
"\u0000\u0000HJ\u0003\u0002\u0001\u0000IH\u0001\u0000\u0000\u0000JK\u0001"+
|
||||
"\u0000\u0000\u0000KI\u0001\u0000\u0000\u0000KL\u0001\u0000\u0000\u0000"+
|
||||
"L\u0001\u0001\u0000\u0000\u0000MO\u0005\u0004\u0000\u0000NM\u0001\u0000"+
|
||||
"\u0000\u0000NO\u0001\u0000\u0000\u0000OP\u0001\u0000\u0000\u0000PQ\u0005"+
|
||||
"$\u0000\u0000QR\u0005-\u0000\u0000RX\u0005 \u0000\u0000SW\u0003\u0004"+
|
||||
"\u0002\u0000TW\u0003,\u0016\u0000UW\u0003\u0006\u0003\u0000VS\u0001\u0000"+
|
||||
"\u0000\u0000VT\u0001\u0000\u0000\u0000VU\u0001\u0000\u0000\u0000WZ\u0001"+
|
||||
"\u0000\u0000\u0000XV\u0001\u0000\u0000\u0000XY\u0001\u0000\u0000\u0000"+
|
||||
"Y]\u0001\u0000\u0000\u0000ZX\u0001\u0000\u0000\u0000[\\\u0005\u0005\u0000"+
|
||||
"\u0000\\^\u0003.\u0017\u0000][\u0001\u0000\u0000\u0000]^\u0001\u0000\u0000"+
|
||||
"\u0000^_\u0001\u0000\u0000\u0000_`\u0005!\u0000\u0000`\u0003\u0001\u0000"+
|
||||
"\u0000\u0000ac\u0005\u0004\u0000\u0000ba\u0001\u0000\u0000\u0000bc\u0001"+
|
||||
"\u0000\u0000\u0000cd\u0001\u0000\u0000\u0000de\u0005-\u0000\u0000eg\u0005"+
|
||||
"\u001e\u0000\u0000fh\u0003\b\u0004\u0000gf\u0001\u0000\u0000\u0000gh\u0001"+
|
||||
"\u0000\u0000\u0000hi\u0001\u0000\u0000\u0000ij\u0005\u001f\u0000\u0000"+
|
||||
"jk\u0003.\u0017\u0000k\u0005\u0001\u0000\u0000\u0000ln\u0005\u0004\u0000"+
|
||||
"\u0000ml\u0001\u0000\u0000\u0000mn\u0001\u0000\u0000\u0000nq\u0001\u0000"+
|
||||
"\u0000\u0000or\u0003B!\u0000pr\u0005\u0006\u0000\u0000qo\u0001\u0000\u0000"+
|
||||
"\u0000qp\u0001\u0000\u0000\u0000rs\u0001\u0000\u0000\u0000st\u0005-\u0000"+
|
||||
"\u0000tv\u0005\u001e\u0000\u0000uw\u0003\b\u0004\u0000vu\u0001\u0000\u0000"+
|
||||
"\u0000vw\u0001\u0000\u0000\u0000wx\u0001\u0000\u0000\u0000xy\u0005\u001f"+
|
||||
"\u0000\u0000yz\u0003.\u0017\u0000z\u0007\u0001\u0000\u0000\u0000{\u0080"+
|
||||
"\u0003\n\u0005\u0000|}\u0005#\u0000\u0000}\u007f\u0003\n\u0005\u0000~"+
|
||||
"|\u0001\u0000\u0000\u0000\u007f\u0082\u0001\u0000\u0000\u0000\u0080~\u0001"+
|
||||
"\u0000\u0000\u0000\u0080\u0081\u0001\u0000\u0000\u0000\u0081\t\u0001\u0000"+
|
||||
"\u0000\u0000\u0082\u0080\u0001\u0000\u0000\u0000\u0083\u0084\u0003B!\u0000"+
|
||||
"\u0084\u0085\u0005-\u0000\u0000\u0085\u000b\u0001\u0000\u0000\u0000\u0086"+
|
||||
"\u0088\u0003\u000e\u0007\u0000\u0087\u0086\u0001\u0000\u0000\u0000\u0087"+
|
||||
"\u0088\u0001\u0000\u0000\u0000\u0088\u0091\u0001\u0000\u0000\u0000\u0089"+
|
||||
"\u008c\u0003\u000e\u0007\u0000\u008a\u008b\u0005#\u0000\u0000\u008b\u008d"+
|
||||
"\u0003\u000e\u0007\u0000\u008c\u008a\u0001\u0000\u0000\u0000\u008d\u008e"+
|
||||
"\u0001\u0000\u0000\u0000\u008e\u008c\u0001\u0000\u0000\u0000\u008e\u008f"+
|
||||
"\u0001\u0000\u0000\u0000\u008f\u0091\u0001\u0000\u0000\u0000\u0090\u0087"+
|
||||
"\u0001\u0000\u0000\u0000\u0090\u0089\u0001\u0000\u0000\u0000\u0091\r\u0001"+
|
||||
"\u0000\u0000\u0000\u0092\u0095\u0003\u0010\b\u0000\u0093\u0095\u0003\u001e"+
|
||||
"\u000f\u0000\u0094\u0092\u0001\u0000\u0000\u0000\u0094\u0093\u0001\u0000"+
|
||||
"\u0000\u0000\u0095\u000f\u0001\u0000\u0000\u0000\u0096\u009e\u0005%\u0000"+
|
||||
"\u0000\u0097\u009e\u0003\u0018\f\u0000\u0098\u009e\u0003\u0016\u000b\u0000"+
|
||||
"\u0099\u009a\u0005\u001e\u0000\u0000\u009a\u009b\u0003\u0010\b\u0000\u009b"+
|
||||
"\u009c\u0005\u001f\u0000\u0000\u009c\u009e\u0001\u0000\u0000\u0000\u009d"+
|
||||
"\u0096\u0001\u0000\u0000\u0000\u009d\u0097\u0001\u0000\u0000\u0000\u009d"+
|
||||
"\u0098\u0001\u0000\u0000\u0000\u009d\u0099\u0001\u0000\u0000\u0000\u009e"+
|
||||
"\u0011\u0001\u0000\u0000\u0000\u009f\u00a1\u0003<\u001e\u0000\u00a0\u009f"+
|
||||
"\u0001\u0000\u0000\u0000\u00a0\u00a1\u0001\u0000\u0000\u0000\u00a1\u00a5"+
|
||||
"\u0001\u0000\u0000\u0000\u00a2\u00a4\u0003>\u001f\u0000\u00a3\u00a2\u0001"+
|
||||
"\u0000\u0000\u0000\u00a4\u00a7\u0001\u0000\u0000\u0000\u00a5\u00a3\u0001"+
|
||||
"\u0000\u0000\u0000\u00a5\u00a6\u0001\u0000\u0000\u0000\u00a6\u00a8\u0001"+
|
||||
"\u0000\u0000\u0000\u00a7\u00a5\u0001\u0000\u0000\u0000\u00a8\u00a9\u0005"+
|
||||
"-\u0000\u0000\u00a9\u00aa\u0005\u001e\u0000\u0000\u00aa\u00ab\u0003\f"+
|
||||
"\u0006\u0000\u00ab\u00ac\u0005\u001f\u0000\u0000\u00ac\u0013\u0001\u0000"+
|
||||
"\u0000\u0000\u00ad\u00ae\u0003*\u0015\u0000\u00ae\u00af\u0005\"\u0000"+
|
||||
"\u0000\u00af\u00ba\u0001\u0000\u0000\u0000\u00b0\u00ba\u0003,\u0016\u0000"+
|
||||
"\u00b1\u00ba\u0003.\u0017\u0000\u00b2\u00ba\u00030\u0018\u0000\u00b3\u00ba"+
|
||||
"\u00032\u0019\u0000\u00b4\u00ba\u0003F#\u0000\u00b5\u00b6\u0003\u0016"+
|
||||
"\u000b\u0000\u00b6\u00b7\u0005\"\u0000\u0000\u00b7\u00ba\u0001\u0000\u0000"+
|
||||
"\u0000\u00b8\u00ba\u0003@ \u0000\u00b9\u00ad\u0001\u0000\u0000\u0000\u00b9"+
|
||||
"\u00b0\u0001\u0000\u0000\u0000\u00b9\u00b1\u0001\u0000\u0000\u0000\u00b9"+
|
||||
"\u00b2\u0001\u0000\u0000\u0000\u00b9\u00b3\u0001\u0000\u0000\u0000\u00b9"+
|
||||
"\u00b4\u0001\u0000\u0000\u0000\u00b9\u00b5\u0001\u0000\u0000\u0000\u00b9"+
|
||||
"\u00b8\u0001\u0000\u0000\u0000\u00ba\u0015\u0001\u0000\u0000\u0000\u00bb"+
|
||||
"\u00bf\u00038\u001c\u0000\u00bc\u00bf\u0003:\u001d\u0000\u00bd\u00bf\u0003"+
|
||||
"\u0012\t\u0000\u00be\u00bb\u0001\u0000\u0000\u0000\u00be\u00bc\u0001\u0000"+
|
||||
"\u0000\u0000\u00be\u00bd\u0001\u0000\u0000\u0000\u00bf\u0017\u0001\u0000"+
|
||||
"\u0000\u0000\u00c0\u00c3\u0005-\u0000\u0000\u00c1\u00c3\u0003\u001c\u000e"+
|
||||
"\u0000\u00c2\u00c0\u0001\u0000\u0000\u0000\u00c2\u00c1\u0001\u0000\u0000"+
|
||||
"\u0000\u00c3\u0019\u0001\u0000\u0000\u0000\u00c4\u00c8\u0005%\u0000\u0000"+
|
||||
"\u00c5\u00c8\u0003:\u001d\u0000\u00c6\u00c8\u0005-\u0000\u0000\u00c7\u00c4"+
|
||||
"\u0001\u0000\u0000\u0000\u00c7\u00c5\u0001\u0000\u0000\u0000\u00c7\u00c6"+
|
||||
"\u0001\u0000\u0000\u0000\u00c8\u00c9\u0001\u0000\u0000\u0000\u00c9\u00ca"+
|
||||
"\u0005\u001d\u0000\u0000\u00ca\u001b\u0001\u0000\u0000\u0000\u00cb\u00cd"+
|
||||
"\u0003\u001a\r\u0000\u00cc\u00cb\u0001\u0000\u0000\u0000\u00cd\u00ce\u0001"+
|
||||
"\u0000\u0000\u0000\u00ce\u00cc\u0001\u0000\u0000\u0000\u00ce\u00cf\u0001"+
|
||||
"\u0000\u0000\u0000\u00cf\u00d3\u0001\u0000\u0000\u0000\u00d0\u00d2\u0003"+
|
||||
">\u001f\u0000\u00d1\u00d0\u0001\u0000\u0000\u0000\u00d2\u00d5\u0001\u0000"+
|
||||
"\u0000\u0000\u00d3\u00d1\u0001\u0000\u0000\u0000\u00d3\u00d4\u0001\u0000"+
|
||||
"\u0000\u0000\u00d4\u00d6\u0001\u0000\u0000\u0000\u00d5\u00d3\u0001\u0000"+
|
||||
"\u0000\u0000\u00d6\u00d7\u0005-\u0000\u0000\u00d7\u001d\u0001\u0000\u0000"+
|
||||
"\u0000\u00d8\u00de\u0003 \u0010\u0000\u00d9\u00de\u0003&\u0013\u0000\u00da"+
|
||||
"\u00de\u0003D\"\u0000\u00db\u00dc\u0005\u001a\u0000\u0000\u00dc\u00de"+
|
||||
"\u0003\u001e\u000f\u0000\u00dd\u00d8\u0001\u0000\u0000\u0000\u00dd\u00d9"+
|
||||
"\u0001\u0000\u0000\u0000\u00dd\u00da\u0001\u0000\u0000\u0000\u00dd\u00db"+
|
||||
"\u0001\u0000\u0000\u0000\u00de\u001f\u0001\u0000\u0000\u0000\u00df\u00e0"+
|
||||
"\u0006\u0010\uffff\uffff\u0000\u00e0\u00e1\u0003\"\u0011\u0000\u00e1\u00e7"+
|
||||
"\u0001\u0000\u0000\u0000\u00e2\u00e3\n\u0002\u0000\u0000\u00e3\u00e4\u0005"+
|
||||
"\u000b\u0000\u0000\u00e4\u00e6\u0003\"\u0011\u0000\u00e5\u00e2\u0001\u0000"+
|
||||
"\u0000\u0000\u00e6\u00e9\u0001\u0000\u0000\u0000\u00e7\u00e5\u0001\u0000"+
|
||||
"\u0000\u0000\u00e7\u00e8\u0001\u0000\u0000\u0000\u00e8!\u0001\u0000\u0000"+
|
||||
"\u0000\u00e9\u00e7\u0001\u0000\u0000\u0000\u00ea\u00eb\u0006\u0011\uffff"+
|
||||
"\uffff\u0000\u00eb\u00ec\u0003$\u0012\u0000\u00ec\u00f2\u0001\u0000\u0000"+
|
||||
"\u0000\u00ed\u00ee\n\u0002\u0000\u0000\u00ee\u00ef\u0005\n\u0000\u0000"+
|
||||
"\u00ef\u00f1\u0003$\u0012\u0000\u00f0\u00ed\u0001\u0000\u0000\u0000\u00f1"+
|
||||
"\u00f4\u0001\u0000\u0000\u0000\u00f2\u00f0\u0001\u0000\u0000\u0000\u00f2"+
|
||||
"\u00f3\u0001\u0000\u0000\u0000\u00f3#\u0001\u0000\u0000\u0000\u00f4\u00f2"+
|
||||
"\u0001\u0000\u0000\u0000\u00f5\u00fe\u0005+\u0000\u0000\u00f6\u00fe\u0005"+
|
||||
"-\u0000\u0000\u00f7\u00fe\u0003\u001c\u000e\u0000\u00f8\u00fe\u0003\u0012"+
|
||||
"\t\u0000\u00f9\u00fa\u0005\u001e\u0000\u0000\u00fa\u00fb\u0003 \u0010"+
|
||||
"\u0000\u00fb\u00fc\u0005\u001f\u0000\u0000\u00fc\u00fe\u0001\u0000\u0000"+
|
||||
"\u0000\u00fd\u00f5\u0001\u0000\u0000\u0000\u00fd\u00f6\u0001\u0000\u0000"+
|
||||
"\u0000\u00fd\u00f7\u0001\u0000\u0000\u0000\u00fd\u00f8\u0001\u0000\u0000"+
|
||||
"\u0000\u00fd\u00f9\u0001\u0000\u0000\u0000\u00fe%\u0001\u0000\u0000\u0000"+
|
||||
"\u00ff\u0100\u0003\u0010\b\u0000\u0100\u0101\u0003(\u0014\u0000\u0101"+
|
||||
"\u0102\u0003\u000e\u0007\u0000\u0102\'\u0001\u0000\u0000\u0000\u0103\u0104"+
|
||||
"\u0007\u0000\u0000\u0000\u0104)\u0001\u0000\u0000\u0000\u0105\u0107\u0005"+
|
||||
")\u0000\u0000\u0106\u0108\u0003\u000e\u0007\u0000\u0107\u0106\u0001\u0000"+
|
||||
"\u0000\u0000\u0107\u0108\u0001\u0000\u0000\u0000\u0108+\u0001\u0000\u0000"+
|
||||
"\u0000\u0109\u010b\u0005\u0004\u0000\u0000\u010a\u0109\u0001\u0000\u0000"+
|
||||
"\u0000\u010a\u010b\u0001\u0000\u0000\u0000\u010b\u010c\u0001\u0000\u0000"+
|
||||
"\u0000\u010c\u010d\u0003B!\u0000\u010d\u0110\u0005-\u0000\u0000\u010e"+
|
||||
"\u010f\u0005\u000e\u0000\u0000\u010f\u0111\u0003\u000e\u0007\u0000\u0110"+
|
||||
"\u010e\u0001\u0000\u0000\u0000\u0110\u0111\u0001\u0000\u0000\u0000\u0111"+
|
||||
"\u0112\u0001\u0000\u0000\u0000\u0112\u0113\u0005\"\u0000\u0000\u0113-"+
|
||||
"\u0001\u0000\u0000\u0000\u0114\u0118\u0005 \u0000\u0000\u0115\u0117\u0003"+
|
||||
"\u0014\n\u0000\u0116\u0115\u0001\u0000\u0000\u0000\u0117\u011a\u0001\u0000"+
|
||||
"\u0000\u0000\u0118\u0116\u0001\u0000\u0000\u0000\u0118\u0119\u0001\u0000"+
|
||||
"\u0000\u0000\u0119\u011b\u0001\u0000\u0000\u0000\u011a\u0118\u0001\u0000"+
|
||||
"\u0000\u0000\u011b\u011c\u0005!\u0000\u0000\u011c/\u0001\u0000\u0000\u0000"+
|
||||
"\u011d\u011e\u0005&\u0000\u0000\u011e\u011f\u0005\u001e\u0000\u0000\u011f"+
|
||||
"\u0120\u0003\u000e\u0007\u0000\u0120\u0121\u0005\u001f\u0000\u0000\u0121"+
|
||||
"\u0122\u0003\u0014\n\u0000\u01221\u0001\u0000\u0000\u0000\u0123\u0125"+
|
||||
"\u00034\u001a\u0000\u0124\u0126\u00036\u001b\u0000\u0125\u0124\u0001\u0000"+
|
||||
"\u0000\u0000\u0125\u0126\u0001\u0000\u0000\u0000\u01263\u0001\u0000\u0000"+
|
||||
"\u0000\u0127\u0128\u0005\'\u0000\u0000\u0128\u0129\u0005\u001e\u0000\u0000"+
|
||||
"\u0129\u012a\u0003\u000e\u0007\u0000\u012a\u012b\u0005\u001f\u0000\u0000"+
|
||||
"\u012b\u012c\u0003\u0014\n\u0000\u012c5\u0001\u0000\u0000\u0000\u012d"+
|
||||
"\u012e\u0005(\u0000\u0000\u012e\u012f\u0003\u0014\n\u0000\u012f7\u0001"+
|
||||
"\u0000\u0000\u0000\u0130\u0131\u0003\u0018\f\u0000\u0131\u0132\u0005\u000e"+
|
||||
"\u0000\u0000\u0132\u0133\u0003\u000e\u0007\u0000\u01339\u0001\u0000\u0000"+
|
||||
"\u0000\u0134\u0135\u0005*\u0000\u0000\u0135\u0136\u0005-\u0000\u0000\u0136"+
|
||||
"\u0137\u0005\u001e\u0000\u0000\u0137\u0138\u0003\f\u0006\u0000\u0138\u0139"+
|
||||
"\u0005\u001f\u0000\u0000\u0139;\u0001\u0000\u0000\u0000\u013a\u013f\u0005"+
|
||||
"%\u0000\u0000\u013b\u013f\u0003\u001c\u000e\u0000\u013c\u013f\u0003:\u001d"+
|
||||
"\u0000\u013d\u013f\u0005-\u0000\u0000\u013e\u013a\u0001\u0000\u0000\u0000"+
|
||||
"\u013e\u013b\u0001\u0000\u0000\u0000\u013e\u013c\u0001\u0000\u0000\u0000"+
|
||||
"\u013e\u013d\u0001\u0000\u0000\u0000\u013f\u0140\u0001\u0000\u0000\u0000"+
|
||||
"\u0140\u0141\u0005\u001d\u0000\u0000\u0141=\u0001\u0000\u0000\u0000\u0142"+
|
||||
"\u0143\u0005-\u0000\u0000\u0143\u0144\u0005\u001e\u0000\u0000\u0144\u0145"+
|
||||
"\u0003\f\u0006\u0000\u0145\u0146\u0005\u001f\u0000\u0000\u0146\u0147\u0005"+
|
||||
"\u001d\u0000\u0000\u0147?\u0001\u0000\u0000\u0000\u0148\u0149\u0005\""+
|
||||
"\u0000\u0000\u0149A\u0001\u0000\u0000\u0000\u014a\u014b\u0007\u0001\u0000"+
|
||||
"\u0000\u014bC\u0001\u0000\u0000\u0000\u014c\u014d\u0007\u0002\u0000\u0000"+
|
||||
"\u014dE\u0001\u0000\u0000\u0000\u014e\u014f\u0005\u0001\u0000\u0000\u014f"+
|
||||
"\u0150\u0005\u001e\u0000\u0000\u0150\u0151\u0005-\u0000\u0000\u0151\u0152"+
|
||||
"\u0005\u001f\u0000\u0000\u0152\u0153\u0005\"\u0000\u0000\u0153G\u0001"+
|
||||
"\u0000\u0000\u0000\"KNVX]bgmqv\u0080\u0087\u008e\u0090\u0094\u009d\u00a0"+
|
||||
"\u00a5\u00b9\u00be\u00c2\u00c7\u00ce\u00d3\u00dd\u00e7\u00f2\u00fd\u0107"+
|
||||
"\u010a\u0110\u0118\u0125\u013e";
|
||||
public static final ATN _ATN =
|
||||
new ATNDeserializer().deserialize(_serializedATN.toCharArray());
|
||||
static {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package AST;
|
||||
import ASTs.emptyClassAST;
|
||||
import ASTs.*;
|
||||
import abstractSyntaxTree.Program;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -11,6 +11,48 @@ public class testAll {
|
||||
this.astComparer = new AstComparer("src/test/resources");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAssignWrongType(){
|
||||
Program ast = AssignWrongTypeAST.getProgram();
|
||||
String pathToCode = "failTests/AssignWrongType.java";
|
||||
testAst(ast, pathToCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharArgument(){
|
||||
Program ast = CharArgumentAST.getProgram();
|
||||
String pathToCode = "SimpleTests/CharArgument.java";
|
||||
testAst(ast, pathToCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassWithMain(){
|
||||
Program ast = ClassWithMainAST.getProgram();
|
||||
String pathToCode = "basicClasses/classWithMain.java";
|
||||
testAst(ast, pathToCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorThisDot(){
|
||||
Program ast = ConstructorThisDotAST.getProgram();
|
||||
String pathToCode = "SimpleTests/ConstructorThisDot.java";
|
||||
testAst(ast, pathToCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorParams(){
|
||||
Program ast = ConstructorParamsAST.getProgram();
|
||||
String pathToCode = "SimpleTests/ConstructorParams.java";
|
||||
testAst(ast, pathToCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDivideByZero(){
|
||||
Program ast = DivideByZeroAST.getProgram();
|
||||
String pathToCode = "failTests/DivideByzero.java";
|
||||
testAst(ast, pathToCode);
|
||||
}
|
||||
@Test
|
||||
public void testEmptyClass(){
|
||||
Program ast = emptyClassAST.getEmptyProgramm();
|
||||
@@ -20,10 +62,32 @@ public class testAll {
|
||||
|
||||
@Test
|
||||
public void testEmptyClassWithConstructor(){
|
||||
Program ast = emptyClassAST.getEmptyProgramm();
|
||||
Program ast = EmptyClassWithConstructorAST.getProgram();
|
||||
String pathToCode = "basicClasses/emptyClassWithConstructor.java";
|
||||
testAst(ast, pathToCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFakultaet(){
|
||||
Program ast = FakultaetAST.getProgram();
|
||||
String pathToCode = "basicClasses/Fakultaet.java";
|
||||
testAst(ast, pathToCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldVariable(){
|
||||
Program ast = FieldVarAST.getProgram();
|
||||
String pathToCode = "SimpleTests/FieldVar.java";
|
||||
testAst(ast, pathToCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfElseIfStatementWithOneReturne(){
|
||||
Program ast = IfElseIfStatementWithOneReturnAST.getProgram();
|
||||
String pathToCode = "SimpleTests/IfElseIfStatementWithOneReturn.java";
|
||||
testAst(ast, pathToCode);
|
||||
}
|
||||
|
||||
public void testAst(Program ast, String pathToCode)
|
||||
{
|
||||
|
||||
|
||||
59
src/test/java/ASTs/AssignWrongTypeAST.java
Normal file
59
src/test/java/ASTs/AssignWrongTypeAST.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package ASTs;
|
||||
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Expression.BooleanConstantExpression;
|
||||
import abstractSyntaxTree.Expression.IntConstantExpression;
|
||||
import abstractSyntaxTree.Expression.LocalVarIdentifier;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
import abstractSyntaxTree.Statement.IStatement;
|
||||
import abstractSyntaxTree.Statement.LocalVarDecl;
|
||||
import abstractSyntaxTree.Statement.ReturnStatement;
|
||||
import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AssignWrongTypeAST {
|
||||
public static Program getProgram(){
|
||||
|
||||
// TestMethod
|
||||
//Expressions
|
||||
// 0
|
||||
IntConstantExpression intConstantExpression0 = new IntConstantExpression(1);
|
||||
LocalVarDecl localVarDecl = new LocalVarDecl("int", "x", intConstantExpression0);
|
||||
|
||||
//1
|
||||
LocalVarIdentifier localVarIdentifier0 = new LocalVarIdentifier("x");
|
||||
BooleanConstantExpression booleanConstantExpression0 = new BooleanConstantExpression(true);
|
||||
AssignStatementExpression assignStatementExpression0 = new AssignStatementExpression("=", localVarIdentifier0, booleanConstantExpression0);
|
||||
|
||||
//2
|
||||
ReturnStatement returnStatement0 = new ReturnStatement(localVarIdentifier0);
|
||||
|
||||
String classThatContainsMethod = "AssignWrongType";
|
||||
String nameMethod0 = "test";
|
||||
String returnType = "int";
|
||||
ParameterList parameterList = new ParameterList(new ArrayList<>());
|
||||
List<IStatement> iStatementList = new ArrayList<>();
|
||||
iStatementList.add(localVarDecl);
|
||||
iStatementList.add(assignStatementExpression0);
|
||||
iStatementList.add(returnStatement0);
|
||||
BlockStatement codeBlock = new BlockStatement(iStatementList, null);
|
||||
MethodDecl test = new MethodDecl(classThatContainsMethod, returnType, nameMethod0, parameterList, codeBlock);
|
||||
|
||||
String name = "AssignWrongType";
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(test);
|
||||
boolean hasMain = false;
|
||||
RefType assignWrongType = new RefType(name, fieldDeclList, methodDeclList, hasMain);
|
||||
List<RefType> refTypeList = new ArrayList<>();
|
||||
refTypeList.add(assignWrongType);
|
||||
Program program = new Program(refTypeList);
|
||||
return program;
|
||||
}
|
||||
}
|
||||
77
src/test/java/ASTs/AssignWrongTypeASTTyped.java
Normal file
77
src/test/java/ASTs/AssignWrongTypeASTTyped.java
Normal file
@@ -0,0 +1,77 @@
|
||||
package ASTs;
|
||||
|
||||
import Typecheck.TypingHelper;
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Expression.BooleanConstantExpression;
|
||||
import abstractSyntaxTree.Expression.IntConstantExpression;
|
||||
import abstractSyntaxTree.Expression.LocalVarIdentifier;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
import abstractSyntaxTree.Statement.IStatement;
|
||||
import abstractSyntaxTree.Statement.LocalVarDecl;
|
||||
import abstractSyntaxTree.Statement.ReturnStatement;
|
||||
import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class AssignWrongTypeASTTyped {
|
||||
public static Program getProgram(){
|
||||
|
||||
// TestMethod
|
||||
//Expressions
|
||||
// 0
|
||||
IntConstantExpression intConstantExpression0 = new IntConstantExpression(1);
|
||||
LocalVarDecl localVarDecl = new LocalVarDecl("int", "x", intConstantExpression0);
|
||||
|
||||
//1
|
||||
LocalVarIdentifier localVarIdentifier0 = new LocalVarIdentifier("x");
|
||||
BooleanConstantExpression booleanConstantExpression0 = new BooleanConstantExpression(true);
|
||||
AssignStatementExpression assignStatementExpression0 = new AssignStatementExpression("=", localVarIdentifier0, booleanConstantExpression0);
|
||||
|
||||
//2
|
||||
ReturnStatement returnStatement0 = new ReturnStatement(localVarIdentifier0);
|
||||
|
||||
String classThatContainsMethod = "AssignWrongType";
|
||||
String nameMethod0 = "test";
|
||||
String returnType = "int";
|
||||
ParameterList parameterList = new ParameterList(new ArrayList<>());
|
||||
List<IStatement> iStatementList = new ArrayList<>();
|
||||
iStatementList.add(localVarDecl);
|
||||
iStatementList.add(assignStatementExpression0);
|
||||
iStatementList.add(returnStatement0);
|
||||
BlockStatement codeBlock = new BlockStatement(iStatementList, null);
|
||||
MethodDecl test = new MethodDecl(classThatContainsMethod, returnType, nameMethod0, parameterList, codeBlock);
|
||||
|
||||
String name = "AssignWrongType";
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(test);
|
||||
boolean hasMain = false;
|
||||
RefType assignWrongType = new RefType(name, fieldDeclList, methodDeclList, hasMain);
|
||||
List<RefType> refTypeList = new ArrayList<>();
|
||||
refTypeList.add(assignWrongType);
|
||||
Program program = new Program(refTypeList);
|
||||
|
||||
addTyping(program);
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
public static void addTyping(Program program){
|
||||
//Type Context
|
||||
TypingHelper.addTypeContext(program, "AssignWrongType", new HashMap<>());
|
||||
|
||||
|
||||
//Method Context
|
||||
HashMap<String, ParameterList> method0 = new HashMap<>();
|
||||
method0.put("int", new ParameterList(new ArrayList<>()));
|
||||
HashMap<String, HashMap<String, ParameterList>> methods = new HashMap<>();
|
||||
methods.put("test", method0);
|
||||
TypingHelper.addMethodContext(program, "AssignWrongType", methods);
|
||||
}
|
||||
}
|
||||
73
src/test/java/ASTs/CharArgumentAST.java
Normal file
73
src/test/java/ASTs/CharArgumentAST.java
Normal file
@@ -0,0 +1,73 @@
|
||||
package ASTs;
|
||||
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Expression.*;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
import abstractSyntaxTree.Statement.IStatement;
|
||||
import abstractSyntaxTree.Statement.ReturnStatement;
|
||||
import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
|
||||
import abstractSyntaxTree.StatementExpression.MethodCallStatementExpression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CharArgumentAST {
|
||||
public static Program getProgram() {
|
||||
|
||||
List<RefType> classes = new ArrayList<>();
|
||||
classes.add(getRefType());
|
||||
Program program = new Program(classes);
|
||||
return program;
|
||||
}
|
||||
|
||||
public static RefType getRefType() {
|
||||
FieldDecl fieldDecl0 = new FieldDecl("char", "c", null);
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
fieldDeclList.add(fieldDecl0);
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(method0());
|
||||
methodDeclList.add(method1());
|
||||
RefType charArgumentClass = new RefType("CharArgument", fieldDeclList, methodDeclList, false);
|
||||
|
||||
return charArgumentClass;
|
||||
}
|
||||
|
||||
public static MethodDecl method0(){
|
||||
SubReceiver subReceiver0 =new SubReceiver(true);
|
||||
List<SubReceiver> subReceiverList0 = new ArrayList<>();
|
||||
subReceiverList0.add(subReceiver0);
|
||||
InstVarExpression instVarExpression0 = new InstVarExpression(subReceiverList0, new ArrayList<>(), "c");
|
||||
CharConstantExpression charConstantExpression0 = new CharConstantExpression('a');
|
||||
List<IExpression> argumentList0 = new ArrayList<>();
|
||||
argumentList0.add(charConstantExpression0);
|
||||
MethodCallStatementExpression methodCallStatementExpression0 = new MethodCallStatementExpression("foo", null, new ArrayList<>(), argumentList0);
|
||||
AssignStatementExpression assignStatementExpression0 = new AssignStatementExpression("=", instVarExpression0,methodCallStatementExpression0);
|
||||
List<IStatement> iStatementList0 = new ArrayList<>();
|
||||
iStatementList0.add(assignStatementExpression0);
|
||||
BlockStatement blockStatement0 = new BlockStatement(iStatementList0, null);
|
||||
MethodDecl methodDecl0 =new MethodDecl("CharArgument", null,
|
||||
"CharArgument", new ParameterList(new ArrayList<>()), blockStatement0);
|
||||
|
||||
return methodDecl0;
|
||||
}
|
||||
|
||||
public static MethodDecl method1(){
|
||||
ReturnStatement returnStatement0 =new ReturnStatement(new LocalVarIdentifier("c"));
|
||||
List<IStatement> iStatementList0 =new ArrayList<>();
|
||||
iStatementList0.add(returnStatement0);
|
||||
BlockStatement blockStatement0 = new BlockStatement(iStatementList0, null);
|
||||
Parameter parameter00 = new Parameter("char", "c");
|
||||
List<Parameter> parameterList0 = new ArrayList<>();
|
||||
parameterList0.add(parameter00);
|
||||
ParameterList parameterListObj0 = new ParameterList(parameterList0);
|
||||
MethodDecl methodDecl = new MethodDecl("CharArgument", "char", "foo",
|
||||
parameterListObj0, blockStatement0);
|
||||
|
||||
return methodDecl;
|
||||
}
|
||||
}
|
||||
100
src/test/java/ASTs/CharArgumentASTTyped.java
Normal file
100
src/test/java/ASTs/CharArgumentASTTyped.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package ASTs;
|
||||
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import Typecheck.TypingHelper;
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Expression.*;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
import abstractSyntaxTree.Statement.IStatement;
|
||||
import abstractSyntaxTree.Statement.ReturnStatement;
|
||||
import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
|
||||
import abstractSyntaxTree.StatementExpression.MethodCallStatementExpression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class CharArgumentASTTyped {
|
||||
public static Program getProgram() {
|
||||
|
||||
List<RefType> classes = new ArrayList<>();
|
||||
classes.add(getRefType());
|
||||
Program program = new Program(classes);
|
||||
addTyping(program);
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
public static RefType getRefType() {
|
||||
FieldDecl fieldDecl0 = new FieldDecl("char", "c", null);
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
fieldDeclList.add(fieldDecl0);
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(method0());
|
||||
methodDeclList.add(method1());
|
||||
RefType charArgumentClass = new RefType("CharArgument", fieldDeclList, methodDeclList, false);
|
||||
|
||||
return charArgumentClass;
|
||||
}
|
||||
|
||||
public static MethodDecl method0(){
|
||||
SubReceiver subReceiver0 =new SubReceiver(true);
|
||||
List<SubReceiver> subReceiverList0 = new ArrayList<>();
|
||||
subReceiverList0.add(subReceiver0);
|
||||
InstVarExpression instVarExpression0 = new InstVarExpression(subReceiverList0, new ArrayList<>(), "c");
|
||||
instVarExpression0.thisClass = "CharArgument";
|
||||
CharConstantExpression charConstantExpression0 = new CharConstantExpression('a');
|
||||
List<IExpression> argumentList0 = new ArrayList<>();
|
||||
charConstantExpression0.setTypeCheckResult(new TypeCheckResult("char"));
|
||||
argumentList0.add(charConstantExpression0);
|
||||
MethodCallStatementExpression methodCallStatementExpression0 = new MethodCallStatementExpression("foo", null, new ArrayList<>(), argumentList0);
|
||||
methodCallStatementExpression0.thisClass = "CharArgument";
|
||||
AssignStatementExpression assignStatementExpression0 = new AssignStatementExpression("=", instVarExpression0,methodCallStatementExpression0);
|
||||
List<IStatement> iStatementList0 = new ArrayList<>();
|
||||
iStatementList0.add(assignStatementExpression0);
|
||||
BlockStatement blockStatement0 = new BlockStatement(iStatementList0, "void");
|
||||
MethodDecl methodDecl0 =new MethodDecl("CharArgument", null,
|
||||
"CharArgument", new ParameterList(new ArrayList<>()), blockStatement0);
|
||||
|
||||
return methodDecl0;
|
||||
}
|
||||
|
||||
public static MethodDecl method1(){
|
||||
LocalVarIdentifier localVarIdentifierC = new LocalVarIdentifier("c");
|
||||
localVarIdentifierC.setTypeCheckResult(new TypeCheckResult("char"));
|
||||
ReturnStatement returnStatement0 =new ReturnStatement(localVarIdentifierC);
|
||||
List<IStatement> iStatementList0 =new ArrayList<>();
|
||||
iStatementList0.add(returnStatement0);
|
||||
BlockStatement blockStatement0 = new BlockStatement(iStatementList0, "char");
|
||||
Parameter parameter00 = new Parameter("char", "c");
|
||||
List<Parameter> parameterList0 = new ArrayList<>();
|
||||
parameterList0.add(parameter00);
|
||||
ParameterList parameterListObj0 = new ParameterList(parameterList0);
|
||||
MethodDecl methodDecl = new MethodDecl("CharArgument", "char", "foo",
|
||||
parameterListObj0, blockStatement0);
|
||||
|
||||
return methodDecl;
|
||||
}
|
||||
|
||||
public static void addTyping(Program program){
|
||||
// TypeContext
|
||||
HashMap<String, String> charArgumentMap0 = new HashMap<>();
|
||||
charArgumentMap0.put("c", "char");
|
||||
TypingHelper.addTypeContext(program, "CharArgument", charArgumentMap0);
|
||||
|
||||
// MethodContext
|
||||
HashMap<String, ParameterList> method0 = new HashMap<>();
|
||||
List<Parameter> parameterList0 = new ArrayList<>();
|
||||
parameterList0.add(new Parameter("char", "c"));
|
||||
ParameterList parameterListObj0 = new ParameterList(parameterList0);
|
||||
method0.put("char", parameterListObj0);
|
||||
HashMap<String, HashMap<String, ParameterList>> methods = new HashMap<>();
|
||||
methods.put("foo", method0);
|
||||
TypingHelper.addMethodContext(program, "CharArgument", methods);
|
||||
}
|
||||
}
|
||||
41
src/test/java/ASTs/ClassWithMainAST.java
Normal file
41
src/test/java/ASTs/ClassWithMainAST.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package ASTs;
|
||||
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ClassWithMainAST {
|
||||
|
||||
public static Program getProgram() {
|
||||
List<RefType> refTypeList = new ArrayList<>();
|
||||
refTypeList.add(getRefType());
|
||||
Program program = new Program(refTypeList);
|
||||
|
||||
return program;
|
||||
}
|
||||
public static RefType getRefType(){
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(method0());
|
||||
RefType classWithMain = new RefType("classWithMain", fieldDeclList, methodDeclList, true);
|
||||
|
||||
return classWithMain;
|
||||
}
|
||||
|
||||
public static MethodDecl method0(){
|
||||
BlockStatement blockStatement = new BlockStatement(new ArrayList<>(), null);
|
||||
List<Parameter> parameterList = new ArrayList<>();
|
||||
ParameterList parameterListObj = new ParameterList(parameterList);
|
||||
MethodDecl methodDecl =new MethodDecl("classWithMain", "void", "main",
|
||||
parameterListObj, blockStatement);
|
||||
|
||||
return methodDecl;
|
||||
}
|
||||
}
|
||||
51
src/test/java/ASTs/ClassWithMainASTTyped.java
Normal file
51
src/test/java/ASTs/ClassWithMainASTTyped.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package ASTs;
|
||||
|
||||
import Typecheck.TypingHelper;
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class ClassWithMainASTTyped {
|
||||
public static Program getProgram() {
|
||||
List<RefType> refTypeList = new ArrayList<>();
|
||||
refTypeList.add(getRefType());
|
||||
Program program = new Program(refTypeList);
|
||||
addTyping(program);
|
||||
return program;
|
||||
}
|
||||
public static RefType getRefType(){
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(method0());
|
||||
RefType classWithMain = new RefType("classWithMain", fieldDeclList, methodDeclList, true);
|
||||
|
||||
return classWithMain;
|
||||
}
|
||||
|
||||
public static MethodDecl method0(){
|
||||
BlockStatement blockStatement = new BlockStatement(new ArrayList<>(), "void");
|
||||
List<Parameter> parameterList = new ArrayList<>();
|
||||
ParameterList parameterListObj = new ParameterList(parameterList);
|
||||
MethodDecl methodDecl =new MethodDecl("classWithMain", "void", "main",
|
||||
parameterListObj, blockStatement);
|
||||
|
||||
return methodDecl;
|
||||
}
|
||||
|
||||
public static void addTyping(Program program){
|
||||
TypingHelper.addTypeContext(program, "classWithMain", new HashMap<>());
|
||||
HashMap<String, ParameterList> method0 = new HashMap<>();
|
||||
method0.put("void", new ParameterList(new ArrayList<>()));
|
||||
HashMap<String, HashMap<String, ParameterList>> methods = new HashMap<>();
|
||||
methods.put("main", method0);
|
||||
TypingHelper.addMethodContext(program, "classWithMain", methods);
|
||||
}
|
||||
}
|
||||
45
src/test/java/ASTs/ConstructorParamsAST.java
Normal file
45
src/test/java/ASTs/ConstructorParamsAST.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package ASTs;
|
||||
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ConstructorParamsAST {
|
||||
|
||||
public static Program getProgram() {
|
||||
List<RefType> refTypeList = new ArrayList<>();
|
||||
refTypeList.add(getRefType());
|
||||
Program program = new Program(refTypeList);
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
public static RefType getRefType() {
|
||||
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(method0());
|
||||
RefType refType = new RefType("ConstructorParams", fieldDeclList, methodDeclList, false);
|
||||
return refType;
|
||||
}
|
||||
|
||||
public static MethodDecl method0() {
|
||||
|
||||
Parameter parameter0 = new Parameter("int", "i");
|
||||
List<Parameter> parameterList = new ArrayList<>();
|
||||
parameterList.add(parameter0);
|
||||
ParameterList parameterListObj = new ParameterList(parameterList);
|
||||
BlockStatement blockStatement = new BlockStatement(new ArrayList<>(), null);
|
||||
MethodDecl methodDecl = new MethodDecl("ConstructorParams", null, "ConstructorParams",
|
||||
parameterListObj, blockStatement);
|
||||
|
||||
return methodDecl;
|
||||
}
|
||||
}
|
||||
59
src/test/java/ASTs/ConstructorParamsASTTyped.java
Normal file
59
src/test/java/ASTs/ConstructorParamsASTTyped.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package ASTs;
|
||||
|
||||
import Typecheck.TypingHelper;
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class ConstructorParamsASTTyped {
|
||||
public static Program getProgram() {
|
||||
List<RefType> refTypeList = new ArrayList<>();
|
||||
refTypeList.add(getRefType());
|
||||
Program program = new Program(refTypeList);
|
||||
addTyping(program);
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
public static RefType getRefType() {
|
||||
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(method0());
|
||||
RefType refType = new RefType("ConstructorParams", fieldDeclList, methodDeclList, false);
|
||||
return refType;
|
||||
}
|
||||
|
||||
public static MethodDecl method0() {
|
||||
|
||||
Parameter parameter0 = new Parameter("int", "i");
|
||||
List<Parameter> parameterList = new ArrayList<>();
|
||||
parameterList.add(parameter0);
|
||||
ParameterList parameterListObj = new ParameterList(parameterList);
|
||||
BlockStatement blockStatement = new BlockStatement(new ArrayList<>(), "void");
|
||||
MethodDecl methodDecl = new MethodDecl("ConstructorParams", null, "ConstructorParams",
|
||||
parameterListObj, blockStatement);
|
||||
|
||||
return methodDecl;
|
||||
}
|
||||
|
||||
public static void addTyping(Program program){
|
||||
// TypeContext
|
||||
TypingHelper.addTypeContext(program, "ConstructorParams", new HashMap<>());
|
||||
|
||||
// MethodContext
|
||||
HashMap<String, ParameterList> method0 = new HashMap<>();
|
||||
//method0.put("void", new ParameterList(new ArrayList<>()));
|
||||
HashMap<String, HashMap<String, ParameterList>> methods = new HashMap<>();
|
||||
//methods.put("main", method0);
|
||||
TypingHelper.addMethodContext(program, "ConstructorParams", methods);
|
||||
}
|
||||
}
|
||||
60
src/test/java/ASTs/ConstructorThisDotAST.java
Normal file
60
src/test/java/ASTs/ConstructorThisDotAST.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package ASTs;
|
||||
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Expression.InstVarExpression;
|
||||
import abstractSyntaxTree.Expression.IntConstantExpression;
|
||||
import abstractSyntaxTree.Expression.SubReceiver;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
import abstractSyntaxTree.Statement.IStatement;
|
||||
import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ConstructorThisDotAST {
|
||||
public static Program getProgram() {
|
||||
List<RefType> refTypeList = new ArrayList<>();
|
||||
refTypeList.add(getRefType());
|
||||
Program program = new Program(refTypeList);
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
public static RefType getRefType() {
|
||||
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
fieldDeclList.add(new FieldDecl("int", "i", null));
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(method0());
|
||||
RefType refType = new RefType("ConstructorThisDot", fieldDeclList, methodDeclList, false);
|
||||
return refType;
|
||||
}
|
||||
|
||||
public static MethodDecl method0() {
|
||||
|
||||
List<Parameter> parameterList = new ArrayList<>();
|
||||
ParameterList parameterListObj = new ParameterList(parameterList);
|
||||
List<IStatement> iStatementList = new ArrayList<>();
|
||||
|
||||
SubReceiver subReceiver = new SubReceiver(true);
|
||||
List<SubReceiver> subReceiverList = new ArrayList<>();
|
||||
subReceiverList.add(subReceiver);
|
||||
InstVarExpression instVarExpressionLeft = new InstVarExpression(subReceiverList, new ArrayList<>(), "i");
|
||||
|
||||
|
||||
IntConstantExpression intConstantExpression = new IntConstantExpression(5);
|
||||
AssignStatementExpression assignStatementExpression = new AssignStatementExpression("=", instVarExpressionLeft, intConstantExpression);
|
||||
|
||||
iStatementList.add(assignStatementExpression);
|
||||
BlockStatement blockStatement = new BlockStatement(iStatementList, null);
|
||||
MethodDecl methodDecl = new MethodDecl("ConstructorThisDot", null, "ConstructorThisDot",
|
||||
parameterListObj, blockStatement);
|
||||
|
||||
return methodDecl;
|
||||
}
|
||||
}
|
||||
77
src/test/java/ASTs/ConstructorThisDotASTTyped.java
Normal file
77
src/test/java/ASTs/ConstructorThisDotASTTyped.java
Normal file
@@ -0,0 +1,77 @@
|
||||
package ASTs;
|
||||
|
||||
import Typecheck.TypingHelper;
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Expression.InstVarExpression;
|
||||
import abstractSyntaxTree.Expression.IntConstantExpression;
|
||||
import abstractSyntaxTree.Expression.SubReceiver;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
import abstractSyntaxTree.Statement.IStatement;
|
||||
import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class ConstructorThisDotASTTyped {
|
||||
public static Program getProgram() {
|
||||
List<RefType> refTypeList = new ArrayList<>();
|
||||
refTypeList.add(getRefType());
|
||||
Program program = new Program(refTypeList);
|
||||
addTyping(program);
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
public static RefType getRefType() {
|
||||
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
fieldDeclList.add(new FieldDecl("int", "i", null));
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(method0());
|
||||
RefType refType = new RefType("ConstructorThisDot", fieldDeclList, methodDeclList, false);
|
||||
return refType;
|
||||
}
|
||||
|
||||
public static MethodDecl method0() {
|
||||
|
||||
List<Parameter> parameterList = new ArrayList<>();
|
||||
ParameterList parameterListObj = new ParameterList(parameterList);
|
||||
List<IStatement> iStatementList = new ArrayList<>();
|
||||
|
||||
SubReceiver subReceiver = new SubReceiver(true);
|
||||
List<SubReceiver> subReceiverList = new ArrayList<>();
|
||||
subReceiverList.add(subReceiver);
|
||||
InstVarExpression instVarExpressionLeft = new InstVarExpression(subReceiverList, new ArrayList<>(), "i");
|
||||
instVarExpressionLeft.thisClass = "ConstructorThisDot";
|
||||
|
||||
IntConstantExpression intConstantExpression = new IntConstantExpression(5);
|
||||
AssignStatementExpression assignStatementExpression = new AssignStatementExpression("=", instVarExpressionLeft, intConstantExpression);
|
||||
|
||||
iStatementList.add(assignStatementExpression);
|
||||
BlockStatement blockStatement = new BlockStatement(iStatementList, "void");
|
||||
MethodDecl methodDecl = new MethodDecl("ConstructorThisDot", null, "ConstructorThisDot",
|
||||
parameterListObj, blockStatement);
|
||||
|
||||
return methodDecl;
|
||||
}
|
||||
|
||||
public static void addTyping(Program program){
|
||||
// TypeContext
|
||||
HashMap<String, String> typeContextMap = new HashMap<>();
|
||||
typeContextMap.put("i", "int");
|
||||
TypingHelper.addTypeContext(program, "ConstructorThisDot", typeContextMap);
|
||||
|
||||
// MethodContext
|
||||
HashMap<String, ParameterList> method0 = new HashMap<>();
|
||||
//method0.put("void", new ParameterList(new ArrayList<>()));
|
||||
HashMap<String, HashMap<String, ParameterList>> methods = new HashMap<>();
|
||||
//methods.put("main", method0);
|
||||
TypingHelper.addMethodContext(program, "ConstructorThisDot", methods);
|
||||
}
|
||||
}
|
||||
50
src/test/java/ASTs/DivideByZeroAST.java
Normal file
50
src/test/java/ASTs/DivideByZeroAST.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package ASTs;
|
||||
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Expression.BinaryExpression;
|
||||
import abstractSyntaxTree.Expression.IntConstantExpression;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
import abstractSyntaxTree.Statement.IStatement;
|
||||
import abstractSyntaxTree.Statement.LocalVarDecl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DivideByZeroAST {
|
||||
|
||||
public static Program getProgram() {
|
||||
List<RefType> refTypeList = new ArrayList<>();
|
||||
refTypeList.add(getRefType());
|
||||
Program program = new Program(refTypeList);
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
public static RefType getRefType(){
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(method0());
|
||||
RefType refType = new RefType("DivideByZero", fieldDeclList, methodDeclList, true);
|
||||
|
||||
return refType;
|
||||
}
|
||||
public static MethodDecl method0(){
|
||||
|
||||
BinaryExpression binaryExpression00 = new BinaryExpression("/", new IntConstantExpression(1), new IntConstantExpression(0));
|
||||
LocalVarDecl localVarDecl00 = new LocalVarDecl("int", "a", binaryExpression00);
|
||||
List<IStatement> iStatementList = new ArrayList<>();
|
||||
iStatementList.add(localVarDecl00);
|
||||
BlockStatement blockStatement = new BlockStatement(iStatementList, null);
|
||||
|
||||
MethodDecl methodDecl = new MethodDecl("DivideByZero", "void", "main",
|
||||
new ParameterList(new ArrayList<>()), blockStatement
|
||||
);
|
||||
|
||||
return methodDecl;
|
||||
}
|
||||
}
|
||||
69
src/test/java/ASTs/DivideByZeroASTTyped.java
Normal file
69
src/test/java/ASTs/DivideByZeroASTTyped.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package ASTs;
|
||||
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import Typecheck.TypingHelper;
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Expression.BinaryExpression;
|
||||
import abstractSyntaxTree.Expression.IntConstantExpression;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
import abstractSyntaxTree.Statement.IStatement;
|
||||
import abstractSyntaxTree.Statement.LocalVarDecl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class DivideByZeroASTTyped {
|
||||
|
||||
public static Program getProgram() {
|
||||
List<RefType> refTypeList = new ArrayList<>();
|
||||
refTypeList.add(getRefType());
|
||||
Program program = new Program(refTypeList);
|
||||
addTyping(program);
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
public static RefType getRefType(){
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(method0());
|
||||
RefType refType = new RefType("DivideByZero", fieldDeclList, methodDeclList, true);
|
||||
|
||||
return refType;
|
||||
}
|
||||
public static MethodDecl method0(){
|
||||
|
||||
IntConstantExpression intConstantExpression0 = new IntConstantExpression(1);
|
||||
intConstantExpression0.setTypeCheckResult(new TypeCheckResult("int"));
|
||||
BinaryExpression binaryExpression00 = new BinaryExpression("/", intConstantExpression0, new IntConstantExpression(0));
|
||||
LocalVarDecl localVarDecl00 = new LocalVarDecl("int", "a", binaryExpression00);
|
||||
List<IStatement> iStatementList = new ArrayList<>();
|
||||
iStatementList.add(localVarDecl00);
|
||||
BlockStatement blockStatement = new BlockStatement(iStatementList, "void");
|
||||
|
||||
MethodDecl methodDecl = new MethodDecl("DivideByZero", "void", "main",
|
||||
new ParameterList(new ArrayList<>()), blockStatement
|
||||
);
|
||||
|
||||
return methodDecl;
|
||||
}
|
||||
|
||||
public static void addTyping(Program program) {
|
||||
//Type Context
|
||||
TypingHelper.addTypeContext(program, "DivideByZero", new HashMap<>());
|
||||
|
||||
|
||||
//Method Context
|
||||
HashMap<String, ParameterList> method0 = new HashMap<>();
|
||||
method0.put("void", new ParameterList(new ArrayList<>()));
|
||||
HashMap<String, HashMap<String, ParameterList>> methods = new HashMap<>();
|
||||
methods.put("main", method0);
|
||||
TypingHelper.addMethodContext(program, "DivideByZero", methods);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package ASTs;
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
@@ -12,23 +11,21 @@ import abstractSyntaxTree.Statement.IStatement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class emptyClassWithConstructorAST extends Program {
|
||||
public emptyClassWithConstructorAST()
|
||||
{
|
||||
super(staticClasses());
|
||||
}
|
||||
private static List<RefType> staticClasses() {
|
||||
public class EmptyClassWithConstructorAST {
|
||||
public static Program getProgram() {
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
|
||||
ParameterList emptyParameterList = new ParameterList(new ArrayList<>());
|
||||
List<IStatement> emptyIStatementList = new ArrayList<>();
|
||||
BlockStatement emptyBlockStatement = new BlockStatement(emptyIStatementList, "void");
|
||||
MethodDecl constructor = new MethodDecl("emptyClassWithConstructor", "null", "emptyClassWithConstructor", emptyParameterList, emptyBlockStatement);
|
||||
BlockStatement emptyBlockStatement = new BlockStatement(emptyIStatementList, null);
|
||||
MethodDecl constructor = new MethodDecl("EmptyClassWithConstructor", null, "EmptyClassWithConstructor", emptyParameterList, emptyBlockStatement);
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(constructor);
|
||||
RefType emptyClass = new RefType("emptyClass", fieldDeclList, methodDeclList, false);
|
||||
RefType emptyClass = new RefType("EmptyClassWithConstructor", fieldDeclList, methodDeclList, false);
|
||||
List<RefType> classes = new ArrayList<>();
|
||||
classes.add(emptyClass);
|
||||
return classes;
|
||||
|
||||
Program program = new Program(classes);
|
||||
return program;
|
||||
}
|
||||
}
|
||||
46
src/test/java/ASTs/EmptyClassWithConstructorASTTyped.java
Normal file
46
src/test/java/ASTs/EmptyClassWithConstructorASTTyped.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package ASTs;
|
||||
|
||||
import Typecheck.TypingHelper;
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.BlockStatement;
|
||||
import abstractSyntaxTree.Statement.IStatement;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class EmptyClassWithConstructorASTTyped {
|
||||
public static Program getProgram() {
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
|
||||
ParameterList emptyParameterList = new ParameterList(new ArrayList<>());
|
||||
List<IStatement> emptyIStatementList = new ArrayList<>();
|
||||
BlockStatement emptyBlockStatement = new BlockStatement(emptyIStatementList, "void");
|
||||
MethodDecl constructor = new MethodDecl("EmptyClassWithConstructor", null, "EmptyClassWithConstructor", emptyParameterList, emptyBlockStatement);
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(constructor);
|
||||
RefType emptyClass = new RefType("EmptyClassWithConstructor", fieldDeclList, methodDeclList, false);
|
||||
List<RefType> classes = new ArrayList<>();
|
||||
classes.add(emptyClass);
|
||||
|
||||
Program program = new Program(classes);
|
||||
addTyping(program);
|
||||
return program;
|
||||
}
|
||||
|
||||
public static void addTyping(Program program){
|
||||
// TypeContext
|
||||
TypingHelper.addTypeContext(program, "EmptyClassWithConstructor", new HashMap<>());
|
||||
|
||||
// MethodContext
|
||||
HashMap<String, ParameterList> method0 = new HashMap<>();
|
||||
//method0.put("void", new ParameterList(new ArrayList<>()));
|
||||
HashMap<String, HashMap<String, ParameterList>> methods = new HashMap<>();
|
||||
//methods.put("main", method0);
|
||||
TypingHelper.addMethodContext(program, "EmptyClassWithConstructor", methods);
|
||||
}
|
||||
}
|
||||
112
src/test/java/ASTs/FakultaetAST.java
Normal file
112
src/test/java/ASTs/FakultaetAST.java
Normal file
@@ -0,0 +1,112 @@
|
||||
package ASTs;
|
||||
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Expression.BinaryExpression;
|
||||
import abstractSyntaxTree.Expression.IntConstantExpression;
|
||||
import abstractSyntaxTree.Expression.LocalVarIdentifier;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.*;
|
||||
import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FakultaetAST {
|
||||
public static Program getProgram() {
|
||||
|
||||
String name = "Fakultaet";
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(method0());
|
||||
methodDeclList.add(method1());
|
||||
List<RefType> classes = new ArrayList<>();
|
||||
RefType fakultaet = new RefType(name, fieldDeclList, methodDeclList, true);
|
||||
classes.add(fakultaet);
|
||||
Program program = new Program(classes);
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
private static MethodDecl method0() {
|
||||
String classThatContainsMethod = "Fakultaet";
|
||||
String name = "main";
|
||||
ParameterList parameterList = new ParameterList(new ArrayList<>());
|
||||
String returnType = "void";
|
||||
List<IStatement> iStmtList = new ArrayList<>();
|
||||
BlockStatement blockStatement = new BlockStatement(iStmtList, null);
|
||||
return new MethodDecl(classThatContainsMethod, returnType, name, parameterList, blockStatement);
|
||||
}
|
||||
|
||||
private static MethodDecl method1() {
|
||||
String classThatContainsMethod = "Fakultaet";
|
||||
String name = "fak";
|
||||
// Parameters
|
||||
Parameter param0 = new Parameter("int", "number");
|
||||
List<Parameter> paramList = new ArrayList<>() {{
|
||||
add(param0);
|
||||
}};
|
||||
ParameterList parameterListObj = new ParameterList(paramList);
|
||||
|
||||
String returnType = "int";
|
||||
|
||||
// Block Statement
|
||||
List<IStatement> iStmtList0 = new ArrayList<>();
|
||||
// If Statament
|
||||
//condition
|
||||
LocalVarIdentifier binExprIdentifier = new LocalVarIdentifier("number");
|
||||
IntConstantExpression binExprIntConst = new IntConstantExpression(0);
|
||||
BinaryExpression binExpr = new BinaryExpression("<", binExprIdentifier, binExprIntConst);
|
||||
|
||||
IntConstantExpression return0Expr0 = new IntConstantExpression(1);
|
||||
ReturnStatement returnStatement0 = new ReturnStatement(return0Expr0);
|
||||
List<IStatement> iStmtList1 = new ArrayList<>();
|
||||
iStmtList1.add(returnStatement0);
|
||||
BlockStatement ifStmt = new BlockStatement(iStmtList1, null);
|
||||
IfStatement ifStatement = new IfStatement(binExpr, ifStmt);
|
||||
|
||||
iStmtList0.add(ifStatement);
|
||||
|
||||
// Expression 1
|
||||
IntConstantExpression intConst0 = new IntConstantExpression(1);
|
||||
LocalVarDecl localVarExpr0 = new LocalVarDecl("int", "factorial", intConst0);
|
||||
|
||||
iStmtList0.add(localVarExpr0);
|
||||
// Expression 2
|
||||
IntConstantExpression intConst1 = new IntConstantExpression(1);
|
||||
LocalVarDecl localVarExpr1 = new LocalVarDecl("int", "i", intConst1);
|
||||
|
||||
iStmtList0.add(localVarExpr1);
|
||||
|
||||
//While Statement
|
||||
BinaryExpression whileCondition = new BinaryExpression("<=", new LocalVarIdentifier("i"), new LocalVarIdentifier("number"));
|
||||
|
||||
BinaryExpression whileBinExpr = new BinaryExpression("*", new LocalVarIdentifier("factorial"), new LocalVarIdentifier("i"));
|
||||
AssignStatementExpression assignStatementExpression0 = new AssignStatementExpression("=", new LocalVarIdentifier("factorial"), whileBinExpr);
|
||||
List<IStatement> whileBlockStmts = new ArrayList<>();
|
||||
|
||||
LocalVarIdentifier identifierI = new LocalVarIdentifier("i");
|
||||
BinaryExpression rightAssign1 = new BinaryExpression("+", identifierI, new IntConstantExpression(1));
|
||||
AssignStatementExpression assignStatementExpression1 = new AssignStatementExpression("=", identifierI, rightAssign1);
|
||||
|
||||
whileBlockStmts.add(assignStatementExpression0);
|
||||
whileBlockStmts.add(assignStatementExpression1);
|
||||
BlockStatement whileBlock = new BlockStatement( whileBlockStmts, null);
|
||||
|
||||
WhileStatement whileStatement0 = new WhileStatement(whileCondition, whileBlock);
|
||||
|
||||
iStmtList0.add(whileStatement0);
|
||||
|
||||
// Return Statement
|
||||
LocalVarIdentifier returnIdentifier = new LocalVarIdentifier("factorial");
|
||||
ReturnStatement returnStatement = new ReturnStatement(returnIdentifier);
|
||||
|
||||
iStmtList0.add(returnStatement);
|
||||
BlockStatement blockStatement = new BlockStatement(iStmtList0, null);
|
||||
return new MethodDecl(classThatContainsMethod, returnType, name, parameterListObj, blockStatement);
|
||||
}
|
||||
|
||||
}
|
||||
153
src/test/java/ASTs/FakultaetASTTyped.java
Normal file
153
src/test/java/ASTs/FakultaetASTTyped.java
Normal file
@@ -0,0 +1,153 @@
|
||||
package ASTs;
|
||||
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import Typecheck.TypingHelper;
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Expression.BinaryExpression;
|
||||
import abstractSyntaxTree.Expression.IntConstantExpression;
|
||||
import abstractSyntaxTree.Expression.LocalVarIdentifier;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.*;
|
||||
import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class FakultaetASTTyped {
|
||||
public static Program getProgram() {
|
||||
|
||||
String name = "Fakultaet";
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(method0());
|
||||
methodDeclList.add(method1());
|
||||
List<RefType> classes = new ArrayList<>();
|
||||
RefType fakultaet = new RefType(name, fieldDeclList, methodDeclList, true);
|
||||
classes.add(fakultaet);
|
||||
Program program = new Program(classes);
|
||||
addTyping(program);
|
||||
return program;
|
||||
}
|
||||
|
||||
private static MethodDecl method0() {
|
||||
String classThatContainsMethod = "Fakultaet";
|
||||
String name = "main";
|
||||
ParameterList parameterList = new ParameterList(new ArrayList<>());
|
||||
String returnType = "void";
|
||||
List<IStatement> iStmtList = new ArrayList<>();
|
||||
BlockStatement blockStatement = new BlockStatement(iStmtList, "void");
|
||||
return new MethodDecl(classThatContainsMethod, returnType, name, parameterList, blockStatement);
|
||||
}
|
||||
|
||||
private static MethodDecl method1() {
|
||||
String classThatContainsMethod = "Fakultaet";
|
||||
String name = "fak";
|
||||
// Parameters
|
||||
Parameter param0 = new Parameter("int", "number");
|
||||
List<Parameter> paramList = new ArrayList<>() {{
|
||||
add(param0);
|
||||
}};
|
||||
ParameterList parameterListObj = new ParameterList(paramList);
|
||||
|
||||
String returnType = "int";
|
||||
|
||||
// Block Statement
|
||||
List<IStatement> iStmtList0 = new ArrayList<>();
|
||||
// If Statament
|
||||
//condition
|
||||
LocalVarIdentifier binExprIdentifier = new LocalVarIdentifier("number");
|
||||
TypeCheckResult typeCheckResultbinExprIdentifier = new TypeCheckResult();
|
||||
typeCheckResultbinExprIdentifier.type = "int";
|
||||
binExprIdentifier.setTypeCheckResult(typeCheckResultbinExprIdentifier);
|
||||
IntConstantExpression binExprIntConst = new IntConstantExpression(0);
|
||||
BinaryExpression binExpr = new BinaryExpression("<", binExprIdentifier, binExprIntConst);
|
||||
TypeCheckResult typeCheckResultbinExpr = new TypeCheckResult();
|
||||
typeCheckResultbinExpr.type = "boolean";
|
||||
binExpr.setTypeCheckResult(typeCheckResultbinExpr);
|
||||
|
||||
IntConstantExpression return0Expr0 = new IntConstantExpression(1);
|
||||
TypeCheckResult typeCheckResult1 = new TypeCheckResult();
|
||||
typeCheckResult1.type = "int";
|
||||
return0Expr0.setTypeCheckResult(typeCheckResult1);
|
||||
ReturnStatement returnStatement0 = new ReturnStatement(return0Expr0);
|
||||
List<IStatement> iStmtList1 = new ArrayList<>();
|
||||
iStmtList1.add(returnStatement0);
|
||||
BlockStatement ifStmt = new BlockStatement(iStmtList1, "int");
|
||||
IfStatement ifStatement = new IfStatement(binExpr, ifStmt);
|
||||
|
||||
iStmtList0.add(ifStatement);
|
||||
|
||||
// Expression 1
|
||||
IntConstantExpression intConst0 = new IntConstantExpression(1);
|
||||
LocalVarDecl localVarExpr0 = new LocalVarDecl("int", "factorial", intConst0);
|
||||
|
||||
iStmtList0.add(localVarExpr0);
|
||||
// Expression 2
|
||||
IntConstantExpression intConst1 = new IntConstantExpression(0);
|
||||
LocalVarDecl localVarExpr1 = new LocalVarDecl("int", "i", intConst1);
|
||||
|
||||
iStmtList0.add(localVarExpr1);
|
||||
|
||||
//While Statement
|
||||
LocalVarIdentifier identifierI = new LocalVarIdentifier("i");
|
||||
identifierI.setTypeCheckResult(new TypeCheckResult("int"));
|
||||
BinaryExpression whileCondition = new BinaryExpression("<=", identifierI, new LocalVarIdentifier("number"));
|
||||
whileCondition.setTypeCheckResult(new TypeCheckResult("void"));
|
||||
|
||||
LocalVarIdentifier localVarIdentifierFactorial = new LocalVarIdentifier("factorial");
|
||||
localVarIdentifierFactorial.setTypeCheckResult(new TypeCheckResult("int"));
|
||||
BinaryExpression whileBinExpr = new BinaryExpression("*", localVarIdentifierFactorial, identifierI);
|
||||
AssignStatementExpression assignStatementExpression0 = new AssignStatementExpression("=", localVarIdentifierFactorial, whileBinExpr);
|
||||
List<IStatement> whileBlockStmts = new ArrayList<>();
|
||||
|
||||
|
||||
BinaryExpression rightAssign1 = new BinaryExpression("+", identifierI, new IntConstantExpression(1));
|
||||
AssignStatementExpression assignStatementExpression1 = new AssignStatementExpression("=", identifierI, rightAssign1);
|
||||
|
||||
whileBlockStmts.add(assignStatementExpression0);
|
||||
whileBlockStmts.add(assignStatementExpression1);
|
||||
BlockStatement whileBlock = new BlockStatement( whileBlockStmts, "void");
|
||||
|
||||
WhileStatement whileStatement0 = new WhileStatement(whileCondition, whileBlock);
|
||||
|
||||
iStmtList0.add(whileStatement0);
|
||||
|
||||
// Return Statement
|
||||
LocalVarIdentifier returnIdentifier = new LocalVarIdentifier("factorial");
|
||||
TypeCheckResult typeCheckResult0 = new TypeCheckResult();
|
||||
typeCheckResult0.type = "int";
|
||||
returnIdentifier.setTypeCheckResult(typeCheckResult0);
|
||||
ReturnStatement returnStatement = new ReturnStatement(returnIdentifier);
|
||||
|
||||
iStmtList0.add(returnStatement);
|
||||
BlockStatement blockStatement = new BlockStatement(iStmtList0, "int");
|
||||
return new MethodDecl(classThatContainsMethod, returnType, name, parameterListObj, blockStatement);
|
||||
}
|
||||
|
||||
public static void addTyping(Program program){
|
||||
// TypeContext
|
||||
TypingHelper.addTypeContext(program, "Fakultaet", new HashMap<>());
|
||||
|
||||
// MethodContext
|
||||
//main Method
|
||||
HashMap<String, ParameterList> method1 = new HashMap<>();
|
||||
method1.put("void", new ParameterList(new ArrayList<>()));
|
||||
//fak Method
|
||||
HashMap<String, ParameterList> method0 = new HashMap<>();
|
||||
List<Parameter> parameterList0 = new ArrayList<>(){{
|
||||
add(new Parameter("int", "number"));
|
||||
}};
|
||||
ParameterList parameterListObj0 = new ParameterList(parameterList0);
|
||||
method0.put("int", parameterListObj0);
|
||||
|
||||
HashMap<String, HashMap<String, ParameterList>> methods = new HashMap<>();
|
||||
methods.put("fak", method0);
|
||||
methods.put("main", method1);
|
||||
TypingHelper.addMethodContext(program, "Fakultaet", methods);
|
||||
}
|
||||
}
|
||||
24
src/test/java/ASTs/FieldVarAST.java
Normal file
24
src/test/java/ASTs/FieldVarAST.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package ASTs;
|
||||
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Program;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FieldVarAST {
|
||||
public static Program getProgram() {
|
||||
// int variable
|
||||
FieldDecl fieldDecl = new FieldDecl("int", "variable", null);
|
||||
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
fieldDeclList.add(fieldDecl);
|
||||
RefType class0 = new RefType("FieldVar", fieldDeclList, methodDeclList, false);
|
||||
List<RefType> refTypeList = new ArrayList<>();
|
||||
refTypeList.add(class0);
|
||||
return new Program(refTypeList);
|
||||
}
|
||||
}
|
||||
43
src/test/java/ASTs/FieldVarASTTyped.java
Normal file
43
src/test/java/ASTs/FieldVarASTTyped.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package ASTs;
|
||||
|
||||
import Typecheck.TypingHelper;
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class FieldVarASTTyped {
|
||||
public static Program getProgram() {
|
||||
// int variable
|
||||
FieldDecl fieldDecl = new FieldDecl("int", "variable", null);
|
||||
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
fieldDeclList.add(fieldDecl);
|
||||
RefType class0 = new RefType("FieldVar", fieldDeclList, methodDeclList, false);
|
||||
List<RefType> refTypeList = new ArrayList<>();
|
||||
refTypeList.add(class0);
|
||||
Program program = new Program(refTypeList);
|
||||
addTyping(program);
|
||||
return program;
|
||||
}
|
||||
|
||||
public static void addTyping(Program program){
|
||||
// TypeContext
|
||||
HashMap<String, String> typeContextMap = new HashMap<>();
|
||||
typeContextMap.put("variable", "int");
|
||||
TypingHelper.addTypeContext(program, "FieldVar", typeContextMap);
|
||||
|
||||
// MethodContext
|
||||
HashMap<String, ParameterList> method0 = new HashMap<>();
|
||||
//method0.put("void", new ParameterList(new ArrayList<>()));
|
||||
HashMap<String, HashMap<String, ParameterList>> methods = new HashMap<>();
|
||||
//methods.put("main", method0);
|
||||
TypingHelper.addMethodContext(program, "FieldVar", methods);
|
||||
}
|
||||
}
|
||||
104
src/test/java/ASTs/IfElseIfStatementWithOneReturnAST.java
Normal file
104
src/test/java/ASTs/IfElseIfStatementWithOneReturnAST.java
Normal file
@@ -0,0 +1,104 @@
|
||||
package ASTs;
|
||||
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Expression.BinaryExpression;
|
||||
import abstractSyntaxTree.Expression.IntConstantExpression;
|
||||
import abstractSyntaxTree.Expression.LocalVarIdentifier;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.*;
|
||||
import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class IfElseIfStatementWithOneReturnAST {
|
||||
public static Program getProgram() {
|
||||
|
||||
List<RefType> refTypeList = new ArrayList<>();
|
||||
refTypeList.add(getRefType());
|
||||
Program program = new Program(refTypeList);
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
public static RefType getRefType() {
|
||||
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(method0());
|
||||
RefType refType = new RefType("IfElseIfStatementWithOneReturn", fieldDeclList, methodDeclList, false);
|
||||
|
||||
return refType;
|
||||
}
|
||||
|
||||
public static MethodDecl method0() {
|
||||
|
||||
List<Parameter> parameterList = new ArrayList<>();
|
||||
parameterList.add(new Parameter("int", "i"));
|
||||
ParameterList parameterListObj = new ParameterList(parameterList);
|
||||
|
||||
List<IStatement> iStatementList = new ArrayList<>();
|
||||
iStatementList.add(statement00());
|
||||
iStatementList.add(statement01());
|
||||
iStatementList.add(statement02());
|
||||
BlockStatement blockStatement0 = new BlockStatement(iStatementList, null);
|
||||
MethodDecl methodDecl = new MethodDecl("IfElseIfStatementWithOneReturn", "int", "foo", parameterListObj, blockStatement0);
|
||||
|
||||
return methodDecl;
|
||||
}
|
||||
|
||||
public static LocalVarDecl statement00() {
|
||||
LocalVarDecl localVarDecl = new LocalVarDecl("int", "result", null);
|
||||
return localVarDecl;
|
||||
}
|
||||
|
||||
public static IfElseStatement statement01() {
|
||||
|
||||
LocalVarIdentifier conditionLeft = new LocalVarIdentifier("i");
|
||||
BinaryExpression condition = new BinaryExpression("==", conditionLeft, new IntConstantExpression(1));
|
||||
|
||||
LocalVarIdentifier identifierResult = new LocalVarIdentifier("result");
|
||||
List<IStatement> ifStatementList = new ArrayList<>();
|
||||
ifStatementList.add(new AssignStatementExpression("=", identifierResult, new IntConstantExpression(10)));
|
||||
BlockStatement ifStatement = new BlockStatement(ifStatementList, null);
|
||||
|
||||
IfElseStatement elseStatement = statement010();
|
||||
|
||||
IfElseStatement ifElseStatement = new IfElseStatement(condition, ifStatement, elseStatement);
|
||||
|
||||
return ifElseStatement;
|
||||
}
|
||||
|
||||
public static IfElseStatement statement010() {
|
||||
LocalVarIdentifier identifieri = new LocalVarIdentifier("i");
|
||||
BinaryExpression condition0 = new BinaryExpression("==", identifieri, new IntConstantExpression(2));
|
||||
|
||||
List<IStatement> iStatementList = new ArrayList<>();
|
||||
LocalVarIdentifier identifierResult = new LocalVarIdentifier("result");
|
||||
AssignStatementExpression assignStatementExpression = new AssignStatementExpression("=", identifierResult, new IntConstantExpression(10));
|
||||
iStatementList.add(assignStatementExpression);
|
||||
BlockStatement ifStatement = new BlockStatement(iStatementList, null);
|
||||
|
||||
BinaryExpression condition1 = new BinaryExpression("==", identifieri, new IntConstantExpression(2));
|
||||
List<IStatement> iStatementList1 = new ArrayList<>();
|
||||
iStatementList1.add(new ReturnStatement(new IntConstantExpression(20)));
|
||||
BlockStatement blockStatementIf = new BlockStatement(iStatementList1, null);
|
||||
List<IStatement> iStatementList2 = new ArrayList<>();
|
||||
AssignStatementExpression assignStatementExpression1 = new AssignStatementExpression("=", identifierResult, new IntConstantExpression(30));
|
||||
iStatementList2.add(assignStatementExpression1);
|
||||
BlockStatement blockStatementElse = new BlockStatement(iStatementList2, null);
|
||||
IfElseStatement ifElseStatement = new IfElseStatement(condition1, blockStatementIf, blockStatementElse);
|
||||
|
||||
return new IfElseStatement(condition1, blockStatementIf, blockStatementElse);
|
||||
}
|
||||
|
||||
public static ReturnStatement statement02() {
|
||||
LocalVarIdentifier identifierResult = new LocalVarIdentifier("result");
|
||||
return new ReturnStatement(identifierResult);
|
||||
}
|
||||
|
||||
}
|
||||
135
src/test/java/ASTs/IfElseIfStatementWithOneReturnASTTyped.java
Normal file
135
src/test/java/ASTs/IfElseIfStatementWithOneReturnASTTyped.java
Normal file
@@ -0,0 +1,135 @@
|
||||
package ASTs;
|
||||
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import Typecheck.TypingHelper;
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Expression.BinaryExpression;
|
||||
import abstractSyntaxTree.Expression.IntConstantExpression;
|
||||
import abstractSyntaxTree.Expression.LocalVarIdentifier;
|
||||
import abstractSyntaxTree.Parameter.Parameter;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import abstractSyntaxTree.Statement.*;
|
||||
import abstractSyntaxTree.StatementExpression.AssignStatementExpression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class IfElseIfStatementWithOneReturnASTTyped {
|
||||
|
||||
public static Program getProgram() {
|
||||
|
||||
List<RefType> refTypeList = new ArrayList<>();
|
||||
refTypeList.add(getRefType());
|
||||
Program program = new Program(refTypeList);
|
||||
addTyping(program);
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
public static RefType getRefType() {
|
||||
|
||||
List<FieldDecl> fieldDeclList = new ArrayList<>();
|
||||
List<MethodDecl> methodDeclList = new ArrayList<>();
|
||||
methodDeclList.add(method0());
|
||||
RefType refType = new RefType("IfElseIfStatementWithOneReturn", fieldDeclList, methodDeclList, false);
|
||||
|
||||
return refType;
|
||||
}
|
||||
|
||||
public static MethodDecl method0() {
|
||||
|
||||
List<Parameter> parameterList = new ArrayList<>();
|
||||
parameterList.add(new Parameter("int", "i"));
|
||||
ParameterList parameterListObj = new ParameterList(parameterList);
|
||||
|
||||
List<IStatement> iStatementList = new ArrayList<>();
|
||||
iStatementList.add(statement00());
|
||||
iStatementList.add(statement01());
|
||||
iStatementList.add(statement02());
|
||||
BlockStatement blockStatement0 = new BlockStatement(iStatementList, "int");
|
||||
MethodDecl methodDecl = new MethodDecl("IfElseIfStatementWithOneReturn", "int", "foo", parameterListObj, blockStatement0);
|
||||
|
||||
return methodDecl;
|
||||
}
|
||||
|
||||
public static LocalVarDecl statement00() {
|
||||
LocalVarDecl localVarDecl = new LocalVarDecl("int", "result", null);
|
||||
return localVarDecl;
|
||||
}
|
||||
|
||||
public static IfElseStatement statement01() {
|
||||
|
||||
LocalVarIdentifier conditionLeft = new LocalVarIdentifier("i");
|
||||
conditionLeft.setTypeCheckResult(new TypeCheckResult("int"));
|
||||
BinaryExpression condition = new BinaryExpression("==", conditionLeft, new IntConstantExpression(1));
|
||||
condition.setTypeCheckResult(new TypeCheckResult("boolean"));
|
||||
|
||||
LocalVarIdentifier identifierResult = new LocalVarIdentifier("result");
|
||||
identifierResult.setTypeCheckResult(new TypeCheckResult("int"));
|
||||
List<IStatement> ifStatementList = new ArrayList<>();
|
||||
ifStatementList.add(new AssignStatementExpression("=", identifierResult, new IntConstantExpression(10)));
|
||||
BlockStatement ifStatement = new BlockStatement(ifStatementList, "void");
|
||||
|
||||
IfElseStatement elseStatement = statement010();
|
||||
|
||||
IfElseStatement ifElseStatement = new IfElseStatement(condition, ifStatement, elseStatement);
|
||||
|
||||
return ifElseStatement;
|
||||
}
|
||||
|
||||
public static IfElseStatement statement010() {
|
||||
LocalVarIdentifier identifieri = new LocalVarIdentifier("i");
|
||||
identifieri.setTypeCheckResult(new TypeCheckResult("int"));
|
||||
BinaryExpression condition0 = new BinaryExpression("==", identifieri, new IntConstantExpression(2));
|
||||
condition0.setTypeCheckResult(new TypeCheckResult("boolean"));
|
||||
|
||||
List<IStatement> iStatementList = new ArrayList<>();
|
||||
LocalVarIdentifier identifierResult = new LocalVarIdentifier("result");
|
||||
identifierResult.setTypeCheckResult(new TypeCheckResult("int"));
|
||||
AssignStatementExpression assignStatementExpression = new AssignStatementExpression("=", identifierResult, new IntConstantExpression(10));
|
||||
iStatementList.add(assignStatementExpression);
|
||||
BlockStatement ifStatement = new BlockStatement(iStatementList, "void");
|
||||
|
||||
BinaryExpression condition1 = new BinaryExpression("==", identifieri, new IntConstantExpression(2));
|
||||
condition1.setTypeCheckResult(new TypeCheckResult("boolean"));
|
||||
List<IStatement> iStatementList1 = new ArrayList<>();
|
||||
IntConstantExpression intConstantExpression20 = new IntConstantExpression(20);
|
||||
intConstantExpression20.setTypeCheckResult(new TypeCheckResult("int"));
|
||||
ReturnStatement return20 = new ReturnStatement(intConstantExpression20);
|
||||
return20.setTypeCheckResult(new TypeCheckResult("int"));
|
||||
iStatementList1.add(return20);
|
||||
BlockStatement blockStatementIf = new BlockStatement(iStatementList1, "int");
|
||||
List<IStatement> iStatementList2 = new ArrayList<>();
|
||||
AssignStatementExpression assignStatementExpression1 = new AssignStatementExpression("=", identifierResult, new IntConstantExpression(30));
|
||||
iStatementList2.add(assignStatementExpression1);
|
||||
BlockStatement blockStatementElse = new BlockStatement(iStatementList2, "void");
|
||||
IfElseStatement ifElseStatement = new IfElseStatement(condition1, blockStatementIf, blockStatementElse);
|
||||
|
||||
return new IfElseStatement(condition1, blockStatementIf, blockStatementElse);
|
||||
}
|
||||
|
||||
public static ReturnStatement statement02() {
|
||||
LocalVarIdentifier identifierResult = new LocalVarIdentifier("result");
|
||||
identifierResult.setTypeCheckResult(new TypeCheckResult("int"));
|
||||
return new ReturnStatement(identifierResult);
|
||||
}
|
||||
|
||||
public static void addTyping(Program program){
|
||||
// TypeContext
|
||||
TypingHelper.addTypeContext(program, "IfElseIfStatementWithOneReturn", new HashMap<>());
|
||||
|
||||
// MethodContext
|
||||
HashMap<String, ParameterList> method0 = new HashMap<>();
|
||||
List<Parameter> parameterList = new ArrayList<>();
|
||||
parameterList.add(new Parameter("int", "i"));
|
||||
ParameterList parameterListObj = new ParameterList(parameterList);
|
||||
method0.put("int", parameterListObj);
|
||||
HashMap<String, HashMap<String, ParameterList>> methods = new HashMap<>();
|
||||
methods.put("foo", method0);
|
||||
TypingHelper.addMethodContext(program, "IfElseIfStatementWithOneReturn", methods);
|
||||
}
|
||||
}
|
||||
32
src/test/java/ASTs/emptyClassASTTyped.java
Normal file
32
src/test/java/ASTs/emptyClassASTTyped.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package ASTs;
|
||||
|
||||
import abstractSyntaxTree.Class.FieldDecl;
|
||||
import abstractSyntaxTree.Class.MethodDecl;
|
||||
import abstractSyntaxTree.Class.RefType;
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
import Typecheck.TypingHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class emptyClassASTTyped {
|
||||
public static Program getEmptyProgramm() {
|
||||
List<FieldDecl> emptyFieldDeclList = new ArrayList<>();
|
||||
List<MethodDecl> emptyMethodDeclList = new ArrayList<>();
|
||||
RefType emptyClass = new RefType("emptyClass", emptyFieldDeclList, emptyMethodDeclList, false);
|
||||
List<RefType> classes = new ArrayList<>();
|
||||
classes.add(emptyClass);
|
||||
Program program = new Program(classes);
|
||||
addTyping(program);
|
||||
return program;
|
||||
}
|
||||
|
||||
public static void addTyping(Program program) {
|
||||
HashMap<String, String> fields = new HashMap<>();
|
||||
//fields.put();
|
||||
TypingHelper.addTypeContext(program, "emptyClass", fields);
|
||||
TypingHelper.addMethodContext(program, "emptyClass", new HashMap<>());
|
||||
}
|
||||
}
|
||||
177
src/test/java/ByteCode/ByteCodeTester.java
Normal file
177
src/test/java/ByteCode/ByteCodeTester.java
Normal file
@@ -0,0 +1,177 @@
|
||||
package ByteCode;
|
||||
|
||||
import abstractSyntaxTree.Program;
|
||||
import astGenerator.ASTGenerator;
|
||||
import gen.DecafLexer;
|
||||
import gen.DecafParser;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class ByteCodeTester {
|
||||
CompareByteCodeBehaviour byteCodeBehaviourComparer;
|
||||
public ByteCodeTester(){
|
||||
byteCodeBehaviourComparer = new CompareByteCodeBehaviour();
|
||||
}
|
||||
|
||||
public void testByteCodeFromAst(String correctClassFilePath, Program abstractSyntaxTree, String className) {
|
||||
typeCheckWithoutmain(abstractSyntaxTree);
|
||||
generateCode(abstractSyntaxTree);
|
||||
testAST(correctClassFilePath, className);
|
||||
}
|
||||
|
||||
public void testByteCodeFromTypedAst(String correctClassFilePath, Program abstractSyntaxTree, String className) {
|
||||
generateCode(abstractSyntaxTree);
|
||||
testAST(correctClassFilePath, className);
|
||||
}
|
||||
|
||||
public void testClassFileFromScratch(String correctClassFilePath, String fileToComparePath, String className) {
|
||||
Program abstractSyntaxTree = generateAST(fileToComparePath);
|
||||
typeCheckWithoutmain(abstractSyntaxTree);
|
||||
generateCode(abstractSyntaxTree);
|
||||
testAST(correctClassFilePath, className);
|
||||
}
|
||||
|
||||
private void typeCheckWithoutmain(Program abstractSyntaxTree){
|
||||
try {
|
||||
abstractSyntaxTree.typeCheckWithoutMain();
|
||||
} catch (Exception e){
|
||||
System.out.println("Le Exception in le type-check");
|
||||
}
|
||||
}
|
||||
|
||||
private void generateCode(Program abstractSyntaxTree){
|
||||
try {
|
||||
abstractSyntaxTree.codeGen();
|
||||
} catch (Exception e){
|
||||
System.out.println("Le Exception in le codegen");
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
private void testAST(String correctClassFilePath, String className) {
|
||||
try {
|
||||
ClassFileLoader classLoader1 = new ClassFileLoader(correctClassFilePath);
|
||||
ClassFileLoader classLoader2 = new ClassFileLoader(className+ ".class");
|
||||
|
||||
Class<?> class1 = classLoader1.findClass(className);
|
||||
Class<?> class2 = classLoader2.findClass(className);
|
||||
|
||||
assertTrue(CompareByteCodeSyntax.haveSameBehavior(class1, class2));
|
||||
assertTrue(byteCodeBehaviourComparer.compareMethodBehaviour(class1, class2));
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
private Program generateAST(String pathToJavaFile){
|
||||
String content = "";
|
||||
try {
|
||||
content = Files.readString(Path.of(pathToJavaFile));
|
||||
} catch (IOException e) {
|
||||
System.out.println("File not found!");
|
||||
fail();
|
||||
}
|
||||
|
||||
CharStream codeCharStream = CharStreams.fromString(content);
|
||||
DecafLexer lexer = new DecafLexer(codeCharStream);
|
||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
|
||||
tokens.fill();
|
||||
|
||||
DecafParser parser = new DecafParser(tokens);
|
||||
|
||||
ParseTree tree = parser.program();
|
||||
|
||||
ASTGenerator generator = new ASTGenerator();
|
||||
Program abstractSyntaxTree = (Program) generator.visit(tree);
|
||||
|
||||
return abstractSyntaxTree;
|
||||
}
|
||||
|
||||
public void compareJarFilesFromAST(Program abstractSyntaxTree, String jarPath, String[] classNames){
|
||||
try {
|
||||
abstractSyntaxTree.codeGen();
|
||||
} catch (Exception e){
|
||||
System.out.println("Le Exception in le codegen");
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
|
||||
compareJarFiles(jarPath, "output.jar", classNames);
|
||||
}
|
||||
|
||||
public void compareJarFilesFromScratch(String javaCodePath, String jarPath, String[] classNames){
|
||||
String content = "";
|
||||
try {
|
||||
content = Files.readString(Path.of(javaCodePath));
|
||||
} catch (IOException e) {
|
||||
System.out.println("File not found!");
|
||||
fail();
|
||||
}
|
||||
|
||||
CharStream codeCharStream = CharStreams.fromString(content);
|
||||
DecafLexer lexer = new DecafLexer(codeCharStream);
|
||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
|
||||
tokens.fill();
|
||||
|
||||
DecafParser parser = new DecafParser(tokens);
|
||||
|
||||
ParseTree tree = parser.program();
|
||||
|
||||
ASTGenerator generator = new ASTGenerator();
|
||||
Program abstractSyntaxTree = (Program) generator.visit(tree);
|
||||
|
||||
try {
|
||||
abstractSyntaxTree.typeCheckWithoutMain();
|
||||
} catch (Exception e){
|
||||
System.out.println("Le Exception in le type-check");
|
||||
fail();
|
||||
}
|
||||
|
||||
try {
|
||||
abstractSyntaxTree.codeGen();
|
||||
} catch (Exception e){
|
||||
System.out.println("Le Exception in le codegen");
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
|
||||
compareJarFiles(jarPath, "output.jar", classNames);
|
||||
|
||||
}
|
||||
|
||||
public void compareJarFiles(String jarPath1, String jarPath2, String[] classNames) {
|
||||
try {
|
||||
JarFileLoader loader1 = new JarFileLoader(jarPath1);
|
||||
JarFileLoader loader2 = new JarFileLoader(jarPath2);
|
||||
CompareByteCodeBehaviour comparator = new CompareByteCodeBehaviour();
|
||||
|
||||
for (String className : classNames) {
|
||||
Class<?> class1 = loader1.loadClass(className);
|
||||
Class<?> class2 = loader2.loadClass(className);
|
||||
|
||||
boolean comparisonResult0 = CompareByteCodeSyntax.haveSameBehavior(class1, class2);
|
||||
System.out.println("Syntax Comparison result for " + className + ": " + comparisonResult0);
|
||||
|
||||
boolean comparisonResult1 = comparator.compareMethodBehaviour(class1, class2);
|
||||
System.out.println("Behaviour Comparison result for " + className + ": " + comparisonResult1);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
fail();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Parameter;
|
||||
import java.util.Random;
|
||||
|
||||
import static ByteCode.CompareByteCodeSyntax.compareMethod;
|
||||
|
||||
@@ -37,6 +39,14 @@ public class CompareByteCodeBehaviour {
|
||||
Method[] methods1 = class1.getDeclaredMethods();
|
||||
Method[] methods2 = class2.getDeclaredMethods();
|
||||
|
||||
/*
|
||||
for(int i = 0; i < methods1.length; i++) {
|
||||
System.out.println("Method1[" + i + "]: " + methods1[i]);
|
||||
System.out.println("Method2[" + i + "]: " + methods2[i]);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
for (Method method1 : methods1) {
|
||||
for (Method method2 : methods2) {
|
||||
if (compareMethod(method1, method2)) {
|
||||
@@ -48,18 +58,27 @@ public class CompareByteCodeBehaviour {
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
for(int i = 0; i < this.methodArray1.size(); i++){
|
||||
System.out.println("Method1[" + i + "]: " + methodArray1.get(i));
|
||||
System.out.println("Method2[" + i + "]: " + methodArray2.get(i));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public boolean compareMethodBehaviour(Class<?> class1, Class<?> class2){
|
||||
try {
|
||||
this.sortMethods(class1, class2);
|
||||
// Create instances
|
||||
Constructor<?> constructor1 = class1.getDeclaredConstructor();
|
||||
Constructor<?> constructor2 = class2.getDeclaredConstructor();
|
||||
Constructor<?>[] constructors1 = class1.getDeclaredConstructors();
|
||||
Constructor<?>[] constructors2 = class2.getDeclaredConstructors();
|
||||
Constructor<?> constructor1 = constructors1[0];
|
||||
Constructor<?> constructor2 = constructors2[0];
|
||||
constructor1.setAccessible(true);
|
||||
constructor2.setAccessible(true);
|
||||
Object obj1 = constructor1.newInstance();
|
||||
Object obj2 = constructor2.newInstance();
|
||||
Object[] constructorArgs = getDefaultArguments(constructor1.getParameters());
|
||||
Object obj1 = constructor1.newInstance(constructorArgs);
|
||||
Object obj2 = constructor2.newInstance(constructorArgs);
|
||||
|
||||
// Get methods
|
||||
Method[] methods1 = new Method[this.methodArray1.size()];
|
||||
@@ -67,31 +86,53 @@ public class CompareByteCodeBehaviour {
|
||||
Method[] methods2 = new Method[this.methodArray2.size()];
|
||||
methods2 = this.methodArray2.toArray(methods2);
|
||||
|
||||
/*
|
||||
for(int i = 0; i < methods1.length; i++) {
|
||||
System.out.println("MethodArray1 [" + i + "]: " + methods1[i]);
|
||||
System.out.println("MethodArray2 [" + i + "]: " + methods2[i]);
|
||||
}
|
||||
*/
|
||||
|
||||
// Compare methods
|
||||
for (int i = 0; i < methods1.length; i++) {
|
||||
Method method1 = methods1[i];
|
||||
Method method2 = methods2[i];
|
||||
|
||||
System.out.println("\n" + method1);
|
||||
System.out.println(method2);
|
||||
|
||||
method1.setAccessible(true);
|
||||
method2.setAccessible(true);
|
||||
|
||||
|
||||
// Test with some sample inputs
|
||||
Object[] testInputs = getTestInputs(method1.getParameterTypes());
|
||||
for(int j = 0; j < testInputs.length; j++){
|
||||
System.out.println("Parameter[" + i + "]: " + testInputs[j]);
|
||||
}
|
||||
|
||||
Object result1 = method1.invoke(obj1, testInputs);
|
||||
Object result2 = method2.invoke(obj2, testInputs);
|
||||
|
||||
System.out.println("Result method 1: " + result1);
|
||||
System.out.println("Result method 2: " + result2);
|
||||
|
||||
if (!result1.equals(result2)) {
|
||||
return false;
|
||||
if( !((result1 == null) && (result2 == null))) {
|
||||
if(( result1 == null) || (result2 == null) ) {
|
||||
return false;
|
||||
}
|
||||
if (!result1.equals(result2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
} catch (InstantiationException | IllegalAccessException |
|
||||
NoSuchMethodException | InvocationTargetException e) {
|
||||
InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -99,15 +140,42 @@ public class CompareByteCodeBehaviour {
|
||||
private static Object[] getTestInputs(Class<?>[] parameterTypes) {
|
||||
// Create test inputs based on parameter types
|
||||
Object[] inputs = new Object[parameterTypes.length];
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < parameterTypes.length; i++) {
|
||||
if (parameterTypes[i] == int.class) {
|
||||
inputs[i] = 1; // example value
|
||||
inputs[i] = random.nextInt(10); // example value
|
||||
} else if (parameterTypes[i] == String.class) {
|
||||
inputs[i] = "test"; // example value
|
||||
inputs[i] = "baguette"; // example value
|
||||
} else if (parameterTypes[i] == char.class) {
|
||||
inputs[i] = 'a';
|
||||
} else if (parameterTypes[i] == boolean.class) {
|
||||
inputs[i] = random.nextBoolean();
|
||||
}
|
||||
// Add more cases as needed for different parameter types
|
||||
}
|
||||
return inputs;
|
||||
}
|
||||
|
||||
private Object[] getDefaultArguments(Parameter[] parameters) {
|
||||
Object[] defaultArgs = new Object[parameters.length];
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
Class<?> paramType = parameters[i].getType();
|
||||
if (paramType.isPrimitive()) {
|
||||
if (paramType == boolean.class) {
|
||||
defaultArgs[i] = random.nextBoolean();
|
||||
} else if (paramType == int.class) {
|
||||
defaultArgs[i] = random.nextInt(10);
|
||||
} else if (paramType == char.class) {
|
||||
defaultArgs[i] = '\u0000';
|
||||
} else if (paramType == String.class) {
|
||||
defaultArgs[i] = "baguette";
|
||||
}
|
||||
} else {
|
||||
defaultArgs[i] = null; // Use null for non-primitive types
|
||||
}
|
||||
}
|
||||
return defaultArgs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,19 +8,15 @@ import java.util.Arrays;
|
||||
public class CompareByteCodeSyntax {
|
||||
|
||||
public static boolean haveSameBehavior(Class<?> class1, Class<?> class2) {
|
||||
System.out.println("Comparing class signatures of " + class1.getName() + " and " + class2.getName());
|
||||
if (!compareClassSignatures(class1, class2)) {
|
||||
return false;
|
||||
}
|
||||
System.out.println("Comparing methods of " + class1.getName() + " and " + class2.getName());
|
||||
if (!compareMethods(class1, class2)) {
|
||||
return false;
|
||||
}
|
||||
System.out.println("Comparing fields of " + class1.getName() + " and " + class2.getName());
|
||||
if (!compareFields(class1, class2)) {
|
||||
return false;
|
||||
}
|
||||
System.out.println("Comparing annotations of " + class1.getName() + " and " + class2.getName());
|
||||
if (!compareAnnotations(class1.getAnnotations(), class2.getAnnotations())) {
|
||||
return false;
|
||||
}
|
||||
@@ -81,6 +77,7 @@ public class CompareByteCodeSyntax {
|
||||
System.out.println("Annotations do not match for methods " + method1.getName() + " and " + method2.getName());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@ public class JarFileLoader extends ClassLoader {
|
||||
byte[] classData = loadClassDataFromJar(classFileName);
|
||||
return defineClass(name, classData, 0, classData.length);
|
||||
} catch (IOException e) {
|
||||
throw new ClassNotFoundException("Class not found", e);
|
||||
e.printStackTrace();
|
||||
throw new ClassNotFoundException("Class not found: " + name, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +32,7 @@ public class JarFileLoader extends ClassLoader {
|
||||
try (JarFile jarFile = new JarFile(new File(jarFilePath))) {
|
||||
JarEntry entry = jarFile.getJarEntry(classFileName);
|
||||
if (entry == null) {
|
||||
System.err.println("Class file " + classFileName + " not found in jar file.");
|
||||
throw new IOException("Class file " + classFileName + " not found in jar file.");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,148 +1,193 @@
|
||||
package ByteCode;
|
||||
|
||||
import abstractSyntaxTree.Program;
|
||||
import astGenerator.ASTGenerator;
|
||||
import gen.DecafLexer;
|
||||
import gen.DecafParser;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import ASTs.emptyClassAST;
|
||||
import ASTs.*;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
|
||||
public class TestAll {
|
||||
CompareByteCodeBehaviour byteCodeBehaviourComparer;
|
||||
public TestAll(){
|
||||
byteCodeBehaviourComparer = new CompareByteCodeBehaviour();
|
||||
}
|
||||
|
||||
public void testByteCodeFromAst(String classPath, Program abstractSyntaxTree, String className) {
|
||||
|
||||
|
||||
try {
|
||||
abstractSyntaxTree.codeGen();
|
||||
} catch (Exception e){
|
||||
System.out.println("Le Exception in le codegen");
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
ClassFileLoader classLoader1 = new ClassFileLoader(classPath);
|
||||
ClassFileLoader classLoader2 = new ClassFileLoader(className + ".class");
|
||||
|
||||
Class<?> class1 = classLoader1.findClass(className);
|
||||
Class<?> class2 = classLoader2.findClass(className);
|
||||
|
||||
assertTrue(CompareByteCodeSyntax.haveSameBehavior(class1, class2));
|
||||
assertTrue(byteCodeBehaviourComparer.compareMethodBehaviour(class1, class2));
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void testByteCodeFromScratch(String correctClassFilePath, String fileToComparePath, String className) {
|
||||
|
||||
String content = "";
|
||||
try {
|
||||
System.out.println("Classpath: " + Path.of(fileToComparePath));
|
||||
content = Files.readString(Path.of(fileToComparePath));
|
||||
} catch (IOException e) {
|
||||
System.out.println("File not found!");
|
||||
fail();
|
||||
}
|
||||
|
||||
CharStream codeCharStream = CharStreams.fromString(content);
|
||||
DecafLexer lexer = new DecafLexer(codeCharStream);
|
||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||
|
||||
tokens.fill();
|
||||
|
||||
DecafParser parser = new DecafParser(tokens);
|
||||
|
||||
ParseTree tree = parser.program();
|
||||
|
||||
ASTGenerator generator = new ASTGenerator();
|
||||
Program abstractSyntaxTree = (Program) generator.visit(tree);
|
||||
|
||||
try {
|
||||
abstractSyntaxTree.typeCheck();
|
||||
} catch (Exception e){
|
||||
System.out.println("Le Exception in le type-check");
|
||||
//fail();
|
||||
}
|
||||
|
||||
try {
|
||||
abstractSyntaxTree.codeGen();
|
||||
} catch (Exception e){
|
||||
System.out.println("Le Exception in le codegen");
|
||||
fail();
|
||||
}
|
||||
|
||||
try {
|
||||
ClassFileLoader classLoader1 = new ClassFileLoader(correctClassFilePath);
|
||||
ClassFileLoader classLoader2 = new ClassFileLoader(className+ ".class");
|
||||
|
||||
Class<?> class1 = classLoader1.findClass(className);
|
||||
Class<?> class2 = classLoader2.findClass(className);
|
||||
|
||||
assertTrue(CompareByteCodeSyntax.haveSameBehavior(class1, class2));
|
||||
assertTrue(byteCodeBehaviourComparer.compareMethodBehaviour(class1, class2));
|
||||
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
ByteCodeTester byteCodeTester;
|
||||
public TestAll(){byteCodeTester = new ByteCodeTester();}
|
||||
@Test
|
||||
public void testEmptyClass() {
|
||||
String classPath = "src/test/resources/basicClasses/emptyClass.class";
|
||||
Program ast = emptyClassAST.getEmptyProgramm();
|
||||
Program ast = emptyClassASTTyped.getEmptyProgramm();
|
||||
String className = "emptyClass";
|
||||
String javacode = "src/test/resources/basicClasses/emptyClass.java";
|
||||
testByteCodeFromAst(classPath, ast ,className);
|
||||
//testByteCodeFromScratch(classPath, javacode, className);
|
||||
byteCodeTester.testByteCodeFromTypedAst(classPath, ast ,className);
|
||||
//byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFourClasses() {
|
||||
String classPath = "src/test/resources/basicClasses/FourClasses.class";
|
||||
Program ast = emptyClassAST.getEmptyProgramm();
|
||||
String className = "emptyClass";
|
||||
String javacode = "src/test/resources/basicClasses/FourClasses.java";
|
||||
//testByteCodeFromAst(classPath, ast ,className);
|
||||
testByteCodeFromScratch(classPath, javacode, className);
|
||||
public void testEmptyClassWithConstructor() {
|
||||
String classPath = "src/test/resources/basicClasses/EmptyClassWithConstructor.class";
|
||||
Program ast = EmptyClassWithConstructorASTTyped.getProgram();
|
||||
String className = "EmptyClassWithConstructor";
|
||||
String javacode = "src/test/resources/basicClasses/emptyClass.java";
|
||||
byteCodeTester.testByteCodeFromTypedAst(classPath, ast ,className);
|
||||
//byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFakultaet() {
|
||||
String classPath = "src/test/resources/basicClasses/Fakultaet.class";
|
||||
Program ast = emptyClassAST.getEmptyProgramm();
|
||||
String className = "Fakultät";
|
||||
Program ast = FakultaetAST.getProgram();
|
||||
String className = "Fakultaet";
|
||||
String javacode = "src/test/resources/basicClasses/Fakultaet.java";
|
||||
//testByteCodeFromAst(classPath, ast ,className);
|
||||
testByteCodeFromScratch(classPath, javacode, className);
|
||||
byteCodeTester.testByteCodeFromAst(classPath, ast ,className);
|
||||
//byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassWithMain() {
|
||||
String classPath = "src/test/resources/basicClasses/classWithMain.class";
|
||||
Program ast = emptyClassAST.getEmptyProgramm();
|
||||
Program ast = ClassWithMainASTTyped.getProgram();
|
||||
String className = "classWithMain";
|
||||
String javacode = "src/test/resources/basicClasses/classWithMain.java";
|
||||
byteCodeTester.testByteCodeFromTypedAst(classPath, ast ,className);
|
||||
//byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharArgument() {
|
||||
String classPath = "src/test/resources/SimpleTests/CharArgument.class";
|
||||
Program ast = CharArgumentASTTyped.getProgram();
|
||||
String className = "CharArgument";
|
||||
String javacode = "src/test/resources/SimpleTests/CharArgument.java";
|
||||
//byteCodeTester.testByteCodeFromTypedAst(classPath, ast ,className);
|
||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClassFields() {
|
||||
String classPath = "src/test/resources/SimpleTests/ClassFields.class";
|
||||
//Program ast = ClassWithMainASTTyped.getProgram();
|
||||
String className = "ClassFields";
|
||||
String javacode = "src/test/resources/SimpleTests/ClassFields.java";
|
||||
//testByteCodeFromAst(classPath, ast ,className);
|
||||
testByteCodeFromScratch(classPath, javacode, className);
|
||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorParams() {
|
||||
String classPath = "src/test/resources/SimpleTests/ConstructorParams.class";
|
||||
//Program ast = ClassWithMainASTTyped.getProgram();
|
||||
String className = "ConstructorParams";
|
||||
String javacode = "src/test/resources/SimpleTests/ConstructorParams.java";
|
||||
//testByteCodeFromAst(classPath, ast ,className);
|
||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorThisDot() {
|
||||
String classPath = "src/test/resources/SimpleTests/ConstructorThisDot.class";
|
||||
//Program ast = ClassWithMainASTTyped.getProgram();
|
||||
String className = "ConstructorThisDot";
|
||||
String javacode = "src/test/resources/SimpleTests/ConstructorThisDot.java";
|
||||
//testByteCodeFromAst(classPath, ast ,className);
|
||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
|
||||
// We dont do null assignments
|
||||
/*
|
||||
@Test
|
||||
public void testExplicitNullAssign() {
|
||||
String classPath = "src/test/resources/SimpleTests/ExplicitNullAssign.class";
|
||||
//Program ast = ClassWithMainASTTyped.getProgram();
|
||||
String className = "ExplicitNullAssign";
|
||||
String javacode = "src/test/resources/SimpleTests/ExplicitNullAssign.java";
|
||||
//testByteCodeFromAst(classPath, ast ,className);
|
||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testFieldVar() {
|
||||
String classPath = "src/test/resources/SimpleTests/FieldVar.class";
|
||||
Program ast = FieldVarASTTyped.getProgram();
|
||||
String className = "FieldVar";
|
||||
String javacode = "src/test/resources/SimpleTests/FieldVar.java";
|
||||
byteCodeTester.testByteCodeFromTypedAst(classPath, ast ,className);
|
||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldWithExpr() {
|
||||
String classPath = "src/test/resources/SimpleTests/FieldWithExpr.class";
|
||||
//Program ast = ClassWithMainASTTyped.getProgram();
|
||||
String className = "FieldWithExpr";
|
||||
String javacode = "src/test/resources/SimpleTests/FieldWithExpr.java";
|
||||
//testByteCodeFromAst(classPath, ast ,className);
|
||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetterFunction() {
|
||||
String classPath = "src/test/resources/SimpleTests/GetterFunction.class";
|
||||
//Program ast = ClassWithMainASTTyped.getProgram();
|
||||
String className = "GetterFunction";
|
||||
String javacode = "src/test/resources/SimpleTests/GetterFunction.java";
|
||||
//testByteCodeFromAst(classPath, ast ,className);
|
||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDivMethod() {
|
||||
String classPath = "src/test/resources/SimpleTests/DivMethod.class";
|
||||
//Program ast = ClassWithMainASTTyped.getProgram();
|
||||
String className = "DivMethod";
|
||||
String javacode = "src/test/resources/SimpleTests/DivMethod.java";
|
||||
//byteCodeTester.testByteCodeFromAst(classPath, ast ,className);
|
||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfElseIfStatement() {
|
||||
String classPath = "src/test/resources/SimpleTests/IfElseIfStatement.class";
|
||||
//Program ast = ClassWithMainASTTyped.getProgram();
|
||||
String className = "IfElseIfStatement";
|
||||
String javacode = "src/test/resources/SimpleTests/IfElseIfStatement.java";
|
||||
//testByteCodeFromAst(classPath, ast ,className);
|
||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfElseIfStatementWithOneReturn() {
|
||||
String classPath = "src/test/resources/SimpleTests/IfElseIfStatementWithOneReturn.class";
|
||||
Program ast = IfElseIfStatementWithOneReturnAST.getProgram();
|
||||
String className = "IfElseIfStatementWithOneReturn";
|
||||
String javacode = "src/test/resources/SimpleTests/IfElseIfStatementWithOneReturn.java";
|
||||
byteCodeTester.testByteCodeFromAst(classPath, ast ,className);
|
||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testTwoClasses() {
|
||||
String jarPath = "src/test/resources/basicClasses/TwoClasses.jar";
|
||||
//Program ast = ClassWithMainASTTyped.getProgram();
|
||||
String[] classNames = {"ClassOne", "ClassTwo"};
|
||||
String javacode = "src/test/resources/basicClasses/TwoClasses.java";
|
||||
byteCodeTester.compareJarFilesFromScratch(javacode, jarPath, classNames);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testFourClasses() {
|
||||
String jarPath = "src/test/resources/basicClasses/FourClasses.jar";
|
||||
//Program ast = ClassWithMainASTTyped.getProgram();
|
||||
String[] classNames = {"FourClasses", "Test", "Test2", "Test3"};
|
||||
String javacode = "src/test/resources/basicClasses/FourClasses.java";
|
||||
byteCodeTester.compareJarFilesFromScratch(javacode, jarPath, classNames);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -31,4 +31,46 @@ public class TestAll {
|
||||
public void testPublicEmptyClass() throws Exception {
|
||||
testLexer.testTokens("basicClasses/PublicEmptyClass.java", "basicClasses/PublicEmptyClass.tokens");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFakultaet() throws Exception {
|
||||
testLexer.testTokens("basicClasses/Fakultaet.java", "basicClasses/Fakultaet.tokens");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssignWrongType() throws Exception {
|
||||
testLexer.testTokens("FailTests/AssignWrongType.java", "FailTests/AssignWrongType.tokens");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBoolAssignedInt() throws Exception {
|
||||
testLexer.testTokens("FailTests/BoolAssignedInt.java", "FailTests/BoolAssignedInt.tokens");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDivideByZero() throws Exception {
|
||||
testLexer.testTokens("FailTests/DivideByZero.java", "FailTests/DivideByZero.tokens");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDuplicateFieldDeclaration() throws Exception {
|
||||
testLexer.testTokens("FailTests/DuplicateFieldDeclaration.java", "FailTests/DuplicateFieldDeclaration.tokens");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDuplicateMethod() throws Exception {
|
||||
testLexer.testTokens("FailTests/DuplicateMethod.java", "FailTests/DuplicateMethod.tokens");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldVar() throws Exception {
|
||||
testLexer.testTokens("SimpleTests/FieldVar.java", "SimpleTests/FieldVar.tokens");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfElseIfStatementWithOneReturn() throws Exception {
|
||||
testLexer.testTokens("SimpleTests/IfElseIfStatementWithOneReturn.java", "SimpleTests/IfElseIfStatementWithOneReturn.tokens");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package Typecheck;
|
||||
|
||||
import ASTs.emptyClassAST;
|
||||
import ASTs.*;
|
||||
import abstractSyntaxTree.Program;
|
||||
import astGenerator.ASTGenerator;
|
||||
import gen.DecafLexer;
|
||||
@@ -12,7 +12,6 @@ import org.antlr.v4.runtime.tree.ParseTree;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
@@ -20,36 +19,156 @@ import static org.junit.Assert.fail;
|
||||
|
||||
public class TestAll {
|
||||
|
||||
@Test
|
||||
public void testClassWithMain() {
|
||||
Program astToBeTested = ClassWithMainAST.getProgram();
|
||||
Program correctAST = ClassWithMainASTTyped.getProgram();
|
||||
boolean expectedResult = true;
|
||||
testTypeCheck(astToBeTested, correctAST, expectedResult);
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testEmptyClass() {
|
||||
Program emptyClassAst = emptyClassAST.getEmptyProgramm();
|
||||
testTypeCheck(emptyClassAst, true);
|
||||
Program astToBeTested = emptyClassAST.getEmptyProgramm();
|
||||
Program correctAST = emptyClassASTTyped.getEmptyProgramm();
|
||||
boolean expectedResult = false;
|
||||
testTypeCheck(astToBeTested, correctAST, expectedResult);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyClassWM() {
|
||||
Program astToBeTested = emptyClassAST.getEmptyProgramm();
|
||||
Program correctAST = emptyClassASTTyped.getEmptyProgramm();
|
||||
boolean expectedResult = true;
|
||||
testTypeCheckWOM(astToBeTested, correctAST, expectedResult);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyClassWithConstructor(){
|
||||
Program abstractSyntaxTree = getAst("test/resources/basicClasses/EmptyClassWithConstructor.java");
|
||||
boolean expectedResult = true;
|
||||
testTypeCheck(abstractSyntaxTree, expectedResult);
|
||||
Program astToBeTested = EmptyClassWithConstructorAST.getProgram();
|
||||
Program correctAST = EmptyClassWithConstructorASTTyped.getProgram();
|
||||
boolean expectedResult = false;
|
||||
testTypeCheck(astToBeTested, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyClassWithConstructorWM(){
|
||||
Program astToBeTested = EmptyClassWithConstructorAST.getProgram();
|
||||
Program correctAST = EmptyClassWithConstructorASTTyped.getProgram();
|
||||
boolean expectedResult = true;
|
||||
testTypeCheckWOM(astToBeTested, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void testFourClasses(){
|
||||
Program abstractSyntaxTree = getAst("test/resources/basicClasses/FourClasses.java");
|
||||
boolean expectedResult = true;
|
||||
Program abstractSyntaxTree = getAst("src/test/resources/basicClasses/FourClasses.java");
|
||||
boolean expectedResult = false;
|
||||
testTypeCheck(abstractSyntaxTree, expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFail(){
|
||||
Program assignWrongType = getAst("test/resources/FailTests/AssignWrongType.java");
|
||||
testTypeCheck(assignWrongType, false);
|
||||
public void testFourClassesWM(){
|
||||
Program abstractSyntaxTree = getAst("src/test/resources/basicClasses/FourClasses.java");
|
||||
boolean expectedResult = true;
|
||||
testTypeCheckWM(abstractSyntaxTree, expectedResult);
|
||||
}
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void testAssignWrongType(){
|
||||
Program astToBeTested = AssignWrongTypeAST.getProgram();
|
||||
Program correctAST = AssignWrongTypeASTTyped.getProgram();
|
||||
boolean expectedResult = false;
|
||||
testTypeCheck(astToBeTested, correctAST,expectedResult);
|
||||
}
|
||||
|
||||
public void testTypeCheck(Program abstractSyntaxTree, boolean expectedResult){
|
||||
@Test
|
||||
public void testAssignWrongTypeWM(){
|
||||
Program astToBeTested = AssignWrongTypeAST.getProgram();
|
||||
Program correctAST = AssignWrongTypeASTTyped.getProgram();
|
||||
boolean expectedResult = false;
|
||||
testTypeCheckWOM(astToBeTested, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFakultaet(){
|
||||
Program astToBeTested = FakultaetAST.getProgram();
|
||||
Program correctAST = FakultaetASTTyped.getProgram();
|
||||
boolean expectedResult = true;
|
||||
testTypeCheck(astToBeTested, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDivideByZero(){
|
||||
Program astToBeTested = DivideByZeroAST.getProgram();
|
||||
Program correctAST = DivideByZeroASTTyped.getProgram();
|
||||
boolean expectedResult = true;
|
||||
testTypeCheck(astToBeTested, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharArgument(){
|
||||
Program astToBeTested = CharArgumentAST.getProgram();
|
||||
Program correctAST = CharArgumentASTTyped.getProgram();
|
||||
boolean expectedResult = true;
|
||||
testTypeCheckWOM(astToBeTested, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldVar(){
|
||||
Program astToBeTested = FieldVarAST.getProgram();
|
||||
Program correctAST = FieldVarASTTyped.getProgram();
|
||||
boolean expectedResult = true;
|
||||
testTypeCheckWOM(astToBeTested, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorParams(){
|
||||
Program astToBeTested = ConstructorParamsAST.getProgram();
|
||||
Program correctAST = ConstructorParamsASTTyped.getProgram();
|
||||
boolean expectedResult = true;
|
||||
testTypeCheckWOM(astToBeTested, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorThisDot(){
|
||||
Program astToBeTested = ConstructorThisDotAST.getProgram();
|
||||
Program correctAST = ConstructorThisDotASTTyped.getProgram();
|
||||
boolean expectedResult = true;
|
||||
testTypeCheckWOM(astToBeTested, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfElseIfStatementWithOneReturn(){
|
||||
Program astToBeTested = IfElseIfStatementWithOneReturnAST.getProgram();
|
||||
Program correctAST = IfElseIfStatementWithOneReturnASTTyped.getProgram();
|
||||
boolean expectedResult = true;
|
||||
testTypeCheckWOM(astToBeTested, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void testTypeCheckWOM(Program abstractSyntaxTree, Program correctAST, boolean expectedResult) {
|
||||
try {
|
||||
TypeChecker.assertTypeCheckResult(abstractSyntaxTree, expectedResult);
|
||||
TypeChecker.assertTypeCheckResultNoMain(abstractSyntaxTree , correctAST,expectedResult);
|
||||
} catch (Exception e) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
public void testTypeCheckWM(Program abstractSyntaxTree, Program correctAST, boolean expectedResult){
|
||||
abstractSyntaxTree.classes.add(ClassWithMainASTTyped.getRefType());
|
||||
correctAST.classes.add(ClassWithMainASTTyped.getRefType());
|
||||
ClassWithMainASTTyped.addTyping(correctAST);
|
||||
testTypeCheck(abstractSyntaxTree, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
public void testTypeCheck(Program abstractSyntaxTree, Program correctAST, boolean expectedResult){
|
||||
try {
|
||||
TypeChecker.assertTypeCheckResult(abstractSyntaxTree , correctAST,expectedResult);
|
||||
} catch (Exception e) {
|
||||
fail();
|
||||
}
|
||||
|
||||
@@ -1,30 +1,40 @@
|
||||
package Typecheck;
|
||||
|
||||
import ASTs.ClassWithMainAST;
|
||||
import TypeCheck.TypeCheckResult;
|
||||
import abstractSyntaxTree.Program;
|
||||
import gen.DecafLexer;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TypeChecker {
|
||||
// Method to test if the TypeCheck returns the expected Result
|
||||
static public void assertTypeCheckResult(Program programmToBeTested, boolean expectedResult) throws Exception {
|
||||
static public void assertTypeCheckResultNoMain(Program programmToBeTested, Program correctAST, boolean expectedResult) {
|
||||
assertTypeCheckResult(false, programmToBeTested, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
static public void assertTypeCheckResult(Program programmToBeTested, Program correctAST, boolean expectedResult) {
|
||||
assertTypeCheckResult(true, programmToBeTested, correctAST, expectedResult);
|
||||
}
|
||||
static public void assertTypeCheckResult(boolean testForMain, Program programmToBeTested, Program correctAST, boolean expectedResult) {
|
||||
boolean actualResult;
|
||||
try {
|
||||
TypeCheckResult typeCheckResult = programmToBeTested.typeCheck();
|
||||
if(testForMain){
|
||||
programmToBeTested.typeCheck();
|
||||
} else {
|
||||
programmToBeTested.typeCheckWithoutMain();
|
||||
}
|
||||
|
||||
actualResult = true;
|
||||
} catch (Exception e) {
|
||||
actualResult = false;
|
||||
}
|
||||
|
||||
assertEquals(expectedResult, actualResult);
|
||||
assertEquals(programmToBeTested.typeContext, correctAST.typeContext);
|
||||
assertEquals(programmToBeTested.methodContext, correctAST.methodContext);
|
||||
if(expectedResult){
|
||||
assertEquals(programmToBeTested, correctAST);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
22
src/test/java/Typecheck/TypingHelper.java
Normal file
22
src/test/java/Typecheck/TypingHelper.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package Typecheck;
|
||||
|
||||
import abstractSyntaxTree.Parameter.ParameterList;
|
||||
import abstractSyntaxTree.Program;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class TypingHelper {
|
||||
public static void addTypeContext(Program program, String className, HashMap<String, String> fields) {
|
||||
if (program.typeContext == null) {
|
||||
program.typeContext = new HashMap<>();
|
||||
}
|
||||
program.typeContext.put(className, fields);
|
||||
}
|
||||
|
||||
public static void addMethodContext(Program program, String className, HashMap<String, HashMap<String, ParameterList>> methods) {
|
||||
if (program.methodContext == null) {
|
||||
program.methodContext = new HashMap<>();
|
||||
}
|
||||
program.methodContext.put(className, methods);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
class EmptyClassWithConstructor{
|
||||
|
||||
public EmptyClassWithConstructor(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
class EmptyClass{}
|
||||
7
src/test/resources/FailTests/AddIntBool.java
Normal file
7
src/test/resources/FailTests/AddIntBool.java
Normal file
@@ -0,0 +1,7 @@
|
||||
class AddIntBool {
|
||||
|
||||
public int add(int myInt, bool myBool) {
|
||||
int result = myInt + myBool;
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user