ast2firm: Implement casting from complex to real types.
[cparser] / attribute.c
index ca9ad19..84869de 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>
 
@@ -132,8 +117,7 @@ type_t *handle_attribute_mode(const attribute_t *attribute, type_t *orig_type)
         * specific modes (according to gcc philosophy that is...) */
        attribute_argument_t *arg = attribute->a.arguments;
        if (arg == NULL) {
-               errorf(&attribute->source_position,
-                      "__attribute__((mode(X))) misses argument");
+               errorf(&attribute->pos, "__attribute__((mode(X))) misses argument");
                return orig_type;
        }
 
@@ -152,8 +136,8 @@ type_t *handle_attribute_mode(const attribute_t *attribute, type_t *orig_type)
        } else if (streq_underscore("DI", symbol_str)) {
                akind = sign ? ATOMIC_TYPE_LONGLONG : ATOMIC_TYPE_ULONGLONG;
        } else {
-               source_position_t const *const pos = &attribute->source_position;
-               warningf(WARN_OTHER, pos, "ignoring unknown mode '%s'", symbol_str);
+               warningf(WARN_OTHER, &attribute->pos, "ignoring unknown mode '%s'",
+                        symbol_str);
                return orig_type;
        }
 
@@ -162,12 +146,11 @@ type_t *handle_attribute_mode(const attribute_t *attribute, type_t *orig_type)
                copy->atomic.akind = akind;
                return identify_new_type(copy);
        } else if (is_type_pointer(type)) {
-               source_position_t const *const pos = &attribute->source_position;
-               warningf(WARN_OTHER, pos, "__attribute__((mode)) on pointers not implemented yet (ignored)");
+               warningf(WARN_OTHER, &attribute->pos, "__attribute__((mode)) on pointers not implemented yet (ignored)");
                return type;
        }
 
-       errorf(&attribute->source_position,
+       errorf(&attribute->pos,
               "__attribute__((mode)) only allowed on integer, enum or pointer type");
        return orig_type;
 }
@@ -188,15 +171,11 @@ static void handle_attribute_aligned(const attribute_t *attribute,
        }
 
        if (!is_po2(alignment)) {
-               errorf(&attribute->source_position,
-                          "alignment must be a power of 2 but is %d\n",
-                          alignment);
+               errorf(&attribute->pos, "alignment must be a power of 2 but is %d", alignment);
                return;
        }
        if (alignment <= 0) {
-               errorf(&attribute->source_position,
-                          "alignment must be bigger than 0 but is %d\n",
-                          alignment);
+               errorf(&attribute->pos, "alignment must be bigger than 0 but is %d", alignment);
                return;
        }
 
@@ -214,7 +193,7 @@ static void handle_attribute_aligned(const attribute_t *attribute,
                break;
 
        default:
-               warningf(WARN_OTHER, &attribute->source_position, "alignment attribute specification on '%N' ignored", entity);
+               warningf(WARN_OTHER, &attribute->pos, "alignment attribute specification on '%N' ignored", entity);
                break;
        }
 }
