OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [c-pragma.c] - Blame information for rev 20

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 jlechner
/* Handle #pragma, system V.4 style.  Supports #pragma weak and #pragma pack.
2
   Copyright (C) 1992, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3
   Free Software Foundation, Inc.
4
 
5
This file is part of GCC.
6
 
7
GCC is free software; you can redistribute it and/or modify it under
8
the terms of the GNU General Public License as published by the Free
9
Software Foundation; either version 2, or (at your option) any later
10
version.
11
 
12
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13
WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15
for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with GCC; see the file COPYING.  If not, write to the Free
19
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
20
02110-1301, USA.  */
21
 
22
#include "config.h"
23
#include "system.h"
24
#include "coretypes.h"
25
#include "tm.h"
26
#include "rtl.h"
27
#include "tree.h"
28
#include "function.h"
29
#include "cpplib.h"
30
#include "c-pragma.h"
31
#include "flags.h"
32
#include "toplev.h"
33
#include "ggc.h"
34
#include "c-common.h"
35
#include "output.h"
36
#include "tm_p.h"
37
#include "vec.h"
38
#include "target.h"
39
 
40
#define GCC_BAD(gmsgid) \
41
  do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
42
#define GCC_BAD2(gmsgid, arg) \
43
  do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
44
 
45
typedef struct align_stack GTY(())
46
{
47
  int                  alignment;
48
  tree                 id;
49
  struct align_stack * prev;
50
} align_stack;
51
 
52
static GTY(()) struct align_stack * alignment_stack;
53
 
54
#ifdef HANDLE_PRAGMA_PACK
55
static void handle_pragma_pack (cpp_reader *);
56
 
57
#ifdef HANDLE_PRAGMA_PACK_PUSH_POP
58
/* If we have a "global" #pragma pack(<n>) in effect when the first
59
   #pragma pack(push,<n>) is encountered, this stores the value of
60
   maximum_field_alignment in effect.  When the final pop_alignment()
61
   happens, we restore the value to this, not to a value of 0 for
62
   maximum_field_alignment.  Value is in bits.  */
63
static int default_alignment;
64
#define SET_GLOBAL_ALIGNMENT(ALIGN) (maximum_field_alignment = *(alignment_stack == NULL \
65
        ? &default_alignment \
66
        : &alignment_stack->alignment) = (ALIGN))
67
 
68
static void push_alignment (int, tree);
69
static void pop_alignment (tree);
70
 
71
/* Push an alignment value onto the stack.  */
72
static void
73
push_alignment (int alignment, tree id)
74
{
75
  align_stack * entry;
76
 
77
  entry = ggc_alloc (sizeof (* entry));
78
 
79
  entry->alignment  = alignment;
80
  entry->id         = id;
81
  entry->prev       = alignment_stack;
82
 
83
  /* The current value of maximum_field_alignment is not necessarily
84
 
85
     so that we can restore it after the final #pragma pop().  */
86
  if (alignment_stack == NULL)
87
    default_alignment = maximum_field_alignment;
88
 
89
  alignment_stack = entry;
90
 
91
  maximum_field_alignment = alignment;
92
}
93
 
94
/* Undo a push of an alignment onto the stack.  */
95
static void
96
pop_alignment (tree id)
97
{
98
  align_stack * entry;
99
 
100
  if (alignment_stack == NULL)
101
    GCC_BAD ("#pragma pack (pop) encountered without matching #pragma pack (push)");
102
 
103
  /* If we got an identifier, strip away everything above the target
104
     entry so that the next step will restore the state just below it.  */
105
  if (id)
106
    {
107
      for (entry = alignment_stack; entry; entry = entry->prev)
108
        if (entry->id == id)
109
          {
110
            alignment_stack = entry;
111
            break;
112
          }
113
      if (entry == NULL)
114
        warning (OPT_Wpragmas, "\
115
#pragma pack(pop, %s) encountered without matching #pragma pack(push, %s)"
116
                 , IDENTIFIER_POINTER (id), IDENTIFIER_POINTER (id));
117
    }
118
 
119
  entry = alignment_stack->prev;
120
 
121
  maximum_field_alignment = entry ? entry->alignment : default_alignment;
122
 
123
  alignment_stack = entry;
124
}
125
#else  /* not HANDLE_PRAGMA_PACK_PUSH_POP */
126
#define SET_GLOBAL_ALIGNMENT(ALIGN) (maximum_field_alignment = (ALIGN))
127
#define push_alignment(ID, N) \
128
    GCC_BAD ("#pragma pack(push[, id], <n>) is not supported on this target")
