[vala/staging] ccode: Implicitly register declaration for added CCodeFunction



commit 7bfd9a38debb873045134aee5bffb58aa552c967
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Oct 1 16:21:21 2019 +0200

    ccode: Implicitly register declaration for added CCodeFunction
    
    This will prevent the user's vala source to override implicitly defined
    functions of vala's boilerblate for a type.

 ccode/valaccodefile.vala | 8 ++++++++
 1 file changed, 8 insertions(+)
---
diff --git a/ccode/valaccodefile.vala b/ccode/valaccodefile.vala
index adbdb1880..cf4870267 100644
--- a/ccode/valaccodefile.vala
+++ b/ccode/valaccodefile.vala
@@ -28,6 +28,7 @@ public class Vala.CCodeFile {
 
        Set<string> features = new HashSet<string> (str_hash, str_equal);
        Set<string> declarations = new HashSet<string> (str_hash, str_equal);
+       Set<string> definitions = new HashSet<string> (str_hash, str_equal);
        Set<string> includes = new HashSet<string> (str_hash, str_equal);
        CCodeFragment comments = new CCodeFragment ();
        CCodeFragment feature_test_macros = new CCodeFragment ();
@@ -89,12 +90,19 @@ public class Vala.CCodeFile {
        }
 
        public void add_function_declaration (CCodeFunction func) {
+               declarations.add (func.name);
+
                var decl = func.copy ();
                decl.is_declaration = true;
                type_member_declaration.append (decl);
        }
 
        public void add_function (CCodeFunction func) {
+               if (!definitions.add (func.name)) {
+                       Report.error (null, "internal: Redefinition of `%s'".printf (func.name));
+                       return;
+               }
+
                type_member_definition.append (func);
        }
 


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