1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! `Checker` implementation for C.
#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]
use super::*;
impl Checker for CCode {
fn is_comment(node: &Node) -> bool {
node.kind_id() == C::Comment
}
fn is_useful_comment(node: &Node, code: &[u8]) -> bool {
get_aho_corasick_match(&code[node.start_byte()..node.end_byte()])
}
// C has no classes/namespaces and no methods, so the only code
// spaces are the translation unit and function definitions. Struct /
// union / enum specifiers hold no functions in C, so — unlike the
// C++ checker — they are deliberately NOT spaces (including them
// would create empty FuncSpaces for every aggregate type).
// `FunctionDefinition2` is the grammar's `function_definition` alias
// (kind_id 197); enumerate it alongside the primary so neither is
// silently dropped from FuncSpace creation (#285, lesson 2).
fn is_func_space(node: &Node) -> bool {
matches!(
node.kind_id().into(),
C::TranslationUnit | C::FunctionDefinition | C::FunctionDefinition2
)
}
// Keep in sync with `is_func_space` and the C getters (#285).
fn is_func(node: &Node) -> bool {
matches!(
node.kind_id().into(),
C::FunctionDefinition | C::FunctionDefinition2
)
}
// C has no closures/lambdas.
fn is_closure(_node: &Node) -> bool {
false
}
fn is_call(node: &Node) -> bool {
node.kind_id() == C::CallExpression
}
fn is_non_arg(node: &Node) -> bool {
matches!(node.kind_id().into(), C::LPAREN | C::COMMA | C::RPAREN)
}
// C has no raw string literals.
impl_simple_is_string!(C, StringLiteral, ConcatenatedString);
impl_is_else_if_parent_clause!(C, IfStatement, ElseClause);
#[inline]
fn is_primitive(node: &Node) -> bool {
node.kind_id() == C::PrimitiveType
}
}