| 361 | } |
| 362 | |
| 363 | std::list<Directive> Preprocessor::createDirectives() const |
| 364 | { |
| 365 | // directive list.. |
| 366 | std::list<Directive> directives; |
| 367 | |
| 368 | std::vector<const simplecpp::TokenList *> list; |
| 369 | list.reserve(1U + mFileCache.size()); |
| 370 | list.push_back(&mTokens); |
| 371 | std::transform(mFileCache.cbegin(), mFileCache.cend(), std::back_inserter(list), |
| 372 | [](const std::unique_ptr<simplecpp::FileData> &filedata) { |
| 373 | return &filedata->tokens; |
| 374 | }); |
| 375 | |
| 376 | for (const simplecpp::TokenList *tokenList : list) { |
| 377 | for (const simplecpp::Token *tok = tokenList->cfront(); tok; tok = tok->next) { |
| 378 | if ((tok->op != '#') || (tok->previous && tok->previous->location.line == tok->location.line)) |
| 379 | continue; |
| 380 | if (tok->next && tok->next->str() == "endfile") |
| 381 | continue; |
| 382 | Directive directive(mTokens, tok->location, ""); |
| 383 | for (const simplecpp::Token *tok2 = tok; tok2 && tok2->location.line == directive.linenr; tok2 = tok2->next) { |
| 384 | if (tok2->comment) |
| 385 | continue; |
| 386 | if (!directive.str.empty() && (tok2->location.col > tok2->previous->location.col + tok2->previous->str().size())) |
| 387 | directive.str += ' '; |
| 388 | if (directive.str == "#" && tok2->str() == "file") |
| 389 | directive.str += "include"; |
| 390 | else |
| 391 | directive.str += tok2->str(); |
| 392 | |
| 393 | directive.strTokens.emplace_back(*tok2); |
| 394 | } |
| 395 | directives.push_back(std::move(directive)); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | return directives; |
| 400 | } |
| 401 | |
| 402 | static std::string readcondition(const simplecpp::Token *iftok, const std::set<std::string> &defined, const std::set<std::string> &undefined) |
| 403 | { |