2121
2222use std:: cell:: Cell ;
2323use std:: fmt;
24+ use std:: path:: PathBuf ;
2425use std:: ptr:: NonNull ;
2526
2627use self :: storage:: { FromConcrete , ToConcrete } ;
@@ -195,6 +196,8 @@ storage_concrete_passthrough! {
195196 [ ] :: Span ,
196197 [ ] :: Delimiter ,
197198 [ ] :: LexError ,
199+
200+ [ ] PathBuf ,
198201 // NOTE(eddyb) this will need some `extern "C" fn write`.
199202 [ ' a, ' b] & ' a mut fmt:: Formatter <' b>,
200203 [ ] fmt:: Error
@@ -243,6 +246,17 @@ macro_rules! each_frontend_method {
243246 } ) ;
244247 $meth!( fn token_cursor_next( & self , cursor: & mut Self :: TokenCursor )
245248 -> Option <Self :: TokenStream >; ) ;
249+
250+ $meth!( fn source_file_cleanup( & self , _file: Self :: SourceFile ) -> ( ) { } ) ;
251+ $meth!( fn source_file_clone( & self , file: & Self :: SourceFile ) -> Self :: SourceFile {
252+ file. clone( )
253+ } ) ;
254+ $meth!( fn source_file_eq( & self , file1: & Self :: SourceFile ,
255+ file2: & Self :: SourceFile ) -> bool ; ) ;
256+ $meth!( fn source_file_path( & self , file: & Self :: SourceFile ) -> PathBuf ; ) ;
257+ $meth!( fn source_file_is_real( & self , file: & Self :: SourceFile ) -> bool ; ) ;
258+
259+ $meth!( fn span_source_file( & self , span: :: Span ) -> Self :: SourceFile ; ) ;
246260 }
247261}
248262
@@ -253,6 +267,7 @@ pub trait FrontendInterface {
253267 type TokenStream : ' static + Clone + fmt:: Debug + fmt:: Display ;
254268 type TokenStreamBuilder : ' static ;
255269 type TokenCursor : ' static + Clone ;
270+ type SourceFile : ' static + Clone ;
256271 each_frontend_method ! ( define_frontend_trait_method) ;
257272}
258273
@@ -310,6 +325,9 @@ define_boxed! {
310325 } ,
311326 TokenCursor {
312327 cleanup: token_cursor_cleanup
328+ } ,
329+ SourceFile {
330+ cleanup: source_file_cleanup
313331 }
314332}
315333
@@ -337,6 +355,12 @@ impl Clone for TokenCursor {
337355 }
338356}
339357
358+ impl Clone for SourceFile {
359+ fn clone ( & self ) -> Self {
360+ Frontend . source_file_clone ( self )
361+ }
362+ }
363+
340364pub ( crate ) struct Frontend ;
341365
342366macro_rules! define_frontend_current_method {
@@ -351,6 +375,7 @@ impl FrontendInterface for Frontend {
351375 type TokenStream = TokenStream ;
352376 type TokenStreamBuilder = TokenStreamBuilder ;
353377 type TokenCursor = TokenCursor ;
378+ type SourceFile = SourceFile ;
354379 each_frontend_method ! ( define_frontend_current_method) ;
355380}
356381
@@ -359,6 +384,7 @@ type CurrentFrontend<'a> = FrontendInterface<
359384 TokenStream = TokenStream ,
360385 TokenStreamBuilder = TokenStreamBuilder ,
361386 TokenCursor = TokenCursor ,
387+ SourceFile = SourceFile ,
362388> + ' a ;
363389
364390// Emulate scoped_thread_local!() here essentially
@@ -421,6 +447,7 @@ fn erase_concrete_frontend<F, G, R>(ng: extern "C" fn() -> generation::Generatio
421447 type TokenStream = TokenStream ;
422448 type TokenStreamBuilder = TokenStreamBuilder ;
423449 type TokenCursor = TokenCursor ;
450+ type SourceFile = SourceFile ;
424451 each_frontend_method ! ( define_frontend_erase_concrete_method) ;
425452 }
426453
0 commit comments