mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 16:28:04 +00:00
Updated the method converToTypedAST
This commit is contained in:
parent
81d1cf6ca8
commit
622a0951f3
@ -31,13 +31,6 @@ public class TypedAssignment implements TypedStatement {
|
||||
}
|
||||
throw new RuntimeException("type of left not equals with type of right");
|
||||
}
|
||||
// int y = 5;
|
||||
// int x = (y + 5 + z);
|
||||
//TypedAssignment([
|
||||
// localVar("x", "int"),
|
||||
// localVar("y","int")
|
||||
// ],
|
||||
// "int")
|
||||
|
||||
@Override
|
||||
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
|
||||
|
@ -9,6 +9,7 @@ import de.maishai.typedast.Type;
|
||||
import lombok.Data;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -51,18 +52,18 @@ public class TypedBlock implements TypedNode {
|
||||
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
|
||||
Block untyped = (Block) unTypedAST;
|
||||
TypedBlock typedBlock = new TypedBlock();
|
||||
typedBlock.setStmts(new ArrayList<>());
|
||||
typedBlock.setVars(new ArrayList<>());
|
||||
|
||||
for (Declaration var : untyped.localVariables()) {
|
||||
TypedLocalVariable typedVar = new TypedLocalVariable();
|
||||
typedVar.convertToTypedAST(localVar, classes, var);
|
||||
typedVar.setName(var.name());
|
||||
typedVar.setType(var.type());
|
||||
typedBlock.getVars().add(typedVar);
|
||||
}
|
||||
typedBlock.getStmts().add((TypedStatement) untyped.stmts());
|
||||
|
||||
for (de.maishai.ast.records.Statement stmt : untyped.stmts()) {
|
||||
|
||||
//TODO: Implement the conversion of the statements
|
||||
}
|
||||
return null;
|
||||
return typedBlock;
|
||||
}
|
||||
|
||||
public void codeGen(MethodVisitor mv, MethodContext ctx) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.maishai.typedast.typedclass;
|
||||
|
||||
import de.maishai.ast.records.Break;
|
||||
import de.maishai.typedast.MethodContext;
|
||||
import de.maishai.typedast.TypedNode;
|
||||
import de.maishai.typedast.TypedStatement;
|
||||
@ -17,6 +18,10 @@ public class TypedBreak implements TypedStatement {
|
||||
|
||||
@Override
|
||||
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
|
||||
Break untyped = (Break) unTypedAST;
|
||||
if(untyped == null) {
|
||||
throw new RuntimeException("Break not found");
|
||||
}
|
||||
return new TypedBreak();
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,8 @@ public class TypedDoWhile implements TypedStatement {
|
||||
DoWhile untyped = (DoWhile) unTypedAST;
|
||||
|
||||
TypedDoWhile typedDoWhile = new TypedDoWhile();
|
||||
typedDoWhile.setTypedBlock( (TypedBlock) typedBlock.convertToTypedAST(localVar, classes, untyped.block()));
|
||||
TypedBlock typedBlock = new TypedBlock();
|
||||
typedDoWhile.setTypedBlock(typedBlock.unTypedBlockToTypedBlock(untyped.block()));
|
||||
typedDoWhile.setCond((TypedExpression) cond.convertToTypedAST(localVar, classes, untyped.cond()));
|
||||
|
||||
return typedDoWhile;
|
||||
|
@ -39,8 +39,9 @@ public class TypedField implements TypedNode {
|
||||
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
|
||||
Declaration untypedDeclaration = (Declaration) unTypedAST;
|
||||
TypedField typedField = new TypedField();
|
||||
typedField.setVarName(untypedDeclaration.name());
|
||||
|
||||
typedField.setType(untypedDeclaration.type());
|
||||
typedField.setVarName(untypedDeclaration.name());
|
||||
|
||||
return typedField;
|
||||
}
|
||||
|
@ -34,7 +34,9 @@ public class TypedFor implements TypedStatement {
|
||||
typedFor.setAssign((TypedExpression) assign.convertToTypedAST(localVar, classes, untyped.assign()));
|
||||
typedFor.setCond((TypedExpression) cond.convertToTypedAST(localVar, classes, untyped.cond()));
|
||||
typedFor.setInc((TypedExpression) inc.convertToTypedAST(localVar, classes, untyped.inc()));
|
||||
typedFor.setTypedBlock((TypedBlock) typedBlock.convertToTypedAST(localVar, classes, untyped.block()));
|
||||
|
||||
TypedBlock typedBlock = new TypedBlock();
|
||||
typedFor.setTypedBlock(typedBlock.unTypedBlockToTypedBlock(untyped.block()));
|
||||
|
||||
return typedFor;
|
||||
}
|
||||
|
@ -32,8 +32,11 @@ public class TypedIfElse implements TypedStatement {
|
||||
|
||||
TypedIfElse typedIfElse = new TypedIfElse();
|
||||
typedIfElse.setTypedCon((TypedExpression) typedCon.convertToTypedAST(localVar, classes, ifElse.cond()));
|
||||
typedIfElse.setIfTypedBlock((TypedBlock) ifTypedBlock.convertToTypedAST(localVar, classes, ifElse.ifBlock()));
|
||||
typedIfElse.setElseTypedBlock((TypedBlock) elseTypedBlock.convertToTypedAST(localVar, classes, ifElse.elseBlock()));
|
||||
|
||||
TypedBlock ifTypedBlock = new TypedBlock();
|
||||
TypedBlock elseTypedBlock = new TypedBlock();
|
||||
typedIfElse.setIfTypedBlock(ifTypedBlock.unTypedBlockToTypedBlock(ifElse.ifBlock()));
|
||||
typedIfElse.setElseTypedBlock(elseTypedBlock.unTypedBlockToTypedBlock(ifElse.elseBlock()));
|
||||
|
||||
return typedIfElse;
|
||||
}
|
||||
|
@ -8,12 +8,12 @@ import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class TypedMethod implements TypedNode {
|
||||
private Boolean isPublic;
|
||||
private String name;
|
||||
private Type returnType;
|
||||
private List<TypedParameter> typedParameters;
|
||||
@ -50,20 +50,19 @@ public class TypedMethod implements TypedNode {
|
||||
Method untypedMethod = (Method) unTypedAST;
|
||||
TypedMethod typedMethod = new TypedMethod();
|
||||
|
||||
typedMethod.setTypedParameters(new ArrayList<>());
|
||||
typedMethod.setName(untypedMethod.methodName());
|
||||
typedMethod.setReturnType(untypedMethod.type());
|
||||
|
||||
if(untypedMethod.params().isEmpty()){
|
||||
//TODO: Implement this
|
||||
}
|
||||
|
||||
for(Parameter parameter : untypedMethod.params()) {
|
||||
TypedParameter typedParameter = getTypedParameter(parameter);
|
||||
TypedParameter typedParameter = new TypedParameter();
|
||||
typedParameter.setParaName(parameter.name());
|
||||
typedParameter.setType(parameter.type());
|
||||
typedMethod.getTypedParameters().add(typedParameter);
|
||||
}
|
||||
|
||||
TypedBlock typedBlock = new TypedBlock();
|
||||
typedMethod.setTypedBlock((TypedBlock) typedBlock.convertToTypedAST(localVar, classes, untypedMethod.block()));
|
||||
typedMethod.setTypedBlock(typedBlock.unTypedBlockToTypedBlock(untypedMethod.block()));
|
||||
|
||||
return typedMethod;
|
||||
}
|
||||
|
@ -1,15 +1,18 @@
|
||||
package de.maishai.typedast.typedclass;
|
||||
|
||||
import de.maishai.ast.records.Parameter;
|
||||
import de.maishai.typedast.TypedNode;
|
||||
import de.maishai.typedast.Type;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class TypedParameter implements TypedNode {
|
||||
private String paraName;
|
||||
@ -23,10 +26,13 @@ public class TypedParameter implements TypedNode {
|
||||
localVar.put(paraName, type);
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypedNode convertToTypedAST(Map<String, Type> localVar, Map<String, TypedClass> classes, de.maishai.ast.records.Node unTypedAST) {
|
||||
return null;
|
||||
Parameter untyped = (Parameter) unTypedAST;
|
||||
TypedParameter typedParameter = new TypedParameter();
|
||||
typedParameter.setParaName(untyped.name());
|
||||
typedParameter.setType(untyped.type());
|
||||
return typedParameter;
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,7 +24,8 @@ public class TypedWhile implements TypedStatement {
|
||||
While untyped = (While) unTypedAST;
|
||||
TypedWhile typedWhile = new TypedWhile();
|
||||
typedWhile.setCond((TypedExpression) cond.convertToTypedAST(localVar, classes, untyped.cond()));
|
||||
typedWhile.setTypedBlock((TypedBlock) typedBlock.convertToTypedAST(localVar, classes, untyped.block()));
|
||||
TypedBlock typedBlock = new TypedBlock();
|
||||
typedWhile.setTypedBlock(typedBlock.unTypedBlockToTypedBlock(untyped.block()));
|
||||
return typedWhile;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user