1pub mod apidoc;
76pub mod apidoc_data;
77pub mod apidoc_patches;
78pub mod ast;
79pub mod c_fn_decl;
80pub mod error;
81pub mod enum_dict;
82pub mod fields_dict;
83pub mod global_const_dict;
84pub mod infer_api;
85pub mod inline_fn;
86pub mod intern;
87pub mod lexer;
88pub mod macro_def;
89pub mod macro_infer;
90pub mod parser;
91pub mod perl_config;
92pub mod perlvar_dict;
93pub mod perlvar_emitter;
94pub mod pipeline;
95pub mod pp_expr;
96pub mod preprocessor;
97pub mod rust_codegen;
98pub mod rust_decl;
99pub mod static_array_emitter;
100pub mod struct_emitter;
101pub mod semantic;
102pub mod sexp;
103pub mod syn_codegen;
104pub mod source;
105pub mod token;
106pub mod token_source;
107pub mod type_env;
108pub mod type_repr;
109pub mod local_usage;
110pub mod unified_type;
111
112pub const VERSION: &str = env!("CARGO_PKG_VERSION");
116
117pub use apidoc::{
119 find_apidoc_dir_from, resolve_apidoc_path,
120 ApidocArg, ApidocCollector, ApidocDict, ApidocEntry, ApidocFlags, ApidocResolveError, ApidocStats, Nullability,
121};
122pub use infer_api::{
123 run_inference_with_preprocessor,
124 DebugOptions, InferConfig, InferError, InferResult, InferStats, TypedefDict,
125};
126pub use ast::*;
127pub use error::{CompileError, DisplayLocation, LexError, PPError, ParseError, Result};
128pub use fields_dict::FieldsDict;
129pub use inline_fn::InlineFnDict;
130pub use intern::{InternedStr, StringInterner};
131pub use rust_decl::RustDeclDict;
132pub use lexer::{IdentResolver, Interning, Lexer, LookupOnly, MutableLexer, ReadOnlyLexer};
133pub use macro_def::{MacroDef, MacroKind, MacroTable};
134pub use macro_infer::{
135 convert_assert_calls_in_compound_stmt, detect_assert_kind, InferStatus, MacroInferContext,
136 MacroInferInfo, MacroInferStats, NoExpandSymbols, ParseResult,
137};
138pub use parser::{parse_expression_from_tokens, parse_expression_from_tokens_ref, parse_type_from_string, Parser};
139pub use perl_config::{
140 build_pp_config_for_perl, get_default_target_dir, get_perl_config, get_perl_version,
141 PerlConfig, PerlConfigError,
142};
143pub use perlvar_dict::{
144 ArrayLength, PerlvarCollector, PerlvarDict, PerlvarEntry, PerlvarKind,
145};
146pub use preprocessor::{
147 CallbackPair, CommentCallback, MacroCalledCallback, MacroCallWatcher, MacroDefCallback,
148 PPConfig, Preprocessor,
149};
150pub use semantic::{SemanticAnalyzer, Symbol, SymbolKind, Type};
151pub use sexp::{SexpPrinter, TypedSexpPrinter};
152pub use source::{FileId, FileRegistry, SourceLocation};
153pub use token::{Comment, CommentKind, Token, TokenKind};
154pub use token_source::{TokenSlice, TokenSliceRef, TokenSource};
155pub use type_env::{ParamLink, TypeConstraint, TypeEnv};
156pub use type_repr::{
157 CDerivedType, CPrimitiveKind, CTypeSource, CTypeSpecs, InferredType,
158 IntSize as TypeReprIntSize, RustPrimitiveKind, RustTypeRepr, RustTypeSource, TypeRepr,
159};
160pub use unified_type::{IntSize, SourcedType, TypeSource, UnifiedType};
161pub use rust_codegen::{CodegenConfig, CodegenDriver, CodegenStats, GeneratedCode, GenerateStatus, RustCodegen};
162pub use rust_codegen::{CodegenReport, RequireCodegenError, RequireViolation};
163pub use pipeline::{
164 Pipeline, PipelineBuilder, PipelineError,
165 PreprocessConfig, InferConfig as PipelineInferConfig, CodegenConfig as PipelineCodegenConfig,
166 PreprocessedPipeline, InferredPipeline, GeneratedPipeline,
167};
168
169#[cfg(test)]
170mod tests {
171 use super::*;
172 use std::path::PathBuf;
173
174 #[test]
175 fn test_basic_lexer_integration() {
176 let source = b"int main(void) { return 0; }";
177
178 let mut files = FileRegistry::new();
179 let file_id = files.register(PathBuf::from("test.c"));
180
181 let mut interner = StringInterner::new();
182 let mut lexer = Lexer::new(source, file_id, &mut interner);
183
184 let mut tokens = Vec::new();
185 loop {
186 let token = lexer.next_token().unwrap();
187 if matches!(token.kind, TokenKind::Eof) {
188 break;
189 }
190 tokens.push(token);
191 }
192
193 assert_eq!(tokens.len(), 10);
195 assert!(matches!(tokens[0].kind, TokenKind::KwInt));
197 assert!(matches!(tokens[1].kind, TokenKind::Ident(_))); assert!(matches!(tokens[2].kind, TokenKind::LParen));
199 assert!(matches!(tokens[3].kind, TokenKind::KwVoid));
200 assert!(matches!(tokens[4].kind, TokenKind::RParen));
201 assert!(matches!(tokens[5].kind, TokenKind::LBrace));
202 assert!(matches!(tokens[6].kind, TokenKind::KwReturn));
203 assert!(matches!(tokens[7].kind, TokenKind::IntLit(0)));
204 assert!(matches!(tokens[8].kind, TokenKind::Semi));
205 assert!(matches!(tokens[9].kind, TokenKind::RBrace));
206
207 if let TokenKind::Ident(id) = tokens[1].kind {
209 assert_eq!(interner.get(id), "main");
210 } else {
211 panic!("Expected identifier for 'main'");
212 }
213 }
214
215 #[test]
216 fn test_comment_preservation() {
217 let source = b"// doc comment\nint x;";
218
219 let mut files = FileRegistry::new();
220 let file_id = files.register(PathBuf::from("test.c"));
221
222 let mut interner = StringInterner::new();
223 let mut lexer = Lexer::new(source, file_id, &mut interner);
224
225 let newline = lexer.next_token().unwrap();
227 assert!(matches!(newline.kind, TokenKind::Newline));
228 assert_eq!(newline.leading_comments.len(), 1);
229 assert!(newline.leading_comments[0].text.contains("doc comment"));
230
231 let token = lexer.next_token().unwrap();
232 assert!(matches!(token.kind, TokenKind::KwInt));
234 }
235}