예제 #1
0
        private static IIntermediateClassMethodMember AddPushMethod(IIntermediateClassType result, IIntermediateClassFieldMember charBufferSize, IIntermediateClassFieldMember charBuffer, IIntermediateClassMethodMember growBufferMethod, IIntermediateCliManager identityManager)
        {
            /* *
             * Full Method:
             * if (buffer == null)
             *     GrowBuffer(2);
             * else if (buffer.Length < actualSize + 1)
             *     GrowBuffer(actualSize + 1);
             * buffer[actualSize] = c;
             * actualSize++;
             * */
            IIntermediateClassMethodMember pushMethod = result.Methods.Add(new TypedName("Push", identityManager.ObtainTypeReference(RuntimeCoreType.VoidType)));

            pushMethod.AccessLevel = AccessLevelModifiers.Public;
            var cParameter = pushMethod.Parameters.Add(new TypedName("c", identityManager.ObtainTypeReference(RuntimeCoreType.Char)));
//          if (buffer == null)
            var nullCheck = pushMethod.If(charBuffer.EqualTo(IntermediateGateway.NullValue));

//              GrowBuffer(2);
            nullCheck.Call(growBufferMethod.GetReference().Invoke(2.ToPrimitive()));
//          else if (buffer.Length < actualSize + 1)
            nullCheck.CreateNext(charBuffer.GetReference().GetProperty("Length").LessThan(charBufferSize.GetReference().Add(1.ToPrimitive())));
            var rangeCheck = (IConditionBlockStatement)nullCheck.Next;

//              GrowBuffer(actualSize + 1);
            rangeCheck.Call(growBufferMethod.GetReference().Invoke(charBufferSize.GetReference().Add(1.ToPrimitive())));
//          buffer[actualSize++] = c;
            pushMethod.Assign(charBuffer.GetReference().GetIndexer(charBufferSize.Increment()), cParameter.GetReference());
            return(pushMethod);
        }
예제 #2
0
        private static IIntermediateClassMethodMember AddPushStringMethod(IIntermediateClassType result, IIntermediateClassFieldMember charBufferSize, IIntermediateClassFieldMember charBuffer, IIntermediateClassMethodMember growBufferMethod, IIntermediateCliManager identityManager)
        {
            /* *
             * Full Method:
             * if (buffer == null)
             *     GrowBuffer(s.Length);
             * else if (buffer.Length < actualSize + s.Length)
             *     GrowBuffer(actualSize + s.Length);
             * for (int i = 0; i < s.Length; i++)
             * {
             *     buffer[actualSize] = s[i];
             *     actualSize++;
             * }
             * */
            IIntermediateClassMethodMember pushStringMethod = result.Methods.Add(new TypedName("Push", identityManager.ObtainTypeReference(RuntimeCoreType.VoidType)));

            pushStringMethod.AccessLevel = AccessLevelModifiers.Public;
            var sParameter = pushStringMethod.Parameters.Add(new TypedName("s", identityManager.ObtainTypeReference(RuntimeCoreType.String)));
//          if (buffer == null)

            var nullCheck = pushStringMethod.If(charBuffer.GetReference().EqualTo(IntermediateGateway.NullValue));

//              GrowBuffer(s.Length);
            nullCheck.Call(growBufferMethod.GetReference().Invoke(sParameter.GetReference().GetProperty("Length")));
//          else if (buffer.Length < actualSize + s.Length)
            nullCheck.CreateNext(charBuffer.GetReference().GetProperty("Length").LessThan(charBufferSize.GetReference().Add(sParameter.GetReference().GetProperty("Length"))));
            var rangeCheck = (IConditionBlockStatement)nullCheck.Next;

//              GrowBuffer(actualSize + s.Length);
            rangeCheck.Call(growBufferMethod.GetReference().Invoke(charBufferSize.GetReference().Add(sParameter.GetReference().GetProperty("Length"))));

            //int i = 0;
            var iLocal = pushStringMethod.Locals.Add(new TypedName("i", identityManager.ObtainTypeReference(RuntimeCoreType.Int32)));

            //So it isn't declared in the main body.
            iLocal.InitializationExpression = IntermediateGateway.NumberZero;
            iLocal.AutoDeclare = false;
            //i++
//          for (int i = 0; i < s.Length; i++)
//          {
            var sToBufferIterate = pushStringMethod.Iterate(iLocal.GetDeclarationStatement(), iLocal.LessThan(sParameter.GetReference().GetProperty("Length")), new IStatementExpression[] { iLocal.Increment() });

            //var sToBufferIterate = pushStringMethod.Iterate(iLocal.GetDeclarationStatement(), IntermediateGateway.NumberZero, sParameter.GetReference().GetProperty("Length"));
//              buffer[actualSize++] = s[i];
            sToBufferIterate.Assign(charBuffer.GetReference().GetIndexer(charBufferSize.Increment()), sParameter.GetReference().GetIndexer(iLocal.GetReference()));
//          }
            return(pushStringMethod);
        }
