00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef YBlock_h
00023 #define YBlock_h
00024
00025 #include <string>
00026 #include <list>
00027 using std::string;
00028 #include <y2util/Ustring.h>
00029
00030 #include <y2/Y2Namespace.h>
00031 #include "ycp/YStatement.h"
00032
00033
00034
00043 class YSImport;
00044
00049 class YBlock : public YCode, public Y2Namespace
00050 {
00051 REP_BODY (YBlock);
00052
00053 public:
00054
00055 typedef enum {
00056 b_unknown = 0,
00057 b_module,
00058 b_file,
00059 b_statement,
00060 b_definition,
00061 b_value,
00062 b_namespace,
00063 b_using
00064 } blockkind_t;
00065
00066 private:
00067
00068
00069
00070
00071
00072
00073 blockkind_t m_kind;
00074
00075
00076
00077 string m_name;
00078
00079
00080
00081
00082
00083
00084
00085 struct yTElist {
00086 struct yTElist *next;
00087 TableEntry *tentry;
00088 unsigned int position;
00089 };
00090 typedef struct yTElist yTElist_t;
00091
00092
00093
00094 yTElist_t *m_tenvironment;
00095
00096
00097
00098 yTElist_t *m_last_tparm;
00099
00100
00101
00102
00103
00104
00105
00106 const Point *m_point;
00107
00108
00109
00110
00111 struct stmtlist {
00112 YStatementPtr stmt;
00113 struct stmtlist *next;
00114 };
00115 typedef struct stmtlist stmtlist_t;
00116
00117
00118 stmtlist_t *m_statements;
00119
00120
00121 stmtlist_t *m_last_statement;
00122
00126 typedef std::list<std::string> stringlist_t;
00127 stringlist_t* m_includes;
00128
00129 constTypePtr m_type;
00130
00131 bool m_running;
00132
00133 public:
00134
00135
00136
00137
00138 YBlock (const std::string & filename, blockkind_t kind = b_unknown);
00139
00140 YBlock (const Point *point);
00141 YBlock (bytecodeistream & str);
00142 ~YBlock ();
00143
00144
00145
00146
00148 virtual bool isBlock () const { return true; }
00149 virtual ykind kind () const { return yeBlock; }
00150
00151
00152 constTypePtr type () const { return m_type; }
00153
00154
00155 void setType (constTypePtr type);
00156
00157
00158 void finishBlock ();
00159
00160
00161 virtual YCPValue evaluate (bool cse = false);
00162
00163
00164 YCPValue evaluateFrom (int statement_index);
00165
00166
00167
00168
00169
00170
00171 YCPValue evaluate (int statement_index, bool skip_initial_imports = true);
00172
00173
00174
00175
00176
00177 virtual const std::string filename () const;
00178
00179
00180
00181 virtual SymbolTable *table () const;
00182
00183 virtual Y2Function* createFunctionCall (const string name, constFunctionTypePtr type);
00184
00185
00186 const Point *point () const;
00187
00188
00189 const string name () const;
00190 void setName (const string & name);
00191
00192 const Y2Namespace *nameSpace () const { return (const Y2Namespace *)this; }
00193 Y2Namespace *nameSpace () { return (Y2Namespace *)this; }
00194
00195
00196
00197
00198
00199 void setKind (blockkind_t kind);
00200
00201
00202 blockkind_t bkind () const;
00203
00204
00205 bool isModule () const { return (m_kind == b_module); }
00206 bool isFile () const { return (m_kind == b_file); }
00207 bool isStatement () const { return (m_kind == b_statement); }
00208 bool isDefinition () const { return (m_kind == b_definition); }
00209 bool isValue () const { return (m_kind == b_value); }
00210 bool isNamespace () const { return (m_kind == b_namespace); }
00211
00212
00213
00214
00215
00216
00217
00218 unsigned int newValue (constTypePtr type, YCodePtr code);
00219
00220
00221
00222
00223 TableEntry *newEntry (const char *name, SymbolEntry::category_t cat, constTypePtr type, unsigned int line);
00224
00225
00226
00227
00228
00229
00230
00231 TableEntry *newNamespace (const string & name, Y2Namespace *name_space, int line);
00232
00233
00234
00235
00236
00237 void attachEntry (TableEntry *entry);
00238
00239
00240 void detachEnvironment (SymbolTable *table);
00241
00242
00243
00244
00245
00246 void attachStatement (YStatementPtr statement);
00247
00248
00249 void pretachStatement (YStatementPtr statement);
00250
00251
00252 int statementCount () const;
00253
00254
00255
00256
00257
00258 YSReturnPtr justReturn () const;
00259
00260
00261
00262
00263
00264 void endInclude ();
00265
00269 bool isIncluded (string includename) const;
00270 void addIncluded (string includename);
00271
00272
00273
00274
00275 string toString () const;
00276 string environmentToString () const;
00277 string toStringSwitch (map<YCPValue, int, ycp_less> cases, int defaultcase) const;
00278
00279
00280
00281
00282
00283 std::ostream & toStream (std::ostream & str) const;
00284 std::ostream & toXml( std::ostream & str, int indent ) const;
00285 std::ostream & toXmlSwitch( map<YCPValue, int, ycp_less> cases, int defaultcase, std::ostream & str, int indent ) const;
00286
00287 };
00288
00289
00290 #endif // YBlock_h