mirror of
https://github.com/JonathanFleischmann/CompilerULTIMATE.git
synced 2024-12-28 02:08:04 +00:00
Updated TypedAssignment and add TODO
This commit is contained in:
parent
cef0c5ba86
commit
de51bcd825
@ -16,9 +16,8 @@ import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
|||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class TypedAssignment implements TypedStatement {
|
public class TypedAssignment implements TypedStatement {
|
||||||
private String varName;
|
|
||||||
private TypedExpression value;
|
private TypedExpression value;
|
||||||
private TypedExpression recursiveOwnerChain;
|
private TypedFieldVarAccess location;
|
||||||
private Type type;
|
private Type type;
|
||||||
|
|
||||||
public TypedAssignment(TypedClass clas, Assignment untyped) {
|
public TypedAssignment(TypedClass clas, Assignment untyped) {
|
||||||
@ -26,30 +25,29 @@ public class TypedAssignment implements TypedStatement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void convertToTypedAssignment(TypedClass clas, Assignment untyped) {
|
public void convertToTypedAssignment(TypedClass clas, Assignment untyped) {
|
||||||
varName = untyped.location().id();
|
|
||||||
value = convertExpression(clas, untyped.value());
|
value = convertExpression(clas, untyped.value());
|
||||||
recursiveOwnerChain = convertExpression( clas, untyped.location().recursiveOwnerChain());
|
location = new TypedFieldVarAccess(clas, untyped.location());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type typeCheck(TypedClass clas) {
|
public Type typeCheck(TypedClass clas) {
|
||||||
Type typeLeft = null;
|
Type typeLeft = null;
|
||||||
|
|
||||||
if (clas.isThereField(varName)) {
|
if (clas.isThereField(location.getName())) {
|
||||||
typeLeft = clas.getFieldType(varName);
|
typeLeft = clas.getFieldType(location.getName());
|
||||||
} else {
|
} else {
|
||||||
if (clas.isCurrentMethodPresent() && !clas.isCurrentConstructorPresent()) {
|
if (clas.isCurrentMethodPresent() && !clas.isCurrentConstructorPresent()) {
|
||||||
if (clas.getCurrentMethod().isLocalVariableInMethod(varName)) {
|
if (clas.getCurrentMethod().isLocalVariableInMethod(location.getName())) {
|
||||||
typeLeft = clas.getCurrentMethod().getLocalVariableType(varName);
|
typeLeft = clas.getCurrentMethod().getLocalVariableType(location.getName());
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Variable " + varName + " not declared in method");
|
throw new RuntimeException("Variable " + location.getName() + " not declared in method");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!clas.isCurrentMethodPresent() && clas.isCurrentConstructorPresent()) {
|
if (!clas.isCurrentMethodPresent() && clas.isCurrentConstructorPresent()) {
|
||||||
if (clas.getCurrentConstructor().isLocalVariableInConstructor(varName)) {
|
if (clas.getCurrentConstructor().isLocalVariableInConstructor(location.getName())) {
|
||||||
typeLeft = clas.getCurrentConstructor().getLocalVariableType(varName);
|
typeLeft = clas.getCurrentConstructor().getLocalVariableType(location.getName());
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Variable " + varName + " not declared in constructor");
|
throw new RuntimeException("Variable " + location.getName() + " not declared in constructor");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
import static de.maishai.typedast.Help.TypedExpressionHelp.convertExpression;
|
||||||
|
|
||||||
|
//TODO: test this after fixing error from parser
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class TypedMethodCall implements TypedExpression, TypedStatement {
|
public class TypedMethodCall implements TypedExpression, TypedStatement {
|
||||||
@ -28,11 +30,33 @@ public class TypedMethodCall implements TypedExpression, TypedStatement {
|
|||||||
for (Expression arg : unTypedMethodCall.args()) {
|
for (Expression arg : unTypedMethodCall.args()) {
|
||||||
args.add(convertExpression(clas, arg));
|
args.add(convertExpression(clas, arg));
|
||||||
}
|
}
|
||||||
|
recipient.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type typeCheck(TypedClass clas) {
|
public Type typeCheck(TypedClass clas) {
|
||||||
//TODO: implement this
|
/* if (clas.isCurrentMethodPresent()) {
|
||||||
|
|
||||||
|
List<TypedMethod> methods = clas.getTypedMethods().stream()
|
||||||
|
.filter(method -> method.getName().equals(name))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
for (TypedMethod method : methods) {
|
||||||
|
if (method.getTypedParameters().size() == args.size()) {
|
||||||
|
boolean allMatch = true;
|
||||||
|
for (int i = 0; i < args.size(); i++) {
|
||||||
|
if (!args.get(i).typeCheck(clas).equals(method.getTypedParameters().get(i).getType())) {
|
||||||
|
allMatch = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (allMatch) {
|
||||||
|
return method.getReturnType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} */
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user