diff --git a/Cargo.toml b/Cargo.toml index 18194caf..0f1533a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,6 @@ name = "cheddar" doc = false [dependencies] -syntex_syntax = "0.24.0" +syntex_syntax = "0.27.0" toml = "0.1.25" clap = "1" diff --git a/src/lib.rs b/src/lib.rs index 70e2fbbb..c318c7c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -315,8 +315,8 @@ impl std::fmt::Display for Error { impl std::error::Error for Error { fn description(&self) -> &str { match self.level { - Level::Bug => "internal error", - Level::Fatal | Level::Error => "error", + Level::Bug | Level::Cancelled => "internal error", + Level::Fatal | Level::Error | Level::PhaseFatal => "error", Level::Warning => "warning", Level::Note => "note", Level::Help => "help", @@ -333,20 +333,34 @@ impl Error { if let Some(span) = self.span { match self.level { Level::Bug => { sess.span_diagnostic.span_bug(span, &self.message); }, - Level::Fatal => { sess.span_diagnostic.span_fatal(span, &self.message); }, + Level::Fatal | Level::PhaseFatal => { + sess.span_diagnostic.span_fatal(span, &self.message); + }, Level::Error => { sess.span_diagnostic.span_err(span, &self.message); }, Level::Warning => { sess.span_diagnostic.span_warn(span, &self.message); }, - Level::Note => { sess.span_diagnostic.span_note(span, &self.message); }, - Level::Help => { sess.span_diagnostic.span_help(span, &self.message); }, + Level::Note => { + sess.span_diagnostic.emit(Some(&span.into()), &self.message, Level::Note); + }, + Level::Help => { + sess.span_diagnostic.emit(Some(&span.into()), &self.message, Level::Help); + }, + Level::Cancelled => {} }; } else { match self.level { Level::Bug => { sess.span_diagnostic.bug(&self.message); }, - Level::Fatal => { sess.span_diagnostic.fatal(&self.message); }, + Level::Fatal | Level::PhaseFatal => { + sess.span_diagnostic.fatal(&self.message); + }, Level::Error => { sess.span_diagnostic.err(&self.message); }, Level::Warning => { sess.span_diagnostic.warn(&self.message); }, - Level::Note => { sess.span_diagnostic.note(&self.message); }, - Level::Help => { sess.span_diagnostic.help(&self.message); }, + Level::Note => { + sess.span_diagnostic.emit(None, &self.message, Level::Note); + }, + Level::Help => { + sess.span_diagnostic.emit(None, &self.message, Level::Help); + }, + Level::Cancelled => {} }; } } @@ -472,7 +486,8 @@ impl Cheddar { module.into(), ); - if let Ok(path) = parser.parse_path(syntax::parse::parser::PathParsingMode::NoTypesAllowed) { + let path = parser.parse_path(syntax::parse::parser::PathParsingMode::NoTypesAllowed); + if let Ok(path) = path { self.module = Some(path); Ok(self) } else { diff --git a/src/parse.rs b/src/parse.rs index bd17044d..de7eb189 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -18,7 +18,7 @@ use Level; /// Check that an expected path has been `pub use`d. fn check_pub_use(item: &ast::Item, expected: &ast::Path) -> bool { - if let ast::Item_::ItemUse(ref path) = item.node { + if let ast::ItemKind::Use(ref path) = item.node { // API has to be public to be used. if let ast::Visibility::Public = item.vis { // Easiest way to ensure all of API has been brought into scope. @@ -58,7 +58,7 @@ pub fn parse_crate(krate: &ast::Crate, path: &ast::Path) -> Result Result> { // TODO: Check for ItemStatic and ItemConst as well. // - How would this work? // - Is it even possible? - ast::Item_::ItemTy(..) => parse_ty(item), - ast::Item_::ItemEnum(..) => parse_enum(item), - ast::Item_::ItemStruct(..) => parse_struct(item), - ast::Item_::ItemFn(..) => parse_fn(item), + ast::ItemKind::Ty(..) => parse_ty(item), + ast::ItemKind::Enum(..) => parse_enum(item), + ast::ItemKind::Struct(..) => parse_struct(item), + ast::ItemKind::Fn(..) => parse_fn(item), _ => Ok(None), }; @@ -129,7 +129,7 @@ fn parse_ty(item: &ast::Item) -> Result, Error> { let name = item.ident.name.as_str(); let new_type = match item.node { - ast::Item_::ItemTy(ref ty, ref generics) => { + ast::ItemKind::Ty(ref ty, ref generics) => { // Can not yet convert generics. if generics.is_parameterized() { return Ok(None); } @@ -139,7 +139,7 @@ fn parse_ty(item: &ast::Item) -> Result, Error> { return Err(Error { level: Level::Bug, span: Some(item.span), - message: "`parse_ty` called on wrong `Item_`".into(), + message: "`parse_ty` called on wrong `ItemKind`".into(), }); }, }; @@ -165,7 +165,7 @@ fn parse_enum(item: &ast::Item) -> Result, Error> { let name = item.ident.name.as_str(); buffer.push_str(&format!("typedef enum {} {{\n", name)); - if let ast::Item_::ItemEnum(ref definition, ref generics) = item.node { + if let ast::ItemKind::Enum(ref definition, ref generics) = item.node { if generics.is_parameterized() { return Err(Error { level: Level::Error, @@ -192,7 +192,7 @@ fn parse_enum(item: &ast::Item) -> Result, Error> { return Err(Error { level: Level::Bug, span: Some(item.span), - message: "`parse_enum` called on wrong `Item_`".into(), + message: "`parse_enum` called on wrong `ItemKind`".into(), }); } @@ -218,7 +218,7 @@ fn parse_struct(item: &ast::Item) -> Result, Error> { let name = item.ident.name.as_str(); buffer.push_str(&format!("typedef struct {}", name)); - if let ast::Item_::ItemStruct(ref variants, ref generics) = item.node { + if let ast::ItemKind::Struct(ref variants, ref generics) = item.node { if generics.is_parameterized() { return Err(Error { level: Level::Error, @@ -256,7 +256,7 @@ fn parse_struct(item: &ast::Item) -> Result, Error> { return Err(Error { level: Level::Bug, span: Some(item.span), - message: "`parse_struct` called on wrong `Item_`".into(), + message: "`parse_struct` called on wrong `ItemKind`".into(), }); } @@ -280,7 +280,7 @@ fn parse_fn(item: &ast::Item) -> Result, Error> { let name = item.ident.name.as_str(); buffer.push_str(&docs); - if let ast::Item_::ItemFn(ref fn_decl, _, _, abi, ref generics, _) = item.node { + if let ast::ItemKind::Fn(ref fn_decl, _, _, abi, ref generics, _) = item.node { use syntax::abi::Abi; match abi { // If it doesn't have a C ABI it can't be called from C. @@ -335,15 +335,15 @@ fn parse_fn(item: &ast::Item) -> Result, Error> { let output_type = &fn_decl.output; let full_declaration = match *output_type { - ast::FunctionRetTy::NoReturn(span) => { + ast::FunctionRetTy::None(span) => { return Err(Error { level: Level::Error, span: Some(span), message: "panics across a C boundary are naughty!".into(), }); }, - ast::FunctionRetTy::DefaultReturn(..) => format!("void {}", buf_without_return), - ast::FunctionRetTy::Return(ref ty) => try_some!(types::rust_to_c(&*ty, &buf_without_return)), + ast::FunctionRetTy::Default(..) => format!("void {}", buf_without_return), + ast::FunctionRetTy::Ty(ref ty) => try_some!(types::rust_to_c(&*ty, &buf_without_return)), }; buffer.push_str(&full_declaration); @@ -352,7 +352,7 @@ fn parse_fn(item: &ast::Item) -> Result, Error> { return Err(Error { level: Level::Bug, span: Some(item.span), - message: "`parse_fn` called on wrong `Item_`".into(), + message: "`parse_fn` called on wrong `ItemKind`".into(), }); } @@ -384,10 +384,10 @@ fn parse_attr(attrs: &[ast::Attribute], check: C, retrieve: R) -> (bool, S /// Check the attribute is #[repr(C)]. fn check_repr_c(attr: &ast::Attribute) -> bool { match attr.node.value.node { - ast::MetaItem_::MetaList(ref name, ref word) if *name == "repr" => match word.first() { + ast::MetaItemKind::List(ref name, ref word) if *name == "repr" => match word.first() { Some(word) => match word.node { // Return true only if attribute is #[repr(C)]. - ast::MetaItem_::MetaWord(ref name) if *name == "C" => true, + ast::MetaItemKind::Word(ref name) if *name == "C" => true, _ => false, }, _ => false, @@ -399,7 +399,7 @@ fn check_repr_c(attr: &ast::Attribute) -> bool { /// Check the attribute is #[no_mangle]. fn check_no_mangle(attr: &ast::Attribute) -> bool { match attr.node.value.node { - ast::MetaItem_::MetaWord(ref name) if *name == "no_mangle" => true, + ast::MetaItemKind::Word(ref name) if *name == "no_mangle" => true, _ => false, } } @@ -407,9 +407,9 @@ fn check_no_mangle(attr: &ast::Attribute) -> bool { /// If the attribute is a docstring, indent it the required amount and return it. fn retrieve_docstring(attr: &ast::Attribute, prepend: &str) -> Option { match attr.node.value.node { - ast::MetaItem_::MetaNameValue(ref name, ref val) if *name == "doc" => match val.node { + ast::MetaItemKind::NameValue(ref name, ref val) if *name == "doc" => match val.node { // Docstring attributes omit the trailing newline. - ast::Lit_::LitStr(ref docs, _) => Some(format!("{}{}\n", prepend, docs)), + ast::LitKind::Str(ref docs, _) => Some(format!("{}{}\n", prepend, docs)), _ => unreachable!("docs must be literal strings"), }, _ => None, diff --git a/src/types.rs b/src/types.rs index ab12809b..e29bc0e9 100644 --- a/src/types.rs +++ b/src/types.rs @@ -11,7 +11,7 @@ use Level; pub fn rust_to_c(ty: &ast::Ty, assoc: &str) -> Result, Error> { match ty.node { // Function pointers make life an absolute pain here. - ast::Ty_::TyBareFn(ref bare_fn) => fn_ptr_to_c(bare_fn, ty.span, assoc), + ast::TyKind::BareFn(ref bare_fn) => fn_ptr_to_c(bare_fn, ty.span, assoc), // All other types just have a name associated with them. _ => Ok(Some(format!("{} {}", try_some!(anon_rust_to_c(ty)), assoc))), } @@ -21,15 +21,15 @@ pub fn rust_to_c(ty: &ast::Ty, assoc: &str) -> Result, Error> { fn anon_rust_to_c(ty: &ast::Ty) -> Result, Error> { match ty.node { // Function pointers should not be in this function. - ast::Ty_::TyBareFn(..) => Err(Error { + ast::TyKind::BareFn(..) => Err(Error { level: Level::Error, span: Some(ty.span), message: "C function pointers must have a name or function declaration associated with them".into(), }), // Standard pointers. - ast::Ty_::TyPtr(ref ptr) => ptr_to_c(ptr), + ast::TyKind::Ptr(ref ptr) => ptr_to_c(ptr), // Plain old types. - ast::Ty_::TyPath(None, ref path) => path_to_c(path), + ast::TyKind::Path(None, ref path) => path_to_c(path), // Possibly void, likely not. _ => { let new_type = print::pprust::ty_to_string(ty); @@ -51,9 +51,9 @@ fn ptr_to_c(ty: &ast::MutTy) -> Result, Error> { let new_type = try_some!(anon_rust_to_c(&ty.ty)); let const_spec = match ty.mutbl { // *const T - ast::Mutability::MutImmutable => " const" , + ast::Mutability::Immutable => " const" , // *mut T - ast::Mutability::MutMutable => "", + ast::Mutability::Mutable => "", }; Ok(Some(format!("{}{}*", new_type, const_spec))) @@ -115,15 +115,15 @@ fn fn_ptr_to_c(fn_ty: &ast::BareFnTy, fn_span: codemap::Span, inner: &str) -> Re let output_type = &fn_decl.output; let full_declaration = match *output_type { - ast::FunctionRetTy::NoReturn(span) => { + ast::FunctionRetTy::None(span) => { return Err(Error { level: Level::Error, span: Some(span), message: "panics across a C boundary are naughty!".into(), }); }, - ast::FunctionRetTy::DefaultReturn(..) => format!("void {}", buf_without_return), - ast::FunctionRetTy::Return(ref ty) => try_some!(rust_to_c(&*ty, &buf_without_return)), + ast::FunctionRetTy::Default(..) => format!("void {}", buf_without_return), + ast::FunctionRetTy::Ty(ref ty) => try_some!(rust_to_c(&*ty, &buf_without_return)), }; @@ -251,7 +251,8 @@ mod test { source.into(), ); - match parser.parse_ty() { + let ty = parser.parse_ty(); + match ty { Ok(p) => (*p).clone(), _ => panic!("internal testing error: could not parse type from {:?}", source), }