From cdd9978c30cb1e82adb96a2a3237c1725023c852 Mon Sep 17 00:00:00 2001 From: Taus Date: Thu, 27 May 2021 10:12:41 +0000 Subject: [PATCH] ifs, implications, instanceof --- ql/src/codeql_ql/ast/Ast.qll | 47 ++++++++++++++++++++++ ql/src/codeql_ql/ast/internal/AstNodes.qll | 14 ++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/ql/src/codeql_ql/ast/Ast.qll b/ql/src/codeql_ql/ast/Ast.qll index c8c5c321ec4..ae50725f897 100644 --- a/ql/src/codeql_ql/ast/Ast.qll +++ b/ql/src/codeql_ql/ast/Ast.qll @@ -620,6 +620,53 @@ class Forex extends Quantifier { override string getAPrimaryQlClass() { result = "Forex" } } +class IfFormula extends TIfFormula, Formula { + Generated::IfTerm ifterm; + + IfFormula() { this = TIfFormula(ifterm) } + + /** Gets the condition of this if formula. */ + Formula getCondition() { toGenerated(result) = ifterm.getCond() } + + /** Gets the then part of this if formula. */ + Formula getThenPart() { toGenerated(result) = ifterm.getFirst() } + + /** Gets the else part of this if formula. */ + Formula getElsePart() { toGenerated(result) = ifterm.getSecond() } + + override string getAPrimaryQlClass() { result = "IfFormula" } +} + +class Implication extends TImplication, Formula { + Generated::Implication imp; + + Implication() { this = TImplication(imp) } + + /** Gets the left operand of this implication. */ + Formula getLeftOperand() { toGenerated(result) = imp.getLeft() } + + /** Gets the right operand of this implication. */ + Formula getRightOperand() { toGenerated(result) = imp.getRight() } + + override string getAPrimaryQlClass() { result = "Implication" } +} + +class InstanceOf extends TInstanceOf, Formula { + Generated::InstanceOf inst; + + InstanceOf() { this = TInstanceOf(inst) } + + /** Gets the expression being checked. */ + Expr getExpr() { toGenerated(result) = inst.getChild(0) } + + /** Gets the reference to the type being checked. */ + Type getType() { toGenerated(result) = inst.getChild(1) } + + /** Gets the type being checked. */ + //QLType getType() { result = getTypeRef().getType() } + override string getAPrimaryQlClass() { result = "InstanceOf" } +} + class Aggregate extends TAggregate, Expr { Generated::Aggregate agg; Generated::FullAggregateBody body; diff --git a/ql/src/codeql_ql/ast/internal/AstNodes.qll b/ql/src/codeql_ql/ast/internal/AstNodes.qll index 6eb65cde7fa..c90231b9d0c 100644 --- a/ql/src/codeql_ql/ast/internal/AstNodes.qll +++ b/ql/src/codeql_ql/ast/internal/AstNodes.qll @@ -37,13 +37,18 @@ newtype TAstNode = not agg.getChild(_) instanceof Generated::FullAggregateBody } or TNegation(Generated::Negation neg) or + TIfFormula(Generated::IfTerm ifterm) or + TImplication(Generated::Implication impl) or + TInstanceOf(Generated::InstanceOf inst) or TAddExpr(Generated::AddExpr addexp) or TLiteral(Generated::Literal lit) or TUnaryExpr(Generated::UnaryExpr unaryexpr) or TDontCare(Generated::Underscore dontcare) or TModuleExpr(Generated::ModuleExpr me) -class TFormula = TDisjunction or TConjunction or TComparisonFormula or TQuantifier or TNegation; +class TFormula = + TDisjunction or TConjunction or TComparisonFormula or TQuantifier or TNegation or TIfFormula or + TImplication or TInstanceOf; class TBinOpExpr = TAddExpr; @@ -59,7 +64,12 @@ Generated::AstNode toGeneratedFormula(AST::AstNode n) { n = TComparisonFormula(result) or n = TComparisonOp(result) or n = TQuantifier(result) or - n = TNegation(result) + n = TAggregate(result) or + n = TIdentifier(result) or + n = TNegation(result) or + n = TIfFormula(result) or + n = TImplication(result) or + n = TInstanceOf(result) } Generated::AstNode toGeneratedExpr(AST::AstNode n) {