]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
CodeNode: add CodeContext property
authorDaniel Espinosa <esodan@gmail.com>
Sun, 2 Jan 2022 04:05:17 +0000 (22:05 -0600)
committerDaniel Espinosa <esodan@gmail.com>
Mon, 3 Jan 2022 23:51:33 +0000 (17:51 -0600)
vala/valacodenode.vala

index 4ca44c8d916168bf2bbf50ce1f0fbc8b656ff148..52757d9b6378cbc4fa1cce7cac6a3c879d8d98fc 100644 (file)
@@ -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<DataType> 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 ();
        }