source: trunk/third/gcc/c-pragma.c @ 11288

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