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

C#: add ability to generate full names of types, for test generator #296

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading