GDB (API)
|
00001 /* Parser definitions for GDB. 00002 00003 Copyright (C) 1986-2013 Free Software Foundation, Inc. 00004 00005 Modified from expread.y by the Department of Computer Science at the 00006 State University of New York at Buffalo. 00007 00008 This file is part of GDB. 00009 00010 This program is free software; you can redistribute it and/or modify 00011 it under the terms of the GNU General Public License as published by 00012 the Free Software Foundation; either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00022 00023 #if !defined (PARSER_DEFS_H) 00024 #define PARSER_DEFS_H 1 00025 00026 #include "doublest.h" 00027 #include "vec.h" 00028 #include "expression.h" 00029 00030 struct block; 00031 00032 extern int parser_debug; 00033 00034 extern struct expression *expout; 00035 extern int expout_size; 00036 extern int expout_ptr; 00037 00038 #define parse_gdbarch (expout->gdbarch) 00039 #define parse_language (expout->language_defn) 00040 00041 /* If this is nonzero, this block is used as the lexical context 00042 for symbol names. */ 00043 00044 extern const struct block *expression_context_block; 00045 00046 /* If expression_context_block is non-zero, then this is the PC within 00047 the block that we want to evaluate expressions at. When debugging 00048 C or C++ code, we use this to find the exact line we're at, and 00049 then look up the macro definitions active at that point. */ 00050 extern CORE_ADDR expression_context_pc; 00051 00052 /* The innermost context required by the stack and register variables 00053 we've encountered so far. */ 00054 extern const struct block *innermost_block; 00055 00056 /* The block in which the most recently discovered symbol was found. 00057 FIXME: Should be declared along with lookup_symbol in symtab.h; is not 00058 related specifically to parsing. */ 00059 extern const struct block *block_found; 00060 00061 /* Number of arguments seen so far in innermost function call. */ 00062 extern int arglist_len; 00063 00064 /* A string token, either a char-string or bit-string. Char-strings are 00065 used, for example, for the names of symbols. */ 00066 00067 struct stoken 00068 { 00069 /* Pointer to first byte of char-string or first bit of bit-string. */ 00070 const char *ptr; 00071 /* Length of string in bytes for char-string or bits for bit-string. */ 00072 int length; 00073 }; 00074 00075 struct typed_stoken 00076 { 00077 /* A language-specific type field. */ 00078 int type; 00079 /* Pointer to first byte of char-string or first bit of bit-string. */ 00080 char *ptr; 00081 /* Length of string in bytes for char-string or bits for bit-string. */ 00082 int length; 00083 }; 00084 00085 struct stoken_vector 00086 { 00087 int len; 00088 struct typed_stoken *tokens; 00089 }; 00090 00091 struct ttype 00092 { 00093 struct stoken stoken; 00094 struct type *type; 00095 }; 00096 00097 struct symtoken 00098 { 00099 struct stoken stoken; 00100 struct symbol *sym; 00101 int is_a_field_of_this; 00102 }; 00103 00104 struct objc_class_str 00105 { 00106 struct stoken stoken; 00107 struct type *type; 00108 int class; 00109 }; 00110 00111 typedef struct type *type_ptr; 00112 DEF_VEC_P (type_ptr); 00113 00114 /* For parsing of complicated types. 00115 An array should be preceded in the list by the size of the array. */ 00116 enum type_pieces 00117 { 00118 tp_end = -1, 00119 tp_pointer, 00120 tp_reference, 00121 tp_array, 00122 tp_function, 00123 tp_function_with_arguments, 00124 tp_const, 00125 tp_volatile, 00126 tp_space_identifier, 00127 tp_type_stack 00128 }; 00129 /* The stack can contain either an enum type_pieces or an int. */ 00130 union type_stack_elt 00131 { 00132 enum type_pieces piece; 00133 int int_val; 00134 struct type_stack *stack_val; 00135 VEC (type_ptr) *typelist_val; 00136 }; 00137 00138 /* The type stack is an instance of this structure. */ 00139 00140 struct type_stack 00141 { 00142 /* Elements on the stack. */ 00143 union type_stack_elt *elements; 00144 /* Current stack depth. */ 00145 int depth; 00146 /* Allocated size of stack. */ 00147 int size; 00148 }; 00149 00150 /* Helper function to initialize the expout, expout_size, expout_ptr 00151 trio before it is used to store expression elements created during 00152 the parsing of an expression. INITIAL_SIZE is the initial size of 00153 the expout array. LANG is the language used to parse the expression. 00154 And GDBARCH is the gdbarch to use during parsing. */ 00155 00156 extern void initialize_expout (int, const struct language_defn *, 00157 struct gdbarch *); 00158 00159 /* Helper function that frees any unsed space in the expout array. 00160 It is generally used when the parser has just been parsed and 00161 created. */ 00162 00163 extern void reallocate_expout (void); 00164 00165 /* Reverse an expression from suffix form (in which it is constructed) 00166 to prefix form (in which we can conveniently print or execute it). 00167 Ordinarily this always returns -1. However, if EXPOUT_LAST_STRUCT 00168 is not -1 (i.e., we are trying to complete a field name), it will 00169 return the index of the subexpression which is the left-hand-side 00170 of the struct operation at EXPOUT_LAST_STRUCT. */ 00171 00172 extern int prefixify_expression (struct expression *expr); 00173 00174 extern void write_exp_elt_opcode (enum exp_opcode); 00175 00176 extern void write_exp_elt_sym (struct symbol *); 00177 00178 extern void write_exp_elt_longcst (LONGEST); 00179 00180 extern void write_exp_elt_dblcst (DOUBLEST); 00181 00182 extern void write_exp_elt_decfloatcst (gdb_byte *); 00183 00184 extern void write_exp_elt_type (struct type *); 00185 00186 extern void write_exp_elt_intern (struct internalvar *); 00187 00188 extern void write_exp_string (struct stoken); 00189 00190 void write_exp_string_vector (int type, struct stoken_vector *vec); 00191 00192 extern void write_exp_bitstring (struct stoken); 00193 00194 extern void write_exp_elt_block (const struct block *); 00195 00196 extern void write_exp_elt_objfile (struct objfile *objfile); 00197 00198 extern void write_exp_msymbol (struct bound_minimal_symbol); 00199 00200 extern void write_dollar_variable (struct stoken str); 00201 00202 extern void mark_struct_expression (void); 00203 00204 extern const char *find_template_name_end (const char *); 00205 00206 extern void start_arglist (void); 00207 00208 extern int end_arglist (void); 00209 00210 extern char *copy_name (struct stoken); 00211 00212 extern void insert_type (enum type_pieces); 00213 00214 extern void push_type (enum type_pieces); 00215 00216 extern void push_type_int (int); 00217 00218 extern void insert_type_address_space (char *); 00219 00220 extern enum type_pieces pop_type (void); 00221 00222 extern int pop_type_int (void); 00223 00224 extern struct type_stack *get_type_stack (void); 00225 00226 extern struct type_stack *append_type_stack (struct type_stack *to, 00227 struct type_stack *from); 00228 00229 extern void push_type_stack (struct type_stack *stack); 00230 00231 extern void type_stack_cleanup (void *arg); 00232 00233 extern void push_typelist (VEC (type_ptr) *typelist); 00234 00235 extern int length_of_subexp (struct expression *, int); 00236 00237 extern int dump_subexp (struct expression *, struct ui_file *, int); 00238 00239 extern int dump_subexp_body_standard (struct expression *, 00240 struct ui_file *, int); 00241 00242 extern void operator_length (const struct expression *, int, int *, int *); 00243 00244 extern void operator_length_standard (const struct expression *, int, int *, 00245 int *); 00246 00247 extern int operator_check_standard (struct expression *exp, int pos, 00248 int (*objfile_func) 00249 (struct objfile *objfile, void *data), 00250 void *data); 00251 00252 extern char *op_name_standard (enum exp_opcode); 00253 00254 extern struct type *follow_types (struct type *); 00255 00256 extern void null_post_parser (struct expression **, int); 00257 00258 extern int parse_float (const char *p, int len, DOUBLEST *d, 00259 const char **suffix); 00260 00261 extern int parse_c_float (struct gdbarch *gdbarch, const char *p, int len, 00262 DOUBLEST *d, struct type **t); 00263 00264 /* During parsing of a C expression, the pointer to the next character 00265 is in this variable. */ 00266 00267 extern const char *lexptr; 00268 00269 /* After a token has been recognized, this variable points to it. 00270 Currently used only for error reporting. */ 00271 extern const char *prev_lexptr; 00272 00273 /* Current depth in parentheses within the expression. */ 00274 00275 extern int paren_depth; 00276 00277 /* Nonzero means stop parsing on first comma (if not within parentheses). */ 00278 00279 extern int comma_terminates; 00280 00281 /* These codes indicate operator precedences for expression printing, 00282 least tightly binding first. */ 00283 /* Adding 1 to a precedence value is done for binary operators, 00284 on the operand which is more tightly bound, so that operators 00285 of equal precedence within that operand will get parentheses. */ 00286 /* PREC_HYPER and PREC_ABOVE_COMMA are not the precedence of any operator; 00287 they are used as the "surrounding precedence" to force 00288 various kinds of things to be parenthesized. */ 00289 enum precedence 00290 { 00291 PREC_NULL, PREC_COMMA, PREC_ABOVE_COMMA, PREC_ASSIGN, PREC_LOGICAL_OR, 00292 PREC_LOGICAL_AND, PREC_BITWISE_IOR, PREC_BITWISE_AND, PREC_BITWISE_XOR, 00293 PREC_EQUAL, PREC_ORDER, PREC_SHIFT, PREC_ADD, PREC_MUL, PREC_REPEAT, 00294 PREC_HYPER, PREC_PREFIX, PREC_SUFFIX, PREC_BUILTIN_FUNCTION 00295 }; 00296 00297 /* Table mapping opcodes into strings for printing operators 00298 and precedences of the operators. */ 00299 00300 struct op_print 00301 { 00302 char *string; 00303 enum exp_opcode opcode; 00304 /* Precedence of operator. These values are used only by comparisons. */ 00305 enum precedence precedence; 00306 00307 /* For a binary operator: 1 iff right associate. 00308 For a unary operator: 1 iff postfix. */ 00309 int right_assoc; 00310 }; 00311 00312 /* Information needed to print, prefixify, and evaluate expressions for 00313 a given language. */ 00314 00315 struct exp_descriptor 00316 { 00317 /* Print subexpression. */ 00318 void (*print_subexp) (struct expression *, int *, struct ui_file *, 00319 enum precedence); 00320 00321 /* Returns number of exp_elements needed to represent an operator and 00322 the number of subexpressions it takes. */ 00323 void (*operator_length) (const struct expression*, int, int*, int *); 00324 00325 /* Call TYPE_FUNC and OBJFILE_FUNC for any TYPE and OBJFILE found being 00326 referenced by the single operator of EXP at position POS. Operator 00327 parameters are located at positive (POS + number) offsets in EXP. 00328 The functions should never be called with NULL TYPE or NULL OBJFILE. 00329 Functions should get passed an arbitrary caller supplied DATA pointer. 00330 If any of the functions returns non-zero value then (any other) non-zero 00331 value should be immediately returned to the caller. Otherwise zero 00332 should be returned. */ 00333 int (*operator_check) (struct expression *exp, int pos, 00334 int (*objfile_func) (struct objfile *objfile, 00335 void *data), 00336 void *data); 00337 00338 /* Name of this operator for dumping purposes. 00339 The returned value should never be NULL, even if EXP_OPCODE is 00340 an unknown opcode (a string containing an image of the numeric 00341 value of the opcode can be returned, for instance). */ 00342 char *(*op_name) (enum exp_opcode); 00343 00344 /* Dump the rest of this (prefix) expression after the operator 00345 itself has been printed. See dump_subexp_body_standard in 00346 (expprint.c). */ 00347 int (*dump_subexp_body) (struct expression *, struct ui_file *, int); 00348 00349 /* Evaluate an expression. */ 00350 struct value *(*evaluate_exp) (struct type *, struct expression *, 00351 int *, enum noside); 00352 }; 00353 00354 00355 /* Default descriptor containing standard definitions of all 00356 elements. */ 00357 extern const struct exp_descriptor exp_descriptor_standard; 00358 00359 /* Functions used by language-specific extended operators to (recursively) 00360 print/dump subexpressions. */ 00361 00362 extern void print_subexp (struct expression *, int *, struct ui_file *, 00363 enum precedence); 00364 00365 extern void print_subexp_standard (struct expression *, int *, 00366 struct ui_file *, enum precedence); 00367 00368 /* Function used to avoid direct calls to fprintf 00369 in the code generated by the bison parser. */ 00370 00371 extern void parser_fprintf (FILE *, const char *, ...) ATTRIBUTE_PRINTF (2, 3); 00372 00373 extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile); 00374 00375 extern void mark_completion_tag (enum type_code, const char *ptr, 00376 int length); 00377 00378 #endif /* PARSER_DEFS_H */ 00379