public override void GenerateCopyInRet(
            FileGeneration fg,
            ObjectGeneration objGen,
            TypeGeneration targetGen,
            TypeGeneration typeGen,
            Accessor readerAccessor,
            AsyncMode asyncMode,
            Accessor retAccessor,
            Accessor outItemAccessor,
            Accessor errorMaskAccessor,
            Accessor translationAccessor,
            Accessor converterAccessor,
            bool inline)
        {
            LoquiType loqui = typeGen as LoquiType;

            if (inline)
            {
                if (loqui.GenericDef != null)
                {
                    fg.AppendLine($"{retAccessor}{Loqui.Generation.Utility.Await(asyncMode)}LoquiBinary{(asyncMode == AsyncMode.Off ? null : "Async")}Translation<{loqui.ObjectTypeName}{loqui.GenericTypes(getter: false)}>.Instance.Parse");
                }
                else
                {
                    fg.AppendLine($"{retAccessor}{loqui.ObjectTypeName}{loqui.GenericTypes(getter: false)}.TryCreateFromBinary");
                }
            }
            else
            {
                fg.AppendLine($"var ret = {loqui.ObjectTypeName}{loqui.GenericTypes(getter: false)}.TryCreateFromBinary({readerAccessor}, out var tmp{outItemAccessor}, {converterAccessor});");
                fg.AppendLine($"{outItemAccessor} = tmp{outItemAccessor};");
                fg.AppendLine("return ret;");
            }
        }
Ejemplo n.º 2
0
        public override void GenerateCopyInRet(
            FileGeneration fg,
            ObjectGeneration objGen,
            TypeGeneration targetGen,
            TypeGeneration typeGen,
            Accessor readerAccessor,
            AsyncMode asyncMode,
            Accessor retAccessor,
            Accessor outItemAccessor,
            Accessor errorMaskAccessor,
            Accessor translationAccessor,
            Accessor converterAccessor,
            bool inline)
        {
            if (inline)
            {
                throw new NotImplementedException();
            }
            if (asyncMode == AsyncMode.Direct)
            {
                throw new NotImplementedException();
            }
            ZeroType zero = typeGen as ZeroType;

            fg.AppendLine($"{readerAccessor}.SetPosition({readerAccessor}.Position + {zero.Length});");
        }
 public override void GenerateCopyInRet(
     FileGeneration fg,
     ObjectGeneration objGen,
     TypeGeneration targetGen,
     TypeGeneration typeGen,
     Accessor nodeAccessor,
     AsyncMode asyncMode,
     Accessor retAccessor,
     Accessor outItemAccessor,
     Accessor errorMaskAccessor,
     Accessor translationMaskAccessor,
     Accessor converterAccessor,
     bool inline)
 {
     if (asyncMode != AsyncMode.Off)
     {
         throw new NotImplementedException();
     }
     if (inline)
     {
         fg.AppendLine($"transl: {this.GetTranslatorInstance(typeGen, getter: false)}.Parse");
     }
     else
     {
         if (typeGen.TryGetFieldData(out var data) &&
             data.RecordType.HasValue)
         {
             if (inline)
             {
                 throw new NotImplementedException();
             }
             fg.AppendLine("r.Position += Constants.SUBRECORD_LENGTH;");
         }
         using (var args = new ArgsWrapper(fg,
                                           $"{outItemAccessor} = {this.Namespace}{this.Typename(typeGen)}BinaryTranslation.Instance.Parse"))
         {
             args.Add(nodeAccessor.DirectAccess);
             if (this.DoErrorMasks)
             {
                 args.Add($"errorMask: {errorMaskAccessor}");
             }
             foreach (var writeParam in this.AdditionalCopyInRetParams)
             {
                 var get = writeParam(
                     objGen: objGen,
                     typeGen: typeGen);
                 if (get.Failed)
                 {
                     continue;
                 }
                 args.Add(get.Value);
             }
         }
         fg.AppendLine("return true;");
     }
 }
