diff --git a/docs/examples/ASTVisitor.cpp b/docs/examples/ASTVisitor.cpp index b8e97365..dfccac80 100644 --- a/docs/examples/ASTVisitor.cpp +++ b/docs/examples/ASTVisitor.cpp @@ -28,9 +28,7 @@ int main(int argc, const char** argv) { "-Xclang", "-no-round-trip-args", "-std=c++20", - "-Wno-everything", argv[1], - "-c", }; invocation = clang::createInvocation(args, {}); diff --git a/docs/examples/CodeCompletion.cpp b/docs/examples/CodeCompletion.cpp index d33db056..e98fad8f 100644 --- a/docs/examples/CodeCompletion.cpp +++ b/docs/examples/CodeCompletion.cpp @@ -31,10 +31,10 @@ public: unsigned NumResults) override { auto contexts = Context.getVisitedContexts(); for(auto c: contexts) { - llvm::outs() << " Kind: " << c->getDeclKindName() << "\n"; - for(auto d: c->decls()) { - d->dump(); - } + // llvm::outs() << " Kind: " << c->getDeclKindName() << "\n"; + // for(auto d: c->decls()) { + // // d->dump(); + // } } llvm::outs() << "code completion results:\n"; @@ -119,9 +119,7 @@ int main(int argc, const char** argv) { "-Xclang", "-no-round-trip-args", "-std=c++20", - "-Wno-everything", argv[1], - "-c", }; invocation = clang::createInvocation(args, {}); diff --git a/docs/examples/Preamble.cpp b/docs/examples/Preamble.cpp index affd318c..7eb2baea 100644 --- a/docs/examples/Preamble.cpp +++ b/docs/examples/Preamble.cpp @@ -36,9 +36,9 @@ auto buildPreamble(std::vector args, const char* path) { std::string storagePath = (fs::path(path).parent_path() / "build").string(); auto VFS = llvm::vfs::getRealFileSystem(); - if(auto error = VFS->setCurrentWorkingDirectory(storagePath)) { - llvm::errs() << error.message() << "\n"; - } + // if(auto error = VFS->setCurrentWorkingDirectory(storagePath)) { + // llvm::errs() << error.message() << "\n"; + // } // use to collect information in the process of building preamble, such as include files and macros // TODO: inherit from clang::PreambleCallbacks and collect the information @@ -52,7 +52,7 @@ auto buildPreamble(std::vector args, const char* path) { llvm::vfs::getRealFileSystem(), std::make_shared(), storeInMemory, - storagePath, + storeInMemory ? "" : storagePath, callbacks); if(auto error = preamble.getError()) { @@ -72,8 +72,8 @@ int main(int argc, const char** argv) { "-Xclang", "-no-round-trip-args", "-std=c++20", - "-Wno-everything", argv[1], + "-c", }; auto preamble = buildPreamble(args, argv[1]); @@ -106,6 +106,12 @@ int main(int argc, const char** argv) { new clang::TextDiagnosticPrinter(llvm::errs(), new clang::DiagnosticOptions()), true); + /// NOTICE: if preamble is stored in memory, the code below is necessary + if(auto VFSWithRemapping = + createVFSFromCompilerInvocation(instance->getInvocation(), instance->getDiagnostics(), VFS)) + VFS = VFSWithRemapping; + instance->createFileManager(VFS); + if(!instance->createTarget()) { llvm::errs() << "Failed to create target\n"; std::terminate(); @@ -125,5 +131,6 @@ int main(int argc, const char** argv) { } instance->getASTContext().getTranslationUnitDecl()->dump(); + action.EndSourceFile(); } diff --git a/docs/examples/Preprocessor.cpp b/docs/examples/Preprocessor.cpp index d22abb00..2c3a1c83 100644 --- a/docs/examples/Preprocessor.cpp +++ b/docs/examples/Preprocessor.cpp @@ -64,19 +64,15 @@ int main(int argc, const char** argv) { auto invocation = std::make_shared(); std::vector args = { - "/usr/local/bin/clang++", - "-x", - "c++", + "/home/ykiko/Project/C++/clice/external/llvm/bin/clang++", "-Xclang", "-no-round-trip-args", "-std=c++20", - "-Wno-everything", argv[1], - "-c", }; - // invocation = clang::createInvocation(args, {}); - clang::CompilerInvocation::CreateFromArgs(*invocation, args, instance->getDiagnostics()); + invocation = clang::createInvocation(args, {}); + instance->setInvocation(std::move(invocation)); if(!instance->createTarget()) { @@ -84,15 +80,6 @@ int main(int argc, const char** argv) { std::terminate(); } - if(clang::FileManager* manager = instance->createFileManager()) { - instance->createSourceManager(*manager); - } else { - llvm::errs() << "Failed to create file manager\n"; - std::terminate(); - } - - instance->createPreprocessor(clang::TranslationUnitKind::TU_Complete); - clang::PreprocessOnlyAction action; if(!action.BeginSourceFile(*instance, instance->getFrontendOpts().Inputs[0])) { @@ -101,7 +88,7 @@ int main(int argc, const char** argv) { } clang::Preprocessor& pp = instance->getPreprocessor(); - pp.addPPCallbacks(std::make_unique(pp)); + // pp.addPPCallbacks(std::make_unique(pp)); clang::syntax::TokenCollector collector{pp}; if(auto error = action.Execute()) {