1 /* Routines for C compiler part of GCC for a Symbian OS targeted SH backend.
2 Copyright (C) 2004, 2005, 2007, 2009 Free Software Foundation, Inc.
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/>. */
24 #include "coretypes.h"
33 #include "sh-symbian.h"
36 /* Return the type that we should use to determine if DECL is
37 imported or exported. */
40 sh_symbian_associated_type (tree decl)
44 /* We can just take the DECL_CONTEXT as normal. */
45 if (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
46 t = DECL_CONTEXT (decl);
51 /* Return nonzero if DECL is a dllimport'd object. */
54 sh_symbian_is_dllimported (tree decl)
58 if ( TREE_CODE (decl) != VAR_DECL
59 && TREE_CODE (decl) != FUNCTION_DECL)
62 imp = lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl));
66 /* Class members get the dllimport status of their class. */
67 imp = sh_symbian_associated_type (decl);
71 imp = lookup_attribute ("dllimport", TYPE_ATTRIBUTES (imp));
75 /* Don't mark defined functions as dllimport. If the definition itself
76 was marked with dllimport, then sh_symbian_handle_dll_attribute reports
77 an error. This handles the case when the definition overrides an
78 earlier declaration. */
79 if (TREE_CODE (decl) == FUNCTION_DECL
80 && DECL_INITIAL (decl)
81 && ! DECL_DECLARED_INLINE_P (decl))
83 warning (OPT_Wattributes, "function %q+D is defined after prior "
84 "declaration as dllimport: attribute ignored",
89 /* Don't allow definitions of static data members in dllimport
90 class. Just ignore the attribute for vtable data. */
91 else if (TREE_CODE (decl) == VAR_DECL
94 && !DECL_EXTERNAL (decl))
96 error ("definition of static data member %q+D of dllimport'd class",
104 /* Handle a "dllimport" or "dllexport" attribute;
105 arguments as in struct attribute_spec.handler. */
108 sh_symbian_handle_dll_attribute (tree *pnode, tree name, tree args,
109 int flags, bool *no_add_attrs)
112 const char *attr = IDENTIFIER_POINTER (name);
114 /* These attributes may apply to structure and union types being
115 created, but otherwise should pass to the declaration involved. */
118 if (flags & ((int) ATTR_FLAG_DECL_NEXT
119 | (int) ATTR_FLAG_FUNCTION_NEXT
120 | (int) ATTR_FLAG_ARRAY_NEXT))
122 warning (OPT_Wattributes, "%qs attribute ignored", attr);
123 *no_add_attrs = true;
124 return tree_cons (name, args, NULL_TREE);
127 if (TREE_CODE (node) != RECORD_TYPE && TREE_CODE (node) != UNION_TYPE)
129 warning (OPT_Wattributes, "%qs attribute ignored", attr);
130 *no_add_attrs = true;
136 /* Report error on dllimport ambiguities
137 seen now before they cause any damage. */
138 else if (is_attribute_p ("dllimport", name))
140 if (TREE_CODE (node) == VAR_DECL)
142 if (DECL_INITIAL (node))
144 error ("variable %q+D definition is marked dllimport",
146 *no_add_attrs = true;
149 /* `extern' needn't be specified with dllimport.
150 Specify `extern' now and hope for the best. Sigh. */
151 DECL_EXTERNAL (node) = 1;
152 /* Also, implicitly give dllimport'd variables declared within
153 a function global scope, unless declared static. */
154 if (current_function_decl != NULL_TREE && ! TREE_STATIC (node))
155 TREE_PUBLIC (node) = 1;
159 /* Report error if symbol is not accessible at global scope. */
160 if (!TREE_PUBLIC (node)
161 && ( TREE_CODE (node) == VAR_DECL
162 || TREE_CODE (node) == FUNCTION_DECL))
164 error ("external linkage required for symbol %q+D because of %qE attribute",
166 *no_add_attrs = true;
170 print_node_brief (stderr, "mark node", node, 0);
171 fprintf (stderr, " as %s\n", attr);
178 sh_symbian_import_export_class (tree ctype ATTRIBUTE_UNUSED, int import_export)
180 return import_export;