Qore Programming Language - C/C++ Library  0.8.12.2
 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 (C) 2003 - 2015 David Nichols
10 
11  Permission is hereby granted, free of charge, to any person obtaining a
12  copy of this software and associated documentation files (the "Software"),
13  to deal in the Software without restriction, including without limitation
14  the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  and/or sell copies of the Software, and to permit persons to whom the
16  Software is furnished to do so, subject to the following conditions:
17 
18  The above copyright notice and this permission notice shall be included in
19  all copies or substantial portions of the Software.
20 
21  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  DEALINGS IN THE SOFTWARE.
28 
29  Note that the Qore library is released under a choice of three open-source
30  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
31  information.
32 */
33 
34 #ifndef _QORE_QOREPROGRAM_H
35 
36 #define _QORE_QOREPROGRAM_H
37 
38 #include <qore/AbstractPrivateData.h>
39 #include <qore/Restrictions.h>
40 
41 // warnings - must correspond with the string order in QoreProgram.cpp
42 // new warnings must also be added as constants
43 #define QP_WARN_NONE 0
44 #define QP_WARN_WARNING_MASK_UNCHANGED (1 << 0)
45 #define QP_WARN_DUPLICATE_LOCAL_VARS (1 << 1)
46 #define QP_WARN_UNKNOWN_WARNING (1 << 2)
47 #define QP_WARN_UNDECLARED_VAR (1 << 3)
48 #define QP_WARN_DUPLICATE_GLOBAL_VARS (1 << 4)
49 #define QP_WARN_UNREACHABLE_CODE (1 << 5)
50 #define QP_WARN_NONEXISTENT_METHOD_CALL (1 << 6)
51 #define QP_WARN_INVALID_OPERATION (1 << 7)
52 #define QP_WARN_CALL_WITH_TYPE_ERRORS (1 << 8)
53 #define QP_WARN_RETURN_VALUE_IGNORED (1 << 9)
54 #define QP_WARN_DEPRECATED (1 << 10)
55 #define QP_WARN_EXCESS_ARGS (1 << 11)
56 #define QP_WARN_DUPLICATE_HASH_KEY (1 << 12)
57 #define QP_WARN_UNREFERENCED_VARIABLE (1 << 13)
58 #define QP_WARN_DUPLICATE_BLOCK_VARS (1 << 14)
59 #define QP_WARN_MODULE_ONLY (1 << 15)
60 #define QP_WARN_ALL -1
61 
62 #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)
63 
64 #define QP_WARN_DEFAULT (QP_WARN_UNKNOWN_WARNING|QP_WARN_MODULES|QP_WARN_DEPRECATED)
65 
67 DLLEXPORT extern const char** qore_warnings;
68 
70 DLLEXPORT extern unsigned qore_num_warnings;
71 
73 DLLEXPORT int get_warning_code(const char* str);
74 
76 class LocalVar;
77 class ExceptionSink;
78 class QoreListNode;
79 class QoreNamespace;
80 class RootQoreNamespace;
81 class QoreStringNode;
82 class QoreHashNode;
83 class FunctionCallNode;
84 class AbstractStatement;
85 class UnresolvedProgramCallReferenceNode;
86 class Var;
87 class LVList;
88 class UserFunctionVariant;
89 class QoreTypeInfo;
90 class QoreParseTypeInfo;
91 class ParamList;
92 class AbstractQoreZoneInfo;
93 class qore_program_private;
94 
96 
104  friend class qore_program_private_base;
105  friend class qore_program_private;
106 private:
108  qore_program_private* priv;
109 
111  DLLLOCAL QoreProgram(const QoreProgram&);
112 
114  DLLLOCAL QoreProgram& operator=(const QoreProgram&);
115 
116 protected:
118 
120  DLLLOCAL virtual ~QoreProgram();
121 
122 public:
124  DLLEXPORT QoreProgram();
125 
127 
130  DLLEXPORT QoreProgram(int64 parse_options);
131 
133 
138  DLLEXPORT AbstractQoreNode* callFunction(const char* name, const QoreListNode* args, ExceptionSink* xsink);
139 
141 
149  DLLEXPORT AbstractQoreNode* run(ExceptionSink* xsink);
150 
152 
159  DLLEXPORT AbstractQoreNode* runTopLevel(ExceptionSink* xsink);
160 
162 
172  DLLEXPORT void parseFileAndRun(const char* filename);
173 
175 
184  DLLEXPORT void parseAndRun(FILE *fp, const char* name);
185 
187 
196  DLLEXPORT void parseAndRun(const char* str, const char* name);
197 
199 
206  DLLEXPORT void runClass(const char* classname, ExceptionSink* xsink);
207 
209 
220  DLLEXPORT void parseFileAndRunClass(const char* filename, const char* classname);
221 
223 
233  DLLEXPORT void parseAndRunClass(FILE *fp, const char* name, const char* classname);
234 
236 
246  DLLEXPORT void parseAndRunClass(const char* str, const char* name, const char* classname);
247 
249 
257  DLLEXPORT void parse(FILE *fp, const char* name, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
258 
260 
268  DLLEXPORT void parse(const QoreString* str, const QoreString* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
269 
271 
281  DLLEXPORT void parse(const QoreString* str, const QoreString* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink, int warn_mask, const QoreString* source, int offset);
282 
284 
292  DLLEXPORT void parse(const char* str, const char* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
293 
295 
305  DLLEXPORT void parse(const char* str, const char* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink, int warn_mask, const char* source, int offset);
306 
308 
316  DLLEXPORT void parseFile(const char* filename, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL, bool only_first_except = false);
317 
319 
328  DLLEXPORT void parsePending(const char* code, const char* label, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
329 
331 
343  DLLEXPORT void parsePending(const char* code, const char* label, ExceptionSink* xsink, ExceptionSink* warn_sink, int warn_mask, const char* source, int offset);
344 
346 
356  DLLEXPORT void parsePending(const QoreString* str, const QoreString* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
357 
359 
371  DLLEXPORT void parsePending(const QoreString* str, const QoreString* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink, int warn_mask, const QoreString* source, int offset);
372 
374 
378  DLLEXPORT void parseCommit(ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
379 
381 
387  DLLEXPORT void parseRollback();
388 
390 
395  DLLEXPORT int parseRollback(ExceptionSink* xsink);
396 
398  DLLEXPORT bool existsFunction(const char* name);
399 
401 
406  DLLEXPORT virtual void deref(ExceptionSink* xsink);
407 
409  DLLEXPORT QoreProgram* programRefSelf() const;
410 
412  DLLEXPORT void lockOptions();
413 
415 
420  DLLEXPORT void setExecClass(const char* ecn = 0);
421 
423  DLLEXPORT void parseSetParseOptions(int po);
424 
426  DLLEXPORT void parseSetParseOptions(int64 po);
427 
429  DLLEXPORT void parseDisableParseOptions(int64 po);
430 
432  DLLEXPORT void waitForTermination();
433 
435 
438  DLLEXPORT void waitForTerminationAndDeref(ExceptionSink* xsink);
439 
441  DLLEXPORT QoreNamespace* getQoreNS() const;
442 
444  DLLEXPORT RootQoreNamespace* getRootNS() const;
445 
447 
451  DLLEXPORT int setWarningMask(int wm);
452 
454 
458  DLLEXPORT int enableWarning(int code);
459 
461 
465  DLLEXPORT int disableWarning(int code);
466 
468  DLLEXPORT int getParseOptions() const;
469 
471  DLLEXPORT int64 getParseOptions64() const;
472 
474 
478  DLLEXPORT void setParseOptions(int po, ExceptionSink* xsink);
479 
481 
485  DLLEXPORT void setParseOptions(int64 po, ExceptionSink* xsink);
486 
488 
492  DLLEXPORT void disableParseOptions(int po, ExceptionSink* xsink);
493 
495 
499  DLLEXPORT void disableParseOptions(int64 po, ExceptionSink* xsink);
500 
502 
506  DLLEXPORT void replaceParseOptions(int64 po, ExceptionSink* xsink);
507 
509 
512  DLLEXPORT QoreListNode* getUserFunctionList();
513 
515  DLLEXPORT bool checkWarning(int code) const;
516 
518  DLLEXPORT int getWarningMask() const;
519 
521  DLLEXPORT bool checkFeature(const char* f) const;
522 
524  DLLEXPORT QoreListNode* getFeatureList() const;
525 
527 
529  DLLEXPORT QoreStringNode* getScriptName() const;
530 
532 
534  DLLEXPORT QoreStringNode* getScriptPath() const;
535 
537 
539  DLLEXPORT QoreStringNode* getScriptDir() const;
540 
542 
544  DLLEXPORT void setScriptPath(const char* path);
545 
547 
551  DLLEXPORT AbstractQoreNode* getGlobalVariableValue(const char* var, bool &found) const;
552 
554 
558  DLLEXPORT QoreValue getGlobalVariableVal(const char* var, bool &found) const;
559 
560  // retrieves the time zone setting for the program
561  DLLEXPORT const AbstractQoreZoneInfo *currentTZ() const;
562 
563  // sets the program's time zone
564  DLLEXPORT void setTZ(const AbstractQoreZoneInfo *n_TZ);
565 
567 
570  DLLEXPORT void addFeature(const char* name);
571 
573 
577  DLLEXPORT void parseSetTimeZone(const char* zone);
578 
580 
587  DLLEXPORT void parseDefine(const char* str, AbstractQoreNode* val);
588 
590 
597  DLLEXPORT void parseDefine(const char* str, const char* val);
598 
600 
607  DLLEXPORT void parseCmdLineDefines(const std::map<std::string, std::string> defmap, ExceptionSink& xs, ExceptionSink& ws, int w);
608 
610 
615  DLLEXPORT void parseCmdLineDefines(ExceptionSink& xs, ExceptionSink& ws, int w, const std::map<std::string, std::string>& defmap);
616 
617  DLLLOCAL QoreProgram(QoreProgram* pgm, int64 po, bool ec = false, const char* ecn = 0);
618 
619  DLLLOCAL LocalVar *createLocalVar(const char* name, const QoreTypeInfo *typeInfo);
620 
621  // returns 0 if a "requires" exception has already occurred
622  DLLLOCAL ExceptionSink* getParseExceptionSink();
623 
624  DLLLOCAL QoreHashNode* getThreadData();
625  DLLLOCAL void depRef();
626  DLLLOCAL void depDeref(ExceptionSink* xsink);
627  DLLLOCAL void addFile(char* f);
628  DLLLOCAL QoreListNode* getVarList();
629  DLLLOCAL void parseSetIncludePath(const char* path);
630  DLLLOCAL const char* parseGetIncludePath() const;
631 
632  /* for run-time module loading; the parse lock must be grabbed
633  before loading new modules - note this should only be assigned
634  to an AutoLock or SafeLocker object!
635  */
636  DLLLOCAL QoreThreadLock *getParseLock();
637  DLLLOCAL const LVList* getTopLevelLVList() const;
638 
640 
642  DLLLOCAL const char* parseGetScriptDir() const;
643 
644  // can only be called while parsing from the same thread doing the parsing
645  DLLLOCAL bool parseExceptionRaised() const;
646 };
647 
649 
652 private:
653  QoreProgram* pgm;
654  ExceptionSink& xsink;
655 
656 public:
658  DLLEXPORT QoreProgramHelper(ExceptionSink& xs);
659 
661  DLLEXPORT QoreProgramHelper(int64 parse_options, ExceptionSink& xs);
662 
664 
666  DLLEXPORT ~QoreProgramHelper();
667 
669  DLLEXPORT QoreProgram* operator->();
670 
672  DLLEXPORT QoreProgram* operator*();
673 };
674 
675 #endif // _QORE_QOREPROGRAM_H
DLLEXPORT void waitForTermination()
this call blocks until the program&#39;s last thread terminates
DLLEXPORT QoreNamespace * getQoreNS() const
returns a pointer to the &quot;Qore&quot; namespace
DLLEXPORT void parseDefine(const char *str, AbstractQoreNode *val)
defines a parse-time variable; call only at parse time (or before parsing)
DLLEXPORT ~QoreProgramHelper()
waits until all background threads in the Qore library have terminated and until the QoreProgram obje...
DLLEXPORT void lockOptions()
locks parse options so they may not be changed
DLLEXPORT QoreProgram * programRefSelf() const
references &quot;this&quot; and returns a non-const pointer to itself
DLLEXPORT RootQoreNamespace * getRootNS() const
returns a pointer to the root namespace
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
DLLEXPORT void addFeature(const char *name)
manually add the feature to the program
DLLEXPORT int getParseOptions() const
returns the parse options currently set for this program; DEPRECATED; use getParseOptions64() instead...
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:49
DLLEXPORT QoreValue getGlobalVariableVal(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...
virtual DLLLOCAL ~QoreProgram()
the destructor is private in order to prohibit the object from being allocated on the stack ...
DLLEXPORT void waitForTerminationAndDeref(ExceptionSink *xsink)
this call blocks until the program&#39;s last thread terminates, and then calls QoreProgram::deref() ...
DLLEXPORT void disableParseOptions(int po, ExceptionSink *xsink)
turns off the parse options given in the passed mask and adds Qore-language exception information if ...
the base class for all data to be used as private data of Qore objects
Definition: AbstractPrivateData.h:44
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...
DLLEXPORT void setExecClass(const char *ecn=0)
sets the name of the application class to be executed (instantiated) instead of top-level code ...
DLLEXPORT AbstractQoreNode * runTopLevel(ExceptionSink *xsink)
tuns the top level code and returns any return value
DLLEXPORT bool checkWarning(int code) const
returns true if the warning code is set
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
contains constants, classes, and subnamespaces in QoreProgram objects
Definition: QoreNamespace.h:58
DLLEXPORT QoreProgram * operator*()
returns the QoreProgram object being managed
DLLEXPORT QoreListNode * getFeatureList() const
returns a list of features in the program object
DLLEXPORT void parseFileAndRun(const char *filename)
parses the given filename and runs the file
base class for call references, reference-counted, dynamically allocated only
Definition: CallReferenceNode.h:39
DLLEXPORT AbstractQoreNode * callFunction(const char *name, const QoreListNode *args, ExceptionSink *xsink)
calls a function from the function name and returns the return value
safely manages QoreProgram objects; note the the destructor will block until all background threads i...
Definition: QoreProgram.h:651
DLLEXPORT void parseSetTimeZone(const char *zone)
sets the time zone during parsing
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:82
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
DLLEXPORT void parseAndRun(FILE *fp, const char *name)
parses the given file and runs the file
DLLEXPORT QoreListNode * getUserFunctionList()
returns a list of all user functions in this program
the root namespace of a QoreProgram object
Definition: QoreNamespace.h:226
DLLEXPORT bool existsFunction(const char *name)
returns true if the given function exists as a user function, false if not
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
DLLEXPORT int enableWarning(int code)
enables a warning by its code
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...
virtual DLLLOCAL void deref()
decrements the reference count of the object without the possibility of throwing a Qore-language exce...
Definition: AbstractPrivateData.h:67
DLLEXPORT void parseCommit(ExceptionSink *xsink, ExceptionSink *warn_sink=0, int warn_mask=QP_WARN_ALL)
commits pending changes to the program
DLLEXPORT int setWarningMask(int wm)
sets the warning mask
DLLEXPORT void setScriptPath(const char *path)
sets the script path
DLLEXPORT QoreStringNode * getScriptPath() const
returns the script path (directory and name), if known (0 if not)
DLLEXPORT int64 getParseOptions64() const
returns the parse options currently set for this program
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only ...
Definition: QoreProgram.h:103
DLLEXPORT void parseRollback()
rolls back changes to the program object that were added with QoreProgram::parsePending() ...
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
DLLEXPORT void parseAndRunClass(FILE *fp, const char *name, const char *classname)
parses the given file and runs the code by instantiating the class given
DLLEXPORT void setParseOptions(int po, ExceptionSink *xsink)
sets the parse options and adds Qore-language exception information if an error occurs ...
DLLEXPORT QoreStringNode * getScriptDir() const
returns the script directory, if known (0 if not)
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:43
DLLEXPORT void runClass(const char *classname, ExceptionSink *xsink)
instantiates the class given and runs its constructor
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:228
DLLEXPORT QoreProgram()
creates the object
DLLEXPORT int disableWarning(int code)
disables a warning by its code
DLLEXPORT void parseSetParseOptions(int po)
adds the parse options given to the parse option mask; DEPRECATED: use parseSetParseOptions(int64) in...
DLLEXPORT void parseDisableParseOptions(int64 po)
disables the parse options given to the parse option mask
DLLEXPORT AbstractQoreNode * run(ExceptionSink *xsink)
runs the program (instantiates the program class if a program class has been set) and returns the ret...
DLLEXPORT QoreProgram * operator->()
returns the QoreProgram object being managed
provides a mutually-exclusive thread lock
Definition: QoreThreadLock.h:49
DLLEXPORT QoreProgramHelper(ExceptionSink &xs)
creates the QoreProgram object: DEPRECATED: use QoreProgramHelper(int64, ExceptionSink&amp;) instead ...
DLLEXPORT bool checkFeature(const char *f) const
returns true if the given feature is present in the program object
DLLEXPORT void replaceParseOptions(int64 po, ExceptionSink *xsink)
replaces the parse options in the program with those given by the argument; adds Qore-language except...
DLLEXPORT int getWarningMask() const
returns the warning mask
DLLEXPORT void parseFileAndRunClass(const char *filename, const char *classname)
parses the given filename and runs the program by instantiating the class given
DLLEXPORT void parseCmdLineDefines(const std::map< std::string, std::string > defmap, ExceptionSink &xs, ExceptionSink &ws, int w)
defines parse-time variables
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
DLLEXPORT QoreStringNode * getScriptName() const
returns the script file name, if known (0 if not)
DLLEXPORT const AbstractQoreZoneInfo * currentTZ()
returns the current local time zone, note that if 0 = UTC