diff options
| author | Aaron Ballman <aaron@aaronballman.com> | 2014-02-19 22:59:32 +0000 |
|---|---|---|
| committer | Aaron Ballman <aaron@aaronballman.com> | 2014-02-19 22:59:32 +0000 |
| commit | e2ceaea5f5ea5786a638e29e92d7d48d7188e7c6 (patch) | |
| tree | 66926e4758c3f2c67e0e7333634eaf9bca8c71e2 /utils | |
| parent | b3a4266e913cd51806a9bc16091d3eee723e6277 (diff) | |
| download | clang-e2ceaea5f5ea5786a638e29e92d7d48d7188e7c6.tar.gz clang-e2ceaea5f5ea5786a638e29e92d7d48d7188e7c6.tar.bz2 clang-e2ceaea5f5ea5786a638e29e92d7d48d7188e7c6.tar.xz | |
Refactored the way attribute category headers are handled so that it is possible to use custom categories. This allows for moving the consumable attributes (consumable, callable_when, return_typestate, etc) to be grouped together, with a content heading, like they were in the language extensions documentation. Moved the consumable attribute documentation from the language extensions into the attribute documentation table.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201732 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/TableGen/ClangAttrEmitter.cpp | 74 |
1 files changed, 25 insertions, 49 deletions
diff --git a/utils/TableGen/ClangAttrEmitter.cpp b/utils/TableGen/ClangAttrEmitter.cpp index 4c94e208a6..8f65d91085 100644 --- a/utils/TableGen/ClangAttrEmitter.cpp +++ b/utils/TableGen/ClangAttrEmitter.cpp @@ -2648,49 +2648,32 @@ void EmitClangAttrParserStringSwitches(RecordKeeper &Records, class DocumentationData { public: - enum DocCategory { - Function, - Variable, - Type, - Statement, - Undocumented - }; - - DocCategory Category; const Record *Documentation; const Record *Attribute; - DocumentationData(DocCategory Category, const Record &Documentation, - const Record &Attribute) - : Category(Category), Documentation(&Documentation), - Attribute(&Attribute) {} + DocumentationData(const Record &Documentation, const Record &Attribute) + : Documentation(&Documentation), Attribute(&Attribute) {} }; -static void WriteCategoryHeader(DocumentationData::DocCategory Category, +static void WriteCategoryHeader(const Record *DocCategory, raw_ostream &OS) { - OS << "\n"; - switch (Category) { - case DocumentationData::Undocumented: - assert(false && "Undocumented attributes are not documented!"); - break; - case DocumentationData::Function: - OS << "Function Attributes\n"; - OS << "===================\n"; - break; - case DocumentationData::Variable: - OS << "Variable Attributes\n"; - OS << "===================\n"; - break; - case DocumentationData::Type: - OS << "Type Attributes\n"; - OS << "===============\n"; - break; - case DocumentationData::Statement: - OS << "Statement Attributes\n"; - OS << "====================\n"; - break; + const std::string &Name = DocCategory->getValueAsString("Name"); + OS << Name << "\n" << std::string(Name.length(), '=') << "\n"; + + // If there is content, print that as well. + std::string ContentStr = DocCategory->getValueAsString("Content"); + if (!ContentStr.empty()) { + // Trim leading and trailing newlines and spaces. + StringRef Content(ContentStr); + while (Content.startswith("\r") || Content.startswith("\n") || + Content.startswith(" ") || Content.startswith("\t")) + Content = Content.substr(1); + while (Content.endswith("\r") || Content.endswith("\n") || + Content.endswith(" ") || Content.endswith("\t")) + Content = Content.substr(0, Content.size() - 1); + OS << Content; } - OS << "\n"; + OS << "\n\n"; } enum SpellingKind { @@ -2828,9 +2811,9 @@ void EmitClangAttrDocs(RecordKeeper &Records, raw_ostream &OS) { return; } - OS << Documentation->getValueAsString("Intro"); + OS << Documentation->getValueAsString("Intro") << "\n"; - typedef std::map<DocumentationData::DocCategory, + typedef std::map<const Record *, std::vector<DocumentationData> > CategoryMap; CategoryMap SplitDocs; @@ -2844,26 +2827,19 @@ void EmitClangAttrDocs(RecordKeeper &Records, raw_ostream &OS) { for (std::vector<Record *>::const_iterator DI = Docs.begin(), DE = Docs.end(); DI != DE; ++DI) { const Record &Doc = **DI; - DocumentationData::DocCategory Cat = - StringSwitch<DocumentationData::DocCategory>( - Doc.getValueAsDef("Category")->getValueAsString("Name")) - .Case("Functions", DocumentationData::Function) - .Case("Variables", DocumentationData::Variable) - .Case("Types", DocumentationData::Type) - .Case("Statements", DocumentationData::Statement) - .Case("Undocumented", DocumentationData::Undocumented); - + const Record *Category = Doc.getValueAsDef("Category"); // If the category is "undocumented", then there cannot be any other // documentation categories (otherwise, the attribute would become // documented). - bool Undocumented = DocumentationData::Undocumented == Cat; + std::string Cat = Category->getValueAsString("Name"); + bool Undocumented = Cat == "Undocumented"; if (Undocumented && Docs.size() > 1) PrintFatalError(Doc.getLoc(), "Attribute is \"Undocumented\", but has multiple " "documentation categories"); if (!Undocumented) - SplitDocs[Cat].push_back(DocumentationData(Cat, Doc, Attr)); + SplitDocs[Category].push_back(DocumentationData(Doc, Attr)); } } |
