ASTVisitor implementieren

This commit is contained in:
JanUlrich 2017-06-28 17:20:26 +02:00
parent 3173cccefa
commit afd3f32f23
35 changed files with 93 additions and 260 deletions

View File

@ -4,8 +4,6 @@ import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.antlr.Java8Parser;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.operator.AndOp;
import de.dhbwstuttgart.syntaxtree.operator.OrOp;
import de.dhbwstuttgart.syntaxtree.statement.*;
import de.dhbwstuttgart.syntaxtree.statement.literal.*;
import de.dhbwstuttgart.syntaxtree.type.RefType;
@ -505,7 +503,7 @@ public class StatementGenerator {
return convert(expression.conditionalAndExpression());
}else{
return new Binary(convert(expression.conditionalOrExpression()),
convert(expression.conditionalAndExpression()), new OrOp(null));
convert(expression.conditionalAndExpression()), Binary.Operator.OR);
}
}
@ -514,7 +512,7 @@ public class StatementGenerator {
return convert(expression.inclusiveOrExpression());
}else{
return new Binary(convert(expression.conditionalAndExpression()),
convert(expression.inclusiveOrExpression()), new AndOp(null));
convert(expression.inclusiveOrExpression()), Binary.Operator.AND);
}
}

View File

@ -0,0 +1,25 @@
package de.dhbwstuttgart.syntaxtree;
import de.dhbwstuttgart.syntaxtree.statement.*;
import de.dhbwstuttgart.syntaxtree.statement.literal.Literal;
import de.dhbwstuttgart.syntaxtree.statement.literal.Null;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
public interface ASTVisitor extends StatementVisitor{
void visit(SourceFile sourceFile);
void visit(ArgumentList argumentList);
void visit(RefTypeOrTPHOrWildcardOrGeneric refTypeOrTPHOrWildcardOrGeneric);
void visit(GenericTypeVar genericTypeVar);
void visit(FormalParameter formalParameter);
void visit(GenericDeclarationList genericTypeVars);
void visit(Field field);
void visit(ParameterList formalParameters);
}

View File

