diff --git a/CMakeLists.txt b/CMakeLists.txt index 41b0d2216f..8cf953cd8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,26 +192,6 @@ add_custom_command( COMMENT "Generating Config Source Files" ) -add_custom_command( - COMMAND - ${PYTHON_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR}/util/generate-info-files.py - src/lib/Metadata/InfoNodes.json - ${CMAKE_CURRENT_BINARY_DIR} - VERBATIM - DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/util/generate-info-files.py - src/lib/Metadata/InfoNodes.json - OUTPUT - ${CMAKE_CURRENT_BINARY_DIR}/include/mrdocs/Metadata/InfoNodesLower.inc - ${CMAKE_CURRENT_BINARY_DIR}/include/mrdocs/Metadata/InfoNodesPascal.inc - ${CMAKE_CURRENT_BINARY_DIR}/include/mrdocs/Metadata/InfoNodesPascalAndLower.inc - ${CMAKE_CURRENT_BINARY_DIR}/include/mrdocs/Metadata/InfoNodesPascalPlural.inc - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMENT "Generating Info Include Files" -) - - # Main library file( GLOB_RECURSE LIB_SOURCES CONFIGURE_DEPENDS @@ -232,10 +212,6 @@ list(APPEND LIB_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/include/mrdocs/Version.hpp ${CMAKE_CURRENT_BINARY_DIR}/include/mrdocs/PublicSettings.hpp ${CMAKE_CURRENT_BINARY_DIR}/src/lib/Lib/PublicSettings.cpp - ${CMAKE_CURRENT_BINARY_DIR}/include/mrdocs/Metadata/InfoNodesLower.inc - ${CMAKE_CURRENT_BINARY_DIR}/include/mrdocs/Metadata/InfoNodesPascal.inc - ${CMAKE_CURRENT_BINARY_DIR}/include/mrdocs/Metadata/InfoNodesPascalAndLower.inc - ${CMAKE_CURRENT_BINARY_DIR}/include/mrdocs/Metadata/InfoNodesPascalPlural.inc ) add_library(mrdocs-core ${LIB_SOURCES}) target_compile_features(mrdocs-core PUBLIC cxx_std_20) diff --git a/docs/antora-playbook.yml b/docs/antora-playbook.yml index 5a4d9fd614..d7f982c42c 100644 --- a/docs/antora-playbook.yml +++ b/docs/antora-playbook.yml @@ -50,5 +50,4 @@ asciidoc: - '@asciidoctor/tabs' - ./extensions/mrdocs-demos.js - ./extensions/mrdocs-releases.js - - ./extensions/c-preprocessor.js - ./extensions/config-options-reference.js diff --git a/docs/extensions/c-preprocessor.js b/docs/extensions/c-preprocessor.js deleted file mode 100644 index 3e29f6e2f7..0000000000 --- a/docs/extensions/c-preprocessor.js +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (c) 2024 Alan de Freitas (alandefreitas@gmail.com) - - Distributed under the Boost Software License, Version 1.0. (See accompanying - file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - - Official repository: https://github.com/cppalliance/mrdocs -*/ - -module.exports = function (registry) { - // Make sure registry is defined - if (!registry) { - throw new Error('registry must be defined'); - } - - registry.block('c-preprocessor', function () { - const self = this - var compiler = require("c-preprocessor"); - self.onContext('example') - self.process((parent, reader) => { - let code = reader.getLines().join('\n') - let processed = '' - const options = { - commentEscape: true - } - compiler.compile(code, options, function (err, result) { - if (err) - return console.log(err); - processed = result - }); - // Remove any comments from the processed code - processed = processed.replace(/\/\/.*\n/g, '') - processed = processed.replace(/\/\*[\s\S]*?\*\//g, '') - return self.createBlock(parent, 'open', processed) - }) - }) -} diff --git a/docs/modules/ROOT/pages/contribute.adoc b/docs/modules/ROOT/pages/contribute.adoc index 919d462da1..376da24277 100644 --- a/docs/modules/ROOT/pages/contribute.adoc +++ b/docs/modules/ROOT/pages/contribute.adoc @@ -75,22 +75,6 @@ For each compilation command: ==== Info Nodes MrDocs represents each C++ symbol or construct as an `Info` node (`mrdocs/Metadata/Info.hpp`). -MrDocs currently defines the following `Info` nodes: - -[c-preprocessor] -==== - -[cols="1,3,2"] -|=== -| Name | Description | Declaration - -#define INFO_PASCAL_AND_DESC(Type, Desc) | `pass:[Type]pass:[Info]` | Desc | `mrdocs/Metadata/pass:[Type].hpp` - -include::partial$InfoNodes.inc[] - -|=== -==== - `Info` can not only represent direct AST symbols but also {cpp} constructs that need to be inferred from these symbols. Nodes in the first category will typically be created in the initial extraction step, and nodes in the second category will be created in the finalization step. diff --git a/docs/modules/ROOT/partials/InfoNodes.inc b/docs/modules/ROOT/partials/InfoNodes.inc deleted file mode 100644 index 857f35ce3c..0000000000 --- a/docs/modules/ROOT/partials/InfoNodes.inc +++ /dev/null @@ -1,110 +0,0 @@ -// -// Licensed under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// Copyright (c) 2024 Alan de Freitas (alandefreitas@gmail.com) -// -// Official repository: https://github.com/cppalliance/mrdocs -// - -/* This file describes the types of Info nodes supported by MrDocs. - * - * It uses the same file format as LLVM .inc files generated by TableGen - * with the exception that we maintain this file directly. - * - * The purpose of this file is to provide a list of Info nodes that can be - * used by MrDocs in such a way that any code that depends on an exaustive - * list of Info nodes can be generated automatically. - * - * The table contains the basic information for each node type, such - * as the name in various casings and the description. - * - * How to use this table: - * - * 1) choose one of the following macros below, such as - * INFO_PASCAL, INFO_PLURAL, INFO_UC, INFO_PASCAL_AND_UC, etc. - * 2) Define this macro with the content to be rendered for each node type, - * such as #define INFO_PASCAL(Type) struct Type##Info; - * 3) Include this file below the macro definition with - * #include - * - * This will render your macro for each node type. - * We do not recommend using the INFO macro directly in your code because - * it might change in the future as more information about the nodes is - * added. - * This can make the code hard to maintain. - * - */ - - -// See files changed in https://github.com/cppalliance/mrdocs/pull/545 - -#ifndef INFO -#ifdef INFO_PASCAL -#define INFO(Pascal, Plural, UC, LC, LC_Plural, Desc) INFO_PASCAL(Pascal) -#endif -#ifdef INFO_PLURAL -#define INFO(Pascal, Plural, UC, LC, LC_Plural, Desc) INFO_PLURAL(Plural) -#endif -#ifdef INFO_UC -#define INFO(Pascal, Plural, UC, LC, LC_Plural, Desc) INFO_UC(UC) -#endif -#ifdef INFO_PASCAL_AND_UC -#define INFO(Pascal, Plural, UC, LC, LC_Plural, Desc) INFO_PASCAL_AND_UC(Pascal, UC) -#endif -#ifdef INFO_PASCAL_AND_LC -#define INFO(Pascal, Plural, UC, LC, LC_Plural, Desc) INFO_PASCAL_AND_LC(Pascal, LC) -#endif -#ifdef INFO_PLURAL_AND_LC_PLURAL -#define INFO(Pascal, Plural, UC, LC, LC_Plural, Desc) INFO_PLURAL_AND_LC_PLURAL(Plural, LC_Plural) -#endif -#ifdef INFO_PASCAL_AND_DESC -#define INFO(Pascal, Plural, UC, LC, LC_Plural, Desc) INFO_PASCAL_AND_DESC(Pascal, Desc) -#endif -#endif - -INFO(Namespace, Namespaces, NAMESPACE, namespace, namespaces, The symbol is a namespace) -INFO(Record, Records, RECORD, record, records, The symbol is a record (class or struct)) -INFO(Function, Functions, FUNCTION, function, functions, The symbol is a function) -INFO(Enum, Enums, ENUM, enum, enums, The symbol is an enum) -INFO(Typedef, Typedefs, TYPEDEF, typedef, typedefs, The symbol is a typedef) -INFO(Variable, Variables, VARIABLE, variable, variables, The symbol is a variable) -INFO(Field, Fields, FIELD, field, fields, The symbol is a field) -INFO(Specialization, Specializations, SPECIALIZATION, specialization, specializations, The symbol is a template specialization) -INFO(Friend, Friends, FRIEND, friend, friends, The symbol is a friend declaration) -INFO(EnumConstant, EnumConstants, ENUM_CONSTANT, enumerator, enumerators, The symbol is an enumerator) -INFO(Guide, Guides, GUIDE, guide, guides, The symbol is a deduction guide) -INFO(Alias, Aliases, ALIAS, alias, aliases, The symbol is a namespace alias) -INFO(Using, Usings, USING, using, usings, The symbol is a using declaration) -INFO(Concept, Concepts, CONCEPT, concept, concepts, The symbol is a concept) - -#ifdef INFO_PASCAL -#undef INFO_PASCAL -#endif - -#ifdef INFO_PLURAL -#undef INFO_PLURAL -#endif - -#ifdef INFO_UC -#undef INFO_UC -#endif - -#ifdef INFO_PASCAL_AND_UC -#undef INFO_PASCAL_AND_UC -#endif - -#ifdef INFO_PASCAL_AND_LC -#undef INFO_PASCAL_AND_LC -#endif - -#ifdef INFO_PLURAL_AND_LC_PLURAL -#undef INFO_PLURAL_AND_LC_PLURAL -#endif - -#ifdef INFO_PASCAL_AND_DESC -#undef INFO_PASCAL_AND_DESC -#endif - -#undef INFO diff --git a/docs/package.json b/docs/package.json index 3aefcc8432..ec6f9bb678 100644 --- a/docs/package.json +++ b/docs/package.json @@ -9,7 +9,6 @@ "@antora/lunr-extension": "^1.0.0-alpha.8", "@asciidoctor/tabs": "^1.0.0-beta.3", "asciidoctor": "^2.2.6", - "c-preprocessor": "^0.2.13", "sync-request": "^6.1.0" } } diff --git a/include/mrdocs/Metadata.hpp b/include/mrdocs/Metadata.hpp index 92e0f518f8..c13449d4f1 100644 --- a/include/mrdocs/Metadata.hpp +++ b/include/mrdocs/Metadata.hpp @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include #include diff --git a/include/mrdocs/Metadata/Info.hpp b/include/mrdocs/Metadata/Info.hpp index f57c539278..6988f78c76 100644 --- a/include/mrdocs/Metadata/Info.hpp +++ b/include/mrdocs/Metadata/Info.hpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -30,7 +30,7 @@ namespace clang::mrdocs { /* Forward declarations */ #define INFO(Type) struct Type##Info; -#include +#include /** Info variant discriminator */ @@ -38,7 +38,7 @@ enum class InfoKind { None = 0, #define INFO(Type) Type, - #include + #include }; /** Return the name of the InfoKind as a string. @@ -65,7 +65,7 @@ countInfoKind() { std::underlying_type_t count = 0; #define INFO(Type) count++; -#include +#include return count; } @@ -149,7 +149,7 @@ struct MRDOCS_VISIBLE Info #define INFO(Type) constexpr bool is##Type() const noexcept { \ return Kind == InfoKind::Type; \ } - #include + #include constexpr Info const& asInfo() const noexcept { @@ -167,7 +167,7 @@ struct MRDOCS_VISIBLE Info return reinterpret_cast(*this); \ MRDOCS_UNREACHABLE(); \ } - #include + #include #define INFO(Type) \ constexpr Type##Info & as##Type() noexcept { \ @@ -175,21 +175,21 @@ struct MRDOCS_VISIBLE Info return reinterpret_cast(*this); \ MRDOCS_UNREACHABLE(); \ } - #include + #include #define INFO(Type) \ constexpr Type##Info const* as##Type##Ptr() const noexcept { \ if (Kind == InfoKind::Type) { return reinterpret_cast(this); } \ return nullptr; \ } - #include + #include #define INFO(Type) \ constexpr Type##Info * as##Type##Ptr() noexcept { \ if (Kind == InfoKind::Type) { return reinterpret_cast(this); } \ return nullptr; \ } - #include + #include auto operator<=>(Info const&) const = default; }; @@ -214,7 +214,7 @@ struct InfoCommonBase : Info #define INFO(Kind) \ static constexpr bool is##Kind() noexcept { return K == InfoKind::Kind; } - #include + #include auto operator<=>(InfoCommonBase const&) const = default; @@ -255,7 +255,7 @@ visit( #define INFO(Type) \ case InfoKind::Type: \ return visitor.template visit(); - #include + #include default: MRDOCS_UNREACHABLE(); } diff --git a/include/mrdocs/Metadata/Info/InfoNodes.inc b/include/mrdocs/Metadata/Info/InfoNodes.inc new file mode 100644 index 0000000000..0e687480ee --- /dev/null +++ b/include/mrdocs/Metadata/Info/InfoNodes.inc @@ -0,0 +1,30 @@ +// +// Licensed under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +// Copyright (c) 2025 Alan de Freitas (alandefreitas@gmail.com) +// +// Official repository: https://github.com/cppalliance/mrdocs +// + +#ifndef INFO +#define INFO(PascalName) +#endif + +INFO(Namespace) +INFO(Record) +INFO(Function) +INFO(Overloads) +INFO(Enum) +INFO(EnumConstant) +INFO(Typedef) +INFO(Variable) +INFO(Friend) +INFO(Guide) +INFO(NamespaceAlias) +INFO(Using) +INFO(Concept) + +#undef INFO + diff --git a/include/mrdocs/Metadata/Javadoc.hpp b/include/mrdocs/Metadata/Javadoc.hpp index eb61c9d2a6..cf9b116bbc 100644 --- a/include/mrdocs/Metadata/Javadoc.hpp +++ b/include/mrdocs/Metadata/Javadoc.hpp @@ -14,7 +14,7 @@ #define MRDOCS_API_METADATA_JAVADOC_HPP #include -#include +#include #include #include #include diff --git a/include/mrdocs/Metadata/Symbols.hpp b/include/mrdocs/Metadata/SymbolID.hpp similarity index 98% rename from include/mrdocs/Metadata/Symbols.hpp rename to include/mrdocs/Metadata/SymbolID.hpp index 227dee8db0..5d71f84b9c 100644 --- a/include/mrdocs/Metadata/Symbols.hpp +++ b/include/mrdocs/Metadata/SymbolID.hpp @@ -10,8 +10,8 @@ // Official repository: https://github.com/cppalliance/mrdocs // -#ifndef MRDOCS_API_METADATA_SYMBOLS_HPP -#define MRDOCS_API_METADATA_SYMBOLS_HPP +#ifndef MRDOCS_API_METADATA_SYMBOLID_HPP +#define MRDOCS_API_METADATA_SYMBOLID_HPP #include #include diff --git a/include/mrdocs/Metadata/Type.hpp b/include/mrdocs/Metadata/Type.hpp index 7eaa6f6d88..6cbf90fac3 100644 --- a/include/mrdocs/Metadata/Type.hpp +++ b/include/mrdocs/Metadata/Type.hpp @@ -17,13 +17,15 @@ #include #include #include -#include -#include +#include #include #include namespace clang::mrdocs { +struct NameInfo; +struct TypeInfo; + std::strong_ordering operator<=>(Polymorphic const& lhs, Polymorphic const& rhs); diff --git a/include/mrdocs/MetadataFwd.hpp b/include/mrdocs/MetadataFwd.hpp deleted file mode 100644 index 3ac13094e7..0000000000 --- a/include/mrdocs/MetadataFwd.hpp +++ /dev/null @@ -1,72 +0,0 @@ -// -// This is a derivative work. originally part of the LLVM Project. -// Licensed under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -// Copyright (c) 2023 Vinnie Falco (vinnie.falco@gmail.com) -// -// Official repository: https://github.com/cppalliance/mrdocs -// - -#ifndef MRDOCS_API_METADATAFWD_HPP -#define MRDOCS_API_METADATAFWD_HPP - -// Forward declarations for all types -// related to metadata extracted from AST - -namespace clang::mrdocs { - -class Corpus; - -class Interface; - -enum class InfoKind; - -enum class AccessKind; -enum class ConstexprKind; -enum class ExplicitKind; -enum class NoexceptKind; -enum class OperatorKind; -enum class ReferenceKind; -enum class StorageClassKind; - -#define INFO(Type) \ -struct Type##Info; -#include - -struct BaseInfo; -struct Info; -struct Javadoc; -struct Location; -struct NameInfo; -struct Param; -struct SpecializationNameInfo; -struct SourceInfo; -struct TypeInfo; -struct VerbatimBlock; - -struct ExprInfo; -template -struct ConstantExprInfo; - -struct TemplateInfo; -struct TArg; -struct TypeTArg; -struct NonTypeTArg; -struct TemplateTArg; -struct TParam; -struct TypeTParam; -struct NonTypeTParam; -struct TemplateTParam; - -struct DataMember; -struct MemberEnum; -struct MemberFunction; -struct MemberRecord; -struct MemberType; -struct StaticDataMember; - -} // clang::mrdocs - -#endif diff --git a/src/lib/AST/ClangHelpers.hpp b/src/lib/AST/ClangHelpers.hpp index 0fc713eca3..250b68e087 100644 --- a/src/lib/AST/ClangHelpers.hpp +++ b/src/lib/AST/ClangHelpers.hpp @@ -14,7 +14,7 @@ #ifndef MRDOCS_LIB_AST_CLANGHELPERS_HPP #define MRDOCS_LIB_AST_CLANGHELPERS_HPP -#include +#include #include #include #include diff --git a/src/lib/AST/ParseRef.hpp b/src/lib/AST/ParseRef.hpp index da27d58b1c..212c53d080 100644 --- a/src/lib/AST/ParseRef.hpp +++ b/src/lib/AST/ParseRef.hpp @@ -20,6 +20,8 @@ namespace clang::mrdocs { +struct TArg; + struct ParsedRefComponent { // Component name std::string_view Name; diff --git a/src/lib/Gen/hbs/Builder.cpp b/src/lib/Gen/hbs/Builder.cpp index 0e1c11a8bb..6ff77997f1 100644 --- a/src/lib/Gen/hbs/Builder.cpp +++ b/src/lib/Gen/hbs/Builder.cpp @@ -347,7 +347,7 @@ operator()(std::ostream& os, T const& I) // Compile the Builder::operator() for each Info type #define INFO(T) template Expected Builder::operator()(std::ostream&, T##Info const&); -#include +#include Expected Builder:: diff --git a/src/lib/Gen/hbs/MultiPageVisitor.cpp b/src/lib/Gen/hbs/MultiPageVisitor.cpp index 59034dab3c..09bb15a856 100644 --- a/src/lib/Gen/hbs/MultiPageVisitor.cpp +++ b/src/lib/Gen/hbs/MultiPageVisitor.cpp @@ -74,6 +74,6 @@ operator()(T const& I) } #define INFO(T) template void MultiPageVisitor::operator()(T##Info const&); -#include +#include } // clang::mrdocs::hbs diff --git a/src/lib/Gen/hbs/SinglePageVisitor.cpp b/src/lib/Gen/hbs/SinglePageVisitor.cpp index d1f5d2bf1e..9c9fc9e8aa 100644 --- a/src/lib/Gen/hbs/SinglePageVisitor.cpp +++ b/src/lib/Gen/hbs/SinglePageVisitor.cpp @@ -43,7 +43,7 @@ operator()(T const& I) } #define INFO(T) template void SinglePageVisitor::operator()(T##Info const&); -#include +#include // pageNumber is zero-based void diff --git a/src/lib/Gen/hbs/SinglePageVisitor.hpp b/src/lib/Gen/hbs/SinglePageVisitor.hpp index c892e0e645..797da308aa 100644 --- a/src/lib/Gen/hbs/SinglePageVisitor.hpp +++ b/src/lib/Gen/hbs/SinglePageVisitor.hpp @@ -13,16 +13,13 @@ #define MRDOCS_LIB_GEN_HBS_SINGLEPAGEVISITOR_HPP #include "Builder.hpp" -#include #include #include #include #include #include -namespace clang { -namespace mrdocs { -namespace hbs { +namespace clang::mrdocs::hbs { /** Visitor which writes everything to a single page. */ @@ -58,8 +55,6 @@ class SinglePageVisitor void operator()(T const& I); }; -} // hbs -} // mrdocs -} // clang +} // clang::mrdocs::hbs #endif diff --git a/src/lib/Gen/xml/CXXTags.cpp b/src/lib/Gen/xml/CXXTags.cpp index 64bf78c205..a5ea3bbfd7 100644 --- a/src/lib/Gen/xml/CXXTags.cpp +++ b/src/lib/Gen/xml/CXXTags.cpp @@ -12,18 +12,19 @@ #include "CXXTags.hpp" #include #include +#include namespace clang::mrdocs::xml { -llvm::StringRef +std::string getDefaultTagName(Info const& I) noexcept { switch(I.Kind) { -#define INFO(PascalName, LowerName) \ - case InfoKind::PascalName: \ - return LowerName##TagName; -#include +#define INFO(Type) \ + case InfoKind::Type: \ + return toKebabCase(#Type) + "TagName"; +#include default: break; } @@ -31,7 +32,7 @@ getDefaultTagName(Info const& I) noexcept } -llvm::StringRef +std::string getTagName(Info const& I) noexcept { switch(I.Kind) @@ -47,10 +48,14 @@ getTagName(Info const& I) noexcept } break; case InfoKind::Typedef: - if(static_cast(I).IsUsing) - return namespaceAliasTagName; + if (static_cast(I).IsUsing) + { + return "namespace"; + } else - return typedefTagName; + { + return "typedef"; + } default: return getDefaultTagName(I); } diff --git a/src/lib/Gen/xml/CXXTags.hpp b/src/lib/Gen/xml/CXXTags.hpp index b9401c9e49..a9d74a7d0c 100644 --- a/src/lib/Gen/xml/CXXTags.hpp +++ b/src/lib/Gen/xml/CXXTags.hpp @@ -24,13 +24,7 @@ in the MRDOCS DTD XML schema. */ -namespace clang { -namespace mrdocs { -namespace xml { - -#define INFO(camelName, LowerName) \ -constexpr auto camelName##TagName = #LowerName; -#include +namespace clang::mrdocs::xml { constexpr auto accessTagName = "access"; constexpr auto attributeTagName = "attr"; @@ -333,11 +327,9 @@ inline void writeTemplateArg(TArg const& I, XMLTags& tags) /** Return the xml tag name for the Info. */ -llvm::StringRef +std::string getTagName(Info const& I) noexcept; -} // xml -} // mrdocs -} // clang +} // clang::mrdocs::xml #endif diff --git a/src/lib/Gen/xml/XMLGenerator.hpp b/src/lib/Gen/xml/XMLGenerator.hpp index 1bc060e766..57a45b58dc 100644 --- a/src/lib/Gen/xml/XMLGenerator.hpp +++ b/src/lib/Gen/xml/XMLGenerator.hpp @@ -14,13 +14,10 @@ #include #include -#include #include #include -namespace clang { -namespace mrdocs { -namespace xml { +namespace clang::mrdocs::xml { //------------------------------------------------ @@ -50,8 +47,6 @@ struct XMLGenerator : Generator Corpus const& corpus) const override; }; -} // xml -} // mrdocs -} // clang +} // clang::mrdocs::xml #endif diff --git a/src/lib/Gen/xml/XMLTags.hpp b/src/lib/Gen/xml/XMLTags.hpp index b797e77442..6dbc01247f 100644 --- a/src/lib/Gen/xml/XMLTags.hpp +++ b/src/lib/Gen/xml/XMLTags.hpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include /* diff --git a/src/lib/Gen/xml/XMLWriter.cpp b/src/lib/Gen/xml/XMLWriter.cpp index e91b9e8972..eb55bb6a7b 100644 --- a/src/lib/Gen/xml/XMLWriter.cpp +++ b/src/lib/Gen/xml/XMLWriter.cpp @@ -197,7 +197,7 @@ operator()( return; } #define INFO(Type) if constexpr(T::is##Type()) write##Type(I); - #include + #include } //------------------------------------------------ @@ -207,6 +207,7 @@ XMLWriter:: writeNamespace( NamespaceInfo const& I) { + constexpr std::string_view namespaceTagName = "namespace"; tags_.open(namespaceTagName, { { "name", I.Name, ! I.Name.empty() }, { I.id }, @@ -230,6 +231,7 @@ XMLWriter:: writeEnum( EnumInfo const& I) { + constexpr std::string_view enumTagName = "enum"; tags_.open(enumTagName, { { "name", I.Name }, { "class", "scoped", I.Scoped }, @@ -261,6 +263,7 @@ writeEnumConstant( std::to_string(*I.Initializer.Value) : I.Initializer.Written; + constexpr std::string_view enumConstantTagName = "enum-constant"; tags_.open(enumConstantTagName, { { "name", I.Name }, { "initializer", val }, @@ -280,6 +283,7 @@ XMLWriter:: writeFriend( FriendInfo const& I) { + constexpr std::string_view friendTagName = "friend"; tags_.open(friendTagName, { { I.Access }, { I.id } @@ -310,6 +314,7 @@ writeFunction( auto except_spec = toString(I.Noexcept); auto explicit_spec = toString(I.Explicit); + constexpr std::string_view functionTagName = "function"; tags_.open(functionTagName, { { "class", toString(I.Class), I.Class != FunctionClass::Normal }, @@ -374,6 +379,7 @@ writeGuide( auto explicit_spec = toString(I.Explicit); + constexpr std::string_view guideTagName = "guide"; tags_.open(guideTagName, { { "name", I.Name }, { I.Access }, @@ -405,6 +411,7 @@ writeConcept( { openTemplate(I.Template); + constexpr std::string_view conceptTagName = "concept"; tags_.open(conceptTagName, { { "name", I.Name }, { I.Access }, @@ -426,6 +433,7 @@ XMLWriter:: writeNamespaceAlias( NamespaceAliasInfo const& I) { + constexpr std::string_view namespaceAliasTagName = "namespace-alias"; tags_.open(namespaceAliasTagName, { { "name", I.Name }, { I.Access }, @@ -469,6 +477,7 @@ XMLWriter:: qualifierStr = toString(*I.Qualifier); } + constexpr std::string_view usingTagName = "using"; tags_.open(usingTagName, { { I.Access }, { I.id }, @@ -532,11 +541,16 @@ writeTypedef( { openTemplate(I.Template); + constexpr std::string_view namespaceAliasTagName = "namespace-alias"; + constexpr std::string_view typedefTagName = "typedef"; llvm::StringRef tag; - if(I.IsUsing) + if (I.IsUsing) + { tag = namespaceAliasTagName; - else + } else + { tag = typedefTagName; + } tags_.open(tag, { { "name", I.Name }, { I.Access }, @@ -793,7 +807,7 @@ XMLWriter:: writeCopied( doc::CopyDetails const& node) { - std::string_view const tag_name = "copydetails"; + std::string_view constexpr tag_name = "copydetails"; tags_.write(tag_name, node.string, { { node.id } }); diff --git a/src/lib/Gen/xml/XMLWriter.hpp b/src/lib/Gen/xml/XMLWriter.hpp index 65ac72e5b2..00603bb500 100644 --- a/src/lib/Gen/xml/XMLWriter.hpp +++ b/src/lib/Gen/xml/XMLWriter.hpp @@ -63,7 +63,7 @@ class XMLWriter // Info types #define INFO(Type) void write##Type(Type##Info const&); -#include +#include void writeSourceInfo(SourceInfo const& I); void writeLocation(Location const& loc, bool def = false); diff --git a/src/lib/Lib/TagfileWriter.cpp b/src/lib/Lib/TagfileWriter.cpp index ac398bd67f..93902b6a2f 100644 --- a/src/lib/Lib/TagfileWriter.cpp +++ b/src/lib/Lib/TagfileWriter.cpp @@ -103,7 +103,7 @@ operator()(T const& I) } #define INFO(Type) template void TagfileWriter::operator()(Type##Info const&); -#include +#include void TagfileWriter:: diff --git a/src/lib/Metadata/Finalizers/JavadocFinalizer.cpp b/src/lib/Metadata/Finalizers/JavadocFinalizer.cpp index 5acfb80ebb..133ef0f6b7 100644 --- a/src/lib/Metadata/Finalizers/JavadocFinalizer.cpp +++ b/src/lib/Metadata/Finalizers/JavadocFinalizer.cpp @@ -758,7 +758,7 @@ finalizeInfoData(InfoTy& I) } #define INFO(T) template void JavadocFinalizer::finalizeInfoData(T## Info&); -#include +#include void JavadocFinalizer:: diff --git a/src/lib/Metadata/Info.cpp b/src/lib/Metadata/Info.cpp index 077c60bb21..aecbce3492 100644 --- a/src/lib/Metadata/Info.cpp +++ b/src/lib/Metadata/Info.cpp @@ -20,17 +20,18 @@ #include #include #include +#include namespace clang::mrdocs { dom::String -toString(InfoKind kind) noexcept +toString(InfoKind const kind) noexcept { switch(kind) { -#define INFO(PascalName, LowerName) \ - case InfoKind::PascalName: return #LowerName; -#include +#define INFO(Type) \ + case InfoKind::Type: return toKebabCase(#Type); +#include default: MRDOCS_UNREACHABLE(); } diff --git a/src/lib/Metadata/Symbols.cpp b/src/lib/Metadata/SymbolID.cpp similarity index 98% rename from src/lib/Metadata/Symbols.cpp rename to src/lib/Metadata/SymbolID.cpp index 2cc68cb6e2..d9aca9edaf 100644 --- a/src/lib/Metadata/Symbols.cpp +++ b/src/lib/Metadata/SymbolID.cpp @@ -9,7 +9,7 @@ // Official repository: https://github.com/cppalliance/mrdocs // -#include +#include #include #include #include diff --git a/src/lib/Support/Debug.cpp b/src/lib/Support/Debug.cpp index 9c478964d6..0cf2499433 100644 --- a/src/lib/Support/Debug.cpp +++ b/src/lib/Support/Debug.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include namespace clang { namespace mrdocs { diff --git a/src/lib/Support/Debug.hpp b/src/lib/Support/Debug.hpp index d471b0f3a1..67048759f1 100644 --- a/src/lib/Support/Debug.hpp +++ b/src/lib/Support/Debug.hpp @@ -17,11 +17,16 @@ #include #endif #include -#include -#include +#include #include #include +namespace clang::mrdocs { + enum class InfoKind; + enum class AccessKind; + struct Info; +} + template<> struct fmt::formatter : fmt::formatter diff --git a/src/lib/Support/LegibleNames.hpp b/src/lib/Support/LegibleNames.hpp index 537fdb290a..a5ca1ee414 100644 --- a/src/lib/Support/LegibleNames.hpp +++ b/src/lib/Support/LegibleNames.hpp @@ -12,8 +12,8 @@ #ifndef MRDOCS_LIB_SUPPORT_LEGIBLENAMES_HPP #define MRDOCS_LIB_SUPPORT_LEGIBLENAMES_HPP -#include -#include +#include +#include #include #include diff --git a/util/generate-info-files.py b/util/generate-info-files.py deleted file mode 100644 index 26043b1229..0000000000 --- a/util/generate-info-files.py +++ /dev/null @@ -1,193 +0,0 @@ -# -# Licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# -# Copyright (c) 2024 Alan de Freitas (alandefreitas@gmail.com) -# -# Official repository: https://github.com/cppalliance/mrdocs -# - -import sys -import json -import os - - -def to_camel_case(kebab_str): - if ' ' in kebab_str: - parts = kebab_str.split(' ') - return to_camel_case('-'.join(parts)) - - if '.' in kebab_str: - parts = kebab_str.split('.') - return '.'.join([to_camel_case(part) for part in parts]) - - kebab_str = kebab_str[0].lower() + kebab_str[1:] - components = kebab_str.split('-') - return components[0] + ''.join(x.title() for x in components[1:]) - - -def to_pascal_case(kebab_str): - separator_chars = [' ', '<', '>'] - for separator_char in separator_chars: - if separator_char in kebab_str: - parts = kebab_str.split(separator_char) - return to_pascal_case('-'.join(parts)) - - if '.' in kebab_str: - parts = kebab_str.split('.') - return '.'.join([to_pascal_case(part) for part in parts]) - - components = kebab_str.split('-') - return ''.join(x.title() for x in components) - - -def generate_header_comment(): - header_comment = '/*\n' - header_comment += ' * This file is generated automatically from the json file\n' - header_comment += ' * `src/lib/Metadata/InfoNodes.json`. Do not edit this file\n' - header_comment += ' * manually. Instead, edit the json file and run the script\n' - header_comment += ' * `util/generate-info-files.py` to regenerate this file.\n' - header_comment += ' */\n\n' - return header_comment - - -def generate_info_nodes_pascal_inc(info_nodes): - contents = generate_header_comment() - contents += f'#ifndef INFO\n' - contents += f'#define INFO(PascalName) \n' - contents += f'#endif\n\n' - for info_node in info_nodes: - contents += f'INFO({to_pascal_case(info_node["name"])})\n' - contents += f'\n#undef INFO\n\n' - return contents - - -def generate_info_nodes_lowercase_inc(info_nodes): - contents = generate_header_comment() - contents += f'#ifndef INFO\n' - contents += f'#define INFO(LowerName) \n' - contents += f'#endif\n\n' - for info_node in info_nodes: - contents += f'INFO({info_node["name"].lower()})\n' - contents += f'\n#undef INFO\n' - return contents - -def generate_info_nodes_camelcase_inc(info_nodes): - contents = generate_header_comment() - contents += f'#ifndef INFO\n' - contents += f'#define INFO(CamelName) \n' - contents += f'#endif\n\n' - for info_node in info_nodes: - contents += f'INFO({to_camel_case(info_node["name"])})\n' - contents += f'\n#undef INFO\n' - return contents - - -def generate_info_nodes_pascal_and_lowercase_inc(info_nodes): - contents = generate_header_comment() - contents += f'#ifndef INFO\n' - contents += f'#define INFO(PascalName, LowerName) \n' - contents += f'#endif\n\n' - for info_node in info_nodes: - contents += f'INFO({to_pascal_case(info_node["name"])}, {info_node["name"].lower()})\n' - contents += f'\n#undef INFO\n' - return contents - -def generate_info_nodes_pascal_and_camelcase_inc(info_nodes): - contents = generate_header_comment() - contents += f'#ifndef INFO\n' - contents += f'#define INFO(PascalName, CamelName) \n' - contents += f'#endif\n\n' - for info_node in info_nodes: - contents += f'INFO({to_pascal_case(info_node["name"])}, {to_camel_case(info_node["name"])})\n' - contents += f'\n#undef INFO\n' - return contents - -def generate_info_nodes_camel_and_lowercase_inc(info_nodes): - contents = generate_header_comment() - contents += f'#ifndef INFO\n' - contents += f'#define INFO(CamelName, LowerName) \n' - contents += f'#endif\n\n' - for info_node in info_nodes: - contents += f'INFO({to_camel_case(info_node["name"])}, {info_node["name"].lower()})\n' - contents += f'\n#undef INFO\n' - return contents - -def to_plural(name): - if name.endswith('y'): - return name[:-1] + 'ies' - if name.endswith('s'): - return name + 'es' - return name + 's' - - -def generate_info_nodes_pascal_plural_inc(info_nodes): - contents = generate_header_comment() - contents += f'#ifndef INFO\n' - contents += f'#define INFO(PluralName) \n' - contents += f'#endif\n\n' - for info_node in info_nodes: - contents += f'INFO({to_plural(to_pascal_case(info_node["name"]))})\n' - contents += f'\n#undef INFO\n' - return contents - -def generate_info_nodes_pascal_plural_and_lowercase_plural_inc(info_nodes): - contents = generate_header_comment() - contents += f'#ifndef INFO\n' - contents += f'#define INFO(PluralName, LowerPluralName) \n' - contents += f'#endif\n\n' - for info_node in info_nodes: - contents += f'INFO({to_plural(to_pascal_case(info_node["name"]))}, {to_plural(info_node["name"].lower())})\n' - contents += f'\n#undef INFO\n' - return contents - -def generate(info_nodes, output_dir): - print('Generating Configuration Information...') - - mrdocs_build_include_dir = os.path.join(output_dir, 'include', 'mrdocs') - mrdocs_info_nodes_include_dir = os.path.join(mrdocs_build_include_dir, 'Metadata') - - all_dirs = [mrdocs_build_include_dir, mrdocs_info_nodes_include_dir] - for dir in all_dirs: - if not os.path.exists(dir): - os.makedirs(dir) - - files_content = { - 'InfoNodesPascal.inc': generate_info_nodes_pascal_inc(info_nodes), - 'InfoNodesPascalAndLower.inc': generate_info_nodes_pascal_and_lowercase_inc(info_nodes), - 'InfoNodesPascalAndCamel.inc': generate_info_nodes_pascal_and_camelcase_inc(info_nodes), - 'InfoNodesCamelAndLower.inc': generate_info_nodes_camel_and_lowercase_inc(info_nodes), - 'InfoNodesLower.inc': generate_info_nodes_lowercase_inc(info_nodes), - 'InfoNodesCamel.inc': generate_info_nodes_camelcase_inc(info_nodes), - 'InfoNodesPascalPlural.inc': generate_info_nodes_pascal_plural_inc(info_nodes), - 'InfoNodesPascalPluralAndLowerPlural.inc': generate_info_nodes_pascal_plural_and_lowercase_plural_inc(info_nodes) - } - - for filename, content in files_content.items(): - with open(os.path.join(mrdocs_info_nodes_include_dir, filename), 'w') as f: - f.write(content) - - -def main(): - # Read command line arguments - input_file = sys.argv[1] - output_dir = sys.argv[2] - - # ensure input is a json file - if not input_file.endswith('.json'): - print('Error: input file must be a json file') - sys.exit(1) - if os.path.exists(output_dir) and not os.path.isdir(output_dir): - print('Error: output directory already exists') - sys.exit(1) - - # parse input file - with open(input_file, 'r') as f: - info_nodes = json.load(f) - - generate(info_nodes, output_dir) - - -if __name__ == "__main__": - main()