Make support for use of variables in array size declarations a command line option (off by default)
authormjsousa
Sun, 28 Dec 2014 13:29:47 +0000
changeset 980 9ed5aff159db
parent 979 f8f1d89ff7d5
child 981 aad6aa35ce60
Make support for use of variables in array size declarations a command line option (off by default)
main.cc
main.hh
stage1_2/iec_bison.yy
--- a/main.cc	Sun Dec 28 12:05:39 2014 +0000
+++ b/main.cc	Sun Dec 28 13:29:47 2014 +0000
@@ -119,6 +119,7 @@
   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");
+  printf(" -a : allow use of non-literals in array size limits (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,6 +148,7 @@
   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.nonliteral_in_array_size= false; /* Allow the use of constant non-literals when specifying size of arrays (ARRAY [1..max] OF INT) */
   runtime_options.includedir              = NULL;  /* Include directory, where included files will be searched for... */
 
   /* Default values for the command line options... */
@@ -155,7 +157,7 @@
   /******************************************/
   /*   Parse command line options...        */
   /******************************************/
-  while ((optres = getopt(argc, argv, ":nhvfplsrRcI:T:O:")) != -1) {
+  while ((optres = getopt(argc, argv, ":nhvfplsrRacI:T:O:")) != -1) {
     switch(optres) {
     case 'h':
       printusage(argv[0]);
@@ -163,31 +165,16 @@
     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 'p':
-      runtime_options.pre_parsing = true;
-      break;
-    case 'f':
-      runtime_options.full_token_loc = true;
-      break;
-    case 's':
-      runtime_options.safe_extensions = true;
-      break;
-    case 'R':
-      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':
-      runtime_options.ref_standard_extensions = true;
-      break;
-    case 'c':
-      runtime_options.conversion_functions = true;
-      break;
-    case 'n':
-      runtime_options.nested_comments = true;
-      break;
+    case 'l': runtime_options.relaxed_datatype_model   = true;  break;
+    case 'p': runtime_options.pre_parsing              = true;  break;
+    case 'f': runtime_options.full_token_loc           = true;  break;
+    case 's': runtime_options.safe_extensions          = true;  break;
+    case 'R': 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': runtime_options.ref_standard_extensions  = true;  break;
+    case 'a': runtime_options.nonliteral_in_array_size = true;  break;
+    case 'c': runtime_options.conversion_functions     = true;  break;
+    case 'n': runtime_options.nested_comments          = true;  break;
     case 'I':
       /* NOTE: To improve the usability under windows:
        *       We delete last char's path if it ends with "\".
--- a/main.hh	Sun Dec 28 12:05:39 2014 +0000
+++ b/main.hh	Sun Dec 28 13:29:47 2014 +0000
@@ -47,6 +47,7 @@
 	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! */
+	bool nonliteral_in_array_size; /* Allow the use of constant non-literals when specifying size of arrays (ARRAY [1..max] OF INT) */
 	const char *includedir;        /* Include directory, where included files will be searched for... */
 	
    /* options specific to stage3 */
--- a/stage1_2/iec_bison.yy	Sun Dec 28 12:05:39 2014 +0000
+++ b/stage1_2/iec_bison.yy	Sun Dec 28 13:29:47 2014 +0000
@@ -2776,11 +2776,26 @@
   signed_integer DOTDOT signed_integer
 	{$$ = new subrange_c($1, $3, locloc(@$));}
 | any_identifier DOTDOT signed_integer
-	{$$ = new subrange_c(new symbolic_constant_c($1, locloc(@1)), $3, locloc(@$));}
+	{$$ = new subrange_c(new symbolic_constant_c($1, locloc(@1)), $3, locloc(@$));
+	 if (!runtime_options.nonliteral_in_array_size) {
+	   print_err_msg(locf(@1), locl(@1), "Use of variables in array size limits is not allowed in IEC 61131-3 (use -a option to activate support for this non-standard feature)."); 
+	   yynerrs++;
+	 }
+	}
 | signed_integer DOTDOT any_identifier
-	{$$ = new subrange_c($1, new symbolic_constant_c($3, locloc(@3)), locloc(@$));}
+	{$$ = new subrange_c($1, new symbolic_constant_c($3, locloc(@3)), locloc(@$));
+	 if (!runtime_options.nonliteral_in_array_size) {
+	   print_err_msg(locf(@3), locl(@3), "Use of variables in array size limits is not allowed in IEC 61131-3 (use -a option to activate support for this non-standard feature)."); 
+	   yynerrs++;
+	 }
+	}
 | any_identifier DOTDOT any_identifier
-	{$$ = new subrange_c(new symbolic_constant_c($1, locloc(@1)), new symbolic_constant_c($3, locloc(@3)), locloc(@$));}
+	{$$ = new subrange_c(new symbolic_constant_c($1, locloc(@1)), new symbolic_constant_c($3, locloc(@3)), locloc(@$));
+	 if (!runtime_options.nonliteral_in_array_size) {
+	   print_err_msg(locf(@$), locl(@$), "Use of variables in array size limits is not allowed in IEC 61131-3 (use -a option to activate support for this non-standard feature)."); 
+	   yynerrs++;
+	 }
+	}
 /* ERROR_CHECK_BEGIN */
 | signed_integer signed_integer
 	{$$ = NULL; print_err_msg(locl(@1), locf(@2), "'..' missing between bounds in subrange definition."); yynerrs++;}