forked from JavaTX/JavaCompilerCore
Assign ändern. Es gibt jetzt eine AssignLeftSide
This commit is contained in:
parent
9a7e717c25
commit
77c59de0f0
@ -0,0 +1,20 @@
|
||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.AssignLeftSide;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||
|
||||
public class AssignToLocal extends AssignLeftSide {
|
||||
public final LocalVar localVar;
|
||||
|
||||
public AssignToLocal(LocalVar leftSide) {
|
||||
super(leftSide.getType(), leftSide.getOffset());
|
||||
localVar = leftSide;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
@ -288,12 +288,15 @@ public class StatementGenerator {
|
||||
}
|
||||
|
||||
private Statement convert(Java8Parser.AssignmentContext stmt) {
|
||||
Expression leftHandSide = convert(stmt.leftHandSide());
|
||||
AssignLeftSide leftHandSide = convert(stmt.leftHandSide());
|
||||
return new Assign(leftHandSide, convert(stmt.expression()), stmt.getStart());
|
||||
}
|
||||
|
||||
private Expression convert(Java8Parser.LeftHandSideContext leftHandSide) {
|
||||
return generateLocalOrFieldVarOrClassName(leftHandSide.getText(), leftHandSide.getStart());
|
||||
private AssignLeftSide convert(Java8Parser.LeftHandSideContext leftHandSide) {
|
||||
Expression leftSide = generateLocalOrFieldVarOrClassName(leftHandSide.getText(), leftHandSide.getStart());
|
||||
if(leftSide instanceof FieldVar)return new AssignToField((FieldVar) leftSide);
|
||||
else if (leftSide instanceof LocalVar)return new AssignToLocal((LocalVar) leftSide);
|
||||
else throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private Statement convert(Java8Parser.IfThenStatementContext stmt){
|
||||
@ -412,7 +415,8 @@ public class StatementGenerator {
|
||||
}else{
|
||||
initValue = convert(varDecl.variableInitializer().expression());
|
||||
}
|
||||
ret.add(new Assign(new LocalVar(name.getText(), type, name.getSymbol()), initValue, name.getSymbol()));
|
||||
ret.add(new Assign(new AssignToLocal(new LocalVar(name.getText(), type, name.getSymbol()))
|
||||
, initValue, name.getSymbol()));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -426,9 +430,9 @@ public class StatementGenerator {
|
||||
}else{
|
||||
initValue = convert(varDecl.variableInitializer().expression());
|
||||
}
|
||||
return (new Assign(
|
||||
return (new Assign(new AssignToField(
|
||||
new FieldVar(new This(varDecl.getStart()), name.getText(),
|
||||
new Void(varDecl.getStart()), varDecl.getStart()),
|
||||
new Void(varDecl.getStart()), varDecl.getStart())),
|
||||
initValue, name.getSymbol()));
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
|
||||
@ -250,4 +252,14 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
||||
public void visit(Literal literal) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToField assignLeftSide) {
|
||||
assignLeftSide.field.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToLocal assignLeftSide) {
|
||||
assignLeftSide.localVar.accept(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree;
|
||||
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
|
||||
@ -58,4 +59,8 @@ public interface StatementVisitor {
|
||||
void visit(Null aNull);
|
||||
|
||||
void visit(Literal literal);
|
||||
|
||||
void visit(AssignToField assignLeftSide);
|
||||
|
||||
void visit(AssignToLocal assignLeftSide);
|
||||
}
|
||||
|
@ -8,13 +8,16 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintsFactory;
|
||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
|
||||
/*
|
||||
Aufbau:
|
||||
rightSide = leftSide
|
||||
*/
|
||||
public class Assign extends Statement
|
||||
{
|
||||
public final Expression rightSide;
|
||||
public final Expression lefSide;
|
||||
public final AssignLeftSide lefSide;
|
||||
|
||||
public Assign(Expression leftHandSide, Expression value, Token offset) {
|
||||
public Assign(AssignLeftSide leftHandSide, Expression value, Token offset) {
|
||||
super(leftHandSide.getType(), offset);
|
||||
this.rightSide = value;
|
||||
this.lefSide = leftHandSide;
|
||||
|
@ -0,0 +1,12 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public abstract class AssignLeftSide extends TypableStatement{
|
||||
|
||||
public AssignLeftSide(RefTypeOrTPHOrWildcardOrGeneric type, Token offset) {
|
||||
super(type, offset);
|
||||
}
|
||||
}
|
16
src/de/dhbwstuttgart/syntaxtree/statement/AssignToField.java
Normal file
16
src/de/dhbwstuttgart/syntaxtree/statement/AssignToField.java
Normal file
@ -0,0 +1,16 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
|
||||
public class AssignToField extends AssignLeftSide{
|
||||
public final FieldVar field;
|
||||
public AssignToField(FieldVar fieldVar) {
|
||||
super(fieldVar.getType(), fieldVar.getOffset());
|
||||
field = fieldVar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(StatementVisitor visitor) {
|
||||
visitor.visit(this);
|
||||
}
|
||||
}
|
@ -9,24 +9,9 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public abstract class Expression extends SyntaxTreeNode
|
||||
public abstract class Expression extends TypableStatement
|
||||
{
|
||||
private RefTypeOrTPHOrWildcardOrGeneric type;
|
||||
|
||||
public Expression(RefTypeOrTPHOrWildcardOrGeneric type, Token offset){
|
||||
super(offset);
|
||||
if(type == null)throw new NullPointerException();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getType(){
|
||||
return type;
|
||||
}
|
||||
|
||||
public abstract void accept(StatementVisitor visitor);
|
||||
|
||||
@Override
|
||||
public void accept(ASTVisitor visitor) {
|
||||
this.accept((StatementVisitor)visitor);
|
||||
super(type, offset);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
public abstract class TypableStatement extends SyntaxTreeNode{
|
||||
private RefTypeOrTPHOrWildcardOrGeneric type;
|
||||
|
||||
public TypableStatement(RefTypeOrTPHOrWildcardOrGeneric type, Token offset){
|
||||
super(offset);
|
||||
if(type == null)throw new NullPointerException();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public RefTypeOrTPHOrWildcardOrGeneric getType(){
|
||||
return type;
|
||||
}
|
||||
|
||||
public abstract void accept(StatementVisitor visitor);
|
||||
|
||||
@Override
|
||||
public void accept(ASTVisitor visitor) {
|
||||
this.accept((StatementVisitor)visitor);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.syntaxtree.visual;
|
||||
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
|
||||
@ -330,4 +331,14 @@ public class OutputGenerator implements ASTVisitor {
|
||||
public void visit(Literal literal) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToField assignLeftSide) {
|
||||
assignLeftSide.field.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToLocal assignLeftSide) {
|
||||
assignLeftSide.localVar.accept(this);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package de.dhbwstuttgart.typedeployment;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.AssignLeftSide;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.ResultSet;
|
||||
@ -27,6 +28,7 @@ public class TypeInsertPlacer extends AbstractASTWalker{
|
||||
this.inserts.addAll(cl.inserts);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
List<TypeInsert> ret = new ArrayList<>();
|
||||
|
||||
|
@ -4,6 +4,7 @@ package de.dhbwstuttgart.typeinference.typeAlgo;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||
import de.dhbwstuttgart.syntaxtree.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
|
||||
@ -219,6 +220,16 @@ public class TYPE implements StatementVisitor{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToField assignLeftSide) {
|
||||
//Hier ist kein Code nötig. Es werden keine extra Constraints generiert
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(AssignToLocal assignLeftSide) {
|
||||
//Hier ist kein Code nötig. Es werden keine extra Constraints generiert
|
||||
}
|
||||
|
||||
/*
|
||||
METHOD CALL Section:
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user