Files
tp2-vsl-pds/src/main/java/TP2/asd/Program.java

152 lines
4.6 KiB
Java

package TP2.asd;
import java.util.ArrayList;
import TP2.asd.Interface.*;
import TP2.llvm.ProgramLLVM.*;
public class Program{
//Prog
public static record ProgramImp(ArrayList<Function> fonctions,ArrayList<Prototype> protos) implements ProgramI{
public <H, S> S accept(ProgramVisitor<H, S> v, H h) {
return v.visitProgram(this, h);
}
public String prettyprinter(){
PrettyprinterVisitor ppVisitor = new PrettyprinterVisitor();
return this.accept(ppVisitor, "");
}
@Override
public ProgramLLVMImpl toLLVM() {
toLLVM_Visitor llvmVisitor = new toLLVM_Visitor();
return this.accept(llvmVisitor,new SymTable());
}
}
//Prototype
public static record PrototypeImp(Type type, String nom, ArrayList<String> s) implements Prototype{
@Override
public <H, S> S accept(PrototypeVisitor<H, S> v, H h) {
return v.visitPrototype(this,h);
}
}
//Fonction
public static record FunctionImp(Type type, String nom, ArrayList<String> s,Instruction instruction)implements Function {
//public FunctionImp(Type type, String name, Instruction instruction) {
// this(type, name, new ArrayList<>() {{ add(instruction); }}); C KOI ?
//}
public <H, S> S accept(FunctionVisitor<H, S> v, H h) {
return v.visitFunction(this, h);
}
}
//Expression
public static record ConstImp(int c) implements Expression{
public <H, S> S accept(ExprVisitor<H, S> v, H h) {
return v.visitConst(this, h);
}
}
public static record BinopExpressionImp(Op op,Expression e1, Expression e2) implements Expression{
public <H, S> S accept(ExprVisitor<H, S> v, H h) {
return v.visitBinOp(this, h);
}
}
public static record VarImp(String name) implements Expression {
public <H, S> S accept(ExprVisitor<H, S> v, H h) {
return v.visitVar(this, h);
}
}
//Declaration
public static record DeclarationImp(Type t, ArrayList<String> s) implements Declaration{
@Override
public <H, S> S accept(DeclVisitor<H, S> v, H h) {
return v.visitDeclaration(this, h);
}
}
//Instructions
public static record Return_instrImp(Expression e) implements Instruction{
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
return v.visitReturn(this,h);
}
}
public static record BlocDecImp(ArrayList<Declaration> decls, ArrayList<Instruction> instrs) implements Instruction{
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
return v.visitBlocDec(this, h);
}
}
public static record BlocImp(ArrayList<Instruction> instrs) implements Instruction{
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
return v.visitBloc(this, h);
}
}
public static record AssignImp(String t, Expression e) implements Instruction{
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
return v.visitAssign(this, h);
}
}
public static record PrintImp(ArrayList<Object> t) implements Instruction{
@Override
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
return v.visitPrint(this, h);
}
}
public static record ReadImp(ArrayList<VarImp> t) implements Instruction{
@Override
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
return v.visitRead(this, h);
}
}
public static record IfThenImp(Expression e, Instruction i1) implements Instruction {
@Override
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
return v.visitIfThen(this, h);
}
}
public static record IfThenElseImp(Expression e, Instruction i1, Instruction i2) implements Instruction {
@Override
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
return v.visitIfThenElse(this, h);
}
}
public static record WhileImp(Expression e, Instruction i1) implements Instruction {
@Override
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
return v.visitWhile(this, h);
}
}
//Type
public static record Type_voidImp() implements Type{
@Override
public <H, S> S accept(TypeVisitor<H, S> v, H h) {
return v.visitVoid(this, h);
}
}
public static record Type_intImp() implements Type{
@Override
public <H, S> S accept(TypeVisitor<H, S> v, H h) {
return v.visitInt(this, h);
}
}
}