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

Function findCppDeclarationSyntax

src/extraction/grammars.ts:978–1002  ·  view source on GitHub ↗
(source: string)

Source from the content-addressed store, hash-verified

976 * section reads as C++, as one with a class or a template there already does.
977 */
978export function findCppDeclarationSyntax(source: string): string | null {
979 if (/^[ \t]*#[ \t]*import\b/m.test(source)) return null;
980 const code = cDeclarationView(source);
981 if (code.includes('@')) return null;
982
983 const constRef = CPP_CONST_REF_RE.exec(code);
984 if (constRef) return constRef[0].trim();
985 const templateDecl = CPP_TEMPLATE_DECLARATION_RE.exec(code);
986 if (templateDecl) return templateDecl[0].replace(/^[;{}]/, '').trim();
987
988 CPP_FUNCTION_HEAD_RE.lastIndex = 0;
989 for (let m = CPP_FUNCTION_HEAD_RE.exec(code); m; m = CPP_FUNCTION_HEAD_RE.exec(code)) {
990 const name = m[2]!;
991 if (C_NOT_FUNCTION_NAMES.has(name) || /^_*[A-Z][A-Z0-9_]*$/.test(name)) continue;
992 const words = m[1]!.replace(/<[^<>]*(?:<[^<>]*>[^<>]*)*>/g, ' ').match(/[A-Za-z_]\w*/g) ?? [];
993 if (words.some((w) => C_STATEMENT_KEYWORDS.has(w))) continue;
994 if (words.every((w) => C_DECL_SPECIFIERS.has(w))) continue;
995 const open = m.index + m[0].length - 1;
996 const params = topLevelParameters(code, open);
997 if (params !== null && hasCppParameterSyntax(params)) {
998 return `${m[0].replace(/^[;{}]/, '').trim()}${params})`;
999 }
1000 }
1001 return null;
1002}
1003
1004/**
1005 * Heuristic: does a .h file contain Objective-C constructs?

Callers 2

detectLanguageFunction · 0.85

Calls 5

cDeclarationViewFunction · 0.85
topLevelParametersFunction · 0.85
hasCppParameterSyntaxFunction · 0.85
hasMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected