32 #ifndef _QORE_STATEMENT_BLOCK_H 34 #define _QORE_STATEMENT_BLOCK_H 36 #include "qore/intern/AbstractStatement.h" 37 #include <qore/safe_dslist> 49 typedef std::vector<LocalVar*> lv_vec_t;
52 DLLLOCAL LVList(
int num) {
56 DLLLOCAL LVList(
const LVList& old) {
57 lv.resize(old.size());
58 for (
unsigned i = 0; i < old.size(); ++i)
71 DLLLOCAL
void add(
int num) {
73 unsigned start = lv.size();
75 lv.resize(start + num);
77 for (
int i = (
int)(start + num - 1); i >= (int)start; --i) {
78 lv[i] = pop_local_var();
84 class LVListInstantiator {
89 DLLLOCAL LVListInstantiator(
const LVList* n_l,
ExceptionSink* xs) : l(n_l), xsink(xs) {
91 for (
unsigned i = 0; i < l->size(); ++i) {
93 l->lv[i]->instantiate();
97 DLLLOCAL ~LVListInstantiator() {
99 for (
int i = (
int)l->size() - 1; i >= 0; --i) {
101 l->lv[i]->uninstantiate(xsink);
107 class qore_program_private_base;
109 class StatementBlock :
public AbstractStatement {
111 typedef safe_dslist<AbstractStatement*> statement_list_t;
112 statement_list_t statement_list;
113 block_list_t on_block_exit_list;
114 LVList* lvars =
nullptr;
117 DLLLOCAL
int parseInitIntern(LocalVar* oflag,
int pflag, statement_list_t::iterator start);
118 DLLLOCAL
void parseCommitIntern(statement_list_t::iterator start);
119 DLLLOCAL
bool hasLastReturn(AbstractStatement* as);
120 DLLLOCAL
void parseCheckReturn();
124 DLLLOCAL StatementBlock(qore_program_private_base* p);
127 DLLLOCAL StatementBlock(
int sline,
int eline);
130 DLLLOCAL StatementBlock(
int sline,
int eline, AbstractStatement* s);
132 DLLLOCAL
virtual ~StatementBlock() {
137 DLLLOCAL
virtual int parseInitImpl(LocalVar* oflag,
int pflag = 0);
141 DLLLOCAL
void addStatement(AbstractStatement* s);
143 using AbstractStatement::exec;
146 using AbstractStatement::parseInit;
147 DLLLOCAL
void parseInit(UserVariantBase* uvb);
150 DLLLOCAL
void parseInitMethod(
const QoreTypeInfo* typeInfo, UserVariantBase* uvb);
151 DLLLOCAL
void parseInitConstructor(
const QoreTypeInfo* typeInfo, UserVariantBase* uvb, BCAList* bcal,
const QoreClass& cls);
154 DLLLOCAL
void parseInitClosure(UserVariantBase* uvb, UserClosureFunction* cf);
156 DLLLOCAL
virtual void parseCommit(
QoreProgram* pgm);
158 DLLLOCAL
void exec();
160 DLLLOCAL
const LVList* getLVList()
const {
164 DLLLOCAL
virtual bool hasFinalReturn()
const {
165 if (statement_list.empty())
168 return (*statement_list.last())->hasFinalReturn();
171 DLLLOCAL
void setupLVList(
int lvids) {
176 lvars =
new LVList(lvids);
180 class TopLevelStatementBlock :
public StatementBlock {
183 statement_list_t::iterator hwm;
188 DLLLOCAL TopLevelStatementBlock(qore_program_private_base* p) : StatementBlock(p), hwm(statement_list.end()), first(true) {
191 DLLLOCAL
virtual ~TopLevelStatementBlock() {
194 using StatementBlock::parseInit;
195 DLLLOCAL
void parseInit();
197 DLLLOCAL
virtual void parseCommit(
QoreProgram* pgm);
199 DLLLOCAL
void parseRollback() {
201 statement_list_t::iterator start = hwm;
202 if (start != statement_list.end())
205 start = statement_list.begin();
207 for (statement_list_t::iterator i = start, e = statement_list.end(); i != e; ++i)
210 statement_list.erase_to_end(hwm);
217 DLLLOCAL
void assignLocalVars(
const LVList* lvl) {
219 lvars =
new LVList(*lvl);
222 DLLLOCAL
void setupLVList(
int lvids) {
229 lvars =
new LVList(lvids);
239 DLLLOCAL VNode(LocalVar* lv,
const QoreProgramLocation* n_loc =
nullptr,
int n_refs = 0,
240 bool n_top_level =
false);
244 DLLLOCAL
void appendLocation(
QoreString& str);
246 DLLLOCAL
void setRef() {
250 DLLLOCAL
bool setBlockStart(
bool bs =
true) {
251 bool rc = block_start;
256 DLLLOCAL
bool isBlockStart()
const {
260 DLLLOCAL
bool isReferenced()
const {
264 DLLLOCAL
int refCount()
const {
268 DLLLOCAL
bool isTopLevel()
const {
272 DLLLOCAL
const char* getName()
const;
275 DLLLOCAL VNode* nextSearch()
const;
282 const QoreProgramLocation* loc;
287 #endif // _QORE_STATEMENT_BLOCK_H size_t qore_size_t
used for sizes (same range as a pointer)
Definition: common.h:73
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
defines a Qore-language class
Definition: QoreClass.h:239
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only ...
Definition: QoreProgram.h:126
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:46