Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
# Conflicts: # src/test/java/semantic/EndToTypedAstTest.java # src/test/resources/input/typedAstFeatureTests/CorrectTest.java
This commit is contained in:
commit
8ba58d492b
@ -2,6 +2,7 @@ package ast.statementexpressions.methodcallstatementnexpressions;
|
||||
|
||||
import ast.expressions.IExpressionNode;
|
||||
import ast.statements.IStatementNode;
|
||||
import ast.type.type.ITypeNode;
|
||||
import bytecode.visitor.MethodVisitor;
|
||||
import semantic.SemanticVisitor;
|
||||
import typechecker.TypeCheckResult;
|
||||
@ -11,6 +12,7 @@ import java.util.List;
|
||||
|
||||
public class MethodCallNode implements IStatementNode {
|
||||
public TargetNode target;
|
||||
public ITypeNode type;
|
||||
public List<ChainedMethodNode> chainedMethods = new ArrayList<>();
|
||||
public String identifier;
|
||||
public List<IExpressionNode> parameters = new ArrayList<>();
|
||||
|
@ -166,7 +166,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
@Override
|
||||
public TypeCheckResult analyze(FieldNode toCheck) {
|
||||
if (toCheck.type instanceof ReferenceType referenceType) {
|
||||
if(!context.containsClass(referenceType.getIdentifier())){
|
||||
if (!context.containsClass(referenceType.getIdentifier())) {
|
||||
errors.add(new NotDeclaredException(referenceType.getIdentifier() + " not declared"));
|
||||
}
|
||||
}
|
||||
@ -233,7 +233,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
}
|
||||
for (IStatementNode statementNode : blockNode.statements) {
|
||||
var result = statementNode.accept(this);
|
||||
if(!(statementNode instanceof IncrementNode) && !(statementNode instanceof DecrementNode)){
|
||||
if (!(statementNode instanceof IncrementNode) && !(statementNode instanceof DecrementNode)) {
|
||||
if (result.getType() != null) {
|
||||
if (blockReturnType == null) {
|
||||
blockReturnType = result.getType();
|
||||
@ -258,6 +258,10 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
} else {
|
||||
if (currentFields.get(toCheck.identifier) != null) {
|
||||
var type = currentFields.get(toCheck.identifier);
|
||||
MemberAccessNode memberAccessNode = new MemberAccessNode(false);
|
||||
memberAccessNode.identifiers.add(currentClass.identifier);
|
||||
memberAccessNode.identifiers.add(toCheck.identifier);
|
||||
toCheck.memberAccess = memberAccessNode;
|
||||
toCheck.setTypeNode(type);
|
||||
return new TypeCheckResult(true, type);
|
||||
} else if (currentScope.getLocalVar(toCheck.identifier) != null) {
|
||||
@ -320,44 +324,66 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
@Override
|
||||
public TypeCheckResult analyze(MethodCallNode toCheck) {
|
||||
|
||||
if (toCheck.target.identifier != null) {
|
||||
var targetType = currentScope.getLocalVar(toCheck.target.identifier);
|
||||
if (targetType == null) {
|
||||
targetType = currentFields.get(toCheck.target.identifier);
|
||||
}
|
||||
if (targetType instanceof ReferenceType reference) {
|
||||
if (!toCheck.chainedMethods.isEmpty()) {
|
||||
for (ChainedMethodNode chainedMethod : toCheck.chainedMethods) {
|
||||
var type = getTypeFromMethod(chainedMethod, reference);
|
||||
if (type instanceof ReferenceType referenceType)
|
||||
reference = referenceType;
|
||||
else
|
||||
errors.add(new TypeMismatchException("Ein Basetyp hat keine funktionen"));
|
||||
if (toCheck.target != null) {
|
||||
if (toCheck.target.identifier != null) {
|
||||
var targetType = currentScope.getLocalVar(toCheck.target.identifier);
|
||||
if (targetType == null) {
|
||||
targetType = currentFields.get(toCheck.target.identifier);
|
||||
}
|
||||
if (targetType instanceof ReferenceType reference) {
|
||||
if (!toCheck.chainedMethods.isEmpty()) {
|
||||
for (ChainedMethodNode chainedMethod : toCheck.chainedMethods) {
|
||||
var type = getTypeFromMethod(chainedMethod, reference);
|
||||
if (type instanceof ReferenceType referenceType)
|
||||
reference = referenceType;
|
||||
else
|
||||
errors.add(new TypeMismatchException("Ein Basetyp hat keine funktionen"));
|
||||
}
|
||||
}
|
||||
var type = getTypeFromMethod(toCheck, reference);
|
||||
if (type != null) {
|
||||
return new TypeCheckResult(true, type);
|
||||
} else {
|
||||
return new TypeCheckResult(false, null);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if (toCheck.target.thisTar != null) {
|
||||
if (toCheck.target.thisTar) {
|
||||
var type = getTypeFromMethod(toCheck, new ReferenceType(currentClass.identifier));
|
||||
if (type != null) {
|
||||
return new TypeCheckResult(true, type);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var result = toCheck.target.accept(this);
|
||||
if (result.getType() instanceof ReferenceType reference) {
|
||||
return new TypeCheckResult(true, getTypeFromMethod(toCheck, reference));
|
||||
}
|
||||
}
|
||||
var type = getTypeFromMethod(toCheck, reference);
|
||||
if (type != null) {
|
||||
return new TypeCheckResult(true, type);
|
||||
} else {
|
||||
return new TypeCheckResult(false, null);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
if (toCheck.target.thisTar != null) {
|
||||
if (toCheck.target.thisTar) {
|
||||
var type = getTypeFromMethod(toCheck, new ReferenceType(currentClass.identifier));
|
||||
if (type != null) {
|
||||
return new TypeCheckResult(true, type);
|
||||
|
||||
ReferenceType reference = new ReferenceType(currentClass.identifier);
|
||||
if (!toCheck.chainedMethods.isEmpty()) {
|
||||
for (ChainedMethodNode chainedMethod : toCheck.chainedMethods) {
|
||||
var type = getTypeFromMethod(chainedMethod, reference);
|
||||
if (type instanceof ReferenceType referenceType)
|
||||
reference = referenceType;
|
||||
else
|
||||
errors.add(new TypeMismatchException("Ein Basetyp hat keine funktionen"));
|
||||
}
|
||||
}
|
||||
var type = getTypeFromMethod(toCheck, reference);
|
||||
if (type != null) {
|
||||
return new TypeCheckResult(true, type);
|
||||
} else {
|
||||
var result = toCheck.target.accept(this);
|
||||
if (result.getType() instanceof ReferenceType reference) {
|
||||
return new TypeCheckResult(true, getTypeFromMethod(toCheck, reference));
|
||||
}
|
||||
return new TypeCheckResult(false, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return new TypeCheckResult(false, null);
|
||||
}
|
||||
|
||||
@ -508,6 +534,10 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
if (currentScope.contains(unary.identifier)) {
|
||||
return new TypeCheckResult(valid, currentScope.getLocalVar(unary.identifier));
|
||||
} else if (currentFields.get(unary.identifier) != null) {
|
||||
MemberAccessNode memberAccessNode = new MemberAccessNode(false);
|
||||
memberAccessNode.identifiers.add(currentClass.identifier);
|
||||
memberAccessNode.identifiers.add(unary.identifier);
|
||||
unary.memberAccess = memberAccessNode;
|
||||
return new TypeCheckResult(valid, currentFields.get(unary.identifier));
|
||||
} else if (unary.statement != null) {
|
||||
var result = unary.statement.accept(this);
|
||||
@ -537,8 +567,16 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
public TypeCheckResult analyze(MemberAccessNode memberAccessNode) {
|
||||
|
||||
ITypeNode currentType = null;
|
||||
int start = 0;
|
||||
if(!memberAccessNode.identifiers.isEmpty()){
|
||||
if(currentFields.get(memberAccessNode.identifiers.get(0)) != null){
|
||||
memberAccessNode.identifiers.add(0, currentClass.identifier);
|
||||
start = 1;
|
||||
}
|
||||
}
|
||||
for (int i = start; i < memberAccessNode.identifiers.size(); i++) {
|
||||
|
||||
for (String s : memberAccessNode.identifiers) {
|
||||
String s = memberAccessNode.identifiers.get(i);
|
||||
if (currentType == null) {
|
||||
if (currentScope.getLocalVar(s) != null) {
|
||||
currentType = currentScope.getLocalVar(s);
|
||||
|
@ -30,6 +30,7 @@ import semantic.exceptions.AlreadyDeclaredException;
|
||||
import semantic.exceptions.MultipleReturnTypes;
|
||||
import semantic.exceptions.NotDeclaredException;
|
||||
import semantic.exceptions.TypeMismatchException;
|
||||
import semantic.exceptions.NotDeclaredException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,19 +0,0 @@
|
||||
// @expected: WrongOverloading
|
||||
public class Test{
|
||||
|
||||
public void test(int x){
|
||||
|
||||
if(this.get()){
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public boolean b;
|
||||
|
||||
public boolean get(int c){
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
@ -6,7 +6,7 @@ public class Test{
|
||||
|
||||
public int test(){
|
||||
|
||||
return this.test(i);
|
||||
return test(i);
|
||||
|
||||
}
|
||||
|
||||
@ -19,4 +19,4 @@ public class Test{
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user