Qore Programming Language  0.9.16
QoreReflection.h
Go to the documentation of this file.
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
3 /*
4  Qore Programming Language
5 
6  Copyright (C) 2003 - 2020 Qore Technologies, s.r.o.
7 
8  Permission is hereby granted, free of charge, to any person obtaining a
9  copy of this software and associated documentation files (the "Software"),
10  to deal in the Software without restriction, including without limitation
11  the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  and/or sell copies of the Software, and to permit persons to whom the
13  Software is furnished to do so, subject to the following conditions:
14 
15  The above copyright notice and this permission notice shall be included in
16  all copies or substantial portions of the Software.
17 
18  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  DEALINGS IN THE SOFTWARE.
25 
26  Note that the Qore library is released under a choice of three open-source
27  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
28  information.
29 */
30 
31 #ifndef _QORE_QOREREFLECTION_H
32 
33 #define _QORE_QOREREFLECTION_H
34 
36 
39 public:
41  DLLEXPORT const QoreClass* getClass() const;
42 
44  DLLEXPORT const char* getSignatureText() const;
45 
47  DLLEXPORT int64 getCodeFlags() const;
48 
50  DLLEXPORT bool isModulePublic() const;
51 
53  DLLEXPORT bool isSynchronized() const;
54 
56  DLLEXPORT bool isBuiltin() const;
57 
59  DLLEXPORT bool hasBody() const;
60 
62  DLLEXPORT int64 getDomain() const;
63 
65  DLLEXPORT unsigned numParams() const;
66 
68  DLLEXPORT const QoreTypeInfo* getReturnTypeInfo() const;
69 
71  DLLEXPORT const type_vec_t& getParamTypeList() const;
72 
74  DLLEXPORT const arg_vec_t& getDefaultArgList() const;
75 
77  DLLEXPORT const name_vec_t& getParamNames() const;
78 
80  DLLEXPORT const QoreExternalProgramLocation* getSourceLocation() const;
81 
82 private:
84  DLLLOCAL QoreExternalVariant();
85 };
86 
88 
91 public:
93  DLLEXPORT const QoreMethod* getMethod() const;
94 
96  DLLEXPORT bool isAbstract() const;
97 
99  DLLEXPORT bool isFinal() const;
100 
102  DLLEXPORT bool isStatic() const;
103 
105  DLLEXPORT ClassAccess getAccess() const;
106 
108  DLLEXPORT const char* getAccessString() const;
109 
110 private:
112  DLLLOCAL QoreExternalMethodVariant();
113 };
114 
116 
119 public:
121  DLLEXPORT const QoreTypeInfo* getTypeInfo() const;
122 
124  DLLEXPORT QoreValue getDefaultValue(ExceptionSink* xsink) const;
125 
127  DLLEXPORT const QoreExternalProgramLocation* getSourceLocation() const;
128 
129 private:
131  DLLLOCAL QoreExternalMemberBase();
132 };
133 
135 
138 public:
140  DLLEXPORT ClassAccess getAccess() const;
141 
143  DLLEXPORT const char* getAccessString() const;
144 
145 private:
147  DLLLOCAL QoreExternalMemberVarBase();
148 };
149 
151 
154 public:
156  DLLEXPORT QoreValue getValue() const;
157 
159 
164  DLLEXPORT int setValue(const QoreValue val, ExceptionSink* xsink) const;
165 
166 private:
168  DLLLOCAL QoreExternalStaticMember();
169 };
170 
172 
175 public:
177  DLLEXPORT bool isTransient() const;
178 
179 private:
181  DLLLOCAL QoreExternalNormalMember();
182 };
183 
185 
188 public:
190  DLLEXPORT QoreHashNode* getHash() const;
191 
192 private:
194  DLLLOCAL QoreExternalProgramLocation();
195 };
196 
198 
201 public:
203  DLLEXPORT const char* getName() const;
204 
206 
208  DLLEXPORT const char* getModuleName() const;
209 
211  DLLEXPORT bool isModulePublic() const;
212 
214  DLLEXPORT bool isBuiltin() const;
215 
217  DLLEXPORT const QoreTypeInfo* getTypeInfo() const;
218 
220  DLLEXPORT QoreValue getReferencedValue() const;
221 
223  DLLEXPORT const QoreExternalProgramLocation* getSourceLocation() const;
224 
226  DLLEXPORT ClassAccess getAccess() const;
227 
228 private:
230  DLLLOCAL QoreExternalConstant();
231 };
232 
233 class QoreExternalFunction {
234 public:
236  DLLEXPORT const char* getName() const;
237 
239 
241  DLLEXPORT const char* getModuleName() const;
242 
244  DLLEXPORT const QoreClass* getClass() const;
245 
247  DLLEXPORT const QoreExternalVariant* findVariant(const type_vec_t& type_vec, ExceptionSink* xsink) const;
248 
250  DLLEXPORT bool isBuiltin() const;
251 
253  DLLEXPORT bool isInjected() const;
254 
256  DLLEXPORT unsigned numVariants() const;
257 
259  DLLEXPORT QoreValue evalFunction(const QoreExternalVariant* variant, const QoreListNode* args, QoreProgram* pgm, ExceptionSink* xsink) const;
260 
262  DLLEXPORT const QoreExternalVariant* getFirstVariant() const;
263 
265 
269  DLLEXPORT int64 getDomain() const;
270 
272 
276  DLLEXPORT int64 getCodeFlags() const;
277 
278 private:
280  DLLLOCAL QoreExternalFunction();
281 };
282 
283 class QoreExternalFunctionIterator {
284 public:
285  DLLEXPORT QoreExternalFunctionIterator(const QoreExternalFunction& f);
286 
287  DLLEXPORT ~QoreExternalFunctionIterator();
288 
289  DLLEXPORT bool next();
290 
291  DLLEXPORT const QoreExternalVariant* getVariant();
292 
293 private:
294  class qore_external_function_iterator_private* priv;
295 };
296 
297 class QoreExternalMethodFunction : public QoreExternalFunction {
298 public:
300  DLLEXPORT const QoreMethod* getMethod() const;
301 
303  DLLEXPORT bool isStatic() const;
304 
305 private:
307  DLLLOCAL QoreExternalMethodFunction();
308 };
309 
310 class QoreExternalGlobalVar {
311 public:
313  DLLEXPORT const char* getName() const;
314 
316  DLLEXPORT bool isModulePublic() const;
317 
319  DLLEXPORT bool isBuiltin() const;
320 
322  DLLEXPORT const QoreTypeInfo* getTypeInfo() const;
323 
325  DLLEXPORT QoreValue getReferencedValue() const;
326 
328  DLLEXPORT const QoreExternalProgramLocation* getSourceLocation() const;
329 
331 
336  DLLEXPORT int setValue(const QoreValue val, ExceptionSink* xsink) const;
337 
338 private:
340  DLLLOCAL QoreExternalGlobalVar();
341 };
342 
344 DLLEXPORT const char* qore_type_get_name(const QoreTypeInfo* ti);
345 
347 DLLEXPORT bool qore_type_equal(const QoreTypeInfo* ti1, const QoreTypeInfo* ti2);
348 
350 DLLEXPORT bool qore_type_is_output_compatible(const QoreTypeInfo* ti1, const QoreTypeInfo* ti2);
351 
353 
362 DLLEXPORT bool qore_type_is_assignable_from(const QoreTypeInfo* ti1, const QoreTypeInfo* ti2);
363 
365 
376 DLLEXPORT bool qore_type_is_assignable_from(const QoreTypeInfo* ti1, const QoreTypeInfo* ti2, bool& may_not_match);
377 
379 
388 DLLEXPORT int qore_type_is_assignable_from(const QoreTypeInfo* t, QoreValue value);
389 
391 
394 DLLEXPORT QoreValue qore_type_assign_value(const QoreTypeInfo* t, const QoreValue value, ExceptionSink* xsink);
395 
397 
400 DLLEXPORT qore_type_t qore_type_get_base_type(const QoreTypeInfo* t);
401 
403 
405 DLLEXPORT QoreHashNode* qore_type_get_accept_types(const QoreTypeInfo* t);
406 
408 
410 DLLEXPORT QoreHashNode* qore_type_get_return_types(const QoreTypeInfo* t);
411 
413 DLLEXPORT bool qore_type_can_convert_to_scalar(const QoreTypeInfo* ti);
414 
416 DLLEXPORT bool qore_type_has_default_value(const QoreTypeInfo* ti);
417 
419 DLLEXPORT QoreValue qore_type_get_default_value(const QoreTypeInfo* ti);
420 
422 DLLEXPORT bool qore_type_is_input_output_compatible(const QoreTypeInfo* ti1, const QoreTypeInfo* ti2);
423 
424 #endif
QoreExternalVariant::numParams
DLLEXPORT unsigned numParams() const
returns the number of parameters
QoreExternalMethodVariant::isFinal
DLLEXPORT bool isFinal() const
returns true if the method variant is final
qore_type_is_output_compatible
DLLEXPORT bool qore_type_is_output_compatible(const QoreTypeInfo *ti1, const QoreTypeInfo *ti2)
returns true if ti2's return type is compatible with ti1's; either argument may be nullptr meaning no...
QoreExternalNormalMember
external wrapper base class for class normal members
Definition: QoreReflection.h:174
QoreExternalVariant::hasBody
DLLEXPORT bool hasBody() const
returns true if the variant has a function body
QoreProgram
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only
Definition: QoreProgram.h:126
QoreExternalMethodVariant
external wrapper class for method variants
Definition: QoreReflection.h:90
QoreExternalMemberBase::getDefaultValue
DLLEXPORT QoreValue getDefaultValue(ExceptionSink *xsink) const
evaluates the initialization expression for the member and returns the referenced value
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
qore_type_is_input_output_compatible
DLLEXPORT bool qore_type_is_input_output_compatible(const QoreTypeInfo *ti1, const QoreTypeInfo *ti2)
returns true if the types are compatible with inputs and outputs
QoreHashNode
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
QoreExternalStaticMember::getValue
DLLEXPORT QoreValue getValue() const
returns the current value of the member; caller owns an reference returned
QoreExternalConstant::getReferencedValue
DLLEXPORT QoreValue getReferencedValue() const
returns the value of the constant; caller owns any reference returned
QoreExternalStaticMember
external wrapper base class for class static members
Definition: QoreReflection.h:153
qore_type_get_name
const DLLEXPORT char * qore_type_get_name(const QoreTypeInfo *ti)
returns the name of the type; the argument may be nullptr meaning no type restrictions
QoreClass
defines a Qore-language class
Definition: QoreClass.h:239
QoreExternalMethodVariant::getAccess
DLLEXPORT ClassAccess getAccess() const
returns the access info for the member
QoreExternalVariant::getSourceLocation
const DLLEXPORT QoreExternalProgramLocation * getSourceLocation() const
returns the source location of the variant
QoreExternalConstant::isBuiltin
DLLEXPORT bool isBuiltin() const
returns true if the constant is builtin
QoreExternalVariant::isModulePublic
DLLEXPORT bool isModulePublic() const
returns true if the variant has the module public flag set
QoreExternalMemberBase::getTypeInfo
const DLLEXPORT QoreTypeInfo * getTypeInfo() const
returns the type info for the member
QoreExternalConstant::getModuleName
const DLLEXPORT char * getModuleName() const
returns the module name, if any, otherwise returns nullptr
QoreListNode
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
int64
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260
qore_type_is_assignable_from
DLLEXPORT bool qore_type_is_assignable_from(const QoreTypeInfo *ti1, const QoreTypeInfo *ti2)
returns true if ti2's return type is compatible with ti1 input (i.e. ti1 is assignable from ti2)
arg_vec_t
std::vector< QoreValue > arg_vec_t
vector of value information for default argument lists
Definition: common.h:254
QoreExternalVariant::getReturnTypeInfo
const DLLEXPORT QoreTypeInfo * getReturnTypeInfo() const
returns the return type
qore_type_has_default_value
DLLEXPORT bool qore_type_has_default_value(const QoreTypeInfo *ti)
returns true if the type has a default value; the argument may be nullptr meaning no type restriction...
QoreExternalConstant
external wrapper class for constants
Definition: QoreReflection.h:200
QoreExternalVariant::getDefaultArgList
const DLLEXPORT arg_vec_t & getDefaultArgList() const
returns a list of default arguments for the variant
qore_type_get_base_type
DLLEXPORT qore_type_t qore_type_get_base_type(const QoreTypeInfo *t)
returns the base type code for the type or NT_ALL for those that don't have types
qore_type_can_convert_to_scalar
DLLEXPORT bool qore_type_can_convert_to_scalar(const QoreTypeInfo *ti)
returns true if the type's value can be converted to a scalar; the argument may be nullptr meaning no...
QoreExternalStaticMember::setValue
DLLEXPORT int setValue(const QoreValue val, ExceptionSink *xsink) const
sets the value of the member
QoreExternalMemberVarBase::getAccess
DLLEXPORT ClassAccess getAccess() const
returns the access info for the member
QoreExternalMethodVariant::isAbstract
DLLEXPORT bool isAbstract() const
returns true if the method variant is abstract
QoreExternalNormalMember::isTransient
DLLEXPORT bool isTransient() const
returns true if the member is transient (i.e. will not be serialized)
QoreExternalVariant::getSignatureText
const DLLEXPORT char * getSignatureText() const
returns the signature for the variant
QoreExternalProgramLocation
external wrapper class for source code location information
Definition: QoreReflection.h:187
QoreExternalVariant::getParamNames
const DLLEXPORT name_vec_t & getParamNames() const
returns a list of parameter names for the variant
qore_type_equal
DLLEXPORT bool qore_type_equal(const QoreTypeInfo *ti1, const QoreTypeInfo *ti2)
returns true if the types are equal; either argument may be nullptr meaning no type restrictions
QoreExternalVariant::getClass
const DLLEXPORT QoreClass * getClass() const
returns the class for a method variant or nullptr for a normal variant
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
QoreExternalMemberVarBase::getAccessString
const DLLEXPORT char * getAccessString() const
returns a string for the access info for the member
QoreExternalMethodVariant::getMethod
const DLLEXPORT QoreMethod * getMethod() const
returns the method for a method variant
qore_type_assign_value
DLLEXPORT QoreValue qore_type_assign_value(const QoreTypeInfo *t, const QoreValue value, ExceptionSink *xsink)
processes the given value by the given type and returns the result; a Qore-language exception is thro...
QoreExternalMemberVarBase
external wrapper base class for class members
Definition: QoreReflection.h:137
qore_type_get_accept_types
DLLEXPORT QoreHashNode * qore_type_get_accept_types(const QoreTypeInfo *t)
returns a hash of base types accepted by the type
QoreExternalVariant::getDomain
DLLEXPORT int64 getDomain() const
returns the functional domain of the variant
QoreExternalMemberBase::getSourceLocation
const DLLEXPORT QoreExternalProgramLocation * getSourceLocation() const
returns the source location of the member's declaration
qore_type_get_default_value
DLLEXPORT QoreValue qore_type_get_default_value(const QoreTypeInfo *ti)
returns the default value of the type (if any); the caller owns any reference returned; the argument ...
QoreExternalMemberBase
external wrapper base class for class and hashdecl members
Definition: QoreReflection.h:118
QoreExternalConstant::isModulePublic
DLLEXPORT bool isModulePublic() const
returns true if the constant has the module public flag set
QoreExternalVariant::getCodeFlags
DLLEXPORT int64 getCodeFlags() const
returns binary-or-combined code flags
QoreExternalVariant::isBuiltin
DLLEXPORT bool isBuiltin() const
returns true if the variant is builtin
QoreExternalConstant::getName
const DLLEXPORT char * getName() const
returns the constant name
QoreExternalMethodVariant::getAccessString
const DLLEXPORT char * getAccessString() const
returns a string for the access info for the member
QoreExternalProgramLocation::getHash
DLLEXPORT QoreHashNode * getHash() const
returns a hash of the given source location
type_vec_t
std::vector< const QoreTypeInfo * > type_vec_t
vector of type information for parameter lists
Definition: common.h:251
QoreMethod
a method in a QoreClass
Definition: QoreClass.h:125
QoreExternalVariant::getParamTypeList
const DLLEXPORT type_vec_t & getParamTypeList() const
returns the parameter types for the variant
QoreExternalConstant::getSourceLocation
const DLLEXPORT QoreExternalProgramLocation * getSourceLocation() const
returns the source code location of the constant's definition
QoreExternalVariant
external wrapper class for function and call variants
Definition: QoreReflection.h:38
QoreExternalConstant::getTypeInfo
const DLLEXPORT QoreTypeInfo * getTypeInfo() const
returns the type info for the constant
QoreExternalConstant::getAccess
DLLEXPORT ClassAccess getAccess() const
returns the access info for the constant
name_vec_t
std::vector< std::string > name_vec_t
vector of parameter names for parameter lists
Definition: common.h:257
qore_type_t
int16_t qore_type_t
used to identify unique Qore data and parse types (descendents of AbstractQoreNode)
Definition: common.h:70
QoreExternalVariant::isSynchronized
DLLEXPORT bool isSynchronized() const
returns true if the variant has the synchronized flag set
qore_type_get_return_types
DLLEXPORT QoreHashNode * qore_type_get_return_types(const QoreTypeInfo *t)
returns a hash of base types returned by the type
QoreExternalMethodVariant::isStatic
DLLEXPORT bool isStatic() const
returns true if the method variant is static