David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
Mark Slee | e9ce01c | 2007-05-16 02:29:53 +0000 | [diff] [blame] | 19 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 20 | #ifndef T_GLOBALS_H |
| 21 | #define T_GLOBALS_H |
| 22 | |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 23 | #include <set> |
| 24 | #include <queue> |
| 25 | #include <stack> |
| 26 | #include <vector> |
| 27 | #include <string> |
| 28 | |
| 29 | /** |
| 30 | * This module contains all the global variables (slap on the wrist) that are |
| 31 | * shared throughout the program. The reason for this is to facilitate simple |
| 32 | * interaction between the parser and the rest of the program. Before calling |
| 33 | * yyparse(), the main.cc program will make necessary adjustments to these |
| 34 | * global variables such that the parser does the right thing and puts entries |
| 35 | * into the right containers, etc. |
| 36 | * |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 37 | */ |
| 38 | |
| 39 | /** |
| 40 | * Hooray for forward declaration of types! |
| 41 | */ |
| 42 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 43 | class t_program; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 44 | class t_scope; |
| 45 | class t_type; |
| 46 | |
| 47 | /** |
| 48 | * Parsing mode, two passes up in this gin rummy! |
| 49 | */ |
| 50 | |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame^] | 51 | enum PARSE_MODE { INCLUDES = 1, PROGRAM = 2 }; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 52 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 53 | /** |
Bryan Duxbury | a145b4d | 2009-04-03 17:29:25 +0000 | [diff] [blame] | 54 | * Strictness level |
| 55 | */ |
| 56 | extern int g_strict; |
| 57 | |
| 58 | /** |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 59 | * The master program parse tree. This is accessed from within the parser code |
| 60 | * to build up the program elements. |
| 61 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 62 | extern t_program* g_program; |
| 63 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 64 | /** |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 65 | * Global types for the parser to be able to reference |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 66 | */ |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 67 | |
| 68 | extern t_type* g_type_void; |
| 69 | extern t_type* g_type_string; |
Mark Slee | 8d725a2 | 2007-04-13 01:57:12 +0000 | [diff] [blame] | 70 | extern t_type* g_type_binary; |
Mark Slee | b6200d8 | 2007-01-19 19:14:36 +0000 | [diff] [blame] | 71 | extern t_type* g_type_slist; |
Mark Slee | f0712dc | 2006-10-25 19:03:57 +0000 | [diff] [blame] | 72 | extern t_type* g_type_bool; |
| 73 | extern t_type* g_type_byte; |
| 74 | extern t_type* g_type_i16; |
| 75 | extern t_type* g_type_i32; |
| 76 | extern t_type* g_type_i64; |
| 77 | extern t_type* g_type_double; |
| 78 | |
| 79 | /** |
| 80 | * The scope that we are currently parsing into |
| 81 | */ |
| 82 | extern t_scope* g_scope; |
| 83 | |
| 84 | /** |
| 85 | * The parent scope to also load symbols into |
| 86 | */ |
| 87 | extern t_scope* g_parent_scope; |
| 88 | |
| 89 | /** |
| 90 | * The prefix for the parent scope entries |
| 91 | */ |
| 92 | extern std::string g_parent_prefix; |
| 93 | |
| 94 | /** |
| 95 | * The parsing pass that we are on. We do different things on each pass. |
| 96 | */ |
| 97 | extern PARSE_MODE g_parse_mode; |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 98 | |
Mark Slee | f5377b3 | 2006-10-10 01:42:59 +0000 | [diff] [blame] | 99 | /** |
| 100 | * Global time string, used in formatting error messages etc. |
| 101 | */ |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 102 | extern char* g_time_str; |
| 103 | |
David Reiss | cbd4bac | 2007-08-14 17:12:33 +0000 | [diff] [blame] | 104 | /** |
| 105 | * The last parsed doctext comment. |
| 106 | */ |
| 107 | extern char* g_doctext; |
| 108 | |
| 109 | /** |
| 110 | * The location of the last parsed doctext comment. |
| 111 | */ |
| 112 | extern int g_doctext_lineno; |
| 113 | |
Bryan Duxbury | c7206a4 | 2011-08-17 23:17:04 +0000 | [diff] [blame] | 114 | /** |
Jens Geyer | e8379b5 | 2014-01-25 00:59:45 +0100 | [diff] [blame] | 115 | * Status of program level doctext candidate |
| 116 | */ |
| 117 | enum PROGDOCTEXT_STATUS { |
| 118 | INVALID = 0, |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame^] | 119 | STILL_CANDIDATE = 1, // the text may or may not be the program doctext |
| 120 | ALREADY_PROCESSED = 2, // doctext has been used and is no longer available |
| 121 | ABSOLUTELY_SURE = 3, // this is the program doctext |
| 122 | NO_PROGRAM_DOCTEXT = 4 // there is no program doctext |
Jens Geyer | e8379b5 | 2014-01-25 00:59:45 +0100 | [diff] [blame] | 123 | }; |
| 124 | |
Jens Geyer | e8379b5 | 2014-01-25 00:59:45 +0100 | [diff] [blame] | 125 | /** |
| 126 | * The program level doctext. Stored seperately to make parsing easier. |
| 127 | */ |
| 128 | extern char* g_program_doctext_candidate; |
Konrad Grochowski | 16a23a6 | 2014-11-13 15:33:38 +0100 | [diff] [blame^] | 129 | extern int g_program_doctext_lineno; |
| 130 | extern PROGDOCTEXT_STATUS g_program_doctext_status; |
Jens Geyer | e8379b5 | 2014-01-25 00:59:45 +0100 | [diff] [blame] | 131 | |
| 132 | /** |
Bryan Duxbury | c7206a4 | 2011-08-17 23:17:04 +0000 | [diff] [blame] | 133 | * Whether or not negative field keys are accepted. |
| 134 | * |
| 135 | * When a field does not have a user-specified key, thrift automatically |
| 136 | * assigns a negative value. However, this is fragile since changes to the |
| 137 | * file may unintentionally change the key numbering, resulting in a new |
| 138 | * protocol that is not backwards compatible. |
| 139 | * |
| 140 | * When g_allow_neg_field_keys is enabled, users can explicitly specify |
| 141 | * negative keys. This way they can write a .thrift file with explicitly |
| 142 | * specified keys that is still backwards compatible with older .thrift files |
| 143 | * that did not specify key values. |
| 144 | */ |
| 145 | extern int g_allow_neg_field_keys; |
| 146 | |
Roger Meier | 887ff75 | 2011-08-19 11:25:39 +0000 | [diff] [blame] | 147 | /** |
| 148 | * Whether or not 64-bit constants will generate a warning. |
| 149 | * |
| 150 | * Some languages don't support 64-bit constants, but many do, so we can |
| 151 | * suppress this warning for projects that don't use any non-64-bit-safe |
| 152 | * languages. |
| 153 | */ |
| 154 | extern int g_allow_64bit_consts; |
| 155 | |
Mark Slee | 3198572 | 2006-05-24 21:45:31 +0000 | [diff] [blame] | 156 | #endif |