[vala] Use SourceLocation in SourceReference



commit 46ad2f001df736b78c2d1d6d38b688215a59bb80
Author: JÃrg Billeter <j bitron ch>
Date:   Sat Jun 2 17:40:24 2012 +0200

    Use SourceLocation in SourceReference

 codegen/valaccodebasemodule.vala         |    2 +-
 codegen/valaccodememberaccessmodule.vala |    2 +-
 vala/valagenieparser.vala                |    7 +--
 vala/valageniescanner.vala               |   65 +++++++++++++++-------------
 vala/valagirparser.vala                  |    6 +-
 vala/valaparser.vala                     |   12 ++---
 vala/valareport.vala                     |    8 ++--
 vala/valascanner.vala                    |   68 ++++++++++++++++--------------
 vala/valasemanticanalyzer.vala           |    2 +-
 vala/valasourcereference.vala            |   30 ++++---------
 vapigen/valagidlparser.vala              |    2 +-
 vapigen/valavapicheck.vala               |    2 +-
 12 files changed, 99 insertions(+), 107 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index f9f9635..57ac8a5 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -560,7 +560,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 	public void push_line (SourceReference? source_reference) {
 		line_directive_stack.add (current_line);
 		if (source_reference != null) {
-			current_line = new CCodeLineDirective (source_reference.file.filename, source_reference.first_line);
+			current_line = new CCodeLineDirective (source_reference.file.filename, source_reference.begin.line);
 			if (ccode != null) {
 				ccode.current_line = current_line;
 			}
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 09b8ad7..843d208 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -134,7 +134,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
 				string s = Path.get_basename (expr.source_reference.file.filename);
 				set_cvalue (expr, new CCodeConstant ("\"%s\"".printf (s)));
 			} else if (fn == "GLib.Log.LINE") {
-				int i = expr.source_reference.first_line;
+				int i = expr.source_reference.begin.line;
 				set_cvalue (expr, new CCodeConstant ("%d".printf (i)));
 			} else if (fn == "GLib.Log.METHOD") {
 				string s = "";
diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala
index 4f9c016..861fe0d 100644
--- a/vala/valagenieparser.vala
+++ b/vala/valagenieparser.vala
@@ -193,11 +193,11 @@ public class Vala.Genie.Parser : CodeVisitor {
 	SourceReference get_src (SourceLocation begin) {
 		int last_index = (index + BUFFER_SIZE - 1) % BUFFER_SIZE;
 
-		return new SourceReference (scanner.source_file, begin.line, begin.column, tokens[last_index].end.line, tokens[last_index].end.column);
+		return new SourceReference (scanner.source_file, begin, tokens[last_index].end);
 	}
 
 	SourceReference get_current_src () {
-		return new SourceReference (scanner.source_file, tokens[index].begin.line, tokens[index].begin.column, tokens[index].end.line, tokens[index].end.column);
+		return new SourceReference (scanner.source_file, tokens[index].begin, tokens[index].end);
 	}
 
 	void rollback (SourceLocation location) {
@@ -1839,8 +1839,7 @@ public class Vala.Genie.Parser : CodeVisitor {
 			}
 		}
 
-		block.source_reference.last_line = get_current_src ().last_line;
-		block.source_reference.last_column = get_current_src ().last_column;
+		block.source_reference.end = get_current_src ().end;
 		
 		return block;
 	}
diff --git a/vala/valageniescanner.vala b/vala/valageniescanner.vala
index 54a557a..5f73ba4 100644
--- a/vala/valageniescanner.vala
+++ b/vala/valageniescanner.vala
@@ -1,6 +1,6 @@
 /* valageniescanner.vala
  *
- * Copyright (C) 2008  Jamie McCracken, JÃrg Billeter
+ * Copyright (C) 2008-2012  Jamie McCracken, JÃrg Billeter
  * Based on code by JÃrg Billeter
  *
  * This library is free software; you can redistribute it and/or
@@ -109,6 +109,9 @@ public class Vala.Genie.Scanner {
 		return (state_stack.length > 0 && state_stack[state_stack.length - 1] == State.REGEX_LITERAL);
 	}
 
+	SourceReference get_source_reference (int offset, int length = 0) {
+		return new SourceReference (source_file, SourceLocation (current, line, column + offset), SourceLocation (current + length, line, column + offset + length));
+	}
 
 	public TokenType read_regex_token (out SourceLocation token_begin, out SourceLocation token_end) {
 		TokenType type;
@@ -133,25 +136,25 @@ public class Vala.Genie.Scanner {
 					switch (current[0]) {
 					case 'i':
 						if (fl_i) {
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "modifier 'i' used more than once");
+							Report.error (get_source_reference (token_length_in_chars), "modifier 'i' used more than once");
 						}
 						fl_i = true;
 						break;
 					case 's':
 						if (fl_s) {
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "modifier 's' used more than once");
+							Report.error (get_source_reference (token_length_in_chars), "modifier 's' used more than once");
 						}
 						fl_s = true;
 						break;
 					case 'm':
 						if (fl_m) {
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "modifier 'm' used more than once");
+							Report.error (get_source_reference (token_length_in_chars), "modifier 'm' used more than once");
 						}
 						fl_m = true;
 						break;
 					case 'x':
 						if (fl_x) {
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "modifier 'x' used more than once");
+							Report.error (get_source_reference (token_length_in_chars), "modifier 'x' used more than once");
 						}
 						fl_x = true;
 						break;
@@ -234,7 +237,7 @@ public class Vala.Genie.Scanner {
 							}
 							break;
 						default:
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "invalid escape sequence");
+							Report.error (get_source_reference (token_length_in_chars), "invalid escape sequence");
 							break;
 						}
 					} else if (current[0] == '\n') {
@@ -246,12 +249,12 @@ public class Vala.Genie.Scanner {
 							token_length_in_chars++;
 						} else {
 							current++;
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "invalid UTF-8 character");
+							Report.error (get_source_reference (token_length_in_chars), "invalid UTF-8 character");
 						}
 					}
 				}
 				if (current >= end || current[0] == '\n') {
-					Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "syntax error, expected \"");
+					Report.error (get_source_reference (token_length_in_chars), "syntax error, expected \"");
 					state_stack.length--;
 					return read_token (out token_begin, out token_end);
 				}
@@ -691,7 +694,7 @@ public class Vala.Genie.Scanner {
 					current++;
 					state_stack += State.TEMPLATE_PART;
 				} else {
-					Report.error (new SourceReference (source_file, line, column + 1, line, column + 1), "unexpected character");
+					Report.error (get_source_reference (1), "unexpected character");
 					return read_template_token (out token_begin, out token_end);
 				}
 				break;
@@ -729,7 +732,7 @@ public class Vala.Genie.Scanner {
 							}
 							break;
 						default:
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "invalid escape sequence");
+							Report.error (get_source_reference (token_length_in_chars), "invalid escape sequence");
 							break;
 						}
 					} else if (current[0] == '\n') {
@@ -741,12 +744,12 @@ public class Vala.Genie.Scanner {
 							token_length_in_chars++;
 						} else {
 							current++;
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "invalid UTF-8 character");
+							Report.error (get_source_reference (token_length_in_chars), "invalid UTF-8 character");
 						}
 					}
 				}
 				if (current >= end || current[0] == '\n') {
-					Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "syntax error, expected \"");
+					Report.error (get_source_reference (token_length_in_chars), "syntax error, expected \"");
 					state_stack.length--;
 					return read_token (out token_begin, out token_end);
 				}
@@ -1232,14 +1235,14 @@ public class Vala.Genie.Scanner {
 								current += u.to_utf8 (null);
 								token_length_in_chars++;
 							} else {
-								Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "invalid UTF-8 character");
+								Report.error (get_source_reference (token_length_in_chars), "invalid UTF-8 character");
 							}
 						}
 					}
 					if (current[0] == '"' && current[1] == '"' && current[2] == '"') {
 						current += 3;
 					} else {
-						Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "syntax error, expected \"\"\"");
+						Report.error (get_source_reference (token_length_in_chars), "syntax error, expected \"\"\"");
 					}
 					break;
 				} else {
@@ -1278,7 +1281,7 @@ public class Vala.Genie.Scanner {
 							}
 							break;
 						default:
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "invalid escape sequence");
+							Report.error (get_source_reference (token_length_in_chars), "invalid escape sequence");
 							break;
 						}
 					} else if (current[0] == '\n') {
@@ -1290,24 +1293,24 @@ public class Vala.Genie.Scanner {
 							token_length_in_chars++;
 						} else {
 							current++;
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "invalid UTF-8 character");
+							Report.error (get_source_reference (token_length_in_chars), "invalid UTF-8 character");
 						}
 					}
 				}
 				if (current < end && current[0] != '\n') {
 					current++;
 				} else {
-					Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "syntax error, expected %c".printf (begin[0]));
+					Report.error (get_source_reference (token_length_in_chars), "syntax error, expected %c".printf (begin[0]));
 				}
 				break;
 			default:
 				unichar u = ((string) current).get_char_validated ((long) (end - current));
 				if (u != (unichar) (-1)) {
 					current += u.to_utf8 (null);
-					Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, unexpected character");
+					Report.error (get_source_reference (0), "syntax error, unexpected character");
 				} else {
 					current++;
-					Report.error (new SourceReference (source_file, line, column, line, column), "invalid UTF-8 character");
+					Report.error (get_source_reference (0), "invalid UTF-8 character");
 				}
 				column++;
 				last_token = TokenType.STRING_LITERAL;
@@ -1425,7 +1428,7 @@ public class Vala.Genie.Scanner {
 			
 			SourceReference source_reference = null;
 			if (file_comment) {
-				source_reference = new SourceReference (source_file, line, column, line, column);
+				source_reference = get_source_reference (0);
 			}
 			
 			current += 2;
@@ -1455,7 +1458,7 @@ public class Vala.Genie.Scanner {
 			}
 
             if (current[2] == '*' || file_comment) {
-				source_reference = new SourceReference (source_file, line, column, line, column);
+				source_reference = get_source_reference (0);
 			}
 
 			current += 2;
@@ -1471,7 +1474,7 @@ public class Vala.Genie.Scanner {
 				column++;
 			}
 			if (current == end - 1) {
-				Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, expected */");
+				Report.error (get_source_reference (0), "syntax error, expected */");
 				return true;
 			}
 
@@ -1575,7 +1578,7 @@ public class Vala.Genie.Scanner {
 		} else if (len == 5 && matches (begin, "endif")) {
 			parse_pp_endif ();
 		} else {
-			Report.error (new SourceReference (source_file, line, column - len, line, column), "syntax error, invalid preprocessing directive");
+			Report.error (get_source_reference (-len, len), "syntax error, invalid preprocessing directive");
 		}
 
 		if (conditional_stack.length > 0
@@ -1605,7 +1608,7 @@ public class Vala.Genie.Scanner {
 	void pp_eol () {
 		pp_whitespace ();
 		if (current >= end || current[0] != '\n') {
-			Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, expected newline");
+			Report.error (get_source_reference (0), "syntax error, expected newline");
 		}
 	}
 
@@ -1635,7 +1638,7 @@ public class Vala.Genie.Scanner {
 		pp_eol ();
 
 		if (conditional_stack.length == 0 || conditional_stack[conditional_stack.length - 1].else_found) {
-			Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, unexpected #elif");
+			Report.error (get_source_reference (0), "syntax error, unexpected #elif");
 			return;
 		}
 
@@ -1654,7 +1657,7 @@ public class Vala.Genie.Scanner {
 		pp_eol ();
 
 		if (conditional_stack.length == 0 || conditional_stack[conditional_stack.length - 1].else_found) {
-			Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, unexpected #else");
+			Report.error (get_source_reference (0), "syntax error, unexpected #else");
 			return;
 		}
 
@@ -1673,7 +1676,7 @@ public class Vala.Genie.Scanner {
 		pp_eol ();
 
 		if (conditional_stack.length == 0) {
-			Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, unexpected #endif");
+			Report.error (get_source_reference (0), "syntax error, unexpected #endif");
 			return;
 		}
 
@@ -1689,7 +1692,7 @@ public class Vala.Genie.Scanner {
 		}
 
 		if (len == 0) {
-			Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, expected identifier");
+			Report.error (get_source_reference (0), "syntax error, expected identifier");
 			return false;
 		}
 
@@ -1708,7 +1711,7 @@ public class Vala.Genie.Scanner {
 
 	bool parse_pp_primary_expression () {
 		if (current >= end) {
-			Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, expected identifier");
+			Report.error (get_source_reference (0), "syntax error, expected identifier");
 		} else if (is_ident_char (current[0])) {
 			return parse_pp_symbol ();
 		} else if (current[0] == '(') {
@@ -1721,11 +1724,11 @@ public class Vala.Genie.Scanner {
 				current++;
 				column++;
 			} else {
-				Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, expected `)'");
+				Report.error (get_source_reference (0), "syntax error, expected `)'");
 			}
 			return result;
 		} else {
-			Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, expected identifier");
+			Report.error (get_source_reference (0), "syntax error, expected identifier");
 		}
 		return false;
 	}
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 530470c..902870d 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -244,7 +244,7 @@ public class Vala.GirParser : CodeVisitor {
 		}
 
 		SourceReference get_current_src () {
-			return new SourceReference (scanner.source_file, begin.line, begin.column, end.line, end.column);
+			return new SourceReference (scanner.source_file, begin, end);
 		}
 
 		SourceReference get_src (SourceLocation begin, SourceLocation? end = null) {
@@ -252,7 +252,7 @@ public class Vala.GirParser : CodeVisitor {
 			if (end != null) {
 				e = end;
 			}
-			return new SourceReference (scanner.source_file, begin.line, begin.column, e.line, e.column);
+			return new SourceReference (scanner.source_file, begin, e);
 		}
 
 		public Metadata parse_metadata (SourceFile metadata_file) {
@@ -1191,7 +1191,7 @@ public class Vala.GirParser : CodeVisitor {
 	}
 
 	SourceReference get_current_src () {
-		return new SourceReference (this.current_source_file, begin.line, begin.column, end.line, end.column);
+		return new SourceReference (this.current_source_file, begin, end);
 	}
 
 	const string GIR_VERSION = "1.2";
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 76ea0b9..099ed07 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -147,17 +147,17 @@ public class Vala.Parser : CodeVisitor {
 	SourceReference get_src (SourceLocation begin) {
 		int last_index = (index + BUFFER_SIZE - 1) % BUFFER_SIZE;
 
-		return new SourceReference (scanner.source_file, begin.line, begin.column, tokens[last_index].end.line, tokens[last_index].end.column);
+		return new SourceReference (scanner.source_file, begin, tokens[last_index].end);
 	}
 
 	SourceReference get_current_src () {
-		return new SourceReference (scanner.source_file, tokens[index].begin.line, tokens[index].begin.column, tokens[index].end.line, tokens[index].end.column);
+		return new SourceReference (scanner.source_file, tokens[index].begin, tokens[index].end);
 	}
 
 	SourceReference get_last_src () {
 		int last_index = (index + BUFFER_SIZE - 1) % BUFFER_SIZE;
 
-		return new SourceReference (scanner.source_file, tokens[last_index].begin.line, tokens[last_index].begin.column, tokens[last_index].end.line, tokens[last_index].end.column);
+		return new SourceReference (scanner.source_file, tokens[last_index].begin, tokens[last_index].end);
 	}
 
 	void rollback (SourceLocation location) {
@@ -1744,8 +1744,7 @@ public class Vala.Parser : CodeVisitor {
 			}
 		}
 
-		block.source_reference.last_line = get_current_src ().last_line;
-		block.source_reference.last_column = get_current_src ().last_column;
+		block.source_reference.end = get_current_src ().end;
 
 		return block;
 	}
@@ -2179,8 +2178,7 @@ public class Vala.Parser : CodeVisitor {
 			Report.error (get_current_src (), "expected end of file");
 		}
 
-		method.body.source_reference.last_line = get_current_src ().last_line;
-		method.body.source_reference.last_column = get_current_src ().last_column;
+		method.body.source_reference.end = get_current_src ().end;
 
 		if (!context.experimental && context.profile != Profile.DOVA) {
 			Report.warning (method.source_reference, "main blocks are experimental");
diff --git a/vala/valareport.vala b/vala/valareport.vala
index 66a1e96..18169c5 100644
--- a/vala/valareport.vala
+++ b/vala/valareport.vala
@@ -58,12 +58,12 @@ public class Vala.Report : Object {
 	 * Pretty-print the actual line of offending code if possible.
 	 */
 	static void report_source (SourceReference source) {
-		if (source.first_line != source.last_line) {
+		if (source.begin.line != source.end.line) {
 			// FIXME Cannot report multi-line issues currently
 			return;
 		}
 
-		string offending_line = source.file.get_source_line (source.first_line);
+		string offending_line = source.file.get_source_line (source.begin.line);
 
 		if (offending_line != null) {
 			stderr.printf ("%s\n", offending_line);
@@ -72,7 +72,7 @@ public class Vala.Report : Object {
 			/* We loop in this manner so that we don't fall over on differing
 			 * tab widths. This means we get the ^s in the right places.
 			 */
-			for (idx = 1; idx < source.first_column; ++idx) {
+			for (idx = 1; idx < source.begin.column; ++idx) {
 				if (offending_line[idx - 1] == '\t') {
 					stderr.printf ("\t");
 				} else {
@@ -80,7 +80,7 @@ public class Vala.Report : Object {
 				}
 			}
 
-			for (idx = source.first_column; idx <= source.last_column; ++idx) {
+			for (idx = source.begin.column; idx <= source.end.column; ++idx) {
 				if (offending_line[idx - 1] == '\t') {
 					stderr.printf ("\t");
 				} else {
diff --git a/vala/valascanner.vala b/vala/valascanner.vala
index 624c77d..39ee41a 100644
--- a/vala/valascanner.vala
+++ b/vala/valascanner.vala
@@ -1,6 +1,6 @@
 /* valascanner.vala
  *
- * Copyright (C) 2008-2010  JÃrg Billeter
+ * Copyright (C) 2008-2012  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
@@ -94,6 +94,10 @@ public class Vala.Scanner {
 		return (c.isalnum () || c == '_');
 	}
 
+	SourceReference get_source_reference (int offset, int length = 0) {
+		return new SourceReference (source_file, SourceLocation (current, line, column + offset), SourceLocation (current + length, line, column + offset + length));
+	}
+
 	public TokenType read_regex_token (out SourceLocation token_begin, out SourceLocation token_end) {
 		TokenType type;
 		char* begin = current;
@@ -117,25 +121,25 @@ public class Vala.Scanner {
 					switch (current[0]) {
 					case 'i':
 						if (fl_i) {
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "modifier 'i' used more than once");
+							Report.error (get_source_reference (token_length_in_chars), "modifier 'i' used more than once");
 						}
 						fl_i = true;
 						break;
 					case 's':
 						if (fl_s) {
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "modifier 's' used more than once");
+							Report.error (get_source_reference (token_length_in_chars), "modifier 's' used more than once");
 						}
 						fl_s = true;
 						break;
 					case 'm':
 						if (fl_m) {
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "modifier 'm' used more than once");
+							Report.error (get_source_reference (token_length_in_chars), "modifier 'm' used more than once");
 						}
 						fl_m = true;
 						break;
 					case 'x':
 						if (fl_x) {
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "modifier 'x' used more than once");
+							Report.error (get_source_reference (token_length_in_chars), "modifier 'x' used more than once");
 						}
 						fl_x = true;
 						break;
@@ -218,7 +222,7 @@ public class Vala.Scanner {
 							}
 							break;
 						default:
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "invalid escape sequence");
+							Report.error (get_source_reference (token_length_in_chars), "invalid escape sequence");
 							break;
 						}
 					} else if (current[0] == '\n') {
@@ -230,12 +234,12 @@ public class Vala.Scanner {
 							token_length_in_chars++;
 						} else {
 							current++;
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "invalid UTF-8 character");
+							Report.error (get_source_reference (token_length_in_chars), "invalid UTF-8 character");
 						}
 					}
 				}
 				if (current >= end || current[0] == '\n') {
-					Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "syntax error, expected \"");
+					Report.error (get_source_reference (token_length_in_chars), "syntax error, expected \"");
 					state_stack.length--;
 					return read_token (out token_begin, out token_end);
 				}
@@ -661,7 +665,7 @@ public class Vala.Scanner {
 					current++;
 					state_stack += State.TEMPLATE_PART;
 				} else {
-					Report.error (new SourceReference (source_file, line, column + 1, line, column + 1), "unexpected character");
+					Report.error (get_source_reference (1), "unexpected character");
 					return read_template_token (out token_begin, out token_end);
 				}
 				break;
@@ -699,7 +703,7 @@ public class Vala.Scanner {
 							}
 							break;
 						default:
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "invalid escape sequence");
+							Report.error (get_source_reference (token_length_in_chars), "invalid escape sequence");
 							break;
 						}
 					} else if (current[0] == '\n') {
@@ -714,12 +718,12 @@ public class Vala.Scanner {
 							token_length_in_chars++;
 						} else {
 							current++;
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "invalid UTF-8 character");
+							Report.error (get_source_reference (token_length_in_chars), "invalid UTF-8 character");
 						}
 					}
 				}
 				if (current >= end) {
-					Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "syntax error, expected \"");
+					Report.error (get_source_reference (token_length_in_chars), "syntax error, expected \"");
 					state_stack.length--;
 					return read_token (out token_begin, out token_end);
 				}
@@ -1069,14 +1073,14 @@ public class Vala.Scanner {
 								current += u.to_utf8 (null);
 								token_length_in_chars++;
 							} else {
-								Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "invalid UTF-8 character");
+								Report.error (get_source_reference (token_length_in_chars), "invalid UTF-8 character");
 							}
 						}
 					}
 					if (current[0] == '"' && current[1] == '"' && current[2] == '"') {
 						current += 3;
 					} else {
-						Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "syntax error, expected \"\"\"");
+						Report.error (get_source_reference (token_length_in_chars), "syntax error, expected \"\"\"");
 					}
 					break;
 				} else {
@@ -1116,7 +1120,7 @@ public class Vala.Scanner {
 							}
 							break;
 						default:
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "invalid escape sequence");
+							Report.error (get_source_reference (token_length_in_chars), "invalid escape sequence");
 							break;
 						}
 					} else if (current[0] == '\n') {
@@ -1138,28 +1142,28 @@ public class Vala.Scanner {
 							token_length_in_chars++;
 						} else {
 							current++;
-							Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "invalid UTF-8 character");
+							Report.error (get_source_reference (token_length_in_chars), "invalid UTF-8 character");
 						}
 					}
 					if (current < end && begin[0] == '\'' && current[0] != '\'') {
 						// multiple characters in single character literal
-						Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "invalid character literal");
+						Report.error (get_source_reference (token_length_in_chars), "invalid character literal");
 					}
 				}
 				if (current < end) {
 					current++;
 				} else {
-					Report.error (new SourceReference (source_file, line, column + token_length_in_chars, line, column + token_length_in_chars), "syntax error, expected %c".printf (begin[0]));
+					Report.error (get_source_reference (token_length_in_chars), "syntax error, expected %c".printf (begin[0]));
 				}
 				break;
 			default:
 				unichar u = ((string) current).get_char_validated ((long) (end - current));
 				if (u != (unichar) (-1)) {
 					current += u.to_utf8 (null);
-					Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, unexpected character");
+					Report.error (get_source_reference (0), "syntax error, unexpected character");
 				} else {
 					current++;
-					Report.error (new SourceReference (source_file, line, column, line, column), "invalid UTF-8 character");
+					Report.error (get_source_reference (0), "invalid UTF-8 character");
 				}
 				column++;
 				return read_token (out token_begin, out token_end);
@@ -1232,7 +1236,7 @@ public class Vala.Scanner {
 		} else if (len == 5 && matches (begin, "endif")) {
 			parse_pp_endif ();
 		} else {
-			Report.error (new SourceReference (source_file, line, column - len, line, column), "syntax error, invalid preprocessing directive");
+			Report.error (get_source_reference (-len, len), "syntax error, invalid preprocessing directive");
 		}
 
 		if (conditional_stack.length > 0
@@ -1262,7 +1266,7 @@ public class Vala.Scanner {
 	void pp_eol () {
 		pp_whitespace ();
 		if (current >= end || current[0] != '\n') {
-			Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, expected newline");
+			Report.error (get_source_reference (0), "syntax error, expected newline");
 		}
 	}
 
@@ -1292,7 +1296,7 @@ public class Vala.Scanner {
 		pp_eol ();
 
 		if (conditional_stack.length == 0 || conditional_stack[conditional_stack.length - 1].else_found) {
-			Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, unexpected #elif");
+			Report.error (get_source_reference (0), "syntax error, unexpected #elif");
 			return;
 		}
 
@@ -1311,7 +1315,7 @@ public class Vala.Scanner {
 		pp_eol ();
 
 		if (conditional_stack.length == 0 || conditional_stack[conditional_stack.length - 1].else_found) {
-			Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, unexpected #else");
+			Report.error (get_source_reference (0), "syntax error, unexpected #else");
 			return;
 		}
 
@@ -1330,7 +1334,7 @@ public class Vala.Scanner {
 		pp_eol ();
 
 		if (conditional_stack.length == 0) {
-			Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, unexpected #endif");
+			Report.error (get_source_reference (0), "syntax error, unexpected #endif");
 			return;
 		}
 
@@ -1346,7 +1350,7 @@ public class Vala.Scanner {
 		}
 
 		if (len == 0) {
-			Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, expected identifier");
+			Report.error (get_source_reference (0), "syntax error, expected identifier");
 			return false;
 		}
 
@@ -1365,7 +1369,7 @@ public class Vala.Scanner {
 
 	bool parse_pp_primary_expression () {
 		if (current >= end) {
-			Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, expected identifier");
+			Report.error (get_source_reference (0), "syntax error, expected identifier");
 		} else if (is_ident_char (current[0])) {
 			return parse_pp_symbol ();
 		} else if (current[0] == '(') {
@@ -1378,11 +1382,11 @@ public class Vala.Scanner {
 				current++;
 				column++;
 			} else {
-				Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, expected `)'");
+				Report.error (get_source_reference (0), "syntax error, expected `)'");
 			}
 			return result;
 		} else {
-			Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, expected identifier");
+			Report.error (get_source_reference (0), "syntax error, expected identifier");
 		}
 		return false;
 	}
@@ -1482,7 +1486,7 @@ public class Vala.Scanner {
 		if (current[1] == '/') {
 			SourceReference source_reference = null;
 			if (file_comment) {
-				source_reference = new SourceReference (source_file, line, column, line, column);
+				source_reference = get_source_reference (0);
 			}
 
 			// single-line comment
@@ -1505,7 +1509,7 @@ public class Vala.Scanner {
 			}
 
 			if (current[2] == '*' || file_comment) {
-				source_reference = new SourceReference (source_file, line, column, line, column);
+				source_reference = get_source_reference (0);
 			}
 
 			current += 2;
@@ -1522,7 +1526,7 @@ public class Vala.Scanner {
 			}
 
 			if (current == end - 1) {
-				Report.error (new SourceReference (source_file, line, column, line, column), "syntax error, expected */");
+				Report.error (get_source_reference (0), "syntax error, expected */");
 				return true;
 			}
 
diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala
index bd4f4fb..5e8c4f5 100644
--- a/vala/valasemanticanalyzer.vala
+++ b/vala/valasemanticanalyzer.vala
@@ -499,7 +499,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
 		if (diag && prev_arg != null) {
 			var format_arg = prev_arg as StringLiteral;
 			if (format_arg != null) {
-				format_arg.value = "\"%s:%d: %s".printf (Path.get_basename (expr.source_reference.file.filename), expr.source_reference.first_line, format_arg.value.substring (1));
+				format_arg.value = "\"%s:%d: %s".printf (Path.get_basename (expr.source_reference.file.filename), expr.source_reference.begin.line, format_arg.value.substring (1));
 			}
 		}
 
diff --git a/vala/valasourcereference.vala b/vala/valasourcereference.vala
index d72d38f..be2f6ad 100644
--- a/vala/valasourcereference.vala
+++ b/vala/valasourcereference.vala
@@ -1,6 +1,6 @@
 /* valasourcereference.vala
  *
- * Copyright (C) 2006-2009  JÃrg Billeter
+ * Copyright (C) 2006-2012  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
@@ -32,24 +32,14 @@ public class Vala.SourceReference {
 	public weak SourceFile file { get; set; }
 
 	/**
-	 * The first line number of the referenced source code.
+	 * The begin of the referenced source code.
 	 */
-	public int first_line { get; set; }
+	public SourceLocation begin { get; set; }
 
 	/**
-	 * The first column number of the referenced source code.
+	 * The end 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; }
+	public SourceLocation end { get; set; }
 
 	public List<UsingDirective> using_directives { get; private set; }
 
@@ -63,12 +53,10 @@ public class Vala.SourceReference {
 	 * @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) {
+	public SourceReference (SourceFile _file, SourceLocation begin, SourceLocation end) {
 		file = _file;
-		first_line = _first_line;
-		first_column = _first_column;
-		last_line = _last_line;
-		last_column = _last_column;
+		this.begin = begin;
+		this.end = end;
 		using_directives = file.current_using_directives;
 	}
 	
@@ -78,6 +66,6 @@ public class Vala.SourceReference {
 	 * @return human-readable string
 	 */
 	public string to_string () {
-		return ("%s:%d.%d-%d.%d".printf (file.get_relative_filename (), first_line, first_column, last_line, last_column));
+		return ("%s:%d.%d-%d.%d".printf (file.get_relative_filename (), begin.line, begin.column, end.line, end.column));
 	}
 }
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index f93784d..5aad014 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -139,7 +139,7 @@ public class Vala.GIdlParser : CodeVisitor {
 		try {
 			var modules = Idl.parse_file (source_file.filename);
 			
-			current_source_reference = new SourceReference (source_file);
+			current_source_reference = new SourceReference (source_file, SourceLocation (null, 0, 0), SourceLocation (null, 0, 0));
 			
 			foreach (weak IdlModule module in modules) {
 				var ns = parse_module (module);
diff --git a/vapigen/valavapicheck.vala b/vapigen/valavapicheck.vala
index daa8776..509645f 100644
--- a/vapigen/valavapicheck.vala
+++ b/vapigen/valavapicheck.vala
@@ -137,7 +137,7 @@ class Vala.VAPICheck : Object {
 				var symbol = tokens[0];
 
 				if (symbol.length > 0 && !_symbols.contains (symbol)) {
-					var src = new SourceReference (metadata, lineno, 1, lineno, (int)symbol.length);
+					var src = new SourceReference (metadata, SourceLocation (null, lineno, 1), SourceLocation (null, lineno, (int)symbol.length));
 					Report.error (src, "Symbol `%s' not found".printf (symbol));
 				}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]