2507 structure_type_name: identifier; |
2504 structure_type_name: identifier; |
2508 */ |
2505 */ |
2509 |
2506 |
2510 data_type_declaration: |
2507 data_type_declaration: |
2511 TYPE type_declaration_list END_TYPE |
2508 TYPE type_declaration_list END_TYPE |
2512 {$$ = new data_type_declaration_c($2, locloc(@$));} |
2509 {$$ = new data_type_declaration_c($2, locloc(@$)); include_string((create_enumtype_conversion_functions_c::get_declaration($$)).c_str());} |
2513 /* ERROR_CHECK_BEGIN */ |
2510 /* ERROR_CHECK_BEGIN */ |
2514 | TYPE END_TYPE |
2511 | TYPE END_TYPE |
2515 {$$ = NULL; print_err_msg(locl(@1), locf(@2), "no data type declared in data type(s) declaration."); yynerrs++;} |
2512 {$$ = NULL; print_err_msg(locl(@1), locf(@2), "no data type declared in data type(s) declaration."); yynerrs++;} |
2516 | TYPE error type_declaration_list END_TYPE |
2513 | TYPE error type_declaration_list END_TYPE |
2517 {$$ = NULL; print_err_msg(locf(@2), locl(@2), "unexpected token after 'TYPE' in data type(s) declaration."); yyerrok;} |
2514 {$$ = NULL; print_err_msg(locf(@2), locl(@2), "unexpected token after 'TYPE' in data type(s) declaration."); yyerrok;} |
2710 * If it were not for the above, we could use the rule |
2707 * If it were not for the above, we could use the rule |
2711 * identifier ':' enumerated_spec_init |
2708 * identifier ':' enumerated_spec_init |
2712 * and include the library_element_symtable.insert(...) code in the rule actions! |
2709 * and include the library_element_symtable.insert(...) code in the rule actions! |
2713 */ |
2710 */ |
2714 identifier ':' enumerated_specification {library_element_symtable.insert($1, prev_declared_enumerated_type_name_token);} |
2711 identifier ':' enumerated_specification {library_element_symtable.insert($1, prev_declared_enumerated_type_name_token);} |
2715 { |
2712 {$$ = new enumerated_type_declaration_c($1, new enumerated_spec_init_c($3, NULL, locloc(@3)), locloc(@$));} |
2716 $$ = new enumerated_type_declaration_c($1, new enumerated_spec_init_c($3, NULL, locloc(@3)), locloc(@$)); |
|
2717 if (conversion_functions_) { |
|
2718 const char *name = ((identifier_c *)$1)->value; |
|
2719 add_enumtype_conversion_functions(name); |
|
2720 } |
|
2721 } |
|
2722 | identifier ':' enumerated_specification {library_element_symtable.insert($1, prev_declared_enumerated_type_name_token);} ASSIGN enumerated_value |
2713 | identifier ':' enumerated_specification {library_element_symtable.insert($1, prev_declared_enumerated_type_name_token);} ASSIGN enumerated_value |
2723 {$$ = new enumerated_type_declaration_c($1, new enumerated_spec_init_c($3, $6, locf(@3), locl(@6)), locloc(@$));} |
2714 {$$ = new enumerated_type_declaration_c($1, new enumerated_spec_init_c($3, $6, locf(@3), locl(@6)), locloc(@$));} |
2724 /* ERROR_CHECK_BEGIN */ |
2715 /* ERROR_CHECK_BEGIN */ |
2725 | error ':' enumerated_spec_init |
2716 | error ':' enumerated_spec_init |
2726 {$$ = NULL; print_err_msg(locf(@1), locl(@1), "invalid name defined for enumerated type declaration."); yyerrok;} |
2717 {$$ = NULL; print_err_msg(locf(@1), locl(@1), "invalid name defined for enumerated type declaration."); yyerrok;} |
8336 current_filename = filename; |
8327 current_filename = filename; |
8337 current_tracking = GetNewTracking(yyin); |
8328 current_tracking = GetNewTracking(yyin); |
8338 {int res; |
8329 {int res; |
8339 if ((res = yyparse()) != 0) { |
8330 if ((res = yyparse()) != 0) { |
8340 fprintf (stderr, "\nParsing failed because of too many consecutive syntax errors. Bailing out!\n"); |
8331 fprintf (stderr, "\nParsing failed because of too many consecutive syntax errors. Bailing out!\n"); |
8341 exit(EXIT_FAILURE); |
8332 exit(EXIT_FAILURE); |
8342 } |
8333 } |
8343 } |
8334 } |
8344 |
8335 |
8345 if (yynerrs > 0) { |
8336 if (yynerrs > 0) { |
8346 fprintf (stderr, "\n%d error(s) found. Bailing out!\n", yynerrs /* global variable */); |
8337 fprintf (stderr, "\n%d error(s) found. Bailing out!\n", yynerrs /* global variable */); |
8347 exit(EXIT_FAILURE); |
8338 exit(EXIT_FAILURE); |
8352 |
8343 |
8353 fclose(in_file); |
8344 fclose(in_file); |
8354 return 0; |
8345 return 0; |
8355 } |
8346 } |
8356 |
8347 |
8357 /* Create a tmp file from a char buffer. */ |
8348 |
8358 FILE *ftmpopen (void *buf, size_t size, const char *opentype) |
8349 |
8359 { |
8350 |
8360 FILE *f; |
8351 |
8361 f = tmpfile(); |
8352 |
8362 fwrite(buf, 1, size, f); |
8353 |
8363 rewind(f); |
8354 |
8364 return f; |
8355 |
8365 } |
8356 |
8366 |
8357 |
8367 /* sstage2__ function allow to parse a ST code inside a string. |
8358 |
8368 * We use this function to add into AST auto generated code like enum conversion functions. |
8359 |
8369 * This appoach allow us to write future changes code indipendetly and to check generate code |
8360 |
8370 * during developing. |
|
8371 */ |
|
8372 int sstage2__(const char *text, |
|
8373 symbol_c **tree_root_ref, |
|
8374 bool full_token_loc_ /* error messages specify full token location */ |
|
8375 ) { |
|
8376 |
|
8377 FILE *in_file = NULL; |
|
8378 |
|
8379 if((in_file = ftmpopen((void *)text, strlen(text), "r")) == NULL) { |
|
8380 perror("Error creating temp file."); |
|
8381 return -1; |
|
8382 } |
|
8383 |
|
8384 /* now parse the input file... */ |
|
8385 #if YYDEBUG |
|
8386 yydebug = 1; |
|
8387 #endif |
|
8388 yyin = in_file; |
|
8389 |
|
8390 /* We turn on "allow_function_overloading" flag to disable some checks. |
|
8391 * In detail when we add to symboltable a symbol already processed we |
|
8392 * don't want to get any error. |
|
8393 */ |
|
8394 |
|
8395 allow_function_overloading = true; |
|
8396 allow_extensible_function_parameters = false; |
|
8397 full_token_loc = full_token_loc_; |
|
8398 current_filename = "built-in"; |
|
8399 current_tracking = GetNewTracking(yyin); |
|
8400 {int res; |
|
8401 if ((res = yyparse()) != 0) { |
|
8402 fprintf (stderr, "\nParsing failed because of too many consecutive syntax errors. Bailing out!\n"); |
|
8403 exit(EXIT_FAILURE); |
|
8404 } |
|
8405 } |
|
8406 |
|
8407 if (yynerrs > 0) { |
|
8408 fprintf (stderr, "\n%d error(s) found. Bailing out!\n", yynerrs /* global variable */); |
|
8409 exit(EXIT_FAILURE); |
|
8410 } |
|
8411 |
|
8412 if (tree_root_ref != NULL) |
|
8413 *tree_root_ref = tree_root; |
|
8414 |
|
8415 fclose(in_file); |
|
8416 return 0; |
|
8417 } |
|
8418 |
|
8419 |
|
8420 /* Create entry in symbol table for function conversion data type*/ |
|
8421 void add_enumtype_conversion_functions(const char * dname) { |
|
8422 std::string strname; |
|
8423 std::string tmp; |
|
8424 |
|
8425 strname = dname; |
|
8426 for (int i = 0; create_enumtype_conversion_functions_c::functionDataType[i] != NULL; i++) { |
|
8427 tmp = strname + std::string("_TO_") + create_enumtype_conversion_functions_c::functionDataType[i]; |
|
8428 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8429 |
|
8430 tmp = create_enumtype_conversion_functions_c::functionDataType[i] + std::string("_TO_") + strname; |
|
8431 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8432 } |
|
8433 } |
|
8434 |
|
8435 |
|
8436 |
|
8437 |
|