Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test")

cc_library(
name = "std_internal_namespace_rendering",
srcs = ["transport.cpp"],
visibility = ["//cpp/libclang:__subpackages__"],
)

cpp_parser_integration_test(
name = "test_std_internal_namespace_rendering",
expected_output = ["expected.json"],
target = ":std_internal_namespace_rendering",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"functions": [],
"types": {
"TextCache": {
"enclosing_namespace_id": null,
"entity_type": "Class",
"enum_literals": [],
"id": "TextCache",
"methods": [
{
"modifiers": [],
"name": "Find",
"parameters": [
{
"is_variadic": false,
"name": "key",
"param_type": "const std::string &"
}
],
"return_type": "std::string_view",
"source_location": {
"file": "cpp/libclang/integration_test/cases/std_internal_namespace_rendering/transport.cpp",
"line": 20
},
"template_parameters": null,
"visibility": "public"
}
],
"name": "TextCache",
"relationships": [],
"source_location": {
"file": "cpp/libclang/integration_test/cases/std_internal_namespace_rendering/transport.cpp",
"line": 17
},
"template_parameters": null,
"type_aliases": [],
"variables": [
{
"data_type": "std::string",
"is_static": false,
"name": "name_",
"source_location": {
"file": "cpp/libclang/integration_test/cases/std_internal_namespace_rendering/transport.cpp",
"line": 23
},
"visibility": "private"
},
{
"data_type": "std::unordered_map<std::string, std::string_view>",
"is_static": false,
"name": "cache_",
"source_location": {
"file": "cpp/libclang/integration_test/cases/std_internal_namespace_rendering/transport.cpp",
"line": 24
},
"visibility": "private"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// *******************************************************************************
// Copyright (c) 2026 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache License Version 2.0 which is available at
// <https://www.apache.org/licenses/LICENSE-2.0>
//
// SPDX-License-Identifier: Apache-2.0
// *******************************************************************************

use test_framework::run_parser_case;

#[test]
fn test_std_internal_namespace_rendering() {
run_parser_case();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/********************************************************************************
* Copyright (c) 2026 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#include <string>
#include <string_view>
#include <unordered_map>

class TextCache
{
public:
std::string_view Find(const std::string& key);

private:
std::string name_;
std::unordered_map<std::string, std::string_view> cache_;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# *******************************************************************************
# Copyright (c) 2026 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License Version 2.0 which is available at
# https://www.apache.org/licenses/LICENSE-2.0
#
# SPDX-License-Identifier: Apache-2.0
# *******************************************************************************
load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test")

cc_library(
name = "std_template_specialization_filter",
srcs = ["specialization.cpp"],
hdrs = ["specialization.h"],
visibility = ["//cpp/libclang:__subpackages__"],
)

cpp_parser_integration_test(
name = "test_std_template_specialization_filter",
expected_output = ["expected.json"],
target = ":std_template_specialization_filter",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"functions": [],
"types": {
"demo::Key": {
"enclosing_namespace_id": "demo",
"entity_type": "Struct",
"enum_literals": [],
"id": "demo::Key",
"methods": [],
"name": "Key",
"relationships": [],
"source_location": {
"file": "./cpp/libclang/integration_test/cases/std_template_specialization_filter/specialization.h",
"line": 23
},
"template_parameters": null,
"type_aliases": [],
"variables": [
{
"data_type": "std::uint32_t",
"is_static": false,
"name": "value",
"source_location": {
"file": "./cpp/libclang/integration_test/cases/std_template_specialization_filter/specialization.h",
"line": 25
},
"visibility": "public"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// *******************************************************************************
// Copyright (c) 2026 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache License Version 2.0 which is available at
// <https://www.apache.org/licenses/LICENSE-2.0>
//
// SPDX-License-Identifier: Apache-2.0
// *******************************************************************************

use test_framework::run_parser_case;

#[test]
fn test_std_template_specialization_filter() {
run_parser_case();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/********************************************************************************
* Copyright (c) 2026 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#include "cpp/libclang/integration_test/cases/std_template_specialization_filter/specialization.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/********************************************************************************
* Copyright (c) 2026 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
#ifndef CPP_LIBCLANG_INTEGRATION_TEST_CASES_STD_TEMPLATE_SPECIALIZATION_FILTER_SPECIALIZATION_H
#define CPP_LIBCLANG_INTEGRATION_TEST_CASES_STD_TEMPLATE_SPECIALIZATION_FILTER_SPECIALIZATION_H

#include <cstddef>
#include <cstdint>
#include <functional>

namespace demo
{

struct Key
{
std::uint32_t value;
};

} // namespace demo

namespace std
{

template <>
struct hash<demo::Key>
{
std::size_t operator()(const demo::Key& key) const noexcept
{
return std::hash<std::uint32_t>{}(key.value);
}
};

} // namespace std

#endif
5 changes: 2 additions & 3 deletions cpp/libclang/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ use class_diagram::{ClassDiagram, SimpleEntity};
use class_serializer::ClassSerializer;

use utils::{render_entity_tree, write_debug_json, write_entity_tree, write_fbs_output};
use visit_tu::visitor;
use visit_tu::{FunctionDef, VisitContext, Visitor};
use visit_tu::{is_external_dependency_path, FunctionDef, VisitContext, Visitor};

#[derive(ClapParser, Debug)]
#[command(name = "cpp_parser")]
Expand Down Expand Up @@ -120,7 +119,7 @@ fn parse_file(
debug!("Parsing TU: {:?}", file);

if let Some(path_str) = file.to_str() {
if visitor::is_external_dependency_path(path_str) {
if is_external_dependency_path(path_str) {
debug!("Skipping external dependency file: {:?}", file);
return;
}
Expand Down
2 changes: 2 additions & 0 deletions cpp/libclang/src/visitor/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ rust_library(
"src/enum_visitor.rs",
"src/function_visitor.rs",
"src/lib.rs",
"src/source_filter.rs",
"src/visitor.rs",
],
visibility = ["//cpp/libclang:__subpackages__"],
Expand All @@ -38,6 +39,7 @@ rust_test(
srcs = [
"src/class_parser_helper.rs",
"src/class_parser_helper_test.rs",
"src/source_filter.rs",
],
deps = [
"@crates//:clang",
Expand Down
18 changes: 2 additions & 16 deletions cpp/libclang/src/visitor/src/class_parser_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#![cfg_attr(test, allow(dead_code))]

use crate::source_filter;
use clang::{Entity, EntityKind, Type, TypeKind};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -306,26 +307,11 @@ fn is_declared_in_external_or_system_header(ty: &Type) -> bool {
.and_then(|decl| decl.get_location())
.map(|location| {
let (path, _, _) = location.get_presumed_location();
is_external_or_system_path(&path)
source_filter::is_external_or_system_path(&path)
})
.unwrap_or(false)
}

fn is_external_or_system_path(path: &str) -> bool {
is_system_header_path(path)
|| path.contains("/external/")
|| path.contains("external/")
|| path.contains("_virtual_includes/")
|| (path.contains("bazel-out/") && path.contains("/external/"))
}

fn is_system_header_path(path: &str) -> bool {
path.starts_with("/usr/include")
|| path.starts_with("/usr/local/include")
|| path.starts_with("/opt/")
|| path.contains("/gcc/")
}

fn contains_template_type(resolved: &ResolvedType) -> bool {
match resolved {
ResolvedType::Template { .. } => true,
Expand Down
2 changes: 2 additions & 0 deletions cpp/libclang/src/visitor/src/class_parser_helper_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#[path = "class_parser_helper.rs"]
mod class_parser_helper;
#[path = "source_filter.rs"]
mod source_filter;

use class_parser_helper::{collapse_std_internal_namespaces, ResolvedType};

Expand Down
2 changes: 2 additions & 0 deletions cpp/libclang/src/visitor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod class_visitor;
pub mod context;
mod enum_visitor;
mod function_visitor;
mod source_filter;
pub mod visitor;

pub use class_parser_helper::ResolvedType;
Expand All @@ -24,5 +25,6 @@ pub use context::VisitContext;
pub use enum_visitor::EnumVisitor;
pub use function_visitor::FunctionVisitor;
pub use sequence_logic::{BodyItem, FunctionDef};
pub use source_filter::is_external_dependency_path;
pub use visitor::AstVisitor;
pub use visitor::Visitor;
Loading
Loading