lxdrgen-swift: fix prefix handling
"Any prefix will work, so long as it's 'Relay'."
This commit is contained in:
parent
be9a3e693e
commit
f78f8a70f1
@ -36,7 +36,7 @@ function codegen_begin() {
|
|||||||
print "// Code generated from " FILENAME ". DO NOT EDIT."
|
print "// Code generated from " FILENAME ". DO NOT EDIT."
|
||||||
print "import Foundation"
|
print "import Foundation"
|
||||||
print ""
|
print ""
|
||||||
print "public struct RelayReader {"
|
print "public struct " PrefixCamel "Reader {"
|
||||||
print "\tpublic var data: Data"
|
print "\tpublic var data: Data"
|
||||||
print ""
|
print ""
|
||||||
print "\tpublic enum ReadError: Error {"
|
print "\tpublic enum ReadError: Error {"
|
||||||
@ -102,7 +102,7 @@ function codegen_begin() {
|
|||||||
print "\t}"
|
print "\t}"
|
||||||
print "}"
|
print "}"
|
||||||
print ""
|
print ""
|
||||||
print "public struct RelayWriter {"
|
print "public struct " PrefixCamel "Writer {"
|
||||||
print "\tpublic var data = Data()"
|
print "\tpublic var data = Data()"
|
||||||
print ""
|
print ""
|
||||||
print "\tpublic mutating func append<T: FixedWidthInteger>(_ number: T) {"
|
print "\tpublic mutating func append<T: FixedWidthInteger>(_ number: T) {"
|
||||||
@ -123,8 +123,8 @@ function codegen_begin() {
|
|||||||
print "\t\tdata.append(bytes)"
|
print "\t\tdata.append(bytes)"
|
||||||
print "\t}"
|
print "\t}"
|
||||||
print ""
|
print ""
|
||||||
print "\tpublic mutating func append<" \
|
print "\tpublic mutating func append<T: " \
|
||||||
"T: RawRepresentable<Int8>>(_ value: T) {"
|
"RawRepresentable<Int8>>(_ value: T) {"
|
||||||
print "\t\tappend(value.rawValue)"
|
print "\t\tappend(value.rawValue)"
|
||||||
print "\t}"
|
print "\t}"
|
||||||
print ""
|
print ""
|
||||||
@ -136,13 +136,14 @@ function codegen_begin() {
|
|||||||
print "\t\t}"
|
print "\t\t}"
|
||||||
print "\t}"
|
print "\t}"
|
||||||
print ""
|
print ""
|
||||||
print "\tpublic mutating func append<T: RelayEncodable>(_ value: T) {"
|
print "\tpublic mutating func append<T: " \
|
||||||
|
PrefixCamel "Encodable>(_ value: T) {"
|
||||||
print "\t\tvalue.encode(to: &self)"
|
print "\t\tvalue.encode(to: &self)"
|
||||||
print "\t}"
|
print "\t}"
|
||||||
print "}"
|
print "}"
|
||||||
print ""
|
print ""
|
||||||
print "public protocol RelayEncodable { " \
|
print "public protocol " PrefixCamel "Encodable { " \
|
||||||
"func encode(to: inout RelayWriter) }"
|
"func encode(to: inout " PrefixCamel "Writer) }"
|
||||||
}
|
}
|
||||||
|
|
||||||
function codegen_constant(name, value) {
|
function codegen_constant(name, value) {
|
||||||
@ -201,10 +202,10 @@ function codegen_struct(name, cg, swifttype) {
|
|||||||
print "public struct " swifttype " {\n" cg["fields"] "}"
|
print "public struct " swifttype " {\n" cg["fields"] "}"
|
||||||
print ""
|
print ""
|
||||||
print "extension " swifttype ": " PrefixCamel "Encodable {"
|
print "extension " swifttype ": " PrefixCamel "Encodable {"
|
||||||
print "\tpublic init(from: inout RelayReader) throws {"
|
print "\tpublic init(from: inout " PrefixCamel "Reader) throws {"
|
||||||
print cg["deserialize"] "\t}"
|
print cg["deserialize"] "\t}"
|
||||||
print ""
|
print ""
|
||||||
print "\tpublic func encode(to: inout RelayWriter) {"
|
print "\tpublic func encode(to: inout " PrefixCamel "Writer) {"
|
||||||
print cg["serialize"] "\t}"
|
print cg["serialize"] "\t}"
|
||||||
print "}"
|
print "}"
|
||||||
|
|
||||||
@ -230,10 +231,10 @@ function codegen_union_struct(name, casename, cg, scg, swifttype) {
|
|||||||
print scg["fields"] "}"
|
print scg["fields"] "}"
|
||||||
print ""
|
print ""
|
||||||
print "extension " swifttype ": " PrefixCamel "Encodable {"
|
print "extension " swifttype ": " PrefixCamel "Encodable {"
|
||||||
print "\tfileprivate init(from: inout RelayReader) throws {"
|
print "\tfileprivate init(from: inout " PrefixCamel "Reader) throws {"
|
||||||
print scg["deserialize"] "\t}"
|
print scg["deserialize"] "\t}"
|
||||||
print ""
|
print ""
|
||||||
print "\tpublic func encode(to: inout RelayWriter) {"
|
print "\tpublic func encode(to: inout " PrefixCamel "Writer) {"
|
||||||
print scg["serialize"] "\t}"
|
print scg["serialize"] "\t}"
|
||||||
print "}"
|
print "}"
|
||||||
|
|
||||||
@ -257,12 +258,12 @@ function codegen_union(name, cg, exhaustive, swifttype, init) {
|
|||||||
|
|
||||||
if (!exhaustive)
|
if (!exhaustive)
|
||||||
append(cg, "cases", "\tdefault:\n" \
|
append(cg, "cases", "\tdefault:\n" \
|
||||||
"\t\tthrow RelayReader.ReadError.unexpectedValue\n")
|
"\t\tthrow " PrefixCamel "Reader.ReadError.unexpectedValue\n")
|
||||||
|
|
||||||
init = decapitalize(swifttype)
|
init = decapitalize(swifttype)
|
||||||
print ""
|
print ""
|
||||||
print "public func " init \
|
print "public func " init \
|
||||||
"(from: inout RelayReader) throws -> " swifttype " {"
|
"(from: inout " PrefixCamel "Reader) throws -> " swifttype " {"
|
||||||
print "\tlet " cg["tagname"] ": " CodegenSwiftType[cg["tagtype"]] \
|
print "\tlet " cg["tagname"] ": " CodegenSwiftType[cg["tagtype"]] \
|
||||||
" = try from.read()"
|
" = try from.read()"
|
||||||
print "\tswitch " cg["tagname"] " {"
|
print "\tswitch " cg["tagname"] " {"
|
||||||
|
Loading…
Reference in New Issue
Block a user