From: Rico Tzschichholz Date: Mon, 25 Dec 2017 11:04:01 +0000 (+0100) Subject: parser: Allow custom invocations of parse_file() X-Git-Tag: 0.39.3~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=71da3b84e23f9d97edaa1735f0e761304519d1f2;p=thirdparty%2Fvala.git parser: Allow custom invocations of parse_file() Use CodeContext of SourceFile if needed https://bugzilla.gnome.org/show_bug.cgi?id=791936 --- diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala index 8c92e9599..dfffa23a7 100644 --- a/vala/valagenieparser.vala +++ b/vala/valagenieparser.vala @@ -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 { diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala index edc580c68..de5d7727c 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -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.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 () { diff --git a/vala/valaparser.vala b/vala/valaparser.vala index de3ee64b9..1b1a06f66 100644 --- a/vala/valaparser.vala +++ b/vala/valaparser.vala @@ -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 () {