From: Daniel Espinosa Date: Sun, 2 Jan 2022 04:05:17 +0000 (-0600) Subject: CodeNode: add CodeContext property X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6742a9f9964f0e4472e3799a0582b15190b28b7;p=thirdparty%2Fvala.git CodeNode: add CodeContext property --- diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala index 4ca44c8d9..52757d9b6 100644 --- a/vala/valacodenode.vala +++ b/vala/valacodenode.vala @@ -29,6 +29,10 @@ using GLib; * compilation process. */ public abstract class Vala.CodeNode { + /** + * Current context. + */ + public weak CodeContext context { get; protected set; } /** * Parent of this code node. */ @@ -429,6 +433,28 @@ public abstract class Vala.CodeNode { public virtual void get_error_types (Collection collection, SourceReference? source_reference = null) { } + /** + * Traverse tree for the current {@link CodeContext} + */ + public CodeContext traverse_for_context () { + CodeContext ctx = null; + if (this is Namespace) { + ctx = this.context; + } + + CodeNode parent = parent_node; + while (ctx == null) { + parent = parent.parent_node; + if (parent == null) { + break; + } + + ctx = parent.context; + } + + return ctx; + } + public static string get_temp_name () { return "." + (++last_temp_nr).to_string (); }