Compare commits
No commits in common. "a2fa6f55d4662cf06753dd74e2bac0b49cc76a0c" and "c2c0c0b442906813768a4be33a11b70b73678e03" have entirely different histories.
a2fa6f55d4
...
c2c0c0b442
166
Grammatik.txt
Normal file
166
Grammatik.txt
Normal file
@ -0,0 +1,166 @@
|
||||
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
|
11
NichtHaskell.iml
Normal file
11
NichtHaskell.iml
Normal file
@ -0,0 +1,11 @@
|
||||
<?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$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
</component>
|
||||
</module>
|
@ -138,7 +138,7 @@ public class BlockStatement extends AbstractType implements IStatement {
|
||||
&& Objects.equals(statements, blockStatement.statements
|
||||
/*&& (Objects.equals(localVars, blockStatement.localVars)*/
|
||||
);
|
||||
System.out.println("In BlockStatement: " + result);
|
||||
System.out.println("In ParameterList: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public class ReturnStatement extends AbstractType implements IStatement{
|
||||
boolean result = (Objects.equals(expression, returnStatement.expression)
|
||||
&& Objects.equals(expression.getTypeCheckResult(), returnStatement.expression.getTypeCheckResult())
|
||||
);
|
||||
System.out.println("In ReturnStatement: " + result);
|
||||
System.out.println("In PrintStatement: " + result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -12,47 +12,12 @@ public class testAll {
|
||||
}
|
||||
|
||||
|
||||
@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();
|
||||
@ -75,16 +40,24 @@ public class testAll {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFieldVariable(){
|
||||
Program ast = FieldVarAST.getProgram();
|
||||
String pathToCode = "SimpleTests/FieldVar.java";
|
||||
public void testAssignWrongType(){
|
||||
Program ast = AssignWrongTypeAST.getProgram();
|
||||
String pathToCode = "failTests/AssignWrongType.java";
|
||||
testAst(ast, pathToCode);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDivideByZero(){
|
||||
Program ast = DivideByZeroAST.getProgram();
|
||||
String pathToCode = "failTests/DivideByzero.java";
|
||||
testAst(ast, pathToCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfElseIfStatementWithOneReturne(){
|
||||
Program ast = IfElseIfStatementWithOneReturnAST.getProgram();
|
||||
String pathToCode = "SimpleTests/IfElseIfStatementWithOneReturn.java";
|
||||
public void testcharArgument(){
|
||||
Program ast = CharArgumentAST.getProgram();
|
||||
String pathToCode = "SimpleTests/CharArgument.java";
|
||||
testAst(ast, pathToCode);
|
||||
}
|
||||
|
||||
|
@ -1,45 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -1,135 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
@ -77,6 +77,7 @@ public class ByteCodeTester {
|
||||
private Program generateAST(String pathToJavaFile){
|
||||
String content = "";
|
||||
try {
|
||||
System.out.println("Classpath: " + Path.of(pathToJavaFile));
|
||||
content = Files.readString(Path.of(pathToJavaFile));
|
||||
} catch (IOException e) {
|
||||
System.out.println("File not found!");
|
||||
@ -114,6 +115,7 @@ public class ByteCodeTester {
|
||||
public void compareJarFilesFromScratch(String javaCodePath, String jarPath, String[] classNames){
|
||||
String content = "";
|
||||
try {
|
||||
System.out.println("Classpath: " + Path.of(javaCodePath));
|
||||
content = Files.readString(Path.of(javaCodePath));
|
||||
} catch (IOException e) {
|
||||
System.out.println("File not found!");
|
||||
|
@ -98,7 +98,7 @@ public class CompareByteCodeBehaviour {
|
||||
Method method1 = methods1[i];
|
||||
Method method2 = methods2[i];
|
||||
|
||||
System.out.println("\n" + method1);
|
||||
System.out.println(method1);
|
||||
System.out.println(method2);
|
||||
|
||||
method1.setAccessible(true);
|
||||
@ -108,7 +108,7 @@ public class CompareByteCodeBehaviour {
|
||||
// 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]);
|
||||
System.out.println("TestInput: " + testInputs[j]);
|
||||
}
|
||||
|
||||
Object result1 = method1.invoke(obj1, testInputs);
|
||||
|
@ -35,11 +35,11 @@ public class TestAll {
|
||||
@Test
|
||||
public void testFakultaet() {
|
||||
String classPath = "src/test/resources/basicClasses/Fakultaet.class";
|
||||
Program ast = FakultaetAST.getProgram();
|
||||
Program ast = FakultaetASTTyped.getProgram();
|
||||
String className = "Fakultaet";
|
||||
String javacode = "src/test/resources/basicClasses/Fakultaet.java";
|
||||
byteCodeTester.testByteCodeFromAst(classPath, ast ,className);
|
||||
//byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
//byteCodeTester.testByteCodeFromTypedAst(classPath, ast ,className);
|
||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -92,6 +92,15 @@ public class TestAll {
|
||||
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";
|
||||
//testByteCodeFromAst(classPath, ast ,className);
|
||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
// We dont do null assignments
|
||||
/*
|
||||
@ -109,10 +118,10 @@ public class TestAll {
|
||||
@Test
|
||||
public void testFieldVar() {
|
||||
String classPath = "src/test/resources/SimpleTests/FieldVar.class";
|
||||
Program ast = FieldVarASTTyped.getProgram();
|
||||
//Program ast = ClassWithMainASTTyped.getProgram();
|
||||
String className = "FieldVar";
|
||||
String javacode = "src/test/resources/SimpleTests/FieldVar.java";
|
||||
byteCodeTester.testByteCodeFromTypedAst(classPath, ast ,className);
|
||||
//testByteCodeFromAst(classPath, ast ,className);
|
||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@ -126,7 +135,6 @@ public class TestAll {
|
||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetterFunction() {
|
||||
String classPath = "src/test/resources/SimpleTests/GetterFunction.class";
|
||||
@ -137,16 +145,6 @@ public class TestAll {
|
||||
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";
|
||||
@ -160,10 +158,10 @@ public class TestAll {
|
||||
@Test
|
||||
public void testIfElseIfStatementWithOneReturn() {
|
||||
String classPath = "src/test/resources/SimpleTests/IfElseIfStatementWithOneReturn.class";
|
||||
Program ast = IfElseIfStatementWithOneReturnAST.getProgram();
|
||||
//Program ast = ClassWithMainASTTyped.getProgram();
|
||||
String className = "IfElseIfStatementWithOneReturn";
|
||||
String javacode = "src/test/resources/SimpleTests/IfElseIfStatementWithOneReturn.java";
|
||||
byteCodeTester.testByteCodeFromAst(classPath, ast ,className);
|
||||
//testByteCodeFromAst(classPath, ast ,className);
|
||||
byteCodeTester.testClassFileFromScratch(classPath, javacode, className);
|
||||
}
|
||||
|
||||
@ -187,6 +185,17 @@ public class TestAll {
|
||||
byteCodeTester.compareJarFilesFromScratch(javacode, jarPath, classNames);
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
public void testDijkstra() {
|
||||
String jarPath = "src/test/resources/Integration/Dijkstra.jar";
|
||||
//Program ast = ClassWithMainASTTyped.getProgram();
|
||||
String[] classNames = {"FourClasses", "Test", "Test2", "Test3"};
|
||||
String javacode = "src/test/resources/Integration/Dijkstra.java";
|
||||
byteCodeTester.compareJarFilesFromScratch(javacode, jarPath, classNames);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -21,44 +21,44 @@ public class TestAll {
|
||||
|
||||
@Test
|
||||
public void testClassWithMain() {
|
||||
Program astToBeTested = ClassWithMainAST.getProgram();
|
||||
Program emptyClassAst = ClassWithMainAST.getProgram();
|
||||
Program correctAST = ClassWithMainASTTyped.getProgram();
|
||||
boolean expectedResult = true;
|
||||
testTypeCheck(astToBeTested, correctAST, expectedResult);
|
||||
testTypeCheck(emptyClassAst, correctAST, expectedResult);
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testEmptyClass() {
|
||||
Program astToBeTested = emptyClassAST.getEmptyProgramm();
|
||||
Program emptyClassAst = emptyClassAST.getEmptyProgramm();
|
||||
Program correctAST = emptyClassASTTyped.getEmptyProgramm();
|
||||
boolean expectedResult = false;
|
||||
testTypeCheck(astToBeTested, correctAST, expectedResult);
|
||||
testTypeCheck(emptyClassAst, correctAST, expectedResult);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyClassWM() {
|
||||
Program astToBeTested = emptyClassAST.getEmptyProgramm();
|
||||
Program emptyClassAst = emptyClassAST.getEmptyProgramm();
|
||||
Program correctAST = emptyClassASTTyped.getEmptyProgramm();
|
||||
boolean expectedResult = true;
|
||||
testTypeCheckWOM(astToBeTested, correctAST, expectedResult);
|
||||
testTypeCheckWM(emptyClassAst, correctAST, expectedResult);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyClassWithConstructor(){
|
||||
Program astToBeTested = EmptyClassWithConstructorAST.getProgram();
|
||||
Program abstractSyntaxTree = EmptyClassWithConstructorAST.getProgram();
|
||||
Program correctAST = EmptyClassWithConstructorASTTyped.getProgram();
|
||||
boolean expectedResult = false;
|
||||
testTypeCheck(astToBeTested, correctAST, expectedResult);
|
||||
testTypeCheck(abstractSyntaxTree, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyClassWithConstructorWM(){
|
||||
Program astToBeTested = EmptyClassWithConstructorAST.getProgram();
|
||||
Program abstractSyntaxTree = EmptyClassWithConstructorAST.getProgram();
|
||||
Program correctAST = EmptyClassWithConstructorASTTyped.getProgram();
|
||||
boolean expectedResult = true;
|
||||
testTypeCheckWOM(astToBeTested, correctAST, expectedResult);
|
||||
testTypeCheckWM(abstractSyntaxTree, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -79,78 +79,44 @@ public class TestAll {
|
||||
|
||||
@Test
|
||||
public void testAssignWrongType(){
|
||||
Program astToBeTested = AssignWrongTypeAST.getProgram();
|
||||
Program assignWrongType = AssignWrongTypeAST.getProgram();
|
||||
Program correctAST = AssignWrongTypeASTTyped.getProgram();
|
||||
boolean expectedResult = false;
|
||||
testTypeCheck(astToBeTested, correctAST,expectedResult);
|
||||
testTypeCheck(assignWrongType, correctAST,expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssignWrongTypeWM(){
|
||||
Program astToBeTested = AssignWrongTypeAST.getProgram();
|
||||
Program assignWrongType = AssignWrongTypeAST.getProgram();
|
||||
Program correctAST = AssignWrongTypeASTTyped.getProgram();
|
||||
boolean expectedResult = false;
|
||||
testTypeCheckWOM(astToBeTested, correctAST, expectedResult);
|
||||
testTypeCheckWM(assignWrongType, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFakultaet(){
|
||||
Program astToBeTested = FakultaetAST.getProgram();
|
||||
Program fakultaet = FakultaetAST.getProgram();
|
||||
Program correctAST = FakultaetASTTyped.getProgram();
|
||||
boolean expectedResult = true;
|
||||
testTypeCheck(astToBeTested, correctAST, expectedResult);
|
||||
testTypeCheck(fakultaet, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDivideByZero(){
|
||||
Program astToBeTested = DivideByZeroAST.getProgram();
|
||||
Program fakultaet = DivideByZeroAST.getProgram();
|
||||
Program correctAST = DivideByZeroASTTyped.getProgram();
|
||||
boolean expectedResult = true;
|
||||
testTypeCheck(astToBeTested, correctAST, expectedResult);
|
||||
testTypeCheck(fakultaet, correctAST, expectedResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharArgument(){
|
||||
Program astToBeTested = CharArgumentAST.getProgram();
|
||||
Program fakultaet = CharArgumentAST.getProgram();
|
||||
Program correctAST = CharArgumentASTTyped.getProgram();
|
||||
boolean expectedResult = true;
|
||||
testTypeCheckWOM(astToBeTested, correctAST, expectedResult);
|
||||
testTypeCheckWOM(fakultaet, 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 {
|
||||
|
@ -1,5 +1,5 @@
|
||||
class FieldVar {
|
||||
|
||||
int variable;
|
||||
int field;
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ Class: "class"
|
||||
Identifier: "FieldVar"
|
||||
OpenCurlyBracket: "{"
|
||||
Int: "int"
|
||||
Identifier: "variable"
|
||||
Identifier: "field"
|
||||
Semicolon: ";"
|
||||
ClosedCurlyBracket: "}"
|
||||
EOF: "<EOF>"
|
Loading…
Reference in New Issue
Block a user