mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 16:28:04 +00:00
fixed program instead of classes and implemented some tests for typecheck
This commit is contained in:
parent
e97b9e55c8
commit
99d2e7a104
@ -12,7 +12,7 @@ public class Type {
|
|||||||
}
|
}
|
||||||
private final Kind kind;
|
private final Kind kind;
|
||||||
private final String reference;
|
private final String reference;
|
||||||
public Type(Kind kind, String reference){
|
private Type(Kind kind, String reference){
|
||||||
this.kind = kind;
|
this.kind = kind;
|
||||||
this.reference = reference;
|
this.reference = reference;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import de.maishai.typedast.MethodContext;
|
|||||||
import de.maishai.typedast.TypedExpression;
|
import de.maishai.typedast.TypedExpression;
|
||||||
import de.maishai.typedast.TypedStatement;
|
import de.maishai.typedast.TypedStatement;
|
||||||
import de.maishai.typedast.Type;
|
import de.maishai.typedast.Type;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
@ -15,6 +16,7 @@ import java.util.Map;
|
|||||||
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
public class TypedAssignment implements TypedStatement {
|
public class TypedAssignment implements TypedStatement {
|
||||||
private TypedExpression value;
|
private TypedExpression value;
|
||||||
private TypedFieldVarAccess location;
|
private TypedFieldVarAccess location;
|
||||||
|
@ -5,6 +5,7 @@ import de.maishai.ast.records.Binary;
|
|||||||
import de.maishai.typedast.MethodContext;
|
import de.maishai.typedast.MethodContext;
|
||||||
import de.maishai.typedast.TypedExpression;
|
import de.maishai.typedast.TypedExpression;
|
||||||
import de.maishai.typedast.Type;
|
import de.maishai.typedast.Type;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
@ -15,6 +16,7 @@ import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class TypedBinary implements TypedExpression {
|
public class TypedBinary implements TypedExpression {
|
||||||
private TypedExpression left;
|
private TypedExpression left;
|
||||||
private Operator op;
|
private Operator op;
|
||||||
|
@ -4,6 +4,7 @@ import de.maishai.ast.records.*;
|
|||||||
import de.maishai.typedast.MethodContext;
|
import de.maishai.typedast.MethodContext;
|
||||||
import de.maishai.typedast.TypedExpression;
|
import de.maishai.typedast.TypedExpression;
|
||||||
import de.maishai.typedast.Type;
|
import de.maishai.typedast.Type;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
@ -14,6 +15,7 @@ import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
public class TypedFieldVarAccess implements TypedExpression {
|
public class TypedFieldVarAccess implements TypedExpression {
|
||||||
private Boolean field;
|
private Boolean field;
|
||||||
private TypedExpression recursiveOwnerChain;
|
private TypedExpression recursiveOwnerChain;
|
||||||
|
@ -20,7 +20,7 @@ import de.maishai.typedast.Type;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AbstractSyntax_ClassWithConstructor {
|
public class AbstractSyntax_ClassWithConstructor {
|
||||||
public static Class get() {
|
public static Program get() {
|
||||||
List<Declaration> declarations = List.of(
|
List<Declaration> declarations = List.of(
|
||||||
new Declaration(
|
new Declaration(
|
||||||
"x",
|
"x",
|
||||||
@ -29,11 +29,15 @@ public class AbstractSyntax_ClassWithConstructor {
|
|||||||
);
|
);
|
||||||
List<Method> methods = List.of();
|
List<Method> methods = List.of();
|
||||||
List<Constructor> constructors = getConstructors();
|
List<Constructor> constructors = getConstructors();
|
||||||
return new Class(
|
return new Program(
|
||||||
|
List.of(
|
||||||
|
new Class(
|
||||||
"ClassWithConstructor",
|
"ClassWithConstructor",
|
||||||
declarations,
|
declarations,
|
||||||
methods,
|
methods,
|
||||||
constructors
|
constructors
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import de.maishai.typedast.Type;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AbstractSyntax_ClassWithConstructorAndMethodCall {
|
public class AbstractSyntax_ClassWithConstructorAndMethodCall {
|
||||||
public static Class get() {
|
public static Program get() {
|
||||||
List<Declaration> declarationList = List.of(
|
List<Declaration> declarationList = List.of(
|
||||||
new Declaration(
|
new Declaration(
|
||||||
"x",
|
"x",
|
||||||
@ -35,11 +35,15 @@ public class AbstractSyntax_ClassWithConstructorAndMethodCall {
|
|||||||
);
|
);
|
||||||
List<Method> methodList = getMethods();
|
List<Method> methodList = getMethods();
|
||||||
List<Constructor> constructorList = getConstructors();
|
List<Constructor> constructorList = getConstructors();
|
||||||
return new Class(
|
return new Program(
|
||||||
|
List.of(
|
||||||
|
new Class(
|
||||||
"ClassWithConstructorAndMethodCall",
|
"ClassWithConstructorAndMethodCall",
|
||||||
declarationList,
|
declarationList,
|
||||||
methodList,
|
methodList,
|
||||||
constructorList
|
constructorList
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +65,7 @@ public class AbstractSyntax_ClassWithConstructorAndMethodCall {
|
|||||||
new While(
|
new While(
|
||||||
new MethodCall(
|
new MethodCall(
|
||||||
new FieldVarAccess(
|
new FieldVarAccess(
|
||||||
true,
|
false,
|
||||||
null,
|
null,
|
||||||
"methodCall"),
|
"methodCall"),
|
||||||
List.of()
|
List.of()
|
||||||
|
@ -21,7 +21,7 @@ import de.maishai.typedast.Type;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AbstractSyntax_ClassWithConstructorWithCodeInComments {
|
public class AbstractSyntax_ClassWithConstructorWithCodeInComments {
|
||||||
public static Class get() {
|
public static Program get() {
|
||||||
List<Declaration> declarations = List.of(
|
List<Declaration> declarations = List.of(
|
||||||
new Declaration(
|
new Declaration(
|
||||||
"x",
|
"x",
|
||||||
@ -30,11 +30,15 @@ public class AbstractSyntax_ClassWithConstructorWithCodeInComments {
|
|||||||
);
|
);
|
||||||
List<Method> methods = List.of();
|
List<Method> methods = List.of();
|
||||||
List<Constructor> constructors = getConstructors();
|
List<Constructor> constructors = getConstructors();
|
||||||
return new Class(
|
return new Program(
|
||||||
|
List.of(
|
||||||
|
new Class(
|
||||||
"ClassWithConstructorWithCodeInComments",
|
"ClassWithConstructorWithCodeInComments",
|
||||||
declarations,
|
declarations,
|
||||||
methods,
|
methods,
|
||||||
constructors
|
constructors
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
import de.maishai.ast.Operator;
|
import de.maishai.ast.Operator;
|
||||||
import de.maishai.ast.records.*;
|
import de.maishai.ast.records.*;
|
||||||
import de.maishai.ast.records.Class;
|
import de.maishai.ast.records.Class;
|
||||||
@ -21,7 +22,7 @@ import de.maishai.typedast.Type;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AbstractSyntax_ClassWithConstructorWithParameters {
|
public class AbstractSyntax_ClassWithConstructorWithParameters {
|
||||||
public static Class get() {
|
public static Program get() {
|
||||||
List<Declaration> declarations = List.of(
|
List<Declaration> declarations = List.of(
|
||||||
new Declaration(
|
new Declaration(
|
||||||
"x",
|
"x",
|
||||||
@ -29,11 +30,15 @@ public class AbstractSyntax_ClassWithConstructorWithParameters {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
List<Constructor> constructors = getConstructors();
|
List<Constructor> constructors = getConstructors();
|
||||||
return new Class(
|
return new Program(
|
||||||
|
List.of(
|
||||||
|
new Class(
|
||||||
"ClassWithConstructorWithParameters",
|
"ClassWithConstructorWithParameters",
|
||||||
declarations,
|
declarations,
|
||||||
List.of(),
|
List.of(),
|
||||||
constructors
|
constructors
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import de.maishai.typedast.Type;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AbstractSyntax_ClassWithField {
|
public class AbstractSyntax_ClassWithField {
|
||||||
public static Class get() {
|
public static Program get() {
|
||||||
List<Declaration> declarations = List.of(
|
List<Declaration> declarations = List.of(
|
||||||
new Declaration(
|
new Declaration(
|
||||||
"x",
|
"x",
|
||||||
@ -28,11 +28,15 @@ public class AbstractSyntax_ClassWithField {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return new Class(
|
return new Program(
|
||||||
|
List.of(
|
||||||
|
new Class(
|
||||||
"ClassWithField",
|
"ClassWithField",
|
||||||
declarations,
|
declarations,
|
||||||
methods,
|
methods,
|
||||||
constructors
|
constructors
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,9 +11,11 @@ import de.maishai.typedast.Type;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AbstractSyntax_ClassWithMethod {
|
public class AbstractSyntax_ClassWithMethod {
|
||||||
public static Class get() {
|
public static Program get() {
|
||||||
List<Method> methods = getMethods();
|
List<Method> methods = getMethods();
|
||||||
return new Class(
|
return new Program(
|
||||||
|
List.of(
|
||||||
|
new Class(
|
||||||
"ClassWithMethod",
|
"ClassWithMethod",
|
||||||
List.of(),
|
List.of(),
|
||||||
methods,
|
methods,
|
||||||
@ -27,6 +29,8 @@ public class AbstractSyntax_ClassWithMethod {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import de.maishai.typedast.Type;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
class AbstractSyntax_ClassWithMethodAndField {
|
class AbstractSyntax_ClassWithMethodAndField {
|
||||||
public static Class get() {
|
public static Program get() {
|
||||||
List<Declaration> declarations = List.of(
|
List<Declaration> declarations = List.of(
|
||||||
new Declaration(
|
new Declaration(
|
||||||
"c",
|
"c",
|
||||||
@ -27,11 +27,15 @@ class AbstractSyntax_ClassWithMethodAndField {
|
|||||||
);
|
);
|
||||||
List<Method> methods = getMethods();
|
List<Method> methods = getMethods();
|
||||||
List<Constructor> constructors = getConstructors();
|
List<Constructor> constructors = getConstructors();
|
||||||
return new Class(
|
return new Program(
|
||||||
|
List.of(
|
||||||
|
new Class(
|
||||||
"ClassWithMethodAndField",
|
"ClassWithMethodAndField",
|
||||||
declarations,
|
declarations,
|
||||||
methods,
|
methods,
|
||||||
constructors
|
constructors
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import de.maishai.typedast.Type;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AbstractSyntax_ClassWithMultipleMethods {
|
public class AbstractSyntax_ClassWithMultipleMethods {
|
||||||
public static Class get() {
|
public static Program get() {
|
||||||
List<Declaration> declarations = List.of(
|
List<Declaration> declarations = List.of(
|
||||||
new Declaration(
|
new Declaration(
|
||||||
"instance",
|
"instance",
|
||||||
@ -35,11 +35,14 @@ public class AbstractSyntax_ClassWithMultipleMethods {
|
|||||||
);
|
);
|
||||||
List<Method> methods = getMethods();
|
List<Method> methods = getMethods();
|
||||||
List<Constructor> constructors = List.of();
|
List<Constructor> constructors = List.of();
|
||||||
return new Class(
|
return new Program(
|
||||||
|
List.of(new Class(
|
||||||
"ClassWithMoreComplexMethodAndMain",
|
"ClassWithMoreComplexMethodAndMain",
|
||||||
declarations,
|
declarations,
|
||||||
methods,
|
methods,
|
||||||
constructors
|
constructors
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,12 +4,15 @@
|
|||||||
import de.maishai.ast.records.Block;
|
import de.maishai.ast.records.Block;
|
||||||
import de.maishai.ast.records.Class;
|
import de.maishai.ast.records.Class;
|
||||||
import de.maishai.ast.records.Constructor;
|
import de.maishai.ast.records.Constructor;
|
||||||
|
import de.maishai.ast.records.Program;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AbstractSyntax_PublicClass {
|
public class AbstractSyntax_PublicClass {
|
||||||
public static Class get() {
|
public static Program get() {
|
||||||
return new Class(
|
return new Program(
|
||||||
|
List.of(
|
||||||
|
new Class(
|
||||||
"PublicClass",
|
"PublicClass",
|
||||||
List.of(),
|
List.of(),
|
||||||
List.of(),
|
List.of(),
|
||||||
@ -23,6 +26,8 @@ public class AbstractSyntax_PublicClass {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,140 +14,230 @@
|
|||||||
|
|
||||||
import de.maishai.ast.Operator;
|
import de.maishai.ast.Operator;
|
||||||
import de.maishai.typedast.Type;
|
import de.maishai.typedast.Type;
|
||||||
|
import de.maishai.typedast.TypedStatement;
|
||||||
import de.maishai.typedast.typedclass.*;
|
import de.maishai.typedast.typedclass.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TypedAbstractSyntax_ClassWithConstructor {
|
public class TypedAbstractSyntax_ClassWithConstructor {
|
||||||
// public static TypedClass get() {
|
public static TypedClass get() {
|
||||||
// TypedClass typedClass = new TypedClass();
|
return new TypedClass(
|
||||||
// typedClass.setIsPublic(true);
|
"ClassWithConstructor",
|
||||||
// typedClass.setTypedId(new TypedId("ClassWithConstructor"));
|
List.of(
|
||||||
//
|
new TypedDeclaration(
|
||||||
// TypedField typedField = new TypedField();
|
"x",
|
||||||
// typedField.setTypedId(new TypedId("x"));
|
Type.INT
|
||||||
// typedField.setType(Type.INT);
|
)
|
||||||
//
|
),
|
||||||
// typedClass.setTypedFields(List.of(typedField));
|
List.of(),
|
||||||
// typedClass.setTypedMethods(List.of());
|
List.of(
|
||||||
// typedClass.setTypedMainMethod(null);
|
new TypedConstructor(
|
||||||
// typedClass.setTypedConstructors(getConstructors());
|
"ClassWithConstructor",
|
||||||
// return typedClass;
|
List.of(),
|
||||||
// }
|
new TypedBlock(
|
||||||
//
|
List.of(),
|
||||||
// private static List<TypedConstructor> getConstructors() {
|
List.of(),
|
||||||
// return List.of(getConstructor1());
|
Type.VOID
|
||||||
// }
|
),
|
||||||
//
|
Type.VOID,
|
||||||
// private static TypedConstructor getConstructor1() {
|
List.of(
|
||||||
// TypedConstructor typedConstructor = new TypedConstructor();
|
new TypedLocalVariable(
|
||||||
// typedConstructor.setIsPublic(true);
|
"i",
|
||||||
// typedConstructor.setTypedId(new TypedId("ClassWithConstructor"));
|
Type.INT
|
||||||
// typedConstructor.setTypedParameters(List.of());
|
)
|
||||||
//
|
)
|
||||||
// TypedBlock typedBlock = new TypedBlock();
|
)
|
||||||
//
|
),
|
||||||
// TypedLocalVariable typedLocalVariable = new TypedLocalVariable();
|
null,
|
||||||
// typedLocalVariable.setTypedId(new TypedId("i"));
|
null,
|
||||||
// typedLocalVariable.setType(Type.INT);
|
Type.REFERENCE("ClassWithField")
|
||||||
//
|
);
|
||||||
// typedBlock.setVars(List.of(typedLocalVariable));
|
}
|
||||||
//
|
|
||||||
// TypedAssignment typedAssignment = new TypedAssignment();
|
private static List<TypedConstructor> getConstructors() {
|
||||||
// typedAssignment.setLoc(new TypedId("x"));
|
return List.of(getTypedConstructor1());
|
||||||
//// typedAssignment.setAssignSign(AssignSign.ASSIGN);
|
}
|
||||||
// typedAssignment.setValue(new TypedIntLiteral(10));
|
|
||||||
//
|
private static TypedConstructor getTypedConstructor1() {
|
||||||
// TypedFor typedFor = new TypedFor();
|
List<TypedParameter> typedParameters = List.of();
|
||||||
//
|
|
||||||
// TypedAssignment typedAssignmentFor = new TypedAssignment();
|
List<TypedLocalVariable> typedLocalVariables = List.of(
|
||||||
// typedAssignmentFor.setLoc(new TypedId("i"));
|
new TypedLocalVariable(
|
||||||
//// typedAssignmentFor.setAssignSign(AssignSign.ASSIGN);
|
"i",
|
||||||
// typedAssignmentFor.setValue(new TypedIntLiteral(0));
|
Type.INT
|
||||||
//
|
)
|
||||||
//// typedFor.setAssign(typedAssignmentFor);
|
);
|
||||||
//
|
List<TypedStatement> typedStatementList =
|
||||||
// TypedBinary typedBinaryFor = new TypedBinary();
|
List.of(
|
||||||
// typedBinaryFor.setLeft(new TypedId("i"));
|
new TypedAssignment(
|
||||||
// typedBinaryFor.setOp(Operator.LT);
|
new TypedIntLiteral(
|
||||||
// typedBinaryFor.setRight(new TypedIntLiteral(6));
|
10,
|
||||||
//
|
Type.INT),
|
||||||
// typedFor.setCond(typedBinaryFor);
|
new TypedFieldVarAccess(
|
||||||
//
|
true,
|
||||||
// TypedBinary typedBinaryForIncr = new TypedBinary();
|
null,
|
||||||
// typedBinaryForIncr.setLeft(new TypedId("i"));
|
"x",
|
||||||
// typedBinaryForIncr.setOp(Operator.ADD);
|
Type.INT
|
||||||
// typedBinaryForIncr.setRight(new TypedIntLiteral(1));
|
),
|
||||||
//
|
Type.INT
|
||||||
// TypedAssignment typedAssignmentForIncr = new TypedAssignment();
|
),
|
||||||
// typedAssignmentForIncr.setLoc(new TypedId("i"));
|
new TypedFor(
|
||||||
//// typedAssignmentForIncr.setAssignSign(AssignSign.ASSIGN);
|
new TypedAssignment(
|
||||||
// typedAssignmentForIncr.setValue(typedBinaryForIncr);
|
new TypedIntLiteral(
|
||||||
//
|
0,
|
||||||
//// typedFor.setInc(typedAssignmentForIncr);
|
Type.INT),
|
||||||
//
|
new TypedFieldVarAccess(
|
||||||
// TypedBlock typedBlockFor = new TypedBlock();
|
false,
|
||||||
//
|
null,
|
||||||
// TypedLocalVariable typedLocalVariableFor = new TypedLocalVariable();
|
"i",
|
||||||
// typedLocalVariableFor.setTypedId(new TypedId("j"));
|
Type.INT
|
||||||
// typedLocalVariableFor.setType(Type.INT);
|
),
|
||||||
//
|
Type.INT
|
||||||
// typedBlockFor.setVars(List.of(typedLocalVariableFor));
|
),
|
||||||
//
|
new TypedBinary(
|
||||||
// TypedFor typedInnerFor = new TypedFor();
|
new TypedFieldVarAccess(
|
||||||
//
|
false,
|
||||||
// TypedAssignment typedAssignmentInnerFor = new TypedAssignment();
|
null,
|
||||||
// typedAssignmentInnerFor.setLoc(new TypedId("j"));
|
"i",
|
||||||
//// typedAssignmentInnerFor.setAssignSign(AssignSign.ASSIGN);
|
Type.INT
|
||||||
// typedAssignmentInnerFor.setValue(new TypedIntLiteral(0));
|
),
|
||||||
//
|
Operator.LT,
|
||||||
//// typedInnerFor.setAssign(typedAssignmentInnerFor);
|
new TypedIntLiteral(
|
||||||
//
|
6,
|
||||||
// TypedBinary typedBinaryInnerFor = new TypedBinary();
|
Type.INT
|
||||||
// typedBinaryInnerFor.setLeft(new TypedId("j"));
|
),
|
||||||
// typedBinaryInnerFor.setOp(Operator.LT);
|
Type.BOOL
|
||||||
// typedBinaryInnerFor.setRight(new TypedId("x"));
|
),
|
||||||
//
|
new TypedAssignment(
|
||||||
// typedInnerFor.setCond(typedBinaryInnerFor);
|
new TypedBinary(
|
||||||
//
|
new TypedFieldVarAccess(
|
||||||
// TypedAssignment typedAssignmentInnerForIncr = new TypedAssignment();
|
false,
|
||||||
// typedAssignmentInnerForIncr.setLoc(new TypedId("j"));
|
null,
|
||||||
//// typedAssignmentInnerForIncr.setAssignSign(AssignSign.ADD_ASSIGN);
|
"i",
|
||||||
// typedAssignmentInnerForIncr.setValue(new TypedIntLiteral(1));
|
Type.INT),
|
||||||
//
|
Operator.ADD,
|
||||||
//// typedInnerFor.setInc(typedAssignmentInnerForIncr);
|
new TypedIntLiteral(
|
||||||
//
|
1,
|
||||||
// TypedBlock typedBlockInnerFor = new TypedBlock();
|
Type.INT
|
||||||
// typedBlockInnerFor.setVars(List.of());
|
),
|
||||||
//
|
Type.INT
|
||||||
// TypedAssignment typedAssignmentInnerForBlock = new TypedAssignment();
|
),
|
||||||
// typedAssignmentInnerForBlock.setLoc(new TypedId("x"));
|
new TypedFieldVarAccess(
|
||||||
//// typedAssignmentInnerForBlock.setAssignSign(AssignSign.ASSIGN);
|
false,
|
||||||
//
|
null,
|
||||||
// TypedBinary typedBinaryInnerForBlock = new TypedBinary();
|
"i",
|
||||||
// typedBinaryInnerForBlock.setLeft(new TypedId("x"));
|
Type.INT
|
||||||
// typedBinaryInnerForBlock.setOp(Operator.MUL);
|
),
|
||||||
// typedBinaryInnerForBlock.setRight(new TypedId("x"));
|
Type.INT
|
||||||
//
|
),
|
||||||
// typedAssignmentInnerForBlock.setValue(typedBinaryInnerForBlock);
|
new TypedBlock(
|
||||||
//
|
List.of(
|
||||||
// typedBlockInnerFor.setStmts(List.of(typedAssignmentInnerForBlock));
|
new TypedLocalVariable(
|
||||||
//
|
"j",
|
||||||
// typedInnerFor.setTypedBlock(typedBlockInnerFor);
|
Type.INT
|
||||||
//
|
)
|
||||||
// typedBlockFor.setStmts(List.of(typedInnerFor));
|
),
|
||||||
//
|
List.of(
|
||||||
// typedFor.setTypedBlock(typedBlockFor);
|
new TypedFor(
|
||||||
//
|
new TypedAssignment(
|
||||||
// typedBlock.setStmts(
|
new TypedIntLiteral(
|
||||||
// List.of(
|
0,
|
||||||
// typedAssignment,
|
Type.INT),
|
||||||
// typedFor
|
new TypedFieldVarAccess(
|
||||||
// )
|
false,
|
||||||
// );
|
null,
|
||||||
//
|
"j",
|
||||||
// typedConstructor.setTypedBlock(typedBlock);
|
Type.INT
|
||||||
//
|
),
|
||||||
// return typedConstructor;
|
Type.INT
|
||||||
// }
|
),
|
||||||
|
new TypedBinary(
|
||||||
|
new TypedFieldVarAccess(
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
"j",
|
||||||
|
Type.INT
|
||||||
|
),
|
||||||
|
Operator.LT,
|
||||||
|
new TypedFieldVarAccess(
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
"x",
|
||||||
|
Type.INT
|
||||||
|
),
|
||||||
|
Type.BOOL
|
||||||
|
),
|
||||||
|
new TypedAssignment(
|
||||||
|
new TypedBinary(
|
||||||
|
new TypedFieldVarAccess(
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
"j",
|
||||||
|
Type.INT),
|
||||||
|
Operator.ADD,
|
||||||
|
new TypedIntLiteral(
|
||||||
|
1,
|
||||||
|
Type.INT
|
||||||
|
),
|
||||||
|
Type.INT
|
||||||
|
),
|
||||||
|
new TypedFieldVarAccess(
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
"j",
|
||||||
|
Type.INT
|
||||||
|
),
|
||||||
|
Type.INT
|
||||||
|
),
|
||||||
|
new TypedBlock(
|
||||||
|
List.of(),
|
||||||
|
List.of(
|
||||||
|
new TypedAssignment(
|
||||||
|
new TypedBinary(
|
||||||
|
new TypedFieldVarAccess(
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
"x",
|
||||||
|
Type.INT),
|
||||||
|
Operator.MUL,
|
||||||
|
new TypedFieldVarAccess(
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
"x",
|
||||||
|
Type.INT),
|
||||||
|
Type.INT
|
||||||
|
),
|
||||||
|
new TypedFieldVarAccess(
|
||||||
|
true,
|
||||||
|
null,
|
||||||
|
"x",
|
||||||
|
Type.INT
|
||||||
|
),
|
||||||
|
Type.INT
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Type.INT
|
||||||
|
),
|
||||||
|
Type.INT
|
||||||
|
)
|
||||||
|
),
|
||||||
|
Type.INT
|
||||||
|
),
|
||||||
|
Type.INT
|
||||||
|
)
|
||||||
|
);
|
||||||
|
TypedBlock typedBlock = new TypedBlock(
|
||||||
|
typedLocalVariables,
|
||||||
|
typedStatementList,
|
||||||
|
Type.INT
|
||||||
|
);
|
||||||
|
|
||||||
|
return new TypedConstructor(
|
||||||
|
"ClassWithConstructor",
|
||||||
|
typedParameters,
|
||||||
|
typedBlock,
|
||||||
|
Type.VOID,
|
||||||
|
List.of()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
@ -9,18 +9,32 @@ import de.maishai.typedast.typedclass.*;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TypedAbstractSyntax_ClassWithField {
|
public class TypedAbstractSyntax_ClassWithField {
|
||||||
// public static TypedClass get() {
|
public static TypedClass get() {
|
||||||
// TypedClass typedClass = new TypedClass();
|
return new TypedClass(
|
||||||
// typedClass.setIsPublic(true);
|
"ClassWithField",
|
||||||
// typedClass.setTypedId(new TypedId("ClassWithField"));
|
List.of(
|
||||||
// typedClass.setTypedFields(
|
new TypedDeclaration(
|
||||||
// List.of(
|
"x",
|
||||||
// new TypedField(new TypedId("x"), Type.INT)
|
Type.INT
|
||||||
// )
|
)
|
||||||
// );
|
),
|
||||||
// typedClass.setTypedMethods(List.of());
|
List.of(),
|
||||||
// typedClass.setTypedMainMethod(null);
|
List.of(
|
||||||
// typedClass.setTypedConstructors(List.of());
|
new TypedConstructor(
|
||||||
// return typedClass;
|
"ClassWithField",
|
||||||
// }
|
List.of(),
|
||||||
|
new TypedBlock(
|
||||||
|
List.of(),
|
||||||
|
List.of(),
|
||||||
|
Type.VOID
|
||||||
|
),
|
||||||
|
Type.VOID,
|
||||||
|
List.of()
|
||||||
|
)
|
||||||
|
),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
Type.REFERENCE("ClassWithField")
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,19 +1,33 @@
|
|||||||
//public class PublicClass {
|
//public class PublicClass {
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
import de.maishai.typedast.Type;
|
||||||
import de.maishai.typedast.typedclass.*;
|
import de.maishai.typedast.typedclass.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TypedAbstractSyntax_PublicClass {
|
public class TypedAbstractSyntax_PublicClass {
|
||||||
// public static TypedClass get() {
|
public static TypedClass get() {
|
||||||
// TypedClass typedClass = new TypedClass();
|
return new TypedClass(
|
||||||
// typedClass.setIsPublic(true);
|
"PublicClass",
|
||||||
// typedClass.setTypedId(new TypedId("PublicClass"));
|
List.of(),
|
||||||
// typedClass.setTypedFields(List.of());
|
List.of(),
|
||||||
// typedClass.setTypedMethods(List.of());
|
List.of(
|
||||||
// typedClass.setTypedMainMethod(null);
|
new TypedConstructor(
|
||||||
// typedClass.setTypedConstructors(List.of());
|
"PublicClass",
|
||||||
// return typedClass;
|
List.of(),
|
||||||
// }
|
new TypedBlock(
|
||||||
|
List.of(),
|
||||||
|
List.of(),
|
||||||
|
Type.VOID
|
||||||
|
),
|
||||||
|
Type.VOID,
|
||||||
|
List.of()
|
||||||
|
)
|
||||||
|
),
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
Type.REFERENCE("PublicClass")
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
@ -48,9 +48,15 @@ public class ScannerParserTests {
|
|||||||
assertEquals(AbstractSyntax_ClassWithMethodAndField.get(), resultAst);
|
assertEquals(AbstractSyntax_ClassWithMethodAndField.get(), resultAst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClassWithConstructorAndMethodCall() {
|
||||||
|
Class resultAst = Compiler.generateASTFromFile("src/main/resources/JavaTestfiles/ClassWithConstructorAndMethodCall.java");
|
||||||
|
assertEquals(AbstractSyntax_ClassWithConstructorAndMethodCall.get(), resultAst);
|
||||||
|
}
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
// public void testClassWithConstructorAndMethodCall() {
|
// public void testClassCanBeTyped() {
|
||||||
// Class resultAst = Compiler.generateASTFromFile("src/main/resources/JavaTestfiles/ClassWithConstructorAndMethodCall.java");
|
// Class resultAst = Compiler.generateASTFromFile("src/main/resources/JavaTestfiles/ClassCanBeTyped.java");
|
||||||
// assertEquals(AbstractSyntax_ClassWithConstructorAndMethodCall.get(), resultAst);
|
// assertEquals(AbstractSyntax_ClassWithConstructorAndMethodCall.get(), resultAst);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
26
src/test/java/TypingTests.java
Normal file
26
src/test/java/TypingTests.java
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import de.maishai.Compiler;
|
||||||
|
import de.maishai.typedast.typedclass.TypedClass;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
public class TypingTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPublicClass() {
|
||||||
|
TypedClass resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_PublicClass.get());
|
||||||
|
assertEquals(TypedAbstractSyntax_PublicClass.get(), resultTypedAst);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClassWithField() {
|
||||||
|
TypedClass resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_ClassWithField.get());
|
||||||
|
assertEquals(TypedAbstractSyntax_ClassWithField.get(), resultTypedAst);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testClassWithConstructor() {
|
||||||
|
TypedClass resultTypedAst = Compiler.generateTypedASTFromAst(AbstractSyntax_ClassWithConstructor.get());
|
||||||
|
assertEquals(TypedAbstractSyntax_ClassWithConstructor.get(), resultTypedAst);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user