15796c8dcSSimon Schubert /* Definitions for expressions stored in reversed prefix form, for GDB. 25796c8dcSSimon Schubert 3*ef5ccd6cSJohn Marino Copyright (C) 1986-2013 Free Software Foundation, Inc. 45796c8dcSSimon Schubert 55796c8dcSSimon Schubert This file is part of GDB. 65796c8dcSSimon Schubert 75796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 85796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 95796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 105796c8dcSSimon Schubert (at your option) any later version. 115796c8dcSSimon Schubert 125796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 135796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 145796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 155796c8dcSSimon Schubert GNU General Public License for more details. 165796c8dcSSimon Schubert 175796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 185796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 195796c8dcSSimon Schubert 205796c8dcSSimon Schubert #if !defined (EXPRESSION_H) 215796c8dcSSimon Schubert #define EXPRESSION_H 1 225796c8dcSSimon Schubert 235796c8dcSSimon Schubert 245796c8dcSSimon Schubert #include "symtab.h" /* Needed for "struct block" type. */ 255796c8dcSSimon Schubert #include "doublest.h" /* Needed for DOUBLEST. */ 265796c8dcSSimon Schubert 275796c8dcSSimon Schubert 285796c8dcSSimon Schubert /* Definitions for saved C expressions. */ 295796c8dcSSimon Schubert 305796c8dcSSimon Schubert /* An expression is represented as a vector of union exp_element's. 315796c8dcSSimon Schubert Each exp_element is an opcode, except that some opcodes cause 325796c8dcSSimon Schubert the following exp_element to be treated as a long or double constant 335796c8dcSSimon Schubert or as a variable. The opcodes are obeyed, using a stack for temporaries. 345796c8dcSSimon Schubert The value is left on the temporary stack at the end. */ 355796c8dcSSimon Schubert 365796c8dcSSimon Schubert /* When it is necessary to include a string, 375796c8dcSSimon Schubert it can occupy as many exp_elements as it needs. 385796c8dcSSimon Schubert We find the length of the string using strlen, 395796c8dcSSimon Schubert divide to find out how many exp_elements are used up, 405796c8dcSSimon Schubert and skip that many. Strings, like numbers, are indicated 415796c8dcSSimon Schubert by the preceding opcode. */ 425796c8dcSSimon Schubert 435796c8dcSSimon Schubert enum exp_opcode 445796c8dcSSimon Schubert { 45c50c785cSJohn Marino #define OP(name) name , 465796c8dcSSimon Schubert 47c50c785cSJohn Marino #include "std-operator.def" 485796c8dcSSimon Schubert 49c50c785cSJohn Marino /* First extension operator. Individual language modules define extra 50c50c785cSJohn Marino operators in *.def include files below with numbers higher than 51c50c785cSJohn Marino OP_EXTENDED0. */ 52c50c785cSJohn Marino OP (OP_EXTENDED0) 535796c8dcSSimon Schubert 54c50c785cSJohn Marino /* Language specific operators. */ 55c50c785cSJohn Marino #include "ada-operator.def" 565796c8dcSSimon Schubert 57c50c785cSJohn Marino #undef OP 585796c8dcSSimon Schubert 595796c8dcSSimon Schubert /* Existing only to swallow the last comma (',') from last .inc file. */ 605796c8dcSSimon Schubert OP_UNUSED_LAST 615796c8dcSSimon Schubert }; 625796c8dcSSimon Schubert 635796c8dcSSimon Schubert union exp_element 645796c8dcSSimon Schubert { 655796c8dcSSimon Schubert enum exp_opcode opcode; 665796c8dcSSimon Schubert struct symbol *symbol; 675796c8dcSSimon Schubert LONGEST longconst; 685796c8dcSSimon Schubert DOUBLEST doubleconst; 695796c8dcSSimon Schubert gdb_byte decfloatconst[16]; 705796c8dcSSimon Schubert /* Really sizeof (union exp_element) characters (or less for the last 715796c8dcSSimon Schubert element of a string). */ 725796c8dcSSimon Schubert char string; 735796c8dcSSimon Schubert struct type *type; 745796c8dcSSimon Schubert struct internalvar *internalvar; 75*ef5ccd6cSJohn Marino const struct block *block; 765796c8dcSSimon Schubert struct objfile *objfile; 775796c8dcSSimon Schubert }; 785796c8dcSSimon Schubert 795796c8dcSSimon Schubert struct expression 805796c8dcSSimon Schubert { 81c50c785cSJohn Marino const struct language_defn *language_defn; /* language it was 82c50c785cSJohn Marino entered in. */ 83c50c785cSJohn Marino struct gdbarch *gdbarch; /* architecture it was parsed in. */ 845796c8dcSSimon Schubert int nelts; 855796c8dcSSimon Schubert union exp_element elts[1]; 865796c8dcSSimon Schubert }; 875796c8dcSSimon Schubert 885796c8dcSSimon Schubert /* Macros for converting between number of expression elements and bytes 895796c8dcSSimon Schubert to store that many expression elements. */ 905796c8dcSSimon Schubert 915796c8dcSSimon Schubert #define EXP_ELEM_TO_BYTES(elements) \ 925796c8dcSSimon Schubert ((elements) * sizeof (union exp_element)) 935796c8dcSSimon Schubert #define BYTES_TO_EXP_ELEM(bytes) \ 945796c8dcSSimon Schubert (((bytes) + sizeof (union exp_element) - 1) / sizeof (union exp_element)) 955796c8dcSSimon Schubert 965796c8dcSSimon Schubert /* From parse.c */ 975796c8dcSSimon Schubert 98*ef5ccd6cSJohn Marino extern struct expression *parse_expression (const char *); 995796c8dcSSimon Schubert 100*ef5ccd6cSJohn Marino extern struct type *parse_expression_for_completion (char *, char **, 101*ef5ccd6cSJohn Marino enum type_code *); 1025796c8dcSSimon Schubert 103*ef5ccd6cSJohn Marino extern struct expression *parse_exp_1 (const char **, CORE_ADDR pc, 104*ef5ccd6cSJohn Marino const struct block *, int); 1055796c8dcSSimon Schubert 1065796c8dcSSimon Schubert /* For use by parsers; set if we want to parse an expression and 107*ef5ccd6cSJohn Marino attempt completion. */ 108*ef5ccd6cSJohn Marino extern int parse_completion; 1095796c8dcSSimon Schubert 1105796c8dcSSimon Schubert /* The innermost context required by the stack and register variables 1115796c8dcSSimon Schubert we've encountered so far. To use this, set it to NULL, then call 1125796c8dcSSimon Schubert parse_<whatever>, then look at it. */ 113*ef5ccd6cSJohn Marino extern const struct block *innermost_block; 1145796c8dcSSimon Schubert 1155796c8dcSSimon Schubert /* From eval.c */ 1165796c8dcSSimon Schubert 1175796c8dcSSimon Schubert /* Values of NOSIDE argument to eval_subexp. */ 1185796c8dcSSimon Schubert 1195796c8dcSSimon Schubert enum noside 1205796c8dcSSimon Schubert { 1215796c8dcSSimon Schubert EVAL_NORMAL, 1225796c8dcSSimon Schubert EVAL_SKIP, /* Only effect is to increment pos. */ 1235796c8dcSSimon Schubert EVAL_AVOID_SIDE_EFFECTS /* Don't modify any variables or 1245796c8dcSSimon Schubert call any functions. The value 1255796c8dcSSimon Schubert returned will have the correct 1265796c8dcSSimon Schubert type, and will have an 1275796c8dcSSimon Schubert approximately correct lvalue 1285796c8dcSSimon Schubert type (inaccuracy: anything that is 1295796c8dcSSimon Schubert listed as being in a register in 1305796c8dcSSimon Schubert the function in which it was 1315796c8dcSSimon Schubert declared will be lval_register). */ 1325796c8dcSSimon Schubert }; 1335796c8dcSSimon Schubert 1345796c8dcSSimon Schubert extern struct value *evaluate_subexp_standard 1355796c8dcSSimon Schubert (struct type *, struct expression *, int *, enum noside); 1365796c8dcSSimon Schubert 1375796c8dcSSimon Schubert /* From expprint.c */ 1385796c8dcSSimon Schubert 1395796c8dcSSimon Schubert extern void print_expression (struct expression *, struct ui_file *); 1405796c8dcSSimon Schubert 141*ef5ccd6cSJohn Marino extern char *op_name (struct expression *exp, enum exp_opcode opcode); 142*ef5ccd6cSJohn Marino 1435796c8dcSSimon Schubert extern char *op_string (enum exp_opcode); 1445796c8dcSSimon Schubert 145c50c785cSJohn Marino extern void dump_raw_expression (struct expression *, 146c50c785cSJohn Marino struct ui_file *, char *); 1475796c8dcSSimon Schubert extern void dump_prefix_expression (struct expression *, struct ui_file *); 1485796c8dcSSimon Schubert 1495796c8dcSSimon Schubert #endif /* !defined (EXPRESSION_H) */ 150