Skip to content

Commit 6d49549

Browse files
committed
refactor(lib): consistent metadata class family hierarchy pattern
Apply a consistent pattern for the class families in the metadata. Class names match their name in all places (such as Symbol instead of Info, and Type instead of TypeInfo), and the clang namespace is described explicitly to avoid name conflicts. The Javadoc hierarchy for blocks and inlines is also well defined.
1 parent 1fed5e5 commit 6d49549

File tree

328 files changed

+4312
-4351
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

328 files changed

+4312
-4351
lines changed

docs/modules/ROOT/pages/contribute.adoc

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ Common options are defined in `mrdocs/Config.hpp`.
3232
The `Config` class represents all public options that could be defined in a configuration file.
3333
It also provides a representation plugins can use to access public options from the command line or configuration file.
3434

35-
The function `clang::mrdocs::loadConfig` is also provided to parse all public options from a YAML configuration file.
35+
The function `mrdocs::loadConfig` is also provided to parse all public options from a YAML configuration file.
3636

37-
Internally, Mr.Docs uses the derived `clang::mrdocs::ConfigImpl` class (`src/lib/Lib/ConfigImpl.hpp`) to also store the private representation of parsed options, such as filters.
37+
Internally, Mr.Docs uses the derived `mrdocs::ConfigImpl` class (`src/lib/Lib/ConfigImpl.hpp`) to also store the private representation of parsed options, such as filters.
3838

3939
==== Finalizing Options
4040

@@ -53,6 +53,14 @@ MrDocs has many categories of objects, where we utilize polymorphism with a fixe
5353

5454
Each base class is defined in its own header and, when necessary, implementation file. Each derived class also has its own header and implementation file. Finally, there is a single aggregator header file that includes all the derived headers. This file centralizes logic that requires knowledge of the full set of variants, such as visitors, comparison operators, and other operations that depend on the discriminator.
5555

56+
Suppose we have a polymorphic family of `Symbol` objects, with derived types `Function`, `Class`, and `Enum`. The files would be organized as follows:
57+
58+
* The `Symbol/SymbolNodes.inc` file defines the possible derived types and is used to generate code via macros.
59+
* The `Symbol/SymbolKind.hpp` file defines the `SymbolKind` enum, which is used as a discriminator for the derived types.
60+
* The base class `Symbol` is defined in `Symbol/BaseSymbol.hpp` and `Symbol/BaseSymbol.cpp` (if needed).
61+
* The available kinds of derived symbols are defined in `Symbol/<Derived>.hpp` and `Symbol/<Derived>.cpp` files, e.g., `Symbol/Function.hpp` and `Symbol/Function.cpp`.
62+
* The `Symbol.hpp` file includes all derived headers and defines operations that require knowledge of all variants, such as visitors and comparison operators.
63+
5664
This pattern keeps the individual derived types self-contained while making cross-variant operations explicit and localized. When adding a new derived type, contributors should create its header and source file alongside the existing ones and update the corresponding aggregator file to register the new variant. This keeps the codebase predictable, avoids scattering logic, and ensures that operations over polymorphic families remain easy to find and maintain.
5765

