fix prototype
This commit is contained in:
@@ -28,16 +28,16 @@ program returns [ProgramImp p] :
|
||||
{$p = new ProgramImp($func.out,$pro.out);}
|
||||
;
|
||||
|
||||
prototypes returns [ArrayList<Prototype> out]
|
||||
prototypes returns [ArrayList<Function> out]
|
||||
@init{
|
||||
$out = new ArrayList<Prototype>();
|
||||
$out = new ArrayList<Function>();
|
||||
}:
|
||||
(proto {
|
||||
$out.add($proto.out);
|
||||
})*
|
||||
;
|
||||
|
||||
proto returns [Prototype out]:
|
||||
proto returns [Function out]:
|
||||
PROTOTYPE t=type i=ident ParO v=liste_param ParF
|
||||
{
|
||||
$out=new PrototypeImp($t.return_type,$i.out, $v.out);
|
||||
|
||||
@@ -18,10 +18,15 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
||||
@Override
|
||||
public String visitProgram(ProgramImp prog, String indent) {
|
||||
String str ="";
|
||||
for(int i = 0; i<prog.fonctions().size(); i++){
|
||||
str += prog.fonctions().get(i).accept(this,INDENT);
|
||||
if(i<prog.fonctions().size()-1) str += "\n";
|
||||
}
|
||||
for(int i= 0; i<prog.protos().size();i++){
|
||||
str+=prog.protos().get(i).accept(this, INDENT);
|
||||
if(i<prog.protos().size()-1) str += "\n";
|
||||
}
|
||||
str+="\n";
|
||||
for(int i = 0; i<prog.fonctions().size(); i++){
|
||||
str += prog.fonctions().get(i).accept(this,INDENT);
|
||||
if(i<prog.fonctions().size()-1) str += "\n";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -29,7 +34,6 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
||||
@Override
|
||||
public String visitPrototype(PrototypeImp proto, String indent){
|
||||
String str= indent + "PROTO "+proto.type().accept(this, "")+ " "+ proto.nom() + "(";
|
||||
|
||||
for(int i=0; i<proto.params().size();i++){
|
||||
str+=proto.params().get(i).accept(this, "");
|
||||
if((i<proto.params().size()-1)){
|
||||
@@ -43,7 +47,6 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
|
||||
@Override
|
||||
public String visitFunction(FunctionImp fun, String indent) {
|
||||
String str = indent+"FUNC " + fun.type().accept(this,"")+ " " + fun.nom() +"(";
|
||||
|
||||
for(int i=0; i<fun.params().size();i++){
|
||||
str+=fun.params().get(i).accept(this, "");
|
||||
if((i<fun.params().size()-1)){
|
||||
|
||||
@@ -7,7 +7,7 @@ import TP2.llvm.ProgramLLVM.*;
|
||||
public class Program{
|
||||
|
||||
//Prog
|
||||
public static record ProgramImp(ArrayList<Function> fonctions) implements ProgramI{
|
||||
public static record ProgramImp(ArrayList<Function> fonctions,ArrayList<Function> protos) implements ProgramI{
|
||||
public <H, S> S accept(ProgramVisitor<H, S> v, H h) {
|
||||
return v.visitProgram(this, h);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user