vancode/interpreter/resolver

This module defines a file resolver for managing file imports and includes. It tracks which files have been resolve (imported/included) by which other files, and provides utilities for checking dependencies and resolving files.

This is used by the interpreter to manage file imports and includes, and to detect circular dependencies.

Types

FileResolver = object
  resolvedFiles*: ResolvedFiles
Manages file resolution for imports/includes
ResolverError = object of CatchableError

Procs

proc clearFile(resolver: var FileResolver; filePath: string) {.
    ...raises: [KeyError], tags: [], forbids: [].}
Clear the resolution status of a file
proc dependants(resolver: FileResolver; target: string; recursive = true): seq[
    string] {....raises: [], tags: [], forbids: [].}
Returns a list of files that depend on the target file. If recursive is true, it will return all files that directly or indirectly depend on the target. Otherwise it will only return files that directly depend to the target.
proc dependencies(resolver: FileResolver; filePath: string): seq[string] {.
    ...raises: [], tags: [], forbids: [].}
proc fileExists(resolver: FileResolver; filePath: string): bool {....raises: [],
    tags: [ReadDirEffect], forbids: [].}
proc initResolver(): FileResolver {....raises: [], tags: [], forbids: [].}
Initialize a new FileResolver
proc isResolved(resolver: FileResolver; filePath: string): bool {....raises: [],
    tags: [], forbids: [].}
proc resolveFile(resolver: var FileResolver; aFile, bFile: string) {.
    ...raises: [ResolverError, KeyError], tags: [ReadDirEffect], forbids: [].}

Resolve a file import/include. This proc checks if the file exists, if it has already been resolved, and if there are any circular or self-imports.

If all checks pass, it marks the file as resolved. TODO handle symlinks

proc setDependencies(resolver: var FileResolver; aFile: string;
                     deps: openArray[string]) {....raises: [], tags: [],
    forbids: [].}
Set the dependencies for a file. This is used to mark which files have been resolved (imported/included) by a given file