mirror of
https://github.com/github/codeql.git
synced 2026-02-08 11:11:06 +01:00
Merge pull request #10 from github/more-expressions
Add more expressions
This commit is contained in:
@@ -403,6 +403,9 @@ class Disjunction extends TDisjunction, AstNode {
|
||||
Formula getAnOperand() { toGenerated(result) in [disj.getLeft(), disj.getRight()] }
|
||||
}
|
||||
|
||||
/**
|
||||
* A comparison operator, such as `<` or `=`.
|
||||
*/
|
||||
class ComparisonOp extends TComparisonOp, AstNode {
|
||||
Generated::Compop op;
|
||||
|
||||
@@ -613,7 +616,7 @@ class FunctionSymbol extends string {
|
||||
FunctionSymbol() { this = "+" or this = "-" or this = "*" or this = "/" or this = "%" }
|
||||
}
|
||||
|
||||
/** A binary operation, such as `x+3` or `y/2` */
|
||||
/** A binary operation expression, such as `x+3` or `y/2` */
|
||||
class BinOpExpr extends TBinOpExpr, Expr { }
|
||||
|
||||
class AddExpr extends TAddExpr, BinOpExpr {
|
||||
@@ -630,6 +633,26 @@ class AddExpr extends TAddExpr, BinOpExpr {
|
||||
FunctionSymbol getOperator() { result = addexpr.getChild().getValue() }
|
||||
}
|
||||
|
||||
/** A unary operation expression, such as `-(x*y)` */
|
||||
class UnaryExpr extends TUnaryExpr, Expr {
|
||||
Generated::UnaryExpr unaryexpr;
|
||||
|
||||
UnaryExpr() { this = TUnaryExpr(unaryexpr) }
|
||||
|
||||
Expr getOperand() { toGenerated(result) = unaryexpr.getChild(1) }
|
||||
|
||||
FunctionSymbol getOperator() { result = unaryexpr.getChild(0).toString() }
|
||||
}
|
||||
|
||||
/** A "don't care" expression, denoted by `_`. */
|
||||
class DontCare extends TDontCare, Expr {
|
||||
Generated::Underscore dontcare;
|
||||
|
||||
DontCare() { this = TDontCare(dontcare) }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "DontCare" }
|
||||
}
|
||||
|
||||
/** A module expression. */
|
||||
class ModuleExpr extends TModuleExpr, AstNode {
|
||||
Generated::ModuleExpr me;
|
||||
|
||||
@@ -27,13 +27,15 @@ newtype TAstNode =
|
||||
TNegation(Generated::Negation neg) 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 TBinOpExpr = TAddExpr;
|
||||
|
||||
class TExpr = TBinOpExpr or TLiteral or TAggregate or TIdentifier;
|
||||
class TExpr = TBinOpExpr or TLiteral or TAggregate or TIdentifier or TUnaryExpr or TDontCare;
|
||||
|
||||
Generated::AstNode toGeneratedFormula(AST::AstNode n) {
|
||||
n = TConjunction(result) or
|
||||
@@ -41,12 +43,17 @@ Generated::AstNode toGeneratedFormula(AST::AstNode n) {
|
||||
n = TComparisonFormula(result) or
|
||||
n = TComparisonOp(result) or
|
||||
n = TQuantifier(result) or
|
||||
n = TAggregate(result) or
|
||||
n = TIdentifier(result) or
|
||||
n = TNegation(result)
|
||||
}
|
||||
|
||||
Generated::AstNode toGeneratedExpr(AST::AstNode n) { n = TAddExpr(result) }
|
||||
Generated::AstNode toGeneratedExpr(AST::AstNode n) {
|
||||
n = TAddExpr(result) or
|
||||
n = TLiteral(result) or
|
||||
n = TAggregate(result) or
|
||||
n = TIdentifier(result) or
|
||||
n = TUnaryExpr(result) or
|
||||
n = TDontCare(result)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the underlying TreeSitter entity for a given AST node.
|
||||
@@ -78,8 +85,6 @@ Generated::AstNode toGenerated(AST::AstNode n) {
|
||||
or
|
||||
n = TType(result)
|
||||
or
|
||||
n = TLiteral(result)
|
||||
or
|
||||
n = TAsExpr(result)
|
||||
or
|
||||
n = TModuleExpr(result)
|
||||
|
||||
Reference in New Issue
Block a user