Provisional API: This reference documents current compiler behavior. Compatibility is not yet promised.
src/preprocess.x
C preprocessor directives in x2c source.
Functions
| Function | Summary |
|---|---|
Compiler.leading_preproc | Returns source-ordered preprocessor nodes in the preceding trivia. |
Compiler.note_object_macro | Records the name of the #define line content so a bare atom spelled the same way inside a literal can be flagged and a declaration prefix can be read. |
Compiler.note_preprocessor_macros | Records object-like #define names and removes names after #undef. |
Compiler.preproc_branch_state | Returns a group’s hidden-arm state after its #elif or #else: 2 when the group’s state was 1, and 0 otherwise. |
Compiler.preproc_conditional_kind | Classifies the preprocessor line text as a conditional directive: <open> for #if, #ifdef, and #ifndef, <branch> for #elif and #else forms, <close> for #endif, or 0 for any other line. |
Compiler.preproc_directive | Returns the preprocessor line text without its # and the blanks around the directive. |
Compiler.preproc_include_target | Returns the file named by the #include line text, or NULL for any other line. |
Compiler.preproc_marker_file | Returns the file that the host preprocessor’s line marker text, # N "file" flags, names and sets line to N, or returns NULL for any other line. |
Compiler.preproc_open_state | Returns the hidden-arm state of the conditional group that text opens: 2 when C never takes its first arm, because the condition requires a never-defined name or is 0; 1 when C never takes the arms after its first #else, because the condition is exactly !defined(NAME); and 0 otherwise. |
Compiler.preproc_track_arms | Follows the conditional groups open after the preprocessor line text. |
Compiler.preproc_within_arms | Returns items inside the conditional arms arms tracked by Compiler.preproc_track_arms: the directives that reopen each group, outermost first, then items, then one #endif per group. |
Compiler.scan_conditionals | Records the open groups after each conditional directive of the tokenized unit, and marks layout attributes where written or where a macro expands to one. |
Compiler
Compiler.leading_preproc
List Compiler.leading_preproc(Compiler c)
Returns source-ordered preprocessor nodes in the preceding trivia.
Spaces and comments remain trivia rather than becoming AST nodes.
Source: src/preprocess.x:289
Compiler.note_object_macro
void Compiler.note_object_macro(Compiler c, String content)
Records the name of the #define line content so a bare atom spelled
the same way inside a literal can be flagged and a declaration prefix
can be read. The directive after #define is scanned as x2c tokens. An
#undef drops the name, so later source reads it as an ordinary
identifier.
Source: src/preprocess.x:312
Compiler.note_preprocessor_macros
void Compiler.note_preprocessor_macros(Compiler c, List directives)
Records object-like #define names and removes names after #undef.
Source storage determines visibility independently of directives.
Source: src/preprocess.x:302
Compiler.preproc_branch_state
int Compiler.preproc_branch_state(int state)
Returns a group’s hidden-arm state after its #elif or #else: 2 when
the group’s state was 1, and 0 otherwise.
Source: src/preprocess.x:79
Compiler.preproc_conditional_kind
Symbol Compiler.preproc_conditional_kind(String text)
Classifies the preprocessor line text as a conditional directive:
<open> for #if, #ifdef, and #ifndef, <branch> for #elif
and #else forms, <close> for #endif, or 0 for any other line.
Source: src/preprocess.x:29
Compiler.preproc_directive
String Compiler.preproc_directive(String text)
Returns the preprocessor line text without its # and the blanks
around the directive.
Source: src/preprocess.x:22
Compiler.preproc_include_target
String Compiler.preproc_include_target(String text, int &angle)
Returns the file named by the #include line text, or NULL for any
other line. angle is 1 for a <...> name and 0 otherwise. Text after
the name, such as a comment, is ignored.
Source: src/preprocess.x:85
Compiler.preproc_marker_file
String Compiler.preproc_marker_file(String text, int &line)
Returns the file that the host preprocessor’s line marker text,
# N "file" flags, names and sets line to N, or returns NULL for
any other line.
Source: src/preprocess.x:99
Compiler.preproc_open_state
int Compiler.preproc_open_state(String text)
Returns the hidden-arm state of the conditional group that text opens:
2 when C never takes its first arm, because the condition requires a
never-defined name or is 0; 1 when C never takes the arms after its
first #else, because the condition is exactly !defined(NAME); and 0
otherwise.
Source: src/preprocess.x:42
Compiler.preproc_track_arms
List Compiler.preproc_track_arms(List arms, String text)
Follows the conditional groups open after the preprocessor line text.
arms holds one entry per open group, innermost first, listing the
preproc nodes that select that group’s current arm.
Source: src/preprocess.x:413
Compiler.preproc_within_arms
List Compiler.preproc_within_arms(List arms, List items)
Returns items inside the conditional arms arms tracked by
Compiler.preproc_track_arms: the directives that reopen each group,
outermost first, then items, then one #endif per group.
Source: src/preprocess.x:426
Compiler.scan_conditionals
void Compiler.scan_conditionals(Compiler c)
Records the open groups after each conditional directive of the tokenized unit, and marks layout attributes where written or where a macro expands to one.
Source: src/preprocess.x:146
Design notes
Preprocessor lines stay in the token stream and become preproc nodes,
so generated C keeps them where they were written. This module owns
what x2c reads from those lines without running a preprocessor: which
conditional arms C can reach, and what the directives before each form
say about layout and the unit’s #define names.