summary refs log tree commit diff
path: root/src/comp/middle/lint.rs
blob: e81759061ae75f3bd24b06291ef6cf922291c6f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import driver::session::session;
import middle::ty::ctxt;
import syntax::{ast, visit};

type crate_ctxt = {tcx: ty::ctxt};

enum option {
    ctypes,
}

fn check_ctypes(tcx: ty::ctxt, crate: @ast::crate) {
    fn check_native_fn(tcx: ty::ctxt, decl: ast::fn_decl) {
        let tys = vec::map(decl.inputs) {|a| a.ty };
        for ty in (tys + [decl.output]) {
            alt ty.node {
              ast::ty_int(ast::ty_i) {
                tcx.sess.span_warn(
                    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) {
                tcx.sess.span_warn(
                    ty.span,
                    "found rust type `uint` in native module, while \
                     ctypes::c_uint or ctypes::ulong should be used");
              }
              _ { }
            }
        }
    }

    fn check_item(tcx: ty::ctxt, it: @ast::item) {
        alt it.node {
          ast::item_native_mod(nmod) {
            for ni in nmod.items {
                alt ni.node {
                  ast::native_item_fn(decl, tps) {
                    check_native_fn(tcx, decl);
                  }
                  _ { }
                }
            }
          }
          _ {/* nothing to do */ }
        }
    }

    let visit = visit::mk_simple_visitor(@{
        visit_item: bind check_item(tcx, _)
        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:
//