]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
accept real literals with trailing dot ignore non-type symbols support
authorJürg Billeter <j@bitron.ch>
Thu, 10 Aug 2006 08:59:03 +0000 (08:59 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Thu, 10 Aug 2006 08:59:03 +0000 (08:59 +0000)
2006-08-10  Jürg Billeter  <j@bitron.ch>

* vala/scanner.l: accept real literals with trailing dot
* vala/valasymbolresolver.vala: ignore non-type symbols
* vala/valacodegenerator.vala: support float and double properties,
  adapt to Field changes, support compound assignments in properties
* vala/valainterfacewriter.vala: support ReferenceType attribute
* vala/valaclass.vala: implement get_lower_case_cprefix ()
* vala/valadatatype.vala: add get_lower_case_cprefix () method
* vala/valafield.vala: let get_cname return full C name
* vala/valamethod.vala: use DataType.get_lower_case_cprefix ()
* vala/valastruct.vala: implement get_lower_case_cprefix (), add
  set_is_reference_type () method

svn path=/trunk/; revision=94

vala/ChangeLog
vala/vala/scanner.l
vala/vala/valaclass.vala
vala/vala/valacodegenerator.vala
vala/vala/valadatatype.vala
vala/vala/valafield.vala
vala/vala/valainterfacewriter.vala
vala/vala/valamethod.vala
vala/vala/valastruct.vala
vala/vala/valasymbolresolver.vala

index e92b9066fb430898dae111fcd6cb7a80aab40d73..aaae701494133bf12bd08c975c9dd199349925d8 100644 (file)
@@ -1,3 +1,17 @@
+2006-08-10  Jürg Billeter  <j@bitron.ch>
+
+       * vala/scanner.l: accept real literals with trailing dot
+       * vala/valasymbolresolver.vala: ignore non-type symbols
+       * vala/valacodegenerator.vala: support float and double properties,
+         adapt to Field changes, support compound assignments in properties
+       * vala/valainterfacewriter.vala: support ReferenceType attribute
+       * vala/valaclass.vala: implement get_lower_case_cprefix ()
+       * vala/valadatatype.vala: add get_lower_case_cprefix () method
+       * vala/valafield.vala: let get_cname return full C name
+       * vala/valamethod.vala: use DataType.get_lower_case_cprefix ()
+       * vala/valastruct.vala: implement get_lower_case_cprefix (), add
+         set_is_reference_type () method
+
 2006-08-09  Jürg Billeter  <j@bitron.ch>
 
        * vala/parser.y: adapt to Vala.Signal change
index f6faa9a22655317b57ad5cc9aaf0d733f638a215..dd00b3434657aea543a7b0bdcbd9843661d503f0 100644 (file)
@@ -43,7 +43,7 @@ static gboolean file_comment = FALSE;
 space                  [ \t\n]*
 ident                  [[:alnum:]_]+
 literal_integer                [[:digit:]]+
-literal_real           [[:digit:]]+"."[[:digit:]]+
+literal_real           [[:digit:]]+"."[[:digit:]]*
 literal_character      \'([^\'\\]|\\[\'\"\?\\abfnrtv])*\'
 literal_string         \"([^\"\\]|\\[\'\"\?\\abfnrtv])*\"
 literal                        ({literal_integer}|{literal_real}|{literal_character}|{literal_string})
index 03b8358d8cb0644ed132b30fbeceb67a407bedd3..66aa0ed73762fbdc65b7b29f87a2e8de18a683d4 100644 (file)
@@ -285,6 +285,10 @@ public class Vala.Class : DataType {
                return "%s%s%s".printf (@namespace.get_lower_case_cprefix (), infix, get_lower_case_csuffix ());
        }
        
+       public override ref string get_lower_case_cprefix () {
+               return "%s_".printf (get_lower_case_cname (null));
+       }
+       
        public override ref string get_upper_case_cname (string infix) {
                return get_lower_case_cname (infix).up ();
        }
index d9b0583234a01b4c8d78c09da333b982f22df93f..fd25b1879daa60d0c3552e43acab77b6a3ea25a3 100644 (file)
@@ -65,6 +65,8 @@ public class Vala.CodeGenerator : CodeVisitor {
        TypeReference bool_type;
        TypeReference int_type;
        TypeReference string_type;
+       TypeReference float_type;
+       TypeReference double_type;
        
        public construct (bool manage_memory = true) {
                memory_management = manage_memory;
@@ -88,6 +90,12 @@ public class Vala.CodeGenerator : CodeVisitor {
                int_type = new TypeReference ();
                int_type.data_type = (DataType) root_symbol.lookup ("int").node;
 
+               float_type = new TypeReference ();
+               float_type.data_type = (DataType) root_symbol.lookup ("float").node;
+
+               double_type = new TypeReference ();
+               double_type.data_type = (DataType) root_symbol.lookup ("double").node;
+
                string_type = new TypeReference ();
                string_type.data_type = (DataType) root_symbol.lookup ("string").node;
        
@@ -393,6 +401,16 @@ public class Vala.CodeGenerator : CodeVisitor {
                        } else if (prop.type_reference.data_type == bool_type.data_type) {
                                cspec.call = new CCodeIdentifier ("g_param_spec_boolean");
                                cspec.add_argument (new CCodeConstant ("FALSE"));
+                       } else if (prop.type_reference.data_type == float_type.data_type) {
+                               cspec.call = new CCodeIdentifier ("g_param_spec_float");
+                               cspec.add_argument (new CCodeConstant ("-G_MAXFLOAT"));
+                               cspec.add_argument (new CCodeConstant ("G_MAXFLOAT"));
+                               cspec.add_argument (new CCodeConstant ("0"));
+                       } else if (prop.type_reference.data_type == double_type.data_type) {
+                               cspec.call = new CCodeIdentifier ("g_param_spec_double");
+                               cspec.add_argument (new CCodeConstant ("-G_MAXDOUBLE"));
+                               cspec.add_argument (new CCodeConstant ("G_MAXDOUBLE"));
+                               cspec.add_argument (new CCodeConstant ("0"));
                        } else {
                                cspec.call = new CCodeIdentifier ("g_param_spec_pointer");
                        }
@@ -606,6 +624,10 @@ public class Vala.CodeGenerator : CodeVisitor {
                        return new CCodeIdentifier ("g_value_set_int");
                } else if (type_reference.data_type == bool_type.data_type) {
                        return new CCodeIdentifier ("g_value_set_boolean");
+               } else if (type_reference.data_type == float_type.data_type) {
+                       return new CCodeIdentifier ("g_value_set_float");
+               } else if (type_reference.data_type == double_type.data_type) {
+                       return new CCodeIdentifier ("g_value_set_double");
                } else {
                        return new CCodeIdentifier ("g_value_set_pointer");
                }
@@ -688,6 +710,10 @@ public class Vala.CodeGenerator : CodeVisitor {
                                cgetcall.call = new CCodeIdentifier ("g_value_get_int");
                        } else if (prop.type_reference.type_name == "bool") {
                                cgetcall.call = new CCodeIdentifier ("g_value_get_boolean");
+                       } else if (prop.type_reference.type_name == "float") {
+                               cgetcall.call = new CCodeIdentifier ("g_value_get_float");
+                       } else if (prop.type_reference.type_name == "double") {
+                               cgetcall.call = new CCodeIdentifier ("g_value_get_double");
                        } else {
                                cgetcall.call = new CCodeIdentifier ("g_value_get_pointer");
                        }
@@ -808,7 +834,7 @@ public class Vala.CodeGenerator : CodeVisitor {
                                if (f.symbol.parent_symbol.node is DataType) {
                                        var t = (DataType) f.symbol.parent_symbol.node;
                                        var cdecl = new CCodeDeclaration (f.type_reference.get_cname ());
-                                       var var_decl = new CCodeVariableDeclarator ("%s_%s".printf (t.get_lower_case_cname (null), f.get_cname ()));
+                                       var var_decl = new CCodeVariableDeclarator (f.get_cname ());
                                        if (f.initializer != null) {
                                                var_decl.initializer = (CCodeExpression) f.initializer.ccodenode;
                                        }
@@ -1711,12 +1737,7 @@ public class Vala.CodeGenerator : CodeVisitor {
                                        expr.ccodenode = new CCodeMemberAccess (inst, f.get_cname ());
                                }
                        } else {
-                               if (f.symbol.parent_symbol.node is DataType) {
-                                       var t = (DataType) f.symbol.parent_symbol.node;
-                                       expr.ccodenode = new CCodeIdentifier ("%s_%s".printf (t.get_lower_case_cname (null), f.get_cname ()));
-                               } else {
-                                       expr.ccodenode = new CCodeIdentifier (f.get_cname ());
-                               }
+                               expr.ccodenode = new CCodeIdentifier (f.get_cname ());
                        }
                } else if (expr.symbol_reference.node is Constant) {
                        var c = (Constant) expr.symbol_reference.node;
@@ -2327,6 +2348,32 @@ public class Vala.CodeGenerator : CodeVisitor {
                                        ccast.add_argument (cexpr);
                                        cexpr = ccast;
                                }
+                               
+                               if (a.operator != AssignmentOperator.SIMPLE) {
+                                       CCodeBinaryOperator cop;
+                                       if (a.operator == AssignmentOperator.BITWISE_OR) {
+                                               cop = CCodeBinaryOperator.BITWISE_OR;
+                                       } else if (a.operator == AssignmentOperator.BITWISE_AND) {
+                                               cop = CCodeBinaryOperator.BITWISE_AND;
+                                       } else if (a.operator == AssignmentOperator.BITWISE_XOR) {
+                                               cop = CCodeBinaryOperator.BITWISE_XOR;
+                                       } else if (a.operator == AssignmentOperator.ADD) {
+                                               cop = CCodeBinaryOperator.PLUS;
+                                       } else if (a.operator == AssignmentOperator.SUB) {
+                                               cop = CCodeBinaryOperator.MINUS;
+                                       } else if (a.operator == AssignmentOperator.MUL) {
+                                               cop = CCodeBinaryOperator.MUL;
+                                       } else if (a.operator == AssignmentOperator.DIV) {
+                                               cop = CCodeBinaryOperator.DIV;
+                                       } else if (a.operator == AssignmentOperator.PERCENT) {
+                                               cop = CCodeBinaryOperator.MOD;
+                                       } else if (a.operator == AssignmentOperator.SHIFT_LEFT) {
+                                               cop = CCodeBinaryOperator.SHIFT_LEFT;
+                                       } else if (a.operator == AssignmentOperator.SHIFT_RIGHT) {
+                                               cop = CCodeBinaryOperator.SHIFT_RIGHT;
+                                       }
+                                       cexpr = new CCodeBinaryExpression (cop, (CCodeExpression) a.left.ccodenode, new CCodeParenthesizedExpression (cexpr));
+                               }
                                        
                                ccall.add_argument (cexpr);
                                
index f5eb4892571dc2fe6ca75fbd7e4d00a713dd2bb6..793f765314f6dd065843351b82c11ee06daef125 100644 (file)
@@ -169,6 +169,14 @@ public abstract class Vala.DataType : CodeNode {
         */
        public abstract ref string get_lower_case_cname (string infix = null);
        
+       /**
+        * Returns the string to be prefixed to members of this data type in
+        * lower case when used in C code.
+        *
+        * @return      the lower case prefix to be used in C code
+        */
+       public abstract ref string get_lower_case_cprefix ();
+       
        /**
         * Returns a list of C header filenames users of this data type must
         * include.
index 3c58710de03b4764a78f7f87d70b0a0971ffb2a7..d045d0a79d600c492b3618dca7e98bb4fc953684 100644 (file)
@@ -98,7 +98,12 @@ public class Vala.Field : CodeNode {
         */
        public string! get_cname () {
                if (cname == null) {
-                       cname = name;
+                       if (!instance && symbol.parent_symbol.node is DataType) {
+                               var t = (DataType) symbol.parent_symbol.node;
+                               cname = "%s_%s".printf (t.get_lower_case_cname (null), name);
+                       } else {
+                               cname = name;
+                       }
                }
                return cname;
        }
index a5e1576bf99912698720c2ae4a197423a8376d16..843aeb0a7b94d037d71820716152fd5231c5bcc0 100644 (file)
@@ -133,6 +133,11 @@ public class Vala.InterfaceWriter : CodeVisitor {
                        return;
                }
                
+               if (st.is_reference_type ()) {
+                       write_indent ();
+                       write_string ("[ReferenceType ()]");
+               }
+               
                write_indent ();
                write_string ("public struct ");
                write_identifier (st.name);
@@ -238,7 +243,7 @@ public class Vala.InterfaceWriter : CodeVisitor {
                        
                write_string (" ");
                if (f.name == "callback" || f.name == "flags" ||
-                   f.name == "out") {
+                   f.name == "in" || f.name == "out") {
                        write_string ("@");
                }
                write_identifier (f.name);
index 7be517a8290384b1329860781557ed1c5b1e5578..e11e5d0b054b70f99b393887deb363c986334bf7 100644 (file)
@@ -178,12 +178,12 @@ public class Vala.Method : CodeNode {
                        if (parent is DataType) {
                                if (construction) {
                                        if (name == null) {
-                                               cname = "%s_new".printf (((DataType) parent).get_lower_case_cname (null));
+                                               cname = "%snew".printf (((DataType) parent).get_lower_case_cprefix ());
                                        } else {
-                                               cname = "%s_new_%s".printf (((DataType) parent).get_lower_case_cname (null), name);
+                                               cname = "%snew_%s".printf (((DataType) parent).get_lower_case_cprefix (), name);
                                        }
                                } else {
-                                       cname = "%s_%s".printf (((DataType) parent).get_lower_case_cname (null), name);
+                                       cname = "%s%s".printf (((DataType) parent).get_lower_case_cprefix (), name);
                                }
                        } else if (parent is Namespace) {
                                cname = "%s%s".printf (((Namespace) parent).get_lower_case_cprefix (), name);
index 714e59ea6be0a6fc66c31bcd603ef24e51f9a17c..d8d30bf50c4097b4d8c3611dc88296fd814bb30f 100644 (file)
@@ -35,6 +35,7 @@ public class Vala.Struct : DataType {
        string dup_function;
        string free_function;
        string type_id;
+       string lower_case_cprefix;
        string lower_case_csuffix;
        bool reference_type;
        string marshaller_type_name;
@@ -146,6 +147,13 @@ public class Vala.Struct : DataType {
                this.cname = cname;
        }
        
+       public override ref string get_lower_case_cprefix () {
+               if (lower_case_cprefix == null) {
+                       lower_case_cprefix = "%s_".printf (get_lower_case_cname (null));
+               }
+               return lower_case_cprefix;
+       }
+       
        private string get_lower_case_csuffix () {
                if (lower_case_csuffix == null) {
                        lower_case_csuffix = Namespace.camel_case_to_lower_case (name);
@@ -172,6 +180,15 @@ public class Vala.Struct : DataType {
                return reference_type;
        }
        
+       /**
+        * Sets whether this data type has value or reference type semantics.
+        *
+        * @param ref_type true if this data type has reference type semantics
+        */
+       public void set_is_reference_type (bool ref_type) {
+               reference_type = ref_type;
+       }
+       
        private void process_ccode_attribute (Attribute! a) {
                foreach (NamedArgument arg in a.args) {
                        if (arg.name == "cname") {
@@ -182,6 +199,14 @@ public class Vala.Struct : DataType {
                                                set_cname (((StringLiteral) lit).eval ());
                                        }
                                }
+                       } else if (arg.name == "cprefix") {
+                               /* this will already be checked during semantic analysis */
+                               if (arg.argument is LiteralExpression) {
+                                       var lit = ((LiteralExpression) arg.argument).literal;
+                                       if (lit is StringLiteral) {
+                                               lower_case_cprefix = ((StringLiteral) lit).eval ();
+                                       }
+                               }
                        } else if (arg.name == "cheader_filename") {
                                /* this will already be checked during semantic analysis */
                                if (arg.argument is LiteralExpression) {
index a622a3eca679bb3b961087dac455371162ebc139..ccccfa6ee14217453816f83863cf87f884ca33ab 100644 (file)
@@ -140,6 +140,10 @@ public class Vala.SymbolResolver : CodeVisitor {
                        while (sym == null && scope != null) {
                                sym = scope.lookup (type.type_name);
                                scope = scope.parent_symbol;
+                               if (sym != null && !(sym.node is DataType) && !(sym.node is TypeParameter)) {
+                                       // ignore non-type symbols
+                                       sym = null;
+                               }
                        }
                        if (sym == null) {
                                foreach (NamespaceReference ns in current_using_directives) {