Add TargetExpression

This commit is contained in:
Andreas Stadelmeier 2022-03-30 03:17:55 +02:00
parent f03d3f5e64
commit 8e80cc2985
14 changed files with 232 additions and 15 deletions

View File

@ -4,14 +4,11 @@ import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
import de.dhbwstuttgart.syntaxtree.Field;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.target.tree.TargetClass;
import de.dhbwstuttgart.target.tree.TargetConstructor;
import de.dhbwstuttgart.target.tree.TargetField;
import de.dhbwstuttgart.target.tree.TargetMethod;
import de.dhbwstuttgart.target.tree.type.TargetRefType;
import de.dhbwstuttgart.target.tree.type.TargetSuperWildcard;
import de.dhbwstuttgart.target.tree.type.TargetType;
import de.dhbwstuttgart.target.tree.*;
import de.dhbwstuttgart.target.tree.expression.TargetBlock;
import de.dhbwstuttgart.target.tree.type.*;
import java.util.ArrayList;
import java.util.List;
@ -31,14 +28,24 @@ public class ASTToTargetAST {
}
private TargetMethod convert(Method input, Map<TypePlaceholder, TargetType> sigma) {
return null;
List<MethodParameter> params = input.getParameterList().getFormalparalist().stream()
.map(param -> new MethodParameter(convert(param.getType(), sigma), param.getName())).collect(Collectors.toList());
return new TargetMethod(input.name, params, convert(input.block));
}
private TargetBlock convert(Block block) {
return new TargetBlock(block.statements.stream().map(e -> {
StatementToTargetExpression converter = new StatementToTargetExpression();
e.accept(converter);
return converter.result;
}).collect(Collectors.toList()));
}
private TargetField convert(Field input, Map<TypePlaceholder, TargetType> sigma) {
return null;
}
private TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input, Map<TypePlaceholder, RefTypeOrTPHOrWildcardOrGeneric> sigma) {
private TargetType convert(RefTypeOrTPHOrWildcardOrGeneric input, Map<TypePlaceholder, TargetType> sigma) {
return input.acceptTV(new TypeVisitor<>() {
@Override
public TargetType visit(RefType refType) {
@ -53,17 +60,17 @@ public class ASTToTargetAST {
@Override
public TargetType visit(TypePlaceholder typePlaceholder) {
return convert(sigma.get(typePlaceholder), sigma);
return sigma.get(typePlaceholder);
}
@Override
public TargetType visit(ExtendsWildcardType extendsWildcardType) {
return null;
return new TargetExtendsWildcard(convert(extendsWildcardType.getInnerType(), sigma));
}
@Override
public TargetType visit(GenericRefType genericRefType) {
return null;
return new TargetGenericType(genericRefType.getParsedName());
}
});
}

View File

@ -0,0 +1,156 @@
package de.dhbwstuttgart.target.generate;
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.statement.*;
import de.dhbwstuttgart.target.tree.expression.TargetExpression;
public class StatementToTargetExpression implements StatementVisitor {
public TargetExpression result;
@Override
public void visit(ArgumentList argumentList) {
}
@Override
public void visit(LambdaExpression lambdaExpression) {
}
@Override
public void visit(Assign assign) {
}
@Override
public void visit(BinaryExpr binary) {
}
@Override
public void visit(Block block) {
}
@Override
public void visit(CastExpr castExpr) {
}
@Override
public void visit(EmptyStmt emptyStmt) {
}
@Override
public void visit(FieldVar fieldVar) {
}
@Override
public void visit(ForStmt forStmt) {
}
@Override
public void visit(IfStmt ifStmt) {
}
@Override
public void visit(InstanceOf instanceOf) {
}
@Override
public void visit(LocalVar localVar) {
}
@Override
public void visit(LocalVarDecl localVarDecl) {
}
@Override
public void visit(MethodCall methodCall) {
}
@Override
public void visit(NewClass methodCall) {
}
@Override
public void visit(NewArray newArray) {
}
@Override
public void visit(Return aReturn) {
}
@Override
public void visit(ReturnVoid aReturn) {
}
@Override
public void visit(StaticClassName staticClassName) {
}
@Override
public void visit(Super aSuper) {
}
@Override
public void visit(This aThis) {
}
@Override
public void visit(WhileStmt whileStmt) {
}
@Override
public void visit(DoStmt whileStmt) {
}
@Override
public void visit(AssignToField assignLeftSide) {
}
@Override
public void visit(AssignToLocal assignLeftSide) {
}
@Override
public void visit(SuperCall superCall) {
}
@Override
public void visit(ExpressionReceiver expressionReceiver) {
}
@Override
public void visit(UnaryExpr unaryExpr) {
}
@Override
public void visit(Literal literal) {
}
}

View File

@ -1,9 +1,9 @@
package de.dhbwstuttgart.target.tree;
import de.dhbwstuttgart.target.tree.type.TargetType;
import de.dhbwstuttgart.target.tree.expression.TargetBlock;
import java.util.List;
public record TargetMethod(String name, List<MethodParameter> parameterTypes) {
public record TargetMethod(String name, List<MethodParameter> parameterTypes, TargetBlock block) {
}

View File

@ -0,0 +1,4 @@
package de.dhbwstuttgart.target.tree.expression;
public record TargetAssign(TargetExpression leftSide, TargetExpression rightSide) implements TargetExpression {
}

View File

@ -0,0 +1,6 @@
package de.dhbwstuttgart.target.tree.expression;
import java.util.List;
public record TargetBlock(List<TargetExpression> statememts) implements TargetExpression {
}

View File

@ -0,0 +1,7 @@
package de.dhbwstuttgart.target.tree.expression;
import de.dhbwstuttgart.target.tree.type.*;
public sealed interface TargetExpression
permits TargetBlock, TargetLambdaExpression, TargetReturn, TargetThis, TargetSuper, TargetNew, TargetAssign {
}

View File

@ -0,0 +1,8 @@
package de.dhbwstuttgart.target.tree.expression;
import de.dhbwstuttgart.target.tree.MethodParameter;
import java.util.List;
public record TargetLambdaExpression(List<MethodParameter> params, TargetExpression block) implements TargetExpression {
}

View File

@ -0,0 +1,8 @@
package de.dhbwstuttgart.target.tree.expression;
import de.dhbwstuttgart.target.tree.type.TargetType;
import java.util.List;
public record TargetNew(TargetType instantiatedType, List<TargetExpression> params) implements TargetExpression {
}

View File

@ -0,0 +1,4 @@
package de.dhbwstuttgart.target.tree.expression;
public record TargetReturn(TargetExpression expression) implements TargetExpression {
}

View File

@ -0,0 +1,4 @@
package de.dhbwstuttgart.target.tree.expression;
public record TargetSuper() implements TargetExpression {
}

View File

@ -0,0 +1,4 @@
package de.dhbwstuttgart.target.tree.expression;
public record TargetThis() implements TargetExpression {
}

View File

@ -0,0 +1,4 @@
package de.dhbwstuttgart.target.tree.type;
public record TargetGenericType(String name) implements TargetType {
}

View File

@ -1,5 +1,5 @@
package de.dhbwstuttgart.target.tree.type;
public sealed interface TargetType
permits TargetExtendsWildcard, TargetFunNType, TargetRefType, TargetSuperWildcard {
permits TargetExtendsWildcard, TargetFunNType, TargetGenericType, TargetRefType, TargetSuperWildcard {
}

View File

@ -0,0 +1,5 @@
package targetast;
public class ASTToTargetTest {
}