Skip to content

Commit

Permalink
C#: add ability to generate full names of types, for test generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingun committed Sep 8, 2024
1 parent 049b464 commit de77ec1
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,11 @@ object CSharpCompiler extends LanguageCompilerStatic
* Determine .NET data type corresponding to a KS data type.
*
* @param attrType KS data type
* @param absolute If `true` then the full name (with namespaces and enclosing types)
of the type will be generated. `true` is used in the test generator
* @return .NET data type
*/
def kaitaiType2NativeType(importList: ImportList, attrType: DataType): String = {
def kaitaiType2NativeType(importList: ImportList, attrType: DataType, absolute: Boolean = false): String = {
attrType match {
case Int1Type(false) => "byte"
case IntMultiType(false, Width2, _) => "ushort"
Expand Down Expand Up @@ -687,15 +689,25 @@ object CSharpCompiler extends LanguageCompilerStatic
case KaitaiStructType | CalcKaitaiStructType(_) => kstructName
case KaitaiStreamType | OwnedKaitaiStreamType => kstreamName

case t: UserType => types2class(t.name)
case EnumType(name, _) => types2class(name)
case t: UserType =>
types2class(if (absolute) {
t.classSpec.get.name
} else {
t.name
})
case t: EnumType =>
types2class(if (absolute) {
t.enumSpec.get.name
} else {
t.name
})

case at: ArrayType => {
importList.add("System.Collections.Generic")
s"List<${kaitaiType2NativeType(importList, at.elType)}>"
s"List<${kaitaiType2NativeType(importList, at.elType, absolute)}>"
}

case st: SwitchType => kaitaiType2NativeType(importList, st.combinedType)
case st: SwitchType => kaitaiType2NativeType(importList, st.combinedType, absolute)
}
}

Expand Down

0 comments on commit de77ec1

Please sign in to comment.