@ -24,5 +24,10 @@ public class Field extends SyntaxTreeNode{
public RefTypeOrTPHOrWildcardOrGeneric getType() {
return type;
}
@Override
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -21,4 +21,9 @@ public class FormalParameter extends SyntaxTreeNode
public String getName() {
return name;
}
@Override
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -26,4 +26,9 @@ public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<G
public Iterator<GenericTypeVar> iterator() {
return gtvs.iterator();
}
@Override
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -51,4 +51,9 @@ public class GenericTypeVar extends SyntaxTreeNode
public GenericTypeName getName() {
return name;
}
@Override
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -34,4 +34,9 @@ public class ParameterList extends SyntaxTreeNode implements Iterable<FormalPara
public Iterator<FormalParameter> iterator() {
return null;
}
@Override
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -62,4 +62,9 @@ public class SourceFile extends SyntaxTreeNode{
public File getFile() {
return file;
}
@Override
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -19,4 +19,5 @@ public abstract class SyntaxTreeNode implements IItemWithOffset{
return offset;
}
public abstract void accept(ASTVisitor visitor);
}

View File

@ -1,23 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import org.antlr.v4.runtime.Token;
import org.apache.bcel.Constants;
import org.apache.bcel.generic.ArithmeticInstruction;
import org.apache.bcel.generic.DUP;
import org.apache.bcel.generic.IADD;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.InvokeInstruction;
import org.apache.bcel.generic.ObjectType;
public abstract class AddOp extends Operator
{
public AddOp(Token offset) {
super(offset);
}
}

View File

@ -1,18 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.statement.Binary;
import org.antlr.v4.runtime.Token;
import org.apache.bcel.generic.InstructionList;
public class AndOp extends LogOp
{
public AndOp(Token offset)
{
super(offset);
}
}

View File

@ -1,12 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import org.antlr.v4.runtime.Token;
public class DivideOp extends MulOp
{
public DivideOp(Token offset) {
super(offset);
}
}

View File

@ -1,15 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import org.antlr.v4.runtime.Token;
import org.apache.bcel.generic.BranchInstruction;
import org.apache.bcel.generic.IF_ICMPNE;
public class EqualOp extends RelOp
{
public EqualOp(Token offset) {
super(offset);
}
}

View File

@ -1,13 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import org.antlr.v4.runtime.Token;
public class GreaterEquOp extends RelOp
{
public GreaterEquOp(Token offset) {
super(offset);
}
}

View File

@ -1,14 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import org.antlr.v4.runtime.Token;
public class GreaterOp extends RelOp
{
public GreaterOp(Token offset) {
super(offset);
}
}

View File

@ -1,15 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import org.antlr.v4.runtime.Token;
public class LessEquOp extends RelOp
{
public LessEquOp(Token offset) {
super(offset);
}
}

View File

@ -1,14 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import org.antlr.v4.runtime.Token;
public class LessOp extends RelOp
{
public LessOp(Token offset)
{
super(offset);
}
}

View File

@ -1,18 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import org.antlr.v4.runtime.Token;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
public abstract class LogOp extends Operator
{
public LogOp(Token offset)
{
super(offset);
}
}

View File

@ -1,11 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import org.antlr.v4.runtime.Token;
public class MinusOp extends AddOp
{
public MinusOp(Token offset) {
super(offset);
}
}

View File

@ -1,15 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import org.antlr.v4.runtime.Token;
public class ModuloOp extends MulOp
{
public ModuloOp(Token offset)
{
super(offset);
}
}

View File

@ -1,10 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import org.antlr.v4.runtime.Token;
public abstract class MulOp extends Operator
{
public MulOp(Token offset) {
super(offset);
}
}

View File

@ -1,11 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import org.antlr.v4.runtime.Token;
public class NotEqualOp extends RelOp
{
public NotEqualOp(Token offset) {
super(offset);
}
}

View File

@ -1,13 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import org.antlr.v4.runtime.Token;
public abstract class Operator extends SyntaxTreeNode
{
public Operator(Token offset) {
super(offset);
}
}

View File

@ -1,15 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import org.antlr.v4.runtime.Token;
public class OrOp extends LogOp
{
public OrOp(Token offset)
{
super(offset);
}
}

View File

@ -1,12 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import org.antlr.v4.runtime.Token;
public class PlusOp extends AddOp
{
public PlusOp(Token offset)
{
super(offset);
}
}

View File

@ -1,11 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import org.antlr.v4.runtime.Token;
public abstract class RelOp extends Operator
{
public RelOp(Token offset) {
super(offset);
}
}

View File

@ -1,11 +0,0 @@
package de.dhbwstuttgart.syntaxtree.operator;
import org.antlr.v4.runtime.Token;
public class TimesOp extends MulOp
{
public TimesOp(Token offset)
{
super(offset);
}
}

View File

@ -1,6 +1,7 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import org.antlr.v4.runtime.Token;
@ -19,4 +20,8 @@ public class ArgumentList extends SyntaxTreeNode
return expr;
}
@Override
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -6,12 +6,16 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
import de.dhbwstuttgart.syntaxtree.operator.Operator;
// neu von Felix
public class Binary extends Expression
{
public enum Operator{
ADD,
SUB,
MUL,
AND, OR, DIV
}
public Binary(Expression expr1, Expression expr2, Operator op){
super(null, null);
}

View File

@ -1,6 +1,7 @@
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;
@ -23,4 +24,9 @@ public abstract class Expression extends SyntaxTreeNode
}
public abstract void accept(StatementVisitor visitor);
@Override
public void accept(ASTVisitor visitor) {
this.accept((StatementVisitor)visitor);
}
}

View File

@ -1,7 +1,6 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
import de.dhbwstuttgart.syntaxtree.operator.Operator;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;

View File

@ -1,5 +1,6 @@
package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import org.antlr.v4.runtime.Token;
@ -7,4 +8,9 @@ public class RefTypeOrTPHOrWildcardOrGeneric extends SyntaxTreeNode{
public RefTypeOrTPHOrWildcardOrGeneric(Token offset) {
super(offset);
}
@Override
public void accept(ASTVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -0,0 +1,5 @@
package de.dhbwstuttgart.syntaxtree.visual;
public class ASTPrinter {
}

View File

@ -1,8 +1,12 @@
class Faculty {
Integer mul(Integer x, Integer y) {
return x;
}
m () {
auto fact = (Integer x) -> {
return fact.apply(x);
return mul(x, fact.apply(x));
};
return fact;
}

View File

@ -26,7 +26,8 @@ public class JavaTXCompilerTest {
@Test
public void test() throws IOException, ClassNotFoundException {
filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
filesToTest.add(new File(rootDirectory+"Faculty.jav"));
//filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda3.jav"));