1 /* valareport.c generated by valac, the Vala compiler
2  * generated from valareport.vala, do not modify */
3 
4 /* valareport.vala
5  *
6  * Copyright (C) 2006-2010  Jürg Billeter
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12 
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17 
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
21  *
22  * Author:
23  * 	Jürg Billeter <j@bitron.ch>
24  */
25 
26 #include "vala.h"
27 #include <stdlib.h>
28 #include <string.h>
29 #include <glib.h>
30 #include <stdio.h>
31 #include <gmodule.h>
32 #include <gobject/gvaluecollector.h>
33 
34 #define _g_free0(var) (var = (g_free (var), NULL))
35 #define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
36 #define _vala_code_context_unref0(var) ((var == NULL) ? NULL : (var = (vala_code_context_unref (var), NULL)))
37 #define _g_module_close0(var) ((var == NULL) ? NULL : (var = (g_module_close (var), NULL)))
38 typedef gint (*ValaReportAttyFunc) (gint fd);
39 typedef struct _ValaParamSpecReport ValaParamSpecReport;
40 
41 struct _ValaReportPrivate {
42 	gchar* locus_color_start;
43 	const gchar* locus_color_end;
44 	gchar* warning_color_start;
45 	const gchar* warning_color_end;
46 	gchar* error_color_start;
47 	const gchar* error_color_end;
48 	gchar* note_color_start;
49 	const gchar* note_color_end;
50 	gchar* caret_color_start;
51 	const gchar* caret_color_end;
52 	gchar* quote_color_start;
53 	const gchar* quote_color_end;
54 	gboolean verbose_errors;
55 	gboolean _enable_warnings;
56 };
57 
58 struct _ValaParamSpecReport {
59 	GParamSpec parent_instance;
60 };
61 
62 static gint ValaReport_private_offset;
63 static gpointer vala_report_parent_class = NULL;
64 static GRegex* vala_report_val_regex;
65 static GRegex* vala_report_val_regex = NULL;
66 
67 #define VALA_REPORT_ANSI_COLOR_END "\x1b[0m"
68 static gboolean vala_report_is_atty (ValaReport* self,
69                               gint fd);
70 static void vala_report_report_source (ValaReport* self,
71                                 ValaSourceReference* source);
72 static void vala_report_print_highlighted_message (ValaReport* self,
73                                             const gchar* message);
74 static void vala_report_print_message (ValaReport* self,
75                                 ValaSourceReference* source,
76                                 const gchar* type,
77                                 const gchar* type_color_start,
78                                 const gchar* type_color_end,
79                                 const gchar* message,
80                                 gboolean do_report_source);
81 static void vala_report_real_note (ValaReport* self,
82                             ValaSourceReference* source,
83                             const gchar* message);
84 static void vala_report_real_depr (ValaReport* self,
85                             ValaSourceReference* source,
86                             const gchar* message);
87 static void vala_report_real_warn (ValaReport* self,
88                             ValaSourceReference* source,
89                             const gchar* message);
90 static void vala_report_real_err (ValaReport* self,
91                            ValaSourceReference* source,
92                            const gchar* message);
93 static void vala_report_finalize (ValaReport * obj);
94 static GType vala_report_get_type_once (void);
95 static void _vala_array_destroy (gpointer array,
96                           gint array_length,
97                           GDestroyNotify destroy_func);
98 static void _vala_array_free (gpointer array,
99                        gint array_length,
100                        GDestroyNotify destroy_func);
101 static gint _vala_array_length (gpointer array);
102 
103 static inline gpointer
vala_report_get_instance_private(ValaReport * self)104 vala_report_get_instance_private (ValaReport* self)
105 {
106 	return G_STRUCT_MEMBER_P (self, ValaReport_private_offset);
107 }
108 
109 static GType
vala_report_colored_get_type_once(void)110 vala_report_colored_get_type_once (void)
111 {
112 	static const GEnumValue values[] = {{VALA_REPORT_COLORED_AUTO, "VALA_REPORT_COLORED_AUTO", "auto"}, {VALA_REPORT_COLORED_NEVER, "VALA_REPORT_COLORED_NEVER", "never"}, {VALA_REPORT_COLORED_ALWAYS, "VALA_REPORT_COLORED_ALWAYS", "always"}, {0, NULL, NULL}};
113 	GType vala_report_colored_type_id;
114 	vala_report_colored_type_id = g_enum_register_static ("ValaReportColored", values);
115 	return vala_report_colored_type_id;
116 }
117 
118 GType
vala_report_colored_get_type(void)119 vala_report_colored_get_type (void)
120 {
121 	static volatile gsize vala_report_colored_type_id__volatile = 0;
122 	if (g_once_init_enter (&vala_report_colored_type_id__volatile)) {
123 		GType vala_report_colored_type_id;
124 		vala_report_colored_type_id = vala_report_colored_get_type_once ();
125 		g_once_init_leave (&vala_report_colored_type_id__volatile, vala_report_colored_type_id);
126 	}
127 	return vala_report_colored_type_id__volatile;
128 }
129 
130 gboolean
vala_report_get_enable_warnings(ValaReport * self)131 vala_report_get_enable_warnings (ValaReport* self)
132 {
133 	gboolean result;
134 	g_return_val_if_fail (self != NULL, FALSE);
135 	result = self->priv->_enable_warnings;
136 	return result;
137 }
138 
139 void
vala_report_set_enable_warnings(ValaReport * self,gboolean value)140 vala_report_set_enable_warnings (ValaReport* self,
141                                  gboolean value)
142 {
143 	g_return_if_fail (self != NULL);
144 	self->priv->_enable_warnings = value;
145 }
146 
147 /**
148  * Set all colors by string
149  *
150  * {{{
151  *   "error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01"
152  * }}}
153  */
154 gboolean
vala_report_set_colors(ValaReport * self,const gchar * str,ValaReportColored colored_output)155 vala_report_set_colors (ValaReport* self,
156                         const gchar* str,
157                         ValaReportColored colored_output)
158 {
159 	gchar* error_color = NULL;
160 	gchar* warning_color = NULL;
161 	gchar* note_color = NULL;
162 	gchar* caret_color = NULL;
163 	gchar* locus_color = NULL;
164 	gchar* quote_color = NULL;
165 	gchar** fragments = NULL;
166 	gchar** _tmp6_;
167 	gchar** _tmp7_;
168 	gint fragments_length1;
169 	gint _fragments_size_;
170 	gchar** _tmp8_;
171 	gint _tmp8__length1;
172 	gboolean _tmp37_ = FALSE;
173 	GError* _inner_error0_ = NULL;
174 	gboolean result = FALSE;
175 	g_return_val_if_fail (self != NULL, FALSE);
176 	g_return_val_if_fail (str != NULL, FALSE);
177 	{
178 		GRegex* _tmp0_;
179 		_tmp0_ = vala_report_val_regex;
180 		if (_tmp0_ == NULL) {
181 			GRegex* _tmp1_ = NULL;
182 			GRegex* _tmp2_;
183 			GRegex* _tmp4_;
184 			_tmp2_ = g_regex_new ("^\\s*[0-9]+(;[0-9]*)*\\s*$", 0, 0, &_inner_error0_);
185 			_tmp1_ = _tmp2_;
186 			if (G_UNLIKELY (_inner_error0_ != NULL)) {
187 				gboolean _tmp3_ = FALSE;
188 				if (_inner_error0_->domain == G_REGEX_ERROR) {
189 					goto __catch0_g_regex_error;
190 				}
191 				g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
192 				g_clear_error (&_inner_error0_);
193 				return _tmp3_;
194 			}
195 			_tmp4_ = _tmp1_;
196 			_tmp1_ = NULL;
197 			_g_regex_unref0 (vala_report_val_regex);
198 			vala_report_val_regex = _tmp4_;
199 			_g_regex_unref0 (_tmp1_);
200 		}
201 	}
202 	goto __finally0;
203 	__catch0_g_regex_error:
204 	{
205 		g_clear_error (&_inner_error0_);
206 		g_assert_not_reached ();
207 	}
208 	__finally0:
209 	if (G_UNLIKELY (_inner_error0_ != NULL)) {
210 		gboolean _tmp5_ = FALSE;
211 		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
212 		g_clear_error (&_inner_error0_);
213 		return _tmp5_;
214 	}
215 	error_color = NULL;
216 	warning_color = NULL;
217 	note_color = NULL;
218 	caret_color = NULL;
219 	locus_color = NULL;
220 	quote_color = NULL;
221 	_tmp7_ = _tmp6_ = g_strsplit (str, ":", 0);
222 	fragments = _tmp7_;
223 	fragments_length1 = _vala_array_length (_tmp6_);
224 	_fragments_size_ = fragments_length1;
225 	_tmp8_ = fragments;
226 	_tmp8__length1 = fragments_length1;
227 	{
228 		gchar** fragment_collection = NULL;
229 		gint fragment_collection_length1 = 0;
230 		gint _fragment_collection_size_ = 0;
231 		gint fragment_it = 0;
232 		fragment_collection = _tmp8_;
233 		fragment_collection_length1 = _tmp8__length1;
234 		for (fragment_it = 0; fragment_it < fragment_collection_length1; fragment_it = fragment_it + 1) {
235 			const gchar* fragment = NULL;
236 			fragment = fragment_collection[fragment_it];
237 			{
238 				gchar** eq = NULL;
239 				const gchar* _tmp9_;
240 				gchar** _tmp10_;
241 				gchar** _tmp11_;
242 				gint eq_length1;
243 				gint _eq_size_;
244 				gchar** _tmp12_;
245 				gint _tmp12__length1;
246 				GRegex* _tmp13_;
247 				gchar** _tmp14_;
248 				gint _tmp14__length1;
249 				const gchar* _tmp15_;
250 				const gchar* checked_value = NULL;
251 				gchar** _tmp16_;
252 				gint _tmp16__length1;
253 				const gchar* _tmp17_;
254 				const gchar* _tmp18_;
255 				gchar** _tmp19_;
256 				gint _tmp19__length1;
257 				const gchar* _tmp20_;
258 				const gchar* _tmp21_;
259 				const gchar* _tmp22_;
260 				GQuark _tmp24_ = 0U;
261 				static GQuark _tmp23_label0 = 0;
262 				static GQuark _tmp23_label1 = 0;
263 				static GQuark _tmp23_label2 = 0;
264 				static GQuark _tmp23_label3 = 0;
265 				static GQuark _tmp23_label4 = 0;
266 				static GQuark _tmp23_label5 = 0;
267 				_tmp9_ = fragment;
268 				_tmp11_ = _tmp10_ = g_strsplit (_tmp9_, "=", 2);
269 				eq = _tmp11_;
270 				eq_length1 = _vala_array_length (_tmp10_);
271 				_eq_size_ = eq_length1;
272 				_tmp12_ = eq;
273 				_tmp12__length1 = eq_length1;
274 				if (_tmp12__length1 != 2) {
275 					result = FALSE;
276 					eq = (_vala_array_free (eq, eq_length1, (GDestroyNotify) g_free), NULL);
277 					fragments = (_vala_array_free (fragments, fragments_length1, (GDestroyNotify) g_free), NULL);
278 					_g_free0 (quote_color);
279 					_g_free0 (locus_color);
280 					_g_free0 (caret_color);
281 					_g_free0 (note_color);
282 					_g_free0 (warning_color);
283 					_g_free0 (error_color);
284 					return result;
285 				}
286 				_tmp13_ = vala_report_val_regex;
287 				_tmp14_ = eq;
288 				_tmp14__length1 = eq_length1;
289 				_tmp15_ = _tmp14_[1];
290 				if (!g_regex_match (_tmp13_, _tmp15_, 0, NULL)) {
291 					result = FALSE;
292 					eq = (_vala_array_free (eq, eq_length1, (GDestroyNotify) g_free), NULL);
293 					fragments = (_vala_array_free (fragments, fragments_length1, (GDestroyNotify) g_free), NULL);
294 					_g_free0 (quote_color);
295 					_g_free0 (locus_color);
296 					_g_free0 (caret_color);
297 					_g_free0 (note_color);
298 					_g_free0 (warning_color);
299 					_g_free0 (error_color);
300 					return result;
301 				}
302 				_tmp16_ = eq;
303 				_tmp16__length1 = eq_length1;
304 				_tmp17_ = _tmp16_[1];
305 				_tmp18_ = g_strstrip (_tmp17_);
306 				checked_value = _tmp18_;
307 				_tmp19_ = eq;
308 				_tmp19__length1 = eq_length1;
309 				_tmp20_ = _tmp19_[0];
310 				_tmp21_ = g_strstrip (_tmp20_);
311 				_tmp22_ = _tmp21_;
312 				_tmp24_ = (NULL == _tmp22_) ? 0 : g_quark_from_string (_tmp22_);
313 				if (_tmp24_ == ((0 != _tmp23_label0) ? _tmp23_label0 : (_tmp23_label0 = g_quark_from_static_string ("error")))) {
314 					switch (0) {
315 						default:
316 						{
317 							const gchar* _tmp25_;
318 							gchar* _tmp26_;
319 							_tmp25_ = checked_value;
320 							_tmp26_ = g_strdup (_tmp25_);
321 							_g_free0 (error_color);
322 							error_color = _tmp26_;
323 							break;
324 						}
325 					}
326 				} else if (_tmp24_ == ((0 != _tmp23_label1) ? _tmp23_label1 : (_tmp23_label1 = g_quark_from_static_string ("warning")))) {
327 					switch (0) {
328 						default:
329 						{
330 							const gchar* _tmp27_;
331 							gchar* _tmp28_;
332 							_tmp27_ = checked_value;
333 							_tmp28_ = g_strdup (_tmp27_);
334 							_g_free0 (warning_color);
335 							warning_color = _tmp28_;
336 							break;
337 						}
338 					}
339 				} else if (_tmp24_ == ((0 != _tmp23_label2) ? _tmp23_label2 : (_tmp23_label2 = g_quark_from_static_string ("note")))) {
340 					switch (0) {
341 						default:
342 						{
343 							const gchar* _tmp29_;
344 							gchar* _tmp30_;
345 							_tmp29_ = checked_value;
346 							_tmp30_ = g_strdup (_tmp29_);
347 							_g_free0 (note_color);
348 							note_color = _tmp30_;
349 							break;
350 						}
351 					}
352 				} else if (_tmp24_ == ((0 != _tmp23_label3) ? _tmp23_label3 : (_tmp23_label3 = g_quark_from_static_string ("caret")))) {
353 					switch (0) {
354 						default:
355 						{
356 							const gchar* _tmp31_;
357 							gchar* _tmp32_;
358 							_tmp31_ = checked_value;
359 							_tmp32_ = g_strdup (_tmp31_);
360 							_g_free0 (caret_color);
361 							caret_color = _tmp32_;
362 							break;
363 						}
364 					}
365 				} else if (_tmp24_ == ((0 != _tmp23_label4) ? _tmp23_label4 : (_tmp23_label4 = g_quark_from_static_string ("locus")))) {
366 					switch (0) {
367 						default:
368 						{
369 							const gchar* _tmp33_;
370 							gchar* _tmp34_;
371 							_tmp33_ = checked_value;
372 							_tmp34_ = g_strdup (_tmp33_);
373 							_g_free0 (locus_color);
374 							locus_color = _tmp34_;
375 							break;
376 						}
377 					}
378 				} else if (_tmp24_ == ((0 != _tmp23_label5) ? _tmp23_label5 : (_tmp23_label5 = g_quark_from_static_string ("quote")))) {
379 					switch (0) {
380 						default:
381 						{
382 							const gchar* _tmp35_;
383 							gchar* _tmp36_;
384 							_tmp35_ = checked_value;
385 							_tmp36_ = g_strdup (_tmp35_);
386 							_g_free0 (quote_color);
387 							quote_color = _tmp36_;
388 							break;
389 						}
390 					}
391 				} else {
392 					switch (0) {
393 						default:
394 						{
395 							result = FALSE;
396 							eq = (_vala_array_free (eq, eq_length1, (GDestroyNotify) g_free), NULL);
397 							fragments = (_vala_array_free (fragments, fragments_length1, (GDestroyNotify) g_free), NULL);
398 							_g_free0 (quote_color);
399 							_g_free0 (locus_color);
400 							_g_free0 (caret_color);
401 							_g_free0 (note_color);
402 							_g_free0 (warning_color);
403 							_g_free0 (error_color);
404 							return result;
405 						}
406 					}
407 				}
408 				eq = (_vala_array_free (eq, eq_length1, (GDestroyNotify) g_free), NULL);
409 			}
410 		}
411 	}
412 	if (colored_output == VALA_REPORT_COLORED_ALWAYS) {
413 		_tmp37_ = TRUE;
414 	} else {
415 		gboolean _tmp38_ = FALSE;
416 		if (colored_output == VALA_REPORT_COLORED_AUTO) {
417 			FILE* _tmp39_;
418 			_tmp39_ = stderr;
419 			_tmp38_ = vala_report_is_atty (self, fileno (_tmp39_));
420 		} else {
421 			_tmp38_ = FALSE;
422 		}
423 		_tmp37_ = _tmp38_;
424 	}
425 	if (_tmp37_) {
426 		const gchar* _tmp40_;
427 		const gchar* _tmp45_;
428 		const gchar* _tmp50_;
429 		const gchar* _tmp55_;
430 		const gchar* _tmp60_;
431 		const gchar* _tmp65_;
432 		_tmp40_ = error_color;
433 		if (_tmp40_ != NULL) {
434 			const gchar* _tmp41_;
435 			gchar* _tmp42_;
436 			gchar* _tmp43_;
437 			gchar* _tmp44_;
438 			_tmp41_ = error_color;
439 			_tmp42_ = g_strconcat ("\x1b[0", _tmp41_, NULL);
440 			_tmp43_ = _tmp42_;
441 			_tmp44_ = g_strconcat (_tmp43_, "m", NULL);
442 			_g_free0 (self->priv->error_color_start);
443 			self->priv->error_color_start = _tmp44_;
444 			_g_free0 (_tmp43_);
445 			self->priv->error_color_end = VALA_REPORT_ANSI_COLOR_END;
446 		}
447 		_tmp45_ = warning_color;
448 		if (_tmp45_ != NULL) {
449 			const gchar* _tmp46_;
450 			gchar* _tmp47_;
451 			gchar* _tmp48_;
452 			gchar* _tmp49_;
453 			_tmp46_ = warning_color;
454 			_tmp47_ = g_strconcat ("\x1b[0", _tmp46_, NULL);
455 			_tmp48_ = _tmp47_;
456 			_tmp49_ = g_strconcat (_tmp48_, "m", NULL);
457 			_g_free0 (self->priv->warning_color_start);
458 			self->priv->warning_color_start = _tmp49_;
459 			_g_free0 (_tmp48_);
460 			self->priv->warning_color_end = VALA_REPORT_ANSI_COLOR_END;
461 		}
462 		_tmp50_ = note_color;
463 		if (_tmp50_ != NULL) {
464 			const gchar* _tmp51_;
465 			gchar* _tmp52_;
466 			gchar* _tmp53_;
467 			gchar* _tmp54_;
468 			_tmp51_ = note_color;
469 			_tmp52_ = g_strconcat ("\x1b[0", _tmp51_, NULL);
470 			_tmp53_ = _tmp52_;
471 			_tmp54_ = g_strconcat (_tmp53_, "m", NULL);
472 			_g_free0 (self->priv->note_color_start);
473 			self->priv->note_color_start = _tmp54_;
474 			_g_free0 (_tmp53_);
475 			self->priv->note_color_end = VALA_REPORT_ANSI_COLOR_END;
476 		}
477 		_tmp55_ = caret_color;
478 		if (_tmp55_ != NULL) {
479 			const gchar* _tmp56_;
480 			gchar* _tmp57_;
481 			gchar* _tmp58_;
482 			gchar* _tmp59_;
483 			_tmp56_ = caret_color;
484 			_tmp57_ = g_strconcat ("\x1b[0", _tmp56_, NULL);
485 			_tmp58_ = _tmp57_;
486 			_tmp59_ = g_strconcat (_tmp58_, "m", NULL);
487 			_g_free0 (self->priv->caret_color_start);
488 			self->priv->caret_color_start = _tmp59_;
489 			_g_free0 (_tmp58_);
490 			self->priv->caret_color_end = VALA_REPORT_ANSI_COLOR_END;
491 		}
492 		_tmp60_ = locus_color;
493 		if (_tmp60_ != NULL) {
494 			const gchar* _tmp61_;
495 			gchar* _tmp62_;
496 			gchar* _tmp63_;
497 			gchar* _tmp64_;
498 			_tmp61_ = locus_color;
499 			_tmp62_ = g_strconcat ("\x1b[0", _tmp61_, NULL);
500 			_tmp63_ = _tmp62_;
501 			_tmp64_ = g_strconcat (_tmp63_, "m", NULL);
502 			_g_free0 (self->priv->locus_color_start);
503 			self->priv->locus_color_start = _tmp64_;
504 			_g_free0 (_tmp63_);
505 			self->priv->locus_color_end = VALA_REPORT_ANSI_COLOR_END;
506 		}
507 		_tmp65_ = quote_color;
508 		if (_tmp65_ != NULL) {
509 			const gchar* _tmp66_;
510 			gchar* _tmp67_;
511 			gchar* _tmp68_;
512 			gchar* _tmp69_;
513 			_tmp66_ = quote_color;
514 			_tmp67_ = g_strconcat ("\x1b[0", _tmp66_, NULL);
515 			_tmp68_ = _tmp67_;
516 			_tmp69_ = g_strconcat (_tmp68_, "m", NULL);
517 			_g_free0 (self->priv->quote_color_start);
518 			self->priv->quote_color_start = _tmp69_;
519 			_g_free0 (_tmp68_);
520 			self->priv->quote_color_end = VALA_REPORT_ANSI_COLOR_END;
521 		}
522 	}
523 	result = TRUE;
524 	fragments = (_vala_array_free (fragments, fragments_length1, (GDestroyNotify) g_free), NULL);
525 	_g_free0 (quote_color);
526 	_g_free0 (locus_color);
527 	_g_free0 (caret_color);
528 	_g_free0 (note_color);
529 	_g_free0 (warning_color);
530 	_g_free0 (error_color);
531 	return result;
532 }
533 
534 /**
535  * Set the error verbosity.
536  */
537 void
vala_report_set_verbose_errors(ValaReport * self,gboolean verbose)538 vala_report_set_verbose_errors (ValaReport* self,
539                                 gboolean verbose)
540 {
541 	g_return_if_fail (self != NULL);
542 	self->priv->verbose_errors = verbose;
543 }
544 
545 /**
546  * Returns the total number of warnings reported.
547  */
548 gint
vala_report_get_warnings(ValaReport * self)549 vala_report_get_warnings (ValaReport* self)
550 {
551 	gint result = 0;
552 	g_return_val_if_fail (self != NULL, 0);
553 	result = self->warnings;
554 	return result;
555 }
556 
557 /**
558  * Returns the total number of errors reported.
559  */
560 gint
vala_report_get_errors(ValaReport * self)561 vala_report_get_errors (ValaReport* self)
562 {
563 	gint result = 0;
564 	g_return_val_if_fail (self != NULL, 0);
565 	result = self->errors;
566 	return result;
567 }
568 
569 /**
570  * Pretty-print the actual line of offending code if possible.
571  */
572 static gchar
string_get(const gchar * self,glong index)573 string_get (const gchar* self,
574             glong index)
575 {
576 	gchar _tmp0_;
577 	gchar result = '\0';
578 	g_return_val_if_fail (self != NULL, '\0');
579 	_tmp0_ = ((gchar*) self)[index];
580 	result = _tmp0_;
581 	return result;
582 }
583 
584 static void
vala_report_report_source(ValaReport * self,ValaSourceReference * source)585 vala_report_report_source (ValaReport* self,
586                            ValaSourceReference* source)
587 {
588 	ValaSourceLocation _tmp0_ = {0};
589 	ValaSourceLocation _tmp1_;
590 	ValaSourceLocation _tmp2_ = {0};
591 	ValaSourceLocation _tmp3_;
592 	gchar* offending_line = NULL;
593 	ValaSourceFile* _tmp4_;
594 	ValaSourceFile* _tmp5_;
595 	ValaSourceLocation _tmp6_ = {0};
596 	ValaSourceLocation _tmp7_;
597 	gchar* _tmp8_;
598 	const gchar* _tmp9_;
599 	g_return_if_fail (self != NULL);
600 	g_return_if_fail (source != NULL);
601 	vala_source_reference_get_begin (source, &_tmp0_);
602 	_tmp1_ = _tmp0_;
603 	vala_source_reference_get_end (source, &_tmp2_);
604 	_tmp3_ = _tmp2_;
605 	if (_tmp1_.line != _tmp3_.line) {
606 		return;
607 	}
608 	_tmp4_ = vala_source_reference_get_file (source);
609 	_tmp5_ = _tmp4_;
610 	vala_source_reference_get_begin (source, &_tmp6_);
611 	_tmp7_ = _tmp6_;
612 	_tmp8_ = vala_source_file_get_source_line (_tmp5_, _tmp7_.line);
613 	offending_line = _tmp8_;
614 	_tmp9_ = offending_line;
615 	if (_tmp9_ != NULL) {
616 		FILE* _tmp10_;
617 		const gchar* _tmp11_;
618 		gint idx = 0;
619 		FILE* _tmp19_;
620 		const gchar* _tmp20_;
621 		FILE* _tmp30_;
622 		const gchar* _tmp31_;
623 		FILE* _tmp32_;
624 		_tmp10_ = stderr;
625 		_tmp11_ = offending_line;
626 		fprintf (_tmp10_, "%s\n", _tmp11_);
627 		{
628 			gboolean _tmp12_ = FALSE;
629 			idx = 1;
630 			_tmp12_ = TRUE;
631 			while (TRUE) {
632 				ValaSourceLocation _tmp14_ = {0};
633 				ValaSourceLocation _tmp15_;
634 				const gchar* _tmp16_;
635 				if (!_tmp12_) {
636 					gint _tmp13_;
637 					idx = idx + 1;
638 					_tmp13_ = idx;
639 				}
640 				_tmp12_ = FALSE;
641 				vala_source_reference_get_begin (source, &_tmp14_);
642 				_tmp15_ = _tmp14_;
643 				if (!(idx < _tmp15_.column)) {
644 					break;
645 				}
646 				_tmp16_ = offending_line;
647 				if (string_get (_tmp16_, (glong) (idx - 1)) == '\t') {
648 					FILE* _tmp17_;
649 					_tmp17_ = stderr;
650 					fprintf (_tmp17_, "\t");
651 				} else {
652 					FILE* _tmp18_;
653 					_tmp18_ = stderr;
654 					fprintf (_tmp18_, " ");
655 				}
656 			}
657 		}
658 		_tmp19_ = stderr;
659 		_tmp20_ = self->priv->caret_color_start;
660 		fputs (_tmp20_, _tmp19_);
661 		{
662 			ValaSourceLocation _tmp21_ = {0};
663 			ValaSourceLocation _tmp22_;
664 			gboolean _tmp23_ = FALSE;
665 			vala_source_reference_get_begin (source, &_tmp21_);
666 			_tmp22_ = _tmp21_;
667 			idx = _tmp22_.column;
668 			_tmp23_ = TRUE;
669 			while (TRUE) {
670 				ValaSourceLocation _tmp25_ = {0};
671 				ValaSourceLocation _tmp26_;
672 				const gchar* _tmp27_;
673 				if (!_tmp23_) {
674 					gint _tmp24_;
675 					idx = idx + 1;
676 					_tmp24_ = idx;
677 				}
678 				_tmp23_ = FALSE;
679 				vala_source_reference_get_end (source, &_tmp25_);
680 				_tmp26_ = _tmp25_;
681 				if (!(idx <= _tmp26_.column)) {
682 					break;
683 				}
684 				_tmp27_ = offending_line;
685 				if (string_get (_tmp27_, (glong) (idx - 1)) == '\t') {
686 					FILE* _tmp28_;
687 					_tmp28_ = stderr;
688 					fprintf (_tmp28_, "\t");
689 				} else {
690 					FILE* _tmp29_;
691 					_tmp29_ = stderr;
692 					fprintf (_tmp29_, "^");
693 				}
694 			}
695 		}
696 		_tmp30_ = stderr;
697 		_tmp31_ = self->priv->caret_color_end;
698 		fputs (_tmp31_, _tmp30_);
699 		_tmp32_ = stderr;
700 		fprintf (_tmp32_, "\n");
701 	}
702 	_g_free0 (offending_line);
703 }
704 
705 static glong
string_strnlen(gchar * str,glong maxlen)706 string_strnlen (gchar* str,
707                 glong maxlen)
708 {
709 	gchar* end = NULL;
710 	gchar* _tmp0_;
711 	gchar* _tmp1_;
712 	glong result = 0L;
713 	_tmp0_ = memchr (str, 0, (gsize) maxlen);
714 	end = _tmp0_;
715 	_tmp1_ = end;
716 	if (_tmp1_ == NULL) {
717 		result = maxlen;
718 		return result;
719 	} else {
720 		gchar* _tmp2_;
721 		_tmp2_ = end;
722 		result = (glong) (_tmp2_ - str);
723 		return result;
724 	}
725 }
726 
727 static gchar*
string_substring(const gchar * self,glong offset,glong len)728 string_substring (const gchar* self,
729                   glong offset,
730                   glong len)
731 {
732 	glong string_length = 0L;
733 	gboolean _tmp0_ = FALSE;
734 	gchar* _tmp3_;
735 	gchar* result = NULL;
736 	g_return_val_if_fail (self != NULL, NULL);
737 	if (offset >= ((glong) 0)) {
738 		_tmp0_ = len >= ((glong) 0);
739 	} else {
740 		_tmp0_ = FALSE;
741 	}
742 	if (_tmp0_) {
743 		string_length = string_strnlen ((gchar*) self, offset + len);
744 	} else {
745 		gint _tmp1_;
746 		gint _tmp2_;
747 		_tmp1_ = strlen (self);
748 		_tmp2_ = _tmp1_;
749 		string_length = (glong) _tmp2_;
750 	}
751 	if (offset < ((glong) 0)) {
752 		offset = string_length + offset;
753 		g_return_val_if_fail (offset >= ((glong) 0), NULL);
754 	} else {
755 		g_return_val_if_fail (offset <= string_length, NULL);
756 	}
757 	if (len < ((glong) 0)) {
758 		len = string_length - offset;
759 	}
760 	g_return_val_if_fail ((offset + len) <= string_length, NULL);
761 	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
762 	result = _tmp3_;
763 	return result;
764 }
765 
766 static gint
string_index_of_char(const gchar * self,gunichar c,gint start_index)767 string_index_of_char (const gchar* self,
768                       gunichar c,
769                       gint start_index)
770 {
771 	gchar* _result_ = NULL;
772 	gchar* _tmp0_;
773 	gchar* _tmp1_;
774 	gint result = 0;
775 	g_return_val_if_fail (self != NULL, 0);
776 	_tmp0_ = g_utf8_strchr (((gchar*) self) + start_index, (gssize) -1, c);
777 	_result_ = _tmp0_;
778 	_tmp1_ = _result_;
779 	if (_tmp1_ != NULL) {
780 		gchar* _tmp2_;
781 		_tmp2_ = _result_;
782 		result = (gint) (_tmp2_ - ((gchar*) self));
783 		return result;
784 	} else {
785 		result = -1;
786 		return result;
787 	}
788 }
789 
790 static const gchar*
string_offset(const gchar * self,glong offset)791 string_offset (const gchar* self,
792                glong offset)
793 {
794 	const gchar* result = NULL;
795 	g_return_val_if_fail (self != NULL, NULL);
796 	result = (const gchar*) (((gchar*) self) + offset);
797 	return result;
798 }
799 
800 static void
vala_report_print_highlighted_message(ValaReport * self,const gchar * message)801 vala_report_print_highlighted_message (ValaReport* self,
802                                        const gchar* message)
803 {
804 	gint start = 0;
805 	gint cur = 0;
806 	FILE* _tmp19_;
807 	const gchar* _tmp20_;
808 	g_return_if_fail (self != NULL);
809 	g_return_if_fail (message != NULL);
810 	start = 0;
811 	cur = 0;
812 	while (TRUE) {
813 		gboolean _tmp0_ = FALSE;
814 		if (!(string_get (message, (glong) cur) != '\0')) {
815 			break;
816 		}
817 		if (string_get (message, (glong) cur) == '\'') {
818 			_tmp0_ = TRUE;
819 		} else {
820 			_tmp0_ = string_get (message, (glong) cur) == '`';
821 		}
822 		if (_tmp0_) {
823 			const gchar* _tmp1_ = NULL;
824 			const gchar* end_chars = NULL;
825 			FILE* _tmp2_;
826 			gchar* _tmp3_;
827 			gchar* _tmp4_;
828 			gint _tmp5_;
829 			if (string_get (message, (glong) cur) == '`') {
830 				_tmp1_ = "`'";
831 			} else {
832 				_tmp1_ = "'";
833 			}
834 			end_chars = _tmp1_;
835 			_tmp2_ = stderr;
836 			_tmp3_ = string_substring (message, (glong) start, (glong) (cur - start));
837 			_tmp4_ = _tmp3_;
838 			fputs (_tmp4_, _tmp2_);
839 			_g_free0 (_tmp4_);
840 			start = cur;
841 			_tmp5_ = cur;
842 			cur = _tmp5_ + 1;
843 			while (TRUE) {
844 				gboolean _tmp6_ = FALSE;
845 				gint _tmp8_;
846 				if (string_get (message, (glong) cur) != '\0') {
847 					const gchar* _tmp7_;
848 					_tmp7_ = end_chars;
849 					_tmp6_ = string_index_of_char (_tmp7_, (gunichar) string_get (message, (glong) cur), 0) < 0;
850 				} else {
851 					_tmp6_ = FALSE;
852 				}
853 				if (!_tmp6_) {
854 					break;
855 				}
856 				_tmp8_ = cur;
857 				cur = _tmp8_ + 1;
858 			}
859 			if (string_get (message, (glong) cur) == '\0') {
860 				FILE* _tmp9_;
861 				gchar* _tmp10_;
862 				gchar* _tmp11_;
863 				_tmp9_ = stderr;
864 				_tmp10_ = string_substring (message, (glong) start, (glong) (cur - start));
865 				_tmp11_ = _tmp10_;
866 				fputs (_tmp11_, _tmp9_);
867 				_g_free0 (_tmp11_);
868 				start = cur;
869 			} else {
870 				gint _tmp12_;
871 				FILE* _tmp13_;
872 				const gchar* _tmp14_;
873 				gchar* _tmp15_;
874 				gchar* _tmp16_;
875 				const gchar* _tmp17_;
876 				_tmp12_ = cur;
877 				cur = _tmp12_ + 1;
878 				_tmp13_ = stderr;
879 				_tmp14_ = self->priv->quote_color_start;
880 				_tmp15_ = string_substring (message, (glong) start, (glong) (cur - start));
881 				_tmp16_ = _tmp15_;
882 				_tmp17_ = self->priv->quote_color_end;
883 				fprintf (_tmp13_, "%s%s%s", _tmp14_, _tmp16_, _tmp17_);
884 				_g_free0 (_tmp16_);
885 				start = cur;
886 			}
887 		} else {
888 			gint _tmp18_;
889 			_tmp18_ = cur;
890 			cur = _tmp18_ + 1;
891 		}
892 	}
893 	_tmp19_ = stderr;
894 	_tmp20_ = string_offset (message, (glong) start);
895 	fputs (_tmp20_, _tmp19_);
896 }
897 
898 static void
vala_report_print_message(ValaReport * self,ValaSourceReference * source,const gchar * type,const gchar * type_color_start,const gchar * type_color_end,const gchar * message,gboolean do_report_source)899 vala_report_print_message (ValaReport* self,
900                            ValaSourceReference* source,
901                            const gchar* type,
902                            const gchar* type_color_start,
903                            const gchar* type_color_end,
904                            const gchar* message,
905                            gboolean do_report_source)
906 {
907 	FILE* _tmp5_;
908 	FILE* _tmp6_;
909 	gboolean _tmp7_ = FALSE;
910 	g_return_if_fail (self != NULL);
911 	g_return_if_fail (type != NULL);
912 	g_return_if_fail (type_color_start != NULL);
913 	g_return_if_fail (type_color_end != NULL);
914 	g_return_if_fail (message != NULL);
915 	if (source != NULL) {
916 		FILE* _tmp0_;
917 		const gchar* _tmp1_;
918 		gchar* _tmp2_;
919 		gchar* _tmp3_;
920 		const gchar* _tmp4_;
921 		_tmp0_ = stderr;
922 		_tmp1_ = self->priv->locus_color_start;
923 		_tmp2_ = vala_source_reference_to_string (source);
924 		_tmp3_ = _tmp2_;
925 		_tmp4_ = self->priv->locus_color_end;
926 		fprintf (_tmp0_, "%s%s:%s ", _tmp1_, _tmp3_, _tmp4_);
927 		_g_free0 (_tmp3_);
928 	}
929 	_tmp5_ = stderr;
930 	fprintf (_tmp5_, "%s%s:%s ", type_color_start, type, type_color_end);
931 	vala_report_print_highlighted_message (self, message);
932 	_tmp6_ = stderr;
933 	fputc ('\n', _tmp6_);
934 	if (do_report_source) {
935 		_tmp7_ = source != NULL;
936 	} else {
937 		_tmp7_ = FALSE;
938 	}
939 	if (_tmp7_) {
940 		vala_report_report_source (self, source);
941 	}
942 }
943 
944 /**
945  * Reports the specified message as note.
946  *
947  * @param source  reference to source code
948  * @param message note message
949  */
950 static void
vala_report_real_note(ValaReport * self,ValaSourceReference * source,const gchar * message)951 vala_report_real_note (ValaReport* self,
952                        ValaSourceReference* source,
953                        const gchar* message)
954 {
955 	gboolean _tmp0_;
956 	const gchar* _tmp1_;
957 	const gchar* _tmp2_;
958 	g_return_if_fail (message != NULL);
959 	_tmp0_ = self->priv->_enable_warnings;
960 	if (!_tmp0_) {
961 		return;
962 	}
963 	_tmp1_ = self->priv->note_color_start;
964 	_tmp2_ = self->priv->note_color_end;
965 	vala_report_print_message (self, source, "note", _tmp1_, _tmp2_, message, self->priv->verbose_errors);
966 }
967 
968 void
vala_report_note(ValaReport * self,ValaSourceReference * source,const gchar * message)969 vala_report_note (ValaReport* self,
970                   ValaSourceReference* source,
971                   const gchar* message)
972 {
973 	g_return_if_fail (self != NULL);
974 	VALA_REPORT_GET_CLASS (self)->note (self, source, message);
975 }
976 
977 /**
978  * Reports the specified message as deprecation warning.
979  *
980  * @param source  reference to source code
981  * @param message warning message
982  */
983 static void
vala_report_real_depr(ValaReport * self,ValaSourceReference * source,const gchar * message)984 vala_report_real_depr (ValaReport* self,
985                        ValaSourceReference* source,
986                        const gchar* message)
987 {
988 	gboolean _tmp0_;
989 	gint _tmp1_;
990 	const gchar* _tmp2_;
991 	const gchar* _tmp3_;
992 	g_return_if_fail (message != NULL);
993 	_tmp0_ = self->priv->_enable_warnings;
994 	if (!_tmp0_) {
995 		return;
996 	}
997 	_tmp1_ = self->warnings;
998 	self->warnings = _tmp1_ + 1;
999 	_tmp2_ = self->priv->warning_color_start;
1000 	_tmp3_ = self->priv->warning_color_end;
1001 	vala_report_print_message (self, source, "warning", _tmp2_, _tmp3_, message, FALSE);
1002 }
1003 
1004 void
vala_report_depr(ValaReport * self,ValaSourceReference * source,const gchar * message)1005 vala_report_depr (ValaReport* self,
1006                   ValaSourceReference* source,
1007                   const gchar* message)
1008 {
1009 	g_return_if_fail (self != NULL);
1010 	VALA_REPORT_GET_CLASS (self)->depr (self, source, message);
1011 }
1012 
1013 /**
1014  * Reports the specified message as warning.
1015  *
1016  * @param source  reference to source code
1017  * @param message warning message
1018  */
1019 static void
vala_report_real_warn(ValaReport * self,ValaSourceReference * source,const gchar * message)1020 vala_report_real_warn (ValaReport* self,
1021                        ValaSourceReference* source,
1022                        const gchar* message)
1023 {
1024 	gboolean _tmp0_;
1025 	gint _tmp1_;
1026 	const gchar* _tmp2_;
1027 	const gchar* _tmp3_;
1028 	g_return_if_fail (message != NULL);
1029 	_tmp0_ = self->priv->_enable_warnings;
1030 	if (!_tmp0_) {
1031 		return;
1032 	}
1033 	_tmp1_ = self->warnings;
1034 	self->warnings = _tmp1_ + 1;
1035 	_tmp2_ = self->priv->warning_color_start;
1036 	_tmp3_ = self->priv->warning_color_end;
1037 	vala_report_print_message (self, source, "warning", _tmp2_, _tmp3_, message, self->priv->verbose_errors);
1038 }
1039 
1040 void
vala_report_warn(ValaReport * self,ValaSourceReference * source,const gchar * message)1041 vala_report_warn (ValaReport* self,
1042                   ValaSourceReference* source,
1043                   const gchar* message)
1044 {
1045 	g_return_if_fail (self != NULL);
1046 	VALA_REPORT_GET_CLASS (self)->warn (self, source, message);
1047 }
1048 
1049 /**
1050  * Reports the specified message as error.
1051  *
1052  * @param source  reference to source code
1053  * @param message error message
1054  */
1055 static void
vala_report_real_err(ValaReport * self,ValaSourceReference * source,const gchar * message)1056 vala_report_real_err (ValaReport* self,
1057                       ValaSourceReference* source,
1058                       const gchar* message)
1059 {
1060 	gint _tmp0_;
1061 	const gchar* _tmp1_;
1062 	const gchar* _tmp2_;
1063 	g_return_if_fail (message != NULL);
1064 	_tmp0_ = self->errors;
1065 	self->errors = _tmp0_ + 1;
1066 	_tmp1_ = self->priv->error_color_start;
1067 	_tmp2_ = self->priv->error_color_end;
1068 	vala_report_print_message (self, source, "error", _tmp1_, _tmp2_, message, self->priv->verbose_errors);
1069 }
1070 
1071 void
vala_report_err(ValaReport * self,ValaSourceReference * source,const gchar * message)1072 vala_report_err (ValaReport* self,
1073                  ValaSourceReference* source,
1074                  const gchar* message)
1075 {
1076 	g_return_if_fail (self != NULL);
1077 	VALA_REPORT_GET_CLASS (self)->err (self, source, message);
1078 }
1079 
1080 void
vala_report_notice(ValaSourceReference * source,const gchar * message)1081 vala_report_notice (ValaSourceReference* source,
1082                     const gchar* message)
1083 {
1084 	ValaCodeContext* _tmp0_;
1085 	ValaCodeContext* _tmp1_;
1086 	ValaReport* _tmp2_;
1087 	ValaReport* _tmp3_;
1088 	g_return_if_fail (message != NULL);
1089 	_tmp0_ = vala_code_context_get ();
1090 	_tmp1_ = _tmp0_;
1091 	_tmp2_ = vala_code_context_get_report (_tmp1_);
1092 	_tmp3_ = _tmp2_;
1093 	vala_report_note (_tmp3_, source, message);
1094 	_vala_code_context_unref0 (_tmp1_);
1095 }
1096 
1097 void
vala_report_deprecated(ValaSourceReference * source,const gchar * message)1098 vala_report_deprecated (ValaSourceReference* source,
1099                         const gchar* message)
1100 {
1101 	ValaCodeContext* _tmp0_;
1102 	ValaCodeContext* _tmp1_;
1103 	ValaReport* _tmp2_;
1104 	ValaReport* _tmp3_;
1105 	g_return_if_fail (message != NULL);
1106 	_tmp0_ = vala_code_context_get ();
1107 	_tmp1_ = _tmp0_;
1108 	_tmp2_ = vala_code_context_get_report (_tmp1_);
1109 	_tmp3_ = _tmp2_;
1110 	vala_report_depr (_tmp3_, source, message);
1111 	_vala_code_context_unref0 (_tmp1_);
1112 }
1113 
1114 void
vala_report_experimental(ValaSourceReference * source,const gchar * message)1115 vala_report_experimental (ValaSourceReference* source,
1116                           const gchar* message)
1117 {
1118 	ValaCodeContext* _tmp0_;
1119 	ValaCodeContext* _tmp1_;
1120 	ValaReport* _tmp2_;
1121 	ValaReport* _tmp3_;
1122 	g_return_if_fail (message != NULL);
1123 	_tmp0_ = vala_code_context_get ();
1124 	_tmp1_ = _tmp0_;
1125 	_tmp2_ = vala_code_context_get_report (_tmp1_);
1126 	_tmp3_ = _tmp2_;
1127 	vala_report_depr (_tmp3_, source, message);
1128 	_vala_code_context_unref0 (_tmp1_);
1129 }
1130 
1131 void
vala_report_warning(ValaSourceReference * source,const gchar * message)1132 vala_report_warning (ValaSourceReference* source,
1133                      const gchar* message)
1134 {
1135 	ValaCodeContext* _tmp0_;
1136 	ValaCodeContext* _tmp1_;
1137 	ValaReport* _tmp2_;
1138 	ValaReport* _tmp3_;
1139 	g_return_if_fail (message != NULL);
1140 	_tmp0_ = vala_code_context_get ();
1141 	_tmp1_ = _tmp0_;
1142 	_tmp2_ = vala_code_context_get_report (_tmp1_);
1143 	_tmp3_ = _tmp2_;
1144 	vala_report_warn (_tmp3_, source, message);
1145 	_vala_code_context_unref0 (_tmp1_);
1146 }
1147 
1148 void
vala_report_error(ValaSourceReference * source,const gchar * message)1149 vala_report_error (ValaSourceReference* source,
1150                    const gchar* message)
1151 {
1152 	ValaCodeContext* _tmp0_;
1153 	ValaCodeContext* _tmp1_;
1154 	ValaReport* _tmp2_;
1155 	ValaReport* _tmp3_;
1156 	g_return_if_fail (message != NULL);
1157 	_tmp0_ = vala_code_context_get ();
1158 	_tmp1_ = _tmp0_;
1159 	_tmp2_ = vala_code_context_get_report (_tmp1_);
1160 	_tmp3_ = _tmp2_;
1161 	vala_report_err (_tmp3_, source, message);
1162 	_vala_code_context_unref0 (_tmp1_);
1163 }
1164 
1165 static gboolean
vala_report_is_atty(ValaReport * self,gint fd)1166 vala_report_is_atty (ValaReport* self,
1167                      gint fd)
1168 {
1169 	GModule* module = NULL;
1170 	GModule* _tmp0_;
1171 	GModule* _tmp1_;
1172 	void* _func = NULL;
1173 	GModule* _tmp2_;
1174 	void* _tmp3_ = NULL;
1175 	void* _tmp4_;
1176 	ValaReportAttyFunc func = NULL;
1177 	void* _tmp5_;
1178 	ValaReportAttyFunc _tmp6_;
1179 	gboolean result = FALSE;
1180 	g_return_val_if_fail (self != NULL, FALSE);
1181 	_tmp0_ = g_module_open (NULL, G_MODULE_BIND_LAZY);
1182 	module = _tmp0_;
1183 	_tmp1_ = module;
1184 	if (_tmp1_ == NULL) {
1185 		result = FALSE;
1186 		_g_module_close0 (module);
1187 		return result;
1188 	}
1189 	_tmp2_ = module;
1190 	g_module_symbol (_tmp2_, "isatty", &_tmp3_);
1191 	_func = _tmp3_;
1192 	_tmp4_ = _func;
1193 	if (_tmp4_ == NULL) {
1194 		result = FALSE;
1195 		_g_module_close0 (module);
1196 		return result;
1197 	}
1198 	_tmp5_ = _func;
1199 	func = (ValaReportAttyFunc) _tmp5_;
1200 	_tmp6_ = func;
1201 	result = _tmp6_ (fd) == 1;
1202 	_g_module_close0 (module);
1203 	return result;
1204 }
1205 
1206 ValaReport*
vala_report_construct(GType object_type)1207 vala_report_construct (GType object_type)
1208 {
1209 	ValaReport* self = NULL;
1210 	self = (ValaReport*) g_type_create_instance (object_type);
1211 	return self;
1212 }
1213 
1214 ValaReport*
vala_report_new(void)1215 vala_report_new (void)
1216 {
1217 	return vala_report_construct (VALA_TYPE_REPORT);
1218 }
1219 
1220 static void
vala_value_report_init(GValue * value)1221 vala_value_report_init (GValue* value)
1222 {
1223 	value->data[0].v_pointer = NULL;
1224 }
1225 
1226 static void
vala_value_report_free_value(GValue * value)1227 vala_value_report_free_value (GValue* value)
1228 {
1229 	if (value->data[0].v_pointer) {
1230 		vala_report_unref (value->data[0].v_pointer);
1231 	}
1232 }
1233 
1234 static void
vala_value_report_copy_value(const GValue * src_value,GValue * dest_value)1235 vala_value_report_copy_value (const GValue* src_value,
1236                               GValue* dest_value)
1237 {
1238 	if (src_value->data[0].v_pointer) {
1239 		dest_value->data[0].v_pointer = vala_report_ref (src_value->data[0].v_pointer);
1240 	} else {
1241 		dest_value->data[0].v_pointer = NULL;
1242 	}
1243 }
1244 
1245 static gpointer
vala_value_report_peek_pointer(const GValue * value)1246 vala_value_report_peek_pointer (const GValue* value)
1247 {
1248 	return value->data[0].v_pointer;
1249 }
1250 
1251 static gchar*
vala_value_report_collect_value(GValue * value,guint n_collect_values,GTypeCValue * collect_values,guint collect_flags)1252 vala_value_report_collect_value (GValue* value,
1253                                  guint n_collect_values,
1254                                  GTypeCValue* collect_values,
1255                                  guint collect_flags)
1256 {
1257 	if (collect_values[0].v_pointer) {
1258 		ValaReport * object;
1259 		object = collect_values[0].v_pointer;
1260 		if (object->parent_instance.g_class == NULL) {
1261 			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
1262 		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
1263 			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
1264 		}
1265 		value->data[0].v_pointer = vala_report_ref (object);
1266 	} else {
1267 		value->data[0].v_pointer = NULL;
1268 	}
1269 	return NULL;
1270 }
1271 
1272 static gchar*
vala_value_report_lcopy_value(const GValue * value,guint n_collect_values,GTypeCValue * collect_values,guint collect_flags)1273 vala_value_report_lcopy_value (const GValue* value,
1274                                guint n_collect_values,
1275                                GTypeCValue* collect_values,
1276                                guint collect_flags)
1277 {
1278 	ValaReport ** object_p;
1279 	object_p = collect_values[0].v_pointer;
1280 	if (!object_p) {
1281 		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
1282 	}
1283 	if (!value->data[0].v_pointer) {
1284 		*object_p = NULL;
1285 	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
1286 		*object_p = value->data[0].v_pointer;
1287 	} else {
1288 		*object_p = vala_report_ref (value->data[0].v_pointer);
1289 	}
1290 	return NULL;
1291 }
1292 
1293 GParamSpec*
vala_param_spec_report(const gchar * name,const gchar * nick,const gchar * blurb,GType object_type,GParamFlags flags)1294 vala_param_spec_report (const gchar* name,
1295                         const gchar* nick,
1296                         const gchar* blurb,
1297                         GType object_type,
1298                         GParamFlags flags)
1299 {
1300 	ValaParamSpecReport* spec;
1301 	g_return_val_if_fail (g_type_is_a (object_type, VALA_TYPE_REPORT), NULL);
1302 	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
1303 	G_PARAM_SPEC (spec)->value_type = object_type;
1304 	return G_PARAM_SPEC (spec);
1305 }
1306 
1307 gpointer
vala_value_get_report(const GValue * value)1308 vala_value_get_report (const GValue* value)
1309 {
1310 	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_REPORT), NULL);
1311 	return value->data[0].v_pointer;
1312 }
1313 
1314 void
vala_value_set_report(GValue * value,gpointer v_object)1315 vala_value_set_report (GValue* value,
1316                        gpointer v_object)
1317 {
1318 	ValaReport * old;
1319 	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_REPORT));
1320 	old = value->data[0].v_pointer;
1321 	if (v_object) {
1322 		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, VALA_TYPE_REPORT));
1323 		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
1324 		value->data[0].v_pointer = v_object;
1325 		vala_report_ref (value->data[0].v_pointer);
1326 	} else {
1327 		value->data[0].v_pointer = NULL;
1328 	}
1329 	if (old) {
1330 		vala_report_unref (old);
1331 	}
1332 }
1333 
1334 void
vala_value_take_report(GValue * value,gpointer v_object)1335 vala_value_take_report (GValue* value,
1336                         gpointer v_object)
1337 {
1338 	ValaReport * old;
1339 	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, VALA_TYPE_REPORT));
1340 	old = value->data[0].v_pointer;
1341 	if (v_object) {
1342 		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, VALA_TYPE_REPORT));
1343 		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
1344 		value->data[0].v_pointer = v_object;
1345 	} else {
1346 		value->data[0].v_pointer = NULL;
1347 	}
1348 	if (old) {
1349 		vala_report_unref (old);
1350 	}
1351 }
1352 
1353 static void
vala_report_class_init(ValaReportClass * klass,gpointer klass_data)1354 vala_report_class_init (ValaReportClass * klass,
1355                         gpointer klass_data)
1356 {
1357 	vala_report_parent_class = g_type_class_peek_parent (klass);
1358 	((ValaReportClass *) klass)->finalize = vala_report_finalize;
1359 	g_type_class_adjust_private_offset (klass, &ValaReport_private_offset);
1360 	((ValaReportClass *) klass)->note = (void (*) (ValaReport*, ValaSourceReference*, const gchar*)) vala_report_real_note;
1361 	((ValaReportClass *) klass)->depr = (void (*) (ValaReport*, ValaSourceReference*, const gchar*)) vala_report_real_depr;
1362 	((ValaReportClass *) klass)->warn = (void (*) (ValaReport*, ValaSourceReference*, const gchar*)) vala_report_real_warn;
1363 	((ValaReportClass *) klass)->err = (void (*) (ValaReport*, ValaSourceReference*, const gchar*)) vala_report_real_err;
1364 }
1365 
1366 static void
vala_report_instance_init(ValaReport * self,gpointer klass)1367 vala_report_instance_init (ValaReport * self,
1368                            gpointer klass)
1369 {
1370 	gchar* _tmp0_;
1371 	gchar* _tmp1_;
1372 	gchar* _tmp2_;
1373 	gchar* _tmp3_;
1374 	gchar* _tmp4_;
1375 	gchar* _tmp5_;
1376 	self->priv = vala_report_get_instance_private (self);
1377 	_tmp0_ = g_strdup ("");
1378 	self->priv->locus_color_start = _tmp0_;
1379 	self->priv->locus_color_end = "";
1380 	_tmp1_ = g_strdup ("");
1381 	self->priv->warning_color_start = _tmp1_;
1382 	self->priv->warning_color_end = "";
1383 	_tmp2_ = g_strdup ("");
1384 	self->priv->error_color_start = _tmp2_;
1385 	self->priv->error_color_end = "";
1386 	_tmp3_ = g_strdup ("");
1387 	self->priv->note_color_start = _tmp3_;
1388 	self->priv->note_color_end = "";
1389 	_tmp4_ = g_strdup ("");
1390 	self->priv->caret_color_start = _tmp4_;
1391 	self->priv->caret_color_end = "";
1392 	_tmp5_ = g_strdup ("");
1393 	self->priv->quote_color_start = _tmp5_;
1394 	self->priv->quote_color_end = "";
1395 	self->priv->_enable_warnings = TRUE;
1396 	self->ref_count = 1;
1397 }
1398 
1399 static void
vala_report_finalize(ValaReport * obj)1400 vala_report_finalize (ValaReport * obj)
1401 {
1402 	ValaReport * self;
1403 	self = G_TYPE_CHECK_INSTANCE_CAST (obj, VALA_TYPE_REPORT, ValaReport);
1404 	g_signal_handlers_destroy (self);
1405 	_g_free0 (self->priv->locus_color_start);
1406 	_g_free0 (self->priv->warning_color_start);
1407 	_g_free0 (self->priv->error_color_start);
1408 	_g_free0 (self->priv->note_color_start);
1409 	_g_free0 (self->priv->caret_color_start);
1410 	_g_free0 (self->priv->quote_color_start);
1411 }
1412 
1413 /**
1414  * Namespace to centralize reporting warnings and errors.
1415  */
1416 static GType
vala_report_get_type_once(void)1417 vala_report_get_type_once (void)
1418 {
1419 	static const GTypeValueTable g_define_type_value_table = { vala_value_report_init, vala_value_report_free_value, vala_value_report_copy_value, vala_value_report_peek_pointer, "p", vala_value_report_collect_value, "p", vala_value_report_lcopy_value };
1420 	static const GTypeInfo g_define_type_info = { sizeof (ValaReportClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) vala_report_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ValaReport), 0, (GInstanceInitFunc) vala_report_instance_init, &g_define_type_value_table };
1421 	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
1422 	GType vala_report_type_id;
1423 	vala_report_type_id = g_type_register_fundamental (g_type_fundamental_next (), "ValaReport", &g_define_type_info, &g_define_type_fundamental_info, 0);
1424 	ValaReport_private_offset = g_type_add_instance_private (vala_report_type_id, sizeof (ValaReportPrivate));
1425 	return vala_report_type_id;
1426 }
1427 
1428 GType
vala_report_get_type(void)1429 vala_report_get_type (void)
1430 {
1431 	static volatile gsize vala_report_type_id__volatile = 0;
1432 	if (g_once_init_enter (&vala_report_type_id__volatile)) {
1433 		GType vala_report_type_id;
1434 		vala_report_type_id = vala_report_get_type_once ();
1435 		g_once_init_leave (&vala_report_type_id__volatile, vala_report_type_id);
1436 	}
1437 	return vala_report_type_id__volatile;
1438 }
1439 
1440 gpointer
vala_report_ref(gpointer instance)1441 vala_report_ref (gpointer instance)
1442 {
1443 	ValaReport * self;
1444 	self = instance;
1445 	g_atomic_int_inc (&self->ref_count);
1446 	return instance;
1447 }
1448 
1449 void
vala_report_unref(gpointer instance)1450 vala_report_unref (gpointer instance)
1451 {
1452 	ValaReport * self;
1453 	self = instance;
1454 	if (g_atomic_int_dec_and_test (&self->ref_count)) {
1455 		VALA_REPORT_GET_CLASS (self)->finalize (self);
1456 		g_type_free_instance ((GTypeInstance *) self);
1457 	}
1458 }
1459 
1460 static void
_vala_array_destroy(gpointer array,gint array_length,GDestroyNotify destroy_func)1461 _vala_array_destroy (gpointer array,
1462                      gint array_length,
1463                      GDestroyNotify destroy_func)
1464 {
1465 	if ((array != NULL) && (destroy_func != NULL)) {
1466 		gint i;
1467 		for (i = 0; i < array_length; i = i + 1) {
1468 			if (((gpointer*) array)[i] != NULL) {
1469 				destroy_func (((gpointer*) array)[i]);
1470 			}
1471 		}
1472 	}
1473 }
1474 
1475 static void
_vala_array_free(gpointer array,gint array_length,GDestroyNotify destroy_func)1476 _vala_array_free (gpointer array,
1477                   gint array_length,
1478                   GDestroyNotify destroy_func)
1479 {
1480 	_vala_array_destroy (array, array_length, destroy_func);
1481 	g_free (array);
1482 }
1483 
1484 static gint
_vala_array_length(gpointer array)1485 _vala_array_length (gpointer array)
1486 {
1487 	gint length;
1488 	length = 0;
1489 	if (array) {
1490 		while (((gpointer*) array)[length]) {
1491 			length++;
1492 		}
1493 	}
1494 	return length;
1495 }
1496 
1497