[vala/1270-remove-static-codecontext-access] ArrayType: avoid use static context



commit 7c3481c95d85f556aad262d91d36a382ceb4e4ca
Author: Daniel Espinosa <esodan gmail com>
Date:   Thu Dec 30 13:00:36 2021 -0600

    ArrayType: avoid use static context

 vala/valaarraycreationexpression.vala |  6 +++---
 vala/valaarraytype.vala               | 11 +++++------
 vala/valacodenode.vala                |  4 ++++
 vala/valagenieparser.vala             | 10 +++++-----
 vala/valagirparser.vala               |  8 ++++----
 vala/valaparser.vala                  |  6 +++---
 vapigen/valagidlparser.vala           | 24 ++++++++++++------------
 7 files changed, 36 insertions(+), 33 deletions(-)
---
diff --git a/vala/valaarraycreationexpression.vala b/vala/valaarraycreationexpression.vala
index 70fc4425a..4e62dbee3 100644
--- a/vala/valaarraycreationexpression.vala
+++ b/vala/valaarraycreationexpression.vala
@@ -270,7 +270,7 @@ public class Vala.ArrayCreationExpression : Expression {
 
                var calc_sizes = new ArrayList<Literal> ();
                if (initlist != null) {
-                       initlist.target_type = new ArrayType (element_type, rank, source_reference);
+                       initlist.target_type = new ArrayType (element_type, rank, context, source_reference);
                        ((ArrayType) initlist.target_type).length_type = length_type.copy ();
 
                        if (!initlist.check (context)) {
@@ -284,7 +284,7 @@ public class Vala.ArrayCreationExpression : Expression {
 
                        if (calc_sizes.size != rank) {
                                error = true;
-                               var actual_type = new ArrayType (element_type, calc_sizes.size, 
source_reference);
+                               var actual_type = new ArrayType (element_type, calc_sizes.size, context, 
source_reference);
                                ((ArrayType) actual_type).length_type = length_type;
                                Report.error (initlist.source_reference, "Expected initializer for `%s' but 
got `%s'", target_type.to_string (), actual_type.to_string ());
                        }
@@ -329,7 +329,7 @@ public class Vala.ArrayCreationExpression : Expression {
                        return false;
                }
 
-               value_type = new ArrayType (element_type, rank, source_reference);
+               value_type = new ArrayType (element_type, rank, context, source_reference);
                ((ArrayType) value_type).length_type = length_type.copy ();
                if (formal_target_type is ArrayType) {
                        ((ArrayType) value_type).fixed_length = ((ArrayType) formal_target_type).fixed_length;
diff --git a/vala/valaarraytype.vala b/vala/valaarraytype.vala
index 55847d5db..374529eb2 100644
--- a/vala/valaarraytype.vala
+++ b/vala/valaarraytype.vala
@@ -83,10 +83,11 @@ public class Vala.ArrayType : ReferenceType {
        private ArrayMoveMethod move_method;
        private ArrayCopyMethod copy_method;
 
-       public ArrayType (DataType element_type, int rank, SourceReference? source_reference = null) {
+       public ArrayType (DataType element_type, int rank, CodeContext context, SourceReference? 
source_reference = null) {
                base (null, source_reference);
                this.element_type = element_type;
                this.rank = rank;
+               this.context = context;
        }
 
        public override Symbol? get_member (string member_name) {
@@ -113,7 +114,7 @@ public class Vala.ArrayType : ReferenceType {
 
                        if (rank > 1) {
                                // length is an int[] containing the dimensions of the array, starting at 0
-                               length_field.variable_type = new ArrayType (length_type.copy (), 1, 
source_reference);
+                               length_field.variable_type = new ArrayType (length_type.copy (), 1, context, 
source_reference);
                        } else {
                                length_field.variable_type = length_type.copy ();
                        }
@@ -129,7 +130,7 @@ public class Vala.ArrayType : ReferenceType {
                        resize_method.return_type = new VoidType ();
                        resize_method.access = SymbolAccessibility.PUBLIC;
 
-                       if (CodeContext.get ().profile == Profile.POSIX) {
+                       if (context.profile == Profile.POSIX) {
                                resize_method.set_attribute_string ("CCode", "cname", "realloc");
                        } else {
                                resize_method.set_attribute_string ("CCode", "cname", "g_renew");
@@ -172,7 +173,7 @@ public class Vala.ArrayType : ReferenceType {
        }
 
        public override DataType copy () {
-               var result = new ArrayType (element_type.copy (), rank, source_reference);
+               var result = new ArrayType (element_type.copy (), rank, context, source_reference);
                if (length_type != null) {
                        result.length_type = length_type.copy ();
                }
@@ -206,8 +207,6 @@ public class Vala.ArrayType : ReferenceType {
        }
 
        public override bool compatible (DataType target_type) {
-               var context = CodeContext.get ();
-
                if (context.profile == Profile.GOBJECT && target_type.type_symbol != null) {
                        if (target_type.type_symbol.is_subtype_of (context.analyzer.gvalue_type.type_symbol) 
&& element_type.type_symbol == context.analyzer.string_type.type_symbol) {
                                // allow implicit conversion from string[] to GValue
diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala
index 4ca44c8d9..74ef68b7a 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.
         */
diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala
index d3346c53d..cc6fa1a8d 100644
--- a/vala/valagenieparser.vala
+++ b/vala/valagenieparser.vala
@@ -588,7 +588,7 @@ public class Vala.Genie.Parser : CodeVisitor {
 
                        if (!accept (TokenType.OPEN_BRACKET)) {
                                type.value_owned = true;
-                               type = new ArrayType (type, 1, get_src (begin));
+                               type = new ArrayType (type, 1, context, get_src (begin));
                                type.nullable = accept (TokenType.INTERR);
 
                        } else {
@@ -609,7 +609,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                                        expect (TokenType.CLOSE_BRACKET);
 
                                        type.value_owned = true;
-                                       var array_type = new ArrayType (type, array_rank, get_src (begin));
+                                       var array_type = new ArrayType (type, array_rank, context, get_src 
(begin));
                                        array_type.nullable = accept (TokenType.INTERR);
 
                                        array_type.invalid_syntax = invalid_array;
@@ -640,7 +640,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                        }
                        expect (TokenType.CLOSE_BRACKET);
 
-                       var array_type = new ArrayType (type, 1, get_src (begin));
+                       var array_type = new ArrayType (type, 1, context, get_src (begin));
                        array_type.inline_allocated = true;
                        if (array_length != null) {
                                array_type.fixed_length = true;
@@ -1102,7 +1102,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                                        throw new ParseError.SYNTAX ("size of inner arrays must not be 
specified in array creation expression");
                                }
 
-                               etype = new ArrayType (etype, size_specifier_list.size, 
etype.source_reference);
+                               etype = new ArrayType (etype, size_specifier_list.size, context, 
etype.source_reference);
                        } else {
                                first = false;
                        }
@@ -2899,7 +2899,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                var sym = new UnresolvedSymbol (null, "string", get_src (begin));
                type = new UnresolvedType.from_symbol (sym, get_src (begin));
                type.value_owned = true;
-               type = new ArrayType (type, 1, get_src (begin));
+               type = new ArrayType (type, 1, context, get_src (begin));
                type.nullable = false;
 
                var param = new Parameter ("args", type, get_src (begin));
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index 462c10035..dc754ebb7 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -1882,7 +1882,7 @@ public class Vala.GirParser : CodeVisitor {
 
                if (array_data != null && array_data.length != 0) {
                        type.value_owned = true;
-                       type = new ArrayType (type, (int) array_data.length - 1, source_reference);
+                       type = new ArrayType (type, (int) array_data.length - 1, context, source_reference);
                }
 
                type.nullable = nullable;
@@ -1916,7 +1916,7 @@ public class Vala.GirParser : CodeVisitor {
 
                        if (!(type is ArrayType) && metadata.get_bool (ArgumentType.ARRAY)) {
                                type.value_owned = true;
-                               type = new ArrayType (type, 1, type.source_reference);
+                               type = new ArrayType (type, 1, context, type.source_reference);
                                changed = true;
                        }
 
@@ -2733,7 +2733,7 @@ public class Vala.GirParser : CodeVisitor {
                                element_type.value_owned = transfer_elements;
                                end_element ("array");
 
-                               var array_type = new ArrayType (element_type, 1, src);
+                               var array_type = new ArrayType (element_type, 1, context, src);
                                if (fixed_length > 0) {
                                        array_type.fixed_length = true;
                                        array_type.length = new IntegerLiteral (fixed_length.to_string ());
@@ -2805,7 +2805,7 @@ public class Vala.GirParser : CodeVisitor {
                } else if (type_name == "GObject.Strv") {
                        var element_type = new UnresolvedType.from_symbol (new UnresolvedSymbol (null, 
"string"));
                        element_type.value_owned = true;
-                       type = new ArrayType (element_type, 1, get_current_src ());
+                       type = new ArrayType (element_type, 1, context, get_current_src ());
                        no_array_length = true;
                        array_null_terminated = true;
                } else {
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 286824b43..57aec6f5d 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -597,7 +597,7 @@ public class Vala.Parser : CodeVisitor {
 
                        type.value_owned = inner_type_owned;
 
-                       var array_type = new ArrayType (type, array_rank, get_src (begin));
+                       var array_type = new ArrayType (type, array_rank, context, get_src (begin));
                        array_type.nullable = accept (TokenType.INTERR);
                        array_type.invalid_syntax = invalid_array;
 
@@ -629,7 +629,7 @@ public class Vala.Parser : CodeVisitor {
                        }
                        expect (TokenType.CLOSE_BRACKET);
 
-                       var array_type = new ArrayType (type, 1, get_src (begin));
+                       var array_type = new ArrayType (type, 1, context, get_src (begin));
                        array_type.inline_allocated = true;
                        if (array_length != null) {
                                array_type.fixed_length = true;
@@ -1073,7 +1073,7 @@ public class Vala.Parser : CodeVisitor {
                                        throw new ParseError.SYNTAX ("size of inner arrays must not be 
specified in array creation expression");
                                }
 
-                               element_type = new ArrayType (element_type, size_specifier_list.size, 
element_type.source_reference);
+                               element_type = new ArrayType (element_type, size_specifier_list.size, 
context, element_type.source_reference);
                        } else {
                                first = false;
                        }
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index e31297b60..ef5676ebd 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -613,7 +613,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                } else if (nv[0] == "is_array") {
                                        if (eval (nv[1]) == "1") {
                                                return_type.value_owned = true;
-                                               return_type = new ArrayType (return_type, 1, 
return_type.source_reference);
+                                               return_type = new ArrayType (return_type, 1, context, 
return_type.source_reference);
                                                cb.return_type = return_type;
                                        }
                                } else if (nv[0] == "throws") {
@@ -697,7 +697,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                                } else if (nv[0] == "is_array") {
                                                        if (eval (nv[1]) == "1") {
                                                                param_type.value_owned = true;
-                                                               param_type = new ArrayType (param_type, 1, 
param_type.source_reference);
+                                                               param_type = new ArrayType (param_type, 1, 
context, param_type.source_reference);
                                                                p.variable_type = param_type;
                                                                if (!out_requested) {
                                                                        p.direction = ParameterDirection.IN;
@@ -1899,7 +1899,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                return element_type;
                        }
                        element_type.value_owned = true;
-                       return new ArrayType (element_type, 1, element_type.source_reference);
+                       return new ArrayType (element_type, 1, context, element_type.source_reference);
                } else if (type_node.tag == TypeTag.LIST) {
                        type.unresolved_symbol = new UnresolvedSymbol (new UnresolvedSymbol (null, "GLib"), 
"List");
                } else if (type_node.tag == TypeTag.SLIST) {
@@ -1945,7 +1945,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                type.unresolved_symbol = new UnresolvedSymbol (null, "uchar");
                                if (type_node.is_pointer) {
                                        type.value_owned = true;
-                                       return new ArrayType (type, 1, type.source_reference);
+                                       return new ArrayType (type, 1, context, type.source_reference);
                                }
                        } else if (n == "gushort") {
                                type.unresolved_symbol = new UnresolvedSymbol (null, "ushort");
@@ -1977,12 +1977,12 @@ public class Vala.GIdlParser : CodeVisitor {
                                type.unresolved_symbol = new UnresolvedSymbol (new UnresolvedSymbol (null, 
"GLib"), "Type");
                                if (type_node.is_pointer) {
                                        type.value_owned = true;
-                                       return new ArrayType (type, 1, type.source_reference);
+                                       return new ArrayType (type, 1, context, type.source_reference);
                                }
                        } else if (n == "GStrv") {
                                type.unresolved_symbol = new UnresolvedSymbol (null, "string");
                                type.value_owned = true;
-                               return new ArrayType (type, 1, type.source_reference);
+                               return new ArrayType (type, 1, context, type.source_reference);
                        } else {
                                var named_type = parse_type_string (n);
                                type = named_type as UnresolvedType;
@@ -2205,7 +2205,7 @@ public class Vala.GIdlParser : CodeVisitor {
 
                if (array_data != null && array_data.length > 0) {
                        type.value_owned = true;
-                       type = new ArrayType (type, array_dimension_data.length + 1, source_reference);
+                       type = new ArrayType (type, array_dimension_data.length + 1, context, 
source_reference);
                }
 
                type.nullable = nullable;
@@ -2310,7 +2310,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                } else if (nv[0] == "is_array") {
                                        if (eval (nv[1]) == "1") {
                                                return_type.value_owned = true;
-                                               return_type = new ArrayType (return_type, 1, 
return_type.source_reference);
+                                               return_type = new ArrayType (return_type, 1, context, 
return_type.source_reference);
                                                m.return_type = return_type;
                                        }
                                } else if (nv[0] == "is_pointer") {
@@ -2461,7 +2461,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                        if (nv[0] == "is_array") {
                                                if (eval (nv[1]) == "1") {
                                                        param_type.value_owned = true;
-                                                       param_type = new ArrayType (param_type, 1, 
param_type.source_reference);
+                                                       param_type = new ArrayType (param_type, 1, context, 
param_type.source_reference);
                                                        p.variable_type = param_type;
                                                        if (!out_requested) {
                                                                p.direction = ParameterDirection.IN;
@@ -2579,7 +2579,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                if (!(last_param_type is ArrayType)) {
                                        // last_param is array, p is array length
                                        last_param_type.value_owned = true;
-                                       last_param_type = new ArrayType (last_param_type, 1, 
last_param_type.source_reference);
+                                       last_param_type = new ArrayType (last_param_type, 1, context, 
last_param_type.source_reference);
                                        last_param.variable_type = last_param_type;
                                        last_param.direction = ParameterDirection.IN;
                                }
@@ -2878,7 +2878,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                } else if (nv[0] == "is_array") {
                                        if (eval (nv[1]) == "1") {
                                                type.value_owned = true;
-                                               type = new ArrayType (type, 1, type.source_reference);
+                                               type = new ArrayType (type, 1, context, 
type.source_reference);
                                        }
                                } else if (nv[0] == "weak") {
                                        if (eval (nv[1]) == "0") {
@@ -3151,7 +3151,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                        } else if (nv[0] == "is_array") {
                                                if (eval (nv[1]) == "1") {
                                                        param_type.value_owned = true;
-                                                       param_type = new ArrayType (param_type, 1, 
param_type.source_reference);
+                                                       param_type = new ArrayType (param_type, 1, context, 
param_type.source_reference);
                                                        p.variable_type = param_type;
                                                        p.direction = ParameterDirection.IN;
                                                }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]