mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[AST] Make it possible to find what Swift version was used to build a module
For imported modules the version is empty because they don't carry this information.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "swift/AST/RawComment.h"
|
||||
#include "swift/Basic/BasicSourceInfo.h"
|
||||
#include "swift/Basic/Debug.h"
|
||||
#include "swift/Basic/Version.h"
|
||||
|
||||
#include "llvm/ADT/PointerIntPair.h"
|
||||
|
||||
@@ -417,6 +418,10 @@ protected:
|
||||
assert(classof(this) && "invalid kind");
|
||||
}
|
||||
public:
|
||||
/// Returns the language version that was used to compile the contents of this
|
||||
/// file. An empty `Version` is returned if the information is not available.
|
||||
virtual version::Version getLanguageVersionBuiltWith() const = 0;
|
||||
|
||||
/// Returns an arbitrary string representing the storage backing this file.
|
||||
///
|
||||
/// This is usually a filesystem path.
|
||||
|
||||
@@ -1147,6 +1147,10 @@ public:
|
||||
|
||||
SourceRange getSourceRange() const { return SourceRange(); }
|
||||
|
||||
/// Returns the language version that was used to compile this module.
|
||||
/// An empty `Version` is returned if the information is not available.
|
||||
version::Version getLanguageVersionBuiltWith() const;
|
||||
|
||||
static bool classof(const DeclContext *DC) {
|
||||
if (auto D = DC->getAsDecl())
|
||||
return classof(D);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#define SWIFT_CLANGIMPORTER_CLANGMODULE_H
|
||||
|
||||
#include "swift/AST/FileUnit.h"
|
||||
#include "swift/Basic/Version.h"
|
||||
#include "swift/ClangImporter/ClangImporter.h"
|
||||
#include "clang/AST/ExternalASTSource.h"
|
||||
#include "clang/Basic/Module.h"
|
||||
@@ -109,6 +110,10 @@ public:
|
||||
llvm_unreachable("no private decls in Clang modules");
|
||||
}
|
||||
|
||||
virtual version::Version getLanguageVersionBuiltWith() const override {
|
||||
return version::Version();
|
||||
}
|
||||
|
||||
virtual StringRef getFilename() const override;
|
||||
|
||||
virtual StringRef getLoadedFilename() const override;
|
||||
|
||||
@@ -400,7 +400,7 @@ public:
|
||||
|
||||
/// Returns the language version that was used to compile the contents of this
|
||||
/// file.
|
||||
const version::Version &getLanguageVersionBuiltWith() const;
|
||||
virtual version::Version getLanguageVersionBuiltWith() const override;
|
||||
|
||||
virtual bool hadLoadError() const override;
|
||||
|
||||
|
||||
@@ -3935,3 +3935,17 @@ bool IsNonUserModuleRequest::evaluate(Evaluator &evaluator, ModuleDecl *mod) con
|
||||
return (!runtimePath.empty() && pathStartsWith(runtimePath, modulePath)) ||
|
||||
(!sdkPath.empty() && pathStartsWith(sdkPath, modulePath));
|
||||
}
|
||||
|
||||
version::Version ModuleDecl::getLanguageVersionBuiltWith() const {
|
||||
for (auto *F : getFiles()) {
|
||||
auto *LD = dyn_cast<LoadedFile>(F);
|
||||
if (!LD)
|
||||
continue;
|
||||
|
||||
auto version = LD->getLanguageVersionBuiltWith();
|
||||
if (!version.empty())
|
||||
return version;
|
||||
}
|
||||
|
||||
return version::Version();
|
||||
}
|
||||
|
||||
@@ -82,6 +82,10 @@ public:
|
||||
llvm_unreachable("no private decls in Clang modules");
|
||||
}
|
||||
|
||||
virtual version::Version getLanguageVersionBuiltWith() const override {
|
||||
return version::Version();
|
||||
}
|
||||
|
||||
virtual StringRef getFilename() const override { return ""; }
|
||||
|
||||
virtual const clang::Module *getUnderlyingClangModule() const override {
|
||||
|
||||
@@ -1393,7 +1393,7 @@ ValueDecl *SerializedASTFile::getMainDecl() const {
|
||||
return cast_or_null<ValueDecl>(File.getDecl(File.getEntryPointDeclID()));
|
||||
}
|
||||
|
||||
const version::Version &SerializedASTFile::getLanguageVersionBuiltWith() const {
|
||||
version::Version SerializedASTFile::getLanguageVersionBuiltWith() const {
|
||||
return File.getCompatibilityVersion();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user