Fix NodeType hierarchy.

This commit is contained in:
Alex Zenla 2023-09-04 03:09:09 -07:00
parent e49ad7c4ba
commit edec706ed4
Signed by: alex
GPG Key ID: C0780728420EBFE5
3 changed files with 3 additions and 6 deletions

View File

@ -11,7 +11,7 @@ class FunctionDefinition(
val arguments: List<Symbol>,
val block: Block
) : Definition() {
override val type: NodeType = NodeType.FunctionDeclaration
override val type: NodeType = NodeType.FunctionDefinition
override fun <T> visitChildren(visitor: NodeVisitor<T>): List<T> =
visitor.visitNodes(symbol)

View File

@ -5,6 +5,7 @@ enum class NodeType(val parent: NodeType? = null) {
Symbol(Node),
Expression(Node),
Declaration(Node),
Definition(Node),
Block(Node),
CompilationUnit(Node),
IntLiteral(Expression),
@ -20,7 +21,7 @@ enum class NodeType(val parent: NodeType? = null) {
FunctionCall(Expression),
If(Expression),
ImportDeclaration(Declaration),
FunctionDeclaration(Declaration);
FunctionDefinition(Definition);
val parents: Set<NodeType>
@ -37,6 +38,4 @@ enum class NodeType(val parent: NodeType? = null) {
}
parents = calculatedParents.toSet()
}
fun isa(type: NodeType): Boolean = this == type || parents.contains(type)
}

View File

@ -37,6 +37,4 @@ class World(val contentSource: ContentSource) {
resolveAllImports(unit)
return unit
}
fun units(path: String): Set<CompilationUnit> = resolveAllImports(loadOneUnit(path))
}