internal.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. /* Part of CPP library.
  2. Copyright (C) 1997-2015 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the
  5. Free Software Foundation; either version 3, or (at your option) any
  6. later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; see the file COPYING3. If not see
  13. <http://www.gnu.org/licenses/>. */
  14. /* This header defines all the internal data structures and functions
  15. that need to be visible across files. It should not be used outside
  16. cpplib. */
  17. #ifndef LIBCPP_INTERNAL_H
  18. #define LIBCPP_INTERNAL_H
  19. #include "symtab.h"
  20. #include "cpp-id-data.h"
  21. #if HAVE_ICONV
  22. #include <iconv.h>
  23. #else
  24. #define HAVE_ICONV 0
  25. typedef int iconv_t; /* dummy */
  26. #endif
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. struct directive; /* Deliberately incomplete. */
  31. struct pending_option;
  32. struct op;
  33. struct _cpp_strbuf;
  34. typedef bool (*convert_f) (iconv_t, const unsigned char *, size_t,
  35. struct _cpp_strbuf *);
  36. struct cset_converter
  37. {
  38. convert_f func;
  39. iconv_t cd;
  40. int width;
  41. };
  42. #define BITS_PER_CPPCHAR_T (CHAR_BIT * sizeof (cppchar_t))
  43. /* Test if a sign is valid within a preprocessing number. */
  44. #define VALID_SIGN(c, prevc) \
  45. (((c) == '+' || (c) == '-') && \
  46. ((prevc) == 'e' || (prevc) == 'E' \
  47. || (((prevc) == 'p' || (prevc) == 'P') \
  48. && CPP_OPTION (pfile, extended_numbers))))
  49. #define DIGIT_SEP(c) ((c) == '\'' && CPP_OPTION (pfile, digit_separators))
  50. #define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION)
  51. #define CPP_BUFFER(PFILE) ((PFILE)->buffer)
  52. #define CPP_BUF_COLUMN(BUF, CUR) ((CUR) - (BUF)->line_base)
  53. #define CPP_BUF_COL(BUF) CPP_BUF_COLUMN(BUF, (BUF)->cur)
  54. #define CPP_INCREMENT_LINE(PFILE, COLS_HINT) do { \
  55. const struct line_maps *line_table = PFILE->line_table; \
  56. const struct line_map *map = \
  57. LINEMAPS_LAST_ORDINARY_MAP (line_table); \
  58. linenum_type line = SOURCE_LINE (map, line_table->highest_line); \
  59. linemap_line_start (PFILE->line_table, line + 1, COLS_HINT); \
  60. } while (0)
  61. /* Maximum nesting of cpp_buffers. We use a static limit, partly for
  62. efficiency, and partly to limit runaway recursion. */
  63. #define CPP_STACK_MAX 200
  64. /* Host alignment handling. */
  65. struct dummy
  66. {
  67. char c;
  68. union
  69. {
  70. double d;
  71. int *p;
  72. } u;
  73. };
  74. #define DEFAULT_ALIGNMENT offsetof (struct dummy, u)
  75. #define CPP_ALIGN2(size, align) (((size) + ((align) - 1)) & ~((align) - 1))
  76. #define CPP_ALIGN(size) CPP_ALIGN2 (size, DEFAULT_ALIGNMENT)
  77. #define _cpp_mark_macro_used(NODE) do { \
  78. if ((NODE)->type == NT_MACRO && !((NODE)->flags & NODE_BUILTIN)) \
  79. (NODE)->value.macro->used = 1; } while (0)
  80. /* A generic memory buffer, and operations on it. */
  81. typedef struct _cpp_buff _cpp_buff;
  82. struct _cpp_buff
  83. {
  84. struct _cpp_buff *next;
  85. unsigned char *base, *cur, *limit;
  86. };
  87. extern _cpp_buff *_cpp_get_buff (cpp_reader *, size_t);
  88. extern void _cpp_release_buff (cpp_reader *, _cpp_buff *);
  89. extern void _cpp_extend_buff (cpp_reader *, _cpp_buff **, size_t);
  90. extern _cpp_buff *_cpp_append_extend_buff (cpp_reader *, _cpp_buff *, size_t);
  91. extern void _cpp_free_buff (_cpp_buff *);
  92. extern unsigned char *_cpp_aligned_alloc (cpp_reader *, size_t);
  93. extern unsigned char *_cpp_unaligned_alloc (cpp_reader *, size_t);
  94. #define BUFF_ROOM(BUFF) (size_t) ((BUFF)->limit - (BUFF)->cur)
  95. #define BUFF_FRONT(BUFF) ((BUFF)->cur)
  96. #define BUFF_LIMIT(BUFF) ((BUFF)->limit)
  97. /* #include types. */
  98. enum include_type {IT_INCLUDE, IT_INCLUDE_NEXT, IT_IMPORT, IT_CMDLINE, IT_DEFAULT};
  99. union utoken
  100. {
  101. const cpp_token *token;
  102. const cpp_token **ptoken;
  103. };
  104. /* A "run" of tokens; part of a chain of runs. */
  105. typedef struct tokenrun tokenrun;
  106. struct tokenrun
  107. {
  108. tokenrun *next, *prev;
  109. cpp_token *base, *limit;
  110. };
  111. /* Accessor macros for struct cpp_context. */
  112. #define FIRST(c) ((c)->u.iso.first)
  113. #define LAST(c) ((c)->u.iso.last)
  114. #define CUR(c) ((c)->u.trad.cur)
  115. #define RLIMIT(c) ((c)->u.trad.rlimit)
  116. /* This describes some additional data that is added to the macro
  117. token context of type cpp_context, when -ftrack-macro-expansion is
  118. on. */
  119. typedef struct
  120. {
  121. /* The node of the macro we are referring to. */
  122. cpp_hashnode *macro_node;
  123. /* This buffer contains an array of virtual locations. The virtual
  124. location at index 0 is the virtual location of the token at index
  125. 0 in the current instance of cpp_context; similarly for all the
  126. other virtual locations. */
  127. source_location *virt_locs;
  128. /* This is a pointer to the current virtual location. This is used
  129. to iterate over the virtual locations while we iterate over the
  130. tokens they belong to. */
  131. source_location *cur_virt_loc;
  132. } macro_context;
  133. /* The kind of tokens carried by a cpp_context. */
  134. enum context_tokens_kind {
  135. /* This is the value of cpp_context::tokens_kind if u.iso.first
  136. contains an instance of cpp_token **. */
  137. TOKENS_KIND_INDIRECT,
  138. /* This is the value of cpp_context::tokens_kind if u.iso.first
  139. contains an instance of cpp_token *. */
  140. TOKENS_KIND_DIRECT,
  141. /* This is the value of cpp_context::tokens_kind when the token
  142. context contains tokens resulting from macro expansion. In that
  143. case struct cpp_context::macro points to an instance of struct
  144. macro_context. This is used only when the
  145. -ftrack-macro-expansion flag is on. */
  146. TOKENS_KIND_EXTENDED
  147. };
  148. typedef struct cpp_context cpp_context;
  149. struct cpp_context
  150. {
  151. /* Doubly-linked list. */
  152. cpp_context *next, *prev;
  153. union
  154. {
  155. /* For ISO macro expansion. Contexts other than the base context
  156. are contiguous tokens. e.g. macro expansions, expanded
  157. argument tokens. */
  158. struct
  159. {
  160. union utoken first;
  161. union utoken last;
  162. } iso;
  163. /* For traditional macro expansion. */
  164. struct
  165. {
  166. const unsigned char *cur;
  167. const unsigned char *rlimit;
  168. } trad;
  169. } u;
  170. /* If non-NULL, a buffer used for storage related to this context.
  171. When the context is popped, the buffer is released. */
  172. _cpp_buff *buff;
  173. /* If tokens_kind is TOKEN_KIND_EXTENDED, then (as we thus are in a
  174. macro context) this is a pointer to an instance of macro_context.
  175. Otherwise if tokens_kind is *not* TOKEN_KIND_EXTENDED, then, if
  176. we are in a macro context, this is a pointer to an instance of
  177. cpp_hashnode, representing the name of the macro this context is
  178. for. If we are not in a macro context, then this is just NULL.
  179. Note that when tokens_kind is TOKEN_KIND_EXTENDED, the memory
  180. used by the instance of macro_context pointed to by this member
  181. is de-allocated upon de-allocation of the instance of struct
  182. cpp_context. */
  183. union
  184. {
  185. macro_context *mc;
  186. cpp_hashnode *macro;
  187. } c;
  188. /* This determines the type of tokens held by this context. */
  189. enum context_tokens_kind tokens_kind;
  190. };
  191. struct lexer_state
  192. {
  193. /* Nonzero if first token on line is CPP_HASH. */
  194. unsigned char in_directive;
  195. /* Nonzero if in a directive that will handle padding tokens itself.
  196. #include needs this to avoid problems with computed include and
  197. spacing between tokens. */
  198. unsigned char directive_wants_padding;
  199. /* True if we are skipping a failed conditional group. */
  200. unsigned char skipping;
  201. /* Nonzero if in a directive that takes angle-bracketed headers. */
  202. unsigned char angled_headers;
  203. /* Nonzero if in a #if or #elif directive. */
  204. unsigned char in_expression;
  205. /* Nonzero to save comments. Turned off if discard_comments, and in
  206. all directives apart from #define. */
  207. unsigned char save_comments;
  208. /* Nonzero if lexing __VA_ARGS__ is valid. */
  209. unsigned char va_args_ok;
  210. /* Nonzero if lexing poisoned identifiers is valid. */
  211. unsigned char poisoned_ok;
  212. /* Nonzero to prevent macro expansion. */
  213. unsigned char prevent_expansion;
  214. /* Nonzero when parsing arguments to a function-like macro. */
  215. unsigned char parsing_args;
  216. /* Nonzero if in a __has_include__ or __has_include_next__ statement. */
  217. unsigned char in__has_include__;
  218. /* Nonzero if prevent_expansion is true only because output is
  219. being discarded. */
  220. unsigned char discarding_output;
  221. /* Nonzero to skip evaluating part of an expression. */
  222. unsigned int skip_eval;
  223. /* Nonzero when handling a deferred pragma. */
  224. unsigned char in_deferred_pragma;
  225. /* Nonzero if the deferred pragma being handled allows macro expansion. */
  226. unsigned char pragma_allow_expansion;
  227. };
  228. /* Special nodes - identifiers with predefined significance. */
  229. struct spec_nodes
  230. {
  231. cpp_hashnode *n_defined; /* defined operator */
  232. cpp_hashnode *n_true; /* C++ keyword true */
  233. cpp_hashnode *n_false; /* C++ keyword false */
  234. cpp_hashnode *n__VA_ARGS__; /* C99 vararg macros */
  235. cpp_hashnode *n__has_include__; /* __has_include__ operator */
  236. cpp_hashnode *n__has_include_next__; /* __has_include_next__ operator */
  237. };
  238. typedef struct _cpp_line_note _cpp_line_note;
  239. struct _cpp_line_note
  240. {
  241. /* Location in the clean line the note refers to. */
  242. const unsigned char *pos;
  243. /* Type of note. The 9 'from' trigraph characters represent those
  244. trigraphs, '\\' an escaped newline, ' ' an escaped newline with
  245. intervening space, 0 represents a note that has already been handled,
  246. and anything else is invalid. */
  247. unsigned int type;
  248. };
  249. /* Represents the contents of a file cpplib has read in. */
  250. struct cpp_buffer
  251. {
  252. const unsigned char *cur; /* Current location. */
  253. const unsigned char *line_base; /* Start of current physical line. */
  254. const unsigned char *next_line; /* Start of to-be-cleaned logical line. */
  255. const unsigned char *buf; /* Entire character buffer. */
  256. const unsigned char *rlimit; /* Writable byte at end of file. */
  257. const unsigned char *to_free; /* Pointer that should be freed when
  258. popping the buffer. */
  259. _cpp_line_note *notes; /* Array of notes. */
  260. unsigned int cur_note; /* Next note to process. */
  261. unsigned int notes_used; /* Number of notes. */
  262. unsigned int notes_cap; /* Size of allocated array. */
  263. struct cpp_buffer *prev;
  264. /* Pointer into the file table; non-NULL if this is a file buffer.
  265. Used for include_next and to record control macros. */
  266. struct _cpp_file *file;
  267. /* Saved value of __TIMESTAMP__ macro - date and time of last modification
  268. of the assotiated file. */
  269. const unsigned char *timestamp;
  270. /* Value of if_stack at start of this file.
  271. Used to prohibit unmatched #endif (etc) in an include file. */
  272. struct if_stack *if_stack;
  273. /* True if we need to get the next clean line. */
  274. bool need_line;
  275. /* True if we have already warned about C++ comments in this file.
  276. The warning happens only for C89 extended mode with -pedantic on,
  277. or for -Wtraditional, and only once per file (otherwise it would
  278. be far too noisy). */
  279. unsigned int warned_cplusplus_comments : 1;
  280. /* True if we don't process trigraphs and escaped newlines. True
  281. for preprocessed input, command line directives, and _Pragma
  282. buffers. */
  283. unsigned int from_stage3 : 1;
  284. /* At EOF, a buffer is automatically popped. If RETURN_AT_EOF is
  285. true, a CPP_EOF token is then returned. Otherwise, the next
  286. token from the enclosing buffer is returned. */
  287. unsigned int return_at_eof : 1;
  288. /* One for a system header, two for a C system header file that therefore
  289. needs to be extern "C" protected in C++, and zero otherwise. */
  290. unsigned char sysp;
  291. /* The directory of the this buffer's file. Its NAME member is not
  292. allocated, so we don't need to worry about freeing it. */
  293. struct cpp_dir dir;
  294. /* Descriptor for converting from the input character set to the
  295. source character set. */
  296. struct cset_converter input_cset_desc;
  297. };
  298. /* The list of saved macros by push_macro pragma. */
  299. struct def_pragma_macro {
  300. /* Chain element to previous saved macro. */
  301. struct def_pragma_macro *next;
  302. /* Name of the macro. */
  303. char *name;
  304. /* The stored macro content. */
  305. unsigned char *definition;
  306. /* Definition line number. */
  307. source_location line;
  308. /* If macro defined in system header. */
  309. unsigned int syshdr : 1;
  310. /* Nonzero if it has been expanded or had its existence tested. */
  311. unsigned int used : 1;
  312. /* Mark if we save an undefined macro. */
  313. unsigned int is_undef : 1;
  314. };
  315. /* A cpp_reader encapsulates the "state" of a pre-processor run.
  316. Applying cpp_get_token repeatedly yields a stream of pre-processor
  317. tokens. Usually, there is only one cpp_reader object active. */
  318. struct cpp_reader
  319. {
  320. /* Top of buffer stack. */
  321. cpp_buffer *buffer;
  322. /* Overlaid buffer (can be different after processing #include). */
  323. cpp_buffer *overlaid_buffer;
  324. /* Lexer state. */
  325. struct lexer_state state;
  326. /* Source line tracking. */
  327. struct line_maps *line_table;
  328. /* The line of the '#' of the current directive. */
  329. source_location directive_line;
  330. /* Memory buffers. */
  331. _cpp_buff *a_buff; /* Aligned permanent storage. */
  332. _cpp_buff *u_buff; /* Unaligned permanent storage. */
  333. _cpp_buff *free_buffs; /* Free buffer chain. */
  334. /* Context stack. */
  335. struct cpp_context base_context;
  336. struct cpp_context *context;
  337. /* If in_directive, the directive if known. */
  338. const struct directive *directive;
  339. /* Token generated while handling a directive, if any. */
  340. cpp_token directive_result;
  341. /* When expanding a macro at top-level, this is the location of the
  342. macro invocation. */
  343. source_location invocation_location;
  344. /* This is the node representing the macro being expanded at
  345. top-level. The value of this data member is valid iff
  346. in_macro_expansion_p() returns TRUE. */
  347. cpp_hashnode *top_most_macro_node;
  348. /* Nonzero if we are about to expand a macro. Note that if we are
  349. really expanding a macro, the function macro_of_context returns
  350. the macro being expanded and this flag is set to false. Client
  351. code should use the function in_macro_expansion_p to know if we
  352. are either about to expand a macro, or are actually expanding
  353. one. */
  354. bool about_to_expand_macro_p;
  355. /* Search paths for include files. */
  356. struct cpp_dir *quote_include; /* "" */
  357. struct cpp_dir *bracket_include; /* <> */
  358. struct cpp_dir no_search_path; /* No path. */
  359. /* Chain of all hashed _cpp_file instances. */
  360. struct _cpp_file *all_files;
  361. struct _cpp_file *main_file;
  362. /* File and directory hash table. */
  363. struct htab *file_hash;
  364. struct htab *dir_hash;
  365. struct file_hash_entry_pool *file_hash_entries;
  366. /* Negative path lookup hash table. */
  367. struct htab *nonexistent_file_hash;
  368. struct obstack nonexistent_file_ob;
  369. /* Nonzero means don't look for #include "foo" the source-file
  370. directory. */
  371. bool quote_ignores_source_dir;
  372. /* Nonzero if any file has contained #pragma once or #import has
  373. been used. */
  374. bool seen_once_only;
  375. /* Multiple include optimization. */
  376. const cpp_hashnode *mi_cmacro;
  377. const cpp_hashnode *mi_ind_cmacro;
  378. bool mi_valid;
  379. /* Lexing. */
  380. cpp_token *cur_token;
  381. tokenrun base_run, *cur_run;
  382. unsigned int lookaheads;
  383. /* Nonzero prevents the lexer from re-using the token runs. */
  384. unsigned int keep_tokens;
  385. /* Buffer to hold macro definition string. */
  386. unsigned char *macro_buffer;
  387. unsigned int macro_buffer_len;
  388. /* Descriptor for converting from the source character set to the
  389. execution character set. */
  390. struct cset_converter narrow_cset_desc;
  391. /* Descriptor for converting from the source character set to the
  392. UTF-8 execution character set. */
  393. struct cset_converter utf8_cset_desc;
  394. /* Descriptor for converting from the source character set to the
  395. UTF-16 execution character set. */
  396. struct cset_converter char16_cset_desc;
  397. /* Descriptor for converting from the source character set to the
  398. UTF-32 execution character set. */
  399. struct cset_converter char32_cset_desc;
  400. /* Descriptor for converting from the source character set to the
  401. wide execution character set. */
  402. struct cset_converter wide_cset_desc;
  403. /* Date and time text. Calculated together if either is requested. */
  404. const unsigned char *date;
  405. const unsigned char *time;
  406. /* EOF token, and a token forcing paste avoidance. */
  407. cpp_token avoid_paste;
  408. cpp_token eof;
  409. /* Opaque handle to the dependencies of mkdeps.c. */
  410. struct deps *deps;
  411. /* Obstack holding all macro hash nodes. This never shrinks.
  412. See identifiers.c */
  413. struct obstack hash_ob;
  414. /* Obstack holding buffer and conditional structures. This is a
  415. real stack. See directives.c. */
  416. struct obstack buffer_ob;
  417. /* Pragma table - dynamic, because a library user can add to the
  418. list of recognized pragmas. */
  419. struct pragma_entry *pragmas;
  420. /* Call backs to cpplib client. */
  421. struct cpp_callbacks cb;
  422. /* Identifier hash table. */
  423. struct ht *hash_table;
  424. /* Expression parser stack. */
  425. struct op *op_stack, *op_limit;
  426. /* User visible options. */
  427. struct cpp_options opts;
  428. /* Special nodes - identifiers with predefined significance to the
  429. preprocessor. */
  430. struct spec_nodes spec_nodes;
  431. /* Whether cpplib owns the hashtable. */
  432. bool our_hashtable;
  433. /* Traditional preprocessing output buffer (a logical line). */
  434. struct
  435. {
  436. unsigned char *base;
  437. unsigned char *limit;
  438. unsigned char *cur;
  439. source_location first_line;
  440. } out;
  441. /* Used for buffer overlays by traditional.c. */
  442. const unsigned char *saved_cur, *saved_rlimit, *saved_line_base;
  443. /* A saved list of the defined macros, for dependency checking
  444. of precompiled headers. */
  445. struct cpp_savedstate *savedstate;
  446. /* Next value of __COUNTER__ macro. */
  447. unsigned int counter;
  448. /* Table of comments, when state.save_comments is true. */
  449. cpp_comment_table comments;
  450. /* List of saved macros by push_macro. */
  451. struct def_pragma_macro *pushed_macros;
  452. /* If non-null, the lexer will use this location for the next token
  453. instead of getting a location from the linemap. */
  454. source_location *forced_token_location_p;
  455. };
  456. /* Character classes. Based on the more primitive macros in safe-ctype.h.
  457. If the definition of `numchar' looks odd to you, please look up the
  458. definition of a pp-number in the C standard [section 6.4.8 of C99].
  459. In the unlikely event that characters other than \r and \n enter
  460. the set is_vspace, the macro handle_newline() in lex.c must be
  461. updated. */
  462. #define _dollar_ok(x) ((x) == '$' && CPP_OPTION (pfile, dollars_in_ident))
  463. #define is_idchar(x) (ISIDNUM(x) || _dollar_ok(x))
  464. #define is_numchar(x) ISIDNUM(x)
  465. #define is_idstart(x) (ISIDST(x) || _dollar_ok(x))
  466. #define is_numstart(x) ISDIGIT(x)
  467. #define is_hspace(x) ISBLANK(x)
  468. #define is_vspace(x) IS_VSPACE(x)
  469. #define is_nvspace(x) IS_NVSPACE(x)
  470. #define is_space(x) IS_SPACE_OR_NUL(x)
  471. /* This table is constant if it can be initialized at compile time,
  472. which is the case if cpp was compiled with GCC >=2.7, or another
  473. compiler that supports C99. */
  474. #if HAVE_DESIGNATED_INITIALIZERS
  475. extern const unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
  476. #else
  477. extern unsigned char _cpp_trigraph_map[UCHAR_MAX + 1];
  478. #endif
  479. /* Macros. */
  480. static inline int cpp_in_system_header (cpp_reader *);
  481. static inline int
  482. cpp_in_system_header (cpp_reader *pfile)
  483. {
  484. return pfile->buffer ? pfile->buffer->sysp : 0;
  485. }
  486. #define CPP_PEDANTIC(PF) CPP_OPTION (PF, cpp_pedantic)
  487. #define CPP_WTRADITIONAL(PF) CPP_OPTION (PF, cpp_warn_traditional)
  488. static inline int cpp_in_primary_file (cpp_reader *);
  489. static inline int
  490. cpp_in_primary_file (cpp_reader *pfile)
  491. {
  492. return pfile->line_table->depth == 1;
  493. }
  494. /* In macro.c */
  495. extern void _cpp_free_definition (cpp_hashnode *);
  496. extern bool _cpp_create_definition (cpp_reader *, cpp_hashnode *);
  497. extern void _cpp_pop_context (cpp_reader *);
  498. extern void _cpp_push_text_context (cpp_reader *, cpp_hashnode *,
  499. const unsigned char *, size_t);
  500. extern bool _cpp_save_parameter (cpp_reader *, cpp_macro *, cpp_hashnode *,
  501. cpp_hashnode *);
  502. extern bool _cpp_arguments_ok (cpp_reader *, cpp_macro *, const cpp_hashnode *,
  503. unsigned int);
  504. extern const unsigned char *_cpp_builtin_macro_text (cpp_reader *,
  505. cpp_hashnode *);
  506. extern int _cpp_warn_if_unused_macro (cpp_reader *, cpp_hashnode *, void *);
  507. extern void _cpp_push_token_context (cpp_reader *, cpp_hashnode *,
  508. const cpp_token *, unsigned int);
  509. extern void _cpp_backup_tokens_direct (cpp_reader *, unsigned int);
  510. /* In identifiers.c */
  511. extern void _cpp_init_hashtable (cpp_reader *, cpp_hash_table *);
  512. extern void _cpp_destroy_hashtable (cpp_reader *);
  513. /* In files.c */
  514. typedef struct _cpp_file _cpp_file;
  515. extern _cpp_file *_cpp_find_file (cpp_reader *, const char *, cpp_dir *,
  516. bool, int, bool);
  517. extern bool _cpp_find_failed (_cpp_file *);
  518. extern void _cpp_mark_file_once_only (cpp_reader *, struct _cpp_file *);
  519. extern void _cpp_fake_include (cpp_reader *, const char *);
  520. extern bool _cpp_stack_file (cpp_reader *, _cpp_file*, bool);
  521. extern bool _cpp_stack_include (cpp_reader *, const char *, int,
  522. enum include_type);
  523. extern int _cpp_compare_file_date (cpp_reader *, const char *, int);
  524. extern void _cpp_report_missing_guards (cpp_reader *);
  525. extern void _cpp_init_files (cpp_reader *);
  526. extern void _cpp_cleanup_files (cpp_reader *);
  527. extern void _cpp_pop_file_buffer (cpp_reader *, struct _cpp_file *,
  528. const unsigned char *);
  529. extern bool _cpp_save_file_entries (cpp_reader *pfile, FILE *f);
  530. extern bool _cpp_read_file_entries (cpp_reader *, FILE *);
  531. extern const char *_cpp_get_file_name (_cpp_file *);
  532. extern struct stat *_cpp_get_file_stat (_cpp_file *);
  533. extern bool _cpp_has_header (cpp_reader *, const char *, int,
  534. enum include_type);
  535. /* In expr.c */
  536. extern bool _cpp_parse_expr (cpp_reader *, bool);
  537. extern struct op *_cpp_expand_op_stack (cpp_reader *);
  538. /* In lex.c */
  539. extern void _cpp_process_line_notes (cpp_reader *, int);
  540. extern void _cpp_clean_line (cpp_reader *);
  541. extern bool _cpp_get_fresh_line (cpp_reader *);
  542. extern bool _cpp_skip_block_comment (cpp_reader *);
  543. extern cpp_token *_cpp_temp_token (cpp_reader *);
  544. extern const cpp_token *_cpp_lex_token (cpp_reader *);
  545. extern cpp_token *_cpp_lex_direct (cpp_reader *);
  546. extern unsigned char *_cpp_spell_ident_ucns (unsigned char *, cpp_hashnode *);
  547. extern int _cpp_equiv_tokens (const cpp_token *, const cpp_token *);
  548. extern void _cpp_init_tokenrun (tokenrun *, unsigned int);
  549. extern cpp_hashnode *_cpp_lex_identifier (cpp_reader *, const char *);
  550. extern int _cpp_remaining_tokens_num_in_context (cpp_context *);
  551. extern void _cpp_init_lexer (void);
  552. /* In init.c. */
  553. extern void _cpp_maybe_push_include_file (cpp_reader *);
  554. extern const char *cpp_named_operator2name (enum cpp_ttype type);
  555. /* In directives.c */
  556. extern int _cpp_test_assertion (cpp_reader *, unsigned int *);
  557. extern int _cpp_handle_directive (cpp_reader *, int);
  558. extern void _cpp_define_builtin (cpp_reader *, const char *);
  559. extern char ** _cpp_save_pragma_names (cpp_reader *);
  560. extern void _cpp_restore_pragma_names (cpp_reader *, char **);
  561. extern int _cpp_do__Pragma (cpp_reader *);
  562. extern void _cpp_init_directives (cpp_reader *);
  563. extern void _cpp_init_internal_pragmas (cpp_reader *);
  564. extern void _cpp_do_file_change (cpp_reader *, enum lc_reason, const char *,
  565. linenum_type, unsigned int);
  566. extern void _cpp_pop_buffer (cpp_reader *);
  567. extern char *_cpp_bracket_include (cpp_reader *);
  568. /* In directives.c */
  569. struct _cpp_dir_only_callbacks
  570. {
  571. /* Called to print a block of lines. */
  572. void (*print_lines) (int, const void *, size_t);
  573. void (*maybe_print_line) (source_location);
  574. };
  575. extern void _cpp_preprocess_dir_only (cpp_reader *,
  576. const struct _cpp_dir_only_callbacks *);
  577. /* In traditional.c. */
  578. extern bool _cpp_scan_out_logical_line (cpp_reader *, cpp_macro *, bool);
  579. extern bool _cpp_read_logical_line_trad (cpp_reader *);
  580. extern void _cpp_overlay_buffer (cpp_reader *pfile, const unsigned char *,
  581. size_t);
  582. extern void _cpp_remove_overlay (cpp_reader *);
  583. extern bool _cpp_create_trad_definition (cpp_reader *, cpp_macro *);
  584. extern bool _cpp_expansions_different_trad (const cpp_macro *,
  585. const cpp_macro *);
  586. extern unsigned char *_cpp_copy_replacement_text (const cpp_macro *,
  587. unsigned char *);
  588. extern size_t _cpp_replacement_text_len (const cpp_macro *);
  589. /* In charset.c. */
  590. /* The normalization state at this point in the sequence.
  591. It starts initialized to all zeros, and at the end
  592. 'level' is the normalization level of the sequence. */
  593. struct normalize_state
  594. {
  595. /* The previous starter character. */
  596. cppchar_t previous;
  597. /* The combining class of the previous character (whether or not a
  598. starter). */
  599. unsigned char prev_class;
  600. /* The lowest normalization level so far. */
  601. enum cpp_normalize_level level;
  602. };
  603. #define INITIAL_NORMALIZE_STATE { 0, 0, normalized_KC }
  604. #define NORMALIZE_STATE_RESULT(st) ((st)->level)
  605. /* We saw a character C that matches ISIDNUM(), update a
  606. normalize_state appropriately. */
  607. #define NORMALIZE_STATE_UPDATE_IDNUM(st, c) \
  608. ((st)->previous = (c), (st)->prev_class = 0)
  609. extern cppchar_t _cpp_valid_ucn (cpp_reader *, const unsigned char **,
  610. const unsigned char *, int,
  611. struct normalize_state *state);
  612. extern void _cpp_destroy_iconv (cpp_reader *);
  613. extern unsigned char *_cpp_convert_input (cpp_reader *, const char *,
  614. unsigned char *, size_t, size_t,
  615. const unsigned char **, off_t *);
  616. extern const char *_cpp_default_encoding (void);
  617. extern cpp_hashnode * _cpp_interpret_identifier (cpp_reader *pfile,
  618. const unsigned char *id,
  619. size_t len);
  620. /* Utility routines and macros. */
  621. #define DSC(str) (const unsigned char *)str, sizeof str - 1
  622. /* These are inline functions instead of macros so we can get type
  623. checking. */
  624. static inline int ustrcmp (const unsigned char *, const unsigned char *);
  625. static inline int ustrncmp (const unsigned char *, const unsigned char *,
  626. size_t);
  627. static inline size_t ustrlen (const unsigned char *);
  628. static inline const unsigned char *uxstrdup (const unsigned char *);
  629. static inline const unsigned char *ustrchr (const unsigned char *, int);
  630. static inline int ufputs (const unsigned char *, FILE *);
  631. /* Use a const char for the second parameter since it is usually a literal. */
  632. static inline int ustrcspn (const unsigned char *, const char *);
  633. static inline int
  634. ustrcmp (const unsigned char *s1, const unsigned char *s2)
  635. {
  636. return strcmp ((const char *)s1, (const char *)s2);
  637. }
  638. static inline int
  639. ustrncmp (const unsigned char *s1, const unsigned char *s2, size_t n)
  640. {
  641. return strncmp ((const char *)s1, (const char *)s2, n);
  642. }
  643. static inline int
  644. ustrcspn (const unsigned char *s1, const char *s2)
  645. {
  646. return strcspn ((const char *)s1, s2);
  647. }
  648. static inline size_t
  649. ustrlen (const unsigned char *s1)
  650. {
  651. return strlen ((const char *)s1);
  652. }
  653. static inline const unsigned char *
  654. uxstrdup (const unsigned char *s1)
  655. {
  656. return (const unsigned char *) xstrdup ((const char *)s1);
  657. }
  658. static inline const unsigned char *
  659. ustrchr (const unsigned char *s1, int c)
  660. {
  661. return (const unsigned char *) strchr ((const char *)s1, c);
  662. }
  663. static inline int
  664. ufputs (const unsigned char *s, FILE *f)
  665. {
  666. return fputs ((const char *)s, f);
  667. }
  668. /* In line-map.c. */
  669. /* Create a macro map. A macro map encodes source locations of tokens
  670. that are part of a macro replacement-list, at a macro expansion
  671. point. See the extensive comments of struct line_map and struct
  672. line_map_macro, in line-map.h.
  673. This map shall be created when the macro is expanded. The map
  674. encodes the source location of the expansion point of the macro as
  675. well as the "original" source location of each token that is part
  676. of the macro replacement-list. If a macro is defined but never
  677. expanded, it has no macro map. SET is the set of maps the macro
  678. map should be part of. MACRO_NODE is the macro which the new macro
  679. map should encode source locations for. EXPANSION is the location
  680. of the expansion point of MACRO. For function-like macros
  681. invocations, it's best to make it point to the closing parenthesis
  682. of the macro, rather than the the location of the first character
  683. of the macro. NUM_TOKENS is the number of tokens that are part of
  684. the replacement-list of MACRO. */
  685. const struct line_map *linemap_enter_macro (struct line_maps *,
  686. struct cpp_hashnode*,
  687. source_location,
  688. unsigned int);
  689. /* Create and return a virtual location for a token that is part of a
  690. macro expansion-list at a macro expansion point. See the comment
  691. inside struct line_map_macro to see what an expansion-list exactly
  692. is.
  693. A call to this function must come after a call to
  694. linemap_enter_macro.
  695. MAP is the map into which the source location is created. TOKEN_NO
  696. is the index of the token in the macro replacement-list, starting
  697. at number 0.
  698. ORIG_LOC is the location of the token outside of this macro
  699. expansion. If the token comes originally from the macro
  700. definition, it is the locus in the macro definition; otherwise it
  701. is a location in the context of the caller of this macro expansion
  702. (which is a virtual location or a source location if the caller is
  703. itself a macro expansion or not).
  704. MACRO_DEFINITION_LOC is the location in the macro definition,
  705. either of the token itself or of a macro parameter that it
  706. replaces. */
  707. source_location linemap_add_macro_token (const struct line_map *,
  708. unsigned int,
  709. source_location,
  710. source_location);
  711. /* Return the source line number corresponding to source location
  712. LOCATION. SET is the line map set LOCATION comes from. If
  713. LOCATION is the location of token that is part of the
  714. expansion-list of a macro expansion return the line number of the
  715. macro expansion point. */
  716. int linemap_get_expansion_line (struct line_maps *,
  717. source_location);
  718. /* Return the path of the file corresponding to source code location
  719. LOCATION.
  720. If LOCATION is the location of a token that is part of the
  721. replacement-list of a macro expansion return the file path of the
  722. macro expansion point.
  723. SET is the line map set LOCATION comes from. */
  724. const char* linemap_get_expansion_filename (struct line_maps *,
  725. source_location);
  726. #ifdef __cplusplus
  727. }
  728. #endif
  729. #endif /* ! LIBCPP_INTERNAL_H */