@@ -34,12 +34,14 @@ fn mk_unary(cx: ext_ctxt, sp: span, op: ast::unop, e: @ast::expr)
34
34
cx. next_id ( ) ; // see ast_util::op_expr_callee_id
35
35
mk_expr ( cx, sp, ast:: expr_unary ( op, e) )
36
36
}
37
+ fn mk_raw_path ( sp : span , idents : ~[ ast:: ident ] ) -> @ast:: path {
38
+ let p : @ast:: path = @{ span: sp, global: false , idents: idents,
39
+ rp: None , types: ~[ ] } ;
40
+ return p;
41
+ }
37
42
fn mk_path ( cx : ext_ctxt , sp : span , idents : ~[ ast:: ident ] ) ->
38
43
@ast:: expr {
39
- let path = @{ span: sp, global: false , idents: idents,
40
- rp: None , types: ~[ ] } ;
41
- let pathexpr = ast:: expr_path ( path) ;
42
- mk_expr ( cx, sp, pathexpr)
44
+ mk_expr ( cx, sp, ast:: expr_path ( mk_raw_path ( sp, idents) ) )
43
45
}
44
46
fn mk_access_ ( cx : ext_ctxt , sp : span , p : @ast:: expr , m : ast:: ident )
45
47
-> @ast:: expr {
@@ -53,7 +55,6 @@ fn mk_access(cx: ext_ctxt, sp: span, p: ~[ast::ident], m: ast::ident)
53
55
fn mk_addr_of ( cx : ext_ctxt , sp : span , e : @ast:: expr ) -> @ast:: expr {
54
56
return mk_expr ( cx, sp, ast:: expr_addr_of ( ast:: m_imm, e) ) ;
55
57
}
56
-
57
58
fn mk_call_ ( cx : ext_ctxt , sp : span , fn_expr : @ast:: expr ,
58
59
args : ~[ @ast:: expr ] ) -> @ast:: expr {
59
60
mk_expr ( cx, sp, ast:: expr_call ( fn_expr, args, false ) )
@@ -90,19 +91,54 @@ fn mk_base_str(cx: ext_ctxt, sp: span, s: ~str) -> @ast::expr {
90
91
fn mk_uniq_str ( cx : ext_ctxt , sp : span , s : ~str ) -> @ast:: expr {
91
92
mk_vstore_e ( cx, sp, mk_base_str ( cx, sp, s) , ast:: expr_vstore_uniq)
92
93
}
93
-
94
+ fn mk_field ( sp : span , f : & { ident: ast:: ident , ex : @ast:: expr } )
95
+ -> ast:: field {
96
+ { node : { mutbl : ast:: m_imm, ident : f. ident , expr : f. ex } , span: sp}
97
+ }
98
+ fn mk_fields ( sp : span , fields : ~[ { ident: ast:: ident , ex : @ast:: expr } ] ) ->
99
+ ~[ ast:: field ] {
100
+ move fields. map ( |f| mk_field ( sp, f) )
101
+ }
94
102
fn mk_rec_e ( cx : ext_ctxt , sp : span ,
95
103
fields : ~[ { ident: ast:: ident , ex : @ast:: expr } ] ) ->
96
104
@ast:: expr {
97
- let mut astfields: ~[ ast:: field ] = ~[ ] ;
98
- for fields. each |field| {
99
- let ident = field. ident ;
100
- let val = field. ex ;
101
- let astfield =
102
- { node : { mutbl : ast:: m_imm, ident : ident, expr : val} , span: sp} ;
103
- astfields. push ( astfield) ;
104
- }
105
- let recexpr = ast:: expr_rec ( astfields, option:: None :: < @ast:: expr > ) ;
106
- mk_expr ( cx, sp, recexpr)
105
+ mk_expr ( cx, sp, ast:: expr_rec ( mk_fields ( sp, fields) ,
106
+ option:: None :: < @ast:: expr > ) )
107
+ }
108
+ fn mk_struct_e ( cx : ext_ctxt , sp : span ,
109
+ ctor_path : ~[ ast:: ident ] ,
110
+ fields : ~[ { ident: ast:: ident , ex : @ast:: expr } ] ) ->
111
+ @ast:: expr {
112
+ mk_expr ( cx, sp,
113
+ ast:: expr_struct ( mk_raw_path ( sp, ctor_path) ,
114
+ mk_fields ( sp, fields) ,
115
+ option:: None :: < @ast:: expr > ) )
116
+ }
117
+ fn mk_glob_use( cx : ext_ctxt , sp : span ,
118
+ path : ~[ ast:: ident ] ) -> @ast:: view_item {
119
+ let glob = @{ node: ast:: view_path_glob ( mk_raw_path ( sp, path) ,
120
+ cx. next_id ( ) ) ,
121
+ span: sp} ;
122
+ @{ node: ast:: view_item_import ( ~[ glob] ) ,
123
+ attrs: ~[ ] ,
124
+ vis: ast:: private,
125
+ span: sp}
126
+ }
127
+ fn mk_block ( cx : ext_ctxt , sp : span ,
128
+ view_items : ~[ @ast:: view_item ] ,
129
+ stmts : ~[ @ast:: stmt ] ,
130
+ expr : Option < @ast:: expr > ) -> @ast:: expr {
131
+ let blk = { node : { view_items : view_items,
132
+ stmts : stmts,
133
+ expr : expr,
134
+ id : cx. next_id ( ) ,
135
+ rules : ast:: default_blk } ,
136
+ span: sp } ;
137
+ mk_expr ( cx, sp, ast:: expr_block ( blk) )
138
+ }
139
+ fn mk_copy ( cx : ext_ctxt , sp : span , e : @ast:: expr ) -> @ast:: expr {
140
+ mk_expr ( cx, sp, ast:: expr_copy ( e) )
141
+ }
142
+ fn mk_managed ( cx : ext_ctxt , sp : span , e : @ast:: expr ) -> @ast:: expr {
143
+ mk_expr ( cx, sp, ast:: expr_unary ( ast:: box ( ast:: m_imm) , e) )
107
144
}
108
-
0 commit comments