mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 13:11:32 +00:00
frontend: implement basic scope analysis
This commit is contained in:
@ -15,7 +15,8 @@ class RootCommand : CliktCommand(
|
||||
ReprintCommand(),
|
||||
ParseCommand(),
|
||||
AstCommand(),
|
||||
AttributeCommand()
|
||||
AttributeCommand(),
|
||||
ScopeAnalysisCommand()
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,27 @@
|
||||
package gay.pizza.pork.tool
|
||||
|
||||
import com.github.ajalt.clikt.core.CliktCommand
|
||||
import com.github.ajalt.clikt.parameters.arguments.argument
|
||||
import gay.pizza.dough.fs.PlatformFsProvider
|
||||
import gay.pizza.pork.frontend.scope.WorldScope
|
||||
import gay.pizza.pork.minimal.FileTool
|
||||
|
||||
class ScopeAnalysisCommand : CliktCommand(help = "Run Scope Analysis", name = "scope-analysis") {
|
||||
val path by argument("file")
|
||||
|
||||
override fun run() {
|
||||
val tool = FileTool(PlatformFsProvider.resolve(path))
|
||||
val world = tool.buildWorld()
|
||||
val root = world.load(tool.rootImportLocator)
|
||||
val scope = WorldScope(world).apply { index(root) }
|
||||
val rootScope = scope.scope(root)
|
||||
val visibleScopeSymbols = rootScope.findInternallyVisibleSymbols()
|
||||
for (visibleScopeSymbol in visibleScopeSymbols) {
|
||||
println(
|
||||
"symbol ${visibleScopeSymbol.scopeSymbol.symbol.id} " +
|
||||
"type=${visibleScopeSymbol.scopeSymbol.definition.type.name} " +
|
||||
"internal=${visibleScopeSymbol.isInternalSymbol}"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user