Exemplo n.º 1
0
        private void CheckMultipleVariableExpression(MultipleVariableExpression e, TypeCheckingContext context)
        {
            List <Type> elementTypes = new List <Type>();

            int index = 0;

            foreach (string variable in e.Variables)
            {
                Type elementType = context.RightOperandType.GenericTypeArguments[index];
                elementTypes.Add(elementType);
                context.VariableContext.Set(variable, context.CreateAutoCreatedVariableValue(elementType));
                index++;

                if (index > context.RightOperandType.GenericTypeArguments.Length - 1)
                {
                    break;
                }
            }


            Type baseType = null;

            int elementCount = elementTypes.Count;

            if (elementCount == 1)
            {
                baseType = typeof(Tuple <>);
            }
            else if (elementCount == 2)
            {
                baseType = typeof(Tuple <,>);
            }
            else if (elementCount == 3)
            {
                baseType = typeof(Tuple <, ,>);
            }
            else if (elementCount == 4)
            {
                baseType = typeof(Tuple <, , ,>);
            }
            else if (elementCount == 5)
            {
                baseType = typeof(Tuple <, , , ,>);
            }
            else if (elementCount == 6)
            {
                baseType = typeof(Tuple <, , , , ,>);
            }

            e.Type = baseType.MakeGenericType(elementTypes.ToArray());
        }
Exemplo n.º 2
0
        private void CheckVariableContextExpression(VariableContextExpression e, TypeCheckingContext context)
        {
            foreach (VariableInfo variable in e.Variables)
            {
                context.VariableContext.Set(variable.Name, context.CreateAutoCreatedVariableValue(variable.Type));
            }


            PerformTypeChecking(e.Expression, context);

            foreach (VariableInfo variable in e.Variables)
            {
                context.VariableContext.Remove(variable.Name);
            }


            e.Type      = typeof(VariableContextExpression);
            e.Evaluator = new MathyExpressionEvaluator();
        }
Exemplo n.º 3
0
        private void CheckVariableExpression(VariableExpression e, TypeCheckingContext context)
        {
            LambdaVariable variable = context.LambdaContext.GetVariable(e.VariableName);

            if (variable != null)
            {
                e.Type = context.LambdaContext.GetVariable(variable.Name).Type;
            }
            else if (context.VariableContext.HasVariable(e.VariableName))
            {
                e.Type = context.VariableContext.GetType(e.VariableName);
            }
            else if (context.CreateVariableOnAssign && context.RightOperandType != null)
            {
                context.VariableContext.Set(e.VariableName, context.CreateAutoCreatedVariableValue(context.RightOperandType));
                e.Type = context.VariableContext.GetType(e.VariableName);
            }
            else
            {
                context.ErrorProvider.ThrowException(string.Format("{0} not defined.", e.VariableName), e);
            }
        }