yast2-core
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
libycp
src
include
ycp
YBlock.h
Go to the documentation of this file.
1
/*---------------------------------------------------------------------\
2
| |
3
| __ __ ____ _____ ____ |
4
| \ \ / /_ _/ ___|_ _|___ \ |
5
| \ V / _` \___ \ | | __) | |
6
| | | (_| |___) || | / __/ |
7
| |_|\__,_|____/ |_| |_____| |
8
| |
9
| core system |
10
| (C) SuSE GmbH |
11
\----------------------------------------------------------------------/
12
13
File: YBlock.h
14
15
Author: Klaus Kaempf <kkaempf@suse.de>
16
Stanislav Visnovsky <visnov@suse.cz>
17
Maintainer: Stanislav Visnovsky <visnov@suse.cz>
18
19
/-*/
20
// -*- c++ -*-
21
22
#ifndef YBlock_h
23
#define YBlock_h
24
25
#include <string>
26
#include <list>
27
using
std::string;
28
#include <
y2util/Ustring.h
>
29
30
#include <
y2/Y2Namespace.h
>
31
#include "
ycp/YStatement.h
"
32
33
//-------------------------------------------------------------------
34
43
class
YSImport
;
44
49
class
YBlock
:
public
YCode
,
public
Y2Namespace
50
{
51
REP_BODY
(
YBlock
);
52
53
public
:
54
// block kinds
55
typedef
enum
{
56
b_unknown
= 0,
// 0: unspecified
57
b_module
,
// 1: toplevel module (-> m_table != 0)
58
b_file
,
// 2: toplevel file block
59
b_statement
,
// 3: used as statement (local block which might contain return)
60
b_definition
,
// 4: used as function definition
61
b_value
,
// 5: used as value (intermediate block)
62
b_namespace
,
// 6: block defines a namespace
63
b_using
// 7: block is evaluated in different namespace
64
}
blockkind_t
;
65
66
private
:
67
// --------------------------------
68
// general block data
69
70
// Block kind
71
// b_statement == implict return YCPNull() (block is statement, default)
72
// else YCPVoid () (treat block as expression)
73
blockkind_t
m_kind
;
74
75
// Pointer to name of block.
76
// normaly empty, non-empty for b_module and b_namespace
77
string
m_name
;
78
79
// --------------------------------
80
// Environment
81
// keep track of symbols entered into SymbolTable (declared
82
// in this block), we must remove then at finishBlock()
83
// so they go out of scope
84
85
struct
yTElist
{
86
struct
yTElist
*
next
;
87
TableEntry
*
tentry
;
88
unsigned
int
position
;
89
};
90
typedef
struct
yTElist
yTElist_t
;
91
92
// block environment (linked list of local declarations)
93
// as TableEntry used during parse time
94
yTElist_t
*
m_tenvironment
;
95
96
// pointer to last declaration for easier append
97
// points to 0 after detachEnvironment()
98
yTElist_t
*
m_last_tparm
;
99
100
// --------------------------------
101
// source file, needs environment
102
103
// Point (Filename) of source file (global SymbolEntry:c_filename)
104
// always points to the current file. During include, it points to
105
// a chain <include file> -> <toplevel file>. See Point.h
106
const
Point
*
m_point
;
107
108
// --------------------------------
109
// Block content
110
111
struct
stmtlist
{
112
YStatementPtr
stmt
;
113
struct
stmtlist
*
next
;
114
};
115
typedef
struct
stmtlist
stmtlist_t
;
116
117
// linked list of statements
118
stmtlist_t
*
m_statements
;
119
120
// pointer to last statement for easier append
121
stmtlist_t
*
m_last_statement
;
122
126
typedef
std::list<std::string>
stringlist_t
;
127
stringlist_t
*
m_includes
;
128
129
constTypePtr
m_type
;
130
131
bool
m_running
;
132
133
public
:
134
//---------------------------------------------------------------
135
// Constructor / Destructor
136
137
// toplevel block
138
YBlock
(
const
std::string &
filename
,
blockkind_t
kind
=
b_unknown
);
139
// midlevel block
140
YBlock
(
const
Point
*
point
);
141
YBlock
(
bytecodeistream
&
str
);
142
~YBlock
();
143
144
//---------------------------------------------------------------
145
// YCode
146
148
virtual
bool
isBlock
()
const
{
return
true
; }
149
virtual
ykind
kind
()
const
{
return
yeBlock
; }
150
151
// warning: it is return type in fact!
152
constTypePtr
type
()
const
{
return
m_type
; }
153
154
// set the return type of this block
155
void
setType
(constTypePtr
type
);
156
157
// the whole block is parsed, do final changes
158
void
finishBlock
();
159
160
// evaluate the complete block
161
virtual
YCPValue
evaluate
(
bool
cse =
false
);
162
163
// evaluate the block from the given statement (switch)
164
YCPValue
evaluateFrom
(
int
statement_index);
165
166
// evaluate a single statement
167
// this is a special purpose interface for macro player
168
// does not handle break, return
169
// and also skips initial 'import' statements (e.g. autogenerated
170
// import "UI") by default
171
YCPValue
evaluate
(
int
statement_index,
bool
skip_initial_imports =
true
);
172
173
//---------------------------------------------------------------
174
// member access
175
176
// return name of source file
177
virtual
const
std::string
filename
()
const
;
178
179
// SymbolTable for global module environment (m_kind == b_module)
180
// non-const return since we must be able to find() which tracks references
181
virtual
SymbolTable
*
table
()
const
;
182
183
virtual
Y2Function
*
createFunctionCall
(
const
string
name
, constFunctionTypePtr
type
);
184
185
// returns the current parse file as Point
186
const
Point
*
point
()
const
;
187
188
// returns the name of the block
189
const
string
name
()
const
;
190
void
setName
(
const
string
&
name
);
191
192
const
Y2Namespace
*
nameSpace
()
const
{
return
(
const
Y2Namespace
*)
this
; }
193
Y2Namespace
*
nameSpace
() {
return
(
Y2Namespace
*)
this
; }
194
195
//---------------------------------------------------------------
196
// block kind
197
198
// set block kind
199
void
setKind
(
blockkind_t
kind
);
200
201
// get block kind
202
blockkind_t
bkind
()
const
;
203
204
// block is toplevel block of a module
205
bool
isModule
()
const
{
return
(
m_kind
==
b_module
); }
// toplevel module block
206
bool
isFile
()
const
{
return
(
m_kind
==
b_file
); }
// toplevel file block
207
bool
isStatement
()
const
{
return
(
m_kind
==
b_statement
); }
// used as statement (local block)
208
bool
isDefinition
()
const
{
return
(
m_kind
==
b_definition
); }
// used as function definition
209
bool
isValue
()
const
{
return
(
m_kind
==
b_value
); }
// used as value (intermediate block)
210
bool
isNamespace
()
const
{
return
(
m_kind
==
b_namespace
); }
// block defines a namespace
211
212
//---------------------------------------------------------------
213
// Value / Entry
214
215
// add new value code to this block
216
// (used for functions which accept either symbolic variables or values, e.g. foreach())
217
// returns position
218
unsigned
int
newValue
(constTypePtr
type
, YCodePtr code);
219
220
// add a new table entry to this block
221
// and attach it to m_tenvironment
222
// return NULL if symbol of same name already declared in this block
223
TableEntry
*
newEntry
(
const
char
*
name
,
SymbolEntry::category_t
cat, constTypePtr
type
,
unsigned
int
line);
224
225
//---------------------------------------------------------------
226
// Namespace
227
228
// add a new namespace entry to this block
229
// and attach it to m_tenvironment
230
// return NULL if symbol of same name already declared in this block
231
TableEntry
*
newNamespace
(
const
string
&
name
,
Y2Namespace
*name_space,
int
line);
232
233
//---------------------------------------------------------------
234
// symbol handling
235
236
// Attach entry (variable, typedef, ...) to local environment
237
void
attachEntry
(
TableEntry
*entry);
238
239
// Detach local environment from symbol table
240
void
detachEnvironment
(
SymbolTable
*
table
);
241
242
//---------------------------------------------------------------
243
// statement handling
244
245
// Attach statement to end of block
246
void
attachStatement
(YStatementPtr statement);
247
248
// Pretach statement to beginning block
249
void
pretachStatement
(YStatementPtr statement);
250
251
// count the statements in this block
252
int
statementCount
()
const
;
253
254
//---------------------------------------------------------------
255
// return
256
257
// returns the return statement if the block just consists of a single return
258
YSReturnPtr
justReturn
()
const
;
259
260
//---------------------------------------------------------------
261
// include
262
263
// end of include block, 'pop' head of m_point chain
264
void
endInclude
();
265
269
bool
isIncluded
(
string
includename)
const
;
270
void
addIncluded
(
string
includename);
271
272
//---------------------------------------------------------------
273
// string output
274
275
string
toString
()
const
;
276
string
environmentToString
()
const
;
277
string
toStringSwitch
(map<YCPValue, int, ycp_less> cases,
int
defaultcase)
const
;
278
279
//---------------------------------------------------------------
280
// stream output
281
282
// write block to stream
283
std::ostream &
toStream
(std::ostream &
str
)
const
;
284
std::ostream &
toXml
( std::ostream &
str
,
int
indent )
const
;
285
std::ostream &
toXmlSwitch
( map<YCPValue, int, ycp_less> cases,
int
defaultcase, std::ostream &
str
,
int
indent )
const
;
286
287
};
288
289
290
#endif // YBlock_h
Generated on a sunny day for yast2-core by
1.8.2