Esempio n. 1
0
        public static void UnpackEnumerable(BooCodeBuilder codeBuilder, Method method, Block block, Expression expression, DeclarationCollection declarations)
        {
            TypeSystemServices tss = codeBuilder.TypeSystemServices;

            InternalLocal local = codeBuilder.DeclareTempLocal(method,
                                                               tss.IEnumeratorType);

            IType expressionType = expression.ExpressionType;

            if (expressionType.IsSubclassOf(codeBuilder.TypeSystemServices.IEnumeratorType))
            {
                block.Add(
                    codeBuilder.CreateAssignment(
                        codeBuilder.CreateReference(local),
                        expression));
            }
            else
            {
                if (!expressionType.IsSubclassOf(codeBuilder.TypeSystemServices.IEnumerableType))
                {
                    expression = codeBuilder.CreateMethodInvocation(
                        RuntimeServices_GetEnumerable, expression);
                }

                block.Add(
                    codeBuilder.CreateAssignment(
                        block.LexicalInfo,
                        codeBuilder.CreateReference(local),
                        codeBuilder.CreateMethodInvocation(
                            expression, IEnumerable_GetEnumerator)));
            }

            for (int i = 0; i < declarations.Count; ++i)
            {
                Declaration declaration = declarations[i];

                block.Add(
                    codeBuilder.CreateAssignment(
                        codeBuilder.CreateReference(declaration.Entity),
                        codeBuilder.CreateMethodInvocation(RuntimeServices_MoveNext,
                                                           codeBuilder.CreateReference(local))));
            }
        }
Esempio n. 2
0
        Method CreateMethodAccessor(IMethod member)
        {
            BooCodeBuilder builder = _context.CodeBuilder;
            Method         method  = builder.CreateMethodFromPrototype(LexicalInfo.Empty, member, TypeMemberModifiers.None);

            method.Name = "___" + member.Name;
            MethodInvocationExpression mie = builder.CreateMethodInvocation(member);

            foreach (ParameterDeclaration p in method.Parameters)
            {
                mie.Arguments.Add(builder.CreateReference(p));
            }
            if (member.ReturnType == _context.TypeSystemServices.VoidType)
            {
                method.Body.Add(mie);
            }
            else
            {
                method.Body.Add(new ReturnStatement(mie));
            }
            return(method);
        }