2012-12-04 00:48:01 +00:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-07-05 23:07:53 +00:00
|
|
|
// Functions for building ASTs, without having to fuss with spans.
|
|
|
|
//
|
|
|
|
// To start with, it will be use dummy spans, but it might someday do
|
|
|
|
// something smarter.
|
|
|
|
|
2013-01-09 03:37:25 +00:00
|
|
|
use core::prelude::*;
|
|
|
|
|
2012-09-04 18:37:29 +00:00
|
|
|
use ast::{ident, node_id};
|
2012-12-23 22:41:37 +00:00
|
|
|
use ast;
|
2013-01-30 17:56:33 +00:00
|
|
|
use ast_util::{ident_to_path};
|
2012-12-23 22:41:37 +00:00
|
|
|
use ast_util;
|
|
|
|
use attr;
|
2013-01-30 17:56:33 +00:00
|
|
|
use codemap::{span, respan, dummy_sp};
|
|
|
|
use codemap;
|
2013-01-09 03:37:25 +00:00
|
|
|
use ext::base::{ext_ctxt, mk_ctxt};
|
2012-12-13 21:05:22 +00:00
|
|
|
use ext::quote::rt::*;
|
2013-02-15 05:50:03 +00:00
|
|
|
use opt_vec;
|
|
|
|
use opt_vec::OptVec;
|
2012-07-05 23:07:53 +00:00
|
|
|
|
2012-12-23 22:41:37 +00:00
|
|
|
use core::vec;
|
|
|
|
|
2012-07-24 01:50:53 +00:00
|
|
|
// Transitional reexports so qquote can find the paths it is looking for
|
|
|
|
mod syntax {
|
2012-09-08 01:08:21 +00:00
|
|
|
pub use ext;
|
|
|
|
pub use parse;
|
2012-07-24 01:50:53 +00:00
|
|
|
}
|
|
|
|
|
2013-01-29 21:54:06 +00:00
|
|
|
pub fn path(ids: ~[ident], span: span) -> @ast::path {
|
2013-01-13 18:48:09 +00:00
|
|
|
@ast::path { span: span,
|
|
|
|
global: false,
|
|
|
|
idents: ids,
|
|
|
|
rp: None,
|
|
|
|
types: ~[] }
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
|
|
|
|
2013-01-29 21:54:06 +00:00
|
|
|
pub fn path_global(ids: ~[ident], span: span) -> @ast::path {
|
2013-01-13 18:48:09 +00:00
|
|
|
@ast::path { span: span,
|
|
|
|
global: true,
|
|
|
|
idents: ids,
|
|
|
|
rp: None,
|
|
|
|
types: ~[] }
|
2012-12-23 22:41:37 +00:00
|
|
|
}
|
|
|
|
|
2013-01-29 21:54:06 +00:00
|
|
|
pub trait append_types {
|
2012-10-15 21:56:42 +00:00
|
|
|
fn add_ty(ty: @ast::Ty) -> @ast::path;
|
|
|
|
fn add_tys(+tys: ~[@ast::Ty]) -> @ast::path;
|
2012-07-11 22:00:40 +00:00
|
|
|
}
|
2012-07-05 23:07:53 +00:00
|
|
|
|
2013-02-27 01:12:00 +00:00
|
|
|
impl append_types for @ast::path {
|
2012-10-15 21:56:42 +00:00
|
|
|
fn add_ty(ty: @ast::Ty) -> @ast::path {
|
2013-01-13 18:48:09 +00:00
|
|
|
@ast::path { types: vec::append_one(self.types, ty),
|
|
|
|
.. *self}
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
|
|
|
|
2012-10-15 21:56:42 +00:00
|
|
|
fn add_tys(+tys: ~[@ast::Ty]) -> @ast::path {
|
2013-01-13 18:48:09 +00:00
|
|
|
@ast::path { types: vec::append(self.types, tys),
|
|
|
|
.. *self}
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-26 00:57:39 +00:00
|
|
|
pub trait ext_ctxt_ast_builder {
|
2013-02-15 05:50:03 +00:00
|
|
|
fn ty_param(&self, id: ast::ident, bounds: @OptVec<ast::TyParamBound>)
|
|
|
|
-> ast::TyParam;
|
2013-02-17 07:51:55 +00:00
|
|
|
fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg;
|
|
|
|
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,
|
2012-07-11 22:00:40 +00:00
|
|
|
+inputs: ~[ast::arg],
|
2012-10-15 21:56:42 +00:00
|
|
|
output: @ast::Ty,
|
2013-02-15 05:50:03 +00:00
|
|
|
+generics: Generics,
|
2012-07-11 22:00:40 +00:00
|
|
|
+body: ast::blk) -> @ast::item;
|
2013-02-17 07:51:55 +00:00
|
|
|
fn item_fn(&self, name: ident,
|
2012-07-11 22:00:40 +00:00
|
|
|
+inputs: ~[ast::arg],
|
2012-10-15 21:56:42 +00:00
|
|
|
output: @ast::Ty,
|
2012-07-11 22:00:40 +00:00
|
|
|
+body: ast::blk) -> @ast::item;
|
2013-02-17 07:51:55 +00:00
|
|
|
fn item_enum_poly(&self, name: ident,
|
2012-08-17 18:26:35 +00:00
|
|
|
span: span,
|
2012-08-09 00:14:25 +00:00
|
|
|
+enum_definition: ast::enum_def,
|
2013-02-15 05:50:03 +00:00
|
|
|
+generics: Generics) -> @ast::item;
|
2013-02-17 07:51:55 +00:00
|
|
|
fn item_enum(&self, name: ident, span: span,
|
2012-08-17 18:26:35 +00:00
|
|
|
+enum_definition: ast::enum_def) -> @ast::item;
|
2013-02-17 07:51:55 +00:00
|
|
|
fn item_struct_poly(&self, name: ident, span: span,
|
2013-02-17 05:55:36 +00:00
|
|
|
struct_def: ast::struct_def,
|
2013-02-15 05:50:03 +00:00
|
|
|
+generics: Generics) -> @ast::item;
|
2013-02-17 07:51:55 +00:00
|
|
|
fn item_struct(&self, name: ident, span: span,
|
2013-02-17 05:55:36 +00:00
|
|
|
struct_def: ast::struct_def) -> @ast::item;
|
2013-02-17 10:24:57 +00:00
|
|
|
fn struct_expr(&self, path: @ast::path,
|
|
|
|
fields: ~[ast::field]) -> @ast::expr;
|
|
|
|
fn variant(&self, name: ident, span: span,
|
|
|
|
+tys: ~[@ast::Ty]) -> ast::variant;
|
|
|
|
fn item_mod(&self, name: ident, span: span,
|
|
|
|
+items: ~[@ast::item]) -> @ast::item;
|
2013-02-17 07:51:55 +00:00
|
|
|
fn ty_path_ast_builder(&self, path: @ast::path) -> @ast::Ty;
|
|
|
|
fn item_ty_poly(&self, name: ident,
|
2012-08-17 18:26:35 +00:00
|
|
|
span: span,
|
2012-10-15 21:56:42 +00:00
|
|
|
ty: @ast::Ty,
|
2013-02-15 05:50:03 +00:00
|
|
|
+generics: Generics) -> @ast::item;
|
2013-02-17 07:51:55 +00:00
|
|
|
fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item;
|
2013-02-15 05:50:03 +00:00
|
|
|
fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> ~[@ast::Ty];
|
|
|
|
fn ty_vars_global(&self, ty_params: &OptVec<ast::TyParam>) -> ~[@ast::Ty];
|
2013-02-17 07:51:55 +00:00
|
|
|
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 ty_option(&self, ty: @ast::Ty) -> @ast::Ty;
|
|
|
|
fn ty_infer(&self) -> @ast::Ty;
|
|
|
|
fn ty_nil_ast_builder(&self) -> @ast::Ty;
|
2013-02-15 05:50:03 +00:00
|
|
|
fn strip_bounds(&self, bounds: &Generics) -> Generics;
|
2012-07-11 22:00:40 +00:00
|
|
|
}
|
|
|
|
|
2013-02-27 01:12:00 +00:00
|
|
|
impl ext_ctxt_ast_builder for ext_ctxt {
|
2013-02-17 07:51:55 +00:00
|
|
|
fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty {
|
2013-01-09 03:37:25 +00:00
|
|
|
self.ty_path_ast_builder(path_global(~[
|
|
|
|
self.ident_of(~"core"),
|
|
|
|
self.ident_of(~"option"),
|
|
|
|
self.ident_of(~"Option")
|
|
|
|
], dummy_sp()).add_ty(ty))
|
2012-08-07 18:46:52 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn block_expr(&self, b: ast::blk) -> @ast::expr {
|
2013-01-15 21:51:43 +00:00
|
|
|
@expr {
|
|
|
|
id: self.next_id(),
|
|
|
|
callee_id: self.next_id(),
|
|
|
|
node: ast::expr_block(b),
|
|
|
|
span: dummy_sp(),
|
|
|
|
}
|
2012-07-24 01:50:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn stmt_expr(&self, e: @ast::expr) -> @ast::stmt {
|
2012-12-27 19:36:00 +00:00
|
|
|
@spanned { node: ast::stmt_expr(e, self.next_id()),
|
|
|
|
span: dummy_sp()}
|
2012-07-24 01:50:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt {
|
|
|
|
let ext_cx = *self;
|
2012-12-07 00:19:50 +00:00
|
|
|
quote_stmt!( let $ident = $e; )
|
2012-07-24 01:50:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field {
|
2013-01-15 05:36:27 +00:00
|
|
|
spanned {
|
|
|
|
node: ast::field_ { mutbl: ast::m_imm, ident: name, expr: e },
|
|
|
|
span: dummy_sp(),
|
|
|
|
}
|
2012-07-24 01:50:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field {
|
2013-01-15 05:36:27 +00:00
|
|
|
spanned {
|
2013-01-15 23:03:49 +00:00
|
|
|
node: ast::ty_field_ {
|
2013-01-15 05:36:27 +00:00
|
|
|
ident: name,
|
|
|
|
mt: ast::mt { ty: ty, mutbl: ast::m_imm },
|
|
|
|
},
|
|
|
|
span: dummy_sp(),
|
|
|
|
}
|
2012-07-23 21:46:39 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn ty_infer(&self) -> @ast::Ty {
|
2013-01-15 22:59:39 +00:00
|
|
|
@ast::Ty {
|
|
|
|
id: self.next_id(),
|
|
|
|
node: ast::ty_infer,
|
|
|
|
span: dummy_sp(),
|
|
|
|
}
|
2012-07-24 01:50:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 05:50:03 +00:00
|
|
|
fn ty_param(&self, id: ast::ident, bounds: @OptVec<ast::TyParamBound>)
|
|
|
|
-> ast::TyParam
|
2012-07-05 23:07:53 +00:00
|
|
|
{
|
2013-02-15 05:50:03 +00:00
|
|
|
ast::TyParam { ident: id, id: self.next_id(), bounds: bounds }
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg {
|
2013-01-16 00:05:20 +00:00
|
|
|
ast::arg {
|
2013-01-15 04:52:28 +00:00
|
|
|
mode: ast::infer(self.next_id()),
|
2013-01-03 16:45:07 +00:00
|
|
|
is_mutbl: false,
|
2013-01-15 04:52:28 +00:00
|
|
|
ty: ty,
|
|
|
|
pat: @ast::pat {
|
|
|
|
id: self.next_id(),
|
2012-11-07 02:41:06 +00:00
|
|
|
node: ast::pat_ident(
|
2013-01-10 18:59:58 +00:00
|
|
|
ast::bind_by_copy,
|
2012-11-13 03:32:48 +00:00
|
|
|
ast_util::ident_to_path(dummy_sp(), name),
|
2012-11-07 02:41:06 +00:00
|
|
|
None),
|
2013-01-15 04:52:28 +00:00
|
|
|
span: dummy_sp(),
|
|
|
|
},
|
|
|
|
id: self.next_id(),
|
|
|
|
}
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn block(&self, +stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk {
|
2013-01-15 03:35:08 +00:00
|
|
|
let blk = ast::blk_ {
|
|
|
|
view_items: ~[],
|
|
|
|
stmts: stmts,
|
|
|
|
expr: Some(e),
|
|
|
|
id: self.next_id(),
|
|
|
|
rules: ast::default_blk,
|
|
|
|
};
|
2012-07-05 23:07:53 +00:00
|
|
|
|
2012-12-27 19:36:00 +00:00
|
|
|
spanned { node: blk, span: dummy_sp() }
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn expr_block(&self, e: @ast::expr) -> ast::blk {
|
2012-07-24 01:50:53 +00:00
|
|
|
self.block(~[], e)
|
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn fn_decl(&self, +inputs: ~[ast::arg],
|
2012-10-15 21:56:42 +00:00
|
|
|
output: @ast::Ty) -> ast::fn_decl {
|
2013-01-16 00:05:20 +00:00
|
|
|
ast::fn_decl {
|
|
|
|
inputs: inputs,
|
|
|
|
output: output,
|
|
|
|
cf: ast::return_val,
|
|
|
|
}
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn item(&self, name: ident, span: span,
|
2012-07-05 23:07:53 +00:00
|
|
|
+node: ast::item_) -> @ast::item {
|
2012-08-28 18:11:15 +00:00
|
|
|
|
|
|
|
// XXX: Would be nice if our generated code didn't violate
|
|
|
|
// Rust coding conventions
|
2013-01-14 00:51:48 +00:00
|
|
|
let non_camel_case_attribute = respan(dummy_sp(), ast::attribute_ {
|
2012-08-28 18:11:15 +00:00
|
|
|
style: ast::attr_outer,
|
2012-11-13 03:32:48 +00:00
|
|
|
value: respan(dummy_sp(),
|
2013-02-14 15:34:21 +00:00
|
|
|
ast::meta_list(@~"allow", ~[
|
2012-11-13 03:32:48 +00:00
|
|
|
@respan(dummy_sp(),
|
2013-02-14 15:34:21 +00:00
|
|
|
ast::meta_word(
|
|
|
|
@~"non_camel_case_types"))
|
2012-08-28 18:11:15 +00:00
|
|
|
])),
|
|
|
|
is_sugared_doc: false
|
|
|
|
});
|
|
|
|
|
2013-01-13 21:13:41 +00:00
|
|
|
@ast::item { ident: name,
|
|
|
|
attrs: ~[non_camel_case_attribute],
|
|
|
|
id: self.next_id(),
|
|
|
|
node: node,
|
|
|
|
vis: ast::public,
|
|
|
|
span: span }
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn item_fn_poly(&self, name: ident,
|
2012-07-05 23:07:53 +00:00
|
|
|
+inputs: ~[ast::arg],
|
2012-10-15 21:56:42 +00:00
|
|
|
output: @ast::Ty,
|
2013-02-15 05:50:03 +00:00
|
|
|
+generics: Generics,
|
2012-07-05 23:07:53 +00:00
|
|
|
+body: ast::blk) -> @ast::item {
|
|
|
|
self.item(name,
|
2012-11-13 03:32:48 +00:00
|
|
|
dummy_sp(),
|
2012-07-05 23:07:53 +00:00
|
|
|
ast::item_fn(self.fn_decl(inputs, output),
|
2012-08-24 01:17:16 +00:00
|
|
|
ast::impure_fn,
|
2013-02-15 05:50:03 +00:00
|
|
|
generics,
|
2012-07-05 23:07:53 +00:00
|
|
|
body))
|
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn item_fn(&self, name: ident,
|
2012-07-05 23:07:53 +00:00
|
|
|
+inputs: ~[ast::arg],
|
2012-10-15 21:56:42 +00:00
|
|
|
output: @ast::Ty,
|
2012-07-05 23:07:53 +00:00
|
|
|
+body: ast::blk) -> @ast::item {
|
2013-02-15 05:50:03 +00:00
|
|
|
self.item_fn_poly(name, inputs, output,
|
|
|
|
ast_util::empty_generics(), body)
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn item_enum_poly(&self, name: ident, span: span,
|
2012-08-09 00:14:25 +00:00
|
|
|
+enum_definition: ast::enum_def,
|
2013-02-15 05:50:03 +00:00
|
|
|
+generics: Generics) -> @ast::item {
|
|
|
|
self.item(name, span, ast::item_enum(enum_definition, generics))
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn item_enum(&self, name: ident, span: span,
|
2012-08-17 18:26:35 +00:00
|
|
|
+enum_definition: ast::enum_def) -> @ast::item {
|
2013-02-15 05:50:03 +00:00
|
|
|
self.item_enum_poly(name, span, enum_definition,
|
|
|
|
ast_util::empty_generics())
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn item_struct(&self, name: ident, span: span,
|
2013-02-17 05:55:36 +00:00
|
|
|
struct_def: ast::struct_def) -> @ast::item {
|
2013-02-15 05:50:03 +00:00
|
|
|
self.item_struct_poly(name, span, struct_def,
|
|
|
|
ast_util::empty_generics())
|
2013-02-17 05:55:36 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn item_struct_poly(&self, name: ident, span: span,
|
2013-02-17 05:55:36 +00:00
|
|
|
struct_def: ast::struct_def,
|
2013-02-15 05:50:03 +00:00
|
|
|
+generics: Generics) -> @ast::item {
|
|
|
|
self.item(name, span, ast::item_struct(@struct_def, generics))
|
2013-02-17 05:55:36 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 10:24:57 +00:00
|
|
|
fn struct_expr(&self, path: @ast::path,
|
|
|
|
fields: ~[ast::field]) -> @ast::expr {
|
2013-02-17 05:55:36 +00:00
|
|
|
@ast::expr {
|
|
|
|
id: self.next_id(),
|
|
|
|
callee_id: self.next_id(),
|
|
|
|
node: ast::expr_struct(path, fields, None),
|
|
|
|
span: dummy_sp()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn variant(&self, name: ident, span: span,
|
2012-10-15 21:56:42 +00:00
|
|
|
+tys: ~[@ast::Ty]) -> ast::variant {
|
2013-01-16 00:05:20 +00:00
|
|
|
let args = do tys.map |ty| {
|
|
|
|
ast::variant_arg { ty: *ty, id: self.next_id() }
|
|
|
|
};
|
|
|
|
|
|
|
|
spanned {
|
|
|
|
node: ast::variant_ {
|
|
|
|
name: name,
|
|
|
|
attrs: ~[],
|
|
|
|
kind: ast::tuple_variant_kind(args),
|
|
|
|
id: self.next_id(),
|
|
|
|
disr_expr: None,
|
2013-02-17 05:55:36 +00:00
|
|
|
vis: ast::public
|
|
|
|
},
|
2013-01-16 00:05:20 +00:00
|
|
|
span: span,
|
|
|
|
}
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn item_mod(&self, name: ident, span: span,
|
2012-07-05 23:07:53 +00:00
|
|
|
+items: ~[@ast::item]) -> @ast::item {
|
2013-02-17 07:51:55 +00:00
|
|
|
|
2013-01-09 03:37:25 +00:00
|
|
|
// XXX: Total hack: import `core::kinds::Owned` to work around a
|
2013-02-21 01:07:17 +00:00
|
|
|
// parser bug whereby `fn f<T:::kinds::Owned>` doesn't parse.
|
2013-02-18 02:45:00 +00:00
|
|
|
let vi = ast::view_item_use(~[
|
2013-01-30 17:56:33 +00:00
|
|
|
@codemap::spanned {
|
2013-01-09 03:37:25 +00:00
|
|
|
node: ast::view_path_simple(
|
|
|
|
self.ident_of(~"Owned"),
|
|
|
|
path(
|
|
|
|
~[
|
|
|
|
self.ident_of(~"core"),
|
|
|
|
self.ident_of(~"kinds"),
|
|
|
|
self.ident_of(~"Owned")
|
|
|
|
],
|
2013-01-30 17:56:33 +00:00
|
|
|
codemap::dummy_sp()
|
2013-01-09 03:37:25 +00:00
|
|
|
),
|
|
|
|
ast::type_value_ns,
|
|
|
|
self.next_id()
|
|
|
|
),
|
2013-01-30 17:56:33 +00:00
|
|
|
span: codemap::dummy_sp()
|
2013-01-09 03:37:25 +00:00
|
|
|
}
|
|
|
|
]);
|
2013-01-14 00:51:48 +00:00
|
|
|
let vi = @ast::view_item {
|
2013-01-09 03:37:25 +00:00
|
|
|
node: vi,
|
|
|
|
attrs: ~[],
|
|
|
|
vis: ast::private,
|
2013-01-30 17:56:33 +00:00
|
|
|
span: codemap::dummy_sp()
|
2013-01-09 03:37:25 +00:00
|
|
|
};
|
|
|
|
|
2013-01-16 00:05:20 +00:00
|
|
|
self.item(
|
|
|
|
name,
|
|
|
|
span,
|
|
|
|
ast::item_mod(ast::_mod {
|
|
|
|
view_items: ~[vi],
|
|
|
|
items: items,
|
|
|
|
})
|
|
|
|
)
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn ty_path_ast_builder(&self, path: @ast::path) -> @ast::Ty {
|
2013-01-15 22:59:39 +00:00
|
|
|
@ast::Ty {
|
|
|
|
id: self.next_id(),
|
|
|
|
node: ast::ty_path(path, self.next_id()),
|
|
|
|
span: path.span,
|
|
|
|
}
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn ty_nil_ast_builder(&self) -> @ast::Ty {
|
2013-01-15 22:59:39 +00:00
|
|
|
@ast::Ty {
|
|
|
|
id: self.next_id(),
|
|
|
|
node: ast::ty_nil,
|
|
|
|
span: dummy_sp(),
|
|
|
|
}
|
2012-07-16 21:44:27 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 05:50:03 +00:00
|
|
|
fn strip_bounds(&self, generics: &Generics) -> Generics {
|
|
|
|
let no_bounds = @opt_vec::Empty;
|
|
|
|
let new_params = do generics.ty_params.map |ty_param| {
|
|
|
|
ast::TyParam { bounds: no_bounds, ..copy *ty_param }
|
|
|
|
};
|
|
|
|
Generics { ty_params: new_params, ..*generics }
|
2013-01-28 18:46:43 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn item_ty_poly(&self, name: ident, span: span, ty: @ast::Ty,
|
2013-02-15 05:50:03 +00:00
|
|
|
+generics: Generics) -> @ast::item {
|
|
|
|
self.item(name, span, ast::item_ty(ty, generics))
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 07:51:55 +00:00
|
|
|
fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item {
|
2013-02-15 05:50:03 +00:00
|
|
|
self.item_ty_poly(name, span, ty, ast_util::empty_generics())
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
|
|
|
|
2013-02-15 05:50:03 +00:00
|
|
|
fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> ~[@ast::Ty] {
|
2012-07-24 23:58:48 +00:00
|
|
|
ty_params.map(|p| self.ty_path_ast_builder(
|
2013-02-15 05:50:03 +00:00
|
|
|
path(~[p.ident], dummy_sp()))).to_vec()
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|
2012-12-23 22:41:37 +00:00
|
|
|
|
2013-02-15 05:50:03 +00:00
|
|
|
fn ty_vars_global(&self,
|
|
|
|
ty_params: &OptVec<ast::TyParam>) -> ~[@ast::Ty] {
|
2012-12-23 22:41:37 +00:00
|
|
|
ty_params.map(|p| self.ty_path_ast_builder(
|
2013-02-15 05:50:03 +00:00
|
|
|
path(~[p.ident], dummy_sp()))).to_vec()
|
2012-12-23 22:41:37 +00:00
|
|
|
}
|
2012-07-05 23:07:53 +00:00
|
|
|
}
|