129
#define pop_alignment(ID) \
130
    GCC_BAD ("#pragma pack(pop[, id], <n>) is not supported on this target")
131
#endif /* HANDLE_PRAGMA_PACK_PUSH_POP */
132
 
133
/* #pragma pack ()
134
   #pragma pack (N)
135
 
136
   #pragma pack (push)
137
   #pragma pack (push, N)
138
   #pragma pack (push, ID)
139
   #pragma pack (push, ID, N)
140
   #pragma pack (pop)
141
   #pragma pack (pop, ID) */
142
static void
143
handle_pragma_pack (cpp_reader * ARG_UNUSED (dummy))
144
{
145
  tree x, id = 0;
146
  int align = -1;
147
  enum cpp_ttype token;
148
  enum { set, push, pop } action;
149
 
150
  if (c_lex (&x) != CPP_OPEN_PAREN)
151
    GCC_BAD ("missing %<(%> after %<#pragma pack%> - ignored");
152
 
153
  token = c_lex (&x);
154
  if (token == CPP_CLOSE_PAREN)
155
    {
156
      action = set;
157
      align = initial_max_fld_align;
158
    }
159
  else if (token == CPP_NUMBER)
160
    {
161
      align = TREE_INT_CST_LOW (x);
162
      action = set;
163
      if (c_lex (&x) != CPP_CLOSE_PAREN)
164
        GCC_BAD ("malformed %<#pragma pack%> - ignored");
165
    }
166
  else if (token == CPP_NAME)
167
    {
168
#define GCC_BAD_ACTION do { if (action != pop) \
169
          GCC_BAD ("malformed %<#pragma pack(push[, id][, <n>])%> - ignored"); \
170
        else \
171
          GCC_BAD ("malformed %<#pragma pack(pop[, id])%> - ignored"); \
172
        } while (0)
173
 
174
      const char *op = IDENTIFIER_POINTER (x);
175
      if (!strcmp (op, "push"))
176
        action = push;
177
      else if (!strcmp (op, "pop"))
178
        action = pop;
179
      else
180
        GCC_BAD2 ("unknown action %qs for %<#pragma pack%> - ignored", op);
181
 
182
      while ((token = c_lex (&x)) == CPP_COMMA)
183
        {
184
          token = c_lex (&x);
185
          if (token == CPP_NAME && id == 0)
186
            {
187
              id = x;
188
            }
189
          else if (token == CPP_NUMBER && action == push && align == -1)
190
            {
191
              align = TREE_INT_CST_LOW (x);
192
              if (align == -1)
193
                action = set;
194
            }
195
          else
196
            GCC_BAD_ACTION;
197
        }
198
 
199
      if (token != CPP_CLOSE_PAREN)
200
        GCC_BAD_ACTION;
201
#undef GCC_BAD_ACTION
202
    }
203
  else
204
    GCC_BAD ("malformed %<#pragma pack%> - ignored");
205
 
206
  if (c_lex (&x) != CPP_EOF)
207
    warning (OPT_Wpragmas, "junk at end of %<#pragma pack%>");
208
 
209
  if (flag_pack_struct)
210
    GCC_BAD ("#pragma pack has no effect with -fpack-struct - ignored");
211
 
212
  if (action != pop)
213
    switch (align)
214
      {
215
      case 0:
216
      case 1:
217
      case 2:
218
      case 4:
219
      case 8:
220
      case 16:
221
        align *= BITS_PER_UNIT;
222
        break;
223
      case -1:
224
        if (action == push)
225
          {
226
            align = maximum_field_alignment;
227
            break;
228
          }
229
      default:
230
        GCC_BAD2 ("alignment must be a small power of two, not %d", align);
231
      }
232
 
233
  switch (action)
234
    {
235
    case set:   SET_GLOBAL_ALIGNMENT (align);  break;
236
    case push:  push_alignment (align, id);    break;
237
    case pop:   pop_alignment (id);            break;
238
    }
239
}
240
#endif  /* HANDLE_PRAGMA_PACK */
241
 
242
static GTY(()) tree pending_weaks;
243
 
244
#ifdef HANDLE_PRAGMA_WEAK
245
static void apply_pragma_weak (tree, tree);
246
static void handle_pragma_weak (cpp_reader *);
247
 
