Qore Programming Language 1.19.1
Loading...
Searching...
No Matches
AbstractStatement.h
1/* -*- mode: c++; indent-tabs-mode: nil -*- */
2/*
3 AbstractStatement.h
4
5 Qore Programming Language
6
7 Copyright (C) 2003 - 2023 Qore Technologies, s.r.o.
8
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the "Software"),
11 to deal in the Software without restriction, including without limitation
12 the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26
27 Note that the Qore library is released under a choice of three open-source
28 licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29 information.
30*/
31
32#ifndef _QORE_ABSTRACTSTATEMENT_H
33
34#define _QORE_ABSTRACTSTATEMENT_H
35
36#include <qore/common.h>
37
38#define RC_RETURN 1
39#define RC_BREAK 2
40#define RC_CONTINUE 3
41
42#define PF_RETURN_VALUE_IGNORED (1 << 0)
43#define PF_BACKGROUND (1 << 1)
44#define PF_RETHROW_OK (1 << 2)
45#define PF_FOR_ASSIGNMENT (1 << 3)
46#define PF_CONST_EXPRESSION (1 << 4)
47#define PF_TOP_LEVEL (1 << 5)
48#define PF_BREAK_OK (1 << 6)
49#define PF_CONTINUE_OK (1 << 7)
50#define PF_NO_TOP_LEVEL_LVARS (1 << 8)
51
52// all definitions in this file are private to the library and subject to change
53// forward references
54class LVList;
55class StatementBlock;
56class QoreBreakpoint;
57
58// forward declaration
59class qore_program_private_base;
60
61class AbstractStatement {
62public:
63 const QoreProgramLocation* loc;
64 hashdecl ParseWarnOptions pwo;
65
66 DLLLOCAL AbstractStatement(qore_program_private_base* p);
67
68 DLLLOCAL AbstractStatement(const QoreProgramLocation* loc);
69 DLLLOCAL AbstractStatement(int sline, int eline);
70 DLLLOCAL virtual ~AbstractStatement();
71
72 DLLLOCAL int exec(QoreValue& return_value, ExceptionSink* xsink);
73 DLLLOCAL int parseInit(QoreParseContext& parse_context);
74
75 DLLLOCAL void finalizeBlock(int sline, int eline);
76
77 DLLLOCAL bool getBreakpointFlag() const {
78 return breakpointFlag;
79 }
80
81 // statement should return true if it ends a block (break, continue, return, throw, etc)
82 // meaning that any subsequent statements will be unconditionally skipped
83 DLLLOCAL virtual bool endsBlock() const {
84 return false;
85 }
86
87 // should return true if the statement is a declaration processed at parse time and should not go into the parse
88 // tree
89 DLLLOCAL virtual bool isParseDeclaration() const {
90 return false;
91 }
92
93 // should return true if the statement is a declaration and does not represent an executable statement
94 DLLLOCAL virtual bool isDeclaration() const {
95 return false;
96 }
97
98 DLLLOCAL virtual bool hasFinalReturn() const {
99 return false;
100 }
101
102 DLLLOCAL virtual void parseCommit(QoreProgram* pgm);
103
104private:
105 QoreBreakpointList_t* breakpoints = nullptr;
106 volatile bool breakpointFlag = false; // fast access to check if breakpoints are non-empty
107
108 DLLLOCAL virtual int execImpl(QoreValue& return_value, ExceptionSink* xsink) = 0;
109
111 DLLLOCAL virtual int parseInitImpl(QoreParseContext& parse_context) = 0;
112
113 friend class qore_program_private;
114 // executed when qore_program_private::lck_breakpoint lock is acquired
115 DLLLOCAL QoreBreakpoint* getBreakpoint() const;
116
117 friend class QoreBreakpoint;
118 DLLLOCAL void assignBreakpoint(QoreBreakpoint *bkpt);
119 DLLLOCAL void unassignBreakpoint(QoreBreakpoint *bkpt);
120};
121
122DLLLOCAL void push_cvar(const char* name);
123DLLLOCAL void pop_cvar();
124DLLLOCAL LocalVar* pop_local_var(bool set_unassigned = false);
125DLLLOCAL int pop_local_var_get_id();
126// used for constructor methods sharing a common "self" local variable and for top-level local variables
127DLLLOCAL void push_local_var(LocalVar* lv, const QoreProgramLocation* loc);
128
129// push a local variable on the stack at parse time
139DLLLOCAL LocalVar* push_local_var(const char* name, const QoreProgramLocation* loc, const QoreTypeInfo* typeInfo,
140 int& err, bool is_auto = true, int n_refs = 0, int pflag = 0);
141
142DLLLOCAL LocalVar* find_local_var(const char* name, bool &in_closure);
143
144#endif // _QORE_ABSTRACTSTATEMENT_H
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:50
Class implementing breakpoint for debugging.
Definition: QoreProgram.h:1040
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only
Definition: QoreProgram.h:128
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:276