Constructor um fieldInits erweitern, auch der TYPE algo
This commit is contained in:
parent
6b98bf6a58
commit
9a7e717c25
@ -4,6 +4,7 @@ import de.dhbwstuttgart.syntaxtree.statement.*;
|
|||||||
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
|
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
|
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
|
|
||||||
public interface ASTVisitor extends StatementVisitor{
|
public interface ASTVisitor extends StatementVisitor{
|
||||||
|
|
||||||
@ -21,6 +22,8 @@ public interface ASTVisitor extends StatementVisitor{
|
|||||||
|
|
||||||
void visit(Method field);
|
void visit(Method field);
|
||||||
|
|
||||||
|
void visit(Constructor field);
|
||||||
|
|
||||||
void visit(ParameterList formalParameters);
|
void visit(ParameterList formalParameters);
|
||||||
|
|
||||||
void visit(ClassOrInterface classOrInterface);
|
void visit(ClassOrInterface classOrInterface);
|
||||||
|
@ -9,6 +9,10 @@ import java.lang.reflect.Modifier;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public abstract class AbstractASTWalker implements ASTVisitor{
|
public abstract class AbstractASTWalker implements ASTVisitor{
|
||||||
|
@Override
|
||||||
|
public void visit(Constructor cons) {
|
||||||
|
visitMethod(cons);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(SourceFile sourceFile) {
|
public void visit(SourceFile sourceFile) {
|
||||||
@ -51,6 +55,10 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(Method method) {
|
public void visit(Method method) {
|
||||||
|
visitMethod(method);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void visitMethod(Method method){
|
||||||
method.getType().accept(this);
|
method.getType().accept(this);
|
||||||
method.getParameterList().accept(this);
|
method.getParameterList().accept(this);
|
||||||
method.block.accept(this);
|
method.block.accept(this);
|
||||||
|
@ -82,7 +82,7 @@ public class ClassOrInterface extends SyntaxTreeNode {
|
|||||||
return this.genericClassParameters;
|
return this.genericClassParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<? extends Method> getConstructors() {
|
public List<Constructor> getConstructors() {
|
||||||
return constructors;
|
return constructors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,10 @@ package de.dhbwstuttgart.syntaxtree;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||||
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||||
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.typeAlgo.TYPE;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||||
@ -23,4 +27,17 @@ public class Constructor extends Method {
|
|||||||
this.fieldInitializations = fieldInitializations;
|
this.fieldInitializations = fieldInitializations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConstraintSet getConstraints(TypeInferenceInformation info, ClassOrInterface currentClass) {
|
||||||
|
TypeInferenceBlockInformation blockInfo = new TypeInferenceBlockInformation(info.getAvailableClasses(), currentClass, null);
|
||||||
|
TYPE methodScope = new TYPE(blockInfo);
|
||||||
|
for(Statement stmt : fieldInitializations)stmt.accept(methodScope);
|
||||||
|
ConstraintSet ret = super.getConstraints(info, currentClass);
|
||||||
|
ret.addAll(methodScope.getConstraints());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(ASTVisitor visitor) {
|
||||||
|
visitor.visit(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,14 @@ public class OutputGenerator implements ASTVisitor {
|
|||||||
out.append("\n");
|
out.append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Constructor method) {
|
||||||
|
out.append(method.getName());
|
||||||
|
method.getParameterList().accept(this);
|
||||||
|
method.block.accept(this);
|
||||||
|
out.append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ParameterList formalParameters) {
|
public void visit(ParameterList formalParameters) {
|
||||||
out.append("(");
|
out.append("(");
|
||||||
@ -121,6 +129,11 @@ public class OutputGenerator implements ASTVisitor {
|
|||||||
m.accept(this);
|
m.accept(this);
|
||||||
out.append("\n");
|
out.append("\n");
|
||||||
}
|
}
|
||||||
|
for(Constructor m : classOrInterface.getConstructors()){
|
||||||
|
out.append(tabs);
|
||||||
|
m.accept(this);
|
||||||
|
out.append("\n");
|
||||||
|
}
|
||||||
untab();
|
untab();
|
||||||
out.append("}");
|
out.append("}");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user