<commit_before>// GtkSharp.Generation.Signature.cs - The Signature Generation Class.
//
// Author: <NAME> <<EMAIL>>
//
// Copyright (c) 2003-2004 Novell, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
// License as published by the Free Software Foundation.
//
// This program 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
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.


namespace GtkSharp.Generation {

	using System;
	using System.Collections.Generic;
	using System.Xml;

	public class Signature  {
		
		private IList<Parameter> parms = new List<Parameter> ();

		public Signature (Parameters parms)
		{
			foreach (Parameter p in parms) {
				if (!parms.IsHidden (p))
					this.parms.Add (p);
			}
		}

		public override string ToString ()
		{
			if (parms.Count == 0)
				return "";

			string[] result = new string [parms.Count];
			int i = 0;

			foreach (Parameter p in parms) {
				result [i] = p.PassAs != "" ? p.PassAs + " " : "";
				result [i++] += p.CSType + " " + p.Name;
			}

			return String.Join (", ", result);
		}

		public string Types {
			get {
				if (parms.Count == 0)
					return "";

				string[] result = new string [parms.Count];
				int i = 0;

				foreach (Parameter p in parms)
					result [i++] = p.CSType;

				return String.Join (":", result);
			}
		}

		public bool IsAccessor {
			get {
				int count = 0;
				foreach (Parameter p in parms) {
					if (p.PassAs == "out")
						count++;
					
					if (count > 1)
						return false;
				}
				return count == 1;
			}
		}

		public string AccessorType {
			get {
				foreach (Parameter p in parms)
					if (p.PassAs == "out")
						return p.CSType;
				
				return null;
			}
		}

		public string AccessorName {
			get {
				foreach (Parameter p in parms)
					if (p.PassAs == "out")
						return p.Name;
				
				return null;
			}
		}

		public string AsAccessor {
			get {
				string[] result = new string [parms.Count - 1];
				int i = 0;

				foreach (Parameter p in parms) {
					if (p.PassAs == "out")
						continue;

					result [i] = p.PassAs != "" ? p.PassAs + " " : "";
					result [i++] += p.CSType + " " + p.Name;
				}
				
				return String.Join (", ", result);
			}
		}

		public string WithoutOptional ()
		{
			if (parms.Count == 0)
				return String.Empty;

			var result = new string [parms.Count];
			int i = 0;

			foreach (Parameter p in parms) {
				if (p.IsOptional && p.PassAs == String.Empty)
					continue;
				result [i] = p.PassAs != String.Empty ? p.PassAs + " " : String.Empty;
				result [i++] += p.CSType + " " + p.Name;
			}

			return String.Join (", ", result, 0, i);
		}

		public string CallWithoutOptionals ()
		{
			if (parms.Count == 0)
				return String.Empty;

			var result = new string [parms.Count];
			int i = 0;

			foreach (Parameter p in parms) {

				result [i] = p.PassAs != "" ? p.PassAs + " " : "";
				if (p.IsOptional && p.PassAs == String.Empty) {
					if (p.Generatable is StructGen || p.Generatable is BoxedGen)
						result [i++] += " .Zero";
					else if (p.CSType == "System.IntPtr")
						result [i++] += "System.IntPtr.Zero";
					else
						result [i++] += "null";
				}
				else
					result [i++] += p.Name;<commit_msg>generator: fix optional parameters again<commit_after>// GtkSharp.Generation.Signature.cs - The Signature Generation Class.
//
// Author: <NAME> <<EMAIL>>
//
// Copyright (c) 2003-2004 Novell, Inc.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the GNU General Public
// License as published by the Free Software Foundation.
//
// This program 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
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.


namespace GtkSharp.Generation {

	using System;
	using System.Collections.Generic;
	using System.Xml;

	public class Signature  {
		
		private IList<Parameter> parms = new List<Parameter> ();

		public Signature (Parameters parms)
		{
			foreach (Parameter p in parms) {
				if (!parms.IsHidden (p))
					this.parms.Add (p);
			}
		}

		public override string ToString ()
		{
			if (parms.Count == 0)
				return "";

			string[] result = new string [parms.Count];
			int i = 0;

			foreach (Parameter p in parms) {
				result [i] = p.PassAs != "" ? p.PassAs + " " : "";
				result [i++] += p.CSType + " " + p.Name;
			}

			return String.Join (", ", result);
		}

		public string Types {
			get {
				if (parms.Count == 0)
					return "";

				string[] result = new string [parms.Count];
				int i = 0;

				foreach (Parameter p in parms)
					result [i++] = p.CSType;

				return String.Join (":", result);
			}
		}

		public bool IsAccessor {
			get {
				int count = 0;
				foreach (Parameter p in parms) {
					if (p.PassAs == "out")
						count++;
					
					if (count > 1)
						return false;
				}
				return count == 1;
			}
		}

		public string AccessorType {
			get {
				foreach (Parameter p in parms)
					if (p.PassAs == "out")
						return p.CSType;
				
				return null;
			}
		}

		public string AccessorName {
			get {
				foreach (Parameter p in parms)
					if (p.PassAs == "out")
						return p.Name;
				
				return null;
			}
		}

		public string AsAccessor {
			get {
				string[] result = new string [parms.Count - 1];
				int i = 0;

				foreach (Parameter p in parms) {
					if (p.PassAs == "out")
						continue;

					result [i] = p.PassAs != "" ? p.PassAs + " " : "";
					result [i++] += p.CSType + " " + p.Name;
				}
				
				return String.Join (", ", result);
			}
		}

		public string WithoutOptional ()
		{
			if (parms.Count == 0)
				return String.Empty;

			var result = new string [parms.Count];
			int i = 0;

			foreach (Parameter p in parms) {
				if (p.IsOptional && p.PassAs == String.Empty)
					continue;
				result [i] = p.PassAs != String.Empty ? p.PassAs + " " : String.Empty;
				result [i++] += p.CSType + " " + p.Name;
			}

			return String.Join (", ", result, 0, i);
		}

		public string CallWithoutOptionals ()
		{
			if (parms.Count == 0)
				return String.Empty;

			var result = new string [parms.Count];
			int i = 0;

			foreach (Parameter p in parms) {

				result [i] = p.PassAs != "" ? p.PassAs + " " : "";
				if (p.IsOptional && p.PassAs == String.Empty) {
					if (p.Generatable is StructGen || p.Generatable is BoxedGen)
						result [i++] += p.CSType + ".Zero";
					else if (p.CSType == "System.IntPtr")
						result [i++] += "System.IntPtr.Zero";
					else
						result [i++] += "null";
				}
				else
					result [i++] += p.Name;
{'fraction_non_alphanumeric': 0.13948055517383537, 'fraction_numerical': 0.010169025697402776, 'mean_word_length': 2.3187414500683996, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 15, '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': '3911653', 'n_tokens_mistral': 3063, 'n_tokens_neox': 2351, 'n_words': 784}