stage3/visit_expression_type.cc
changeset 360 f4ce1b1c2112
parent 350 2c3c4dc34979
child 361 e0c2f01251dc
equal deleted inserted replaced
359:84f81f8eac2f 360:f4ce1b1c2112
   659     if (right_expr != NULL)
   659     if (right_expr != NULL)
   660       STAGE3_ERROR(right_expr, right_expr, "Invalid data type of operand.");
   660       STAGE3_ERROR(right_expr, right_expr, "Invalid data type of operand.");
   661     error = true;
   661     error = true;
   662   }
   662   }
   663   if (!is_compatible_type(left_type, right_type)) {
   663   if (!is_compatible_type(left_type, right_type)) {
       
   664 printf("visit_expression_type_c::compute_expression(): left_type & right_type are incompatible\n");
   664     if (debug) printf("visit_expression_type_c::compute_expression(): left_type & right_type are incompatible\n");
   665     if (debug) printf("visit_expression_type_c::compute_expression(): left_type & right_type are incompatible\n");
   665     if ((left_expr != NULL) && (right_expr != NULL))
   666     if ((left_expr != NULL) && (right_expr != NULL))
   666       STAGE3_ERROR(left_expr, right_expr, "Type mismatch between operands.");
   667       STAGE3_ERROR(left_expr, right_expr, "Type mismatch between operands.");
   667     error = true;
   668     error = true;
   668   }
   669   }
  1684 }
  1685 }
  1685 
  1686 
  1686 // SYM_REF0(MOD_operator_c)
  1687 // SYM_REF0(MOD_operator_c)
  1687 void *visit_expression_type_c::visit(MOD_operator_c *symbol) {
  1688 void *visit_expression_type_c::visit(MOD_operator_c *symbol) {
  1688   verify_null(symbol);
  1689   verify_null(symbol);
  1689   il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_INT_compatible); 
  1690   il_default_variable_type = compute_expression(il_default_variable_type, il_operand_type, &visit_expression_type_c::is_ANY_INT_compatible,
       
  1691                                                 symbol                  , il_operand);
  1690   return NULL;
  1692   return NULL;
  1691 }
  1693 }
  1692 
  1694 
  1693 // SYM_REF0(GT_operator_c)
  1695 // SYM_REF0(GT_operator_c)
  1694 void *visit_expression_type_c::visit(GT_operator_c *symbol) {
  1696 void *visit_expression_type_c::visit(GT_operator_c *symbol) {
  1835 /***********************/
  1837 /***********************/
  1836 
  1838 
  1837 void *visit_expression_type_c::visit(or_expression_c *symbol) {
  1839 void *visit_expression_type_c::visit(or_expression_c *symbol) {
  1838   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1840   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1839   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1841   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1840   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_compatible);
  1842   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_compatible, symbol->l_exp, symbol->r_exp);
  1841 }
  1843 }
  1842 
  1844 
  1843 
  1845 
  1844 void *visit_expression_type_c::visit(xor_expression_c *symbol) {
  1846 void *visit_expression_type_c::visit(xor_expression_c *symbol) {
  1845   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1847   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1846   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1848   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1847   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_compatible);
  1849   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_compatible, symbol->l_exp, symbol->r_exp);
  1848 }
  1850 }
  1849 
  1851 
  1850 
  1852 
  1851 void *visit_expression_type_c::visit(and_expression_c *symbol) {
  1853 void *visit_expression_type_c::visit(and_expression_c *symbol) {
  1852   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1854   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1853   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1855   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1854   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_compatible);
  1856   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_BIT_compatible, symbol->l_exp, symbol->r_exp);
  1855 }
  1857 }
  1856 
  1858 
  1857 
  1859 
  1858 void *visit_expression_type_c::visit(equ_expression_c *symbol) {
  1860 void *visit_expression_type_c::visit(equ_expression_c *symbol) {
  1859   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1861   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1860   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1862   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1861   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1863   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible, symbol->l_exp, symbol->r_exp);
  1862   return &search_expression_type_c::bool_type_name;
  1864   return &search_expression_type_c::bool_type_name;
  1863 }
  1865 }
  1864 
  1866 
  1865 
  1867 
  1866 void *visit_expression_type_c::visit(notequ_expression_c *symbol)  {
  1868 void *visit_expression_type_c::visit(notequ_expression_c *symbol)  {
  1867   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1869   symbol_c *left_type = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1868   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1870   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1869   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1871   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible, symbol->l_exp, symbol->r_exp);
  1870   return &search_expression_type_c::bool_type_name;
  1872   return &search_expression_type_c::bool_type_name;
  1871 }
  1873 }
  1872 
  1874 
  1873 
  1875 
  1874 void *visit_expression_type_c::visit(lt_expression_c *symbol) {
  1876 void *visit_expression_type_c::visit(lt_expression_c *symbol) {
  1875   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1877   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1876   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1878   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1877   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1879   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible, symbol->l_exp, symbol->r_exp);
  1878   return &search_expression_type_c::bool_type_name;
  1880   return &search_expression_type_c::bool_type_name;
  1879 }
  1881 }
  1880 
  1882 
  1881 
  1883 
  1882 void *visit_expression_type_c::visit(gt_expression_c *symbol) {
  1884 void *visit_expression_type_c::visit(gt_expression_c *symbol) {
  1883   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1885   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1884   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1886   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1885   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1887   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible, symbol->l_exp, symbol->r_exp);
  1886   return &search_expression_type_c::bool_type_name;
  1888   return &search_expression_type_c::bool_type_name;
  1887 }
  1889 }
  1888 
  1890 
  1889 
  1891 
  1890 void *visit_expression_type_c::visit(le_expression_c *symbol) {
  1892 void *visit_expression_type_c::visit(le_expression_c *symbol) {
  1891   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1893   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1892   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1894   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1893   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1895   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible, symbol->l_exp, symbol->r_exp);
  1894   return &search_expression_type_c::bool_type_name;
  1896   return &search_expression_type_c::bool_type_name;
  1895 }
  1897 }
  1896 
  1898 
  1897 
  1899 
  1898 void *visit_expression_type_c::visit(ge_expression_c *symbol) {
  1900 void *visit_expression_type_c::visit(ge_expression_c *symbol) {
  1899   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1901   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1900   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1902   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  1901   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible);
  1903   compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_ELEMENTARY_compatible, symbol->l_exp, symbol->r_exp);
  1902   return &search_expression_type_c::bool_type_name;
  1904   return &search_expression_type_c::bool_type_name;
  1903 }
  1905 }
  1904 
  1906 
  1905 
  1907 
  1906 void *visit_expression_type_c::visit(add_expression_c *symbol) {
  1908 void *visit_expression_type_c::visit(add_expression_c *symbol) {
  1929   if (is_type(left_type, dt_type_name_c)       && is_type(right_type, safetime_type_name_c)) 
  1931   if (is_type(left_type, dt_type_name_c)       && is_type(right_type, safetime_type_name_c)) 
  1930     return (void *)&dt_type_name;
  1932     return (void *)&dt_type_name;
  1931   if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, safetime_type_name_c)) 
  1933   if (is_type(left_type, safedt_type_name_c)   && is_type(right_type, safetime_type_name_c)) 
  1932     return (void *)&safedt_type_name;
  1934     return (void *)&safedt_type_name;
  1933 
  1935 
  1934   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_MAGNITUDE_compatible);
  1936   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_MAGNITUDE_compatible, symbol->l_exp, symbol->r_exp);
  1935 }
  1937 }
  1936 
  1938 
  1937 
  1939 
  1938 void *visit_expression_type_c::visit(sub_expression_c *symbol) {
  1940 void *visit_expression_type_c::visit(sub_expression_c *symbol) {
  1939   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1941   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  1988   if (is_type(left_type, dt_type_name_c)     && is_type(right_type, safedt_type_name_c))
  1990   if (is_type(left_type, dt_type_name_c)     && is_type(right_type, safedt_type_name_c))
  1989     return (void *)&time_type_name;
  1991     return (void *)&time_type_name;
  1990   if (is_type(left_type, safedt_type_name_c) && is_type(right_type, safedt_type_name_c))
  1992   if (is_type(left_type, safedt_type_name_c) && is_type(right_type, safedt_type_name_c))
  1991     return (void *)&safetime_type_name;
  1993     return (void *)&safetime_type_name;
  1992 
  1994 
  1993   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_MAGNITUDE_compatible);
  1995   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_MAGNITUDE_compatible, symbol->l_exp, symbol->r_exp);
  1994 }
  1996 }
  1995 
  1997 
  1996 
  1998 
  1997 void *visit_expression_type_c::visit(mul_expression_c *symbol) {
  1999 void *visit_expression_type_c::visit(mul_expression_c *symbol) {
  1998   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  2000   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  2008    * this next line is really only to check for integers/reals of undefined type on 'right_type'... 
  2010    * this next line is really only to check for integers/reals of undefined type on 'right_type'... 
  2009    */
  2011    */
  2010   if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_compatible(right_type)) 
  2012   if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_compatible(right_type)) 
  2011     return (void *)&safetime_type_name;
  2013     return (void *)&safetime_type_name;
  2012 
  2014 
  2013   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_NUM_compatible);
  2015   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_NUM_compatible, symbol->l_exp, symbol->r_exp);
  2014 }
  2016 }
  2015 
  2017 
  2016 
  2018 
  2017 void *visit_expression_type_c::visit(div_expression_c *symbol) {
  2019 void *visit_expression_type_c::visit(div_expression_c *symbol) {
  2018   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  2020   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  2028    * this next line is really only to check for integers/reals of undefined type on 'right_type'... 
  2030    * this next line is really only to check for integers/reals of undefined type on 'right_type'... 
  2029    */
  2031    */
  2030   if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_compatible(right_type)) 
  2032   if (is_type(left_type, safetime_type_name_c) && is_ANY_NUM_compatible(right_type)) 
  2031     return (void *)&safetime_type_name;
  2033     return (void *)&safetime_type_name;
  2032 
  2034 
  2033   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_NUM_compatible);
  2035   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_NUM_compatible, symbol->l_exp, symbol->r_exp);
  2034 }
  2036 }
  2035 
  2037 
  2036 
  2038 
  2037 void *visit_expression_type_c::visit(mod_expression_c *symbol) {
  2039 void *visit_expression_type_c::visit(mod_expression_c *symbol) {
  2038   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  2040   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  2039   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  2041   symbol_c *right_type = base_type((symbol_c *)symbol->r_exp->accept(*this));
  2040   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_INT_compatible);
  2042   return compute_expression(left_type, right_type, &visit_expression_type_c::is_ANY_INT_compatible, symbol->l_exp, symbol->r_exp);
  2041 }
  2043 }
  2042 
  2044 
  2043 
  2045 
  2044 void *visit_expression_type_c::visit(power_expression_c *symbol) {
  2046 void *visit_expression_type_c::visit(power_expression_c *symbol) {
  2045   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  2047   symbol_c *left_type  = base_type((symbol_c *)symbol->l_exp->accept(*this));
  2062 }
  2064 }
  2063 
  2065 
  2064 
  2066 
  2065 void *visit_expression_type_c::visit(not_expression_c *symbol) {
  2067 void *visit_expression_type_c::visit(not_expression_c *symbol) {
  2066   symbol_c *type = base_type((symbol_c *)symbol->exp->accept(*this));
  2068   symbol_c *type = base_type((symbol_c *)symbol->exp->accept(*this));
  2067   return compute_expression(type, type, &visit_expression_type_c::is_ANY_BIT_compatible);
  2069   return compute_expression(type, type, &visit_expression_type_c::is_ANY_BIT_compatible, NULL, symbol->exp);
  2068 }
  2070 }
  2069 
  2071 
  2070 
  2072 
  2071 void *visit_expression_type_c::visit(function_invocation_c *symbol) {
  2073 void *visit_expression_type_c::visit(function_invocation_c *symbol) {
  2072   function_symtable_t::iterator lower = function_symtable.lower_bound(symbol->function_name);
  2074   function_symtable_t::iterator lower = function_symtable.lower_bound(symbol->function_name);