diff --git a/src/ts/Sa2ts.java b/src/ts/Sa2ts.java index 3838506778de3f84e420f4b308981246c8ea2d1e..f2c3b196fec1139e1d42ef9ee9c0c28bd45c13fc 100644 --- a/src/ts/Sa2ts.java +++ b/src/ts/Sa2ts.java @@ -25,40 +25,42 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> { @Override public Void visit(SaDecTab node) throws Exception { - String nomTableau = node.getNom(); - Type typeTableau = node.getType(); - int tailleTableau = node.getTaille(); + String idTab = node.getNom(); + Type typeTab = node.getType(); + int tailleTab = node.getTaille(); + System.out.println(node); if (context == Context.GLOBAL) { - if (tableGlobale.getVar(nomTableau) != null) { - throw new ErrorException(Error.TS, "Le tableau " + nomTableau + " est déjà défini."); + if (tableGlobale.getVar(idTab) != null) { + throw new ErrorException(Error.TS, "Le tableau " + idTab + " est déjà défini."); } - tableGlobale.addTab(nomTableau, typeTableau, tailleTableau); + node.tsItem = tableGlobale.addTab(idTab, typeTab, tailleTab); } + return null; } @Override public Void visit(SaDecFonc node) throws Exception { - String nomFonction = node.getNom(); + String idFct = node.getNom(); SaLDecVar parameters = node.getParametres(); SaLDecVar variable = node.getVariable(); SaInst corps = node.getCorps(); - if (tableGlobale.getFct(nomFonction) != null) { - throw new ErrorException(Error.TS, "La fonction " + nomFonction + " est déjà définie."); + if (tableGlobale.getFct(idFct) != null) { + throw new ErrorException(Error.TS, "La fonction " + idFct + " est déjà définie."); } Ts table = new Ts(); tableLocaleCourante = table; - int param = 0; + int nbArgs = 0; if (parameters != null) { context = Context.PARAM; parameters.accept(this); - param = parameters.length(); + nbArgs = parameters.length(); } if (variable != null) { context = Context.LOCAL; variable.accept(this); } - node.tsItem = tableGlobale.addFct(nomFonction, node.getTypeRetour(), param, table, node); + node.tsItem = tableGlobale.addFct(idFct, node.getTypeRetour(), nbArgs, table, node); if (corps != null) { context = Context.LOCAL; corps.accept(this); @@ -69,70 +71,70 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> { @Override public Void visit(SaDecVar node) throws Exception { - String nomVar = node.getNom(); + String idVar = node.getNom(); Type typeVar = node.getType(); if (context == Context.LOCAL) { - if (tableLocaleCourante.getVar(nomVar) != null) { - throw new ErrorException(Error.TS, "La variable " + nomVar + " est déjà définie."); + if (tableLocaleCourante.getVar(idVar) != null) { + throw new ErrorException(Error.TS, "La variable " + idVar + " est déjà définie dans la fonction."); } - node.setTsItem(tableLocaleCourante.addVar(nomVar, typeVar)); + node.setTsItem(tableLocaleCourante.addVar(idVar, typeVar)); } else if (context == Context.PARAM) { - if (tableLocaleCourante.getVar(nomVar) != null) { - throw new ErrorException(Error.TS, "La variable " + nomVar + " est déjà définie."); + if (tableLocaleCourante.getVar(idVar) != null) { + throw new ErrorException(Error.TS, "La variable " + idVar + " est déjà définie dans les parametres."); } - node.setTsItem(tableLocaleCourante.addParam(nomVar, typeVar)); + node.setTsItem(tableLocaleCourante.addParam(idVar, typeVar)); } else if (context == Context.GLOBAL) { - if (tableGlobale.getVar(nomVar) != null) { - throw new ErrorException(Error.TS, "La variable " + nomVar + " est déjà définie."); + if (tableGlobale.getVar(idVar) != null) { + throw new ErrorException(Error.TS, "La variable " + idVar + " est déjà définie dans la table globale."); } - node.setTsItem(tableGlobale.addVar(nomVar, typeVar)); + node.setTsItem(tableGlobale.addVar(idVar, typeVar)); } return null; } @Override public Void visit(SaVarSimple node) throws Exception { - String nomVar = node.getNom(); + String idVar = node.getNom(); TsItemVarSimple varSimple = node.getTsItem(); if (context == Context.LOCAL) { - if (tableLocaleCourante.getVar(nomVar) == null && tableGlobale.getVar(nomVar) == null) { - throw new ErrorException(Error.TS, "La variable " + nomVar + " n'est pas définie."); + if (tableLocaleCourante.getVar(idVar) == null && tableGlobale.getVar(idVar) == null) { + throw new ErrorException(Error.TS, "La variable " + idVar + " n'est pas définie."); } - if (tableLocaleCourante.getVar(nomVar) != null) { - node.tsItem = (TsItemVarSimple) tableLocaleCourante.getVar(nomVar); + if (tableLocaleCourante.getVar(idVar) != null) { + node.tsItem = (TsItemVarSimple) tableLocaleCourante.getVar(idVar); } else { - node.tsItem = (TsItemVarSimple) tableGlobale.getVar(nomVar); + node.tsItem = (TsItemVarSimple) tableGlobale.getVar(idVar); } } else if (context == Context.PARAM) { - if (tableLocaleCourante.getVar(nomVar) == null) { - throw new ErrorException(Error.TS, "La variable " + nomVar + " n'est pas définie."); + if (tableLocaleCourante.getVar(idVar) == null) { + throw new ErrorException(Error.TS, "La variable " + idVar + " n'est pas définie."); } } else if (context == Context.GLOBAL) { - if (tableGlobale.getVar(nomVar) == null || varSimple.getTaille() > 1) { - throw new ErrorException(Error.TS, "La variable " + nomVar + " n'est pas définie."); + if (tableGlobale.getVar(idVar) == null || varSimple.getTaille() > 1) { + throw new ErrorException(Error.TS, "La variable " + idVar + " n'est pas définie."); } - node.tsItem = (TsItemVarSimple) tableGlobale.getVar(nomVar); + node.tsItem = (TsItemVarSimple) tableGlobale.getVar(idVar); } return null; } @Override public Void visit(SaAppel node) throws Exception { - String nomFonction = node.getNom(); + String idFct = node.getNom(); SaLExp arguments = node.getArguments(); - int args = 0; + int nbArgs = 0; if (arguments != null) { arguments.accept(this); - args = arguments.length(); + nbArgs = arguments.length(); } - if (tableGlobale.getFct(nomFonction) == null) { - throw new ErrorException(Error.TS, "La fonction " + nomFonction + " n'est pas définie."); + if (tableGlobale.getFct(idFct) == null) { + throw new ErrorException(Error.TS, "La fonction " + idFct + " n'est pas définie."); } - if (this.tableGlobale.getFct(nomFonction).getNbArgs() != args) { + if (this.tableGlobale.getFct(idFct).getNbArgs() != nbArgs) { throw new ErrorException(Error.TS, "Le nombre d'arguments est incorrect." - + this.tableGlobale.getFct(nomFonction).getNbArgs() + " requis."); + + this.tableGlobale.getFct(idFct).getNbArgs() + " requis."); } node.tsItem = tableGlobale.getFct(node.getNom()); @@ -141,10 +143,10 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> { @Override public Void visit(SaVarIndicee node) throws Exception { - String nomVar = node.getNom(); + String idVar = node.getNom(); SaExp indice = node.getIndice(); - if (tableGlobale.getVar(nomVar) == null && tableGlobale.getVar(nomVar).getTaille() == 1) - throw new ErrorException(Error.TS, "indice " + nomVar + " incorrect."); + if (tableGlobale.getVar(idVar) == null && tableGlobale.getVar(idVar).getTaille() == 1) + throw new ErrorException(Error.TS, "indice " + idVar + " incorrect."); node.tsItem = tableGlobale.getVar(node.getNom()); indice.accept(this);