Skip to content

Commit

Permalink
Update dependency on syntex_syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Feb 20, 2016
1 parent 7703b51 commit d0c658d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ Automated tests of FFI bindings.
"""

[dependencies]
syntex_syntax = "0.19.1"
syntex_syntax = "0.29"
gcc = "0.3.14"
86 changes: 44 additions & 42 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ use std::io::prelude::*;
use std::path::{Path, PathBuf};

use syntax::abi::Abi;
use syntax::ast;
use syntax::ast::{self, ItemKind, ForeignItemKind, Visibility, FunctionRetTy};
use syntax::ast::{ExprKind, LitKind, TyKind, PathParameters, Mutability};
use syntax::attr::{self, ReprAttr};
use syntax::diagnostic::SpanHandler;
use syntax::ext::base::SyntaxExtension;
use syntax::errors::Handler;
use syntax::ext::base::{SyntaxExtension, ExtCtxt};
use syntax::ext::expand;
use syntax::parse::token::{intern, InternedString};
use syntax::parse::{self, ParseSess};
Expand Down Expand Up @@ -55,7 +56,7 @@ struct Generator<'a> {
target: &'a str,
rust: Box<Write>,
c: Box<Write>,
sh: &'a SpanHandler,
sh: &'a Handler,
structs: HashSet<String>,
abi: Abi,
tests: Vec<String>,
Expand Down Expand Up @@ -262,8 +263,9 @@ impl TestGenerator {
let exts = vec![
(intern("macro_rules"), SyntaxExtension::MacroRulesTT),
];
let mut krate = expand::expand_crate(&sess, ecfg, Vec::new(),
exts, &mut Vec::new(), krate);
let mut gated = Vec::new();
let cx = ExtCtxt::new(&sess, Vec::new(), ecfg, &mut gated);
let mut krate = expand::expand_crate(cx, Vec::new(), exts, krate).0;

// Strip the crate down to just what's configured for our target
let target = self.target.clone().unwrap_or_else(|| {
Expand Down Expand Up @@ -498,8 +500,8 @@ impl<'a> Generator<'a> {
"#, ty = ty));
for field in s.fields() {
let name = match field.node.kind {
ast::NamedField(name, ast::Public) => name,
ast::NamedField(_, ast::Inherited) => continue,
ast::NamedField(name, Visibility::Public) => name,
ast::NamedField(_, Visibility::Inherited) => continue,
ast::UnnamedField(..) => panic!("no tuple structs in FFI"),
};
let name = name.to_string();
Expand Down Expand Up @@ -721,11 +723,11 @@ impl<'a> Generator<'a> {

fn ty2name(&self, ty: &ast::Ty, rust: bool) -> String {
match ty.node {
ast::TyPath(_, ref path) => {
TyKind::Path(_, ref path) => {
let last = path.segments.last().unwrap();
if last.identifier.to_string() == "Option" {
match last.parameters {
ast::AngleBracketedParameters(ref p) => {
PathParameters::AngleBracketed(ref p) => {
self.ty2name(&p.types[0], rust)
}
_ => panic!(),
Expand All @@ -736,20 +738,20 @@ impl<'a> Generator<'a> {
self.rust2c(&last.identifier.to_string())
}
}
ast::TyPtr(ref t) => {
TyKind::Ptr(ref t) => {
if rust {
format!("*{} {}", match t.mutbl {
ast::MutImmutable => "const",
ast::MutMutable => "mut",
Mutability::Immutable => "const",
Mutability::Mutable => "mut",
}, self.ty2name(&t.ty, rust))
} else {
let modifier = match t.mutbl {
ast::MutImmutable => "const ",
ast::MutMutable => "",
Mutability::Immutable => "const ",
Mutability::Mutable => "",
};
match t.ty.node {
ast::TyBareFn(..) => self.ty2name(&t.ty, rust),
ast::TyPtr(..) => {
TyKind::BareFn(..) => self.ty2name(&t.ty, rust),
TyKind::Ptr(..) => {
format!("{} {}*", self.ty2name(&t.ty, rust),
modifier)
}
Expand All @@ -759,15 +761,15 @@ impl<'a> Generator<'a> {
}
}
}
ast::TyBareFn(ref t) => {
TyKind::BareFn(ref t) => {
if rust {
let args = t.decl.inputs.iter().map(|a| {
self.ty2name(&a.ty, rust)
}).collect::<Vec<_>>().connect(", ");
let ret = match t.decl.output {
ast::NoReturn(..) => "!".to_string(),
ast::DefaultReturn(..) => "()".to_string(),
ast::Return(ref t) => self.ty2name(t, rust),
FunctionRetTy::None(..) => "!".to_string(),
FunctionRetTy::Default(..) => "()".to_string(),
FunctionRetTy::Ty(ref t) => self.ty2name(t, rust),
};
format!("extern fn({}) -> {}", args, ret)
} else {
Expand All @@ -780,7 +782,7 @@ impl<'a> Generator<'a> {
format!("{}(*)({})", ret, args.connect(", "))
}
}
ast::TyFixedLengthVec(ref t, ref e) => {
TyKind::FixedLengthVec(ref t, ref e) => {
assert!(rust);
format!("[{}; {}]", self.ty2name(t, rust), self.expr2str(e))
}
Expand All @@ -790,18 +792,18 @@ impl<'a> Generator<'a> {

fn csig_returning_ptr(&self, ty: &ast::Ty, sig: &str) -> String {
match ty.node {
ast::TyPath(_, ref path) if path.segments.last().unwrap()
.identifier.to_string() == "Option"
TyKind::Path(_, ref path) if path.segments.last().unwrap()
.identifier.to_string() == "Option"
=> {
let last = path.segments.last().unwrap();
match last.parameters {
ast::AngleBracketedParameters(ref p) => {
PathParameters::AngleBracketed(ref p) => {
self.csig_returning_ptr(&p.types[0], sig)
}
_ => panic!(),
}
}
ast::TyBareFn(ref t) => {
TyKind::BareFn(ref t) => {
assert!(t.lifetimes.len() == 0);
let (ret, mut args, variadic) = self.decl2rust(&t.decl);
if variadic {
Expand All @@ -811,7 +813,7 @@ impl<'a> Generator<'a> {
}
format!("{}(**{})({})", ret, sig, args.connect(", "))
}
ast::TyFixedLengthVec(ref t, ref e) => {
TyKind::FixedLengthVec(ref t, ref e) => {
format!("{}(*{})[{}]", self.ty2name(t, false), sig,
self.expr2str(e))
}
Expand All @@ -821,13 +823,13 @@ impl<'a> Generator<'a> {

fn expr2str(&self, e: &ast::Expr) -> String {
match e.node {
ast::ExprLit(ref l) => {
ExprKind::Lit(ref l) => {
match l.node {
ast::LitInt(a, _) => a.to_string(),
LitKind::Int(a, _) => a.to_string(),
_ => panic!("unknown literal: {:?}", l),
}
}
ast::ExprPath(_, ref path) => {
ExprKind::Path(_, ref path) => {
path.segments.last().unwrap().identifier.to_string()
}
_ => panic!("unknown expr: {:?}", e),
Expand All @@ -839,9 +841,9 @@ impl<'a> Generator<'a> {
self.ty2name(&arg.ty, false)
}).collect::<Vec<_>>();
let ret = match decl.output {
ast::NoReturn(..) |
ast::DefaultReturn(..) => "void".to_string(),
ast::Return(ref t) => self.ty2name(t, false),
FunctionRetTy::None(..) |
FunctionRetTy::Default(..) => "void".to_string(),
FunctionRetTy::Ty(ref t) => self.ty2name(t, false),
};
(ret, args, decl.variadic)
}
Expand All @@ -862,14 +864,14 @@ impl<'a> Generator<'a> {
impl<'a, 'v> Visitor<'v> for Generator<'a> {
fn visit_item(&mut self, i: &'v ast::Item) {
let prev_abi = self.abi;
let public = i.vis == ast::Public;
let public = i.vis == Visibility::Public;
match i.node {
ast::ItemTy(_, ref generics) if public => {
ItemKind::Ty(_, ref generics) if public => {
self.assert_no_generics(i.ident, generics);
self.test_type(&i.ident.to_string());
}

ast::ItemStruct(ref s, ref generics) if public => {
ItemKind::Struct(ref s, ref generics) if public => {
self.assert_no_generics(i.ident, generics);
let is_c = i.attrs.iter().any(|a| {
attr::find_repr_attrs(self.sh, a).iter().any(|a| {
Expand All @@ -882,12 +884,12 @@ impl<'a, 'v> Visitor<'v> for Generator<'a> {
self.test_struct(&i.ident.to_string(), s);
}

ast::ItemConst(ref ty, _) if public => {
ItemKind::Const(ref ty, _) if public => {
let ty = self.ty2name(ty, true);
self.test_const(&i.ident.to_string(), &ty);
}

ast::ItemForeignMod(ref fm) if public => {
ItemKind::ForeignMod(ref fm) if public => {
self.abi = fm.abi;
}

Expand All @@ -899,7 +901,7 @@ impl<'a, 'v> Visitor<'v> for Generator<'a> {

fn visit_foreign_item(&mut self, i: &'v ast::ForeignItem) {
match i.node {
ast::ForeignItemFn(ref decl, ref generics) => {
ForeignItemKind::Fn(ref decl, ref generics) => {
self.assert_no_generics(i.ident, generics);
let (ret, args, variadic) = self.decl2rust(decl);
let cname = attr::first_attr_value_str_by_name(&i.attrs, "link_name")
Expand All @@ -908,7 +910,7 @@ impl<'a, 'v> Visitor<'v> for Generator<'a> {
self.test_extern_fn(&i.ident.to_string(), cname, &args, &ret,
variadic, abi);
}
ast::ForeignItemStatic(_, _) => {
ForeignItemKind::Static(_, _) => {
}
}
visit::walk_foreign_item(self, i)
Expand All @@ -920,10 +922,10 @@ impl<'a, 'v> Visitor<'v> for Generator<'a> {
impl<'v> Visitor<'v> for StructFinder {
fn visit_item(&mut self, i: &'v ast::Item) {
match i.node {
ast::ItemStruct(..) => {
ItemKind::Struct(..) => {
self.structs.insert(i.ident.to_string());
}
ast::ItemEnum(..) => {
ItemKind::Enum(..) => {
self.structs.insert(i.ident.to_string());
}

Expand Down
2 changes: 1 addition & 1 deletion testcrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ctest = { path = ".." }
gcc = "0.3"

[dependencies]
libc = "0.1"
libc = "0.2"

[lib]
name = "testcrate"
Expand Down

0 comments on commit d0c658d

Please sign in to comment.