コード例 #1
0
        private void CreateCheckBuffer()
        {
            var mathTypeExp = typeof(Math).ObtainCILibraryType <IClassType>((ICliManager)this._identityManager).GetTypeExpression();
            var maxMethod   = mathTypeExp.GetMethod("Max");

            var bufferCharArray = this.CharStream.Fields.Add(new TypedName("buffer", RuntimeCoreType.Char, this._identityManager));

            bufferCharArray.AccessLevel = AccessLevelModifiers.Private;
            var actualBufferLength = this.CharStream.Fields.Add(new TypedName("actualBufferLength", RuntimeCoreType.Int64, this._identityManager));

            actualBufferLength.AccessLevel = AccessLevelModifiers.Private;

            var checkBufferMethod = this.CharStream.Methods.Add(new TypedName("CheckBuffer", RuntimeCoreType.VoidType, this._identityManager), new TypedNameSeries(new TypedName("requiredLength", RuntimeCoreType.Int64, this._identityManager)));
            var cbRequiredLength  = checkBufferMethod.Parameters["requiredLength"];
            var charTypeRef       = bufferCharArray.FieldType;

            bufferCharArray.FieldType     = charTypeRef.MakeArray();
            bufferCharArray.SummaryText   = "Denotes the @s:Char; array which acts as a buffer to the file.";
            checkBufferMethod.SummaryText = string.Format("Checks the state of the internal @s:Char; @s:{0}; on whether it's at least as large as @p:{1};.", bufferCharArray.Name, cbRequiredLength.Name);
            cbRequiredLength.SummaryText  = string.Format("The @s:Int64; value which denotes how large the @s:{0}; needs to be in order to succeed.", bufferCharArray.Name);

            // if (this.buffer == null)
            var bufferNullCheck = checkBufferMethod.If(bufferCharArray.EqualTo(IntermediateGateway.NullValue));

            //     this.buffer = new char[Math.Max(requiredLength, 4096)];
            bufferNullCheck.Assign(bufferCharArray, new MalleableCreateArrayExpression(charTypeRef, maxMethod.Invoke(cbRequiredLength.GetReference(), 4096.ToPrimitive())));
            // else if (requiredLength >= this.buffer.LongLength)
            bufferNullCheck.CreateNext(cbRequiredLength.GreaterThanOrEqualTo(bufferCharArray.GetReference().GetProperty("LongLength")));

            // ... new char[...;
            var tempCreate = new MalleableCreateArrayDetailExpression(charTypeRef);

            // ... Math.Max(requiredLength, this.buffer.LongLength * 2)]
            tempCreate.Sizes.Add(maxMethod.Invoke(cbRequiredLength.GetReference(), bufferCharArray.GetReference().GetProperty("LongLength").Multiply(2)));

            //     char[] tempBuffer = new char[Math.Max(requiredLength, this.buffer.LongLength * 2)];
            var tempBuffer = bufferNullCheck.Next.Locals.Add(new TypedName("tempBuffer", bufferCharArray.FieldType), tempCreate);

            var arrayType = typeof(Array).ObtainCILibraryType <IClassType>(this._identityManager);
            //     Array.Copy(this.buffer, 0, tempBuffer, 0, this.actualBufferLength);
            var copy = arrayType.Methods.Values.First(k => k.Name == "Copy" && k.Parameters.Count == 5 && k.Parameters.Values.Last().ParameterType == cbRequiredLength.ParameterType);

            bufferNullCheck.Next.Call(copy.GetReference().Invoke(bufferCharArray.GetReference(), IntermediateGateway.NumberZero, tempBuffer.GetReference(), IntermediateGateway.NumberZero, actualBufferLength.GetReference()));
            // this.buffer = tempBuffer;
            bufferNullCheck.Next.Assign(bufferCharArray, tempBuffer);

            this.BufferArrayField         = bufferCharArray;
            this.ActualBufferLength       = actualBufferLength;
            checkBufferMethod.AccessLevel = AccessLevelModifiers.Private;
            this.CheckBufferImpl          = checkBufferMethod;
        }
コード例 #2
0
        private static IIntermediateClassMethodMember AddToStringMethod(IIntermediateClassType result, IIntermediateClassFieldMember charBufferSize, IIntermediateClassFieldMember charBuffer, IIntermediateCliManager identityManager)
        {
            /* *
             * Full method:
             * char[] result = new char[this.actualSize];
             * for (int i = 0; i < this.actualSize; i++)
             *     result[i] = buffer[i];
             * return new string(result);
             * */
            IIntermediateClassMethodMember toStringOverride = result.Methods.Add(new TypedName("ToString", identityManager.ObtainTypeReference(RuntimeCoreType.String)));

            toStringOverride.AccessLevel = AccessLevelModifiers.Public;
            toStringOverride.IsOverride  = true;
            //char[] result = new char[this.actualSize];
            var resultCharsInitExp = new MalleableCreateArrayDetailExpression(identityManager.ObtainTypeReference(RuntimeCoreType.Char));

            resultCharsInitExp.Sizes.Add(charBufferSize.GetReference());
            var resultChars = toStringOverride.Locals.Add(new TypedName("result", identityManager.ObtainTypeReference(RuntimeCoreType.Char).MakeArray()), resultCharsInitExp);

            var iLocal = toStringOverride.Locals.Add(new TypedName("i", identityManager.ObtainTypeReference(RuntimeCoreType.Int32)));

            //int i = 0;
            iLocal.InitializationExpression = IntermediateGateway.NumberZero;
            //So it isn't declared in the main body.
            iLocal.AutoDeclare = false;
            //i++

            var increment = iLocal.Increment();
            //for (int i = 0; i < this.actualSize; i++)

            var loop = toStringOverride.Iterate(iLocal.GetDeclarationStatement(), iLocal.LessThan(charBufferSize), new IStatementExpression[] { increment });

            //    result[i] = this.buffer[i];
            loop.Assign(resultChars.GetReference().GetIndexer(iLocal.GetReference()), charBuffer.GetReference().GetIndexer(iLocal.GetReference()));
            //return new string(result);
            toStringOverride.Return(identityManager.ObtainTypeReference(RuntimeCoreType.String).GetNewExpression(resultChars.GetReference()));
            return(toStringOverride);
        }