about summary refs log tree commit diff
path: root/src/comp/middle
diff options
context:
space:
mode:
authorHaitao Li <lihaitao@gmail.com>2012-01-19 16:50:51 +0800
committerHaitao Li <lihaitao@gmail.com>2012-01-19 17:54:38 +0800
commit7ffb2cb7e8d3f1845455a51f83fde3fd4759790c (patch)
treec94f04c555ac77099b07f30862f6d6d7eae1dfea /src/comp/middle
parent327a15d58c06136794621315388959b390511834 (diff)
rustc: Name the lint-style check module `lint`
Issue #1543
Diffstat (limited to 'src/comp/middle')
-rw-r--r--src/comp/middle/check_usage.rs59
-rw-r--r--src/comp/middle/lint.rs75
2 files changed, 75 insertions, 59 deletions
diff --git a/src/comp/middle/check_usage.rs b/src/comp/middle/check_usage.rs
deleted file mode 100644
index 227e563ed7c..00000000000
--- a/src/comp/middle/check_usage.rs
+++ /dev/null
@@ -1,59 +0,0 @@
-import driver::session::session;
-import middle::ty::ctxt;
-import syntax::{ast, visit};
-
-type crate_ctxt = {tcx: ty::ctxt};
-
-fn check_native_fn(ccx: @crate_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.) {
-            ccx.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.) {
-            ccx.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(ccx: @crate_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(ccx, decl);
-              }
-              _ { }
-            }
-        }
-      }
-      _ {/* nothing to do */ }
-    }
-}
-
-fn check_crate(tcx: ty::ctxt, crate: @ast::crate) {
-    let ccx = @{tcx: tcx};
-    let visit = visit::mk_simple_visitor(@{
-        visit_item: bind check_item(ccx, _)
-        with *visit::default_simple_visitor()
-    });
-    visit::visit_crate(*crate, (), visit);
-    tcx.sess.abort_if_errors();
-}
-//
-// Local Variables:
-// mode: rust
-// fill-column: 78;
-// indent-tabs-mode: nil
-// c-basic-offset: 4
-// buffer-file-coding-system: utf-8-unix
-// End:
-//
diff --git a/src/comp/middle/lint.rs b/src/comp/middle/lint.rs
new file mode 100644
index 00000000000..1b19fd60066
--- /dev/null
+++ b/src/comp/middle/lint.rs
@@ -0,0 +1,75 @@
+import driver::session::session;
+import middle::ty::ctxt;
+import syntax::{ast, visit};
+
+type crate_ctxt = {tcx: ty::ctxt};
+
+enum option {
+    ctypes;
+}
+
+fn check_crate(tcx: ty::ctxt, crate: @ast::crate,
+               checks: [option], timer: block(str, fn@())) {
+    let ccx = @{tcx: tcx};
+    vec::iter(checks) {|c|
+        alt c {
+          ctypes {
+            timer("ctypes usage checking", bind check_ctypes(ccx, crate))
+          }
+        }
+    }
+}
+
+fn check_ctypes(ccx: @crate_ctxt, crate: @ast::crate) {
+    fn check_native_fn(ccx: @crate_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) {
+                ccx.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) {
+                ccx.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(ccx: @crate_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(ccx, decl);
+                  }
+                  _ { }
+                }
+            }
+          }
+          _ {/* nothing to do */ }
+        }
+    }
+
+    let visit = visit::mk_simple_visitor(@{
+        visit_item: bind check_item(ccx, _)
+        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:
+//