@@ -97,35 +97,62 @@ pub fn print_crate<'a>(cm: &'a CodeMap,
97
97
out : Box < io:: Writer > ,
98
98
ann : & ' a PpAnn ,
99
99
is_expanded : bool ) -> IoResult < ( ) > {
100
- let ( cmnts, lits) = comments:: gather_comments_and_literals (
101
- span_diagnostic,
102
- filename,
103
- input
104
- ) ;
105
- let mut s = State {
106
- s : pp:: mk_printer ( out, default_columns) ,
107
- cm : Some ( cm) ,
108
- comments : Some ( cmnts) ,
109
- // If the code is post expansion, don't use the table of
110
- // literals, since it doesn't correspond with the literals
111
- // in the AST anymore.
112
- literals : if is_expanded {
113
- None
114
- } else {
115
- Some ( lits)
116
- } ,
117
- cur_cmnt_and_lit : CurrentCommentAndLiteral {
118
- cur_cmnt : 0 ,
119
- cur_lit : 0
120
- } ,
121
- boxes : Vec :: new ( ) ,
122
- ann : ann
123
- } ;
100
+ let mut s = State :: new_from_input ( cm,
101
+ span_diagnostic,
102
+ filename,
103
+ input,
104
+ out,
105
+ ann,
106
+ is_expanded) ;
124
107
try!( s. print_mod ( & krate. module , krate. attrs . as_slice ( ) ) ) ;
125
108
try!( s. print_remaining_comments ( ) ) ;
126
109
eof ( & mut s. s )
127
110
}
128
111
112
+ impl < ' a > State < ' a > {
113
+ pub fn new_from_input ( cm : & ' a CodeMap ,
114
+ span_diagnostic : & diagnostic:: SpanHandler ,
115
+ filename : String ,
116
+ input : & mut io:: Reader ,
117
+ out : Box < io:: Writer > ,
118
+ ann : & ' a PpAnn ,
119
+ is_expanded : bool ) -> State < ' a > {
120
+ let ( cmnts, lits) = comments:: gather_comments_and_literals (
121
+ span_diagnostic,
122
+ filename,
123
+ input) ;
124
+
125
+ State :: new (
126
+ cm,
127
+ out,
128
+ ann,
129
+ Some ( cmnts) ,
130
+ // If the code is post expansion, don't use the table of
131
+ // literals, since it doesn't correspond with the literals
132
+ // in the AST anymore.
133
+ if is_expanded { None } else { Some ( lits) } )
134
+ }
135
+
136
+ pub fn new ( cm : & ' a CodeMap ,
137
+ out : Box < io:: Writer > ,
138
+ ann : & ' a PpAnn ,
139
+ comments : Option < Vec < comments:: Comment > > ,
140
+ literals : Option < Vec < comments:: Literal > > ) -> State < ' a > {
141
+ State {
142
+ s : pp:: mk_printer ( out, default_columns) ,
143
+ cm : Some ( cm) ,
144
+ comments : comments,
145
+ literals : literals,
146
+ cur_cmnt_and_lit : CurrentCommentAndLiteral {
147
+ cur_cmnt : 0 ,
148
+ cur_lit : 0
149
+ } ,
150
+ boxes : Vec :: new ( ) ,
151
+ ann : ann
152
+ }
153
+ }
154
+ }
155
+
129
156
pub fn to_string ( f: |& mut State | -> IoResult < ( ) > ) -> String {
130
157
let mut s = rust_printer( box MemWriter :: new( ) ) ;
131
158
f( & mut s) . unwrap( ) ;
0 commit comments