-
Notifications
You must be signed in to change notification settings - Fork 1
/
TypeDescriptor.hpp
88 lines (72 loc) · 2.27 KB
/
TypeDescriptor.hpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Created by Tyler Gearing 3/14/19
*
*/
#ifndef EXPRINTER_TYPEDESCRIPTOR_HPP
#define EXPRINTER_TYPEDESCRIPTOR_HPP
#include "Token.hpp"
#include <vector>
class TypeDescriptor {
public:
enum types { INTEGER, DOUBLE, BOOLEAN, STRING, NULLARRAY, STRINGARRAY,
NUMBERARRAY };
explicit TypeDescriptor(types type);
virtual ~TypeDescriptor() = default;
types &type();
private:
types _type;
};
class NumberDescriptor : public TypeDescriptor {
public:
explicit NumberDescriptor(types descType);
union {
int intValue;
double doubleValue;
bool boolValue;
} value;
};
class StringDescriptor : public TypeDescriptor {
public:
explicit StringDescriptor(types descType);
std::string value;
};
class StringArray : public TypeDescriptor {
public:
explicit StringArray(types descType);
int sArraySize() { return stringArray.size(); }
void sPopIndex(TypeDescriptor* desc);
void sPop() { stringArray.pop_back(); }
void sAppend(std::string element) { stringArray.push_back(element); }
//returns indexed value of vector
std::string sSub(int n);
//sets indexed value of vector
void setSubStr(int n, std::string s) { stringArray[n] = s; }
std::vector<std::string> stringArray;
};
class NumberArray : public TypeDescriptor {
public:
explicit NumberArray(types descType);
int nArraySize() { return numberArray.size(); }
void nPopIndex(TypeDescriptor *desc);
void nPop() { numberArray.pop_back(); }
void nAppend(int element) { numberArray.push_back(element); }
//returns indexed value of vector
int nSub(int n);
//sets indexed value of vector
void setSubNum(int n, int s) { numberArray[n] = s;}
std::vector<int> numberArray;
};
void printValue (TypeDescriptor *desc);
bool evaluateBool(TypeDescriptor *desc);
void changeSign(TypeDescriptor *desc);
std::shared_ptr<TypeDescriptor> negate(TypeDescriptor *desc);
std::shared_ptr<TypeDescriptor> stringOperations(StringDescriptor *lValue,
StringDescriptor *rValue,
Token const &tok);
std::shared_ptr<TypeDescriptor> relOperations(NumberDescriptor *lDesc,
NumberDescriptor *rDesc,
Token const &tok);
std::shared_ptr<TypeDescriptor> arithOperations(NumberDescriptor *lDesc,
NumberDescriptor *rDesc,
Token const &tok);
#endif //EXPRINTER_TYPEDESCRIPTOR_HPP