248
static void
249
apply_pragma_weak (tree decl, tree value)
250
{
251
  if (value)
252
    {
253
      value = build_string (IDENTIFIER_LENGTH (value),
254
                            IDENTIFIER_POINTER (value));
255
      decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
256
                                               build_tree_list (NULL, value)),
257
                       0);
258
    }
259
 
260
  if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
261
      && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma.  */
262
      && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
263
    warning (OPT_Wpragmas, "applying #pragma weak %q+D after first use "
264
             "results in unspecified behavior", decl);
265
 
266
  declare_weak (decl);
267
}
268
 
269
void
270
maybe_apply_pragma_weak (tree decl)
271
{
272
  tree *p, t, id;
273
 
274
  /* Avoid asking for DECL_ASSEMBLER_NAME when it's not needed.  */
275
 
276
  /* No weak symbols pending, take the short-cut.  */
277
  if (!pending_weaks)
278
    return;
279
  /* If it's not visible outside this file, it doesn't matter whether
280
     it's weak.  */
281
  if (!DECL_EXTERNAL (decl) && !TREE_PUBLIC (decl))
282
    return;
283
  /* If it's not a function or a variable, it can't be weak.
284
     FIXME: what kinds of things are visible outside this file but
285
     aren't functions or variables?   Should this be an assert instead?  */
286
  if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
287
    return;
288
 
289
  id = DECL_ASSEMBLER_NAME (decl);
290
 
291
  for (p = &pending_weaks; (t = *p) ; p = &TREE_CHAIN (t))
292
    if (id == TREE_PURPOSE (t))
293
      {
294
        apply_pragma_weak (decl, TREE_VALUE (t));
295
        *p = TREE_CHAIN (t);
296
        break;
297
      }
298
}
299
 
300
/* Process all "#pragma weak A = B" directives where we have not seen
301
   a decl for A.  */
302
void
303
maybe_apply_pending_pragma_weaks (void)
304
{
305
  tree *p, t, alias_id, id, decl, *next;
306
 
307
  for (p = &pending_weaks; (t = *p) ; p = next)
308
    {
309
      next = &TREE_CHAIN (t);
310
      alias_id = TREE_PURPOSE (t);
311
      id = TREE_VALUE (t);
312
 
313
      if (TREE_VALUE (t) == NULL)
314
        continue;
315
 
316
      decl = build_decl (FUNCTION_DECL, alias_id, default_function_type);
317
 
318
      DECL_ARTIFICIAL (decl) = 1;
319
      TREE_PUBLIC (decl) = 1;
320
      DECL_EXTERNAL (decl) = 1;
321
      DECL_WEAK (decl) = 1;
322
 
323
      assemble_alias (decl, id);
324
    }
325
}
326
 
327
/* #pragma weak name [= value] */
328
static void
329
handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy))
330
{
331
  tree name, value, x, decl;
332
  enum cpp_ttype t;
333
 
334
  value = 0;
335
 
336
  if (c_lex (&name) != CPP_NAME)
337
    GCC_BAD ("malformed #pragma weak, ignored");
338
  t = c_lex (&x);
339
  if (t == CPP_EQ)
340
    {
341
      if (c_lex (&value) != CPP_NAME)
342
        GCC_BAD ("malformed #pragma weak, ignored");
343
      t = c_lex (&x);
344
    }
345
  if (t != CPP_EOF)
346
    warning (OPT_Wpragmas, "junk at end of #pragma weak");
347
 
348
  decl = identifier_global_value (name);
349
  if (decl && DECL_P (decl))
350
    {
351
      apply_pragma_weak (decl, value);
352
      if (value)
353
        assemble_alias (decl, value);
354
    }
355
  else
356
    pending_weaks = tree_cons (name, value, pending_weaks);
357
}
358
#else
359
void
360
maybe_apply_pragma_weak (tree ARG_UNUSED (decl))
361
{
362
}
363
 
364
void
365
maybe_apply_pending_pragma_weaks (void)
366
{
367
}
368
#endif /* HANDLE_PRAGMA_WEAK */
369
 
