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)
67 DLLLOCAL
size_t size()
const {
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) {
95 l->lv[i]->instantiate();
99 DLLLOCAL ~LVListInstantiator() {
101 for (
int i = (
int)l->size() - 1; i >= 0; --i) {
104 l->lv[i]->uninstantiate(xsink);
110 class qore_program_private_base;
112 class StatementBlock :
public AbstractStatement {
114 DLLLOCAL StatementBlock(
int sline,
int eline);
117 DLLLOCAL StatementBlock(
int sline,
int eline, AbstractStatement* s);
119 DLLLOCAL
virtual ~StatementBlock() {
124 DLLLOCAL
virtual int parseInitImpl(QoreParseContext& parse_context);
128 DLLLOCAL
void addStatement(AbstractStatement* s);
130 using AbstractStatement::exec;
133 using AbstractStatement::parseInit;
134 DLLLOCAL
int parseInit(UserVariantBase* uvb);
137 DLLLOCAL
int parseInitMethod(
const QoreTypeInfo* typeInfo, UserVariantBase* uvb);
138 DLLLOCAL
int parseInitConstructor(
const QoreTypeInfo* typeInfo, UserVariantBase* uvb, BCAList* bcal,
142 DLLLOCAL
int parseInitClosure(UserVariantBase* uvb, UserClosureFunction* cf);
144 DLLLOCAL
virtual void parseCommit(
QoreProgram* pgm);
146 DLLLOCAL
void exec();
148 DLLLOCAL
const LVList* getLVList()
const {
152 DLLLOCAL
virtual bool hasFinalReturn()
const {
153 if (statement_list.empty())
156 return (*statement_list.last())->hasFinalReturn();
159 DLLLOCAL
void setupLVList(QoreParseContext& parse_context) {
161 if (!parse_context.lvids) {
165 lvars =
new LVList(parse_context.lvids);
166 parse_context.lvids = 0;
170 typedef safe_dslist<AbstractStatement*> statement_list_t;
171 statement_list_t statement_list;
172 block_list_t on_block_exit_list;
173 LVList* lvars =
nullptr;
176 DLLLOCAL
int parseInitIntern(QoreParseContext& parse_context, statement_list_t::iterator start);
177 DLLLOCAL
void parseCommitIntern(statement_list_t::iterator start);
178 DLLLOCAL
bool hasLastReturn(AbstractStatement* as);
179 DLLLOCAL
int parseCheckReturn();
183 DLLLOCAL StatementBlock(qore_program_private_base* p);
186 class TopLevelStatementBlock :
public StatementBlock {
188 DLLLOCAL TopLevelStatementBlock(qore_program_private_base* p) : StatementBlock(p), hwm(statement_list.end()),
192 DLLLOCAL
virtual ~TopLevelStatementBlock() {
195 using StatementBlock::parseInit;
196 DLLLOCAL
int 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(QoreParseContext& parse_context) {
224 if (!parse_context.lvids) {
229 lvars->add(parse_context.lvids);
231 lvars =
new LVList(parse_context.lvids);
233 parse_context.lvids = 0;
238 statement_list_t::iterator hwm;
249 DLLLOCAL VNode(LocalVar* lv,
const QoreProgramLocation* n_loc =
nullptr,
int n_refs = 0,
250 bool n_top_level =
false);
254 DLLLOCAL
void appendLocation(
QoreString& str);
256 DLLLOCAL
void setRef() {
260 DLLLOCAL
bool setBlockStart(
bool bs =
true) {
261 bool rc = block_start;
266 DLLLOCAL
bool isBlockStart()
const {
270 DLLLOCAL
bool isReferenced()
const {
274 DLLLOCAL
int refCount()
const {
278 DLLLOCAL
bool isTopLevel()
const {
282 DLLLOCAL
const char* getName()
const;
285 DLLLOCAL VNode* nextSearch()
const;
292 const QoreProgramLocation* loc;
297 class CatchExceptionHelper {
302 DLLLOCAL CatchExceptionHelper(QoreException* n_e) : e(catch_swap_exception(n_e)) {
305 DLLLOCAL ~CatchExceptionHelper() {
306 catch_swap_exception(e);
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
defines a Qore-language class
Definition: QoreClass.h:249
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only
Definition: QoreProgram.h:127
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:275