Lines Matching full:table
32 #define DEBUG_TYPE "searchable-table-emitter"
157 std::string searchableFieldType(const GenericTable &Table,
176 PrintFatalError(Index.Loc, Twine("In table '") + Table.Name +
185 Twine("In table '") + Table.Name + "' lookup method '" +
190 void emitGenericTable(const GenericTable &Table, raw_ostream &OS);
192 void emitLookupDeclaration(const GenericTable &Table,
194 void emitLookupFunction(const GenericTable &Table, const SearchIndex &Index,
200 parseSearchIndex(GenericTable &Table, const RecordVal *RecVal, StringRef Name,
204 void collectTableEntries(GenericTable &Table, ArrayRef<const Record *> Items);
319 void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
324 emitLookupDeclaration(Table, Index, OS);
333 IndexTypeName = Table.CppTypeName;
334 IndexName = Table.Name;
335 IndexRows = Table.Entries;
340 << searchableFieldType(Table, Index, Field, TypeInStaticStruct) << " "
349 Entries.reserve(Table.Entries.size());
350 for (unsigned i = 0; i < Table.Entries.size(); ++i)
351 Entries.emplace_back(Table.Entries[i], i);
404 '(' + searchableFieldType(Table, Index, Field, TypeInStaticStruct) +
411 OS << " auto Table = ArrayRef(" << IndexName << ");\n";
415 OS << "&Table[Idx]";
417 OS << "&" << Table.Name << "[Table[Idx]._index]";
426 OS << " " << searchableFieldType(Table, Index, Field, TypeInTempStruct)
438 Twine("In table '") + Table.Name +
487 OS << " auto Table = ArrayRef(" << IndexName << ");\n";
489 OS << " auto It = std::equal_range(Table.begin(), Table.end(), Key, ";
491 OS << " auto Idx = std::lower_bound(Table.begin(), Table.end(), Key, ";
495 OS << " if (Idx == Table.end()";
507 OS << " return &" << Table.Name << "[Idx->_index];\n";
513 void SearchableTableEmitter::emitLookupDeclaration(const GenericTable &Table,
517 OS << "llvm::iterator_range<const " << Table.CppTypeName << " *> ";
519 OS << "const " << Table.CppTypeName << " *";
523 OS << LS << searchableFieldType(Table, Index, Field, TypeInArgument) << " "
528 void SearchableTableEmitter::emitGenericTable(const GenericTable &Table,
530 emitIfdef((Twine("GET_") + Table.PreprocessorGuard + "_DECL").str(), OS);
533 if (Table.PrimaryKey) {
534 emitLookupDeclaration(Table, *Table.PrimaryKey, OS);
537 for (const auto &Index : Table.Indices) {
538 emitLookupDeclaration(Table, *Index, OS);
544 emitIfdef((Twine("GET_") + Table.PreprocessorGuard + "_IMPL").str(), OS);
546 // The primary data table contains all the fields defined for this map.
547 OS << "constexpr " << Table.CppTypeName << " " << Table.Name << "[] = {\n";
548 for (unsigned i = 0; i < Table.Entries.size(); ++i) {
549 const Record *Entry = Table.Entries[i];
553 for (const auto &Field : Table.Fields)
555 << primaryRepresentation(Table.Locs[0], Field,
564 if (Table.PrimaryKey)
565 emitLookupFunction(Table, *Table.PrimaryKey, /*IsPrimary=*/true, OS);
566 for (const auto &Index : Table.Indices)
567 emitLookupFunction(Table, *Index, /*IsPrimary=*/false, OS);
597 GenericTable &Table, const RecordVal *KeyRecVal, StringRef Name,
606 const GenericField *Field = Table.getFieldByName(FieldName);
610 Twine("In table '") + Table.Name +
657 GenericTable &Table, ArrayRef<const Record *> Items) {
659 PrintFatalError(Table.Locs,
660 Twine("Table '") + Table.Name + "' has no entries");
663 for (auto &Field : Table.Fields) {
667 "' for table '" + Table.Name +
677 Twine("Field '") + Field.Name + "' of table '" +
678 Table.Name + "' entry has incompatible type: " +
685 Table.Entries.push_back(EntryRec); // Add record to table's record list.
690 for (auto &Field : Table.Fields) {
693 "' in table '" + Table.Name + "'. Maybe it is not used?");
704 std::copy(Table.Fields.begin(), Table.Fields.end(),
706 llvm::sort(Table.Entries, [&](const Record *LHS, const Record *RHS) {
750 auto Table = std::make_unique<GenericTable>();
751 Table->Name = std::string(TableRec->getName());
752 Table->Locs = TableRec->getLoc();
753 Table->PreprocessorGuard = std::string(TableRec->getName());
754 Table->CppTypeName = std::string(TableRec->getValueAsString("CppTypeName"));
758 Table->Fields.emplace_back(FieldName); // Construct a GenericField.
762 if (!parseFieldType(Table->Fields.back(),
765 Twine("Table '") + Table->Name + "' has invalid 'TypeOf_" +
777 Twine("Table FilterClass '") + FilterClass +
797 collectTableEntries(*Table, Definitions);
800 Table->PrimaryKey =
801 parseSearchIndex(*Table, TableRec->getValue("PrimaryKey"),
807 llvm::stable_sort(Table->Entries,
809 return compareBy(LHS, RHS, *Table->PrimaryKey);
813 TableMap.try_emplace(TableRec, Table.get());
814 Tables.emplace_back(std::move(Table));
819 const Record *TableRec = IndexRec->getValueAsDef("Table");
822 PrintFatalError(IndexRec->getValue("Table"),
824 "' refers to nonexistent table '" +
827 GenericTable &Table = *It->second;
828 Table.Indices.push_back(parseSearchIndex(
829 Table, IndexRec->getValue("Key"), IndexRec->getName(),
861 auto Table = std::make_unique<GenericTable>();
862 Table->Name = (Twine(Class->getName()) + "sList").str();
863 Table->Locs = Class->getLoc();
864 Table->PreprocessorGuard = Class->getName().upper();
865 Table->CppTypeName = std::string(Class->getName());
877 Table->Fields.emplace_back(FieldName);
880 collectTableEntries(*Table, Items);
885 (Twine("lookup") + Table->CppTypeName + "By" + Field).str();
886 Table->Indices.push_back(
887 parseSearchIndex(*Table, Class->getValue(Field), Name, {Field},
891 Tables.emplace_back(std::move(Table));
898 for (const auto &Table : Tables)
899 emitGenericTable(*Table, OS);
908 X("gen-searchable-tables", "Generate generic binary-searchable table");