@@ -1132,13 +1132,16 @@ class ImportDecl final : public Decl,
11321132
11331133 SourceLoc ImportLoc;
11341134 SourceLoc KindLoc;
1135+ // / Used to store the real module name corresponding to this import decl in
1136+ // / case module aliasing is used. For example if '-module-alias Foo=Bar' was
1137+ // / passed and this decl is 'import Foo', the real name 'Bar' will be stored.
1138+ Identifier RealModuleName;
11351139
11361140 // / The resolved module.
11371141 ModuleDecl *Mod = nullptr ;
11381142
11391143 ImportDecl (DeclContext *DC, SourceLoc ImportLoc, ImportKind K,
11401144 SourceLoc KindLoc, ImportPath Path);
1141-
11421145public:
11431146 static ImportDecl *create (ASTContext &C, DeclContext *DC,
11441147 SourceLoc ImportLoc, ImportKind Kind,
@@ -1162,15 +1165,57 @@ class ImportDecl final : public Decl,
11621165 return static_cast <ImportKind>(Bits.ImportDecl .ImportKind );
11631166 }
11641167
1168+ // / Retrieves the import path as written in the source code.
1169+ // /
1170+ // / \returns An \c ImportPath corresponding to this import decl. If module aliasing
1171+ // / was used, this will contain the aliased name of the module; for instance,
1172+ // / if you wrote 'import Foo' but passed '-module-alias Foo=Bar', this import
1173+ // / path will include 'Foo'. This return value is always owned by \c ImportDecl
1174+ // / (which is owned by the AST context), so it can be persisted.
11651175 ImportPath getImportPath () const {
11661176 return ImportPath ({ getTrailingObjects<ImportPath::Element>(),
11671177 static_cast <size_t >(Bits.ImportDecl .NumPathElements ) });
11681178 }
11691179
1180+ // / Retrieves the import path, replacing any module aliases with real names.
1181+ // /
1182+ // / \param scratch An \c ImportPath::Builder which may, if necessary, be used to
1183+ // / construct the return value. It may go unused, so you should not try to
1184+ // / read the result from it; use the return value instead.
1185+ // / \returns An \c ImportPath corresponding to this import decl. If module aliasing
1186+ // / was used, this will contain the real name of the module; for instance,
1187+ // / if you wrote 'import Foo' but passed '-module-alias Foo=Bar', this import
1188+ // / path will include 'Bar'. This return value may be owned by \p scratch,
1189+ // / so it should not be used after \p scratch is destroyed.
1190+ ImportPath getRealImportPath (ImportPath::Builder &scratch) const ;
1191+
1192+ // / Retrieves the part of the import path that contains the module name,
1193+ // / as written in the source code.
1194+ // /
1195+ // / \returns A \c ImportPath::Module corresponding to this import decl. If module
1196+ // / aliasing was used, this will contain the aliased name of the module; for
1197+ // / instance, if you wrote 'import Foo' but passed '-module-alias Foo=Bar',
1198+ // / this module path will contain 'Foo'. This return value is always owned by
1199+ // / \c ImportDecl (which is owned by the AST context), so it can be persisted.
11701200 ImportPath::Module getModulePath () const {
11711201 return getImportPath ().getModulePath (getImportKind ());
11721202 }
11731203
1204+ // / Retrieves the part of the import path that contains the module name,
1205+ // / replacing any module aliases with real names.
1206+ // /
1207+ // / \param scratch An \c ImportPath::Builder which may, if necessary, be used to
1208+ // / construct the return value. It may go unused, so you should not try to
1209+ // / read the result from it; use the return value instead.
1210+ // / \returns An \c ImportPath::Module corresponding to this import decl. If module
1211+ // / aliasing was used, this will contain the real name of the module; for
1212+ // / instance, if you wrote 'import Foo' but passed '-module-alias Foo=Bar',
1213+ // / the returned path will contain 'Bar'. This return value may be owned
1214+ // / by \p scratch, so it should not be used after \p scratch is destroyed.
1215+ ImportPath::Module getRealModulePath (ImportPath::Builder &scratch) const {
1216+ return getRealImportPath (scratch).getModulePath (getImportKind ());
1217+ }
1218+
11741219 ImportPath::Access getAccessPath () const {
11751220 return getImportPath ().getAccessPath (getImportKind ());
11761221 }
0 commit comments