Qore Programming Language  0.9.16
AbstractStatement.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  AbstractStatement.h
4 
5  Qore Programming Language
6 
7  Copyright (C) 2003 - 2020 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
54 class LVList;
55 class StatementBlock;
56 class QoreBreakpoint;
57 
58 // forward declaration
59 class qore_program_private_base;
60 
61 class AbstractStatement {
62 private:
63  volatile bool breakpointFlag; // fast access to check if breakpoints are non-empty
64  QoreBreakpointList_t *breakpoints;
65 
66  DLLLOCAL virtual int execImpl(QoreValue& return_value, ExceptionSink* xsink) = 0;
67  DLLLOCAL virtual int parseInitImpl(LocalVar* oflag, int pflag = 0) = 0;
68 
69  friend class qore_program_private;
70  // executed when qore_program_private::lck_breakpoint lock is acquired
71  DLLLOCAL QoreBreakpoint* getBreakpoint() const;
72 
73  friend class QoreBreakpoint;
74  DLLLOCAL void assignBreakpoint(QoreBreakpoint *bkpt);
75  DLLLOCAL void unassignBreakpoint(QoreBreakpoint *bkpt);
76 
77 public:
78  const QoreProgramLocation* loc;
79  hashdecl ParseWarnOptions pwo;
80 
81  DLLLOCAL AbstractStatement(qore_program_private_base* p);
82 
83  DLLLOCAL AbstractStatement(const QoreProgramLocation* loc);
84  DLLLOCAL AbstractStatement(int sline, int eline);
85  DLLLOCAL virtual ~AbstractStatement();
86 
87  DLLLOCAL int exec(QoreValue& return_value, ExceptionSink* xsink);
88  DLLLOCAL int parseInit(LocalVar* oflag, int pflag = 0);
89 
90  DLLLOCAL void finalizeBlock(int sline, int eline);
91 
92  DLLLOCAL bool getBreakpointFlag() const {
93  return breakpointFlag;
94  }
95 
96  // statement should return true if it ends a block (break, continue, return, throw, etc)
97  // meaning that any subsequent statements will be unconditionally skipped
98  DLLLOCAL virtual bool endsBlock() const {
99  return false;
100  }
101 
102  // should return true if the statement is a declaration processed at parse time and should not go into the parse tree
103  DLLLOCAL virtual bool isParseDeclaration() const {
104  return false;
105  }
106 
107  // should return true if the statement is a declaration and does not represent an executable statement
108  DLLLOCAL virtual bool isDeclaration() const {
109  return false;
110  }
111 
112  DLLLOCAL virtual bool hasFinalReturn() const {
113  return false;
114  }
115 
116  DLLLOCAL virtual void parseCommit(QoreProgram* pgm);
117 };
118 
119 DLLLOCAL void push_cvar(const char* name);
120 DLLLOCAL void pop_cvar();
121 DLLLOCAL LocalVar* pop_local_var(bool set_unassigned = false);
122 DLLLOCAL int pop_local_var_get_id();
123 // used for constructor methods sharing a common "self" local variable and for top-level local variables
124 DLLLOCAL void push_local_var(LocalVar* lv, const QoreProgramLocation* loc);
125 
126 // push a local variable on the stack at parse time
136 DLLLOCAL LocalVar* push_local_var(const char* name, const QoreProgramLocation* loc, const QoreTypeInfo* typeInfo, bool is_auto = true, int n_refs = 0, int pflag = 0);
137 
138 DLLLOCAL LocalVar* find_local_var(const char* name, bool &in_closure);
139 
140 #endif // _QORE_ABSTRACTSTATEMENT_H
QoreProgram
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only
Definition: QoreProgram.h:126
QoreValue
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
QoreBreakpoint
Class implementing breakpoint for debugging.
Definition: QoreProgram.h:1030
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
common.h