370
/* GCC supports two #pragma directives for renaming the external
371
   symbol associated with a declaration (DECL_ASSEMBLER_NAME), for
372
   compatibility with the Solaris and Tru64 system headers.  GCC also
373
   has its own notation for this, __asm__("name") annotations.
374
 
375
   Corner cases of these features and their interaction:
376
 
377
   1) Both pragmas silently apply only to declarations with external
378
      linkage (that is, TREE_PUBLIC || DECL_EXTERNAL).  Asm labels
379
      do not have this restriction.
380
 
381
   2) In C++, both #pragmas silently apply only to extern "C" declarations.
382
      Asm labels do not have this restriction.
383
 
384
   3) If any of the three ways of changing DECL_ASSEMBLER_NAME is
385
      applied to a decl whose DECL_ASSEMBLER_NAME is already set, and the
386
      new name is different, a warning issues and the name does not change.
387
 
388
   4) The "source name" for #pragma redefine_extname is the DECL_NAME,
389
      *not* the DECL_ASSEMBLER_NAME.
390
 
391
   5) If #pragma extern_prefix is in effect and a declaration occurs
392
      with an __asm__ name, the #pragma extern_prefix is silently
393
      ignored for that declaration.
394
 
395
   6) If #pragma extern_prefix and #pragma redefine_extname apply to
396
      the same declaration, whichever triggered first wins, and a warning
397
      is issued.  (We would like to have #pragma redefine_extname always
398
      win, but it can appear either before or after the declaration, and
399
      if it appears afterward, we have no way of knowing whether a modified
400
      DECL_ASSEMBLER_NAME is due to #pragma extern_prefix.)  */
401
 
402
static GTY(()) tree pending_redefine_extname;
403
 
404
static void handle_pragma_redefine_extname (cpp_reader *);
405
 
406
/* #pragma redefine_extname oldname newname */
407
static void
408
handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy))
409
{
410
  tree oldname, newname, decl, x;
411
  enum cpp_ttype t;
412
 
413
  if (c_lex (&oldname) != CPP_NAME)
414
    GCC_BAD ("malformed #pragma redefine_extname, ignored");
415
  if (c_lex (&newname) != CPP_NAME)
416
    GCC_BAD ("malformed #pragma redefine_extname, ignored");
417
  t = c_lex (&x);
418
  if (t != CPP_EOF)
419
    warning (OPT_Wpragmas, "junk at end of #pragma redefine_extname");
420
 
421
  if (!flag_mudflap && !targetm.handle_pragma_redefine_extname)
422
    {
423
      if (warn_unknown_pragmas > in_system_header)
424
        warning (OPT_Wunknown_pragmas,
425
                 "#pragma redefine_extname not supported on this target");
426
      return;
427
    }
428
 
429
  decl = identifier_global_value (oldname);
430
  if (decl
431
      && (TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
432
      && (TREE_CODE (decl) == FUNCTION_DECL
433
          || TREE_CODE (decl) == VAR_DECL)
434
      && has_c_linkage (decl))
435
    {
436
      if (DECL_ASSEMBLER_NAME_SET_P (decl))
437
        {
438
          const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
439
          name = targetm.strip_name_encoding (name);
440
 
441
          if (strcmp (name, IDENTIFIER_POINTER (newname)))
442
            warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
443
                     "conflict with previous rename");
444
        }
445
      else
446
        change_decl_assembler_name (decl, newname);
447
    }
448
  else
449
    /* We have to add this to the rename list even if there's already
450
       a global value that doesn't meet the above criteria, because in
451
       C++ "struct foo {...};" puts "foo" in the current namespace but
452
       does *not* conflict with a subsequent declaration of a function
453
       or variable foo.  See g++.dg/other/pragma-re-2.C.  */
454
    add_to_renaming_pragma_list (oldname, newname);
455
}
456
 
457
/* This is called from here and from ia64.c.  */
458
void
459
add_to_renaming_pragma_list (tree oldname, tree newname)
460
{
461
  tree previous = purpose_member (oldname, pending_redefine_extname);
462
  if (previous)
463
    {
464
      if (TREE_VALUE (previous) != newname)
465
        warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
466
                 "conflict with previous #pragma redefine_extname");
467
      return;
468
    }
469
 
470
  pending_redefine_extname
471
    = tree_cons (oldname, newname, pending_redefine_extname);
472
}
473
 
474
static GTY(()) tree pragma_extern_prefix;
475
 
