1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 use crate::backend::{Literal, Type};
9 pub struct OptionalCodeType {
13 impl OptionalCodeType {
14 pub fn new(inner: Type) -> Self {
19 impl CodeType for OptionalCodeType {
20 fn type_label(&self) -> String {
21 format!("{}?", super::SwiftCodeOracle.find(&self.inner).type_label())
24 fn canonical_name(&self) -> String {
27 super::SwiftCodeOracle.find(&self.inner).canonical_name()
31 fn literal(&self, literal: &Literal) -> String {
33 Literal::Null => "nil".into(),
34 _ => super::SwiftCodeOracle.find(&self.inner).literal(literal),
40 pub struct SequenceCodeType {
44 impl SequenceCodeType {
45 pub fn new(inner: Type) -> Self {
50 impl CodeType for SequenceCodeType {
51 fn type_label(&self) -> String {
54 super::SwiftCodeOracle.find(&self.inner).type_label()
58 fn canonical_name(&self) -> String {
61 super::SwiftCodeOracle.find(&self.inner).canonical_name()
65 fn literal(&self, literal: &Literal) -> String {
67 Literal::EmptySequence => "[]".into(),
74 pub struct MapCodeType {
80 pub fn new(key: Type, value: Type) -> Self {
85 impl CodeType for MapCodeType {
86 fn type_label(&self) -> String {
89 super::SwiftCodeOracle.find(&self.key).type_label(),
90 super::SwiftCodeOracle.find(&self.value).type_label()
94 fn canonical_name(&self) -> String {
97 super::SwiftCodeOracle.find(&self.key).canonical_name(),
98 super::SwiftCodeOracle.find(&self.value).canonical_name()
102 fn literal(&self, literal: &Literal) -> String {
104 Literal::EmptyMap => "[:]".into(),