00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "config.h"
00023 #include "system.h"
00024 #include "coretypes.h"
00025 #include "tree.h"
00026 #include "tm.h"
00027 #include "tm_p.h"
00028 #include "toplev.h"
00029
00030 #include "c-format.h"
00031 #include "intl.h"
00032
00033 #include "cpplib.h"
00034 #include "c-pragma.h"
00035 #include "c-common.h"
00036
00037
00038 static const format_length_info cmn_err_length_specs[] =
00039 {
00040 { "l", FMT_LEN_l, STD_C89, "ll", FMT_LEN_ll, STD_C89 },
00041 { NULL, 0, 0, NULL, 0, 0 }
00042 };
00043
00044 static const format_flag_spec cmn_err_flag_specs[] =
00045 {
00046 { 'w', 0, 0, N_("field width"), N_("field width in printf format"), STD_C89 },
00047 { 'L', 0, 0, N_("length modifier"), N_("length modifier in printf format"), STD_C89 },
00048 { 0, 0, 0, NULL, NULL, 0 }
00049 };
00050
00051
00052 static const format_flag_pair cmn_err_flag_pairs[] =
00053 {
00054 { 0, 0, 0, 0 }
00055 };
00056
00057 static const format_char_info bitfield_string_type =
00058 { "b", 1, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "cR", NULL };
00059
00060 static const format_char_info cmn_err_char_table[] =
00061 {
00062
00063 { "dD", 0, STD_C89, { T89_I, BADLEN, BADLEN, T89_L, T9L_LL, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", NULL },
00064 { "oOxX",0, STD_C89, { T89_UI, BADLEN, BADLEN, T89_UL, T9L_ULL, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", NULL },
00065 { "u", 0, STD_C89, { T89_UI, BADLEN, BADLEN, T89_UL, T9L_ULL, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", NULL },
00066 { "c", 0, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "", NULL },
00067 { "p", 1, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "c", NULL },
00068 { "s", 1, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "w", "cR", NULL },
00069 { "b", 0, STD_C89, { T89_I, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "", &bitfield_string_type },
00070 { NULL, 0, 0, NOLENGTHS, NULL, NULL, NULL }
00071 };
00072
00073 const format_kind_info solaris_format_types[] = {
00074 { "cmn_err", cmn_err_length_specs, cmn_err_char_table, "", NULL,
00075 cmn_err_flag_specs, cmn_err_flag_pairs,
00076 FMT_FLAG_ARG_CONVERT|FMT_FLAG_EMPTY_PREC_OK,
00077 'w', 0, 0, 0, 'L',
00078 &integer_type_node, &integer_type_node
00079 }
00080 };
00081
00082
00083
00084 static void
00085 solaris_pragma_align (cpp_reader *pfile ATTRIBUTE_UNUSED)
00086 {
00087 tree t, x;
00088 enum cpp_ttype ttype;
00089 HOST_WIDE_INT low;
00090
00091 if (c_lex (&x) != CPP_NUMBER
00092 || c_lex (&t) != CPP_OPEN_PAREN)
00093 {
00094 warning ("malformed %<#pragma align%>, ignoring");
00095 return;
00096 }
00097
00098 low = TREE_INT_CST_LOW (x);
00099 if (TREE_INT_CST_HIGH (x) != 0
00100 || (low != 1 && low != 2 && low != 4 && low != 8 && low != 16
00101 && low != 32 && low != 64 && low != 128))
00102 {
00103 warning ("invalid alignment for %<#pragma align%>, ignoring");
00104 return;
00105 }
00106
00107 ttype = c_lex (&t);
00108 if (ttype != CPP_NAME)
00109 {
00110 warning ("malformed %<#pragma align%>, ignoring");
00111 return;
00112 }
00113
00114 while (1)
00115 {
00116 tree decl = identifier_global_value (t);
00117 if (decl && DECL_P (decl))
00118 warning ("%<#pragma align%> must appear before the declaration of "
00119 "%D, ignoring", decl);
00120 else
00121 solaris_pending_aligns = tree_cons (t, build_tree_list (NULL, x),
00122 solaris_pending_aligns);
00123
00124 ttype = c_lex (&t);
00125 if (ttype == CPP_COMMA)
00126 {
00127 ttype = c_lex (&t);
00128 if (ttype != CPP_NAME)
00129 {
00130 warning ("malformed %<#pragma align%>");
00131 return;
00132 }
00133 }
00134 else if (ttype == CPP_CLOSE_PAREN)
00135 {
00136 if (c_lex (&t) != CPP_EOF)
00137 warning ("junk at end of %<#pragma align%>");
00138 return;
00139 }
00140 else
00141 {
00142 warning ("malformed %<#pragma align%>");
00143 return;
00144 }
00145 }
00146 }
00147
00148
00149
00150 static void
00151 solaris_pragma_init (cpp_reader *pfile ATTRIBUTE_UNUSED)
00152 {
00153 tree t;
00154 enum cpp_ttype ttype;
00155
00156 if (c_lex (&t) != CPP_OPEN_PAREN)
00157 {
00158 warning ("malformed %<#pragma init%>, ignoring");
00159 return;
00160 }
00161
00162 ttype = c_lex (&t);
00163 if (ttype != CPP_NAME)
00164 {
00165 warning ("malformed %<#pragma init%>, ignoring");
00166 return;
00167 }
00168
00169 while (1)
00170 {
00171 tree decl = identifier_global_value (t);
00172 if (decl && DECL_P (decl))
00173 {
00174 tree init_list = build_tree_list (get_identifier ("init"),
00175 NULL);
00176 tree attrs = tree_cons (get_identifier ("used"), NULL, init_list);
00177 decl_attributes (&decl, attrs, 0);
00178 }
00179 else
00180 solaris_pending_inits = tree_cons (t, NULL, solaris_pending_inits);
00181
00182 ttype = c_lex (&t);
00183 if (ttype == CPP_COMMA)
00184 {
00185 ttype = c_lex (&t);
00186 if (ttype != CPP_NAME)
00187 {
00188 warning ("malformed %<#pragma init%>");
00189 return;
00190 }
00191 }
00192 else if (ttype == CPP_CLOSE_PAREN)
00193 {
00194 if (c_lex (&t) != CPP_EOF)
00195 warning ("junk at end of %<#pragma init%>");
00196 return;
00197 }
00198 else
00199 {
00200 warning ("malformed %<#pragma init%>");
00201 return;
00202 }
00203 }
00204 }
00205
00206
00207
00208 static void
00209 solaris_pragma_fini (cpp_reader *pfile ATTRIBUTE_UNUSED)
00210 {
00211 tree t;
00212 enum cpp_ttype ttype;
00213
00214 if (c_lex (&t) != CPP_OPEN_PAREN)
00215 {
00216 warning ("malformed %<#pragma fini%>, ignoring");
00217 return;
00218 }
00219
00220 ttype = c_lex (&t);
00221 if (ttype != CPP_NAME)
00222 {
00223 warning ("malformed %<#pragma fini%>, ignoring");
00224 return;
00225 }
00226
00227 while (1)
00228 {
00229 tree decl = identifier_global_value (t);
00230 if (decl && DECL_P (decl))
00231 {
00232 tree fini_list = build_tree_list (get_identifier ("fini"),
00233 NULL);
00234 tree attrs = tree_cons (get_identifier ("used"), NULL, fini_list);
00235 decl_attributes (&decl, attrs, 0);
00236 }
00237 else
00238 solaris_pending_finis = tree_cons (t, NULL, solaris_pending_finis);
00239
00240 ttype = c_lex (&t);
00241 if (ttype == CPP_COMMA)
00242 {
00243 ttype = c_lex (&t);
00244 if (ttype != CPP_NAME)
00245 {
00246 warning ("malformed %<#pragma fini%>");
00247 return;
00248 }
00249 }
00250 else if (ttype == CPP_CLOSE_PAREN)
00251 {
00252 if (c_lex (&t) != CPP_EOF)
00253 warning ("junk at end of %<#pragma fini%>");
00254 return;
00255 }
00256 else
00257 {
00258 warning ("malformed %<#pragma fini%>");
00259 return;
00260 }
00261 }
00262 }
00263
00264
00265
00266 void
00267 solaris_register_pragmas (void)
00268 {
00269 c_register_pragma_with_expansion (0, "align", solaris_pragma_align);
00270 c_register_pragma (0, "init", solaris_pragma_init);
00271 c_register_pragma (0, "fini", solaris_pragma_fini);
00272 }