absyntax_utils/search_varfb_instance_type.cc
changeset 321 a96399ab57c2
parent 279 c0453b7f99df
child 326 e3fbf97d2021
equal deleted inserted replaced
320:4df13059b982 321:a96399ab57c2
    35  * struture element within a data structured type (a struct or a fb), or
    35  * struture element within a data structured type (a struct or a fb), or
    36  * an array element.
    36  * an array element.
    37  * A mixture of array element of a structure element of a structure element
    37  * A mixture of array element of a structure element of a structure element
    38  * of a .... is also suported!
    38  * of a .... is also suported!
    39  *
    39  *
    40  * A reference to the relevant base type __definition__ is returned.
       
    41  * This means that if we find that the variable is of type MY_INT,
       
    42  * which was previously declared to be
       
    43  * TYPE MY_INT: INT := 9;
       
    44  * this class wil return INT, and __not__ MY_INT !!
       
    45  *
       
    46  *
       
    47  *  example:
    40  *  example:
    48  *    window.points[1].coordinate.x
    41  *    window.points[1].coordinate.x
    49  *    window.points[1].colour
    42  *    window.points[1].colour
    50  *    etc... ARE ALLOWED!
    43  *    etc... ARE ALLOWED!
    51  *
    44  *
    52  * This class must be passed the scope within which the
    45  * This class must be passed the scope within which the
    53  * variable was declared, and the variable name...
    46  * variable was declared, and the variable name...
    54  */
    47  *
       
    48  *
       
    49  *
       
    50  *
       
    51  *
       
    52  * This class has several members, depending on the exact data the caller
       
    53  * is looking for...
       
    54  *
       
    55  *    - item i: we can get either the name of the data type(A),
       
    56  *              or it's declaration (B)
       
    57  *             (notice however that some variables belong to a data type that does
       
    58  *              not have a name, only a declaration as in
       
    59  *              VAR a: ARRAY [1..3] of INT; END_VAR
       
    60  *             )
       
    61  *    - item ii: we can get either the direct data type (1), 
       
    62  *               or the base type (2)
       
    63  * 
       
    64  *   By direct type, I mean the data type of the variable. By base type, I 
       
    65  * mean the data type on which the direct type is based on. For example, in 
       
    66  * a subrange on INT, the direct type is the subrange itself, while the 
       
    67  * base type is INT.
       
    68  * e.g.
       
    69  *   This means that if we find that the variable is of type MY_INT,
       
    70  *   which was previously declared to be
       
    71  *   TYPE MY_INT: INT := 9;
       
    72  *   option (1) will return MY_INT
       
    73  *   option (2) will return INT
       
    74  * 
       
    75  *
       
    76  * Member functions:
       
    77  * ================
       
    78  *   get_basetype_decl()  ---> returns 2B 
       
    79  *   get_type_id()        ---> returns 1A
       
    80  * 
       
    81  *   Since we haven't yet needed them, we don't yet implement
       
    82  *   get_basetype_id()    ----> would return 2A
       
    83  *   get_type_decl()      ----> would return 1B
       
    84  */ 
    55 
    85 
    56 
    86 
    57 /*
    87 /*
    58  * TODO: this code has a memory leak...
    88  * TODO: this code has a memory leak...
    59  *       We call 'new' in several locations, but bever get to 'delete' the object instances...
    89  *       We call 'new' in several locations, but bever get to 'delete' the object instances...
    65   this->decompose_var_instance_name = NULL;
    95   this->decompose_var_instance_name = NULL;
    66   this->current_structelement_name = NULL;
    96   this->current_structelement_name = NULL;
    67   this->current_rawtype = NULL;
    97   this->current_rawtype = NULL;
    68 }
    98 }
    69 
    99 
    70 symbol_c *search_varfb_instance_type_c::get_type(symbol_c *variable_name) {
   100 symbol_c *search_varfb_instance_type_c::get_basetype_decl(symbol_c *variable_name) {
    71   this->current_structelement_name = NULL;
   101   this->current_structelement_name = NULL;
    72   this->current_rawtype = NULL;
   102   this->current_rawtype = NULL;
    73   this->decompose_var_instance_name = new decompose_var_instance_name_c(variable_name);
   103   this->decompose_var_instance_name = new decompose_var_instance_name_c(variable_name);
    74   if (NULL == decompose_var_instance_name) ERROR;
   104   if (NULL == decompose_var_instance_name) ERROR;
    75 
   105 
   138   if (NULL != var_name) ERROR;
   168   if (NULL != var_name) ERROR;
   139 
   169 
   140   return res;
   170   return res;
   141 }
   171 }
   142 
   172 
   143 symbol_c *search_varfb_instance_type_c::get_rawtype(symbol_c *variable_name) {
   173 symbol_c *search_varfb_instance_type_c::get_type_id(symbol_c *variable_name) {
   144   symbol_c *rawtype = this->get_type(variable_name);
   174   symbol_c *rawtype = this->get_basetype_decl(variable_name);
   145   if (this->current_rawtype != NULL)
   175   if (this->current_rawtype != NULL)
   146     return this->current_rawtype;
   176     return this->current_rawtype;
   147   else
   177   else
   148 	return rawtype;
   178 	return rawtype;
   149 }
   179 }