-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.cpp
More file actions
67 lines (58 loc) · 1.46 KB
/
types.cpp
File metadata and controls
67 lines (58 loc) · 1.46 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
65
#include "types.h"
TypeNms::Type TypeNms::strToType(const std::string& str) {
// :)
return std::unordered_map<std::string, Type> {
{"int", INT},
{"float", FLOAT},
{"char", CHAR},
{"string", STRING},
{"bool", BOOL},
}.at(str);
}
std::string TypeNms::typeToStr(const Type type) {
switch (type) {
case INT:
return "Int";
break;
case FLOAT:
return "Float";
break;
case CHAR:
return "Char";
break;
case STRING:
return "String";
break;
case BOOL:
return "Bool";
break;
case CUSTOM:
return "Class";
break;
}
throw "Invalid argument";
}
bool Operation::booleanOperator(const BinaryOp op) {
using enum BinaryOp;
return std::unordered_set<BinaryOp>{
ORB, ANDB, EQ, NEQ
}.contains(op);
}
bool Operation::booleanOperator(const UnaryOp op) {
using enum UnaryOp;
return std::unordered_set<UnaryOp>{
NEGB
}.contains(op);
}
bool Operation::conversionOperator(const BinaryOp op) {
using enum BinaryOp;
return std::unordered_set<BinaryOp>{
LT, LEQ, GT, GEQ, EQ, NEQ
}.contains(op);
}
bool Operation::expressionOperator(const BinaryOp op) {
return !booleanOperator(op) && !conversionOperator(op);
}
bool Operation::expressionOperator(const UnaryOp op) {
return !booleanOperator(op);
}