cmListFileCache.cxx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmListFileCache.h"
  4. #include <cassert>
  5. #include <memory>
  6. #include <sstream>
  7. #include <utility>
  8. #include "cmListFileLexer.h"
  9. #include "cmMessageType.h"
  10. #include "cmMessenger.h"
  11. #include "cmState.h"
  12. #include "cmStateDirectory.h"
  13. #include "cmStringAlgorithms.h"
  14. #include "cmSystemTools.h"
  15. struct cmListFileParser
  16. {
  17. cmListFileParser(cmListFile* lf, cmListFileBacktrace lfbt,
  18. cmMessenger* messenger);
  19. ~cmListFileParser();
  20. cmListFileParser(const cmListFileParser&) = delete;
  21. cmListFileParser& operator=(const cmListFileParser&) = delete;
  22. void IssueFileOpenError(std::string const& text) const;
  23. void IssueError(std::string const& text) const;
  24. bool ParseFile(const char* filename);
  25. bool ParseString(const char* str, const char* virtual_filename);
  26. bool Parse();
  27. bool ParseFunction(const char* name, long line);
  28. bool AddArgument(cmListFileLexer_Token* token,
  29. cmListFileArgument::Delimiter delim);
  30. cm::optional<cmListFileContext> CheckNesting();
  31. cmListFile* ListFile;
  32. cmListFileBacktrace Backtrace;
  33. cmMessenger* Messenger;
  34. const char* FileName;
  35. cmListFileLexer* Lexer;
  36. std::string FunctionName;
  37. long FunctionLine;
  38. std::vector<cmListFileArgument> FunctionArguments;
  39. enum
  40. {
  41. SeparationOkay,
  42. SeparationWarning,
  43. SeparationError
  44. } Separation;
  45. };
  46. cmListFileParser::cmListFileParser(cmListFile* lf, cmListFileBacktrace lfbt,
  47. cmMessenger* messenger)
  48. : ListFile(lf)
  49. , Backtrace(std::move(lfbt))
  50. , Messenger(messenger)
  51. , FileName(nullptr)
  52. , Lexer(cmListFileLexer_New())
  53. {
  54. }
  55. cmListFileParser::~cmListFileParser()
  56. {
  57. cmListFileLexer_Delete(this->Lexer);
  58. }
  59. void cmListFileParser::IssueFileOpenError(const std::string& text) const
  60. {
  61. this->Messenger->IssueMessage(MessageType::FATAL_ERROR, text,
  62. this->Backtrace);
  63. }
  64. void cmListFileParser::IssueError(const std::string& text) const
  65. {
  66. cmListFileContext lfc;
  67. lfc.FilePath = this->FileName;
  68. lfc.Line = cmListFileLexer_GetCurrentLine(this->Lexer);
  69. cmListFileBacktrace lfbt = this->Backtrace;
  70. lfbt = lfbt.Push(lfc);
  71. this->Messenger->IssueMessage(MessageType::FATAL_ERROR, text, lfbt);
  72. cmSystemTools::SetFatalErrorOccured();
  73. }
  74. bool cmListFileParser::ParseFile(const char* filename)
  75. {
  76. this->FileName = filename;
  77. // Open the file.
  78. cmListFileLexer_BOM bom;
  79. if (!cmListFileLexer_SetFileName(this->Lexer, this->FileName, &bom)) {
  80. this->IssueFileOpenError("cmListFileCache: error can not open file.");
  81. return false;
  82. }
  83. if (bom == cmListFileLexer_BOM_Broken) {
  84. cmListFileLexer_SetFileName(this->Lexer, nullptr, nullptr);
  85. this->IssueFileOpenError("Error while reading Byte-Order-Mark. "
  86. "File not seekable?");
  87. return false;
  88. }
  89. // Verify the Byte-Order-Mark, if any.
  90. if (bom != cmListFileLexer_BOM_None && bom != cmListFileLexer_BOM_UTF8) {
  91. cmListFileLexer_SetFileName(this->Lexer, nullptr, nullptr);
  92. this->IssueFileOpenError(
  93. "File starts with a Byte-Order-Mark that is not UTF-8.");
  94. return false;
  95. }
  96. return this->Parse();
  97. }
  98. bool cmListFileParser::ParseString(const char* str,
  99. const char* virtual_filename)
  100. {
  101. this->FileName = virtual_filename;
  102. if (!cmListFileLexer_SetString(this->Lexer, str)) {
  103. this->IssueFileOpenError("cmListFileCache: cannot allocate buffer.");
  104. return false;
  105. }
  106. return this->Parse();
  107. }
  108. bool cmListFileParser::Parse()
  109. {
  110. // Use a simple recursive-descent parser to process the token
  111. // stream.
  112. bool haveNewline = true;
  113. while (cmListFileLexer_Token* token = cmListFileLexer_Scan(this->Lexer)) {
  114. if (token->type == cmListFileLexer_Token_Space) {
  115. } else if (token->type == cmListFileLexer_Token_Newline) {
  116. haveNewline = true;
  117. } else if (token->type == cmListFileLexer_Token_CommentBracket) {
  118. haveNewline = false;
  119. } else if (token->type == cmListFileLexer_Token_Identifier) {
  120. if (haveNewline) {
  121. haveNewline = false;
  122. if (this->ParseFunction(token->text, token->line)) {
  123. this->ListFile->Functions.emplace_back(
  124. std::move(this->FunctionName), this->FunctionLine,
  125. std::move(this->FunctionArguments));
  126. } else {
  127. return false;
  128. }
  129. } else {
  130. std::ostringstream error;
  131. error << "Parse error. Expected a newline, got "
  132. << cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
  133. << " with text \"" << token->text << "\".";
  134. this->IssueError(error.str());
  135. return false;
  136. }
  137. } else {
  138. std::ostringstream error;
  139. error << "Parse error. Expected a command name, got "
  140. << cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
  141. << " with text \"" << token->text << "\".";
  142. this->IssueError(error.str());
  143. return false;
  144. }
  145. }
  146. // Check if all functions are nested properly.
  147. if (auto badNesting = this->CheckNesting()) {
  148. this->Messenger->IssueMessage(
  149. MessageType::FATAL_ERROR,
  150. "Flow control statements are not properly nested.",
  151. this->Backtrace.Push(*badNesting));
  152. cmSystemTools::SetFatalErrorOccured();
  153. return false;
  154. }
  155. return true;
  156. }
  157. bool cmListFile::ParseFile(const char* filename, cmMessenger* messenger,
  158. cmListFileBacktrace const& lfbt)
  159. {
  160. if (!cmSystemTools::FileExists(filename) ||
  161. cmSystemTools::FileIsDirectory(filename)) {
  162. return false;
  163. }
  164. bool parseError = false;
  165. {
  166. cmListFileParser parser(this, lfbt, messenger);
  167. parseError = !parser.ParseFile(filename);
  168. }
  169. return !parseError;
  170. }
  171. bool cmListFile::ParseString(const char* str, const char* virtual_filename,
  172. cmMessenger* messenger,
  173. const cmListFileBacktrace& lfbt)
  174. {
  175. bool parseError = false;
  176. {
  177. cmListFileParser parser(this, lfbt, messenger);
  178. parseError = !parser.ParseString(str, virtual_filename);
  179. }
  180. return !parseError;
  181. }
  182. bool cmListFileParser::ParseFunction(const char* name, long line)
  183. {
  184. // Ininitialize a new function call.
  185. this->FunctionName = name;
  186. this->FunctionLine = line;
  187. // Command name has already been parsed. Read the left paren.
  188. cmListFileLexer_Token* token;
  189. while ((token = cmListFileLexer_Scan(this->Lexer)) &&
  190. token->type == cmListFileLexer_Token_Space) {
  191. }
  192. if (!token) {
  193. std::ostringstream error;
  194. /* clang-format off */
  195. error << "Unexpected end of file.\n"
  196. << "Parse error. Function missing opening \"(\".";
  197. /* clang-format on */
  198. this->IssueError(error.str());
  199. return false;
  200. }
  201. if (token->type != cmListFileLexer_Token_ParenLeft) {
  202. std::ostringstream error;
  203. error << "Parse error. Expected \"(\", got "
  204. << cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
  205. << " with text \"" << token->text << "\".";
  206. this->IssueError(error.str());
  207. return false;
  208. }
  209. // Arguments.
  210. unsigned long parenDepth = 0;
  211. this->Separation = SeparationOkay;
  212. while ((token = cmListFileLexer_Scan(this->Lexer))) {
  213. if (token->type == cmListFileLexer_Token_Space ||
  214. token->type == cmListFileLexer_Token_Newline) {
  215. this->Separation = SeparationOkay;
  216. continue;
  217. }
  218. if (token->type == cmListFileLexer_Token_ParenLeft) {
  219. parenDepth++;
  220. this->Separation = SeparationOkay;
  221. if (!this->AddArgument(token, cmListFileArgument::Unquoted)) {
  222. return false;
  223. }
  224. } else if (token->type == cmListFileLexer_Token_ParenRight) {
  225. if (parenDepth == 0) {
  226. return true;
  227. }
  228. parenDepth--;
  229. this->Separation = SeparationOkay;
  230. if (!this->AddArgument(token, cmListFileArgument::Unquoted)) {
  231. return false;
  232. }
  233. this->Separation = SeparationWarning;
  234. } else if (token->type == cmListFileLexer_Token_Identifier ||
  235. token->type == cmListFileLexer_Token_ArgumentUnquoted) {
  236. if (!this->AddArgument(token, cmListFileArgument::Unquoted)) {
  237. return false;
  238. }
  239. this->Separation = SeparationWarning;
  240. } else if (token->type == cmListFileLexer_Token_ArgumentQuoted) {
  241. if (!this->AddArgument(token, cmListFileArgument::Quoted)) {
  242. return false;
  243. }
  244. this->Separation = SeparationWarning;
  245. } else if (token->type == cmListFileLexer_Token_ArgumentBracket) {
  246. if (!this->AddArgument(token, cmListFileArgument::Bracket)) {
  247. return false;
  248. }
  249. this->Separation = SeparationError;
  250. } else if (token->type == cmListFileLexer_Token_CommentBracket) {
  251. this->Separation = SeparationError;
  252. } else {
  253. // Error.
  254. std::ostringstream error;
  255. error << "Parse error. Function missing ending \")\". "
  256. << "Instead found "
  257. << cmListFileLexer_GetTypeAsString(this->Lexer, token->type)
  258. << " with text \"" << token->text << "\".";
  259. this->IssueError(error.str());
  260. return false;
  261. }
  262. }
  263. std::ostringstream error;
  264. cmListFileContext lfc;
  265. lfc.FilePath = this->FileName;
  266. lfc.Line = line;
  267. cmListFileBacktrace lfbt = this->Backtrace;
  268. lfbt = lfbt.Push(lfc);
  269. error << "Parse error. Function missing ending \")\". "
  270. << "End of file reached.";
  271. this->Messenger->IssueMessage(MessageType::FATAL_ERROR, error.str(), lfbt);
  272. return false;
  273. }
  274. bool cmListFileParser::AddArgument(cmListFileLexer_Token* token,
  275. cmListFileArgument::Delimiter delim)
  276. {
  277. this->FunctionArguments.emplace_back(token->text, delim, token->line);
  278. if (this->Separation == SeparationOkay) {
  279. return true;
  280. }
  281. bool isError = (this->Separation == SeparationError ||
  282. delim == cmListFileArgument::Bracket);
  283. std::ostringstream m;
  284. cmListFileContext lfc;
  285. lfc.FilePath = this->FileName;
  286. lfc.Line = token->line;
  287. cmListFileBacktrace lfbt = this->Backtrace;
  288. lfbt = lfbt.Push(lfc);
  289. m << "Syntax " << (isError ? "Error" : "Warning") << " in cmake code at "
  290. << "column " << token->column << "\n"
  291. << "Argument not separated from preceding token by whitespace.";
  292. /* clang-format on */
  293. if (isError) {
  294. this->Messenger->IssueMessage(MessageType::FATAL_ERROR, m.str(), lfbt);
  295. return false;
  296. }
  297. this->Messenger->IssueMessage(MessageType::AUTHOR_WARNING, m.str(), lfbt);
  298. return true;
  299. }
  300. namespace {
  301. enum class NestingStateEnum
  302. {
  303. If,
  304. Else,
  305. While,
  306. Foreach,
  307. Function,
  308. Macro,
  309. };
  310. struct NestingState
  311. {
  312. NestingStateEnum State;
  313. cmListFileContext Context;
  314. };
  315. bool TopIs(std::vector<NestingState>& stack, NestingStateEnum state)
  316. {
  317. return !stack.empty() && stack.back().State == state;
  318. }
  319. }
  320. cm::optional<cmListFileContext> cmListFileParser::CheckNesting()
  321. {
  322. std::vector<NestingState> stack;
  323. for (auto const& func : this->ListFile->Functions) {
  324. auto const& name = func.LowerCaseName();
  325. if (name == "if") {
  326. stack.push_back({
  327. NestingStateEnum::If,
  328. cmListFileContext::FromCommandContext(func, this->FileName),
  329. });
  330. } else if (name == "elseif") {
  331. if (!TopIs(stack, NestingStateEnum::If)) {
  332. return cmListFileContext::FromCommandContext(func, this->FileName);
  333. }
  334. stack.back() = {
  335. NestingStateEnum::If,
  336. cmListFileContext::FromCommandContext(func, this->FileName),
  337. };
  338. } else if (name == "else") {
  339. if (!TopIs(stack, NestingStateEnum::If)) {
  340. return cmListFileContext::FromCommandContext(func, this->FileName);
  341. }
  342. stack.back() = {
  343. NestingStateEnum::Else,
  344. cmListFileContext::FromCommandContext(func, this->FileName),
  345. };
  346. } else if (name == "endif") {
  347. if (!TopIs(stack, NestingStateEnum::If) &&
  348. !TopIs(stack, NestingStateEnum::Else)) {
  349. return cmListFileContext::FromCommandContext(func, this->FileName);
  350. }
  351. stack.pop_back();
  352. } else if (name == "while") {
  353. stack.push_back({
  354. NestingStateEnum::While,
  355. cmListFileContext::FromCommandContext(func, this->FileName),
  356. });
  357. } else if (name == "endwhile") {
  358. if (!TopIs(stack, NestingStateEnum::While)) {
  359. return cmListFileContext::FromCommandContext(func, this->FileName);
  360. }
  361. stack.pop_back();
  362. } else if (name == "foreach") {
  363. stack.push_back({
  364. NestingStateEnum::Foreach,
  365. cmListFileContext::FromCommandContext(func, this->FileName),
  366. });
  367. } else if (name == "endforeach") {
  368. if (!TopIs(stack, NestingStateEnum::Foreach)) {
  369. return cmListFileContext::FromCommandContext(func, this->FileName);
  370. }
  371. stack.pop_back();
  372. } else if (name == "function") {
  373. stack.push_back({
  374. NestingStateEnum::Function,
  375. cmListFileContext::FromCommandContext(func, this->FileName),
  376. });
  377. } else if (name == "endfunction") {
  378. if (!TopIs(stack, NestingStateEnum::Function)) {
  379. return cmListFileContext::FromCommandContext(func, this->FileName);
  380. }
  381. stack.pop_back();
  382. } else if (name == "macro") {
  383. stack.push_back({
  384. NestingStateEnum::Macro,
  385. cmListFileContext::FromCommandContext(func, this->FileName),
  386. });
  387. } else if (name == "endmacro") {
  388. if (!TopIs(stack, NestingStateEnum::Macro)) {
  389. return cmListFileContext::FromCommandContext(func, this->FileName);
  390. }
  391. stack.pop_back();
  392. }
  393. }
  394. if (!stack.empty()) {
  395. return stack.back().Context;
  396. }
  397. return cm::nullopt;
  398. }
  399. // We hold either the bottom scope of a directory or a call/file context.
  400. // Discriminate these cases via the parent pointer.
  401. struct cmListFileBacktrace::Entry
  402. {
  403. Entry(cmStateSnapshot bottom)
  404. : Bottom(bottom)
  405. {
  406. }
  407. Entry(std::shared_ptr<Entry const> parent, cmListFileContext lfc)
  408. : Context(std::move(lfc))
  409. , Parent(std::move(parent))
  410. {
  411. }
  412. ~Entry()
  413. {
  414. if (this->Parent) {
  415. this->Context.~cmListFileContext();
  416. } else {
  417. this->Bottom.~cmStateSnapshot();
  418. }
  419. }
  420. bool IsBottom() const { return !this->Parent; }
  421. union
  422. {
  423. cmStateSnapshot Bottom;
  424. cmListFileContext Context;
  425. };
  426. std::shared_ptr<Entry const> Parent;
  427. };
  428. cmListFileBacktrace::cmListFileBacktrace(cmStateSnapshot const& snapshot)
  429. : TopEntry(std::make_shared<Entry const>(snapshot.GetCallStackBottom()))
  430. {
  431. }
  432. /* NOLINTNEXTLINE(performance-unnecessary-value-param) */
  433. cmListFileBacktrace::cmListFileBacktrace(std::shared_ptr<Entry const> parent,
  434. cmListFileContext const& lfc)
  435. : TopEntry(std::make_shared<Entry const>(std::move(parent), lfc))
  436. {
  437. }
  438. cmListFileBacktrace::cmListFileBacktrace(std::shared_ptr<Entry const> top)
  439. : TopEntry(std::move(top))
  440. {
  441. }
  442. cmStateSnapshot cmListFileBacktrace::GetBottom() const
  443. {
  444. cmStateSnapshot bottom;
  445. if (Entry const* cur = this->TopEntry.get()) {
  446. while (Entry const* parent = cur->Parent.get()) {
  447. cur = parent;
  448. }
  449. bottom = cur->Bottom;
  450. }
  451. return bottom;
  452. }
  453. cmListFileBacktrace cmListFileBacktrace::Push(std::string const& file) const
  454. {
  455. // We are entering a file-level scope but have not yet reached
  456. // any specific line or command invocation within it. This context
  457. // is useful to print when it is at the top but otherwise can be
  458. // skipped during call stack printing.
  459. cmListFileContext lfc;
  460. lfc.FilePath = file;
  461. return this->Push(lfc);
  462. }
  463. cmListFileBacktrace cmListFileBacktrace::Push(
  464. cmListFileContext const& lfc) const
  465. {
  466. assert(this->TopEntry);
  467. assert(!this->TopEntry->IsBottom() || this->TopEntry->Bottom.IsValid());
  468. return cmListFileBacktrace(this->TopEntry, lfc);
  469. }
  470. cmListFileBacktrace cmListFileBacktrace::Pop() const
  471. {
  472. assert(this->TopEntry);
  473. assert(!this->TopEntry->IsBottom());
  474. return cmListFileBacktrace(this->TopEntry->Parent);
  475. }
  476. cmListFileContext const& cmListFileBacktrace::Top() const
  477. {
  478. assert(this->TopEntry);
  479. assert(!this->TopEntry->IsBottom());
  480. return this->TopEntry->Context;
  481. }
  482. void cmListFileBacktrace::PrintTitle(std::ostream& out) const
  483. {
  484. // The title exists only if we have a call on top of the bottom.
  485. if (!this->TopEntry || this->TopEntry->IsBottom()) {
  486. return;
  487. }
  488. cmListFileContext lfc = this->TopEntry->Context;
  489. cmStateSnapshot bottom = this->GetBottom();
  490. if (!bottom.GetState()->GetIsInTryCompile()) {
  491. lfc.FilePath = bottom.GetDirectory().ConvertToRelPathIfNotContained(
  492. bottom.GetState()->GetSourceDirectory(), lfc.FilePath);
  493. }
  494. out << (lfc.Line ? " at " : " in ") << lfc;
  495. }
  496. void cmListFileBacktrace::PrintCallStack(std::ostream& out) const
  497. {
  498. // The call stack exists only if we have at least two calls on top
  499. // of the bottom.
  500. if (!this->TopEntry || this->TopEntry->IsBottom() ||
  501. this->TopEntry->Parent->IsBottom()) {
  502. return;
  503. }
  504. bool first = true;
  505. cmStateSnapshot bottom = this->GetBottom();
  506. for (Entry const* cur = this->TopEntry->Parent.get(); !cur->IsBottom();
  507. cur = cur->Parent.get()) {
  508. if (cur->Context.Name.empty() &&
  509. cur->Context.Line != cmListFileContext::DeferPlaceholderLine) {
  510. // Skip this whole-file scope. When we get here we already will
  511. // have printed a more-specific context within the file.
  512. continue;
  513. }
  514. if (first) {
  515. first = false;
  516. out << "Call Stack (most recent call first):\n";
  517. }
  518. cmListFileContext lfc = cur->Context;
  519. if (!bottom.GetState()->GetIsInTryCompile()) {
  520. lfc.FilePath = bottom.GetDirectory().ConvertToRelPathIfNotContained(
  521. bottom.GetState()->GetSourceDirectory(), lfc.FilePath);
  522. }
  523. out << " " << lfc << "\n";
  524. }
  525. }
  526. size_t cmListFileBacktrace::Depth() const
  527. {
  528. size_t depth = 0;
  529. if (Entry const* cur = this->TopEntry.get()) {
  530. for (; !cur->IsBottom(); cur = cur->Parent.get()) {
  531. ++depth;
  532. }
  533. }
  534. return depth;
  535. }
  536. bool cmListFileBacktrace::Empty() const
  537. {
  538. return !this->TopEntry || this->TopEntry->IsBottom();
  539. }
  540. std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc)
  541. {
  542. os << lfc.FilePath;
  543. if (lfc.Line > 0) {
  544. os << ":" << lfc.Line;
  545. if (!lfc.Name.empty()) {
  546. os << " (" << lfc.Name << ")";
  547. }
  548. } else if (lfc.Line == cmListFileContext::DeferPlaceholderLine) {
  549. os << ":DEFERRED";
  550. }
  551. return os;
  552. }
  553. bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs)
  554. {
  555. if (lhs.Line != rhs.Line) {
  556. return lhs.Line < rhs.Line;
  557. }
  558. return lhs.FilePath < rhs.FilePath;
  559. }
  560. bool operator==(const cmListFileContext& lhs, const cmListFileContext& rhs)
  561. {
  562. return lhs.Line == rhs.Line && lhs.FilePath == rhs.FilePath;
  563. }
  564. bool operator!=(const cmListFileContext& lhs, const cmListFileContext& rhs)
  565. {
  566. return !(lhs == rhs);
  567. }
  568. std::ostream& operator<<(std::ostream& os, BT<std::string> const& s)
  569. {
  570. return os << s.Value;
  571. }
  572. std::vector<BT<std::string>> ExpandListWithBacktrace(
  573. std::string const& list, cmListFileBacktrace const& bt)
  574. {
  575. std::vector<BT<std::string>> result;
  576. std::vector<std::string> tmp = cmExpandedList(list);
  577. result.reserve(tmp.size());
  578. for (std::string& i : tmp) {
  579. result.emplace_back(std::move(i), bt);
  580. }
  581. return result;
  582. }