#include "clang/Basic/SourceManager.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
-#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/HeaderSearchOptions.h"
#include "clang/Lex/ModuleLoader.h"
ModuleDeclStateTest()
: FileMgr(FileMgrOpts), DiagID(new DiagnosticIDs()),
Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
- SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions), Invocation() {
+ SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions) {
TargetOpts->Triple = "x86_64-unknown-linux-gnu";
Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
}
- LangOptions &getLangOpts(ArrayRef<const char *> CommandLineArgs) {
- CompilerInvocation::CreateFromArgs(Invocation, CommandLineArgs, Diags);
- return *Invocation.getLangOpts();
- }
-
std::unique_ptr<Preprocessor>
- getPreprocessor(const char *source, ArrayRef<const char *> CommandLineArgs) {
+ getPreprocessor(const char *source, Language Lang) {
std::unique_ptr<llvm::MemoryBuffer> Buf =
llvm::MemoryBuffer::getMemBuffer(source);
SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
- LangOptions &LangOpts = getLangOpts(CommandLineArgs);
+ std::vector<std::string> Includes;
+ LangOptions::setLangDefaults(LangOpts, Lang, Target->getTriple(), Includes, LangStandard::lang_cxx20);
+ LangOpts.CPlusPlusModules = true;
+ if (Lang != Language::CXX) {
+ LangOpts.Modules = true;
+ LangOpts.ImplicitModules = true;
+ }
+
HeaderInfo.emplace(std::make_shared<HeaderSearchOptions>(), SourceMgr,
Diags, LangOpts, Target.get());
SourceManager SourceMgr;
std::shared_ptr<TargetOptions> TargetOpts;
IntrusiveRefCntPtr<TargetInfo> Target;
- CompilerInvocation Invocation;
+ LangOptions LangOpts;
TrivialModuleLoader ModLoader;
std::optional<HeaderSearch> HeaderInfo;
};
const char *source = R"(
export module foo;
)";
- std::unique_ptr<Preprocessor> PP = getPreprocessor(source, "-std=c++20");
+ std::unique_ptr<Preprocessor> PP = getPreprocessor(source, Language::CXX);
std::initializer_list<bool> ImportKinds = {};
preprocess(*PP,
const char *source = R"(
module foo;
)";
- std::unique_ptr<Preprocessor> PP = getPreprocessor(source, "-std=c++20");
+ std::unique_ptr<Preprocessor> PP = getPreprocessor(source, Language::CXX);
std::initializer_list<bool> ImportKinds = {};
preprocess(*PP,
const char *source = R"(
module foo:part;
)";
- std::unique_ptr<Preprocessor> PP = getPreprocessor(source, "-std=c++20");
+ std::unique_ptr<Preprocessor> PP = getPreprocessor(source, Language::CXX);
std::initializer_list<bool> ImportKinds = {};
preprocess(*PP,
const char *source = R"(
export module foo:part;
)";
- std::unique_ptr<Preprocessor> PP = getPreprocessor(source, "-std=c++20");
+ std::unique_ptr<Preprocessor> PP = getPreprocessor(source, Language::CXX);
std::initializer_list<bool> ImportKinds = {};
preprocess(*PP,
const char *source = R"(
export module foo.dot:part.dot;
)";
- std::unique_ptr<Preprocessor> PP = getPreprocessor(source, "-std=c++20");
+ std::unique_ptr<Preprocessor> PP = getPreprocessor(source, Language::CXX);
std::initializer_list<bool> ImportKinds = {};
preprocess(*PP,
const char *source = R"(
// export module foo:part;
)";
- std::unique_ptr<Preprocessor> PP = getPreprocessor(source, "-std=c++20");
+ std::unique_ptr<Preprocessor> PP = getPreprocessor(source, Language::CXX);
std::initializer_list<bool> ImportKinds = {};
preprocess(*PP,
import M;
import :another;
)";
- std::unique_ptr<Preprocessor> PP = getPreprocessor(source, "-std=c++20");
+ std::unique_ptr<Preprocessor> PP = getPreprocessor(source, Language::CXX);
std::initializer_list<bool> ImportKinds = {true, true};
preprocess(*PP,
import M;
import :another;
)";
- std::unique_ptr<Preprocessor> PP = getPreprocessor(source, "-std=c++20");
+ std::unique_ptr<Preprocessor> PP = getPreprocessor(source, Language::CXX);
std::initializer_list<bool> ImportKinds = {true, true};
preprocess(*PP,
// We can't import a partition in non-module TU.
import :another;
)";
- std::unique_ptr<Preprocessor> PP = getPreprocessor(source, "-std=c++20");
+ std::unique_ptr<Preprocessor> PP = getPreprocessor(source, Language::CXX);
std::initializer_list<bool> ImportKinds = {true};
preprocess(*PP,
const char *source = R"(
@import anything;
)";
- std::unique_ptr<Preprocessor> PP =
- getPreprocessor(source, {"-fmodules", "-fimplicit-module-maps", "-x",
- "objective-c++", "-std=c++20"});
+ std::unique_ptr<Preprocessor> PP = getPreprocessor(source, Language::ObjCXX);
std::initializer_list<bool> ImportKinds = {false};
preprocess(*PP,
@import another;
import M2;
)";
- std::unique_ptr<Preprocessor> PP =
- getPreprocessor(source, {"-fmodules", "-fimplicit-module-maps", "-x",
- "objective-c++", "-std=c++20"});
+ std::unique_ptr<Preprocessor> PP = getPreprocessor(source, Language::ObjCXX);
std::initializer_list<bool> ImportKinds = {false, true, false, true};
preprocess(*PP,