AST: add getChild/getParent method

This commit is contained in:
Arthur Baars
2021-02-17 13:36:01 +01:00
parent ac3da22158
commit 214f113016
2 changed files with 8 additions and 0 deletions

View File

@@ -36,4 +36,10 @@ class AstNode extends @ast_node {
/** Gets the location of this node. */
final Location getLocation() { result = range.getLocation() }
/** Gets a child node of this `AstNode`. */
final AstNode getAChild() { range.child(_, result) }
/** Gets the parent of this `AstNode`, if this node is not a root node. */
final AstNode getParent() { result.getAChild() = this }
}

View File

@@ -11,6 +11,8 @@ module AstNode {
abstract string toString();
Location getLocation() { result = generated.getLocation() }
predicate child(string label, AstNode::Range child) { none() }
}
// TODO: Remove