stage3/fill_candidate_datatypes.cc
changeset 933 76324f461aed
parent 921 d228aaa4d616
child 935 be4373d07201
equal deleted inserted replaced
932:061824c45a5b 933:76324f461aed
  1887 /* B.3 - Language ST (Structured Text) */
  1887 /* B.3 - Language ST (Structured Text) */
  1888 /***************************************/
  1888 /***************************************/
  1889 /***********************/
  1889 /***********************/
  1890 /* B 3.1 - Expressions */
  1890 /* B 3.1 - Expressions */
  1891 /***********************/
  1891 /***********************/
       
  1892 /* SYM_REF1(deref_expression_c, exp)  --> an extension to the IEC 61131-3 standard - based on the IEC 61131-3 v3 standard. Returns address of the varible! */
       
  1893 void *fill_candidate_datatypes_c::visit(deref_expression_c  *symbol) {
       
  1894   symbol->exp->accept(*this);
       
  1895 
       
  1896   for (unsigned int i = 0; i < symbol->exp->candidate_datatypes.size(); i++) {
       
  1897     /* Determine whether the datatype is a ref_spec_c, as this is the class used as the    */
       
  1898     /* canonical/base datatype of REF_TO types (see search_base_type_c ...)                */ 
       
  1899     ref_spec_c *ref_spec = dynamic_cast<ref_spec_c *>(symbol->exp->candidate_datatypes[i]);
       
  1900     
       
  1901     if (NULL != ref_spec)
       
  1902       add_datatype_to_candidate_list(symbol, ref_spec->type_name);
       
  1903   }
       
  1904   
       
  1905   return NULL;
       
  1906 }
       
  1907 
       
  1908 
  1892 /* SYM_REF1(ref_expression_c, exp)  --> an extension to the IEC 61131-3 standard - based on the IEC 61131-3 v3 standard. Returns address of the varible! */
  1909 /* SYM_REF1(ref_expression_c, exp)  --> an extension to the IEC 61131-3 standard - based on the IEC 61131-3 v3 standard. Returns address of the varible! */
  1893 void *fill_candidate_datatypes_c::visit(  ref_expression_c  *symbol) {
  1910 void *fill_candidate_datatypes_c::visit(  ref_expression_c  *symbol) {
  1894   /* We must first determine the datatype of the expression passe to the REF() operator, with no ambiguities! 
  1911   /* We must first determine the datatype of the expression passed to the REF() operator, with no ambiguities! 
  1895    * To do this, we could use the complete standard fill/narrow algorithm for determining the datatype
  1912    * To do this, we could use the complete standard fill/narrow algorithm for determining the datatype
  1896    * of the expression. This is actually possible, as nothing stops us from directly calling the narrow_candidate_datatypes_c
  1913    * of the expression. This is actually possible, as nothing stops us from directly calling the narrow_candidate_datatypes_c
  1897    * from this method inside fill_candidate_datatypes_c, to complete the fill/narrow algorithm on this
  1914    * from this method inside fill_candidate_datatypes_c, to complete the fill/narrow algorithm on this
  1898    * expression only.
  1915    * expression only.
  1899    * However, for the moment we take a shortcut, and set the expression's "datatype" directly, even though this 
  1916    * However, for the moment we take a shortcut, and set the expression's "datatype" directly, even though this 
  1908    */
  1925    */
  1909   symbol->exp->accept(*this);
  1926   symbol->exp->accept(*this);
  1910   if (symbol->exp->candidate_datatypes.size() == 1)
  1927   if (symbol->exp->candidate_datatypes.size() == 1)
  1911     symbol->exp->datatype = symbol->exp->candidate_datatypes[0];
  1928     symbol->exp->datatype = symbol->exp->candidate_datatypes[0];
  1912 
  1929 
  1913   /* Create a new object of ref_spec_c, as this is the class used as the canonical/base datatype of REF_TO types 
  1930   /* Create a new object of ref_spec_c, as this is the class used as the  */
  1914    * (see search_base_type_c ...)
  1931   /* canonical/base datatype of REF_TO types (see search_base_type_c ...) */ 
  1915    */ 
       
  1916   ref_spec_c *ref_spec = new ref_spec_c(symbol->exp->datatype);
  1932   ref_spec_c *ref_spec = new ref_spec_c(symbol->exp->datatype);
  1917   add_datatype_to_candidate_list(symbol, ref_spec);
  1933   add_datatype_to_candidate_list(symbol, ref_spec);
  1918   return NULL;
  1934   return NULL;
  1919 }
  1935 }
  1920     
  1936