fixed constructor node parameter decleration
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:
parent
71ffb8bb83
commit
561eafbf4c
@ -9,13 +9,10 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ConstructorNode extends MethodNode {
|
public class ConstructorNode extends MethodNode {
|
||||||
public AccessModifierNode accessType;
|
|
||||||
public String identifier;
|
public String identifier;
|
||||||
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.accesModifier = new AccessModifierNode(accessType);
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
this.block = block;
|
this.block = block;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ public class Scope {
|
|||||||
|
|
||||||
public void addLocalVar(String name, ITypeNode type) {
|
public void addLocalVar(String name, ITypeNode type) {
|
||||||
if (this.contains(name)) {
|
if (this.contains(name)) {
|
||||||
throw new AlreadyDeclaredException("Variable " + name + " already exists in this scope");
|
SemanticAnalyzer.errors.add(new AlreadyDeclaredException("Duplicate local variable " + name));
|
||||||
}
|
}
|
||||||
localVars.peek().put(name, type);
|
localVars.peek().put(name, type);
|
||||||
}
|
}
|
||||||
|
@ -112,9 +112,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;
|
||||||
|
|
||||||
@ -159,7 +156,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
|||||||
return new TypeCheckResult(valid, resultType);
|
return new TypeCheckResult(valid, resultType);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TypeCheckResult analyze(FieldNode toCheck) {
|
public TypeCheckResult analyze(FieldNode toCheck) {
|
||||||
@ -224,7 +220,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
|
|||||||
}
|
}
|
||||||
for (IStatementNode statementNode : blockNode.statements) {
|
for (IStatementNode statementNode : blockNode.statements) {
|
||||||
var result = statementNode.accept(this);
|
var result = statementNode.accept(this);
|
||||||
if(!(statementNode instanceof IncrementNode) && !(statementNode instanceof DecrementNode)){
|
if (!(statementNode instanceof IncrementNode) && !(statementNode instanceof DecrementNode)) {
|
||||||
if (result.getType() != null) {
|
if (result.getType() != null) {
|
||||||
if (blockReturnType == null) {
|
if (blockReturnType == null) {
|
||||||
blockReturnType = result.getType();
|
blockReturnType = result.getType();
|
||||||
|
@ -1,38 +1,11 @@
|
|||||||
public class AllFeaturesClassExample {
|
public class AllFeaturesClassExample {
|
||||||
int a;
|
|
||||||
boolean b;
|
|
||||||
char c;
|
|
||||||
|
|
||||||
public void controlStructures(int adf, boolean bool) {
|
|
||||||
if (a > (10 + 8)) {
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
while (a > adf) {
|
|
||||||
a--;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++) {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public void controlStructures(int a, boolean b) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// void logicalOperations() {
|
public AllFeaturesClassExample(boolean b){
|
||||||
// Logische UND-Operation
|
|
||||||
// if (b && a > 5) {
|
|
||||||
// System.out.println("a ist größer als 5 und b ist wahr");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Logische ODER-Operation
|
}
|
||||||
// if (b || a < 5) {
|
|
||||||
// System.out.println("b ist wahr oder a ist kleiner als 5");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public static void main(String[] args) {
|
|
||||||
// AllFeaturesClassExample obj = new AllFeaturesClassExample(12, true, 'a');
|
|
||||||
// obj.controlStructures();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user