diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-03-26 09:59:59 -0700 | 
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-03-26 10:00:33 -0700 | 
| commit | c282810ab04a57f7d3f476e9628b6b82184b19b2 (patch) | |
| tree | 6380e576e5dc63e5c415513a811564a2b90c5a50 /src/rustc/syntax/ast_util.rs | |
| parent | a00538b3b3da226b751767ce282682d9de28fa75 (diff) | |
| download | rust-c282810ab04a57f7d3f476e9628b6b82184b19b2.tar.gz rust-c282810ab04a57f7d3f476e9628b6b82184b19b2.zip  | |
Enforce privacy declarations for class fields and methods
Diffstat (limited to 'src/rustc/syntax/ast_util.rs')
| -rw-r--r-- | src/rustc/syntax/ast_util.rs | 21 | 
1 files changed, 17 insertions, 4 deletions
diff --git a/src/rustc/syntax/ast_util.rs b/src/rustc/syntax/ast_util.rs index 57dbfacbfbb..308b13be882 100644 --- a/src/rustc/syntax/ast_util.rs +++ b/src/rustc/syntax/ast_util.rs @@ -435,16 +435,29 @@ pure fn class_item_ident(ci: @class_item) -> ident { } } -type ivar = {ident: ident, ty: @ty, cm: class_mutability, id: node_id}; +type ivar = {ident: ident, ty: @ty, cm: class_mutability, + id: node_id, privacy: privacy}; -fn split_class_items(cs: [@class_item]) -> ([ivar], [@method]) { +type cmethod = {privacy: privacy, meth: @method}; + +fn public_methods(cms: [cmethod]) -> [@method] { + vec::filter_map(cms, {|cm| alt cm.privacy { + pub { some(cm.meth) } + _ { none }}}) +} + +fn ignore_privacy(cms: [cmethod]) -> [@method] { + vec::map(cms, {|cm| cm.meth}) +} + +fn split_class_items(cs: [@class_item]) -> ([ivar], [cmethod]) { let mut vs = [], ms = []; for c in cs { alt c.node.decl { instance_var(i, t, cm, id) { - vs += [{ident: i, ty: t, cm: cm, id: id}]; + vs += [{ident: i, ty: t, cm: cm, id: id, privacy: c.node.privacy}]; } - class_method(m) { ms += [m]; } + class_method(m) { ms += [{privacy: c.node.privacy, meth: m}]; } } } (vs, ms)  | 
