big_code_analysis_ast/roles/mozcpp.rs
1//! Mozcpp's role rows. The dialect owns no file extension and shares
2//! Cpp's grammar shape with different kind ids, so its rows splice the
3//! same `cpp_family_*` fragments Cpp's do (`roles/c_family.rs`,
4//! contract 5 of #1690): the paying-construct rows (#1694, #1695), the
5//! space tree (#1696) and the control flow (#1697) are declared through
6//! them, the Halstead keyword rows are declared (#1693) and the rest
7//! are pending or absent as Cpp's are.
8//! Nothing routes a file to this dialect, so no corpus snapshot reaches
9//! these rows; `tests/parity/cpp_mozcpp_parity.rs` holds the two
10//! dialects together.
11
12use crate::Mozcpp;
13use crate::role_table;
14use crate::roles::c_family::{
15 c_family_calls, c_family_conditional_kinds, c_family_decl_keywords, c_family_doc_conditionals,
16 c_family_doc_entries, c_family_doc_gates, c_family_modifiers, c_family_primitives,
17 c_family_strings, cpp_doc_entries, cpp_family_binary_owners, cpp_family_comparison_payers,
18 cpp_family_containers, cpp_family_exits, cpp_family_func_openers, cpp_family_gates,
19 cpp_family_loops, cpp_family_short_circuit_payers,
20};
21use crate::roles::control_flow::else_if_parent_clause_gate;
22
23// The documentation gates, per dialect (#1699).
24c_family_doc_gates!(MozcppCode);
25// The `DocTarget` row's conditional owners as a kind test (#1795).
26c_family_conditional_kinds!(Mozcpp);
27
28cpp_family_gates!(Mozcpp);
29// The chained `if` sits directly inside an `else_clause`; a nested one
30// under `else { … }` sits inside the compound statement (#1697).
31else_if_parent_clause_gate!(Mozcpp, ElseClause);
32
33role_table! {
34 lang: Mozcpp;
35 Call { owns [..c_family_calls!()] }
36 // `R"(…)"` joins the family's two: it is one string-like token to
37 // `find` and the dump (#398, the peer of #391 for Rust).
38 StringLit { owns [..c_family_strings!(), RawStringLiteral] }
39 // The C++ binary operators are one `binary_expression` kind (the
40 // aliased `BinaryExpression2` at the pinned grammar; the unsuffixed
41 // id is the never-emitted pre-alias) plus the fold, told apart by
42 // the `operator` field, so each row's owners are gated on that
43 // field holding one of its payers and each payer on applying its
44 // operator (`roles/c_family.rs` has both lists and their
45 // derivations — #1448, #1522, #1525, #1533). A `requires` clause or
46 // expression is compile-time and its operators decide nothing; the
47 // rows do not know that, because a parenthesised constraint parses
48 // as an ordinary `binary_expression` and only the root crate's
49 // `ConstraintReach` can see the clause above it. The consumers read
50 // the rows *under* that reach.
51 Comparison {
52 owns [..cpp_family_binary_owners!()]
53 pays [..cpp_family_comparison_payers!()]
54 project "operator"
55 }
56 ShortCircuit {
57 owns [..cpp_family_binary_owners!()]
58 pays [..cpp_family_short_circuit_payers!()]
59 project "operator"
60 }
61 EagerLogical { absent "C++'s `&` / `|` / `^` are bitwise; `and` / `or` are the lazy spellings" }
62 // The `conditional_expression` owns the ternary and its `?` pays,
63 // ungated: the grammar spells a bare `?` in no other production. The
64 // GNU elision `a ?: b` is the same node with its `consequence` field
65 // empty, which the ABC slot walker reads by field (#1102).
66 Ternary {
67 owns [ConditionalExpression]
68 pays [QMARK]
69 project "operator"
70 }
71 NullSafe { absent "C++ has no optional navigation or null coalescing" }
72 // A `case_statement` is the grammar's node for a `case X:` label
73 // and a `default:` label alike; the arm owns a decision when it
74 // holds the `case` keyword, which pays — one per label, so a
75 // fall-through run `case 2: case 3:` is two. The `default` keyword
76 // is the fallback and pays nothing (lesson 11, #469); Halstead
77 // bills it as the keyword it is through the byte-less arm.
78 CaseArm {
79 owns [CaseStatement(holds_payer)]
80 pays [Case]
81 excludes [Default "the fallback label, no decision (lesson 11, #469)"]
82 }
83 Guard { absent "C++ has no guard clause on a case or a function head" }
84 // The C family's control flow (#1697): the one-kind rows are spelled
85 // inline, the loop and exit lists are the two C++ grammars' own
86 // fragments (`cpp_family_loops!`, `cpp_family_exits!` in
87 // `roles/c_family.rs`), so this is Cpp's table under other ids. The
88 // `ElseIf` gate is emitted beside this table. `Catch` pays at the `catch`
89 // keyword, which is where this dialect differs from ObjC.
90 Branch { owns [IfStatement] pays [If] }
91 Switch { owns [SwitchStatement] }
92 Loop { owns [..cpp_family_loops!()] pays [For, While] }
93 Catch { owns [CatchClause] pays [Catch] }
94 ElseIf { owns [IfStatement(gated_by continues_else_clause)] pays [] }
95 Exit { owns [..cpp_family_exits!()] }
96 // Cpp's three keyword rows, verbatim. The dialect shares Cpp's
97 // grammar shape and owns no file extension, so nothing routes to it
98 // and no corpus snapshot reaches these rows;
99 // `tests/parity/cpp_mozcpp_parity.rs` holds the two vocabularies
100 // together. The derivations are on the Cpp rows.
101 Modifier {
102 owns [
103 ..c_family_modifiers!(),
104 Virtual, Mutable, Constinit, Consteval, Explicit, Friend, Public, Private,
105 Protected, Override, Final, Noexcept2,
106 ]
107 }
108 DeclKeyword { owns [..c_family_decl_keywords!(), Class, Namespace, Template, Typename, Using] }
109 Primitive { owns [..c_family_primitives!()] }
110 // The shared C++ openers and containers (`roles/c_family.rs`); the
111 // lambda is a closure that opens no space.
112 FuncOpener { owns [..cpp_family_func_openers!()] }
113 Closure { owns [LambdaExpression] }
114 Container { owns [..cpp_family_containers!()] }
115 // A `field_declaration` in a class body — a data member, or a
116 // bodiless member function the method consumer tells apart by its
117 // declarator (#1300). Which it is, and the access section it sits
118 // in, is the consumers' reading.
119 Member { owns [FieldDeclaration] }
120 // The one comment kind, a `DocComment` owner under Doxygen's marker
121 // gate (#1699).
122 Comment { owns [Comment] }
123 DocComment { owns [Comment(text_gated_by opens_with_doxygen_marker no_chain)] }
124 Docstring { absent "C++ documents with comments, not string literals" }
125 // What Doxygen documents from a doc block before it: the entries of
126 // `roles/c_family.rs`'s fragment, and every
127 // preprocessor conditional holding an entry in any branch
128 // (`conditional_declares`, memoised). The `ERROR` node holding an
129 // entry is the Checker's clause. Most targets are outside the
130 // space-tree rows — a macro, a typedef, an enumerator, a field, a
131 // conditional — the parity exceptions `roles/doc_tests/parity.rs` records.
132 DocTarget {
133 owns [
134 ..c_family_doc_entries!(),
135 ..cpp_doc_entries!(),
136 ..c_family_doc_conditionals!(),
137 ]
138 }
139 DocRunOpener { absent "Doxygen attaches every block to an entry or the file; none documents by its own content" }
140 DocRunDirective { absent "Doxygen reads no directive comment" }
141 DocBodyResidual { absent "Doxygen reads every block in a body as the function's in-body description; nothing withholds one" }
142}