OSDN Git Service

(expand_divmod): Always check result of emit_store_flag.
[pf3gnuchains/gcc-fork.git] / gcc / c-pragma.c
1 /* Handle #pragma, system V.4 style.  Supports #pragma weak and #pragma pack.
2    Copyright (C) 1992 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #include <stdio.h>
21 #include "config.h"
22 #include "tree.h"
23 #include "function.h"
24 #include "defaults.h"
25 #include "c-pragma.h"
26
27 #ifdef HANDLE_SYSV_PRAGMA
28
29 /* When structure field packing is in effect, this variable is the
30    number of bits to use as the maximum alignment.  When packing is not
31    in effect, this is zero. */
32
33 extern int maximum_field_alignment;
34
35 /* File used for outputting assembler code.  */
36 extern FILE *asm_out_file;
37
38 /* Handle one token of a pragma directive.  TOKEN is the
39    current token, and STRING is its printable form.  */
40
41 void
42 handle_pragma_token (string, token)
43      char *string;
44      tree token;
45 {
46   static enum pragma_state state = ps_start, type;
47   static char *name;
48   static char *value;
49   static int align;
50
51   if (string == 0)
52     {
53       if (type == ps_pack)
54         {
55           if (state == ps_right)
56             maximum_field_alignment = align * 8;
57           else
58             warning ("malformed `#pragma pack'");
59         }
60       else if (type == ps_weak)
61         {
62 #ifdef HANDLE_PRAGMA_WEAK
63           if (HANDLE_PRAGMA_WEAK)
64             handle_pragma_weak (state, name, value);
65
66 #endif /* HANDLE_PRAMA_WEAK */
67         }
68
69       type = state = ps_start;
70       return;
71     }
72
73   switch (state)
74     {
75     case ps_start:
76       if (token && TREE_CODE (token) == IDENTIFIER_NODE)
77         {
78           if (strcmp (IDENTIFIER_POINTER (token), "pack") == 0)
79             type = state = ps_pack;
80           else if (strcmp (IDENTIFIER_POINTER (token), "weak") == 0)
81             type = state = ps_weak;
82           else
83             type = state = ps_done;
84         }
85       else
86         type = state = ps_done;
87       break;
88
89     case ps_weak:
90       if (token && TREE_CODE (token) == IDENTIFIER_NODE)
91         {
92           name = IDENTIFIER_POINTER (token);
93           state = ps_name;
94         }
95       else
96         state = ps_bad;
97       break;
98
99     case ps_name:
100       state = (strcmp (string, "=") ? ps_bad : ps_equals);
101       break;
102
103     case ps_equals:
104       if (token && TREE_CODE (token) == IDENTIFIER_NODE)
105         {
106           value = IDENTIFIER_POINTER (token);
107           state = ps_value;
108         }
109       else
110         state = ps_bad;
111       break;
112
113     case ps_value:
114       state = ps_bad;
115       break;
116
117     case ps_pack:
118       if (strcmp (string, "(") == 0)
119         state = ps_left;
120       else
121         state = ps_bad;
122       break;
123
124     case ps_left:
125       if (token && TREE_CODE (token) == INTEGER_CST
126           && TREE_INT_CST_HIGH (token) == 0)
127         switch (TREE_INT_CST_LOW (token))
128           {
129           case 1:
130           case 2:
131           case 4:
132             align = TREE_INT_CST_LOW (token);
133             state = ps_align;
134             break;
135
136           default:
137             state = ps_bad;
138           }
139       else if (! token && strcmp (string, ")") == 0)
140         {
141           align = 0;
142           state = ps_right;
143         }
144       else
145         state = ps_bad;
146       break;
147
148     case ps_align:
149       if (strcmp (string, ")") == 0)
150         state = ps_right;
151       else
152         state = ps_bad;
153       break;
154
155     case ps_right:
156       state = ps_bad;
157       break;
158
159     case ps_bad:
160     case ps_done:
161       break;
162
163     default:
164       abort ();
165     }
166 }
167 #endif /* HANDLE_SYSV_PRAGMA */