OSDN Git Service

fb51455ae6243060027518de6a0bd951c2c2eadb
[pf3gnuchains/gcc-fork.git] / gcc / config / darwin-c.c
1 /* Darwin support needed only by C/C++ frontends.
2    Copyright (C) 2001, 2003  Free Software Foundation, Inc.
3    Contributed by Apple Computer Inc.
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 2, 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 COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "cpplib.h"
27 #include "tree.h"
28 #include "c-pragma.h"
29 #include "c-tree.h"
30 #include "toplev.h"
31 #include "tm_p.h"
32
33 /* Pragmas.  */
34
35 #define BAD(msgid) do { warning (msgid); return; } while (0)
36
37 /* Maintain a small stack of alignments.  This is similar to pragma
38    pack's stack, but simpler.  */
39
40 static void push_field_alignment (int);
41 static void pop_field_alignment (void);
42
43 typedef struct align_stack
44 {
45   int alignment;
46   struct align_stack * prev;
47 } align_stack;
48
49 static struct align_stack * field_align_stack = NULL;
50
51 static void
52 push_field_alignment (int bit_alignment)
53 {
54   align_stack *entry = (align_stack *) xmalloc (sizeof (align_stack));
55
56   entry->alignment = maximum_field_alignment;
57   entry->prev = field_align_stack;
58   field_align_stack = entry;
59
60   maximum_field_alignment = bit_alignment;
61 }
62
63 static void
64 pop_field_alignment (void)
65 {
66   if (field_align_stack)
67     {
68       align_stack *entry = field_align_stack;
69
70       maximum_field_alignment = entry->alignment;
71       field_align_stack = entry->prev;
72       free (entry);
73     }
74   else
75     error ("too many #pragma options align=reset");
76 }
77
78 /* Handlers for Darwin-specific pragmas.  */
79
80 void
81 darwin_pragma_ignore (cpp_reader *pfile ATTRIBUTE_UNUSED)
82 {
83   /* Do nothing.  */
84 }
85
86 /* #pragma options align={mac68k|power|reset} */
87
88 void
89 darwin_pragma_options (cpp_reader *pfile ATTRIBUTE_UNUSED)
90 {
91   const char *arg;
92   tree t, x;
93
94   if (c_lex (&t) != CPP_NAME)
95     BAD ("malformed '#pragma options', ignoring");
96   arg = IDENTIFIER_POINTER (t);
97   if (strcmp (arg, "align"))
98     BAD ("malformed '#pragma options', ignoring");
99   if (c_lex (&t) != CPP_EQ)
100     BAD ("malformed '#pragma options', ignoring");
101   if (c_lex (&t) != CPP_NAME)
102     BAD ("malformed '#pragma options', ignoring");
103
104   if (c_lex (&x) != CPP_EOF)
105     warning ("junk at end of '#pragma options'");
106
107   arg = IDENTIFIER_POINTER (t);
108   if (!strcmp (arg, "mac68k"))
109     push_field_alignment (16);
110   else if (!strcmp (arg, "power"))
111     push_field_alignment (0);
112   else if (!strcmp (arg, "reset"))
113     pop_field_alignment ();
114   else
115     warning ("malformed '#pragma options align={mac68k|power|reset}', ignoring");
116 }
117
118 /* #pragma unused ([var {, var}*]) */
119
120 void
121 darwin_pragma_unused (cpp_reader *pfile ATTRIBUTE_UNUSED)
122 {
123   tree decl, x;
124   int tok;
125
126   if (c_lex (&x) != CPP_OPEN_PAREN)
127     BAD ("missing '(' after '#pragma unused', ignoring");
128
129   while (1)
130     {
131       tok = c_lex (&decl);
132       if (tok == CPP_NAME && decl)
133         {
134           tree local = lookup_name (decl);
135           if (local && (TREE_CODE (local) == PARM_DECL
136                         || TREE_CODE (local) == VAR_DECL))
137             TREE_USED (local) = 1;
138           tok = c_lex (&x);
139           if (tok != CPP_COMMA)
140             break;
141         }
142     }
143
144   if (tok != CPP_CLOSE_PAREN)
145     BAD ("missing ')' after '#pragma unused', ignoring");
146
147   if (c_lex (&x) != CPP_EOF)
148     warning ("junk at end of '#pragma unused'");
149 }