jsp c'est un arraylist de string ou varImp dans proto et func
This commit is contained in:
@@ -64,9 +64,9 @@ functions returns [ArrayList<Function> out]
|
||||
;
|
||||
|
||||
function returns [Function out]:
|
||||
FUNCTION t=type i=ident ParO ParF instr= instruction
|
||||
FUNCTION t=type i=ident ParO vars_locaux ParF instr= instruction
|
||||
{
|
||||
$out=new FunctionImp($t.return_type, $i.out, $instr.out);
|
||||
$out=new FunctionImp($t.return_type, $i.out, $vars_locaux.out, $instr.out);
|
||||
}
|
||||
;
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public class TypeChecking {
|
||||
if(!h.searchVar(instr.t())){
|
||||
return TypeCheckExprDiag.error("Variable "+instr.t()+" n'existe pas");
|
||||
}
|
||||
Type t_type=h.getvar_Type(instr.t()).type;
|
||||
Type t_type=h.getvar_Type(instr.t());
|
||||
TypeCheckExprDiag expr= instr.e().accept(expr_check, h);
|
||||
|
||||
if (!expr.get_check()) return expr;
|
||||
@@ -132,7 +132,7 @@ public class TypeChecking {
|
||||
if(!h.searchVar(e.name())){
|
||||
return TypeCheckExprDiag.error("Ce variable n'existe pas");
|
||||
}
|
||||
Type e_type= h.getvar_Type(e.name()).type;
|
||||
Type e_type= h.getvar_Type(e.name());
|
||||
return TypeCheckExprDiag.checked(e_type);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,19 +35,29 @@ 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.s().size();i++){
|
||||
str+=proto.s().get(i);
|
||||
if((i<proto.s().size()-1)){
|
||||
str+=", ";
|
||||
}
|
||||
}
|
||||
|
||||
return str+")";
|
||||
}
|
||||
|
||||
//FUNCTION
|
||||
@Override
|
||||
public String visitFunction(FunctionImp fun, String indent) {
|
||||
String str = indent+"FUNC " + fun.type().accept(this,"")+ " " + fun.nom() +"() ";
|
||||
String str = indent+"FUNC " + fun.type().accept(this,"")+ " " + fun.nom() +"(";
|
||||
|
||||
for(int i=0; i<fun.s().size();i++){
|
||||
str+=fun.s().get(i);
|
||||
if((i<fun.s().size()-1)){
|
||||
str+=", ";
|
||||
}
|
||||
}
|
||||
str+= ") ";
|
||||
str += fun.instruction().accept(this,indent)+"\n";
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class Program{
|
||||
}
|
||||
|
||||
//Fonction
|
||||
public static record FunctionImp(Type type, String nom, Instruction instruction)implements Function {
|
||||
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 ?
|
||||
//}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package TP2.llvm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import TP2.asd.Program.IfThenElseImp;
|
||||
import TP2.llvm.Interface.*;
|
||||
@@ -44,7 +45,12 @@ TypeLLVMVisitor<String,String>
|
||||
StringBuilder str = new StringBuilder("define ");
|
||||
str.append(define.type().accept(this,indent)).append(" @").append(define.name()).append("(");
|
||||
|
||||
//TODO param
|
||||
List<VarLLVMImpl> params = define.params();
|
||||
for (int i = 0; i < params.size(); i++) {
|
||||
VarLLVMImpl param = params.get(i);
|
||||
str.append(param.getType().accept(this, indent)).append(" ").append(param.accept(this, indent));
|
||||
if (i < params.size() - 1) str.append(", ");
|
||||
}
|
||||
|
||||
str.append("){\n");
|
||||
for(InstructionLLVM instr : define.instrs()){
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
PROTO INT add(x,y)
|
||||
FUNC INT main() {
|
||||
FUNC INT main(x,y) {
|
||||
INT a,b,c
|
||||
b:=3
|
||||
c:=1
|
||||
|
||||
Reference in New Issue
Block a user