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 {
52 DLLLOCAL VarRefNode(
const QoreProgramLocation* loc,
char* n, qore_var_t t,
bool n_has_effect =
false)
53 : ParseNode(loc,
NT_VARREF, true, n_has_effect), name(n), type(t), new_decl(t == VT_LOCAL),
54 explicit_scope(false) {
57 assert(type != VT_GLOBAL);
60 DLLLOCAL VarRefNode(
const QoreProgramLocation* loc,
char* n, LocalVar* n_id,
bool in_closure)
61 : ParseNode(loc,
NT_VARREF, true, false), name(n), new_decl(false), explicit_scope(false) {
73 DLLLOCAL
bool parseEqualTo(
const VarRefNode& other)
const;
78 DLLLOCAL
virtual const QoreTypeInfo* getTypeInfo()
const {
79 if (type == VT_LOCAL || type == VT_CLOSURE || type == VT_LOCAL_TS)
80 return ref.id->getTypeInfo();
81 if (type == VT_GLOBAL || type == VT_THREAD_LOCAL)
82 return ref.var->getTypeInfo();
87 DLLLOCAL
virtual const char* getTypeName()
const;
89 DLLLOCAL
virtual bool stayInTree()
const {
90 return !(type == VT_GLOBAL);
93 DLLLOCAL
virtual bool parseIsDecl()
const {
return type != VT_UNRESOLVED; }
94 DLLLOCAL
virtual bool isDecl()
const {
return false; }
95 DLLLOCAL
bool explicitScope()
const {
return explicit_scope; }
96 DLLLOCAL
void setExplicitScope() { explicit_scope =
true; }
99 DLLLOCAL
virtual const char* parseGetTypeName()
const {
107 DLLLOCAL
bool isGlobalDecl()
const {
return new_decl; }
109 DLLLOCAL
bool isGlobalVar()
const {
return type == VT_GLOBAL; }
112 DLLLOCAL
int getLValue(LValueHelper& lvh,
bool for_remove)
const;
114 DLLLOCAL
bool isRef()
const {
115 if (type == VT_LOCAL)
116 return ref.id->isRef();
117 if (type == VT_IMMEDIATE)
119 assert(type == VT_GLOBAL);
120 return ref.var->isRef();
123 DLLLOCAL
void remove(LValueRemoveHelper& lvrh);
125 DLLLOCAL qore_var_t getType()
const {
return type; }
126 DLLLOCAL
const char* getName()
const {
return name.ostr; }
128 DLLLOCAL
void makeLocal() {
129 assert(type != VT_GLOBAL);
135 DLLLOCAL
virtual void makeGlobal(qore_var_t type);
138 DLLLOCAL
char* takeName() {
140 return name.takeName();
143 DLLLOCAL
void setThreadSafe() {
144 if (type == VT_LOCAL)
145 setThreadSafeIntern();
148 DLLLOCAL
void setClosure() {
149 if (type == VT_LOCAL || type == VT_LOCAL_TS)
153 DLLLOCAL
void setPublic() {
154 assert(type == VT_GLOBAL);
155 ref.var->setPublic();
158 DLLLOCAL
void parseAssigned() {
159 assert(type != VT_IMMEDIATE);
160 if (type == VT_LOCAL || type == VT_CLOSURE || type == VT_LOCAL_TS)
161 ref.id->parseAssigned();
164 DLLLOCAL
bool scanMembers(RSetHelper& rsh);
170 bool explicit_scope : 1;
172 DLLLOCAL ~VarRefNode() {
174 assert(type != VT_IMMEDIATE || !
ref.cvv);
175 assert(type != VT_IMMEDIATE || !
ref.cvv);
179 if (type == VT_IMMEDIATE) {
181 ref.cvv->deref(xsink);
191 DLLLOCAL
void resolve(
const QoreTypeInfo* typeInfo);
192 DLLLOCAL
int parseInitIntern(QoreParseContext& parse_context,
bool is_new =
false);
193 DLLLOCAL VarRefNewObjectNode* globalMakeNewCall(
QoreValue args);
196 DLLLOCAL
virtual int parseInitImpl(
QoreValue& val, QoreParseContext& parse_context);
198 DLLLOCAL
virtual const QoreTypeInfo* parseGetTypeInfo()
const {
199 if (type == VT_LOCAL || type == VT_CLOSURE || type == VT_LOCAL_TS)
200 return ref.id->parseGetTypeInfo();
201 if (type == VT_GLOBAL || type == VT_THREAD_LOCAL)
202 return ref.var->parseGetTypeInfo();
206 DLLLOCAL
virtual const QoreTypeInfo* parseGetTypeInfoForInitialAssignment()
const {
207 const QoreTypeInfo* rv;
208 if (type == VT_LOCAL || type == VT_CLOSURE || type == VT_LOCAL_TS) {
209 rv =
ref.id->parseGetTypeInfoForInitialAssignment();
210 }
else if (type == VT_GLOBAL || type == VT_THREAD_LOCAL) {
211 rv =
ref.var->parseGetTypeInfoForInitialAssignment();
215 if (rv && QoreTypeInfo::isReference(rv)) {
216 return QoreTypeInfo::getHardReference(rv);
221 DLLLOCAL
void setThreadSafeIntern() {
222 ref.id->setClosureUse();
226 DLLLOCAL
void setClosureIntern() {
227 ref.id->setClosureUse();
231 DLLLOCAL VarRefNode(
const QoreProgramLocation* loc,
char* n, ClosureVarValue* cvv)
232 : ParseNode(loc,
NT_VARREF, true, false), name(n), type(VT_IMMEDIATE), new_decl(false),
233 explicit_scope(false) {
238 DLLLOCAL VarRefNode(
const QoreProgramLocation* loc,
char* n, Var* n_var,
bool n_has_effect =
false,
239 bool n_new_decl =
true, qore_var_t type = VT_GLOBAL) : ParseNode(loc,
NT_VARREF, true, n_has_effect),
241 new_decl(n_new_decl), explicit_scope(false) {
246 class GlobalVarRefNode :
public VarRefNode {
249 DLLLOCAL GlobalVarRefNode(
const QoreProgramLocation* loc,
char* n, Var* v)
250 : VarRefNode(loc, n, v, false, false, v && v->isThreadLocal() ? VT_THREAD_LOCAL : VT_GLOBAL) {
251 explicit_scope =
true;
254 DLLLOCAL GlobalVarRefNode(
const QoreProgramLocation* loc,
char* n,
const QoreTypeInfo* typeInfo =
nullptr,
255 qore_var_t type = VT_GLOBAL);
256 DLLLOCAL GlobalVarRefNode(
const QoreProgramLocation* loc,
char* n, QoreParseTypeInfo* parseTypeInfo,
257 qore_var_t type = VT_GLOBAL);
264 class VarRefDeclNode :
public VarRefNode {
266 DLLLOCAL VarRefDeclNode(
const QoreProgramLocation* loc,
char* n, qore_var_t t,
const QoreTypeInfo* n_typeInfo) :
267 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) {
280 DLLLOCAL VarRefDeclNode(
const QoreProgramLocation* loc,
char* n, qore_var_t t, QoreParseTypeInfo* n_parseTypeInfo) :
281 VarRefNode(loc, n, t), parseTypeInfo(n_parseTypeInfo), typeInfo(0) {
287 DLLLOCAL VarRefDeclNode(
const QoreProgramLocation* loc,
char* n, qore_var_t t,
const QoreTypeInfo* n_typeInfo,
288 QoreParseTypeInfo* n_parseTypeInfo) :
289 VarRefNode(loc, n, t), parseTypeInfo(n_parseTypeInfo), typeInfo(n_typeInfo) {
294 DLLLOCAL ~VarRefDeclNode() {
295 delete parseTypeInfo;
297 DLLLOCAL
virtual bool parseIsDecl()
const {
300 DLLLOCAL
virtual bool isDecl()
const {
307 DLLLOCAL QoreParseTypeInfo* takeParseTypeInfo() {
308 QoreParseTypeInfo* ti = parseTypeInfo;
309 parseTypeInfo =
nullptr;
312 DLLLOCAL QoreParseTypeInfo* getParseTypeInfo() {
313 return parseTypeInfo;
315 DLLLOCAL
virtual const QoreTypeInfo* getTypeInfo()
const {
316 assert(!parseTypeInfo);
319 DLLLOCAL
virtual void makeGlobal(qore_var_t type);
321 DLLLOCAL
int parseInitCommon(QoreParseContext& parse_context,
bool is_new =
false);
324 QoreParseTypeInfo* parseTypeInfo;
325 const QoreTypeInfo* typeInfo;
327 DLLLOCAL VarRefDeclNode(
const QoreProgramLocation* loc,
char* n, qore_var_t t,
const QoreTypeInfo* n_typeInfo,
328 QoreParseTypeInfo* n_parseTypeInfo,
bool n_has_effect) :
329 VarRefNode(loc, n, t, n_has_effect), parseTypeInfo(n_parseTypeInfo), typeInfo(n_typeInfo) {
334 DLLLOCAL VarRefDeclNode(
const QoreProgramLocation* loc,
char* n, Var* var,
const QoreTypeInfo* n_typeInfo,
335 QoreParseTypeInfo* n_parseTypeInfo) :
336 VarRefNode(loc, n, var, true), parseTypeInfo(n_parseTypeInfo), typeInfo(n_typeInfo) {
340 DLLLOCAL
virtual int parseInitImpl(
QoreValue& val, QoreParseContext& parse_context);
342 DLLLOCAL VarRefDeclNode(
const QoreProgramLocation* loc,
char* n, ClosureVarValue* cvv,
343 const QoreTypeInfo* n_typeInfo) : VarRefNode(loc, n, cvv), parseTypeInfo(0), typeInfo(n_typeInfo) {
347 class VarRefImmediateNode :
public VarRefDeclNode {
349 DLLLOCAL VarRefImmediateNode(
const QoreProgramLocation* loc,
char* n, ClosureVarValue* cvv,
350 const QoreTypeInfo* n_typeInfo) : VarRefDeclNode(loc, n, cvv, n_typeInfo) {
354 DLLLOCAL
virtual ~VarRefImmediateNode() {
362 ref.cvv->deref(xsink);
370 DLLLOCAL
void deref() {
384 : VarRefDeclNode(loc, n, VT_LOCAL, hashTypeInfo) {
391 class VarRefNewObjectNode :
public VarRefDeclNode,
public FunctionCallBase {
393 DLLLOCAL VarRefNewObjectNode(
const QoreProgramLocation* loc,
char* n,
const QoreTypeInfo* n_typeInfo,
394 QoreParseTypeInfo* n_parseTypeInfo, QoreParseListNode* n_args, qore_var_t t) :
395 VarRefDeclNode(loc, n, t, n_typeInfo, n_parseTypeInfo, true), FunctionCallBase(n_args) {
398 DLLLOCAL VarRefNewObjectNode(
const QoreProgramLocation* loc,
char* n, Var* var, QoreParseListNode* n_args,
399 const QoreTypeInfo* n_typeInfo, QoreParseTypeInfo* n_parseTypeInfo) :
400 VarRefDeclNode(loc, n, var, n_typeInfo, n_parseTypeInfo), FunctionCallBase(n_args) {
403 DLLLOCAL
virtual ~VarRefNewObjectNode() {
405 new_args.discard(
nullptr);
408 DLLLOCAL
virtual bool stayInTree()
const {
412 DLLLOCAL
const char* parseGetTypeName()
const {
413 return typeInfo ? QoreTypeInfo::getName(typeInfo) : parseTypeInfo->cscope->getIdentifier();
416 DLLLOCAL QoreParseListNode* takeParseArgs() {
417 QoreParseListNode* rv = parse_args;
418 parse_args =
nullptr;
423 enum vrn_type_e :
unsigned char {
429 } vrn_type = VRN_NONE;
431 bool runtime_check =
false;
436 DLLLOCAL
virtual int parseInitImpl(
QoreValue& val, QoreParseContext& parse_context);
438 DLLLOCAL
int parseInitConstructorCall(
const QoreProgramLocation* loc, QoreParseContext& parse_context,
441 DLLLOCAL
int parseInitHashDeclInitialization(
const QoreProgramLocation* loc, QoreParseContext& parse_context,
444 DLLLOCAL
int parseInitComplexHashInitialization(
const QoreProgramLocation* loc, QoreParseContext& parse_context);
446 DLLLOCAL
int parseInitComplexListInitialization(
const QoreProgramLocation* loc, QoreParseContext& parse_context);
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:57
DLLEXPORT void ref() const
increments the reference count
DLLEXPORT void deref(ExceptionSink *xsink)
decrements the reference count and calls derefImpl() if there_can_be_only_one is false,...
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
defines a Qore-language class
Definition: QoreClass.h:249
DLLEXPORT bool ROdereference() const
atomically decrements the reference count
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
typed hash declaration
Definition: TypedHashDecl.h:44
Definition: VarRefNode.h:381
const qore_type_t NT_VARREF
type value for VarRefNode
Definition: node_types.h:56
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:275