@@ -12,9 +12,6 @@ use std::serialization::{Serializer,
12
12
serialize_bool,
13
13
deserialize_bool} ;
14
14
15
- #[ auto_serialize]
16
- type str_num = uint ;
17
-
18
15
#[ auto_serialize]
19
16
enum binop {
20
17
PLUS ,
@@ -72,17 +69,17 @@ enum token {
72
69
LIT_INT ( i64 , ast:: int_ty ) ,
73
70
LIT_UINT ( u64 , ast:: uint_ty ) ,
74
71
LIT_INT_UNSUFFIXED ( i64 ) ,
75
- LIT_FLOAT ( str_num , ast:: float_ty ) ,
76
- LIT_STR ( str_num ) ,
72
+ LIT_FLOAT ( ast :: ident , ast:: float_ty ) ,
73
+ LIT_STR ( ast :: ident ) ,
77
74
78
75
/* Name components */
79
- IDENT ( str_num , bool ) ,
76
+ IDENT ( ast :: ident , bool ) ,
80
77
UNDERSCORE ,
81
78
82
79
/* For interpolation */
83
80
INTERPOLATED ( nonterminal ) ,
84
81
85
- DOC_COMMENT ( str_num ) ,
82
+ DOC_COMMENT ( ast :: ident ) ,
86
83
EOF ,
87
84
}
88
85
@@ -95,7 +92,7 @@ enum nonterminal {
95
92
nt_pat( @ast:: pat ) ,
96
93
nt_expr( @ast:: expr ) ,
97
94
nt_ty( @ast:: ty ) ,
98
- nt_ident( str_num , bool ) ,
95
+ nt_ident( ast :: ident , bool ) ,
99
96
nt_path( @ast:: path ) ,
100
97
nt_tt( @ast:: token_tree ) , //needs @ed to break a circularity
101
98
nt_matchers( ~[ ast:: matcher ] )
@@ -116,7 +113,7 @@ fn binop_to_str(o: binop) -> ~str {
116
113
}
117
114
}
118
115
119
- fn to_str(in: interner<@~str> , t: token) -> ~str {
116
+ fn to_str(in: @ident_interner , t: token) -> ~str {
120
117
match t {
121
118
EQ => ~" =",
122
119
LT => ~" <",
@@ -174,7 +171,7 @@ fn to_str(in: interner<@~str>, t: token) -> ~str {
174
171
}
175
172
body + ast_util:: float_ty_to_str ( t)
176
173
}
177
- LIT_STR ( s) => { ~"\" " + str:: escape_default ( * in. get ( s) ) + ~"\" " }
174
+ LIT_STR ( s) => { ~"\" " + str:: escape_default ( * in. get ( s) ) + ~"\" " }
178
175
179
176
/* Name components */
180
177
IDENT ( s, _) => * in. get ( s) ,
@@ -281,49 +278,66 @@ pure fn is_bar(t: token) -> bool {
281
278
mod special_idents {
282
279
#[ legacy_exports] ;
283
280
use ast:: ident;
284
- const underscore : ident = 0 u ;
285
- const anon : ident = 1 u ;
286
- const dtor : ident = 2 u ; // 'drop', but that's reserved
287
- const invalid : ident = 3 u ; // ''
288
- const unary : ident = 4 u ;
289
- const not_fn : ident = 5 u ;
290
- const idx_fn : ident = 6 u ;
291
- const unary_minus_fn : ident = 7 u ;
292
- const clownshoes_extensions : ident = 8 u ;
293
-
294
- const self_ : ident = 9 u ; // 'self'
281
+ const underscore : ident = ident { repr : 0 u } ;
282
+ const anon : ident = ident { repr : 1 u } ;
283
+ const dtor : ident = ident { repr : 2 u } ; // 'drop', but that's reserved
284
+ const invalid : ident = ident { repr : 3 u } ; // ''
285
+ const unary : ident = ident { repr : 4 u } ;
286
+ const not_fn : ident = ident { repr : 5 u } ;
287
+ const idx_fn : ident = ident { repr : 6 u } ;
288
+ const unary_minus_fn : ident = ident { repr : 7 u } ;
289
+ const clownshoes_extensions : ident = ident { repr : 8 u } ;
290
+
291
+ const self_ : ident = ident { repr : 9 u } ; // 'self'
295
292
296
293
/* for matcher NTs */
297
- const item : ident = 10 u;
298
- const block : ident = 11 u;
299
- const stmt : ident = 12 u;
300
- const pat : ident = 13 u;
301
- const expr : ident = 14 u;
302
- const ty : ident = 15 u;
303
- const ident : ident = 16 u;
304
- const path : ident = 17 u;
305
- const tt : ident = 18 u;
306
- const matchers : ident = 19 u;
307
-
308
- const str : ident = 20 u; // for the type
294
+ const item : ident = ident { repr : 10 u } ;
295
+ const block : ident = ident { repr : 11 u } ;
296
+ const stmt : ident = ident { repr : 12 u } ;
297
+ const pat : ident = ident { repr : 13 u } ;
298
+ const expr : ident = ident { repr : 14 u } ;
299
+ const ty : ident = ident { repr : 15 u } ;
300
+ const ident : ident = ident { repr : 16 u } ;
301
+ const path : ident = ident { repr : 17 u } ;
302
+ const tt : ident = ident { repr : 18 u } ;
303
+ const matchers : ident = ident { repr : 19 u } ;
304
+
305
+ const str : ident = ident { repr : 20 u } ; // for the type
309
306
310
307
/* outside of libsyntax */
311
- const ty_visitor : ident = 21 u;
312
- const arg : ident = 22 u;
313
- const descrim : ident = 23 u;
314
- const clownshoe_abi : ident = 24 u;
315
- const clownshoe_stack_shim : ident = 25 u;
316
- const tydesc : ident = 26 u;
317
- const literally_dtor : ident = 27 u;
318
- const main : ident = 28 u;
319
- const opaque : ident = 29 u;
320
- const blk : ident = 30 u;
321
- const static : ident = 31 u;
322
- const intrinsic : ident = 32 u;
323
- const clownshoes_foreign_mod: ident = 33 ;
308
+ const ty_visitor : ident = ident { repr : 21 u } ;
309
+ const arg : ident = ident { repr : 22 u } ;
310
+ const descrim : ident = ident { repr : 23 u } ;
311
+ const clownshoe_abi : ident = ident { repr : 24 u } ;
312
+ const clownshoe_stack_shim : ident = ident { repr : 25 u } ;
313
+ const tydesc : ident = ident { repr : 26 u } ;
314
+ const literally_dtor : ident = ident { repr : 27 u } ;
315
+ const main : ident = ident { repr : 28 u } ;
316
+ const opaque : ident = ident { repr : 29 u } ;
317
+ const blk : ident = ident { repr : 30 u } ;
318
+ const static : ident = ident { repr : 31 u } ;
319
+ const intrinsic : ident = ident { repr : 32 u } ;
320
+ const clownshoes_foreign_mod: ident = ident { repr : 33 } ;
324
321
}
325
322
326
- type ident_interner = util:: interner:: interner < @~str > ;
323
+ struct ident_interner {
324
+ priv interner : util:: interner:: interner < @~str > ,
325
+ }
326
+
327
+ impl ident_interner {
328
+ fn intern ( val : @~str ) -> ast:: ident {
329
+ ast:: ident { repr : self . interner . intern ( val) }
330
+ }
331
+ fn gensym ( val : @~str ) -> ast:: ident {
332
+ ast:: ident { repr : self . interner . gensym ( val) }
333
+ }
334
+ pure fn get ( idx : ast:: ident ) -> @~str {
335
+ self . interner . get ( idx. repr )
336
+ }
337
+ fn len ( ) -> uint {
338
+ self . interner . len ( )
339
+ }
340
+ }
327
341
328
342
/** Key for thread-local data for sneaking interner information to the
329
343
* serializer/deserializer. It sounds like a hack because it is one.
@@ -335,7 +349,7 @@ macro_rules! interner_key (
335
349
( -3 as uint, 0 u) ) )
336
350
)
337
351
338
- fn mk_ident_interner ( ) -> ident_interner {
352
+ fn mk_ident_interner ( ) -> @ ident_interner {
339
353
/* the indices here must correspond to the numbers in special_idents */
340
354
let init_vec = ~[ @~"_", @~"anon", @~"drop", @~"", @~"unary", @~"!",
341
355
@~"[ ] ", @~"unary-", @~" __extensions__", @~"self ",
@@ -346,7 +360,9 @@ fn mk_ident_interner() -> ident_interner {
346
360
@~"dtor", @~"main", @~"<opaque>", @~" blk", @~"static ",
347
361
@~"intrinsic", @~"__foreign_mod__"] ;
348
362
349
- let rv = interner:: mk_prefill :: < @~str > ( init_vec) ;
363
+ let rv = @ident_interner {
364
+ interner : interner:: mk_prefill :: < @~str > ( init_vec)
365
+ } ;
350
366
351
367
/* having multiple interners will just confuse the serializer */
352
368
unsafe {
@@ -360,8 +376,8 @@ fn mk_ident_interner() -> ident_interner {
360
376
361
377
/* for when we don't care about the contents; doesn't interact with TLD or
362
378
serialization */
363
- fn mk_fake_ident_interner ( ) -> ident_interner {
364
- interner:: mk :: < @~str > ( )
379
+ fn mk_fake_ident_interner ( ) -> @ ident_interner {
380
+ @ ident_interner { interner : interner :: mk :: < @~str > ( ) }
365
381
}
366
382
367
383
/**
0 commit comments