Example #1
0
        public override VisitorEnterResult Visit(EquationSyntaxNode node)
        {
            var type = _solving.GetVariableType(node.Id);

            node.OutputType = _tiToLangTypeConverter.Convert(type);
            return(VisitorEnterResult.Continue);
        }
Example #2
0
        public bool Visit(EquationSyntaxNode node)
        {
            VisitChildren(node);
#if DEBUG
            Trace(node, $"{node.Id}:{node.OutputType} = {node.Expression.OrderNumber}");
#endif
            if (node.OutputTypeSpecified)
            {
                var type = node.OutputType.ConvertToTiType();
                if (!_ticTypeGraph.TrySetVarType(node.Id, type))
                {
                    throw ErrorFactory.VariableIsAlreadyDeclared(node.Id, node.Interval);
                }
            }

            _ticTypeGraph.SetDef(node.Id, node.Expression.OrderNumber);
            return(true);
        }
Example #3
0
 public IExpressionNode Visit(EquationSyntaxNode node)
 => ThrowNotAnExpression(node);
Example #4
0
        private static Equation BuildEquationAndPutItToVariables(
            EquationSyntaxNode equation,
            IFunctionDictionary functionsDictionary,
            VariableDictionary variables,
            TypeInferenceResults typeInferenceResults)
        {
            var expression = ExpressionBuilderVisitor.BuildExpression(
                node:       equation.Expression,
                functions:  functionsDictionary,
                outputType: equation.OutputType,
                variables:  variables,
                typeInferenceResults: typeInferenceResults,
                typesConverter: TicTypesConverter.Concrete);

            VariableSource outputVariableSource;

            if (equation.OutputTypeSpecified)
            {
                outputVariableSource = VariableSource.CreateWithStrictTypeLabel(
                    name: equation.Id,
                    type: equation.OutputType,
                    typeSpecificationIntervalOrNull: equation.TypeSpecificationOrNull.Interval,
                    attributes: equation.Attributes,
                    isOutput: true);
            }
            else
            {
                outputVariableSource = VariableSource.CreateWithoutStrictTypeLabel(
                    name: equation.Id,
                    type: equation.OutputType,
                    isOutput: true,
                    equation.Attributes);
            }

            var itVariable = variables.GetSuperAnonymousVariableOrNull();

            if (itVariable != null)
            {
                throw FunParseException.ErrorStubToDo("Variable cannot starts with it");
            }


            if (!variables.TryAdd(outputVariableSource))
            {
                //some equation referenced the source before
                var usages = variables.GetUsages(equation.Id);
                if (usages.Source.IsOutput)
                {
                    throw ErrorFactory.OutputNameWithDifferentCase(equation.Id, equation.Expression.Interval);
                }
                else
                {
                    throw ErrorFactory.CannotUseOutputValueBeforeItIsDeclared(usages);
                }
            }


            //ReplaceInputType
            if (outputVariableSource.Type != expression.Type)
            {
                throw new ImpossibleException("fitless");
            }
            return(new Equation(equation.Id, expression, outputVariableSource));
        }
Example #5
0
 public virtual VisitorEnterResult Visit(EquationSyntaxNode node) => DefaultVisitEnter(node);
Example #6
0
 public string Visit(EquationSyntaxNode node) => $"{node.Id} = ... ";
Example #7
0
 public virtual bool Visit(EquationSyntaxNode node) => true;