خرید بک لینک

Vote count: 0

Im trying to create virtual files for codecompletion in clang. Unfortunately, my application segfaults. I have the following setup:

auto createVirtualFile = [](
  clang::CompilerInstance& ci,
  std::string name,
  llvm::StringRef input
) {
  std::unique_ptr<llvm::MemoryBuffer>
    MB(llvm::MemoryBuffer::getMemBuffer(input, name));
  retu std::move(MB);
};

Once the file is created i setup a CodeCompletConsumer:

auto setupCodeComplete = [](
  clang::CompilerInstance& ci,
  std::string File,
  int Line,
  int Column
) {
  auto& F = ci.getFrontendOpts();
  F.CodeCompletionAt.FileName = File;
  F.CodeCompletionAt.Line = Line;
  F.CodeCompletionAt.Column = Column;
  clang::FrontendInputFile FrontFile(File, clang::IK_CXX);
  //F.Inputs.push_back(FrontFile);
  ci.createCodeCompletionConsumer();
  retu FrontFile;
};

I invoke those two functions the following way and execute a syntax only action:

auto runCodeCompleteAt = [] (
  clang::CompilerInstance& ci,
  std::string Filename,
  std::string Code,
  int Line,
  int Column
) {
  auto fid = createVirtualFile(ci, Filename, Code);
  auto File = setupCodeComplete(ci, Filename, Line, Column);
  clang::SyntaxOnlyAction Act;
  if (Act.BeginSourceFile(ci, File )) {
    Act.Execute(); // segfault
    Act.EndSourceFile();
  }
};

auto runExample = [](auto& ci){
  runCodeCompleterAt(ci, "test.cpp", "std::cou", 1, 7);
}

I appreciate any hints.

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 3 خرداد 1395 ساعت: 17:37

صفحه بندی