Add support for non-standard VOID datatype. May ony be used to define functions returning VOID.
--- a/absyntax/absyntax.def Wed May 11 19:38:31 2016 +0100
+++ b/absyntax/absyntax.def Fri May 13 12:18:50 2016 +0100
@@ -267,6 +267,7 @@
SYM_REF0(lword_type_name_c)
SYM_REF0(string_type_name_c)
SYM_REF0(wstring_type_name_c)
+SYM_REF0(void_c) /* a non-standard extension! */
/*****************************************************************/
/* Keywords defined in "Safety Software Technical Specification" */
--- a/absyntax_utils/search_base_type.cc Wed May 11 19:38:31 2016 +0100
+++ b/absyntax_utils/search_base_type.cc Fri May 13 12:18:50 2016 +0100
@@ -184,6 +184,8 @@
void *search_base_type_c::visit(string_type_name_c *symbol) {return (void *)symbol;}
void *search_base_type_c::visit(wstring_type_name_c *symbol) {return (void *)symbol;}
+/* A non standard datatype! */
+void *search_base_type_c::visit(void_c *symbol) {return (void *)symbol;}
/******************************************************/
/* Extensions to the base standard as defined in */
--- a/absyntax_utils/search_base_type.hh Wed May 11 19:38:31 2016 +0100
+++ b/absyntax_utils/search_base_type.hh Fri May 13 12:18:50 2016 +0100
@@ -141,6 +141,7 @@
void *visit(lword_type_name_c *symbol);
void *visit(string_type_name_c *symbol);
void *visit(wstring_type_name_c *symbol);
+ void *visit(void_c *symbol); /* A non standard datatype! */
/******************************************************/
/* Extensions to the base standard as defined in */
--- a/main.cc Wed May 11 19:38:31 2016 +0100
+++ b/main.cc Fri May 13 12:18:50 2016 +0100
@@ -122,6 +122,7 @@
printf(" as well as REF_TO in ARRAYs and STRUCTs (a non-standard extension!)\n");
printf(" -a : allow use of non-literals in array size limits (a non-standard extension!)\n");
printf(" -i : allow POUs with no in out and inout parameters (a non-standard extension!)\n");
+ printf(" -b : allow functions returning VOID (a non-standard extension!)\n");
printf(" -e : disable generation of implicit EN and ENO parameters.\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);
@@ -145,6 +146,7 @@
int path_len;
/* Default values for the command line options... */
+ runtime_options.allow_void_datatype = false; /* disable: allow declaration of functions returning VOID */
runtime_options.allow_missing_var_in = false; /* disable: allow definition and invocation of POUs with no input, output and in_out parameters! */
runtime_options.disable_implicit_en_eno = false; /* disable: do not generate EN and ENO parameters */
runtime_options.pre_parsing = false; /* disable: allow use of forward references (run pre-parsing phase before the definitive parsing phase that builds the AST) */
@@ -163,7 +165,7 @@
/******************************************/
/* Parse command line options... */
/******************************************/
- while ((optres = getopt(argc, argv, ":nehvfplsrRaicI:T:O:")) != -1) {
+ while ((optres = getopt(argc, argv, ":nehvfplsrRabicI:T:O:")) != -1) {
switch(optres) {
case 'h':
printusage(argv[0]);
@@ -179,6 +181,7 @@
runtime_options.ref_nonstand_extensions = true; break;
case 'r': runtime_options.ref_standard_extensions = true; break;
case 'a': runtime_options.nonliteral_in_array_size = true; break;
+ case 'b': runtime_options.allow_void_datatype = true; break;
case 'i': runtime_options.allow_missing_var_in = true; break;
case 'c': runtime_options.conversion_functions = true; break;
case 'n': runtime_options.nested_comments = true; break;
--- a/main.hh Wed May 11 19:38:31 2016 +0100
+++ b/main.hh Fri May 13 12:18:50 2016 +0100
@@ -40,6 +40,7 @@
typedef struct {
/* options specific to stage1_2 */
+ bool allow_void_datatype; /* Allow declaration of functions returning VOID */
bool allow_missing_var_in; /* Allow definition and invocation of POUs with no input, output and in_out parameters! */
bool disable_implicit_en_eno; /* Disable the generation of implicit EN and ENO parameters on functions and Function Blocks */
bool pre_parsing; /* Support forward references (Run a pre-parsing phase before the defintive parsing phase that builds the AST) */
--- a/stage1_2/iec_bison.yy Wed May 11 19:38:31 2016 +0100
+++ b/stage1_2/iec_bison.yy Fri May 13 12:18:50 2016 +0100
@@ -650,6 +650,9 @@
%token TIME_OF_DAY
%token TOD
+/* A non-standard extension! */
+%token VOID
+
/******************************************************/
/* Symbols defined in */
/* "Safety Software Technical Specification, */
@@ -5008,6 +5011,14 @@
direct_variable_symtable.pop();
library_element_symtable.insert($1, prev_declared_derived_function_name_token);
}
+/* | FUNCTION derived_function_name ':' VOID io_OR_function_var_declarations_list function_body END_FUNCTION */
+| function_name_declaration ':' VOID io_OR_function_var_declarations_list function_body END_FUNCTION
+ {$$ = new function_declaration_c($1, new void_c(locloc(@3)), $4, $5, locloc(@$));
+ if (!runtime_options.disable_implicit_en_eno) add_en_eno_param_decl_c::add_to($$); /* add EN and ENO declarations, if not already there */
+ variable_name_symtable.pop();
+ direct_variable_symtable.pop();
+ library_element_symtable.insert($1, prev_declared_derived_function_name_token);
+ }
/* ERROR_CHECK_BEGIN */
| function_name_declaration elementary_type_name io_OR_function_var_declarations_list function_body END_FUNCTION
{$$ = NULL; print_err_msg(locl(@1), locf(@2), "':' missing after function name in function declaration."); yynerrs++;}
--- a/stage1_2/iec_flex.ll Wed May 11 19:38:31 2016 +0100
+++ b/stage1_2/iec_flex.ll Fri May 13 12:18:50 2016 +0100
@@ -1367,6 +1367,10 @@
DATE_AND_TIME return DATE_AND_TIME; /* Keyword (Data Type) */
TIME_OF_DAY return TIME_OF_DAY; /* Keyword (Data Type) */
+ /* A non-standard extension! */
+VOID {if (runtime_options.allow_void_datatype) {return VOID;} else {REJECT;}}
+
+
/*****************************************************************/
/* Keywords defined in "Safety Software Technical Specification" */
/*****************************************************************/
--- a/stage4/generate_iec/generate_iec.cc Wed May 11 19:38:31 2016 +0100
+++ b/stage4/generate_iec/generate_iec.cc Fri May 13 12:18:50 2016 +0100
@@ -392,48 +392,50 @@
/***********************************/
/* B 1.3.1 - Elementary Data Types */
/***********************************/
-void *visit(time_type_name_c *symbol) {s4o.print("TIME"); return NULL;}
-void *visit(bool_type_name_c *symbol) {s4o.print("BOOL"); return NULL;}
-void *visit(sint_type_name_c *symbol) {s4o.print("SINT"); return NULL;}
-void *visit(int_type_name_c *symbol) {s4o.print("INT"); return NULL;}
-void *visit(dint_type_name_c *symbol) {s4o.print("DINT"); return NULL;}
-void *visit(lint_type_name_c *symbol) {s4o.print("LINT"); return NULL;}
-void *visit(usint_type_name_c *symbol) {s4o.print("USINT"); return NULL;}
-void *visit(uint_type_name_c *symbol) {s4o.print("UINT"); return NULL;}
-void *visit(udint_type_name_c *symbol) {s4o.print("UDINT"); return NULL;}
-void *visit(ulint_type_name_c *symbol) {s4o.print("ULINT"); return NULL;}
-void *visit(real_type_name_c *symbol) {s4o.print("REAL"); return NULL;}
-void *visit(lreal_type_name_c *symbol) {s4o.print("LREAL"); return NULL;}
-void *visit(date_type_name_c *symbol) {s4o.print("DATE"); return NULL;}
-void *visit(tod_type_name_c *symbol) {s4o.print("TOD"); return NULL;}
-void *visit(dt_type_name_c *symbol) {s4o.print("DT"); return NULL;}
-void *visit(byte_type_name_c *symbol) {s4o.print("BYTE"); return NULL;}
-void *visit(word_type_name_c *symbol) {s4o.print("WORD"); return NULL;}
-void *visit(lword_type_name_c *symbol) {s4o.print("LWORD"); return NULL;}
-void *visit(dword_type_name_c *symbol) {s4o.print("DWORD"); return NULL;}
-void *visit(string_type_name_c *symbol) {s4o.print("STRING"); return NULL;}
-void *visit(wstring_type_name_c *symbol) {s4o.print("WSTRING"); return NULL;}
-
-void *visit(safetime_type_name_c *symbol) {s4o.print("SAFETIME"); return NULL;}
-void *visit(safebool_type_name_c *symbol) {s4o.print("SAFEBOOL"); return NULL;}
-void *visit(safesint_type_name_c *symbol) {s4o.print("SAFESINT"); return NULL;}
-void *visit(safeint_type_name_c *symbol) {s4o.print("SAFEINT"); return NULL;}
-void *visit(safedint_type_name_c *symbol) {s4o.print("SAFEDINT"); return NULL;}
-void *visit(safelint_type_name_c *symbol) {s4o.print("SAFELINT"); return NULL;}
-void *visit(safeusint_type_name_c *symbol) {s4o.print("SAFEUSINT"); return NULL;}
-void *visit(safeuint_type_name_c *symbol) {s4o.print("SAFEUINT"); return NULL;}
-void *visit(safeudint_type_name_c *symbol) {s4o.print("SAFEUDINT"); return NULL;}
-void *visit(safeulint_type_name_c *symbol) {s4o.print("SAFEULINT"); return NULL;}
-void *visit(safereal_type_name_c *symbol) {s4o.print("SAFEREAL"); return NULL;}
-void *visit(safelreal_type_name_c *symbol) {s4o.print("SAFELREAL"); return NULL;}
-void *visit(safedate_type_name_c *symbol) {s4o.print("SAFEDATE"); return NULL;}
-void *visit(safetod_type_name_c *symbol) {s4o.print("SAFETOD"); return NULL;}
-void *visit(safedt_type_name_c *symbol) {s4o.print("SAFEDT"); return NULL;}
-void *visit(safebyte_type_name_c *symbol) {s4o.print("SAFEBYTE"); return NULL;}
-void *visit(safeword_type_name_c *symbol) {s4o.print("SAFEWORD"); return NULL;}
-void *visit(safelword_type_name_c *symbol) {s4o.print("SAFELWORD"); return NULL;}
-void *visit(safedword_type_name_c *symbol) {s4o.print("SAFEDWORD"); return NULL;}
-void *visit(safestring_type_name_c *symbol) {s4o.print("SAFESTRING"); return NULL;}
+void *visit( time_type_name_c *symbol) {s4o.print("TIME"); return NULL;}
+void *visit( bool_type_name_c *symbol) {s4o.print("BOOL"); return NULL;}
+void *visit( sint_type_name_c *symbol) {s4o.print("SINT"); return NULL;}
+void *visit( int_type_name_c *symbol) {s4o.print("INT"); return NULL;}
+void *visit( dint_type_name_c *symbol) {s4o.print("DINT"); return NULL;}
+void *visit( lint_type_name_c *symbol) {s4o.print("LINT"); return NULL;}
+void *visit( usint_type_name_c *symbol) {s4o.print("USINT"); return NULL;}
+void *visit( uint_type_name_c *symbol) {s4o.print("UINT"); return NULL;}
+void *visit( udint_type_name_c *symbol) {s4o.print("UDINT"); return NULL;}
+void *visit( ulint_type_name_c *symbol) {s4o.print("ULINT"); return NULL;}
+void *visit( real_type_name_c *symbol) {s4o.print("REAL"); return NULL;}
+void *visit( lreal_type_name_c *symbol) {s4o.print("LREAL"); return NULL;}
+void *visit( date_type_name_c *symbol) {s4o.print("DATE"); return NULL;}
+void *visit( tod_type_name_c *symbol) {s4o.print("TOD"); return NULL;}
+void *visit( dt_type_name_c *symbol) {s4o.print("DT"); return NULL;}
+void *visit( byte_type_name_c *symbol) {s4o.print("BYTE"); return NULL;}
+void *visit( word_type_name_c *symbol) {s4o.print("WORD"); return NULL;}
+void *visit( lword_type_name_c *symbol) {s4o.print("LWORD"); return NULL;}
+void *visit( dword_type_name_c *symbol) {s4o.print("DWORD"); return NULL;}
+void *visit( string_type_name_c *symbol) {s4o.print("STRING"); return NULL;}
+void *visit( wstring_type_name_c *symbol) {s4o.print("WSTRING"); return NULL;}
+
+void *visit( void_c *symbol) {s4o.print("VOID"); return NULL;} /* a non-standard extension! */
+
+void *visit( safetime_type_name_c *symbol) {s4o.print("SAFETIME"); return NULL;}
+void *visit( safebool_type_name_c *symbol) {s4o.print("SAFEBOOL"); return NULL;}
+void *visit( safesint_type_name_c *symbol) {s4o.print("SAFESINT"); return NULL;}
+void *visit( safeint_type_name_c *symbol) {s4o.print("SAFEINT"); return NULL;}
+void *visit( safedint_type_name_c *symbol) {s4o.print("SAFEDINT"); return NULL;}
+void *visit( safelint_type_name_c *symbol) {s4o.print("SAFELINT"); return NULL;}
+void *visit( safeusint_type_name_c *symbol) {s4o.print("SAFEUSINT"); return NULL;}
+void *visit( safeuint_type_name_c *symbol) {s4o.print("SAFEUINT"); return NULL;}
+void *visit( safeudint_type_name_c *symbol) {s4o.print("SAFEUDINT"); return NULL;}
+void *visit( safeulint_type_name_c *symbol) {s4o.print("SAFEULINT"); return NULL;}
+void *visit( safereal_type_name_c *symbol) {s4o.print("SAFEREAL"); return NULL;}
+void *visit( safelreal_type_name_c *symbol) {s4o.print("SAFELREAL"); return NULL;}
+void *visit( safedate_type_name_c *symbol) {s4o.print("SAFEDATE"); return NULL;}
+void *visit( safetod_type_name_c *symbol) {s4o.print("SAFETOD"); return NULL;}
+void *visit( safedt_type_name_c *symbol) {s4o.print("SAFEDT"); return NULL;}
+void *visit( safebyte_type_name_c *symbol) {s4o.print("SAFEBYTE"); return NULL;}
+void *visit( safeword_type_name_c *symbol) {s4o.print("SAFEWORD"); return NULL;}
+void *visit( safelword_type_name_c *symbol) {s4o.print("SAFELWORD"); return NULL;}
+void *visit( safedword_type_name_c *symbol) {s4o.print("SAFEDWORD"); return NULL;}
+void *visit( safestring_type_name_c *symbol) {s4o.print("SAFESTRING"); return NULL;}
void *visit(safewstring_type_name_c *symbol) {s4o.print("SAFEWSTRING"); return NULL;}
/********************************/