2012-12-03 16:48:01 -08: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 16:07:53 -07: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-08 19:37:25 -08:00
|
|
|
use core::prelude::*;
|
|
|
|
|
|
2013-03-13 22:25:28 -04:00
|
|
|
use abi::AbiSet;
|
|
|
|
|
use ast::{ident, node_id};
|
2012-12-23 17:41:37 -05:00
|
|
|
use ast;
|
|
|
|
|
use ast_util;
|
2013-02-25 14:11:21 -05:00
|
|
|
use codemap::{span, respan, dummy_sp, spanned};
|
2013-01-30 09:56:33 -08:00
|
|
|
use codemap;
|
2013-03-26 16:38:07 -04:00
|
|
|
use ext::base::ext_ctxt;
|
2012-12-13 13:05:22 -08:00
|
|
|
use ext::quote::rt::*;
|
2013-02-14 21:50:03 -08:00
|
|
|
use opt_vec;
|
|
|
|
|
use opt_vec::OptVec;
|
2012-07-05 16:07:53 -07:00
|
|
|
|
2012-12-23 17:41:37 -05:00
|
|
|
use core::vec;
|
|
|
|
|
|
2012-07-23 18:50:53 -07:00
|
|
|
// Transitional reexports so qquote can find the paths it is looking for
|
|
|
|
|
mod syntax {
|
2012-09-07 18:08:21 -07:00
|
|
|
pub use ext;
|
|
|
|
|
pub use parse;
|
2012-07-23 18:50:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 08:28:11 -08:00
|
|
|
pub fn path(+ids: ~[ident], span: span) -> @ast::path {
|
2013-01-13 10:48:09 -08:00
|
|
|
@ast::path { span: span,
|
|
|
|
|
global: false,
|
|
|
|
|
idents: ids,
|
|
|
|
|
rp: None,
|
|
|
|
|
types: ~[] }
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 08:28:11 -08:00
|
|
|
pub fn path_global(+ids: ~[ident], span: span) -> @ast::path {
|
2013-01-13 10:48:09 -08:00
|
|
|
@ast::path { span: span,
|
|
|
|
|
global: true,
|
|
|
|
|
idents: ids,
|
|
|
|
|
rp: None,
|
|
|
|
|
types: ~[] }
|
2012-12-23 17:41:37 -05:00
|
|
|
}
|
|
|
|
|
|
2013-01-29 13:54:06 -08:00
|
|
|
pub trait append_types {
|
2013-02-17 08:28:11 -08:00
|
|
|
fn add_ty(&self, ty: @ast::Ty) -> @ast::path;
|
|
|
|
|
fn add_tys(&self, +tys: ~[@ast::Ty]) -> @ast::path;
|
2012-07-11 15:00:40 -07:00
|
|
|
}
|
2012-07-05 16:07:53 -07:00
|
|
|
|
2013-02-26 17:12:00 -08:00
|
|
|
impl append_types for @ast::path {
|
2013-02-17 08:28:11 -08:00
|
|
|
fn add_ty(&self, ty: @ast::Ty) -> @ast::path {
|
|
|
|
|
@ast::path {
|
|
|
|
|
types: vec::append_one(copy self.types, ty),
|
2013-02-24 21:27:51 -08:00
|
|
|
.. copy **self
|
2013-02-17 08:28:11 -08:00
|
|
|
}
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 08:28:11 -08:00
|
|
|
fn add_tys(&self, +tys: ~[@ast::Ty]) -> @ast::path {
|
|
|
|
|
@ast::path {
|
|
|
|
|
types: vec::append(copy self.types, tys),
|
2013-02-24 21:27:51 -08:00
|
|
|
.. copy **self
|
2013-02-17 08:28:11 -08:00
|
|
|
}
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-25 16:57:39 -08:00
|
|
|
pub trait ext_ctxt_ast_builder {
|
2013-02-14 21:50:03 -08:00
|
|
|
fn ty_param(&self, id: ast::ident, bounds: @OptVec<ast::TyParamBound>)
|
|
|
|
|
-> ast::TyParam;
|
2013-02-17 02:51:55 -05: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;
|
2013-02-17 08:28:11 -08:00
|
|
|
fn item_fn_poly(&self,
|
2013-02-28 07:25:31 -08:00
|
|
|
ame: ident,
|
2012-07-11 15:00:40 -07:00
|
|
|
+inputs: ~[ast::arg],
|
2012-10-15 14:56:42 -07:00
|
|
|
output: @ast::Ty,
|
2013-02-14 21:50:03 -08:00
|
|
|
+generics: Generics,
|
2012-07-11 15:00:40 -07:00
|
|
|
+body: ast::blk) -> @ast::item;
|
2013-02-17 08:28:11 -08:00
|
|
|
fn item_fn(&self,
|
2013-02-28 07:25:31 -08:00
|
|
|
name: ident,
|
2012-07-11 15:00:40 -07:00
|
|
|
+inputs: ~[ast::arg],
|
2012-10-15 14:56:42 -07:00
|
|
|
output: @ast::Ty,
|
2012-07-11 15:00:40 -07:00
|
|
|
+body: ast::blk) -> @ast::item;
|
2013-02-17 08:28:11 -08:00
|
|
|
fn item_enum_poly(&self,
|
2013-02-28 07:25:31 -08:00
|
|
|
name: ident,
|
2012-08-17 11:26:35 -07:00
|
|
|
span: span,
|
2012-08-08 17:14:25 -07:00
|
|
|
+enum_definition: ast::enum_def,
|
2013-02-14 21:50:03 -08:00
|
|
|
+generics: Generics) -> @ast::item;
|
2013-02-28 07:25:31 -08:00
|
|
|
fn item_enum(&self,
|
|
|
|
|
name: ident,
|
|
|
|
|
span: span,
|
2012-08-17 11:26:35 -07:00
|
|
|
+enum_definition: ast::enum_def) -> @ast::item;
|
2013-02-17 08:28:11 -08:00
|
|
|
fn item_struct_poly(&self,
|
2013-02-28 07:25:31 -08:00
|
|
|
name: ident,
|
|
|
|
|
span: span,
|
|
|
|
|
+struct_def: ast::struct_def,
|
2013-02-14 21:50:03 -08:00
|
|
|
+generics: Generics) -> @ast::item;
|
2013-02-28 07:25:31 -08:00
|
|
|
fn item_struct(&self,
|
|
|
|
|
name: ident,
|
|
|
|
|
span: span,
|
2013-02-24 21:27:51 -08:00
|
|
|
+struct_def: ast::struct_def) -> @ast::item;
|
2013-02-28 07:25:31 -08:00
|
|
|
fn struct_expr(&self,
|
|
|
|
|
path: @ast::path,
|
2013-02-24 21:27:51 -08:00
|
|
|
+fields: ~[ast::field]) -> @ast::expr;
|
2013-02-28 07:25:31 -08:00
|
|
|
fn variant(&self,
|
|
|
|
|
name: ident,
|
|
|
|
|
span: span,
|
2013-02-17 05:24:57 -05:00
|
|
|
+tys: ~[@ast::Ty]) -> ast::variant;
|
2013-02-28 07:25:31 -08:00
|
|
|
fn item_mod(&self,
|
|
|
|
|
name: ident,
|
|
|
|
|
span: span,
|
2013-02-17 05:24:57 -05:00
|
|
|
+items: ~[@ast::item]) -> @ast::item;
|
2013-02-17 02:51:55 -05:00
|
|
|
fn ty_path_ast_builder(&self, path: @ast::path) -> @ast::Ty;
|
2013-02-28 07:25:31 -08:00
|
|
|
fn item_ty_poly(&self,
|
|
|
|
|
name: ident,
|
2012-08-17 11:26:35 -07:00
|
|
|
span: span,
|
2012-10-15 14:56:42 -07:00
|
|
|
ty: @ast::Ty,
|
2013-02-14 21:50:03 -08:00
|
|
|
+generics: Generics) -> @ast::item;
|
2013-02-17 02:51:55 -05:00
|
|
|
fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item;
|
2013-02-14 21:50:03 -08: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 02:51:55 -05: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;
|
2013-02-17 08:28:11 -08:00
|
|
|
fn block_expr(&self, +b: ast::blk) -> @ast::expr;
|
2013-02-17 02:51:55 -05:00
|
|
|
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-14 21:50:03 -08:00
|
|
|
fn strip_bounds(&self, bounds: &Generics) -> Generics;
|
2012-07-11 15:00:40 -07:00
|
|
|
}
|
|
|
|
|
|
2013-03-12 13:00:50 -07:00
|
|
|
impl ext_ctxt_ast_builder for @ext_ctxt {
|
2013-02-17 02:51:55 -05:00
|
|
|
fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty {
|
2013-01-08 19:37:25 -08: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 11:46:52 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 08:28:11 -08:00
|
|
|
fn block_expr(&self, +b: ast::blk) -> @ast::expr {
|
2013-01-15 13:51:43 -08:00
|
|
|
@expr {
|
|
|
|
|
id: self.next_id(),
|
|
|
|
|
callee_id: self.next_id(),
|
|
|
|
|
node: ast::expr_block(b),
|
|
|
|
|
span: dummy_sp(),
|
|
|
|
|
}
|
2012-07-23 18:50:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn stmt_expr(&self, e: @ast::expr) -> @ast::stmt {
|
2012-12-27 14:36:00 -05:00
|
|
|
@spanned { node: ast::stmt_expr(e, self.next_id()),
|
|
|
|
|
span: dummy_sp()}
|
2012-07-23 18:50:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt {
|
|
|
|
|
let ext_cx = *self;
|
2012-12-06 16:19:50 -08:00
|
|
|
quote_stmt!( let $ident = $e; )
|
2012-07-23 18:50:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field {
|
2013-01-14 21:36:27 -08:00
|
|
|
spanned {
|
|
|
|
|
node: ast::field_ { mutbl: ast::m_imm, ident: name, expr: e },
|
|
|
|
|
span: dummy_sp(),
|
|
|
|
|
}
|
2012-07-23 18:50:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field {
|
2013-01-14 21:36:27 -08:00
|
|
|
spanned {
|
2013-01-15 15:03:49 -08:00
|
|
|
node: ast::ty_field_ {
|
2013-01-14 21:36:27 -08:00
|
|
|
ident: name,
|
|
|
|
|
mt: ast::mt { ty: ty, mutbl: ast::m_imm },
|
|
|
|
|
},
|
|
|
|
|
span: dummy_sp(),
|
|
|
|
|
}
|
2012-07-23 14:46:39 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn ty_infer(&self) -> @ast::Ty {
|
2013-01-15 14:59:39 -08:00
|
|
|
@ast::Ty {
|
|
|
|
|
id: self.next_id(),
|
|
|
|
|
node: ast::ty_infer,
|
|
|
|
|
span: dummy_sp(),
|
|
|
|
|
}
|
2012-07-23 18:50:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-14 21:50:03 -08:00
|
|
|
fn ty_param(&self, id: ast::ident, bounds: @OptVec<ast::TyParamBound>)
|
|
|
|
|
-> ast::TyParam
|
2012-07-05 16:07:53 -07:00
|
|
|
{
|
2013-02-14 21:50:03 -08:00
|
|
|
ast::TyParam { ident: id, id: self.next_id(), bounds: bounds }
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg {
|
2013-01-15 16:05:20 -08:00
|
|
|
ast::arg {
|
2013-01-14 20:52:28 -08:00
|
|
|
mode: ast::infer(self.next_id()),
|
2013-01-04 01:45:07 +09:00
|
|
|
is_mutbl: false,
|
2013-01-14 20:52:28 -08:00
|
|
|
ty: ty,
|
|
|
|
|
pat: @ast::pat {
|
|
|
|
|
id: self.next_id(),
|
2012-11-06 18:41:06 -08:00
|
|
|
node: ast::pat_ident(
|
2013-01-10 10:59:58 -08:00
|
|
|
ast::bind_by_copy,
|
2012-11-12 19:32:48 -08:00
|
|
|
ast_util::ident_to_path(dummy_sp(), name),
|
2012-11-06 18:41:06 -08:00
|
|
|
None),
|
2013-01-14 20:52:28 -08:00
|
|
|
span: dummy_sp(),
|
|
|
|
|
},
|
|
|
|
|
id: self.next_id(),
|
|
|
|
|
}
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn block(&self, +stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk {
|
2013-01-14 19:35:08 -08:00
|
|
|
let blk = ast::blk_ {
|
|
|
|
|
view_items: ~[],
|
|
|
|
|
stmts: stmts,
|
|
|
|
|
expr: Some(e),
|
|
|
|
|
id: self.next_id(),
|
|
|
|
|
rules: ast::default_blk,
|
|
|
|
|
};
|
2012-07-05 16:07:53 -07:00
|
|
|
|
2012-12-27 14:36:00 -05:00
|
|
|
spanned { node: blk, span: dummy_sp() }
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn expr_block(&self, e: @ast::expr) -> ast::blk {
|
2012-07-23 18:50:53 -07:00
|
|
|
self.block(~[], e)
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn fn_decl(&self, +inputs: ~[ast::arg],
|
2012-10-15 14:56:42 -07:00
|
|
|
output: @ast::Ty) -> ast::fn_decl {
|
2013-01-15 16:05:20 -08:00
|
|
|
ast::fn_decl {
|
|
|
|
|
inputs: inputs,
|
|
|
|
|
output: output,
|
|
|
|
|
cf: ast::return_val,
|
|
|
|
|
}
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn item(&self, name: ident, span: span,
|
2012-07-05 16:07:53 -07:00
|
|
|
+node: ast::item_) -> @ast::item {
|
2012-08-28 11:11:15 -07:00
|
|
|
|
|
|
|
|
// XXX: Would be nice if our generated code didn't violate
|
|
|
|
|
// Rust coding conventions
|
2013-01-13 16:51:48 -08:00
|
|
|
let non_camel_case_attribute = respan(dummy_sp(), ast::attribute_ {
|
2012-08-28 11:11:15 -07:00
|
|
|
style: ast::attr_outer,
|
2013-02-25 06:19:44 -08:00
|
|
|
value: @respan(dummy_sp(),
|
2013-02-14 07:34:21 -08:00
|
|
|
ast::meta_list(@~"allow", ~[
|
2012-11-12 19:32:48 -08:00
|
|
|
@respan(dummy_sp(),
|
2013-02-14 07:34:21 -08:00
|
|
|
ast::meta_word(
|
|
|
|
|
@~"non_camel_case_types"))
|
2012-08-28 11:11:15 -07:00
|
|
|
])),
|
|
|
|
|
is_sugared_doc: false
|
|
|
|
|
});
|
|
|
|
|
|
2013-01-13 13:13:41 -08:00
|
|
|
@ast::item { ident: name,
|
|
|
|
|
attrs: ~[non_camel_case_attribute],
|
|
|
|
|
id: self.next_id(),
|
|
|
|
|
node: node,
|
|
|
|
|
vis: ast::public,
|
|
|
|
|
span: span }
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn item_fn_poly(&self, name: ident,
|
2012-07-05 16:07:53 -07:00
|
|
|
+inputs: ~[ast::arg],
|
2012-10-15 14:56:42 -07:00
|
|
|
output: @ast::Ty,
|
2013-02-14 21:50:03 -08:00
|
|
|
+generics: Generics,
|
2012-07-05 16:07:53 -07:00
|
|
|
+body: ast::blk) -> @ast::item {
|
|
|
|
|
self.item(name,
|
2012-11-12 19:32:48 -08:00
|
|
|
dummy_sp(),
|
2012-07-05 16:07:53 -07:00
|
|
|
ast::item_fn(self.fn_decl(inputs, output),
|
2012-08-23 18:17:16 -07:00
|
|
|
ast::impure_fn,
|
2013-03-13 22:25:28 -04:00
|
|
|
AbiSet::Rust(),
|
2013-02-14 21:50:03 -08:00
|
|
|
generics,
|
2012-07-05 16:07:53 -07:00
|
|
|
body))
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-28 07:25:31 -08:00
|
|
|
fn item_fn(&self,
|
|
|
|
|
name: ident,
|
2012-07-05 16:07:53 -07:00
|
|
|
+inputs: ~[ast::arg],
|
2012-10-15 14:56:42 -07:00
|
|
|
output: @ast::Ty,
|
2013-02-28 07:25:31 -08:00
|
|
|
+body: ast::blk
|
|
|
|
|
) -> @ast::item {
|
|
|
|
|
self.item_fn_poly(
|
|
|
|
|
name,
|
|
|
|
|
inputs,
|
|
|
|
|
output,
|
|
|
|
|
ast_util::empty_generics(),
|
|
|
|
|
body
|
|
|
|
|
)
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn item_enum_poly(&self, name: ident, span: span,
|
2012-08-08 17:14:25 -07:00
|
|
|
+enum_definition: ast::enum_def,
|
2013-02-14 21:50:03 -08:00
|
|
|
+generics: Generics) -> @ast::item {
|
|
|
|
|
self.item(name, span, ast::item_enum(enum_definition, generics))
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn item_enum(&self, name: ident, span: span,
|
2012-08-17 11:26:35 -07:00
|
|
|
+enum_definition: ast::enum_def) -> @ast::item {
|
2013-02-14 21:50:03 -08:00
|
|
|
self.item_enum_poly(name, span, enum_definition,
|
|
|
|
|
ast_util::empty_generics())
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-28 07:25:31 -08:00
|
|
|
fn item_struct(
|
|
|
|
|
&self, name: ident,
|
|
|
|
|
span: span,
|
|
|
|
|
+struct_def: ast::struct_def
|
|
|
|
|
) -> @ast::item {
|
|
|
|
|
self.item_struct_poly(
|
|
|
|
|
name,
|
|
|
|
|
span,
|
|
|
|
|
struct_def,
|
|
|
|
|
ast_util::empty_generics()
|
|
|
|
|
)
|
2013-02-17 00:55:36 -05:00
|
|
|
}
|
|
|
|
|
|
2013-02-28 07:25:31 -08:00
|
|
|
fn item_struct_poly(
|
|
|
|
|
&self,
|
|
|
|
|
name: ident,
|
|
|
|
|
span: span,
|
|
|
|
|
+struct_def: ast::struct_def,
|
|
|
|
|
+generics: Generics
|
|
|
|
|
) -> @ast::item {
|
2013-02-14 21:50:03 -08:00
|
|
|
self.item(name, span, ast::item_struct(@struct_def, generics))
|
2013-02-17 00:55:36 -05:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 05:24:57 -05:00
|
|
|
fn struct_expr(&self, path: @ast::path,
|
2013-02-24 21:27:51 -08:00
|
|
|
+fields: ~[ast::field]) -> @ast::expr {
|
2013-02-17 00:55:36 -05: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 02:51:55 -05:00
|
|
|
fn variant(&self, name: ident, span: span,
|
2012-10-15 14:56:42 -07:00
|
|
|
+tys: ~[@ast::Ty]) -> ast::variant {
|
2013-01-15 16:05:20 -08: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 00:55:36 -05:00
|
|
|
vis: ast::public
|
|
|
|
|
},
|
2013-01-15 16:05:20 -08:00
|
|
|
span: span,
|
|
|
|
|
}
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn item_mod(&self, name: ident, span: span,
|
2012-07-05 16:07:53 -07:00
|
|
|
+items: ~[@ast::item]) -> @ast::item {
|
2013-02-17 02:51:55 -05:00
|
|
|
|
2013-01-08 19:37:25 -08:00
|
|
|
// XXX: Total hack: import `core::kinds::Owned` to work around a
|
2013-02-20 17:07:17 -08:00
|
|
|
// parser bug whereby `fn f<T:::kinds::Owned>` doesn't parse.
|
2013-02-17 21:45:00 -05:00
|
|
|
let vi = ast::view_item_use(~[
|
2013-01-30 09:56:33 -08:00
|
|
|
@codemap::spanned {
|
2013-01-08 19:37:25 -08: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 09:56:33 -08:00
|
|
|
codemap::dummy_sp()
|
2013-01-08 19:37:25 -08:00
|
|
|
),
|
|
|
|
|
ast::type_value_ns,
|
|
|
|
|
self.next_id()
|
|
|
|
|
),
|
2013-01-30 09:56:33 -08:00
|
|
|
span: codemap::dummy_sp()
|
2013-01-08 19:37:25 -08:00
|
|
|
}
|
|
|
|
|
]);
|
2013-01-13 16:51:48 -08:00
|
|
|
let vi = @ast::view_item {
|
2013-01-08 19:37:25 -08:00
|
|
|
node: vi,
|
|
|
|
|
attrs: ~[],
|
|
|
|
|
vis: ast::private,
|
2013-01-30 09:56:33 -08:00
|
|
|
span: codemap::dummy_sp()
|
2013-01-08 19:37:25 -08:00
|
|
|
};
|
|
|
|
|
|
2013-01-15 16:05:20 -08:00
|
|
|
self.item(
|
|
|
|
|
name,
|
|
|
|
|
span,
|
|
|
|
|
ast::item_mod(ast::_mod {
|
|
|
|
|
view_items: ~[vi],
|
|
|
|
|
items: items,
|
|
|
|
|
})
|
|
|
|
|
)
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn ty_path_ast_builder(&self, path: @ast::path) -> @ast::Ty {
|
2013-01-15 14:59:39 -08:00
|
|
|
@ast::Ty {
|
|
|
|
|
id: self.next_id(),
|
|
|
|
|
node: ast::ty_path(path, self.next_id()),
|
|
|
|
|
span: path.span,
|
|
|
|
|
}
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn ty_nil_ast_builder(&self) -> @ast::Ty {
|
2013-01-15 14:59:39 -08:00
|
|
|
@ast::Ty {
|
|
|
|
|
id: self.next_id(),
|
|
|
|
|
node: ast::ty_nil,
|
|
|
|
|
span: dummy_sp(),
|
|
|
|
|
}
|
2012-07-16 14:44:27 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-14 21:50:03 -08: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 }
|
|
|
|
|
};
|
2013-02-28 07:25:31 -08:00
|
|
|
Generics {
|
|
|
|
|
ty_params: new_params,
|
|
|
|
|
.. copy *generics
|
2013-01-28 10:46:43 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn item_ty_poly(&self, name: ident, span: span, ty: @ast::Ty,
|
2013-02-14 21:50:03 -08:00
|
|
|
+generics: Generics) -> @ast::item {
|
|
|
|
|
self.item(name, span, ast::item_ty(ty, generics))
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-17 02:51:55 -05:00
|
|
|
fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item {
|
2013-02-14 21:50:03 -08:00
|
|
|
self.item_ty_poly(name, span, ty, ast_util::empty_generics())
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-02-14 21:50:03 -08:00
|
|
|
fn ty_vars(&self, ty_params: &OptVec<ast::TyParam>) -> ~[@ast::Ty] {
|
2013-03-01 19:38:39 -05:00
|
|
|
opt_vec::take_vec(
|
|
|
|
|
ty_params.map(|p| self.ty_path_ast_builder(
|
|
|
|
|
path(~[p.ident], dummy_sp()))))
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
2012-12-23 17:41:37 -05:00
|
|
|
|
2013-02-14 21:50:03 -08:00
|
|
|
fn ty_vars_global(&self,
|
|
|
|
|
ty_params: &OptVec<ast::TyParam>) -> ~[@ast::Ty] {
|
2013-03-01 19:38:39 -05:00
|
|
|
opt_vec::take_vec(
|
|
|
|
|
ty_params.map(|p| self.ty_path_ast_builder(
|
|
|
|
|
path(~[p.ident], dummy_sp()))))
|
2012-12-23 17:41:37 -05:00
|
|
|
}
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|