mirror of
https://github.com/github/codeql.git
synced 2026-04-29 18:55:14 +02:00
QL: Add module expressions and module aliases
This commit is contained in:
@@ -203,6 +203,11 @@ class Module extends TModule, AstNode, ModuleMember {
|
||||
AstNode getAMember() {
|
||||
toGenerated(result) = mod.getChild(_).(Generated::ModuleMember).getChild(_)
|
||||
}
|
||||
|
||||
/** Gets the module expression that this module is an alias for, if any. */
|
||||
ModuleExpr getAlias() {
|
||||
toGenerated(result) = mod.getAFieldOrChild().(Generated::ModuleAliasBody).getChild()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -624,3 +629,38 @@ class AddExpr extends TAddExpr, BinOpExpr {
|
||||
|
||||
FunctionSymbol getOperator() { result = addexpr.getChild().getValue() }
|
||||
}
|
||||
|
||||
/** A module expression. */
|
||||
class ModuleExpr extends TModuleExpr, AstNode {
|
||||
Generated::ModuleExpr me;
|
||||
|
||||
ModuleExpr() { this = TModuleExpr(me) }
|
||||
|
||||
/**
|
||||
* Gets the name of this module expression. For example, the name of
|
||||
*
|
||||
* ```ql
|
||||
* Foo::Bar
|
||||
* ```
|
||||
*
|
||||
* is `Bar`.
|
||||
*/
|
||||
string getName() {
|
||||
result = me.getName().getValue()
|
||||
or
|
||||
not exists(me.getName()) and result = me.getChild().(Generated::SimpleId).getValue()
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the qualifier of this module expression. For example, the qualifier of
|
||||
*
|
||||
* ```ql
|
||||
* Foo::Bar::Baz
|
||||
* ```
|
||||
*
|
||||
* is `Foo::Bar`.
|
||||
*/
|
||||
ModuleExpr getQualifier() { result = TModuleExpr(me.getChild()) }
|
||||
|
||||
final override string toString() { result = this.getName() }
|
||||
}
|
||||
|
||||
@@ -26,7 +26,8 @@ newtype TAstNode =
|
||||
TAsExpr(Generated::AsExpr asExpr) or
|
||||
TNegation(Generated::Negation neg) or
|
||||
TAddExpr(Generated::AddExpr addexp) or
|
||||
TLiteral(Generated::Literal lit)
|
||||
TLiteral(Generated::Literal lit) or
|
||||
TModuleExpr(Generated::ModuleExpr me)
|
||||
|
||||
class TFormula = TDisjunction or TConjunction or TComparisonFormula or TQuantifier or TNegation;
|
||||
|
||||
@@ -80,6 +81,8 @@ Generated::AstNode toGenerated(AST::AstNode n) {
|
||||
n = TLiteral(result)
|
||||
or
|
||||
n = TAsExpr(result)
|
||||
or
|
||||
n = TModuleExpr(result)
|
||||
}
|
||||
|
||||
class TPredicate = TCharPred or TClasslessPredicate or TClassPredicate;
|
||||
|
||||
Reference in New Issue
Block a user