예제 #3
0
        public override void ImplementMethodBodyPropertyGroup(
            VisitorImplementationVariationPropertyGroupContext groupContext,
            VisitorImplementationVariationContext context,
            VisitorImplementationVariationPropertiesContext visitorPropertiesContext,
            IInterfaceType visitorInterface,
            IInterfaceMethodMember interfaceMethod,
            IIntermediateClassMethodMember concreteVariant,
            IVisitorImplementationBuilder implementationBuilder)
        {
            switch (groupContext.GroupId)
            {
            case "IntermediateGenericParameter":
                concreteVariant.Literal(string.Format("#region {0}", groupContext.GroupId));
                base.ImplementMethodBodyPropertyGroup(groupContext, context, visitorPropertiesContext, visitorInterface, interfaceMethod, concreteVariant, implementationBuilder);
                concreteVariant.Literal(string.Format("#endregion //{0}", groupContext.GroupId));
                break;

            case "IntermediateInterface":
            case "IntermediateInstantiable":
                concreteVariant.Literal(string.Format("#region {0}", groupContext.GroupId));
                var target    = concreteVariant.If(implementationBuilder.ResultVisitorClass.GetThis().GetField("allowPartials"));
                var initParam = concreteVariant.Parameters.Values[0].GetReference();
                target.CreateNext(initParam.GetProperty("IsRoot"));
                var targetNext = target.Next;
                target = target.If(initParam.GetProperty("HasMembers"));
                var targetEnumerable          = target.Enumerate("member", initParam.GetProperty("Members").GetMethod("ExclusivelyOnParent").Invoke(initParam));
                var targetEnumerableNullCheck = targetEnumerable.If(targetEnumerable.Local.GetReference().GetProperty("Value").GetProperty("Entry").InequalTo(IntermediateGateway.NullValue, implementationBuilder.Context.ExpressionService));
                targetEnumerableNullCheck.Call(targetEnumerable.Local.GetReference().GetProperty("Value").GetProperty("Entry").GetMethod("Accept").Invoke(implementationBuilder.ResultVisitorClass.GetThis()));
                targetEnumerable          = targetNext.Enumerate("member", initParam.GetProperty("Members").GetProperty("Values"));
                targetEnumerableNullCheck = targetEnumerable.If(targetEnumerable.Local.GetReference().GetProperty("Entry").InequalTo(IntermediateGateway.NullValue, implementationBuilder.Context.ExpressionService));
                targetEnumerableNullCheck.Call(targetEnumerable.Local.GetReference().GetProperty("Entry").GetMethod("Accept").Invoke(implementationBuilder.ResultVisitorClass.GetThis()));
                concreteVariant.Literal(string.Format("#endregion //{0}", groupContext.GroupId));
                break;

            default:
                base.ImplementMethodBodyPropertyGroup(groupContext, context, visitorPropertiesContext, visitorInterface, interfaceMethod, concreteVariant, implementationBuilder);
                break;
            }
        }