00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _QORE_QOREPROGRAM_H
00026
00027 #define _QORE_QOREPROGRAM_H
00028
00029 #include <qore/AbstractPrivateData.h>
00030 #include <qore/Restrictions.h>
00031
00032
00033 #define QP_WARN_NONE 0
00034 #define QP_WARN_WARNING_MASK_UNCHANGED (1 << 0)
00035 #define QP_WARN_DUPLICATE_LOCAL_VARS (1 << 1)
00036 #define QP_WARN_UNKNOWN_WARNING (1 << 2)
00037 #define QP_WARN_UNDECLARED_VAR (1 << 3)
00038 #define QP_WARN_DUPLICATE_GLOBAL_VARS (1 << 4)
00039 #define QP_WARN_UNREACHABLE_CODE (1 << 5)
00040 #define QP_WARN_ALL -1
00041
00043 DLLEXPORT extern const char **qore_warnings;
00044
00046 DLLEXPORT extern unsigned qore_num_warnings;
00047
00049 DLLEXPORT int get_warning_code(const char *str);
00050
00051 class AbstractCallReferenceNode;
00052 class LocalVar;
00053 class ExceptionSink;
00054 class QoreListNode;
00055 class QoreNamespace;
00056 class RootQoreNamespace;
00057 class QoreStringNode;
00058 class QoreHashNode;
00059 class FunctionCallNode;
00060 class AbstractStatement;
00061 class UnresolvedCallReferenceNode;
00062 class Var;
00063 class LVList;
00064 class UserFunction;
00065
00067
00074 class QoreProgram : public AbstractPrivateData {
00075 private:
00077 struct qore_program_private *priv;
00078
00079 DLLLOCAL void initGlobalVars();
00080 DLLLOCAL void importUserFunction(QoreProgram *p, UserFunction *uf, ExceptionSink *xsink);
00081 DLLLOCAL void del(ExceptionSink *xsink);
00082
00084 DLLLOCAL QoreProgram(const QoreProgram&);
00085
00087 DLLLOCAL QoreProgram& operator=(const QoreProgram&);
00088
00089 protected:
00091
00093 DLLLOCAL virtual ~QoreProgram();
00094
00095 public:
00097 DLLEXPORT QoreProgram();
00098
00100
00105 DLLEXPORT AbstractQoreNode *callFunction(const char *name, const QoreListNode *args, ExceptionSink *xsink);
00106
00108
00116 DLLEXPORT AbstractQoreNode *run(ExceptionSink *xsink);
00117
00119
00126 DLLEXPORT AbstractQoreNode *runTopLevel(ExceptionSink *xsink);
00127
00129
00139 DLLEXPORT void parseFileAndRun(const char *filename);
00140
00142
00151 DLLEXPORT void parseAndRun(FILE *fp, const char *name);
00152
00154
00163 DLLEXPORT void parseAndRun(const char *str, const char *name);
00164
00166
00173 DLLEXPORT void runClass(const char *classname, ExceptionSink *xsink);
00174
00176
00187 DLLEXPORT void parseFileAndRunClass(const char *filename, const char *classname);
00188
00190
00200 DLLEXPORT void parseAndRunClass(FILE *fp, const char *name, const char *classname);
00201
00203
00213 DLLEXPORT void parseAndRunClass(const char *str, const char *name, const char *classname);
00214
00216
00224 DLLEXPORT void parse(FILE *fp, const char *name, ExceptionSink *xsink, ExceptionSink *warn_sink = 0, int warn_mask = -1);
00225
00227
00235 DLLEXPORT void parse(const QoreString *str, const QoreString *lstr, ExceptionSink *xsink, ExceptionSink *warn_sink = 0, int warn_mask = -1);
00236
00238
00246 DLLEXPORT void parse(const char *str, const char *lstr, ExceptionSink *xsink, ExceptionSink *warn_sink = 0, int warn_mask = -1);
00247
00249
00256 DLLEXPORT void parseFile(const char *filename, ExceptionSink *xsink, ExceptionSink *warn_sink = 0, int warn_mask = -1);
00257
00259
00268 DLLEXPORT void parsePending(const char *code, const char *label, ExceptionSink *xsink, ExceptionSink *warn_sink = 0, int warn_mask = -1);
00269
00271
00280 DLLEXPORT void parsePending(const QoreString *str, const QoreString *lstr, ExceptionSink *xsink, ExceptionSink *warn_sink = 0, int warn_mask = -1);
00281
00283
00287 DLLEXPORT void parseCommit(ExceptionSink *xsink, ExceptionSink *warn_sink = 0, int warn_mask = -1);
00288
00290
00294 DLLEXPORT void parseRollback();
00295
00297 DLLEXPORT bool existsFunction(const char *name);
00298
00300
00304 DLLEXPORT virtual void deref(ExceptionSink *xsink);
00305
00307 DLLEXPORT void lockOptions();
00308
00310
00315 DLLEXPORT void setExecClass(const char *ecn = 0);
00316
00318 DLLEXPORT void parseSetParseOptions(int po);
00319
00321 DLLEXPORT void waitForTermination();
00322
00324
00327 DLLEXPORT void waitForTerminationAndDeref(ExceptionSink *xsink);
00328
00330 DLLEXPORT QoreNamespace *getQoreNS() const;
00331
00333 DLLEXPORT RootQoreNamespace *getRootNS() const;
00334
00336
00340 DLLEXPORT int setWarningMask(int wm);
00341
00343
00347 DLLEXPORT int enableWarning(int code);
00348
00350
00354 DLLEXPORT int disableWarning(int code);
00355
00357 DLLEXPORT int getParseOptions() const;
00358
00360
00364 DLLEXPORT void setParseOptions(int po, ExceptionSink *xsink);
00365
00367
00371 DLLEXPORT void disableParseOptions(int po, ExceptionSink *xsink);
00372
00374
00377 DLLEXPORT QoreListNode *getUserFunctionList();
00378
00380 DLLEXPORT bool checkWarning(int code) const;
00381
00383 DLLEXPORT int getWarningMask() const;
00384
00386 DLLEXPORT bool checkFeature(const char *f) const;
00387
00389 DLLEXPORT QoreListNode *getFeatureList() const;
00390
00392
00394 DLLEXPORT QoreStringNode *getScriptName() const;
00395
00397
00399 DLLEXPORT QoreStringNode *getScriptPath() const;
00400
00402
00404 DLLEXPORT QoreStringNode *getScriptDir() const;
00405
00407
00409 DLLEXPORT void setScriptPath(const char *path);
00410
00412
00416 DLLEXPORT AbstractQoreNode *getGlobalVariableValue(const char *var, bool &found) const;
00417
00419 DLLLOCAL UserFunction *findUserFunction(const char *name);
00420
00421 DLLLOCAL QoreProgram(QoreProgram *pgm, int po, bool ec = false, const char *ecn = 0);
00422
00424
00425
00426
00427
00428
00429 DLLLOCAL AbstractQoreNode *callFunction(const UserFunction *func, const QoreListNode *args, ExceptionSink *xsink);
00430
00431 DLLLOCAL LocalVar *createLocalVar(const char *name);
00432
00433 DLLLOCAL void registerUserFunction(UserFunction *u);
00434 DLLLOCAL void resolveFunction(FunctionCallNode *f);
00435 DLLLOCAL AbstractCallReferenceNode *resolveCallReference(UnresolvedCallReferenceNode *fr);
00436 DLLLOCAL void addGlobalVarDef(const char *name);
00437 DLLLOCAL void addStatement(AbstractStatement *s);
00438 DLLLOCAL Var *findGlobalVar(const char *name);
00439 DLLLOCAL const Var *findGlobalVar(const char *name) const;
00440 DLLLOCAL Var *checkGlobalVar(const char *name);
00441 DLLLOCAL Var *createGlobalVar(const char *name);
00442 DLLLOCAL void importGlobalVariable(Var *var, ExceptionSink *xsink, bool readonly);
00443 DLLLOCAL void makeParseException(const char *err, QoreStringNode *desc);
00444 DLLLOCAL void makeParseException(int sline, int eline, QoreStringNode *desc);
00445 DLLLOCAL void makeParseException(QoreStringNode *desc);
00446 DLLLOCAL void addParseException(ExceptionSink *xsink);
00447 DLLLOCAL void makeParseWarning(int code, const char *warn, const char *fmt, ...);
00448 DLLLOCAL void addParseWarning(int code, ExceptionSink *xsink);
00449 DLLLOCAL void cannotProvideFeature(QoreStringNode *desc);
00450 DLLLOCAL void exportUserFunction(const char *name, QoreProgram *p, ExceptionSink *xsink);
00451 DLLLOCAL void endThread(ExceptionSink *xsink);
00452 DLLLOCAL void startThread();
00453 DLLLOCAL QoreHashNode *getThreadData();
00454 DLLLOCAL void depRef();
00455 DLLLOCAL void depDeref(ExceptionSink *xsink);
00456 DLLLOCAL void addFeature(const char *f);
00457 DLLLOCAL void addFile(char *f);
00458 DLLLOCAL QoreListNode *getVarList();
00459 DLLLOCAL void parseSetIncludePath(const char *path);
00460 DLLLOCAL const char *parseGetIncludePath() const;
00461
00462
00463 DLLLOCAL void tc_inc();
00464
00465
00466 DLLLOCAL void tc_dec();
00467
00468
00469
00470
00471
00472 DLLLOCAL QoreThreadLock *getParseLock();
00473 DLLLOCAL QoreHashNode *clearThreadData(ExceptionSink *xsink);
00474 DLLLOCAL const LVList *getTopLevelLVList() const;
00475
00477
00479 DLLLOCAL const char *parseGetScriptDir() const;
00480
00481 };
00482
00484 class QoreProgramHelper {
00485 private:
00486 QoreProgram *pgm;
00487 ExceptionSink &xsink;
00488
00489 public:
00491 DLLLOCAL QoreProgramHelper(ExceptionSink &xs) : pgm(new QoreProgram), xsink(xs) {
00492 }
00493
00495
00497 DLLLOCAL ~QoreProgramHelper() {
00498 pgm->waitForTerminationAndDeref(&xsink);
00499 }
00500
00502 DLLLOCAL QoreProgram* operator->() { return pgm; }
00503
00505 DLLLOCAL QoreProgram* operator*() { return pgm; }
00506 };
00507
00508 #endif // _QORE_QOREPROGRAM_H