ast2firm: Implement casting from complex to real types.
[cparser] / ast_t.h
diff --git a/ast_t.h b/ast_t.h
index 4b94ca2..ca796a8 100644 (file)
--- a/ast_t.h
+++ b/ast_t.h
@@ -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>
  */
 #ifndef AST_T_H
 #define AST_T_H
@@ -67,15 +52,10 @@ typedef enum expression_kind_t {
        EXPR_ENUM_CONSTANT,
        EXPR_LITERAL_BOOLEAN,
        EXPR_LITERAL_INTEGER,
-       EXPR_LITERAL_INTEGER_OCTAL,
-       EXPR_LITERAL_INTEGER_HEXADECIMAL,
        EXPR_LITERAL_FLOATINGPOINT,
-       EXPR_LITERAL_FLOATINGPOINT_HEXADECIMAL,
        EXPR_LITERAL_CHARACTER,
-       EXPR_LITERAL_WIDE_CHARACTER,
        EXPR_LITERAL_MS_NOOP, /**< MS __noop extension */
        EXPR_STRING_LITERAL,
-       EXPR_WIDE_STRING_LITERAL,
        EXPR_COMPOUND_LITERAL,
        EXPR_CALL,
        EXPR_CONDITIONAL,
@@ -98,7 +78,7 @@ typedef enum expression_kind_t {
        EXPR_UNARY_FIRST,
        EXPR_UNARY_NEGATE = EXPR_UNARY_FIRST,
        EXPR_UNARY_PLUS,
-       EXPR_UNARY_BITWISE_NEGATE,
+       EXPR_UNARY_COMPLEMENT,
        EXPR_UNARY_NOT,
        EXPR_UNARY_DEREFERENCE,
        EXPR_UNARY_TAKE_ADDRESS,
@@ -111,7 +91,9 @@ typedef enum expression_kind_t {
        EXPR_UNARY_DELETE,
        EXPR_UNARY_DELETE_ARRAY,
        EXPR_UNARY_THROW,
-       EXPR_UNARY_LAST = EXPR_UNARY_THROW,
+       EXPR_UNARY_REAL,
+       EXPR_UNARY_IMAG,
+       EXPR_UNARY_LAST = EXPR_UNARY_IMAG,
 
        EXPR_BINARY_FIRST,
        EXPR_BINARY_ADD = EXPR_BINARY_FIRST,
@@ -206,7 +188,7 @@ typedef enum funcname_kind_t {
 #define EXPR_UNARY_CASES_MANDATORY   \
             EXPR_UNARY_NEGATE:            \
        case EXPR_UNARY_PLUS:              \
-       case EXPR_UNARY_BITWISE_NEGATE:    \
+       case EXPR_UNARY_COMPLEMENT:        \
        case EXPR_UNARY_NOT:               \
        case EXPR_UNARY_DEREFERENCE:       \
        case EXPR_UNARY_TAKE_ADDRESS:      \
@@ -217,7 +199,9 @@ typedef enum funcname_kind_t {
        case EXPR_UNARY_CAST:              \
        case EXPR_UNARY_ASSUME:            \
        case EXPR_UNARY_DELETE:            \
-       case EXPR_UNARY_DELETE_ARRAY
+       case EXPR_UNARY_DELETE_ARRAY:      \
+       case EXPR_UNARY_IMAG:              \
+       case EXPR_UNARY_REAL
 
 /**
  * unary expression with optional operand
@@ -232,59 +216,55 @@ typedef enum funcname_kind_t {
 #define EXPR_LITERAL_CASES                     \
             EXPR_LITERAL_BOOLEAN:                   \
        case EXPR_LITERAL_INTEGER:                   \
-       case EXPR_LITERAL_INTEGER_OCTAL:             \
-       case EXPR_LITERAL_INTEGER_HEXADECIMAL:       \
        case EXPR_LITERAL_FLOATINGPOINT:             \
-       case EXPR_LITERAL_FLOATINGPOINT_HEXADECIMAL: \
-       case EXPR_LITERAL_CHARACTER:                 \
-       case EXPR_LITERAL_WIDE_CHARACTER:            \
        case EXPR_LITERAL_MS_NOOP
 
 /**
  * The base class of every expression.
  */
 struct expression_base_t {
-       expression_kind_t   kind;            /**< The expression kind. */
-       type_t             *type;            /**< The type of the expression. */
-       source_position_t   source_position; /**< The source position of this expression. */
-       bool                parenthesized : 1;
+       expression_kind_t kind;     /**< The expression kind. */
+       type_t           *type;     /**< The type of the expression. */
+       position_t        pos;      /**< The source position of this expression. */
+       bool              parenthesized : 1;
 #ifndef NDEBUG
-       bool                transformed : 1;     /**< Set if this expression was transformed. */
+       bool              transformed : 1; /**< Set if this expression was transformed. */
 #endif
-       bool                implicit : 1;    /**< compiler generated expression.
-                                                 Examples:
-                                                    select into anonymous structs
-                                                    implicit casts
-                                             */
+       bool              implicit : 1;  /**< compiler generated expression.
+                                           Examples: select into anonymous structs,
+                                           implicit casts */
 };
 
 /**
- * integer/float constants, character and string literals
+ * integer, float and boolean constants
  */
 struct literal_expression_t {
-       expression_base_t  base;
-       string_t           value;
-       string_t           suffix;
+       expression_base_t base;
+       string_t          value;
+       char const       *suffix; /**< Start of the suffix in value. */
 
        /* ast2firm data */
-       ir_tarval         *target_value;
+       ir_tarval        *target_value;
 };
 
+/**
+ * string and character literals
+ */
 struct string_literal_expression_t {
-       expression_base_t  base;
-       string_t           value;
+       expression_base_t base;
+       string_t          value;
 };
 
 struct funcname_expression_t {
        expression_base_t  base;
        funcname_kind_t    kind;
-       string_t           value;     /**< the value once assigned. */
 };
 
 struct compound_literal_expression_t {
        expression_base_t  base;
        type_t            *type;
        initializer_t     *initializer;
+       bool               global_scope;
 };
 
 struct builtin_constant_expression_t {
@@ -350,10 +330,11 @@ struct typeprop_expression_t {
 };
 
 struct designator_t {
-       source_position_t  source_position;
-       symbol_t          *symbol;      /**< the symbol if any */
-       expression_t      *array_index; /**< the array index if any */
-       designator_t      *next;
+       position_t    pos;
+       symbol_t     *symbol;      /**< the symbol if any */
+       expression_t *array_index; /**< the array index if any */
+       expression_t *range_last;  /**< last index of a range initializer, if any */
+       designator_t *next;
 };
 
 struct offsetof_expression_t {
@@ -365,7 +346,7 @@ struct offsetof_expression_t {
 struct va_start_expression_t {
        expression_base_t  base;
        expression_t      *ap;
-       variable_t        *parameter;
+       expression_t      *parameter;
 };
 
 struct va_arg_expression_t {
@@ -431,7 +412,6 @@ typedef enum initializer_kind_t {
        INITIALIZER_VALUE,
        INITIALIZER_LIST,
        INITIALIZER_STRING,
-       INITIALIZER_WIDE_STRING,
        INITIALIZER_DESIGNATOR
 } initializer_kind_t;
 
@@ -450,16 +430,6 @@ struct initializer_list_t {
        initializer_t      *initializers[];
 };
 
-struct initializer_string_t {
-       initializer_base_t base;
-       string_t           string;
-};
-
-struct initializer_wide_string_t {
-       initializer_base_t  base;
-       string_t            string;
-};
-
 struct initializer_designator_t {
        initializer_base_t  base;
        designator_t       *designator;
@@ -470,11 +440,16 @@ union initializer_t {
        initializer_base_t        base;
        initializer_value_t       value;
        initializer_list_t        list;
-       initializer_string_t      string;
-       initializer_wide_string_t wide_string;
        initializer_designator_t  designator;
 };
 
+static inline string_literal_expression_t const *get_init_string(initializer_t const *const init)
+{
+       assert(init->kind == INITIALIZER_STRING);
+       assert(init->value.value->kind == EXPR_STRING_LITERAL);
+       return &init->value.value->string_literal;
+}
+
 /**
  * The statement kinds.
  */
@@ -493,7 +468,6 @@ typedef enum statement_kind_t {
        STATEMENT_GOTO,
        STATEMENT_LABEL,
        STATEMENT_CASE_LABEL,
-       STATEMENT_WHILE,
        STATEMENT_DO_WHILE,
        STATEMENT_FOR,
        STATEMENT_ASM,
@@ -505,13 +479,13 @@ typedef enum statement_kind_t {
  * The base class of every statement.
  */
 struct statement_base_t {
-       statement_kind_t   kind;
-       statement_t       *next;         /**< Point to the next statement in a compound statement. */
-       source_position_t  source_position;
-       statement_t       *parent;       /**< The Parent statement that controls the execution. */
-       bool               reachable;    /**< True, if this statement is reachable. */
+       statement_kind_t kind;
+       statement_t     *next;      /**< Point to the next statement in a compound statement. */
+       position_t       pos;
+       statement_t     *parent;    /**< The Parent statement that controls the execution. */
+       bool             reachable; /**< True, if this statement is reachable. */
 #ifndef NDEBUG
-       bool               transformed;
+       bool             transformed;
 #endif
 };
 
@@ -567,8 +541,8 @@ struct case_label_statement_t {
        expression_t           *end_range;     /**< For GNUC case a .. b: the end range expression, NULL else. */
        case_label_statement_t *next;          /**< link to the next case label in switch */
        statement_t            *statement;
-       long                   first_case;     /**< The folded value of expression. */
-       long                   last_case;      /**< The folded value of end_range. */
+       ir_tarval              *first_case;
+       ir_tarval              *last_case;
        bool                   is_bad;         /**< If set marked as bad to suppress warnings. */
        bool                   is_empty_range; /**< If set marked this as an empty range. */
        long                   pn;
@@ -586,13 +560,6 @@ struct expression_statement_t {
        expression_t     *expression;
 };
 
-struct while_statement_t {
-       statement_base_t  base;
-       scope_t           scope;
-       expression_t     *condition;
-       statement_t      *body;
-};
-
 struct do_while_statement_t {
        statement_base_t  base;
        scope_t           scope;
@@ -623,12 +590,18 @@ struct asm_clobber_t {
        asm_clobber_t *next;
 };
 
+struct asm_label_t {
+       label_t     *label;
+       asm_label_t *next;
+};
+
 struct asm_statement_t {
        statement_base_t base;
        string_t         asm_text;
        asm_argument_t  *inputs;
        asm_argument_t  *outputs;
        asm_clobber_t   *clobbers;
+       asm_label_t     *labels;
        bool             is_volatile;
 };
 
@@ -656,7 +629,6 @@ union statement_t {
        case_label_statement_t    case_label;
        label_statement_t         label;
        expression_statement_t    expression;
-       while_statement_t         whiles;
        do_while_statement_t      do_while;
        for_statement_t           fors;
        asm_statement_t           asms;