summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Espinosa <esodan@gmail.com>2022-01-01 22:05:17 -0600
committerDaniel Espinosa <esodan@gmail.com>2022-01-03 17:51:33 -0600
commitf6742a9f9964f0e4472e3799a0582b15190b28b7 (patch)
tree85614525335156b482d5b51a98d13ea8716d9a41
parentd3910cd7221fef7f9313a964764c9e94d7a9b6ec (diff)
downloadvala-f6742a9f9964f0e4472e3799a0582b15190b28b7.tar.gz
CodeNode: add CodeContext property
-rw-r--r--vala/valacodenode.vala26
1 files changed, 26 insertions, 0 deletions
diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala
index 4ca44c8d9..52757d9b6 100644
--- a/vala/valacodenode.vala
+++ b/vala/valacodenode.vala
@@ -30,6 +30,10 @@ using GLib;
*/
public abstract class Vala.CodeNode {
/**
+ * Current context.
+ */
+ public weak CodeContext context { get; protected set; }
+ /**
* Parent of this code node.
*/
public weak CodeNode? parent_node { get; protected set; }
@@ -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 ();
}