 //  gir2swift
 //
 //  Created by Rene Hexel on 29/04/2016.
-//  Copyright © 2016, 2017, 2018, 2019 Rene Hexel. All rights reserved.
+//  Copyright © 2016, 2017, 2018, 2019, 2020 Rene Hexel. All rights reserved.
 //
 #if os(Linux)
     import Glibc

        return swiftIdentifier
    }

    /// return a valid Swift type for an underlying C type
    var swiftTypeVerbatim: String {
        if let s = swiftVerbatimReplacements[self] { return s }
        return swiftIdentifier
    }
    
    /// return a valid Swift name by appending '_' to a reserved name
    var swiftName: String {
        guard !reservedNames.contains(self) else { return self + "_" }
        return swiftIdentifier
    }


  "int64_t" : "Int64", "uint64_t" : "UInt64",
  "Error" : "ErrorType", "ErrorType" : "ErrorEnum" ]

/// Mapping that allows casting from original C types to more idiomatic Swift types
/// FIXME: these types only work correctly on 64bit systems
private let swiftConvenience = [ "CInt" : "Int", "CUnsignedInt" : "Int",
  "CLong" : "Int", "CUnsignedLong" : "Int", "CLongLong" : "Int", "CUnsignedLongLong" : "Int",
  "CShort" : "Int", "CUnsignedShort" : "Int", "CDouble" : "Double", "CFloat" : "Double" ]

/// Idiomatic Swift type equivalents for C types
private let swiftIdiomaticReplacements: [ String : String] = swiftReplacementsForC.mapValues {
    guard let replacement = swiftConvenience[$0] else { return $0 }
    return replacement
}

/// Verbatim Swift type equivalents for C types
private let swiftVerbatimReplacements = swiftReplacementsForC.mapValues { $0 == "String" ? "UnsafePointer<CChar>" : $0 }

/// Verbatim Swift type equivalents for C types
private let swiftVerbatimIdiomaticReplacements = swiftIdiomaticReplacements.mapValues { $0 == "String" ? "UnsafePointer<CChar>" : $0 }

/// Types that already exist in Swift and therefore need to be treated specially
private let reservedTypes: Set = ["String", "Array", "Optional", "Set", "Error", "ErrorProtocol"]
