@@ -32,41 +32,46 @@ fn syntax_expander_table() -> hashmap[str, syntax_extension] {
32
32
ret syntax_expanders;
33
33
}
34
34
35
- type span_msg_fn = fn ( span , str ) -> ! ;
36
- type msg_fn = fn ( str ) -> ! ;
35
+ obj ext_ctxt( sess: @session, crate_file_name_hack: str ,
36
+ mutable backtrace: span[ ] ) {
37
+ fn crate_file_name ( ) -> str { ret crate_file_name_hack; }
37
38
38
- type next_id_fn = fn ( ) -> ast:: node_id ;
39
-
40
-
41
- // Provides a limited set of services necessary for syntax extensions
42
- // to do their thing
43
- type ext_ctxt =
44
- { crate_file_name_hack : str ,
45
- span_fatal : span_msg_fn ,
46
- span_unimpl : span_msg_fn ,
47
- span_bug : span_msg_fn ,
48
- bug : msg_fn ,
49
- next_id : next_id_fn } ;
39
+ fn print_backtrace ( ) {
40
+ for sp: span in backtrace {
41
+ sess. span_note ( sp, "(while expanding this)" )
42
+ }
43
+ }
44
+
45
+ fn bt_push ( sp : span ) { backtrace += ~[ sp] ; }
46
+ fn bt_pop ( ) { ivec:: pop ( backtrace) ; }
50
47
51
- fn mk_ctxt ( sess : & session ) -> ext_ctxt {
52
- fn ext_span_fatal_ ( sess : & session , sp : span , msg : str ) -> ! {
48
+ fn span_fatal ( sp : span , msg : str ) -> ! {
49
+ self . print_backtrace ( ) ;
50
+ sess. span_fatal ( sp, msg) ;
51
+ }
52
+ fn span_err ( sp : span , msg : str ) {
53
+ self . print_backtrace ( ) ;
53
54
sess. span_err ( sp, msg) ;
54
- fail;
55
55
}
56
- let ext_span_fatal = bind ext_span_fatal_ ( sess, _, _) ;
57
- fn ext_span_unimpl_ ( sess : & session , sp : span , msg : str ) -> ! {
58
- sess. span_err ( sp, "unimplemented " + msg) ;
59
- fail;
56
+ fn span_unimpl ( sp : span , msg : str ) -> ! {
57
+ self . print_backtrace ( ) ;
58
+ sess. span_unimpl ( sp, msg) ;
60
59
}
61
- let ext_span_bug = bind ext_span_bug_ ( sess, _, _) ;
62
- fn ext_span_bug_ ( sess : & session , sp : span , msg : str ) -> ! {
63
- sess. span_bug ( sp, msg) ;
60
+ fn span_bug ( sp : span , msg : str ) -> ! {
61
+ self . print_backtrace ( ) ;
62
+ sess. span_bug ( sp, msg) ;
63
+ }
64
+ fn bug ( msg : str ) -> ! {
65
+ self . print_backtrace ( ) ;
66
+ sess. bug ( msg) ;
67
+ }
68
+ fn next_id ( ) -> ast:: node_id {
69
+ ret sess. next_node_id ( ) ;
64
70
}
65
- let ext_span_unimpl = bind ext_span_unimpl_ ( sess, _, _) ;
66
- fn ext_bug_ ( sess : & session , msg : str ) -> ! { sess. bug ( msg) ; }
67
- let ext_bug = bind ext_bug_ ( sess, _) ;
68
71
72
+ }
69
73
74
+ fn mk_ctxt ( sess : & session ) -> ext_ctxt {
70
75
// FIXME: Some extensions work by building ASTs with paths to functions
71
76
// they need to call at runtime. As those functions live in the std crate,
72
77
// the paths are prefixed with "std::". Unfortunately, these paths can't
@@ -76,16 +81,7 @@ fn mk_ctxt(sess: &session) -> ext_ctxt {
76
81
// super-ugly and needs a better solution.
77
82
let crate_file_name_hack = sess. get_codemap ( ) . files . ( 0 ) . name ;
78
83
79
- fn ext_next_id_ ( sess : & session ) -> ast:: node_id {
80
- ret sess. next_node_id ( ) ; // temporary, until bind works better
81
- }
82
- let ext_next_id = bind ext_next_id_ ( sess) ;
83
- ret { crate_file_name_hack : crate_file_name_hack,
84
- span_fatal : ext_span_fatal,
85
- span_unimpl : ext_span_unimpl,
86
- span_bug : ext_span_bug,
87
- bug : ext_bug,
88
- next_id : ext_next_id} ;
84
+ ret ext_ctxt( @sess, crate_file_name_hack, ~[ ] ) ;
89
85
}
90
86
91
87
fn expr_to_str ( cx : & ext_ctxt , expr : @ast:: expr , error : str ) -> str {
0 commit comments