Пример #1
0
        private CodeExpression GenerateValueExpressionShift(ExpressionNode node, ref CodeTypeReference exprType)
        {
            bool isLeft = false;

            switch (node.Token.TokenType)
            {
            case TokenType.OpShiftLeft:
                isLeft = true;
                break;

            case TokenType.OpShiftRight:
                isLeft = false;
                break;

            default:
                ThrowInvalidEnumValue(node.Token.TokenType);
                return(null);
            }

            CodeTypeReference leftType  = null;
            CodeTypeReference rightType = null;
            CodeExpression    expr      = new CodeShiftExpression(this._lang, isLeft, GenerateValueExpressionImpl(node.LeftNode, ref leftType), GenerateValueExpressionImpl(node.RightNode, ref rightType));

            exprType = leftType;
            return(expr);
        }
Пример #2
0
        private void IterateExprImpl(CodeExpression expr, List <object> list)
        {
            ThrowIfNull(list);
            if (expr == null)
            {
                return;
            }

            list.Add(expr);
            CodePrimitiveExpression primExpr = expr as CodePrimitiveExpression;

            if (primExpr != null)
            {
                list.Add(primExpr.Value);
                return;
            }

            CodeFieldReferenceExpression fieldRef = expr as CodeFieldReferenceExpression;

            if (fieldRef != null)
            {
                IterateExprImpl(fieldRef.TargetObject, list);
                return;
            }

            CodeTypeReferenceExpression typeRefExpr = expr as CodeTypeReferenceExpression;

            if (typeRefExpr != null)
            {
                IterateTypeRefImpl(typeRefExpr.Type, list);
                return;
            }

            CodeBinaryOperatorExpression binExpr = expr as CodeBinaryOperatorExpression;

            if (binExpr != null)
            {
                IterateExprImpl(binExpr.Left, list);
                IterateExprImpl(binExpr.Right, list);
                return;
            }

            CodePropertySetValueReferenceExpression propSetExpr = expr as CodePropertySetValueReferenceExpression;

            if (propSetExpr != null)
            {
                return;
            }

            CodeThisReferenceExpression thisExpr = expr as CodeThisReferenceExpression;

            if (thisExpr != null)
            {
                return;
            }

            CodeMethodInvokeExpression methodInvokeExpr = expr as CodeMethodInvokeExpression;

            if (methodInvokeExpr != null)
            {
                foreach (CodeExpression arg in methodInvokeExpr.Parameters)
                {
                    IterateExprImpl(arg, list);
                }
                IterateExprImpl(methodInvokeExpr.Method, list);
                return;
            }

            CodeMethodReferenceExpression methodRefExpr = expr as CodeMethodReferenceExpression;

            if (methodRefExpr != null)
            {
                IterateExprImpl(methodRefExpr.TargetObject, list);
                return;
            }

            CodeObjectCreateExpression createExpr = expr as CodeObjectCreateExpression;

            if (createExpr != null)
            {
                IterateTypeRefImpl(createExpr.CreateType, list);
                return;
            }

            CodeVariableReferenceExpression varRefExpr = expr as CodeVariableReferenceExpression;

            if (varRefExpr != null)
            {
                return;
            }

            CodeArrayCreateExpression createArrayExpr = expr as CodeArrayCreateExpression;

            if (createArrayExpr != null)
            {
                IterateTypeRefImpl(createArrayExpr.CreateType, list);
                return;
            }

            CodeCastExpression castExpr = expr as CodeCastExpression;

            if (castExpr != null)
            {
                IterateTypeRefImpl(castExpr.TargetType, list);
                IterateExprImpl(castExpr.Expression, list);
                return;
            }

            CodeNotExpression notExpr = expr as CodeNotExpression;

            if (notExpr != null)
            {
                IterateExprImpl(notExpr.Expression, list);
                return;
            }

            CodeNegativeExpression negativeExpr = expr as CodeNegativeExpression;

            if (negativeExpr != null)
            {
                IterateExprImpl(negativeExpr.Expression, list);
                return;
            }

            CodeShiftExpression shiftExpr = expr as CodeShiftExpression;

            if (shiftExpr != null)
            {
                IterateExprImpl(shiftExpr.Left, list);
                IterateExprImpl(shiftExpr.Right, list);
                return;
            }

            CodeDirectionalSymbolExpression directionalExpr = expr as CodeDirectionalSymbolExpression;

            if (directionalExpr != null)
            {
                IterateExprImpl(directionalExpr.Expression, list);
                return;
            }

            throw new NotImplementedException("Unrecognized expression");
        }