summaryrefslogtreecommitdiff
path: root/vala/valasourcereference.vala
blob: 8bc2f2d60757776f24bf7b35703eb5868f2f5a93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* valasourcereference.vala
 *
 * Copyright (C) 2006  Jürg Billeter
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Jürg Billeter <j@bitron.ch>
 */

/**
 * Represents a reference to a location in a source file.
 */
public class Vala.SourceReference {
	/**
	 * The source file to be referenced.
	 */
	public weak SourceFile file { get; set; }

	/**
	 * The first line number of the referenced source code.
	 */
	public int first_line { get; set; }

	/**
	 * The first column number of the referenced source code.
	 */
	public int first_column { get; set; }

	/**
	 * The last line number of the referenced source code.
	 */
	public int last_line { get; set; }

	/**
	 * The last column number of the referenced source code.
	 */
	public int last_column { get; set; }

	/**
	 * The text describing the referenced source code.
	 */
	public string comment { get; set; }
	
	/**
	 * Creates a new source reference.
	 *
	 * @param file         a source file
	 * @param first_line   first line number
	 * @param first_column first column number
	 * @param last_line    last line number
	 * @param last_column  last column number
	 * @return             newly created source reference
	 */
	public SourceReference (SourceFile _file, int _first_line = 0, int _first_column = 0, int _last_line = 0, int _last_column = 0) {
		file = _file;
		first_line = _first_line;
		first_column = _first_column;
		last_line = _last_line;
		last_column = _last_column;
	}
	
	/**
	 * Creates a new commented source reference.
	 *
	 * @param file         a source file
	 * @param first_line   first line number
	 * @param first_column first column number
	 * @param last_line    last line number
	 * @param last_column  last column number
	 * @param comment      code comment
	 * @return             newly created source reference
	 */
	public SourceReference.with_comment (SourceFile _file, int _first_line, int _first_column, int _last_line, int _last_column, string _comment) {
		file = _file;
		first_line = _first_line;
		first_column = _first_column;
		last_line = _last_line;
		last_column = _last_column;
		comment = _comment;
	}
	
	/**
	 * Returns a string representation of this source reference.
	 *
	 * @return human-readable string
	 */
	public ref string! to_string () {
		return ("%s:%d.%d-%d.%d".printf (file.filename, first_line, first_column, last_line, last_column));
	}
}