aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.c
diff options
context:
space:
mode:
authorNeil Booth <neil@daikokuya.demon.co.uk>2001-06-26 18:09:27 +0000
committerNeil Booth <neil@gcc.gnu.org>2001-06-26 18:09:27 +0000
commit672a6f42e98d55a92af9b649f077c0d38517116e (patch)
treed665db59621711f135866f664fecbdc22274c141 /gcc/tree.c
parent51da3560e0f89359b53d63f90ee422e95872be45 (diff)
downloadgcc-672a6f42e98d55a92af9b649f077c0d38517116e.zip
gcc-672a6f42e98d55a92af9b649f077c0d38517116e.tar.gz
gcc-672a6f42e98d55a92af9b649f077c0d38517116e.tar.bz2
Makefile.in (TARGET_H, [...]): New.
* Makefile.in (TARGET_H, TARGET_DEF_H): New. (c-decl.o, tree.o, c-typeck.o, $(out_object_file)): Update. * c-decl.c (duplicate_decls): Use function pointer. * c-typeck.c (common_type): Similarly. * tree.c (valid_machine_attribute): Similarly. (merge_machine_type_attributes): Rename merge_type_attributes. (merge_machine_decl_attributes): Rename merge_decl_attributes. (merge_dllimport_decl_attributes): New function. * tree.h (merge_machine_type_attributes): Rename merge_type_attributes. (merge_machine_decl_attributes): Rename merge_decl_attributes. (merge_dllimport_decl_attributes): New prototype. * target.h: New. * target-def.h: New. doc: (Joseph Myers) * doc/gcc.texi, doc/tm.texi: Update documentation. cp: Make-lang.in: Update dependencies. * spew.c: Include target.h. (duplicate_decls): Call target function. * decl2.c: include target.h (import_export_class): Use existence of target function pointer. * typeck.c: Include target.h. (qualify_type_recursive): Rename variable. Call target function. (type_after_usual_arithmetic_conversions): Similarly. (common_type): Similarly. config: * 1750a/1750a.c, a29k/29k.c, alpha/alpha.c, arc/arc.c, arm/arm.c, avr/avr.c, c4x/c4x.c, clipper/clipper.c, convex/convex.c, d30v/d30v.c, dsp16xx/dsp16xx.c, elxsi/elxsi.c, fr30/fr30.c, i370/i370.c, i386/i386.c, i860/i860.c, i960/i960.c, ia64/ia64.c, m32r/m32r.c, m68hc11/m68hc11.c, m68k/m68k.c, m88k/m88k.c, mips/mips.c, mn10200/mn10200.c, mn10300/mn10300.c, ns32k/ns32k.c, pa/pa.c, pdp11/pdp11.c, pj/pj.c, romp/romp.c, rs6000/rs6000.c, sh/sh.c, sparc/sparc.c, v850/v850.c, vax/vax.c, we32k/we32k.c) : Include target.h and target-def.h. Define target. * arc/arc-protos.h (arc_valid_machine_decl_attribute): Remove. * arc/arc.c (arc_valid_machine_decl_attribute): Rename arc_valid_decl_attribute, make static. * arc/arc.h (VALID_MACHINE_TYPE_ATTRIBUTE): Remove. * arm/arm-protos.h (arm_valid_machine_decl_attribute, arm_valid_type_attribute_p, arm_pe_valid_machine_decl_attribute, arm_pe_merge_machine_decl_attributes): Remove. * arm/arm.c (arm_valid_machine_decl_attribute_p): Rename arm_valid_decl_attribute_p, make static. (arm_pe_valid_decl_attribute_p): Move from pe.c. * arm/pe.c (arm_pe_valid_machine_decl_attribute_p): Move to arm.c. (arm_pe_merge_machine_decl_attributes): Move to tree.c. * arm/arm.h (VALID_MACHINE_TYPE_ATTRIBUTE): Remove. * arm/coff.h (VALID_MACHINE_DECL_ATTRIBUTE): Remove. * arm/elf.h (VALID_MACHINE_DECL_ATTRIBUTE): Remove. * arm/pe.h (TARGET_DLLIMPORT_DECL_ATTRIBUTES): New. (VALID_MACHINE_TYPE_ATTRIBUTE, VALID_MACHINE_DECL_ATTRIBUTE): Remove. * avr/avr-protos.h (valid_machine_type_attribute, valid_machine_decl_attribute): Remove. * avr/avr.c (valid_machine_type_attribute, valid_machine_decl_attribute): Rename and make static. * avr/avr.h (VALID_MACHINE_TYPE_ATTRIBUTE, VALID_MACHINE_DECL_ATTRIBUTE): Remove. * c4x/c4x-protos.h (c4x_valid_type_attribute_p): Remove. * c4x/c4x.c (c4x_valid_type_attribute_p): Make static. * c4x/c4x.h (VALID_MACHINE_TYPE_ATTRIBUTE): Remove. * d30v/d30v.h: Remove obsolete comments. * h8300/h8300-protos.h (h8300_valid_machine_decl_attribute): Remove. * h8300/h8300.c (h8300_valid_machine_decl_attribute): Rename, make static. * h8300/h8300.h (VALID_MACHINE_DECL_ATTRIBUTE): Remove. * i386/cygwin.h (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Define. (i386_pe_merge_decl_attributes, MERGE_MACHINE_DECL_ATTRIBUTES, i386_pe_valid_type_attributes_p): Remove. * i386/i386-protos.h (ix86_valid_decl_attribute_p, ix86_valid_type_attribute_p): Remove. * i386/i386.c (ix86_valid_decl_attribute_p): Remove. (ix86_valid_type_attribute_p): Make static. * i386/i386.h (VALID_MACHINE_DECL_ATTRIBUTE, VALID_MACHINE_TYPE_ATTRIBUTE): Remove. * i386/winnt.c (i386_pe_merge_decl_attributes): Move to tree.c. * ia64/ia64-protos.h (ia64_valid_type_attribute): Remove. * ia64/ia64.c (ia64_valid_type_attribute): Make static. * ia64/ia64.h (VALID_MACHINE_TYPE_ATTRIBUTE): Remove. * m32r/m32r-protos.h (m32r_valid_machine_decl_attribute): Remove. * m32r/m32r.c (m32r_valid_decl_attribute): Make static. * m32r/m32r.h (VALID_MACHINE_DECL_ATTRIBUTE): Remove. * m68hc11/m68hc11-protos.h (m68hc11_valid_decl_attribute_p, m68hc11_valid_type_attribute_p): Remove. * m68hc11/m68hc11.c (m68hc11_valid_decl_attribute_p): Remove. (m68hc11_valid_type_attribute_p): Make static. * m68hc11/m68hc11.h (VALID_MACHINE_DECL_ATTRIBUTE, VALID_MACHINE_TYPE_ATTRIBUTE): Remove. * mcore/mcore-protos.h (mcore_valid_machine_decl_attribute, mcore_merge_machine_decl_attribute): Remove. * mcore/mcore.c (mcore_valid_machine_decl_attribute): Rename, make static. (mcore_merge_machine_decl_attributes): Move to tree.c. * mcore/mcore.h (VALID_MACHINE_DECL_ATTRIBUTE, VALID_MACHINE_TYPE_ATTRIBUTE): Remove. (TARGET_DLLIMPORT_DECL_ATTRIBUTES): Define. * ns32k/ns32k-protos.h (ns32k_valid_decl_attribute_p, ns32k_valid_type_attribute_p): Remove. * ns32k/ns32k.c (ns32k_valid_decl_attribute_p): Remove. (ns32k_valid_type_attribute_p): Make static. * ns32k/ns32k.h (VALID_MACHINE_DECL_ATTRIBUTE, VALID_MACHINE_TYPE_ATTRIBUTE): Remove. * rs6000/rs6000-protos.h (rs6000_valid_decl_attribute_p, rs6000_valid_type_attribute_p): Remove. * rs6000/rs6000.c (rs6000_valid_decl_attribute_p): Remove. (rs6000_valid_type_attribute_p): Make static. * rs6000/rs6000.h (VALID_MACHINE_DECL_ATTRIBUTE, VALID_MACHINE_TYPE_ATTRIBUTE): Remove. * sh/sh-protos.h (sh_valid_machine_decl_attribute): Remove. * sh/sh.c (sh_valid_machine_decl_attribute): Rename, make static. * sh/sh.h (VALID_MACHINE_DECL_ATTRIBUTE): Remove. * v850/v850-protos.h (v850_valid_machine_decl_attribute): Remove. * v850/v850.c (v850_valid_machine_decl_attribute): Rename, make static. * v850/v850.h (VALID_MACHINE_DECL_ATTRIBUTE): Remove. From-SVN: r43585
Diffstat (limited to 'gcc/tree.c')
-rw-r--r--gcc/tree.c255
1 files changed, 150 insertions, 105 deletions
diff --git a/gcc/tree.c b/gcc/tree.c
index 2461c9b..40524c3 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -44,6 +44,7 @@ Boston, MA 02111-1307, USA. */
#include "ggc.h"
#include "hashtab.h"
#include "output.h"
+#include "target.h"
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
@@ -2706,124 +2707,119 @@ build_type_attribute_variant (ttype, attribute)
return ttype;
}
-/* Return a 1 if ATTR_NAME and ATTR_ARGS is valid for either declaration DECL
- or type TYPE and 0 otherwise. Validity is determined the configuration
- macros VALID_MACHINE_DECL_ATTRIBUTE and VALID_MACHINE_TYPE_ATTRIBUTE. */
+/* Return 1 if ATTR_NAME and ATTR_ARGS is valid for either declaration
+ DECL or type TYPE and 0 otherwise. Validity is determined the
+ target functions valid_decl_attribute and valid_machine_attribute. */
int
valid_machine_attribute (attr_name, attr_args, decl, type)
- tree attr_name;
- tree attr_args ATTRIBUTE_UNUSED;
- tree decl ATTRIBUTE_UNUSED;
- tree type ATTRIBUTE_UNUSED;
-{
- int validated = 0;
-#ifdef VALID_MACHINE_DECL_ATTRIBUTE
- tree decl_attr_list = decl != 0 ? DECL_MACHINE_ATTRIBUTES (decl) : 0;
-#endif
-#ifdef VALID_MACHINE_TYPE_ATTRIBUTE
- tree type_attr_list = TYPE_ATTRIBUTES (type);
-#endif
-
+ tree attr_name;
+ tree attr_args;
+ tree decl;
+ tree type;
+{
if (TREE_CODE (attr_name) != IDENTIFIER_NODE)
abort ();
-#ifdef VALID_MACHINE_DECL_ATTRIBUTE
- if (decl != 0
- && VALID_MACHINE_DECL_ATTRIBUTE (decl, decl_attr_list, attr_name,
- attr_args))
+ if (decl && target.valid_decl_attribute != NULL)
{
- tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
- decl_attr_list);
+ tree decl_attrs = DECL_MACHINE_ATTRIBUTES (decl);
- if (attr != NULL_TREE)
- {
- /* Override existing arguments. Declarations are unique so we can
- modify this in place. */
- TREE_VALUE (attr) = attr_args;
- }
- else
+ if ((*target.valid_decl_attribute) (decl, decl_attrs, attr_name,
+ attr_args))
{
- decl_attr_list = tree_cons (attr_name, attr_args, decl_attr_list);
- decl = build_decl_attribute_variant (decl, decl_attr_list);
- }
+ tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
+ decl_attrs);
- validated = 1;
+ if (attr != NULL_TREE)
+ {
+ /* Override existing arguments. Declarations are unique
+ so we can modify this in place. */
+ TREE_VALUE (attr) = attr_args;
+ }
+ else
+ {
+ decl_attrs = tree_cons (attr_name, attr_args, decl_attrs);
+ decl = build_decl_attribute_variant (decl, decl_attrs);
+ }
+
+ /* Don't apply the attribute to both the decl and the type. */
+ return 1;
+ }
}
-#endif
-#ifdef VALID_MACHINE_TYPE_ATTRIBUTE
- if (validated)
- /* Don't apply the attribute to both the decl and the type. */
- ;
- else if (VALID_MACHINE_TYPE_ATTRIBUTE (type, type_attr_list, attr_name,
- attr_args))
+ if (target.valid_type_attribute != NULL)
{
- tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
- type_attr_list);
+ tree type_attrs = TYPE_ATTRIBUTES (type);
- if (attr != NULL_TREE)
+ if ((*target.valid_type_attribute) (type, type_attrs, attr_name,
+ attr_args))
{
- /* Override existing arguments.
- ??? This currently works since attribute arguments are not
- included in `attribute_hash_list'. Something more complicated
- may be needed in the future. */
- TREE_VALUE (attr) = attr_args;
- }
- else
- {
- /* If this is part of a declaration, create a type variant,
- otherwise, this is part of a type definition, so add it
- to the base type. */
- type_attr_list = tree_cons (attr_name, attr_args, type_attr_list);
- if (decl != 0)
- type = build_type_attribute_variant (type, type_attr_list);
- else
- TYPE_ATTRIBUTES (type) = type_attr_list;
- }
-
- if (decl != 0)
- TREE_TYPE (decl) = type;
+ tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
+ type_attrs);
- validated = 1;
- }
+ if (attr != NULL_TREE)
+ {
+ /* Override existing arguments. ??? This currently
+ works since attribute arguments are not included in
+ `attribute_hash_list'. Something more complicated
+ may be needed in the future. */
+ TREE_VALUE (attr) = attr_args;
+ }
+ else
+ {
+ /* If this is part of a declaration, create a type variant,
+ otherwise, this is part of a type definition, so add it
+ to the base type. */
+ type_attrs = tree_cons (attr_name, attr_args, type_attrs);
+ if (decl != 0)
+ type = build_type_attribute_variant (type, type_attrs);
+ else
+ TYPE_ATTRIBUTES (type) = type_attrs;
+ }
- /* Handle putting a type attribute on pointer-to-function-type by putting
- the attribute on the function type. */
- else if (POINTER_TYPE_P (type)
- && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
- && VALID_MACHINE_TYPE_ATTRIBUTE (TREE_TYPE (type), type_attr_list,
- attr_name, attr_args))
- {
- tree inner_type = TREE_TYPE (type);
- tree inner_attr_list = TYPE_ATTRIBUTES (inner_type);
- tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
- type_attr_list);
+ if (decl)
+ TREE_TYPE (decl) = type;
- if (attr != NULL_TREE)
- TREE_VALUE (attr) = attr_args;
- else
- {
- inner_attr_list = tree_cons (attr_name, attr_args, inner_attr_list);
- inner_type = build_type_attribute_variant (inner_type,
- inner_attr_list);
+ return 1;
}
- if (decl != 0)
- TREE_TYPE (decl) = build_pointer_type (inner_type);
- else
+ /* Handle putting a type attribute on pointer-to-function-type
+ by putting the attribute on the function type. */
+ else if (POINTER_TYPE_P (type)
+ && TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
+ && (*target.valid_type_attribute) (TREE_TYPE (type), type_attrs,
+ attr_name, attr_args))
{
- /* Clear TYPE_POINTER_TO for the old inner type, since
- `type' won't be pointing to it anymore. */
- TYPE_POINTER_TO (TREE_TYPE (type)) = NULL_TREE;
- TREE_TYPE (type) = inner_type;
- }
+ tree inner_type = TREE_TYPE (type);
+ tree inner_attrs = TYPE_ATTRIBUTES (inner_type);
+ tree attr = lookup_attribute (IDENTIFIER_POINTER (attr_name),
+ type_attrs);
- validated = 1;
+ if (attr != NULL_TREE)
+ TREE_VALUE (attr) = attr_args;
+ else
+ {
+ inner_attrs = tree_cons (attr_name, attr_args, inner_attrs);
+ inner_type = build_type_attribute_variant (inner_type,
+ inner_attrs);
+ }
+
+ if (decl)
+ TREE_TYPE (decl) = build_pointer_type (inner_type);
+ else
+ {
+ /* Clear TYPE_POINTER_TO for the old inner type, since
+ `type' won't be pointing to it anymore. */
+ TYPE_POINTER_TO (TREE_TYPE (type)) = NULL_TREE;
+ TREE_TYPE (type) = inner_type;
+ }
+
+ return 1;
+ }
}
-#endif
- return validated;
+ return 0;
}
/* Return non-zero if IDENT is a valid name for attribute ATTR,
@@ -2938,34 +2934,83 @@ merge_attributes (a1, a2)
}
/* Given types T1 and T2, merge their attributes and return
- the result. */
+ the result. */
tree
-merge_machine_type_attributes (t1, t2)
+merge_type_attributes (t1, t2)
tree t1, t2;
{
-#ifdef MERGE_MACHINE_TYPE_ATTRIBUTES
- return MERGE_MACHINE_TYPE_ATTRIBUTES (t1, t2);
-#else
return merge_attributes (TYPE_ATTRIBUTES (t1),
TYPE_ATTRIBUTES (t2));
-#endif
}
/* Given decls OLDDECL and NEWDECL, merge their attributes and return
the result. */
tree
-merge_machine_decl_attributes (olddecl, newdecl)
+merge_decl_attributes (olddecl, newdecl)
tree olddecl, newdecl;
{
-#ifdef MERGE_MACHINE_DECL_ATTRIBUTES
- return MERGE_MACHINE_DECL_ATTRIBUTES (olddecl, newdecl);
-#else
return merge_attributes (DECL_MACHINE_ATTRIBUTES (olddecl),
DECL_MACHINE_ATTRIBUTES (newdecl));
-#endif
}
+
+#ifdef TARGET_DLLIMPORT_DECL_ATTRIBUTES
+
+/* Specialization of merge_decl_attributes for various Windows targets.
+
+ This handles the following situation:
+
+ __declspec (dllimport) int foo;
+ int foo;
+
+ The second instance of `foo' nullifies the dllimport. */
+
+tree
+merge_dllimport_decl_attributes (old, new)
+ tree old;
+ tree new;
+{
+ tree a;
+ int delete_dllimport_p;
+
+ old = DECL_MACHINE_ATTRIBUTES (old);
+ new = DECL_MACHINE_ATTRIBUTES (new);
+
+ /* What we need to do here is remove from `old' dllimport if it doesn't
+ appear in `new'. dllimport behaves like extern: if a declaration is
+ marked dllimport and a definition appears later, then the object
+ is not dllimport'd. */
+ if (lookup_attribute ("dllimport", old) != NULL_TREE
+ && lookup_attribute ("dllimport", new) == NULL_TREE)
+ delete_dllimport_p = 1;
+ else
+ delete_dllimport_p = 0;
+
+ a = merge_attributes (old, new);
+
+ if (delete_dllimport_p)
+ {
+ tree prev,t;
+
+ /* Scan the list for dllimport and delete it. */
+ for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t))
+ {
+ if (is_attribute_p ("dllimport", TREE_PURPOSE (t)))
+ {
+ if (prev == NULL_TREE)
+ a = TREE_CHAIN (a);
+ else
+ TREE_CHAIN (prev) = TREE_CHAIN (t);
+ break;
+ }
+ }
+ }
+
+ return a;
+}
+
+#endif /* TARGET_DLLIMPORT_DECL_ATTRIBUTES */
/* Set the type qualifiers for TYPE to TYPE_QUALS, which is a bitmask
of the various TYPE_QUAL values. */