detection d'erreur Fonction/Proto + harmonisation nom des Class dans ProgramLLVM (mélange de 'Imp' et 'Impl')

This commit is contained in:
Rochas
2025-04-27 19:02:08 +02:00
parent 0105a3f59e
commit 6dfa1c6fd8
10 changed files with 131 additions and 114 deletions

View File

@@ -3,13 +3,13 @@ import java.util.Stack;
import org.pcollections.*;
import TP2.asd.Interface.Type;
import TP2.asd.Program.Type_intImp;
import TP2.llvm.ProgramLLVM.DefineLLVMImpl;
import TP2.llvm.ProgramLLVM.DefineLLVMImp;
public class SymTable {
private PMap<String,ValueTable> varMap;
private PMap<String,DefineLLVMImpl> fuctionsMap;
private PMap<String,ValueVarMap> varMap;
private PMap<String,ValueFunMap> fuctionsMap;
private int id=1;
private int idLabel = 1;
@@ -17,19 +17,28 @@ public class SymTable {
this.varMap= HashTreePMap.empty();
this.fuctionsMap = HashTreePMap.empty();
}
public SymTable(PMap<String,ValueTable> varMap,PMap<String,DefineLLVMImpl> fuctionsMap, int id, int idLabel){
public SymTable(PMap<String,ValueVarMap> varMap, PMap<String,ValueFunMap> fuctionsMap, int id, int idLabel){
this.varMap= varMap;
this.id = id;
this.fuctionsMap = fuctionsMap;
this.idLabel = idLabel;
}
public static class ValueFunMap{
public DefineLLVMImp define;
public Boolean isProto;
public static class ValueTable{
public ValueFunMap(DefineLLVMImp define, Boolean isProto){
this.define = define;
this.isProto = isProto;
}
}
public static class ValueVarMap{
public Type type;
public int id;
public Boolean isParam;
public ValueTable(Type type,int id, Boolean isParam){
public ValueVarMap(Type type,int id, Boolean isParam){
this.type = type;
this.id = id;
this.isParam = isParam;
@@ -52,14 +61,20 @@ public class SymTable {
public SymTable addFunction(DefineLLVMImpl function){
if(!this.fuctionsMap.containsKey(function.name())){
return new SymTable(this.varMap,this.fuctionsMap.plus(function.name(),function),this.id,this.idLabel);
public SymTable addFunction(DefineLLVMImp function, Boolean isProto){
ValueFunMap value = this.fuctionsMap.get(function.name());
if(value == null || (value!=null && value.isProto && !isProto)){
return new SymTable(this.varMap, this.fuctionsMap.plus(function.name(),new ValueFunMap(function,isProto)), this.id, this.idLabel);
}
else{
if(value.isProto) System.err.println("[VSL compile error] : Le prototype "+function.name()+" existe déjà");
else if(isProto) System.err.println("[VSL compile error] : Le prototype "+function.name()+" doit être déclaré avant son implémentation");
else System.err.println("[VSL compile error] : La fonction "+function.name()+" existe déjà");
return null;
}
return this;
}
public DefineLLVMImpl getFunction(String name){
public ValueFunMap getFunction(String name){
return this.fuctionsMap.get(name);
}
@@ -104,7 +119,7 @@ public class SymTable {
//retourne le nom de la var déjà déclaré avec son id
public String getVar(String nomVar){
String prefix = "";
ValueTable value = this.varMap.get(nomVar);
ValueVarMap value = this.varMap.get(nomVar);
if(value.isParam){
prefix = "param_";
}
@@ -129,8 +144,8 @@ public class SymTable {
public SymTable addVar(String s, Type t,Boolean isParam){
PMap<String, ValueTable> pmap = this.varMap;
pmap= pmap.plus(s,new ValueTable(t, /*getNewId()*/ id,isParam));
PMap<String, ValueVarMap> pmap = this.varMap;
pmap= pmap.plus(s,new ValueVarMap(t, /*getNewId()*/ id,isParam));
return new SymTable(pmap,this.fuctionsMap,this.id+1,this.idLabel);
}
@@ -141,11 +156,11 @@ public class SymTable {
str.append("Id = " + id+"\n");
str.append("VAR :\n");
for(String s: this.varMap.keySet()){
str.append(s).append(" ").append(varMap.get(s)).append("\n");
str.append(s).append(" id :").append(varMap.get(s).id).append(" type :").append(varMap.get(s).type).append(" isParam :").append(varMap.get(s).isParam).append("\n");
}
str.append("FUNCTION :\n");
for(String f: this.fuctionsMap.keySet()){
str.append(f).append(" ").append(fuctionsMap.get(f)).append("\n");
str.append(f).append("\n");
}
return str.toString();
}