Example #1
0
        /// <summary>
        ///     Performs "Function" specific operations.
        /// </summary>
        /// <param name="node">The "Function" node.</param>
        /// <param name="foundedMethod">The founded .NET method.</param>
        private void Visit(RawFunctionNode node, out MethodInfo foundedMethod)
        {
            var argTypes         = node.Descendants.Select(f => f.ReturnType).ToArray();
            var registeredMethod = _metadatas.GetMethod(node.Name, argTypes);

            foundedMethod = registeredMethod;
            var occurenceAmount = _functionOccurences[node.GeneralFunctionIdentifier()];
            var occurenceOrder  = _functionOccurences[node.SpecificFunctionIdentifier()] - 1;

            Instructions.Add(new CallExternal(_callMethodContext, registeredMethod, argTypes.Length, _partOfDate, occurenceAmount, occurenceOrder));
        }
Example #2
0
        private RdlSyntaxNode ComposeBaseTypes()
        {
            switch (Current.TokenType)
            {
            case StatementType.Numeric:
                var token = ConsumeAndGetToken(StatementType.Numeric);
                return(new NumericNode(token, InferMinimalNumericType(token)));

            case StatementType.Word:
                return(new WordNode(ConsumeAndGetToken(StatementType.Word)));

            case StatementType.Var:
                return(new VarNode(ConsumeAndGetToken(StatementType.Var) as VarToken));

            case StatementType.Case:
                return(new CaseNode(ConsumeAndGetToken(), ComposeWhenThenNodes(),
                                    ComposeAndSkip(f => ComposeElseNode(), StatementType.CaseEnd)));

            case StatementType.Function:

                if (!(Current is FunctionToken func))
                {
                    throw new ArgumentNullException();
                }

                Consume(StatementType.Function);

                var args      = ComposeArgs();
                var argsTypes = args.Descendants.Select(f => f.ReturnType).ToArray();

                if (_resolver.TryResolveMethod(func.Value, argsTypes, out var registeredMethod))
                {
                    var function = new RawFunctionNode(func, args, registeredMethod.ReturnType, !_resolver.CanBeCached(registeredMethod));
                    var detailedIdentifierHash = function.DetailedFunctionIdentifier();
                    var generalIdentifierHash  = function.GeneralFunctionIdentifier();
                    var specificIdentifierHash = function.SpecificFunctionIdentifier();

                    if (!FunctionCallOccurence.ContainsKey(detailedIdentifierHash))
                    {
                        FunctionCallOccurence.Add(detailedIdentifierHash, 1);
                    }
                    else
                    {
                        FunctionCallOccurence[detailedIdentifierHash] += 1;
                    }

                    if (!FunctionCallOccurence.ContainsKey(generalIdentifierHash))
                    {
                        FunctionCallOccurence.Add(generalIdentifierHash, 1);
                    }
                    else
                    {
                        FunctionCallOccurence[generalIdentifierHash] += 1;
                    }

                    if (!FunctionCallOccurence.ContainsKey(specificIdentifierHash))
                    {
                        FunctionCallOccurence.Add(specificIdentifierHash, FunctionCallOccurence[generalIdentifierHash]);
                    }
                    else
                    {
                        FunctionCallOccurence[specificIdentifierHash] = FunctionCallOccurence[generalIdentifierHash];
                    }

                    return(function);
                }
                throw new MethodNotFoundedException();

            case StatementType.LeftParenthesis:
                return(SkipComposeSkip(StatementType.LeftParenthesis, f => f.ComposeWhere(),
                                       StatementType.RightParenthesis));
            }
            throw new NotSupportedException();
        }