<commit_before>/* valastruct.vala
 *
 * Copyright (C) 2006-2010  <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>>
 */

using GLib;

/**
 * Represents a struct declaration in the source code.
 */
public class Vala.Struct : TypeSymbol {
	private List<TypeParameter> type_parameters = new ArrayList<TypeParameter> ();
	private List<Constant> constants = new ArrayList<Constant> ();
	private List<Field> fields = new ArrayList<Field> ();
	private List<Method> methods = new ArrayList<Method> ();
	private List<Property> properties = new ArrayList<Property> ();
	private DataType _base_type = null;

	private bool? boolean_type;
	private bool? integer_type;
	private bool? floating_type;
	private bool? decimal_floating_type;
	private bool? simple_type;
	private int? _rank;
	private int? _width;
	private bool? _signed;
	private bool? _is_immutable;

	/**
	 * Specifies the base type.
	 */
	public DataType? base_type {
		get {
			return _base_type;
		}
		set {
			value.parent_node = this;
			_base_type = value;
		}
	}

	/**
	 * Specifies the base Struct.
	 */
	public Struct? base_struct {
		get {
			if (_base_type != null) {
				return _base_type.data_type as Struct;
			}
			return null;
		}
	}

	/**
	 * Specifies the default construction method.
	 */
	public Method default_construction_method { get; set; }

	/**
	 * Specifies if 'const' should be emitted for input parameters
	 * of this type.
	 */
	public bool is_immutable {
		get {
			if (_is_immutable == null) {
				_is_immutable = get_attribute ("Immutable") != null;
			}
			return _is_immutable;
		}
		set {
			_is_immutable = value;
			set_attribute ("Immutable", value);
		}
	}

	public int width {
		get {
			if (_width == null) {
				if (is_integer_type ()) {
					_width = get_attribute_integer ("IntegerType", "width", 32);
				} else {
					_width = get_attribute_integer ("FloatingType", "width", 32);
				}
			}
			return _width;
		}
		set {
			_width = value;
			if (is_integer_type ()) {
				set_attribute_integer ("IntegerType", "width", value);
			} else {
				set_attribute_integer ("FloatingType", "width", value);
			}
		}
	}

	public bool signed {
		get {
			if (_signed == null) {
				_signed = get_attribute_bool ("IntegerType", "signed", true);
			}
			return _signed;
		}
		set {
			_signed = value;
			set_attribute_bool ("IntegerType", "signed", value);
		}
	}

	/**
	 * Specifies the rank of this integer or floating point type.
	 */
	public int rank {
		get {
			if (_rank == null) {
				if (is_integer_type () && has_attribute_argument ("IntegerType", "rank")) {
					_rank = get_attribute_integer ("IntegerType", "rank");
				} else if (has_attribute_argument ("FloatingType", "rank")) {
					_rank = get_attribute_integer ("FloatingType", "rank");
				} else {
					var st = base_struct;
					if (st != null) {
						_rank = st.rank;
					} else {
						Report.error (source_reference, "internal error: struct has no rank");
					}
				}
			}
			return _rank;
		}
		set {
			_rank = value;
			if (is_integer_type ()) {
				set_attribute_integer ("IntegerType", "rank", _rank);
			} else {
				set_attribute_integer ("FloatingType", "rank", _rank);
			}
		}
	}

	/**
	 * Creates a new struct.
	 *
	 * @param name             type name
	 * @param source_reference reference to source code
	 * @return                 newly created struct
	 */
	public Struct (string name, SourceReference? source_reference = null, Comment? comment = null) {<commit_msg>vala: Don't return null if no rank attribute was found<commit_after>/* valastruct.vala
 *
 * Copyright (C) 2006-2010  <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>>
 */

using GLib;

/**
 * Represents a struct declaration in the source code.
 */
public class Vala.Struct : TypeSymbol {
	private List<TypeParameter> type_parameters = new ArrayList<TypeParameter> ();
	private List<Constant> constants = new ArrayList<Constant> ();
	private List<Field> fields = new ArrayList<Field> ();
	private List<Method> methods = new ArrayList<Method> ();
	private List<Property> properties = new ArrayList<Property> ();
	private DataType _base_type = null;

	private bool? boolean_type;
	private bool? integer_type;
	private bool? floating_type;
	private bool? decimal_floating_type;
	private bool? simple_type;
	private int? _rank;
	private int? _width;
	private bool? _signed;
	private bool? _is_immutable;

	/**
	 * Specifies the base type.
	 */
	public DataType? base_type {
		get {
			return _base_type;
		}
		set {
			value.parent_node = this;
			_base_type = value;
		}
	}

	/**
	 * Specifies the base Struct.
	 */
	public Struct? base_struct {
		get {
			if (_base_type != null) {
				return _base_type.data_type as Struct;
			}
			return null;
		}
	}

	/**
	 * Specifies the default construction method.
	 */
	public Method default_construction_method { get; set; }

	/**
	 * Specifies if 'const' should be emitted for input parameters
	 * of this type.
	 */
	public bool is_immutable {
		get {
			if (_is_immutable == null) {
				_is_immutable = get_attribute ("Immutable") != null;
			}
			return _is_immutable;
		}
		set {
			_is_immutable = value;
			set_attribute ("Immutable", value);
		}
	}

	public int width {
		get {
			if (_width == null) {
				if (is_integer_type ()) {
					_width = get_attribute_integer ("IntegerType", "width", 32);
				} else {
					_width = get_attribute_integer ("FloatingType", "width", 32);
				}
			}
			return _width;
		}
		set {
			_width = value;
			if (is_integer_type ()) {
				set_attribute_integer ("IntegerType", "width", value);
			} else {
				set_attribute_integer ("FloatingType", "width", value);
			}
		}
	}

	public bool signed {
		get {
			if (_signed == null) {
				_signed = get_attribute_bool ("IntegerType", "signed", true);
			}
			return _signed;
		}
		set {
			_signed = value;
			set_attribute_bool ("IntegerType", "signed", value);
		}
	}

	/**
	 * Specifies the rank of this integer or floating point type.
	 */
	public int rank {
		get {
			if (_rank == null) {
				if (is_integer_type () && has_attribute_argument ("IntegerType", "rank")) {
					_rank = get_attribute_integer ("IntegerType", "rank");
				} else if (has_attribute_argument ("FloatingType", "rank")) {
					_rank = get_attribute_integer ("FloatingType", "rank");
				} else {
					var st = base_struct;
					if (st != null) {
						_rank = st.rank;
					} else {
						Report.error (source_reference, "internal error: struct has no rank");
						return 0;
					}
				}
			}
			return _rank;
		}
		set {
			_rank = value;
			if (is_integer_type ()) {
				set_attribute_integer ("IntegerType", "rank", _rank);
			} else {
				set_attribute_integer ("FloatingType", "rank", _rank);
			}
		}
	}

	/**
	 * Creates a new struct.
	 *
	 * @param name             type name
	 * @param source_reference reference to source code
	 * @return                 newly created struct
	 */
	public Struct (string name, SourceReference? source_reference = null, Comment? comment = null) {
{'fraction_non_alphanumeric': 0.11005353955978585, 'fraction_numerical': 0.006067816775728733, 'mean_word_length': 3.2156469408224675, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '2931644', 'n_tokens_mistral': 3007, 'n_tokens_neox': 2579, 'n_words': 855}