[vala/staging] Move some errors from signal-module to the semantic-analyzer pass



commit cd0b3a990e2f1bc981110b710a5dc9eaf53b8c18
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Sep 22 18:39:36 2018 +0200

    Move some errors from signal-module to the semantic-analyzer pass

 codegen/valagsignalmodule.vala | 31 -------------------------------
 vala/valadynamicsignal.vala    |  4 ----
 vala/valaelementaccess.vala    | 11 ++++++++++-
 vala/valasignal.vala           | 22 ++++++++++++++++++++++
 4 files changed, 32 insertions(+), 36 deletions(-)
---
diff --git a/codegen/valagsignalmodule.vala b/codegen/valagsignalmodule.vala
index f9a3b9faf..486f2c359 100644
--- a/codegen/valagsignalmodule.vala
+++ b/codegen/valagsignalmodule.vala
@@ -112,12 +112,6 @@ public class Vala.GSignalModule : GObjectModule {
                        return get_signal_canonical_constant (sig);
                }
 
-               if (detail_expr.value_type is NullType || !detail_expr.value_type.compatible (string_type)) {
-                       node.error = true;
-                       Report.error (detail_expr.source_reference, "only string details are supported");
-                       return null;
-               }
-
                if (detail_expr is StringLiteral) {
                        return get_signal_canonical_constant (sig, ((StringLiteral) detail_expr).eval ());
                }
@@ -143,12 +137,6 @@ public class Vala.GSignalModule : GObjectModule {
        }
 
        private CCodeExpression? get_detail_cexpression (Expression detail_expr, CodeNode node) {
-               if (detail_expr.value_type is NullType || !detail_expr.value_type.compatible (string_type)) {
-                       node.error = true;
-                       Report.error (detail_expr.source_reference, "only string details are supported");
-                       return null;
-               }
-
                var detail_cexpr = get_cvalue (detail_expr);
                CCodeFunctionCall detail_ccall;
                if (is_constant_ccode_expression (detail_cexpr)) {
@@ -162,25 +150,6 @@ public class Vala.GSignalModule : GObjectModule {
        }
 
        public override void visit_signal (Signal sig) {
-               // parent_symbol may be null for dynamic signals
-
-               var cl = sig.parent_symbol as Class;
-               if (cl != null && cl.is_compact) {
-                       sig.error = true;
-                       Report.error (sig.source_reference, "Signals are not supported in compact classes");
-                       return;
-               }
-
-               if (cl != null) {
-                       foreach (DataType base_type in cl.get_base_types ()) {
-                               if (SemanticAnalyzer.symbol_lookup_inherited (base_type.data_type, sig.name) 
is Signal) {
-                                       sig.error = true;
-                                       Report.error (sig.source_reference, "Signals with the same name as a 
signal in a base type are not supported");
-                                       return;
-                               }
-                       }
-               }
-
                if (signal_enum != null && sig.parent_symbol is TypeSymbol) {
                        signal_enum.add_value (new CCodeEnumValue ("%s_%s_SIGNAL".printf 
(get_ccode_upper_case_name ((TypeSymbol) sig.parent_symbol), get_ccode_upper_case_name (sig))));
                }
diff --git a/vala/valadynamicsignal.vala b/vala/valadynamicsignal.vala
index c3cae8b06..c250dac20 100644
--- a/vala/valadynamicsignal.vala
+++ b/vala/valadynamicsignal.vala
@@ -34,8 +34,4 @@ public class Vala.DynamicSignal : Signal {
                base (name, return_type, source_reference, comment);
                this.dynamic_type = dynamic_type;
        }
-
-       public override bool check (CodeContext context) {
-               return true;
-       }
 }
diff --git a/vala/valaelementaccess.vala b/vala/valaelementaccess.vala
index 755eaf6ee..62cd1a65d 100644
--- a/vala/valaelementaccess.vala
+++ b/vala/valaelementaccess.vala
@@ -132,7 +132,16 @@ public class Vala.ElementAccess : Expression {
                                Report.error (source_reference, "Element access with more than one dimension 
is not supported for signals");
                                return false;
                        }
-                       get_indices ().get (0).target_type = context.analyzer.string_type.copy ();
+
+                       var detail_expr = get_indices ().get (0);
+                       detail_expr.target_type = context.analyzer.string_type.copy ();
+                       detail_expr.check (context);
+
+                       if (detail_expr.value_type is NullType || !detail_expr.value_type.compatible 
(context.analyzer.string_type)) {
+                               error = true;
+                               Report.error (detail_expr.source_reference, "only string details are 
supported");
+                               return false;
+                       }
                }
 
                foreach (Expression index in get_indices ()) {
diff --git a/vala/valasignal.vala b/vala/valasignal.vala
index 9e971b6f8..fa32cbe64 100644
--- a/vala/valasignal.vala
+++ b/vala/valasignal.vala
@@ -181,6 +181,28 @@ public class Vala.Signal : Symbol, Callable {
 
                checked = true;
 
+               // parent_symbol may be null for dynamic signals
+               var parent_cl = parent_symbol as Class;
+               if (parent_cl != null && parent_cl.is_compact) {
+                       error = true;
+                       Report.error (source_reference, "Signals are not supported in compact classes");
+                       return false;
+               }
+
+               if (parent_cl != null) {
+                       foreach (DataType base_type in parent_cl.get_base_types ()) {
+                               if (SemanticAnalyzer.symbol_lookup_inherited (base_type.data_type, name) is 
Signal) {
+                                       error = true;
+                                       Report.error (source_reference, "Signals with the same name as a 
signal in a base type are not supported");
+                                       return false;
+                               }
+                       }
+               }
+
+               if (this is DynamicSignal) {
+                       return !error;
+               }
+
                return_type.check (context);
 
                foreach (Parameter param in parameters) {


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