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();
84class LVListInstantiator {
90 DLLLOCAL LVListInstantiator(
ExceptionSink* xs,
const LVList* l,
int64 parse_options) : l(l) {
94 for (
unsigned i = 0; i < l->size(); ++i) {
97 l->lv[i]->instantiate(parse_options);
101 DLLLOCAL ~LVListInstantiator() {
103 for (
int i = (
int)l->size() - 1; i >= 0; --i) {
106 l->lv[i]->uninstantiate(xsink);
112class qore_program_private_base;
114class StatementBlock :
public AbstractStatement {
116 DLLLOCAL StatementBlock(
int sline,
int eline);
119 DLLLOCAL StatementBlock(
int sline,
int eline, AbstractStatement* s);
121 DLLLOCAL
virtual ~StatementBlock() {
126 DLLLOCAL
virtual int parseInitImpl(QoreParseContext& parse_context);
130 DLLLOCAL
void addStatement(AbstractStatement* s);
132 using AbstractStatement::exec;
135 using AbstractStatement::parseInit;
136 DLLLOCAL
int parseInit(UserVariantBase* uvb);
139 DLLLOCAL
int parseInitMethod(
const QoreTypeInfo* typeInfo, UserVariantBase* uvb);
140 DLLLOCAL
int parseInitConstructor(
const QoreTypeInfo* typeInfo, UserVariantBase* uvb, BCAList* bcal,
144 DLLLOCAL
int parseInitClosure(UserVariantBase* uvb, UserClosureFunction* cf);
146 DLLLOCAL
virtual void parseCommit(
QoreProgram* pgm);
148 DLLLOCAL
void exec();
150 DLLLOCAL
const LVList* getLVList()
const {
154 DLLLOCAL
virtual bool hasFinalReturn()
const {
155 if (statement_list.empty())
158 return (*statement_list.last())->hasFinalReturn();
161 DLLLOCAL
void setupLVList(QoreParseContext& parse_context) {
163 if (!parse_context.lvids) {
167 lvars =
new LVList(parse_context.lvids);
168 parse_context.lvids = 0;
172 typedef safe_dslist<AbstractStatement*> statement_list_t;
173 statement_list_t statement_list;
174 block_list_t on_block_exit_list;
175 LVList* lvars =
nullptr;
178 DLLLOCAL
int parseInitIntern(QoreParseContext& parse_context, statement_list_t::iterator start);
179 DLLLOCAL
void parseCommitIntern(statement_list_t::iterator start);
180 DLLLOCAL
bool hasLastReturn(AbstractStatement* as);
181 DLLLOCAL
int parseCheckReturn();
185 DLLLOCAL StatementBlock(qore_program_private_base* p);
188class TopLevelStatementBlock :
public StatementBlock {
190 DLLLOCAL TopLevelStatementBlock(qore_program_private_base* p) : StatementBlock(p), hwm(statement_list.end()),
194 DLLLOCAL
virtual ~TopLevelStatementBlock() {
197 using StatementBlock::parseInit;
198 DLLLOCAL
int parseInit();
200 DLLLOCAL
virtual void parseCommit(
QoreProgram* pgm);
202 DLLLOCAL
void parseRollback() {
204 statement_list_t::iterator start = hwm;
205 if (start != statement_list.end())
208 start = statement_list.begin();
210 for (statement_list_t::iterator i = start, e = statement_list.end(); i != e; ++i)
213 statement_list.erase_to_end(hwm);
220 DLLLOCAL
void assignLocalVars(
const LVList* lvl) {
222 lvars =
new LVList(*lvl);
225 DLLLOCAL
void setupLVList(QoreParseContext& parse_context) {
226 if (!parse_context.lvids) {
231 lvars->add(parse_context.lvids);
233 lvars =
new LVList(parse_context.lvids);
235 parse_context.lvids = 0;
240 statement_list_t::iterator hwm;
251 DLLLOCAL VNode(LocalVar* lv,
const QoreProgramLocation* n_loc =
nullptr,
int n_refs = 0,
252 bool n_top_level =
false);
256 DLLLOCAL
void appendLocation(
QoreString& str);
258 DLLLOCAL
void setRef() {
262 DLLLOCAL
bool setBlockStart(
bool bs =
true) {
263 bool rc = block_start;
268 DLLLOCAL
bool isBlockStart()
const {
272 DLLLOCAL
bool isReferenced()
const {
276 DLLLOCAL
int refCount()
const {
280 DLLLOCAL
bool isTopLevel()
const {
284 DLLLOCAL
const char* getName()
const;
287 DLLLOCAL VNode* nextSearch()
const;
294 const QoreProgramLocation* loc;
299class CatchExceptionHelper {
304 DLLLOCAL CatchExceptionHelper(QoreException* n_e) : e(catch_swap_exception(n_e)) {
307 DLLLOCAL ~CatchExceptionHelper() {
308 catch_swap_exception(e);
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:50
defines a Qore-language class
Definition: QoreClass.h:257
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only
Definition: QoreProgram.h:128
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
long long int64
64bit integer type, cannot use int64_t here since it breaks the API on some 64-bit systems due to equ...
Definition: common.h:260
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:279