Turn support of derefencing operator '^' an option (default is not supported).
--- a/main.cc Sun Sep 28 16:35:44 2014 +0100
+++ b/main.cc Sun Sep 28 17:39:28 2014 +0100
@@ -144,13 +144,13 @@
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_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... */
+ 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... */
/******************************************/
/* Parse command line options... */
@@ -170,11 +170,11 @@
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;
+ 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;
break;
case 'r':
- stage1_2_options.ref_operator = true;
+ stage1_2_options.ref_standard_extensions = true;
break;
case 'c':
stage1_2_options.conversion_functions = true;
--- a/stage1_2/iec_bison.yy Sun Sep 28 16:35:44 2014 +0100
+++ b/stage1_2/iec_bison.yy Sun Sep 28 17:39:28 2014 +0100
@@ -202,9 +202,12 @@
extern bool full_token_loc;
/* A global flag used to tell the parser whether to generate conversion function for enumerated data types. */
-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 conversion_functions;
+
+/* A global flag used to tell the parser whether to allow use of DREF and '^' operators (defined in IEC 61131-3 v3) */
+extern bool allow_ref_dereferencing;
+
+/* A global flag used to tell the parser whether to allow use of REF_TO ANY datatypes (non-standard extension to IEC 61131-3 v3) */
extern bool allow_ref_to_any;
/* A global flag used to tell the parser whether to allow use of REF_TO as a struct or array element (non-standard extension) */
@@ -2552,7 +2555,7 @@
data_type_declaration:
TYPE type_declaration_list END_TYPE
- {$$ = new data_type_declaration_c($2, locloc(@$)); if (conversion_functions_) include_string((create_enumtype_conversion_functions_c::get_declaration($$)).c_str());}
+ {$$ = new data_type_declaration_c($2, locloc(@$)); if (conversion_functions) include_string((create_enumtype_conversion_functions_c::get_declaration($$)).c_str());}
/* ERROR_CHECK_BEGIN */
| TYPE END_TYPE
{$$ = NULL; print_err_msg(locl(@1), locf(@2), "no data type declared in data type(s) declaration."); yynerrs++;}
@@ -3403,7 +3406,12 @@
*/
| symbolic_variable '^'
/* Dereferencing operator defined in IEC 61131-3 v3. However, implemented here differently then how it is defined in the standard! See following note for explanation! */
- {$$ = new deref_expression_c($1, locloc(@$));}
+ {$$ = new deref_expression_c($1, locloc(@$));
+ if (!allow_ref_dereferencing) {
+ print_err_msg(locf(@$), locl(@$), "Derefencing REF_TO datatypes with '^' is not allowed (use -r option to activate support for this IEC 61131-3 v3 feature).");
+ yynerrs++;
+ }
+}
;
/*
* NOTE: The syntax defined in the v3 standard for the dereferencing operator '^' seems to me to be un-intentionally
@@ -8248,6 +8256,10 @@
/* A global flag indicating whether to include the full variable location when printing out error messages... */
bool full_token_loc;
+/* A global flag used to tell the parser whether to generate conversion function for enumerated data types. */
+bool conversion_functions = false;
+/* A global flag used to tell the parser whether to allow use of DREF and '^' operators (defined in IEC 61131-3 v3) */
+bool allow_ref_dereferencing;
/* 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 global flag used to tell the parser whether to allow use of REF_TO as a struct or array element (non-standard extension) */
@@ -8474,17 +8486,14 @@
extern const char *INCLUDE_DIRECTORIES[];
-
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 allow_ref_to_nonstandard_extensions_ /* allow use of non-standard REF_TO ANY datatypes, and REF_TO inside structs and arrays */
- ) {
+ stage1_2_options_t options
+ ) {
char *libfilename = NULL;
- if (includedir != NULL) {
- INCLUDE_DIRECTORIES[0] = includedir;
+ if (options.includedir != NULL) {
+ INCLUDE_DIRECTORIES[0] = options.includedir;
}
/* first parse the standard library file... */
@@ -8511,9 +8520,11 @@
allow_function_overloading = true;
allow_extensible_function_parameters = true;
- full_token_loc = full_token_loc_;
- allow_ref_to_any = allow_ref_to_nonstandard_extensions_;
- allow_ref_to_in_derived_datatypes = allow_ref_to_nonstandard_extensions_;
+ 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;
if (yyparse() != 0)
ERROR;
fclose(libfile);
@@ -8546,9 +8557,11 @@
allow_function_overloading = false;
allow_extensible_function_parameters = false;
- full_token_loc = full_token_loc_;
- allow_ref_to_any = allow_ref_to_nonstandard_extensions_;
- allow_ref_to_in_derived_datatypes = allow_ref_to_nonstandard_extensions_;
+ 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;
//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) {
--- a/stage1_2/iec_flex.ll Sun Sep 28 16:35:44 2014 +0100
+++ b/stage1_2/iec_flex.ll Sun Sep 28 17:39:28 2014 +0100
@@ -1251,10 +1251,10 @@
/******************************************************/
-REF {if (get_opt_ref_operator()) return REF; else{REJECT;}} /* Keyword in IEC 61131-3 v3 */
-DREF {if (get_opt_ref_operator()) return DREF; else{REJECT;}} /* Keyword in IEC 61131-3 v3 */
-REF_TO {if (get_opt_ref_operator()) return REF_TO; else{REJECT;}} /* Keyword in IEC 61131-3 v3 */
-NULL {if (get_opt_ref_operator()) return NULL_token; else{REJECT;}} /* Keyword in IEC 61131-3 v3 */
+REF {if (get_opt_ref_standard_extensions()) return REF; else{REJECT;}} /* Keyword in IEC 61131-3 v3 */
+DREF {if (get_opt_ref_standard_extensions()) return DREF; else{REJECT;}} /* Keyword in IEC 61131-3 v3 */
+REF_TO {if (get_opt_ref_standard_extensions()) return REF_TO; else{REJECT;}} /* Keyword in IEC 61131-3 v3 */
+NULL {if (get_opt_ref_standard_extensions()) return NULL_token; else{REJECT;}} /* Keyword in IEC 61131-3 v3 */
EN return EN; /* Keyword */
ENO return ENO; /* Keyword */
--- a/stage1_2/stage1_2.cc Sun Sep 28 16:35:44 2014 +0100
+++ b/stage1_2/stage1_2.cc Sun Sep 28 17:39:28 2014 +0100
@@ -51,7 +51,7 @@
-
+static stage1_2_options_t options_;
/******************************************************/
/* whether we are supporting safe extensions */
@@ -60,27 +60,18 @@
/* Part 1: Concepts and Function Blocks, */
/* Version 1.0 – Official Release */
/******************************************************/
-bool safe_extensions_ = false;
-bool get_opt_safe_extensions() {return safe_extensions_;}
+bool get_opt_safe_extensions() {return options_.safe_extensions;}
/************************************/
/* whether to allow nested comments */
/************************************/
-bool nested_comments_ = false;
-bool get_opt_nested_comments() {return nested_comments_;}
-
-/************************************/
-/* whether to allow REF() operator */
-/************************************/
-bool ref_operator_ = false;
-bool get_opt_ref_operator() {return ref_operator_;}
-
-
-/******************************************************/
-/* whether we are supporting conversion functions */
-/* for enumerate data types */
-/******************************************************/
-bool conversion_functions_ = false;
+bool get_opt_nested_comments() {return 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;}
+
/****************************************************/
@@ -234,12 +225,9 @@
/***********************************************************************/
/***********************************************************************/
-
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 ref_to_any /* allow use of non-standard REF_TO ANY datatypes */
+ stage1_2_options_t options
);
@@ -254,11 +242,7 @@
* These callback functions will get their data from local (to this file) global variables...
* We now set those variables...
*/
-
- nested_comments_ = options.nested_comments;
- 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, options.ref_to_any);
-}
-
+ options_ = options;
+ return stage2__(filename, tree_root_ref, options);
+}
+
--- a/stage1_2/stage1_2.hh Sun Sep 28 16:35:44 2014 +0100
+++ b/stage1_2/stage1_2.hh Sun Sep 28 17:39:28 2014 +0100
@@ -57,12 +57,12 @@
/* 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_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... */
+ 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;
--- a/stage1_2/stage1_2_priv.hh Sun Sep 28 16:35:44 2014 +0100
+++ b/stage1_2/stage1_2_priv.hh Sun Sep 28 17:39:28 2014 +0100
@@ -93,10 +93,10 @@
/************************************/
bool get_opt_nested_comments();
-/************************************/
-/* whether to allow REF() operator */
-/************************************/
-bool get_opt_ref_operator();
+/**************************************************************************/
+/* whether to allow REF(), DREF(), REF_TO, NULL and ^ operators/keywords */
+/**************************************************************************/
+bool get_opt_ref_standard_extensions();