| 1623 | } |
| 1624 | |
| 1625 | void clangimport::parseClangAstDump(Tokenizer &tokenizer, std::istream &f) |
| 1626 | { |
| 1627 | TokenList &tokenList = tokenizer.list; |
| 1628 | |
| 1629 | tokenizer.createSymbolDatabase(); |
| 1630 | auto *symbolDatabase = const_cast<SymbolDatabase *>(tokenizer.getSymbolDatabase()); |
| 1631 | symbolDatabase->scopeList.emplace_back(*symbolDatabase, nullptr, nullptr); |
| 1632 | symbolDatabase->scopeList.back().type = ScopeType::eGlobal; |
| 1633 | |
| 1634 | clangimport::Data data(tokenizer.getSettings(), *symbolDatabase); |
| 1635 | std::string line; |
| 1636 | std::vector<AstNodePtr> tree; |
| 1637 | while (std::getline(f,line)) { |
| 1638 | const std::string::size_type pos1 = line.find('-'); |
| 1639 | if (pos1 == std::string::npos) |
| 1640 | continue; |
| 1641 | if (!tree.empty() && line.substr(pos1) == "-<<<NULL>>>") { |
| 1642 | const int level = (pos1 - 1) / 2; |
| 1643 | tree[level - 1]->children.push_back(nullptr); |
| 1644 | continue; |
| 1645 | } |
| 1646 | const std::string::size_type pos2 = line.find(' ', pos1); |
| 1647 | if (pos2 < pos1 + 4 || pos2 == std::string::npos) |
| 1648 | continue; |
| 1649 | const std::string nodeType = line.substr(pos1+1, pos2 - pos1 - 1); |
| 1650 | const std::string ext = line.substr(pos2); |
| 1651 | |
| 1652 | if (pos1 == 1 && endsWith(nodeType, "Decl")) { |
| 1653 | if (!tree.empty()) |
| 1654 | tree[0]->createTokens1(tokenList); |
| 1655 | tree.clear(); |
| 1656 | tree.push_back(std::make_shared<AstNode>(nodeType, ext, &data)); |
| 1657 | continue; |
| 1658 | } |
| 1659 | |
| 1660 | const int level = (pos1 - 1) / 2; |
| 1661 | if (level == 0 || level > tree.size()) |
| 1662 | continue; |
| 1663 | |
| 1664 | AstNodePtr newNode = std::make_shared<AstNode>(nodeType, ext, &data); |
| 1665 | tree[level - 1]->children.push_back(newNode); |
| 1666 | if (level >= tree.size()) |
| 1667 | tree.push_back(std::move(newNode)); |
| 1668 | else |
| 1669 | tree[level] = std::move(newNode); |
| 1670 | } |
| 1671 | |
| 1672 | if (!tree.empty()) |
| 1673 | tree[0]->createTokens1(tokenList); |
| 1674 | |
| 1675 | // Validation |
| 1676 | for (const Token *tok = tokenList.front(); tok; tok = tok->next()) { |
| 1677 | if (Token::Match(tok, "(|)|[|]|{|}") && !tok->link()) |
| 1678 | throw InternalError(tok, "Token::link() is not set properly"); |
| 1679 | } |
| 1680 | |
| 1681 | if (tokenList.front()) |
| 1682 | tokenList.front()->assignIndexes(); |
nothing calls this directly
no test coverage detected