-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathVariable.cpp
More file actions
64 lines (51 loc) · 1.68 KB
/
Copy pathVariable.cpp
File metadata and controls
64 lines (51 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "Variable.h"
#include "FetlangException.h"
void Variable::setGender(Gender gender) { this->gender = gender; }
void Variable::setCode(const std::string& code) { this->code = code; }
void Variable::setName(const std::string& name) {
this->name = name;
/* The code and the C identifier are one in the same, here
It takes this format: fetvar_6_richardstallman
Where the "6" is a unique identifying number,
and "richardstallman" is a stripped version of the original
Fetlang identifier
*/
// Make sure each var is given a unique identifier
static unsigned int unique_id = 0;
unique_id++;
// First parts of C identifier
this->code = "fetvar_" + std::to_string(unique_id) + "_";
// Strip the name and add
for (const char& c : name) {
if (isalnum(c)) {
this->code += c;
}
}
}
void Variable::setType(FetType type) { this->type = type; }
std::string Variable::getName() const { return this->name; }
Gender Variable::getGender() const { return this->gender; }
std::string Variable::getCode() const {
if (getType() == REFERENCE_TYPE) {
return "(*" + this->code + ").value";
} else {
return this->code;
}
}
std::string Variable::getRawCode() const { return this->code; }
FetType Variable::getType() const { return this->type; }
Variable::Variable(const std::string& name, FetType type) {
setName(name);
setGender(UNASSIGNED_GENDER);
setType(type);
needs_constructing = true;
}
BuiltinVariable::BuiltinVariable(const std::string& name, FetType type, const std::string& code,
Gender gender) {
setName(name);
setGender(gender);
setType(type);
setCode(code);
needs_constructing = false;
}
void BuiltinVariable::setName(const std::string& name) { this->name = name; }