use crate::checker::{csharp_is_aliased_modifier, csharp_member_has_accessors};
use crate::getter::node_text;
use crate::lang_helpers::case_arms::{
csharp_case_token_is_switch_arm, csharp_switch_expression_arm_is_bare_discard,
};
use crate::lang_helpers::doc_comment::csharp_doc;
use crate::role_table;
use crate::roles::control_flow::else_if_prev_sibling_gate;
use crate::{Ancestors, Csharp, Node};
fn has_no_accessors(node: &Node<'_>, _code: &[u8]) -> bool {
!csharp_member_has_accessors(node)
}
fn aliases_a_modifier_keyword(node: &Node<'_>, code: &[u8]) -> bool {
csharp_is_aliased_modifier(node)
&& matches!(
node_text(code, node),
Some("ref" | "out" | "in" | "scoped" | "readonly" | "static" | "async")
)
}
fn is_decision_arm<'a>(node: &Node<'a>, _code: &[u8], _ancestors: Ancestors<'a, '_>) -> bool {
!csharp_switch_expression_arm_is_bare_discard(node)
}
fn is_switch_arm_case<'a>(node: &Node<'a>, _code: &[u8], ancestors: Ancestors<'a, '_>) -> bool {
csharp_case_token_is_switch_arm(node, ancestors)
}
else_if_prev_sibling_gate!(Csharp, Else);
crate::roles::byte_gate!(opens_with_xml_doc_marker, csharp_doc);
role_table! {
lang: Csharp;
Call { owns [InvocationExpression, InvocationExpression2, InvocationExpression3] }
StringLit {
owns [StringLiteral, VerbatimStringLiteral, RawStringLiteral, InterpolatedStringExpression]
wraps [Interpolation]
}
Comparison {
owns [
BinaryExpression(holds_payer),
BinaryExpression2(holds_payer),
IsExpression, IsPatternExpression,
]
pays [
EQEQ under [BinaryExpression, BinaryExpression2], BANGEQ under [BinaryExpression, BinaryExpression2],
LTEQ under [BinaryExpression, BinaryExpression2], GTEQ under [BinaryExpression, BinaryExpression2],
LT under [BinaryExpression, BinaryExpression2], GT under [BinaryExpression, BinaryExpression2],
Is under [IsExpression, IsPatternExpression],
]
project "operator"
}
ShortCircuit {
owns [
BinaryExpression(holds_payer),
BinaryExpression2(holds_payer),
]
pays [AMPAMP, PIPEPIPE]
project "operator"
}
EagerLogical {
owns []
excludes [
AMP "a boolean `&` is the integral `&`'s kind, which the grammar does not tell apart",
PIPE "a boolean `|` is the integral `|`'s kind, which the grammar does not tell apart",
CARET "a boolean `^` is the integral `^`'s kind, which the grammar does not tell apart",
]
}
Ternary {
owns [ConditionalExpression]
pays [QMARK under ConditionalExpression]
project "operator"
}
NullSafe {
owns [
BinaryExpression(holds_payer),
BinaryExpression2(holds_payer),
ConditionalAccessExpression(pays_itself),
]
pays [QMARKQMARK]
project "operator"
excludes [QMARKQMARKEQ "the compound `??=`, an assignment ABC pays as one and a decision cyclomatic pays as its own (#236)"]
}
CaseArm {
owns [
SwitchSection(holds_payer),
SwitchExpressionArm(pays_itself gated_by is_decision_arm),
]
pays [Case gated_by is_switch_arm_case]
excludes [Default "the fallback label, no decision (lesson 11, #469); `goto default;` spells it too"]
}
Guard {
owns [WhenClause, CatchFilterClause]
excludes [When "also a reserved identifier at this pin: `int when = 1;` spells it"]
}
Branch { owns [IfStatement] }
Switch { owns [SwitchStatement, SwitchExpression] }
Loop { owns [ForStatement, ForeachStatement, WhileStatement, DoStatement] }
Catch { owns [CatchClause] }
ElseIf { owns [IfStatement(gated_by follows_else_keyword)] pays [] }
Exit { owns [ReturnStatement, YieldStatement, ThrowStatement, ThrowExpression] }
Modifier {
owns [
Public, Private, Protected, Internal, Static, Abstract, Virtual, Override, Sealed,
Partial, Readonly, Const, Extern, Unsafe, Volatile, Async, Required, File, Fixed,
Implicit, Explicit, Modifier(text_gated_by aliases_a_modifier_keyword no_chain),
]
}
DeclKeyword { owns [Class, Struct, Interface, Enum, Record, Delegate, Namespace, Using] }
Primitive {
owns [PredefinedType]
excludes [Var "`var` names no type; its `implicit_type` wrapper bills nothing"]
}
FuncOpener {
owns [
MethodDeclaration(callable opens Function),
ConstructorDeclaration(callable opens Function),
DestructorDeclaration(callable opens Function),
LocalFunctionStatement(callable opens Function),
AccessorDeclaration(callable opens Function),
OperatorDeclaration(callable opens Function),
ConversionOperatorDeclaration(callable opens Function),
IndexerDeclaration(callable opens Function gated_by has_no_accessors no_chain),
PropertyDeclaration(callable opens Function gated_by has_no_accessors no_chain),
LambdaExpression(opens Function),
AnonymousMethodExpression(opens Function),
]
}
Closure { owns [LambdaExpression, AnonymousMethodExpression] }
Container {
owns [
CompilationUnit(opens Unit),
ClassDeclaration(opens Class),
StructDeclaration(opens Class),
RecordDeclaration(opens Class),
EnumDeclaration(opens Class),
InterfaceDeclaration(opens Interface),
]
}
Member { owns [FieldDeclaration] }
Comment { owns [Comment] }
DocComment { owns [Comment(text_gated_by opens_with_xml_doc_marker no_chain)] }
Docstring { absent "C# documents with `///` comments, not string literals" }
DocTarget {
owns [
ClassDeclaration,
StructDeclaration,
RecordDeclaration,
InterfaceDeclaration,
EnumDeclaration,
DelegateDeclaration,
MethodDeclaration,
ConstructorDeclaration,
DestructorDeclaration,
OperatorDeclaration,
ConversionOperatorDeclaration,
FieldDeclaration,
EventFieldDeclaration,
EventDeclaration,
PropertyDeclaration,
IndexerDeclaration,
EnumMemberDeclaration,
]
}
DocRunOpener { absent "Roslyn attaches every doc comment to a member; none documents by its own content" }
DocRunDirective { absent "Roslyn reads no directive comment" }
DocBodyResidual { owns [IndexerDeclaration, PropertyDeclaration] }
}