lat.md 0.10.2 → 0.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/source-parser.js +44 -9
- package/package.json +1 -1
|
@@ -546,8 +546,13 @@ function extractCSymbols(tree) {
|
|
|
546
546
|
return symbols;
|
|
547
547
|
}
|
|
548
548
|
/**
|
|
549
|
-
* Walk C AST nodes, collecting symbols. Recurses into
|
|
550
|
-
*
|
|
549
|
+
* Walk C AST nodes, collecting symbols. Recurses into preprocessor
|
|
550
|
+
* conditional blocks (ifdef/ifndef/if), linkage specifications
|
|
551
|
+
* (extern "C" { ... }), and declaration lists so that include guards
|
|
552
|
+
* and conditional compilation don't hide declarations.
|
|
553
|
+
*
|
|
554
|
+
* For #if/#ifdef/#ifndef, only the "then" branch is traversed —
|
|
555
|
+
* preproc_else and preproc_elif children are skipped.
|
|
551
556
|
*/
|
|
552
557
|
function collectCNodes(parent, symbols) {
|
|
553
558
|
for (let i = 0; i < parent.childCount; i++) {
|
|
@@ -592,7 +597,12 @@ function collectCNodes(parent, symbols) {
|
|
|
592
597
|
}
|
|
593
598
|
}
|
|
594
599
|
else if (node.type === 'type_definition') {
|
|
595
|
-
|
|
600
|
+
let declarator = node.childForFieldName('declarator');
|
|
601
|
+
// Unwrap pointer_declarator for pointer typedefs
|
|
602
|
+
// e.g. `typedef struct __JSValue *JSValue;`
|
|
603
|
+
while (declarator?.type === 'pointer_declarator') {
|
|
604
|
+
declarator = declarator.childForFieldName('declarator') ?? null;
|
|
605
|
+
}
|
|
596
606
|
const name = declarator?.type === 'type_identifier' ? declarator.text : null;
|
|
597
607
|
if (name) {
|
|
598
608
|
symbols.push({
|
|
@@ -606,16 +616,30 @@ function collectCNodes(parent, symbols) {
|
|
|
606
616
|
}
|
|
607
617
|
else if (node.type === 'declaration') {
|
|
608
618
|
const declarator = node.childForFieldName('declarator');
|
|
609
|
-
|
|
610
|
-
|
|
619
|
+
// Try as function declaration first (e.g. `void greet(const char *name);`
|
|
620
|
+
// in headers), then fall back to variable.
|
|
621
|
+
const funcName = declarator ? cFuncName(declarator) : null;
|
|
622
|
+
if (funcName) {
|
|
611
623
|
symbols.push({
|
|
612
|
-
name,
|
|
613
|
-
kind: '
|
|
624
|
+
name: funcName,
|
|
625
|
+
kind: 'function',
|
|
614
626
|
startLine,
|
|
615
627
|
endLine,
|
|
616
628
|
signature: firstLine(node.text),
|
|
617
629
|
});
|
|
618
630
|
}
|
|
631
|
+
else {
|
|
632
|
+
const name = declarator ? cVarName(declarator) : null;
|
|
633
|
+
if (name) {
|
|
634
|
+
symbols.push({
|
|
635
|
+
name,
|
|
636
|
+
kind: 'variable',
|
|
637
|
+
startLine,
|
|
638
|
+
endLine,
|
|
639
|
+
signature: firstLine(node.text),
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
}
|
|
619
643
|
}
|
|
620
644
|
else if (node.type === 'preproc_def' ||
|
|
621
645
|
node.type === 'preproc_function_def') {
|
|
@@ -631,10 +655,21 @@ function collectCNodes(parent, symbols) {
|
|
|
631
655
|
}
|
|
632
656
|
}
|
|
633
657
|
else if (node.type === 'preproc_ifdef' ||
|
|
634
|
-
node.type === 'preproc_ifndef'
|
|
635
|
-
|
|
658
|
+
node.type === 'preproc_ifndef' ||
|
|
659
|
+
node.type === 'preproc_if') {
|
|
660
|
+
// Recurse into conditional blocks (then-branch only).
|
|
661
|
+
// preproc_else / preproc_elif children are skipped.
|
|
662
|
+
collectCNodes(node, symbols);
|
|
663
|
+
}
|
|
664
|
+
else if (node.type === 'linkage_specification' ||
|
|
665
|
+
node.type === 'declaration_list') {
|
|
666
|
+
// extern "C" { ... } wraps declarations in linkage_specification
|
|
667
|
+
// containing a declaration_list — recurse through both.
|
|
636
668
|
collectCNodes(node, symbols);
|
|
637
669
|
}
|
|
670
|
+
else if (node.type === 'preproc_else' || node.type === 'preproc_elif') {
|
|
671
|
+
// Skip else/elif branches of preprocessor conditionals.
|
|
672
|
+
}
|
|
638
673
|
}
|
|
639
674
|
}
|
|
640
675
|
function firstLine(text) {
|