15796c8dcSSimon Schubert /* Parser definitions for GDB. 25796c8dcSSimon Schubert 3*ef5ccd6cSJohn Marino Copyright (C) 1986-2013 Free Software Foundation, Inc. 45796c8dcSSimon Schubert 55796c8dcSSimon Schubert Modified from expread.y by the Department of Computer Science at the 65796c8dcSSimon Schubert State University of New York at Buffalo. 75796c8dcSSimon Schubert 85796c8dcSSimon Schubert This file is part of GDB. 95796c8dcSSimon Schubert 105796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 115796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 125796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 135796c8dcSSimon Schubert (at your option) any later version. 145796c8dcSSimon Schubert 155796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 165796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 175796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 185796c8dcSSimon Schubert GNU General Public License for more details. 195796c8dcSSimon Schubert 205796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 215796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 225796c8dcSSimon Schubert 235796c8dcSSimon Schubert #if !defined (PARSER_DEFS_H) 245796c8dcSSimon Schubert #define PARSER_DEFS_H 1 255796c8dcSSimon Schubert 265796c8dcSSimon Schubert #include "doublest.h" 27*ef5ccd6cSJohn Marino #include "vec.h" 285796c8dcSSimon Schubert 295796c8dcSSimon Schubert struct block; 305796c8dcSSimon Schubert 31cf7f2e2dSJohn Marino extern int parser_debug; 32cf7f2e2dSJohn Marino 335796c8dcSSimon Schubert extern struct expression *expout; 345796c8dcSSimon Schubert extern int expout_size; 355796c8dcSSimon Schubert extern int expout_ptr; 365796c8dcSSimon Schubert 375796c8dcSSimon Schubert #define parse_gdbarch (expout->gdbarch) 385796c8dcSSimon Schubert #define parse_language (expout->language_defn) 395796c8dcSSimon Schubert 405796c8dcSSimon Schubert /* If this is nonzero, this block is used as the lexical context 415796c8dcSSimon Schubert for symbol names. */ 425796c8dcSSimon Schubert 43*ef5ccd6cSJohn Marino extern const struct block *expression_context_block; 445796c8dcSSimon Schubert 455796c8dcSSimon Schubert /* If expression_context_block is non-zero, then this is the PC within 465796c8dcSSimon Schubert the block that we want to evaluate expressions at. When debugging 475796c8dcSSimon Schubert C or C++ code, we use this to find the exact line we're at, and 485796c8dcSSimon Schubert then look up the macro definitions active at that point. */ 495796c8dcSSimon Schubert extern CORE_ADDR expression_context_pc; 505796c8dcSSimon Schubert 515796c8dcSSimon Schubert /* The innermost context required by the stack and register variables 525796c8dcSSimon Schubert we've encountered so far. */ 53*ef5ccd6cSJohn Marino extern const struct block *innermost_block; 545796c8dcSSimon Schubert 555796c8dcSSimon Schubert /* The block in which the most recently discovered symbol was found. 565796c8dcSSimon Schubert FIXME: Should be declared along with lookup_symbol in symtab.h; is not 575796c8dcSSimon Schubert related specifically to parsing. */ 58*ef5ccd6cSJohn Marino extern const struct block *block_found; 595796c8dcSSimon Schubert 605796c8dcSSimon Schubert /* Number of arguments seen so far in innermost function call. */ 615796c8dcSSimon Schubert extern int arglist_len; 625796c8dcSSimon Schubert 635796c8dcSSimon Schubert /* A string token, either a char-string or bit-string. Char-strings are 645796c8dcSSimon Schubert used, for example, for the names of symbols. */ 655796c8dcSSimon Schubert 665796c8dcSSimon Schubert struct stoken 675796c8dcSSimon Schubert { 68c50c785cSJohn Marino /* Pointer to first byte of char-string or first bit of bit-string. */ 695796c8dcSSimon Schubert char *ptr; 70c50c785cSJohn Marino /* Length of string in bytes for char-string or bits for bit-string. */ 715796c8dcSSimon Schubert int length; 725796c8dcSSimon Schubert }; 735796c8dcSSimon Schubert 745796c8dcSSimon Schubert struct typed_stoken 755796c8dcSSimon Schubert { 765796c8dcSSimon Schubert /* A language-specific type field. */ 775796c8dcSSimon Schubert int type; 78c50c785cSJohn Marino /* Pointer to first byte of char-string or first bit of bit-string. */ 795796c8dcSSimon Schubert char *ptr; 80c50c785cSJohn Marino /* Length of string in bytes for char-string or bits for bit-string. */ 815796c8dcSSimon Schubert int length; 825796c8dcSSimon Schubert }; 835796c8dcSSimon Schubert 845796c8dcSSimon Schubert struct stoken_vector 855796c8dcSSimon Schubert { 865796c8dcSSimon Schubert int len; 875796c8dcSSimon Schubert struct typed_stoken *tokens; 885796c8dcSSimon Schubert }; 895796c8dcSSimon Schubert 905796c8dcSSimon Schubert struct ttype 915796c8dcSSimon Schubert { 925796c8dcSSimon Schubert struct stoken stoken; 935796c8dcSSimon Schubert struct type *type; 945796c8dcSSimon Schubert }; 955796c8dcSSimon Schubert 965796c8dcSSimon Schubert struct symtoken 975796c8dcSSimon Schubert { 985796c8dcSSimon Schubert struct stoken stoken; 995796c8dcSSimon Schubert struct symbol *sym; 1005796c8dcSSimon Schubert int is_a_field_of_this; 1015796c8dcSSimon Schubert }; 1025796c8dcSSimon Schubert 1035796c8dcSSimon Schubert struct objc_class_str 1045796c8dcSSimon Schubert { 1055796c8dcSSimon Schubert struct stoken stoken; 1065796c8dcSSimon Schubert struct type *type; 1075796c8dcSSimon Schubert int class; 1085796c8dcSSimon Schubert }; 1095796c8dcSSimon Schubert 110*ef5ccd6cSJohn Marino typedef struct type *type_ptr; 111*ef5ccd6cSJohn Marino DEF_VEC_P (type_ptr); 1125796c8dcSSimon Schubert 1135796c8dcSSimon Schubert /* For parsing of complicated types. 1145796c8dcSSimon Schubert An array should be preceded in the list by the size of the array. */ 1155796c8dcSSimon Schubert enum type_pieces 1165796c8dcSSimon Schubert { 1175796c8dcSSimon Schubert tp_end = -1, 1185796c8dcSSimon Schubert tp_pointer, 1195796c8dcSSimon Schubert tp_reference, 1205796c8dcSSimon Schubert tp_array, 1215796c8dcSSimon Schubert tp_function, 122*ef5ccd6cSJohn Marino tp_function_with_arguments, 1235796c8dcSSimon Schubert tp_const, 1245796c8dcSSimon Schubert tp_volatile, 125*ef5ccd6cSJohn Marino tp_space_identifier, 126*ef5ccd6cSJohn Marino tp_type_stack 1275796c8dcSSimon Schubert }; 1285796c8dcSSimon Schubert /* The stack can contain either an enum type_pieces or an int. */ 1295796c8dcSSimon Schubert union type_stack_elt 1305796c8dcSSimon Schubert { 1315796c8dcSSimon Schubert enum type_pieces piece; 1325796c8dcSSimon Schubert int int_val; 133*ef5ccd6cSJohn Marino struct type_stack *stack_val; 134*ef5ccd6cSJohn Marino VEC (type_ptr) *typelist_val; 1355796c8dcSSimon Schubert }; 136*ef5ccd6cSJohn Marino 137*ef5ccd6cSJohn Marino /* The type stack is an instance of this structure. */ 138*ef5ccd6cSJohn Marino 139*ef5ccd6cSJohn Marino struct type_stack 140*ef5ccd6cSJohn Marino { 141*ef5ccd6cSJohn Marino /* Elements on the stack. */ 142*ef5ccd6cSJohn Marino union type_stack_elt *elements; 143*ef5ccd6cSJohn Marino /* Current stack depth. */ 144*ef5ccd6cSJohn Marino int depth; 145*ef5ccd6cSJohn Marino /* Allocated size of stack. */ 146*ef5ccd6cSJohn Marino int size; 147*ef5ccd6cSJohn Marino }; 148*ef5ccd6cSJohn Marino 149*ef5ccd6cSJohn Marino /* Helper function to initialize the expout, expout_size, expout_ptr 150*ef5ccd6cSJohn Marino trio before it is used to store expression elements created during 151*ef5ccd6cSJohn Marino the parsing of an expression. INITIAL_SIZE is the initial size of 152*ef5ccd6cSJohn Marino the expout array. LANG is the language used to parse the expression. 153*ef5ccd6cSJohn Marino And GDBARCH is the gdbarch to use during parsing. */ 154*ef5ccd6cSJohn Marino 155*ef5ccd6cSJohn Marino extern void initialize_expout (int, const struct language_defn *, 156*ef5ccd6cSJohn Marino struct gdbarch *); 157*ef5ccd6cSJohn Marino 158*ef5ccd6cSJohn Marino /* Helper function that frees any unsed space in the expout array. 159*ef5ccd6cSJohn Marino It is generally used when the parser has just been parsed and 160*ef5ccd6cSJohn Marino created. */ 161*ef5ccd6cSJohn Marino 162*ef5ccd6cSJohn Marino extern void reallocate_expout (void); 163*ef5ccd6cSJohn Marino 164*ef5ccd6cSJohn Marino /* Reverse an expression from suffix form (in which it is constructed) 165*ef5ccd6cSJohn Marino to prefix form (in which we can conveniently print or execute it). 166*ef5ccd6cSJohn Marino Ordinarily this always returns -1. However, if EXPOUT_LAST_STRUCT 167*ef5ccd6cSJohn Marino is not -1 (i.e., we are trying to complete a field name), it will 168*ef5ccd6cSJohn Marino return the index of the subexpression which is the left-hand-side 169*ef5ccd6cSJohn Marino of the struct operation at EXPOUT_LAST_STRUCT. */ 170*ef5ccd6cSJohn Marino 171*ef5ccd6cSJohn Marino extern int prefixify_expression (struct expression *expr); 1725796c8dcSSimon Schubert 1735796c8dcSSimon Schubert extern void write_exp_elt_opcode (enum exp_opcode); 1745796c8dcSSimon Schubert 1755796c8dcSSimon Schubert extern void write_exp_elt_sym (struct symbol *); 1765796c8dcSSimon Schubert 1775796c8dcSSimon Schubert extern void write_exp_elt_longcst (LONGEST); 1785796c8dcSSimon Schubert 1795796c8dcSSimon Schubert extern void write_exp_elt_dblcst (DOUBLEST); 1805796c8dcSSimon Schubert 1815796c8dcSSimon Schubert extern void write_exp_elt_decfloatcst (gdb_byte *); 1825796c8dcSSimon Schubert 1835796c8dcSSimon Schubert extern void write_exp_elt_type (struct type *); 1845796c8dcSSimon Schubert 1855796c8dcSSimon Schubert extern void write_exp_elt_intern (struct internalvar *); 1865796c8dcSSimon Schubert 1875796c8dcSSimon Schubert extern void write_exp_string (struct stoken); 1885796c8dcSSimon Schubert 1895796c8dcSSimon Schubert void write_exp_string_vector (int type, struct stoken_vector *vec); 1905796c8dcSSimon Schubert 1915796c8dcSSimon Schubert extern void write_exp_bitstring (struct stoken); 1925796c8dcSSimon Schubert 193*ef5ccd6cSJohn Marino extern void write_exp_elt_block (const struct block *); 1945796c8dcSSimon Schubert 1955796c8dcSSimon Schubert extern void write_exp_elt_objfile (struct objfile *objfile); 1965796c8dcSSimon Schubert 1975796c8dcSSimon Schubert extern void write_exp_msymbol (struct minimal_symbol *); 1985796c8dcSSimon Schubert 1995796c8dcSSimon Schubert extern void write_dollar_variable (struct stoken str); 2005796c8dcSSimon Schubert 2015796c8dcSSimon Schubert extern void mark_struct_expression (void); 2025796c8dcSSimon Schubert 2035796c8dcSSimon Schubert extern char *find_template_name_end (char *); 2045796c8dcSSimon Schubert 2055796c8dcSSimon Schubert extern void start_arglist (void); 2065796c8dcSSimon Schubert 2075796c8dcSSimon Schubert extern int end_arglist (void); 2085796c8dcSSimon Schubert 2095796c8dcSSimon Schubert extern char *copy_name (struct stoken); 2105796c8dcSSimon Schubert 211*ef5ccd6cSJohn Marino extern void insert_type (enum type_pieces); 212*ef5ccd6cSJohn Marino 2135796c8dcSSimon Schubert extern void push_type (enum type_pieces); 2145796c8dcSSimon Schubert 2155796c8dcSSimon Schubert extern void push_type_int (int); 2165796c8dcSSimon Schubert 217*ef5ccd6cSJohn Marino extern void insert_type_address_space (char *); 2185796c8dcSSimon Schubert 2195796c8dcSSimon Schubert extern enum type_pieces pop_type (void); 2205796c8dcSSimon Schubert 2215796c8dcSSimon Schubert extern int pop_type_int (void); 2225796c8dcSSimon Schubert 223*ef5ccd6cSJohn Marino extern struct type_stack *get_type_stack (void); 224*ef5ccd6cSJohn Marino 225*ef5ccd6cSJohn Marino extern struct type_stack *append_type_stack (struct type_stack *to, 226*ef5ccd6cSJohn Marino struct type_stack *from); 227*ef5ccd6cSJohn Marino 228*ef5ccd6cSJohn Marino extern void push_type_stack (struct type_stack *stack); 229*ef5ccd6cSJohn Marino 230*ef5ccd6cSJohn Marino extern void type_stack_cleanup (void *arg); 231*ef5ccd6cSJohn Marino 232*ef5ccd6cSJohn Marino extern void push_typelist (VEC (type_ptr) *typelist); 233*ef5ccd6cSJohn Marino 2345796c8dcSSimon Schubert extern int length_of_subexp (struct expression *, int); 2355796c8dcSSimon Schubert 2365796c8dcSSimon Schubert extern int dump_subexp (struct expression *, struct ui_file *, int); 2375796c8dcSSimon Schubert 2385796c8dcSSimon Schubert extern int dump_subexp_body_standard (struct expression *, 2395796c8dcSSimon Schubert struct ui_file *, int); 2405796c8dcSSimon Schubert 241cf7f2e2dSJohn Marino extern void operator_length (const struct expression *, int, int *, int *); 2425796c8dcSSimon Schubert 243cf7f2e2dSJohn Marino extern void operator_length_standard (const struct expression *, int, int *, 244cf7f2e2dSJohn Marino int *); 245cf7f2e2dSJohn Marino 246cf7f2e2dSJohn Marino extern int operator_check_standard (struct expression *exp, int pos, 247cf7f2e2dSJohn Marino int (*objfile_func) 248cf7f2e2dSJohn Marino (struct objfile *objfile, void *data), 249cf7f2e2dSJohn Marino void *data); 2505796c8dcSSimon Schubert 2515796c8dcSSimon Schubert extern char *op_name_standard (enum exp_opcode); 2525796c8dcSSimon Schubert 2535796c8dcSSimon Schubert extern struct type *follow_types (struct type *); 2545796c8dcSSimon Schubert 2555796c8dcSSimon Schubert extern void null_post_parser (struct expression **, int); 2565796c8dcSSimon Schubert 257c50c785cSJohn Marino extern int parse_float (const char *p, int len, DOUBLEST *d, 258c50c785cSJohn Marino const char **suffix); 259c50c785cSJohn Marino 260c50c785cSJohn Marino extern int parse_c_float (struct gdbarch *gdbarch, const char *p, int len, 261c50c785cSJohn Marino DOUBLEST *d, struct type **t); 262c50c785cSJohn Marino 2635796c8dcSSimon Schubert /* During parsing of a C expression, the pointer to the next character 2645796c8dcSSimon Schubert is in this variable. */ 2655796c8dcSSimon Schubert 2665796c8dcSSimon Schubert extern char *lexptr; 2675796c8dcSSimon Schubert 2685796c8dcSSimon Schubert /* After a token has been recognized, this variable points to it. 2695796c8dcSSimon Schubert Currently used only for error reporting. */ 2705796c8dcSSimon Schubert extern char *prev_lexptr; 2715796c8dcSSimon Schubert 2725796c8dcSSimon Schubert /* Current depth in parentheses within the expression. */ 2735796c8dcSSimon Schubert 2745796c8dcSSimon Schubert extern int paren_depth; 2755796c8dcSSimon Schubert 2765796c8dcSSimon Schubert /* Nonzero means stop parsing on first comma (if not within parentheses). */ 2775796c8dcSSimon Schubert 2785796c8dcSSimon Schubert extern int comma_terminates; 2795796c8dcSSimon Schubert 2805796c8dcSSimon Schubert /* These codes indicate operator precedences for expression printing, 2815796c8dcSSimon Schubert least tightly binding first. */ 2825796c8dcSSimon Schubert /* Adding 1 to a precedence value is done for binary operators, 2835796c8dcSSimon Schubert on the operand which is more tightly bound, so that operators 2845796c8dcSSimon Schubert of equal precedence within that operand will get parentheses. */ 2855796c8dcSSimon Schubert /* PREC_HYPER and PREC_ABOVE_COMMA are not the precedence of any operator; 2865796c8dcSSimon Schubert they are used as the "surrounding precedence" to force 2875796c8dcSSimon Schubert various kinds of things to be parenthesized. */ 2885796c8dcSSimon Schubert enum precedence 2895796c8dcSSimon Schubert { 2905796c8dcSSimon Schubert PREC_NULL, PREC_COMMA, PREC_ABOVE_COMMA, PREC_ASSIGN, PREC_LOGICAL_OR, 2915796c8dcSSimon Schubert PREC_LOGICAL_AND, PREC_BITWISE_IOR, PREC_BITWISE_AND, PREC_BITWISE_XOR, 2925796c8dcSSimon Schubert PREC_EQUAL, PREC_ORDER, PREC_SHIFT, PREC_ADD, PREC_MUL, PREC_REPEAT, 2935796c8dcSSimon Schubert PREC_HYPER, PREC_PREFIX, PREC_SUFFIX, PREC_BUILTIN_FUNCTION 2945796c8dcSSimon Schubert }; 2955796c8dcSSimon Schubert 2965796c8dcSSimon Schubert /* Table mapping opcodes into strings for printing operators 2975796c8dcSSimon Schubert and precedences of the operators. */ 2985796c8dcSSimon Schubert 2995796c8dcSSimon Schubert struct op_print 3005796c8dcSSimon Schubert { 3015796c8dcSSimon Schubert char *string; 3025796c8dcSSimon Schubert enum exp_opcode opcode; 3035796c8dcSSimon Schubert /* Precedence of operator. These values are used only by comparisons. */ 3045796c8dcSSimon Schubert enum precedence precedence; 3055796c8dcSSimon Schubert 3065796c8dcSSimon Schubert /* For a binary operator: 1 iff right associate. 3075796c8dcSSimon Schubert For a unary operator: 1 iff postfix. */ 3085796c8dcSSimon Schubert int right_assoc; 3095796c8dcSSimon Schubert }; 3105796c8dcSSimon Schubert 3115796c8dcSSimon Schubert /* Information needed to print, prefixify, and evaluate expressions for 3125796c8dcSSimon Schubert a given language. */ 3135796c8dcSSimon Schubert 3145796c8dcSSimon Schubert struct exp_descriptor 3155796c8dcSSimon Schubert { 3165796c8dcSSimon Schubert /* Print subexpression. */ 3175796c8dcSSimon Schubert void (*print_subexp) (struct expression *, int *, struct ui_file *, 3185796c8dcSSimon Schubert enum precedence); 3195796c8dcSSimon Schubert 3205796c8dcSSimon Schubert /* Returns number of exp_elements needed to represent an operator and 3215796c8dcSSimon Schubert the number of subexpressions it takes. */ 322cf7f2e2dSJohn Marino void (*operator_length) (const struct expression*, int, int*, int *); 323cf7f2e2dSJohn Marino 324cf7f2e2dSJohn Marino /* Call TYPE_FUNC and OBJFILE_FUNC for any TYPE and OBJFILE found being 325cf7f2e2dSJohn Marino referenced by the single operator of EXP at position POS. Operator 326cf7f2e2dSJohn Marino parameters are located at positive (POS + number) offsets in EXP. 327cf7f2e2dSJohn Marino The functions should never be called with NULL TYPE or NULL OBJFILE. 328cf7f2e2dSJohn Marino Functions should get passed an arbitrary caller supplied DATA pointer. 329cf7f2e2dSJohn Marino If any of the functions returns non-zero value then (any other) non-zero 330cf7f2e2dSJohn Marino value should be immediately returned to the caller. Otherwise zero 331cf7f2e2dSJohn Marino should be returned. */ 332cf7f2e2dSJohn Marino int (*operator_check) (struct expression *exp, int pos, 333cf7f2e2dSJohn Marino int (*objfile_func) (struct objfile *objfile, 334cf7f2e2dSJohn Marino void *data), 335cf7f2e2dSJohn Marino void *data); 3365796c8dcSSimon Schubert 337*ef5ccd6cSJohn Marino /* Name of this operator for dumping purposes. 338*ef5ccd6cSJohn Marino The returned value should never be NULL, even if EXP_OPCODE is 339*ef5ccd6cSJohn Marino an unknown opcode (a string containing an image of the numeric 340*ef5ccd6cSJohn Marino value of the opcode can be returned, for instance). */ 3415796c8dcSSimon Schubert char *(*op_name) (enum exp_opcode); 3425796c8dcSSimon Schubert 3435796c8dcSSimon Schubert /* Dump the rest of this (prefix) expression after the operator 3445796c8dcSSimon Schubert itself has been printed. See dump_subexp_body_standard in 3455796c8dcSSimon Schubert (expprint.c). */ 3465796c8dcSSimon Schubert int (*dump_subexp_body) (struct expression *, struct ui_file *, int); 3475796c8dcSSimon Schubert 3485796c8dcSSimon Schubert /* Evaluate an expression. */ 3495796c8dcSSimon Schubert struct value *(*evaluate_exp) (struct type *, struct expression *, 3505796c8dcSSimon Schubert int *, enum noside); 3515796c8dcSSimon Schubert }; 3525796c8dcSSimon Schubert 3535796c8dcSSimon Schubert 3545796c8dcSSimon Schubert /* Default descriptor containing standard definitions of all 3555796c8dcSSimon Schubert elements. */ 3565796c8dcSSimon Schubert extern const struct exp_descriptor exp_descriptor_standard; 3575796c8dcSSimon Schubert 3585796c8dcSSimon Schubert /* Functions used by language-specific extended operators to (recursively) 3595796c8dcSSimon Schubert print/dump subexpressions. */ 3605796c8dcSSimon Schubert 3615796c8dcSSimon Schubert extern void print_subexp (struct expression *, int *, struct ui_file *, 3625796c8dcSSimon Schubert enum precedence); 3635796c8dcSSimon Schubert 3645796c8dcSSimon Schubert extern void print_subexp_standard (struct expression *, int *, 3655796c8dcSSimon Schubert struct ui_file *, enum precedence); 3665796c8dcSSimon Schubert 3675796c8dcSSimon Schubert /* Function used to avoid direct calls to fprintf 3685796c8dcSSimon Schubert in the code generated by the bison parser. */ 3695796c8dcSSimon Schubert 370cf7f2e2dSJohn Marino extern void parser_fprintf (FILE *, const char *, ...) ATTRIBUTE_PRINTF (2, 3); 371cf7f2e2dSJohn Marino 372cf7f2e2dSJohn Marino extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile); 3735796c8dcSSimon Schubert 374*ef5ccd6cSJohn Marino extern void mark_completion_tag (enum type_code, const char *ptr, 375*ef5ccd6cSJohn Marino int length); 376*ef5ccd6cSJohn Marino 3775796c8dcSSimon Schubert #endif /* PARSER_DEFS_H */ 378*ef5ccd6cSJohn Marino 379