зеркало из https://github.com/mozilla/moz-cheddar.git
Update to syntex 0.58.1.
This commit is contained in:
Родитель
1a9a00e69d
Коммит
43e5ff4e11
|
@ -31,7 +31,7 @@ doc = false
|
|||
path = "src/bin/cheddar.rs"
|
||||
|
||||
[dependencies]
|
||||
syntex_errors = {version = "0.42.0", optional = true}
|
||||
syntex_syntax = {version = "0.42.0", optional = true}
|
||||
syntex_errors = {version = "0.58.1", optional = true}
|
||||
syntex_syntax = {version = "0.58.1", optional = true}
|
||||
toml = "0.3.2"
|
||||
clap = "2"
|
||||
|
|
|
@ -489,7 +489,6 @@ impl Cheddar {
|
|||
let result = {
|
||||
let mut parser = ::syntax::parse::new_parser_from_source_str(
|
||||
&sess,
|
||||
vec![],
|
||||
"".into(),
|
||||
module.into(),
|
||||
);
|
||||
|
@ -526,13 +525,12 @@ impl Cheddar {
|
|||
pub fn compile_code(&self) -> Result<String, Vec<Error>> {
|
||||
let sess = &self.session;
|
||||
let krate = match self.input {
|
||||
Source::File(ref path) => syntax::parse::parse_crate_from_file(path, vec![], sess),
|
||||
Source::File(ref path) => syntax::parse::parse_crate_from_file(path, sess),
|
||||
Source::String(ref source) => syntax::parse::parse_crate_from_source_str(
|
||||
"cheddar_source".to_owned(),
|
||||
// TODO: this clone could be quite costly, maybe rethink this design?
|
||||
// or just use a slice.
|
||||
source.clone(),
|
||||
vec![],
|
||||
sess,
|
||||
),
|
||||
}.unwrap();
|
||||
|
|
20
src/parse.rs
20
src/parse.rs
|
@ -23,7 +23,11 @@ fn check_pub_use(item: &ast::Item, expected: &ast::Path) -> bool {
|
|||
if let ast::Visibility::Public = item.vis {
|
||||
// Easiest way to ensure all of API has been brought into scope.
|
||||
if let ast::ViewPath_::ViewPathGlob(ref path) = path.node {
|
||||
return path.segments == expected.segments;
|
||||
let mut segments = path.segments.iter();
|
||||
if path.is_global() {
|
||||
segments.next();
|
||||
}
|
||||
return segments.eq(expected.segments.iter());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -383,11 +387,11 @@ fn parse_attr<C, R>(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::MetaItemKind::List(ref name, ref word) if *name == "repr" => match word.first() {
|
||||
match attr.value.node {
|
||||
ast::MetaItemKind::List(ref word) if attr.name() == "repr" => match word.first() {
|
||||
Some(word) => match word.node {
|
||||
// Return true only if attribute is #[repr(C)].
|
||||
ast::MetaItemKind::Word(ref name) if *name == "C" => true,
|
||||
ast::NestedMetaItemKind::MetaItem(ref item) if item.name == "C" => true,
|
||||
_ => false,
|
||||
},
|
||||
_ => false,
|
||||
|
@ -398,16 +402,16 @@ 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::MetaItemKind::Word(ref name) if *name == "no_mangle" => true,
|
||||
match attr.value.node {
|
||||
ast::MetaItemKind::Word if attr.name() == "no_mangle" => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// If the attribute is a docstring, indent it the required amount and return it.
|
||||
fn retrieve_docstring(attr: &ast::Attribute, prepend: &str) -> Option<String> {
|
||||
match attr.node.value.node {
|
||||
ast::MetaItemKind::NameValue(ref name, ref val) if *name == "doc" => match val.node {
|
||||
match attr.value.node {
|
||||
ast::MetaItemKind::NameValue(ref val) if attr.name() == "doc" => match val.node {
|
||||
// Docstring attributes omit the trailing newline.
|
||||
ast::LitKind::Str(ref docs, _) => Some(format!("{}{}\n", prepend, docs)),
|
||||
_ => unreachable!("docs must be literal strings"),
|
||||
|
|
15
src/types.rs
15
src/types.rs
|
@ -15,12 +15,14 @@ pub fn rust_to_c(ty: &ast::Ty, assoc: &str) -> Result<Option<String>, Error> {
|
|||
// Special case Options wrapping function pointers.
|
||||
ast::TyKind::Path(None, ref path) => {
|
||||
if path.segments.len() == 1 &&
|
||||
path.segments[0].identifier.name.as_str() == "Option" {
|
||||
if let ast::PathParameters::AngleBracketed(ref d) = path.segments[0].parameters {
|
||||
assert!(d.lifetimes.is_empty() && d.bindings.is_empty());
|
||||
if d.types.len() == 1 {
|
||||
if let ast::TyKind::BareFn(ref bare_fn) = d.types[0].node {
|
||||
return fn_ptr_to_c(bare_fn, ty.span, assoc);
|
||||
path.segments[0].identifier.name == "Option" {
|
||||
if let Some(ref param) = path.segments[0].parameters {
|
||||
if let ast::PathParameters::AngleBracketed(ref d) = **param {
|
||||
assert!(d.lifetimes.is_empty() && d.bindings.is_empty());
|
||||
if d.types.len() == 1 {
|
||||
if let ast::TyKind::BareFn(ref bare_fn) = d.types[0].node {
|
||||
return fn_ptr_to_c(bare_fn, ty.span, assoc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -263,7 +265,6 @@ mod test {
|
|||
let result = {
|
||||
let mut parser = ::syntax::parse::new_parser_from_source_str(
|
||||
&sess,
|
||||
vec![],
|
||||
"".into(),
|
||||
source.into(),
|
||||
);
|
||||
|
|
Загрузка…
Ссылка в новой задаче