Skip to content

Commit e112472

Browse files
melodyoncodehoe-jo
authored andcommitted
[cpp parser] normalize callable declaration identity and add regression tests
1 parent a139c91 commit e112472

49 files changed

Lines changed: 1429 additions & 95 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test")
14+
15+
cc_library(
16+
name = "extern_c_identity",
17+
srcs = ["functions.cpp"],
18+
hdrs = ["functions.hpp"],
19+
visibility = ["//cpp/libclang:__subpackages__"],
20+
)
21+
22+
cpp_parser_integration_test(
23+
name = "test_extern_c_identity",
24+
expected_output = ["expected.json"],
25+
target = ":extern_c_identity",
26+
)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"free_function_declarations": [
3+
{
4+
"name": "c_api",
5+
"enclosing_namespace_id": null,
6+
"return_type": "int",
7+
"parameters": [
8+
{
9+
"name": "",
10+
"param_type": "int",
11+
"is_variadic": false
12+
}
13+
],
14+
"template_parameters": null,
15+
"source_location": {
16+
"file": "cpp/libclang/integration_test/function_cases/extern_c_identity/functions.hpp",
17+
"line": 16
18+
}
19+
},
20+
{
21+
"name": "c_api_block",
22+
"enclosing_namespace_id": null,
23+
"return_type": "int",
24+
"parameters": [
25+
{
26+
"name": "",
27+
"param_type": "double",
28+
"is_variadic": false
29+
}
30+
],
31+
"template_parameters": null,
32+
"source_location": {
33+
"file": "cpp/libclang/integration_test/function_cases/extern_c_identity/functions.hpp",
34+
"line": 19
35+
}
36+
}
37+
],
38+
"functions": [
39+
{
40+
"id": {
41+
"name": "c_api",
42+
"scope": "Global"
43+
},
44+
"kind": "Free",
45+
"return_type": {
46+
"Builtin": "int"
47+
},
48+
"body": []
49+
},
50+
{
51+
"id": {
52+
"name": "c_api_block",
53+
"scope": "Global"
54+
},
55+
"kind": "Free",
56+
"return_type": {
57+
"Builtin": "int"
58+
},
59+
"body": []
60+
}
61+
],
62+
"types": {}
63+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
14+
#include "functions.hpp"
15+
16+
extern "C" {
17+
int c_api(int value) {
18+
return value;
19+
}
20+
21+
int c_api_block(double value) {
22+
return static_cast<int>(value);
23+
}
24+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
14+
#pragma once
15+
16+
extern "C" int c_api(int);
17+
18+
extern "C" {
19+
int c_api_block(double);
20+
}
21+
22+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
14+
use test_framework::run_parser_case;
15+
16+
#[test]
17+
fn test_extern_c_identity() {
18+
run_parser_case();
19+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
14+
load("//cpp/libclang/integration_test:test_rules.bzl", "cpp_parser_integration_test")
15+
16+
cc_library(
17+
name = "header_internal_linkage_declaration_identity",
18+
srcs = [
19+
"first.cpp",
20+
"second.cpp",
21+
],
22+
hdrs = ["internal_linkage.h"],
23+
visibility = ["//cpp/libclang:__subpackages__"],
24+
)
25+
26+
cpp_parser_integration_test(
27+
name = "test_header_internal_linkage_declaration_identity",
28+
expected_output = ["expected.json"],
29+
target = ":header_internal_linkage_declaration_identity",
30+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"free_function_declarations": [
3+
{
4+
"name": "hidden",
5+
"enclosing_namespace_id": null,
6+
"return_type": "void",
7+
"parameters": [],
8+
"template_parameters": null,
9+
"source_location": {
10+
"file": "cpp/libclang/integration_test/function_cases/header_internal_linkage_declaration_identity/internal_linkage.h",
11+
"line": 17
12+
}
13+
},
14+
{
15+
"name": "local_static",
16+
"enclosing_namespace_id": null,
17+
"return_type": "void",
18+
"parameters": [],
19+
"template_parameters": null,
20+
"source_location": {
21+
"file": "cpp/libclang/integration_test/function_cases/header_internal_linkage_declaration_identity/internal_linkage.h",
22+
"line": 20
23+
}
24+
}
25+
],
26+
"functions": [],
27+
"types": {}
28+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
14+
#include "cpp/libclang/integration_test/function_cases/header_internal_linkage_declaration_identity/internal_linkage.h"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
14+
// Forbidden based on MISRA C++:2023 Rule 10.3.1.
15+
16+
namespace {
17+
void hidden();
18+
}
19+
20+
static void local_static();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
14+
use test_framework::run_parser_case;
15+
16+
#[test]
17+
fn test_header_internal_linkage_declaration_identity() {
18+
run_parser_case();
19+
}

0 commit comments

Comments
 (0)