32 #ifndef _QORE_VARREFNODE_H 33 #define _QORE_VARREFNODE_H 35 #include "qore/intern/FunctionCallNode.h" 37 class VarRefNewObjectNode;
41 hashdecl ClosureVarValue;
43 class VarRefNode :
public ParseNode {
48 bool explicit_scope : 1;
50 DLLLOCAL ~VarRefNode() {
52 assert(type != VT_IMMEDIATE || !
ref.cvv);
53 assert(type != VT_IMMEDIATE || !
ref.cvv);
57 if (type == VT_IMMEDIATE) {
59 ref.cvv->deref(xsink);
69 DLLLOCAL
void resolve(
const QoreTypeInfo* typeInfo);
70 DLLLOCAL
void parseInitIntern(LocalVar* oflag,
int pflag,
int& lvids,
const QoreTypeInfo* typeInfo,
bool is_new =
false);
71 DLLLOCAL VarRefNewObjectNode* globalMakeNewCall(
QoreValue args);
74 DLLLOCAL
virtual void parseInitImpl(
QoreValue& val, LocalVar *oflag,
int pflag,
int &lvids,
const QoreTypeInfo *&typeInfo);
76 DLLLOCAL
virtual const QoreTypeInfo* parseGetTypeInfo()
const {
77 if (type == VT_LOCAL || type == VT_CLOSURE || type == VT_LOCAL_TS)
78 return ref.id->parseGetTypeInfo();
79 if (type == VT_GLOBAL)
80 return ref.var->parseGetTypeInfo();
84 DLLLOCAL
virtual const QoreTypeInfo* parseGetTypeInfoForInitialAssignment()
const {
85 if (type == VT_LOCAL || type == VT_CLOSURE || type == VT_LOCAL_TS)
86 return ref.id->parseGetTypeInfoForInitialAssignment();
87 if (type == VT_GLOBAL)
88 return ref.var->parseGetTypeInfoForInitialAssignment();
92 DLLLOCAL
void setThreadSafeIntern() {
93 ref.id->setClosureUse();
97 DLLLOCAL
void setClosureIntern() {
98 ref.id->setClosureUse();
102 DLLLOCAL VarRefNode(
const QoreProgramLocation* loc,
char* n, ClosureVarValue* cvv) : ParseNode(loc,
NT_VARREF, true, false), name(n), type(VT_IMMEDIATE), new_decl(false), explicit_scope(false) {
107 DLLLOCAL VarRefNode(
const QoreProgramLocation* loc,
char* n, Var* n_var,
bool n_has_effect =
false,
bool n_new_decl =
true) : ParseNode(loc,
NT_VARREF, true, n_has_effect), name(n), type(VT_GLOBAL), new_decl(n_new_decl), explicit_scope(false) {
115 ClosureVarValue* cvv;
119 DLLLOCAL VarRefNode(
const QoreProgramLocation* loc,
char* n, qore_var_t t,
bool n_has_effect =
false) : ParseNode(loc,
NT_VARREF, true, n_has_effect), name(n), type(t), new_decl(t == VT_LOCAL), explicit_scope(false) {
120 if (type == VT_LOCAL)
122 assert(type != VT_GLOBAL);
125 DLLLOCAL VarRefNode(
const QoreProgramLocation* loc,
char* n, LocalVar* n_id,
bool in_closure) : ParseNode(loc,
NT_VARREF, true, false), name(n), new_decl(false), explicit_scope(false) {
137 DLLLOCAL
bool parseEqualTo(
const VarRefNode& other)
const;
142 DLLLOCAL
virtual const QoreTypeInfo* getTypeInfo()
const {
143 if (type == VT_LOCAL || type == VT_CLOSURE || type == VT_LOCAL_TS)
144 return ref.id->getTypeInfo();
145 if (type == VT_GLOBAL)
146 return ref.var->getTypeInfo();
151 DLLLOCAL
virtual const char* getTypeName()
const;
153 DLLLOCAL
virtual bool stayInTree()
const {
154 return !(type == VT_GLOBAL);
157 DLLLOCAL
virtual bool parseIsDecl()
const {
return type != VT_UNRESOLVED; }
158 DLLLOCAL
virtual bool isDecl()
const {
return false; }
159 DLLLOCAL
bool explicitScope()
const {
return explicit_scope; }
160 DLLLOCAL
void setExplicitScope() { explicit_scope =
true; }
163 DLLLOCAL
virtual const char* parseGetTypeName()
const {
171 DLLLOCAL
bool isGlobalDecl()
const {
return new_decl; }
173 DLLLOCAL
bool isGlobalVar()
const {
return type == VT_GLOBAL; }
176 DLLLOCAL
int getLValue(LValueHelper& lvh,
bool for_remove)
const;
178 DLLLOCAL
bool isRef()
const {
179 if (type == VT_LOCAL)
180 return ref.id->isRef();
181 if (type == VT_IMMEDIATE)
183 assert(type == VT_GLOBAL);
184 return ref.var->isRef();
187 DLLLOCAL
void remove(LValueRemoveHelper& lvrh);
189 DLLLOCAL qore_var_t getType()
const {
return type; }
190 DLLLOCAL
const char* getName()
const {
return name.ostr; }
192 DLLLOCAL
void makeLocal() {
193 assert(type != VT_GLOBAL);
199 DLLLOCAL
virtual void makeGlobal();
202 DLLLOCAL
char* takeName() {
204 return name.takeName();
207 DLLLOCAL
void setThreadSafe() {
208 if (type == VT_LOCAL)
209 setThreadSafeIntern();
212 DLLLOCAL
void setClosure() {
213 if (type == VT_LOCAL || type == VT_LOCAL_TS)
217 DLLLOCAL
void setPublic() {
218 assert(type == VT_GLOBAL);
219 ref.var->setPublic();
222 DLLLOCAL
void parseAssigned() {
223 assert(type != VT_IMMEDIATE);
224 if (type == VT_LOCAL || type == VT_CLOSURE || type == VT_LOCAL_TS)
225 ref.id->parseAssigned();
228 DLLLOCAL
bool scanMembers(RSetHelper& rsh);
231 class GlobalVarRefNode :
public VarRefNode {
234 DLLLOCAL GlobalVarRefNode(
const QoreProgramLocation* loc,
char* n, Var* v) : VarRefNode(loc, n, v, false, false) {
235 explicit_scope =
true;
238 DLLLOCAL GlobalVarRefNode(
const QoreProgramLocation* loc,
char* n,
const QoreTypeInfo* typeInfo = 0);
239 DLLLOCAL GlobalVarRefNode(
const QoreProgramLocation* loc,
char* n, QoreParseTypeInfo* parseTypeInfo);
246 class VarRefDeclNode :
public VarRefNode {
248 QoreParseTypeInfo* parseTypeInfo;
249 const QoreTypeInfo* typeInfo;
251 DLLLOCAL VarRefDeclNode(
const QoreProgramLocation* loc,
char* n, qore_var_t t,
const QoreTypeInfo* n_typeInfo, QoreParseTypeInfo* n_parseTypeInfo,
bool n_has_effect) :
252 VarRefNode(loc, n, t, n_has_effect), parseTypeInfo(n_parseTypeInfo), typeInfo(n_typeInfo) {
256 DLLLOCAL VarRefDeclNode(
const QoreProgramLocation* loc,
char* n, Var* var,
const QoreTypeInfo* n_typeInfo, QoreParseTypeInfo* n_parseTypeInfo) :
257 VarRefNode(loc, n, var, true), parseTypeInfo(n_parseTypeInfo), typeInfo(n_typeInfo) {
261 DLLLOCAL
virtual void parseInitImpl(
QoreValue& val, LocalVar *oflag,
int pflag,
int &lvids,
const QoreTypeInfo *&typeInfo);
263 DLLLOCAL VarRefDeclNode(
const QoreProgramLocation* loc,
char* n, ClosureVarValue* cvv,
const QoreTypeInfo* n_typeInfo) : VarRefNode(loc, n, cvv), parseTypeInfo(0), typeInfo(n_typeInfo) {
267 DLLLOCAL VarRefDeclNode(
const QoreProgramLocation* loc,
char* n, qore_var_t t,
const QoreTypeInfo* n_typeInfo) :
268 VarRefNode(loc, n, t), parseTypeInfo(nullptr), typeInfo(n_typeInfo) {
273 DLLLOCAL VarRefDeclNode(
const QoreProgramLocation* loc,
char* n, qore_var_t t,
char* class_name) :
274 VarRefNode(loc, n, t), parseTypeInfo(new QoreParseTypeInfo(class_name)), typeInfo(0) {
279 DLLLOCAL VarRefDeclNode(
const QoreProgramLocation* loc,
char* n, qore_var_t t, QoreParseTypeInfo* n_parseTypeInfo) :
280 VarRefNode(loc, n, t), parseTypeInfo(n_parseTypeInfo), typeInfo(0) {
285 DLLLOCAL VarRefDeclNode(
const QoreProgramLocation* loc,
char* n, qore_var_t t,
const QoreTypeInfo* n_typeInfo, QoreParseTypeInfo* n_parseTypeInfo) :
286 VarRefNode(loc, n, t), parseTypeInfo(n_parseTypeInfo), typeInfo(n_typeInfo) {
290 DLLLOCAL ~VarRefDeclNode() {
291 delete parseTypeInfo;
293 DLLLOCAL
virtual bool parseIsDecl()
const {
296 DLLLOCAL
virtual bool isDecl()
const {
303 DLLLOCAL QoreParseTypeInfo* takeParseTypeInfo() {
304 QoreParseTypeInfo* ti = parseTypeInfo;
305 parseTypeInfo =
nullptr;
308 DLLLOCAL QoreParseTypeInfo* getParseTypeInfo() {
309 return parseTypeInfo;
311 DLLLOCAL
virtual const QoreTypeInfo* getTypeInfo()
const {
312 assert(!parseTypeInfo);
315 DLLLOCAL
virtual void makeGlobal();
317 DLLLOCAL
void parseInitCommon(LocalVar* oflag,
int pflag,
int& lvids,
bool is_new =
false);
320 class VarRefImmediateNode :
public VarRefDeclNode {
322 DLLLOCAL
void deref() {
331 ref.cvv->deref(xsink);
339 DLLLOCAL VarRefImmediateNode(
const QoreProgramLocation* loc,
char* n, ClosureVarValue* cvv,
const QoreTypeInfo* n_typeInfo) : VarRefDeclNode(loc, n, cvv, n_typeInfo) {
343 DLLLOCAL
virtual ~VarRefImmediateNode() {
350 class VarRefTryModuleErrorNode :
public VarRefDeclNode {
352 DLLLOCAL VarRefTryModuleErrorNode(
const QoreProgramLocation* loc,
char* n) : VarRefDeclNode(loc, n, VT_LOCAL, hashTypeInfo) {
355 DLLLOCAL
virtual ~VarRefTryModuleErrorNode() {
359 class VarRefNewObjectNode :
public VarRefDeclNode,
public FunctionCallBase {
361 DLLLOCAL VarRefNewObjectNode(
const QoreProgramLocation* loc,
char* n,
const QoreTypeInfo* n_typeInfo, QoreParseTypeInfo* n_parseTypeInfo, QoreParseListNode* n_args, qore_var_t t) :
362 VarRefDeclNode(loc, n, t, n_typeInfo, n_parseTypeInfo, true), FunctionCallBase(n_args) {
365 DLLLOCAL VarRefNewObjectNode(
const QoreProgramLocation* loc,
char* n, Var* var, QoreParseListNode* n_args,
const QoreTypeInfo* n_typeInfo, QoreParseTypeInfo* n_parseTypeInfo) :
366 VarRefDeclNode(loc, n, var, n_typeInfo, n_parseTypeInfo), FunctionCallBase(n_args) {
369 DLLLOCAL
virtual ~VarRefNewObjectNode() {
371 new_args.discard(
nullptr);
374 DLLLOCAL
virtual bool stayInTree()
const {
378 DLLLOCAL
const char* parseGetTypeName()
const {
379 return typeInfo ? QoreTypeInfo::getName(typeInfo) : parseTypeInfo->cscope->getIdentifier();
382 DLLLOCAL QoreParseListNode* takeParseArgs() {
383 QoreParseListNode* rv = parse_args;
384 parse_args =
nullptr;
389 enum vrn_type_e :
unsigned char {
395 } vrn_type = VRN_NONE;
397 bool runtime_check =
false;
402 DLLLOCAL
virtual void parseInitImpl(
QoreValue& val, LocalVar *oflag,
int pflag,
int &lvids,
const QoreTypeInfo *&typeInfo);
404 DLLLOCAL
void parseInitConstructorCall(
const QoreProgramLocation* loc, LocalVar* oflag,
int pflag,
int& lvids,
const QoreClass* qc);
406 DLLLOCAL
void parseInitHashDeclInitialization(
const QoreProgramLocation* loc, LocalVar* oflag,
int pflag,
int& lvids,
const TypedHashDecl* hd);
408 DLLLOCAL
void parseInitComplexHashInitialization(
const QoreProgramLocation* loc, LocalVar* oflag,
int pflag,
int& lvids,
const QoreTypeInfo* ti);
410 DLLLOCAL
void parseInitComplexListInitialization(
const QoreProgramLocation* loc, LocalVar* oflag,
int pflag,
int& lvids,
const QoreTypeInfo* ti);
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:54
const qore_type_t NT_VARREF
type value for VarRefNode
Definition: node_types.h:56
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
defines a Qore-language class
Definition: QoreClass.h:239
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:46
typed hash declaration
Definition: TypedHashDecl.h:44
DLLEXPORT void ref() const
increments the reference count