<commit_before>/* valaccodestructmodule.vala
 *
 * Copyright (C) 2006-2009  <NAME>
 * Copyright (C) 2006-2008  <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	<NAME> <<EMAIL>>
 *	<NAME> <<EMAIL>>
 */

using GLib;

public abstract class Vala.CCodeStructModule : CCodeBaseModule {
	public override void generate_struct_declaration (Struct st, CCodeFile decl_space) {
		if (add_symbol_declaration (decl_space, st, get_ccode_name (st))) {
			return;
		}

		if (st.is_boolean_type () || st.is_integer_type () || st.is_floating_type ()) {
			// See GTypeModule.visit_struct()
			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;
		}

		if (context.profile == Profile.GOBJECT) {
			if (get_ccode_has_type_id (st)) {
				decl_space.add_include ("glib-object.h");
				decl_space.add_type_declaration (new CCodeNewline ());
				var macro = "(%s_get_type ())".printf (get_ccode_lower_case_name (st, null));
				decl_space.add_type_declaration (new CCodeMacroReplacement (get_ccode_type_id (st), macro));

				var type_fun = new StructRegisterFunction (st);
				type_fun.init_from_type (context, false, true);
				decl_space.add_type_member_declaration (type_fun.get_declaration ());
			}
		}

		if (st.base_struct == null) {
			decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (get_ccode_name (st)), new CCodeVariableDeclarator (get_ccode_name (st))));
		} else {
			decl_space.add_type_declaration (new CCodeTypeDefinition (get_ccode_name (st.base_struct), new CCodeVariableDeclarator (get_ccode_name (st))));
		}

		var instance_struct = new CCodeStruct ("_%s".printf (get_ccode_name (st)));
		instance_struct.modifiers |= (st.version.deprecated ? CCodeModifiers.DEPRECATED : 0);

		foreach (Field f in st.get_fields ()) {
			if (f.binding == MemberBinding.INSTANCE)  {
				append_field (instance_struct, f, decl_space);
			}<commit_msg>codegen: Always include base_struct declaration if available<commit_after>/* valaccodestructmodule.vala
 *
 * Copyright (C) 2006-2009  <NAME>
 * Copyright (C) 2006-2008  <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	<NAME> <<EMAIL>>
 *	<NAME> <<EMAIL>>
 */

using GLib;

public abstract class Vala.CCodeStructModule : CCodeBaseModule {
	public override void generate_struct_declaration (Struct st, CCodeFile decl_space) {
		if (add_symbol_declaration (decl_space, st, get_ccode_name (st))) {
			return;
		}

		if (st.base_struct != null) {
			generate_struct_declaration (st.base_struct, decl_space);
		}

		if (st.is_boolean_type () || st.is_integer_type () || st.is_floating_type ()) {
			string typename;
			// See GTypeModule.visit_struct()
			if (st.base_struct != null) {
				typename = get_ccode_name (st.base_struct);
			} else 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");
			} else {
				assert_not_reached ();
			}
			decl_space.add_type_declaration (new CCodeTypeDefinition (typename, new CCodeVariableDeclarator (get_ccode_name (st))));
			return;
		}

		if (context.profile == Profile.GOBJECT) {
			if (get_ccode_has_type_id (st)) {
				decl_space.add_include ("glib-object.h");
				decl_space.add_type_declaration (new CCodeNewline ());
				var macro = "(%s_get_type ())".printf (get_ccode_lower_case_name (st, null));
				decl_space.add_type_declaration (new CCodeMacroReplacement (get_ccode_type_id (st), macro));

				var type_fun = new StructRegisterFunction (st);
				type_fun.init_from_type (context, false, true);
				decl_space.add_type_member_declaration (type_fun.get_declaration ());
			}
		}

		if (st.base_struct == null) {
			decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (get_ccode_name (st)), new CCodeVariableDeclarator (get_ccode_name (st))));
		} else {
			decl_space.add_type_declaration (new CCodeTypeDefinition (get_ccode_name (st.base_struct), new CCodeVariableDeclarator (get_ccode_name (st))));
		}

		var instance_struct = new CCodeStruct ("_%s".printf (get_ccode_name (st)));
		instance_struct.modifiers |= (st.version.deprecated ? CCodeModifiers.DEPRECATED : 0);

		foreach (Field f in st.get_fields ()) {
			if (f.binding == MemberBinding.INSTANCE)  {
				append_field (instance_struct, f, decl_space);
			}
{'fraction_non_alphanumeric': 0.11291034888856176, 'fraction_numerical': 0.00942146327101428, 'mean_word_length': 4.2021439509954055, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4420700', 'n_tokens_mistral': 2469, 'n_tokens_neox': 2182, 'n_words': 614}