Store actual Terms with spans instead of booleans

parent 95f2ec03
Pipeline #9048 failed with stages
in 4 minutes and 4 seconds
// use lalrpop_intern::InternedString;
// use quote::Tokens;
use proc_macro2::Term;
use syn::punctuated::Punctuated;
use syn::{Attribute, Lit};
use syn::{Block, FnArg, Ident, Path, ReturnType};
......@@ -71,9 +72,9 @@ pub enum ImplItemKind {
}
pub struct ImplItemMethod {
pub public: bool, // requires body
pub virtual_: bool, // implies public, doesn't need body
pub signal: bool, // ignore
pub public: Option<Term>, // requires body
pub virtual_: Option<Term>, // implies public, doesn't need body
pub signal: Option<Term>, // ignore
pub name: Ident,
pub inputs: Punctuated<FnArg, Token!(,)>, // must start with &self
pub output: ReturnType,
......
......@@ -215,13 +215,13 @@ impl<'ast> Classes<'ast> {
bail!("can't reserve slots in a parent class impl");
}
};
if item.signal {
if item.signal.is_some() {
bail!("can't implement signals for parent classes")
}
if !item.virtual_ {
if !item.virtual_.is_some() {
bail!("can only implement virtual functions for parent classes")
}
if item.public {
if item.public.is_some() {
bail!("overrides are always public, no `pub` needed")
}
let method = match class.translate_method(item)? {
......@@ -273,15 +273,15 @@ impl<'ast> Class<'ast> {
}
fn translate_method(&mut self, method: &'ast ast::ImplItemMethod) -> Result<Slot<'ast>> {
if method.signal {
if method.public {
if method.signal.is_some() {
if method.public.is_some() {
bail!(
"function `{}` is a signal so it doesn't need to be public",
method.name
)
}
if method.virtual_ {
if method.virtual_.is_some() {
bail!(
"function `{}` is a signal so it doesn't need to be virtual",
method.name
......@@ -294,8 +294,8 @@ impl<'ast> Class<'ast> {
sig,
body: method.body.as_ref(),
}))
} else if method.virtual_ {
if method.public {
} else if method.virtual_.is_some() {
if method.public.is_some() {
bail!(
"function `{}` is virtual so it doesn't need to be public",
method.name
......@@ -310,7 +310,7 @@ impl<'ast> Class<'ast> {
let sig = self.extract_sig(method)?;
Ok(Slot::Method(Method {
sig,
public: method.public,
public: method.public.is_some(),
body: method
.body
.as_ref()
......
......@@ -151,9 +151,9 @@ impl Synom for ast::ImplItemKind {
impl Synom for ast::ImplItemMethod {
named!(parse -> Self, do_parse!(
public: map!(option!(call!(keyword("pub"))), |x| x.is_some()) >>
virtual_: map!(option!(call!(keyword("virtual"))), |x| x.is_some()) >>
signal: map!(option!(call!(keyword("signal"))), |x| x.is_some()) >>
public: option!(call!(keyword("pub"))) >>
virtual_: option!(call!(keyword("virtual"))) >>
signal: option!(call!(keyword("signal"))) >>
keyword!(fn) >>
name: syn!(syn::Ident) >>
params: parens!(Punctuated::parse_terminated) >>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment