Skip to content

Commit

Permalink
Revert "Revert "Remove support for types keyword (#1411)" (#1413)" (#…
Browse files Browse the repository at this point in the history
…1415)

This reverts commit b3cf89d.
  • Loading branch information
DanielKamkha authored Jul 5, 2022
1 parent b83e641 commit 861ba70
Show file tree
Hide file tree
Showing 29 changed files with 31 additions and 383 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Gluecodium project Release Notes

## Unreleased
### Removed:
* Support for `types` declaration was removed.

## 12.2.0
Release date: 2022-07-05
### Breaking changes:
Expand Down
23 changes: 9 additions & 14 deletions docs/lime_idl.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ interface ProcessorDelegate: com.example.utils.GenericDelegate {
fun onProcessorEvent(message: String)
}
types ProcessorHelperTypes {
struct ProcessorHelperTypes {
typealias Timestamp = Date
const DefaultOptions: SomeImportantProcessor.Options = {flagOption = true, uintOption = 42, {}}
Expand Down Expand Up @@ -104,7 +104,7 @@ Most elements can be prefixed with a visibility prefix. Possible visibility pref
such a prefix is considered `public`. The visibility prefix, if present, should precede the rest of the declaration.

* Example: `internal static property secretDelegate: ProcessorDelegate? { get set }`
* List of element kinds that can have a visibility prefix: class, interface, types, function, constructor, property,
* List of element kinds that can have a visibility prefix: class, interface, function, constructor, property,
struct, struct field, enumeration, exception, type alias, lambda, constant.
* Visibility prefix has no effect on C++ generated code.
* `open` and `open internal` are currently only supported for classes. Both mean the class can be
Expand All @@ -122,7 +122,7 @@ attribute name that follows.
### File-level declarations

There are three kinds of file-level declarations: package, import or element declaration. The
following element types can be placed at the top level: `class`, `interface`, `types`, `struct`,
following element types can be placed at the top level: `class`, `interface`, `struct`,
`enum`, `exception`, `typealias`, `lambda`. All other declarations can only be placed as child elements to
some other element.

Expand All @@ -144,17 +144,16 @@ immediately after the package declaration.

#### Container-type elements

* Syntax: (**class** | **interface** | **types**) *ElementName*\[**:** *ParentName*\] **{**
* Syntax: (**class** | **interface**) *ElementName*\[**:** *ParentName*\] **{**
*child-elements-declarations...* **}**
* Example: `class SomeImportantProcessor { ... }`
* Example: `interface ProcessorDelegate: GenericDelegate { ... }`
* Description: declares a container-type language element:
* **class** corresponds to a class declaration in the output languages.
* **interface** corresponds to an interface (protocol) declaration in the output languages.
* **types** declares a loose collection of elements, most of which become free-standing elements
in the output languages.
* Classes and interfaces can be free-standing elements at file level or can be placed in another
class, interface, or struct. `types` declaration can be only placed at file level.
class, interface, or struct.

#### Inheritance

Expand Down Expand Up @@ -264,7 +263,7 @@ struct Options {
additionalOptions: List<String> = {}
}
```
* Can be a free-standing element at file level or can be placed in: class, interface, types, struct.
* Can be a free-standing element at file level or can be placed in: class, interface, struct.
* Description: declares a struct type (data type) in the parent type:
* a struct can have any number of fields, but at least one field is required.
* a struct field can have a default value associated with it (optionally). For more details on
Expand All @@ -279,7 +278,7 @@ struct Options {
* where *enumerators-list* is a comma-separated list of enumerators, each enumerator declared as
*EnumeratorName* \[**=** *EnumeratorValue*\]
* Example: `enum Mode { SLOW, FAST, CHEAP }`
* Can be a free-standing element at file level or can be placed in: class, interface, types, struct.
* Can be a free-standing element at file level or can be placed in: class, interface, struct.
* Description: declares an enumeration type in the parent type:
* an enumeration can have any number of enumerators, but at least one enumerator is required.
* an enumerator can have a value associated with it (optionally). The value can be either an integer or another
Expand All @@ -290,7 +289,7 @@ struct Options {

* Syntax: **exception** *ExceptionName*__(__*ErrorTypeName*__)__
* Example: `exception SomethingWrong(ErrorType)`
* Can be a free-standing element at file level or can be placed in: class, interface, types, struct.
* Can be a free-standing element at file level or can be placed in: class, interface, struct.
* Description: declares an exception (error) type in the parent type:
* an exception has an error-value type associated with it.
* an exception type cannot be used as a regular type, it can only be used in a `throws` clause of
Expand All @@ -300,7 +299,7 @@ struct Options {

* Syntax: **const** *ConstantName*__:__ *ConstantType* **=** *ValueLiteral*
* Example: `const DefaultOptions: Options = {true, 42, {}}`
* Can be placed in: class, types, struct
* Can be placed in: class, struct
* Description: declares a constant in the parent type. For more details on values and literals see
`Values and Literals` below.

Expand Down Expand Up @@ -572,10 +571,6 @@ element is skipped (not generated). Custom tags are case-insensitive.
This is the default specification for this attribute.
* **Label** **=** **"**_LabelName_**"**: marks a parameter of a function or a constructor to have a distinct argument
label in Swift.
* **Extension**: marks a type collection (`types`) to be generated as Swift extension. The primary
use case for this is adding nested types into a pre-existing Swift type (i.e. non-generated).
Extending a generated type is also possible, but requires usage of `Name` attribute to avoid name
clashes on other platforms.
* **Skip** \[**=** **"**_CustomTag_**"** \]: marks an element to be skipped (not generated) in Swift. Can be applied to
any element except for enumerators. Optionally, if custom tag is specified, the element is only skipped if that tag
was defined (see `@Skip` above).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ import com.here.gluecodium.model.lime.LimeStruct
import com.here.gluecodium.model.lime.LimeType
import com.here.gluecodium.model.lime.LimeTypeRef
import com.here.gluecodium.model.lime.LimeTypedElement
import com.here.gluecodium.model.lime.LimeTypesCollection
import java.io.File

internal class CBridgeImplIncludeResolver(private val cppIncludeResolver: CppIncludeResolver) :
ImportsResolver<Include> {

override fun resolveElementImports(limeElement: LimeElement) =
when (limeElement) {
is LimeTypesCollection, is LimeConstant -> emptyList()
is LimeConstant -> emptyList()
is LimeTypeRef -> resolveTypeRefIncludes(limeElement)
is LimeReturnType -> resolveTypeRefIncludes(limeElement.typeRef)
is LimeLambdaParameter -> resolveTypeRefIncludes(limeElement.typeRef)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import com.here.gluecodium.model.lime.LimeNamedElement
import com.here.gluecodium.model.lime.LimeStruct
import com.here.gluecodium.model.lime.LimeTypeAlias
import com.here.gluecodium.model.lime.LimeTypeHelper
import com.here.gluecodium.model.lime.LimeTypesCollection
import com.here.gluecodium.validator.LimeOverloadsValidator
import java.io.File
import java.nio.file.Paths
Expand Down Expand Up @@ -153,12 +152,7 @@ internal class CppGenerator : Generator {
val allTypes = LimeTypeHelper.getAllTypes(rootElement)
val errorEnums = allTypes.filter { allErrorEnums.contains(it.fullName) }.toSet()

val limeElements = when (rootElement) {
is LimeTypesCollection ->
rootElement.structs + rootElement.enumerations +
rootElement.constants + rootElement.typeAliases
else -> listOf(rootElement)
}
val limeElements = listOf(rootElement) // TODO
val hasConstants = limeElements.any { it is LimeConstant }
val needsHeader = hasConstants || limeElements.any { it !is LimeException && it.external?.cpp == null }
val needsImplementation = hasConstants || errorEnums.isNotEmpty() ||
Expand Down Expand Up @@ -273,7 +267,6 @@ internal class CppGenerator : Generator {

private fun selectTemplate(limeElement: LimeNamedElement) =
when (limeElement) {
is LimeTypesCollection -> "cpp/CppTypes"
is LimeContainerWithInheritance -> "cpp/CppClass"
is LimeStruct -> "cpp/CppStruct"
is LimeEnumeration -> "cpp/CppEnumeration"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.here.gluecodium.model.lime.LimeExternalDescriptor.Companion.SETTER_NA
import com.here.gluecodium.model.lime.LimeField
import com.here.gluecodium.model.lime.LimeNamedElement
import com.here.gluecodium.model.lime.LimeProperty
import com.here.gluecodium.model.lime.LimeTypesCollection
import java.util.HashMap

internal class CppNameCache(
Expand Down Expand Up @@ -81,14 +80,8 @@ internal class CppNameCache(
}

private fun resolveNames(limeElement: LimeNamedElement): NamesCacheEntry {
var parentPath = limeElement.path.parent
var parentElement = limeReferenceMap[parentPath.toString()] as? LimeNamedElement
if (parentElement is LimeTypesCollection) {
// A type collection doesn't correspond to any named entity in C++ generated code.
// So skip it and use the parent namespace instead.
parentPath = parentPath.parent
parentElement = null
}
val parentPath = limeElement.path.parent
val parentElement = limeReferenceMap[parentPath.toString()] as? LimeNamedElement

val parentFullName: String
var parentIsExternal = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import com.here.gluecodium.model.lime.LimeLambda
import com.here.gluecodium.model.lime.LimeNamedElement
import com.here.gluecodium.model.lime.LimeStruct
import com.here.gluecodium.model.lime.LimeTypeAlias
import com.here.gluecodium.model.lime.LimeTypesCollection

internal class DartDeclarationImportResolver(
limeReferenceMap: Map<String, LimeElement>,
Expand All @@ -55,9 +54,7 @@ internal class DartDeclarationImportResolver(
override fun resolveElementImports(limeElement: LimeElement): List<DartImport> {
if (limeElement !is LimeNamedElement) return emptyList()

if (limeElement is LimeTypesCollection || limeElement is LimeException || limeElement is LimeTypeAlias ||
limeElement is LimeConstant
) return emptyList()
if (limeElement is LimeException || limeElement is LimeTypeAlias || limeElement is LimeConstant) return emptyList()

return when {
limeElement is LimeLambda -> listOf(tokenCacheImport)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ import com.here.gluecodium.model.lime.LimeType
import com.here.gluecodium.model.lime.LimeTypeAlias
import com.here.gluecodium.model.lime.LimeTypeHelper
import com.here.gluecodium.model.lime.LimeTypeRef
import com.here.gluecodium.model.lime.LimeTypesCollection
import java.util.logging.Logger

internal class DartGenerator : Generator {
Expand Down Expand Up @@ -225,9 +224,7 @@ internal class DartGenerator : Generator {

val allTypes = LimeTypeHelper.getAllTypes(rootElement).filterNot { it is LimeTypeAlias }
val nonExternalTypes = allTypes.filter { it.external?.dart == null }
val freeConstants = (rootElement as? LimeTypesCollection)?.constants ?: emptyList()
val allSymbols =
(nonExternalTypes + freeConstants).filter { it !is LimeTypesCollection && it.visibility.isPublic }
val allSymbols = nonExternalTypes.filter { it.visibility.isPublic }
if (allSymbols.isNotEmpty()) {
val allNames = allSymbols.map { dartNameResolver.resolveName(it) }
val testNames = allSymbols
Expand Down Expand Up @@ -524,7 +521,6 @@ internal class DartGenerator : Generator {

private fun selectTemplate(limeElement: LimeNamedElement) =
when (limeElement) {
is LimeTypesCollection -> "dart/DartTypes"
is LimeClass -> "dart/DartClass"
is LimeInterface -> "dart/DartInterface"
is LimeStruct -> "dart/DartStruct"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import com.here.gluecodium.model.lime.LimeType
import com.here.gluecodium.model.lime.LimeTypeAlias
import com.here.gluecodium.model.lime.LimeTypeHelper
import com.here.gluecodium.model.lime.LimeTypeRef
import com.here.gluecodium.model.lime.LimeTypesCollection
import com.here.gluecodium.model.lime.LimeValue
import com.here.gluecodium.model.lime.LimeValue.Duration.TimeUnit
import com.here.gluecodium.model.lime.LimeVisibility
Expand Down Expand Up @@ -231,7 +230,6 @@ internal class DartNameResolver(
val parentType = if (limeType.path.hasParent) getParentElement(limeType) as? LimeType else null
return when (parentType) {
null -> listOf(typeName)
is LimeTypesCollection -> listOf(typeName)
else -> listOf(resolveTypeName(parentType), typeName)
}.joinToString(joinInfix)
}
Expand Down Expand Up @@ -313,7 +311,7 @@ internal class DartNameResolver(
private fun buildDuplicateNames() =
limeReferenceMap.values
.filterIsInstance<LimeType>()
.filterNot { it is LimeTypesCollection || it is LimeTypeAlias || it is LimeGenericType || it is LimeBasicType }
.filterNot { it is LimeTypeAlias || it is LimeGenericType || it is LimeBasicType }
.filter { it.external?.dart == null }
.groupBy { resolveTypeName(it) }
.filterValues { it.size > 1 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import com.here.gluecodium.model.lime.LimeSet
import com.here.gluecodium.model.lime.LimeType
import com.here.gluecodium.model.lime.LimeTypeAlias
import com.here.gluecodium.model.lime.LimeTypeRef
import com.here.gluecodium.model.lime.LimeTypesCollection

internal class FfiCppIncludeResolver(
limeReferenceMap: Map<String, LimeElement>,
Expand All @@ -55,7 +54,7 @@ internal class FfiCppIncludeResolver(
override fun resolveElementImports(limeElement: LimeElement): List<Include> =
when (limeElement) {
is LimeTypeRef -> getTypeRefIncludes(limeElement)
is LimeTypesCollection, is LimeException, is LimeTypeAlias, is LimeConstant -> emptyList()
is LimeException, is LimeTypeAlias, is LimeConstant -> emptyList()
is LimeInterface -> getTypeIncludes(limeElement) + getThrownTypeIncludes(limeElement) +
getContainerIncludes(limeElement) + proxyIncludes
is LimeContainer -> getTypeIncludes(limeElement) + getContainerIncludes(limeElement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import com.here.gluecodium.model.lime.LimeNamedElement
import com.here.gluecodium.model.lime.LimeStruct
import com.here.gluecodium.model.lime.LimeTypeAlias
import com.here.gluecodium.model.lime.LimeTypeHelper
import com.here.gluecodium.model.lime.LimeTypesCollection
import com.here.gluecodium.validator.LimeOverloadsValidator
import java.io.File
import java.util.logging.Logger
Expand Down Expand Up @@ -118,7 +117,7 @@ internal class JavaGenerator : Generator {
val importCollector = JavaImportCollector(importResolver) {
LimeModelSkipPredicates.shouldRetainCheckParent(it, activeTags, JAVA, limeModel.referenceMap)
}
val resultFiles = flattenTypeCollections(javaFilteredModel.topElements)
val resultFiles = javaFilteredModel.topElements
.flatMap { generateJavaFiles(it, nameResolver, importResolver, importCollector) }
.toMutableList()

Expand Down Expand Up @@ -170,16 +169,6 @@ internal class JavaGenerator : Generator {
return resultFiles
}

private fun flattenTypeCollections(limeElements: List<LimeNamedElement>) =
limeElements.flatMap {
when (it) {
is LimeTypesCollection ->
it.structs + it.enumerations + it.exceptions +
if (it.constants.isNotEmpty()) listOf(it) else emptyList()
else -> listOf(it)
}
}

private fun generateJavaFiles(
limeElement: LimeNamedElement,
nameResolver: JavaNameResolver,
Expand Down Expand Up @@ -242,7 +231,6 @@ internal class JavaGenerator : Generator {

private fun selectTemplate(limeElement: LimeNamedElement) =
when (limeElement) {
is LimeTypesCollection -> "java/JavaConstantsWrapper"
is LimeClass -> "java/JavaClass"
is LimeInterface -> "java/JavaInterface"
is LimeStruct -> "java/JavaStruct"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import com.here.gluecodium.model.lime.LimeSet
import com.here.gluecodium.model.lime.LimeStruct
import com.here.gluecodium.model.lime.LimeType
import com.here.gluecodium.model.lime.LimeTypeRef
import com.here.gluecodium.model.lime.LimeTypesCollection
import com.here.gluecodium.model.lime.LimeValue

internal class JavaImportResolver(
Expand Down Expand Up @@ -80,12 +79,9 @@ internal class JavaImportResolver(
else -> emptyList()
}

private fun resolveLambdaImports(limeLambda: LimeLambda): List<JavaImport> {
val isNestedDeclaration =
limeLambda.path.hasParent && limeReferenceMap[limeLambda.path.parent.toString()] !is LimeTypesCollection
return resolveFunctionImports(limeLambda.asFunction()) +
listOfNotNull(nativeBaseImport.takeIf { isNestedDeclaration })
}
private fun resolveLambdaImports(limeLambda: LimeLambda) =
resolveFunctionImports(limeLambda.asFunction()) +
listOfNotNull(nativeBaseImport.takeIf { limeLambda.path.hasParent })

private fun resolveStructImports(limeStruct: LimeStruct) =
when {
Expand Down Expand Up @@ -151,8 +147,7 @@ internal class JavaImportResolver(
fun createTopElementImport(limeType: LimeType): JavaImport? {
if (nameResolver.typesWithDuplicateNames.contains(limeType.fullName)) return null
val topElement = generateSequence(limeType) {
val parentType = limeReferenceMap[it.path.parent.toString()] as? LimeType
if (parentType is LimeTypesCollection) null else parentType
limeReferenceMap[it.path.parent.toString()] as? LimeType
}.last()
return JavaImport(nameResolver.resolvePackageNames(topElement), nameResolver.resolveName(topElement))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import com.here.gluecodium.model.lime.LimeAttributeValueType.FUNCTION_NAME
import com.here.gluecodium.model.lime.LimeBasicType
import com.here.gluecodium.model.lime.LimeBasicType.TypeId
import com.here.gluecodium.model.lime.LimeComment
import com.here.gluecodium.model.lime.LimeConstant
import com.here.gluecodium.model.lime.LimeDirectTypeRef
import com.here.gluecodium.model.lime.LimeElement
import com.here.gluecodium.model.lime.LimeExternalDescriptor.Companion.NAME_NAME
Expand All @@ -47,7 +46,6 @@ import com.here.gluecodium.model.lime.LimeType
import com.here.gluecodium.model.lime.LimeTypeAlias
import com.here.gluecodium.model.lime.LimeTypeRef
import com.here.gluecodium.model.lime.LimeTypedElement
import com.here.gluecodium.model.lime.LimeTypesCollection
import com.here.gluecodium.model.lime.LimeValue
import com.here.gluecodium.model.lime.LimeVisibility

Expand Down Expand Up @@ -170,8 +168,7 @@ internal class JavaNameResolver(
val elementName = javaNameRules.getName(limeElement)
val parentElement = if (limeElement.path.hasParent) getParentElement(limeElement) else null
return when {
parentElement != null && parentElement !is LimeTypesCollection ->
resolveNestedNames(parentElement) + elementName
parentElement != null -> resolveNestedNames(parentElement) + elementName
else -> listOf(elementName)
}
}
Expand Down Expand Up @@ -252,11 +249,7 @@ internal class JavaNameResolver(
}

val parentElement = getParentElement(limeElement)
val prefix = when {
parentElement is LimeTypesCollection && limeElement !is LimeConstant ->
resolvePackageNames(limeElement).joinToString(".")
else -> resolveFullName(parentElement)
}
val prefix = resolveFullName(parentElement)

val delimiter = when {
forceDelimiter != null -> forceDelimiter
Expand All @@ -282,7 +275,7 @@ internal class JavaNameResolver(
private fun buildDuplicateNames() =
limeReferenceMap.values
.filterIsInstance<LimeType>()
.filterNot { it is LimeTypesCollection || it is LimeTypeAlias }
.filterNot { it is LimeTypeAlias }
.filter { it.external?.java == null }
.groupBy { resolveNestedNames(it).joinToString(".") }
.filterValues { it.size > 1 }
Expand Down
Loading

0 comments on commit 861ba70

Please sign in to comment.