@@ -128,19 +128,25 @@ pub struct TrapFile {
128128 compression : Compression ,
129129}
130130
131+ #[ derive( Copy , Clone ) ]
132+ pub enum DiagnosticSeverity {
133+ Debug = 10 ,
134+ Info = 20 ,
135+ Warning = 30 ,
136+ Error = 40 ,
137+ }
131138impl TrapFile {
132- pub fn emit_location < E : TrapClass > (
139+ pub fn emit_location_label (
133140 & mut self ,
134141 file_label : UntypedLabel ,
135- entity_label : Label < E > ,
136142 start : LineCol ,
137143 end : LineCol ,
138- ) {
144+ ) -> UntypedLabel {
139145 let start_line = 1 + start. line as usize ;
140146 let start_column = 1 + start. col as usize ;
141147 let end_line = 1 + end. line as usize ;
142148 let end_column = 1 + end. col as usize ;
143- let location_label = extractor:: location_label (
149+ extractor:: location_label (
144150 & mut self . writer ,
145151 trap:: Location {
146152 file_label,
@@ -149,13 +155,43 @@ impl TrapFile {
149155 end_line,
150156 end_column,
151157 } ,
152- ) ;
158+ )
159+ }
160+ pub fn emit_location < E : TrapClass > (
161+ & mut self ,
162+ file_label : UntypedLabel ,
163+ entity_label : Label < E > ,
164+ start : LineCol ,
165+ end : LineCol ,
166+ ) {
167+ let location_label = self . emit_location_label ( file_label, start, end) ;
153168 self . writer . add_tuple (
154169 "locatable_locations" ,
155170 vec ! [ entity_label. into( ) , location_label. into( ) ] ,
156171 ) ;
157172 }
158173
174+ pub fn emit_diagnostic (
175+ & mut self ,
176+ severity : DiagnosticSeverity ,
177+ error_tag : String ,
178+ error_message : String ,
179+ full_error_message : String ,
180+ location : UntypedLabel ,
181+ ) {
182+ let label = self . writer . fresh_id ( ) ;
183+ self . writer . add_tuple (
184+ "diagnostics" ,
185+ vec ! [
186+ trap:: Arg :: Label ( label) ,
187+ trap:: Arg :: Int ( severity as usize ) ,
188+ trap:: Arg :: String ( error_tag) ,
189+ trap:: Arg :: String ( error_message) ,
190+ trap:: Arg :: String ( full_error_message) ,
191+ trap:: Arg :: Label ( location) ,
192+ ] ,
193+ ) ;
194+ }
159195 pub fn emit_file ( & mut self , absolute_path : & Path ) -> trap:: Label {
160196 extractor:: populate_file ( & mut self . writer , absolute_path)
161197 }
0 commit comments