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* l,
ExceptionSink* xs) : l(l) {
92 for (
unsigned i = 0; i < l->size(); ++i) {
94 l->lv[i]->instantiate();
98 DLLLOCAL ~LVListInstantiator() {
100 for (
int i = (
int)l->size() - 1; i >= 0; --i) {
102 l->lv[i]->uninstantiate(xsink);
108 class qore_program_private_base;
110 class StatementBlock :
public AbstractStatement {
112 typedef safe_dslist<AbstractStatement*> statement_list_t;
113 statement_list_t statement_list;
114 block_list_t on_block_exit_list;
115 LVList* lvars =
nullptr;
118 DLLLOCAL
int parseInitIntern(LocalVar* oflag,
int pflag, statement_list_t::iterator start);
119 DLLLOCAL
void parseCommitIntern(statement_list_t::iterator start);
120 DLLLOCAL
bool hasLastReturn(AbstractStatement* as);
121 DLLLOCAL
void parseCheckReturn();
125 DLLLOCAL StatementBlock(qore_program_private_base* p);
128 DLLLOCAL StatementBlock(
int sline,
int eline);
131 DLLLOCAL StatementBlock(
int sline,
int eline, AbstractStatement* s);
133 DLLLOCAL
virtual ~StatementBlock() {
138 DLLLOCAL
virtual int parseInitImpl(LocalVar* oflag,
int pflag = 0);
142 DLLLOCAL
void addStatement(AbstractStatement* s);
144 using AbstractStatement::exec;
147 using AbstractStatement::parseInit;
148 DLLLOCAL
void parseInit(UserVariantBase* uvb);
151 DLLLOCAL
void parseInitMethod(
const QoreTypeInfo* typeInfo, UserVariantBase* uvb);
152 DLLLOCAL
void parseInitConstructor(
const QoreTypeInfo* typeInfo, UserVariantBase* uvb, BCAList* bcal,
const QoreClass& cls);
155 DLLLOCAL
void parseInitClosure(UserVariantBase* uvb, UserClosureFunction* cf);
157 DLLLOCAL
virtual void parseCommit(
QoreProgram* pgm);
159 DLLLOCAL
void exec();
161 DLLLOCAL
const LVList* getLVList()
const {
165 DLLLOCAL
virtual bool hasFinalReturn()
const {
166 if (statement_list.empty())
169 return (*statement_list.last())->hasFinalReturn();
172 DLLLOCAL
void setupLVList(
int lvids) {
177 lvars =
new LVList(lvids);
181 class TopLevelStatementBlock :
public StatementBlock {
184 statement_list_t::iterator hwm;
189 DLLLOCAL TopLevelStatementBlock(qore_program_private_base* p) : StatementBlock(p), hwm(statement_list.end()), first(true) {
192 DLLLOCAL
virtual ~TopLevelStatementBlock() {
195 using StatementBlock::parseInit;
196 DLLLOCAL
void parseInit();
198 DLLLOCAL
virtual void parseCommit(
QoreProgram* pgm);
200 DLLLOCAL
void parseRollback() {
202 statement_list_t::iterator start = hwm;
203 if (start != statement_list.end())
206 start = statement_list.begin();
208 for (statement_list_t::iterator i = start, e = statement_list.end(); i != e; ++i)
211 statement_list.erase_to_end(hwm);
218 DLLLOCAL
void assignLocalVars(
const LVList* lvl) {
220 lvars =
new LVList(*lvl);
223 DLLLOCAL
void setupLVList(
int lvids) {
230 lvars =
new LVList(lvids);
240 DLLLOCAL VNode(LocalVar* lv,
const QoreProgramLocation* n_loc =
nullptr,
int n_refs = 0,
241 bool n_top_level =
false);
245 DLLLOCAL
void appendLocation(
QoreString& str);
247 DLLLOCAL
void setRef() {
251 DLLLOCAL
bool setBlockStart(
bool bs =
true) {
252 bool rc = block_start;
257 DLLLOCAL
bool isBlockStart()
const {
261 DLLLOCAL
bool isReferenced()
const {
265 DLLLOCAL
int refCount()
const {
269 DLLLOCAL
bool isTopLevel()
const {
273 DLLLOCAL
const char* getName()
const;
276 DLLLOCAL VNode* nextSearch()
const;
283 const QoreProgramLocation* loc;
288 #endif // _QORE_STATEMENT_BLOCK_H