Changed the Name of classes

This commit is contained in:
ahmad 2024-05-04 17:19:04 +02:00
parent f129277236
commit cabadd7594
29 changed files with 184 additions and 181 deletions

View File

@ -1,10 +1,10 @@
package de.maishai.typedast;
import de.maishai.typedast.typedclass.Class;
import de.maishai.typedast.typedclass.TypedClass;
import java.util.Map;
public interface Node {
Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes);
Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST);
Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes);
Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST);
}

View File

@ -1,35 +0,0 @@
package de.maishai.typedast.typedclass;
import de.maishai.typedast.Node;
import de.maishai.typedast.Type;
import lombok.Data;
import java.util.List;
import java.util.Map;
@Data
public class Method implements Node {
private Id id;
private Type returnType;
private List<Parameter> parameters;
private Block block;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
if(localVar.containsKey(id.getName())) {
throw new RuntimeException("Method " + id.getName() + " already exists");
}
localVar.put(id.getName(), returnType);
for(Parameter parameter: parameters) {
parameter.typeCheck(localVar, classes);
}
return block.typeCheck(localVar, classes);
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -9,13 +9,13 @@ import lombok.Data;
import java.util.Map;
@Data
public class Assignment implements Statement {
private Id loc;
public class TypedAssignment implements Statement {
private TypedId loc;
private AssignSign assignSign;
private Expression value;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
if(!localVar.containsKey(loc.getName())) {
throw new RuntimeException("Variable not declared");
}
@ -28,7 +28,7 @@ public class Assignment implements Statement {
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -8,12 +8,12 @@ import lombok.Data;
import java.util.Map;
@Data
public class Binary implements Expression {
public class TypedBinary implements Expression {
private Expression left;
private Operator op;
private Expression right;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
if(left.typeCheck(localVar, classes) == Type.INT &&
right.typeCheck(localVar, classes) == Type.INT) {
@ -31,7 +31,7 @@ public class Binary implements Expression {
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -8,13 +8,13 @@ import lombok.Data;
import java.util.List;
import java.util.Map;
@Data
public class Block implements Node {
private List<LocalVariable> vars;
public class TypedBlock implements Node {
private List<TypedLocalVariable> vars;
private List<Statement> stmts;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
Type typeOfLastStmt = Type.VOID;
for(LocalVariable var : vars){
for(TypedLocalVariable var : vars){
var.typeCheck(localVar, classes);
}
for(Statement stmt : stmts){
@ -26,7 +26,7 @@ public class Block implements Node {
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -7,18 +7,21 @@ import lombok.Data;
import java.util.Map;
@Data
public class BoolLiteral implements Expression {
public class TypedBoolLiteral implements Expression {
private Boolean value;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
return Type.BOOL;
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
de.maishai.ast.records.BoolLiteral untyped = (de.maishai.ast.records.BoolLiteral) unTypedAST;
TypedBoolLiteral typedBoolLiteral = new TypedBoolLiteral();
typedBoolLiteral.setValue(untyped.value());
return typedBoolLiteral;
}
// implemented the methods of typeCheck for each class in
}

View File

@ -7,15 +7,14 @@ import lombok.Data;
import java.util.Map;
@Data
public class ReturnVoid implements Statement {
public class TypedBreak implements Statement {
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
return Type.VOID;
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -7,15 +7,15 @@ import lombok.Data;
import java.util.Map;
@Data
public class CharLiteral implements Expression {
public class TypedCharLiteral implements Expression {
private char value;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
return Type.CHAR;
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -12,38 +12,38 @@ import java.util.List;
import java.util.Map;
@Data
public class Class implements Node {
private Id id;
private List<Field> fields;
private List<Method> methods;
public class TypedClass implements Node {
private TypedId typedId;
private List<TypedField> typedFields;
private List<TypedMethod> typedMethods;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
if(classes.containsKey(id.getName())) {
throw new RuntimeException("Class " + id.getName() + " already exists");
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
if(classes.containsKey(typedId.getName())) {
throw new RuntimeException("Class " + typedId.getName() + " already exists");
}
classes.put(id.getName(), this);
for(Field field: fields) {
classes.put(typedId.getName(), this);
for(TypedField field: typedFields) {
field.typeCheck(localVar, classes);
}
for(Method method: methods) {
method.typeCheck(localVar, classes);
for(TypedMethod typedMethod : typedMethods) {
typedMethod.typeCheck(localVar, classes);
}
return Type.REFERENCE(id.getName());
return Type.REFERENCE(typedId.getName());
}
public Node startConversion(de.maishai.ast.records.Class c) {
Map<String, Type> local = new HashMap<>();
Map<String, Class> classMap = new HashMap<>();
Map<String, TypedClass> classMap = new HashMap<>();
return convertToTypedAST(local, classMap, c);
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
Class typedClass = new Class();
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
TypedClass typedClass = new TypedClass();
for (Field field: fields) {
for (TypedField field: typedFields) {
}
return typedClass;
@ -51,14 +51,14 @@ public class Class implements Node {
public void codeGen() {
ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, id.getName(), null, "java/lang/Object", null);
for(Field field : fields) {
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, typedId.getName(), null, "java/lang/Object", null);
for(TypedField field : typedFields) {
//field.codeGen(cw);
}
for(Method m: methods) {
for(TypedMethod m: typedMethods) {
//m.codeGen(cw);
}
writeClassfile(cw, id.getName());
writeClassfile(cw, typedId.getName());
}
public static void writeClassfile(ClassWriter cw, String name) {
@ -74,10 +74,10 @@ public class Class implements Node {
public static void main(String[] args) {
Class c = new Class();
c.fields = new ArrayList<>();
c.methods = new ArrayList<>();
c.id.setName("Test");
TypedClass c = new TypedClass();
c.typedFields = new ArrayList<>();
c.typedMethods = new ArrayList<>();
c.typedId.setName("Test");
c.codeGen();
}
}

View File

@ -7,29 +7,29 @@ import lombok.Data;
import java.util.List;
import java.util.Map;
@Data
public class Constructor implements Node {
public class TypedConstructor implements Node {
private Id id;
private List<Parameter> params;
private Block block;
private TypedId typedId;
private List<TypedParameter> typedParameters;
private TypedBlock typedBlock;
//constructor: PUBLIC? id '(' params? ')' block;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
if(localVar.containsKey(id.getName())) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
if(localVar.containsKey(typedId.getName())) {
throw new RuntimeException("constructor already declared");
}
localVar.put(id.getName(), Type.VOID);
if(params != null){
for(Parameter param : params){
localVar.put(typedId.getName(), Type.VOID);
if(typedParameters != null){
for(TypedParameter param : typedParameters){
param.typeCheck(localVar, classes);
}
}
block.typeCheck(localVar, classes);
typedBlock.typeCheck(localVar, classes);
return Type.VOID;
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -7,15 +7,15 @@ import lombok.Data;
import java.util.Map;
@Data
public class Continue implements Statement {
public class TypedContinue implements Statement {
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
return Type.VOID;
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -8,20 +8,20 @@ import lombok.Data;
import java.util.Map;
@Data
public class DoWhile implements Statement {
private Block block;
public class TypedDoWhile implements Statement {
private TypedBlock typedBlock;
private Expression cond;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
if(cond.typeCheck(localVar, classes) != Type.BOOL){
throw new RuntimeException("Condition must be boolean");
}
block.typeCheck(localVar, classes);
typedBlock.typeCheck(localVar, classes);
return Type.VOID;
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -7,21 +7,21 @@ import lombok.Data;
import java.util.Map;
@Data
public class Field implements Node {
private Id id;
public class TypedField implements Node {
private TypedId typedId;
private Type type;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
if(localVar.containsKey(id.getName())){
throw new RuntimeException("Variable " + id.getName() + " already declared");
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
if(localVar.containsKey(typedId.getName())){
throw new RuntimeException("Variable " + typedId.getName() + " already declared");
}
localVar.put(id.getName(), type);
localVar.put(typedId.getName(), type);
return type;
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}

View File

@ -7,12 +7,12 @@ import lombok.Data;
import java.util.Map;
@Data
public class FieldId implements Node {
public class TypedFieldId implements Node {
private Boolean field;
private Expression recipient;
private Id id;
private TypedId typedId;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
//TODO: Implement typeCheck for FieldId
if(field){
return null;
@ -22,7 +22,7 @@ public class FieldId implements Node {
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -9,23 +9,23 @@ import lombok.Data;
import java.util.Map;
@Data
public class For implements Statement {
public class TypedFor implements Statement {
private Expression assign;
private Expression cond;
private Expression inc;
private Block block;
private TypedBlock typedBlock;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
assign.typeCheck(localVar, classes);
if(!cond.typeCheck(localVar, classes).equals(Type.BOOL)) {
throw new RuntimeException("Condition must be a boolean");
}
inc.typeCheck(localVar, classes);
return block.typeCheck(localVar, classes);
return typedBlock.typeCheck(localVar, classes);
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -8,11 +8,11 @@ import lombok.Data;
import java.util.Map;
@Data
public class Id implements Expression {
public class TypedId implements Expression {
private String name;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
if(!localVar.containsKey(name)){
throw new RuntimeException("Variable " + name + " not declared or not found");
}
@ -21,7 +21,7 @@ public class Id implements Expression {
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -9,26 +9,26 @@ import lombok.Data;
import java.util.Map;
@Data
public class IfElse implements Statement {
public class TypedIfElse implements Statement {
private Expression cond;
private Block ifBlock;
private Block elseBlock;
private TypedBlock ifTypedBlock;
private TypedBlock elseTypedBlock;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
// if(cond, Statement1, Statement2)
// condition must be a boolean
if(cond.typeCheck(localVar, classes) != Type.BOOL){
throw new RuntimeException("If condition must be a boolean");
}
//Statement1 and Statement2 must be of type void
if(ifBlock.typeCheck(localVar, classes) != Type.VOID){
if(ifTypedBlock.typeCheck(localVar, classes) != Type.VOID){
throw new RuntimeException("If block must be of type void");
}
return Type.VOID;
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -8,15 +8,15 @@ import lombok.Data;
import java.util.Map;
@Data
public class IntLiteral implements Expression {
public class TypedIntLiteral implements Expression {
private Integer value;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
return Type.INT;
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -6,21 +6,21 @@ import lombok.Data;
import java.util.Map;
@Data
public class LocalVariable implements Node {
private Id name;
public class TypedLocalVariable implements Node {
private TypedId typedId;
private Type type;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
if(localVar.containsKey(name.getName())) {
throw new RuntimeException("Variable " + name.getName() + " already exists");
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
if(localVar.containsKey(typedId.getName())) {
throw new RuntimeException("Variable " + typedId.getName() + " already exists");
}
localVar.put(name.getName(), type);
localVar.put(typedId.getName(), type);
return type;
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -7,15 +7,15 @@ import lombok.Data;
import java.util.Map;
@Data
public class MainMethod implements Node {
private Block block;
public class TypedMainMethod implements Node {
private TypedBlock typedBlock;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
return block.typeCheck(localVar, classes);
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
return typedBlock.typeCheck(localVar, classes);
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -0,0 +1,35 @@
package de.maishai.typedast.typedclass;
import de.maishai.typedast.Node;
import de.maishai.typedast.Type;
import lombok.Data;
import java.util.List;
import java.util.Map;
@Data
public class TypedMethod implements Node {
private TypedId typedId;
private Type returnType;
private List<TypedParameter> typedParameters;
private TypedBlock typedBlock;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
if(localVar.containsKey(typedId.getName())) {
throw new RuntimeException("Method " + typedId.getName() + " already exists");
}
localVar.put(typedId.getName(), returnType);
for(TypedParameter typedParameter : typedParameters) {
typedParameter.typeCheck(localVar, classes);
}
return typedBlock.typeCheck(localVar, classes);
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -10,20 +10,20 @@ import java.util.List;
import java.util.Map;
@Data
public class MethodCall implements Expression, Statement {
public class TypedMethodCall implements Expression, Statement {
private Boolean field;
private Expression recipient;
private Id id;
private TypedId typedId;
private List<Expression> args;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
//TODO: Implement typeCheck for MethodCall
return null;
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -10,24 +10,24 @@ import java.util.List;
import java.util.Map;
@Data
public class New implements Expression, Statement {
public class TypedNew implements Expression, Statement {
private Type type;
private List<Expression> args;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
// new A(1, 2, 3)
if (!classes.containsKey(this.type.getReference())) {
throw new RuntimeException("Class " + this.type.getReference() + " not found");
}
Class klasse = classes.get(this.type.getReference());
if (klasse.getFields().size() != args.size()) {
TypedClass klasse = classes.get(this.type.getReference());
if (klasse.getTypedFields().size() != args.size()) {
throw new RuntimeException("number of arguments is invalid for class" + this.type.getReference());
}
// compare the types of the arguments
for (int i = 0; i < args.size(); i++) {
Type type = args.get(i).typeCheck(localVar, classes);
if (!type.equals(klasse.getFields().get(i).getType())) {
if (!type.equals(klasse.getTypedFields().get(i).getType())) {
throw new RuntimeException("False type for argument " + i + " in class " + type.getKind());
}
}
@ -35,7 +35,7 @@ public class New implements Expression, Statement {
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -7,21 +7,21 @@ import lombok.Data;
import java.util.Map;
@Data
public class Parameter implements Node {
private Id id;
public class TypedParameter implements Node {
private TypedId typedId;
private Type type;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
if(localVar.containsKey(id.getName())) {
throw new RuntimeException("Parameter " + id.getName() + " already exists");
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
if(localVar.containsKey(typedId.getName())) {
throw new RuntimeException("Parameter " + typedId.getName() + " already exists");
}
localVar.put(id.getName(), type);
localVar.put(typedId.getName(), type);
return type;
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}

View File

@ -8,18 +8,18 @@ import java.util.List;
import java.util.Map;
@Data
public class Program implements Node {
private List<Class> classes;
public class TypedProgram implements Node {
private List<TypedClass> typedClasses;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
for(Class c : this.classes){
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
for(TypedClass c : this.typedClasses){
c.typeCheck(localVar, classes);
}
return Type.VOID;
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -9,16 +9,16 @@ import lombok.Data;
import java.util.Map;
@Data
public class Return implements Statement {
public class TypedReturn implements Statement {
private Expression ret;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
return ret.typeCheck(localVar, classes);
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -7,14 +7,15 @@ import lombok.Data;
import java.util.Map;
@Data
public class Break implements Statement {
public class TypedReturnVoid implements Statement {
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
return Type.VOID;
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -8,11 +8,11 @@ import lombok.Data;
import java.util.Map;
@Data
public class Unary implements Expression {
public class TypedUnary implements Expression {
private UnaryOperator op;
private Expression right;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
if(op == UnaryOperator.NOT){
if(right.typeCheck(localVar, classes) != Type.BOOL){
@ -31,7 +31,7 @@ public class Unary implements Expression {
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}

View File

@ -9,19 +9,19 @@ import lombok.Data;
import java.util.Map;
@Data
public class While implements Statement {
public class TypedWhile implements Statement {
private Expression cond;
private Block block;
private TypedBlock typedBlock;
@Override
public Type typeCheck(Map<String, Type> localVar, Map<String, Class> classes) {
public Type typeCheck(Map<String, Type> localVar, Map<String, TypedClass> classes) {
if(cond.typeCheck(localVar, classes) != Type.BOOL){
throw new RuntimeException("While condition must be a boolean");
}
return block.typeCheck(localVar, classes);
return typedBlock.typeCheck(localVar, classes);
}
@Override
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, Class> classes, de.maishai.ast.records.Node unTypedAST) {
public Node convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
return null;
}
}