Ejemplo n.º 4
0
 public abstract void GenerateCopyInRet(
     FileGeneration fg,
     ObjectGeneration objGen,
     TypeGeneration targetGen,
     TypeGeneration typeGen,
     Accessor readerAccessor,
     AsyncMode asyncMode,
     Accessor retAccessor,
     Accessor outItemAccessor,
     Accessor errorMaskAccessor,
     Accessor translationAccessor,
     Accessor converterAccessor,
     bool inline);
Ejemplo n.º 5
0
    public static string ConfigAwait(AsyncMode mode)
    {
        switch (mode)
        {
        case AsyncMode.Off:
        case AsyncMode.Direct:
            return(ConfigAwait(false));

        case AsyncMode.Async:
            return(ConfigAwait(true));

        default:
            throw new NotImplementedException();
        }
    }
 public override void GenerateCopyInRet(
     FileGeneration fg,
     ObjectGeneration objGen,
     TypeGeneration targetGen,
     TypeGeneration typeGen,
     Accessor readerAccessor,
     AsyncMode asyncMode,
     Accessor retAccessor,
     Accessor outItemAccessor,
     Accessor errorMaskAccessor,
     Accessor translationAccessor,
     Accessor converterAccessor,
     bool inline)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 7
0
        public override void GenerateCopyInRet(
            FileGeneration fg,
            ObjectGeneration objGen,
            TypeGeneration targetGen,
            TypeGeneration typeGen,
            Accessor nodeAccessor,
            AsyncMode asyncMode,
            Accessor retAccessor,
            Accessor outItemAccessor,
            Accessor errorMaskAccessor,
            Accessor translationMaskAccessor,
            Accessor converterAccessor,
            bool inline)
        {
            if (inline)
            {
                fg.AppendLine($"transl: {this.GetTranslatorInstance(typeGen, getter: false)}.Parse");
                return;
            }
            if (asyncMode != AsyncMode.Off)
            {
                throw new NotImplementedException();
            }
            var stringType = typeGen as StringType;
            var data       = typeGen.GetFieldData();

            using (var args = new ArgsWrapper(fg,
                                              $"{retAccessor}{this.NamespacePrefix}StringBinaryTranslation.Instance.Parse"))
            {
                args.Add(nodeAccessor.Access);
                if (this.DoErrorMasks)
                {
                    args.Add($"errorMask: {errorMaskAccessor}");
                }
                args.Add($"item: out {outItemAccessor}");
                args.Add($"parseWhole: {(data.HasTrigger ? "true" : "false")}");
                if (data.Length.HasValue)
                {
                    args.Add($"length: {data.Length.Value}");
                }
                args.Add($"binaryType: {nameof(StringBinaryType)}.{stringType.BinaryType}");
                if (stringType.Translated.HasValue)
                {
                    args.Add($"source: {nameof(StringsSource)}.{stringType.Translated.Value}");
                }
            }
        }
        public override void GenerateCopyInRet(
            FileGeneration fg,
            ObjectGeneration objGen,
            TypeGeneration targetGen,
            TypeGeneration typeGen,
            Accessor nodeAccessor,
            AsyncMode asyncMode,
            Accessor retAccessor,
            Accessor outItemAccessor,
            Accessor errorMaskAccessor,
            Accessor translationAccessor,
            Accessor converterAccessor,
            bool inline)
        {
            if (inline)
            {
                fg.AppendLine($"transl: {this.GetTranslatorInstance(typeGen, getter: false)}.Parse");
                return;
            }
            var data = typeGen.CustomData[Constants.DataKey] as MutagenFieldData;

            using (var args = new ArgsWrapper(fg,
                                              $"{retAccessor}{Loqui.Generation.Utility.Await(asyncMode)}{this.Namespace}ByteArrayBinaryTranslation.Instance.Parse",
                                              suffixLine: Loqui.Generation.Utility.ConfigAwait(asyncMode)))
            {
                args.Add(nodeAccessor.Access);
                if (this.DoErrorMasks)
                {
                    args.Add($"errorMask: out {errorMaskAccessor}");
                }
                if (asyncMode == AsyncMode.Off)
                {
                    args.Add($"item: out {outItemAccessor}");
                }
                if (data.HasTrigger)
                {
                    args.Add($"length: subLength");
                }
                else
                {
                    args.Add($"length: {data.Length.Value}");
                }
            }
        }
