summaryrefslogtreecommitdiff
path: root/cpp/token2.h
blob: 62e69b1cea038a034dca94f07cde162971393dbc (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
131
132
133
134
135
136
137
138
139
/* C code produced by gperf version 2.7.1 (19981006 egcs) */
/* Command-line: gperf -aptTc -k1,3 -N is_ckey -H hash2 token2.tok  */

#define TOTAL_KEYWORDS 34
#define MIN_WORD_LENGTH 2
#define MAX_WORD_LENGTH 8
#define MIN_HASH_VALUE 2
#define MAX_HASH_VALUE 69
/* maximum key range = 68, duplicates = 0 */

#ifdef __GNUC__
__inline
#endif
static unsigned int
hash2 (str, len)
     register const char *str;
     register unsigned int len;
{
  static unsigned char asso_values[] =
    {
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
       5, 70, 70, 70, 70, 70,  0, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70,  0, 70,  5,  5, 10,
      10, 20, 20, 25, 70,  0, 70, 70, 50, 70,
       0, 15,  0, 70, 15,  0, 40, 20,  0,  0,
      70, 70, 10, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
      70, 70, 70, 70, 70, 70
    };
  register int hval = len;

  switch (hval)
    {
      default:
      case 3:
        hval += asso_values[(unsigned char)str[2]];
      case 2:
      case 1:
        hval += asso_values[(unsigned char)str[0]];
        break;
    }
  return hval;
}

#ifdef __GNUC__
__inline
#endif
struct token_trans *
is_ckey (str, len)
     register const char *str;
     register unsigned int len;
{
  static struct token_trans wordlist[] =
    {
      {""}, {""},
      {"if",		TK_IF},
      {""},
      {"void",		TK_VOID},
      {"while",		TK_WHILE},
      {"switch",		TK_SWITCH},
      {""},
      {"__LINE__",	TK_LINE},
      {""}, {""},
      {"static",		TK_STATIC},
      {"do",		TK_DO},
      {"__FILE__",	TK_FILE},
      {"case",		TK_CASE},
      {"const",		TK_CONST},
      {"sizeof",		TK_SIZEOF},
      {""},
      {"continue",	TK_CONTINUE},
      {"char",		TK_CHAR},
      {"short",		TK_SHORT},
      {"struct",		TK_STRUCT},
      {""}, {""},
      {"else",		TK_ELSE},
      {"union",		TK_UNION},
      {""}, {""},
      {"unsigned",	TK_UNSIGNED},
      {""},
      {"break",		TK_BREAK},
      {"signed",		TK_SIGNED},
      {""}, {""}, {""}, {""},
      {"double",		TK_DOUBLE},
      {"default",	TK_DEFAULT},
      {"for",		TK_FOR},
      {""},
      {"float",		TK_FLOAT},
      {""}, {""},
      {"int",		TK_INT},
      {"enum",		TK_ENUM},
      {""}, {""},
      {"typedef",	TK_TYPEDEF},
      {"register",	TK_REGISTER},
      {"auto",		TK_AUTO},
      {""}, {""}, {""}, {""},
      {"long",		TK_LONG},
      {""}, {""}, {""},
      {"volatile",	TK_VOLATILE},
      {""}, {""},
      {"return",		TK_RETURN},
      {""}, {""}, {""}, {""},
      {"extern",		TK_EXTERN},
      {""}, {""},
      {"goto",		TK_GOTO}
    };

  if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
    {
      register int key = hash2 (str, len);

      if (key <= MAX_HASH_VALUE && key >= 0)
        {
          register const char *s = wordlist[key].name;

          if (*str == *s && !strncmp (str + 1, s + 1, len - 1))
            return &wordlist[key];
        }
    }
  return 0;
}