1 /* CPP Library - lexical analysis.
2 Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
3 Contributed by Per Bothner, 1994-95.
4 Based on CCCP program by Paul Rubin, June 1986
5 Adapted to ANSI C, Richard Stallman, Jan 1987
6 Broken out to separate file, Zack Weinberg, Mar 2000
8 This program is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #include "coretypes.h"
39 enum spell_type category
;
40 const unsigned char *name
;
43 static const unsigned char *const digraph_spellings
[] =
44 { U
"%:", U
"%:%:", U
"<:", U
":>", U
"<%", U
"%>" };
46 #define OP(e, s) { SPELL_OPERATOR, U s },
47 #define TK(e, s) { s, U STRINGX (e) },
48 static const struct token_spelling token_spellings
[N_TTYPES
] = { TTYPE_TABLE
};
52 #define TOKEN_SPELL(token) (token_spellings[(token)->type].category)
53 #define TOKEN_NAME(token) (token_spellings[(token)->type].name)
55 static void add_line_note
PARAMS ((cpp_buffer
*, const uchar
*, unsigned int));
56 static int skip_line_comment
PARAMS ((cpp_reader
*));
57 static void skip_whitespace
PARAMS ((cpp_reader
*, cppchar_t
));
58 static cpp_hashnode
*lex_identifier
PARAMS ((cpp_reader
*, const uchar
*));
59 static void lex_number
PARAMS ((cpp_reader
*, cpp_string
*));
60 static bool forms_identifier_p
PARAMS ((cpp_reader
*, int));
61 static void lex_string
PARAMS ((cpp_reader
*, cpp_token
*, const uchar
*));
62 static void save_comment
PARAMS ((cpp_reader
*, cpp_token
*, const uchar
*,
64 static void create_literal
PARAMS ((cpp_reader
*, cpp_token
*, const uchar
*,
65 unsigned int, enum cpp_ttype
));
66 static int name_p
PARAMS ((cpp_reader
*, const cpp_string
*));
67 static cppchar_t maybe_read_ucn
PARAMS ((cpp_reader
*, const uchar
**));
68 static tokenrun
*next_tokenrun
PARAMS ((tokenrun
*));
70 static unsigned int hex_digit_value
PARAMS ((unsigned int));
71 static _cpp_buff
*new_buff
PARAMS ((size_t));
76 Compares, the token TOKEN to the NUL-terminated string STRING.
77 TOKEN must be a CPP_NAME. Returns 1 for equal, 0 for unequal. */
79 cpp_ideq (token
, string
)
80 const cpp_token
*token
;
83 if (token
->type
!= CPP_NAME
)
86 return !ustrcmp (NODE_NAME (token
->val
.node
), (const uchar
*) string
);
89 /* Record a note TYPE at byte POS into the current cleaned logical
92 add_line_note (buffer
, pos
, type
)
97 if (buffer
->notes_used
== buffer
->notes_cap
)
99 buffer
->notes_cap
= buffer
->notes_cap
* 2 + 200;
100 buffer
->notes
= (_cpp_line_note
*)
101 xrealloc (buffer
->notes
, buffer
->notes_cap
* sizeof (_cpp_line_note
));
104 buffer
->notes
[buffer
->notes_used
].pos
= pos
;
105 buffer
->notes
[buffer
->notes_used
].type
= type
;
106 buffer
->notes_used
++;
109 /* Returns with a logical line that contains no escaped newlines or
110 trigraphs. This is a time-critical inner loop. */
112 _cpp_clean_line (pfile
)
119 buffer
= pfile
->buffer
;
120 buffer
->cur_note
= buffer
->notes_used
= 0;
121 buffer
->cur
= buffer
->line_base
= buffer
->next_line
;
122 buffer
->need_line
= false;
123 s
= buffer
->next_line
- 1;
125 if (!buffer
->from_stage3
)
134 if (c
== '\n' || c
== '\r')
136 /* Handle DOS line endings. */
137 if (c
== '\r' && s
!= buffer
->rlimit
&& s
[1] == '\n')
139 if (s
== buffer
->rlimit
)
144 while (p
!= buffer
->next_line
&& is_nvspace (p
[-1]))
146 if (p
== buffer
->next_line
|| p
[-1] != '\\')
149 add_line_note (buffer
, p
- 1, p
!= d
? ' ': '\\');
151 buffer
->next_line
= p
- 1;
153 else if (c
== '?' && s
[1] == '?' && _cpp_trigraph_map
[s
[2]])
155 /* Add a note regardless, for the benefit of -Wtrigraphs. */
156 add_line_note (buffer
, d
, s
[2]);
157 if (CPP_OPTION (pfile
, trigraphs
))
159 *d
= _cpp_trigraph_map
[s
[2]];
169 while (*s
!= '\n' && *s
!= '\r');
172 /* Handle DOS line endings. */
173 if (*s
== '\r' && s
!= buffer
->rlimit
&& s
[1] == '\n')
178 /* A sentinel note that should never be processed. */
179 add_line_note (buffer
, d
+ 1, '\n');
180 buffer
->next_line
= s
+ 1;
183 /* Process the notes created by add_line_note as far as the current
186 _cpp_process_line_notes (pfile
, in_comment
)
190 cpp_buffer
*buffer
= pfile
->buffer
;
194 _cpp_line_note
*note
= &buffer
->notes
[buffer
->cur_note
];
197 if (note
->pos
> buffer
->cur
)
201 col
= CPP_BUF_COLUMN (buffer
, note
->pos
+ 1);
203 if (note
->type
== '\\' || note
->type
== ' ')
205 if (note
->type
== ' ' && !in_comment
)
206 cpp_error_with_line (pfile
, DL_WARNING
, pfile
->line
, col
,
207 "backslash and newline separated by space");
209 if (buffer
->next_line
> buffer
->rlimit
)
211 cpp_error_with_line (pfile
, DL_PEDWARN
, pfile
->line
, col
,
212 "backslash-newline at end of file");
213 /* Prevent "no newline at end of file" warning. */
214 buffer
->next_line
= buffer
->rlimit
;
217 buffer
->line_base
= note
->pos
;
220 else if (_cpp_trigraph_map
[note
->type
])
222 if (!in_comment
&& CPP_OPTION (pfile
, warn_trigraphs
))
224 if (CPP_OPTION (pfile
, trigraphs
))
225 cpp_error_with_line (pfile
, DL_WARNING
, pfile
->line
, col
,
226 "trigraph ??%c converted to %c",
228 (int) _cpp_trigraph_map
[note
->type
]);
230 cpp_error_with_line (pfile
, DL_WARNING
, pfile
->line
, col
,
231 "trigraph ??%c ignored",
240 /* Skip a C-style block comment. We find the end of the comment by
241 seeing if an asterisk is before every '/' we encounter. Returns
242 nonzero if comment terminated by EOF, zero otherwise.
244 Buffer->cur points to the initial asterisk of the comment. */
246 _cpp_skip_block_comment (pfile
)
249 cpp_buffer
*buffer
= pfile
->buffer
;
253 if (*buffer
->cur
== '/')
260 /* People like decorating comments with '*', so check for '/'
261 instead for efficiency. */
264 if (buffer
->cur
[-2] == '*')
267 /* Warn about potential nested comments, but not if the '/'
268 comes immediately before the true comment delimiter.
269 Don't bother to get it right across escaped newlines. */
270 if (CPP_OPTION (pfile
, warn_comments
)
271 && buffer
->cur
[0] == '*' && buffer
->cur
[1] != '/')
272 cpp_error_with_line (pfile
, DL_WARNING
,
273 pfile
->line
, CPP_BUF_COL (buffer
),
274 "\"/*\" within comment");
279 _cpp_process_line_notes (pfile
, true);
280 if (buffer
->next_line
>= buffer
->rlimit
)
282 _cpp_clean_line (pfile
);
290 /* Skip a C++ line comment, leaving buffer->cur pointing to the
291 terminating newline. Handles escaped newlines. Returns nonzero
292 if a multiline comment. */
294 skip_line_comment (pfile
)
297 cpp_buffer
*buffer
= pfile
->buffer
;
298 unsigned int orig_line
= pfile
->line
;
300 while (*buffer
->cur
!= '\n')
303 _cpp_process_line_notes (pfile
, true);
304 return orig_line
!= pfile
->line
;
307 /* Skips whitespace, saving the next non-whitespace character. */
309 skip_whitespace (pfile
, c
)
313 cpp_buffer
*buffer
= pfile
->buffer
;
314 bool saw_NUL
= false;
318 /* Horizontal space always OK. */
319 if (c
== ' ' || c
== '\t')
321 /* Just \f \v or \0 left. */
324 else if (pfile
->state
.in_directive
&& CPP_PEDANTIC (pfile
))
325 cpp_error_with_line (pfile
, DL_PEDWARN
, pfile
->line
,
326 CPP_BUF_COL (buffer
),
327 "%s in preprocessing directive",
328 c
== '\f' ? "form feed" : "vertical tab");
332 /* We only want non-vertical space, i.e. ' ' \t \f \v \0. */
333 while (is_nvspace (c
));
336 cpp_error (pfile
, DL_WARNING
, "null character(s) ignored");
341 /* See if the characters of a number token are valid in a name (no
344 name_p (pfile
, string
)
346 const cpp_string
*string
;
350 for (i
= 0; i
< string
->len
; i
++)
351 if (!is_idchar (string
->text
[i
]))
357 /* Returns TRUE if the sequence starting at buffer->cur is invalid in
358 an identifier. FIRST is TRUE if this starts an identifier. */
360 forms_identifier_p (pfile
, first
)
364 cpp_buffer
*buffer
= pfile
->buffer
;
366 if (*buffer
->cur
== '$')
368 if (!CPP_OPTION (pfile
, dollars_in_ident
))
372 if (CPP_PEDANTIC (pfile
)
373 && !pfile
->state
.skipping
374 && !pfile
->warned_dollar
)
376 pfile
->warned_dollar
= true;
377 cpp_error (pfile
, DL_PEDWARN
, "'$' in identifier or number");
383 /* Is this a syntactically valid UCN? */
384 if (0 && *buffer
->cur
== '\\'
385 && (buffer
->cur
[1] == 'u' || buffer
->cur
[1] == 'U'))
388 if (_cpp_valid_ucn (pfile
, &buffer
->cur
, 1 + !first
))
396 /* Lex an identifier starting at BUFFER->CUR - 1. */
397 static cpp_hashnode
*
398 lex_identifier (pfile
, base
)
402 cpp_hashnode
*result
;
407 cur
= pfile
->buffer
->cur
;
409 /* N.B. ISIDNUM does not include $. */
410 while (ISIDNUM (*cur
))
413 pfile
->buffer
->cur
= cur
;
415 while (forms_identifier_p (pfile
, false));
417 result
= (cpp_hashnode
*)
418 ht_lookup (pfile
->hash_table
, base
, cur
- base
, HT_ALLOC
);
420 /* Rarely, identifiers require diagnostics when lexed. */
421 if (__builtin_expect ((result
->flags
& NODE_DIAGNOSTIC
)
422 && !pfile
->state
.skipping
, 0))
424 /* It is allowed to poison the same identifier twice. */
425 if ((result
->flags
& NODE_POISONED
) && !pfile
->state
.poisoned_ok
)
426 cpp_error (pfile
, DL_ERROR
, "attempt to use poisoned \"%s\"",
429 /* Constraint 6.10.3.5: __VA_ARGS__ should only appear in the
430 replacement list of a variadic macro. */
431 if (result
== pfile
->spec_nodes
.n__VA_ARGS__
432 && !pfile
->state
.va_args_ok
)
433 cpp_error (pfile
, DL_PEDWARN
,
434 "__VA_ARGS__ can only appear in the expansion of a C99 variadic macro");
440 /* Lex a number to NUMBER starting at BUFFER->CUR - 1. */
442 lex_number (pfile
, number
)
450 base
= pfile
->buffer
->cur
- 1;
453 cur
= pfile
->buffer
->cur
;
455 /* N.B. ISIDNUM does not include $. */
456 while (ISIDNUM (*cur
) || *cur
== '.' || VALID_SIGN (*cur
, cur
[-1]))
459 pfile
->buffer
->cur
= cur
;
461 while (forms_identifier_p (pfile
, false));
463 number
->len
= cur
- base
;
464 dest
= _cpp_unaligned_alloc (pfile
, number
->len
+ 1);
465 memcpy (dest
, base
, number
->len
);
466 dest
[number
->len
] = '\0';
470 /* Create a token of type TYPE with a literal spelling. */
472 create_literal (pfile
, token
, base
, len
, type
)
479 uchar
*dest
= _cpp_unaligned_alloc (pfile
, len
+ 1);
481 memcpy (dest
, base
, len
);
484 token
->val
.str
.len
= len
;
485 token
->val
.str
.text
= dest
;
488 /* Lexes a string, character constant, or angle-bracketed header file
489 name. The stored string contains the spelling, including opening
490 quote and leading any leading 'L'. It returns the type of the
491 literal, or CPP_OTHER if it was not properly terminated.
493 The spelling is NUL-terminated, but it is not guaranteed that this
494 is the first NUL since embedded NULs are preserved. */
496 lex_string (pfile
, token
, base
)
501 bool saw_NUL
= false;
503 cppchar_t terminator
;
508 if (terminator
== 'L')
510 if (terminator
== '\"')
511 type
= *base
== 'L' ? CPP_WSTRING
: CPP_STRING
;
512 else if (terminator
== '\'')
513 type
= *base
== 'L' ? CPP_WCHAR
: CPP_CHAR
;
515 terminator
= '>', type
= CPP_HEADER_NAME
;
519 cppchar_t c
= *cur
++;
521 /* In #include-style directives, terminators are not escapable. */
522 if (c
== '\\' && !pfile
->state
.angled_headers
&& *cur
!= '\n')
524 else if (c
== terminator
)
536 if (saw_NUL
&& !pfile
->state
.skipping
)
537 cpp_error (pfile
, DL_WARNING
, "null character(s) preserved in literal");
539 pfile
->buffer
->cur
= cur
;
540 create_literal (pfile
, token
, base
, cur
- base
, type
);
543 /* The stored comment includes the comment start and any terminator. */
545 save_comment (pfile
, token
, from
, type
)
548 const unsigned char *from
;
551 unsigned char *buffer
;
552 unsigned int len
, clen
;
554 len
= pfile
->buffer
->cur
- from
+ 1; /* + 1 for the initial '/'. */
556 /* C++ comments probably (not definitely) have moved past a new
557 line, which we don't want to save in the comment. */
558 if (is_vspace (pfile
->buffer
->cur
[-1]))
561 /* If we are currently in a directive, then we need to store all
562 C++ comments as C comments internally, and so we need to
563 allocate a little extra space in that case.
565 Note that the only time we encounter a directive here is
566 when we are saving comments in a "#define". */
567 clen
= (pfile
->state
.in_directive
&& type
== '/') ? len
+ 2 : len
;
569 buffer
= _cpp_unaligned_alloc (pfile
, clen
);
571 token
->type
= CPP_COMMENT
;
572 token
->val
.str
.len
= clen
;
573 token
->val
.str
.text
= buffer
;
576 memcpy (buffer
+ 1, from
, len
- 1);
578 /* Finish conversion to a C comment, if necessary. */
579 if (pfile
->state
.in_directive
&& type
== '/')
582 buffer
[clen
- 2] = '*';
583 buffer
[clen
- 1] = '/';
587 /* Allocate COUNT tokens for RUN. */
589 _cpp_init_tokenrun (run
, count
)
593 run
->base
= xnewvec (cpp_token
, count
);
594 run
->limit
= run
->base
+ count
;
598 /* Returns the next tokenrun, or creates one if there is none. */
603 if (run
->next
== NULL
)
605 run
->next
= xnew (tokenrun
);
606 run
->next
->prev
= run
;
607 _cpp_init_tokenrun (run
->next
, 250);
613 /* Allocate a single token that is invalidated at the same time as the
614 rest of the tokens on the line. Has its line and col set to the
615 same as the last lexed token, so that diagnostics appear in the
618 _cpp_temp_token (pfile
)
621 cpp_token
*old
, *result
;
623 old
= pfile
->cur_token
- 1;
624 if (pfile
->cur_token
== pfile
->cur_run
->limit
)
626 pfile
->cur_run
= next_tokenrun (pfile
->cur_run
);
627 pfile
->cur_token
= pfile
->cur_run
->base
;
630 result
= pfile
->cur_token
++;
631 result
->line
= old
->line
;
632 result
->col
= old
->col
;
636 /* Lex a token into RESULT (external interface). Takes care of issues
637 like directive handling, token lookahead, multiple include
638 optimization and skipping. */
640 _cpp_lex_token (pfile
)
647 if (pfile
->cur_token
== pfile
->cur_run
->limit
)
649 pfile
->cur_run
= next_tokenrun (pfile
->cur_run
);
650 pfile
->cur_token
= pfile
->cur_run
->base
;
653 if (pfile
->lookaheads
)
656 result
= pfile
->cur_token
++;
659 result
= _cpp_lex_direct (pfile
);
661 if (result
->flags
& BOL
)
663 /* Is this a directive. If _cpp_handle_directive returns
664 false, it is an assembler #. */
665 if (result
->type
== CPP_HASH
666 /* 6.10.3 p 11: Directives in a list of macro arguments
667 gives undefined behavior. This implementation
668 handles the directive as normal. */
669 && pfile
->state
.parsing_args
!= 1
670 && _cpp_handle_directive (pfile
, result
->flags
& PREV_WHITE
))
672 if (pfile
->cb
.line_change
&& !pfile
->state
.skipping
)
673 (*pfile
->cb
.line_change
)(pfile
, result
, pfile
->state
.parsing_args
);
676 /* We don't skip tokens in directives. */
677 if (pfile
->state
.in_directive
)
680 /* Outside a directive, invalidate controlling macros. At file
681 EOF, _cpp_lex_direct takes care of popping the buffer, so we never
682 get here and MI optimisation works. */
683 pfile
->mi_valid
= false;
685 if (!pfile
->state
.skipping
|| result
->type
== CPP_EOF
)
692 /* Returns true if a fresh line has been loaded. */
694 _cpp_get_fresh_line (pfile
)
697 /* We can't get a new line until we leave the current directive. */
698 if (pfile
->state
.in_directive
)
703 cpp_buffer
*buffer
= pfile
->buffer
;
705 if (!buffer
->need_line
)
708 if (buffer
->next_line
< buffer
->rlimit
)
710 _cpp_clean_line (pfile
);
714 /* First, get out of parsing arguments state. */
715 if (pfile
->state
.parsing_args
)
718 /* End of buffer. Non-empty files should end in a newline. */
719 if (buffer
->buf
!= buffer
->rlimit
720 && buffer
->next_line
> buffer
->rlimit
721 && !buffer
->from_stage3
)
723 /* Only warn once. */
724 buffer
->next_line
= buffer
->rlimit
;
725 cpp_error_with_line (pfile
, DL_PEDWARN
, pfile
->line
- 1,
726 CPP_BUF_COLUMN (buffer
, buffer
->cur
),
727 "no newline at end of file");
733 if (buffer
->return_at_eof
)
735 _cpp_pop_buffer (pfile
);
739 _cpp_pop_buffer (pfile
);
743 #define IF_NEXT_IS(CHAR, THEN_TYPE, ELSE_TYPE) \
746 result->type = ELSE_TYPE; \
747 if (*buffer->cur == CHAR) \
748 buffer->cur++, result->type = THEN_TYPE; \
752 /* Lex a token into pfile->cur_token, which is also incremented, to
753 get diagnostics pointing to the correct location.
755 Does not handle issues such as token lookahead, multiple-include
756 optimisation, directives, skipping etc. This function is only
757 suitable for use by _cpp_lex_token, and in special cases like
758 lex_expansion_token which doesn't care for any of these issues.
760 When meeting a newline, returns CPP_EOF if parsing a directive,
761 otherwise returns to the start of the token buffer if permissible.
762 Returns the location of the lexed token. */
764 _cpp_lex_direct (pfile
)
769 const unsigned char *comment_start
;
770 cpp_token
*result
= pfile
->cur_token
++;
774 if (pfile
->buffer
->need_line
)
776 if (!_cpp_get_fresh_line (pfile
))
778 result
->type
= CPP_EOF
;
779 if (!pfile
->state
.in_directive
)
781 /* Tell the compiler the line number of the EOF token. */
782 result
->line
= pfile
->line
;
787 if (!pfile
->keep_tokens
)
789 pfile
->cur_run
= &pfile
->base_run
;
790 result
= pfile
->base_run
.base
;
791 pfile
->cur_token
= result
+ 1;
794 if (pfile
->state
.parsing_args
== 2)
795 result
->flags
|= PREV_WHITE
;
797 buffer
= pfile
->buffer
;
799 result
->line
= pfile
->line
;
802 if (buffer
->cur
>= buffer
->notes
[buffer
->cur_note
].pos
803 && !pfile
->overlaid_buffer
)
805 _cpp_process_line_notes (pfile
, false);
806 result
->line
= pfile
->line
;
809 result
->col
= CPP_BUF_COLUMN (buffer
, buffer
->cur
);
813 case ' ': case '\t': case '\f': case '\v': case '\0':
814 result
->flags
|= PREV_WHITE
;
815 skip_whitespace (pfile
, c
);
820 buffer
->need_line
= true;
823 case '0': case '1': case '2': case '3': case '4':
824 case '5': case '6': case '7': case '8': case '9':
825 result
->type
= CPP_NUMBER
;
826 lex_number (pfile
, &result
->val
.str
);
830 /* 'L' may introduce wide characters or strings. */
831 if (*buffer
->cur
== '\'' || *buffer
->cur
== '"')
833 lex_string (pfile
, result
, buffer
->cur
- 1);
839 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
840 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
841 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
842 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
844 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
845 case 'G': case 'H': case 'I': case 'J': case 'K':
846 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
847 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
849 result
->type
= CPP_NAME
;
850 result
->val
.node
= lex_identifier (pfile
, buffer
->cur
- 1);
852 /* Convert named operators to their proper types. */
853 if (result
->val
.node
->flags
& NODE_OPERATOR
)
855 result
->flags
|= NAMED_OP
;
856 result
->type
= result
->val
.node
->directive_index
;
862 lex_string (pfile
, result
, buffer
->cur
- 1);
866 /* A potential block or line comment. */
867 comment_start
= buffer
->cur
;
872 if (_cpp_skip_block_comment (pfile
))
873 cpp_error (pfile
, DL_ERROR
, "unterminated comment");
875 else if (c
== '/' && (CPP_OPTION (pfile
, cplusplus_comments
)
876 || CPP_IN_SYSTEM_HEADER (pfile
)))
878 /* Warn about comments only if pedantically GNUC89, and not
879 in system headers. */
880 if (CPP_OPTION (pfile
, lang
) == CLK_GNUC89
&& CPP_PEDANTIC (pfile
)
881 && ! buffer
->warned_cplusplus_comments
)
883 cpp_error (pfile
, DL_PEDWARN
,
884 "C++ style comments are not allowed in ISO C90");
885 cpp_error (pfile
, DL_PEDWARN
,
886 "(this will be reported only once per input file)");
887 buffer
->warned_cplusplus_comments
= 1;
890 if (skip_line_comment (pfile
) && CPP_OPTION (pfile
, warn_comments
))
891 cpp_error (pfile
, DL_WARNING
, "multi-line comment");
896 result
->type
= CPP_DIV_EQ
;
901 result
->type
= CPP_DIV
;
905 if (!pfile
->state
.save_comments
)
907 result
->flags
|= PREV_WHITE
;
908 goto update_tokens_line
;
911 /* Save the comment as a token in its own right. */
912 save_comment (pfile
, result
, comment_start
, c
);
916 if (pfile
->state
.angled_headers
)
918 lex_string (pfile
, result
, buffer
->cur
- 1);
922 result
->type
= CPP_LESS
;
923 if (*buffer
->cur
== '=')
924 buffer
->cur
++, result
->type
= CPP_LESS_EQ
;
925 else if (*buffer
->cur
== '<')
928 IF_NEXT_IS ('=', CPP_LSHIFT_EQ
, CPP_LSHIFT
);
930 else if (*buffer
->cur
== '?' && CPP_OPTION (pfile
, cplusplus
))
933 IF_NEXT_IS ('=', CPP_MIN_EQ
, CPP_MIN
);
935 else if (CPP_OPTION (pfile
, digraphs
))
937 if (*buffer
->cur
== ':')
940 result
->flags
|= DIGRAPH
;
941 result
->type
= CPP_OPEN_SQUARE
;
943 else if (*buffer
->cur
== '%')
946 result
->flags
|= DIGRAPH
;
947 result
->type
= CPP_OPEN_BRACE
;
953 result
->type
= CPP_GREATER
;
954 if (*buffer
->cur
== '=')
955 buffer
->cur
++, result
->type
= CPP_GREATER_EQ
;
956 else if (*buffer
->cur
== '>')
959 IF_NEXT_IS ('=', CPP_RSHIFT_EQ
, CPP_RSHIFT
);
961 else if (*buffer
->cur
== '?' && CPP_OPTION (pfile
, cplusplus
))
964 IF_NEXT_IS ('=', CPP_MAX_EQ
, CPP_MAX
);
969 result
->type
= CPP_MOD
;
970 if (*buffer
->cur
== '=')
971 buffer
->cur
++, result
->type
= CPP_MOD_EQ
;
972 else if (CPP_OPTION (pfile
, digraphs
))
974 if (*buffer
->cur
== ':')
977 result
->flags
|= DIGRAPH
;
978 result
->type
= CPP_HASH
;
979 if (*buffer
->cur
== '%' && buffer
->cur
[1] == ':')
980 buffer
->cur
+= 2, result
->type
= CPP_PASTE
;
982 else if (*buffer
->cur
== '>')
985 result
->flags
|= DIGRAPH
;
986 result
->type
= CPP_CLOSE_BRACE
;
992 result
->type
= CPP_DOT
;
993 if (ISDIGIT (*buffer
->cur
))
995 result
->type
= CPP_NUMBER
;
996 lex_number (pfile
, &result
->val
.str
);
998 else if (*buffer
->cur
== '.' && buffer
->cur
[1] == '.')
999 buffer
->cur
+= 2, result
->type
= CPP_ELLIPSIS
;
1000 else if (*buffer
->cur
== '*' && CPP_OPTION (pfile
, cplusplus
))
1001 buffer
->cur
++, result
->type
= CPP_DOT_STAR
;
1005 result
->type
= CPP_PLUS
;
1006 if (*buffer
->cur
== '+')
1007 buffer
->cur
++, result
->type
= CPP_PLUS_PLUS
;
1008 else if (*buffer
->cur
== '=')
1009 buffer
->cur
++, result
->type
= CPP_PLUS_EQ
;
1013 result
->type
= CPP_MINUS
;
1014 if (*buffer
->cur
== '>')
1017 result
->type
= CPP_DEREF
;
1018 if (*buffer
->cur
== '*' && CPP_OPTION (pfile
, cplusplus
))
1019 buffer
->cur
++, result
->type
= CPP_DEREF_STAR
;
1021 else if (*buffer
->cur
== '-')
1022 buffer
->cur
++, result
->type
= CPP_MINUS_MINUS
;
1023 else if (*buffer
->cur
== '=')
1024 buffer
->cur
++, result
->type
= CPP_MINUS_EQ
;
1028 result
->type
= CPP_AND
;
1029 if (*buffer
->cur
== '&')
1030 buffer
->cur
++, result
->type
= CPP_AND_AND
;
1031 else if (*buffer
->cur
== '=')
1032 buffer
->cur
++, result
->type
= CPP_AND_EQ
;
1036 result
->type
= CPP_OR
;
1037 if (*buffer
->cur
== '|')
1038 buffer
->cur
++, result
->type
= CPP_OR_OR
;
1039 else if (*buffer
->cur
== '=')
1040 buffer
->cur
++, result
->type
= CPP_OR_EQ
;
1044 result
->type
= CPP_COLON
;
1045 if (*buffer
->cur
== ':' && CPP_OPTION (pfile
, cplusplus
))
1046 buffer
->cur
++, result
->type
= CPP_SCOPE
;
1047 else if (*buffer
->cur
== '>' && CPP_OPTION (pfile
, digraphs
))
1050 result
->flags
|= DIGRAPH
;
1051 result
->type
= CPP_CLOSE_SQUARE
;
1055 case '*': IF_NEXT_IS ('=', CPP_MULT_EQ
, CPP_MULT
); break;
1056 case '=': IF_NEXT_IS ('=', CPP_EQ_EQ
, CPP_EQ
); break;
1057 case '!': IF_NEXT_IS ('=', CPP_NOT_EQ
, CPP_NOT
); break;
1058 case '^': IF_NEXT_IS ('=', CPP_XOR_EQ
, CPP_XOR
); break;
1059 case '#': IF_NEXT_IS ('#', CPP_PASTE
, CPP_HASH
); break;
1061 case '?': result
->type
= CPP_QUERY
; break;
1062 case '~': result
->type
= CPP_COMPL
; break;
1063 case ',': result
->type
= CPP_COMMA
; break;
1064 case '(': result
->type
= CPP_OPEN_PAREN
; break;
1065 case ')': result
->type
= CPP_CLOSE_PAREN
; break;
1066 case '[': result
->type
= CPP_OPEN_SQUARE
; break;
1067 case ']': result
->type
= CPP_CLOSE_SQUARE
; break;
1068 case '{': result
->type
= CPP_OPEN_BRACE
; break;
1069 case '}': result
->type
= CPP_CLOSE_BRACE
; break;
1070 case ';': result
->type
= CPP_SEMICOLON
; break;
1072 /* @ is a punctuator in Objective-C. */
1073 case '@': result
->type
= CPP_ATSIGN
; break;
1078 const uchar
*base
= --buffer
->cur
;
1080 if (forms_identifier_p (pfile
, true))
1082 result
->type
= CPP_NAME
;
1083 result
->val
.node
= lex_identifier (pfile
, base
);
1090 create_literal (pfile
, result
, buffer
->cur
- 1, 1, CPP_OTHER
);
1097 /* An upper bound on the number of bytes needed to spell TOKEN.
1098 Does not include preceding whitespace. */
1100 cpp_token_len (token
)
1101 const cpp_token
*token
;
1105 switch (TOKEN_SPELL (token
))
1107 default: len
= 4; break;
1108 case SPELL_LITERAL
: len
= token
->val
.str
.len
; break;
1109 case SPELL_IDENT
: len
= NODE_LEN (token
->val
.node
); break;
1115 /* Write the spelling of a token TOKEN to BUFFER. The buffer must
1116 already contain the enough space to hold the token's spelling.
1117 Returns a pointer to the character after the last character
1120 cpp_spell_token (pfile
, token
, buffer
)
1121 cpp_reader
*pfile
; /* Would be nice to be rid of this... */
1122 const cpp_token
*token
;
1123 unsigned char *buffer
;
1125 switch (TOKEN_SPELL (token
))
1127 case SPELL_OPERATOR
:
1129 const unsigned char *spelling
;
1132 if (token
->flags
& DIGRAPH
)
1134 = digraph_spellings
[(int) token
->type
- (int) CPP_FIRST_DIGRAPH
];
1135 else if (token
->flags
& NAMED_OP
)
1138 spelling
= TOKEN_NAME (token
);
1140 while ((c
= *spelling
++) != '\0')
1147 memcpy (buffer
, NODE_NAME (token
->val
.node
), NODE_LEN (token
->val
.node
));
1148 buffer
+= NODE_LEN (token
->val
.node
);
1152 memcpy (buffer
, token
->val
.str
.text
, token
->val
.str
.len
);
1153 buffer
+= token
->val
.str
.len
;
1157 cpp_error (pfile
, DL_ICE
, "unspellable token %s", TOKEN_NAME (token
));
1164 /* Returns TOKEN spelt as a null-terminated string. The string is
1165 freed when the reader is destroyed. Useful for diagnostics. */
1167 cpp_token_as_text (pfile
, token
)
1169 const cpp_token
*token
;
1171 unsigned int len
= cpp_token_len (token
) + 1;
1172 unsigned char *start
= _cpp_unaligned_alloc (pfile
, len
), *end
;
1174 end
= cpp_spell_token (pfile
, token
, start
);
1180 /* Used by C front ends, which really should move to using
1181 cpp_token_as_text. */
1183 cpp_type2name (type
)
1184 enum cpp_ttype type
;
1186 return (const char *) token_spellings
[type
].name
;
1189 /* Writes the spelling of token to FP, without any preceding space.
1190 Separated from cpp_spell_token for efficiency - to avoid stdio
1191 double-buffering. */
1193 cpp_output_token (token
, fp
)
1194 const cpp_token
*token
;
1197 switch (TOKEN_SPELL (token
))
1199 case SPELL_OPERATOR
:
1201 const unsigned char *spelling
;
1204 if (token
->flags
& DIGRAPH
)
1206 = digraph_spellings
[(int) token
->type
- (int) CPP_FIRST_DIGRAPH
];
1207 else if (token
->flags
& NAMED_OP
)
1210 spelling
= TOKEN_NAME (token
);
1215 while ((c
= *++spelling
) != '\0');
1221 fwrite (NODE_NAME (token
->val
.node
), 1, NODE_LEN (token
->val
.node
), fp
);
1225 fwrite (token
->val
.str
.text
, 1, token
->val
.str
.len
, fp
);
1229 /* An error, most probably. */
1234 /* Compare two tokens. */
1236 _cpp_equiv_tokens (a
, b
)
1237 const cpp_token
*a
, *b
;
1239 if (a
->type
== b
->type
&& a
->flags
== b
->flags
)
1240 switch (TOKEN_SPELL (a
))
1242 default: /* Keep compiler happy. */
1243 case SPELL_OPERATOR
:
1246 return (a
->type
!= CPP_MACRO_ARG
|| a
->val
.arg_no
== b
->val
.arg_no
);
1248 return a
->val
.node
== b
->val
.node
;
1250 return (a
->val
.str
.len
== b
->val
.str
.len
1251 && !memcmp (a
->val
.str
.text
, b
->val
.str
.text
,
1258 /* Returns nonzero if a space should be inserted to avoid an
1259 accidental token paste for output. For simplicity, it is
1260 conservative, and occasionally advises a space where one is not
1261 needed, e.g. "." and ".2". */
1263 cpp_avoid_paste (pfile
, token1
, token2
)
1265 const cpp_token
*token1
, *token2
;
1267 enum cpp_ttype a
= token1
->type
, b
= token2
->type
;
1270 if (token1
->flags
& NAMED_OP
)
1272 if (token2
->flags
& NAMED_OP
)
1276 if (token2
->flags
& DIGRAPH
)
1277 c
= digraph_spellings
[(int) b
- (int) CPP_FIRST_DIGRAPH
][0];
1278 else if (token_spellings
[b
].category
== SPELL_OPERATOR
)
1279 c
= token_spellings
[b
].name
[0];
1281 /* Quickly get everything that can paste with an '='. */
1282 if ((int) a
<= (int) CPP_LAST_EQ
&& c
== '=')
1287 case CPP_GREATER
: return c
== '>' || c
== '?';
1288 case CPP_LESS
: return c
== '<' || c
== '?' || c
== '%' || c
== ':';
1289 case CPP_PLUS
: return c
== '+';
1290 case CPP_MINUS
: return c
== '-' || c
== '>';
1291 case CPP_DIV
: return c
== '/' || c
== '*'; /* Comments. */
1292 case CPP_MOD
: return c
== ':' || c
== '>';
1293 case CPP_AND
: return c
== '&';
1294 case CPP_OR
: return c
== '|';
1295 case CPP_COLON
: return c
== ':' || c
== '>';
1296 case CPP_DEREF
: return c
== '*';
1297 case CPP_DOT
: return c
== '.' || c
== '%' || b
== CPP_NUMBER
;
1298 case CPP_HASH
: return c
== '#' || c
== '%'; /* Digraph form. */
1299 case CPP_NAME
: return ((b
== CPP_NUMBER
1300 && name_p (pfile
, &token2
->val
.str
))
1302 || b
== CPP_CHAR
|| b
== CPP_STRING
); /* L */
1303 case CPP_NUMBER
: return (b
== CPP_NUMBER
|| b
== CPP_NAME
1304 || c
== '.' || c
== '+' || c
== '-');
1306 case CPP_OTHER
: return ((token1
->val
.str
.text
[0] == '\\'
1308 || (CPP_OPTION (pfile
, objc
)
1309 && token1
->val
.str
.text
[0] == '@'
1310 && (b
== CPP_NAME
|| b
== CPP_STRING
)));
1317 /* Output all the remaining tokens on the current line, and a newline
1318 character, to FP. Leading whitespace is removed. If there are
1319 macros, special token padding is not performed. */
1321 cpp_output_line (pfile
, fp
)
1325 const cpp_token
*token
;
1327 token
= cpp_get_token (pfile
);
1328 while (token
->type
!= CPP_EOF
)
1330 cpp_output_token (token
, fp
);
1331 token
= cpp_get_token (pfile
);
1332 if (token
->flags
& PREV_WHITE
)
1339 /* Returns the value of a hexadecimal digit. */
1345 return hex_value (c
);
1350 /* Read a possible universal character name starting at *PSTR. */
1352 maybe_read_ucn (pfile
, pstr
)
1356 cppchar_t result
, c
= (*pstr
)[-1];
1358 result
= _cpp_valid_ucn (pfile
, pstr
, false);
1361 if (CPP_WTRADITIONAL (pfile
))
1362 cpp_error (pfile
, DL_WARNING
,
1363 "the meaning of '\\%c' is different in traditional C",
1366 if (CPP_OPTION (pfile
, EBCDIC
))
1368 cpp_error (pfile
, DL_ERROR
,
1369 "universal character with an EBCDIC target");
1370 result
= 0x3f; /* EBCDIC invalid character */
1377 /* Returns the value of an escape sequence, truncated to the correct
1378 target precision. PSTR points to the input pointer, which is just
1379 after the backslash. LIMIT is how much text we have. WIDE is true
1380 if the escape sequence is part of a wide character constant or
1381 string literal. Handles all relevant diagnostics. */
1383 cpp_parse_escape (pfile
, pstr
, limit
, wide
)
1385 const unsigned char **pstr
;
1386 const unsigned char *limit
;
1389 /* Values of \a \b \e \f \n \r \t \v respectively. */
1390 static const uchar ascii
[] = { 7, 8, 27, 12, 10, 13, 9, 11 };
1391 static const uchar ebcdic
[] = { 47, 22, 39, 12, 21, 13, 5, 11 };
1394 const unsigned char *str
= *pstr
, *charconsts
;
1395 cppchar_t c
, ucn
, mask
;
1398 if (CPP_OPTION (pfile
, EBCDIC
))
1399 charconsts
= ebcdic
;
1404 width
= CPP_OPTION (pfile
, wchar_precision
);
1406 width
= CPP_OPTION (pfile
, char_precision
);
1407 if (width
< BITS_PER_CPPCHAR_T
)
1408 mask
= ((cppchar_t
) 1 << width
) - 1;
1415 case '\\': case '\'': case '"': case '?': break;
1416 case 'b': c
= charconsts
[1]; break;
1417 case 'f': c
= charconsts
[3]; break;
1418 case 'n': c
= charconsts
[4]; break;
1419 case 'r': c
= charconsts
[5]; break;
1420 case 't': c
= charconsts
[6]; break;
1421 case 'v': c
= charconsts
[7]; break;
1423 case '(': case '{': case '[': case '%':
1424 /* '\(', etc, are used at beginning of line to avoid confusing Emacs.
1425 '\%' is used to prevent SCCS from getting confused. */
1426 unknown
= CPP_PEDANTIC (pfile
);
1430 if (CPP_WTRADITIONAL (pfile
))
1431 cpp_error (pfile
, DL_WARNING
,
1432 "the meaning of '\\a' is different in traditional C");
1437 if (CPP_PEDANTIC (pfile
))
1438 cpp_error (pfile
, DL_PEDWARN
,
1439 "non-ISO-standard escape sequence, '\\%c'", (int) c
);
1444 ucn
= maybe_read_ucn (pfile
, &str
);
1452 if (CPP_WTRADITIONAL (pfile
))
1453 cpp_error (pfile
, DL_WARNING
,
1454 "the meaning of '\\x' is different in traditional C");
1457 cppchar_t i
= 0, overflow
= 0;
1458 int digits_found
= 0;
1466 overflow
|= i
^ (i
<< 4 >> 4);
1467 i
= (i
<< 4) + hex_digit_value (c
);
1472 cpp_error (pfile
, DL_ERROR
,
1473 "\\x used with no following hex digits");
1475 if (overflow
| (i
!= (i
& mask
)))
1477 cpp_error (pfile
, DL_PEDWARN
,
1478 "hex escape sequence out of range");
1485 case '0': case '1': case '2': case '3':
1486 case '4': case '5': case '6': case '7':
1489 cppchar_t i
= c
- '0';
1491 while (str
< limit
&& ++count
< 3)
1494 if (c
< '0' || c
> '7')
1497 i
= (i
<< 3) + c
- '0';
1500 if (i
!= (i
& mask
))
1502 cpp_error (pfile
, DL_PEDWARN
,
1503 "octal escape sequence out of range");
1518 cpp_error (pfile
, DL_PEDWARN
,
1519 "unknown escape sequence '\\%c'", (int) c
);
1521 cpp_error (pfile
, DL_PEDWARN
,
1522 "unknown escape sequence: '\\%03o'", (int) c
);
1527 cpp_error (pfile
, DL_PEDWARN
, "escape sequence out of range for its type");
1535 /* Interpret a (possibly wide) character constant in TOKEN.
1536 WARN_MULTI warns about multi-character charconsts. PCHARS_SEEN
1537 points to a variable that is filled in with the number of
1538 characters seen, and UNSIGNEDP to a variable that indicates whether
1539 the result has signed type. */
1541 cpp_interpret_charconst (pfile
, token
, pchars_seen
, unsignedp
)
1543 const cpp_token
*token
;
1544 unsigned int *pchars_seen
;
1547 const unsigned char *str
, *limit
;
1548 unsigned int chars_seen
= 0;
1549 size_t width
, max_chars
;
1550 cppchar_t c
, mask
, result
= 0;
1553 str
= token
->val
.str
.text
+ 1 + (token
->type
== CPP_WCHAR
);
1554 limit
= token
->val
.str
.text
+ token
->val
.str
.len
- 1;
1556 if (token
->type
== CPP_CHAR
)
1558 width
= CPP_OPTION (pfile
, char_precision
);
1559 max_chars
= CPP_OPTION (pfile
, int_precision
) / width
;
1560 unsigned_p
= CPP_OPTION (pfile
, unsigned_char
);
1564 width
= CPP_OPTION (pfile
, wchar_precision
);
1566 unsigned_p
= CPP_OPTION (pfile
, unsigned_wchar
);
1569 if (width
< BITS_PER_CPPCHAR_T
)
1570 mask
= ((cppchar_t
) 1 << width
) - 1;
1579 c
= cpp_parse_escape (pfile
, &str
, limit
, token
->type
== CPP_WCHAR
);
1581 #ifdef MAP_CHARACTER
1583 c
= MAP_CHARACTER (c
);
1588 /* Truncate the character, scale the result and merge the two. */
1590 if (width
< BITS_PER_CPPCHAR_T
)
1591 result
= (result
<< width
) | c
;
1596 if (chars_seen
== 0)
1597 cpp_error (pfile
, DL_ERROR
, "empty character constant");
1598 else if (chars_seen
> 1)
1600 /* Multichar charconsts are of type int and therefore signed. */
1603 if (chars_seen
> max_chars
)
1605 chars_seen
= max_chars
;
1606 cpp_error (pfile
, DL_WARNING
,
1607 "character constant too long for its type");
1609 else if (CPP_OPTION (pfile
, warn_multichar
))
1610 cpp_error (pfile
, DL_WARNING
, "multi-character character constant");
1613 /* Sign-extend or truncate the constant to cppchar_t. The value is
1614 in WIDTH bits, but for multi-char charconsts it's value is the
1615 full target type's width. */
1618 if (width
< BITS_PER_CPPCHAR_T
)
1620 mask
= ((cppchar_t
) 1 << width
) - 1;
1621 if (unsigned_p
|| !(result
& (1 << (width
- 1))))
1627 *pchars_seen
= chars_seen
;
1628 *unsignedp
= unsigned_p
;
1632 /* Memory buffers. Changing these three constants can have a dramatic
1633 effect on performance. The values here are reasonable defaults,
1634 but might be tuned. If you adjust them, be sure to test across a
1635 range of uses of cpplib, including heavy nested function-like macro
1636 expansion. Also check the change in peak memory usage (NJAMD is a
1637 good tool for this). */
1638 #define MIN_BUFF_SIZE 8000
1639 #define BUFF_SIZE_UPPER_BOUND(MIN_SIZE) (MIN_BUFF_SIZE + (MIN_SIZE) * 3 / 2)
1640 #define EXTENDED_BUFF_SIZE(BUFF, MIN_EXTRA) \
1641 (MIN_EXTRA + ((BUFF)->limit - (BUFF)->cur) * 2)
1643 #if MIN_BUFF_SIZE > BUFF_SIZE_UPPER_BOUND (0)
1644 #error BUFF_SIZE_UPPER_BOUND must be at least as large as MIN_BUFF_SIZE!
1647 /* Create a new allocation buffer. Place the control block at the end
1648 of the buffer, so that buffer overflows will cause immediate chaos. */
1654 unsigned char *base
;
1656 if (len
< MIN_BUFF_SIZE
)
1657 len
= MIN_BUFF_SIZE
;
1658 len
= CPP_ALIGN (len
);
1660 base
= xmalloc (len
+ sizeof (_cpp_buff
));
1661 result
= (_cpp_buff
*) (base
+ len
);
1662 result
->base
= base
;
1664 result
->limit
= base
+ len
;
1665 result
->next
= NULL
;
1669 /* Place a chain of unwanted allocation buffers on the free list. */
1671 _cpp_release_buff (pfile
, buff
)
1675 _cpp_buff
*end
= buff
;
1679 end
->next
= pfile
->free_buffs
;
1680 pfile
->free_buffs
= buff
;
1683 /* Return a free buffer of size at least MIN_SIZE. */
1685 _cpp_get_buff (pfile
, min_size
)
1689 _cpp_buff
*result
, **p
;
1691 for (p
= &pfile
->free_buffs
;; p
= &(*p
)->next
)
1696 return new_buff (min_size
);
1698 size
= result
->limit
- result
->base
;
1699 /* Return a buffer that's big enough, but don't waste one that's
1701 if (size
>= min_size
&& size
<= BUFF_SIZE_UPPER_BOUND (min_size
))
1706 result
->next
= NULL
;
1707 result
->cur
= result
->base
;
1711 /* Creates a new buffer with enough space to hold the uncommitted
1712 remaining bytes of BUFF, and at least MIN_EXTRA more bytes. Copies
1713 the excess bytes to the new buffer. Chains the new buffer after
1714 BUFF, and returns the new buffer. */
1716 _cpp_append_extend_buff (pfile
, buff
, min_extra
)
1721 size_t size
= EXTENDED_BUFF_SIZE (buff
, min_extra
);
1722 _cpp_buff
*new_buff
= _cpp_get_buff (pfile
, size
);
1724 buff
->next
= new_buff
;
1725 memcpy (new_buff
->base
, buff
->cur
, BUFF_ROOM (buff
));
1729 /* Creates a new buffer with enough space to hold the uncommitted
1730 remaining bytes of the buffer pointed to by BUFF, and at least
1731 MIN_EXTRA more bytes. Copies the excess bytes to the new buffer.
1732 Chains the new buffer before the buffer pointed to by BUFF, and
1733 updates the pointer to point to the new buffer. */
1735 _cpp_extend_buff (pfile
, pbuff
, min_extra
)
1740 _cpp_buff
*new_buff
, *old_buff
= *pbuff
;
1741 size_t size
= EXTENDED_BUFF_SIZE (old_buff
, min_extra
);
1743 new_buff
= _cpp_get_buff (pfile
, size
);
1744 memcpy (new_buff
->base
, old_buff
->cur
, BUFF_ROOM (old_buff
));
1745 new_buff
->next
= old_buff
;
1749 /* Free a chain of buffers starting at BUFF. */
1751 _cpp_free_buff (buff
)
1756 for (; buff
; buff
= next
)
1763 /* Allocate permanent, unaligned storage of length LEN. */
1765 _cpp_unaligned_alloc (pfile
, len
)
1769 _cpp_buff
*buff
= pfile
->u_buff
;
1770 unsigned char *result
= buff
->cur
;
1772 if (len
> (size_t) (buff
->limit
- result
))
1774 buff
= _cpp_get_buff (pfile
, len
);
1775 buff
->next
= pfile
->u_buff
;
1776 pfile
->u_buff
= buff
;
1780 buff
->cur
= result
+ len
;
1784 /* Allocate permanent, unaligned storage of length LEN from a_buff.
1785 That buffer is used for growing allocations when saving macro
1786 replacement lists in a #define, and when parsing an answer to an
1787 assertion in #assert, #unassert or #if (and therefore possibly
1788 whilst expanding macros). It therefore must not be used by any
1789 code that they might call: specifically the lexer and the guts of
1792 All existing other uses clearly fit this restriction: storing
1793 registered pragmas during initialization. */
1795 _cpp_aligned_alloc (pfile
, len
)
1799 _cpp_buff
*buff
= pfile
->a_buff
;
1800 unsigned char *result
= buff
->cur
;
1802 if (len
> (size_t) (buff
->limit
- result
))
1804 buff
= _cpp_get_buff (pfile
, len
);
1805 buff
->next
= pfile
->a_buff
;
1806 pfile
->a_buff
= buff
;
1810 buff
->cur
= result
+ len
;