Ejemplo n.º 9
0
        public void Arrange(out AsyncMode asyncMode, out Frame topFrame)
        {
            var compiled = compileFrames(_method.Frames);



            asyncMode = AsyncMode.AsyncTask;

            if (compiled.All(x => !x.IsAsync))
            {
                asyncMode = AsyncMode.None;
            }
            else if (compiled.Count(x => x.IsAsync) == 1 && compiled.Last().IsAsync&& compiled.Last().CanReturnTask())
            {
                asyncMode = compiled.Any(x => x.Wraps) ? AsyncMode.AsyncTask : AsyncMode.ReturnFromLastNode;
            }

            topFrame = chainFrames(compiled);
        }
Ejemplo n.º 10
0
        public override void GenerateCopyInRet(
            FileGeneration fg,
            ObjectGeneration objGen,
            TypeGeneration targetGen,
            TypeGeneration typeGen,
            Accessor nodeAccessor,
            AsyncMode asyncMode,
            Accessor retAccessor,
            Accessor outItemAccessor,
            Accessor errorMaskAccessor,
            Accessor translationMaskAccessor,
            Accessor converterAccessor,
            bool inline)
        {
            if (inline)
            {
                throw new NotImplementedException();
            }
            if (asyncMode != AsyncMode.Off)
            {
                throw new NotImplementedException();
            }
            var data = typeGen.GetFieldData();

            if (data.RecordType.HasValue)
            {
                fg.AppendLine("r.Position += Constants.SUBRECORD_LENGTH;");
            }
            using (var args = new ArgsWrapper(fg,
                                              $"{retAccessor}{this.NamespacePrefix}{this.Typename(typeGen)}BinaryTranslation.Instance.Parse"))
            {
                args.Add(nodeAccessor.Access);
                if (this.DoErrorMasks)
                {
                    args.Add($"errorMask: {errorMaskAccessor}");
                }
                args.Add($"translationMask: {translationMaskAccessor}");
            }
        }
        public override void GenerateCopyInRet(
            FileGeneration fg,
            ObjectGeneration objGen,
            TypeGeneration targetGen,
            TypeGeneration typeGen,
            Accessor nodeAccessor,
            AsyncMode asyncMode,
            Accessor retAccessor,
            Accessor outItemAccessor,
            Accessor errorMaskAccessor,
            Accessor translationAccessor,
            Accessor converterAccessor,
            bool inline)
        {
            if (inline)
            {
                throw new NotImplementedException();
            }
            var data = typeGen.CustomData[Constants.DataKey] as MutagenFieldData;

            using (var args = new ArgsWrapper(fg,
                                              $"{retAccessor}{Loqui.Generation.Utility.Await(asyncMode)}{this.NamespacePrefix}FilePathBinaryTranslation.Instance.Parse",
                                              suffixLine: Loqui.Generation.Utility.ConfigAwait(asyncMode)))
            {
                args.Add(nodeAccessor.Access);
                if (asyncMode == AsyncMode.Off)
                {
                    args.Add($"item: out {outItemAccessor}");
                }
                if (data.RecordType.HasValue)
                {
                    args.Add($"header: recordTypeConverter.Convert({objGen.RecordTypeHeaderName(data.RecordType.Value)})");
                }
                else
                {
                    args.Add($"length: {data.Length.Value}");
                }
            }
        }
Ejemplo n.º 12
0
        public override void GenerateCopyInRet(
            FileGeneration fg,
            ObjectGeneration objGen,
            TypeGeneration targetGen,
            TypeGeneration typeGen,
            Accessor nodeAccessor,
            AsyncMode asyncMode,
            Accessor retAccessor,
            Accessor outItemAccessor,
            Accessor errorMaskAccessor,
            Accessor translationAccessor,
            Accessor converterAccessor,
            bool inline)
        {
            var eType = typeGen as EnumType;

            if (inline)
            {
                throw new NotImplementedException();
            }
            else
            {
                using (var args = new ArgsWrapper(fg,
                                                  $"{retAccessor}{this.NamespacePrefix}{GetTranslatorInstance(typeGen, getter: true)}.Parse"))
                {
                    args.Add($"reader: {nodeAccessor}.SpawnWithLength({eType.ByteLength})");
                    if (asyncMode == AsyncMode.Off)
                    {
                        args.Add($"item: out {outItemAccessor}");
                    }
                    if (this.DoErrorMasks)
                    {
                        args.Add($"errorMask: {errorMaskAccessor}");
                    }
                }
            }
        }
