KCC - Kayte C Compiler 1.10.0
A C compiler implementation with preprocessor, lexer, parser, and code generator
Loading...
Searching...
No Matches
preprocessor.h
1#ifndef PREPROCESSOR_H
2#define PREPROCESSOR_H
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7#include <stdbool.h>
8#include <ctype.h>
9#include "types.h"
10
11// Complete Preprocessor struct definition
12typedef struct Preprocessor {
13 // Macro storage
14 Macro macros[MAX_MACROS];
15 int macro_count;
16
17 // Conditional compilation stack
18 ConditionalState cond_stack[32];
19 int cond_stack_depth;
20
21 // Include file stack
22 IncludeFile include_stack[MAX_INCLUDE_DEPTH];
23 int include_depth;
24
25 // Output buffer
26 char *output;
27 size_t output_size;
28 size_t output_capacity;
29
30 // Current file tracking
31 char *current_file;
32 int current_line;
33 bool skip_lines;
35
36// Preprocessor creation and destruction
37Preprocessor *preprocessor_create(void);
38void preprocessor_destroy(Preprocessor *preprocessor);
39
40// Main preprocessing functions
41char *preprocessor_process_file(Preprocessor *pp, const char *filename);
42char *preprocessor_process_string(Preprocessor *pp, const char *source, const char *filename);
43
44// Macro management
45bool preprocessor_define_macro(Preprocessor *pp, const char *name, const char *body);
46bool preprocessor_define_function_macro(Preprocessor *pp, const char *name,
47 const char *params[], int param_count, const char *body);
48bool preprocessor_undefine_macro(Preprocessor *pp, const char *name);
49Macro *preprocessor_find_macro(Preprocessor *pp, const char *name);
50bool preprocessor_is_macro_defined(Preprocessor *pp, const char *name);
51
52// Macro expansion
53char *preprocessor_expand_macros(Preprocessor *pp, const char *line);
54char *preprocessor_expand_function_macro(Preprocessor *pp, Macro *macro,
55 const char *args[], int arg_count);
56
57// Directive processing
58bool preprocessor_process_directive(Preprocessor *pp, const char *line);
59bool preprocessor_handle_define(Preprocessor *pp, const char *directive);
60bool preprocessor_handle_undef(Preprocessor *pp, const char *directive);
61bool preprocessor_handle_include(Preprocessor *pp, const char *directive);
62bool preprocessor_handle_if(Preprocessor *pp, const char *directive);
63bool preprocessor_handle_ifdef(Preprocessor *pp, const char *directive);
64bool preprocessor_handle_ifndef(Preprocessor *pp, const char *directive);
65bool preprocessor_handle_elif(Preprocessor *pp, const char *directive);
66bool preprocessor_handle_else(Preprocessor *pp, const char *directive);
67bool preprocessor_handle_endif(Preprocessor *pp, const char *directive);
68bool preprocessor_handle_error(Preprocessor *pp, const char *directive);
69bool preprocessor_handle_warning(Preprocessor *pp, const char *directive);
70bool preprocessor_handle_pragma(Preprocessor *pp, const char *directive);
71bool preprocessor_handle_line(Preprocessor *pp, const char *directive);
72
73// Conditional compilation
74bool preprocessor_evaluate_condition(Preprocessor *pp, const char *condition);
75bool preprocessor_should_skip_line(Preprocessor *pp);
76void preprocessor_push_conditional(Preprocessor *pp, ConditionalType type, bool condition);
77bool preprocessor_pop_conditional(Preprocessor *pp);
78
79// Utility functions
80char *preprocessor_read_file(const char *filename);
81void preprocessor_append_output(Preprocessor *pp, const char *text);
82char *preprocessor_parse_macro_args(const char *call, char *args[], int max_args);
83char *preprocessor_substitute_params(const char *body, const char *params[],
84 const char *args[], int param_count);
85bool preprocessor_is_directive(const char *line);
86char *preprocessor_get_directive_name(const char *line);
87char *preprocessor_get_directive_args(const char *line);
88void preprocessor_add_predefined_macros(Preprocessor *pp);
89
90// String utilities for macros
91char *preprocessor_stringify(const char *text);
92char *preprocessor_concatenate(const char *left, const char *right);
93char *preprocessor_trim_whitespace(char *str);
94
95// Error handling for preprocessor
96int preprocessor_error(Preprocessor* pp, const char* format, ...);
97int preprocessor_warning(Preprocessor* pp, const char* format, ...);
98
99// Built-in macro management
100void preprocessor_add_builtin_macros(Preprocessor *pp);
101void preprocessor_add_user_macros(Preprocessor *pp, const char *macro_definitions[], int count);
102void preprocessor_add_environment_macros(Preprocessor *pp);
103void preprocessor_add_system_macros(Preprocessor *pp);
104
105// Cleanup
106void free_macro(Macro *macro);
107
108#endif // PREPROCESSOR_H
Conditional state tracking.
Definition types.h:598
Include file tracking.
Definition types.h:608
Macro definition.
Definition types.h:572
Type definitions for KCC compiler with Objective-C support.
ConditionalType
Conditional compilation state.
Definition types.h:586