QL: Add module expressions and module aliases

This commit is contained in:
Tom Hvitved
2021-05-27 11:28:37 +02:00
parent 9f68fdfb61
commit 7b64df51ab
2 changed files with 44 additions and 1 deletions

View File

@@ -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() }
}

View File

@@ -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;