1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! # codegraph-c
//!
//! C parser for CodeGraph - extracts code entities and relationships from C source files.
//!
//! ## Features
//!
//! - Parse C source files (.c) and header files (.h)
//! - Extract functions, structs, unions, enums, and typedefs
//! - Track relationships (includes, function calls)
//! - Calculate cyclomatic complexity metrics
//! - **Tolerant parsing mode** for incomplete/kernel code
//! - **Macro preprocessing** for Linux kernel and system code
//! - **Layered processing pipeline** for better parsing of kernel code
//! - **Platform detection** with support for Linux, FreeBSD, Darwin
//! - Full integration with codegraph-parser-api
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use codegraph_c::CParser;
//! use codegraph_parser_api::CodeParser;
//! use codegraph::CodeGraph;
//! use std::path::Path;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let mut graph = CodeGraph::in_memory()?;
//! let parser = CParser::new();
//!
//! let file_info = parser.parse_file(Path::new("main.c"), &mut graph)?;
//! println!("Parsed {} functions", file_info.functions.len());
//! # Ok(())
//! # }
//! ```
//!
//! ## Tolerant Parsing
//!
//! For code with syntax errors or missing headers (like kernel code):
//!
//! ```rust,no_run
//! use codegraph_c::{extractor::{extract_with_options, ExtractionOptions}, CParser};
//! use codegraph_parser_api::ParserConfig;
//! use std::path::Path;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let source = r#"
//! static __init int my_init(void) { return 0; }
//! "#;
//!
//! // Use kernel-optimized extraction
//! let options = ExtractionOptions::for_kernel_code();
//! let result = extract_with_options(source, Path::new("test.c"), &ParserConfig::default(), &options)?;
//!
//! println!("Extracted {} functions (partial: {})", result.ir.functions.len(), result.is_partial);
//! # Ok(())
//! # }
//! ```
//!
//! ## Layered Pipeline
//!
//! For advanced processing with platform-specific optimizations:
//!
//! ```rust,no_run
//! use codegraph_c::pipeline::{Pipeline, PipelineConfig};
//!
//! let pipeline = Pipeline::new();
//! let config = PipelineConfig::for_kernel_code();
//!
//! let source = r#"
//! #include <linux/module.h>
//! MODULE_LICENSE("GPL");
//! static __init int my_init(void) { return 0; }
//! "#;
//!
//! let result = pipeline.process(source, &config);
//! println!("Platform: {} (confidence: {:.0}%)",
//! result.platform.platform_id,
//! result.platform.confidence * 100.0);
//! ```
// Re-export parser-api types for convenience
pub use ;
// Export the C parser implementation
pub use CParser;
// Export key types from submodules
pub use ;
pub use ;
pub use ;
pub use ;
pub use FunctionCall;