1 /********************************************************************/ 2 /* */ 3 /* s7 Seed7 interpreter */ 4 /* Copyright (C) 1990 - 2005 Thomas Mertes */ 5 /* */ 6 /* This program is free software; you can redistribute it and/or */ 7 /* modify it under the terms of the GNU General Public License as */ 8 /* published by the Free Software Foundation; either version 2 of */ 9 /* the License, or (at your option) any later version. */ 10 /* */ 11 /* This program is distributed in the hope that it will be useful, */ 12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ 14 /* GNU General Public License for more details. */ 15 /* */ 16 /* You should have received a copy of the GNU General Public */ 17 /* License along with this program; if not, write to the */ 18 /* Free Software Foundation, Inc., 51 Franklin Street, */ 19 /* Fifth Floor, Boston, MA 02110-1301, USA. */ 20 /* */ 21 /* Module: Main */ 22 /* File: seed7/src/data.h */ 23 /* Changes: 1990, 1991, 1992, 1993, 1994, 2000 Thomas Mertes */ 24 /* Content: Type definitions for general data structures. */ 25 /* */ 26 /********************************************************************/ 27 28 typedef enum { 29 SYMBOLOBJECT, /* pos (file, line) - Symbol object */ 30 /* created by read_atom */ 31 /* and read_name */ 32 DECLAREDOBJECT, /* NO VALUE - Object declared and */ 33 /* not initialized */ 34 FORWARDOBJECT, /* NO VALUE - Object declared */ 35 /* forward */ 36 FWDREFOBJECT, /* objValue - Reference to Object which */ 37 /* was declared forward */ 38 BLOCKOBJECT, /* blockValue - Procedure possibly with */ 39 /* parameters, declared */ 40 /* result or local variables */ 41 CALLOBJECT, /* listValue - Subroutine call: */ 42 /* First element is subroutine */ 43 /* Rest of list is parameters */ 44 MATCHOBJECT, /* listValue - Don't exec subroutine call: */ 45 /* First element is subroutine */ 46 /* Rest of list is parameters */ 47 TYPEOBJECT, /* typeValue - type */ 48 FORMPARAMOBJECT, /* objValue - Reference to formal param */ 49 INTOBJECT, /* intValue - integer */ 50 BIGINTOBJECT, /* bigIntValue - bigInteger */ 51 CHAROBJECT, /* charValue - char */ 52 STRIOBJECT, /* striValue - string */ 53 BSTRIOBJECT, /* bstriValue - byte string */ 54 ARRAYOBJECT, /* arrayValue - array */ 55 HASHOBJECT, /* hashValue - hash */ 56 STRUCTOBJECT, /* structValue - struct */ 57 CLASSOBJECT, /* structValue - struct */ 58 INTERFACEOBJECT, /* objValue - Dynamic Object */ 59 SETOBJECT, /* setValue - set */ 60 FILEOBJECT, /* fileValue - file */ 61 FILEDESOBJECT, /* fileDesValue - file descriptor */ 62 SOCKETOBJECT, /* socketValue - socket */ 63 POLLOBJECT, /* pollValue - poll list */ 64 LISTOBJECT, /* listValue - list */ 65 FLOATOBJECT, /* floatValue - float */ 66 WINOBJECT, /* winValue - Window */ 67 PROCESSOBJECT, /* processValue - Process */ 68 ENUMLITERALOBJECT, /* objValue - Enumeration literal */ 69 CONSTENUMOBJECT, /* objValue - Constant enumeration obj */ 70 VARENUMOBJECT, /* objValue - Variable enumeration obj */ 71 REFOBJECT, /* objValue - reference */ 72 REFLISTOBJECT, /* listValue - ref_list */ 73 EXPROBJECT, /* listValue - expression */ 74 ACTOBJECT, /* actValue - Action */ 75 VALUEPARAMOBJECT, /* objValue - Formal value parameter */ 76 REFPARAMOBJECT, /* objValue - Formal ref parameter */ 77 RESULTOBJECT, /* objValue - Result of procedure */ 78 LOCALVOBJECT, /* objValue - Local variable */ 79 DATABASEOBJECT, /* databaseValue - Database */ 80 SQLSTMTOBJECT, /* sqlStmtValue - SQL statement */ 81 PROGOBJECT /* progValue - Program */ 82 } objectCategory; 83 84 typedef enum { 85 SY_TOKEN, 86 EXPR_TOKEN, 87 UNDEF_SYNTAX, 88 LIST_WITH_TYPEOF_SYNTAX, 89 SELECT_ELEMENT_FROM_LIST_SYNTAX 90 } tokenCategory; 91 92 typedef uint32Type posType; 93 typedef unsigned int lineNumType; 94 typedef unsigned int fileNumType; 95 typedef uint16Type categoryType; 96 97 typedef struct identStruct *identType; 98 typedef struct tokenStruct *tokenType; 99 typedef struct nodeStruct *nodeType; 100 typedef struct entityStruct *entityType; 101 typedef struct ownerStruct *ownerType; 102 typedef struct objectStruct *objectType; 103 typedef struct propertyStruct *propertyType; 104 typedef struct stackStruct *stackType; 105 typedef struct typeListStruct *typeListType; 106 typedef struct typeStruct *typeType; 107 typedef struct listStruct *listType; 108 typedef struct locObjStruct *locObjType; 109 typedef struct locListStruct *locListType; 110 typedef struct blockStruct *blockType; 111 typedef struct arrayStruct *arrayType; 112 typedef struct hashElemStruct *hashElemType; 113 typedef struct hashStruct *hashType; 114 typedef struct structStruct *structType; 115 typedef struct progStruct *progType; 116 typedef struct inFileStruct *inFileType; 117 118 typedef const struct identStruct *const_identType; 119 typedef const struct tokenStruct *const_tokenType; 120 typedef const struct nodeStruct *const_nodeType; 121 typedef const struct entityStruct *const_entityType; 122 typedef const struct ownerStruct *const_ownerType; 123 typedef const struct objectStruct *const_objectType; 124 typedef const struct propertyStruct *const_propertyType; 125 typedef const struct stackStruct *const_stackType; 126 typedef const struct typeListStruct *const_typeListType; 127 typedef const struct typeStruct *const_typeType; 128 typedef const struct listStruct *const_listType; 129 typedef const struct locObjStruct *const_locObjType; 130 typedef const struct locListStruct *const_locListType; 131 typedef const struct blockStruct *const_blockType; 132 typedef const struct arrayStruct *const_arrayType; 133 typedef const struct hashElemStruct *const_hashElemType; 134 typedef const struct hashStruct *const_hashType; 135 typedef const struct structStruct *const_structType; 136 typedef const struct progStruct *const_progType; 137 typedef const struct inFileStruct *const_inFileType; 138 139 typedef objectType (*actType) (listType); 140 141 typedef struct identStruct { 142 ustriType name; 143 identType next1; 144 identType next2; 145 entityType entity; 146 tokenType prefix_token; 147 tokenType infix_token; 148 priorityType prefix_priority; 149 priorityType infix_priority; 150 priorityType left_token_priority; 151 } identRecord; 152 153 typedef struct tokenStruct { 154 tokenType next; 155 tokenType alternative; 156 union { 157 identType ident; 158 struct { 159 priorityType priority; 160 typeType type_of; 161 } expr_par; 162 typeType type_of; 163 intType select; 164 } token_value; 165 tokenCategory token_category; 166 } tokenRecord; 167 168 typedef struct nodeStruct { 169 uintType usage_count; 170 objectType match_obj; 171 nodeType next1; 172 nodeType next2; 173 entityType entity; 174 nodeType symbol; 175 nodeType inout_param; 176 nodeType other_param; 177 nodeType attr; 178 } nodeRecord; 179 180 typedef struct entityStruct { 181 identType ident; 182 objectType syobject; 183 listType fparam_list; 184 union { 185 ownerType owner; 186 entityType next; 187 } data; 188 } entityRecord; 189 190 typedef struct ownerStruct { 191 objectType obj; 192 stackType decl_level; 193 ownerType next; 194 } ownerRecord; 195 196 typedef union { 197 posType pos; /* SYMBOLOBJECT */ 198 typeType typeValue; /* TYPEOBJECT */ 199 intType intValue; /* INTOBJECT */ 200 bigIntType bigIntValue; /* BIGINTOBJECT */ 201 charType charValue; /* CHAROBJECT */ 202 striType striValue; /* STRIOBJECT */ 203 bstriType bstriValue; /* BSTRIOBJECT */ 204 arrayType arrayValue; /* ARRAYOBJECT */ 205 hashType hashValue; /* HASHOBJECT */ 206 setType setValue; /* SETOBJECT */ 207 structType structValue; /* STRUCTOBJECT */ 208 uintType binaryValue; /* INTOBJECT */ 209 fileType fileValue; /* FILEOBJECT */ 210 fileDesType fileDesValue; /* FILEDESOBJECT */ 211 socketType socketValue; /* SOCKETOBJECT */ 212 pollType pollValue; /* POLLOBJECT */ 213 listType listValue; /* LISTOBJECT, EXPROBJECT */ 214 winType winValue; /* WINOBJECT */ 215 processType processValue; /* PROCESSOBJECT */ 216 objectType objValue; /* ENUMLITERALOBJECT, CONSTENUMOBJECT */ 217 /* VARENUMOBJECT, VALUEPARAMOBJECT */ 218 /* REFPARAMOBJECT, RESULTOBJECT */ 219 /* LOCALVOBJECT, FORMPARAMOBJECT */ 220 /* INTERFACEOBJECT */ 221 blockType blockValue; /* BLOCKOBJECT */ 222 actType actValue; /* ACTOBJECT */ 223 databaseType databaseValue; /* DATABASEOBJECT */ 224 sqlStmtType sqlStmtValue; /* SQLSTMTOBJECT */ 225 progType progValue; /* PROGOBJECT */ 226 #if WITH_FLOAT 227 floatType floatValue; /* FLOATOBJECT */ 228 #endif 229 } valueUnion; 230 231 typedef struct propertyStruct { 232 entityType entity; 233 listType params; 234 fileNumType file_number; 235 lineNumType line; 236 unsigned int syNumberInLine; 237 } propertyRecord; 238 239 typedef union { 240 propertyType property; 241 posType posinfo; 242 } descriptorUnion; 243 244 typedef struct objectStruct { 245 typeType type_of; 246 descriptorUnion descriptor; 247 valueUnion value; 248 categoryType objcategory; 249 } objectRecord; 250 251 typedef struct stackStruct { 252 listType local_object_list; 253 listType *object_list_insert_place; 254 stackType upward; 255 stackType downward; 256 } stackRecord; 257 258 typedef struct typeListStruct { 259 typeListType next; 260 typeType type_elem; 261 } typeListRecord; 262 263 typedef enum { 264 PARAM_UNDEFINED, 265 PARAM_VALUE, 266 PARAM_REF 267 } parameterType; 268 269 typedef struct typeStruct { 270 objectType match_obj; 271 typeType meta; 272 typeType func_type; 273 typeType varfunc_type; 274 typeType result_type; 275 boolType is_varfunc_type; 276 parameterType in_param_type; 277 typeListType interfaces; 278 identType name; 279 progType owningProg; 280 objectType inout_f_param_prototype; 281 objectType other_f_param_prototype; 282 objectType create_call_obj; 283 objectType destroy_call_obj; 284 objectType copy_call_obj; 285 objectType ord_call_obj; 286 objectType in_call_obj; 287 objectType value_obj; 288 } typeRecord; 289 290 typedef struct listStruct { 291 listType next; 292 objectType obj; 293 } listRecord; 294 295 typedef struct locObjStruct { 296 objectType object; 297 objectType init_value; 298 objectType create_call_obj; 299 objectType destroy_call_obj; 300 } locObjRecord; 301 302 typedef struct locListStruct { 303 locObjRecord local; 304 locListType next; 305 } locListRecord; 306 307 typedef struct blockStruct { 308 locListType params; 309 locObjRecord result; 310 locListType local_vars; 311 listType local_consts; 312 objectType body; 313 } blockRecord; 314 315 typedef struct arrayStruct { 316 intType min_position; 317 intType max_position; 318 objectRecord arr[1]; 319 } arrayRecord; 320 321 typedef struct hashElemStruct { 322 hashElemType next_less; 323 hashElemType next_greater; 324 objectRecord key; 325 objectRecord data; 326 } hashElemRecord; 327 328 typedef struct hashStruct { 329 unsigned int bits; 330 unsigned int mask; 331 unsigned int table_size; 332 memSizeType size; 333 hashElemType table[1]; 334 } hashRecord; 335 336 typedef struct structStruct { 337 memSizeType usage_count; 338 memSizeType size; 339 objectRecord stru[1]; 340 } structRecord; 341 342 #define NUMBER_OF_SYSVARS 31 343 344 typedef objectType sysType[NUMBER_OF_SYSVARS]; 345 346 #define ID_TABLE_SIZE 1024 347 348 typedef struct { 349 identType table[ID_TABLE_SIZE]; 350 identType table1[127]; 351 identType literal; 352 identType end_of_file; 353 } idRootType; 354 355 typedef struct { 356 identType lparen; 357 identType lbrack; 358 identType lbrace; 359 identType rparen; 360 identType rbrack; 361 identType rbrace; 362 identType dot; 363 identType colon; 364 identType comma; 365 identType semicolon; 366 identType dollar; 367 identType r_arrow; 368 identType l_arrow; 369 identType out_arrow; 370 identType in_arrow; 371 identType type; 372 identType constant; 373 identType ref; 374 identType syntax; 375 identType system; 376 identType include; 377 identType is; 378 identType func; 379 identType param; 380 identType enumlit; 381 identType subtype; 382 identType newtype; 383 identType action; 384 } findIdType; 385 386 typedef struct { 387 entityType literal; 388 entityType inactive_list; 389 } entityRootType; 390 391 typedef struct { 392 propertyType literal; 393 } propertyRootType; 394 395 typedef struct progStruct { 396 uintType usage_count; 397 objectType main_object; 398 const_striType arg0; 399 const_striType program_name; 400 const_striType program_path; 401 objectType arg_v; 402 uintType option_flags; 403 unsigned int error_count; 404 void *includeFileHash; 405 idRootType ident; 406 findIdType id_for; 407 entityRootType entity; 408 propertyRootType property; 409 sysType sys_var; 410 listType types; 411 listType literals; 412 nodeType declaration_root; 413 stackType stack_global; 414 stackType stack_data; 415 stackType stack_current; 416 listType exec_expr_temp_results; 417 } progRecord; 418 419 typedef struct inFileStruct { 420 FILE *fil; 421 const_ustriType name_ustri; 422 striType name; 423 #if USE_ALTERNATE_NEXT_CHARACTER 424 ustriType start; 425 const_ustriType nextch; 426 const_ustriType beyond; 427 memSizeType buffer_size; 428 #else 429 #if USE_INFILE_BUFFER 430 ustriType buffer; 431 #endif 432 #endif 433 int character; 434 inFileType curr_infile; 435 inFileType up_infile; 436 inFileType next; 437 #if WITH_COMPILATION_INFO 438 boolType write_library_names; 439 boolType write_line_numbers; 440 #endif 441 lineNumType line; 442 lineNumType incr_message_line; 443 lineNumType next_msg_line; 444 fileNumType file_number; 445 progType owningProg; 446 boolType end_of_file; 447 } inFileRecord; 448 449 450 extern progType prog; 451 452 453 #define INIT_POS(O,L,F) (O)->value.pos = ((posType) (L)) | (((posType) (F)) << 20) 454 #define GET_POS_LINE_NUM(O) (lineNumType) ((O)->value.pos & 1048575L) 455 #define GET_POS_FILE_NUM(O) (fileNumType) (((O)->value.pos & 2146435072L) >> 20) 456 457 #define CREATE_POSINFO(L,F) (((posType) (L)) | (((posType) (F)) << 20)) 458 #define GET_LINE_NUM(O) (lineNumType) (((long)(O)->descriptor.posinfo) & 1048575L) 459 #define GET_FILE_NUM(O) (fileNumType) ((((long)(O)->descriptor.posinfo) & 2146435072L) >> 20) 460 461 #define CATEGORY_MASK ((categoryType) 63) 462 #define VAR_MASK ((categoryType) 64) 463 #define TEMP_MASK ((categoryType) 128) 464 #define TEMP2_MASK ((categoryType) 256) 465 #define POSINFO_MASK ((categoryType) 512) 466 #define MATCH_ERR_MASK ((categoryType) 1024) 467 #define UNUSED_MASK ((categoryType) 2048) 468 469 #define MAX_CATEGORY_FIELD_VALUE ((categoryType) 4095) 470 #define LEGAL_CATEGORY_FIELD(O) ((objectCategory) ((O)->objcategory <= MAX_CATEGORY_FIELD_VALUE)) 471 472 #define SET_ANY_FLAG(O,FLAG) (O)->objcategory = (categoryType) ((O)->objcategory | (FLAG)) 473 474 #define INIT_CATEGORY_OF_OBJ(O,CAT) (O)->objcategory = (categoryType) (CAT) 475 #define SET_CATEGORY_OF_OBJ(O,CAT) (O)->objcategory = (categoryType) (((O)->objcategory & ~CATEGORY_MASK) | (categoryType) (CAT)) 476 #define CATEGORY_OF_OBJ(O) ((objectCategory) ((O)->objcategory & CATEGORY_MASK)) 477 478 #define INIT_CATEGORY_OF_VAR(O,CAT) (O)->objcategory = (categoryType) ((CAT) | VAR_MASK) 479 #define SET_VAR_FLAG(O) (O)->objcategory = (categoryType) ((O)->objcategory | VAR_MASK) 480 #define CLEAR_VAR_FLAG(O) (O)->objcategory = (categoryType) ((O)->objcategory & ~VAR_MASK) 481 #define VAR_OBJECT(O) ((O)->objcategory & VAR_MASK) 482 #define COPY_VAR_FLAG(O1,O2) (O1)->objcategory = (categoryType) (((O1)->objcategory & ~VAR_MASK) | ((O2)->objcategory & VAR_MASK)) 483 484 #define INIT_CATEGORY_OF_TEMP(O,CAT) (O)->objcategory = (categoryType) ((CAT) | TEMP_MASK) 485 #define SET_TEMP_FLAG(O) (O)->objcategory = (categoryType) ((O)->objcategory | TEMP_MASK) 486 #define CLEAR_TEMP_FLAG(O) (O)->objcategory = (categoryType) ((O)->objcategory & ~TEMP_MASK) 487 #define TEMP_OBJECT(O) ((O)->objcategory & TEMP_MASK) 488 489 #define INIT_CATEGORY_OF_TEMP2(O,CAT) (O)->objcategory = (categoryType) ((CAT) | TEMP2_MASK) 490 #define SET_TEMP2_FLAG(O) (O)->objcategory = (categoryType) ((O)->objcategory | TEMP2_MASK) 491 #define CLEAR_TEMP2_FLAG(O) (O)->objcategory = (categoryType) ((O)->objcategory & ~TEMP2_MASK) 492 #define TEMP2_OBJECT(O) ((O)->objcategory & TEMP2_MASK) 493 494 #define INIT_CATEGORY_OF_POSINFO(O,CAT) (O)->objcategory = (categoryType) ((CAT) | POSINFO_MASK) 495 #define SET_POSINFO_FLAG(O) (O)->objcategory = (categoryType) ((O)->objcategory | POSINFO_MASK) 496 #define CLEAR_POSINFO_FLAG(O) (O)->objcategory = (categoryType) ((O)->objcategory & ~POSINFO_MASK) 497 #define HAS_POSINFO(O) ((O)->objcategory & POSINFO_MASK) 498 #define COPY_POSINFO_FLAG(O1,O2) (O1)->objcategory = (categoryType) (((O1)->objcategory & ~POSINFO_MASK) | ((O2)->objcategory & POSINFO_MASK)) 499 500 #define SET_MATCH_ERR_FLAG(O) (O)->objcategory = (categoryType) ((O)->objcategory | MATCH_ERR_MASK) 501 #define CLEAR_MATCH_ERR_FLAG(O) (O)->objcategory = (categoryType) ((O)->objcategory & ~MATCH_ERR_MASK) 502 #define HAS_MATCH_ERR(O) ((O)->objcategory & MATCH_ERR_MASK) 503 504 #define SET_UNUSED_FLAG(O) (O)->objcategory = (categoryType) ((O)->objcategory | UNUSED_MASK) 505 #define CLEAR_UNUSED_FLAG(O) (O)->objcategory = (categoryType) ((O)->objcategory & ~UNUSED_MASK) 506 #define IS_UNUSED(O) ((O)->objcategory & UNUSED_MASK) 507 508 #define HAS_PROPERTY(O) (!HAS_POSINFO(O) && (O)->descriptor.property != NULL) 509 #define HAS_ENTITY(O) (HAS_PROPERTY(O) && (O)->descriptor.property->entity != NULL) 510 #define GET_ENTITY(O) ((O)->descriptor.property->entity) 511