Skip to content
Closed
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,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 = "parameter_adjustment_dedup",
srcs = ["functions.cpp"],
hdrs = ["functions.hpp"],
visibility = ["//cpp/libclang:__subpackages__"],
)

cpp_parser_integration_test(
name = "test_parameter_adjustment_dedup",
expected_output = ["expected.json"],
target = ":parameter_adjustment_dedup",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
{
"free_function_declarations": [
{
"name": "alias_fn",
"enclosing_namespace_id": null,
"return_type": "void",
"parameters": [
{
"name": "",
"param_type": "MyInt",
"is_variadic": false
}
],
"template_parameters": null,
"source_location": {
"file": "cpp/libclang/integration_test/function_cases/parameter_adjustment_dedup/functions.hpp",
"line": 19
}
},
{
"name": "typedef_fn",
"enclosing_namespace_id": null,
"return_type": "void",
"parameters": [
{
"name": "",
"param_type": "OldInt",
"is_variadic": false
}
],
"template_parameters": null,
"source_location": {
"file": "cpp/libclang/integration_test/function_cases/parameter_adjustment_dedup/functions.hpp",
"line": 20
}
},
{
"name": "arr_fn",
"enclosing_namespace_id": null,
"return_type": "void",
"parameters": [
{
"name": "",
"param_type": "int[5]",
"is_variadic": false
}
],
"template_parameters": null,
"source_location": {
"file": "cpp/libclang/integration_test/function_cases/parameter_adjustment_dedup/functions.hpp",
"line": 21
}
},
{
"name": "incomplete_arr_fn",
"enclosing_namespace_id": null,
"return_type": "void",
"parameters": [
{
"name": "",
"param_type": "int[]",
"is_variadic": false
}
],
"template_parameters": null,
"source_location": {
"file": "cpp/libclang/integration_test/function_cases/parameter_adjustment_dedup/functions.hpp",
"line": 22
}
},
{
"name": "callback_fn",
"enclosing_namespace_id": null,
"return_type": "void",
"parameters": [
{
"name": "callback",
"param_type": "void (int)",
"is_variadic": false
}
],
"template_parameters": null,
"source_location": {
"file": "cpp/libclang/integration_test/function_cases/parameter_adjustment_dedup/functions.hpp",
"line": 23
}
},
{
"name": "callback_noexcept_identity",
"enclosing_namespace_id": null,
"return_type": "void",
"parameters": [
{
"name": "",
"param_type": "void (*)()",
"is_variadic": false
}
],
"template_parameters": null,
"source_location": {
"file": "cpp/libclang/integration_test/function_cases/parameter_adjustment_dedup/functions.hpp",
"line": 24
}
},
{
"name": "callback_noexcept_identity",
"enclosing_namespace_id": null,
"return_type": "void",
"parameters": [
{
"name": "",
"param_type": "void (*)() noexcept",
"is_variadic": false
}
],
"template_parameters": null,
"source_location": {
"file": "cpp/libclang/integration_test/function_cases/parameter_adjustment_dedup/functions.hpp",
"line": 25
}
}
],
"functions": [
{
"id": {
"name": "alias_fn",
"scope": "Global"
},
"kind": "Free",
"return_type": {
"Builtin": "void"
},
"body": []
},
{
"id": {
"name": "typedef_fn",
"scope": "Global"
},
"kind": "Free",
"return_type": {
"Builtin": "void"
},
"body": []
},
{
"id": {
"name": "arr_fn",
"scope": "Global"
},
"kind": "Free",
"return_type": {
"Builtin": "void"
},
"body": []
},
{
"id": {
"name": "incomplete_arr_fn",
"scope": "Global"
},
"kind": "Free",
"return_type": {
"Builtin": "void"
},
"body": []
},
{
"id": {
"name": "callback_fn",
"scope": "Global"
},
"kind": "Free",
"return_type": {
"Builtin": "void"
},
"body": []
},
{
"id": {
"name": "callback_noexcept_identity",
"scope": "Global"
},
"kind": "Free",
"return_type": {
"Builtin": "void"
},
"body": []
},
{
"id": {
"name": "callback_noexcept_identity",
"scope": "Global"
},
"kind": "Free",
"return_type": {
"Builtin": "void"
},
"body": []
}
],
"types": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/********************************************************************************
* 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 "functions.hpp"

void alias_fn(int value) {}
void typedef_fn(int value) {}
void arr_fn(int* values) {}
void incomplete_arr_fn(int* values) {}
void callback_fn(void (*callback)(int)) {}
void callback_noexcept_identity(void (*)()) {}
void callback_noexcept_identity(void (*)() noexcept) {}
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
********************************************************************************/

#pragma once

using MyInt = int;
typedef int OldInt;

void alias_fn(MyInt);
void typedef_fn(OldInt);
void arr_fn(int[5]);
void incomplete_arr_fn(int[]);
void callback_fn(void callback(int));
void callback_noexcept_identity(void (*)());
void callback_noexcept_identity(void (*)() noexcept);
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_parameter_adjustment_dedup() {
run_parser_case();
}
19 changes: 17 additions & 2 deletions cpp/libclang/src/semantics/src/resolved_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub enum ResolvedType {
return_type: Box<ResolvedType>,
parameter_types: Vec<ResolvedType>,
is_variadic: bool,
#[serde(default, skip_serializing_if = "is_false")]
is_noexcept: bool,
},
FunctionPointer(Box<ResolvedType>),
FunctionReference(Box<ResolvedType>),
Expand Down Expand Up @@ -173,12 +175,18 @@ impl ResolvedType {
return_type,
parameter_types,
is_variadic,
is_noexcept,
} => {
let mut parameters = parameter_types.iter().map(Self::render).collect::<Vec<_>>();
if *is_variadic {
parameters.push("...".to_string());
}
format!("{}({})", return_type.render(), parameters.join(", "))
let noexcept = if *is_noexcept { " noexcept" } else { "" };
format!(
"{}({}){noexcept}",
return_type.render(),
parameters.join(", ")
)
}
Self::FunctionPointer(inner) => render_function_wrapper(inner, "*"),
Self::FunctionReference(inner) => render_function_wrapper(inner, "&"),
Expand All @@ -198,11 +206,16 @@ impl ResolvedType {
}
}

fn is_false(value: &bool) -> bool {
!value
}

fn render_function_wrapper(inner: &ResolvedType, marker: &str) -> String {
if let ResolvedType::Function {
return_type,
parameter_types,
is_variadic,
is_noexcept,
} = inner
{
let mut parameters = parameter_types
Expand All @@ -212,8 +225,9 @@ fn render_function_wrapper(inner: &ResolvedType, marker: &str) -> String {
if *is_variadic {
parameters.push("...".to_string());
}
let noexcept = if *is_noexcept { " noexcept" } else { "" };
format!(
"{} ({marker})({})",
"{} ({marker})({}){noexcept}",
return_type.render(),
parameters.join(", ")
)
Expand Down Expand Up @@ -335,6 +349,7 @@ mod tests {
return_type: Box::new(ResolvedType::Builtin("void".to_string())),
parameter_types: vec![ResolvedType::UserDefined("Engine".to_string())],
is_variadic: false,
is_noexcept: false,
};
assert_eq!(
ResolvedType::FunctionPointer(Box::new(function)).render_for_display(),
Expand Down
1 change: 1 addition & 0 deletions cpp/libclang/src/visitor/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rust_library(
name = "visit_tu",
srcs = [
"src/callable_declaration.rs",
"src/clang_adapter/exception_specification.rs",
"src/clang_adapter/mod.rs",
"src/clang_adapter/scope.rs",
"src/clang_adapter/source_filter.rs",
Expand Down
Loading
Loading