jsp c'est un arraylist de string ou varImp dans proto et func

This commit is contained in:
Vu Tuan Minh
2025-04-24 07:00:31 +02:00
parent 0ae9660fc5
commit a86f3433be
6 changed files with 24 additions and 8 deletions

View File

@@ -64,9 +64,9 @@ functions returns [ArrayList<Function> out]
; ;
function returns [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);
} }
; ;

View File

@@ -54,7 +54,7 @@ public class TypeChecking {
if(!h.searchVar(instr.t())){ if(!h.searchVar(instr.t())){
return TypeCheckExprDiag.error("Variable "+instr.t()+" n'existe pas"); 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); TypeCheckExprDiag expr= instr.e().accept(expr_check, h);
if (!expr.get_check()) return expr; if (!expr.get_check()) return expr;
@@ -132,7 +132,7 @@ public class TypeChecking {
if(!h.searchVar(e.name())){ if(!h.searchVar(e.name())){
return TypeCheckExprDiag.error("Ce variable n'existe pas"); 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); return TypeCheckExprDiag.checked(e_type);
} }

View File

@@ -35,19 +35,29 @@ public class PrettyprinterVisitor implements ProgramVisitor<String,String>,
@Override @Override
public String visitPrototype(PrototypeImp proto, String indent){ public String visitPrototype(PrototypeImp proto, String indent){
String str= indent + "PROTO "+proto.type().accept(this, "")+ " "+ proto.nom() + "("; String str= indent + "PROTO "+proto.type().accept(this, "")+ " "+ proto.nom() + "(";
for(int i=0; i<proto.s().size();i++){ for(int i=0; i<proto.s().size();i++){
str+=proto.s().get(i); str+=proto.s().get(i);
if((i<proto.s().size()-1)){ if((i<proto.s().size()-1)){
str+=", "; str+=", ";
} }
} }
return str+")"; return str+")";
} }
//FUNCTION //FUNCTION
@Override @Override
public String visitFunction(FunctionImp fun, String indent) { 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"; str += fun.instruction().accept(this,indent)+"\n";
return str; return str;
} }

View File

@@ -34,7 +34,7 @@ public class Program{
} }
//Fonction //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) { //public FunctionImp(Type type, String name, Instruction instruction) {
// this(type, name, new ArrayList<>() {{ add(instruction); }}); C KOI ? // this(type, name, new ArrayList<>() {{ add(instruction); }}); C KOI ?
//} //}

View File

@@ -1,6 +1,7 @@
package TP2.llvm; package TP2.llvm;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import TP2.asd.Program.IfThenElseImp; import TP2.asd.Program.IfThenElseImp;
import TP2.llvm.Interface.*; import TP2.llvm.Interface.*;
@@ -44,7 +45,12 @@ TypeLLVMVisitor<String,String>
StringBuilder str = new StringBuilder("define "); StringBuilder str = new StringBuilder("define ");
str.append(define.type().accept(this,indent)).append(" @").append(define.name()).append("("); 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"); str.append("){\n");
for(InstructionLLVM instr : define.instrs()){ for(InstructionLLVM instr : define.instrs()){

View File

@@ -1,5 +1,5 @@
PROTO INT add(x,y) PROTO INT add(x,y)
FUNC INT main() { FUNC INT main(x,y) {
INT a,b,c INT a,b,c
b:=3 b:=3
c:=1 c:=1