# HG changeset patch # User mjsousa # Date 1416149212 0 # Node ID c012a64dc2faf2a3bd7f6109bc38858fff5e2f63 # Parent 477393b00f957e225a99452fd9c8dce186f2a89b Make the relaxed datatype model a runtime option (off by default) diff -r 477393b00f95 -r c012a64dc2fa absyntax_utils/get_datatype_info.cc --- a/absyntax_utils/get_datatype_info.cc Sun Nov 16 12:54:10 2014 +0000 +++ b/absyntax_utils/get_datatype_info.cc Sun Nov 16 14:46:52 2014 +0000 @@ -43,7 +43,7 @@ */ #include "absyntax_utils.hh" -#include "../main.hh" // required for ERROR() and ERROR_MSG() macros. +#include "../main.hh" // required for ERROR() and ERROR_MSG() macros, as well as the runtime_options global variable @@ -576,14 +576,13 @@ } // check for same datatype - if (first_type == second_type) {return true;} + if (first_type == second_type) {return true;} // remaining type equivalence rules are not applied in the strict datatype model - //if (!option...relaxed_datatypemodel) - //return false; + if (false == runtime_options.relaxed_datatype_model) {return false;} // check for array equivalence usig the relaxed datatype model - if (is_arraytype_equal_relaxed(first_type, second_type)) {return true;} + if (is_arraytype_equal_relaxed(first_type, second_type)) {return true;} return false; } diff -r 477393b00f95 -r c012a64dc2fa main.cc --- a/main.cc Sun Nov 16 12:54:10 2014 +0000 +++ b/main.cc Sun Nov 16 14:46:52 2014 +0000 @@ -113,15 +113,8 @@ printf(" -h : show this help message\n"); printf(" -v : print version number\n"); printf(" -f : display full token location on error messages\n"); - /******************************************************/ - /* whether we are supporting safe extensions */ - /* as defined in PLCopen - Technical Committee 5 */ - /* Safety Software Technical Specification, */ - /* Part 1: Concepts and Function Blocks, */ - /* Version 1.0 is Official Release */ - /******************************************************/ - 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(" -l : use a relaxed datatype equivalence model (a non-standard extension?)\n"); + printf(" -s : allow use of safe datatypes (SAFEBOOL, etc.) (defined in PLCOpen Safety)\n"); // PLCopen TC5 "Safety Software Technical Specification - Part 1" v1.0 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 (a non-standard extension!)\n"); printf(" as well as REF_TO in ARRAYs and STRUCTs (a non-standard extension!)\n"); @@ -135,27 +128,32 @@ } +/* declare the global options variable */ +runtime_options_t runtime_options; + int main(int argc, char **argv) { symbol_c *tree_root; char * builddir = NULL; - stage1_2_options_t stage1_2_options; int optres, errflg = 0; int path_len; /* Default values for the command line options... */ - stage1_2_options.safe_extensions = false; /* allow use of SAFExxx datatypes */ - stage1_2_options.full_token_loc = false; /* error messages specify full token location */ - 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_standard_extensions = false; /* Allow the use of REFerences (keywords REF_TO, REF, DREF, ^, NULL). */ - stage1_2_options.ref_nonstand_extensions = false; /* Allow the use of non-standard extensions to REF_TO datatypes: REF_TO ANY, and REF_TO in struct elements! */ - stage1_2_options.includedir = NULL; /* Include directory, where included files will be searched for... */ - + runtime_options.safe_extensions = false; /* allow use of SAFExxx datatypes */ + runtime_options.full_token_loc = false; /* error messages specify full token location */ + runtime_options.conversion_functions = false; /* Create a conversion function for derived datatype */ + runtime_options.nested_comments = false; /* Allow the use of nested comments. */ + runtime_options.ref_standard_extensions = false; /* Allow the use of REFerences (keywords REF_TO, REF, DREF, ^, NULL). */ + runtime_options.ref_nonstand_extensions = false; /* Allow the use of non-standard extensions to REF_TO datatypes: REF_TO ANY, and REF_TO in struct elements! */ + runtime_options.includedir = NULL; /* Include directory, where included files will be searched for... */ + + /* Default values for the command line options... */ + runtime_options.relaxed_datatype_model = false; /* by default use the strict datatype equivalence model */ + /******************************************/ /* Parse command line options... */ /******************************************/ - while ((optres = getopt(argc, argv, ":nhvfrRscI:T:O:")) != -1) { + while ((optres = getopt(argc, argv, ":nhvflsrRcI:T:O:")) != -1) { switch(optres) { case 'h': printusage(argv[0]); @@ -163,24 +161,28 @@ case 'v': fprintf(stdout, "%s version %s\n" "changeset id: %s\n", PACKAGE_NAME, PACKAGE_VERSION, HGVERSION); return 0; + case 'l': + runtime_options.relaxed_datatype_model = true; + break; + case 'f': - stage1_2_options.full_token_loc = true; + runtime_options.full_token_loc = true; break; case 's': - stage1_2_options.safe_extensions = true; + runtime_options.safe_extensions = true; break; case 'R': - stage1_2_options.ref_standard_extensions = true; /* use of REF_TO ANY implies activating support for REF extensions! */ - stage1_2_options.ref_nonstand_extensions = true; + runtime_options.ref_standard_extensions = true; /* use of REF_TO ANY implies activating support for REF extensions! */ + runtime_options.ref_nonstand_extensions = true; break; case 'r': - stage1_2_options.ref_standard_extensions = true; + runtime_options.ref_standard_extensions = true; break; case 'c': - stage1_2_options.conversion_functions = true; + runtime_options.conversion_functions = true; break; case 'n': - stage1_2_options.nested_comments = true; + runtime_options.nested_comments = true; break; case 'I': /* NOTE: To improve the usability under windows: @@ -190,7 +192,7 @@ */ path_len = strlen(optarg) - 1; if (optarg[path_len] == '\\') optarg[path_len]= '\0'; - stage1_2_options.includedir = optarg; + runtime_options.includedir = optarg; break; case 'T': /* NOTE: see note above */ @@ -236,7 +238,7 @@ /* Run the compiler... */ /***************************/ /* 1st Pass */ - if (stage1_2(argv[optind], &tree_root, stage1_2_options) < 0) + if (stage1_2(argv[optind], &tree_root) < 0) return EXIT_FAILURE; /* 2nd Pass */ @@ -245,7 +247,7 @@ /* moved to bison, although it could perfectly well still be here instead of in bison code. */ //add_en_eno_param_decl_c::add_to(tree_root); - /* Do semantic verification of code (data type and lvalue checking currently implemented) */ + /* Do semantic verification of code */ if (stage3(tree_root) < 0) return EXIT_FAILURE; diff -r 477393b00f95 -r c012a64dc2fa main.hh --- a/main.hh Sun Nov 16 12:54:10 2014 +0000 +++ b/main.hh Sun Nov 16 14:46:52 2014 +0000 @@ -36,6 +36,29 @@ +/* Compiler options, specified at runtime on the command line */ + +typedef struct { + /* options specific to stage1_2 */ + bool safe_extensions; /* support SAFE_* datatypes defined in PLCOpen TC5 "Safety Software Technical Specification - Part 1" v1.0 */ + 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_standard_extensions; /* Allow the use of REFerences (keywords REF_TO, REF, DREF, ^, NULL). */ + bool ref_nonstand_extensions; /* Allow the use of non-standard extensions to REF_TO datatypes: REF_TO ANY, and REF_TO in struct elements! */ + const char *includedir; /* Include directory, where included files will be searched for... */ + + /* options specific to stage3 */ + bool relaxed_datatype_model; /* Use the relaxed datatype equivalence model, instead of the default strict equivalence model */ +} runtime_options_t; + +extern runtime_options_t runtime_options; + + + + + + /* Function used throughout the code --> used to report failed assertions (i.e. internal compiler errors)! */ #include /* required for NULL */ diff -r 477393b00f95 -r c012a64dc2fa stage1_2/iec_bison.yy --- a/stage1_2/iec_bison.yy Sun Nov 16 12:54:10 2014 +0000 +++ b/stage1_2/iec_bison.yy Sun Nov 16 14:46:52 2014 +0000 @@ -8487,13 +8487,12 @@ int stage2__(const char *filename, - symbol_c **tree_root_ref, - stage1_2_options_t options + symbol_c **tree_root_ref ) { char *libfilename = NULL; - if (options.includedir != NULL) { - INCLUDE_DIRECTORIES[0] = options.includedir; + if (runtime_options.includedir != NULL) { + INCLUDE_DIRECTORIES[0] = runtime_options.includedir; } /* first parse the standard library file... */ @@ -8520,11 +8519,11 @@ allow_function_overloading = true; allow_extensible_function_parameters = true; - full_token_loc = options.full_token_loc; - conversion_functions = options.conversion_functions; - allow_ref_dereferencing = options.ref_standard_extensions; - allow_ref_to_any = options.ref_nonstand_extensions; - allow_ref_to_in_derived_datatypes = options.ref_nonstand_extensions; + full_token_loc = runtime_options.full_token_loc; + conversion_functions = runtime_options.conversion_functions; + allow_ref_dereferencing = runtime_options.ref_standard_extensions; + allow_ref_to_any = runtime_options.ref_nonstand_extensions; + allow_ref_to_in_derived_datatypes = runtime_options.ref_nonstand_extensions; if (yyparse() != 0) ERROR; fclose(libfile); @@ -8557,11 +8556,11 @@ allow_function_overloading = false; allow_extensible_function_parameters = false; - full_token_loc = options.full_token_loc; - conversion_functions = options.conversion_functions; - allow_ref_dereferencing = options.ref_standard_extensions; - allow_ref_to_any = options.ref_nonstand_extensions; - allow_ref_to_in_derived_datatypes = options.ref_nonstand_extensions; + full_token_loc = runtime_options.full_token_loc; + conversion_functions = runtime_options.conversion_functions; + allow_ref_dereferencing = runtime_options.ref_standard_extensions; + allow_ref_to_any = runtime_options.ref_nonstand_extensions; + allow_ref_to_in_derived_datatypes = runtime_options.ref_nonstand_extensions; //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) { diff -r 477393b00f95 -r c012a64dc2fa stage1_2/stage1_2.cc --- a/stage1_2/stage1_2.cc Sun Nov 16 12:54:10 2014 +0000 +++ b/stage1_2/stage1_2.cc Sun Nov 16 14:46:52 2014 +0000 @@ -43,6 +43,7 @@ #include "../absyntax/absyntax.hh" +#include "../main.hh" #include "stage1_2.hh" #include "iec_bison.hh" #include "stage1_2_priv.hh" @@ -51,7 +52,6 @@ -static stage1_2_options_t options_; /******************************************************/ /* whether we are supporting safe extensions */ @@ -60,17 +60,17 @@ /* Part 1: Concepts and Function Blocks, */ /* Version 1.0 – Official Release */ /******************************************************/ -bool get_opt_safe_extensions() {return options_.safe_extensions;} +bool get_opt_safe_extensions() {return runtime_options.safe_extensions;} /************************************/ /* whether to allow nested comments */ /************************************/ -bool get_opt_nested_comments() {return options_.nested_comments;} +bool get_opt_nested_comments() {return runtime_options.nested_comments;} /**************************************************************************/ /* whether to allow REF(), DREF(), REF_TO, NULL and ^ operators/keywords */ /**************************************************************************/ -bool get_opt_ref_standard_extensions() {return options_.ref_standard_extensions;} +bool get_opt_ref_standard_extensions() {return runtime_options.ref_standard_extensions;} @@ -226,12 +226,11 @@ /***********************************************************************/ int stage2__(const char *filename, - symbol_c **tree_root_ref, - stage1_2_options_t options + symbol_c **tree_root_ref ); -int stage1_2(const char *filename, symbol_c **tree_root_ref, stage1_2_options_t options) { +int stage1_2(const char *filename, symbol_c **tree_root_ref) { /* NOTE: we only call stage2 (bison - syntax analysis) directly, as stage 2 will itself call stage1 (flex - lexical analysis) * automatically as needed */ @@ -242,7 +241,6 @@ * These callback functions will get their data from local (to this file) global variables... * We now set those variables... */ - options_ = options; - return stage2__(filename, tree_root_ref, options); -} - + return stage2__(filename, tree_root_ref); +} + diff -r 477393b00f95 -r c012a64dc2fa stage1_2/stage1_2.hh --- a/stage1_2/stage1_2.hh Sun Nov 16 12:54:10 2014 +0000 +++ b/stage1_2/stage1_2.hh Sun Nov 16 14:46:52 2014 +0000 @@ -42,31 +42,10 @@ -/* - * This file includes the interface through which the main function accesses the stage1_2 services - */ +/* This file includes the interface through which the main function accesses the stage1_2 services */ - -typedef struct { - /******************************************************/ - /* whether we are suporting safe extensions */ - /* as defined in PLCopen - Technical Committee 5 */ - /* Safety Software Technical Specification, */ - /* Part 1: Concepts and Function Blocks, */ - /* Version 1.0 – Official Release */ - /******************************************************/ - bool safe_extensions; - 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_standard_extensions; /* Allow the use of REFerences (keywords REF_TO, REF, DREF, ^, NULL). */ - bool ref_nonstand_extensions; /* Allow the use of non-standard extensions to REF_TO datatypes: REF_TO ANY, and REF_TO in struct elements! */ - const char *includedir; /* Include directory, where included files will be searched for... */ -} stage1_2_options_t; - - -int stage1_2(const char *filename, symbol_c **tree_root, stage1_2_options_t options); +int stage1_2(const char *filename, symbol_c **tree_root);