[vala] codegen: Generate typedefs for boolean, integer, and floating types



commit de1cbc407a2740586e62c5624e873b7565064fcc
Author: JÃrg Billeter <j bitron ch>
Date:   Fri Mar 30 21:32:33 2012 +0200

    codegen: Generate typedefs for boolean, integer, and floating types

 codegen/valaccodeattribute.vala    |   14 --------------
 codegen/valaccodestructmodule.vala |   27 ++++++++++++++++++++-------
 2 files changed, 20 insertions(+), 21 deletions(-)
---
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index 49900dc..f22598b 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -596,20 +596,6 @@ public class Vala.CCodeAttribute : AttributeCache {
 				}
 			} else if (sym is Signal) {
 				return Symbol.camel_case_to_lower_case (sym.name);
-			} else if (sym is Struct && !sym.external) {
-				var st = (Struct) sym;
-				if (st.is_boolean_type ()) {
-					// typedef for boolean types
-					return "bool";
-				} else if (st.is_integer_type ()) {
-					// typedef for integral types
-					return "%sint%d_t".printf (st.signed ? "" : "u", st.width);
-				} else if (st.is_floating_type ()) {
-					// typedef for floating types
-					return st.width == 64 ? "double" : "float";
-				} else {
-					return "%s%s".printf (CCodeBaseModule.get_ccode_prefix (sym.parent_symbol), sym.name);
-				}
 			} else if (sym is LocalVariable || sym is Parameter) {
 				return sym.name;
 			} else {
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index ec258d5..75b14bd 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -30,13 +30,26 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
 			return;
 		}
 
-		if (st.is_boolean_type ()) {
-			// typedef for boolean types
-			decl_space.add_include ("stdbool.h");
-			return;
-		} else if (st.is_integer_type ()) {
-			// typedef for integral types
-			decl_space.add_include ("stdint.h");
+		if (st.is_boolean_type () || st.is_integer_type () || st.is_floating_type ()) {
+			if (st.base_struct != null) {
+				generate_struct_declaration (st.base_struct, decl_space);
+				decl_space.add_type_declaration (new CCodeTypeDefinition (get_ccode_name (st.base_struct), new CCodeVariableDeclarator (get_ccode_name (st))));
+			} else {
+				string typename = null;
+				if (st.is_boolean_type ()) {
+					// typedef for boolean types
+					decl_space.add_include ("stdbool.h");
+					typename = "bool";
+				} else if (st.is_integer_type ()) {
+					// typedef for integral types
+					decl_space.add_include ("stdint.h");
+					typename = "%sint%d_t".printf (st.signed ? "" : "u", st.width);
+				} else if (st.is_floating_type ()) {
+					// typedef for floating types
+					typename = (st.width == 64 ? "double" : "float");
+				}
+				decl_space.add_type_declaration (new CCodeTypeDefinition (typename, new CCodeVariableDeclarator (get_ccode_name (st))));
+			}
 			return;
 		}
 



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