libsyntax: add explicit modes where required to copy strs/vecs
This commit is contained in:
parent
5b9e110eab
commit
44f5537abf
@ -209,7 +209,7 @@ fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
|
||||
|
||||
pub fn contains_name(metas: &[@ast::meta_item], name: &str) -> bool {
|
||||
let matches = find_meta_items_by_name(metas, name);
|
||||
return vec::len(matches) > 0u;
|
||||
matches.len() > 0u
|
||||
}
|
||||
|
||||
pub fn attrs_contains_name(attrs: &[ast::attribute], name: &str) -> bool {
|
||||
@ -227,14 +227,14 @@ pub fn first_attr_value_str_by_name(attrs: ~[ast::attribute], name: &str)
|
||||
}
|
||||
}
|
||||
|
||||
fn last_meta_item_by_name(items: ~[@ast::meta_item], name: &str)
|
||||
fn last_meta_item_by_name(items: &[@ast::meta_item], name: &str)
|
||||
-> Option<@ast::meta_item> {
|
||||
|
||||
let items = attr::find_meta_items_by_name(items, name);
|
||||
vec::last_opt(items)
|
||||
}
|
||||
|
||||
pub fn last_meta_item_value_str_by_name(items: ~[@ast::meta_item], name: &str)
|
||||
pub fn last_meta_item_value_str_by_name(items: &[@ast::meta_item], name: &str)
|
||||
-> Option<@~str> {
|
||||
|
||||
match last_meta_item_by_name(items, name) {
|
||||
|
@ -120,7 +120,7 @@ pub fn expand_auto_encode(
|
||||
fn filter_attrs(item: @ast::item) -> @ast::item {
|
||||
@ast::item {
|
||||
attrs: item.attrs.filtered(|a| !is_auto_encode(a)),
|
||||
.. *item
|
||||
.. copy *item
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,7 +175,7 @@ pub fn expand_auto_decode(
|
||||
fn filter_attrs(item: @ast::item) -> @ast::item {
|
||||
@ast::item {
|
||||
attrs: item.attrs.filtered(|a| !is_auto_decode(a)),
|
||||
.. *item
|
||||
.. copy *item
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,7 +237,7 @@ priv impl ext_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn expr(span: span, node: ast::expr_) -> @ast::expr {
|
||||
fn expr(span: span, +node: ast::expr_) -> @ast::expr {
|
||||
@ast::expr {
|
||||
id: self.next_id(),
|
||||
callee_id: self.next_id(),
|
||||
@ -246,7 +246,7 @@ priv impl ext_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn path(span: span, strs: ~[ast::ident]) -> @ast::path {
|
||||
fn path(span: span, +strs: ~[ast::ident]) -> @ast::path {
|
||||
@ast::path {
|
||||
span: span,
|
||||
global: false,
|
||||
@ -256,7 +256,7 @@ priv impl ext_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn path_global(span: span, strs: ~[ast::ident]) -> @ast::path {
|
||||
fn path_global(span: span, +strs: ~[ast::ident]) -> @ast::path {
|
||||
@ast::path {
|
||||
span: span,
|
||||
global: true,
|
||||
@ -266,8 +266,11 @@ priv impl ext_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn path_tps(span: span, strs: ~[ast::ident],
|
||||
tps: ~[@ast::Ty]) -> @ast::path {
|
||||
fn path_tps(
|
||||
span: span,
|
||||
+strs: ~[ast::ident],
|
||||
+tps: ~[@ast::Ty]
|
||||
) -> @ast::path {
|
||||
@ast::path {
|
||||
span: span,
|
||||
global: false,
|
||||
@ -277,8 +280,11 @@ priv impl ext_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn path_tps_global(span: span, strs: ~[ast::ident],
|
||||
tps: ~[@ast::Ty]) -> @ast::path {
|
||||
fn path_tps_global(
|
||||
span: span,
|
||||
+strs: ~[ast::ident],
|
||||
+tps: ~[@ast::Ty]
|
||||
) -> @ast::path {
|
||||
@ast::path {
|
||||
span: span,
|
||||
global: true,
|
||||
@ -288,8 +294,11 @@ priv impl ext_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn ty_path(span: span, strs: ~[ast::ident],
|
||||
tps: ~[@ast::Ty]) -> @ast::Ty {
|
||||
fn ty_path(
|
||||
span: span,
|
||||
+strs: ~[ast::ident],
|
||||
+tps: ~[@ast::Ty]
|
||||
) -> @ast::Ty {
|
||||
@ast::Ty {
|
||||
id: self.next_id(),
|
||||
node: ast::ty_path(
|
||||
@ -335,13 +344,13 @@ priv impl ext_ctxt {
|
||||
span: span}))
|
||||
}
|
||||
|
||||
fn lambda(blk: ast::blk) -> @ast::expr {
|
||||
fn lambda(+blk: ast::blk) -> @ast::expr {
|
||||
let ext_cx = self;
|
||||
let blk_e = self.expr(blk.span, ast::expr_block(blk));
|
||||
quote_expr!( || $blk_e )
|
||||
}
|
||||
|
||||
fn blk(span: span, stmts: ~[@ast::stmt]) -> ast::blk {
|
||||
fn blk(span: span, +stmts: ~[@ast::stmt]) -> ast::blk {
|
||||
codemap::spanned {
|
||||
node: ast::blk_ {
|
||||
view_items: ~[],
|
||||
@ -367,15 +376,15 @@ priv impl ext_ctxt {
|
||||
}
|
||||
}
|
||||
|
||||
fn expr_path(span: span, strs: ~[ast::ident]) -> @ast::expr {
|
||||
fn expr_path(span: span, +strs: ~[ast::ident]) -> @ast::expr {
|
||||
self.expr(span, ast::expr_path(self.path(span, strs)))
|
||||
}
|
||||
|
||||
fn expr_path_global(span: span, strs: ~[ast::ident]) -> @ast::expr {
|
||||
fn expr_path_global(span: span, +strs: ~[ast::ident]) -> @ast::expr {
|
||||
self.expr(span, ast::expr_path(self.path_global(span, strs)))
|
||||
}
|
||||
|
||||
fn expr_var(span: span, var: ~str) -> @ast::expr {
|
||||
fn expr_var(span: span, +var: ~str) -> @ast::expr {
|
||||
self.expr_path(span, ~[self.ident_of(var)])
|
||||
}
|
||||
|
||||
@ -390,7 +399,7 @@ priv impl ext_ctxt {
|
||||
fn expr_call(
|
||||
span: span,
|
||||
expr: @ast::expr,
|
||||
args: ~[@ast::expr]
|
||||
+args: ~[@ast::expr]
|
||||
) -> @ast::expr {
|
||||
self.expr(span, ast::expr_call(expr, args, ast::NoSugar))
|
||||
}
|
||||
@ -399,7 +408,7 @@ priv impl ext_ctxt {
|
||||
self.lambda(self.expr_blk(expr))
|
||||
}
|
||||
|
||||
fn lambda_stmts(span: span, stmts: ~[@ast::stmt]) -> @ast::expr {
|
||||
fn lambda_stmts(span: span, +stmts: ~[@ast::stmt]) -> @ast::expr {
|
||||
self.lambda(self.blk(span, stmts))
|
||||
}
|
||||
}
|
||||
@ -545,7 +554,7 @@ fn mk_deser_impl(
|
||||
fn mk_ser_method(
|
||||
cx: ext_ctxt,
|
||||
span: span,
|
||||
ser_body: ast::blk
|
||||
+ser_body: ast::blk
|
||||
) -> @ast::method {
|
||||
let ty_s = @ast::Ty {
|
||||
id: cx.next_id(),
|
||||
@ -609,7 +618,7 @@ fn mk_deser_method(
|
||||
cx: ext_ctxt,
|
||||
span: span,
|
||||
ty: @ast::Ty,
|
||||
deser_body: ast::blk
|
||||
+deser_body: ast::blk
|
||||
) -> @ast::method {
|
||||
let ty_d = @ast::Ty {
|
||||
id: cx.next_id(),
|
||||
@ -947,7 +956,7 @@ fn mk_enum_ser_body(
|
||||
cx: ext_ctxt,
|
||||
span: span,
|
||||
name: ast::ident,
|
||||
variants: ~[ast::variant]
|
||||
+variants: ~[ast::variant]
|
||||
) -> @ast::expr {
|
||||
let arms = do variants.mapi |v_idx, variant| {
|
||||
match variant.node.kind {
|
||||
|
@ -33,7 +33,7 @@ mod syntax {
|
||||
pub use parse;
|
||||
}
|
||||
|
||||
pub fn path(ids: ~[ident], span: span) -> @ast::path {
|
||||
pub fn path(+ids: ~[ident], span: span) -> @ast::path {
|
||||
@ast::path { span: span,
|
||||
global: false,
|
||||
idents: ids,
|
||||
@ -41,7 +41,7 @@ pub fn path(ids: ~[ident], span: span) -> @ast::path {
|
||||
types: ~[] }
|
||||
}
|
||||
|
||||
pub fn path_global(ids: ~[ident], span: span) -> @ast::path {
|
||||
pub fn path_global(+ids: ~[ident], span: span) -> @ast::path {
|
||||
@ast::path { span: span,
|
||||
global: true,
|
||||
idents: ids,
|
||||
@ -50,19 +50,23 @@ pub fn path_global(ids: ~[ident], span: span) -> @ast::path {
|
||||
}
|
||||
|
||||
pub trait append_types {
|
||||
fn add_ty(ty: @ast::Ty) -> @ast::path;
|
||||
fn add_tys(+tys: ~[@ast::Ty]) -> @ast::path;
|
||||
fn add_ty(&self, ty: @ast::Ty) -> @ast::path;
|
||||
fn add_tys(&self, +tys: ~[@ast::Ty]) -> @ast::path;
|
||||
}
|
||||
|
||||
pub impl append_types for @ast::path {
|
||||
fn add_ty(ty: @ast::Ty) -> @ast::path {
|
||||
@ast::path { types: vec::append_one(self.types, ty),
|
||||
.. *self}
|
||||
fn add_ty(&self, ty: @ast::Ty) -> @ast::path {
|
||||
@ast::path {
|
||||
types: vec::append_one(copy self.types, ty),
|
||||
.. **self
|
||||
}
|
||||
}
|
||||
|
||||
fn add_tys(+tys: ~[@ast::Ty]) -> @ast::path {
|
||||
@ast::path { types: vec::append(self.types, tys),
|
||||
.. *self}
|
||||
fn add_tys(&self, +tys: ~[@ast::Ty]) -> @ast::path {
|
||||
@ast::path {
|
||||
types: vec::append(copy self.types, tys),
|
||||
.. **self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,24 +77,28 @@ pub trait ext_ctxt_ast_builder {
|
||||
fn expr_block(&self, e: @ast::expr) -> ast::blk;
|
||||
fn fn_decl(&self, +inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl;
|
||||
fn item(&self, name: ident, span: span, +node: ast::item_) -> @ast::item;
|
||||
fn item_fn_poly(&self, name: ident,
|
||||
+inputs: ~[ast::arg],
|
||||
output: @ast::Ty,
|
||||
+ty_params: ~[ast::ty_param],
|
||||
+body: ast::blk) -> @ast::item;
|
||||
fn item_fn(&self, name: ident,
|
||||
+inputs: ~[ast::arg],
|
||||
output: @ast::Ty,
|
||||
+body: ast::blk) -> @ast::item;
|
||||
fn item_enum_poly(&self, name: ident,
|
||||
span: span,
|
||||
+enum_definition: ast::enum_def,
|
||||
+ty_params: ~[ast::ty_param]) -> @ast::item;
|
||||
fn item_fn_poly(&self,
|
||||
name: ident,
|
||||
+inputs: ~[ast::arg],
|
||||
output: @ast::Ty,
|
||||
+ty_params: ~[ast::ty_param],
|
||||
+body: ast::blk) -> @ast::item;
|
||||
fn item_fn(&self,
|
||||
name: ident,
|
||||
+inputs: ~[ast::arg],
|
||||
output: @ast::Ty,
|
||||
+body: ast::blk) -> @ast::item;
|
||||
fn item_enum_poly(&self,
|
||||
name: ident,
|
||||
span: span,
|
||||
+enum_definition: ast::enum_def,
|
||||
+ty_params: ~[ast::ty_param]) -> @ast::item;
|
||||
fn item_enum(&self, name: ident, span: span,
|
||||
+enum_definition: ast::enum_def) -> @ast::item;
|
||||
fn item_struct_poly(&self, name: ident, span: span,
|
||||
struct_def: ast::struct_def,
|
||||
ty_params: ~[ast::ty_param]) -> @ast::item;
|
||||
fn item_struct_poly(&self,
|
||||
name: ident, span: span,
|
||||
struct_def: ast::struct_def,
|
||||
+ty_params: ~[ast::ty_param]) -> @ast::item;
|
||||
fn item_struct(&self, name: ident, span: span,
|
||||
struct_def: ast::struct_def) -> @ast::item;
|
||||
fn struct_expr(&self, path: @ast::path,
|
||||
@ -105,14 +113,14 @@ pub trait ext_ctxt_ast_builder {
|
||||
ty: @ast::Ty,
|
||||
+params: ~[ast::ty_param]) -> @ast::item;
|
||||
fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item;
|
||||
fn ty_vars(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
|
||||
fn ty_vars_global(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
|
||||
fn ty_vars(&self, ty_params: &[ast::ty_param]) -> ~[@ast::Ty];
|
||||
fn ty_vars_global(&self, ty_params: &[ast::ty_param]) -> ~[@ast::Ty];
|
||||
fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field;
|
||||
fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field;
|
||||
fn block(&self, +stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk;
|
||||
fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt;
|
||||
fn stmt_expr(&self, e: @ast::expr) -> @ast::stmt;
|
||||
fn block_expr(&self, b: ast::blk) -> @ast::expr;
|
||||
fn block_expr(&self, +b: ast::blk) -> @ast::expr;
|
||||
fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty;
|
||||
fn ty_infer(&self) -> @ast::Ty;
|
||||
fn ty_nil_ast_builder(&self) -> @ast::Ty;
|
||||
@ -128,7 +136,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
|
||||
], dummy_sp()).add_ty(ty))
|
||||
}
|
||||
|
||||
fn block_expr(&self, b: ast::blk) -> @ast::expr {
|
||||
fn block_expr(&self, +b: ast::blk) -> @ast::expr {
|
||||
@expr {
|
||||
id: self.next_id(),
|
||||
callee_id: self.next_id(),
|
||||
@ -282,7 +290,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
|
||||
|
||||
fn item_struct_poly(&self, name: ident, span: span,
|
||||
struct_def: ast::struct_def,
|
||||
ty_params: ~[ast::ty_param]) -> @ast::item {
|
||||
+ty_params: ~[ast::ty_param]) -> @ast::item {
|
||||
self.item(name, span, ast::item_struct(@struct_def, ty_params))
|
||||
}
|
||||
|
||||
@ -386,12 +394,12 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
|
||||
self.item_ty_poly(name, span, ty, ~[])
|
||||
}
|
||||
|
||||
fn ty_vars(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
|
||||
fn ty_vars(&self, +ty_params: &[ast::ty_param]) -> ~[@ast::Ty] {
|
||||
ty_params.map(|p| self.ty_path_ast_builder(
|
||||
path(~[p.ident], dummy_sp())))
|
||||
}
|
||||
|
||||
fn ty_vars_global(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
|
||||
fn ty_vars_global(&self, ty_params: &[ast::ty_param]) -> ~[@ast::Ty] {
|
||||
ty_params.map(|p| self.ty_path_ast_builder(
|
||||
path(~[p.ident], dummy_sp())))
|
||||
}
|
||||
|
@ -58,8 +58,7 @@ pub impl gen_send for message {
|
||||
let next = this.proto.get_state(next_state.state);
|
||||
assert next_state.tys.len() == next.ty_params.len();
|
||||
let arg_names = tys.mapi(|i, _ty| cx.ident_of(~"x_"+i.to_str()));
|
||||
|
||||
let args_ast = (arg_names, *tys).map(|n, t| cx.arg(*n, *t));
|
||||
let args_ast = vec::map2(arg_names, *tys, |n, t| cx.arg(*n, *t));
|
||||
|
||||
let pipe_ty = cx.ty_path_ast_builder(
|
||||
path(~[this.data_name()], span)
|
||||
@ -137,7 +136,7 @@ pub impl gen_send for message {
|
||||
debug!("pipec: no next state");
|
||||
let arg_names = tys.mapi(|i, _ty| (~"x_" + i.to_str()));
|
||||
|
||||
let args_ast = do (arg_names, *tys).map |n, t| {
|
||||
let args_ast = do vec::map2(arg_names, *tys) |n, t| {
|
||||
cx.arg(cx.ident_of(*n), *t)
|
||||
};
|
||||
|
||||
|
@ -120,11 +120,11 @@ pub impl state_ {
|
||||
|
||||
pub type protocol = @mut protocol_;
|
||||
|
||||
pub fn protocol(name: ~str, +span: span) -> protocol {
|
||||
pub fn protocol(+name: ~str, +span: span) -> protocol {
|
||||
@mut protocol_(name, span)
|
||||
}
|
||||
|
||||
pub fn protocol_(name: ~str, span: span) -> protocol_ {
|
||||
pub fn protocol_(+name: ~str, span: span) -> protocol_ {
|
||||
protocol_ {
|
||||
name: name,
|
||||
span: span,
|
||||
@ -174,7 +174,7 @@ pub impl protocol_ {
|
||||
}
|
||||
|
||||
pub impl protocol {
|
||||
fn add_state_poly(&self, name: ~str, ident: ast::ident, dir: direction,
|
||||
fn add_state_poly(&self, +name: ~str, ident: ast::ident, dir: direction,
|
||||
+ty_params: ~[ast::ty_param]) -> state {
|
||||
let messages = @mut ~[];
|
||||
|
||||
|
@ -23,19 +23,33 @@ use core::str;
|
||||
use core::vec;
|
||||
|
||||
fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo {
|
||||
let ExpandedFrom(CallInfo { call_site, _ }) = *expn_info;
|
||||
match call_site.expn_info {
|
||||
Some(next_expn_info) => {
|
||||
let ExpandedFrom(CallInfo {
|
||||
callee: NameAndSpan {name, _},
|
||||
_
|
||||
}) = *next_expn_info;
|
||||
// Don't recurse into file using "include!"
|
||||
if name == ~"include" { return expn_info; }
|
||||
// FIXME(#3874): this would be better written as:
|
||||
// let @ExpandedFrom(CallInfo {
|
||||
// call_site: ref call_site,
|
||||
// _
|
||||
// }) = expn_info;
|
||||
match *expn_info {
|
||||
ExpandedFrom(CallInfo { call_site: ref call_site, _}) => {
|
||||
match call_site.expn_info {
|
||||
Some(next_expn_info) => {
|
||||
// Don't recurse into file using "include!"
|
||||
match *next_expn_info {
|
||||
ExpandedFrom(
|
||||
CallInfo { callee: NameAndSpan {
|
||||
name: ref name,
|
||||
_
|
||||
},
|
||||
_
|
||||
}) => {
|
||||
if *name == ~"include" { return expn_info; }
|
||||
}
|
||||
}
|
||||
|
||||
topmost_expn_info(next_expn_info)
|
||||
},
|
||||
None => expn_info
|
||||
topmost_expn_info(next_expn_info)
|
||||
},
|
||||
None => expn_info
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user