-
Notifications
You must be signed in to change notification settings - Fork 0
Add C and C++ extraction coverage #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,6 +96,27 @@ const patterns: Partial<Record<Language, Pattern[]>> = { | |
| { kind: "protocol", regex: /^\s*(?:public|internal|private|fileprivate|\s)*protocol\s+([A-Za-z_]\w*)/gm }, | ||
| { kind: "actor", regex: /^\s*(?:public|open|internal|private|fileprivate|final|\s)*actor\s+([A-Za-z_]\w*)/gm }, | ||
| { kind: "function", regex: /^\s*(?:public|open|internal|private|fileprivate|static|class|mutating|nonisolated|override|async|\s)*func\s+([A-Za-z_]\w*)/gm } | ||
| ], | ||
| c: [ | ||
| { kind: "struct", regex: /^\s*(?:typedef\s+)?struct\s+([A-Za-z_]\w*)/gm }, | ||
| { kind: "enum", regex: /^\s*(?:typedef\s+)?enum\s+([A-Za-z_]\w*)/gm }, | ||
| { kind: "macro", regex: /^\s*#\s*define\s+([A-Za-z_]\w*)/gm }, | ||
| { | ||
| kind: "function", | ||
| regex: | ||
| /^[^\S\r\n]*(?:(?:static|inline|extern|const|volatile|unsigned|signed|long|short)[^\S\r\n]+){0,8}[A-Za-z_]\w*(?:[^\S\r\n]+[\w*]+)*[^\S\r\n]+(?:\*[^\S\r\n]*)?([A-Za-z_]\w*)[^\S\r\n]*\([^;{}\n]*\)[^\S\r\n]*\{/gm | ||
| } | ||
| ], | ||
| cpp: [ | ||
| { kind: "namespace", regex: /^\s*namespace\s+([A-Za-z_]\w*)\s*\{/gm }, | ||
| { kind: "class", regex: /^\s*(?:template\s*<[^>]+>\s*)?(?:class|typename\s+)?class\s+([A-Za-z_]\w*)/gm }, | ||
| { kind: "struct", regex: /^\s*(?:template\s*<[^>]+>\s*)?struct\s+([A-Za-z_]\w*)/gm }, | ||
| { kind: "enum", regex: /^\s*enum(?:\s+class)?\s+([A-Za-z_]\w*)/gm }, | ||
| { | ||
| kind: "function", | ||
| regex: | ||
| /^[^\S\r\n]*(?:template[^\S\r\n]*<[^>\n]+>[^\S\r\n]*)?(?:(?:inline|static|virtual|constexpr|consteval|explicit|friend|extern|typename|class)[^\S\r\n]+){0,8}[A-Za-z_][\w:<>,~*&\[\]]*(?:[^\S\r\n]+[\w:<>,~*&\[\]]+)*[^\S\r\n]+(?:[A-Za-z_]\w*::)?([A-Za-z_]\w*)[^\S\r\n]*\([^;{}\n]*\)[^\S\r\n]*(?:const[^\S\r\n]*)?(?:noexcept[^\S\r\n]*)?(?:override[^\S\r\n]*)?(?:final[^\S\r\n]*)?\{/gm | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
|
|
@@ -621,7 +642,9 @@ export function extractImports(language: Language, content: string): string[] { | |
| go: [/^\s*import\s+(?:"([^"]+)"|`([^`]+)`)/gm], | ||
| java: [/^\s*import\s+([\w.*]+);/gm], | ||
| rust: [/^\s*use\s+([^;]+);/gm], | ||
| swift: [/^\s*import\s+([A-Za-z_][\w.]*)/gm] | ||
| swift: [/^\s*import\s+([A-Za-z_][\w.]*)/gm], | ||
| c: [/^\s*#\s*include\s+[<"]([^>"]+)[>"]/gm], | ||
| cpp: [/^\s*#\s*include\s+[<"]([^>"]+)[>"]/gm, /^\s*import\s+([A-Za-z_][\w.:]*)\s*;/gm] | ||
| }; | ||
| for (const regex of patternsByLanguage[language] ?? []) { | ||
| for (const match of content.matchAll(regex)) { | ||
|
|
@@ -2171,10 +2194,10 @@ function declarationTypeRelations(symbol: SymbolNode, declaration: string): Arra | |
| if (rustTraitBounds?.[1]) { | ||
| relations.push({ type: "INHERITS", targets: typeNamesFromList(rustTraitBounds[1]), reason: "trait bound" }); | ||
| } | ||
| if (["swift", "kotlin"].includes(symbol.language) || ["struct", "enum", "protocol", "actor"].includes(symbol.kind)) { | ||
| const swiftConformance = /\b(?:class|struct|enum|actor|protocol)\s+[A-Za-z_]\w*(?:<[^>{}]+>)?\s*:\s*([^{}]+)/.exec(compact); | ||
| if (swiftConformance?.[1]) { | ||
| relations.push({ targets: typeNamesFromList(swiftConformance[1]), reason: "swift inheritance or conformance" }); | ||
| if (["swift", "kotlin", "cpp"].includes(symbol.language) || ["struct", "enum", "protocol", "actor"].includes(symbol.kind)) { | ||
| const colonConformance = /\b(?:class|struct|enum|actor|protocol)\s+[A-Za-z_]\w*(?:<[^>{}]+>)?\s*:\s*([^{}]+)/.exec(compact); | ||
| if (colonConformance?.[1]) { | ||
| relations.push({ targets: typeNamesFromList(colonConformance[1]), reason: "colon inheritance or conformance" }); | ||
|
Comment on lines
+2197
to
+2200
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For C++ inheritance like Useful? React with 👍 / 👎. |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -2196,6 +2219,7 @@ function typeNamesFromList(value: string): string[] { | |
| for (const segment of value.split(/[,|+&]/)) { | ||
| const cleaned = segment | ||
| .replace(/<[^<>]*>/g, " ") | ||
| .replace(/\b(?:public|private|protected|virtual|override|final)\b/g, " ") | ||
| .replace(/\bwhere\b[\s\S]*$/i, " ") | ||
| .trim(); | ||
| const match = /(?:[A-Za-z_$][\w$]*\.)*([A-Za-z_$][\w$]*)/.exec(cleaned); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ export type Language = | |
| | "java" | ||
| | "rust" | ||
| | "swift" | ||
| | "c" | ||
| | "cpp" | ||
| | "sql" | ||
| | "yaml" | ||
| | "markdown" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a local C/C++ header is included with the normal quoted form (
#include "orders.h"), this regex returns onlyorders.hand loses that it was quoted.buildResolvedImportEdgesthen passes the bare specifier toresolveImportFile, which only performs same-directory relative resolution for specifiers starting with., so common local headers in the same folder are left as external-only imports and never produceIMPORTS_FILEedges. This breaks the new include graph for the typical non-./quoted include case.Useful? React with 👍 / 👎.