1 /* Subroutines shared by all languages that are variants of C.
2 Copyright (C) 1992 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
30 /* Given a chain of STRING_CST nodes,
31 concatenate them into one STRING_CST
32 and give it a suitable array-of-chars data type. */
35 combine_strings (strings
)
38 register tree value
, t
;
39 register int length
= 1;
42 int wchar_bytes
= TYPE_PRECISION (wchar_type_node
) / BITS_PER_UNIT
;
45 if (TREE_CHAIN (strings
))
47 /* More than one in the chain, so concatenate. */
50 /* Don't include the \0 at the end of each substring,
51 except for the last one.
52 Count wide strings and ordinary strings separately. */
53 for (t
= strings
; t
; t
= TREE_CHAIN (t
))
55 if (TREE_TYPE (t
) == wchar_array_type_node
)
57 wide_length
+= (TREE_STRING_LENGTH (t
) - wchar_bytes
);
61 length
+= (TREE_STRING_LENGTH (t
) - 1);
64 /* If anything is wide, the non-wides will be converted,
65 which makes them take more space. */
67 length
= length
* wchar_bytes
+ wide_length
;
69 p
= savealloc (length
);
71 /* Copy the individual strings into the new combined string.
72 If the combined string is wide, convert the chars to ints
73 for any individual strings that are not wide. */
76 for (t
= strings
; t
; t
= TREE_CHAIN (t
))
78 int len
= (TREE_STRING_LENGTH (t
)
79 - ((TREE_TYPE (t
) == wchar_array_type_node
)
81 if ((TREE_TYPE (t
) == wchar_array_type_node
) == wide_flag
)
83 bcopy (TREE_STRING_POINTER (t
), q
, len
);
89 for (i
= 0; i
< len
; i
++)
90 ((int *) q
)[i
] = TREE_STRING_POINTER (t
)[i
];
91 q
+= len
* wchar_bytes
;
97 for (i
= 0; i
< wchar_bytes
; i
++)
103 value
= make_node (STRING_CST
);
104 TREE_STRING_POINTER (value
) = p
;
105 TREE_STRING_LENGTH (value
) = length
;
106 TREE_CONSTANT (value
) = 1;
111 length
= TREE_STRING_LENGTH (value
);
112 if (TREE_TYPE (value
) == wchar_array_type_node
)
116 /* Compute the number of elements, for the array type. */
117 nchars
= wide_flag
? length
/ wchar_bytes
: length
;
119 /* Create the array type for the string constant.
120 -Wwrite-strings says make the string constant an array of const char
121 so that copying it to a non-const pointer will get a warning. */
122 if (warn_write_strings
123 && (! flag_traditional
&& ! flag_writable_strings
))
126 = build_type_variant (wide_flag
? wchar_type_node
: char_type_node
,
129 = build_array_type (elements
,
130 build_index_type (build_int_2 (nchars
- 1, 0)));
134 = build_array_type (wide_flag
? wchar_type_node
: char_type_node
,
135 build_index_type (build_int_2 (nchars
- 1, 0)));
136 TREE_CONSTANT (value
) = 1;
137 TREE_STATIC (value
) = 1;
141 /* Process the attributes listed in ATTRIBUTES
142 and install them in DECL. */
145 decl_attributes (decl
, attributes
)
146 tree decl
, attributes
;
149 for (a
= attributes
; a
; a
= TREE_CHAIN (a
))
150 if (TREE_VALUE (a
) == get_identifier ("packed"))
152 if (TREE_CODE (decl
) == FIELD_DECL
)
153 DECL_PACKED (decl
) = 1;
155 else if (TREE_VALUE (a
) != 0
156 && TREE_CODE (TREE_VALUE (a
)) == TREE_LIST
157 && TREE_PURPOSE (TREE_VALUE (a
)) == get_identifier ("mode"))
161 = IDENTIFIER_POINTER (TREE_VALUE (TREE_VALUE (a
)));
163 /* Give this decl a type with the specified mode. */
164 for (i
= 0; i
< NUM_MACHINE_MODES
; i
++)
165 if (!strcmp (specified_name
, GET_MODE_NAME (i
)))
168 = type_for_size (GET_MODE_BITSIZE (i
),
169 TREE_UNSIGNED (TREE_TYPE (decl
)));
172 TREE_TYPE (decl
) = type
;
173 DECL_SIZE (decl
) = 0;
177 error ("no data type for mode `%s'", specified_name
);
179 if (i
== NUM_MACHINE_MODES
)
180 error ("unknown machine mode `%s'", specified_name
);
182 else if (TREE_VALUE (a
) != 0
183 && TREE_CODE (TREE_VALUE (a
)) == TREE_LIST
184 && TREE_PURPOSE (TREE_VALUE (a
)) == get_identifier ("aligned"))
186 int align
= TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (a
)))
189 if (exact_log2 (align
) == -1)
190 warning_with_decl (decl
,
191 "requested alignment of `%s' is not a power of 2");
192 else if (TREE_CODE (decl
) != VAR_DECL
193 && TREE_CODE (decl
) != FIELD_DECL
)
194 warning_with_decl (decl
,
195 "alignment specified for `%s' which is not a variable");
197 DECL_ALIGN (decl
) = align
;
199 else if (TREE_VALUE (a
) != 0
200 && TREE_CODE (TREE_VALUE (a
)) == TREE_LIST
201 && TREE_PURPOSE (TREE_VALUE (a
)) == get_identifier ("format"))
203 tree list
= TREE_VALUE (TREE_VALUE (a
));
204 tree format_type
= TREE_PURPOSE (list
);
205 int format_num
= TREE_INT_CST_LOW (TREE_PURPOSE (TREE_VALUE (list
)));
206 int first_arg_num
= TREE_INT_CST_LOW (TREE_VALUE (TREE_VALUE (list
)));
209 if (TREE_CODE (decl
) != FUNCTION_DECL
)
211 warning_with_decl (decl
,
212 "argument format specified for non-function `%s'");
216 if (format_type
== get_identifier ("printf"))
218 else if (format_type
== get_identifier ("scanf"))
222 warning_with_decl (decl
,"unrecognized format specifier for `%s'");
226 if (first_arg_num
!= 0 && first_arg_num
<= format_num
)
228 warning_with_decl (decl
,
229 "format string arg follows the args to be formatted, for `%s'");
233 record_format_info (DECL_NAME (decl
), is_scan
, format_num
,
239 c_expand_expr_stmt (expr
)
242 /* Do default conversion if safe and possibly important,
243 in case within ({...}). */
244 if ((TREE_CODE (TREE_TYPE (expr
)) == ARRAY_TYPE
&& lvalue_p (expr
))
245 || TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
)
246 expr
= default_conversion (expr
);
248 if (TREE_TYPE (expr
) != error_mark_node
249 && TYPE_SIZE (TREE_TYPE (expr
)) == 0
250 && TREE_CODE (TREE_TYPE (expr
)) != ARRAY_TYPE
)
251 error ("expression statement has incomplete type");
253 expand_expr_stmt (expr
);
256 /* Validate the expression after `case' and apply default promotions. */
259 check_case_value (value
)
262 if (value
== NULL_TREE
)
265 /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */
266 if (TREE_CODE (value
) == NON_LVALUE_EXPR
)
267 value
= TREE_OPERAND (value
, 0);
269 if (TREE_CODE (value
) != INTEGER_CST
270 && value
!= error_mark_node
)
272 error ("case label does not reduce to an integer constant");
273 value
= error_mark_node
;
276 /* Promote char or short to int. */
277 value
= default_conversion (value
);
282 /* Return an integer type with BITS bits of precision,
283 that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */
286 type_for_size (bits
, unsignedp
)
290 if (bits
<= TYPE_PRECISION (signed_char_type_node
))
291 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
293 if (bits
<= TYPE_PRECISION (short_integer_type_node
))
294 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
296 if (bits
<= TYPE_PRECISION (integer_type_node
))
297 return unsignedp
? unsigned_type_node
: integer_type_node
;
299 if (bits
<= TYPE_PRECISION (long_integer_type_node
))
300 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
302 if (bits
<= TYPE_PRECISION (long_long_integer_type_node
))
303 return (unsignedp
? long_long_unsigned_type_node
304 : long_long_integer_type_node
);
309 /* Return a data type that has machine mode MODE.
310 If the mode is an integer,
311 then UNSIGNEDP selects between signed and unsigned types. */
314 type_for_mode (mode
, unsignedp
)
315 enum machine_mode mode
;
318 if (mode
== TYPE_MODE (signed_char_type_node
))
319 return unsignedp
? unsigned_char_type_node
: signed_char_type_node
;
321 if (mode
== TYPE_MODE (short_integer_type_node
))
322 return unsignedp
? short_unsigned_type_node
: short_integer_type_node
;
324 if (mode
== TYPE_MODE (integer_type_node
))
325 return unsignedp
? unsigned_type_node
: integer_type_node
;
327 if (mode
== TYPE_MODE (long_integer_type_node
))
328 return unsignedp
? long_unsigned_type_node
: long_integer_type_node
;
330 if (mode
== TYPE_MODE (long_long_integer_type_node
))
331 return unsignedp
? long_long_unsigned_type_node
: long_long_integer_type_node
;
333 if (mode
== TYPE_MODE (float_type_node
))
334 return float_type_node
;
336 if (mode
== TYPE_MODE (double_type_node
))
337 return double_type_node
;
339 if (mode
== TYPE_MODE (long_double_type_node
))
340 return long_double_type_node
;
342 if (mode
== TYPE_MODE (build_pointer_type (char_type_node
)))
343 return build_pointer_type (char_type_node
);
345 if (mode
== TYPE_MODE (build_pointer_type (integer_type_node
)))
346 return build_pointer_type (integer_type_node
);
351 /* Print an error message for invalid operands to arith operation CODE.
352 NOP_EXPR is used as a special case (see truthvalue_conversion). */
355 binary_op_error (code
)
358 register char *opname
;
362 error ("invalid truth-value expression");
372 opname
= "max"; break;
374 opname
= "min"; break;
376 opname
= "=="; break;
378 opname
= "!="; break;
380 opname
= "<="; break;
382 opname
= ">="; break;
388 opname
= "<<"; break;
390 opname
= ">>"; break;
399 case TRUTH_ANDIF_EXPR
:
400 opname
= "&&"; break;
401 case TRUTH_ORIF_EXPR
:
402 opname
= "||"; break;
406 error ("invalid operands to binary %s", opname
);
409 /* Subroutine of build_binary_op, used for comparison operations.
410 See if the operands have both been converted from subword integer types
411 and, if so, perhaps change them both back to their original type.
413 The arguments of this function are all pointers to local variables
414 of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1,
415 RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE.
417 If this function returns nonzero, it means that the comparison has
418 a constant value. What this function returns is an expression for
422 shorten_compare (op0_ptr
, op1_ptr
, restype_ptr
, rescode_ptr
)
423 tree
*op0_ptr
, *op1_ptr
;
425 enum tree_code
*rescode_ptr
;
430 int unsignedp0
, unsignedp1
;
432 tree primop0
, primop1
;
433 enum tree_code code
= *rescode_ptr
;
435 /* Throw away any conversions to wider types
436 already present in the operands. */
438 primop0
= get_narrower (op0
, &unsignedp0
);
439 primop1
= get_narrower (op1
, &unsignedp1
);
441 /* Handle the case that OP0 does not *contain* a conversion
442 but it *requires* conversion to FINAL_TYPE. */
444 if (op0
== primop0
&& TREE_TYPE (op0
) != *restype_ptr
)
445 unsignedp0
= TREE_UNSIGNED (TREE_TYPE (op0
));
446 if (op1
== primop1
&& TREE_TYPE (op1
) != *restype_ptr
)
447 unsignedp1
= TREE_UNSIGNED (TREE_TYPE (op1
));
449 /* If one of the operands must be floated, we cannot optimize. */
450 real1
= TREE_CODE (TREE_TYPE (primop0
)) == REAL_TYPE
;
451 real2
= TREE_CODE (TREE_TYPE (primop1
)) == REAL_TYPE
;
453 /* If first arg is constant, swap the args (changing operation
454 so value is preserved), for canonicalization. */
456 if (TREE_CONSTANT (primop0
))
458 register tree tem
= primop0
;
459 register int temi
= unsignedp0
;
467 unsignedp0
= unsignedp1
;
491 /* If comparing an integer against a constant more bits wide,
492 maybe we can deduce a value of 1 or 0 independent of the data.
493 Or else truncate the constant now
494 rather than extend the variable at run time.
496 This is only interesting if the constant is the wider arg.
497 Also, it is not safe if the constant is unsigned and the
498 variable arg is signed, since in this case the variable
499 would be sign-extended and then regarded as unsigned.
500 Our technique fails in this case because the lowest/highest
501 possible unsigned results don't follow naturally from the
502 lowest/highest possible values of the variable operand.
503 For just EQ_EXPR and NE_EXPR there is another technique that
504 could be used: see if the constant can be faithfully represented
505 in the other operand's type, by truncating it and reextending it
506 and see if that preserves the constant's value. */
509 && TREE_CODE (primop1
) == INTEGER_CST
510 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
))
512 int min_gt
, max_gt
, min_lt
, max_lt
;
514 /* 1 if comparison is nominally unsigned. */
515 int unsignedp
= TREE_UNSIGNED (*restype_ptr
);
518 type
= signed_or_unsigned_type (unsignedp0
, TREE_TYPE (primop0
));
520 maxval
= TYPE_MAX_VALUE (type
);
521 minval
= TYPE_MIN_VALUE (type
);
523 if (unsignedp
&& !unsignedp0
)
524 *restype_ptr
= signed_type (*restype_ptr
);
526 if (TREE_TYPE (primop1
) != *restype_ptr
)
527 primop1
= convert (*restype_ptr
, primop1
);
528 if (type
!= *restype_ptr
)
530 minval
= convert (*restype_ptr
, minval
);
531 maxval
= convert (*restype_ptr
, maxval
);
534 if (unsignedp
&& unsignedp0
)
536 min_gt
= INT_CST_LT_UNSIGNED (primop1
, minval
);
537 max_gt
= INT_CST_LT_UNSIGNED (primop1
, maxval
);
538 min_lt
= INT_CST_LT_UNSIGNED (minval
, primop1
);
539 max_lt
= INT_CST_LT_UNSIGNED (maxval
, primop1
);
543 min_gt
= INT_CST_LT (primop1
, minval
);
544 max_gt
= INT_CST_LT (primop1
, maxval
);
545 min_lt
= INT_CST_LT (minval
, primop1
);
546 max_lt
= INT_CST_LT (maxval
, primop1
);
550 /* This used to be a switch, but Genix compiler can't handle that. */
553 if (max_lt
|| min_gt
)
554 val
= integer_one_node
;
556 else if (code
== EQ_EXPR
)
558 if (max_lt
|| min_gt
)
559 val
= integer_zero_node
;
561 else if (code
== LT_EXPR
)
564 val
= integer_one_node
;
566 val
= integer_zero_node
;
568 else if (code
== GT_EXPR
)
571 val
= integer_one_node
;
573 val
= integer_zero_node
;
575 else if (code
== LE_EXPR
)
578 val
= integer_one_node
;
580 val
= integer_zero_node
;
582 else if (code
== GE_EXPR
)
585 val
= integer_one_node
;
587 val
= integer_zero_node
;
590 /* If primop0 was sign-extended and unsigned comparison specd,
591 we did a signed comparison above using the signed type bounds.
592 But the comparison we output must be unsigned.
594 Also, for inequalities, VAL is no good; but if the signed
595 comparison had *any* fixed result, it follows that the
596 unsigned comparison just tests the sign in reverse
597 (positive values are LE, negative ones GE).
598 So we can generate an unsigned comparison
599 against an extreme value of the signed type. */
601 if (unsignedp
&& !unsignedp0
)
608 primop1
= TYPE_MIN_VALUE (type
);
614 primop1
= TYPE_MAX_VALUE (type
);
618 type
= unsigned_type (type
);
621 if (max_lt
&& !unsignedp0
)
623 /* This is the case of (char)x >?< 0x80, which people used to use
624 expecting old C compilers to change the 0x80 into -0x80. */
625 if (val
== integer_zero_node
)
626 warning ("comparison is always 0 due to limited range of data type");
627 if (val
== integer_one_node
)
628 warning ("comparison is always 1 due to limited range of data type");
631 if (min_gt
&& unsignedp0
)
633 /* This is the case of (unsigned char)x >?< -1. */
634 if (val
== integer_zero_node
)
635 warning ("comparison is always 0 due to limited range of data type");
636 if (val
== integer_one_node
)
637 warning ("comparison is always 1 due to limited range of data type");
642 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
643 if (TREE_SIDE_EFFECTS (primop0
))
644 return build (COMPOUND_EXPR
, TREE_TYPE (val
), primop0
, val
);
648 /* Value is not predetermined, but do the comparison
649 in the type of the operand that is not constant.
650 TYPE is already properly set. */
652 else if (real1
&& real2
653 && TYPE_PRECISION (TREE_TYPE (primop0
)) == TYPE_PRECISION (TREE_TYPE (primop1
)))
654 type
= TREE_TYPE (primop0
);
656 /* If args' natural types are both narrower than nominal type
657 and both extend in the same manner, compare them
658 in the type of the wider arg.
659 Otherwise must actually extend both to the nominal
660 common type lest different ways of extending
662 (eg, (short)-1 == (unsigned short)-1 should be 0.) */
664 else if (unsignedp0
== unsignedp1
&& real1
== real2
665 && TYPE_PRECISION (TREE_TYPE (primop0
)) < TYPE_PRECISION (*restype_ptr
)
666 && TYPE_PRECISION (TREE_TYPE (primop1
)) < TYPE_PRECISION (*restype_ptr
))
668 type
= common_type (TREE_TYPE (primop0
), TREE_TYPE (primop1
));
669 type
= signed_or_unsigned_type (unsignedp0
670 || TREE_UNSIGNED (*restype_ptr
),
672 /* Make sure shorter operand is extended the right way
673 to match the longer operand. */
674 primop0
= convert (signed_or_unsigned_type (unsignedp0
, TREE_TYPE (primop0
)),
676 primop1
= convert (signed_or_unsigned_type (unsignedp1
, TREE_TYPE (primop1
)),
681 /* Here we must do the comparison on the nominal type
682 using the args exactly as we received them. */
687 if (!real1
&& !real2
&& integer_zerop (primop1
)
688 && TREE_UNSIGNED (TREE_TYPE (primop0
)))
695 warning ("unsigned value >= 0 is always 1");
696 value
= integer_one_node
;
701 warning ("unsigned value < 0 is always 0");
702 value
= integer_zero_node
;
707 /* Don't forget to evaluate PRIMOP0 if it has side effects. */
708 if (TREE_SIDE_EFFECTS (primop0
))
709 return build (COMPOUND_EXPR
, TREE_TYPE (value
),
716 *op0_ptr
= convert (type
, primop0
);
717 *op1_ptr
= convert (type
, primop1
);
719 *restype_ptr
= integer_type_node
;
724 /* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
725 or validate its data type for an `if' or `while' statement or ?..: exp.
727 This preparation consists of taking the ordinary
728 representation of an expression expr and producing a valid tree
729 boolean expression describing whether expr is nonzero. We could
730 simply always do build_binary_op (NE_EXPR, expr, integer_zero_node, 1),
731 but we optimize comparisons, &&, ||, and !.
733 The resulting type should always be `integer_type_node'. */
736 truthvalue_conversion (expr
)
739 register enum tree_code code
;
741 switch (TREE_CODE (expr
))
743 /* It is simpler and generates better code to have only TRUTH_*_EXPR
744 or comparison expressions as truth values at this level. */
747 /* A one-bit unsigned bit-field is already acceptable. */
748 if (1 == TREE_INT_CST_LOW (DECL_SIZE (TREE_OPERAND (expr
, 1)))
749 && TREE_UNSIGNED (TREE_OPERAND (expr
, 1)))
755 /* It is simpler and generates better code to have only TRUTH_*_EXPR
756 or comparison expressions as truth values at this level. */
758 if (integer_zerop (TREE_OPERAND (expr
, 1)))
759 return build_unary_op (TRUTH_NOT_EXPR
, TREE_OPERAND (expr
, 0), 0);
761 case NE_EXPR
: case LE_EXPR
: case GE_EXPR
: case LT_EXPR
: case GT_EXPR
:
762 case TRUTH_ANDIF_EXPR
:
763 case TRUTH_ORIF_EXPR
:
770 return integer_zerop (expr
) ? integer_zero_node
: integer_one_node
;
773 return real_zerop (expr
) ? integer_zero_node
: integer_one_node
;
776 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 0)))
777 return build (COMPOUND_EXPR
, integer_type_node
,
778 TREE_OPERAND (expr
, 0), integer_one_node
);
780 return integer_one_node
;
786 /* These don't change whether an object is non-zero or zero. */
787 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
791 /* These don't change whether an object is zero or non-zero, but
792 we can't ignore them if their second arg has side-effects. */
793 if (TREE_SIDE_EFFECTS (TREE_OPERAND (expr
, 1)))
794 return build (COMPOUND_EXPR
, integer_type_node
, TREE_OPERAND (expr
, 1),
795 truthvalue_conversion (TREE_OPERAND (expr
, 0)));
797 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
800 /* Distribute the conversion into the arms of a COND_EXPR. */
801 return fold (build (COND_EXPR
, integer_type_node
, TREE_OPERAND (expr
, 0),
802 truthvalue_conversion (TREE_OPERAND (expr
, 1)),
803 truthvalue_conversion (TREE_OPERAND (expr
, 2))));
806 /* Don't cancel the effect of a CONVERT_EXPR from a REFERENCE_TYPE,
807 since that affects how `default_conversion' will behave. */
808 if (TREE_CODE (TREE_TYPE (expr
)) == REFERENCE_TYPE
809 || TREE_CODE (TREE_TYPE (TREE_OPERAND (expr
, 0))) == REFERENCE_TYPE
)
811 /* fall through... */
813 /* If this is widening the argument, we can ignore it. */
814 if (TYPE_PRECISION (TREE_TYPE (expr
))
815 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (expr
, 0))))
816 return truthvalue_conversion (TREE_OPERAND (expr
, 0));
821 /* These can be changed into a comparison of the two objects. */
822 if (TREE_TYPE (TREE_OPERAND (expr
, 0))
823 == TREE_TYPE (TREE_OPERAND (expr
, 1)))
824 return build_binary_op (NE_EXPR
, TREE_OPERAND (expr
, 0),
825 TREE_OPERAND (expr
, 1), 1);
826 return build_binary_op (NE_EXPR
, TREE_OPERAND (expr
, 0),
827 fold (build1 (NOP_EXPR
,
828 TREE_TYPE (TREE_OPERAND (expr
, 0)),
829 TREE_OPERAND (expr
, 1))), 1);
832 return build_binary_op (NE_EXPR
, expr
, integer_zero_node
, 1);
835 /* Read the rest of a #-directive from input stream FINPUT.
836 In normal use, the directive name and the white space after it
837 have already been read, so they won't be included in the result.
838 We allow for the fact that the directive line may contain
839 a newline embedded within a character or string literal which forms
840 a part of the directive.
842 The value is a string in a reusable buffer. It remains valid
843 only until the next time this function is called. */
846 get_directive_line (finput
)
847 register FILE *finput
;
849 static char *directive_buffer
= NULL
;
850 static unsigned buffer_length
= 0;
852 register char *buffer_limit
;
853 register int looking_for
= 0;
854 register int char_escaped
= 0;
856 if (buffer_length
== 0)
858 directive_buffer
= (char *)xmalloc (128);
862 buffer_limit
= &directive_buffer
[buffer_length
];
864 for (p
= directive_buffer
; ; )
868 /* Make buffer bigger if it is full. */
869 if (p
>= buffer_limit
)
871 register unsigned bytes_used
= (p
- directive_buffer
);
875 = (char *)xrealloc (directive_buffer
, buffer_length
);
876 p
= &directive_buffer
[bytes_used
];
877 buffer_limit
= &directive_buffer
[buffer_length
];
882 /* Discard initial whitespace. */
883 if ((c
== ' ' || c
== '\t') && p
== directive_buffer
)
886 /* Detect the end of the directive. */
887 if (c
== '\n' && looking_for
== 0)
896 return directive_buffer
;
898 /* Handle string and character constant syntax. */
901 if (looking_for
== c
&& !char_escaped
)
902 looking_for
= 0; /* Found terminator... stop looking. */
905 if (c
== '\'' || c
== '"')
906 looking_for
= c
; /* Don't stop buffering until we see another
907 another one of these (or an EOF). */
909 /* Handle backslash. */
910 char_escaped
= (c
== '\\' && ! char_escaped
);