# HG changeset patch # User mjsousa # Date 1407575558 -3600 # Node ID 9e824bb0c3d4c7835f761b65191b598fc62ad329 # Parent 0ad7843d3790690da83f5956000483e1a27f8136 Make support for REF_TO ANY a command line option. diff -r 0ad7843d3790 -r 9e824bb0c3d4 main.cc --- a/main.cc Sat Aug 09 09:20:03 2014 +0100 +++ b/main.cc Sat Aug 09 10:12:38 2014 +0100 @@ -120,9 +120,10 @@ /* Part 1: Concepts and Function Blocks, */ /* Version 1.0 is Official Release */ /******************************************************/ - printf(" -s : allow use of safe extensions (e.g. SAFExxx data types))\n"); - printf(" -n : allow use of nested comments (an IEC 61131-3 v3 feature)\n"); - printf(" -r : allow use of REF() operator (an IEC 61131-3 v3 feature)\n"); + printf(" -s : allow use of safe datatypes (SAFEBOOL, etc.) (defined in PLCOpen Safety)\n"); + printf(" -n : allow use of nested comments (an IEC 61131-3 v3 feature)\n"); + printf(" -r : allow use of references (REF_TO, REF, NULL) (an IEC 61131-3 v3 feature)\n"); + printf(" -R : allow use of REF_TO ANY datatypes (implies -r) (a non-standard extension!)\n"); printf(" -c : create conversion functions for enumerated data types\n"); printf(" -O : options for output (code generation) stage. Available options for %s are...\n", cmd); stage4_print_options(); @@ -147,41 +148,39 @@ stage1_2_options.conversion_functions = false; /* Create a conversion function for derived datatype */ stage1_2_options.nested_comments = false; /* Allow the use of nested comments. */ stage1_2_options.ref_operator = false; /* Allow the use of REF() operator. */ + stage1_2_options.ref_to_any = false; /* Allow the use of REF_TO ANY datatype. */ stage1_2_options.includedir = NULL; /* Include directory, where included files will be searched for... */ /******************************************/ /* Parse command line options... */ /******************************************/ - while ((optres = getopt(argc, argv, ":nhvfrscI:T:O:")) != -1) { + while ((optres = getopt(argc, argv, ":nhvfrRscI:T:O:")) != -1) { switch(optres) { case 'h': printusage(argv[0]); return 0; - case 'v': fprintf(stdout, "%s version %s\n" "changeset id: %s\n", PACKAGE_NAME, PACKAGE_VERSION, HGVERSION); return 0; - case 'f': stage1_2_options.full_token_loc = true; break; - case 's': stage1_2_options.safe_extensions = true; break; - + case 'R': + stage1_2_options.ref_operator = true; /* use of REF_TO ANY implies activating support for REF extensions! */ + stage1_2_options.ref_to_any = true; + break; case 'r': stage1_2_options.ref_operator = true; break; - case 'c': stage1_2_options.conversion_functions = true; break; - case 'n': stage1_2_options.nested_comments = true; break; - case 'I': /* NOTE: To improve the usability under windows: * We delete last char's path if it ends with "\". @@ -192,28 +191,23 @@ if (optarg[path_len] == '\\') optarg[path_len]= '\0'; stage1_2_options.includedir = optarg; break; - case 'T': /* NOTE: see note above */ path_len = strlen(optarg) - 1; if (optarg[path_len] == '\\') optarg[path_len]= '\0'; builddir = optarg; break; - case 'O': if (stage4_parse_options(optarg) < 0) errflg++; break; - case ':': /* -I, -T, or -O without operand */ fprintf(stderr, "Option -%c requires an operand\n", optopt); errflg++; break; - case '?': fprintf(stderr, "Unrecognized option: -%c\n", optopt); errflg++; break; - default: fprintf(stderr, "Unknown error while parsing command line options."); errflg++; diff -r 0ad7843d3790 -r 9e824bb0c3d4 stage1_2/iec_bison.yy --- a/stage1_2/iec_bison.yy Sat Aug 09 09:20:03 2014 +0100 +++ b/stage1_2/iec_bison.yy Sat Aug 09 10:12:38 2014 +0100 @@ -208,6 +208,9 @@ */ extern bool conversion_functions_; +/* A global flag used to tell the parser whether to allow use of REF_TO ANY datatypes (non-standard extension) */ +extern bool allow_ref_to_any; + /* A pointer to the root of the parsing tree that will be generated * by bison. */ @@ -3223,7 +3226,12 @@ | REF_TO function_block_type_name {$$ = new ref_spec_c($2, locloc(@$));} | REF_TO ANY - {$$ = new ref_spec_c(new generic_type_any_c(locloc(@2)), locloc(@$));} + {$$ = new ref_spec_c(new generic_type_any_c(locloc(@2)), locloc(@$)); + if (!allow_ref_to_any) { + print_err_msg(locf(@$), locl(@$), "REF_TO ANY datatypes are not allowed (use -R option to activate support for this non-standard syntax)."); + yynerrs++; + } + } /* The following line is actually not included in IEC 61131-3, but we add it anyway otherwise it will not be possible to * define a REF_TO datatype as an alias to an already previously declared REF_TO datatype. * For example: @@ -8156,6 +8164,9 @@ */ bool full_token_loc; +/* A global flag used to tell the parser whether to allow use of REF_TO ANY datatypes (non-standard extension) */ +bool allow_ref_to_any = false; + /* A pointer to the root of the parsing tree that will be generated * by bison. */ @@ -8383,7 +8394,8 @@ int stage2__(const char *filename, const char *includedir, /* Include directory, where included files will be searched for... */ symbol_c **tree_root_ref, - bool full_token_loc_ /* error messages specify full token location */ + bool full_token_loc_, /* error messages specify full token location */ + bool ref_to_any_ /* allow use of non-standard REF_TO ANY datatypes */ ) { char *libfilename = NULL; @@ -8413,9 +8425,10 @@ return -1; } - allow_function_overloading = true; + allow_function_overloading = true; allow_extensible_function_parameters = true; - full_token_loc = full_token_loc_; + full_token_loc = full_token_loc_; + allow_ref_to_any = ref_to_any_; if (yyparse() != 0) ERROR; fclose(libfile); @@ -8446,9 +8459,11 @@ return -1; } - allow_function_overloading = false; + allow_function_overloading = false; allow_extensible_function_parameters = false; - full_token_loc = full_token_loc_; + full_token_loc = full_token_loc_; + allow_ref_to_any = ref_to_any_; + //allow_ref_to_any = false; /* we only allow REF_TO ANY in library functions/FBs, no matter what the user asks for in the command line */ if (yyparse() != 0) { fprintf (stderr, "\nParsing failed because of too many consecutive syntax errors. Bailing out!\n"); diff -r 0ad7843d3790 -r 9e824bb0c3d4 stage1_2/stage1_2.cc --- a/stage1_2/stage1_2.cc Sat Aug 09 09:20:03 2014 +0100 +++ b/stage1_2/stage1_2.cc Sat Aug 09 10:12:38 2014 +0100 @@ -238,7 +238,8 @@ int stage2__(const char *filename, const char *includedir, /* Include directory, where included files will be searched for... */ symbol_c **tree_root_ref, - bool full_token_loc /* error messages specify full token location */ + bool full_token_loc, /* error messages specify full token location */ + bool ref_to_any /* allow use of non-standard REF_TO ANY datatypes */ ); @@ -258,6 +259,6 @@ ref_operator_ = options.ref_operator; safe_extensions_ = options.safe_extensions; conversion_functions_ = options.conversion_functions; - return stage2__(filename, options.includedir, tree_root_ref, options.full_token_loc); -} - + return stage2__(filename, options.includedir, tree_root_ref, options.full_token_loc, options.ref_to_any); +} + diff -r 0ad7843d3790 -r 9e824bb0c3d4 stage1_2/stage1_2.hh --- a/stage1_2/stage1_2.hh Sat Aug 09 09:20:03 2014 +0100 +++ b/stage1_2/stage1_2.hh Sat Aug 09 10:12:38 2014 +0100 @@ -60,7 +60,8 @@ bool full_token_loc; /* error messages specify full token location */ bool conversion_functions; /* Create a conversion function for derived datatype */ bool nested_comments; /* Allow the use of nested comments. */ - bool ref_operator; /* Allow the use of REF() operator. */ + bool ref_operator; /* Allow the use of REFerences (keywords REF_TO, REF, NULL). */ + bool ref_to_any; /* Allow the use of REF_TO ANY datatypes - non-standard extension! */ const char *includedir; /* Include directory, where included files will be searched for... */ } stage1_2_options_t;