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+ }
0 commit comments