Skip to content

Commit

Permalink
Remove the CodeOracle (#1591)
Browse files Browse the repository at this point in the history
* Remove the CodeOracle

This is now purely a local consideration for bindings, there's
no need for a shared trait. This removes a lot of unnecessary code.

* More kotlin improvements: enum/error variants now work as a CodeType.
  • Loading branch information
mhammond authored Jun 13, 2023
1 parent 62979fa commit 5e3dea5
Show file tree
Hide file tree
Showing 30 changed files with 240 additions and 300 deletions.
31 changes: 0 additions & 31 deletions uniffi_bindgen/src/backend/declarations.rs

This file was deleted.

7 changes: 1 addition & 6 deletions uniffi_bindgen/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

mod config;
mod declarations;
mod oracle;
mod types;

pub use crate::interface::{Literal, Type};
pub use config::TemplateExpression;
pub use declarations::CodeDeclaration;
pub use oracle::CodeOracle;
pub use types::CodeType;

pub use crate::interface::{Literal, Type};
29 changes: 0 additions & 29 deletions uniffi_bindgen/src/backend/oracle.rs

This file was deleted.

23 changes: 3 additions & 20 deletions uniffi_bindgen/src/backend/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,12 @@

//! # Backend traits
//!
//! This module provides a number of traits useful for implementing a backend for Uniffi.
//! A trait to help format items.
//!
//! A `CodeType` is needed for each type that will cross the FFI. It should provide helper machinery
//! in the target language to lift from and lower into a value of that type into a primitive type
//! (the FfiType), and foreign language expressions that call into the machinery. This helper code
//! can be provided by a template file.
//!
//! The `CodeOracle` provides methods to map the `Type` values found in the `ComponentInterface` to the `CodeType`s specified
//! by the backend. It also provides methods for transforming identifiers into the coding standard for the target language.
//!
//! There's also a CodeTypeDispatch trait, implemented for every type, which allows a CodeType to be created
//! by the specified `CodeOracle`. This means backends are able to provide a custom CodeType for each type
//! via that backend's CodeOracle.
//!
//! Each backend will have its own `filter` module, which is used by the askama templates used in all `CodeType`s and `CodeDeclaration`s.
//! This filter provides methods to generate expressions and identifiers in the target language. These are all forwarded to the oracle.
//! Each backend will have its own `filter` module, which is used by the askama templates.
use super::Literal;
use std::fmt::Debug;

use crate::interface::*;

/// A Trait to help render types in a language specific format.
pub trait CodeType: Debug {
/// The language specific label used to reference this type. This will be used in
Expand All @@ -40,8 +25,6 @@ pub trait CodeType: Debug {
self.type_label()
}

/// A representation of the given literal for this type.
/// N.B. `Literal` is aliased from `interface::Literal`, so may not be whole suited to this task.
fn literal(&self, _literal: &Literal) -> String {
unimplemented!("Unimplemented for {}", self.type_label())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use crate::backend::{CodeOracle, CodeType, Literal};
use crate::backend::{CodeType, Literal};

#[derive(Debug)]
pub struct CallbackInterfaceCodeType {
Expand Down
2 changes: 1 addition & 1 deletion uniffi_bindgen/src/bindings/kotlin/gen_kotlin/compounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use crate::backend::{CodeOracle, CodeType, Literal, Type};
use crate::backend::{CodeType, Literal, Type};
use paste::paste;

fn render_literal(literal: &Literal, inner: &Type) -> String {
Expand Down
2 changes: 1 addition & 1 deletion uniffi_bindgen/src/bindings/kotlin/gen_kotlin/enum_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use crate::backend::{CodeOracle, CodeType, Literal};
use crate::backend::{CodeType, Literal};

#[derive(Debug)]
pub struct EnumCodeType {
Expand Down
2 changes: 1 addition & 1 deletion uniffi_bindgen/src/bindings/kotlin/gen_kotlin/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use crate::backend::{CodeOracle, CodeType, Literal};
use crate::backend::{CodeType, Literal};

#[derive(Debug)]
pub struct ErrorCodeType {
Expand Down
Loading

0 comments on commit 5e3dea5

Please sign in to comment.