aboutsummaryrefslogtreecommitdiff
path: root/gcc/cppinit.c
blob: 32ebad998052909553ed8eee5b0d3e264064b1e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* CPP Library.
   Copyright (C) 1986, 87, 89, 92-98, 1999 Free Software Foundation, Inc.
   Contributed by Per Bothner, 1994-95.
   Based on CCCP program by Paul Rubin, June 1986
   Adapted to ANSI C, Richard Stallman, Jan 1987

This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */

/* This file will have more stuff in it eventually, but right now
   we just have one hack: we move all the is_* table initialization
   in here, and we can declare them const in cpplib.h, which improves
   code a bit. */

#include "config.h"
#include "system.h"

typedef unsigned char U_CHAR;

/* table to tell if char can be part of a C identifier.  */
U_CHAR is_idchar[256] = { 0 };
/* table to tell if char can be first char of a c identifier.  */
U_CHAR is_idstart[256] = { 0 };
/* table to tell if c is horizontal space.  */
U_CHAR is_hor_space[256] = { 0 };
/* table to tell if c is horizontal or vertical space.  */
U_CHAR is_space[256] = { 0 };
/* Table to handle trigraph conversion, which occurs before all other
   processing, everywhere in the file.  (This is necessary since one
   of the trigraphs encodes backslash.)  Note it's off by default.

	from	to	from	to	from	to
	?? =	#	?? )	]	?? !	|
	?? (	[	?? '	^	?? >	}
	?? /	\	?? <	{	?? -	~

   There is not a space between the ?? and the third char.  I put spaces
   there to avoid warnings when compiling this file. */
U_CHAR trigraph_table[256] = { 0 };

/* Initialize syntactic classifications of characters. */
void
initialize_char_syntax (dollar_in_ident)
     int dollar_in_ident;
{
  is_idstart['a'] = 1; is_idstart['b'] = 1; is_idstart['c'] = 1;
  is_idstart['d'] = 1; is_idstart['e'] = 1; is_idstart['f'] = 1;
  is_idstart['g'] = 1; is_idstart['h'] = 1; is_idstart['i'] = 1;
  is_idstart['j'] = 1; is_idstart['k'] = 1; is_idstart['l'] = 1;
  is_idstart['m'] = 1; is_idstart['n'] = 1; is_idstart['o'] = 1;
  is_idstart['p'] = 1; is_idstart['q'] = 1; is_idstart['r'] = 1;
  is_idstart['s'] = 1; is_idstart['t'] = 1; is_idstart['u'] = 1;
  is_idstart['v'] = 1; is_idstart['w'] = 1; is_idstart['x'] = 1;
  is_idstart['y'] = 1; is_idstart['z'] = 1;

  is_idstart['A'] = 1; is_idstart['B'] = 1; is_idstart['C'] = 1;
  is_idstart['D'] = 1; is_idstart['E'] = 1; is_idstart['F'] = 1;
  is_idstart['G'] = 1; is_idstart['H'] = 1; is_idstart['I'] = 1;
  is_idstart['J'] = 1; is_idstart['K'] = 1; is_idstart['L'] = 1;
  is_idstart['M'] = 1; is_idstart['N'] = 1; is_idstart['O'] = 1;
  is_idstart['P'] = 1; is_idstart['Q'] = 1; is_idstart['R'] = 1;
  is_idstart['S'] = 1; is_idstart['T'] = 1; is_idstart['U'] = 1;
  is_idstart['V'] = 1; is_idstart['W'] = 1; is_idstart['X'] = 1;
  is_idstart['Y'] = 1; is_idstart['Z'] = 1;

  is_idstart['_'] = 1;

  is_idchar['a'] = 1; is_idchar['b'] = 1; is_idchar['c'] = 1;
  is_idchar['d'] = 1; is_idchar['e'] = 1; is_idchar['f'] = 1;
  is_idchar['g'] = 1; is_idchar['h'] = 1; is_idchar['i'] = 1;
  is_idchar['j'] = 1; is_idchar['k'] = 1; is_idchar['l'] = 1;
  is_idchar['m'] = 1; is_idchar['n'] = 1; is_idchar['o'] = 1;
  is_idchar['p'] = 1;  is_idchar['q'] = 1; is_idchar['r'] = 1;
  is_idchar['s'] = 1; is_idchar['t'] = 1;  is_idchar['u'] = 1;
  is_idchar['v'] = 1; is_idchar['w'] = 1; is_idchar['x'] = 1;
  is_idchar['y'] = 1; is_idchar['z'] = 1;

  is_idchar['A'] = 1; is_idchar['B'] = 1; is_idchar['C'] = 1;
  is_idchar['D'] = 1; is_idchar['E'] = 1; is_idchar['F'] = 1;
  is_idchar['G'] = 1; is_idchar['H'] = 1; is_idchar['I'] = 1;
  is_idchar['J'] = 1; is_idchar['K'] = 1; is_idchar['L'] = 1;
  is_idchar['M'] = 1; is_idchar['N'] = 1; is_idchar['O'] = 1;
  is_idchar['P'] = 1; is_idchar['Q'] = 1; is_idchar['R'] = 1;
  is_idchar['S'] = 1; is_idchar['T'] = 1;  is_idchar['U'] = 1;
  is_idchar['V'] = 1; is_idchar['W'] = 1; is_idchar['X'] = 1;
  is_idchar['Y'] = 1; is_idchar['Z'] = 1;

  is_idchar['1'] = 1; is_idchar['2'] = 1; is_idchar['3'] = 1;
  is_idchar['4'] = 1; is_idchar['5'] = 1; is_idchar['6'] = 1;
  is_idchar['7'] = 1; is_idchar['8'] = 1; is_idchar['9'] = 1;
  is_idchar['0'] = 1;

  is_idchar['_']  = 1;

  /* These will be reset later if -$ is in effect. */
  is_idchar['$']  = dollar_in_ident;
  is_idstart['$'] = dollar_in_ident;

  /* horizontal space table */
  is_hor_space[' '] = 1;
  is_hor_space['\t'] = 1;
  is_hor_space['\v'] = 1;
  is_hor_space['\f'] = 1;
  is_hor_space['\r'] = 1;

  is_space[' '] = 1;
  is_space['\t'] = 1;
  is_space['\v'] = 1;
  is_space['\f'] = 1;
  is_space['\n'] = 1;
  is_space['\r'] = 1;

  /* trigraph conversion */
  trigraph_table['='] = '#';  trigraph_table[')'] = ']';
  trigraph_table['!'] = '|';  trigraph_table['('] = '[';
  trigraph_table['\''] = '^'; trigraph_table['>'] = '}';
  trigraph_table['/'] = '\\'; trigraph_table['<'] = '{';
  trigraph_table['-'] = '~';
}