Compare commits

..

2 Commits

Author SHA1 Message Date
4bee432294 Merge remote-tracking branch 'origin/Endabgabe' into Endabgabe
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
2024-07-04 22:24:59 +02:00
0cf4715782 Fixes of Constructor 2024-07-04 22:24:50 +02:00
4 changed files with 11 additions and 13 deletions

View File

@ -11,12 +11,8 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
public class ConstructorNode extends MethodNode implements Visitable { public class ConstructorNode extends MethodNode implements Visitable {
public AccessModifierNode accessType;
public String identifier;
public List<ParameterNode> parameters = new ArrayList<>();
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;
} }

View File

@ -53,7 +53,7 @@ public class MethodCodeGen implements bytecode.visitor.MethodVisitor {
@Override @Override
public void visit(ConstructorNode constructorNode) { public void visit(ConstructorNode constructorNode) {
methodVisitor = methodVisitor =
classWriter.visitMethod(mapper.mapAccessTypeToOpcode(constructorNode.accessType), classWriter.visitMethod(mapper.mapAccessTypeToOpcode(constructorNode.accesModifier),
"<init>", "<init>",
mapper.generateMethodDescriptor(new BaseType(TypeEnum.VOID), constructorNode.parameters), mapper.generateMethodDescriptor(new BaseType(TypeEnum.VOID), constructorNode.parameters),
null, null,

View File

@ -1,6 +1,5 @@
package semantic; package semantic;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -25,15 +24,11 @@ import ast.statementexpressions.methodcallstatementnexpressions.ChainedMethodNod
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode; import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
import ast.statementexpressions.methodcallstatementnexpressions.TargetNode; import ast.statementexpressions.methodcallstatementnexpressions.TargetNode;
import ast.statements.*; import ast.statements.*;
import ast.type.AccessModifierNode;
import ast.type.EnumAccessModifierNode; import ast.type.EnumAccessModifierNode;
import ast.type.ValueNode; import ast.type.ValueNode;
import ast.type.type.*; import ast.type.type.*;
import com.sun.jdi.IntegerType;
import semantic.context.ClassContext;
import semantic.context.Context; import semantic.context.Context;
import semantic.exceptions.*; import semantic.exceptions.*;
import semantic.TypeCheckResult;
public class SemanticAnalyzer implements SemanticVisitor { public class SemanticAnalyzer implements SemanticVisitor {
@ -311,7 +306,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
var resultIf = toCheck.ifStatement.accept(this); var resultIf = toCheck.ifStatement.accept(this);
var validElseIf = true; var validElseIf = true;
if(toCheck.elseIfStatements.size() != 0) { if(!toCheck.elseIfStatements.isEmpty()) {
for(IfNode ifNode : toCheck.elseIfStatements) { for(IfNode ifNode : toCheck.elseIfStatements) {
var resultIfFor = ifNode.accept(this); var resultIfFor = ifNode.accept(this);
validElseIf = validElseIf && resultIfFor.isValid(); validElseIf = validElseIf && resultIfFor.isValid();
@ -365,6 +360,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
if (toCheck.target.thisTar) { if (toCheck.target.thisTar) {
var type = getTypeFromMethod(toCheck, new ReferenceType(currentClass.identifier)); var type = getTypeFromMethod(toCheck, new ReferenceType(currentClass.identifier));
if (type != null) { if (type != null) {
toCheck.type = type;
return new TypeCheckResult(true, type); return new TypeCheckResult(true, type);
} }
} }
@ -376,7 +372,6 @@ public class SemanticAnalyzer implements SemanticVisitor {
} }
} }
} else { } else {
ReferenceType reference = new ReferenceType(currentClass.identifier); ReferenceType reference = new ReferenceType(currentClass.identifier);
if (!toCheck.chainedMethods.isEmpty()) { if (!toCheck.chainedMethods.isEmpty()) {
for (ChainedMethodNode chainedMethod : toCheck.chainedMethods) { for (ChainedMethodNode chainedMethod : toCheck.chainedMethods) {

View File

@ -9,3 +9,10 @@ public class Person {
return this.age; return this.age;
} }
} }
public class Person2 {
public void greet() {
Person person = new Person(10);
person.getAge();
}
}