Skip to content

Commit d39901c

Browse files
committed
Clippy fix and add CI workflows
1 parent f786255 commit d39901c

13 files changed

Lines changed: 84 additions & 28 deletions

File tree

.github/workflows/tests.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,9 @@ jobs:
5757
- name: Ensure correct dependency resolution
5858
run: |
5959
bazel mod deps --lockfile_mode=update
60+
- name: Run Libclang Parser Tooling clippy
61+
run: |
62+
bazel build //cpp/libclang/... --config=clippy
63+
- name: Run Libclang Parser Tooling tests
64+
run: |
65+
bazel test //cpp/libclang/...

cpp/libclang/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
<!-- ----------------------------------------------------------------------------
2+
Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
4+
See the NOTICE file(s) distributed with this work for additional
5+
information regarding copyright ownership.
6+
7+
This program and the accompanying materials are made available under the
8+
terms of the Apache License Version 2.0 which is available at
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
SPDX-License-Identifier: Apache-2.0
12+
----------------------------------------------------------------------------- -->
13+
114
# Run C++ parser targets
215

316
## Configure a parser target in `BUILD`

cpp/libclang/integration_test/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
<!-- ----------------------------------------------------------------------------
2+
Copyright (c) 2026 Contributors to the Eclipse Foundation
3+
4+
See the NOTICE file(s) distributed with this work for additional
5+
information regarding copyright ownership.
6+
7+
This program and the accompanying materials are made available under the
8+
terms of the Apache License Version 2.0 which is available at
9+
https://www.apache.org/licenses/LICENSE-2.0
10+
11+
SPDX-License-Identifier: Apache-2.0
12+
----------------------------------------------------------------------------- -->
13+
114
# libclang Integration Tests
215

316
This directory contains integration tests for the C++ libclang parser and related tooling.

cpp/libclang/src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct Args {
4949

5050
fn parse_file(
5151
file: &PathBuf,
52-
compilation_flags: &Vec<String>,
52+
compilation_flags: &[String],
5353
index: &clang::Index,
5454
ast_file_output_path: &PathBuf,
5555
all_classes: &mut BTreeMap<String, context::TypeMapValue>,
@@ -64,7 +64,7 @@ fn parse_file(
6464
}
6565
};
6666

67-
let parse_result = index.parser(&file).arguments(&compilation_flags).parse();
67+
let parse_result = index.parser(file).arguments(compilation_flags).parse();
6868

6969
match parse_result {
7070
Ok(parsed) => {
@@ -76,7 +76,7 @@ fn parse_file(
7676
}
7777

7878
let entity = parsed.get_entity();
79-
print_entity(&entity, 0, PrintMode::File(&ast_file_output_path));
79+
print_entity(&entity, 0, PrintMode::File(ast_file_output_path));
8080
print_entity(&entity, 0, PrintMode::Stdout);
8181

8282
let mut ctx = VisitContext::default();
@@ -139,8 +139,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
139139
let compilation_flags = &command_line_args.extra_args;
140140

141141
parse_file(
142-
&file,
143-
&compilation_flags,
142+
file,
143+
compilation_flags,
144144
&index,
145145
&ast_file_output_path,
146146
&mut all_classes,

cpp/libclang/src/visitor/src/class_parser_helper.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//
1111
// SPDX-License-Identifier: Apache-2.0
1212
////////////////////////////////////////////////////////////////////////////////////
13+
#![cfg_attr(test, allow(dead_code))]
14+
1315
use clang::{Entity, EntityKind, Type, TypeKind};
1416
use serde::{Deserialize, Serialize};
1517

@@ -450,7 +452,7 @@ fn resolve_unqualified_type(original: &Type, canonical: &Type) -> ResolvedType {
450452

451453
ResolvedType::Array {
452454
element: Box::new(element),
453-
size: original.get_size().map(|s| s as usize),
455+
size: original.get_size(),
454456
}
455457
}
456458

@@ -624,7 +626,7 @@ fn build_fqn_from_entity(entity: &Entity) -> String {
624626
// Traversal is semantic (not lexical) so aliases/nested constructs resolve to
625627
// stable ownership hierarchy used by relationship and id matching.
626628
let mut parts: Vec<(String, bool)> = Vec::new();
627-
let mut current = Some(entity.clone());
629+
let mut current = Some(*entity);
628630

629631
while let Some(entity) = current {
630632
match entity.get_kind() {

cpp/libclang/src/visitor/src/class_visitor.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl ClassVisitor {
7474
};
7575

7676
let mut class_entity = SimpleEntity {
77-
id: id,
77+
id,
7878
name: name.clone(),
7979
enclosing_namespace_id: namespace.map(|ns| ns.to_string()),
8080
..Default::default()
@@ -153,12 +153,8 @@ fn parse_source_location(entity: &Entity) -> (Option<String>, Option<u32>) {
153153
}
154154

155155
fn collect_variable_type(entity: &Entity) -> Option<ParsedVariableType> {
156-
let Some(name) = entity.get_name() else {
157-
return None;
158-
};
159-
let Some(field_type) = entity.get_type() else {
160-
return None;
161-
};
156+
let name = entity.get_name()?;
157+
let field_type = entity.get_type()?;
162158

163159
Some(ParsedVariableType {
164160
name,

cpp/libclang/src/visitor/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};
1414
use std::collections::HashMap;
1515

1616
pub use class_diagram::SimpleEntity;
17-
use sequence_diagram::FunctionDef;
17+
use sequence_logic::FunctionDef;
1818

1919
use crate::class_parser_helper::ResolvedType;
2020

cpp/libclang/src/visitor/src/enum_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl EnumVisitor {
3636
};
3737
Some(SimpleEntity {
3838
id: full_qualified_id,
39-
name: name,
39+
name,
4040
enclosing_namespace_id: namespace_id,
4141
entity_type: EntityType::Enum,
4242
enum_literals: get_literals(entity),

cpp/libclang/src/visitor/src/function_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
use crate::{context::VisitContext, AstVisitor};
2020
use clang::{Entity, EntityKind};
21-
use sequence_diagram::{BodyItem, FunctionDef};
21+
use sequence_logic::{BodyItem, FunctionDef};
2222

2323
pub struct FunctionVisitor;
2424

cpp/libclang/src/visitor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ pub use class_visitor::ClassVisitor;
2222
pub use context::VisitContext;
2323
pub use enum_visitor::EnumVisitor;
2424
pub use function_visitor::FunctionVisitor;
25-
pub use sequence_diagram::{BodyItem, FunctionDef};
25+
pub use sequence_logic::{BodyItem, FunctionDef};
2626
pub use visitor::AstVisitor;
2727
pub use visitor::Visitor;

0 commit comments

Comments
 (0)