5866
[#extract_symbols]
@@ -80,19 +88,18 @@ For each compilation command:
8088
* Paths are normalized
8189
* Non C++ files are filtered
8290

83-
[#info_nodes]
84-
==== Info Nodes
91+
[#symbol_nodes]
92+
==== Symbol Nodes
8593

86-
MrDocs represents each C++ symbol or construct as an `Info` node (`mrdocs/Metadata/Info.hpp`).
87-
`Info` can not only represent direct AST symbols but also {cpp} constructs that need to be inferred from these symbols.
94+
MrDocs represents each C++ symbol or construct as an `Symbol` node (`mrdocs/Metadata/Symbol.hpp`).
95+
`Symbol` can not only represent direct AST symbols but also {cpp} constructs that need to be inferred from these symbols.
8896
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.
8997

90-
When defining a new `Info` type, it is important to consider how this type will be supported in all other modules of the codebase, including the AST visitor, generators, tests, and the documentation.
91-
The script `.github/check_info_nodes_support.sh` will attempt to infer whether most of these features have been implemented for each node type.
98+
When defining a new `Symbol` type, it is important to consider how this type will be supported in all other modules of the codebase, including the AST visitor, generators, tests, and the documentation.
9299

93100
==== Clang LibTooling
94101

95-
MrDocs uses Clang to extract `Info` objects from the {cpp} AST.
102+
MrDocs uses Clang to extract `Symbol` objects from the {cpp} AST.
96103
Clang offers two https://clang.llvm.org/docs/Tooling.html[interfaces] to access the C++ AST: the https://clang.llvm.org/doxygen/group__CINDEX.html[`LibClang`] and https://clang.llvm.org/docs/LibTooling.html[`LibTooling`] libraries.
97104
MrDocs uses the latter, as it provides full control over the AST traversal process at the cost of an unstable API.
98105

@@ -109,7 +116,7 @@ The `clang::tooling::ClangTool::run` method takes a `clang::tooling::ToolAction`
109116
The action object usually comes from a `clang::tooling::FrontendActionFactory`.
110117
In the example above, the `SyntaxOnlyAction` is used to parse the source code and generate the AST without any further processing.
111118

112-
In MrDocs, this process happens in `clang::mrdocs::CorpusImpl::build` (`src/lib/Lib/CorpusImpl.cpp`), where we call `Tool.run` for each object in the database with our custom `ASTAction` action and `ASTActionFactory` factory (`src/lib/AST/ASTVisitor.cpp`).
119+
In MrDocs, this process happens in `mrdocs::CorpusImpl::build` (`src/lib/Lib/CorpusImpl.cpp`), where we call `Tool.run` for each object in the database with our custom `ASTAction` action and `ASTActionFactory` factory (`src/lib/AST/ASTVisitor.cpp`).
113120

114121
==== AST Traversal
115122

@@ -119,7 +126,7 @@ As the AST is generated, it is traversed by the `ASTVisitor` class.
119126
The entry point of this class is `ASTVisitor::build`, which recursively calls `ASTVisitor::traverseDecl` for the root `clang::TranslationUnitDecl` node of the translation unit.
120127
During the AST traversal stage, the complete AST generated by the clang frontend is walked beginning with this root `TranslationUnitDecl` node.
121128

122-
Each `clang` node is converted into a `<<info_nodes,mrdocs::Info>>` node, which is then stored with any relevant information in a `mrdocs::Corpus` object.
129+
Each `clang` node is converted into a `<<symbol_nodes,mrdocs::Symbol>>` node, which is then stored with any relevant information in a `mrdocs::Corpus` object.
123130

124131
==== USR Generation
125132

@@ -132,15 +139,15 @@ This is necessary to generate the full interface for user-defined types.
132139
After running the AST traversal on all translation units, `CorpusImpl::build` contains finalization steps for the `Corpus` object.
133140
At this point, we process C++ constructs that are not directly represented in the AST.
134141

135-
The first finalization step happens in `CorpusImpl::build` (`src/lib/Lib/CorpusImpl.cpp`), where the `Info` objects from a single translation unit
142+
The first finalization step happens in `CorpusImpl::build` (`src/lib/Lib/CorpusImpl.cpp`), where the `Symbol` objects from a single translation unit
136143
are merged into a map containing the merged results from all other TUs.
137144
The merging step is necessary as there may be multiple identical definitions of the same entity.
138145
For instance, this represents the case where a function is declared at different points in the code base and might have different attributes or comments.
139146
At this step, the doc comments are also finalized.
140-
Each `Info` object has a pointer to its `Javadoc` object (`mrdocs/Metadata/Javadoc.hpp`), which is a representation of the documentation comments.
147+
Each `Symbol` object has a pointer to its `Javadoc` object (`mrdocs/Metadata/Javadoc.hpp`), which is a representation of the documentation comments.
141148

142-
After AST traversal and `Info` merging, the result is stored as a map of `Info` objects indexed by their respective `SymbolID`.
143-
A second finalization step is then performed in `clang::mrdocs::finalize`, where any references to `SymbolID` objects that don't exist are removed.
149+
After AST traversal and `Symbol` merging, the result is stored as a map of `Symbol` objects indexed by their respective `SymbolID`.
150+
A second finalization step is then performed in `mrdocs::finalize`, where any references to `SymbolID` objects that don't exist are removed.
144151
This is necessary because the AST traversal will generate references to entities that should be filtered and are not present in the corpus.
145152

146153
At this point, the `Corpus` object contains representations of all entities in the code base and further semantic {cpp} constructs that are not directly represented in the AST can be inferred.
@@ -164,7 +171,7 @@ This directory contains the public headers for the MrDocs library.
164171
* `include/mrdocs/`—The core library headers
165172
** `include/mrdocs/ADT`—Data Structures
166173
** `include/mrdocs/Dom`—The Document Object Model for Abstract Trees
167-
** `include/mrdocs/Metadata`—`Info` nodes and metadata classes
174+
** `include/mrdocs/Metadata`—`Symbol` nodes and metadata classes
168175
** `include/mrdocs/Support`—Various utility classes
169176

170177
==== `src/`—The main source directory
@@ -176,7 +183,7 @@ This directory contains the source code for the MrDocs library and private heade
176183
** `src/lib/Dom/`—The Document Object Model for Abstract Trees
177184
** `src/lib/Gen/`—Generators
178185
** `src/lib/Lib/`—The core library classes
179-
** `src/lib/Metadata/`—`Info` nodes and metadata classes
186+
** `src/lib/Metadata/`—`Symbol` nodes and metadata classes
180187
** `src/lib/Support/`—Various utility classes
181188
* `src/test/`—The test directory
182189
* `src/test_suite/`—The library used for testing

docs/modules/ROOT/pages/generators.adoc

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ Symbol objects that contain information about the location include the following
227227
|Property |Type| Description
228228

229229
| `loc`
230-
| `<<source-info-fields,Source Info Object>>`
230+
| `<<source-info-fields,Source Object>>`
231231
| The location of the symbol in the source code.
232232
|===
233233

@@ -267,15 +267,15 @@ When the symbol kind is `record` (e.g., `class`, `struct`, `union`), the symbol
267267
| Whether the record is a typedef.
268268

269269
| `bases`
270-
| `<<base-info-fields,Base Info Object[]>>`
270+
| `<<base-info-fields,Base Symbol Object[]>>`
271271
| The base classes of the record.
272272

273273
| `interface`
274274
| `<<interface-fields,Interface Object>>`
275275
| The interface of the record.
276276

277277
| `template`
278-
| `<<template-info-fields,Template Info Object>>`
278+
| `<<template-info-fields,Template Object>>`
279279
| The template information of the record.
280280
|===
281281

@@ -285,7 +285,7 @@ When the symbol kind is `enum`, the symbol object has the following additional p
285285
|Property |Type| Description
286286

287287
| `type`
288-
| `<<type-info-fields,Type Info Object>>`
288+
| `<<type-info-fields,Type Object>>`
289289
| The type information of the enum.
290290

291291
| `isScoped`
@@ -383,11 +383,11 @@ When the symbol kind is `function`, the symbol object has the following addition
383383
| The parameters of the function.
384384

385385
| `return`
386-
| `<<type-info-fields,Type Info Object>>`
386+
| `<<type-info-fields,Type Object>>`
387387
| The return type of the function.
388388

389389
| `template`
390-
| `<<template-info-fields,Template Info Object>>`
390+
| `<<template-info-fields,Template Object>>`
391391
| The template information of the function.
392392

393393
| `overloadedOperator`
@@ -417,11 +417,11 @@ When the symbol kind is `typedef`, the symbol object has the following additiona
417417
| Property | Type | Description
418418

419419
| `type`
420-
| `<<type-info-fields,Type Info Object>>`
420+
| `<<type-info-fields,Type Object>>`
421421
| The type information of the typedef.
422422

423423
| `template`
424-
| `<<template-info-fields,Template Info Object>>`
424+
| `<<template-info-fields,Template Object>>`
425425
| The template information of the typedef.
426426

427427
| `isUsing`
@@ -435,11 +435,11 @@ When the symbol kind is `variable`, the symbol object has the following addition
435435
| Property | Type | Description
436436

437437
| `type`
438-
| `<<type-info-fields,Type Info Object>>`
438+
| `<<type-info-fields,Type Object>>`
439439
| The type information of the variable.
440440

441441
| `template`
442-
| `<<template-info-fields,Template Info Object>>`
442+
| `<<template-info-fields,Template Object>>`
443443
| The template information of the variable.
444444

445445
| `storageClass`
@@ -477,7 +477,7 @@ When the symbol kind is `field` (i.e. non-static data members), the symbol objec
477477
| Property | Type | Description
478478

479479
| `type`
480-
| `<<type-info-fields,Type Info Object>>`
480+
| `<<type-info-fields,Type Object>>`
481481
| The type information of the field.
482482

483483
| `default`
@@ -531,7 +531,7 @@ When the symbol kind is `friend`, the symbol object has the following additional
531531
| The friend symbol.
532532

533533
| `type`
534-
| <<type-info-fields,Type Info Object>>
534+
| <<type-info-fields,Type Object>>
535535
| The friend type.
536536
|===
537537

@@ -541,7 +541,7 @@ When the symbol kind is `namespace-alias`, the symbol object has the following a
541541
| Property | Type | Description
542542

543543
| `aliasedSymbol`
544-
| <<name-info-fields,Name Info Object>>
544+
| <<name-info-fields,Name Object>>
545545
| The aliased symbol.
546546
|===
547547

@@ -559,7 +559,7 @@ When the symbol kind is `using`, the symbol object has the following additional
559559
| The symbols being used.
560560

561561
| `qualifier`
562-
| `<<name-info-fields,Name Info Object>>`
562+
| `<<name-info-fields,Name Object>>`
563563
| The qualifier of the using declaration.
564564
|===
565565

@@ -583,11 +583,11 @@ When the symbol kind is `guide`, the symbol object has the following additional
583583
| The parameters of the guide.
584584

585585
| `deduced`
586-
| `<<type-info-fields,Type Info Object>>`
586+
| `<<type-info-fields,Type Object>>`
587587
| The deduced type of the guide.
588588

589589
| `template`
590-
| `<<template-info-fields,Template Info Object>>`
590+
| `<<template-info-fields,Template Object>>`
591591
| The template information of the guide.
592592

593593
| `explicitSpec`
@@ -601,7 +601,7 @@ When the symbol kind is `concept`, the symbol object has the following additiona
601601
| Property | Type | Description
602602

603603
| `template`
604-
| `<<template-info-fields,Template Info Object>>`
604+
| `<<template-info-fields,Template Object>>`
605605
| The template information of the concept.
606606

607607
| `constraint`
@@ -610,9 +610,9 @@ When the symbol kind is `concept`, the symbol object has the following additiona
610610
|===
611611

612612
[#source-info-fields]
613-
=== Source Info Fields
613+
=== Source Fields
614614

615-
The `Source Info` object represents the location of the symbol in the source code.
615+
The `Source` object represents the location of the symbol in the source code.
616616
The source info object has the following properties:
617617

618618
|===
@@ -697,14 +697,14 @@ The base info object has the following properties:
697697
| Whether the base class is virtual.
698698

699699
| `type`
700-
| `<<type-info-fields,Type Info Object>>`
700+
| `<<type-info-fields,Type Object>>`
701701
| The type information of the base class.
702702
|===
703703

704704
[#template-info-fields]
705-
=== Template Info Fields
705+
=== Template Fields
706706

707-
The `Template Info` object represents the template information of a record, function, or typedef.
707+
The `Template` object represents the template information of a record, function, or typedef.
708708
The template info object has the following properties:
709709

710710
|===
@@ -723,7 +723,7 @@ The template info object has the following properties:
723723
| The template parameters.
724724

725725
| `args`
726-
| `<<targ-fields,Type Info Object[]>>`
726+
| `<<targ-fields,Type Object[]>>`
727727
| The template arguments.
728728

729729
| `requires`
@@ -732,9 +732,9 @@ The template info object has the following properties:
732732
|===
733733

734734
[#type-info-fields]
735-
=== Type Info Fields
735+
=== Type Fields
736736

737-
The `Type Info` object represents the type information of a symbol.
737+
The `Type` object represents the type information of a symbol.
738738
The type info object has the following properties:
739739

740740
|===
@@ -769,15 +769,15 @@ The type info object has the following properties:
769769
| The cv qualifier of the type (e.g., `const`, `volatile`).
770770

771771
| `parent-type`
772-
| `<<type-info-fields,Type Info Object>>`
772+
| `<<type-info-fields,Type Object>>`
773773
| The parent type of the type.
774774

775775
| `pointee-type`
776-
| `<<type-info-fields,Type Info Object>>`
776+
| `<<type-info-fields,Type Object>>`
777777
| The pointee type of the type.
778778

779779
| `element-type`
780-
| `<<type-info-fields,Type Info Object>>`
780+
| `<<type-info-fields,Type Object>>`
781781
| The element type of the type.
782782

783783
| `bounds-value`
@@ -789,11 +789,11 @@ The type info object has the following properties:
789789
| The bounds expression of the type.
790790

791791
| `return-type`
792-
| `<<type-info-fields,Type Info Object>>`
792+
| `<<type-info-fields,Type Object>>`
793793
| The return type of the type.
794794

795795
| `param-types`
796-
| `<<type-info-fields,Type Info Object[]>>`
796+
| `<<type-info-fields,Type Object[]>>`
797797
| The parameter types of the type.
798798

799799
| `exception-spec`
@@ -823,7 +823,7 @@ The param object has the following properties:
823823
| The name of the parameter.
824824

825825
| `type`
826-
| `<<type-info-fields,Type Info Object>>`
826+
| `<<type-info-fields,Type Object>>`
827827
| The type information of the parameter.
828828

829829
| `default`
@@ -832,9 +832,9 @@ The param object has the following properties:
832832
|===
833833

834834
[#name-info-fields]
835-
=== Name Info Fields
835+
=== Name Fields
836836

837-
The `Name Info` object represents the name of a symbol.
837+
The `Name` object represents the name of a symbol.
838838
The name info object has the following properties:
839839

840840
|===
@@ -849,7 +849,7 @@ The name info object has the following properties:
849849
| The unique identifier of the symbol.
850850

851851
| `args`
852-
| `<<targ-fields,Type Info Object[]>>`
852+
| `<<targ-fields,Type Object[]>>`
853853
| The template arguments of the symbol.
854854

855855
| `prefix`
@@ -921,7 +921,7 @@ The tparam object has the following properties:
921921
| The constraint of the template parameter.
922922

923923
| `type`
924-
| `<<type-info-fields,Type Info Object>>`
924+
| `<<type-info-fields,Type Object>>`
925925
| The type information of the template parameter.
926926

927927
| `params`
@@ -947,7 +947,7 @@ The targ object has the following properties:
947947
| Whether the template argument is a pack expansion.
948948

949949
| `type`
950-
| `<<type-info-fields,Type Info Object>>`
950+
| `<<type-info-fields,Type Object>>`
951951
| The type information of the template argument.
952952

953953
| `value`
@@ -959,7 +959,7 @@ The targ object has the following properties:
959959
| The name of the template argument.
960960

961961
| `template`
962-
| `<<template-info-fields,Template Info Object>>`
962+
| `<<template-info-fields,Template Object>>`
963963
| The template information of the template argument.
964964
|===
965965

0 commit comments

Comments
 (0)