diff options
| author | bors <bors@rust-lang.org> | 2013-09-03 12:22:16 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-09-03 12:22:16 -0700 |
| commit | b4ff0bca4c123399f8be8d44877e271767c5871c (patch) | |
| tree | 1dce179b3e5f546fb7c4cecb7d042dae88dbcb65 /src/libsyntax | |
| parent | 7ee90a002ab0841f5fcfdf74eb74b58b1c1a8000 (diff) | |
| parent | 506f69aed7e2f5dfdd2134ae0c74e47559e1c649 (diff) | |
| download | rust-b4ff0bca4c123399f8be8d44877e271767c5871c.tar.gz rust-b4ff0bca4c123399f8be8d44877e271767c5871c.zip | |
auto merge of #8921 : huonw/rust/stability, r=brson
Significant progress on #6875, enough that I'll open new bugs and turn that into a metabug when this lands. Description & example in the commit message.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast_map.rs | 20 | ||||
| -rw-r--r-- | src/libsyntax/attr.rs | 38 |
2 files changed, 58 insertions, 0 deletions
diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index ccaadcbad4d..e3023b919f8 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -80,6 +80,26 @@ pub enum ast_node { node_callee_scope(@Expr) } +impl ast_node { + pub fn with_attrs<T>(&self, f: &fn(Option<&[Attribute]>) -> T) -> T { + let attrs = match *self { + node_item(i, _) => Some(i.attrs.as_slice()), + node_foreign_item(fi, _, _, _) => Some(fi.attrs.as_slice()), + node_trait_method(tm, _, _) => match *tm { + required(ref type_m) => Some(type_m.attrs.as_slice()), + provided(m) => Some(m.attrs.as_slice()) + }, + node_method(m, _, _) => Some(m.attrs.as_slice()), + node_variant(ref v, _, _) => Some(v.node.attrs.as_slice()), + // unit/tuple structs take the attributes straight from + // the struct definition. + node_struct_ctor(_, strct, _) => Some(strct.attrs.as_slice()), + _ => None + }; + f(attrs) + } +} + pub type map = @mut HashMap<NodeId, ast_node>; pub struct Ctx { diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 2ed03040fa1..fd0887de722 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -313,6 +313,44 @@ pub fn test_cfg<AM: AttrMetaMethods, It: Iterator<AM>> no_cfgs || some_cfg_matches } +/// Represents the #[deprecated="foo"] (etc) attributes. +pub struct Stability { + level: StabilityLevel, + text: Option<@str> +} + +/// The available stability levels. +#[deriving(Eq,Ord,Clone)] +pub enum StabilityLevel { + Deprecated, + Experimental, + Unstable, + Stable, + Frozen, + Locked +} + +/// Find the first stability attribute. `None` if none exists. +pub fn find_stability<AM: AttrMetaMethods, It: Iterator<AM>>(mut metas: It) -> Option<Stability> { + for m in metas { + let level = match m.name().as_slice() { + "deprecated" => Deprecated, + "experimental" => Experimental, + "unstable" => Unstable, + "stable" => Stable, + "frozen" => Frozen, + "locked" => Locked, + _ => loop // not a stability level + }; + + return Some(Stability { + level: level, + text: m.value_str() + }); + } + None +} + pub fn require_unique_names(diagnostic: @mut span_handler, metas: &[@MetaItem]) { let mut set = HashSet::new(); |
