forked from pclewis/lslint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.hh
71 lines (65 loc) · 2.31 KB
/
types.hh
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
#ifndef _TYPES_HH
#define _TYPES_HH 1
#include "ast.hh" // LLASTNode
#include <vector>
#define TYPE(t) LLScriptType::get(t) // convenience
enum LST_TYPE {
LST_ERROR = -1, // special value so processing can continue without throwing bogus errors
LST_NULL = 0,
LST_INTEGER = 1,
LST_FLOATINGPOINT = 2,
LST_STRING = 3,
LST_KEY = 4,
LST_VECTOR = 5,
LST_QUATERNION = 6,
LST_LIST = 7, // ??
LST_LAST
};
class LLScriptType : public LLASTNode {
public:
LLScriptType(LST_TYPE type) : LLASTNode(0), itype(type) {};
static LLScriptType *get( LST_TYPE type ) {
std::vector<LLScriptType*>::iterator i;
LLScriptType *t;
for ( i = types.begin(); i != types.end(); ++i ) {
if ( (*i)->get_itype() == type ) return *i;
}
t = new LLScriptType(type);
types.push_back( t );
return t;
}
bool can_coerce( LLScriptType *to );
LLScriptType *get_result_type(int op, LLScriptType *right);
LST_TYPE get_itype() { return itype; } ;
virtual const char *get_node_name() {
switch (itype) {
case LST_ERROR: return "error";
case LST_INTEGER: return "integer";
case LST_FLOATINGPOINT: return "float";
case LST_STRING: return "string";
case LST_KEY: return "key";
case LST_VECTOR: return "vector";
case LST_QUATERNION: return "quaternion";
case LST_LIST: return "list";
case LST_NULL: return "none";
default: return "!invalid!";
}
}
virtual const char *get_cil_type() {
switch (itype) {
case LST_ERROR: throw "trying to gen code for error type!";
case LST_INTEGER: return "int32";
case LST_FLOATINGPOINT: return "float32";
case LST_STRING: return "string";
case LST_KEY: return "string";
case LST_VECTOR: return "class [lsl]Vector";
case LST_QUATERNION: return "class [lsl]Quaternion";
case LST_LIST: return "class [lsl]List";
default: throw "request for type of non-storage type";
}
};
private:
LST_TYPE itype;
static std::vector<LLScriptType *> types;
};
#endif /* not _TYPES_HH */