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 Apr 7, 2024
1 parent 128e179 commit 0f862f8
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,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. Value of `true` is used in the test generator
* @return .NET data type
*/
def kaitaiType2NativeType(attrType: DataType): String = {
def kaitaiType2NativeType(attrType: DataType, absolute: Boolean = false): String = {
attrType match {
case Int1Type(false) => "byte"
case IntMultiType(false, Width2, _) => "ushort"
Expand Down Expand Up @@ -648,12 +650,22 @@ 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 => s"List<${kaitaiType2NativeType(at.elType)}>"
case at: ArrayType => s"List<${kaitaiType2NativeType(at.elType, absolute)}>"

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

Expand Down

0 comments on commit 0f862f8

Please sign in to comment.