Ejemplo n.º 13
0
 public FakeDbConnection(AsyncMode asyncMode, FakeDbDelays delays = null)
 {
     this.AsyncMode    = asyncMode;
     this.FakeDbDelays = delays ?? FakeDb.FakeDbDelays.DefaultDelaysNone;
 }
Ejemplo n.º 14
0
Archivo: XType.cs Proyecto: NeoTim/etch
 /// <summary>
 /// Sets the AysncMode
 /// </summary>
 /// <param name="mode"></param>
 public void SetAsyncMode(AsyncMode mode)
 {
     CheckNotLocked();
     asyncMode = mode;
 }
Ejemplo n.º 15
0
        public override void GenerateCopyInRet(
            FileGeneration fg,
            ObjectGeneration objGen,
            TypeGeneration targetGen,
            TypeGeneration typeGen,
            Accessor nodeAccessor,
            AsyncMode asyncMode,
            Accessor retAccessor,
            Accessor outItemAccessor,
            Accessor errorMaskAccessor,
            Accessor translationAccessor,
            Accessor converterAccessor,
            bool inline)
        {
            if (inline)
            {
                fg.AppendLine($"transl: {this.GetTranslatorInstance(typeGen, getter: false)}.Parse");
                return;
            }
            if (asyncMode != AsyncMode.Off)
            {
                throw new NotImplementedException();
            }
            FormLinkType linkType = typeGen as FormLinkType;

            if (typeGen.TryGetFieldData(out var data) &&
                data.RecordType.HasValue)
            {
                if (asyncMode == AsyncMode.Direct)
                {
                    throw new NotImplementedException();
                }
                fg.AppendLine("r.Position += Mutagen.Bethesda.Constants.SUBRECORD_LENGTH;");
            }
            switch (linkType.FormIDType)
            {
            case FormLinkType.FormIDTypeEnum.Normal:
                using (var args = new ArgsWrapper(fg,
                                                  $"{retAccessor}{this.Namespace}{this.Typename(typeGen)}BinaryTranslation.Instance.Parse"))
                {
                    args.Add(nodeAccessor.DirectAccess);
                    if (this.DoErrorMasks)
                    {
                        args.Add($"errorMask: {errorMaskAccessor}");
                    }
                    args.Add($"item: out {outItemAccessor.DirectAccess}");
                    foreach (var writeParam in this.AdditionalCopyInRetParams)
                    {
                        var get = writeParam(
                            objGen: objGen,
                            typeGen: typeGen);
                        if (get.Failed)
                        {
                            continue;
                        }
                        args.Add(get.Value);
                    }
                }
                break;

            case FormLinkType.FormIDTypeEnum.EDIDChars:
                fg.AppendLine($"{errorMaskAccessor} = null;");
                fg.AppendLine($"{outItemAccessor.DirectAccess} = new {linkType.TypeName(getter: false)}(HeaderTranslation.ReadNextRecordType(r.Reader));");
                fg.AppendLine($"return true;");
                break;

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 16
0
 public static Boolean AllowAsync(this AsyncMode value) => ((Int32)value & 2) == 2;
Ejemplo n.º 17
0
 ///<summary>Constructs a StubHelper which uses specified mode to
 ///dispatch method from message.</summary>
 ///<param name="mode">param mode</param>
 public StubHelper(AsyncMode mode)
 {
     this.mode = mode;
 }
Ejemplo n.º 18
0
 /// <summary>Not named <c>AllowSync</c> because it's too similar to <see cref="AllowAsync(AsyncMode)"/>.</summary>
 public static Boolean AllowOld(this AsyncMode value) => ((Int32)value & 1) == 1;
Ejemplo n.º 19
0
 public StubHelper(Delegate del, AsyncMode mode)
 {
     this.mode = mode;
     this.del  = del;
 }