mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 01:38:03 +00:00
Merge branch 'main' of https://github.com/JonathanFleischmann/CompilerULTIMATE
This commit is contained in:
commit
871447b9df
@ -1,10 +1,22 @@
|
||||
package de.maishai.typedast;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.*;
|
||||
import org.objectweb.asm.Label;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@Data
|
||||
public class MethodContext {
|
||||
private Label startLabel;
|
||||
private Label endLabel;
|
||||
private int localVarIndex = 0;
|
||||
private Map<String, Integer> variableIndex = new HashMap<>();
|
||||
|
||||
public void addVariable(String name, int index) {
|
||||
variableIndex.put(name, index);
|
||||
}
|
||||
}
|
||||
|
@ -38,5 +38,9 @@ public final class TypedLocalVariable implements TypedNode {
|
||||
}
|
||||
|
||||
public void codeGen(MethodVisitor mv, MethodContext ctx) {
|
||||
int index = ctx.getLocalVarIndex();
|
||||
ctx.setLocalVarIndex(index + 1);
|
||||
ctx.addVariable(name, index);
|
||||
mv.visitLocalVariable(name, type.getDescriptor(), null, ctx.getStartLabel(), ctx.getEndLabel(), index);
|
||||
}
|
||||
}
|
||||
|
@ -22,12 +22,17 @@ public class TypedMethod implements TypedNode {
|
||||
public TypedMethod unTypedMethodToTypedMethod(Method unTypedMethod) {
|
||||
TypedMethod typedMethod = new TypedMethod();
|
||||
typedMethod.setName(unTypedMethod.methodName());
|
||||
typedMethod.setTypedParameters(new ArrayList<>());
|
||||
|
||||
for(Parameter parameter : unTypedMethod.params()){
|
||||
TypedParameter typedParameter = new TypedParameter();
|
||||
typedParameter.setParaName(parameter.name());
|
||||
typedParameter.setType(parameter.type());
|
||||
typedParameters.add(typedParameter);
|
||||
if(unTypedMethod.params().isEmpty()){
|
||||
typedMethod.setTypedParameters(List.of());
|
||||
}else {
|
||||
for (Parameter parameter : unTypedMethod.params()) {
|
||||
TypedParameter typedParameter = new TypedParameter();
|
||||
typedParameter.setParaName(parameter.name());
|
||||
typedParameter.setType(parameter.type());
|
||||
typedParameters.add(typedParameter);
|
||||
}
|
||||
}
|
||||
TypedBlock block = new TypedBlock();
|
||||
typedMethod.setTypedBlock(block.unTypedBlockToTypedBlock(unTypedMethod.block()));
|
||||
|
Loading…
Reference in New Issue
Block a user