119370Spst/* Parser definitions for GDB. 2130803Smarcel 3130803Smarcel Copyright 1986, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 4130803Smarcel 1997, 1998, 1999, 2000, 2002 Free Software Foundation, Inc. 5130803Smarcel 619370Spst Modified from expread.y by the Department of Computer Science at the 719370Spst State University of New York at Buffalo. 819370Spst 998944Sobrien This file is part of GDB. 1019370Spst 1198944Sobrien This program is free software; you can redistribute it and/or modify 1298944Sobrien it under the terms of the GNU General Public License as published by 1398944Sobrien the Free Software Foundation; either version 2 of the License, or 1498944Sobrien (at your option) any later version. 1519370Spst 1698944Sobrien This program is distributed in the hope that it will be useful, 1798944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1898944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1998944Sobrien GNU General Public License for more details. 2019370Spst 2198944Sobrien You should have received a copy of the GNU General Public License 2298944Sobrien along with this program; if not, write to the Free Software 2398944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 2498944Sobrien Boston, MA 02111-1307, USA. */ 2519370Spst 2619370Spst#if !defined (PARSER_DEFS_H) 2719370Spst#define PARSER_DEFS_H 1 2819370Spst 2998944Sobrien#include "doublest.h" 3019370Spst 31130803Smarcelstruct block; 3298944Sobrien 3319370Spstextern struct expression *expout; 3419370Spstextern int expout_size; 3519370Spstextern int expout_ptr; 3619370Spst 3719370Spst/* If this is nonzero, this block is used as the lexical context 3819370Spst for symbol names. */ 3919370Spst 4019370Spstextern struct block *expression_context_block; 4119370Spst 42130803Smarcel/* If expression_context_block is non-zero, then this is the PC within 43130803Smarcel the block that we want to evaluate expressions at. When debugging 44130803Smarcel C or C++ code, we use this to find the exact line we're at, and 45130803Smarcel then look up the macro definitions active at that point. */ 46130803Smarcelextern CORE_ADDR expression_context_pc; 47130803Smarcel 4819370Spst/* The innermost context required by the stack and register variables 4919370Spst we've encountered so far. */ 5019370Spstextern struct block *innermost_block; 5119370Spst 5219370Spst/* The block in which the most recently discovered symbol was found. 5319370Spst FIXME: Should be declared along with lookup_symbol in symtab.h; is not 5419370Spst related specifically to parsing. */ 5519370Spstextern struct block *block_found; 5619370Spst 5719370Spst/* Number of arguments seen so far in innermost function call. */ 5819370Spstextern int arglist_len; 5919370Spst 6019370Spst/* A string token, either a char-string or bit-string. Char-strings are 6119370Spst used, for example, for the names of symbols. */ 6219370Spst 6319370Spststruct stoken 6419370Spst { 6519370Spst /* Pointer to first byte of char-string or first bit of bit-string */ 6619370Spst char *ptr; 6719370Spst /* Length of string in bytes for char-string or bits for bit-string */ 6819370Spst int length; 6919370Spst }; 7019370Spst 7119370Spststruct ttype 7219370Spst { 7319370Spst struct stoken stoken; 7419370Spst struct type *type; 7519370Spst }; 7619370Spst 7719370Spststruct symtoken 7819370Spst { 7919370Spst struct stoken stoken; 8019370Spst struct symbol *sym; 8119370Spst int is_a_field_of_this; 8219370Spst }; 8319370Spst 84130803Smarcelstruct objc_class_str 85130803Smarcel { 86130803Smarcel struct stoken stoken; 87130803Smarcel struct type *type; 88130803Smarcel int class; 89130803Smarcel }; 90130803Smarcel 91130803Smarcel 9219370Spst/* For parsing of complicated types. 9319370Spst An array should be preceded in the list by the size of the array. */ 9419370Spstenum type_pieces 9598944Sobrien { 9698944Sobrien tp_end = -1, 9798944Sobrien tp_pointer, 9898944Sobrien tp_reference, 9998944Sobrien tp_array, 10098944Sobrien tp_function, 10198944Sobrien tp_const, 10298944Sobrien tp_volatile, 10398944Sobrien tp_space_identifier 10498944Sobrien }; 10519370Spst/* The stack can contain either an enum type_pieces or an int. */ 10698944Sobrienunion type_stack_elt 10798944Sobrien { 10898944Sobrien enum type_pieces piece; 10998944Sobrien int int_val; 11098944Sobrien }; 11119370Spstextern union type_stack_elt *type_stack; 11219370Spstextern int type_stack_depth, type_stack_size; 11319370Spst 11498944Sobrienextern void write_exp_elt (union exp_element); 11519370Spst 11698944Sobrienextern void write_exp_elt_opcode (enum exp_opcode); 11719370Spst 11898944Sobrienextern void write_exp_elt_sym (struct symbol *); 11919370Spst 12098944Sobrienextern void write_exp_elt_longcst (LONGEST); 12119370Spst 12298944Sobrienextern void write_exp_elt_dblcst (DOUBLEST); 12319370Spst 12498944Sobrienextern void write_exp_elt_type (struct type *); 12519370Spst 12698944Sobrienextern void write_exp_elt_intern (struct internalvar *); 12719370Spst 12898944Sobrienextern void write_exp_string (struct stoken); 12919370Spst 13098944Sobrienextern void write_exp_bitstring (struct stoken); 13119370Spst 13298944Sobrienextern void write_exp_elt_block (struct block *); 13319370Spst 13498944Sobrienextern void write_exp_msymbol (struct minimal_symbol *, 13598944Sobrien struct type *, struct type *); 13619370Spst 13798944Sobrienextern void write_dollar_variable (struct stoken str); 13819370Spst 13998944Sobrienextern struct symbol *parse_nested_classes_for_hpacc (char *, int, char **, 14098944Sobrien int *, char **); 14146283Sdfr 14298944Sobrienextern char *find_template_name_end (char *); 14346283Sdfr 14498944Sobrienextern void start_arglist (void); 14519370Spst 14698944Sobrienextern int end_arglist (void); 14719370Spst 14898944Sobrienextern char *copy_name (struct stoken); 14919370Spst 15098944Sobrienextern void push_type (enum type_pieces); 15119370Spst 15298944Sobrienextern void push_type_int (int); 15319370Spst 15498944Sobrienextern void push_type_address_space (char *); 15519370Spst 15698944Sobrienextern enum type_pieces pop_type (void); 15719370Spst 15898944Sobrienextern int pop_type_int (void); 15946283Sdfr 16098944Sobrienextern int length_of_subexp (struct expression *, int); 16119370Spst 162130803Smarcelextern int dump_subexp (struct expression *, struct ui_file *, int); 163130803Smarcel 164130803Smarcelextern int dump_subexp_body_standard (struct expression *, 165130803Smarcel struct ui_file *, int); 166130803Smarcel 167130803Smarcelextern void operator_length (struct expression *, int, int *, int *); 168130803Smarcel 169130803Smarcelextern void operator_length_standard (struct expression *, int, int *, int *); 170130803Smarcel 171130803Smarcelextern char *op_name_standard (enum exp_opcode); 172130803Smarcel 17398944Sobrienextern struct type *follow_types (struct type *); 17498944Sobrien 17519370Spst/* During parsing of a C expression, the pointer to the next character 17619370Spst is in this variable. */ 17719370Spst 17819370Spstextern char *lexptr; 17919370Spst 180130803Smarcel/* After a token has been recognized, this variable points to it. 181130803Smarcel Currently used only for error reporting. */ 182130803Smarcelextern char *prev_lexptr; 183130803Smarcel 18419370Spst/* Tokens that refer to names do so with explicit pointer and length, 18519370Spst so they can share the storage that lexptr is parsing. 18619370Spst 18719370Spst When it is necessary to pass a name to a function that expects 18819370Spst a null-terminated string, the substring is copied out 18919370Spst into a block of storage that namecopy points to. 19019370Spst 19119370Spst namecopy is allocated once, guaranteed big enough, for each parsing. */ 19219370Spst 19319370Spstextern char *namecopy; 19419370Spst 19519370Spst/* Current depth in parentheses within the expression. */ 19619370Spst 19719370Spstextern int paren_depth; 19819370Spst 19919370Spst/* Nonzero means stop parsing on first comma (if not within parentheses). */ 20019370Spst 20119370Spstextern int comma_terminates; 20219370Spst 20319370Spst/* These codes indicate operator precedences for expression printing, 20419370Spst least tightly binding first. */ 20519370Spst/* Adding 1 to a precedence value is done for binary operators, 20619370Spst on the operand which is more tightly bound, so that operators 20719370Spst of equal precedence within that operand will get parentheses. */ 20819370Spst/* PREC_HYPER and PREC_ABOVE_COMMA are not the precedence of any operator; 20919370Spst they are used as the "surrounding precedence" to force 21019370Spst various kinds of things to be parenthesized. */ 21119370Spstenum precedence 21298944Sobrien { 21398944Sobrien PREC_NULL, PREC_COMMA, PREC_ABOVE_COMMA, PREC_ASSIGN, PREC_LOGICAL_OR, 21498944Sobrien PREC_LOGICAL_AND, PREC_BITWISE_IOR, PREC_BITWISE_AND, PREC_BITWISE_XOR, 21598944Sobrien PREC_EQUAL, PREC_ORDER, PREC_SHIFT, PREC_ADD, PREC_MUL, PREC_REPEAT, 21698944Sobrien PREC_HYPER, PREC_PREFIX, PREC_SUFFIX, PREC_BUILTIN_FUNCTION 21798944Sobrien }; 21819370Spst 21919370Spst/* Table mapping opcodes into strings for printing operators 22019370Spst and precedences of the operators. */ 22119370Spst 22219370Spststruct op_print 22398944Sobrien { 22498944Sobrien char *string; 22598944Sobrien enum exp_opcode opcode; 22698944Sobrien /* Precedence of operator. These values are used only by comparisons. */ 22798944Sobrien enum precedence precedence; 22819370Spst 22998944Sobrien /* For a binary operator: 1 iff right associate. 23098944Sobrien For a unary operator: 1 iff postfix. */ 23198944Sobrien int right_assoc; 23298944Sobrien }; 23319370Spst 234130803Smarcel/* Information needed to print, prefixify, and evaluate expressions for 235130803Smarcel a given language. */ 23698944Sobrien 237130803Smarcelstruct exp_descriptor 238130803Smarcel { 239130803Smarcel /* Print subexpression. */ 240130803Smarcel void (*print_subexp) (struct expression *, int *, struct ui_file *, 241130803Smarcel enum precedence); 24298944Sobrien 243130803Smarcel /* Returns number of exp_elements needed to represent an operator and 244130803Smarcel the number of subexpressions it takes. */ 245130803Smarcel void (*operator_length) (struct expression*, int, int*, int *); 246130803Smarcel 247130803Smarcel /* Name of this operator for dumping purposes. */ 248130803Smarcel char *(*op_name) (enum exp_opcode); 249130803Smarcel 250130803Smarcel /* Dump the rest of this (prefix) expression after the operator 251130803Smarcel itself has been printed. See dump_subexp_body_standard in 252130803Smarcel (expprint.c). */ 253130803Smarcel int (*dump_subexp_body) (struct expression *, struct ui_file *, int); 254130803Smarcel 255130803Smarcel /* Evaluate an expression. */ 256130803Smarcel struct value *(*evaluate_exp) (struct type *, struct expression *, 257130803Smarcel int *, enum noside); 258130803Smarcel }; 259130803Smarcel 260130803Smarcel 261130803Smarcel/* Default descriptor containing standard definitions of all 262130803Smarcel elements. */ 263130803Smarcelextern const struct exp_descriptor exp_descriptor_standard; 264130803Smarcel 265130803Smarcel/* Functions used by language-specific extended operators to (recursively) 266130803Smarcel print/dump subexpressions. */ 267130803Smarcel 268130803Smarcelextern void print_subexp (struct expression *, int *, struct ui_file *, 269130803Smarcel enum precedence); 270130803Smarcel 271130803Smarcelextern void print_subexp_standard (struct expression *, int *, 272130803Smarcel struct ui_file *, enum precedence); 273130803Smarcel 274130803Smarcel/* Function used to avoid direct calls to fprintf 275130803Smarcel in the code generated by the bison parser. */ 276130803Smarcel 277130803Smarcelextern void parser_fprintf (FILE *, const char *, ...) ATTR_FORMAT (printf, 2 ,3); 278130803Smarcel 27998944Sobrien#endif /* PARSER_DEFS_H */ 280