提交 cfd768e2 编写于 作者: E Eduard Burtescu

hir_map: Provide expression and statement attributes.

上级 5739ed1f
......@@ -22,6 +22,7 @@
use syntax::abi::Abi;
use syntax::ast::{self, Name, NodeId, DUMMY_NODE_ID};
use syntax::attr::ThinAttributesExt;
use syntax::codemap::{Span, Spanned};
use syntax::parse::token;
......@@ -718,6 +719,8 @@ pub fn attrs(&self, id: NodeId) -> &'ast [ast::Attribute] {
Some(NodeTraitItem(ref ti)) => Some(&ti.attrs[..]),
Some(NodeImplItem(ref ii)) => Some(&ii.attrs[..]),
Some(NodeVariant(ref v)) => Some(&v.node.attrs[..]),
Some(NodeExpr(ref e)) => Some(e.attrs.as_attr_slice()),
Some(NodeStmt(ref s)) => Some(s.node.attrs()),
// unit/tuple structs take the attributes straight from
// the struct definition.
Some(NodeStructCtor(_)) => {
......
......@@ -39,7 +39,7 @@
use syntax::abi::Abi;
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect};
use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, MetaItem};
use syntax::attr::ThinAttributes;
use syntax::attr::{ThinAttributes, ThinAttributesExt};
use syntax::parse::token::InternedString;
use syntax::ptr::P;
......@@ -635,6 +635,16 @@ pub enum Stmt_ {
StmtSemi(P<Expr>, NodeId),
}
impl Stmt_ {
pub fn attrs(&self) -> &[Attribute] {
match *self {
StmtDecl(ref d, _) => d.node.attrs(),
StmtExpr(ref e, _) |
StmtSemi(ref e, _) => e.attrs.as_attr_slice(),
}
}
}
// FIXME (pending discussion of #1697, #2178...): local should really be
// a refinement on pat.
/// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
......@@ -659,6 +669,15 @@ pub enum Decl_ {
DeclItem(ItemId),
}
impl Decl_ {
pub fn attrs(&self) -> &[Attribute] {
match *self {
DeclLocal(ref l) => l.attrs.as_attr_slice(),
DeclItem(_) => &[]
}
}
}
/// represents one arm of a 'match'
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub struct Arm {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册