OSDN Git Service

Fix PR44768
[pf3gnuchains/gcc-fork.git] / gcc / config / sol2-c.c
1 /* Solaris support needed only by C/C++ frontends.
2    Copyright (C) 2004, 2005, 2007, 2009, 2010 Free Software Foundation, Inc.
3    Contributed by CodeSourcery, LLC.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tree.h"
25 #include "tm.h"
26 #include "tm_p.h"
27 #include "diagnostic-core.h"
28 #include "toplev.h"
29
30 #include "c-family/c-format.h"
31 #include "intl.h"
32
33 #include "cpplib.h"
34 #include "c-family/c-pragma.h"
35 #include "c-family/c-common.h"
36
37 /* cmn_err only accepts "l" and "ll".  */
38 static const format_length_info cmn_err_length_specs[] =
39 {
40   { "l", FMT_LEN_l, STD_C89, "ll", FMT_LEN_ll, STD_C89, 0 },
41   { NULL, FMT_LEN_none, STD_C89, NULL, FMT_LEN_none, STD_C89, 0 }
42 };
43
44 static const format_flag_spec cmn_err_flag_specs[] =
45 {
46   { 'w',  0, 0, N_("field width"),     N_("field width in printf format"),     STD_C89 },
47   { 'L',  0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89 },
48   { 0, 0, 0, NULL, NULL, STD_C89 }
49 };
50
51
52 static const format_flag_pair cmn_err_flag_pairs[] =
53 {
54   { 0, 0, 0, 0 }
55 };
56
57 static const format_char_info bitfield_string_type =
58   { "b",   1, STD_C89, { T89_C,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "",   "cR", NULL };
59
60 static const format_char_info cmn_err_char_table[] =
61 {
62   /* C89 conversion specifiers.  */
63   { "dD",  0, STD_C89, { T89_I,   BADLEN,  BADLEN,  T89_L,   T9L_LL,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "w",  "",   NULL },
64   { "oOxX",0, STD_C89, { T89_UI,  BADLEN,  BADLEN,  T89_UL,  T9L_ULL, BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "w",  "",   NULL },
65   { "u",   0, STD_C89, { T89_UI,  BADLEN,  BADLEN,  T89_UL,  T9L_ULL, BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "w",  "",   NULL },
66   { "c",   0, STD_C89, { T89_C,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "w",  "",   NULL },
67   { "p",   1, STD_C89, { T89_V,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "w", "c",  NULL },
68   { "s",   1, STD_C89, { T89_C,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "w",  "cR", NULL },
69   { "b",   0, STD_C89, { T89_I,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "w",   "",   &bitfield_string_type },
70   { NULL,  0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
71 };
72
73 const format_kind_info solaris_format_types[] = {
74   { "cmn_err",  cmn_err_length_specs,  cmn_err_char_table, "", NULL,
75     cmn_err_flag_specs, cmn_err_flag_pairs,
76     FMT_FLAG_ARG_CONVERT|FMT_FLAG_EMPTY_PREC_OK,
77     'w', 0, 0, 0, 'L', 0,
78     &integer_type_node, &integer_type_node
79   }
80 };
81
82 /* Handle #pragma align ALIGNMENT (VAR [, VAR]...)  */
83
84 static void
85 solaris_pragma_align (cpp_reader *pfile ATTRIBUTE_UNUSED)
86 {
87   tree t, x;
88   enum cpp_ttype ttype;
89   HOST_WIDE_INT low;
90
91   if (pragma_lex (&x) != CPP_NUMBER
92       || pragma_lex (&t) != CPP_OPEN_PAREN)
93     {
94       warning (0, "malformed %<#pragma align%>, ignoring");
95       return;
96     }
97
98   low = TREE_INT_CST_LOW (x);
99   if (TREE_INT_CST_HIGH (x) != 0
100       || (low != 1 && low != 2 && low != 4 && low != 8 && low != 16
101           && low != 32 && low != 64 && low != 128))
102     {
103       warning (0, "invalid alignment for %<#pragma align%>, ignoring");
104       return;
105     }
106
107   ttype = pragma_lex (&t);
108   if (ttype != CPP_NAME)
109     {
110       warning (0, "malformed %<#pragma align%>, ignoring");
111       return;
112     }
113
114   while (1)
115     {
116       tree decl = identifier_global_value (t);
117       if (decl && DECL_P (decl))
118         warning (0, "%<#pragma align%> must appear before the declaration of "
119                  "%D, ignoring", decl);
120       else
121         solaris_pending_aligns = tree_cons (t, build_tree_list (NULL, x),
122                                             solaris_pending_aligns);
123
124       ttype = pragma_lex (&t);
125       if (ttype == CPP_COMMA)
126         {
127           ttype = pragma_lex (&t);
128           if (ttype != CPP_NAME)
129             {
130               warning (0, "malformed %<#pragma align%>");
131               return;
132             }
133         }
134       else if (ttype == CPP_CLOSE_PAREN)
135         {
136           if (pragma_lex (&t) != CPP_EOF)
137             warning (0, "junk at end of %<#pragma align%>");
138           return;
139         }
140       else
141         {
142           warning (0, "malformed %<#pragma align%>");
143           return;
144         }
145     }
146 }
147
148 /* Handle #pragma init (function [, function]...)  */
149
150 static void
151 solaris_pragma_init (cpp_reader *pfile ATTRIBUTE_UNUSED)
152 {
153   tree t;
154   enum cpp_ttype ttype;
155
156   if (pragma_lex (&t) != CPP_OPEN_PAREN)
157     {
158       warning (0, "malformed %<#pragma init%>, ignoring");
159       return;
160     }
161
162   ttype = pragma_lex (&t);
163   if (ttype != CPP_NAME)
164     {
165       warning (0, "malformed %<#pragma init%>, ignoring");
166       return;
167     }
168
169   while (1)
170     {
171       tree decl = identifier_global_value (t);
172       if (decl && DECL_P (decl))
173         {
174           tree attrs = build_tree_list (get_identifier ("init"),
175                                         NULL);
176           TREE_USED (decl) = 1;
177           DECL_PRESERVE_P (decl) = 1;
178           decl_attributes (&decl, attrs, 0);
179         }
180       else
181         solaris_pending_inits = tree_cons (t, NULL, solaris_pending_inits);
182
183       ttype = pragma_lex (&t);
184       if (ttype == CPP_COMMA)
185         {
186           ttype = pragma_lex (&t);
187           if (ttype != CPP_NAME)
188             {
189               warning (0, "malformed %<#pragma init%>");
190               return;
191             }
192         }
193       else if (ttype == CPP_CLOSE_PAREN)
194         {
195           if (pragma_lex (&t) != CPP_EOF)
196             warning (0, "junk at end of %<#pragma init%>");
197           return;
198         }
199       else
200         {
201           warning (0, "malformed %<#pragma init%>");
202           return;
203         }
204     }
205 }
206
207 /* Handle #pragma fini (function [, function]...)  */
208
209 static void
210 solaris_pragma_fini (cpp_reader *pfile ATTRIBUTE_UNUSED)
211 {
212   tree t;
213   enum cpp_ttype ttype;
214
215   if (pragma_lex (&t) != CPP_OPEN_PAREN)
216     {
217       warning (0, "malformed %<#pragma fini%>, ignoring");
218       return;
219     }
220
221   ttype = pragma_lex (&t);
222   if (ttype != CPP_NAME)
223     {
224       warning (0, "malformed %<#pragma fini%>, ignoring");
225       return;
226     }
227
228   while (1)
229     {
230       tree decl = identifier_global_value (t);
231       if (decl && DECL_P (decl))
232         {
233           tree attrs = build_tree_list (get_identifier ("fini"),
234                                         NULL);
235           TREE_USED (decl) = 1;
236           DECL_PRESERVE_P (decl) = 1;
237           decl_attributes (&decl, attrs, 0);
238         }
239       else
240         solaris_pending_finis = tree_cons (t, NULL, solaris_pending_finis);
241
242       ttype = pragma_lex (&t);
243       if (ttype == CPP_COMMA)
244         {
245           ttype = pragma_lex (&t);
246           if (ttype != CPP_NAME)
247             {
248               warning (0, "malformed %<#pragma fini%>");
249               return;
250             }
251         }
252       else if (ttype == CPP_CLOSE_PAREN)
253         {
254           if (pragma_lex (&t) != CPP_EOF)
255             warning (0, "junk at end of %<#pragma fini%>");
256           return;
257         }
258       else
259         {
260           warning (0, "malformed %<#pragma fini%>");
261           return;
262         }
263     }
264 }
265
266 /* Register Solaris-specific #pragma directives.  */
267
268 void
269 solaris_register_pragmas (void)
270 {
271   c_register_pragma_with_expansion (0, "align", solaris_pragma_align);
272   c_register_pragma (0, "init", solaris_pragma_init);
273   c_register_pragma (0, "fini", solaris_pragma_fini);
274 }