@@ -640,7 +640,7 @@ class FieldDecl extends TFieldDecl, AstNode {
640640/**
641641 * A type reference, such as `DataFlow::Node`.
642642 */
643- class TypeExpr extends TType , AstNode {
643+ class TypeExpr extends TType , TypeRef {
644644 QL:: TypeExpr type ;
645645
646646 TypeExpr ( ) { this = TType ( type ) }
@@ -677,10 +677,14 @@ class TypeExpr extends TType, AstNode {
677677 */
678678 ModuleExpr getModule ( ) { toQL ( result ) = type .getQualifier ( ) }
679679
680- /**
681- * Gets the type that this type reference refers to.
682- */
683- Type getResolvedType ( ) { resolveTypeExpr ( this , result ) }
680+ /** Gets the type that this type reference refers to. */
681+ override Type getResolvedType ( ) {
682+ // resolve type
683+ resolveTypeExpr ( this , result )
684+ or
685+ // if it resolves to a module
686+ exists ( FileOrModule mod | resolveModuleRef ( this , mod ) | result = mod .toType ( ) )
687+ }
684688
685689 override AstNode getAChild ( string pred ) {
686690 result = super .getAChild ( pred )
@@ -713,7 +717,7 @@ class Module extends TModule, ModuleDeclaration {
713717 }
714718
715719 /** Gets a ref to the module that this module implements. */
716- ModuleParameterRef getImplements ( int i ) { toQL ( result ) = mod .getImplements ( i ) .getTypeExpr ( ) }
720+ TypeExpr getImplements ( int i ) { toQL ( result ) = mod .getImplements ( i ) .getTypeExpr ( ) }
717721
718722 /** Gets the module expression that this module is an alias for, if any. */
719723 ModuleExpr getAlias ( ) { toQL ( result ) = mod .getAFieldOrChild ( ) .( QL:: ModuleAliasBody ) .getChild ( ) }
@@ -1111,18 +1115,18 @@ class InlineCast extends TInlineCast, Expr {
11111115 }
11121116}
11131117
1114- /** An entity that resolves to a module. */
1115- class ModuleRef extends AstNode , TModuleRef {
1116- /** Gets the module that this entity resolves to. */
1117- FileOrModule getResolvedModule ( ) { none ( ) }
1118+ /** An entity that resolves to a type. */
1119+ class TypeRef extends AstNode , TTypeRef {
1120+ abstract Type getResolvedType ( ) ;
11181121
1119- string getName ( ) { none ( ) }
1122+ /** Gets the module that this entity resolves to, if this reference resolves to a module */
1123+ final FileOrModule getResolvedModule ( ) { result .toType ( ) = this .getResolvedType ( ) }
11201124}
11211125
11221126/**
11231127 * An import statement.
11241128 */
1125- class Import extends TImport , ModuleMember , ModuleRef {
1129+ class Import extends TImport , ModuleMember , TypeRef {
11261130 QL:: ImportDirective imp ;
11271131
11281132 Import ( ) { this = TImport ( imp ) }
@@ -1173,7 +1177,9 @@ class Import extends TImport, ModuleMember, ModuleRef {
11731177 )
11741178 }
11751179
1176- final override FileOrModule getResolvedModule ( ) { resolve ( this , result ) }
1180+ override Type getResolvedType ( ) {
1181+ exists ( FileOrModule mod | resolve ( this , mod ) | result = mod .toType ( ) )
1182+ }
11771183}
11781184
11791185/** A formula, such as `x = 6 and y < 5`. */
@@ -2191,18 +2197,8 @@ class DontCare extends TDontCare, Expr {
21912197 override string getAPrimaryQlClass ( ) { result = "DontCare" }
21922198}
21932199
2194- /**
2195- * A type expression seen as a reference to a module as part of a parameterized module (or it's instantiation).
2196- * This might not be a reference to a module, but we assume so until we find out in the resolve phase.
2197- */
2198- class ModuleParameterRef extends ModuleRef instanceof TypeExpr {
2199- final override FileOrModule getResolvedModule ( ) { resolveModuleRef ( this , result ) }
2200-
2201- override string getName ( ) { result = TypeExpr .super .getClassName ( ) }
2202- }
2203-
22042200/** A module expression. Such as `DataFlow` in `DataFlow::Node` */
2205- class ModuleExpr extends TModuleExpr , ModuleRef {
2201+ class ModuleExpr extends TModuleExpr , TypeRef {
22062202 QL:: ModuleExpr me ;
22072203
22082204 ModuleExpr ( ) { this = TModuleExpr ( me ) }
@@ -2216,7 +2212,7 @@ class ModuleExpr extends TModuleExpr, ModuleRef {
22162212 *
22172213 * is `Bar`.
22182214 */
2219- override string getName ( ) {
2215+ string getName ( ) {
22202216 result = me .getName ( ) .( QL:: SimpleId ) .getValue ( )
22212217 or
22222218 not exists ( me .getName ( ) ) and result = me .getChild ( ) .( QL:: SimpleId ) .getValue ( )
@@ -2237,7 +2233,9 @@ class ModuleExpr extends TModuleExpr, ModuleRef {
22372233 */
22382234 ModuleExpr getQualifier ( ) { result = TModuleExpr ( me .getChild ( ) ) }
22392235
2240- final override FileOrModule getResolvedModule ( ) { resolveModuleRef ( this , result ) }
2236+ override Type getResolvedType ( ) {
2237+ exists ( FileOrModule mod | resolveModuleRef ( this , mod ) | result = mod .toType ( ) )
2238+ }
22412239
22422240 final override string toString ( ) { result = this .getName ( ) }
22432241
@@ -2269,7 +2267,7 @@ class SignatureExpr extends TSignatureExpr, AstNode {
22692267 SignatureExpr ( ) {
22702268 toQL ( this ) = sig .getPredicate ( )
22712269 or
2272- toQL ( this ) = sig .getTypeExpr ( ) // both `TypeExpr` and `ModuleParameterRef`
2270+ toQL ( this ) = sig .getTypeExpr ( )
22732271 }
22742272
22752273 /** Gets the generated AST node that contains this signature expression. */
@@ -2280,8 +2278,6 @@ class SignatureExpr extends TSignatureExpr, AstNode {
22802278
22812279 /** Gets this signature expression if it represents a type expression. */
22822280 TypeExpr asType ( ) { result = this }
2283-
2284- ModuleParameterRef asModuleRef ( ) { result = this }
22852281}
22862282
22872283/** An argument to an annotation. */
0 commit comments