From 214f1130165ada0ee47d2711aef6c11b6dad28c5 Mon Sep 17 00:00:00 2001 From: Arthur Baars Date: Wed, 17 Feb 2021 13:36:01 +0100 Subject: [PATCH] AST: add getChild/getParent method --- ql/src/codeql_ruby/AST.qll | 6 ++++++ ql/src/codeql_ruby/ast/internal/AST.qll | 2 ++ 2 files changed, 8 insertions(+) diff --git a/ql/src/codeql_ruby/AST.qll b/ql/src/codeql_ruby/AST.qll index 11c41330aa4..28a05877c5f 100644 --- a/ql/src/codeql_ruby/AST.qll +++ b/ql/src/codeql_ruby/AST.qll @@ -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 } } diff --git a/ql/src/codeql_ruby/ast/internal/AST.qll b/ql/src/codeql_ruby/ast/internal/AST.qll index b09355148a1..8fb1159c83f 100644 --- a/ql/src/codeql_ruby/ast/internal/AST.qll +++ b/ql/src/codeql_ruby/ast/internal/AST.qll @@ -11,6 +11,8 @@ module AstNode { abstract string toString(); Location getLocation() { result = generated.getLocation() } + + predicate child(string label, AstNode::Range child) { none() } } // TODO: Remove