forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcppExpression.h
More file actions
203 lines (180 loc) · 5.3 KB
/
cppExpression.h
File metadata and controls
203 lines (180 loc) · 5.3 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file cppExpression.h
* @author drose
* @date 1999-10-25
*/
#ifndef CPPEXPRESSION_H
#define CPPEXPRESSION_H
#include "dtoolbase.h"
#include "cppDeclaration.h"
class CPPIdentifier;
class CPPType;
class CPPPreprocessor;
class CPPFunctionGroup;
/**
*
*/
class CPPExpression : public CPPDeclaration {
public:
enum Type {
T_nullptr,
T_boolean,
T_integer,
T_real,
T_string,
T_wstring,
T_u8string,
T_u16string,
T_u32string,
T_variable,
T_function,
T_unknown_ident,
T_typecast,
T_static_cast,
T_dynamic_cast,
T_const_cast,
T_reinterpret_cast,
T_construct,
T_default_construct,
T_aggregate_init,
T_empty_aggregate_init,
T_new,
T_default_new,
T_sizeof_type,
T_sizeof_expr,
T_sizeof_ellipsis,
T_alignof,
T_unary_operation,
T_binary_operation,
T_trinary_operation,
T_literal,
T_raw_literal,
T_typeid_type,
T_typeid_expr,
T_type_trait,
T_lambda,
// These are used when parsing =default and =delete methods.
T_default,
T_delete,
};
CPPExpression(bool value);
CPPExpression(unsigned long long value);
CPPExpression(int value);
CPPExpression(const std::string &value);
CPPExpression(long double value);
CPPExpression(CPPIdentifier *ident, CPPScope *current_scope,
CPPScope *global_scope, CPPPreprocessor *error_sink = nullptr);
CPPExpression(int unary_operator, CPPExpression *op1);
CPPExpression(int binary_operator, CPPExpression *op1, CPPExpression *op2);
CPPExpression(int trinary_operator, CPPExpression *op1, CPPExpression *op2, CPPExpression *op3);
static CPPExpression typecast_op(CPPType *type, CPPExpression *op1, Type cast_type = T_typecast);
static CPPExpression construct_op(CPPType *type, CPPExpression *op1);
static CPPExpression aggregate_init_op(CPPType *type, CPPExpression *op1);
static CPPExpression new_op(CPPType *type, CPPExpression *op1 = nullptr);
static CPPExpression typeid_op(CPPType *type, CPPType *std_type_info);
static CPPExpression typeid_op(CPPExpression *op1, CPPType *std_type_info);
static CPPExpression type_trait(int trait, CPPType *type, CPPType *arg = nullptr);
static CPPExpression sizeof_func(CPPType *type);
static CPPExpression sizeof_func(CPPExpression *op1);
static CPPExpression sizeof_ellipsis_func(CPPIdentifier *ident);
static CPPExpression alignof_func(CPPType *type);
static CPPExpression lambda(CPPClosureType *type);
static CPPExpression literal(unsigned long long value, CPPInstance *lit_op);
static CPPExpression literal(long double value, CPPInstance *lit_op);
static CPPExpression literal(CPPExpression *value, CPPInstance *lit_op);
static CPPExpression raw_literal(const std::string &raw, CPPInstance *lit_op);
static const CPPExpression &get_nullptr();
static const CPPExpression &get_default();
static const CPPExpression &get_delete();
enum ResultType {
RT_integer,
RT_real,
RT_pointer,
RT_error
};
class Result {
public:
Result();
Result(int value);
Result(double value);
Result(void *value);
int as_integer() const;
double as_real() const;
void *as_pointer() const;
bool as_boolean() const;
void output(std::ostream &out) const;
ResultType _type;
union {
int _integer;
double _real;
void *_pointer;
} _u;
};
Result evaluate() const;
CPPType *determine_type() const;
bool is_lvalue() const;
bool is_tbd() const;
virtual bool is_fully_specified() const;
virtual CPPDeclaration *substitute_decl(SubstDecl &subst,
CPPScope *current_scope,
CPPScope *global_scope);
virtual void output(std::ostream &out, int indent_level, CPPScope *scope,
bool complete) const;
virtual SubType get_subtype() const;
virtual CPPExpression *as_expression();
Type _type;
std::string _str;
union {
bool _boolean;
unsigned long long _integer;
long double _real;
CPPInstance *_variable;
CPPFunctionGroup *_fgroup;
CPPIdentifier *_ident;
CPPClosureType *_closure_type;
struct {
union {
CPPType *_type;
CPPExpression *_expr;
};
CPPType *_std_type_info;
} _typeid;
struct {
CPPType *_to;
CPPExpression *_op1;
} _typecast;
struct {
// One of the yytoken values: a character, or something like EQCOMPARE.
int _operator;
CPPExpression *_op1;
CPPExpression *_op2;
CPPExpression *_op3;
} _op;
struct {
CPPInstance *_operator;
CPPExpression *_value;
} _literal;
struct {
int _trait;
CPPType *_type;
CPPType *_arg;
} _type_trait;
} _u;
protected:
static CPPType *elevate_type(CPPType *t1, CPPType *t2);
virtual bool is_equal(const CPPDeclaration *other) const;
virtual bool is_less(const CPPDeclaration *other) const;
};
inline std::ostream &
operator << (std::ostream &out, const CPPExpression::Result &result) {
result.output(out);
return out;
}
#endif