@@ -174,17 +174,6 @@ abstract class PathString extends string {
174174 Path resolve ( Folder root ) { result = resolveUpTo ( getNumComponent ( ) , root ) }
175175}
176176
177- /**
178- * Non-abstract base class for path expressions.
179- */
180- private class PathExprBase extends Locatable {
181- // We must put getEnclosingModule here for it to be usable in the characteristic predicate of PathExprInModule
182- /** Gets the module containing this path expression, if any. */
183- Module getEnclosingModule ( ) {
184- result = this .( Expr ) .getTopLevel ( ) or result = this .( Comment ) .getTopLevel ( )
185- }
186- }
187-
188177/**
189178 * An expression whose value represents a (relative or absolute) file system path.
190179 *
@@ -197,12 +186,25 @@ private class PathExprBase extends Locatable {
197186 * as their highest-priority root, with default library paths as additional roots
198187 * of lower priority.
199188 */
200- abstract class PathExpr extends PathExprBase {
189+ abstract class PathExpr extends Locatable {
201190 /** Gets the (unresolved) path represented by this expression. */
202191 abstract string getValue ( ) ;
203192
204193 /** Gets the root folder of priority `priority` associated with this path expression. */
205- abstract Folder getSearchRoot ( int priority ) ;
194+ Folder getSearchRoot ( int priority ) {
195+ // We default to the enclosing module's search root, though this may be overridden.
196+ getEnclosingModule ( ) .searchRoot ( this , result , priority )
197+ or
198+ result = getAdditionalSearchRoot ( priority )
199+ }
200+
201+ /**
202+ * INTERNAL. Use `getSearchRoot` instead.
203+ *
204+ * Can be overridden by subclasses of `PathExpr` to provide additional search roots
205+ * without overriding `getSearchRoot`.
206+ */
207+ Folder getAdditionalSearchRoot ( int priority ) { none ( ) }
206208
207209 /** Gets the `i`th component of this path. */
208210 string getComponent ( int i ) { result = getValue ( ) .( PathString ) .getComponent ( i ) }
@@ -246,6 +248,11 @@ abstract class PathExpr extends PathExprBase {
246248
247249 /** Gets the file or folder that this path refers to. */
248250 Container resolve ( ) { result = resolveUpTo ( getNumComponent ( ) ) }
251+
252+ /** Gets the module containing this path expression, if any. */
253+ Module getEnclosingModule ( ) {
254+ result = this .( Expr ) .getTopLevel ( ) or result = this .( Comment ) .getTopLevel ( )
255+ }
249256}
250257
251258/** A path string derived from a path expression. */
@@ -279,8 +286,8 @@ private class ConcatPath extends PathExpr {
279286 )
280287 }
281288
282- override Folder getSearchRoot ( int priority ) {
283- result = this .( AddExpr ) .getAnOperand ( ) .( PathExpr ) .getSearchRoot ( priority )
289+ override Folder getAdditionalSearchRoot ( int priority ) {
290+ result = this .( AddExpr ) .getAnOperand ( ) .( PathExpr ) .getAdditionalSearchRoot ( priority )
284291 }
285292}
286293
0 commit comments