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 AccessModifierNode accessType;
|
||||||
public String identifier;
|
public String identifier;
|
||||||
public List<ParameterNode> parameters = new ArrayList<>();
|
public List<ParameterNode> parameters = new ArrayList<>();
|
||||||
public BlockNode block;
|
|
||||||
|
|
||||||
public ConstructorNode(String accessType, String identifier, BlockNode block) {
|
public ConstructorNode(String accessType, String identifier, BlockNode block) {
|
||||||
this.accessType = new AccessModifierNode(accessType);
|
this.accessType = new AccessModifierNode(accessType);
|
||||||
|
@ -114,10 +114,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TypeCheckResult analyze(MethodNode methodNode) {
|
public TypeCheckResult analyze(MethodNode methodNode) {
|
||||||
if (methodNode instanceof ConstructorNode) {
|
|
||||||
return new TypeCheckResult(true, new BaseType(TypeEnum.VOID));
|
|
||||||
} else {
|
|
||||||
|
|
||||||
var valid = true;
|
var valid = true;
|
||||||
|
|
||||||
for (var otherMethod : currentClass.getMethods()) {
|
for (var otherMethod : currentClass.getMethods()) {
|
||||||
@ -159,8 +155,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new TypeCheckResult(valid, resultType);
|
return new TypeCheckResult(valid, resultType);
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -177,8 +171,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
|||||||
currentFields.put(toCheck.identifier, toCheck.type);
|
currentFields.put(toCheck.identifier, toCheck.type);
|
||||||
}
|
}
|
||||||
return new TypeCheckResult(true, null);
|
return new TypeCheckResult(true, null);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -317,9 +309,18 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
|||||||
@Override
|
@Override
|
||||||
public TypeCheckResult analyze(IfElseNode toCheck) {
|
public TypeCheckResult analyze(IfElseNode toCheck) {
|
||||||
var resultIf = toCheck.ifStatement.accept(this);
|
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){
|
if(toCheck.elseStatement != null){
|
||||||
var resultElse = toCheck.elseStatement.accept(this);
|
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);
|
var type = currentFields.get(unary.identifier);
|
||||||
unary.setType(type);
|
unary.setType(type);
|
||||||
return new TypeCheckResult(valid,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) {
|
} else if (unary.statement != null) {
|
||||||
var result = unary.statement.accept(this);
|
var result = unary.statement.accept(this);
|
||||||
unary.setType(result.getType());
|
unary.setType(result.getType());
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
class Null{
|
class Null{
|
||||||
|
|
||||||
Null a;
|
int a;
|
||||||
|
|
||||||
public Null(){
|
public Null(){
|
||||||
this.a = null;
|
this.a = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,16 +1,8 @@
|
|||||||
public class Compiler {
|
public class If {
|
||||||
Node node;
|
public If() {
|
||||||
public int add(int i, int j) {
|
int intValue = 5;
|
||||||
node = new Node();
|
if(intValue == 5) {
|
||||||
node.x = 1;
|
intValue--;
|
||||||
return i+j;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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