/Users/deen/code/yugabyte-db/src/postgres/src/interfaces/ecpg/preproc/c_keywords.c
Line | Count | Source (jump to first uncovered line) |
1 | | /*------------------------------------------------------------------------- |
2 | | * |
3 | | * c_keywords.c |
4 | | * lexical token lookup for reserved words in postgres embedded SQL |
5 | | * |
6 | | * src/interfaces/ecpg/preproc/c_keywords.c |
7 | | * |
8 | | *------------------------------------------------------------------------- |
9 | | */ |
10 | | #include "postgres_fe.h" |
11 | | |
12 | | #include <ctype.h> |
13 | | |
14 | | #include "extern.h" |
15 | | #include "preproc.h" |
16 | | |
17 | | /* |
18 | | * List of (keyword-name, keyword-token-value) pairs. |
19 | | * |
20 | | * !!WARNING!!: This list must be sorted, because binary |
21 | | * search is used to locate entries. |
22 | | */ |
23 | | static const ScanKeyword ScanCKeywords[] = { |
24 | | /* name, value, category */ |
25 | | |
26 | | /* |
27 | | * category is not needed in ecpg, it is only here so we can share the |
28 | | * data structure with the backend |
29 | | */ |
30 | | {"VARCHAR", VARCHAR, 0}, |
31 | | {"auto", S_AUTO, 0}, |
32 | | {"bool", SQL_BOOL, 0}, |
33 | | {"char", CHAR_P, 0}, |
34 | | {"const", S_CONST, 0}, |
35 | | {"enum", ENUM_P, 0}, |
36 | | {"extern", S_EXTERN, 0}, |
37 | | {"float", FLOAT_P, 0}, |
38 | | {"hour", HOUR_P, 0}, |
39 | | {"int", INT_P, 0}, |
40 | | {"long", SQL_LONG, 0}, |
41 | | {"minute", MINUTE_P, 0}, |
42 | | {"month", MONTH_P, 0}, |
43 | | {"register", S_REGISTER, 0}, |
44 | | {"second", SECOND_P, 0}, |
45 | | {"short", SQL_SHORT, 0}, |
46 | | {"signed", SQL_SIGNED, 0}, |
47 | | {"static", S_STATIC, 0}, |
48 | | {"struct", SQL_STRUCT, 0}, |
49 | | {"to", TO, 0}, |
50 | | {"typedef", S_TYPEDEF, 0}, |
51 | | {"union", UNION, 0}, |
52 | | {"unsigned", SQL_UNSIGNED, 0}, |
53 | | {"varchar", VARCHAR, 0}, |
54 | | {"volatile", S_VOLATILE, 0}, |
55 | | {"year", YEAR_P, 0}, |
56 | | }; |
57 | | |
58 | | |
59 | | /* |
60 | | * Do a binary search using plain strcmp() comparison. This is much like |
61 | | * ScanKeywordLookup(), except we want case-sensitive matching. |
62 | | */ |
63 | | const ScanKeyword * |
64 | | ScanCKeywordLookup(const char *text) |
65 | 0 | { |
66 | 0 | const ScanKeyword *low = &ScanCKeywords[0]; |
67 | 0 | const ScanKeyword *high = &ScanCKeywords[lengthof(ScanCKeywords) - 1]; |
68 | |
|
69 | 0 | while (low <= high) |
70 | 0 | { |
71 | 0 | const ScanKeyword *middle; |
72 | 0 | int difference; |
73 | |
|
74 | 0 | middle = low + (high - low) / 2; |
75 | 0 | difference = strcmp(middle->name, text); |
76 | 0 | if (difference == 0) |
77 | 0 | return middle; |
78 | 0 | else if (difference < 0) |
79 | 0 | low = middle + 1; |
80 | 0 | else |
81 | 0 | high = middle - 1; |
82 | 0 | } |
83 | | |
84 | 0 | return NULL; |
85 | 0 | } |