@@ -56,6 +56,15 @@ class AstNode extends TAstNode {
5656 * Gets the primary QL class for the ast node.
5757 */
5858 string getAPrimaryQlClass ( ) { result = "???" }
59+
60+ /**
61+ * Gets the predicate that contains this AST node.
62+ */
63+ pragma [ noinline]
64+ Predicate getEnclosingPredicate ( ) {
65+ not this instanceof Predicate and
66+ toGenerated ( result ) = toGenerated ( this ) .getParent + ( )
67+ }
5968}
6069
6170/** A toplevel QL program, i.e. a file. */
@@ -145,7 +154,14 @@ class Predicate extends TPredicate, AstNode {
145154 /**
146155 * Gets the number of parameters.
147156 */
148- int getArity ( ) { result = count ( getParameter ( _) ) }
157+ int getArity ( ) {
158+ not this .( ClasslessPredicate ) .getAlias ( ) instanceof PredicateExpr and
159+ result = count ( getParameter ( _) )
160+ or
161+ exists ( PredicateExpr alias | alias = this .( ClasslessPredicate ) .getAlias ( ) |
162+ result = alias .getArity ( )
163+ )
164+ }
149165
150166 /**
151167 * Gets the return type (if any) of the predicate.
@@ -990,6 +1006,21 @@ class Float extends Literal {
9901006 float getValue ( ) { result = lit .getChild ( ) .( Generated:: Float ) .getValue ( ) .toFloat ( ) }
9911007}
9921008
1009+ /** A boolean literal */
1010+ class Boolean extends Literal {
1011+ Generated:: Bool bool ;
1012+
1013+ Boolean ( ) { lit .getChild ( ) = bool }
1014+
1015+ /** Holds if the value is `true` */
1016+ predicate isTrue ( ) { bool .getChild ( ) instanceof Generated:: True }
1017+
1018+ /** Holds if the value is `false` */
1019+ predicate isFalse ( ) { bool .getChild ( ) instanceof Generated:: False }
1020+
1021+ override string getAPrimaryQlClass ( ) { result = "Boolean" }
1022+ }
1023+
9931024/** A comparison symbol, such as `"<"` or `"="`. */
9941025class ComparisonSymbol extends string {
9951026 ComparisonSymbol ( ) {
@@ -1315,6 +1346,19 @@ class ExprAggregate extends TExprAggregate, Expr {
13151346 pred = indexedMember ( "getOrderBy" , i ) and result = this .getOrderBy ( i )
13161347 )
13171348 }
1349+
1350+ override Type getType ( ) {
1351+ exists ( PrimitiveType prim | prim = result |
1352+ kind .regexpMatch ( "(strict)?count|sum|min|max|rank" ) and
1353+ result .getName ( ) = "int"
1354+ or
1355+ kind .regexpMatch ( "(strict)?concat" ) and
1356+ result .getName ( ) = "string"
1357+ )
1358+ or
1359+ not kind = [ "count" , "strictcount" ] and
1360+ result = getExpr ( 0 ) .getType ( )
1361+ }
13181362}
13191363
13201364/** An aggregate expression, such as `count` or `sum`. */
@@ -1365,12 +1409,21 @@ class Aggregate extends TAggregate, Expr {
13651409
13661410 override string getAPrimaryQlClass ( ) { result = "Aggregate[" + kind + "]" }
13671411
1368- override PrimitiveType getType ( ) {
1369- kind .regexpMatch ( "(strict)?count|sum|min|max|rank" ) and
1370- result .getName ( ) = "int"
1412+ override Type getType ( ) {
1413+ exists ( PrimitiveType prim | prim = result |
1414+ kind .regexpMatch ( "(strict)?count|sum|min|max|rank" ) and
1415+ result .getName ( ) = "int"
1416+ or
1417+ kind .regexpMatch ( "(strict)?concat" ) and
1418+ result .getName ( ) = "string"
1419+ )
1420+ or
1421+ kind = [ "any" , "min" , "max" ] and
1422+ not exists ( getExpr ( _) ) and
1423+ result = getArgument ( 0 ) .getTypeExpr ( ) .getResolvedType ( )
13711424 or
1372- kind . regexpMatch ( "(strict)?concat" ) and
1373- result . getName ( ) = "string"
1425+ not kind = [ "count" , "strictcount" ] and
1426+ result = getExpr ( 0 ) . getType ( )
13741427 }
13751428
13761429 override AstNode getAChild ( string pred ) {
@@ -1499,6 +1552,13 @@ class ThisAccess extends Identifier {
14991552 override string getAPrimaryQlClass ( ) { result = "ThisAccess" }
15001553}
15011554
1555+ /** A use of `super`. */
1556+ class Super extends TSuper , Expr {
1557+ Super ( ) { this = TSuper ( _) }
1558+
1559+ override string getAPrimaryQlClass ( ) { result = "SuperAccess" }
1560+ }
1561+
15021562/** An access to `result`. */
15031563class ResultAccess extends Identifier {
15041564 ResultAccess ( ) { any ( Generated:: Result r ) .getParent ( ) = id }
0 commit comments