MCPcopy Create free account
hub / github.com/LegacyCodeHQ/clarity-cli / ResolveCppIncludePath

Function ResolveCppIncludePath

depgraph/languages/cpp/parser_cpp.go:247–277  ·  view source on GitHub ↗

ResolveCppIncludePath resolves a C++ include path to possible file paths.

(sourceFile, includePath string, suppliedFiles map[string]bool)

Source from the content-addressed store, hash-verified

245
246// ResolveCppIncludePath resolves a C++ include path to possible file paths.
247func ResolveCppIncludePath(sourceFile, includePath string, suppliedFiles map[string]bool) []string {
248 sourceDir := filepath.Dir(sourceFile)
249 baseCandidates := includeBasePathCandidates(sourceDir, includePath)
250 seen := make(map[string]bool)
251
252 var resolvedPaths []string
253 appendResolved := func(path string) {
254 if !seen[path] && suppliedFiles[path] {
255 seen[path] = true
256 resolvedPaths = append(resolvedPaths, path)
257 }
258 }
259
260 if filepath.Ext(includePath) != "" {
261 for _, base := range baseCandidates {
262 appendResolved(base)
263 }
264 sort.Strings(resolvedPaths)
265 return resolvedPaths
266 }
267
268 extensions := []string{".h", ".hpp", ".hh", ".hxx"}
269 for _, base := range baseCandidates {
270 for _, ext := range extensions {
271 appendResolved(base + ext)
272 }
273 }
274
275 sort.Strings(resolvedPaths)
276 return resolvedPaths
277}
278
279func includeBasePathCandidates(sourceDir, includePath string) []string {
280 candidates := make(map[string]bool)

Calls 1