Make use of pre-parser a command line option.
authormjsousa
Sun, 30 Nov 2014 10:27:28 +0000
changeset 956 513809fbfaf9
parent 955 5e2e7707f770
child 957 4489afa5b1c5
Make use of pre-parser a command line option.
main.cc
main.hh
stage1_2/iec_bison.yy
--- a/main.cc	Sun Nov 30 10:26:31 2014 +0000
+++ b/main.cc	Sun Nov 30 10:27:28 2014 +0000
@@ -113,6 +113,7 @@
   printf(" -h : show this help message\n");
   printf(" -v : print version number\n");  
   printf(" -f : display full token location on error messages\n");
+  printf(" -p : allow use of forward references                (a non-standard extension?)\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");
@@ -139,6 +140,7 @@
   int path_len;
 
   /* Default values for the command line options... */
+  runtime_options.pre_parsing             = false; /* allow use of forward references (run pre-parsing phase before the definitive parsing phase that builds the AST) */
   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 */
@@ -153,7 +155,7 @@
   /******************************************/
   /*   Parse command line options...        */
   /******************************************/
-  while ((optres = getopt(argc, argv, ":nhvflsrRcI:T:O:")) != -1) {
+  while ((optres = getopt(argc, argv, ":nhvfplsrRcI:T:O:")) != -1) {
     switch(optres) {
     case 'h':
       printusage(argv[0]);
@@ -164,7 +166,9 @@
     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;
--- a/main.hh	Sun Nov 30 10:26:31 2014 +0000
+++ b/main.hh	Sun Nov 30 10:27:28 2014 +0000
@@ -40,6 +40,7 @@
 
 typedef struct {
    /* options specific to stage1_2 */
+	bool pre_parsing;              /* Support forward references (Run a pre-parsing phase before the defintive parsing phase that builds the AST) */
 	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 */
--- a/stage1_2/iec_bison.yy	Sun Nov 30 10:26:31 2014 +0000
+++ b/stage1_2/iec_bison.yy	Sun Nov 30 10:27:28 2014 +0000
@@ -8730,13 +8730,14 @@
   /*******************************/
   /* Do the  PRE parsing run...! */
   /*******************************/
-  // fprintf (stderr, "----> Starting pre-parsing!\n");
-  tree_root = NULL;
-  set_preparse_state();
-  if (parse_files(libfilename, filename) < 0)
-    exit(EXIT_FAILURE);
-  // TODO: delete the current AST. For the moment, we leave all the objects in memory (not much of an issue in a program that always runs to completion).
-
+  if (runtime_options.pre_parsing) {
+    // fprintf (stderr, "----> Starting pre-parsing!\n");
+    tree_root = NULL;
+    set_preparse_state();
+    if (parse_files(libfilename, filename) < 0)
+      exit(EXIT_FAILURE);
+    // TODO: delete the current AST. For the moment, we leave all the objects in memory (not much of an issue in a program that always runs to completion).
+  }
   /*******************************/
   /* Do the main parsing run...! */
   /*******************************/