Skip to content

Commit 85a280c

Browse files
committed
Check pt fixing warnings
1 parent 5edb8bc commit 85a280c

File tree

4 files changed

+149
-5
lines changed

4 files changed

+149
-5
lines changed

crates/parser/src/ast_builder.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,25 @@ impl ASTBuilder {
248248
source: &str,
249249
attributes: &mut HashMap<String, String>,
250250
) {
251+
// Debug output for C functions
252+
if self.language == Language::C {
253+
eprintln!("DEBUG: Extracting function attributes from node: {}", node.kind());
254+
eprintln!("DEBUG: Node text: {:?}", node.utf8_text(source.as_bytes()).unwrap_or(""));
255+
}
256+
257+
// Extract function name - try different field names for C
258+
if let Some(declarator) = node.child_by_field_name("declarator") {
259+
if let Ok(_name_text) = declarator.utf8_text(source.as_bytes()) {
260+
// For C, the declarator might contain the function name
261+
if let Some(name) = self.extract_function_name_from_declarator(&declarator, source) {
262+
if self.language == Language::C {
263+
eprintln!("DEBUG: Extracted function name: {}", name);
264+
}
265+
attributes.insert("name".to_string(), name);
266+
}
267+
}
268+
}
269+
251270
// Extract return type
252271
if let Some(type_node) = node.child_by_field_name("type") {
253272
if let Ok(return_type) = type_node.utf8_text(source.as_bytes()) {
@@ -416,10 +435,17 @@ impl ASTBuilder {
416435
/// Map tree-sitter node type to our NodeType
417436
fn map_node_type(&self, kind: &str) -> NodeType {
418437
use crate::language_config::NODE_TYPE_MAPPINGS;
419-
NODE_TYPE_MAPPINGS
438+
let node_type = NODE_TYPE_MAPPINGS
420439
.get(kind)
421440
.copied()
422-
.unwrap_or(NodeType::Unknown)
441+
.unwrap_or(NodeType::Unknown);
442+
443+
// Debug output for C language
444+
if self.language == Language::C && (kind.contains("function") || kind.contains("declaration")) {
445+
eprintln!("DEBUG: C node mapping: '{}' -> {:?}", kind, node_type);
446+
}
447+
448+
node_type
423449
}
424450

425451
/// Create a placeholder node for filtered content
@@ -444,6 +470,25 @@ impl ASTBuilder {
444470
.get("placeholder")
445471
.is_some_and(|v| v == "true")
446472
}
473+
474+
/// Extract function name from C function declarator
475+
fn extract_function_name_from_declarator(&self, declarator: &Node, source: &str) -> Option<String> {
476+
// For C, the function declarator structure is: function_declarator -> identifier
477+
for i in 0..declarator.child_count() {
478+
if let Some(child) = declarator.child(i) {
479+
if child.kind() == "identifier" {
480+
if let Ok(name) = child.utf8_text(source.as_bytes()) {
481+
return Some(name.to_string());
482+
}
483+
}
484+
// Recursively search in children
485+
if let Some(name) = self.extract_function_name_from_declarator(&child, source) {
486+
return Some(name);
487+
}
488+
}
489+
}
490+
None
491+
}
447492
}
448493

449494
/// Builder pattern for AST construction with fluent interface

crates/parser/src/language_config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ pub static NODE_TYPE_MAPPINGS: Lazy<HashMap<&'static str, NodeType>> = Lazy::new
125125
// Functions and methods
126126
mappings.insert("function_declaration", NodeType::Function);
127127
mappings.insert("function_definition", NodeType::Function);
128+
mappings.insert("function_declarator", NodeType::Function);
128129
mappings.insert("function_expression", NodeType::Function);
129130
mappings.insert("arrow_function", NodeType::Function);
130131
mappings.insert("method_declaration", NodeType::Method);

crates/semantic-analysis/src/analyzer.rs

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,96 @@ impl SemanticAnalyzer {
8484
})
8585
}
8686

87-
fn collect_symbols(&mut self, _ast: &ASTNode, _file_path: &str) -> Result<(), AnalysisError> {
88-
// TODO: Implement symbol collection
89-
// This would traverse the AST and populate the symbol table
87+
fn collect_symbols(&mut self, ast: &ASTNode, file_path: &str) -> Result<(), AnalysisError> {
88+
// Traverse the AST and collect symbols
89+
self.collect_symbols_recursive(ast, file_path, &mut Vec::new())?;
90+
Ok(())
91+
}
92+
93+
fn collect_symbols_recursive(&mut self, node: &ASTNode, file_path: &str, scope_path: &mut Vec<String>) -> Result<(), AnalysisError> {
94+
use crate::symbol_table::{Symbol, SymbolKind, Scope, ScopeType};
95+
use crate::ast::NodeType;
96+
97+
match node.node_type {
98+
NodeType::Function | NodeType::Method | NodeType::Constructor => {
99+
if let Some(name) = node.metadata.attributes.get("name") {
100+
eprintln!("DEBUG: Found function: {}", name);
101+
102+
let symbol = Symbol {
103+
name: name.clone(),
104+
kind: SymbolKind::Function,
105+
scope_id: self.symbol_table.current_scope(),
106+
line: node.metadata.line,
107+
column: node.metadata.column,
108+
file_path: file_path.to_string(),
109+
type_info: node.metadata.attributes.get("return_type").cloned(),
110+
references: Vec::new(),
111+
};
112+
113+
self.symbol_table.add_symbol(symbol);
114+
}
115+
}
116+
NodeType::VariableDeclaration | NodeType::FieldDeclaration => {
117+
if let Some(name) = node.metadata.attributes.get("name") {
118+
eprintln!("DEBUG: Found variable: {}", name);
119+
120+
let symbol = Symbol {
121+
name: name.clone(),
122+
kind: SymbolKind::Variable,
123+
scope_id: self.symbol_table.current_scope(),
124+
line: node.metadata.line,
125+
column: node.metadata.column,
126+
file_path: file_path.to_string(),
127+
type_info: node.metadata.attributes.get("type").cloned(),
128+
references: Vec::new(),
129+
};
130+
131+
self.symbol_table.add_symbol(symbol);
132+
}
133+
}
134+
NodeType::Class | NodeType::Interface => {
135+
if let Some(name) = node.metadata.attributes.get("name") {
136+
let symbol = Symbol {
137+
name: name.clone(),
138+
kind: SymbolKind::Type,
139+
scope_id: self.symbol_table.current_scope(),
140+
line: node.metadata.line,
141+
column: node.metadata.column,
142+
file_path: file_path.to_string(),
143+
type_info: Some("class".to_string()),
144+
references: Vec::new(),
145+
};
146+
147+
self.symbol_table.add_symbol(symbol);
148+
149+
// Create new scope for class
150+
let scope = Scope {
151+
scope_type: ScopeType::Class,
152+
name: Some(name.clone()),
153+
parent: Some(self.symbol_table.current_scope()),
154+
symbols: Vec::new(),
155+
};
156+
let scope_id = self.symbol_table.add_scope(scope);
157+
self.symbol_table.enter_scope(scope_id);
158+
scope_path.push(name.clone());
159+
}
160+
}
161+
_ => {}
162+
}
163+
164+
// Recursively process children
165+
for child in &node.children {
166+
self.collect_symbols_recursive(child, file_path, scope_path)?;
167+
}
168+
169+
// Exit scope if we entered one
170+
if matches!(node.node_type, NodeType::Class | NodeType::Interface) {
171+
if node.metadata.attributes.get("name").is_some() {
172+
self.symbol_table.exit_scope();
173+
scope_path.pop();
174+
}
175+
}
176+
90177
Ok(())
91178
}
92179

crates/semantic-analysis/src/comprehensive_dependency_graph.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ impl ComprehensiveDependencyGraphBuilder {
261261
context: &mut FileAnalysisContext,
262262
scope_path: Vec<String>,
263263
) -> Result<()> {
264+
// Debug output for C language
265+
if context.language == Language::C {
266+
eprintln!("DEBUG: Processing AST node: {:?}", node.node_type);
267+
}
268+
264269
match node.node_type {
265270
NodeType::Function | NodeType::Method | NodeType::Constructor => {
266271
if let Some(function_info) = self.extract_function_info(node, &scope_path)? {
@@ -320,6 +325,12 @@ impl ComprehensiveDependencyGraphBuilder {
320325
node: &ASTNode,
321326
scope_path: &[String],
322327
) -> Result<Option<FunctionInfo>> {
328+
// Debug output for C functions
329+
if matches!(node.node_type, NodeType::Function | NodeType::Method | NodeType::Constructor) {
330+
eprintln!("DEBUG: Extracting function info from node: {:?}", node.node_type);
331+
eprintln!("DEBUG: Node attributes: {:?}", node.metadata.attributes);
332+
}
333+
323334
let name = node
324335
.metadata
325336
.attributes

0 commit comments

Comments
 (0)