1 /* YACC grammar for Modula-2 expressions, for GDB.
2 Copyright (C) 1986, 1989, 1990, 1991, 1993, 1994, 1995
3 Free Software Foundation, Inc.
4 Generated from expread.y (now c-exp.y) and contributed by the Department
5 of Computer Science at the State University of New York at Buffalo, 1991.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 /* Parse a Modula-2 expression from text in a string,
24 and return the result as a struct expression pointer.
25 That structure contains arithmetic operations in reverse polish,
26 with constants represented by operations that are followed by special data.
27 See expression.h for the details of the format.
28 What is important here is that it can be built up sequentially
29 during the process of parsing; the lower levels of the tree always
30 come first in the result.
32 Note that malloc's and realloc's in this file are transformed to
33 xmalloc and xrealloc respectively by the same sed command in the
34 makefile that remaps any other malloc/realloc inserted by the parser
35 generator. Doing this with #defines and trying to control the interaction
36 with include files (<malloc.h> and <stdlib.h> for example) just became
37 too messy, particularly when such includes can be inserted at random
38 times by the parser generator. */
44 #include "expression.h"
47 #include "parser-defs.h"
49 #include "bfd.h" /* Required by objfiles.h. */
50 #include "symfile.h" /* Required by objfiles.h. */
51 #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
53 /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
54 as well as gratuitiously global symbol names, so we can have multiple
55 yacc generated parsers in gdb. Note that these are only the variables
56 produced by yacc. If other parser generators (bison, byacc, etc) produce
57 additional global names that conflict at link time, then those parser
58 generators need to be fixed instead of adding those names to this list. */
60 #define yymaxdepth m2_maxdepth
61 #define yyparse m2_parse
63 #define yyerror m2_error
64 #define yylval m2_lval
65 #define yychar m2_char
66 #define yydebug m2_debug
67 #define yypact m2_pact
74 #define yyexca m2_exca
75 #define yyerrflag m2_errflag
76 #define yynerrs m2_nerrs
81 #define yystate m2_state
86 #define yylloc m2_lloc
87 #define yyreds m2_reds /* With YYDEBUG defined */
88 #define yytoks m2_toks /* With YYDEBUG defined */
91 #define YYDEBUG 0 /* Default to no yydebug support */
95 yyparse PARAMS ((void));
98 yylex PARAMS ((void));
101 yyerror PARAMS ((char *));
105 make_qualname PARAMS ((char *, char *));
109 parse_number PARAMS ((int));
111 /* The sign of the number being parsed. */
112 static int number_sign = 1;
114 /* The block that the module specified by the qualifer on an identifer is
117 static struct block *modblock=0;
122 /* Although the yacc "value" of an expression is not used,
123 since the result is stored in the structure being created,
124 other node types do have values. */
129 unsigned LONGEST ulval;
136 enum exp_opcode opcode;
137 struct internalvar *ivar;
143 %type <voidval> exp type_exp start set
144 %type <voidval> variable
149 %token <lval> INT HEX ERROR
150 %token <ulval> UINT M2_TRUE M2_FALSE CHAR
153 /* Both NAME and TYPENAME tokens represent symbols in the input,
154 and both convey their data as strings.
155 But a TYPENAME is a string that happens to be defined as a typedef
156 or builtin type name (such as int or char)
157 and a NAME is any other symbol.
159 Contexts where this distinction is not important can use the
160 nonterminal "name", which matches either NAME or TYPENAME. */
163 %token <sval> NAME BLOCKNAME IDENT VARNAME
164 %token <sval> TYPENAME
166 %token SIZE CAP ORD HIGH ABS MIN_FUNC MAX_FUNC FLOAT_FUNC VAL CHR ODD TRUNC
167 %token INC DEC INCL EXCL
169 /* The GDB scope operator */
172 %token <lval> LAST REGNAME
174 %token <ivar> INTERNAL_VAR
180 %left '<' '>' LEQ GEQ '=' NOTEQUAL '#' IN
182 %left LOGICAL_AND '&'
185 %left '*' '/' DIV MOD
187 %right '^' DOT '[' '('
190 /* This is not an actual token ; it is used for precedence.
202 { write_exp_elt_opcode(OP_TYPE);
203 write_exp_elt_type($1);
204 write_exp_elt_opcode(OP_TYPE);
210 exp : exp '^' %prec UNARY
211 { write_exp_elt_opcode (UNOP_IND); }
214 { number_sign = -1; }
217 write_exp_elt_opcode (UNOP_NEG); }
220 exp : '+' exp %prec UNARY
221 { write_exp_elt_opcode(UNOP_PLUS); }
224 exp : not_exp exp %prec UNARY
225 { write_exp_elt_opcode (UNOP_LOGICAL_NOT); }
232 exp : CAP '(' exp ')'
233 { write_exp_elt_opcode (UNOP_CAP); }
236 exp : ORD '(' exp ')'
237 { write_exp_elt_opcode (UNOP_ORD); }
240 exp : ABS '(' exp ')'
241 { write_exp_elt_opcode (UNOP_ABS); }
244 exp : HIGH '(' exp ')'
245 { write_exp_elt_opcode (UNOP_HIGH); }
248 exp : MIN_FUNC '(' type ')'
249 { write_exp_elt_opcode (UNOP_MIN);
250 write_exp_elt_type ($3);
251 write_exp_elt_opcode (UNOP_MIN); }
254 exp : MAX_FUNC '(' type ')'
255 { write_exp_elt_opcode (UNOP_MAX);
256 write_exp_elt_type ($3);
257 write_exp_elt_opcode (UNOP_MIN); }
260 exp : FLOAT_FUNC '(' exp ')'
261 { write_exp_elt_opcode (UNOP_FLOAT); }
264 exp : VAL '(' type ',' exp ')'
265 { write_exp_elt_opcode (BINOP_VAL);
266 write_exp_elt_type ($3);
267 write_exp_elt_opcode (BINOP_VAL); }
270 exp : CHR '(' exp ')'
271 { write_exp_elt_opcode (UNOP_CHR); }
274 exp : ODD '(' exp ')'
275 { write_exp_elt_opcode (UNOP_ODD); }
278 exp : TRUNC '(' exp ')'
279 { write_exp_elt_opcode (UNOP_TRUNC); }
282 exp : SIZE exp %prec UNARY
283 { write_exp_elt_opcode (UNOP_SIZEOF); }
287 exp : INC '(' exp ')'
288 { write_exp_elt_opcode(UNOP_PREINCREMENT); }
291 exp : INC '(' exp ',' exp ')'
292 { write_exp_elt_opcode(BINOP_ASSIGN_MODIFY);
293 write_exp_elt_opcode(BINOP_ADD);
294 write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); }
297 exp : DEC '(' exp ')'
298 { write_exp_elt_opcode(UNOP_PREDECREMENT);}
301 exp : DEC '(' exp ',' exp ')'
302 { write_exp_elt_opcode(BINOP_ASSIGN_MODIFY);
303 write_exp_elt_opcode(BINOP_SUB);
304 write_exp_elt_opcode(BINOP_ASSIGN_MODIFY); }
308 { write_exp_elt_opcode (STRUCTOP_STRUCT);
309 write_exp_string ($3);
310 write_exp_elt_opcode (STRUCTOP_STRUCT); }
317 { error("Sets are not implemented.");}
320 exp : INCL '(' exp ',' exp ')'
321 { error("Sets are not implemented.");}
324 exp : EXCL '(' exp ',' exp ')'
325 { error("Sets are not implemented.");}
327 set : '{' arglist '}'
328 { error("Sets are not implemented.");}
329 | type '{' arglist '}'
330 { error("Sets are not implemented.");}
334 /* Modula-2 array subscript notation [a,b,c...] */
336 /* This function just saves the number of arguments
337 that follow in the list. It is *not* specific to
340 non_empty_arglist ']' %prec DOT
341 { write_exp_elt_opcode (MULTI_SUBSCRIPT);
342 write_exp_elt_longcst ((LONGEST) end_arglist());
343 write_exp_elt_opcode (MULTI_SUBSCRIPT); }
347 /* This is to save the value of arglist_len
348 being accumulated by an outer function call. */
349 { start_arglist (); }
350 arglist ')' %prec DOT
351 { write_exp_elt_opcode (OP_FUNCALL);
352 write_exp_elt_longcst ((LONGEST) end_arglist ());
353 write_exp_elt_opcode (OP_FUNCALL); }
363 arglist : arglist ',' exp %prec ABOVE_COMMA
373 : non_empty_arglist ',' exp %prec ABOVE_COMMA
378 exp : '{' type '}' exp %prec UNARY
379 { write_exp_elt_opcode (UNOP_MEMVAL);
380 write_exp_elt_type ($2);
381 write_exp_elt_opcode (UNOP_MEMVAL); }
384 exp : type '(' exp ')' %prec UNARY
385 { write_exp_elt_opcode (UNOP_CAST);
386 write_exp_elt_type ($1);
387 write_exp_elt_opcode (UNOP_CAST); }
394 /* Binary operators in order of decreasing precedence. Note that some
395 of these operators are overloaded! (ie. sets) */
399 { write_exp_elt_opcode (BINOP_REPEAT); }
403 { write_exp_elt_opcode (BINOP_MUL); }
407 { write_exp_elt_opcode (BINOP_DIV); }
411 { write_exp_elt_opcode (BINOP_INTDIV); }
415 { write_exp_elt_opcode (BINOP_REM); }
419 { write_exp_elt_opcode (BINOP_ADD); }
423 { write_exp_elt_opcode (BINOP_SUB); }
427 { write_exp_elt_opcode (BINOP_EQUAL); }
430 exp : exp NOTEQUAL exp
431 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
433 { write_exp_elt_opcode (BINOP_NOTEQUAL); }
437 { write_exp_elt_opcode (BINOP_LEQ); }
441 { write_exp_elt_opcode (BINOP_GEQ); }
445 { write_exp_elt_opcode (BINOP_LESS); }
449 { write_exp_elt_opcode (BINOP_GTR); }
452 exp : exp LOGICAL_AND exp
453 { write_exp_elt_opcode (BINOP_LOGICAL_AND); }
457 { write_exp_elt_opcode (BINOP_LOGICAL_OR); }
461 { write_exp_elt_opcode (BINOP_ASSIGN); }
468 { write_exp_elt_opcode (OP_BOOL);
469 write_exp_elt_longcst ((LONGEST) $1);
470 write_exp_elt_opcode (OP_BOOL); }
474 { write_exp_elt_opcode (OP_BOOL);
475 write_exp_elt_longcst ((LONGEST) $1);
476 write_exp_elt_opcode (OP_BOOL); }
480 { write_exp_elt_opcode (OP_LONG);
481 write_exp_elt_type (builtin_type_m2_int);
482 write_exp_elt_longcst ((LONGEST) $1);
483 write_exp_elt_opcode (OP_LONG); }
488 write_exp_elt_opcode (OP_LONG);
489 write_exp_elt_type (builtin_type_m2_card);
490 write_exp_elt_longcst ((LONGEST) $1);
491 write_exp_elt_opcode (OP_LONG);
496 { write_exp_elt_opcode (OP_LONG);
497 write_exp_elt_type (builtin_type_m2_char);
498 write_exp_elt_longcst ((LONGEST) $1);
499 write_exp_elt_opcode (OP_LONG); }
504 { write_exp_elt_opcode (OP_DOUBLE);
505 write_exp_elt_type (builtin_type_m2_real);
506 write_exp_elt_dblcst ($1);
507 write_exp_elt_opcode (OP_DOUBLE); }
513 /* The GDB internal variable $$, et al. */
515 { write_exp_elt_opcode (OP_LAST);
516 write_exp_elt_longcst ((LONGEST) $1);
517 write_exp_elt_opcode (OP_LAST); }
521 { write_exp_elt_opcode (OP_REGISTER);
522 write_exp_elt_longcst ((LONGEST) $1);
523 write_exp_elt_opcode (OP_REGISTER); }
526 exp : SIZE '(' type ')' %prec UNARY
527 { write_exp_elt_opcode (OP_LONG);
528 write_exp_elt_type (builtin_type_int);
529 write_exp_elt_longcst ((LONGEST) TYPE_LENGTH ($3));
530 write_exp_elt_opcode (OP_LONG); }
534 { write_exp_elt_opcode (OP_M2_STRING);
535 write_exp_string ($1);
536 write_exp_elt_opcode (OP_M2_STRING); }
539 /* This will be used for extensions later. Like adding modules. */
541 { $$ = SYMBOL_BLOCK_VALUE($1); }
546 = lookup_symbol (copy_name ($1), expression_context_block,
547 VAR_NAMESPACE, 0, NULL);
552 /* GDB scope operator */
553 fblock : block COLONCOLON BLOCKNAME
555 = lookup_symbol (copy_name ($3), $1,
556 VAR_NAMESPACE, 0, NULL);
557 if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
558 error ("No function \"%s\" in specified context.",
564 /* Useful for assigning to PROCEDURE variables */
566 { write_exp_elt_opcode(OP_VAR_VALUE);
567 write_exp_elt_block (NULL);
568 write_exp_elt_sym ($1);
569 write_exp_elt_opcode (OP_VAR_VALUE); }
572 /* GDB internal ($foo) variable */
573 variable: INTERNAL_VAR
574 { write_exp_elt_opcode (OP_INTERNALVAR);
575 write_exp_elt_intern ($1);
576 write_exp_elt_opcode (OP_INTERNALVAR); }
579 /* GDB scope operator */
580 variable: block COLONCOLON NAME
581 { struct symbol *sym;
582 sym = lookup_symbol (copy_name ($3), $1,
583 VAR_NAMESPACE, 0, NULL);
585 error ("No symbol \"%s\" in specified context.",
588 write_exp_elt_opcode (OP_VAR_VALUE);
589 /* block_found is set by lookup_symbol. */
590 write_exp_elt_block (block_found);
591 write_exp_elt_sym (sym);
592 write_exp_elt_opcode (OP_VAR_VALUE); }
595 /* Base case for variables. */
597 { struct symbol *sym;
598 int is_a_field_of_this;
600 sym = lookup_symbol (copy_name ($1),
601 expression_context_block,
607 if (symbol_read_needs_frame (sym))
609 if (innermost_block == 0 ||
610 contained_in (block_found,
612 innermost_block = block_found;
615 write_exp_elt_opcode (OP_VAR_VALUE);
616 /* We want to use the selected frame, not
617 another more inner frame which happens to
618 be in the same block. */
619 write_exp_elt_block (NULL);
620 write_exp_elt_sym (sym);
621 write_exp_elt_opcode (OP_VAR_VALUE);
625 struct minimal_symbol *msymbol;
626 register char *arg = copy_name ($1);
629 lookup_minimal_symbol (arg, NULL, NULL);
634 lookup_function_type (builtin_type_int),
637 else if (!have_full_symbols () && !have_partial_symbols ())
638 error ("No symbol table is loaded. Use the \"symbol-file\" command.");
640 error ("No symbol \"%s\" in current context.",
648 { $$ = lookup_typename (copy_name ($1),
649 expression_context_block, 0); }
660 return (MAX_OF_TYPE(builtin_type_m2_int) - b) < a;
667 return (MAX_OF_TYPE(builtin_type_m2_card) - b) < a;
671 /* Take care of parsing a number (anything that starts with a digit).
672 Set yylval and return the token type; update lexptr.
673 LEN is the number of characters in it. */
675 /*** Needs some error checking for the float case ***/
681 register char *p = lexptr;
682 register LONGEST n = 0;
683 register LONGEST prevn = 0;
684 register int c,i,ischar=0;
685 register int base = input_radix;
686 register int len = olen;
687 int unsigned_p = number_sign == 1 ? 1 : 0;
694 else if(p[len-1] == 'C' || p[len-1] == 'B')
697 ischar = p[len-1] == 'C';
701 /* Scan the number */
702 for (c = 0; c < len; c++)
704 if (p[c] == '.' && base == 10)
706 /* It's a float since it contains a point. */
707 yylval.dval = atof (p);
711 if (p[c] == '.' && base != 10)
712 error("Floating point numbers must be base 10.");
713 if (base == 10 && (p[c] < '0' || p[c] > '9'))
714 error("Invalid digit \'%c\' in number.",p[c]);
721 if( base == 8 && (c == '8' || c == '9'))
722 error("Invalid digit \'%c\' in octal number.",c);
723 if (c >= '0' && c <= '9')
727 if (base == 16 && c >= 'A' && c <= 'F')
735 if(!unsigned_p && number_sign == 1 && (prevn >= n))
736 unsigned_p=1; /* Try something unsigned */
737 /* Don't do the range check if n==i and i==0, since that special
738 case will give an overflow error. */
739 if(RANGE_CHECK && n!=i && i)
741 if((unsigned_p && (unsigned)prevn >= (unsigned)n) ||
742 ((!unsigned_p && number_sign==-1) && -prevn <= -n))
743 range_error("Overflow on numeric constant.");
749 if(*p == 'B' || *p == 'C' || *p == 'H')
750 lexptr++; /* Advance past B,C or H */
757 else if ( unsigned_p && number_sign == 1)
762 else if((unsigned_p && (n<0))) {
763 range_error("Overflow on numeric constant -- number too large.");
764 /* But, this can return if range_check == range_warn. */
779 { {'<', '>'}, NOTEQUAL },
780 { {':', '='}, ASSIGN },
783 { {':', ':'}, COLONCOLON },
787 /* Some specific keywords */
794 static struct keyword keytab[] =
797 {"IN", IN },/* Note space after IN */
798 {"AND", LOGICAL_AND},
816 {"FLOAT", FLOAT_FUNC },
821 /* Read one token, getting characters through lexptr. */
823 /* This is where we will check to make sure that the language and the operators used are
830 register int namelen;
832 register char *tokstart;
840 /* See if it is a special token of length 2 */
841 for( i = 0 ; i < sizeof tokentab2 / sizeof tokentab2[0] ; i++)
842 if(STREQN(tokentab2[i].name, tokstart, 2))
845 return tokentab2[i].token;
848 switch (c = *tokstart)
865 if (paren_depth == 0)
872 if (comma_terminates && paren_depth == 0)
878 /* Might be a floating point number. */
879 if (lexptr[1] >= '0' && lexptr[1] <= '9')
880 break; /* Falls into number code. */
887 /* These are character tokens that appear as-is in the YACC grammar */
910 for (namelen = 1; (c = tokstart[namelen]) != quote && c != '\0'; namelen++)
913 c = tokstart[++namelen];
914 if (c >= '0' && c <= '9')
916 c = tokstart[++namelen];
917 if (c >= '0' && c <= '9')
918 c = tokstart[++namelen];
922 error("Unterminated string or character constant.");
923 yylval.sval.ptr = tokstart + 1;
924 yylval.sval.length = namelen - 1;
925 lexptr += namelen + 1;
927 if(namelen == 2) /* Single character */
929 yylval.ulval = tokstart[1];
936 /* Is it a number? */
937 /* Note: We have already dealt with the case of the token '.'.
938 See case '.' above. */
939 if ((c >= '0' && c <= '9'))
942 int got_dot = 0, got_e = 0;
943 register char *p = tokstart;
948 if (!got_e && (*p == 'e' || *p == 'E'))
950 else if (!got_dot && *p == '.')
952 else if (got_e && (p[-1] == 'e' || p[-1] == 'E')
953 && (*p == '-' || *p == '+'))
954 /* This is the sign of the exponent, not the end of the
957 else if ((*p < '0' || *p > '9') &&
958 (*p < 'A' || *p > 'F') &&
959 (*p != 'H')) /* Modula-2 hexadecimal number */
962 toktype = parse_number (p - tokstart);
963 if (toktype == ERROR)
965 char *err_copy = (char *) alloca (p - tokstart + 1);
967 memcpy (err_copy, tokstart, p - tokstart);
968 err_copy[p - tokstart] = 0;
969 error ("Invalid number \"%s\".", err_copy);
975 if (!(c == '_' || c == '$'
976 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
977 /* We must have come across a bad character (e.g. ';'). */
978 error ("Invalid character '%c' in expression.", c);
980 /* It's a name. See how long it is. */
982 for (c = tokstart[namelen];
983 (c == '_' || c == '$' || (c >= '0' && c <= '9')
984 || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
985 c = tokstart[++namelen])
988 /* The token "if" terminates the expression and is NOT
989 removed from the input stream. */
990 if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
997 /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
998 and $$digits (equivalent to $<-digits> if you could type that).
999 Make token type LAST, and put the number (the digits) in yylval. */
1001 if (*tokstart == '$')
1003 register int negate = 0;
1005 /* Double dollar means negate the number and add -1 as well.
1006 Thus $$ alone means -1. */
1007 if (namelen >= 2 && tokstart[1] == '$')
1014 /* Just dollars (one or two) */
1015 yylval.lval = - negate;
1018 /* Is the rest of the token digits? */
1019 for (; c < namelen; c++)
1020 if (!(tokstart[c] >= '0' && tokstart[c] <= '9'))
1024 yylval.lval = atoi (tokstart + 1 + negate);
1026 yylval.lval = - yylval.lval;
1031 /* Handle tokens that refer to machine registers:
1032 $ followed by a register name. */
1034 if (*tokstart == '$') {
1035 for (c = 0; c < NUM_REGS; c++)
1036 if (namelen - 1 == strlen (reg_names[c])
1037 && STREQN (tokstart + 1, reg_names[c], namelen - 1))
1042 for (c = 0; c < num_std_regs; c++)
1043 if (namelen - 1 == strlen (std_regs[c].name)
1044 && STREQN (tokstart + 1, std_regs[c].name, namelen - 1))
1046 yylval.lval = std_regs[c].regnum;
1052 /* Lookup special keywords */
1053 for(i = 0 ; i < sizeof(keytab) / sizeof(keytab[0]) ; i++)
1054 if(namelen == strlen(keytab[i].keyw) && STREQN(tokstart,keytab[i].keyw,namelen))
1055 return keytab[i].token;
1057 yylval.sval.ptr = tokstart;
1058 yylval.sval.length = namelen;
1060 /* Any other names starting in $ are debugger internal variables. */
1062 if (*tokstart == '$')
1064 yylval.ivar = (struct internalvar *) lookup_internalvar (copy_name (yylval.sval) + 1);
1065 return INTERNAL_VAR;
1069 /* Use token-type BLOCKNAME for symbols that happen to be defined as
1070 functions. If this is not so, then ...
1071 Use token-type TYPENAME for symbols that happen to be defined
1072 currently as names of types; NAME for other symbols.
1073 The caller is not constrained to care about the distinction. */
1077 char *tmp = copy_name (yylval.sval);
1080 if (lookup_partial_symtab (tmp))
1082 sym = lookup_symbol (tmp, expression_context_block,
1083 VAR_NAMESPACE, 0, NULL);
1084 if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
1086 if (lookup_typename (copy_name (yylval.sval), expression_context_block, 1))
1098 case LOC_REGPARM_ADDR:
1102 case LOC_BASEREG_ARG:
1104 case LOC_CONST_BYTES:
1105 case LOC_OPTIMIZED_OUT:
1115 error("internal: Undefined class in m2lex()");
1118 error("internal: Unforseen case in m2lex()");
1123 /* Built-in BOOLEAN type. This is sort of a hack. */
1124 if(STREQN(tokstart,"TRUE",4))
1129 else if(STREQN(tokstart,"FALSE",5))
1136 /* Must be another type of name... */
1143 make_qualname(mod,ident)
1146 char *new = malloc(strlen(mod)+strlen(ident)+2);
1159 error ("A %s in expression, near `%s'.", (msg ? msg : "error"), lexptr);