public static List <string> IdentGeneratable(this IGeneratable multiLineGeneratable, int identCount = 1)
        {
            var lines = multiLineGeneratable.ToLines();
            var ret   = lines.IdentLines(identCount);

            return(ret);
        }
Exemplo n.º 2
0
        public string Finish(string indent)
        {
            string ret = "";

            foreach (Parameter p in parms.Keys)
            {
                if (parms [p] == false)
                {
                    continue;
                }

                IGeneratable igen = p.Generatable;

                if (igen is CallbackGen)
                {
                    continue;
                }
                else if (igen is StructBase || igen is ByRefGen)
                {
                    ret += indent + String.Format("if ({0} != IntPtr.Zero) System.Runtime.InteropServices.Marshal.StructureToPtr (my{0}, {0}, false);\n", p.Name);
                }
                else if (igen is IManualMarshaler)
                {
                    ret += String.Format("{0}{1} = {2};", indent, p.Name, (igen as IManualMarshaler).AllocNative("my" + p.Name));
                }
                else
                {
                    ret += indent + p.Name + " = " + igen.CallByName("my" + p.Name) + ";\n";
                }
            }

            return(ret);
        }
Exemplo n.º 3
0
        public static void GenerateMembers(this IGeneratable gen, IndentWriter writer, Func <IMemberGeneratable, bool> where = null)
        {
            var array = gen.GetMemberGeneratables().Where(x => where == null || where (x)).ToArray();

            for (int i = 0; i < array.Length; ++i)
            {
                var member = array [i];

                // Generate pinvoke signature for a method
                if (!(gen is Interface) && member is INativeCallable callable)
                {
                    callable.GenerateImport(gen, writer);
                }

                // Generate documentation is a member supports it.
                if (member is IDocumented doc)
                {
                    doc.GenerateDocumentation(writer);
                }

                // Call the main member generation implementation.
                member.Generate(gen, writer);

                if (i != array.Length - 1 && member.NewlineAfterGeneration(writer.Options))
                {
                    writer.WriteLine();
                }
            }
        }
Exemplo n.º 4
0
        public string Finish(string indent)
        {
            string ret = "";

            for (int i = 0; i < parms.Count; i++)
            {
                if ((bool)special[i] == false)
                {
                    continue;
                }

                Parameter    p    = parms [i] as Parameter;
                IGeneratable igen = p.Generatable;

                if (igen is CallbackGen)
                {
                    continue;
                }
                else if (igen is StructBase || igen is ByRefGen)
                {
                    ret += indent + String.Format("if ({0} != IntPtr.Zero) System.Runtime.InteropServices.Marshal.StructureToPtr (my{0}, {0}, false);\n", p.Name);
                }
                else
                {
                    ret += indent + p.Name + " = " + igen.ToNativeReturn("my" + p.Name) + ";\n";
                }
            }

            return(ret);
        }
Exemplo n.º 5
0
        public static void GenerateCallableDefinition(this INativeCallable callable, IGeneratable gen, IndentWriter writer)
        {
            callable.ReturnValue.GenerateDocumentation(writer);

            writer.WriteIndent();
            if (!string.IsNullOrEmpty(callable.GetModifiers(gen, writer.Options)) && !(gen is Interface))
            {
                writer.Write(callable.GetModifiers(gen, writer.Options) + " ");
            }

            var returnType = callable.GetReturnCSharpType(writer);

            // generate ReturnValue then Parameters
            var result = BuildParameters(callable, writer.Options, !callable.IsInstanceCallable(gen, writer.Options));

            writer.Write($"{returnType} {callable.Name.ToCSharp ()} ({result.TypesAndNames})");

            if (gen is Interface)
            {
                writer.Write(";");
                writer.WriteLine();
                return;
            }

            writer.WriteLine();
            writer.WriteLine("{");
            using (writer.Indent())
            {
                string prefix = returnType != "void" ? "return " : string.Empty;
                writer.WriteLine($"{prefix}{callable.CIdentifier} ({result.Names});");
            }
            writer.WriteLine("}");
        }
