2012-01-19 16:50:51 +08:00
|
|
|
import driver::session::session;
|
|
|
|
import middle::ty::ctxt;
|
|
|
|
import syntax::{ast, visit};
|
|
|
|
|
|
|
|
type crate_ctxt = {tcx: ty::ctxt};
|
|
|
|
|
|
|
|
enum option {
|
2012-01-19 17:56:05 -08:00
|
|
|
ctypes,
|
2012-01-19 16:50:51 +08:00
|
|
|
}
|
|
|
|
|
2012-01-19 20:29:50 +08:00
|
|
|
fn check_ctypes(tcx: ty::ctxt, crate: @ast::crate) {
|
|
|
|
fn check_native_fn(tcx: ty::ctxt, decl: ast::fn_decl) {
|
2012-01-19 16:50:51 +08:00
|
|
|
let tys = vec::map(decl.inputs) {|a| a.ty };
|
|
|
|
for ty in (tys + [decl.output]) {
|
|
|
|
alt ty.node {
|
|
|
|
ast::ty_int(ast::ty_i) {
|
2012-01-19 20:29:50 +08:00
|
|
|
tcx.sess.span_warn(
|
2012-01-19 16:50:51 +08:00
|
|
|
ty.span,
|
|
|
|
"found rust type `int` in native module, while \
|
|
|
|
ctypes::c_int or ctypes::long should be used");
|
|
|
|
}
|
|
|
|
ast::ty_uint(ast::ty_u) {
|
2012-01-19 20:29:50 +08:00
|
|
|
tcx.sess.span_warn(
|
2012-01-19 16:50:51 +08:00
|
|
|
ty.span,
|
|
|
|
"found rust type `uint` in native module, while \
|
|
|
|
ctypes::c_uint or ctypes::ulong should be used");
|
|
|
|
}
|
|
|
|
_ { }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-19 20:29:50 +08:00
|
|
|
fn check_item(tcx: ty::ctxt, it: @ast::item) {
|
2012-01-19 16:50:51 +08:00
|
|
|
alt it.node {
|
|
|
|
ast::item_native_mod(nmod) {
|
|
|
|
for ni in nmod.items {
|
|
|
|
alt ni.node {
|
|
|
|
ast::native_item_fn(decl, tps) {
|
2012-01-19 20:29:50 +08:00
|
|
|
check_native_fn(tcx, decl);
|
2012-01-19 16:50:51 +08:00
|
|
|
}
|
|
|
|
_ { }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ {/* nothing to do */ }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let visit = visit::mk_simple_visitor(@{
|
2012-01-19 20:29:50 +08:00
|
|
|
visit_item: bind check_item(tcx, _)
|
2012-01-19 16:50:51 +08:00
|
|
|
with *visit::default_simple_visitor()
|
|
|
|
});
|
|
|
|
visit::visit_crate(*crate, (), visit);
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|
|
|
|
//
|