@@ -238,19 +217,19 @@ static void handle_attribute_visibility(const attribute_t *attribute,
         * specific modes (according to gcc philosophy that is...) */
        attribute_argument_t *arg = attribute->a.arguments;
        if (arg == NULL) {
-               errorf(&attribute->source_position,
+               errorf(&attribute->pos,
                       "__attribute__((visibility(X))) misses argument");
                return;
        }
        const char *string = get_argument_string(arg);
        if (string == NULL) {
-               errorf(&attribute->source_position,
+               errorf(&attribute->pos,
                       "__attribute__((visibility(X))) argument is not a string");
                return;
        }
        elf_visibility_tag_t visibility = get_elf_visibility_from_string(string);
        if (visibility == ELF_VISIBILITY_ERROR) {
-               errorf(&attribute->source_position,
+               errorf(&attribute->pos,
                       "unknown visibility type '%s'", string);
                return;
        }
@@ -264,7 +243,7 @@ static void handle_attribute_visibility(const attribute_t *attribute,
                break;
 
        default:
-               warningf(WARN_OTHER, &attribute->source_position, "visibility attribute specification on '%N' ignored", entity);
+               warningf(WARN_OTHER, &attribute->pos, "visibility attribute specification on '%N' ignored", entity);
                break;
        }
 }
@@ -274,8 +253,8 @@ static void warn_arguments(const attribute_t *attribute)
        if (attribute->a.arguments == NULL)
                return;
 
-       source_position_t const *const pos  = &attribute->source_position;
-       char              const *const what = get_attribute_name(attribute->kind);
+       position_t const *const pos  = &attribute->pos;
+       char       const *const what = get_attribute_name(attribute->kind);
        warningf(WARN_OTHER, pos, "attribute '%s' needs no arguments", what);
 }
 
@@ -284,7 +263,7 @@ static void handle_attribute_packed_e(const attribute_t *attribute,
 {
 #if 0
        if (entity->kind != ENTITY_STRUCT) {
-               warningf(WARN_OTHER, &attribute->source_position, "packed attribute on '%N' ignored", entity);
+               warningf(WARN_OTHER, &attribute->pos, "packed attribute on '%N' ignored", entity);
                return;
        }
 #endif
@@ -296,7 +275,7 @@ static void handle_attribute_packed_e(const attribute_t *attribute,
 static void handle_attribute_packed(const attribute_t *attribute, type_t *type)
 {
        if (type->kind != TYPE_COMPOUND_STRUCT) {
-               source_position_t const *const pos  = &attribute->source_position;
+               position_t const *const pos  = &attribute->pos;
                warningf(WARN_OTHER, pos, "packed attribute on type '%T' ignored", type);
                return;
        }
@@ -311,8 +290,7 @@ static void handle_attribute_asm(const attribute_t *attribute,
        assert (argument->kind == ATTRIBUTE_ARGUMENT_EXPRESSION);
        expression_t *expression = argument->v.expression;
        if (expression->kind != EXPR_STRING_LITERAL)
-               errorf(&attribute->source_position,
-                      "Invalid asm attribute expression");
+               errorf(&attribute->pos, "Invalid asm attribute expression");
        symbol_t *sym = symbol_table_insert(expression->string_literal.value.begin);
        entity->function.actual_name = sym;
        assert(argument->next == NULL);
@@ -334,7 +312,7 @@ void handle_entity_attributes(const attribute_t *attributes, entity_t *entity)
        decl_modifiers_t modifiers = 0;
        const attribute_t *attribute = attributes;
        for ( ; attribute != NULL; attribute = attribute->next) {
-               switch(attribute->kind) {
+               switch (attribute->kind) {
                case ATTRIBUTE_GNU_CONST:         modifiers |= DM_CONST; break;
                case ATTRIBUTE_GNU_DEPRECATED:    modifiers |= DM_DEPRECATED; break;
                case ATTRIBUTE_GNU_NOINLINE:      modifiers |= DM_NOINLINE; break;
@@ -383,7 +361,7 @@ void handle_entity_attributes(const attribute_t *attributes, entity_t *entity)
        }
 
        if (modifiers != 0) {
-               switch(entity->kind) {
+               switch (entity->kind) {
                case ENTITY_TYPEDEF:
                        entity->typedefe.modifiers |= modifiers;
                        break;
@@ -435,7 +413,7 @@ type_t *handle_type_attributes(const attribute_t *attributes, type_t *type)
 {
        const attribute_t *attribute = attributes;
        for ( ; attribute != NULL; attribute = attribute->next) {
-               switch(attribute->kind) {
+               switch (attribute->kind) {
                case ATTRIBUTE_GNU_PACKED:
                        handle_attribute_packed(attribute, type);
                        break;