prettyprinter en Visitor
This commit is contained in:
@@ -17,12 +17,9 @@ public class Program{
|
||||
}
|
||||
|
||||
public String prettyprinter(){
|
||||
String str ="";
|
||||
for(int i = 0; i<fonctions.size(); i++){
|
||||
str += fonctions.get(i).prettyprinter(INDENT);
|
||||
if(i<fonctions.size()-1) str += "\n";
|
||||
}
|
||||
return str;
|
||||
PrettyprinterVisitor ppVisitor = new PrettyprinterVisitor();
|
||||
return this.accept(ppVisitor, "");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -47,15 +44,6 @@ public class Program{
|
||||
return v.visitFunction(this, h);
|
||||
}
|
||||
|
||||
public String prettyprinter(String indent){
|
||||
String str = indent+"FUNC " + type.prettyprinter()+ " " + nom +"(){\n";
|
||||
for(int i = 0; i<instructions.size(); i++){
|
||||
str += instructions.get(i).prettyprinter(indent+INDENT)+"\n";
|
||||
}
|
||||
str+= indent+"}";
|
||||
return str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefineLLVM toLLVM() {
|
||||
ArrayList<InstructionLLVM> instrLLVM = new ArrayList<>();
|
||||
@@ -72,10 +60,6 @@ public class Program{
|
||||
return v.visitConst(this, h);
|
||||
}
|
||||
|
||||
public String prettyprinter(){
|
||||
return c+"";
|
||||
}
|
||||
|
||||
public ValLLVM getValLLVM(){
|
||||
ValLLVM val = new ValLLVMImpl(new IntLLVMImpl(),c);
|
||||
return val;
|
||||
@@ -97,19 +81,6 @@ public class Program{
|
||||
return v.visitBinOp(this, h);
|
||||
}
|
||||
|
||||
public String prettyprinter(){
|
||||
String opStr = "?";
|
||||
switch(op){
|
||||
case PLUS: opStr = "+"; break;
|
||||
case DIV: opStr = "/"; break;
|
||||
case MINUS: opStr = "-"; break;
|
||||
case MOD: opStr = "%"; break;
|
||||
case TIMES: opStr = "*"; break;
|
||||
default:break;
|
||||
}
|
||||
return "(" + e1.prettyprinter() +" "+ opStr +" " + e2.prettyprinter() + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<AssignLVMImp> toLLVM() { //TODO si e1 ou e2 est une constante, elle doit pouvoir être mise directement dans l'expression
|
||||
ArrayList<AssignLVMImp> list = new ArrayList<>();
|
||||
@@ -145,10 +116,6 @@ public class Program{
|
||||
return v.visitReturn(this,h);
|
||||
}
|
||||
|
||||
public String prettyprinter(String indent){
|
||||
return indent+"RETURN " + e.prettyprinter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> toLLVM() {
|
||||
ArrayList<AssignLVMImp> list = e.toLLVM();
|
||||
@@ -167,11 +134,6 @@ public class Program{
|
||||
return v.visitAssign(this, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prettyprinter(String indent) {
|
||||
return t+ " :=" + e.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> toLLVM() {
|
||||
ArrayList<AssignLVMImp> list = e.toLLVM();
|
||||
@@ -190,15 +152,6 @@ public class Program{
|
||||
return v.visitDeclaration(this, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prettyprinter(String indent) {
|
||||
String str = indent + "declare "+t.prettyprinter() + " ";
|
||||
for(int i = 0; i<s.size();i++){
|
||||
str += s.get(i) + ", ";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<InstructionLLVM> toLLVM() {
|
||||
// TODO Auto-generated method stub
|
||||
@@ -208,20 +161,23 @@ public class Program{
|
||||
|
||||
//Type
|
||||
public static record Type_voidImp() implements Type{
|
||||
public String prettyprinter() {
|
||||
return "VOID";
|
||||
@Override
|
||||
public <H, S> S accept(TypeVisitor<H, S> v, H h) {
|
||||
return v.visitVoid(this, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeLLVM toLLVM() {
|
||||
return new IntLLVMImpl();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static record Type_intImp() implements Type{
|
||||
public String prettyprinter() {
|
||||
return "INT";
|
||||
@Override
|
||||
public <H, S> S accept(TypeVisitor<H, S> v, H h) {
|
||||
return v.visitInt(this, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user