private static Expression[] MakeArray(params object[] expressions)
        {
            LightList <Expression> seq = new LightList <Expression>();

            for (int i = 0; i < expressions.Length; i++)
            {
                object expression = expressions[i];

                if (expression == null)
                {
                    continue;
                }

                if (expression is Expression expr)
                {
                    seq.Add(expr);
                }
                else if (expression is IEnumerable <Expression> exprs)
                {
                    foreach (Expression ex in exprs)
                    {
                        seq.Add(ex);
                    }
                }
                else
                {
                    throw new ArgumentException();
                }
            }

            return(seq.ToArray());
        }
示例#2
0
        public BlockExpression PopBlock()
        {
            LightList <Expression> statements = statementStacks.Pop();

            Expression[] array = statements.ToArray();
            LightList <Expression> .Release(ref statements);

            return(Expression.Block(typeof(void), array));
        }
示例#3
0
        public BlockExpression Finalize(Type type)
        {
            LightList <Expression> statements = statementStacks.Pop();

            Expression[] array = statements.ToArray();
            LightList <Expression> .Release(ref statements);

            return(Expression.Block(type, variables, array));
        }
示例#4
0
        private bool ParseIfStatement(ref ASTNode node)
        {
            if (tokenStream.Current != ExpressionTokenType.If)
            {
                return(false);
            }

            LightList <ElseIfNode> statements = LightList <ElseIfNode> .Get();

            tokenStream.Advance();

            ASTNode condition = null;

            if (!ParseParenExpression(ref condition))
            {
                throw new ParseException("Expected a condition statement wrapped in parentheses but failed.");
            }

            BlockNode thenBlock = ParseBlock();

            if (thenBlock == null)
            {
                throw new ParseException("Expected a block statement following an if statement but failed to parse the block");
            }

            if (tokenStream.Current != ExpressionTokenType.ElseIf && tokenStream.Current != ExpressionTokenType.Else)
            {
                node = new IfStatementNode()
                {
                    // elseIfStatements = statements.ToArray(),
                    condition = condition,
                    thenBlock = thenBlock
                };
                return(true);
            }

            while (tokenStream.Current == ExpressionTokenType.ElseIf)
            {
                tokenStream.Advance();

                ASTNode elseIfCondition = null;

                if (!ParseParenExpression(ref elseIfCondition))
                {
                    throw new ParseException("Expected a condition statement wrapped in parentheses but failed.");
                }

                BlockNode block = ParseBlock();

                if (block == null)
                {
                    throw new ParseException("Expected a block statement following an if statement but failed to parse the block");
                }

                statements.Add(new ElseIfNode()
                {
                    condition = elseIfCondition,
                    thenBlock = block
                });
            }

            BlockNode elseBlock = null;

            if (tokenStream.Current == ExpressionTokenType.Else)
            {
                tokenStream.Advance();
                elseBlock = ParseBlock();

                if (elseBlock == null)
                {
                    throw new ParseException("Expected a block statement following an else statement but failed to parse the block");
                }
            }

            node = new IfStatementNode()
            {
                condition        = condition,
                thenBlock        = thenBlock,
                elseIfStatements = statements.size == 0 ? null : statements.ToArray(),
                elseBlock        = elseBlock
            };

            statements.Release();

            return(true);
        }
示例#5
0
        private UIStyleGroupContainer CompileStyleGroup(StyleRootNode styleRoot, AnimationData[] styleSheetAnimations, UISoundData[] uiSoundData)
        {
            UIStyleGroup defaultGroup = new UIStyleGroup();

            defaultGroup.normal = UIStyleRunCommand.CreateInstance();
            defaultGroup.name   = styleRoot.identifier ?? styleRoot.tagName;
            StyleType styleType = styleRoot.tagName != null ? StyleType.Implicit : StyleType.Shared;

            scratchGroupList.size = 0;

            scratchGroupList.Add(defaultGroup);

            CompileStyleGroups(styleRoot, styleType, scratchGroupList, defaultGroup, styleSheetAnimations, uiSoundData);

            return(new UIStyleGroupContainer(styleSheetImporter.NextStyleGroupId, defaultGroup.name, styleType, scratchGroupList.ToArray()));
        }