Qore Programming Language 0.8.8

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreProgram.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3 QoreProgram.h
4
5 Program Object Definition
6
7 Qore Programming Language
8
9 Copyright 2003 - 2013 David Nichols
10
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Lesser General Public
13 License as published by the Free Software Foundation; either
14 version 2.1 of the License, or (at your option) any later version.
15
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Lesser General Public License for more details.
20
21 You should have received a copy of the GNU Lesser General Public
22 License along with this library; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 #ifndef _QORE_QOREPROGRAM_H
27
28 #define _QORE_QOREPROGRAM_H
29
30 #include <qore/AbstractPrivateData.h>
31 #include <qore/Restrictions.h>
32
33 // warnings - must correspond with the string order in QoreProgram.cpp
34 // new warnings must also be added as constants
35 #define QP_WARN_NONE 0
36 #define QP_WARN_WARNING_MASK_UNCHANGED (1 << 0)
37 #define QP_WARN_DUPLICATE_LOCAL_VARS (1 << 1)
38 #define QP_WARN_UNKNOWN_WARNING (1 << 2)
39 #define QP_WARN_UNDECLARED_VAR (1 << 3)
40 #define QP_WARN_DUPLICATE_GLOBAL_VARS (1 << 4)
41 #define QP_WARN_UNREACHABLE_CODE (1 << 5)
42 #define QP_WARN_NONEXISTENT_METHOD_CALL (1 << 6)
43 #define QP_WARN_INVALID_OPERATION (1 << 7)
44 #define QP_WARN_CALL_WITH_TYPE_ERRORS (1 << 8)
45 #define QP_WARN_RETURN_VALUE_IGNORED (1 << 9)
46 #define QP_WARN_DEPRECATED (1 << 10)
47 #define QP_WARN_EXCESS_ARGS (1 << 11)
48 #define QP_WARN_DUPLICATE_HASH_KEY (1 << 12)
49 #define QP_WARN_UNREFERENCED_VARIABLE (1 << 13)
50 #define QP_WARN_DUPLICATE_BLOCK_VARS (1 << 14)
51 #define QP_WARN_MODULE_ONLY (1 << 15)
52 #define QP_WARN_ALL -1
53
54 #define QP_WARN_MODULES (QP_WARN_UNREACHABLE_CODE|QP_WARN_NONEXISTENT_METHOD_CALL|QP_WARN_INVALID_OPERATION|QP_WARN_CALL_WITH_TYPE_ERRORS|QP_WARN_RETURN_VALUE_IGNORED|QP_WARN_DUPLICATE_HASH_KEY|QP_WARN_DUPLICATE_BLOCK_VARS)
55
56 #define QP_WARN_DEFAULT (QP_WARN_UNKNOWN_WARNING|QP_WARN_MODULES|QP_WARN_DEPRECATED)
57
59 DLLEXPORT extern const char** qore_warnings;
60
62 DLLEXPORT extern unsigned qore_num_warnings;
63
65 DLLEXPORT int get_warning_code(const char* str);
66
67 class AbstractCallReferenceNode;
68 class LocalVar;
69 class ExceptionSink;
70 class QoreListNode;
71 class QoreNamespace;
72 class RootQoreNamespace;
73 class QoreStringNode;
74 class QoreHashNode;
75 class FunctionCallNode;
76 class AbstractStatement;
77 class UnresolvedProgramCallReferenceNode;
78 class Var;
79 class LVList;
80 class UserFunctionVariant;
81 class QoreTypeInfo;
82 class QoreParseTypeInfo;
83 class ParamList;
84 class AbstractQoreZoneInfo;
85 class qore_program_private;
86
88
95 class QoreProgram : public AbstractPrivateData {
96 friend class qore_program_private_base;
97 friend class qore_program_private;
98 private:
100 qore_program_private* priv;
101
103 DLLLOCAL QoreProgram(const QoreProgram&);
104
106 DLLLOCAL QoreProgram& operator=(const QoreProgram&);
107
108 protected:
110
112 DLLLOCAL virtual ~QoreProgram();
113
114 public:
116 DLLEXPORT QoreProgram();
117
119
122 DLLEXPORT QoreProgram(int64 parse_options);
123
125
130 DLLEXPORT AbstractQoreNode* callFunction(const char* name, const QoreListNode* args, ExceptionSink* xsink);
131
133
141 DLLEXPORT AbstractQoreNode* run(ExceptionSink* xsink);
142
144
151 DLLEXPORT AbstractQoreNode* runTopLevel(ExceptionSink* xsink);
152
154
164 DLLEXPORT void parseFileAndRun(const char* filename);
165
167
176 DLLEXPORT void parseAndRun(FILE *fp, const char* name);
177
179
188 DLLEXPORT void parseAndRun(const char* str, const char* name);
189
191
198 DLLEXPORT void runClass(const char* classname, ExceptionSink* xsink);
199
201
212 DLLEXPORT void parseFileAndRunClass(const char* filename, const char* classname);
213
215
225 DLLEXPORT void parseAndRunClass(FILE *fp, const char* name, const char* classname);
226
228
238 DLLEXPORT void parseAndRunClass(const char* str, const char* name, const char* classname);
239
241
249 DLLEXPORT void parse(FILE *fp, const char* name, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
250
252
260 DLLEXPORT void parse(const QoreString* str, const QoreString* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
261
263
273 DLLEXPORT void parse(const QoreString* str, const QoreString* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink, int warn_mask, const QoreString* source, int offset);
274
276
284 DLLEXPORT void parse(const char* str, const char* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
285
287
297 DLLEXPORT void parse(const char* str, const char* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink, int warn_mask, const char* source, int offset);
298
300
308 DLLEXPORT void parseFile(const char* filename, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL, bool only_first_except = false);
309
311
320 DLLEXPORT void parsePending(const char* code, const char* label, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
321
323
335 DLLEXPORT void parsePending(const char* code, const char* label, ExceptionSink* xsink, ExceptionSink* warn_sink, int warn_mask, const char* source, int offset);
336
338
348 DLLEXPORT void parsePending(const QoreString* str, const QoreString* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
349
351
363 DLLEXPORT void parsePending(const QoreString* str, const QoreString* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink, int warn_mask, const QoreString* source, int offset);
364
366
370 DLLEXPORT void parseCommit(ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
371
373
377 DLLEXPORT void parseRollback();
378
380 DLLEXPORT bool existsFunction(const char* name);
381
383
387 using AbstractPrivateData::deref;
388 DLLEXPORT virtual void deref(ExceptionSink* xsink);
389
391 DLLEXPORT void lockOptions();
392
394
399 DLLEXPORT void setExecClass(const char* ecn = 0);
400
402 DLLEXPORT void parseSetParseOptions(int po);
403
405 DLLEXPORT void parseSetParseOptions(int64 po);
406
408 DLLEXPORT void parseDisableParseOptions(int64 po);
409
411 DLLEXPORT void waitForTermination();
412
414
417 DLLEXPORT void waitForTerminationAndDeref(ExceptionSink* xsink);
418
420 DLLEXPORT QoreNamespace* getQoreNS() const;
421
423 DLLEXPORT RootQoreNamespace* getRootNS() const;
424
426
430 DLLEXPORT int setWarningMask(int wm);
431
433
437 DLLEXPORT int enableWarning(int code);
438
440
444 DLLEXPORT int disableWarning(int code);
445
447 DLLEXPORT int getParseOptions() const;
448
450 DLLEXPORT int64 getParseOptions64() const;
451
453
457 DLLEXPORT void setParseOptions(int po, ExceptionSink* xsink);
458
460
464 DLLEXPORT void setParseOptions(int64 po, ExceptionSink* xsink);
465
467
471 DLLEXPORT void disableParseOptions(int po, ExceptionSink* xsink);
472
474
478 DLLEXPORT void disableParseOptions(int64 po, ExceptionSink* xsink);
479
481
485 DLLEXPORT void replaceParseOptions(int64 po, ExceptionSink* xsink);
486
488
491 DLLEXPORT QoreListNode* getUserFunctionList();
492
494 DLLEXPORT bool checkWarning(int code) const;
495
497 DLLEXPORT int getWarningMask() const;
498
500 DLLEXPORT bool checkFeature(const char* f) const;
501
503 DLLEXPORT QoreListNode* getFeatureList() const;
504
506
508 DLLEXPORT QoreStringNode* getScriptName() const;
509
511
513 DLLEXPORT QoreStringNode* getScriptPath() const;
514
516
518 DLLEXPORT QoreStringNode* getScriptDir() const;
519
521
523 DLLEXPORT void setScriptPath(const char* path);
524
526
530 DLLEXPORT AbstractQoreNode* getGlobalVariableValue(const char* var, bool &found) const;
531
532 // retrieves the time zone setting for the program
533 DLLEXPORT const AbstractQoreZoneInfo *currentTZ() const;
534
535 // sets the program's time zone
536 DLLEXPORT void setTZ(const AbstractQoreZoneInfo *n_TZ);
537
539
542 DLLEXPORT void addFeature(const char* name);
543
545
547 DLLEXPORT void parseSetTimeZone(const char* zone);
548
550
557 DLLEXPORT void parseDefine(const char* str, AbstractQoreNode* val);
558
560
567 DLLEXPORT void parseDefine(const char* str, const char* val);
568
569 DLLLOCAL QoreProgram(QoreProgram* pgm, int64 po, bool ec = false, const char* ecn = 0);
570
571 DLLLOCAL LocalVar *createLocalVar(const char* name, const QoreTypeInfo *typeInfo);
572
573 // returns 0 if a "requires" exception has already occurred
574 DLLLOCAL ExceptionSink* getParseExceptionSink();
575
576 DLLLOCAL QoreHashNode* getThreadData();
577 DLLLOCAL void depRef();
578 DLLLOCAL void depDeref(ExceptionSink* xsink);
579 DLLLOCAL void addFile(char* f);
580 DLLLOCAL QoreListNode* getVarList();
581 DLLLOCAL void parseSetIncludePath(const char* path);
582 DLLLOCAL const char* parseGetIncludePath() const;
583
584 /* for run-time module loading; the parse lock must be grabbed
585 before loading new modules - note this should only be assigned
586 to an AutoLock or SafeLocker object!
587 */
588 DLLLOCAL QoreThreadLock *getParseLock();
589 DLLLOCAL QoreHashNode* clearThreadData(ExceptionSink* xsink);
590 DLLLOCAL const LVList* getTopLevelLVList() const;
591
593
595 DLLLOCAL const char* parseGetScriptDir() const;
596
597 // can only be called while parsing from the same thread doing the parsing
598 DLLLOCAL bool parseExceptionRaised() const;
599 };
600
602
604 class QoreProgramHelper {
605 private:
606 QoreProgram* pgm;
607 ExceptionSink& xsink;
608
609 public:
611 DLLLOCAL QoreProgramHelper(ExceptionSink& xs) : pgm(new QoreProgram), xsink(xs) {
612 }
613
615 DLLLOCAL QoreProgramHelper(int64 parse_options, ExceptionSink& xs) : pgm(new QoreProgram(parse_options)), xsink(xs) {
616 }
617
619
621 DLLLOCAL ~QoreProgramHelper() {
622 // waits for all background threads to execute
623 thread_counter.waitForZero(&xsink);
624 // waits for the current Program to terminate
625 pgm->waitForTerminationAndDeref(&xsink);
626 }
627
629 DLLLOCAL QoreProgram* operator->() { return pgm; }
630
632 DLLLOCAL QoreProgram* operator*() { return pgm; }
633 };
634
635 #endif // _QORE_QOREPROGRAM_H
QoreProgram::waitForTermination
DLLEXPORT void waitForTermination()
this call blocks until the program&#39;s last thread terminates
QoreProgram::getQoreNS
DLLEXPORT QoreNamespace * getQoreNS() const
returns a pointer to the &quot;Qore&quot; namespace
QoreProgram::parseDefine
DLLEXPORT void parseDefine(const char *str, AbstractQoreNode *val)
defines a parse-time variable; call only at parse time (or before parsing)
QoreProgram::lockOptions
DLLEXPORT void lockOptions()
locks parse options so they may not be changed
QoreProgram::getRootNS
DLLEXPORT RootQoreNamespace * getRootNS() const
returns a pointer to the root namespace
QoreProgram::parsePending
DLLEXPORT void parsePending(const char *code, const char *label, ExceptionSink *xsink, ExceptionSink *warn_sink=0, int warn_mask=QP_WARN_ALL)
parses code from the given string but does not commit changes to the QoreProgram
QoreProgram::addFeature
DLLEXPORT void addFeature(const char *name)
manually add the feature to the program
QoreProgram::getParseOptions
DLLEXPORT int getParseOptions() const
returns the parse options currently set for this program; DEPRECATED; use getParseOptions64() instead...
QoreProgramHelper::~QoreProgramHelper
DLLLOCAL ~QoreProgramHelper()
waits until all background threads in the Qore library have terminated and until the QoreProgram obje...
Definition: QoreProgram.h:621
QoreHashNode
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:41
QoreProgram::~QoreProgram
virtual DLLLOCAL ~QoreProgram()
the destructor is private in order to prohibit the object from being allocated on the stack ...
QoreProgramHelper::operator*
DLLLOCAL QoreProgram * operator*()
returns the QoreProgram object being managed
Definition: QoreProgram.h:632
QoreProgram::waitForTerminationAndDeref
DLLEXPORT void waitForTerminationAndDeref(ExceptionSink *xsink)
this call blocks until the program&#39;s last thread terminates, and then calls QoreProgram::deref() ...
QoreProgram::disableParseOptions
DLLEXPORT void disableParseOptions(int po, ExceptionSink *xsink)
turns off the parse options given in the passed mask and adds Qore-language exception information if ...
AbstractPrivateData
the base class for all data to be used as private data of Qore objects
Definition: AbstractPrivateData.h:36
QoreProgram::getGlobalVariableValue
DLLEXPORT AbstractQoreNode * getGlobalVariableValue(const char *var, bool &found) const
returns the value of the global variable given (do not include the &quot;$&quot; symbol), the caller owns the r...
Restrictions.h
QoreProgram::setExecClass
DLLEXPORT void setExecClass(const char *ecn=0)
sets the name of the application class to be executed (instantiated) instead of top-level code ...
QoreProgram::runTopLevel
DLLEXPORT AbstractQoreNode * runTopLevel(ExceptionSink *xsink)
tuns the top level code and returns any return value
QoreProgram::checkWarning
DLLEXPORT bool checkWarning(int code) const
returns true if the warning code is set
AbstractQoreNode
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:47
QoreNamespace
contains constants, classes, and subnamespaces in QoreProgram objects
Definition: QoreNamespace.h:50
QoreProgram::getFeatureList
DLLEXPORT QoreListNode * getFeatureList() const
returns a list of features in the program object
QoreProgram::parseFileAndRun
DLLEXPORT void parseFileAndRun(const char *filename)
parses the given filename and runs the file
thread_counter
DLLEXPORT QoreCounter thread_counter
global background thread counter (for threads started explicitly by Qore)
QoreProgramHelper::QoreProgramHelper
DLLLOCAL QoreProgramHelper(ExceptionSink &xs)
creates the QoreProgram object: DEPRECATED: use QoreProgramHelper(int64, ExceptionSink&amp;) instead ...
Definition: QoreProgram.h:611
AbstractCallReferenceNode
base class for call references, reference-counted, dynamically allocated only
Definition: CallReferenceNode.h:31
QoreProgram::callFunction
DLLEXPORT AbstractQoreNode * callFunction(const char *name, const QoreListNode *args, ExceptionSink *xsink)
calls a function from the function name and returns the return value
QoreProgramHelper
safely manages QoreProgram objects; note the the destructor will block until all background threads i...
Definition: QoreProgram.h:604
QoreProgram::parseSetTimeZone
DLLEXPORT void parseSetTimeZone(const char *zone)
sets the time zone during parsing
QoreString
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:42
QoreStringNode
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:40
QoreProgram::parseAndRun
DLLEXPORT void parseAndRun(FILE *fp, const char *name)
parses the given file and runs the file
QoreProgram::getUserFunctionList
DLLEXPORT QoreListNode * getUserFunctionList()
returns a list of all user functions in this program
RootQoreNamespace
the root namespace of a QoreProgram object
Definition: QoreNamespace.h:211
QoreProgram::existsFunction
DLLEXPORT bool existsFunction(const char *name)
returns true if the given function exists as a user function, false if not
QoreListNode
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:44
QoreProgram::enableWarning
DLLEXPORT int enableWarning(int code)
enables a warning by its code
QoreProgram::parseGetScriptDir
DLLLOCAL const char * parseGetScriptDir() const
returns the script directory, if known (0 if not), does not grab the parse lock, only to be called wh...
QoreProgramHelper::QoreProgramHelper
DLLLOCAL QoreProgramHelper(int64 parse_options, ExceptionSink &xs)
creates the QoreProgram object and sets the parse options
Definition: QoreProgram.h:615
AbstractPrivateData::deref
virtual DLLLOCAL void deref()
decrements the reference count of the object without the possibility of throwing a Qore-language exce...
Definition: AbstractPrivateData.h:57
QoreProgram::parseCommit
DLLEXPORT void parseCommit(ExceptionSink *xsink, ExceptionSink *warn_sink=0, int warn_mask=QP_WARN_ALL)
commits pending changes to the program
QoreProgram::setWarningMask
DLLEXPORT int setWarningMask(int wm)
sets the warning mask
QoreProgram::setScriptPath
DLLEXPORT void setScriptPath(const char *path)
sets the script path
QoreProgram::getScriptPath
DLLEXPORT QoreStringNode * getScriptPath() const
returns the script path (directory and name), if known (0 if not)
QoreProgram::getParseOptions64
DLLEXPORT int64 getParseOptions64() const
returns the parse options currently set for this program
QoreProgram
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only ...
Definition: QoreProgram.h:95
QoreProgram::parseRollback
DLLEXPORT void parseRollback()
rolls back changes to the program object that were added with QoreProgram::parsePending() ...
QoreProgram::parse
DLLEXPORT void parse(FILE *fp, const char *name, ExceptionSink *xsink, ExceptionSink *warn_sink=0, int warn_mask=QP_WARN_ALL)
parses code from the file given and commits changes to the QoreProgram
QoreProgram::parseAndRunClass
DLLEXPORT void parseAndRunClass(FILE *fp, const char *name, const char *classname)
parses the given file and runs the code by instantiating the class given
QoreProgram::setParseOptions
DLLEXPORT void setParseOptions(int po, ExceptionSink *xsink)
sets the parse options and adds Qore-language exception information if an error occurs ...
QoreProgramHelper::operator->
DLLLOCAL QoreProgram * operator->()
returns the QoreProgram object being managed
Definition: QoreProgram.h:629
QoreProgram::getScriptDir
DLLEXPORT QoreStringNode * getScriptDir() const
returns the script directory, if known (0 if not)
ExceptionSink
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:35
QoreProgram::runClass
DLLEXPORT void runClass(const char *classname, ExceptionSink *xsink)
instantiates the class given and runs its constructor
QoreProgram::QoreProgram
DLLEXPORT QoreProgram()
creates the object
QoreProgram::disableWarning
DLLEXPORT int disableWarning(int code)
disables a warning by its code
QoreProgram::parseSetParseOptions
DLLEXPORT void parseSetParseOptions(int po)
adds the parse options given to the parse option mask; DEPRECATED: use parseSetParseOptions(int64) in...
QoreProgram::parseDisableParseOptions
DLLEXPORT void parseDisableParseOptions(int64 po)
disables the parse options given to the parse option mask
QoreProgram::run
DLLEXPORT AbstractQoreNode * run(ExceptionSink *xsink)
runs the program (instantiates the program class if a program class has been set) and returns the ret...
QoreThreadLock
provides a mutually-exclusive thread lock
Definition: QoreThreadLock.h:41
QoreProgram::checkFeature
DLLEXPORT bool checkFeature(const char *f) const
returns true if the given feature is present in the program object
QoreProgram::replaceParseOptions
DLLEXPORT void replaceParseOptions(int64 po, ExceptionSink *xsink)
replaces the parse options in the program with those given by the argument; adds Qore-language except...
QoreCounter::waitForZero
DLLEXPORT int waitForZero(ExceptionSink *xsink, int timeout_ms=0)
blocks the calling thread until the counter reaches 0
QoreProgram::getWarningMask
DLLEXPORT int getWarningMask() const
returns the warning mask
QoreProgram::parseFileAndRunClass
DLLEXPORT void parseFileAndRunClass(const char *filename, const char *classname)
parses the given filename and runs the program by instantiating the class given
QoreProgram::parseFile
DLLEXPORT void parseFile(const char *filename, ExceptionSink *xsink, ExceptionSink *warn_sink=0, int warn_mask=QP_WARN_ALL, bool only_first_except=false)
parses code from the file given and commits changes to the QoreProgram
QoreProgram::getScriptName
DLLEXPORT QoreStringNode * getScriptName() const
returns the script file name, if known (0 if not)
currentTZ
DLLEXPORT const AbstractQoreZoneInfo * currentTZ()
returns the current local time zone, note that if 0 = UTC