absyntax_utils/search_var_instance_decl.cc
changeset 217 f5dfadf5de54
parent 202 da1a8186f86f
child 221 c6aed7e5f070
equal deleted inserted replaced
216:136d6ae70745 217:f5dfadf5de54
    23  */
    23  */
    24 
    24 
    25 /* Determine the data type of a specific variable instance, including
    25 /* Determine the data type of a specific variable instance, including
    26  * function block instances.
    26  * function block instances.
    27  * A reference to the relevant variable declaration is returned.
    27  * A reference to the relevant variable declaration is returned.
    28  * The variable instance may NOT be a member of a structure of a memeber
    28  * The variable instance may NOT be a member of a structure of a member
    29  * of a structure of an element of an array of ...
    29  * of a structure of an element of an array of ...
    30  *
    30  *
    31  * example:
    31  * example:
    32  *    window.points[1].coordinate.x
    32  *    window.points[1].coordinate.x
    33  *    window.points[1].colour
    33  *    window.points[1].colour
    56 #include "absyntax_utils.hh"
    56 #include "absyntax_utils.hh"
    57 
    57 
    58 
    58 
    59 search_var_instance_decl_c::search_var_instance_decl_c(symbol_c *search_scope) {
    59 search_var_instance_decl_c::search_var_instance_decl_c(symbol_c *search_scope) {
    60   this->current_vartype = none_vt;
    60   this->current_vartype = none_vt;
       
    61   this->current_varqualifier = none_vq;
    61   this->search_scope = search_scope;
    62   this->search_scope = search_scope;
    62   this->search_name = NULL;
    63   this->search_name = NULL;
    63   this->current_type_decl = NULL;
    64   this->current_type_decl = NULL;
    64 }
    65 }
    65 
    66 
    66 symbol_c *search_var_instance_decl_c::get_decl(symbol_c *variable_instance_name) {
    67 symbol_c *search_var_instance_decl_c::get_decl(symbol_c *variable_instance_name) {
       
    68   this->current_vartype = none_vt;
       
    69   this->current_varqualifier = none_vq;
    67   this->search_name = variable_instance_name;
    70   this->search_name = variable_instance_name;
    68   return (symbol_c *)search_scope->accept(*this);
    71   return (symbol_c *)search_scope->accept(*this);
    69 }
    72 }
    70 
    73 
    71 unsigned int search_var_instance_decl_c::get_vartype() {
    74 unsigned int search_var_instance_decl_c::get_vartype() {
    72   return current_vartype;
    75   return current_vartype;
       
    76 }
       
    77 
       
    78 unsigned int search_var_instance_decl_c::get_varqualifier() {
       
    79   return current_varqualifier;
    73 }
    80 }
    74 
    81 
    75 /***************************/
    82 /***************************/
    76 /* B 0 - Programming Model */
    83 /* B 0 - Programming Model */
    77 /***************************/
    84 /***************************/
    78 void *search_var_instance_decl_c::visit(library_c *symbol) {
    85 void *search_var_instance_decl_c::visit(library_c *symbol) {
    79   /* we do not want to search multiple declaration scopes,
    86   /* we do not want to search multiple declaration scopes,
    80    * so we do not visit all the functions, fucntion blocks, etc...
    87    * so we do not visit all the functions, function blocks, etc...
    81    */
    88    */
    82   return NULL;
    89   return NULL;
    83 }
    90 }
    84 
    91 
    85 
    92 
    86 
    93 
    87 /******************************************/
    94 /******************************************/
    88 /* B 1.4.3 - Declaration & Initialisation */
    95 /* B 1.4.3 - Declaration & Initialization */
    89 /******************************************/
    96 /******************************************/
       
    97 
       
    98 void *search_var_instance_decl_c::visit(constant_option_c *symbol) {
       
    99   current_varqualifier = constant_vq;
       
   100   return NULL;
       
   101 }
       
   102 
       
   103 void *search_var_instance_decl_c::visit(retain_option_c *symbol) {
       
   104   current_varqualifier = retain_vq;
       
   105   return NULL;
       
   106 }
       
   107 
       
   108 void *search_var_instance_decl_c::visit(non_retain_option_c *symbol) {
       
   109   current_varqualifier = non_retain_vq;
       
   110   return NULL;
       
   111 }
       
   112 
    90 /* edge -> The F_EDGE or R_EDGE directive */
   113 /* edge -> The F_EDGE or R_EDGE directive */
    91 // SYM_REF2(edge_declaration_c, edge, var1_list)
   114 // SYM_REF2(edge_declaration_c, edge, var1_list)
    92 // TODO
   115 // TODO
    93 
   116 
    94 void *search_var_instance_decl_c::visit(input_declarations_c *symbol) {
   117 void *search_var_instance_decl_c::visit(input_declarations_c *symbol) {
    95   current_vartype = input_vt;
   118   current_vartype = input_vt;
       
   119   if (symbol->option != NULL)
       
   120     symbol->option->accept(*this);
    96   void *res = symbol->input_declaration_list->accept(*this);
   121   void *res = symbol->input_declaration_list->accept(*this);
    97   if (res == NULL) {
   122   if (res == NULL) {
    98     current_vartype = none_vt;
   123     current_vartype = none_vt;
       
   124     current_varqualifier = none_vq;
    99   }
   125   }
   100   return res;
   126   return res;
   101 }
   127 }
   102 
   128 
   103 /* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */
   129 /* VAR_OUTPUT [RETAIN | NON_RETAIN] var_init_decl_list END_VAR */
   104 /* option -> may be NULL ! */
   130 /* option -> may be NULL ! */
   105 void *search_var_instance_decl_c::visit(output_declarations_c *symbol) {
   131 void *search_var_instance_decl_c::visit(output_declarations_c *symbol) {
   106   current_vartype = output_vt;
   132   current_vartype = output_vt;
       
   133   if (symbol->option != NULL)
       
   134     symbol->option->accept(*this);
   107   void *res = symbol->var_init_decl_list->accept(*this);
   135   void *res = symbol->var_init_decl_list->accept(*this);
   108   if (res == NULL) {
   136   if (res == NULL) {
   109     current_vartype = none_vt;
   137     current_vartype = none_vt;
       
   138     current_varqualifier = none_vq;
   110   }
   139   }
   111   return res;
   140   return res;
   112 }
   141 }
   113 
   142 
   114 /*  VAR_IN_OUT var_declaration_list END_VAR */
   143 /*  VAR_IN_OUT var_declaration_list END_VAR */
   132 /* VAR [CONSTANT] var_init_decl_list END_VAR */
   161 /* VAR [CONSTANT] var_init_decl_list END_VAR */
   133 /* option -> may be NULL ! */
   162 /* option -> may be NULL ! */
   134 /* helper symbol for input_declarations */
   163 /* helper symbol for input_declarations */
   135 void *search_var_instance_decl_c::visit(var_declarations_c *symbol) {
   164 void *search_var_instance_decl_c::visit(var_declarations_c *symbol) {
   136   current_vartype = private_vt;
   165   current_vartype = private_vt;
       
   166   if (symbol->option != NULL)
       
   167     symbol->option->accept(*this);
   137   void *res = symbol->var_init_decl_list->accept(*this);
   168   void *res = symbol->var_init_decl_list->accept(*this);
   138   if (res == NULL) {
   169   if (res == NULL) {
   139     current_vartype = none_vt;
   170     current_vartype = none_vt;
       
   171     current_varqualifier = none_vq;
   140   }
   172   }
   141   return res;
   173   return res;
   142 }
   174 }
   143 
   175 
   144 /*  VAR RETAIN var_init_decl_list END_VAR */
   176 /*  VAR RETAIN var_init_decl_list END_VAR */
   145 void *search_var_instance_decl_c::visit(retentive_var_declarations_c *symbol) {
   177 void *search_var_instance_decl_c::visit(retentive_var_declarations_c *symbol) {
   146   current_vartype = private_vt;
   178   current_vartype = private_vt;
       
   179   current_varqualifier = retain_vq;
   147   void *res = symbol->var_init_decl_list->accept(*this);
   180   void *res = symbol->var_init_decl_list->accept(*this);
   148   if (res == NULL) {
   181   if (res == NULL) {
   149     current_vartype = none_vt;
   182     current_vartype = none_vt;
       
   183     current_varqualifier = none_vq;
   150   }
   184   }
   151   return res;
   185   return res;
   152 }
   186 }
   153 
   187 
   154 /*  VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */
   188 /*  VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */
   155 /* option -> may be NULL ! */
   189 /* option -> may be NULL ! */
   156 //SYM_REF2(located_var_declarations_c, option, located_var_decl_list)
   190 //SYM_REF2(located_var_declarations_c, option, located_var_decl_list)
   157 void *search_var_instance_decl_c::visit(located_var_declarations_c *symbol) {
   191 void *search_var_instance_decl_c::visit(located_var_declarations_c *symbol) {
   158   current_vartype = located_vt;
   192   current_vartype = located_vt;
       
   193   if (symbol->option != NULL)
       
   194     symbol->option->accept(*this);
   159   void *res = symbol->located_var_decl_list->accept(*this);
   195   void *res = symbol->located_var_decl_list->accept(*this);
   160   if (res == NULL) {
   196   if (res == NULL) {
   161     current_vartype = none_vt;
   197     current_vartype = none_vt;
       
   198     current_varqualifier = none_vq;
   162   }
   199   }
   163   return res;
   200   return res;
   164 }
   201 }
   165 
   202 
   166 /*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */
   203 /*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */
   167 /* option -> may be NULL ! */
   204 /* option -> may be NULL ! */
   168 //SYM_REF2(external_var_declarations_c, option, external_declaration_list)
   205 //SYM_REF2(external_var_declarations_c, option, external_declaration_list)
   169 void *search_var_instance_decl_c::visit(external_var_declarations_c *symbol) {
   206 void *search_var_instance_decl_c::visit(external_var_declarations_c *symbol) {
   170   current_vartype = external_vt;
   207   current_vartype = external_vt;
       
   208   if (symbol->option != NULL)
       
   209     symbol->option->accept(*this);
   171   void *res = symbol->external_declaration_list->accept(*this);
   210   void *res = symbol->external_declaration_list->accept(*this);
   172   if (res == NULL) {
   211   if (res == NULL) {
   173     current_vartype = none_vt;
   212     current_vartype = none_vt;
       
   213     current_varqualifier = none_vq;
   174   }
   214   }
   175   return res;
   215   return res;
   176 }
   216 }
   177 
   217 
   178 /*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */
   218 /*| VAR_GLOBAL [CONSTANT|RETAIN] global_var_decl_list END_VAR */
   179 /* option -> may be NULL ! */
   219 /* option -> may be NULL ! */
   180 //SYM_REF2(global_var_declarations_c, option, global_var_decl_list)
   220 //SYM_REF2(global_var_declarations_c, option, global_var_decl_list)
   181 void *search_var_instance_decl_c::visit(global_var_declarations_c *symbol) {
   221 void *search_var_instance_decl_c::visit(global_var_declarations_c *symbol) {
   182   current_vartype = global_vt;
   222   current_vartype = global_vt;
       
   223   if (symbol->option != NULL)
       
   224     symbol->option->accept(*this);
   183   void *res = symbol->global_var_decl_list->accept(*this);
   225   void *res = symbol->global_var_decl_list->accept(*this);
   184   if (res == NULL) {
   226   if (res == NULL) {
   185     current_vartype = none_vt;
   227     current_vartype = none_vt;
       
   228     current_varqualifier = none_vq;
   186   }
   229   }
   187   return res;
   230   return res;
   188 }
   231 }
   189 
   232 
   190 /* var1_list is one of the following...
   233 /* var1_list is one of the following...