Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absolute paths in enum and type frequently handled incorrectly #1135

Open
Mingun opened this issue Oct 4, 2024 · 0 comments
Open

Absolute paths in enum and type frequently handled incorrectly #1135

Mingun opened this issue Oct 4, 2024 · 0 comments

Comments

@Mingun
Copy link

Mingun commented Oct 4, 2024

Reference to enum that includes absolute path (like ::path::to::enum) will be parsed to DataType.EnumType(List(,path,to,enum)) (note the first empty string in EnumType.name)

Creation of EnumType instance:
https://github.com/kaitai-io/kaitai_struct_compiler/blob/542b24124a95f5308df625d667f8776dd023c696/shared/src/main/scala/io/kaitai/struct/datatype/DataType.scala#L486-L497

The same will happen with the CalcUserType.name when type is defined in a parameter with absolute path:

params:
  - id: param1
    type: ::absolute::path::to::type
  - id: param2
    type: u1
    enum: ::absolute::path::to::enum

https://github.com/kaitai-io/kaitai_struct_compiler/blob/542b24124a95f5308df625d667f8776dd023c696/shared/src/main/scala/io/kaitai/struct/datatype/DataType.scala#L549

In many cases in the generators such paths will produce uncompilable code, for example, in Java and C# the generated type name will begin with dot: .Absolute.Path.To.Type and .Absolute.Path.To.Enum:

Language Path
Java https://github.com/kaitai-io/kaitai_struct_compiler/blob/542b24124a95f5308df625d667f8776dd023c696/shared/src/main/scala/io/kaitai/struct/languages/JavaCompiler.scala#L920-L921
C# https://github.com/kaitai-io/kaitai_struct_compiler/blob/542b24124a95f5308df625d667f8776dd023c696/shared/src/main/scala/io/kaitai/struct/languages/CSharpCompiler.scala#L690-L691

I think, that sign of absolute path should be present in types explicitly instead of implicitly as empty first component of a name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant