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-05-17 15:28:44 -07:00
|
|
|
use core::prelude::*;
|
|
|
|
|
|
2013-03-31 19:27:51 -07:00
|
|
|
use ast::ident;
|
2012-12-23 17:41:37 -05:00
|
|
|
use ast;
|
2013-05-17 23:51:25 +10:00
|
|
|
use codemap::span;
|
2012-07-05 16:07:53 -07:00
|
|
|
|
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-04-17 12:15:08 -04:00
|
|
|
pub fn path(ids: ~[ident], span: span) -> @ast::Path {
|
2013-03-26 17:00:35 -07:00
|
|
|
@ast::Path { span: span,
|
2013-01-13 10:48:09 -08:00
|
|
|
global: false,
|
|
|
|
|
idents: ids,
|
|
|
|
|
rp: None,
|
|
|
|
|
types: ~[] }
|
2012-07-05 16:07:53 -07:00
|
|
|
}
|
|
|
|
|
|
2013-04-17 12:15:08 -04:00
|
|
|
pub fn path_global(ids: ~[ident], span: span) -> @ast::Path {
|
2013-03-26 17:00:35 -07:00
|
|
|
@ast::Path { span: span,
|
2013-01-13 10:48:09 -08:00
|
|
|
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-03-26 17:00:35 -07:00
|
|
|
fn add_ty(&self, ty: @ast::Ty) -> @ast::Path;
|
2013-04-17 12:15:08 -04:00
|
|
|
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-03-26 17:00:35 -07:00
|
|
|
impl append_types for @ast::Path {
|
|
|
|
|
fn add_ty(&self, ty: @ast::Ty) -> @ast::Path {
|
|
|
|
|
@ast::Path {
|
2013-02-17 08:28:11 -08:00
|
|
|
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-04-17 12:15:08 -04:00
|
|
|
fn add_tys(&self, tys: ~[@ast::Ty]) -> @ast::Path {
|
2013-03-26 17:00:35 -07:00
|
|
|
@ast::Path {
|
2013-02-17 08:28:11 -08:00
|
|
|
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-05-20 15:20:16 -07:00
|
|
|
|