2702 * If it were not for the above, we could use the rule |
2705 * If it were not for the above, we could use the rule |
2703 * identifier ':' enumerated_spec_init |
2706 * identifier ':' enumerated_spec_init |
2704 * and include the library_element_symtable.insert(...) code in the rule actions! |
2707 * and include the library_element_symtable.insert(...) code in the rule actions! |
2705 */ |
2708 */ |
2706 identifier ':' enumerated_specification {library_element_symtable.insert($1, prev_declared_enumerated_type_name_token);} |
2709 identifier ':' enumerated_specification {library_element_symtable.insert($1, prev_declared_enumerated_type_name_token);} |
2707 {$$ = new enumerated_type_declaration_c($1, new enumerated_spec_init_c($3, NULL, locloc(@3)), locloc(@$));} |
2710 { |
|
2711 $$ = new enumerated_type_declaration_c($1, new enumerated_spec_init_c($3, NULL, locloc(@3)), locloc(@$)); |
|
2712 const char *name = ((identifier_c *)$1)->value; |
|
2713 make_derived_conversion_functions(name); |
|
2714 } |
2708 | identifier ':' enumerated_specification {library_element_symtable.insert($1, prev_declared_enumerated_type_name_token);} ASSIGN enumerated_value |
2715 | identifier ':' enumerated_specification {library_element_symtable.insert($1, prev_declared_enumerated_type_name_token);} ASSIGN enumerated_value |
2709 {$$ = new enumerated_type_declaration_c($1, new enumerated_spec_init_c($3, $6, locf(@3), locl(@6)), locloc(@$));} |
2716 {$$ = new enumerated_type_declaration_c($1, new enumerated_spec_init_c($3, $6, locf(@3), locl(@6)), locloc(@$));} |
2710 /* ERROR_CHECK_BEGIN */ |
2717 /* ERROR_CHECK_BEGIN */ |
2711 | error ':' enumerated_spec_init |
2718 | error ':' enumerated_spec_init |
2712 {$$ = NULL; print_err_msg(locf(@1), locl(@1), "invalid name defined for enumerated type declaration."); yyerrok;} |
2719 {$$ = NULL; print_err_msg(locf(@1), locl(@1), "invalid name defined for enumerated type declaration."); yyerrok;} |
8338 |
8345 |
8339 fclose(in_file); |
8346 fclose(in_file); |
8340 return 0; |
8347 return 0; |
8341 } |
8348 } |
8342 |
8349 |
8343 |
8350 FILE *ftmpopen (void *buf, size_t size, const char *opentype) |
8344 |
8351 { |
|
8352 FILE *f; |
|
8353 f = tmpfile(); |
|
8354 fwrite(buf, 1, size, f); |
|
8355 rewind(f); |
|
8356 return f; |
|
8357 } |
|
8358 |
|
8359 |
|
8360 int sstage2__(const char *text, |
|
8361 symbol_c **tree_root_ref, |
|
8362 bool full_token_loc_ /* error messages specify full token location */ |
|
8363 ) { |
|
8364 |
|
8365 FILE *in_file = NULL; |
|
8366 |
|
8367 if((in_file = ftmpopen((void *)text, strlen(text), "r")) == NULL) { |
|
8368 perror("Error temp file."); |
|
8369 return -1; |
|
8370 } |
|
8371 |
|
8372 /* now parse the input file... */ |
|
8373 #if YYDEBUG |
|
8374 yydebug = 1; |
|
8375 #endif |
|
8376 yyin = in_file; |
|
8377 allow_function_overloading = true; |
|
8378 allow_extensible_function_parameters = false; |
|
8379 full_token_loc = full_token_loc_; |
|
8380 current_filename = "built-in"; |
|
8381 current_tracking = GetNewTracking(yyin); |
|
8382 {int res; |
|
8383 if ((res = yyparse()) != 0) { |
|
8384 fprintf (stderr, "\nParsing failed because of too many consecutive syntax errors. Bailing out!\n"); |
|
8385 exit(EXIT_FAILURE); |
|
8386 } |
|
8387 } |
|
8388 |
|
8389 if (yynerrs > 0) { |
|
8390 fprintf (stderr, "\n%d error(s) found. Bailing out!\n", yynerrs /* global variable */); |
|
8391 exit(EXIT_FAILURE); |
|
8392 } |
|
8393 |
|
8394 if (tree_root_ref != NULL) |
|
8395 *tree_root_ref = tree_root; |
|
8396 |
|
8397 fclose(in_file); |
|
8398 return 0; |
|
8399 } |
|
8400 |
|
8401 |
|
8402 |
|
8403 /* Create entry in symbol table for function conversion data type*/ |
|
8404 void make_derived_conversion_functions(const char * dname) { |
|
8405 std::string strname; |
|
8406 std::string tmp; |
|
8407 |
|
8408 strname = dname; |
|
8409 tmp = strname + "_TO_STRING"; |
|
8410 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8411 tmp = strname + "_TO_SINT"; |
|
8412 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8413 tmp = strname + "_TO_INT"; |
|
8414 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8415 tmp = strname + "_TO_DINT"; |
|
8416 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8417 tmp = strname + "_TO_LINT"; |
|
8418 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8419 tmp = strname + "_TO_USINT"; |
|
8420 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8421 tmp = strname + "_TO_UINT"; |
|
8422 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8423 tmp = strname + "_TO_UDINT"; |
|
8424 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8425 tmp = strname + "_TO_ULINT"; |
|
8426 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8427 /* ... */ |
|
8428 tmp = "STRING_TO_" + strname; |
|
8429 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8430 tmp = "SINT_TO_" + strname; |
|
8431 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8432 tmp = "INT_TO_" + strname; |
|
8433 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8434 tmp = "DINT_TO_" + strname; |
|
8435 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8436 tmp = "LINT_TO_" + strname; |
|
8437 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8438 tmp = "USINT_TO_" + strname; |
|
8439 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8440 tmp = "UINT_TO_" + strname; |
|
8441 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8442 tmp = "UDINT_TO_" + strname; |
|
8443 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8444 tmp = "ULINT_TO_" + strname; |
|
8445 library_element_symtable.insert(tmp.c_str(), prev_declared_derived_function_name_token); |
|
8446 /* ... */ |
|
8447 } |
|
8448 |
|
8449 |
|
8450 |
|
8451 |