All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
QoreProgram.h
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
QoreProgram.h
Program Object Definition
Qore Programming Language
Copyright 2003 - 2013 David Nichols
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _QORE_QOREPROGRAM_H
#define _QORE_QOREPROGRAM_H
#include <qore/AbstractPrivateData.h>
#include <qore/Restrictions.h>
// warnings - must correspond with the string order in QoreProgram.cpp
// new warnings must also be added as constants
#define QP_WARN_NONE 0
#define QP_WARN_WARNING_MASK_UNCHANGED (1 << 0)
#define QP_WARN_DUPLICATE_LOCAL_VARS (1 << 1)
#define QP_WARN_UNKNOWN_WARNING (1 << 2)
#define QP_WARN_UNDECLARED_VAR (1 << 3)
#define QP_WARN_DUPLICATE_GLOBAL_VARS (1 << 4)
#define QP_WARN_UNREACHABLE_CODE (1 << 5)
#define QP_WARN_NONEXISTENT_METHOD_CALL (1 << 6)
#define QP_WARN_INVALID_OPERATION (1 << 7)
#define QP_WARN_CALL_WITH_TYPE_ERRORS (1 << 8)
#define QP_WARN_RETURN_VALUE_IGNORED (1 << 9)
#define QP_WARN_DEPRECATED (1 << 10)
#define QP_WARN_EXCESS_ARGS (1 << 11)
#define QP_WARN_DUPLICATE_HASH_KEY (1 << 12)
#define QP_WARN_UNREFERENCED_VARIABLE (1 << 13)
#define QP_WARN_DUPLICATE_BLOCK_VARS (1 << 14)
#define QP_WARN_MODULE_ONLY (1 << 15)
#define QP_WARN_ALL -1
#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)
#define QP_WARN_DEFAULT (QP_WARN_UNKNOWN_WARNING|QP_WARN_MODULES|QP_WARN_DEPRECATED)
DLLEXPORT extern const char** qore_warnings;
DLLEXPORT extern unsigned qore_num_warnings;
DLLEXPORT int get_warning_code(const char* str);
class AbstractCallReferenceNode;
class LocalVar;
class ExceptionSink;
class QoreListNode;
class QoreNamespace;
class RootQoreNamespace;
class QoreStringNode;
class QoreHashNode;
class FunctionCallNode;
class AbstractStatement;
class UnresolvedProgramCallReferenceNode;
class Var;
class LVList;
class UserFunctionVariant;
class QoreTypeInfo;
class QoreParseTypeInfo;
class ParamList;
class AbstractQoreZoneInfo;
class qore_program_private;
class QoreProgram : public AbstractPrivateData {
friend class qore_program_private_base;
friend class qore_program_private;
private:
qore_program_private* priv;
DLLLOCAL QoreProgram(const QoreProgram&);
DLLLOCAL QoreProgram& operator=(const QoreProgram&);
protected:
DLLLOCAL virtual ~QoreProgram();
public:
DLLEXPORT QoreProgram();
DLLEXPORT QoreProgram(int64 parse_options);
DLLEXPORT AbstractQoreNode* callFunction(const char* name, const QoreListNode* args, ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* run(ExceptionSink* xsink);
DLLEXPORT AbstractQoreNode* runTopLevel(ExceptionSink* xsink);
DLLEXPORT void parseFileAndRun(const char* filename);
DLLEXPORT void parseAndRun(FILE *fp, const char* name);
DLLEXPORT void parseAndRun(const char* str, const char* name);
DLLEXPORT void runClass(const char* classname, ExceptionSink* xsink);
DLLEXPORT void parseFileAndRunClass(const char* filename, const char* classname);
DLLEXPORT void parseAndRunClass(FILE *fp, const char* name, const char* classname);
DLLEXPORT void parseAndRunClass(const char* str, const char* name, const char* classname);
DLLEXPORT void parse(FILE *fp, const char* name, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
DLLEXPORT void parse(const QoreString* str, const QoreString* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
DLLEXPORT void parse(const QoreString* str, const QoreString* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink, int warn_mask, const QoreString* source, int offset);
DLLEXPORT void parse(const char* str, const char* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
DLLEXPORT void parse(const char* str, const char* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink, int warn_mask, const char* source, int offset);
DLLEXPORT void parseFile(const char* filename, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL, bool only_first_except = false);
DLLEXPORT void parsePending(const char* code, const char* label, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
DLLEXPORT void parsePending(const char* code, const char* label, ExceptionSink* xsink, ExceptionSink* warn_sink, int warn_mask, const char* source, int offset);
DLLEXPORT void parsePending(const QoreString* str, const QoreString* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
DLLEXPORT void parsePending(const QoreString* str, const QoreString* lstr, ExceptionSink* xsink, ExceptionSink* warn_sink, int warn_mask, const QoreString* source, int offset);
DLLEXPORT void parseCommit(ExceptionSink* xsink, ExceptionSink* warn_sink = 0, int warn_mask = QP_WARN_ALL);
DLLEXPORT void parseRollback();
DLLEXPORT bool existsFunction(const char* name);
using AbstractPrivateData::deref;
DLLEXPORT virtual void deref(ExceptionSink* xsink);
DLLEXPORT void lockOptions();
DLLEXPORT void setExecClass(const char* ecn = 0);
DLLEXPORT void parseSetParseOptions(int po);
DLLEXPORT void parseSetParseOptions(int64 po);
DLLEXPORT void parseDisableParseOptions(int64 po);
DLLEXPORT void waitForTermination();
DLLEXPORT void waitForTerminationAndDeref(ExceptionSink* xsink);
DLLEXPORT QoreNamespace* getQoreNS() const;
DLLEXPORT RootQoreNamespace* getRootNS() const;
DLLEXPORT int setWarningMask(int wm);
DLLEXPORT int enableWarning(int code);
DLLEXPORT int disableWarning(int code);
DLLEXPORT int getParseOptions() const;
DLLEXPORT int64 getParseOptions64() const;
DLLEXPORT void setParseOptions(int po, ExceptionSink* xsink);
DLLEXPORT void setParseOptions(int64 po, ExceptionSink* xsink);
DLLEXPORT void disableParseOptions(int po, ExceptionSink* xsink);
DLLEXPORT void disableParseOptions(int64 po, ExceptionSink* xsink);
DLLEXPORT void replaceParseOptions(int64 po, ExceptionSink* xsink);
DLLEXPORT QoreListNode* getUserFunctionList();
DLLEXPORT bool checkWarning(int code) const;
DLLEXPORT int getWarningMask() const;
DLLEXPORT bool checkFeature(const char* f) const;
DLLEXPORT QoreListNode* getFeatureList() const;
DLLEXPORT QoreStringNode* getScriptName() const;
DLLEXPORT QoreStringNode* getScriptPath() const;
DLLEXPORT QoreStringNode* getScriptDir() const;
DLLEXPORT void setScriptPath(const char* path);
DLLEXPORT AbstractQoreNode* getGlobalVariableValue(const char* var, bool &found) const;
// retrieves the time zone setting for the program
DLLEXPORT const AbstractQoreZoneInfo *currentTZ() const;
// sets the program's time zone
DLLEXPORT void setTZ(const AbstractQoreZoneInfo *n_TZ);
DLLEXPORT void addFeature(const char* name);
DLLEXPORT void parseSetTimeZone(const char* zone);
DLLEXPORT void parseDefine(const char* str, AbstractQoreNode* val);
DLLEXPORT void parseDefine(const char* str, const char* val);
DLLLOCAL QoreProgram(QoreProgram* pgm, int64 po, bool ec = false, const char* ecn = 0);
DLLLOCAL LocalVar *createLocalVar(const char* name, const QoreTypeInfo *typeInfo);
// returns 0 if a "requires" exception has already occurred
DLLLOCAL ExceptionSink* getParseExceptionSink();
DLLLOCAL QoreHashNode* getThreadData();
DLLLOCAL void depRef();
DLLLOCAL void depDeref(ExceptionSink* xsink);
DLLLOCAL void addFile(char* f);
DLLLOCAL QoreListNode* getVarList();
DLLLOCAL void parseSetIncludePath(const char* path);
DLLLOCAL const char* parseGetIncludePath() const;
/* for run-time module loading; the parse lock must be grabbed
before loading new modules - note this should only be assigned
to an AutoLock or SafeLocker object!
*/
DLLLOCAL QoreThreadLock *getParseLock();
DLLLOCAL QoreHashNode* clearThreadData(ExceptionSink* xsink);
DLLLOCAL const LVList* getTopLevelLVList() const;
DLLLOCAL const char* parseGetScriptDir() const;
// can only be called while parsing from the same thread doing the parsing
DLLLOCAL bool parseExceptionRaised() const;
};
class QoreProgramHelper {
private:
QoreProgram* pgm;
ExceptionSink& xsink;
public:
DLLLOCAL QoreProgramHelper(ExceptionSink& xs) : pgm(new QoreProgram), xsink(xs) {
}
DLLLOCAL QoreProgramHelper(int64 parse_options, ExceptionSink& xs) : pgm(new QoreProgram(parse_options)), xsink(xs) {
}
DLLLOCAL ~QoreProgramHelper() {
// waits for all background threads to execute
thread_counter.waitForZero(&xsink);
// waits for the current Program to terminate
pgm->waitForTerminationAndDeref(&xsink);
}
DLLLOCAL QoreProgram* operator->() { return pgm; }
DLLLOCAL QoreProgram* operator*() { return pgm; }
};
#endif // _QORE_QOREPROGRAM_H