Support for data types of STEP.T and STEP.X in SFCs
authorMario de Sousa <msousa@fe.up.pt>
Wed, 01 Aug 2012 10:31:14 +0100
changeset 619 f8c9ac5c529a
parent 618 5e09f665c2f1
child 620 aef32856eeb5
Support for data types of STEP.T and STEP.X in SFCs
absyntax/absyntax.def
absyntax_utils/search_base_type.cc
absyntax_utils/search_base_type.hh
absyntax_utils/search_var_instance_decl.cc
absyntax_utils/search_var_instance_decl.hh
absyntax_utils/search_varfb_instance_type.cc
absyntax_utils/search_varfb_instance_type.hh
--- a/absyntax/absyntax.def	Wed Aug 01 09:05:25 2012 +0100
+++ b/absyntax/absyntax.def	Wed Aug 01 10:31:14 2012 +0100
@@ -466,8 +466,13 @@
 /*  record_variable '.' field_selector */
 /*  WARNING: input and/or output variables of function blocks
  *           may be accessed as fields of a structured variable!
- *           Code handling a structured_variable_c must take
- *           this into account!
+ *           Code handling a structured_variable_c must take this into account!
+ *           (i.e. that a FB instance may be accessed as a structured variable)!
+ *
+ *  WARNING: Status bit (.X) and activation time (.T) of STEPS in SFC diagrams
+ *           may be accessed as fields of a structured variable!
+ *           Code handling a structured_variable_c must take this into account 
+ *           (i.e. that an SFC STEP may be accessed as a structured variable)!
  */
 SYM_REF2(structured_variable_c, record_variable, field_selector)
 
--- a/absyntax_utils/search_base_type.cc	Wed Aug 01 09:05:25 2012 +0100
+++ b/absyntax_utils/search_base_type.cc	Wed Aug 01 10:31:14 2012 +0100
@@ -334,4 +334,20 @@
 
 
 
-
+/*********************************************/
+/* B.1.6  Sequential function chart elements */
+/*********************************************/
+/* INITIAL_STEP step_name ':' action_association_list END_STEP */
+// SYM_REF2(initial_step_c, step_name, action_association_list)
+void *search_base_type_c::visit(initial_step_c *symbol) {
+  this->current_type_name = NULL; /* this pseudo data type does not have a type name! */
+  return (void *)symbol;
+}
+
+/* STEP step_name ':' action_association_list END_STEP */
+// SYM_REF2(step_c, step_name, action_association_list)
+void *search_base_type_c::visit(step_c *symbol) {
+  this->current_type_name = NULL; /* this pseudo data type does not have a type name! */
+  return (void *)symbol;
+}
+
--- a/absyntax_utils/search_base_type.hh	Wed Aug 01 09:05:25 2012 +0100
+++ b/absyntax_utils/search_base_type.hh	Wed Aug 01 10:31:14 2012 +0100
@@ -234,6 +234,18 @@
   // SYM_REF3(function_block_declaration_c, fblock_name, var_declarations, fblock_body)
     void *visit(function_block_declaration_c *symbol);
 
+  /*********************************************/
+  /* B.1.6  Sequential function chart elements */
+  /*********************************************/
+  /* INITIAL_STEP step_name ':' action_association_list END_STEP */
+  // SYM_REF2(initial_step_c, step_name, action_association_list)
+    void *visit(initial_step_c *symbol);
+
+  /* STEP step_name ':' action_association_list END_STEP */
+  // SYM_REF2(step_c, step_name, action_association_list)
+    void *visit(step_c *symbol);
+
+
 }; // search_base_type_c
 
 
--- a/absyntax_utils/search_var_instance_decl.cc	Wed Aug 01 09:05:25 2012 +0100
+++ b/absyntax_utils/search_var_instance_decl.cc	Wed Aug 01 10:31:14 2012 +0100
@@ -511,21 +511,62 @@
 /*****************************/
 /* B 1.5.2 - Function Blocks */
 /*****************************/
+/*  FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */
+// SYM_REF3(function_block_declaration_c, fblock_name, var_declarations, fblock_body)
 void *search_var_instance_decl_c::visit(function_block_declaration_c *symbol) {
-  /* no need to search through all the body, so we only
-   * visit the variable declarations...!
-   */
-  return symbol->var_declarations->accept(*this);
+  /* visit the variable declarations...! */
+  void *res = symbol->var_declarations->accept(*this);
+  if (NULL != res)
+    return res;
+  
+  /* not yet found, so we look into the body, to see if it is an SFC step! */
+  return symbol->fblock_body->accept(*this);
 }
 
 /**********************/
 /* B 1.5.3 - Programs */
 /**********************/
