mirror of
https://github.com/topjohnwu/cxx.git
synced 2024-11-24 04:20:02 +00:00
Add Type::Void variant
Not currently usable as a function argument or explicit return value, but will be required when we introduce Result for the case of fallible void functions, whose return type will be Result<()>.
This commit is contained in:
parent
9542f227db
commit
2fb14e934b
@ -472,6 +472,7 @@ fn write_type(out: &mut OutFile, ty: &Type) {
|
||||
Type::Str(_) => {
|
||||
write!(out, "::rust::Str");
|
||||
}
|
||||
Type::Void(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -480,6 +481,7 @@ fn write_type_space(out: &mut OutFile, ty: &Type) {
|
||||
match ty {
|
||||
Type::Ident(_) | Type::RustBox(_) | Type::UniquePtr(_) | Type::Str(_) => write!(out, " "),
|
||||
Type::Ref(_) => {}
|
||||
Type::Void(_) => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,6 +161,7 @@ fn describe(ty: &Type, types: &Types) -> String {
|
||||
Type::UniquePtr(_) => "unique_ptr".to_owned(),
|
||||
Type::Ref(_) => "reference".to_owned(),
|
||||
Type::Str(_) => "&str".to_owned(),
|
||||
Type::Void(_) => "()".to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,11 @@ pub mod ident;
|
||||
mod impls;
|
||||
mod parse;
|
||||
pub mod set;
|
||||
mod span;
|
||||
mod tokens;
|
||||
pub mod types;
|
||||
|
||||
use self::span::Span;
|
||||
use proc_macro2::Ident;
|
||||
use syn::{LitStr, Token};
|
||||
|
||||
@ -70,6 +72,7 @@ pub enum Type {
|
||||
UniquePtr(Box<Ty1>),
|
||||
Ref(Box<Ref>),
|
||||
Str(Box<Ref>),
|
||||
Void(Span),
|
||||
}
|
||||
|
||||
pub struct Ty1 {
|
||||
|
16
syntax/span.rs
Normal file
16
syntax/span.rs
Normal file
@ -0,0 +1,16 @@
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Span(pub proc_macro2::Span);
|
||||
|
||||
impl Hash for Span {
|
||||
fn hash<H: Hasher>(&self, _state: &mut H) {}
|
||||
}
|
||||
|
||||
impl Eq for Span {}
|
||||
|
||||
impl PartialEq for Span {
|
||||
fn eq(&self, _other: &Span) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ impl ToTokens for Type {
|
||||
}
|
||||
Type::RustBox(ty) | Type::UniquePtr(ty) => ty.to_tokens(tokens),
|
||||
Type::Ref(r) | Type::Str(r) => r.to_tokens(tokens),
|
||||
Type::Void(span) => tokens.extend(quote_spanned!(span.0=> ())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ impl<'a> Types<'a> {
|
||||
fn visit<'a>(all: &mut Set<'a, Type>, ty: &'a Type) {
|
||||
all.insert(ty);
|
||||
match ty {
|
||||
Type::Ident(_) | Type::Str(_) => {}
|
||||
Type::Ident(_) | Type::Str(_) | Type::Void(_) => {}
|
||||
Type::RustBox(ty) | Type::UniquePtr(ty) => visit(all, &ty.inner),
|
||||
Type::Ref(r) => visit(all, &r.inner),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user