Files
tp2-vsl-pds/src/main/java/TP2/asd/Program.java
Rochas 058ea815a1 clean
2025-04-30 19:41:42 +02:00

174 lines
5.3 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) 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, "");
}
//public TypeCheckExprDiag typeChecking(){
// TypeChecking tcVisitor = new TypeChecking();
// return this.accept(tcVisitor, new SymTable());
//}
public ProgramLLVMImp toLLVM() {
toLLVM_Visitor llvmVisitor = new toLLVM_Visitor();
return this.accept(llvmVisitor,new SymTable());
}
}
//Fonction
public static record FunctionImp(Type type, String nom, ArrayList<VarImp> params,Instruction instruction) implements Function {
public <H, S> S accept(FunctionVisitor<H, S> v, H h) {
return v.visitFunction(this, h);
}
}
public static record PrototypeImp(Type type, String nom, ArrayList<VarImp> params) implements Function{
@Override
public <H, S> S accept(FunctionVisitor<H, S> v, H h) {
return v.visitPrototype(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);
}
}
public static record CallImp(String fName, ArrayList<Expression> params) implements Expression{
@Override
public <H, S> S accept(ExprVisitor<H, S> v, H h) {
return v.visitCall(this, h);
}
}
//Declaration
public static record DeclarationImp(Type t, ArrayList<VarDeclImp> s) implements Declaration{
@Override
public <H, S> S accept(DeclVisitor<H, S> v, H h) {
return v.visitDeclaration(this, h);
}
}
public static record VarDeclImp(String nom, Expression size) implements Declaration{
@Override
public <H, S> S accept(DeclVisitor<H, S> v, H h) {
return v.visitVarDecl(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);
}
}
//t : String et Expression
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);
}
}
public static record VoidFunctionImp(String nom, ArrayList<Expression> expr) implements Instruction{
@Override
public <H, S> S accept(InstrVisitor<H, S> v, H h) {
return v.visitVoidFunction(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);
}
}
}