+/*  PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */
+// SYM_REF3(program_declaration_c, program_type_name, var_declarations, function_block_body)
 void *search_var_instance_decl_c::visit(program_declaration_c *symbol) {
-  /* no need to search through all the body, so we only
-   * visit the variable declarations...!
-   */
-  return symbol->var_declarations->accept(*this);
+  /* visit the variable declarations...! */
+  void *res = symbol->var_declarations->accept(*this);
+  if (NULL != res)
+    return res;
+  
+  /* not yet found, so we look into the body, to see if it is an SFC step! */
+  return symbol->function_block_body->accept(*this);
+}
+
+
+/*********************************************/
+/* B.1.6  Sequential function chart elements */
+/*********************************************/
+/* | sequential_function_chart sfc_network */
+// SYM_LIST(sequential_function_chart_c)
+/* search_var_instance_decl_c inherits from serach_visitor_c, so no need to implement the following method. */
+// void *search_var_instance_decl_c::visit(sequential_function_chart_c *symbol) {...}
+
+/* initial_step {step | transition | action} */
+// SYM_LIST(sfc_network_c)
+/* search_var_instance_decl_c inherits from serach_visitor_c, so no need to implement the following method. */
+// void *search_var_instance_decl_c::visit(sfc_network_c *symbol) {...}
+
+
+/* INITIAL_STEP step_name ':' action_association_list END_STEP */
+// SYM_REF2(initial_step_c, step_name, action_association_list)
+void *search_var_instance_decl_c::visit(initial_step_c *symbol) {
+  if (compare_identifiers(symbol->step_name, search_name) == 0)
+      return symbol;
+  return NULL;
+}
+
+/* STEP step_name ':' action_association_list END_STEP */
+// SYM_REF2(step_c, step_name, action_association_list)
+void *search_var_instance_decl_c::visit(step_c *symbol) {
+  if (compare_identifiers(symbol->step_name, search_name) == 0)
+      return symbol;
+  return NULL;
 }
 
 
@@ -580,3 +621,30 @@
   return NULL;
 }
 
+
+
+/****************************************/
+/* B.2 - Language IL (Instruction List) */
+/****************************************/
+/***********************************/
+/* B 2.1 Instructions and Operands */
+/***********************************/
+/*| instruction_list il_instruction */
+// SYM_LIST(instruction_list_c)
+void *search_var_instance_decl_c::visit(instruction_list_c *symbol) {
+  /* IL code does not contain any variable declarations! */
+  return NULL;
+}
+
+
+/***************************************/
+/* B.3 - Language ST (Structured Text) */
+/***************************************/
+/********************/
+/* B 3.2 Statements */
+/********************/
+// SYM_LIST(statement_list_c)
+void *search_var_instance_decl_c::visit(statement_list_c *symbol) {
+  /* ST code does not contain any variable declarations! */
+  return NULL;
+}
--- a/absyntax_utils/search_var_instance_decl.hh	Wed Aug 01 09:05:25 2012 +0100
+++ b/absyntax_utils/search_var_instance_decl.hh	Wed Aug 01 10:31:14 2012 +0100
@@ -301,6 +301,28 @@
     /**********************/
     void *visit(program_declaration_c *symbol);
 
+    /*********************************************/
+    /* B.1.6  Sequential function chart elements */
+    /*********************************************/
+    /* | sequential_function_chart sfc_network */
+    // SYM_LIST(sequential_function_chart_c)
+    /* search_var_instance_decl_c inherits from serach_visitor_c, so no need to implement the following method. */
+    // void *visit(sequential_function_chart_c *symbol);
+    
+    /* initial_step {step | transition | action} */
+    // SYM_LIST(sfc_network_c)
+    /* search_var_instance_decl_c inherits from serach_visitor_c, so no need to implement the following method. */
+    // void *visit(sfc_network_c *symbol);
+
+
+    /* INITIAL_STEP step_name ':' action_association_list END_STEP */
+    // SYM_REF2(initial_step_c, step_name, action_association_list)
+    void *visit(initial_step_c *symbol);
+
+    /* STEP step_name ':' action_association_list END_STEP */
+    // SYM_REF2(step_c, step_name, action_association_list)
+    void *visit(step_c *symbol);
+
     /********************************/
     /* B 1.7 Configuration elements */
     /********************************/
@@ -330,5 +352,26 @@
     // SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list)
     void *visit(single_resource_declaration_c *symbol);
 
+    
+    /****************************************/
+    /* B.2 - Language IL (Instruction List) */
+    /****************************************/
+    /***********************************/
+    /* B 2.1 Instructions and Operands */
+    /***********************************/
+    /*| instruction_list il_instruction */
+    // SYM_LIST(instruction_list_c)
+    void *visit(instruction_list_c *symbol);
+
+
+    /***************************************/
+    /* B.3 - Language ST (Structured Text) */
+    /***************************************/
+    /********************/
+    /* B 3.2 Statements */
+    /********************/
+    // SYM_LIST(statement_list_c)
+    void *visit(statement_list_c *symbol);
+
 }; // search_var_instance_decl_c
 
