예제 #1
0
 public override void GenerateCopySetToConverter(StructuredStringBuilder sb)
 {
     using (sb.IncreaseDepth())
     {
         sb.AppendLine(".Select(b => new MemorySlice<byte>(b.ToArray()))");
     }
 }
예제 #2
0
 private void GenerateCopy(StructuredStringBuilder sb, string accessorPrefix, string rhsAccessorPrefix)
 {
     sb.AppendLine($"{accessorPrefix}.{Name}.SetTo(");
     using (sb.IncreaseDepth())
     {
         sb.AppendLine($"{rhsAccessorPrefix}.{Name}.Select(");
         using (sb.IncreaseDepth())
         {
             sb.AppendLine($"(i) => new KeyValuePair<{KeyTypeGen.TypeName(getter: false)}, {ValueTypeGen.TypeName(getter: false)}>(");
             using (sb.IncreaseDepth())
             {
                 sb.AppendLine($"i.Key{(KeyIsLoqui ? ".CopyFieldsFrom()" : string.Empty) },");
                 sb.AppendLine($"i.Value{(ValueIsLoqui ? ".CopyFieldsFrom()" : string.Empty)})),");
             }
         }
     }
 }
예제 #3
0
 public override void GenerateSetNth(StructuredStringBuilder sb, Accessor accessor, Accessor rhs, bool internalUse)
 {
     sb.AppendLine($"{accessor}.SetTo(");
     using (sb.IncreaseDepth())
     {
         sb.AppendLine($"({rhs}).Select(");
         using (sb.IncreaseDepth())
         {
             sb.AppendLine($"(i) => new KeyValuePair<{KeyTypeGen.TypeName(getter: false)}, {ValueTypeGen.TypeName(getter: false)}>(");
             using (sb.IncreaseDepth())
             {
                 sb.AppendLine($"i.Key{(KeyIsLoqui ? ".Copy()" : string.Empty) },");
                 sb.AppendLine($"i.Value{(ValueIsLoqui ? ".Copy()" : string.Empty)})),");
             }
         }
     }
     sb.AppendLine($"break;");
 }
예제 #4
0
파일: ArrayType.cs 프로젝트: Noggog/Loqui
 public override void WrapSet(StructuredStringBuilder sb, Accessor accessor, Action <StructuredStringBuilder> a)
 {
     if (FixedSize.HasValue && SubTypeGeneration is not LoquiType)
     {
         sb.AppendLine($"{accessor} = ");
         using (sb.IncreaseDepth())
         {
             a(sb);
             sb.AppendLine($"{NullChar}.ToArray();");
         }
     }
     else
     {
         base.WrapSet(sb, accessor, a);
     }
 }
예제 #5
0
 public override void WrapSet(StructuredStringBuilder sb, Accessor accessor, Action <StructuredStringBuilder> a)
 {
     if (Nullable)
     {
         sb.AppendLine($"{accessor} = ");
         using (sb.IncreaseDepth())
         {
             a(sb);
             sb.AppendLine($".ShallowClone();");
         }
     }
     else
     {
         using (var args = sb.Call(
                    $"{accessor}.SetTo"))
         {
             args.Add(subFg => a(subFg));
         }
     }
 }
예제 #6
0
파일: ListType.cs 프로젝트: Noggog/Loqui
 public virtual void WrapSet(StructuredStringBuilder sb, Accessor accessor, Action <StructuredStringBuilder> a)
 {
     if (Nullable)
     {
         sb.AppendLine($"{accessor} = ");
         using (sb.IncreaseDepth())
         {
             a(sb);
             sb.AppendLine($".ToExtendedList<{SubTypeGeneration.TypeName(getter: false, needsCovariance: true)}>();");
         }
     }
     else
     {
         using (var args = sb.Call(
                    $"{accessor}.SetTo"))
         {
             args.Add(subFg => a(subFg));
         }
     }
 }