476
/* #pragma extern_prefix "prefix" */
477
static void
478
handle_pragma_extern_prefix (cpp_reader * ARG_UNUSED (dummy))
479
{
480
  tree prefix, x;
481
  enum cpp_ttype t;
482
 
483
  if (c_lex (&prefix) != CPP_STRING)
484
    GCC_BAD ("malformed #pragma extern_prefix, ignored");
485
  t = c_lex (&x);
486
  if (t != CPP_EOF)
487
    warning (OPT_Wpragmas, "junk at end of #pragma extern_prefix");
488
 
489
  if (targetm.handle_pragma_extern_prefix)
490
    /* Note that the length includes the null terminator.  */
491
    pragma_extern_prefix = (TREE_STRING_LENGTH (prefix) > 1 ? prefix : NULL);
492
  else if (warn_unknown_pragmas > in_system_header)
493
    warning (OPT_Wunknown_pragmas,
494
             "#pragma extern_prefix not supported on this target");
495
}
496
 
497
/* Hook from the front ends to apply the results of one of the preceding
498
   pragmas that rename variables.  */
499
 
500
tree
501
maybe_apply_renaming_pragma (tree decl, tree asmname)
502
{
503
  tree *p, t;
504
 
505
  /* The renaming pragmas are only applied to declarations with
506
     external linkage.  */
507
  if ((TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
508
      || (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
509
      || !has_c_linkage (decl))
510
    return asmname;
511
 
512
  /* If the DECL_ASSEMBLER_NAME is already set, it does not change,
513
     but we may warn about a rename that conflicts.  */
514
  if (DECL_ASSEMBLER_NAME_SET_P (decl))
515
    {
516
      const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
517
      oldname = targetm.strip_name_encoding (oldname);
518
 
519
      if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
520
          warning (OPT_Wpragmas, "asm declaration ignored due to "
521
                   "conflict with previous rename");
522
 
523
      /* Take any pending redefine_extname off the list.  */
524
      for (p = &pending_redefine_extname; (t = *p); p = &TREE_CHAIN (t))
525
        if (DECL_NAME (decl) == TREE_PURPOSE (t))
526
          {
527
            /* Only warn if there is a conflict.  */
528
            if (strcmp (IDENTIFIER_POINTER (TREE_VALUE (t)), oldname))
529
              warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
530
                       "conflict with previous rename");
531
 
532
            *p = TREE_CHAIN (t);
533
            break;
534
          }
535
      return 0;
536
    }
537
 
538
  /* Find out if we have a pending #pragma redefine_extname.  */
539
  for (p = &pending_redefine_extname; (t = *p); p = &TREE_CHAIN (t))
540
    if (DECL_NAME (decl) == TREE_PURPOSE (t))
541
      {
542
        tree newname = TREE_VALUE (t);
543
        *p = TREE_CHAIN (t);
544
 
545
        /* If we already have an asmname, #pragma redefine_extname is
546
           ignored (with a warning if it conflicts).  */
547
        if (asmname)
548
          {
549
            if (strcmp (TREE_STRING_POINTER (asmname),
550
                        IDENTIFIER_POINTER (newname)) != 0)
551
              warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
552
                       "conflict with __asm__ declaration");
553
            return asmname;
554
          }
555
 
556
        /* Otherwise we use what we've got; #pragma extern_prefix is
557
           silently ignored.  */
558
        return build_string (IDENTIFIER_LENGTH (newname),
559
                             IDENTIFIER_POINTER (newname));
560
      }
561
 
562
  /* If we've got an asmname, #pragma extern_prefix is silently ignored.  */
563
  if (asmname)
564
    return asmname;
565
 
566
  /* If #pragma extern_prefix is in effect, apply it.  */
567
  if (pragma_extern_prefix)
568
    {
569
      const char *prefix = TREE_STRING_POINTER (pragma_extern_prefix);
570
      size_t plen = TREE_STRING_LENGTH (pragma_extern_prefix) - 1;
571
 
572
      const char *id = IDENTIFIER_POINTER (DECL_NAME (decl));
573
      size_t ilen = IDENTIFIER_LENGTH (DECL_NAME (decl));
574
 
575
      char *newname = (char *) alloca (plen + ilen + 1);
576
 
577
      memcpy (newname,        prefix, plen);
578
      memcpy (newname + plen, id, ilen + 1);
579
 
580
      return build_string (plen + ilen, newname);
581
    }
582
 
583
  /* Nada.  */
584
  return 0;
585
}
586
 
587
 
588
#ifdef HANDLE_PRAGMA_VISIBILITY
589
static void handle_pragma_visibility (cpp_reader *);
590
 