Exemplo n.º 6
0
 private void Add <T>(IGeneratable <T> generator)
 {
     if (!Has(typeof(T)) && !generator.GetType().IsInterface)
     {
         supportedGenerators.Add(typeof(T), generator);
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Gets a case form entity that has been converted to it's .docx form.
        /// </summary>
        public async Task <byte[]> GetCaseFormAsDocx(int id)
        {
            _logger.LogInformation(LoggingEvents.GetItem, "Getting case form {Id}", id);

            var caseForm = await _caseFormRepo.GetByIdAsync(id);

            if (caseForm == null)
            {
                _logger.LogWarning(LoggingEvents.GetItemNotFound, "Case form {Id} NOT FOUND", id);
            }

            IGeneratable generatable = null;

            if (caseForm is WarrantInDebtForm)
            {
                generatable = _mapper.Map <WarrantInDebtDocxForm>(caseForm, opt =>
                {
                    opt.Items.Add("court", _serviceRunSettings.CaseFormSettings.CourtName);
                    opt.Items.Add("courtAddress", _serviceRunSettings.CaseFormSettings.CourtAddress);
                    // TODO: If above works, can pass in user profile /attorney info here
                });
            }
            else if (caseForm is SummonsForUnlawfulDetainerForm)
            {
                // todo: map new SummonsForUnlawfulDetainerDocxForm()
            }

            return(await _docxConverterService.Convert(generatable));
        }
Exemplo n.º 8
0
        string CallCount(string name)
        {
            string       result = CountCast + "(" + name + " == null ? 0 : " + name + ".Length)";
            IGeneratable gen    = SymbolTable.Table[count_elem.GetAttribute("type")];

            return(gen.CallByName(result));
        }
 public void initExistingModel(IGeneratable data)
 {
     if (!(data is PropertyData))
     {
         throw new ArgumentException("parameter must be PropertyData");
     }
     this.data = (PropertyData)data;
 }
Exemplo n.º 10
0
 // TODO: Decide what to do here if we have functions which work
 // on instances (instance-parameter is not set)
 public string GetModifiers(IGeneratable parent, GenerationOptions opts)
 {
     if (CanFirstParameterBeInstance(parent, opts))
     {
         return("public");
     }
     return("public static");
 }
Exemplo n.º 11
0
        string EventHandlerQualifiedName(IGeneratable parent)
        {
            if (IsEventHandler)
            {
                return("System.EventHandler");
            }

            return(parent.Name + "." + EventHandlerName);
        }
Exemplo n.º 12
0
        public string GetModifiers(IGeneratable parent, GenerationOptions opts)
        {
            if (parent is Class @class && @class.Abstract)
            {
                return("protected");
            }

            return("public");
        }
Exemplo n.º 13
0
		public override void Generate (GenerationInfo gen_info, string indent)
		{
			if (Hidden)
				return;

			visible = Access != "private";

			StreamWriter sw = gen_info.Writer;
			SymbolTable table = SymbolTable.Table;

			string wrapped = table.GetCSType (CType);
			string wrapped_name = SymbolTable.Table.MangleName (CName);
			IGeneratable gen = table [CType];

			if (IsArray && !IsNullTermArray) {
				sw.WriteLine (indent + "[MarshalAs (UnmanagedType.ByValArray, SizeConst=" + ArrayLength + ")]");
				sw.WriteLine (indent + "{0} {1} {2};", Access, CSType, StudlyName);
			} else if (IsArray && IsNullTermArray) {
				sw.WriteLine (indent + "private {0} {1};", "IntPtr", StudlyName+ "Ptr");
				if ((Readable || Writable) && Access == "public") {
					sw.WriteLine (indent + "public {0} {1} {{", CSType, StudlyName);
					if (Readable)
						sw.WriteLine (indent + "\tget {{ return GLib.Marshaller.StructArrayFromNullTerminatedIntPtr<{0}> ({1}); }}",
						              base.CSType, StudlyName + "Ptr");
					if (Writable)
						sw.WriteLine (indent + "\tset {{ {0} = GLib.Marshaller.StructArrayToNullTerminatedStructArrayIntPtr<{1}> (value); }}",
						              StudlyName + "Ptr", base.CSType);
					sw.WriteLine (indent + "}");
				}
			} else if (IsBitfield) {
				base.Generate (gen_info, indent);
			} else if (gen is IAccessor) {
				sw.WriteLine (indent + "private {0} {1};", gen.MarshalType, Name);

				if (Access != "private") {
					IAccessor acc = table [CType] as IAccessor;
					sw.WriteLine (indent + Access + " " + wrapped + " " + StudlyName + " {");
					acc.WriteAccessors (sw, indent + "\t", Name);
					sw.WriteLine (indent + "}");
				}
			} else if (IsPointer && (gen is StructGen || gen is BoxedGen || gen is UnionGen)) {
				sw.WriteLine (indent + "private {0} {1};", CSType, Name);
				sw.WriteLine ();
				if (Access != "private") {
					sw.WriteLine (indent + Access + " " + wrapped + " " + wrapped_name + " {");
					sw.WriteLine (indent + "\tget { return " + table.FromNative (CType, Name) + "; }");
					sw.WriteLine (indent + "}");
				}
			} else if (IsPointer && CSType != "string") {
				// FIXME: probably some fields here which should be visible.
				visible = false;
				sw.WriteLine (indent + "private {0} {1};", CSType, Name);
			} else {
				sw.WriteLine (indent + "{0} {1} {2};", Access, CSType, Access == "public" ? StudlyName : Name);
			}
		}
Exemplo n.º 14
0
        public override void Generate(GenerationInfo gen_info, string indent)
        {
            if (Hidden)
            {
                return;
            }

            StreamWriter sw    = gen_info.Writer;
            SymbolTable  table = SymbolTable.Table;

            string       wrapped      = table.GetCSType(CType);
            string       wrapped_name = SymbolTable.Table.MangleName(CName);
            IGeneratable gen          = table [CType];

            if (IsArray)
            {
                sw.WriteLine(indent + "[MarshalAs (UnmanagedType.ByValArray, SizeConst=" + ArrayLength + ")]");
                sw.WriteLine(indent + "{0} {1} {2};", Access, CSType, StudlyName);
            }
            else if (IsBitfield)
            {
                base.Generate(gen_info, indent);
            }
            else if (gen is IAccessor)
            {
                sw.WriteLine(indent + "private {0} {1};", gen.MarshalType, Name);

                if (Access != "private")
                {
                    IAccessor acc = table [CType] as IAccessor;
                    sw.WriteLine(indent + Access + " " + wrapped + " " + StudlyName + " {");
                    acc.WriteAccessors(sw, indent + "\t", Name);
                    sw.WriteLine(indent + "}");
                }
            }
            else if (IsPointer && (gen is StructGen || gen is BoxedGen))
            {
                sw.WriteLine(indent + "private {0} {1};", CSType, Name);
                sw.WriteLine();
                if (Access != "private")
                {
                    sw.WriteLine(indent + Access + " " + wrapped + " " + wrapped_name + " {");
                    sw.WriteLine(indent + "\tget { return " + table.FromNativeReturn(CType, Name) + "; }");
                    sw.WriteLine(indent + "}");
                }
            }
            else if (IsPointer && CSType != "string")
            {
                // FIXME: probably some fields here which should be visible.
                sw.WriteLine(indent + "private {0} {1};", CSType, Name);
            }
            else
            {
                sw.WriteLine(indent + "{0} {1} {2};", Access, CSType, Access == "public" ? StudlyName : Name);
            }
        }
Exemplo n.º 15
0
        public string GetToNativeReturnType(string c_type)
        {
            IGeneratable gen = this[c_type];

            if (gen == null)
            {
                return("");
            }
            return(gen.ToNativeReturnType);
        }
Exemplo n.º 16
0
        public string ToNativeReturn(string c_type, string val)
        {
            IGeneratable gen = this[c_type];

            if (gen == null)
            {
                return("");
            }
            return(gen.ToNativeReturn(val));
        }
Exemplo n.º 17
0
        public string CallByName(string c_type, string var_name)
        {
            IGeneratable gen = this[c_type];

            if (gen == null)
            {
                return("");
            }
            return(gen.CallByName(var_name));
        }
Exemplo n.º 18
0
        public string FromNative(string c_type, string val)
        {
            IGeneratable gen = this[c_type];

            if (gen == null)
            {
                return("");
            }
            return(gen.FromNative(val));
        }
Exemplo n.º 19
0
        public IGeneratable <T> GetGenerator <T>(Type type)
        {
            IGeneratable <T> generator = null;

            if (Has(type))
            {
                generator = (IGeneratable <T>)supportedGenerators[type];
            }
            return(generator);
        }
Exemplo n.º 20
0
        public string GetCSType(string c_type)
        {
            IGeneratable gen = this[c_type];

            if (gen == null)
            {
                return("");
            }
            return(gen.QualifiedName);
        }
Exemplo n.º 21
0
        public string GetName(string c_type)
        {
            IGeneratable gen = this[c_type];

            if (gen == null)
            {
                return("");
            }
            return(gen.Name);
        }
Exemplo n.º 22
0
        public string GetMarshalType(string c_type)
        {
            IGeneratable gen = this[c_type];

            if (gen == null)
            {
                return("");
            }
            return(gen.MarshalType);
        }
Exemplo n.º 23
0
        public void Generate(IGeneratable parent, IndentWriter writer)
        {
            string value = Value;

            if (parent is IEnumFormatter formatter)
            {
                value = formatter.FormatValue(value);
            }

            writer.WriteLine(Name.ToCSharp() + " = " + value + ",");
        }
Exemplo n.º 24
0
        public virtual bool IsCPointer()
        {
            IGeneratable gen = SymbolTable.Table[CType];

            return(CType.EndsWith("*") ||
                   CType.EndsWith("pointer") ||
                   gen is CallbackGen ||
                   cstype == "string" ||
                   (CType == "guint8" && (IsArray && IsNullTermArray)) ||
                   elem.GetAttributeAsBoolean("is_callback"));
        }
Exemplo n.º 25
0
        public void Generate(IGeneratable parent, IndentWriter writer)
        {
            // Simple uncorrect gen for now
            var managedType = this.Resolve(writer.Options);

            // We need something that will tell us the equivalent C# type
            // including the number of pointers.
            // For now, generate normal info.

            writer.WriteLine($"{managedType.CSharpType} {Name.ToCSharp ()};");
        }
        public string Setup(string indent)
        {
            string ret = "";

            for (int i = 0; i < parms.Count; i++)
            {
                if ((bool)special[i] == false)
                {
                    continue;
                }

                Parameter    p    = parms [i] as Parameter;
                IGeneratable igen = p.Generatable;

                if (igen is CallbackGen)
                {
                    if (user_data_param == null)
                    {
                        ret += indent + String.Format("{0} {1}_invoker = new {0} ({1});\n", (igen as CallbackGen).InvokerName, p.Name);
                    }
                    else if (destroy_param == null)
                    {
                        ret += indent + String.Format("{0} {1}_invoker = new {0} ({1}, {2});\n", (igen as CallbackGen).InvokerName, p.Name, user_data_param);
                    }
                    else
                    {
                        ret += indent + String.Format("{0} {1}_invoker = new {0} ({1}, {2}, {3});\n", (igen as CallbackGen).InvokerName, p.Name, user_data_param, destroy_param);
                    }
                }
                else if (p.Scope == "call")
                {
                    if (igen is ObjectBase)
                    {
                        ret += indent + igen.QualifiedName + " my" + p.Name + " = " + (igen as ObjectBase).FromNative(p.Name, true) + ";\n";
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    ret += indent + igen.QualifiedName + " my" + p.Name;
                    if (p.PassAs == "ref")
                    {
                        ret += " = " + p.FromNative(p.Name);
                    }
                    ret += ";\n";
                }
            }

            return(ret);
        }
Exemplo n.º 27
0
        private object DeAlias(string type)
        {
            type = Trim(type);
            while (types [type] is AliasGen)
            {
                IGeneratable igen = types [type] as AliasGen;
                types [type] = types [igen.Name];
                type         = igen.Name;
            }

            return(types [type]);
        }
Exemplo n.º 28
0
        // TODO: Unexpose this
        public bool CanFirstParameterBeInstance(IGeneratable parent, GenerationOptions opts)
        {
            var param = Parameters.FirstOrDefault();

            if (param == null)
            {
                return(false);
            }

            // hacky check for symbol equality
            return(param.Resolve(opts).GetType() == parent.GetType());
        }
Exemplo n.º 29
0
        public static void GenerateConstructor(this INativeCallable callable, IGeneratable parent, IndentWriter writer)
        {
            callable.ReturnValue.GenerateDocumentation(writer);

            var modifier = callable.GetModifiers(parent, writer.Options);

            var result = BuildParameters(callable, writer.Options, !callable.IsInstanceCallable(parent, writer.Options));

            // FIXME, should check to see if it is deprecated
            writer.WriteLine($"{modifier} {parent.Name} ({result.TypesAndNames}) : base ({result.Names})");
            writer.WriteLine("{");
            writer.WriteLine("}");
        }
Exemplo n.º 30
0
        public void Generate(GenerationOptions opts, IGeneratable parent, IndentWriter writer)
        {
            writer.WriteDocumentation(Doc);

            // Simple uncorrect gen for now
            var managedType = this.GetSymbol(opts);

            // We need something that will tell us the equivalent C# type
            // including the number of pointers.
            // For now, generate normal info.

            writer.WriteLine($"{managedType.Name} {Name};");
        }
        /// <summary>
        /// Generates an item any given times
        /// </summary>
        /// <param name="item">The item to generate</param>
        /// <param name="itemCount">Times the item will be generated</param>
        public void Generate(IGeneratable item, int itemCount)
        {
            int generatedMines = 0;

            while (generatedMines < itemCount)
            {
                int rowToPutMine = RandomNumber.Get(this.field.Rows);
                int colToPutMine = RandomNumber.Get(this.field.Columns);

                if (field[rowToPutMine, colToPutMine] != item.Symbol)
                {
                    field[rowToPutMine, colToPutMine] = item.Symbol;
                    generatedMines++;
                }
            }
        }
Exemplo n.º 32
0
		public static void AddType (IGeneratable gen)
		{
			complex_types [gen.Name] = gen;
		}
Exemplo n.º 33
0
 public void AddType(IGeneratable gen)
 {
     types [gen.CName] = gen;
 }
Exemplo n.º 34
0
 public void AddTypes(IGeneratable[] gens)
 {
     foreach (IGeneratable gen in gens)
         types [gen.CName] = gen;
 }
 public void InitializeMineFieldTests()
 {
     this.field = new Field(Rows, Columns);
     this.generator = new MineGenerator(this.field);
     this.item = new Mine('$');
 }
Exemplo n.º 36
0
 public ClassField(XmlElement elem)
 {
     name = elem.GetAttribute ("name");
     igen = SymbolTable.Table [elem.GetAttribute ("type")];
 }
 /// <summary>
 /// Initilizes a new instance of the <see cref="MinesweeperAdjacencyMap"/> class.
 /// </summary>
 /// <param name="field">The field which will be mapped</param>
 /// <param name="item">The item which the mapping will be calculated for</param>
 public MinesweeperAdjacencyMap(IField field, IGeneratable item)
 {
     this.field = field;
     this.item = item;
 }