Merge from mainline (165734:167278).
[official-gcc/graphite-test-results.git] / gcc / config / sh / symbian-c.c
blobcbffdb565812b7b4d67463db3cfa120e4374a993
1 /* Routines for C compiler part of GCC for a Symbian OS targeted SH backend.
2 Copyright (C) 2004, 2005, 2007, 2009, 2010 Free Software Foundation, Inc.
3 Contributed by RedHat.
4 Most of this code is stolen from i386/winnt.c.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published
10 by the Free Software Foundation; either version 3, or (at your
11 option) any later version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "rtl.h"
27 #include "output.h"
28 #include "flags.h"
29 #include "tree.h"
30 #include "expr.h"
31 #include "tm_p.h"
32 #include "diagnostic-core.h"
33 #include "toplev.h"
34 #include "sh-symbian.h"
37 /* Return the type that we should use to determine if DECL is
38 imported or exported. */
40 tree
41 sh_symbian_associated_type (tree decl)
43 tree t = NULL_TREE;
45 /* We can just take the DECL_CONTEXT as normal. */
46 if (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
47 t = DECL_CONTEXT (decl);
49 return t;
52 /* Return nonzero if DECL is a dllimport'd object. */
54 bool
55 sh_symbian_is_dllimported (tree decl)
57 tree imp;
59 if ( TREE_CODE (decl) != VAR_DECL
60 && TREE_CODE (decl) != FUNCTION_DECL)
61 return false;
63 imp = lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl));
64 if (imp)
65 return true;
67 /* Class members get the dllimport status of their class. */
68 imp = sh_symbian_associated_type (decl);
69 if (! imp)
70 return false;
72 imp = lookup_attribute ("dllimport", TYPE_ATTRIBUTES (imp));
73 if (!imp)
74 return false;
76 /* Don't mark defined functions as dllimport. If the definition itself
77 was marked with dllimport, then sh_symbian_handle_dll_attribute reports
78 an error. This handles the case when the definition overrides an
79 earlier declaration. */
80 if (TREE_CODE (decl) == FUNCTION_DECL
81 && DECL_INITIAL (decl)
82 && ! DECL_DECLARED_INLINE_P (decl))
84 warning (OPT_Wattributes, "function %q+D is defined after prior "
85 "declaration as dllimport: attribute ignored",
86 decl);
87 return false;
90 /* Don't allow definitions of static data members in dllimport
91 class. Just ignore the attribute for vtable data. */
92 else if (TREE_CODE (decl) == VAR_DECL
93 && TREE_STATIC (decl)
94 && TREE_PUBLIC (decl)
95 && !DECL_EXTERNAL (decl))
97 error ("definition of static data member %q+D of dllimport%'d class",
98 decl);
99 return false;
102 return true;
105 /* Handle a "dllimport" or "dllexport" attribute;
106 arguments as in struct attribute_spec.handler. */
108 tree
109 sh_symbian_handle_dll_attribute (tree *pnode, tree name, tree args,
110 int flags, bool *no_add_attrs)
112 tree node = *pnode;
113 const char *attr = IDENTIFIER_POINTER (name);
115 /* These attributes may apply to structure and union types being
116 created, but otherwise should pass to the declaration involved. */
117 if (!DECL_P (node))
119 if (flags & ((int) ATTR_FLAG_DECL_NEXT
120 | (int) ATTR_FLAG_FUNCTION_NEXT
121 | (int) ATTR_FLAG_ARRAY_NEXT))
123 warning (OPT_Wattributes, "%qs attribute ignored", attr);
124 *no_add_attrs = true;
125 return tree_cons (name, args, NULL_TREE);
128 if (TREE_CODE (node) != RECORD_TYPE && TREE_CODE (node) != UNION_TYPE)
130 warning (OPT_Wattributes, "%qs attribute ignored", attr);
131 *no_add_attrs = true;
134 return NULL_TREE;
137 /* Report error on dllimport ambiguities
138 seen now before they cause any damage. */
139 else if (is_attribute_p ("dllimport", name))
141 if (TREE_CODE (node) == VAR_DECL)
143 if (DECL_INITIAL (node))
145 error ("variable %q+D definition is marked dllimport",
146 node);
147 *no_add_attrs = true;
150 /* `extern' needn't be specified with dllimport.
151 Specify `extern' now and hope for the best. Sigh. */
152 DECL_EXTERNAL (node) = 1;
153 /* Also, implicitly give dllimport'd variables declared within
154 a function global scope, unless declared static. */
155 if (current_function_decl != NULL_TREE && ! TREE_STATIC (node))
156 TREE_PUBLIC (node) = 1;
160 /* Report error if symbol is not accessible at global scope. */
161 if (!TREE_PUBLIC (node)
162 && ( TREE_CODE (node) == VAR_DECL
163 || TREE_CODE (node) == FUNCTION_DECL))
165 error ("external linkage required for symbol %q+D because of %qE attribute",
166 node, name);
167 *no_add_attrs = true;
170 #if SYMBIAN_DEBUG
171 print_node_brief (stderr, "mark node", node, 0);
172 fprintf (stderr, " as %s\n", attr);
173 #endif
175 return NULL_TREE;
179 sh_symbian_import_export_class (tree ctype ATTRIBUTE_UNUSED, int import_export)
181 return import_export;