Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion compiler/ast/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@

string ExprVar::linearize(CFG * cfg)
{
return varName;
if(cfg->get_current_level() == cfg->get_level(varName)){
return varName;
}
else
{
// TODO:: Gérer les erreurs
/*
Error *error = new Error();
ErrorManager::addError(error);
*/
return NULL;
}
}

string ExprConst::linearize(CFG * cfg)
Expand Down
21 changes: 21 additions & 0 deletions compiler/intermediateRepresentation/CFG.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

#include "IR.h"
Expand All @@ -15,6 +18,24 @@ CFG::~CFG() {
}
}

string CFG::get_current_level()
{
return symbolTable->current_function;
}

string CFG::get_level(string varName)
{
//Extract the number after the last "_" in the variable name (ex : a_1, or get_var_2).
string level;
string token = strtok(varName,"_");
while(token!= NULL)
{
level = token;
token = strtok(NULL, "-");
}
return level;
}

void CFG::add_bb(BasicBlock *bb)
{
current_bb = bb;
Expand Down
2 changes: 2 additions & 0 deletions compiler/intermediateRepresentation/IR.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class CFG
void add_to_symbol_table(string name, TypeSymbol t, StateSymbol stateSymbol);
string create_new_tempvar(TypeSymbol t);
int get_var_index(string name);
string get_current_level();
string get_level(string varName);
TypeSymbol get_var_type(string name);
void assignSymbol(string name);
bool isAssigneSymbol(string name);
Expand Down