@@ -49,6 +49,7 @@ class AstNode extends TAstNode {
4949 /**
5050 * Gets the parent in the AST for this node.
5151 */
52+ cached
5253 AstNode getParent ( ) { result .getAChild ( _) = this }
5354
5455 /**
@@ -74,12 +75,14 @@ class AstNode extends TAstNode {
7475 predicate hasAnnotation ( string name ) { this .getAnAnnotation ( ) .getName ( ) = name }
7576
7677 /** Gets an annotation of this AST node. */
77- Annotation getAnAnnotation ( ) { toQL ( this ) .getParent ( ) = toQL ( result ) .getParent ( ) }
78+ Annotation getAnAnnotation ( ) {
79+ toQL ( this ) .getParent ( ) = pragma [ only_bind_out ] ( toQL ( result ) ) .getParent ( )
80+ }
7881
7982 /**
8083 * Gets the predicate that contains this AST node.
8184 */
82- pragma [ noinline ]
85+ cached
8386 Predicate getEnclosingPredicate ( ) { this = getANodeInPredicate ( result ) }
8487}
8588
@@ -563,8 +566,10 @@ class VarDecl extends TVarDecl, VarDef, Declaration {
563566 )
564567 }
565568
566- /** If this is a field, returns the class type that declares it. */
567- ClassType getDeclaringType ( ) { result .getDeclaration ( ) .getAField ( ) = this }
569+ /** If this is declared in a field, returns the class type that declares it. */
570+ ClassType getDeclaringType ( ) {
571+ exists ( FieldDecl f | f .getVarDecl ( ) = this and result = f .getParent ( ) .( Class ) .getType ( ) )
572+ }
568573
569574 /**
570575 * Holds if this is a class field that overrides the field `other`.
@@ -580,6 +585,32 @@ class VarDecl extends TVarDecl, VarDef, Declaration {
580585 override string toString ( ) { result = this .getName ( ) }
581586}
582587
588+ /**
589+ * A field declaration;
590+ */
591+ class FieldDecl extends TFieldDecl , AstNode {
592+ QL:: Field f ;
593+
594+ FieldDecl ( ) { this = TFieldDecl ( f ) }
595+
596+ VarDecl getVarDecl ( ) { toQL ( result ) = f .getChild ( ) }
597+
598+ override AstNode getAChild ( string pred ) {
599+ result = super .getAChild ( pred )
600+ or
601+ pred = directMember ( "getVarDecl" ) and result = this .getVarDecl ( )
602+ }
603+
604+ override string getAPrimaryQlClass ( ) { result = "FieldDecl" }
605+
606+ /** Holds if this field is annotated as overriding another field. */
607+ predicate isOverride ( ) { this .hasAnnotation ( "override" ) }
608+
609+ string getName ( ) { result = getVarDecl ( ) .getName ( ) }
610+
611+ override QLDoc getQLDoc ( ) { result = any ( Class c ) .getQLDocFor ( this ) }
612+ }
613+
583614/**
584615 * A type reference, such as `DataFlow::Node`.
585616 */
@@ -716,10 +747,7 @@ class Class extends TClass, TypeDeclaration, ModuleDeclaration {
716747 */
717748 CharPred getCharPred ( ) { toQL ( result ) = cls .getChild ( _) .( QL:: ClassMember ) .getChild ( _) }
718749
719- AstNode getMember ( int i ) {
720- toQL ( result ) = cls .getChild ( i ) .( QL:: ClassMember ) .getChild ( _) or
721- toQL ( result ) = cls .getChild ( i ) .( QL:: ClassMember ) .getChild ( _) .( QL:: Field ) .getChild ( )
722- }
750+ AstNode getMember ( int i ) { toQL ( result ) = cls .getChild ( i ) .( QL:: ClassMember ) .getChild ( _) }
723751
724752 QLDoc getQLDocFor ( AstNode m ) {
725753 exists ( int i | result = this .getMember ( i ) and m = this .getMember ( i + 1 ) )
@@ -743,9 +771,7 @@ class Class extends TClass, TypeDeclaration, ModuleDeclaration {
743771 /**
744772 * Gets a field in this class.
745773 */
746- VarDecl getAField ( ) {
747- toQL ( result ) = cls .getChild ( _) .( QL:: ClassMember ) .getChild ( _) .( QL:: Field ) .getChild ( )
748- }
774+ FieldDecl getAField ( ) { result = getMember ( _) }
749775
750776 /**
751777 * Gets a super-type referenced in the `extends` part of the class declaration.
@@ -1102,9 +1128,15 @@ class Conjunction extends TConjunction, AstNode, Formula {
11021128
11031129 override string getAPrimaryQlClass ( ) { result = "Conjunction" }
11041130
1105- /** Gets an operand to this formula . */
1131+ /** Gets an operand to this conjunction . */
11061132 Formula getAnOperand ( ) { toQL ( result ) in [ conj .getLeft ( ) , conj .getRight ( ) ] }
11071133
1134+ /** Gets the left operand to this conjunction. */
1135+ Formula getLeft ( ) { toQL ( result ) = conj .getLeft ( ) }
1136+
1137+ /** Gets the right operand to this conjunction. */
1138+ Formula getRight ( ) { toQL ( result ) = conj .getRight ( ) }
1139+
11081140 override AstNode getAChild ( string pred ) {
11091141 result = super .getAChild ( pred )
11101142 or
@@ -1120,33 +1152,22 @@ class Disjunction extends TDisjunction, AstNode, Formula {
11201152
11211153 override string getAPrimaryQlClass ( ) { result = "Disjunction" }
11221154
1123- /** Gets an operand to this formula . */
1155+ /** Gets an operand to this disjunction . */
11241156 Formula getAnOperand ( ) { toQL ( result ) in [ disj .getLeft ( ) , disj .getRight ( ) ] }
11251157
1158+ /** Gets the left operand to this disjunction */
1159+ Formula getLeft ( ) { toQL ( result ) = disj .getLeft ( ) }
1160+
1161+ /** Gets the right operand to this disjunction */
1162+ Formula getRight ( ) { toQL ( result ) = disj .getRight ( ) }
1163+
11261164 override AstNode getAChild ( string pred ) {
11271165 result = super .getAChild ( pred )
11281166 or
11291167 pred = directMember ( "getAnOperand" ) and result = this .getAnOperand ( )
11301168 }
11311169}
11321170
1133- /**
1134- * A comparison operator, such as `<` or `=`.
1135- */
1136- class ComparisonOp extends TComparisonOp , AstNode {
1137- QL:: Compop op ;
1138-
1139- ComparisonOp ( ) { this = TComparisonOp ( op ) }
1140-
1141- /**
1142- * Gets a string representing the operator.
1143- * E.g. "<" or "=".
1144- */
1145- ComparisonSymbol getSymbol ( ) { result = op .getValue ( ) }
1146-
1147- override string getAPrimaryQlClass ( ) { result = "ComparisonOp" }
1148- }
1149-
11501171/**
11511172 * A literal expression, such as `6` or `true` or `"foo"`.
11521173 */
@@ -1243,10 +1264,7 @@ class ComparisonFormula extends TComparisonFormula, Formula {
12431264 Expr getAnOperand ( ) { result in [ this .getLeftOperand ( ) , this .getRightOperand ( ) ] }
12441265
12451266 /** Gets the operator of this comparison. */
1246- ComparisonOp getOperator ( ) { toQL ( result ) = comp .getChild ( ) }
1247-
1248- /** Gets the symbol of this comparison (as a string). */
1249- ComparisonSymbol getSymbol ( ) { result = this .getOperator ( ) .getSymbol ( ) }
1267+ ComparisonSymbol getOperator ( ) { result = comp .getChild ( ) .getValue ( ) }
12501268
12511269 override string getAPrimaryQlClass ( ) { result = "ComparisonFormula" }
12521270
@@ -1256,8 +1274,6 @@ class ComparisonFormula extends TComparisonFormula, Formula {
12561274 pred = directMember ( "getLeftOperand" ) and result = this .getLeftOperand ( )
12571275 or
12581276 pred = directMember ( "getRightOperand" ) and result = this .getRightOperand ( )
1259- or
1260- pred = directMember ( "getOperator" ) and result = this .getOperator ( )
12611277 }
12621278}
12631279
@@ -2218,6 +2234,8 @@ class Annotation extends TAnnotation, AstNode {
22182234 /** Gets the node corresponding to the field `name`. */
22192235 string getName ( ) { result = annot .getName ( ) .getValue ( ) }
22202236
2237+ override AstNode getParent ( ) { result = AstNode .super .getParent ( ) }
2238+
22212239 override AstNode getAChild ( string pred ) {
22222240 result = super .getAChild ( pred )
22232241 or
0 commit comments