예제 #7
0
    protected override async Task GenerateCtor(StructuredStringBuilder sb)
    {
        if (BasicCtorPermission == CtorPermissionLevel.noGeneration)
        {
            return;
        }
        if (BasicCtorPermission == CtorPermissionLevel.@public)
        {
            sb.AppendLine($"public {Name}(");
            List <string> lines = new List <string>();
            foreach (var field in IterateFields())
            {
                lines.Add($"{field.TypeName(getter: false)} {field.Name} = default({field.TypeName(getter: false)})");
            }
            for (int i = 0; i < lines.Count; i++)
            {
                using (sb.IncreaseDepth())
                {
                    using (sb.Line())
                    {
                        sb.Append(lines[i]);
                        if (i != lines.Count - 1)
                        {
                            sb.Append(",");
                        }
                        else
                        {
                            sb.Append(")");
                        }
                    }
                }
            }

            using (sb.CurlyBrace())
            {
                foreach (var field in IterateFields())
                {
                    sb.AppendLine($"this.{field.Name} = {field.Name};");
                }
                foreach (var mod in gen.GenerationModules)
                {
                    await mod.GenerateInCtor(this, sb);
                }
                sb.AppendLine("CustomCtor();");
            }
            sb.AppendLine();
        }

        sb.AppendLine($"{BasicCtorPermission.ToStringFast_Enum_Only()} {Name}({Interface(getter: true)} rhs)");
        using (sb.CurlyBrace())
        {
            foreach (var field in IterateFields())
            {
                sb.AppendLine($"this.{field.Name} = {field.GenerateACopy("rhs." + field.Name)};");
            }
        }
        sb.AppendLine();

        sb.AppendLine("partial void CustomCtor();");
        sb.AppendLine();
    }
예제 #8
0
    protected virtual void FillPublicElement(ObjectGeneration obj, StructuredStringBuilder sb)
    {
        using (var args = new Function(sb,
                                       $"public static void FillPublicElement{ModuleNickname}"))
        {
            args.Add($"{obj.Interface(getter: false)} item");
            args.Add($"XElement {XElementLine.GetParameterName(obj, Context.Backend)}");
            args.Add("string name");
            args.Add($"ErrorMaskBuilder? errorMask");
            args.Add($"{nameof(TranslationCrystal)}? translationMask");
        }
        using (sb.CurlyBrace())
        {
            sb.AppendLine("switch (name)");
            using (sb.CurlyBrace())
            {
                foreach (var field in obj.IterateFields())
                {
                    if (field.Derivative)
                    {
                        continue;
                    }
                    if (field.ReadOnly)
                    {
                        continue;
                    }
                    if (!TryGetTypeGeneration(field.GetType(), out var generator))
                    {
                        throw new ArgumentException("Unsupported type generator: " + field);
                    }

                    sb.AppendLine($"case \"{field.Name}\":");
                    using (sb.IncreaseDepth())
                    {
                        if (generator.ShouldGenerateCopyIn(field))
                        {
                            List <string> conditions = new List <string>();
                            if (TranslationMaskParameter)
                            {
                                conditions.Add(field.GetTranslationIfAccessor("translationMask"));
                            }
                            if (conditions.Count > 0)
                            {
                                using (var args = sb.If(ands: true))
                                {
                                    foreach (var item in conditions)
                                    {
                                        args.Add(item);
                                    }
                                }
                            }
                            using (sb.CurlyBrace(doIt: conditions.Count > 0))
                            {
                                generator.GenerateCopyIn(
                                    sb: sb,
                                    objGen: obj,
                                    typeGen: field,
                                    nodeAccessor: XElementLine.GetParameterName(obj, Context.Backend).Result,
                                    itemAccessor: Accessor.FromType(field, "item"),
                                    translationMaskAccessor: "translationMask",
                                    errorMaskAccessor: $"errorMask");
                            }
                        }
                        sb.AppendLine("break;");
                    }
                }

                sb.AppendLine("default:");
                using (sb.IncreaseDepth())
                {
                    if (obj.HasLoquiBaseObject)
                    {
                        using (var args = sb.Call(
                                   $"{obj.BaseClass.CommonClassName(LoquiInterfaceType.ISetter)}.FillPublicElement{ModuleNickname}{obj.GetBaseMask_GenericTypes(MaskType.Error)}"))
                        {
                            args.Add("item: item");
                            args.Add($"{XElementLine.GetParameterName(obj, Context.Backend)}: {XElementLine.GetParameterName(obj, Context.Backend)}");
                            args.Add("name: name");
                            args.Add("errorMask: errorMask");
                            if (TranslationMaskParameter)
                            {
                                args.Add($"translationMask: translationMask");
                            }
                        }
                    }
                    sb.AppendLine("break;");
                }
            }
        }
        sb.AppendLine();
    }