[vala/wip/issue/745: 1/2] vala: Add Symbol.is_extern and use/set is accordingly



commit 3d5c94abbf038129541a0174935e9b4e8f83c80f
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Jun 18 23:34:09 2019 +0200

    vala: Add Symbol.is_extern and use/set is accordingly
    
    This actually holds the information whether a symbol was declared
    with `extern` modificator. Adjust the setting of Symbol.external and
    usage of Symbol.external_package.
    
    See https://gitlab.gnome.org/GNOME/vala/issues/745

 vala/valaenumvaluetype.vala |  2 +-
 vala/valagenieparser.vala   | 32 +++++++++++++++----------------
 vala/valagirparser.vala     | 16 ----------------
 vala/valamethod.vala        |  4 ++--
 vala/valaparser.vala        | 46 ++++++++++++++++++++++-----------------------
 vala/valasymbol.vala        | 15 ++++++++++++++-
 6 files changed, 54 insertions(+), 61 deletions(-)
---
diff --git a/vala/valaenumvaluetype.vala b/vala/valaenumvaluetype.vala
index c409763fe..896371323 100644
--- a/vala/valaenumvaluetype.vala
+++ b/vala/valaenumvaluetype.vala
@@ -47,7 +47,7 @@ public class Vala.EnumValueType : ValueType {
                        string_type.value_owned = false;
                        to_string_method = new Method ("to_string", string_type);
                        to_string_method.access = SymbolAccessibility.PUBLIC;
-                       to_string_method.external = true;
+                       to_string_method.is_extern = true;
                        to_string_method.owner = type_symbol.scope;
                        to_string_method.this_parameter = new Parameter ("this", this);
                        to_string_method.scope.add (to_string_method.this_parameter.name, 
to_string_method.this_parameter);
diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala
index 39f8f4692..2348d4346 100644
--- a/vala/valagenieparser.vala
+++ b/vala/valagenieparser.vala
@@ -2765,8 +2765,8 @@ public class Vala.Genie.Parser : CodeVisitor {
                var c = new Constant (id, type, initializer, get_src (begin), comment);
                c.access = get_default_accessibility (id);
 
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) 
{
-                       c.external = true;
+               if (ModifierFlags.EXTERN in flags) {
+                       c.is_extern = true;
                }
                if (ModifierFlags.NEW in flags) {
                        c.hides = true;
@@ -2808,8 +2808,8 @@ public class Vala.Genie.Parser : CodeVisitor {
 
                set_attributes (f, attrs);
 
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) 
{
-                       f.external = true;
+               if (ModifierFlags.EXTERN in flags) {
+                       f.is_extern = true;
                }
                if (ModifierFlags.NEW in flags) {
                        f.hides = true;
@@ -2989,7 +2989,7 @@ public class Vala.Genie.Parser : CodeVisitor {
                        method.is_inline = true;
                }
                if (ModifierFlags.EXTERN in flags) {
-                       method.external = true;
+                       method.is_extern = true;
                }
 
                expect (TokenType.EOL);
@@ -3039,8 +3039,7 @@ public class Vala.Genie.Parser : CodeVisitor {
 
                if (accept_block ()) {
                        method.body = parse_block ();
-               } else if (scanner.source_file.file_type == SourceFileType.PACKAGE) {
-                       method.external = true;
+                       method.external = false;
                }
                return method;
        }
@@ -3089,8 +3088,8 @@ public class Vala.Genie.Parser : CodeVisitor {
                if (ModifierFlags.NEW in flags) {
                        prop.hides = true;
                }
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) 
{
-                       prop.external = true;
+               if (ModifierFlags.EXTERN in flags) {
+                       prop.is_extern = true;
                }
 
                if (ModifierFlags.ASYNC in flags) {
@@ -3345,8 +3344,8 @@ public class Vala.Genie.Parser : CodeVisitor {
                } else {
                        iface.access = get_default_accessibility (sym.name);
                }
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) 
{
-                       iface.external = true;
+               if (ModifierFlags.EXTERN in flags) {
+                       iface.is_extern = true;
                }
                set_attributes (iface, attrs);
                foreach (TypeParameter type_param in type_param_list) {
@@ -3415,8 +3414,8 @@ public class Vala.Genie.Parser : CodeVisitor {
                } else {
                        en.access = get_default_accessibility (sym.name);
                }
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) 
{
-                       en.external = true;
+               if (ModifierFlags.EXTERN in flags) {
+                       en.is_extern = true;
                }
                set_attributes (en, attrs);
 
@@ -3704,8 +3703,7 @@ public class Vala.Genie.Parser : CodeVisitor {
 
                if (accept_block ()) {
                        method.body = parse_block ();
-               } else if (scanner.source_file.file_type == SourceFileType.PACKAGE) {
-                       method.external = true;
+                       method.external = false;
                }
 
                return method;
@@ -3766,8 +3764,8 @@ public class Vala.Genie.Parser : CodeVisitor {
                if (ModifierFlags.STATIC in flags) {
                        d.has_target = false;
                }
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) 
{
-                       d.external = true;
+               if (ModifierFlags.EXTERN in flags) {
+                       d.is_extern = true;
                }
 
                set_attributes (d, attrs);
diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala
index fe4a060a8..4e9372976 100644
--- a/vala/valagirparser.vala
+++ b/vala/valagirparser.vala
@@ -2345,7 +2345,6 @@ public class Vala.GirParser : CodeVisitor {
                if (!error_domain)
                        set_type_id_ccode (sym);
 
-               sym.external = true;
                sym.access = SymbolAccessibility.PUBLIC;
 
                string common_prefix = null;
@@ -2786,7 +2785,6 @@ public class Vala.GirParser : CodeVisitor {
 
                set_type_id_ccode (st);
 
-               st.external = true;
                st.access = SymbolAccessibility.PUBLIC;
 
                var gtype_struct_for = reader.get_attribute ("glib:is-gtype-struct-for");
@@ -2858,7 +2856,6 @@ public class Vala.GirParser : CodeVisitor {
                set_type_id_ccode (cl);
 
                cl.access = SymbolAccessibility.PUBLIC;
-               cl.external = true;
 
                next ();
 
@@ -2935,8 +2932,6 @@ public class Vala.GirParser : CodeVisitor {
                set_type_id_ccode (iface);
 
                iface.access = SymbolAccessibility.PUBLIC;
-               iface.external = true;
-
 
                next ();
 
@@ -3040,7 +3035,6 @@ public class Vala.GirParser : CodeVisitor {
                var prop = new Property (current.name, type, null, null, current.source_reference);
                prop.comment = comment;
                prop.access = SymbolAccessibility.PUBLIC;
-               prop.external = true;
                prop.is_abstract = is_abstract;
                if (no_array_length || array_null_terminated) {
                        prop.set_attribute_bool ("CCode", "array_length", !no_array_length);
@@ -3155,7 +3149,6 @@ public class Vala.GirParser : CodeVisitor {
 
                s.access = SymbolAccessibility.PUBLIC;
                s.comment = comment;
-               s.external = true;
 
                // Transform fixed-array properties of return-type into ccode-attribute
                var array_type = return_type as ArrayType;
@@ -3411,7 +3404,6 @@ public class Vala.GirParser : CodeVisitor {
                require_copy_free = cl.has_attribute_argument ("CCode", "type_id");
 
                cl.access = SymbolAccessibility.PUBLIC;
-               cl.external = true;
 
                if (metadata.has_argument (ArgumentType.BASE_TYPE)) {
                        cl.add_base_type (parse_type_from_string (metadata.get_string 
(ArgumentType.BASE_TYPE), true, metadata.get_source_reference (ArgumentType.BASE_TYPE)));
@@ -3512,7 +3504,6 @@ public class Vala.GirParser : CodeVisitor {
                        st = (Struct) current.symbol;
                }
                st.access = SymbolAccessibility.PUBLIC;
-               st.external = true;
 
                next ();
 
@@ -3564,7 +3555,6 @@ public class Vala.GirParser : CodeVisitor {
                current.symbol = c;
                c.access = SymbolAccessibility.PUBLIC;
                c.comment = comment;
-               c.external = true;
                if (no_array_length || array_null_terminated) {
                        c.set_attribute_bool ("CCode", "array_length", !no_array_length);
                }
@@ -3719,7 +3709,6 @@ public class Vala.GirParser : CodeVisitor {
                                st.base_type = base_type;
                        }
                        st.comment = alias.comment;
-                       st.external = true;
                        st.set_simple_type (simple_type);
                        alias.symbol = st;
                } else if (type_sym is Class) {
@@ -3729,7 +3718,6 @@ public class Vala.GirParser : CodeVisitor {
                                cl.add_base_type (base_type);
                        }
                        cl.comment = alias.comment;
-                       cl.external = true;
                        cl.is_compact = ((Class) type_sym).is_compact;
                        alias.symbol = cl;
                } else if (type_sym is Interface) {
@@ -3740,7 +3728,6 @@ public class Vala.GirParser : CodeVisitor {
                                iface.add_prerequisite (base_type);
                        }
                        iface.comment = alias.comment;
-                       iface.external = true;
                        alias.symbol = iface;
                } else if (type_sym is Delegate) {
                        var orig = (Delegate) type_sym;
@@ -3766,8 +3753,6 @@ public class Vala.GirParser : CodeVisitor {
                                deleg.attributes.append (attribute);
                        }
 
-                       deleg.external = true;
-
                        alias.symbol = deleg;
                } else if (type_sym != null) {
                        Report.warning (alias.source_reference, "alias `%s' for `%s' is not supported".printf 
(alias.get_full_name (), type_sym.get_full_name ()));
@@ -4154,7 +4139,6 @@ public class Vala.GirParser : CodeVisitor {
                                method = new CreationMethod (((CreationMethod) finish_method).class_name, 
null, m.source_reference);
                                method.access = m.access;
                                method.binding = m.binding;
-                               method.external = true;
                                method.coroutine = true;
                                method.has_construct_function = finish_method.has_construct_function;
 
diff --git a/vala/valamethod.vala b/vala/valamethod.vala
index bfaf2a00b..60a1a3543 100644
--- a/vala/valamethod.vala
+++ b/vala/valamethod.vala
@@ -757,9 +757,9 @@ public class Vala.Method : Subroutine, Callable {
 
                if (is_abstract && body != null) {
                        Report.error (source_reference, "Abstract methods cannot have bodies");
-               } else if ((is_abstract || is_virtual) && external && !external_package && 
!parent_symbol.external) {
+               } else if ((is_abstract || is_virtual) && is_extern) {
                        Report.error (source_reference, "Extern methods cannot be abstract or virtual");
-               } else if (external && body != null) {
+               } else if (is_extern && body != null) {
                        Report.error (source_reference, "Extern methods cannot have bodies");
                } else if (!is_abstract && !external && source_type == SourceFileType.SOURCE && body == null) 
{
                        Report.error (source_reference, "Non-abstract, non-extern methods must have bodies");
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index 10c42d6d6..754d50cb5 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -2576,8 +2576,8 @@ public class Vala.Parser : CodeVisitor {
                if (ModifierFlags.ABSTRACT in flags) {
                        cl.is_abstract = true;
                }
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) 
{
-                       cl.external = true;
+               if (ModifierFlags.EXTERN in flags) {
+                       cl.is_extern = true;
                }
                set_attributes (cl, attrs);
                foreach (TypeParameter type_param in type_param_list) {
@@ -2630,8 +2630,8 @@ public class Vala.Parser : CodeVisitor {
 
                var c = new Constant (id, type, null, get_src (begin), comment);
                c.access = access;
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) 
{
-                       c.external = true;
+               if (ModifierFlags.EXTERN in flags) {
+                       c.is_extern = true;
                }
                if (ModifierFlags.NEW in flags) {
                        c.hides = true;
@@ -2679,8 +2679,8 @@ public class Vala.Parser : CodeVisitor {
                    || ModifierFlags.OVERRIDE in flags) {
                        Report.error (f.source_reference, "abstract, virtual, and override modifiers are not 
applicable to fields");
                }
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) 
{
-                       f.external = true;
+               if (ModifierFlags.EXTERN in flags) {
+                       f.is_extern = true;
                }
                if (ModifierFlags.NEW in flags) {
                        f.hides = true;
@@ -2767,7 +2767,7 @@ public class Vala.Parser : CodeVisitor {
                        method.is_inline = true;
                }
                if (ModifierFlags.EXTERN in flags) {
-                       method.external = true;
+                       method.is_extern = true;
                }
                expect (TokenType.OPEN_PARENS);
                if (current () != TokenType.CLOSE_PARENS) {
@@ -2794,8 +2794,7 @@ public class Vala.Parser : CodeVisitor {
                }
                if (!accept (TokenType.SEMICOLON)) {
                        method.body = parse_block ();
-               } else if (scanner.source_file.file_type == SourceFileType.PACKAGE) {
-                       method.external = true;
+                       method.external = false;
                }
 
                parent.add_method (method);
@@ -2832,8 +2831,8 @@ public class Vala.Parser : CodeVisitor {
                if (ModifierFlags.ASYNC in flags) {
                        Report.error (prop.source_reference, "async properties are not supported yet");
                }
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) 
{
-                       prop.external = true;
+               if (ModifierFlags.EXTERN in flags) {
+                       prop.is_extern = true;
                }
                if ((prop.is_abstract && prop.is_virtual)
                        || (prop.is_abstract && prop.overrides)
@@ -3011,8 +3010,8 @@ public class Vala.Parser : CodeVisitor {
                }
                var st = new Struct (sym.name, get_src (begin), comment);
                st.access = access;
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) 
{
-                       st.external = true;
+               if (ModifierFlags.EXTERN in flags) {
+                       st.is_extern = true;
                }
                set_attributes (st, attrs);
                foreach (TypeParameter type_param in type_param_list) {
@@ -3054,8 +3053,8 @@ public class Vala.Parser : CodeVisitor {
                }
                var iface = new Interface (sym.name, get_src (begin), comment);
                iface.access = access;
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) 
{
-                       iface.external = true;
+               if (ModifierFlags.EXTERN in flags) {
+                       iface.is_extern = true;
                }
                set_attributes (iface, attrs);
                foreach (TypeParameter type_param in type_param_list) {
@@ -3089,8 +3088,8 @@ public class Vala.Parser : CodeVisitor {
                var sym = parse_symbol_name ();
                var en = new Enum (sym.name, get_src (begin), comment);
                en.access = access;
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) 
{
-                       en.external = true;
+               if (ModifierFlags.EXTERN in flags) {
+                       en.is_extern = true;
                }
                set_attributes (en, attrs);
 
@@ -3156,8 +3155,8 @@ public class Vala.Parser : CodeVisitor {
                var sym = parse_symbol_name ();
                var ed = new ErrorDomain (sym.name, get_src (begin), comment);
                ed.access = access;
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) 
{
-                       ed.external = true;
+               if (ModifierFlags.EXTERN in flags) {
+                       ed.is_extern = true;
                }
                set_attributes (ed, attrs);
 
@@ -3363,7 +3362,7 @@ public class Vala.Parser : CodeVisitor {
                        method = new CreationMethod (sym.inner.name, sym.name, get_src (begin), comment);
                }
                if (ModifierFlags.EXTERN in flags) {
-                       method.external = true;
+                       method.is_extern = true;
                }
                if (ModifierFlags.ABSTRACT in flags
                    || ModifierFlags.VIRTUAL in flags
@@ -3400,8 +3399,7 @@ public class Vala.Parser : CodeVisitor {
                set_attributes (method, attrs);
                if (!accept (TokenType.SEMICOLON)) {
                        method.body = parse_block ();
-               } else if (scanner.source_file.file_type == SourceFileType.PACKAGE) {
-                       method.external = true;
+                       method.external = false;
                }
 
                parent.add_method (method);
@@ -3428,8 +3426,8 @@ public class Vala.Parser : CodeVisitor {
                        }
                        d.has_target = false;
                }
-               if (ModifierFlags.EXTERN in flags || scanner.source_file.file_type == SourceFileType.PACKAGE) 
{
-                       d.external = true;
+               if (ModifierFlags.EXTERN in flags) {
+                       d.is_extern = true;
                }
                if (!d.get_attribute_bool ("CCode", "has_typedef", true)) {
                        if (!d.external) {
diff --git a/vala/valasymbol.vala b/vala/valasymbol.vala
index 67484821b..633719676 100644
--- a/vala/valasymbol.vala
+++ b/vala/valasymbol.vala
@@ -152,11 +152,23 @@ public abstract class Vala.Symbol : CodeNode {
                get { return _scope; }
        }
 
+       public bool is_extern { get; set; }
+
        /**
         * Specifies whether the implementation is external, for example in
         * a separate C source file or in an external library.
         */
-       public bool external { get; set; }
+       public bool external {
+               get {
+                       if (_external != null) {
+                               return _external;
+                       }
+                       return is_extern || external_package;
+               }
+               set {
+                       _external = value;
+               }
+       }
 
        /**
         * Specifies whether the implementation is in an external library.
@@ -196,6 +208,7 @@ public abstract class Vala.Symbol : CodeNode {
 
        private weak Scope _owner;
        private Scope _scope;
+       private bool? _external;
 
        protected Symbol (string? name, SourceReference? source_reference, Comment? comment = null) {
                this.name = name;


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