From 399170fd58e085a770fe831e2f9770a6b16258ef Mon Sep 17 00:00:00 2001 From: Nick Rolfe Date: Thu, 26 Nov 2020 15:33:50 +0000 Subject: [PATCH] Add getParent(Index) to user-facing AstNode --- ql/src/codeql_ruby/AST.qll | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/ql/src/codeql_ruby/AST.qll b/ql/src/codeql_ruby/AST.qll index d9f0bfb47a9..89ccae6c3eb 100644 --- a/ql/src/codeql_ruby/AST.qll +++ b/ql/src/codeql_ruby/AST.qll @@ -1,14 +1,17 @@ +import codeql.Locations import codeql_ruby.Method import codeql_ruby.Parameter private import codeql_ruby.Generated -class Location = Generated::Location; - /** * A node in the abstract syntax tree. This class is the base class for all Ruby * program elements. */ class AstNode extends @ast_node { + Generated::AstNode generated; + + AstNode() { generated = this } + /** * Gets the name of a primary CodeQL class to which this node belongs. * @@ -22,7 +25,18 @@ class AstNode extends @ast_node { string toString() { result = "AstNode" } /** Gets the location if this node. */ - Location getLocation() { result = this.(Generated::AstNode).getLocation() } + Location getLocation() { result = generated.getLocation() } + + /** + * Gets the parent of this node in the abstract syntax tree, if it has one. + */ + AstNode getParent() { result = generated.getParent() } + + /** + * Gets the index (position) of this node in the parent node's list of + * children. + */ + int getParentIndex() { result = generated.getParentIndex() } } /**