--- a/absyntax_utils/search_varfb_instance_type.cc	Wed Aug 01 09:05:25 2012 +0100
+++ b/absyntax_utils/search_varfb_instance_type.cc	Wed Aug 01 10:31:14 2012 +0100
@@ -245,7 +245,7 @@
   for(int i = 0; i < symbol->n; i++) {
     symbol->elements[i]->accept(*this);
   }
-  
+
   return NULL;
 }
 
@@ -306,10 +306,12 @@
    *    ARRAY [xx..yy] OF Stored_Data_Type
    */
   symbol->subscripted_variable->accept(*this);
+  symbol_c *basetype_decl = current_basetype_decl;
+  this->init(); /* set all current_*** pointers to NULL ! */
   
   /* Now we determine the 'Stored_Data_Type', i.e. the data type of the variable stored in the array. */
-  if (NULL != current_basetype_decl) {
-    current_basetype_decl->accept(*this);
+  if (NULL != basetype_decl) {
+    basetype_decl->accept(*this);
   }
   
   return NULL;
@@ -319,17 +321,24 @@
 /*  record_variable '.' field_selector */
 /*  WARNING: input and/or output variables of function blocks
  *           may be accessed as fields of a structured variable!
- *           Code handling a structured_variable_c must take
- *           this into account!
+ *           Code handling a structured_variable_c must take this into account!
+ *           (i.e. that a FB instance may be accessed as a structured variable)!
+ *
+ *  WARNING: Status bit (.X) and activation time (.T) of STEPS in SFC diagrams
+ *           may be accessed as fields of a structured variable!
+ *           Code handling a structured_variable_c must take this into account 
+ *           (i.e. that an SFC STEP may be accessed as a structured variable)!
  */
 // SYM_REF2(structured_variable_c, record_variable, field_selector)
 void *search_varfb_instance_type_c::visit(structured_variable_c *symbol) {
   symbol->record_variable->accept(*this);
+  symbol_c *basetype_decl = current_basetype_decl;
+  this->init(); /* set all current_*** pointers to NULL ! */
   
   /* Now we search for the data type of the field... But only if we were able to determine the data type of the variable */
-  if (NULL != current_basetype_decl) {
+  if (NULL != basetype_decl) {
     current_field_selector = symbol->field_selector;
-    current_basetype_decl->accept(*this);
+    basetype_decl->accept(*this);
     current_field_selector = NULL;
   }
   
@@ -359,3 +368,38 @@
   
   return NULL;
 }
+
+
+
+/*********************************************/
+/* B.1.6  Sequential function chart elements */
+/*********************************************/
+/* INITIAL_STEP step_name ':' action_association_list END_STEP */
+// SYM_REF2(initial_step_c, step_name, action_association_list)
+/* NOTE: this method may be called from visit(structured_variable_c *symbol) method| */
+void *search_varfb_instance_type_c::visit(initial_step_c *symbol) {
+  if (NULL == current_field_selector) ERROR;
+
+  identifier_c T("T");
+  identifier_c X("X");
+  
+  if (compare_identifiers(&T, current_field_selector) == 0)   
+    current_type_id = &search_constant_type_c::time_type_name;
+  if (compare_identifiers(&X, current_field_selector) == 0)   
+    current_type_id = &search_constant_type_c::bool_type_name;
+  
+  current_basetype_decl = search_base_type.get_basetype_decl(current_type_id);
+  current_basetype_id   = search_base_type.get_basetype_id  (current_type_id);
+
+  return NULL;
+}
+
+
+/* STEP step_name ':' action_association_list END_STEP */
+// SYM_REF2(step_c, step_name, action_association_list)
+/* NOTE: this method may be called from visit(structured_variable_c *symbol) method| */
+void *search_varfb_instance_type_c::visit(step_c *symbol) {
+  /* The code here should be identicial to the code in the visit(initial_step_c *) visitor! So we simply call the other visitor! */
+  initial_step_c initial_step(NULL, NULL);
+  return initial_step.accept(*this);
+}
--- a/absyntax_utils/search_varfb_instance_type.hh	Wed Aug 01 09:05:25 2012 +0100
+++ b/absyntax_utils/search_varfb_instance_type.hh	Wed Aug 01 10:31:14 2012 +0100
@@ -188,6 +188,17 @@
     // SYM_REF4(function_block_declaration_c, fblock_name, var_declarations, fblock_body, unused)
     void *visit(function_block_declaration_c *symbol);
 
+    
+    /*********************************************/
+    /* B.1.6  Sequential function chart elements */
+    /*********************************************/
+    /* INITIAL_STEP step_name ':' action_association_list END_STEP */
+    // SYM_REF2(initial_step_c, step_name, action_association_list)
+    void *visit(initial_step_c *symbol);
+    /* STEP step_name ':' action_association_list END_STEP */
+    // SYM_REF2(step_c, step_name, action_association_list)
+    void *visit(step_c *symbol);
+
 }; // search_varfb_instance_type_c