MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / looksLikeCpp

Function looksLikeCpp

src/extraction/grammars.ts:503–515  ·  view source on GitHub ↗

* Heuristic: does a .h file contain C++ constructs? * Checks the first ~8KB for patterns that are unique to C++ and never valid C.

(source: string)

Source from the content-addressed store, hash-verified

501 * Checks the first ~8KB for patterns that are unique to C++ and never valid C.
502 */
503function looksLikeCpp(source: string): boolean {
504 const sample = source.substring(0, 8192);
505 // The `class MACRO Name : Base` / `class MACRO Name { … }` branch mirrors what
506 // `blankCppExportMacros` recovers: an ALL-CAPS export/visibility macro
507 // (`ENGINE_API`, `MYMODULE_API`, `*_EXPORT`, …) sitting between `class`/`struct`
508 // and the type name. Without it, a header whose ONLY C++ signal is such a
509 // macro-annotated class — common for lean Unreal-Engine types that carry just
510 // `GENERATED_BODY()` and no explicit `public:`/`virtual` — is misdetected as C,
511 // routed through the C extractor (which extracts no classes), and its class
512 // definition silently vanishes. The two-token shape (`<KW> <MACRO> <Name>`
513 // before a `[:{]`) never occurs in valid C, so this can't misclassify C headers.
514 return /\bnamespace\b|\bclass\s+\w+\s*[:{]|\b(?:class|struct)\s+[A-Z][A-Z0-9_]+\s+\w+\s*(?:final\s*)?[:{]|\btemplate\s*<|\b(?:public|private|protected)\s*:|\bvirtual\b|\busing\s+(?:namespace\b|\w+\s*=)/.test(sample);
515}
516
517/**
518 * Heuristic: does a .h file contain Objective-C constructs?

Callers 1

detectLanguageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected