mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 08:54:53 +00:00
TODO: - [ ] test writing of .nif files - [x] implement loading of fields in PType/PSym that might not have been loaded - [ ] implement interface logic - [ ] implement pragma "replays" - [ ] implement special logic for `converter` - [ ] implement special logic for `method` - [ ] test the logic holds up for `export` - [ ] implement logic to free the memory of PSym/PType if memory pressure is high - [ ] implement logic to close memory mapped files if too many are open. --------- Co-authored-by: demotomohiro <gpuppur@gmail.com> Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> Co-authored-by: Jacek Sieka <arnetheduck@gmail.com>
62 lines
1.8 KiB
Nim
62 lines
1.8 KiB
Nim
#
|
|
#
|
|
# The Nim Compiler
|
|
# (c) Copyright 2022 Andreas Rumpf
|
|
#
|
|
# See the file "copying.txt", included in this
|
|
# distribution, for details about the copyright.
|
|
#
|
|
|
|
## Package related procs.
|
|
##
|
|
## See Also:
|
|
## * `packagehandling` for package path handling
|
|
## * `modulegraphs.getPackage`
|
|
## * `modulegraphs.belongsToStdlib`
|
|
|
|
import "." / [options, ast, lineinfos, idents, pathutils, msgs]
|
|
|
|
when defined(nimPreviewSlimSystem):
|
|
import std/assertions
|
|
|
|
|
|
proc getPackage*(conf: ConfigRef; cache: IdentCache; fileIdx: FileIndex): PSym =
|
|
## Return a new package symbol.
|
|
##
|
|
## See Also:
|
|
## * `modulegraphs.getPackage`
|
|
let
|
|
filename = AbsoluteFile toFullPath(conf, fileIdx)
|
|
name = getIdent(cache, splitFile(filename).name)
|
|
info = newLineInfo(fileIdx, 1, 1)
|
|
pkgName = getPackageName(conf, filename.string)
|
|
pkgIdent = getIdent(cache, pkgName)
|
|
newSym(skPackage, pkgIdent, idGeneratorForPackage(int32(fileIdx)), nil, info)
|
|
|
|
proc getPackageSymbol*(sym: PSym): PSym =
|
|
## Return the owning package symbol.
|
|
assert sym != nil
|
|
result = sym
|
|
while result.kind != skPackage:
|
|
result = result.owner
|
|
assert result != nil, repr(sym.info)
|
|
|
|
proc getPackageId*(sym: PSym): int =
|
|
## Return the owning package ID.
|
|
sym.getPackageSymbol.id
|
|
|
|
proc belongsToProjectPackage*(conf: ConfigRef, sym: PSym): bool =
|
|
## Return whether the symbol belongs to the project's package.
|
|
##
|
|
## See Also:
|
|
## * `modulegraphs.belongsToStdlib`
|
|
conf.mainPackageId == sym.getPackageId
|
|
|
|
proc belongsToProjectPackageMaybeNil*(conf: ConfigRef, sym: PSym): bool =
|
|
## Return whether the symbol belongs to the project's package.
|
|
## Returns `false` if `sym` is nil.
|
|
##
|
|
## See Also:
|
|
## * `modulegraphs.belongsToStdlib`
|
|
sym != nil and conf.mainPackageId == sym.getPackageId
|