diff options
author | Fred Fish <fnf@specifix.com> | 1993-01-06 16:52:10 +0000 |
---|---|---|
committer | Fred Fish <fnf@specifix.com> | 1993-01-06 16:52:10 +0000 |
commit | 81028ab0e7f01315dbb7853b81260670ba57fae0 (patch) | |
tree | b3e8e3870c1659b05b284f17fb6acc1f13083f35 /gdb/parse.c | |
parent | 5d4ec8518be9aea84cc8cae134fcca564219e438 (diff) | |
download | gdb-81028ab0e7f01315dbb7853b81260670ba57fae0.zip gdb-81028ab0e7f01315dbb7853b81260670ba57fae0.tar.gz gdb-81028ab0e7f01315dbb7853b81260670ba57fae0.tar.bz2 |
* defs.h (HOST_CHAR_BIT): New macro, defaults to either CHAR_BIT
from a configuration file (typically including <limits.h>), or to
TARGET_CHAR_BIT if CHAR_BIT is not defined.
* eval.c (evaluate_subexp): Use new BYTES_TO_EXP_ELEM macro.
* eval.c (evaluate_subexp): Add case for OP_BITSTRING.
* expprint.c (print_subexp): Use new BYTES_TO_EXP_ELEM macro.
* exppritn.c (print_subexp, dump_expression): Add case for
OP_BITSTRING.
* expression.h (OP_BITSTRING): New expression element type for
packed bitstrings.
* expression.h (EXP_ELEM_TO_BYTES, BYTES_TO_EXP_ELEM): New
macros to convert between number of expression elements and bytes
to store that many elements.
* i960-tdep.c (leafproc_return): Use new macros to access
minimal symbol name and address fields.
* m88k-pinsn.c (sprint_address): Use new macros to access
minimal symbol name and address fields.
* nindy-tdep.c (nindy_frame_chain_valid): Use new macro to access
minimal symbol address field.
* parse.c (write_exp_elt, write_exp_string, prefixify_expression,
parse_exp_1): Use new EXP_ELEM_TO_BYTES macro.
* parse.c (write_exp_string, length_of_subexp, prefixify_expression):
Use new BYTES_TO_EXP_ELEM macro.
* parse.c (write_exp_bitstring): New function to write packed
bitstrings into the expression element vector.
* parse.c (length_of_subexp, prefixify_subexp): Add case for
OP_BITSTRING.
* parser-defs.h (struct stoken): Document that it is used for
OP_BITSTRING as well as OP_STRING.
* parser-defs.h (write_exp_bitstring): Add prototype.
**** start-sanitize-chill ****
* ch-exp.y (BIT_STRING_LITERAL): Change token type to sval.
* ch-exp.y (NUM, PRED, SUCC, ABS, CARD, MAX, MIN, SIZE, UPPER,
LOWER, LENGTH): New tokens for keywords.
* ch-exp.y (chill_value_built_in_routine_call, mode_argument,
upper_lower_argument, length_argument, array_mode_name,
string_mode_name, variant_structure_mode_name): New non-terminals
and productions.
* ch-exp.y (literal): Useful production for BIT_STRING_LITERAL.
* ch-exp.y (match_bitstring_literal): New lexer support function
to recognize bitstring literals.
* ch-exp.y (tokentab6): New token table for 6 character keywords.
* ch-exp.y (tokentab5): Add LOWER, UPPER.
* ch-exp.y (tokentab4): Add PRED, SUCC, CARD, SIZE.
* ch-exp.y (tokentab3): Add NUM, ABS, MIN, MAX.
* ch-exp.y (yylex): Check tokentab6.
* ch-exp.y (yylex): Call match_bitstring_literal.
**** end-sanitize-chill ****
Diffstat (limited to 'gdb/parse.c')
-rw-r--r-- | gdb/parse.c | 102 |
1 files changed, 78 insertions, 24 deletions
diff --git a/gdb/parse.c b/gdb/parse.c index e6e6fff..81f79e7 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -126,9 +126,9 @@ write_exp_elt (expelt) if (expout_ptr >= expout_size) { expout_size *= 2; - expout = (struct expression *) xrealloc ((char *) expout, - sizeof (struct expression) - + expout_size * sizeof (union exp_element)); + expout = (struct expression *) + xrealloc ((char *) expout, sizeof (struct expression) + + EXP_ELEM_TO_BYTES (expout_size)); } expout->elts[expout_ptr++] = expelt; } @@ -233,7 +233,7 @@ write_exp_string (str) at each end to record the actual string length (not including the null byte terminator). */ - lenelt = 2 + (len + sizeof (union exp_element)) / sizeof (union exp_element); + lenelt = 2 + BYTES_TO_EXP_ELEM (len + 1); /* Ensure that we have enough available expression elements to store everything. */ @@ -243,7 +243,7 @@ write_exp_string (str) expout_size = max (expout_size * 2, expout_ptr + lenelt + 10); expout = (struct expression *) xrealloc ((char *) expout, (sizeof (struct expression) - + (expout_size * sizeof (union exp_element)))); + + EXP_ELEM_TO_BYTES (expout_size))); } /* Write the leading length expression element (which advances the current @@ -258,6 +258,54 @@ write_exp_string (str) expout_ptr += lenelt - 2; write_exp_elt_longcst ((LONGEST) len); } + +/* Add a bitstring constant to the end of the expression. + + Bitstring constants are stored by first writing an expression element + that contains the length of the bitstring (in bits), then stuffing the + bitstring constant itself into however many expression elements are + needed to hold it, and then writing another expression element that + contains the length of the bitstring. I.E. an expression element at + each end of the bitstring records the bitstring length, so you can skip + over the expression elements containing the actual bitstring bytes from + either end of the bitstring. */ + +void +write_exp_bitstring (str) + struct stoken str; +{ + register int bits = str.length; /* length in bits */ + register int len = (bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT; + register int lenelt; + register char *strdata; + + /* Compute the number of expression elements required to hold the bitstring, + along with one expression element at each end to record the actual + bitstring length in bits. */ + + lenelt = 2 + BYTES_TO_EXP_ELEM (len); + + /* Ensure that we have enough available expression elements to store + everything. */ + + if ((expout_ptr + lenelt) >= expout_size) + { + expout_size = max (expout_size * 2, expout_ptr + lenelt + 10); + expout = (struct expression *) + xrealloc ((char *) expout, (sizeof (struct expression) + + EXP_ELEM_TO_BYTES (expout_size))); + } + + /* Write the leading length expression element (which advances the current + expression element index), then write the bitstring constant, and then + write the trailing length expression element. */ + + write_exp_elt_longcst ((LONGEST) bits); + strdata = (char *) &expout->elts[expout_ptr]; + memcpy (strdata, str.ptr, len); + expout_ptr += lenelt - 2; + write_exp_elt_longcst ((LONGEST) bits); +} /* Return a null-terminated temporary copy of the name of a string token. */ @@ -278,8 +326,8 @@ static void prefixify_expression (expr) register struct expression *expr; { - register int len = sizeof (struct expression) + - expr->nelts * sizeof (union exp_element); + register int len = + sizeof (struct expression) + EXP_ELEM_TO_BYTES (expr->nelts); register struct expression *temp; register int inpos = expr->nelts, outpos = 0; @@ -312,9 +360,8 @@ length_of_subexp (expr, endpos) { /* C++ */ case OP_SCOPE: - oplen = 5 + ((longest_to_int (expr->elts[endpos - 2].longconst) - + sizeof (union exp_element)) - / sizeof (union exp_element)); + oplen = longest_to_int (expr->elts[endpos - 2].longconst); + oplen = 5 + BYTES_TO_EXP_ELEM (oplen + 1); break; case OP_LONG: @@ -366,9 +413,14 @@ length_of_subexp (expr, endpos) /* fall through */ case OP_M2_STRING: case OP_STRING: - oplen = 4 + ((longest_to_int (expr->elts[endpos - 2].longconst) - + sizeof (union exp_element)) - / sizeof (union exp_element)); + oplen = longest_to_int (expr->elts[endpos - 2].longconst); + oplen = 4 + BYTES_TO_EXP_ELEM (oplen + 1); + break; + + case OP_BITSTRING: + oplen = longest_to_int (expr->elts[endpos - 2].longconst); + oplen = (oplen + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT; + oplen = 4 + BYTES_TO_EXP_ELEM (oplen); break; case TERNOP_COND: @@ -430,9 +482,8 @@ prefixify_subexp (inexpr, outexpr, inend, outbeg) { /* C++ */ case OP_SCOPE: - oplen = 5 + ((longest_to_int (inexpr->elts[inend - 2].longconst) - + sizeof (union exp_element)) - / sizeof (union exp_element)); + oplen = longest_to_int (inexpr->elts[inend - 2].longconst); + oplen = 5 + BYTES_TO_EXP_ELEM (oplen + 1); break; case OP_LONG: @@ -483,9 +534,14 @@ prefixify_subexp (inexpr, outexpr, inend, outbeg) /* fall through */ case OP_M2_STRING: case OP_STRING: - oplen = 4 + ((longest_to_int (inexpr->elts[inend - 2].longconst) - + sizeof (union exp_element)) - / sizeof (union exp_element)); + oplen = longest_to_int (inexpr->elts[inend - 2].longconst); + oplen = 4 + BYTES_TO_EXP_ELEM (oplen + 1); + break; + + case OP_BITSTRING: + oplen = longest_to_int (inexpr->elts[inend - 2].longconst); + oplen = (oplen + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT; + oplen = 4 + BYTES_TO_EXP_ELEM (oplen); break; case TERNOP_COND: @@ -516,7 +572,7 @@ prefixify_subexp (inexpr, outexpr, inend, outbeg) to the beginning of the output. */ inend -= oplen; memcpy (&outexpr->elts[outbeg], &inexpr->elts[inend], - oplen * sizeof (union exp_element)); + EXP_ELEM_TO_BYTES (oplen)); outbeg += oplen; /* Find the lengths of the arg subexpressions. */ @@ -582,8 +638,7 @@ parse_exp_1 (stringptr, block, comma) expout_size = 10; expout_ptr = 0; expout = (struct expression *) - xmalloc (sizeof (struct expression) - + expout_size * sizeof (union exp_element)); + xmalloc (sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_size)); expout->language_defn = current_language; make_cleanup (free_current_contents, &expout); @@ -599,8 +654,7 @@ parse_exp_1 (stringptr, block, comma) expout->nelts = expout_ptr; expout = (struct expression *) xrealloc ((char *) expout, - sizeof (struct expression) - + expout_ptr * sizeof (union exp_element)); + sizeof (struct expression) + EXP_ELEM_TO_BYTES (expout_ptr));; /* Convert expression from postfix form as generated by yacc parser, to a prefix form. */ |