Skip to content

Commit 193e090

Browse files
committed
Added "Data" to get last information(s) in the code + to update.
1 parent 32861e4 commit 193e090

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

src/Essentials/Utils/Data.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#include "Data.h"
2+
3+
#include <utility>
4+
5+
namespace FPL::Data {
6+
Data::Data(std::vector<FPL::Tokenizer::Token>& Tokens) {
7+
AllFPLTypes["entier"] = FPL::Types::Types("entier", Types::BUILTIN_TYPE::INT);
8+
AllFPLTypes["decimal"] = FPL::Types::Types("decimal", Types::BUILTIN_TYPE::DOUBLE);
9+
AllFPLTypes["texte"] = FPL::Types::Types("texte", Types::BUILTIN_TYPE::STRING);
10+
AllFPLTypes["auto"] = FPL::Types::Types("auto", Types::BUILTIN_TYPE::AUTO);
11+
AllFPLTypes["bool"] = FPL::Types::Types("bool", Types::BUILTIN_TYPE::BOOL); // Deux façons d'avoir le type bool.
12+
AllFPLTypes["boolean"] = FPL::Types::Types("boolean", Types::BUILTIN_TYPE::BOOL);
13+
14+
current_token = Tokens.begin();
15+
end_token = Tokens.end();
16+
17+
InstructionsList = {
18+
// Instructions:
19+
"envoyer",
20+
"variable",
21+
"saisir",
22+
// Types:
23+
"entier",
24+
"decimal",
25+
"texte",
26+
"auto",
27+
"bool",
28+
"boolean",
29+
};
30+
}
31+
32+
void Data::addVariableToMap(std::string& name, std::string& value, FPL::Types::Types& type, bool del, bool globale) {
33+
VariableDef newVariable;
34+
newVariable.VariableName = name;
35+
newVariable.VariableValue = value;
36+
newVariable.VariableType = type;
37+
newVariable.NeedDelete = del;
38+
newVariable.IsGlobal = globale;
39+
Map_Variables[newVariable.VariableName] = newVariable;
40+
}
41+
42+
bool Data::isVariable(std::string& name) const {
43+
if (Map_Variables.contains(name)) { return true; }
44+
return false;
45+
}
46+
47+
std::optional<FPL::VariableDef> Data::getVariable(std::string& name) {
48+
if (isVariable(name)) {
49+
VariableDef var = Map_Variables[name];
50+
return var;
51+
}
52+
return std::nullopt;
53+
}
54+
55+
std::vector<Token>::iterator Data::incrementeAndGetToken(FPL::Data::Data& data) {
56+
data.current_token++;
57+
return data.current_token;
58+
}
59+
60+
void Data::decrementeTokens(Data &data) {
61+
data.current_token--;
62+
}
63+
64+
void Data::incrementeTokens(FPL::Data::Data &data) {
65+
data.current_token++;
66+
}
67+
68+
void Data::updateValue(std::string &name, std::basic_string<char> value) {
69+
if (isVariable(name)) {
70+
Map_Variables[name].VariableValue = std::move(value);
71+
}
72+
}
73+
74+
void Data::updateType(std::string& name, std::string& TypeName, Types::BUILTIN_TYPE Type) {
75+
if (isVariable(name)) {
76+
Map_Variables[name].VariableType.Name = TypeName;
77+
Map_Variables[name].VariableType.Type = Type;
78+
}
79+
}
80+
81+
std::optional<FPL::FonctionDef> Data::getFonction(std::string& name) {
82+
return this->Map_Fonctions[name];
83+
}
84+
}

src/Essentials/Utils/Data.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#pragma once
2+
3+
#include <vector>
4+
#include <iostream>
5+
#include <map>
6+
#include <optional>
7+
8+
#include "../Types.h"
9+
#include "../Tokenizer.h"
10+
#include "../Definitions/Variables.h"
11+
#include "../Definitions/Fonction.h"
12+
13+
namespace FPL::Data {
14+
using namespace FPL::Tokenizer;
15+
16+
class Data {
17+
public:
18+
explicit Data(std::vector<FPL::Tokenizer::Token>& Tokens);
19+
20+
std::vector<Token>::iterator current_token; // Le token que le Parser analyze
21+
std::vector<Token>::iterator end_token; // Le dernier token sauvegardé
22+
23+
std::vector<Token>::iterator incrementeAndGetToken(FPL::Data::Data& data);
24+
void decrementeTokens(FPL::Data::Data& data);
25+
void incrementeTokens(FPL::Data::Data& data);
26+
27+
std::map<std::string, FPL::Types::Types> AllFPLTypes;
28+
std::vector<std::string> InstructionsList;
29+
std::map<std::string, FPL::VariableDef> Map_Variables;
30+
std::map<std::string, FPL::FonctionDef> Map_Fonctions;
31+
32+
void addVariableToMap(std::string& name, std::string& value, FPL::Types::Types& type, bool del, bool globale);
33+
bool isVariable(std::string& name) const;
34+
std::optional<FPL::VariableDef> getVariable(std::string& name);
35+
void updateValue(std::string &name, std::basic_string<char> value);
36+
void updateType(std::string& name, std::string& TypeName, Types::BUILTIN_TYPE Type);
37+
38+
std::optional<FPL::FonctionDef> getFonction(std::string& name);
39+
bool HasReturnValue = false;
40+
std::string ReturnValue = "N/A";
41+
Types::Types ReturnType;
42+
};
43+
}

0 commit comments

Comments
 (0)