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.
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"
32 #include "diagnostic-core.h"
34 #include "sh-symbian.h"
37 /* Return the type that we should use to determine if DECL is
38 imported or exported. */
41 sh_symbian_associated_type (tree decl
)
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
);
52 /* Return nonzero if DECL is a dllimport'd object. */
55 sh_symbian_is_dllimported (tree decl
)
59 if ( TREE_CODE (decl
) != VAR_DECL
60 && TREE_CODE (decl
) != FUNCTION_DECL
)
63 imp
= lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl
));
67 /* Class members get the dllimport status of their class. */
68 imp
= sh_symbian_associated_type (decl
);
72 imp
= lookup_attribute ("dllimport", TYPE_ATTRIBUTES (imp
));
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",
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
95 && !DECL_EXTERNAL (decl
))
97 error ("definition of static data member %q+D of dllimport%'d class",
105 /* Handle a "dllimport" or "dllexport" attribute;
106 arguments as in struct attribute_spec.handler. */
109 sh_symbian_handle_dll_attribute (tree
*pnode
, tree name
, tree args
,
110 int flags
, bool *no_add_attrs
)
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. */
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;
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",
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",
167 *no_add_attrs
= true;
171 print_node_brief (stderr
, "mark node", node
, 0);
172 fprintf (stderr
, " as %s\n", attr
);
179 sh_symbian_import_export_class (tree ctype ATTRIBUTE_UNUSED
, int import_export
)
181 return import_export
;