ast2firm: Implement casting from complex to real types.
[cparser] / ast2firm.c
index 9a78945..2e85c8a 100644 (file)
@@ -1,21 +1,6 @@
 /*
  * This file is part of cparser.
- * Copyright (C) 2007-2009 Matthias Braun <matze@braunis.de>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * Copyright (C) 2012 Matthias Braun <matze@braunis.de>
  */
 #include <config.h>
 
@@ -2222,10 +2207,13 @@ static ir_node *create_cast(unary_expression_t const *const expr)
        if (is_type_void(type))
                return NULL;
 
-       ir_node        *value     = expression_to_value(expr->value);
-       dbg_info *const dbgi      = get_dbg_info(&expr->base.pos);
-       type_t   *const from_type = skip_typeref(expr->value->base.type);
-       ir_mode  *const mode      = get_ir_mode_storage(type);
+       type_t  *const from_type = skip_typeref(expr->value->base.type);
+       ir_node       *value     = is_type_complex(from_type)
+               ? expression_to_complex(expr->value).real
+               : expression_to_value(expr->value);
+
+       dbg_info *const dbgi = get_dbg_info(&expr->base.pos);
+       ir_mode  *const mode = get_ir_mode_storage(type);
        /* check for conversion from / to __based types */
        if (is_type_pointer(type) && is_type_pointer(from_type)) {
                const variable_t *from_var = from_type->pointer.base_variable;