591
typedef enum symbol_visibility visibility;
592
DEF_VEC_I (visibility);
593
DEF_VEC_ALLOC_I (visibility, heap);
594
 
595
/* Sets the default visibility for symbols to something other than that
596
   specified on the command line.  */
597
static void
598
handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED)
599
{
600
  /* Form is #pragma GCC visibility push(hidden)|pop */
601
  tree x;
602
  enum cpp_ttype token;
603
  enum { bad, push, pop } action = bad;
604
  static VEC (visibility, heap) *visstack;
605
 
606
  token = c_lex (&x);
607
  if (token == CPP_NAME)
608
    {
609
      const char *op = IDENTIFIER_POINTER (x);
610
      if (!strcmp (op, "push"))
611
        action = push;
612
      else if (!strcmp (op, "pop"))
613
        action = pop;
614
    }
615
  if (bad == action)
616
    GCC_BAD ("#pragma GCC visibility must be followed by push or pop");
617
  else
618
    {
619
      if (pop == action)
620
        {
621
          if (!VEC_length (visibility, visstack))
622
            {
623
              GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
624
            }
625
          else
626
            {
627
              default_visibility = VEC_pop (visibility, visstack);
628
              visibility_options.inpragma
629
                = VEC_length (visibility, visstack) != 0;
630
            }
631
        }
632
      else
633
        {
634
          if (c_lex (&x) != CPP_OPEN_PAREN)
635
            GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
636
          token = c_lex (&x);
637
          if (token != CPP_NAME)
638
            {
639
              GCC_BAD ("malformed #pragma GCC visibility push");
640
            }
641
          else
642
            {
643
              const char *str = IDENTIFIER_POINTER (x);
644
              VEC_safe_push (visibility, heap, visstack,
645
                             default_visibility);
646
              if (!strcmp (str, "default"))
647
                default_visibility = VISIBILITY_DEFAULT;
648
              else if (!strcmp (str, "internal"))
649
                default_visibility = VISIBILITY_INTERNAL;
650
              else if (!strcmp (str, "hidden"))
651
                default_visibility = VISIBILITY_HIDDEN;
652
              else if (!strcmp (str, "protected"))
653
                default_visibility = VISIBILITY_PROTECTED;
654
              else
655
                {
656
                  GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected");
657
                }
658
              visibility_options.inpragma = 1;
659
            }
660
          if (c_lex (&x) != CPP_CLOSE_PAREN)
661
            GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
662
        }
663
    }
664
  if (c_lex (&x) != CPP_EOF)
665
    warning (OPT_Wpragmas, "junk at end of %<#pragma GCC visibility%>");
666
}
667
 
668
#endif
669
 
670
/* Front-end wrappers for pragma registration to avoid dragging
671
   cpplib.h in almost everywhere.  */
672
void
673
c_register_pragma (const char *space, const char *name,
674
                   void (*handler) (struct cpp_reader *))
675
{
676
  cpp_register_pragma (parse_in, space, name, handler, 0);
677
}
678
 
679
void
680
c_register_pragma_with_expansion (const char *space, const char *name,
681
                                  void (*handler) (struct cpp_reader *))
682
{
683
  cpp_register_pragma (parse_in, space, name, handler, 1);
684
}
685
 
686
/* Set up front-end pragmas.  */
687
void
688
init_pragma (void)
689
{
690
#ifdef HANDLE_PRAGMA_PACK
691
#ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
692
  c_register_pragma_with_expansion (0, "pack", handle_pragma_pack);
693
#else
694
  c_register_pragma (0, "pack", handle_pragma_pack);
695
#endif
696
#endif
697
#ifdef HANDLE_PRAGMA_WEAK
698
  c_register_pragma (0, "weak", handle_pragma_weak);
699
#endif
700
#ifdef HANDLE_PRAGMA_VISIBILITY
701
  c_register_pragma ("GCC", "visibility", handle_pragma_visibility);
702
#endif
703
 
704
  c_register_pragma (0, "redefine_extname", handle_pragma_redefine_extname);
705
  c_register_pragma (0, "extern_prefix", handle_pragma_extern_prefix);
706
 
707
  c_register_pragma ("GCC", "pch_preprocess", c_common_pch_pragma);
708
 
709
#ifdef REGISTER_TARGET_PRAGMAS
710
  REGISTER_TARGET_PRAGMAS ();
711
#endif
712
}
713
 
714
#include "gt-c-pragma.h"

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.