QL: Add AST support for HOPs

This commit is contained in:
Taus
2021-05-27 14:37:15 +00:00
committed by GitHub
parent 69b4d577d5
commit f61471c451
2 changed files with 20 additions and 2 deletions

View File

@@ -753,6 +753,22 @@ class InstanceOf extends TInstanceOf, Formula {
override string getAPrimaryQlClass() { result = "InstanceOf" }
}
class HigherOrderFormula extends THigherOrderFormula, Formula {
Generated::HigherOrderTerm hop;
HigherOrderFormula() { this = THigherOrderFormula(hop) }
PredicateExpr getInput(int i) { toGenerated(result) = hop.getChild(i).(Generated::PredicateExpr) }
private int getNumInputs() { result = 1 + max(int i | exists(this.getInput(i))) }
Expr getArgument(int i) { toGenerated(result) = hop.getChild(i + getNumInputs()) }
string getName() { result = hop.getName().getValue() }
override string getAPrimaryQlClass() { result = "HigherOrderFormula" }
}
/** An aggregate expression, such as `count` or `sum`. */
class Aggregate extends TAggregate, Expr {
Generated::Aggregate agg;

View File

@@ -40,6 +40,7 @@ newtype TAstNode =
TIfFormula(Generated::IfTerm ifterm) or
TImplication(Generated::Implication impl) or
TInstanceOf(Generated::InstanceOf inst) or
THigherOrderFormula(Generated::HigherOrderTerm hop) or
TExprAnnotation(Generated::ExprAnnotation expr_anno) or
TAddExpr(Generated::AddExpr addexp) or
TLiteral(Generated::Literal lit) or
@@ -50,7 +51,7 @@ newtype TAstNode =
class TFormula =
TDisjunction or TConjunction or TComparisonFormula or TQuantifier or TNegation or TIfFormula or
TImplication or TInstanceOf or TCall;
TImplication or TInstanceOf or TCall or THigherOrderFormula;
class TBinOpExpr = TAddExpr;
@@ -73,7 +74,8 @@ Generated::AstNode toGeneratedFormula(AST::AstNode n) {
n = TNegation(result) or
n = TIfFormula(result) or
n = TImplication(result) or
n = TInstanceOf(result)
n = TInstanceOf(result) or
n = THigherOrderFormula(result)
}
Generated::AstNode toGeneratedExpr(AST::AstNode n) {