FANDOM


このページを編集する際は,編集に関する方針に従ってください. 編集

概要 編集

引数 編集

実装 編集

 1915 /* Convert expression ARG to type TYPE.  Used by the middle-end for
 1916    simple conversions in preference to calling the front-end's convert.  */
1917 
1918 tree
1919 fold_convert (tree type, tree arg)
1920 {
1921   tree orig = TREE_TYPE (arg);
1922   tree tem;
1923 
1924   if (type == orig)
1925     return arg;
1926 
1927   if (TREE_CODE (arg) == [[ERROR_MARK>enum tree_code]]
1928       || TREE_CODE (type) == [[ERROR_MARK>enum tree_code]]
1929       || TREE_CODE (orig) == [[ERROR_MARK>enum tree_code]])
1930     return error_mark_node;
1931 
1932   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (orig)
1933       || lang_hooks.types_compatible_p (TYPE_MAIN_VARIANT (type),
1934                                         TYPE_MAIN_VARIANT (orig)))
1935     return fold_build1 ([[NOP_EXPR>enum tree_code]], type, arg);
1936 
1937   switch (TREE_CODE (type))
1938     {

~

1939     case [[INTEGER_TYPE>enum tree_code]]: case [[CHAR_TYPE>enum tree_code]]: case ENUMERAL_TYPE: case [[BOOLEAN_TYPE>enum tree_code]]:
1940     case [[POINTER_TYPE>enum tree_code]]: case [[REFERENCE_TYPE>enum tree_code]]:
1941     case [[OFFSET_TYPE>enum tree_code]]:
1942       if (TREE_CODE (arg) == [[INTEGER_CST>enum tree_code]])
1943         {
1944           tem = fold_convert_const ([[NOP_EXPR>enum tree_code]], type, arg);
1945           if (tem != NULL_TREE)
1946             return tem;
1947         }
1948       if (INTEGRAL_TYPE_P (orig) || POINTER_TYPE_P (orig)
1949           || TREE_CODE (orig) == [[OFFSET_TYPE>enum tree_code]])
1950         return fold_build1 ([[NOP_EXPR>enum tree_code]], type, arg);
1951       if (TREE_CODE (orig) == [[COMPLEX_TYPE>enum tree_code]])
1952         {
1953           tem = fold_build1 ([[REALPART_EXPR>enum tree_code]], TREE_TYPE (orig), arg);
1954           return fold_convert (type, tem);
1955         }
1956       gcc_assert (TREE_CODE (orig) == [[VECTOR_TYPE>enum tree_code]]
1957                   && tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (orig)));
1958       return fold_build1 ([[NOP_EXPR>enum tree_code]], type, arg);
1959 

~

1960     case [[REAL_TYPE>enum tree_code]]:
1961       if (TREE_CODE (arg) == [[INTEGER_CST>enum tree_code]])
1962         {
1963           tem = fold_convert_const ([[FLOAT_EXPR>enum tree_code]], type, arg);
1964           if (tem != NULL_TREE)
1965             return tem;
1966         }
1967       else if (TREE_CODE (arg) == [[REAL_CST>enum tree_code]])
1968         {
1969           tem = fold_convert_const ([[NOP_EXPR>enum tree_code]], type, arg);
1970           if (tem != NULL_TREE)
1971             return tem;
1972         }
1973 

~

1974       switch (TREE_CODE (orig))
1975         {
1976         case [[INTEGER_TYPE>enum tree_code]]: case [[CHAR_TYPE>enum tree_code]]:
1977         case [[BOOLEAN_TYPE>enum tree_code]]: case [[ENUMERAL_TYPE>enum tree_code]]:
1978         case [[POINTER_TYPE>enum tree_code]]: case [[REFERENCE_TYPE>enum tree_code]]:
1979           return fold_build1 ([[FLOAT_EXPR>enum tree_code]], type, arg);
1980 
1981         case [[REAL_TYPE>enum tree_code]]:
1982           return fold_build1 (flag_float_store ? [[CONVERT_EXPR>enum tree_code]] : [[NOP_EXPR>enum tree_code]],
1983                               type, arg);
1984 
1985         case [[COMPLEX_TYPE>enum tree_code]]:
1986           tem = fold_build1 ([[REALPART_EXPR>enum tree_code]], TREE_TYPE (orig), arg);
1987           return fold_convert (type, tem);
1988 
1989         default:
1990           gcc_unreachable ();
1991         }
1992 

~

1993     case [[COMPLEX_TYPE>enum tree_code]]:
1994       switch (TREE_CODE (orig))
1995         {
1996         case [[INTEGER_TYPE>enum tree_code]]: case [[CHAR_TYPE>enum tree_code]]:
1997         case [[BOOLEAN_TYPE>enum tree_code]]: case [[ENUMERAL_TYPE>enum tree_code]]:
1998         case [[POINTER_TYPE>enum tree_code]]: case [[REFERENCE_TYPE>enum tree_code]]:
1999         case [[REAL_TYPE>enum tree_code]]:
2000           return build2 ([[COMPLEX_EXPR>enum tree_code]], type,
2001                          fold_convert (TREE_TYPE (type), arg),
2002                          fold_convert (TREE_TYPE (type), integer_zero_node));
2003         case [[COMPLEX_TYPE>enum tree_code]]:
2004           {
2005             tree rpart, ipart;
2006 
2007             if (TREE_CODE (arg) == [[COMPLEX_EXPR>enum tree_code]])
2008               {
2009                 rpart = fold_convert (TREE_TYPE (type), TREE_OPERAND (arg, 0));
2010                 ipart = fold_convert (TREE_TYPE (type), TREE_OPERAND (arg, 1));
2011                 return fold_build2 ([[COMPLEX_EXPR>enum tree_code]], type, rpart, ipart);
2012               }
2013 
2014             arg = save_expr (arg);
2015             rpart = fold_build1 ([[REALPART_EXPR>enum tree_code]], TREE_TYPE (orig), arg);
2016             ipart = fold_build1 ([[IMAGPART_EXPR>enum tree_code]], TREE_TYPE (orig), arg);
2017             rpart = fold_convert (TREE_TYPE (type), rpart);
2018             ipart = fold_convert (TREE_TYPE (type), ipart);
2019             return fold_build2 ([[COMPLEX_EXPR>enum tree_code]], type, rpart, ipart);
2020           }
2021 
2022         default:
2023           gcc_unreachable ();
2024         }
2025 

~

2026     case [[VECTOR_TYPE>enum tree_code]]:
2027       if (integer_zerop (arg))
2028         return build_zero_vector (type);
2029       gcc_assert (tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (orig)));
2030       gcc_assert (INTEGRAL_TYPE_P (orig) || POINTER_TYPE_P (orig)
2031                   || TREE_CODE (orig) == [[VECTOR_TYPE>enum tree_code]]);
2032       return fold_build1 ([[VIEW_CONVERT_EXPR>enum tree_code]], type, arg);
2033 

~

2034     case [[VOID_TYPE>enum tree_code]]:
2035       return fold_build1 ([[CONVERT_EXPR>enum tree_code]], type, fold_ignored_result (arg));
2036 

~

2037     default:
2038       gcc_unreachable ();
2039     }
2040 }


リンク元