performance improvements

This commit is contained in:
Erik Krogh Kristensen
2021-11-18 12:11:45 +01:00
parent 84d277dc94
commit ac4476fa82
2 changed files with 8 additions and 2 deletions

View File

@@ -49,6 +49,7 @@ class AstNode extends TAstNode {
/**
* Gets the parent in the AST for this node.
*/
cached
AstNode getParent() { result.getAChild(_) = this }
/**
@@ -74,12 +75,14 @@ class AstNode extends TAstNode {
predicate hasAnnotation(string name) { this.getAnAnnotation().getName() = name }
/** Gets an annotation of this AST node. */
Annotation getAnAnnotation() { toQL(this).getParent() = toQL(result).getParent() }
Annotation getAnAnnotation() {
toQL(this).getParent() = pragma[only_bind_out](toQL(result)).getParent()
}
/**
* Gets the predicate that contains this AST node.
*/
pragma[noinline]
cached
Predicate getEnclosingPredicate() { this = getANodeInPredicate(result) }
}
@@ -2231,6 +2234,8 @@ class Annotation extends TAnnotation, AstNode {
/** Gets the node corresponding to the field `name`. */
string getName() { result = annot.getName().getValue() }
override AstNode getParent() { result = AstNode.super.getParent() }
override AstNode getAChild(string pred) {
result = super.getAChild(pred)
or

View File

@@ -126,6 +126,7 @@ private QL::AstNode toGenerateYAML(AST::AstNode n) {
/**
* Gets the underlying TreeSitter entity for a given AST node.
*/
cached
QL::AstNode toQL(AST::AstNode n) {
result = toQLExpr(n)
or