]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Use SourceLocation in SourceReference
authorJürg Billeter <j@bitron.ch>
Sat, 2 Jun 2012 15:40:24 +0000 (17:40 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 2 Jun 2012 15:40:24 +0000 (17:40 +0200)
12 files changed:
codegen/valaccodebasemodule.vala
codegen/valaccodememberaccessmodule.vala
vala/valagenieparser.vala
vala/valageniescanner.vala
vala/valagirparser.vala
vala/valaparser.vala
vala/valareport.vala
vala/valascanner.vala
vala/valasemanticanalyzer.vala
vala/valasourcereference.vala
vapigen/valagidlparser.vala
vapigen/valavapicheck.vala

index f9f96358e9f33c8841dd6060ab4b7518b66f5b1f..57ac8a5f1f6994766217e4932808cc89c0062e45 100644 (file)
@@ -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;
                        }
index 09b8ad7448949391ee62436e96c65eaca3afeada..843d208cfff034f7a668b17917ef887bed7b585a 100644 (file)
@@ -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 = "";
index 4f9c01640d3c360e4241767ec63a1b6d153c8838..861fe0d09d574ba1aa02dfe4b804c8f0fb09b4d7 100644 (file)
@@ -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;
        }
index 54a557a6e148da14f4ad29f622e6a858a856f06d..5f73ba483f7c6ff395b6ee0f86e53d56e86f94ef 100644 (file)
@@ -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;
        }
index 530470cc58d6bdbcf34f65fbe1068dcbb08d737e..902870d67bf6a413aaf5649e37ffd971f7e4fb9a 100644 (file)
@@ -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";
index 76ea0b92dd3372b9e285b72759d0bb4f5b95ecb7..099ed073a9ff2646df35d0602ec72934334078c0 100644 (file)
@@ -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");
index 66a1e9614aae85275aa079c58f2426d32ecb275b..18169c58f88d6d11e00b67aa52ff99a0e2df189f 100644 (file)
@@ -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 {
index 624c77d106fe48c0e100c9cff78834967de744f6..39ee41a53036757650fb370e1b1f592d5626ec96 100644 (file)
@@ -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;
                        }
 
index bd4f4fb68718789aaf0c38304132b1fbb6f247e4..5e8c4f5612143f528674971561b0d83695f06e6d 100644 (file)
@@ -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));
                        }
                }
 
index d72d38fb25d7369d809df0e39a096d0a7f04ff88..be2f6ad7f2ab7a7e13e9ffd3743fa7d6541ffdc5 100644 (file)
@@ -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));
        }
 }
index f93784df09b7a0543d433e4b05ff3dc8f9fbda99..5aad01468220840a27e2a09bae240ba0ca25b9a2 100644 (file)
@@ -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);
index daa8776b9a5f9207244409b947e58e5e6a47993d..509645f4bf1d80731ff14ebe92c18ac966e445e2 100644 (file)
@@ -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));
                                }