15796c8dcSSimon Schubert /* Parser definitions for GDB. 25796c8dcSSimon Schubert 35796c8dcSSimon Schubert Copyright (C) 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 4*cf7f2e2dSJohn Marino 1998, 1999, 2000, 2002, 2007, 2008, 2009, 2010 5*cf7f2e2dSJohn Marino Free Software Foundation, Inc. 65796c8dcSSimon Schubert 75796c8dcSSimon Schubert Modified from expread.y by the Department of Computer Science at the 85796c8dcSSimon Schubert State University of New York at Buffalo. 95796c8dcSSimon Schubert 105796c8dcSSimon Schubert This file is part of GDB. 115796c8dcSSimon Schubert 125796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 135796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 145796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 155796c8dcSSimon Schubert (at your option) any later version. 165796c8dcSSimon Schubert 175796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 185796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 195796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 205796c8dcSSimon Schubert GNU General Public License for more details. 215796c8dcSSimon Schubert 225796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 235796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 245796c8dcSSimon Schubert 255796c8dcSSimon Schubert #if !defined (PARSER_DEFS_H) 265796c8dcSSimon Schubert #define PARSER_DEFS_H 1 275796c8dcSSimon Schubert 285796c8dcSSimon Schubert #include "doublest.h" 295796c8dcSSimon Schubert 305796c8dcSSimon Schubert struct block; 315796c8dcSSimon Schubert 32*cf7f2e2dSJohn Marino extern int parser_debug; 33*cf7f2e2dSJohn Marino 345796c8dcSSimon Schubert extern struct expression *expout; 355796c8dcSSimon Schubert extern int expout_size; 365796c8dcSSimon Schubert extern int expout_ptr; 375796c8dcSSimon Schubert 385796c8dcSSimon Schubert #define parse_gdbarch (expout->gdbarch) 395796c8dcSSimon Schubert #define parse_language (expout->language_defn) 405796c8dcSSimon Schubert 415796c8dcSSimon Schubert /* If this is nonzero, this block is used as the lexical context 425796c8dcSSimon Schubert for symbol names. */ 435796c8dcSSimon Schubert 445796c8dcSSimon Schubert extern struct block *expression_context_block; 455796c8dcSSimon Schubert 465796c8dcSSimon Schubert /* If expression_context_block is non-zero, then this is the PC within 475796c8dcSSimon Schubert the block that we want to evaluate expressions at. When debugging 485796c8dcSSimon Schubert C or C++ code, we use this to find the exact line we're at, and 495796c8dcSSimon Schubert then look up the macro definitions active at that point. */ 505796c8dcSSimon Schubert extern CORE_ADDR expression_context_pc; 515796c8dcSSimon Schubert 525796c8dcSSimon Schubert /* The innermost context required by the stack and register variables 535796c8dcSSimon Schubert we've encountered so far. */ 545796c8dcSSimon Schubert extern struct block *innermost_block; 555796c8dcSSimon Schubert 565796c8dcSSimon Schubert /* The block in which the most recently discovered symbol was found. 575796c8dcSSimon Schubert FIXME: Should be declared along with lookup_symbol in symtab.h; is not 585796c8dcSSimon Schubert related specifically to parsing. */ 595796c8dcSSimon Schubert extern struct block *block_found; 605796c8dcSSimon Schubert 615796c8dcSSimon Schubert /* Number of arguments seen so far in innermost function call. */ 625796c8dcSSimon Schubert extern int arglist_len; 635796c8dcSSimon Schubert 645796c8dcSSimon Schubert /* A string token, either a char-string or bit-string. Char-strings are 655796c8dcSSimon Schubert used, for example, for the names of symbols. */ 665796c8dcSSimon Schubert 675796c8dcSSimon Schubert struct stoken 685796c8dcSSimon Schubert { 695796c8dcSSimon Schubert /* Pointer to first byte of char-string or first bit of bit-string */ 705796c8dcSSimon Schubert char *ptr; 715796c8dcSSimon Schubert /* Length of string in bytes for char-string or bits for bit-string */ 725796c8dcSSimon Schubert int length; 735796c8dcSSimon Schubert }; 745796c8dcSSimon Schubert 755796c8dcSSimon Schubert struct typed_stoken 765796c8dcSSimon Schubert { 775796c8dcSSimon Schubert /* A language-specific type field. */ 785796c8dcSSimon Schubert int type; 795796c8dcSSimon Schubert /* Pointer to first byte of char-string or first bit of bit-string */ 805796c8dcSSimon Schubert char *ptr; 815796c8dcSSimon Schubert /* Length of string in bytes for char-string or bits for bit-string */ 825796c8dcSSimon Schubert int length; 835796c8dcSSimon Schubert }; 845796c8dcSSimon Schubert 855796c8dcSSimon Schubert struct stoken_vector 865796c8dcSSimon Schubert { 875796c8dcSSimon Schubert int len; 885796c8dcSSimon Schubert struct typed_stoken *tokens; 895796c8dcSSimon Schubert }; 905796c8dcSSimon Schubert 915796c8dcSSimon Schubert struct ttype 925796c8dcSSimon Schubert { 935796c8dcSSimon Schubert struct stoken stoken; 945796c8dcSSimon Schubert struct type *type; 955796c8dcSSimon Schubert }; 965796c8dcSSimon Schubert 975796c8dcSSimon Schubert struct symtoken 985796c8dcSSimon Schubert { 995796c8dcSSimon Schubert struct stoken stoken; 1005796c8dcSSimon Schubert struct symbol *sym; 1015796c8dcSSimon Schubert int is_a_field_of_this; 1025796c8dcSSimon Schubert }; 1035796c8dcSSimon Schubert 1045796c8dcSSimon Schubert struct objc_class_str 1055796c8dcSSimon Schubert { 1065796c8dcSSimon Schubert struct stoken stoken; 1075796c8dcSSimon Schubert struct type *type; 1085796c8dcSSimon Schubert int class; 1095796c8dcSSimon Schubert }; 1105796c8dcSSimon Schubert 1115796c8dcSSimon Schubert 1125796c8dcSSimon Schubert /* For parsing of complicated types. 1135796c8dcSSimon Schubert An array should be preceded in the list by the size of the array. */ 1145796c8dcSSimon Schubert enum type_pieces 1155796c8dcSSimon Schubert { 1165796c8dcSSimon Schubert tp_end = -1, 1175796c8dcSSimon Schubert tp_pointer, 1185796c8dcSSimon Schubert tp_reference, 1195796c8dcSSimon Schubert tp_array, 1205796c8dcSSimon Schubert tp_function, 1215796c8dcSSimon Schubert tp_const, 1225796c8dcSSimon Schubert tp_volatile, 1235796c8dcSSimon Schubert tp_space_identifier 1245796c8dcSSimon Schubert }; 1255796c8dcSSimon Schubert /* The stack can contain either an enum type_pieces or an int. */ 1265796c8dcSSimon Schubert union type_stack_elt 1275796c8dcSSimon Schubert { 1285796c8dcSSimon Schubert enum type_pieces piece; 1295796c8dcSSimon Schubert int int_val; 1305796c8dcSSimon Schubert }; 1315796c8dcSSimon Schubert extern union type_stack_elt *type_stack; 1325796c8dcSSimon Schubert extern int type_stack_depth, type_stack_size; 1335796c8dcSSimon Schubert 1345796c8dcSSimon Schubert extern void write_exp_elt (union exp_element); 1355796c8dcSSimon Schubert 1365796c8dcSSimon Schubert extern void write_exp_elt_opcode (enum exp_opcode); 1375796c8dcSSimon Schubert 1385796c8dcSSimon Schubert extern void write_exp_elt_sym (struct symbol *); 1395796c8dcSSimon Schubert 1405796c8dcSSimon Schubert extern void write_exp_elt_longcst (LONGEST); 1415796c8dcSSimon Schubert 1425796c8dcSSimon Schubert extern void write_exp_elt_dblcst (DOUBLEST); 1435796c8dcSSimon Schubert 1445796c8dcSSimon Schubert extern void write_exp_elt_decfloatcst (gdb_byte *); 1455796c8dcSSimon Schubert 1465796c8dcSSimon Schubert extern void write_exp_elt_type (struct type *); 1475796c8dcSSimon Schubert 1485796c8dcSSimon Schubert extern void write_exp_elt_intern (struct internalvar *); 1495796c8dcSSimon Schubert 1505796c8dcSSimon Schubert extern void write_exp_string (struct stoken); 1515796c8dcSSimon Schubert 1525796c8dcSSimon Schubert void write_exp_string_vector (int type, struct stoken_vector *vec); 1535796c8dcSSimon Schubert 1545796c8dcSSimon Schubert extern void write_exp_bitstring (struct stoken); 1555796c8dcSSimon Schubert 1565796c8dcSSimon Schubert extern void write_exp_elt_block (struct block *); 1575796c8dcSSimon Schubert 1585796c8dcSSimon Schubert extern void write_exp_elt_objfile (struct objfile *objfile); 1595796c8dcSSimon Schubert 1605796c8dcSSimon Schubert extern void write_exp_msymbol (struct minimal_symbol *); 1615796c8dcSSimon Schubert 1625796c8dcSSimon Schubert extern void write_dollar_variable (struct stoken str); 1635796c8dcSSimon Schubert 1645796c8dcSSimon Schubert extern void mark_struct_expression (void); 1655796c8dcSSimon Schubert 1665796c8dcSSimon Schubert extern char *find_template_name_end (char *); 1675796c8dcSSimon Schubert 1685796c8dcSSimon Schubert extern void start_arglist (void); 1695796c8dcSSimon Schubert 1705796c8dcSSimon Schubert extern int end_arglist (void); 1715796c8dcSSimon Schubert 1725796c8dcSSimon Schubert extern char *copy_name (struct stoken); 1735796c8dcSSimon Schubert 1745796c8dcSSimon Schubert extern void push_type (enum type_pieces); 1755796c8dcSSimon Schubert 1765796c8dcSSimon Schubert extern void push_type_int (int); 1775796c8dcSSimon Schubert 1785796c8dcSSimon Schubert extern void push_type_address_space (char *); 1795796c8dcSSimon Schubert 1805796c8dcSSimon Schubert extern enum type_pieces pop_type (void); 1815796c8dcSSimon Schubert 1825796c8dcSSimon Schubert extern int pop_type_int (void); 1835796c8dcSSimon Schubert 1845796c8dcSSimon Schubert extern int length_of_subexp (struct expression *, int); 1855796c8dcSSimon Schubert 1865796c8dcSSimon Schubert extern int dump_subexp (struct expression *, struct ui_file *, int); 1875796c8dcSSimon Schubert 1885796c8dcSSimon Schubert extern int dump_subexp_body_standard (struct expression *, 1895796c8dcSSimon Schubert struct ui_file *, int); 1905796c8dcSSimon Schubert 191*cf7f2e2dSJohn Marino extern void operator_length (const struct expression *, int, int *, int *); 1925796c8dcSSimon Schubert 193*cf7f2e2dSJohn Marino extern void operator_length_standard (const struct expression *, int, int *, 194*cf7f2e2dSJohn Marino int *); 195*cf7f2e2dSJohn Marino 196*cf7f2e2dSJohn Marino extern int operator_check_standard (struct expression *exp, int pos, 197*cf7f2e2dSJohn Marino int (*objfile_func) 198*cf7f2e2dSJohn Marino (struct objfile *objfile, void *data), 199*cf7f2e2dSJohn Marino void *data); 2005796c8dcSSimon Schubert 2015796c8dcSSimon Schubert extern char *op_name_standard (enum exp_opcode); 2025796c8dcSSimon Schubert 2035796c8dcSSimon Schubert extern struct type *follow_types (struct type *); 2045796c8dcSSimon Schubert 2055796c8dcSSimon Schubert extern void null_post_parser (struct expression **, int); 2065796c8dcSSimon Schubert 2075796c8dcSSimon Schubert /* During parsing of a C expression, the pointer to the next character 2085796c8dcSSimon Schubert is in this variable. */ 2095796c8dcSSimon Schubert 2105796c8dcSSimon Schubert extern char *lexptr; 2115796c8dcSSimon Schubert 2125796c8dcSSimon Schubert /* After a token has been recognized, this variable points to it. 2135796c8dcSSimon Schubert Currently used only for error reporting. */ 2145796c8dcSSimon Schubert extern char *prev_lexptr; 2155796c8dcSSimon Schubert 2165796c8dcSSimon Schubert /* Tokens that refer to names do so with explicit pointer and length, 2175796c8dcSSimon Schubert so they can share the storage that lexptr is parsing. 2185796c8dcSSimon Schubert 2195796c8dcSSimon Schubert When it is necessary to pass a name to a function that expects 2205796c8dcSSimon Schubert a null-terminated string, the substring is copied out 2215796c8dcSSimon Schubert into a block of storage that namecopy points to. 2225796c8dcSSimon Schubert 2235796c8dcSSimon Schubert namecopy is allocated once, guaranteed big enough, for each parsing. */ 2245796c8dcSSimon Schubert 2255796c8dcSSimon Schubert extern char *namecopy; 2265796c8dcSSimon Schubert 2275796c8dcSSimon Schubert /* Current depth in parentheses within the expression. */ 2285796c8dcSSimon Schubert 2295796c8dcSSimon Schubert extern int paren_depth; 2305796c8dcSSimon Schubert 2315796c8dcSSimon Schubert /* Nonzero means stop parsing on first comma (if not within parentheses). */ 2325796c8dcSSimon Schubert 2335796c8dcSSimon Schubert extern int comma_terminates; 2345796c8dcSSimon Schubert 2355796c8dcSSimon Schubert /* These codes indicate operator precedences for expression printing, 2365796c8dcSSimon Schubert least tightly binding first. */ 2375796c8dcSSimon Schubert /* Adding 1 to a precedence value is done for binary operators, 2385796c8dcSSimon Schubert on the operand which is more tightly bound, so that operators 2395796c8dcSSimon Schubert of equal precedence within that operand will get parentheses. */ 2405796c8dcSSimon Schubert /* PREC_HYPER and PREC_ABOVE_COMMA are not the precedence of any operator; 2415796c8dcSSimon Schubert they are used as the "surrounding precedence" to force 2425796c8dcSSimon Schubert various kinds of things to be parenthesized. */ 2435796c8dcSSimon Schubert enum precedence 2445796c8dcSSimon Schubert { 2455796c8dcSSimon Schubert PREC_NULL, PREC_COMMA, PREC_ABOVE_COMMA, PREC_ASSIGN, PREC_LOGICAL_OR, 2465796c8dcSSimon Schubert PREC_LOGICAL_AND, PREC_BITWISE_IOR, PREC_BITWISE_AND, PREC_BITWISE_XOR, 2475796c8dcSSimon Schubert PREC_EQUAL, PREC_ORDER, PREC_SHIFT, PREC_ADD, PREC_MUL, PREC_REPEAT, 2485796c8dcSSimon Schubert PREC_HYPER, PREC_PREFIX, PREC_SUFFIX, PREC_BUILTIN_FUNCTION 2495796c8dcSSimon Schubert }; 2505796c8dcSSimon Schubert 2515796c8dcSSimon Schubert /* Table mapping opcodes into strings for printing operators 2525796c8dcSSimon Schubert and precedences of the operators. */ 2535796c8dcSSimon Schubert 2545796c8dcSSimon Schubert struct op_print 2555796c8dcSSimon Schubert { 2565796c8dcSSimon Schubert char *string; 2575796c8dcSSimon Schubert enum exp_opcode opcode; 2585796c8dcSSimon Schubert /* Precedence of operator. These values are used only by comparisons. */ 2595796c8dcSSimon Schubert enum precedence precedence; 2605796c8dcSSimon Schubert 2615796c8dcSSimon Schubert /* For a binary operator: 1 iff right associate. 2625796c8dcSSimon Schubert For a unary operator: 1 iff postfix. */ 2635796c8dcSSimon Schubert int right_assoc; 2645796c8dcSSimon Schubert }; 2655796c8dcSSimon Schubert 2665796c8dcSSimon Schubert /* Information needed to print, prefixify, and evaluate expressions for 2675796c8dcSSimon Schubert a given language. */ 2685796c8dcSSimon Schubert 2695796c8dcSSimon Schubert struct exp_descriptor 2705796c8dcSSimon Schubert { 2715796c8dcSSimon Schubert /* Print subexpression. */ 2725796c8dcSSimon Schubert void (*print_subexp) (struct expression *, int *, struct ui_file *, 2735796c8dcSSimon Schubert enum precedence); 2745796c8dcSSimon Schubert 2755796c8dcSSimon Schubert /* Returns number of exp_elements needed to represent an operator and 2765796c8dcSSimon Schubert the number of subexpressions it takes. */ 277*cf7f2e2dSJohn Marino void (*operator_length) (const struct expression*, int, int*, int *); 278*cf7f2e2dSJohn Marino 279*cf7f2e2dSJohn Marino /* Call TYPE_FUNC and OBJFILE_FUNC for any TYPE and OBJFILE found being 280*cf7f2e2dSJohn Marino referenced by the single operator of EXP at position POS. Operator 281*cf7f2e2dSJohn Marino parameters are located at positive (POS + number) offsets in EXP. 282*cf7f2e2dSJohn Marino The functions should never be called with NULL TYPE or NULL OBJFILE. 283*cf7f2e2dSJohn Marino Functions should get passed an arbitrary caller supplied DATA pointer. 284*cf7f2e2dSJohn Marino If any of the functions returns non-zero value then (any other) non-zero 285*cf7f2e2dSJohn Marino value should be immediately returned to the caller. Otherwise zero 286*cf7f2e2dSJohn Marino should be returned. */ 287*cf7f2e2dSJohn Marino int (*operator_check) (struct expression *exp, int pos, 288*cf7f2e2dSJohn Marino int (*objfile_func) (struct objfile *objfile, 289*cf7f2e2dSJohn Marino void *data), 290*cf7f2e2dSJohn Marino void *data); 2915796c8dcSSimon Schubert 2925796c8dcSSimon Schubert /* Name of this operator for dumping purposes. */ 2935796c8dcSSimon Schubert char *(*op_name) (enum exp_opcode); 2945796c8dcSSimon Schubert 2955796c8dcSSimon Schubert /* Dump the rest of this (prefix) expression after the operator 2965796c8dcSSimon Schubert itself has been printed. See dump_subexp_body_standard in 2975796c8dcSSimon Schubert (expprint.c). */ 2985796c8dcSSimon Schubert int (*dump_subexp_body) (struct expression *, struct ui_file *, int); 2995796c8dcSSimon Schubert 3005796c8dcSSimon Schubert /* Evaluate an expression. */ 3015796c8dcSSimon Schubert struct value *(*evaluate_exp) (struct type *, struct expression *, 3025796c8dcSSimon Schubert int *, enum noside); 3035796c8dcSSimon Schubert }; 3045796c8dcSSimon Schubert 3055796c8dcSSimon Schubert 3065796c8dcSSimon Schubert /* Default descriptor containing standard definitions of all 3075796c8dcSSimon Schubert elements. */ 3085796c8dcSSimon Schubert extern const struct exp_descriptor exp_descriptor_standard; 3095796c8dcSSimon Schubert 3105796c8dcSSimon Schubert /* Functions used by language-specific extended operators to (recursively) 3115796c8dcSSimon Schubert print/dump subexpressions. */ 3125796c8dcSSimon Schubert 3135796c8dcSSimon Schubert extern void print_subexp (struct expression *, int *, struct ui_file *, 3145796c8dcSSimon Schubert enum precedence); 3155796c8dcSSimon Schubert 3165796c8dcSSimon Schubert extern void print_subexp_standard (struct expression *, int *, 3175796c8dcSSimon Schubert struct ui_file *, enum precedence); 3185796c8dcSSimon Schubert 3195796c8dcSSimon Schubert /* Function used to avoid direct calls to fprintf 3205796c8dcSSimon Schubert in the code generated by the bison parser. */ 3215796c8dcSSimon Schubert 322*cf7f2e2dSJohn Marino extern void parser_fprintf (FILE *, const char *, ...) ATTRIBUTE_PRINTF (2, 3); 323*cf7f2e2dSJohn Marino 324*cf7f2e2dSJohn Marino extern int exp_uses_objfile (struct expression *exp, struct objfile *objfile); 3255796c8dcSSimon Schubert 3265796c8dcSSimon Schubert #endif /* PARSER_DEFS_H */ 327