Skip to content

Commit

Permalink
Introduce type aliases in syntax tree
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 8, 2020
1 parent d09e012 commit 9938381
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions macro/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fn expand(namespace: &Namespace, ffi: ItemMod, apis: &[Api], types: &Types) -> T
Api::RustFunction(efn) => {
hidden.extend(expand_rust_function_shim(namespace, efn, types))
}
Api::TypeAlias(_alias) => unimplemented!(),
}
}

Expand Down
1 change: 1 addition & 0 deletions syntax/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub(crate) fn check_all(cx: &mut Check, namespace: &Namespace, apis: &[Api]) {
check(cx, &arg.ident);
}
}
Api::TypeAlias(_alias) => unimplemented!(),
}
}
}
11 changes: 10 additions & 1 deletion syntax/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use self::parse::kw;
use proc_macro2::{Ident, Span};
use syn::punctuated::Punctuated;
use syn::token::{Brace, Bracket, Paren};
use syn::{Lifetime, LitStr, Token};
use syn::{Lifetime, LitStr, Token, Type as RustType};

pub use self::atom::Atom;
pub use self::doc::Doc;
Expand All @@ -35,6 +35,7 @@ pub enum Api {
CxxFunction(ExternFn),
RustType(ExternType),
RustFunction(ExternFn),
TypeAlias(TypeAlias),
}

pub struct ExternType {
Expand Down Expand Up @@ -68,6 +69,14 @@ pub struct ExternFn {
pub semi_token: Token![;],
}

pub struct TypeAlias {
pub type_token: Token![type],
pub ident: Ident,
pub eq_token: Token![=],
pub ty: RustType,
pub semi_token: Token![;],
}

pub struct Signature {
pub fn_token: Token![fn],
pub receiver: Option<Receiver>,
Expand Down
11 changes: 10 additions & 1 deletion syntax/tokens.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::syntax::atom::Atom::*;
use crate::syntax::{
Derive, Enum, ExternFn, ExternType, Receiver, Ref, Signature, Slice, Struct, Ty1, Type, Var,
Derive, Enum, ExternFn, ExternType, Receiver, Ref, Signature, Slice, Struct, Ty1, Type,
TypeAlias, Var,
};
use proc_macro2::{Ident, Span, TokenStream};
use quote::{quote_spanned, ToTokens};
Expand Down Expand Up @@ -86,6 +87,14 @@ impl ToTokens for ExternType {
}
}

impl ToTokens for TypeAlias {
fn to_tokens(&self, tokens: &mut TokenStream) {
// Notional token range for error reporting purposes.
self.type_token.to_tokens(tokens);
self.ident.to_tokens(tokens);
}
}

impl ToTokens for Struct {
fn to_tokens(&self, tokens: &mut TokenStream) {
// Notional token range for error reporting purposes.
Expand Down
1 change: 1 addition & 0 deletions syntax/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl<'a> Types<'a> {
visit(&mut all, ret);
}
}
Api::TypeAlias(_alias) => unimplemented!(),
}
}

Expand Down

0 comments on commit 9938381

Please sign in to comment.