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
00026 #ifndef _QORE_QOREPROGRAM_H
00027
00028 #define _QORE_QOREPROGRAM_H
00029
00030 #include <qore/AbstractPrivateData.h>
00031 #include <qore/Restrictions.h>
00032
00033
00034
00035 #define QP_WARN_NONE 0
00036 #define QP_WARN_WARNING_MASK_UNCHANGED (1 << 0)
00037 #define QP_WARN_DUPLICATE_LOCAL_VARS (1 << 1)
00038 #define QP_WARN_UNKNOWN_WARNING (1 << 2)
00039 #define QP_WARN_UNDECLARED_VAR (1 << 3)
00040 #define QP_WARN_DUPLICATE_GLOBAL_VARS (1 << 4)
00041 #define QP_WARN_UNREACHABLE_CODE (1 << 5)
00042 #define QP_WARN_NONEXISTENT_METHOD_CALL (1 << 6)
00043 #define QP_WARN_INVALID_OPERATION (1 << 7)
00044 #define QP_WARN_CALL_WITH_TYPE_ERRORS (1 << 8)
00045 #define QP_WARN_RETURN_VALUE_IGNORED (1 << 9)
00046 #define QP_WARN_DEPRECATED (1 << 10)
00047 #define QP_WARN_EXCESS_ARGS (1 << 11)
00048 #define QP_WARN_DUPLICATE_HASH_KEY (1 << 12)
00049 #define QP_WARN_UNREFERENCED_VARIABLE (1 << 13)
00050 #define QP_WARN_ALL -1
00051
00052 #define QP_WARN_DEFAULT (QP_WARN_UNKNOWN_WARNING|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)
00053
00055 DLLEXPORT extern const char **qore_warnings;
00056
00058 DLLEXPORT extern unsigned qore_num_warnings;
00059
00061 DLLEXPORT int get_warning_code(const char *str);
00062
00063 class AbstractCallReferenceNode;
00064 class LocalVar;
00065 class ExceptionSink;
00066 class QoreListNode;
00067 class QoreNamespace;
00068 class RootQoreNamespace;
00069 class QoreStringNode;
00070 class QoreHashNode;
00071 class FunctionCallNode;
00072 class AbstractStatement;
00073 class UnresolvedCallReferenceNode;
00074 class Var;
00075 class LVList;
00076 class UserFunction;
00077 class UserFunctionVariant;
00078 class QoreTypeInfo;
00079 class QoreParseTypeInfo;
00080 class ParamList;
00081 class AbstractQoreFunction;
00082 class AbstractQoreZoneInfo;
00083
00085
00092 class QoreProgram : public AbstractPrivateData {
00093 private:
00095 struct qore_program_private *priv;
00096
00097 DLLLOCAL void del(ExceptionSink *xsink);
00098
00100 DLLLOCAL QoreProgram(const QoreProgram&);
00101
00103 DLLLOCAL QoreProgram& operator=(const QoreProgram&);
00104
00105 protected:
00107
00109 DLLLOCAL virtual ~QoreProgram();
00110
00111 public:
00113 DLLEXPORT QoreProgram();
00114
00116
00119 DLLEXPORT QoreProgram(int64 parse_options);
00120
00122
00127 DLLEXPORT AbstractQoreNode *callFunction(const char *name, const QoreListNode *args, ExceptionSink *xsink);
00128
00130
00138 DLLEXPORT AbstractQoreNode *run(ExceptionSink *xsink);
00139
00141
00148 DLLEXPORT AbstractQoreNode *runTopLevel(ExceptionSink *xsink);
00149
00151
00161 DLLEXPORT void parseFileAndRun(const char *filename);
00162
00164
00173 DLLEXPORT void parseAndRun(FILE *fp, const char *name);
00174
00176
00185 DLLEXPORT void parseAndRun(const char *str, const char *name);
00186
00188
00195 DLLEXPORT void runClass(const char *classname, ExceptionSink *xsink);
00196
00198
00209 DLLEXPORT void parseFileAndRunClass(const char *filename, const char *classname);
00210
00212
00222 DLLEXPORT void parseAndRunClass(FILE *fp, const char *name, const char *classname);
00223
00225
00235 DLLEXPORT void parseAndRunClass(const char *str, const char *name, const char *classname);
00236
00238
00246 DLLEXPORT void parse(FILE *fp, const char *name, ExceptionSink *xsink, ExceptionSink *warn_sink = 0, int warn_mask = QP_WARN_ALL);
00247
00249
00257 DLLEXPORT void parse(const QoreString *str, const QoreString *lstr, ExceptionSink *xsink, ExceptionSink *warn_sink = 0, int warn_mask = QP_WARN_ALL);
00258
00260
00268 DLLEXPORT void parse(const char *str, const char *lstr, ExceptionSink *xsink, ExceptionSink *warn_sink = 0, int warn_mask = QP_WARN_ALL);
00269
00271
00279 DLLEXPORT void parseFile(const char *filename, ExceptionSink *xsink, ExceptionSink *warn_sink = 0, int warn_mask = QP_WARN_ALL, bool only_first_except = false);
00280
00282
00291 DLLEXPORT void parsePending(const char *code, const char *label, ExceptionSink *xsink, ExceptionSink *warn_sink = 0, int warn_mask = QP_WARN_ALL);
00292
00294
00303 DLLEXPORT void parsePending(const QoreString *str, const QoreString *lstr, ExceptionSink *xsink, ExceptionSink *warn_sink = 0, int warn_mask = QP_WARN_ALL);
00304
00306
00310 DLLEXPORT void parseCommit(ExceptionSink *xsink, ExceptionSink *warn_sink = 0, int warn_mask = QP_WARN_ALL);
00311
00313
00317 DLLEXPORT void parseRollback();
00318
00320 DLLEXPORT bool existsFunction(const char *name);
00321
00323
00327 using AbstractPrivateData::deref;
00328 DLLEXPORT virtual void deref(ExceptionSink *xsink);
00329
00331 DLLEXPORT void lockOptions();
00332
00334
00339 DLLEXPORT void setExecClass(const char *ecn = 0);
00340
00342 DLLEXPORT void parseSetParseOptions(int po);
00343
00345 DLLEXPORT void parseSetParseOptions(int64 po);
00346
00348 DLLEXPORT void waitForTermination();
00349
00351
00354 DLLEXPORT void waitForTerminationAndDeref(ExceptionSink *xsink);
00355
00357 DLLEXPORT QoreNamespace *getQoreNS() const;
00358
00360 DLLEXPORT RootQoreNamespace *getRootNS() const;
00361
00363
00367 DLLEXPORT int setWarningMask(int wm);
00368
00370
00374 DLLEXPORT int enableWarning(int code);
00375
00377
00381 DLLEXPORT int disableWarning(int code);
00382
00384 DLLEXPORT int getParseOptions() const;
00385
00387 DLLEXPORT int64 getParseOptions64() const;
00388
00390
00394 DLLEXPORT void setParseOptions(int po, ExceptionSink *xsink);
00395
00397
00401 DLLEXPORT void setParseOptions(int64 po, ExceptionSink *xsink);
00402
00404
00408 DLLEXPORT void disableParseOptions(int po, ExceptionSink *xsink);
00409
00411
00415 DLLEXPORT void disableParseOptions(int64 po, ExceptionSink *xsink);
00416
00418
00421 DLLEXPORT QoreListNode *getUserFunctionList();
00422
00424 DLLEXPORT bool checkWarning(int code) const;
00425
00427 DLLEXPORT int getWarningMask() const;
00428
00430 DLLEXPORT bool checkFeature(const char *f) const;
00431
00433 DLLEXPORT QoreListNode *getFeatureList() const;
00434
00436
00438 DLLEXPORT QoreStringNode *getScriptName() const;
00439
00441
00443 DLLEXPORT QoreStringNode *getScriptPath() const;
00444
00446
00448 DLLEXPORT QoreStringNode *getScriptDir() const;
00449
00451
00453 DLLEXPORT void setScriptPath(const char *path);
00454
00456
00460 DLLEXPORT AbstractQoreNode *getGlobalVariableValue(const char *var, bool &found) const;
00461
00462
00463 DLLEXPORT const AbstractQoreZoneInfo *currentTZ() const;
00464
00465
00466 DLLEXPORT void setTZ(const AbstractQoreZoneInfo *n_TZ);
00467
00469 DLLLOCAL UserFunction *findUserFunction(const char *name);
00470
00471 DLLLOCAL QoreProgram(QoreProgram *pgm, int64 po, bool ec = false, const char *ecn = 0);
00472
00473 DLLLOCAL LocalVar *createLocalVar(const char *name, const QoreTypeInfo *typeInfo);
00474
00475 DLLLOCAL void registerUserFunctionVariant(char *name, UserFunctionVariant *variant);
00476
00477
00478 DLLLOCAL const AbstractQoreFunction *resolveFunction(const char *name, QoreProgram *&pgm);
00479
00480 DLLLOCAL AbstractCallReferenceNode *resolveCallReference(UnresolvedCallReferenceNode *fr);
00481 DLLLOCAL Var *addGlobalVarDef(const char *name, QoreParseTypeInfo *typeInfo);
00482 DLLLOCAL Var *addResolvedGlobalVarDef(const char *name, const QoreTypeInfo *typeInfo);
00483 DLLLOCAL void addStatement(AbstractStatement *s);
00484 DLLLOCAL Var *findGlobalVar(const char *name);
00485 DLLLOCAL const Var *findGlobalVar(const char *name) const;
00486 DLLLOCAL Var *checkGlobalVar(const char *name, const QoreTypeInfo *typeInfo);
00487 DLLLOCAL void importGlobalVariable(Var *var, ExceptionSink *xsink, bool readonly);
00488 DLLLOCAL void makeParseException(const char *err, QoreStringNode *desc);
00489 DLLLOCAL void makeParseException(int sline, int eline, QoreStringNode *desc);
00490 DLLLOCAL void makeParseException(int sline, int eline, const char *file, QoreStringNode *desc);
00491 DLLLOCAL void makeParseException(QoreStringNode *desc);
00492
00493 DLLLOCAL void addParseException(ExceptionSink *xsink);
00494
00495 DLLLOCAL ExceptionSink *getParseExceptionSink();
00496 DLLLOCAL void makeParseWarning(int sline, int eline, const char *file, int code, const char *warn, const char *fmt, ...);
00497 DLLLOCAL void makeParseWarning(int code, const char *warn, const char *fmt, ...);
00498
00499 DLLLOCAL void makeParseWarning(int code, const char *warn, QoreStringNode *desc);
00500 DLLLOCAL void addParseWarning(int code, ExceptionSink *xsink);
00501 DLLLOCAL void cannotProvideFeature(QoreStringNode *desc);
00502 DLLLOCAL void exportUserFunction(const char *name, QoreProgram *p, ExceptionSink *xsink);
00503 DLLLOCAL void exportUserFunction(const char *name, const char *new_name, QoreProgram *p, ExceptionSink *xsink);
00504 DLLLOCAL void endThread(ExceptionSink *xsink);
00505 DLLLOCAL void startThread();
00506 DLLLOCAL QoreHashNode *getThreadData();
00507 DLLLOCAL void depRef();
00508 DLLLOCAL void depDeref(ExceptionSink *xsink);
00509 DLLLOCAL void addFeature(const char *f);
00510 DLLLOCAL void addFile(char *f);
00511 DLLLOCAL QoreListNode *getVarList();
00512 DLLLOCAL void parseSetIncludePath(const char *path);
00513 DLLLOCAL const char *parseGetIncludePath() const;
00514
00515
00516 DLLLOCAL void tc_inc();
00517
00518
00519 DLLLOCAL void tc_dec();
00520
00521
00522
00523
00524
00525 DLLLOCAL QoreThreadLock *getParseLock();
00526 DLLLOCAL QoreHashNode *clearThreadData(ExceptionSink *xsink);
00527 DLLLOCAL const LVList *getTopLevelLVList() const;
00528
00530
00532 DLLLOCAL const char *parseGetScriptDir() const;
00533 };
00534
00536 class QoreProgramHelper {
00537 private:
00538 QoreProgram *pgm;
00539 ExceptionSink &xsink;
00540
00541 public:
00543 DLLLOCAL QoreProgramHelper(ExceptionSink &xs) : pgm(new QoreProgram), xsink(xs) {
00544 }
00545
00547 DLLLOCAL QoreProgramHelper(int64 parse_options, ExceptionSink &xs) : pgm(new QoreProgram(parse_options)), xsink(xs) {
00548 }
00549
00551
00553 DLLLOCAL ~QoreProgramHelper() {
00554 pgm->waitForTerminationAndDeref(&xsink);
00555 }
00556
00558 DLLLOCAL QoreProgram* operator->() { return pgm; }
00559
00561 DLLLOCAL QoreProgram* operator*() { return pgm; }
00562 };
00563
00564 #endif // _QORE_QOREPROGRAM_H