Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This commit is contained in:
commit
bd61a0e595
@ -14,7 +14,6 @@ public class ConstructorNode extends MethodNode implements Visitable {
|
||||
public AccessModifierNode accessType;
|
||||
public String identifier;
|
||||
public List<ParameterNode> parameters = new ArrayList<>();
|
||||
public BlockNode block;
|
||||
|
||||
public ConstructorNode(String accessType, String identifier, BlockNode block) {
|
||||
this.accessType = new AccessModifierNode(accessType);
|
||||
|
@ -114,10 +114,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
|
||||
@Override
|
||||
public TypeCheckResult analyze(MethodNode methodNode) {
|
||||
if (methodNode instanceof ConstructorNode) {
|
||||
return new TypeCheckResult(true, new BaseType(TypeEnum.VOID));
|
||||
} else {
|
||||
|
||||
var valid = true;
|
||||
|
||||
for (var otherMethod : currentClass.getMethods()) {
|
||||
@ -159,8 +155,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
}
|
||||
|
||||
return new TypeCheckResult(valid, resultType);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -177,8 +171,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
currentFields.put(toCheck.identifier, toCheck.type);
|
||||
}
|
||||
return new TypeCheckResult(true, null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -317,9 +309,18 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
@Override
|
||||
public TypeCheckResult analyze(IfElseNode toCheck) {
|
||||
var resultIf = toCheck.ifStatement.accept(this);
|
||||
var validElseIf = true;
|
||||
|
||||
if(toCheck.elseIfStatements.size() != 0) {
|
||||
for(IfNode ifNode : toCheck.elseIfStatements) {
|
||||
var resultIfFor = ifNode.accept(this);
|
||||
validElseIf = validElseIf && resultIfFor.isValid();
|
||||
}
|
||||
}
|
||||
|
||||
if(toCheck.elseStatement != null){
|
||||
var resultElse = toCheck.elseStatement.accept(this);
|
||||
return new TypeCheckResult(resultIf.isValid() && resultElse.isValid(), new BaseType(TypeEnum.VOID));
|
||||
return new TypeCheckResult(resultIf.isValid() && resultElse.isValid() && validElseIf, new BaseType(TypeEnum.VOID));
|
||||
}
|
||||
|
||||
|
||||
@ -575,6 +576,10 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
||||
var type = currentFields.get(unary.identifier);
|
||||
unary.setType(type);
|
||||
return new TypeCheckResult(valid,type );
|
||||
} else if (unary.value != null) {
|
||||
var result = unary.value.accept(this);
|
||||
unary.setType(result.getType());
|
||||
return new TypeCheckResult(result.isValid(), result.getType());
|
||||
} else if (unary.statement != null) {
|
||||
var result = unary.statement.accept(this);
|
||||
unary.setType(result.getType());
|
||||
|
@ -1,8 +1,8 @@
|
||||
class Null{
|
||||
|
||||
Null a;
|
||||
int a;
|
||||
|
||||
public Null(){
|
||||
this.a = null;
|
||||
this.a = 1;
|
||||
}
|
||||
}
|
@ -1,16 +1,8 @@
|
||||
public class Compiler {
|
||||
Node node;
|
||||
public int add(int i, int j) {
|
||||
node = new Node();
|
||||
node.x = 1;
|
||||
return i+j;
|
||||
public class If {
|
||||
public If() {
|
||||
int intValue = 5;
|
||||
if(intValue == 5) {
|
||||
intValue--;
|
||||
}
|
||||
}
|
||||
|
||||
public class Node {
|
||||
public int x;
|
||||
public void main() {
|
||||
Compiler compiler = new Compiler();
|
||||
int i = compiler.add(5, 8);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user