Skip to content
Snippets Groups Projects
Commit 68ab49e9 authored by BAUQUIN Niels's avatar BAUQUIN Niels
Browse files

dfg

parent 086b4789
Branches
Tags
No related merge requests found
...@@ -25,40 +25,42 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> { ...@@ -25,40 +25,42 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
@Override @Override
public Void visit(SaDecTab node) throws Exception { public Void visit(SaDecTab node) throws Exception {
String nomTableau = node.getNom(); String idTab = node.getNom();
Type typeTableau = node.getType(); Type typeTab = node.getType();
int tailleTableau = node.getTaille(); int tailleTab = node.getTaille();
System.out.println(node);
if (context == Context.GLOBAL) { if (context == Context.GLOBAL) {
if (tableGlobale.getVar(nomTableau) != null) { if (tableGlobale.getVar(idTab) != null) {
throw new ErrorException(Error.TS, "Le tableau " + nomTableau + " est déjà défini."); 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; return null;
} }
@Override @Override
public Void visit(SaDecFonc node) throws Exception { public Void visit(SaDecFonc node) throws Exception {
String nomFonction = node.getNom(); String idFct = node.getNom();
SaLDecVar parameters = node.getParametres(); SaLDecVar parameters = node.getParametres();
SaLDecVar variable = node.getVariable(); SaLDecVar variable = node.getVariable();
SaInst corps = node.getCorps(); SaInst corps = node.getCorps();
if (tableGlobale.getFct(nomFonction) != null) { if (tableGlobale.getFct(idFct) != null) {
throw new ErrorException(Error.TS, "La fonction " + nomFonction + " est déjà définie."); throw new ErrorException(Error.TS, "La fonction " + idFct + " est déjà définie.");
} }
Ts table = new Ts(); Ts table = new Ts();
tableLocaleCourante = table; tableLocaleCourante = table;
int param = 0; int nbArgs = 0;
if (parameters != null) { if (parameters != null) {
context = Context.PARAM; context = Context.PARAM;
parameters.accept(this); parameters.accept(this);
param = parameters.length(); nbArgs = parameters.length();
} }
if (variable != null) { if (variable != null) {
context = Context.LOCAL; context = Context.LOCAL;
variable.accept(this); 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) { if (corps != null) {
context = Context.LOCAL; context = Context.LOCAL;
corps.accept(this); corps.accept(this);
...@@ -69,70 +71,70 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> { ...@@ -69,70 +71,70 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
@Override @Override
public Void visit(SaDecVar node) throws Exception { public Void visit(SaDecVar node) throws Exception {
String nomVar = node.getNom(); String idVar = node.getNom();
Type typeVar = node.getType(); Type typeVar = node.getType();
if (context == Context.LOCAL) { if (context == Context.LOCAL) {
if (tableLocaleCourante.getVar(nomVar) != null) { if (tableLocaleCourante.getVar(idVar) != null) {
throw new ErrorException(Error.TS, "La variable " + nomVar + " est déjà définie."); 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) { } else if (context == Context.PARAM) {
if (tableLocaleCourante.getVar(nomVar) != null) { if (tableLocaleCourante.getVar(idVar) != null) {
throw new ErrorException(Error.TS, "La variable " + nomVar + " est déjà définie."); 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) { } else if (context == Context.GLOBAL) {
if (tableGlobale.getVar(nomVar) != null) { if (tableGlobale.getVar(idVar) != null) {
throw new ErrorException(Error.TS, "La variable " + nomVar + " est déjà définie."); 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; return null;
} }
@Override @Override
public Void visit(SaVarSimple node) throws Exception { public Void visit(SaVarSimple node) throws Exception {
String nomVar = node.getNom(); String idVar = node.getNom();
TsItemVarSimple varSimple = node.getTsItem(); TsItemVarSimple varSimple = node.getTsItem();
if (context == Context.LOCAL) { if (context == Context.LOCAL) {
if (tableLocaleCourante.getVar(nomVar) == null && tableGlobale.getVar(nomVar) == null) { if (tableLocaleCourante.getVar(idVar) == null && tableGlobale.getVar(idVar) == null) {
throw new ErrorException(Error.TS, "La variable " + nomVar + " n'est pas définie."); throw new ErrorException(Error.TS, "La variable " + idVar + " n'est pas définie.");
} }
if (tableLocaleCourante.getVar(nomVar) != null) { if (tableLocaleCourante.getVar(idVar) != null) {
node.tsItem = (TsItemVarSimple) tableLocaleCourante.getVar(nomVar); node.tsItem = (TsItemVarSimple) tableLocaleCourante.getVar(idVar);
} else { } else {
node.tsItem = (TsItemVarSimple) tableGlobale.getVar(nomVar); node.tsItem = (TsItemVarSimple) tableGlobale.getVar(idVar);
} }
} else if (context == Context.PARAM) { } else if (context == Context.PARAM) {
if (tableLocaleCourante.getVar(nomVar) == null) { if (tableLocaleCourante.getVar(idVar) == null) {
throw new ErrorException(Error.TS, "La variable " + nomVar + " n'est pas définie."); throw new ErrorException(Error.TS, "La variable " + idVar + " n'est pas définie.");
} }
} else if (context == Context.GLOBAL) { } else if (context == Context.GLOBAL) {
if (tableGlobale.getVar(nomVar) == null || varSimple.getTaille() > 1) { if (tableGlobale.getVar(idVar) == null || varSimple.getTaille() > 1) {
throw new ErrorException(Error.TS, "La variable " + nomVar + " n'est pas définie."); 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; return null;
} }
@Override @Override
public Void visit(SaAppel node) throws Exception { public Void visit(SaAppel node) throws Exception {
String nomFonction = node.getNom(); String idFct = node.getNom();
SaLExp arguments = node.getArguments(); SaLExp arguments = node.getArguments();
int args = 0; int nbArgs = 0;
if (arguments != null) { if (arguments != null) {
arguments.accept(this); arguments.accept(this);
args = arguments.length(); nbArgs = arguments.length();
} }
if (tableGlobale.getFct(nomFonction) == null) { if (tableGlobale.getFct(idFct) == null) {
throw new ErrorException(Error.TS, "La fonction " + nomFonction + " n'est pas définie."); 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." 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()); node.tsItem = tableGlobale.getFct(node.getNom());
...@@ -141,10 +143,10 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> { ...@@ -141,10 +143,10 @@ public class Sa2ts extends SaDepthFirstVisitor <Void> {
@Override @Override
public Void visit(SaVarIndicee node) throws Exception { public Void visit(SaVarIndicee node) throws Exception {
String nomVar = node.getNom(); String idVar = node.getNom();
SaExp indice = node.getIndice(); SaExp indice = node.getIndice();
if (tableGlobale.getVar(nomVar) == null && tableGlobale.getVar(nomVar).getTaille() == 1) if (tableGlobale.getVar(idVar) == null && tableGlobale.getVar(idVar).getTaille() == 1)
throw new ErrorException(Error.TS, "indice " + nomVar + " incorrect."); throw new ErrorException(Error.TS, "indice " + idVar + " incorrect.");
node.tsItem = tableGlobale.getVar(node.getNom()); node.tsItem = tableGlobale.getVar(node.getNom());
indice.accept(this); indice.accept(this);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment