Skip to content

Commit

Permalink
Fixes wrong FD for nested types
Browse files Browse the repository at this point in the history
Signed-off-by: Yauheni Khnykin <yauheni.khnykin@here.com>
  • Loading branch information
Hsilgos committed Feb 23, 2024
1 parent f5f0c82 commit 04a53ff
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unpublished:
### Bug fixes:
* Bridging headers from linked frameworks are used. It solves problem with some cases, for example when interface inherts (extends) another one in lime.
* Fixes forward declaration in C++ for types when contain nested types and both type and nested type are referred.

## 13.8.1
Release date: 2024-02-07
Expand Down
5 changes: 5 additions & 0 deletions functional-tests/functional/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,11 @@ feature(Nesting cpp android swift dart SOURCES
input/src/cpp/NestedContainers.cpp
input/src/cpp/NestedClassWithProperty.cpp
input/src/cpp/NestingInStruct.cpp
input/src/cpp/InterfaceRefersNestedClassAsReturnValue.cpp
input/src/cpp/InterfaceRefersNestedEnumAsReturnValue.cpp
input/src/cpp/InterfaceRefersNestedLambdaAsReturnValue.cpp
input/src/cpp/InterfaceRefersNestedStructAsReturnValue.cpp
input/src/cpp/InterfaceRefersNestedTypedefAsReturnValue.cpp

input/lime/TopLevelTypes.lime
input/lime/NestedContainers.lime
Expand Down
35 changes: 35 additions & 0 deletions functional-tests/functional/input/lime/NestedContainers.lime
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,46 @@ class OuterClass {
class InnerClass {
fun foo(input: String): String
}
struct InnerStruct {
foo: Int
}
interface InnerInterfaceInClass {
fun foo(input: String): String
}
enum InnerEnum {
FOO,
BAR
}

fun foo(input: String): String

typealias InnerTypedef = UByte
lambda InnerLambda = () -> Void
}

interface InterfaceRefersNestedEnumAsReturnValue {
fun foo(): OuterClass.InnerEnum
fun bar(): OuterClass
}

interface InterfaceRefersNestedClassAsReturnValue {
fun foo(): OuterClass.InnerClass
fun bar(): OuterClass
}

interface InterfaceRefersNestedStructAsReturnValue {
fun foo(): OuterClass.InnerStruct
fun bar(): OuterClass
}

interface InterfaceRefersNestedTypedefAsReturnValue {
fun foo(): OuterClass.InnerTypedef
fun bar(): OuterClass
}

interface InterfaceRefersNestedLambdaAsReturnValue {
fun foo(): OuterClass.InnerLambda
fun bar(): OuterClass
}

class LevelOne {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// -------------------------------------------------------------------------------------------------
// Copyright (C) 2016-2024 HERE Europe B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
// License-Filename: LICENSE
//
// -------------------------------------------------------------------------------------------------

// Include this header to check that nested class is not forward-declared.
#include "test/InterfaceRefersNestedClassAsReturnValue.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// -------------------------------------------------------------------------------------------------
// Copyright (C) 2016-2024 HERE Europe B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
// License-Filename: LICENSE
//
// -------------------------------------------------------------------------------------------------

// Include this header to check that nested class is not forward-declared.
#include "test/InterfaceRefersNestedEnumAsReturnValue.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// -------------------------------------------------------------------------------------------------
// Copyright (C) 2016-2024 HERE Europe B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
// License-Filename: LICENSE
//
// -------------------------------------------------------------------------------------------------

// Include this header to check that nested class is not forward-declared.
#include "test/InterfaceRefersNestedLambdaAsReturnValue.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// -------------------------------------------------------------------------------------------------
// Copyright (C) 2016-2024 HERE Europe B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
// License-Filename: LICENSE
//
// -------------------------------------------------------------------------------------------------

// Include this header to check that nested class is not forward-declared.
#include "test/InterfaceRefersNestedStructAsReturnValue.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// -------------------------------------------------------------------------------------------------
// Copyright (C) 2016-2024 HERE Europe B.V.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
// License-Filename: LICENSE
//
// -------------------------------------------------------------------------------------------------

// Include this header to check that nested class is not forward-declared.
#include "test/InterfaceRefersNestedTypedefAsReturnValue.h"
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,21 @@ internal abstract class CppImportsCollector<T> : ImportsCollector<T> {
): List<LimeContainerWithInheritance> {
val parentPaths =
if (limeElement is LimeContainerWithInheritance) limeElement.parents.map { it.type.path } else emptyList()
val filteredPaths = setOf(limeElement.path) + parentPaths
return allTypeRefs.map { it.type }
.filterIsInstance<LimeContainerWithInheritance>()
val allTypes = allTypeRefs.map { it.type }

// classes, enums, type alias and structs can be nested. If such type is nested then nesting type can't be
// forward declared.
val allContainersWithInheritance = allTypes.filterIsInstance<LimeContainerWithInheritance>()
val canBeNestedTypes =
allContainersWithInheritance +
allTypes.filterIsInstance<LimeEnumeration>() +
allTypes.filterIsInstance<LimeStruct>() +
allTypes.filterIsInstance<LimeTypeAlias>() +
allTypes.filterIsInstance<LimeLambda>()
val nestingTypePaths = canBeNestedTypes.filter { it.path.hasParent }.map { it.path.parent }

val filteredPaths = setOf(limeElement.path) + parentPaths + nestingTypePaths
return allContainersWithInheritance
.filter { !it.path.hasParent && it.external?.cpp == null && !filteredPaths.contains(it.path) }
}

Expand Down

0 comments on commit 04a53ff

Please sign in to comment.