]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
parser: Allow custom invocations of parse_file()
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 25 Dec 2017 11:04:01 +0000 (12:04 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 2 Jan 2018 11:42:02 +0000 (12:42 +0100)
Use CodeContext of SourceFile if needed

https://bugzilla.gnome.org/show_bug.cgi?id=791936

vala/valagenieparser.vala
vala/valagirparser.vala
vala/valaparser.vala

index 8c92e95991f725bd1f1dafb3b46ef437bb8f86f0..dfffa23a7a51220bac59e39ba679a36463375748 100644 (file)
@@ -399,6 +399,11 @@ public class Vala.Genie.Parser : CodeVisitor {
        }
 
        public void parse_file (SourceFile source_file) {
+               var has_global_context = (context != null);
+               if (!has_global_context) {
+                       context = source_file.context;
+               }
+
                scanner = new Scanner (source_file);
                scanner.parse_file_comments ();
                scanner.indent_spaces = 0;
@@ -430,6 +435,9 @@ public class Vala.Genie.Parser : CodeVisitor {
                }
                
                scanner = null;
+               if (!has_global_context) {
+                       context = null;
+               }
        }
 
        void skip_symbol_name () throws ParseError {
index edc580c6804045f76180c33f82566942405f8287..de5d7727cba7c66d0e50d45dfc9151f51c487651 100644 (file)
@@ -1375,6 +1375,11 @@ public class Vala.GirParser : CodeVisitor {
        }
 
        public void parse_file (SourceFile source_file) {
+               var has_global_context = (context != null);
+               if (!has_global_context) {
+                       context = source_file.context;
+               }
+
                metadata_stack = new ArrayList<Metadata> ();
                metadata = Metadata.empty;
                cheader_filenames = null;
@@ -1391,6 +1396,9 @@ public class Vala.GirParser : CodeVisitor {
 
                reader = null;
                this.current_source_file = null;
+               if (!has_global_context) {
+                       context = null;
+               }
        }
 
        void next () {
index de3ee64b93b5c33780ed896a24308ff3b1d212af..1b1a06f66ffb84ec8a1eeae411b620c4a8098219 100644 (file)
@@ -80,7 +80,7 @@ public class Vala.Parser : CodeVisitor {
        }
 
        public override void visit_source_file (SourceFile source_file) {
-               if (context.run_output || source_file.filename.has_suffix (".vala") || source_file.filename.has_suffix (".vapi")) {
+               if ((context != null && context.run_output) || source_file.filename.has_suffix (".vala") || source_file.filename.has_suffix (".vapi")) {
                        parse_file (source_file);
                }
        }
@@ -322,6 +322,11 @@ public class Vala.Parser : CodeVisitor {
        }
 
        public void parse_file (SourceFile source_file) {
+               var has_global_context = (context != null);
+               if (!has_global_context) {
+                       context = source_file.context;
+               }
+
                scanner = new Scanner (source_file);
                parse_file_comments ();
 
@@ -345,6 +350,9 @@ public class Vala.Parser : CodeVisitor {
                }
                
                scanner = null;
+               if (!has_global_context) {
+                       context = null;
+               }
        }
 
        void parse_file_comments () {