mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
rustc: Convert attribute in the AST to interior vectors
This commit is contained in:
parent
7714cb297b
commit
0226f56115
@ -1,5 +1,6 @@
|
|||||||
// Functions dealing with attributes and meta_items
|
// Functions dealing with attributes and meta_items
|
||||||
|
|
||||||
|
import std::ivec;
|
||||||
import std::vec;
|
import std::vec;
|
||||||
import std::str;
|
import std::str;
|
||||||
import std::map;
|
import std::map;
|
||||||
@ -28,7 +29,7 @@ export mk_attr;
|
|||||||
|
|
||||||
// From a list of crate attributes get only the meta_items that impact crate
|
// From a list of crate attributes get only the meta_items that impact crate
|
||||||
// linkage
|
// linkage
|
||||||
fn find_linkage_metas(vec[ast::attribute] attrs) -> vec[@ast::meta_item] {
|
fn find_linkage_metas(&ast::attribute[] attrs) -> vec[@ast::meta_item] {
|
||||||
let vec[@ast::meta_item] metas = [];
|
let vec[@ast::meta_item] metas = [];
|
||||||
for (ast::attribute attr in find_attrs_by_name(attrs, "link")) {
|
for (ast::attribute attr in find_attrs_by_name(attrs, "link")) {
|
||||||
alt (attr.node.value.node) {
|
alt (attr.node.value.node) {
|
||||||
@ -44,8 +45,8 @@ fn find_linkage_metas(vec[ast::attribute] attrs) -> vec[@ast::meta_item] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Search a list of attributes and return only those with a specific name
|
// Search a list of attributes and return only those with a specific name
|
||||||
fn find_attrs_by_name(vec[ast::attribute] attrs,
|
fn find_attrs_by_name(&ast::attribute[] attrs,
|
||||||
ast::ident name) -> vec[ast::attribute] {
|
ast::ident name) -> ast::attribute[] {
|
||||||
auto filter = bind fn(&ast::attribute a,
|
auto filter = bind fn(&ast::attribute a,
|
||||||
ast::ident name) -> option::t[ast::attribute] {
|
ast::ident name) -> option::t[ast::attribute] {
|
||||||
if (get_attr_name(a) == name) {
|
if (get_attr_name(a) == name) {
|
||||||
@ -54,7 +55,7 @@ fn find_attrs_by_name(vec[ast::attribute] attrs,
|
|||||||
option::none
|
option::none
|
||||||
}
|
}
|
||||||
} (_, name);
|
} (_, name);
|
||||||
ret vec::filter_map(filter, attrs);
|
ret ivec::filter_map(filter, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_attr_name(&ast::attribute attr) -> ast::ident {
|
fn get_attr_name(&ast::attribute attr) -> ast::ident {
|
||||||
@ -101,8 +102,10 @@ fn get_meta_item_value_str(&@ast::meta_item meta) -> option::t[str] {
|
|||||||
fn attr_meta(&ast::attribute attr) -> @ast::meta_item { @attr.node.value }
|
fn attr_meta(&ast::attribute attr) -> @ast::meta_item { @attr.node.value }
|
||||||
|
|
||||||
// Get the meta_items from inside a vector of attributes
|
// Get the meta_items from inside a vector of attributes
|
||||||
fn attr_metas(&vec[ast::attribute] attrs) -> vec[@ast::meta_item] {
|
fn attr_metas(&ast::attribute[] attrs) -> vec[@ast::meta_item] {
|
||||||
ret vec::map(attr_meta, attrs);
|
auto mitems = [];
|
||||||
|
for (ast::attribute a in attrs) { mitems += [attr_meta(a)]; }
|
||||||
|
ret mitems;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eq(@ast::meta_item a, @ast::meta_item b) -> bool {
|
fn eq(@ast::meta_item a, @ast::meta_item b) -> bool {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import std::ivec;
|
||||||
import std::option;
|
import std::option;
|
||||||
import std::vec;
|
import std::vec;
|
||||||
import syntax::ast;
|
import syntax::ast;
|
||||||
@ -97,11 +98,11 @@ fn native_item_in_cfg(&ast::crate_cfg cfg, &@ast::native_item item) -> bool {
|
|||||||
|
|
||||||
// Determine if an item should be translated in the current crate
|
// Determine if an item should be translated in the current crate
|
||||||
// configuration based on the item's attributes
|
// configuration based on the item's attributes
|
||||||
fn in_cfg(&ast::crate_cfg cfg, &vec[ast::attribute] attrs) -> bool {
|
fn in_cfg(&ast::crate_cfg cfg, &ast::attribute[] attrs) -> bool {
|
||||||
|
|
||||||
// The "cfg" attributes on the item
|
// The "cfg" attributes on the item
|
||||||
auto item_cfg_attrs = attr::find_attrs_by_name(attrs, "cfg");
|
auto item_cfg_attrs = attr::find_attrs_by_name(attrs, "cfg");
|
||||||
auto item_has_cfg_attrs = vec::len(item_cfg_attrs) > 0u;
|
auto item_has_cfg_attrs = ivec::len(item_cfg_attrs) > 0u;
|
||||||
if (!item_has_cfg_attrs) { ret true; }
|
if (!item_has_cfg_attrs) { ret true; }
|
||||||
|
|
||||||
// Pull the inner meta_items from the #[cfg(meta_item, ...)] attributes,
|
// Pull the inner meta_items from the #[cfg(meta_item, ...)] attributes,
|
||||||
|
@ -290,8 +290,8 @@ fn get_meta_items(&ebml::doc md) -> vec[@ast::meta_item] {
|
|||||||
ret items;
|
ret items;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_attributes(&ebml::doc md) -> vec[ast::attribute] {
|
fn get_attributes(&ebml::doc md) -> ast::attribute[] {
|
||||||
let vec[ast::attribute] attrs = [];
|
let ast::attribute[] attrs = ~[];
|
||||||
alt (ebml::maybe_get_doc(md, tag_attributes)) {
|
alt (ebml::maybe_get_doc(md, tag_attributes)) {
|
||||||
case (option::some(?attrs_d)) {
|
case (option::some(?attrs_d)) {
|
||||||
for each (ebml::doc attr_doc in
|
for each (ebml::doc attr_doc in
|
||||||
@ -301,9 +301,9 @@ fn get_attributes(&ebml::doc md) -> vec[ast::attribute] {
|
|||||||
// an attribute
|
// an attribute
|
||||||
assert (vec::len(meta_items) == 1u);
|
assert (vec::len(meta_items) == 1u);
|
||||||
auto meta_item = meta_items.(0);
|
auto meta_item = meta_items.(0);
|
||||||
attrs += [rec(node=rec(style=ast::attr_outer,
|
attrs += ~[rec(node=rec(style=ast::attr_outer,
|
||||||
value=*meta_item),
|
value=*meta_item),
|
||||||
span=rec(lo=0u, hi=0u))];
|
span=rec(lo=0u, hi=0u))];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case (option::none) { }
|
case (option::none) { }
|
||||||
@ -327,7 +327,7 @@ fn list_crate_attributes(&ebml::doc md, io::writer out) {
|
|||||||
out.write_str("\n\n");
|
out.write_str("\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_crate_attributes(&vec[u8] data) -> vec[ast::attribute] {
|
fn get_crate_attributes(&vec[u8] data) -> ast::attribute[] {
|
||||||
ret get_attributes(ebml::new_doc(data));
|
ret get_attributes(ebml::new_doc(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,13 +87,13 @@ type crate = spanned[crate_];
|
|||||||
|
|
||||||
type crate_ = rec(vec[@crate_directive] directives,
|
type crate_ = rec(vec[@crate_directive] directives,
|
||||||
_mod module,
|
_mod module,
|
||||||
vec[attribute] attrs,
|
attribute[] attrs,
|
||||||
crate_cfg config);
|
crate_cfg config);
|
||||||
|
|
||||||
tag crate_directive_ {
|
tag crate_directive_ {
|
||||||
cdir_src_mod(ident, option::t[filename], vec[attribute]);
|
cdir_src_mod(ident, option::t[filename], attribute[]);
|
||||||
cdir_dir_mod(ident, option::t[filename],
|
cdir_dir_mod(ident, option::t[filename],
|
||||||
vec[@crate_directive], vec[attribute]);
|
vec[@crate_directive], attribute[]);
|
||||||
cdir_view_item(@view_item);
|
cdir_view_item(@view_item);
|
||||||
cdir_syntax(path);
|
cdir_syntax(path);
|
||||||
cdir_auth(path, _auth);
|
cdir_auth(path, _auth);
|
||||||
@ -526,7 +526,7 @@ tag attr_style { attr_outer; attr_inner; }
|
|||||||
type attribute_ = rec(attr_style style, meta_item value);
|
type attribute_ = rec(attr_style style, meta_item value);
|
||||||
|
|
||||||
type item = rec(ident ident,
|
type item = rec(ident ident,
|
||||||
vec[attribute] attrs,
|
attribute[] attrs,
|
||||||
node_id id, // For objs and resources, this is the type def_id
|
node_id id, // For objs and resources, this is the type def_id
|
||||||
item_ node,
|
item_ node,
|
||||||
span span);
|
span span);
|
||||||
@ -544,7 +544,7 @@ tag item_ {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type native_item = rec(ident ident,
|
type native_item = rec(ident ident,
|
||||||
vec[attribute] attrs,
|
attribute[] attrs,
|
||||||
native_item_ node,
|
native_item_ node,
|
||||||
node_id id,
|
node_id id,
|
||||||
span span);
|
span span);
|
||||||
|
@ -132,10 +132,10 @@ fn noop_fold_crate(&crate_ c, ast_fold fld) -> crate_ {
|
|||||||
auto fold_meta_item = bind fold_meta_item_(_,fld);
|
auto fold_meta_item = bind fold_meta_item_(_,fld);
|
||||||
auto fold_attribute = bind fold_attribute_(_,fold_meta_item);
|
auto fold_attribute = bind fold_attribute_(_,fold_meta_item);
|
||||||
|
|
||||||
ret rec(directives=map(fld.fold_crate_directive, c.directives),
|
ret rec(directives=vec::map(fld.fold_crate_directive, c.directives),
|
||||||
module=fld.fold_mod(c.module),
|
module=fld.fold_mod(c.module),
|
||||||
attrs=map(fold_attribute, c.attrs),
|
attrs=ivec::map(fold_attribute, c.attrs),
|
||||||
config=map(fold_meta_item, c.config));
|
config=vec::map(fold_meta_item, c.config));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn noop_fold_crate_directive(&crate_directive_ cd, ast_fold fld)
|
fn noop_fold_crate_directive(&crate_directive_ cd, ast_fold fld)
|
||||||
@ -167,7 +167,7 @@ fn noop_fold_native_item(&@native_item ni, ast_fold fld) -> @native_item {
|
|||||||
auto fold_attribute = bind fold_attribute_(_,fold_meta_item);
|
auto fold_attribute = bind fold_attribute_(_,fold_meta_item);
|
||||||
|
|
||||||
ret @rec(ident=fld.fold_ident(ni.ident),
|
ret @rec(ident=fld.fold_ident(ni.ident),
|
||||||
attrs=map(fold_attribute, ni.attrs),
|
attrs=ivec::map(fold_attribute, ni.attrs),
|
||||||
node=alt (ni.node) {
|
node=alt (ni.node) {
|
||||||
case (native_item_ty) { native_item_ty }
|
case (native_item_ty) { native_item_ty }
|
||||||
case (native_item_fn(?st, ?fdec, ?typms)) {
|
case (native_item_fn(?st, ?fdec, ?typms)) {
|
||||||
@ -189,7 +189,7 @@ fn noop_fold_item(&@item i, ast_fold fld) -> @item {
|
|||||||
auto fold_attribute = bind fold_attribute_(_,fold_meta_item);
|
auto fold_attribute = bind fold_attribute_(_,fold_meta_item);
|
||||||
|
|
||||||
ret @rec(ident=fld.fold_ident(i.ident),
|
ret @rec(ident=fld.fold_ident(i.ident),
|
||||||
attrs=map(fold_attribute,i.attrs),
|
attrs=ivec::map(fold_attribute,i.attrs),
|
||||||
id=i.id, node=fld.fold_item_underscore(i.node),
|
id=i.id, node=fld.fold_item_underscore(i.node),
|
||||||
span=i.span);
|
span=i.span);
|
||||||
}
|
}
|
||||||
|
@ -1479,7 +1479,7 @@ fn parse_stmt(&parser p) -> @ast::stmt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_crate_stmt(&parser p) -> @ast::stmt {
|
fn parse_crate_stmt(&parser p) -> @ast::stmt {
|
||||||
auto cdir = parse_crate_directive(p, []);
|
auto cdir = parse_crate_directive(p, ~[]);
|
||||||
ret @spanned(cdir.span.lo, cdir.span.hi,
|
ret @spanned(cdir.span.lo, cdir.span.hi,
|
||||||
ast::stmt_crate_directive(@cdir));
|
ast::stmt_crate_directive(@cdir));
|
||||||
}
|
}
|
||||||
@ -1497,7 +1497,7 @@ fn parse_source_stmt(&parser p) -> @ast::stmt {
|
|||||||
auto item_attrs;
|
auto item_attrs;
|
||||||
alt (parse_outer_attrs_or_ext(p)) {
|
alt (parse_outer_attrs_or_ext(p)) {
|
||||||
case (none) {
|
case (none) {
|
||||||
item_attrs = [];
|
item_attrs = ~[];
|
||||||
}
|
}
|
||||||
case (some(left(?attrs))) {
|
case (some(left(?attrs))) {
|
||||||
item_attrs = attrs;
|
item_attrs = attrs;
|
||||||
@ -1511,7 +1511,7 @@ fn parse_source_stmt(&parser p) -> @ast::stmt {
|
|||||||
auto maybe_item = parse_item(p, item_attrs);
|
auto maybe_item = parse_item(p, item_attrs);
|
||||||
|
|
||||||
// If we have attributes then we should have an item
|
// If we have attributes then we should have an item
|
||||||
if (vec::len(item_attrs) > 0u) {
|
if (ivec::len(item_attrs) > 0u) {
|
||||||
alt (maybe_item) {
|
alt (maybe_item) {
|
||||||
case (got_item(_)) { /* fallthrough */ }
|
case (got_item(_)) { /* fallthrough */ }
|
||||||
case (_) {
|
case (_) {
|
||||||
@ -1717,7 +1717,7 @@ fn parse_fn_header(&parser p) -> tup(ast::ident, vec[ast::ty_param]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn mk_item(&parser p, uint lo, uint hi, &ast::ident ident, &ast::item_ node,
|
fn mk_item(&parser p, uint lo, uint hi, &ast::ident ident, &ast::item_ node,
|
||||||
&vec[ast::attribute] attrs) -> @ast::item {
|
&ast::attribute[] attrs) -> @ast::item {
|
||||||
ret @rec(ident=ident,
|
ret @rec(ident=ident,
|
||||||
attrs=attrs,
|
attrs=attrs,
|
||||||
id=p.get_id(),
|
id=p.get_id(),
|
||||||
@ -1726,7 +1726,7 @@ fn mk_item(&parser p, uint lo, uint hi, &ast::ident ident, &ast::item_ node,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_item_fn_or_iter(&parser p, ast::purity purity, ast::proto proto,
|
fn parse_item_fn_or_iter(&parser p, ast::purity purity, ast::proto proto,
|
||||||
vec[ast::attribute] attrs) -> @ast::item {
|
&ast::attribute[] attrs) -> @ast::item {
|
||||||
auto lo = p.get_last_lo_pos();
|
auto lo = p.get_last_lo_pos();
|
||||||
auto t = parse_fn_header(p);
|
auto t = parse_fn_header(p);
|
||||||
auto f = parse_fn(p, proto, purity);
|
auto f = parse_fn(p, proto, purity);
|
||||||
@ -1777,7 +1777,7 @@ fn parse_dtor(&parser p) -> @ast::method {
|
|||||||
ret @spanned(lo, f.body.span.hi, m);
|
ret @spanned(lo, f.body.span.hi, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_item_obj(&parser p, ast::layer lyr, vec[ast::attribute] attrs) ->
|
fn parse_item_obj(&parser p, ast::layer lyr, &ast::attribute[] attrs) ->
|
||||||
@ast::item {
|
@ast::item {
|
||||||
auto lo = p.get_last_lo_pos();
|
auto lo = p.get_last_lo_pos();
|
||||||
auto ident = parse_value_ident(p);
|
auto ident = parse_value_ident(p);
|
||||||
@ -1800,7 +1800,7 @@ fn parse_item_obj(&parser p, ast::layer lyr, vec[ast::attribute] attrs) ->
|
|||||||
p.get_id()), attrs);
|
p.get_id()), attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_item_res(&parser p, ast::layer lyr, vec[ast::attribute] attrs) ->
|
fn parse_item_res(&parser p, ast::layer lyr, &ast::attribute[] attrs) ->
|
||||||
@ast::item {
|
@ast::item {
|
||||||
auto lo = p.get_last_lo_pos();
|
auto lo = p.get_last_lo_pos();
|
||||||
auto ident = parse_value_ident(p);
|
auto ident = parse_value_ident(p);
|
||||||
@ -1822,8 +1822,8 @@ fn parse_item_res(&parser p, ast::layer lyr, vec[ast::attribute] attrs) ->
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_mod_items(&parser p, token::token term,
|
fn parse_mod_items(&parser p, token::token term,
|
||||||
vec[ast::attribute] first_item_attrs) -> ast::_mod {
|
&ast::attribute[] first_item_attrs) -> ast::_mod {
|
||||||
auto view_items = if (vec::len(first_item_attrs) == 0u) {
|
auto view_items = if (ivec::len(first_item_attrs) == 0u) {
|
||||||
parse_view(p)
|
parse_view(p)
|
||||||
} else {
|
} else {
|
||||||
// Shouldn't be any view items since we've already parsed an item attr
|
// Shouldn't be any view items since we've already parsed an item attr
|
||||||
@ -1833,7 +1833,7 @@ fn parse_mod_items(&parser p, token::token term,
|
|||||||
auto initial_attrs = first_item_attrs;
|
auto initial_attrs = first_item_attrs;
|
||||||
while (p.peek() != term) {
|
while (p.peek() != term) {
|
||||||
auto attrs = initial_attrs + parse_outer_attributes(p);
|
auto attrs = initial_attrs + parse_outer_attributes(p);
|
||||||
initial_attrs = [];
|
initial_attrs = ~[];
|
||||||
alt (parse_item(p, attrs)) {
|
alt (parse_item(p, attrs)) {
|
||||||
case (got_item(?i)) { vec::push(items, i); }
|
case (got_item(?i)) { vec::push(items, i); }
|
||||||
case (_) {
|
case (_) {
|
||||||
@ -1845,7 +1845,7 @@ fn parse_mod_items(&parser p, token::token term,
|
|||||||
ret rec(view_items=view_items, items=items);
|
ret rec(view_items=view_items, items=items);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_item_const(&parser p, vec[ast::attribute] attrs) -> @ast::item {
|
fn parse_item_const(&parser p, &ast::attribute[] attrs) -> @ast::item {
|
||||||
auto lo = p.get_last_lo_pos();
|
auto lo = p.get_last_lo_pos();
|
||||||
auto ty = parse_ty(p);
|
auto ty = parse_ty(p);
|
||||||
auto id = parse_value_ident(p);
|
auto id = parse_value_ident(p);
|
||||||
@ -1856,21 +1856,20 @@ fn parse_item_const(&parser p, vec[ast::attribute] attrs) -> @ast::item {
|
|||||||
ret mk_item(p, lo, hi, id, ast::item_const(ty, e), attrs);
|
ret mk_item(p, lo, hi, id, ast::item_const(ty, e), attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_item_mod(&parser p, vec[ast::attribute] attrs) -> @ast::item {
|
fn parse_item_mod(&parser p, &ast::attribute[] attrs) -> @ast::item {
|
||||||
auto lo = p.get_last_lo_pos();
|
auto lo = p.get_last_lo_pos();
|
||||||
auto id = parse_ident(p);
|
auto id = parse_ident(p);
|
||||||
expect(p, token::LBRACE);
|
expect(p, token::LBRACE);
|
||||||
auto inner_attrs = parse_inner_attrs_and_next(p);
|
auto inner_attrs = parse_inner_attrs_and_next(p);
|
||||||
auto first_item_outer_attrs = inner_attrs._1;
|
auto first_item_outer_attrs = inner_attrs._1;
|
||||||
auto m = parse_mod_items(p, token::RBRACE,
|
auto m = parse_mod_items(p, token::RBRACE, first_item_outer_attrs);
|
||||||
first_item_outer_attrs);
|
|
||||||
auto hi = p.get_hi_pos();
|
auto hi = p.get_hi_pos();
|
||||||
expect(p, token::RBRACE);
|
expect(p, token::RBRACE);
|
||||||
ret mk_item(p, lo, hi, id, ast::item_mod(m), attrs + inner_attrs._0);
|
ret mk_item(p, lo, hi, id, ast::item_mod(m), attrs + inner_attrs._0);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_item_native_type(&parser p,
|
fn parse_item_native_type(&parser p, &ast::attribute[] attrs)
|
||||||
&vec[ast::attribute] attrs) -> @ast::native_item {
|
-> @ast::native_item {
|
||||||
auto t = parse_type_decl(p);
|
auto t = parse_type_decl(p);
|
||||||
auto hi = p.get_hi_pos();
|
auto hi = p.get_hi_pos();
|
||||||
expect(p, token::SEMI);
|
expect(p, token::SEMI);
|
||||||
@ -1881,8 +1880,8 @@ fn parse_item_native_type(&parser p,
|
|||||||
span=rec(lo=t._0, hi=hi));
|
span=rec(lo=t._0, hi=hi));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_item_native_fn(&parser p,
|
fn parse_item_native_fn(&parser p, &ast::attribute[] attrs)
|
||||||
&vec[ast::attribute] attrs) -> @ast::native_item {
|
-> @ast::native_item {
|
||||||
auto lo = p.get_last_lo_pos();
|
auto lo = p.get_last_lo_pos();
|
||||||
auto t = parse_fn_header(p);
|
auto t = parse_fn_header(p);
|
||||||
auto decl = parse_fn_decl(p, ast::impure_fn);
|
auto decl = parse_fn_decl(p, ast::impure_fn);
|
||||||
@ -1900,8 +1899,8 @@ fn parse_item_native_fn(&parser p,
|
|||||||
span=rec(lo=lo, hi=hi));
|
span=rec(lo=lo, hi=hi));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_native_item(&parser p,
|
fn parse_native_item(&parser p, &ast::attribute[] attrs)
|
||||||
&vec[ast::attribute] attrs) -> @ast::native_item {
|
-> @ast::native_item {
|
||||||
parse_layer(p);
|
parse_layer(p);
|
||||||
if (eat_word(p, "type")) {
|
if (eat_word(p, "type")) {
|
||||||
ret parse_item_native_type(p, attrs);
|
ret parse_item_native_type(p, attrs);
|
||||||
@ -1911,9 +1910,9 @@ fn parse_native_item(&parser p,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_native_mod_items(&parser p, &str native_name, ast::native_abi abi,
|
fn parse_native_mod_items(&parser p, &str native_name, ast::native_abi abi,
|
||||||
&vec[ast::attribute] first_item_attrs) ->
|
&ast::attribute[] first_item_attrs)
|
||||||
ast::native_mod {
|
-> ast::native_mod {
|
||||||
auto view_items = if (vec::len(first_item_attrs) == 0u) {
|
auto view_items = if (ivec::len(first_item_attrs) == 0u) {
|
||||||
parse_native_view(p)
|
parse_native_view(p)
|
||||||
} else {
|
} else {
|
||||||
// Shouldn't be any view items since we've already parsed an item attr
|
// Shouldn't be any view items since we've already parsed an item attr
|
||||||
@ -1923,7 +1922,7 @@ fn parse_native_mod_items(&parser p, &str native_name, ast::native_abi abi,
|
|||||||
auto initial_attrs = first_item_attrs;
|
auto initial_attrs = first_item_attrs;
|
||||||
while (p.peek() != token::RBRACE) {
|
while (p.peek() != token::RBRACE) {
|
||||||
auto attrs = initial_attrs + parse_outer_attributes(p);
|
auto attrs = initial_attrs + parse_outer_attributes(p);
|
||||||
initial_attrs = [];
|
initial_attrs = ~[];
|
||||||
items += [parse_native_item(p, attrs)];
|
items += [parse_native_item(p, attrs)];
|
||||||
}
|
}
|
||||||
ret rec(native_name=native_name,
|
ret rec(native_name=native_name,
|
||||||
@ -1932,7 +1931,7 @@ fn parse_native_mod_items(&parser p, &str native_name, ast::native_abi abi,
|
|||||||
items=items);
|
items=items);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_item_native_mod(&parser p, vec[ast::attribute] attrs) -> @ast::item {
|
fn parse_item_native_mod(&parser p, &ast::attribute[] attrs) -> @ast::item {
|
||||||
auto lo = p.get_last_lo_pos();
|
auto lo = p.get_last_lo_pos();
|
||||||
auto abi = ast::native_abi_cdecl;
|
auto abi = ast::native_abi_cdecl;
|
||||||
if (!is_word(p, "mod")) {
|
if (!is_word(p, "mod")) {
|
||||||
@ -1972,7 +1971,7 @@ fn parse_type_decl(&parser p) -> tup(uint, ast::ident) {
|
|||||||
ret tup(lo, id);
|
ret tup(lo, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_item_type(&parser p, vec[ast::attribute] attrs) -> @ast::item {
|
fn parse_item_type(&parser p, &ast::attribute[] attrs) -> @ast::item {
|
||||||
auto t = parse_type_decl(p);
|
auto t = parse_type_decl(p);
|
||||||
auto tps = parse_ty_params(p);
|
auto tps = parse_ty_params(p);
|
||||||
expect(p, token::EQ);
|
expect(p, token::EQ);
|
||||||
@ -1982,7 +1981,7 @@ fn parse_item_type(&parser p, vec[ast::attribute] attrs) -> @ast::item {
|
|||||||
ret mk_item(p, t._0, hi, t._1, ast::item_ty(ty, tps), attrs);
|
ret mk_item(p, t._0, hi, t._1, ast::item_ty(ty, tps), attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_item_tag(&parser p, vec[ast::attribute] attrs) -> @ast::item {
|
fn parse_item_tag(&parser p, &ast::attribute[] attrs) -> @ast::item {
|
||||||
auto lo = p.get_last_lo_pos();
|
auto lo = p.get_last_lo_pos();
|
||||||
auto id = parse_ident(p);
|
auto id = parse_ident(p);
|
||||||
auto ty_params = parse_ty_params(p);
|
auto ty_params = parse_ty_params(p);
|
||||||
@ -2061,7 +2060,7 @@ fn parse_auth(&parser p) -> ast::_auth {
|
|||||||
|
|
||||||
tag parsed_item { got_item(@ast::item); no_item; fn_no_item; }
|
tag parsed_item { got_item(@ast::item); no_item; fn_no_item; }
|
||||||
|
|
||||||
fn parse_item(&parser p, vec[ast::attribute] attrs) -> parsed_item {
|
fn parse_item(&parser p, &ast::attribute[] attrs) -> parsed_item {
|
||||||
if (eat_word(p, "const")) {
|
if (eat_word(p, "const")) {
|
||||||
ret got_item(parse_item_const(p, attrs));
|
ret got_item(parse_item_const(p, attrs));
|
||||||
} else if (eat_word(p, "fn")) {
|
} else if (eat_word(p, "fn")) {
|
||||||
@ -2095,8 +2094,7 @@ fn parse_item(&parser p, vec[ast::attribute] attrs) -> parsed_item {
|
|||||||
|
|
||||||
// A type to distingush between the parsing of item attributes or syntax
|
// A type to distingush between the parsing of item attributes or syntax
|
||||||
// extensions, which both begin with token.POUND
|
// extensions, which both begin with token.POUND
|
||||||
type attr_or_ext = option::t[either::t[vec[ast::attribute],
|
type attr_or_ext = option::t[either::t[ast::attribute[], @ast::expr]];
|
||||||
@ast::expr]];
|
|
||||||
|
|
||||||
fn parse_outer_attrs_or_ext(&parser p) -> attr_or_ext {
|
fn parse_outer_attrs_or_ext(&parser p) -> attr_or_ext {
|
||||||
if (p.peek() == token::POUND) {
|
if (p.peek() == token::POUND) {
|
||||||
@ -2104,7 +2102,7 @@ fn parse_outer_attrs_or_ext(&parser p) -> attr_or_ext {
|
|||||||
p.bump();
|
p.bump();
|
||||||
if (p.peek() == token::LBRACKET) {
|
if (p.peek() == token::LBRACKET) {
|
||||||
auto first_attr = parse_attribute_naked(p, ast::attr_outer, lo);
|
auto first_attr = parse_attribute_naked(p, ast::attr_outer, lo);
|
||||||
ret some(left([first_attr] + parse_outer_attributes(p)));
|
ret some(left(~[first_attr] + parse_outer_attributes(p)));
|
||||||
} else {
|
} else {
|
||||||
ret some(right(parse_syntax_ext_naked(p, lo)));
|
ret some(right(parse_syntax_ext_naked(p, lo)));
|
||||||
}
|
}
|
||||||
@ -2114,10 +2112,10 @@ fn parse_outer_attrs_or_ext(&parser p) -> attr_or_ext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse attributes that appear before an item
|
// Parse attributes that appear before an item
|
||||||
fn parse_outer_attributes(&parser p) -> vec[ast::attribute] {
|
fn parse_outer_attributes(&parser p) -> ast::attribute[] {
|
||||||
let vec[ast::attribute] attrs = [];
|
let ast::attribute[] attrs = ~[];
|
||||||
while (p.peek() == token::POUND) {
|
while (p.peek() == token::POUND) {
|
||||||
attrs += [parse_attribute(p, ast::attr_outer)];
|
attrs += ~[parse_attribute(p, ast::attr_outer)];
|
||||||
}
|
}
|
||||||
ret attrs;
|
ret attrs;
|
||||||
}
|
}
|
||||||
@ -2143,22 +2141,22 @@ fn parse_attribute_naked(&parser p, ast::attr_style style,
|
|||||||
// next item (since we can't know whether the attribute is an inner attribute
|
// next item (since we can't know whether the attribute is an inner attribute
|
||||||
// of the containing item or an outer attribute of the first contained item
|
// of the containing item or an outer attribute of the first contained item
|
||||||
// until we see the semi).
|
// until we see the semi).
|
||||||
fn parse_inner_attrs_and_next(&parser p) -> tup(vec[ast::attribute],
|
fn parse_inner_attrs_and_next(&parser p) -> tup(ast::attribute[],
|
||||||
vec[ast::attribute]) {
|
ast::attribute[]) {
|
||||||
let vec[ast::attribute] inner_attrs = [];
|
let ast::attribute[] inner_attrs = ~[];
|
||||||
let vec[ast::attribute] next_outer_attrs = [];
|
let ast::attribute[] next_outer_attrs = ~[];
|
||||||
while (p.peek() == token::POUND) {
|
while (p.peek() == token::POUND) {
|
||||||
auto attr = parse_attribute(p, ast::attr_inner);
|
auto attr = parse_attribute(p, ast::attr_inner);
|
||||||
if (p.peek() == token::SEMI) {
|
if (p.peek() == token::SEMI) {
|
||||||
p.bump();
|
p.bump();
|
||||||
inner_attrs += [attr];
|
inner_attrs += ~[attr];
|
||||||
} else {
|
} else {
|
||||||
// It's not really an inner attribute
|
// It's not really an inner attribute
|
||||||
auto outer_attr = spanned(attr.span.lo,
|
auto outer_attr = spanned(attr.span.lo,
|
||||||
attr.span.hi,
|
attr.span.hi,
|
||||||
rec(style=ast::attr_outer,
|
rec(style=ast::attr_outer,
|
||||||
value=attr.node.value));
|
value=attr.node.value));
|
||||||
next_outer_attrs += [outer_attr];
|
next_outer_attrs += ~[outer_attr];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2339,8 +2337,7 @@ fn parse_crate_from_source_file(&str input, &ast::crate_cfg cfg,
|
|||||||
auto first_item_outer_attrs = crate_attrs._1;
|
auto first_item_outer_attrs = crate_attrs._1;
|
||||||
auto m = parse_mod_items(p, token::EOF,
|
auto m = parse_mod_items(p, token::EOF,
|
||||||
first_item_outer_attrs);
|
first_item_outer_attrs);
|
||||||
let vec[@ast::crate_directive] cdirs = [];
|
ret @spanned(lo, p.get_lo_pos(), rec(directives=[],
|
||||||
ret @spanned(lo, p.get_lo_pos(), rec(directives=cdirs,
|
|
||||||
module=m,
|
module=m,
|
||||||
attrs=crate_attrs._0,
|
attrs=crate_attrs._0,
|
||||||
config=p.get_cfg()));
|
config=p.get_cfg()));
|
||||||
@ -2361,14 +2358,13 @@ fn parse_str(&parser p) -> ast::ident {
|
|||||||
// Each crate file is a sequence of directives.
|
// Each crate file is a sequence of directives.
|
||||||
//
|
//
|
||||||
// Each directive imperatively extends its environment with 0 or more items.
|
// Each directive imperatively extends its environment with 0 or more items.
|
||||||
fn parse_crate_directive(&parser p, vec[ast::attribute] first_outer_attr)
|
fn parse_crate_directive(&parser p, &ast::attribute[] first_outer_attr)
|
||||||
-> ast::crate_directive {
|
-> ast::crate_directive {
|
||||||
|
|
||||||
// Collect the next attributes
|
// Collect the next attributes
|
||||||
auto outer_attrs = first_outer_attr
|
auto outer_attrs = first_outer_attr + parse_outer_attributes(p);
|
||||||
+ parse_outer_attributes(p);
|
|
||||||
// In a crate file outer attributes are only going to apply to mods
|
// In a crate file outer attributes are only going to apply to mods
|
||||||
auto expect_mod = vec::len(outer_attrs) > 0u;
|
auto expect_mod = ivec::len(outer_attrs) > 0u;
|
||||||
|
|
||||||
auto lo = p.get_lo_pos();
|
auto lo = p.get_lo_pos();
|
||||||
if (expect_mod || is_word(p, "mod")) {
|
if (expect_mod || is_word(p, "mod")) {
|
||||||
@ -2423,13 +2419,13 @@ fn parse_crate_directive(&parser p, vec[ast::attribute] first_outer_attr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse_crate_directives(&parser p, token::token term,
|
fn parse_crate_directives(&parser p, token::token term,
|
||||||
vec[ast::attribute] first_outer_attr) ->
|
&ast::attribute[] first_outer_attr) ->
|
||||||
vec[@ast::crate_directive] {
|
vec[@ast::crate_directive] {
|
||||||
|
|
||||||
// This is pretty ugly. If we have an outer attribute then we can't accept
|
// This is pretty ugly. If we have an outer attribute then we can't accept
|
||||||
// seeing the terminator next, so if we do see it then fail the same way
|
// seeing the terminator next, so if we do see it then fail the same way
|
||||||
// parse_crate_directive would
|
// parse_crate_directive would
|
||||||
if (vec::len(first_outer_attr) > 0u && p.peek() == term) {
|
if (ivec::len(first_outer_attr) > 0u && p.peek() == term) {
|
||||||
expect_word(p, "mod");
|
expect_word(p, "mod");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +242,7 @@ fn commasep_exprs(&ps s, breaks b, vec[@ast::expr] exprs) {
|
|||||||
commasep_cmnt(s, b, exprs, print_expr, expr_span);
|
commasep_cmnt(s, b, exprs, print_expr, expr_span);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_mod(&ps s, ast::_mod _mod, &vec[ast::attribute] attrs) {
|
fn print_mod(&ps s, ast::_mod _mod, &ast::attribute[] attrs) {
|
||||||
print_inner_attributes(s, attrs);
|
print_inner_attributes(s, attrs);
|
||||||
for (@ast::view_item vitem in _mod.view_items) {
|
for (@ast::view_item vitem in _mod.view_items) {
|
||||||
print_view_item(s, vitem);
|
print_view_item(s, vitem);
|
||||||
@ -533,7 +533,7 @@ fn print_item(&ps s, &@ast::item item) {
|
|||||||
s.ann.post(ann_node);
|
s.ann.post(ann_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_outer_attributes(&ps s, vec[ast::attribute] attrs) {
|
fn print_outer_attributes(&ps s, &ast::attribute[] attrs) {
|
||||||
auto count = 0;
|
auto count = 0;
|
||||||
for (ast::attribute attr in attrs) {
|
for (ast::attribute attr in attrs) {
|
||||||
alt (attr.node.style) {
|
alt (attr.node.style) {
|
||||||
@ -544,7 +544,7 @@ fn print_outer_attributes(&ps s, vec[ast::attribute] attrs) {
|
|||||||
if (count > 0) { hardbreak_if_not_bol(s); }
|
if (count > 0) { hardbreak_if_not_bol(s); }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_inner_attributes(&ps s, vec[ast::attribute] attrs) {
|
fn print_inner_attributes(&ps s, &ast::attribute[] attrs) {
|
||||||
auto count = 0;
|
auto count = 0;
|
||||||
for (ast::attribute attr in attrs) {
|
for (ast::attribute attr in attrs) {
|
||||||
alt (attr.node.style) {
|
alt (attr.node.style) {
|
||||||
|
Loading…
Reference in New Issue
Block a user