mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-27 09:08:04 +00:00
Merge branch 'main' of https://github.com/JonathanFleischmann/CompilerULTIMATE
This commit is contained in:
commit
a5d13fd2a9
@ -90,7 +90,7 @@ public class Compiler {
|
||||
options.addOption("d", "debug", false, "Enable debug logging");
|
||||
|
||||
CommandLineParser parser = new DefaultParser();
|
||||
CommandLine cmd = null;
|
||||
CommandLine cmd;
|
||||
try {
|
||||
cmd = parser.parse(options, args);
|
||||
} catch (ParseException e) {
|
||||
|
@ -28,8 +28,7 @@ public class MethodContext {
|
||||
private final Deque<Label> continueLabels = new ArrayDeque<>();
|
||||
|
||||
public MethodContext(ClassContext classContext, MethodVisitor mv, Type returnType) {
|
||||
// if DEBUG env variable is set, log all method calls
|
||||
if (System.getenv("DEBUG") != null) {
|
||||
if (Objects.equals(System.getenv("DEBUG"), "true")) {
|
||||
this.mv = new LoggingMethodVisitor(mv);
|
||||
} else {
|
||||
this.mv = mv;
|
||||
@ -85,7 +84,6 @@ public class MethodContext {
|
||||
}
|
||||
|
||||
public void wrapUp() {
|
||||
//if return type is void, add return instruction
|
||||
if (returnType.getKind() == Type.Kind.VOID) {
|
||||
mv.visitInsn(Opcodes.RETURN);
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package de.maishai.typedast.Help;
|
||||
package de.maishai.typedast.Util;
|
||||
|
||||
import de.maishai.ast.records.*;
|
||||
import de.maishai.typedast.TypedExpression;
|
||||
import de.maishai.typedast.typedclass.*;
|
||||
|
||||
public class TypedExpressionHelp {
|
||||
public class TypedExpressionUtil {
|
||||
|
||||
public static TypedExpression convertExpression( TypedProgram typedProgram, Expression expression) {
|
||||
if (expression instanceof BoolLiteral boolLiteral) {
|
@ -13,7 +13,7 @@ import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||
import static de.maishai.typedast.Util.TypedExpressionUtil.convertExpression;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
@ -11,7 +11,7 @@ import lombok.NoArgsConstructor;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||
import static de.maishai.typedast.Util.TypedExpressionUtil.convertExpression;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@ -52,13 +52,20 @@ public class TypedBinary implements TypedExpression {
|
||||
} else {
|
||||
throw new RuntimeException("Type mismatch in " + op);
|
||||
}
|
||||
} else if (op == Operator.EQ || op == Operator.NE || op == Operator.AND || op == Operator.OR) {
|
||||
} else if (op == Operator.EQ || op == Operator.NE ) {
|
||||
if (leftType == Type.INT && rightType == Type.INT || leftType == Type.BOOL && rightType == Type.BOOL) {
|
||||
type = Type.BOOL;
|
||||
return Type.BOOL;
|
||||
} else {
|
||||
throw new RuntimeException("Type mismatch in " + op);
|
||||
}
|
||||
} else if (op == Operator.AND || op == Operator.OR ){
|
||||
if (leftType == Type.BOOL && rightType == Type.BOOL) {
|
||||
type = Type.BOOL;
|
||||
return Type.BOOL;
|
||||
} else {
|
||||
throw new RuntimeException("Type mismatch in " + op);
|
||||
}
|
||||
}
|
||||
|
||||
if (leftType == rightType && leftType != Type.VOID) {
|
||||
|
@ -56,7 +56,7 @@ public class TypedClass implements TypedNode {
|
||||
typedDeclarations.add(new TypedDeclaration(typedProgram, declaration));
|
||||
}
|
||||
for (Constructor constructor : c.constructors()) {
|
||||
typedConstructors.add(new TypedConstructor(typedProgram, constructor));
|
||||
typedConstructors.add(new TypedConstructor(typedProgram, constructor, this.className));
|
||||
}
|
||||
|
||||
for (Method method : c.methods()) {
|
||||
|
@ -32,9 +32,14 @@ public class TypedConstructor implements TypedNode {
|
||||
this.typedParameters = typedParameters;
|
||||
this.typedBlock = typedBlock;
|
||||
}
|
||||
public TypedConstructor(TypedProgram typedProgram, Constructor unTypedConstructor, String className) {
|
||||
convertToTypedConstructor(typedProgram, unTypedConstructor, className);
|
||||
}
|
||||
|
||||
|
||||
public void convertToTypedConstructor(TypedProgram typedProgram, Constructor unTypedConstructor) {
|
||||
public void convertToTypedConstructor(TypedProgram typedProgram, Constructor unTypedConstructor, String className) {
|
||||
if(!unTypedConstructor.className().equals(className)) {
|
||||
throw new RuntimeException("Constructor name "+ unTypedConstructor.className() +" must be the same as class name" + className);
|
||||
}
|
||||
name = unTypedConstructor.className();
|
||||
convertToTypedParameter(typedProgram, unTypedConstructor.params());
|
||||
type = Type.VOID;
|
||||
@ -59,9 +64,7 @@ public class TypedConstructor implements TypedNode {
|
||||
return type;
|
||||
}
|
||||
|
||||
public TypedConstructor(TypedProgram typedProgram, Constructor unTypedConstructor) {
|
||||
convertToTypedConstructor(typedProgram, unTypedConstructor);
|
||||
}
|
||||
|
||||
|
||||
public boolean isLocalVariablePresent(String localVarName) {
|
||||
return localVariables.stream().anyMatch(localVariable -> localVariable.getName().equals(localVarName));
|
||||
|
@ -7,7 +7,7 @@ import lombok.Data;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||
import static de.maishai.typedast.Util.TypedExpressionUtil.convertExpression;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
@ -13,7 +13,7 @@ import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||
import static de.maishai.typedast.Util.TypedExpressionUtil.convertExpression;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
|
@ -8,7 +8,7 @@ import lombok.NoArgsConstructor;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||
import static de.maishai.typedast.Util.TypedExpressionUtil.convertExpression;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
@ -8,7 +8,7 @@ import lombok.NoArgsConstructor;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||
import static de.maishai.typedast.Util.TypedExpressionUtil.convertExpression;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
|
@ -14,7 +14,7 @@ import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||
import static de.maishai.typedast.Util.TypedExpressionUtil.convertExpression;
|
||||
|
||||
|
||||
@Data
|
||||
|
@ -12,7 +12,7 @@ import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||
import static de.maishai.typedast.Util.TypedExpressionUtil.convertExpression;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
@ -7,7 +7,7 @@ import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||
import static de.maishai.typedast.Util.TypedExpressionUtil.convertExpression;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class TypedPrint implements TypedStatement {
|
||||
|
@ -10,7 +10,7 @@ import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||
import static de.maishai.typedast.Util.TypedExpressionUtil.convertExpression;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
|
@ -9,7 +9,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||
import static de.maishai.typedast.Util.TypedExpressionUtil.convertExpression;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
@ -10,7 +10,7 @@ import lombok.Data;
|
||||
import org.objectweb.asm.Label;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||
import static de.maishai.typedast.Util.TypedExpressionUtil.convertExpression;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
|
Loading…
Reference in New Issue
Block a user