private bool TryGetDsInfo(CallNode callNode, TexlBinding binding, out IExternalDataSource dsInfo)
        {
            Contracts.AssertValueOrNull(callNode);
            Contracts.AssertValue(binding);

            dsInfo = null;
            if (callNode == null || !binding.IsDelegatable(callNode) || !binding.GetType(callNode).IsTable)
            {
                return(false);
            }

            var callInfo = binding.GetInfo(callNode);

            if (callInfo == null)
            {
                return(false);
            }

            var function = callInfo.Function;

            if (function == null)
            {
                return(false);
            }

            bool success = function.TryGetDataSource(callNode, binding, out var external);

            dsInfo = (IExternalDataSource)external;
            return(success);
        }
Exemple #2
0
        public override bool TryGetDelegationMetadata(CallNode node, TexlBinding binding, out IDelegationMetadata metadata)
        {
            Contracts.AssertValue(node);
            Contracts.AssertValue(binding);

            metadata = null;

            // Get metadata if it's an entity.
            IExpandInfo entityInfo;

            if (binding.TryGetEntityInfo(node.Args.Children[0], out entityInfo))
            {
                Contracts.AssertValue(entityInfo.ParentDataSource);
                Contracts.AssertValue(entityInfo.ParentDataSource.DataEntityMetadataProvider);

                var metadataProvider = entityInfo.ParentDataSource.DataEntityMetadataProvider;

                IDataEntityMetadata entityMetadata;
                if (!metadataProvider.TryGetEntityMetadata(entityInfo.Identity, out entityMetadata))
                {
                    return(false);
                }

                metadata = entityMetadata.DelegationMetadata.VerifyValue();
                return(true);
            }

            if (!TryGetValidDataSourceForDelegation(node, binding, FunctionDelegationCapability, out var ds))
            {
                return(false);
            }

            metadata = ds.DelegationMetadata;
            return(true);
        }
        private CallNode convertMember(CallNode parent, ParseNode m)
        {
            if (!m.Equals("<member>"))
            {
                return(null);
            }


            bool hasFunctionCall = m.Contains("<function_call>"),
                 hasMember       = m.Contains("<member>");

            CallNode output;

            if (hasFunctionCall)
            {
                output = createObjectFunctionCall(parent, m["<symbol>"], m["<function_call>"]);
            }
            else
            {
                output = createSymbolNode(parent, m["<symbol>"]);
            }

            if (hasMember)
            {
                output = convertMember(output, m["<member>"]);
            }

            return(output);
        }
Exemple #4
0
        public override bool UpdateDataQuerySelects(CallNode callNode, TexlBinding binding, DataSourceToQueryOptionsMap dataSourceToQueryOptionsMap)
        {
            Contracts.AssertValue(callNode);
            Contracts.AssertValue(binding);

            if (!CheckArgsCount(callNode, binding))
            {
                return(false);
            }

            TexlNode[] args = callNode.Args.Children.VerifyValue();

            DType dsType = binding.GetType(args[0]);

            if (dsType.AssociatedDataSources == null)
            {
                return(false);
            }

            var resultType = binding.GetType(callNode).VerifyValue();

            bool retval = false;

            foreach (var typedName in resultType.GetNames(DPath.Root))
            {
                DType  columnType = typedName.Type;
                string columnName = typedName.Name.Value;

                Contracts.Assert(dsType.Contains(new DName(columnName)));

                retval |= dsType.AssociateDataSourcesToSelect(dataSourceToQueryOptionsMap, columnName, columnType, true);
            }
            return(retval);
        }
Exemple #5
0
        public bool IsValidCallNode(CallNode node, TexlBinding binding, OperationCapabilityMetadata metadata)
        {
            Contracts.AssertValue(node);
            Contracts.AssertValue(binding);
            Contracts.AssertValue(metadata);

            if (!IsValidNode(node, binding))
            {
                SuggestDelegationHint(node, binding);
                return(false);
            }

            // If the node is not row scoped and it's valid then it can be delegated.
            var isRowScoped = binding.IsRowScope(node);

            if (!isRowScoped)
            {
                return(true);
            }

            CallInfo callInfo = binding.GetInfo(node);

            if (callInfo?.Function != null && ((TexlFunction)callInfo.Function).IsRowScopedServerDelegatable(node, binding, metadata))
            {
                return(true);
            }

            var telemetryMessage = string.Format("Kind:{0}, isRowScoped:{1}", node.Kind, isRowScoped);

            SuggestDelegationHintAndAddTelemetryMessage(node, binding, telemetryMessage);
            TrackingProvider.Instance.SetDelegationTrackerStatus(DelegationStatus.UndelegatableFunction, node, binding, _function, DelegationTelemetryInfo.CreateUndelegatableFunctionTelemetryInfo((TexlFunction)callInfo?.Function));
            return(false);
        }
Exemple #6
0
        private bool TryGetEntityInfo(CallNode callNode, TexlBinding binding, out IExpandInfo entityInfo)
        {
            Contracts.AssertValueOrNull(callNode);
            Contracts.AssertValue(binding);

            entityInfo = null;
            if (callNode == null || !binding.GetType(callNode).IsTable)
            {
                return(false);
            }

            var callInfo = binding.GetInfo(callNode);

            if (callInfo == null)
            {
                return(false);
            }

            var function = callInfo.Function;

            if (function == null)
            {
                return(false);
            }

            return(function.TryGetEntityInfo(callNode, binding, out entityInfo));
        }
Exemple #7
0
        private void InitImpl(CallNode node, VariableMap map)
        {
            Init(node, map);

            _willAlloc.CopyFrom(node.UsedArgs);
            _willSpill.Reset();
        }
Exemple #8
0
        private static IAnalysisSet FsBasename(FunctionValue func, Node node, AnalysisUnit unit, IAnalysisSet @this, IAnalysisSet[] args)
        {
            CallNode     call = (CallNode)node;
            IAnalysisSet res  = AnalysisSet.Empty;

            if (args.Length == 2)
            {
                foreach (var extArg in args[1])
                {
                    var strExt = extArg.Value.GetStringValue();
                    if (strExt != null)
                    {
                        foreach (var nameArg in args[0])
                        {
                            string name = nameArg.Value.GetStringValue();
                            if (name != null)
                            {
                                string oldName = name;
                                if (name.EndsWith(strExt, StringComparison.OrdinalIgnoreCase))
                                {
                                    name = name.Substring(0, name.Length - strExt.Length);
                                }
                                res = res.Union(unit.Analyzer.GetConstant(name).Proxy);
                            }
                        }
                    }
                }
            }
            if (res.Count == 0)
            {
                return(unit.Analyzer._emptyStringValue.SelfSet);
            }
            return(res);
        }
Exemple #9
0
        private static IAnalysisSet FsReadDirSync(FunctionValue func, Node node, AnalysisUnit unit, IAnalysisSet @this, IAnalysisSet[] args)
        {
            CallNode call = (CallNode)node;

            if (call.Arguments.Length == 1)
            {
                var                   ee = new ExpressionEvaluator(unit);
                IAnalysisSet          arraySet;
                ReadDirSyncArrayValue array;
                if (!unit.GetDeclaringModuleEnvironment().TryGetNodeValue(NodeEnvironmentKind.ArrayValue, call, out arraySet))
                {
                    array = new ReadDirSyncArrayValue(
                        unit.ProjectEntry,
                        node
                        );
                    arraySet = array.SelfSet;
                    unit.GetDeclaringModuleEnvironment().AddNodeValue(NodeEnvironmentKind.ArrayValue, call, arraySet);
                }
                else
                {
                    array = (ReadDirSyncArrayValue)arraySet.First().Value;
                }

                foreach (var path in ee.MergeStringLiterals(call.Arguments[0]))
                {
                    array.AddDirectoryMembers(unit, path);
                }

                return(array.SelfSet);
            }
            return(AnalysisSet.Empty);
        }
        static MethodDeclarationNode GenerateDestructor(ClassDeclarationNode classDeclarationNode) //Generates destruction method from variable list in class
        {
            foreach (MethodDeclarationNode method in classDeclarationNode.MethodDeclarations)      //check if method already given
            {
                if (method.isDestruction)
                {
                    return(method);
                }
            }
            MethodDeclarationNode destructor = new MethodDeclarationNode(true);

            foreach (VariableDeclarationNode declaration in classDeclarationNode.VariableDeclarations)  //for every variable collect a destruction function
            {
                CallNode call = new CallNode();
                call.SetCallerName(declaration.name);
                string className = declaration.expression.call.CalleeNames[0];
                foreach (ClassDeclarationNode classDeclaration in _rootNode.ClassDeclarations)
                {
                    if (classDeclaration.name == className)
                    {
                        call.AddCallee(GenerateDestructor(classDeclaration).name, new List <ExpressionNode>());
                    }
                }
                destructor.AddBodyNode(call);  //Add destruction call to method
            }
            return(destructor);
        }
Exemple #11
0
 public virtual void Visit(CallNode node)
 {
     if (node != null)
     {
          AcceptChildren(node);
     }
 }
Exemple #12
0
        public override string Visit(CallNode node)
        {
            var expr       = Visit(node.Expr);
            var parameters = string.Join(", ", node.Parameters.Select(Visit));

            return($"{expr}({parameters})");
        }
Exemple #13
0
        public override bool IsServerDelegatable(CallNode callNode, TexlBinding binding)
        {
            Contracts.AssertValue(callNode);
            Contracts.AssertValue(binding);

            IExternalDataSource dataSource = null;

            // Only delegate First, not last
            if (!_isFirst)
            {
                return(false);
            }

            // If has top capability (e.g. Dataverse)
            if (TryGetValidDataSourceForDelegation(callNode, binding, FunctionDelegationCapability, out dataSource))
            {
                return(true);
            }

            // If is a client-side pageable data source
            if (TryGetDataSource(callNode, binding, out dataSource) && dataSource.Kind == DataSourceKind.Connected && dataSource.IsPageable)
            {
                return(true);
            }

            if (dataSource != null && dataSource.IsDelegatable)
            {
                binding.ErrorContainer.EnsureError(DocumentErrorSeverity.Warning, callNode, TexlStrings.OpNotSupportedByServiceSuggestionMessage_OpNotSupportedByService, Name);
            }

            return(false);
        }
        public override string VisitFunctionCall(CallNode functionCall)
        {
            var procedureCall = functionCall;
            var param         = "";

            if (procedureCall.Parameters.Any())
            {
                foreach (var procedureCallParameter in procedureCall.Parameters)
                {
                    param += VisitNode(procedureCallParameter);
                    param += ",";
                }

                param = param.Remove(param.Length - 1);
            }
            //if (procedureCall.Name.ToUpper() == "WRITELN")
            //{
            //    var assembly = "using System;";
            //    if (_assembliesCalled.Contains(assembly) != true)
            //    {
            //        _assembliesCalled.Add(assembly);
            //    }

            //    return $"{AddSpaces()}Console.WriteLine({param});\r\n";
            //}

            return($"{AddSpaces()}{procedureCall.Name}({param})");
        }
Exemple #15
0
        internal CallNode CreateCall(Operand op, FunctionDeclaration fn)
        {
            var node = new CallNode(op, fn);

            AddNode(node);
            return(node);
        }
Exemple #16
0
        public static bool FindCurFuncAndArgs(TexlNode curNode, int cursorPos, TexlBinding binding, out TexlFunction curFunc, out int argIndex, out int argCount, out DType expectedType)
        {
            Contracts.AssertValue(curNode);
            Contracts.AssertValue(binding);

            if (curNode.Kind == NodeKind.Call)
            {
                CallNode callNode = curNode.CastCall();
                if (callNode.Token.Span.Lim <= cursorPos && callNode.ParenClose != null && cursorPos <= callNode.ParenClose.Span.Min)
                {
                    CallInfo info = binding.GetInfo(callNode);

                    if (info.Function != null)
                    {
                        curFunc      = info.Function;
                        argIndex     = 0;
                        argCount     = callNode.Args.Count;
                        expectedType = curFunc.ParamTypes.Length > 0 ? curFunc.ParamTypes[0] : DType.Error;

                        return(true);
                    }
                }
            }

            if (IntellisenseHelper.TryGetInnerMostFunction(curNode, binding, out curFunc, out argIndex, out argCount))
            {
                expectedType = curFunc.ParamTypes.Length > argIndex ? curFunc.ParamTypes[argIndex] : DType.Error;
                return(true);
            }

            expectedType = DType.Error;
            return(false);
        }
Exemple #17
0
        public override bool SupportsPaging(CallNode callNode, TexlBinding binding)
        {
            IList <FirstNameNode> dsNodes;

            if (!TryGetDataSourceNodes(callNode, binding, out dsNodes))
            {
                return(false);
            }

            var args  = callNode.Args.Children.VerifyValue();
            var count = args.Count();

            for (int i = 1; i < count;)
            {
                if (!binding.IsPageable(args[i]))
                {
                    return(false);
                }

                // If there are an odd number of args, the last arg also participates.
                i += 2;
                if (i == count)
                {
                    i--;
                }
            }

            return(true);
        }
        private bool TryGetDsNodes(CallNode callNode, TexlBinding binding, out IList <FirstNameNode> dsInfos)
        {
            Contracts.AssertValueOrNull(callNode);
            Contracts.AssertValue(binding);

            dsInfos = new List <FirstNameNode>();
            if (callNode == null || !(binding.GetType(callNode).IsAggregate))
            {
                return(false);
            }

            var callInfo = binding.GetInfo(callNode);

            if (callInfo == null)
            {
                return(false);
            }

            var function = callInfo.Function;

            if (function == null)
            {
                return(false);
            }

            return(function.TryGetDataSourceNodes(callNode, binding, out dsInfos));
        }
Exemple #19
0
 public CallArgumentNode(CallNode call, VariableData src, VariableData conv)
     : base(CodeNodeType.CallArgument)
 {
     Call   = call;
     Source = src;
     Conv   = conv;
 }
Exemple #20
0
 public void VisitCall(CallNode node)
 {
     UpdateLine(node);
     node.Proc.Accept(this);
     node.Arguments.ForEach(a => a.Accept(this));
     asm.Call((short)node.Arguments.Count);
 }
Exemple #21
0
        public override bool UpdateDataQuerySelects(CallNode callNode, TexlBinding binding, DataSourceToQueryOptionsMap dataSourceToQueryOptionsMap)
        {
            Contracts.AssertValue(callNode);
            Contracts.AssertValue(binding);

            // Ignore delegation warning
            if (!CheckArgsCount(callNode, binding, DocumentErrorSeverity.Moderate))
            {
                return(false);
            }

            TexlNode[] args = callNode.Args.Children.VerifyValue();

            DType dsType = binding.GetType(args[0]);

            if (dsType.AssociatedDataSources == null)
            {
                return(false);
            }

            DType      columnType = binding.GetType(args[1]);
            StrLitNode columnNode = args[1].AsStrLit();

            if (columnType.Kind != DKind.String || columnNode == null)
            {
                return(false);
            }
            string columnName = columnNode.Value;

            Contracts.Assert(dsType.Contains(new DName(columnName)));

            return(dsType.AssociateDataSourcesToSelect(dataSourceToQueryOptionsMap, columnName, columnType, true));
        }
Exemple #22
0
        // Typecheck an input for this function, and get the cursor type for an invocation with that input.
        // arg0 and arg0Type correspond to the input and its type.
        // The cursor type for aggregate functions is generally the type of a row in the input schema (table),
        // for example Table in an invocation Average(Table, valueFunction).
        // Returns true on success, false if the input or its type are invalid with respect to this function's declaration
        // (and populate the error container accordingly).
        public virtual bool CheckInput(TexlNode inputNode, DType inputSchema, IErrorContainer errors, out DType typeScope)
        {
            Contracts.AssertValue(inputNode);
            Contracts.Assert(inputSchema.IsValid);
            Contracts.AssertValue(errors);

            CallNode callNode = inputNode.Parent.CastList().Parent.CastCall();

            Contracts.AssertValue(callNode);

            typeScope = inputSchema;

            bool fArgsValid = true;

            if (_function.ParamTypes.Length == 0)
            {
                switch (typeScope.Kind)
                {
                case DKind.Record:
                    break;

                case DKind.Error:
                    fArgsValid = false;
                    errors.EnsureError(inputNode, TexlStrings.ErrBadType);
                    break;

                default:
                    fArgsValid = false;
                    errors.Error(callNode, TexlStrings.ErrBadType);
                    break;
                }
            }
            else if (_function.ParamTypes[0].IsTable)
            {
                if (!typeScope.IsTable)
                {
                    errors.Error(callNode, TexlStrings.ErrNeedTable_Func, _function.Name);
                    fArgsValid = false;
                }
                // This assumes that the lambdas operate on the individual records
                // of the table, not the entire table.
                bool fError = false;
                typeScope   = typeScope.ToRecord(ref fError);
                fArgsValid &= !fError;
            }
            else
            {
                Contracts.Assert(_function.ParamTypes[0].IsRecord);
                if (!typeScope.IsRecord)
                {
                    errors.Error(callNode, TexlStrings.ErrNeedRecord_Func, _function.Name);
                    bool fError = false;
                    typeScope  = typeScope.ToRecord(ref fError);
                    fArgsValid = false;
                }
            }

            return(fArgsValid);
        }
Exemple #23
0
        public override bool IsRowScopedServerDelegatable(CallNode callNode, TexlBinding binding, OperationCapabilityMetadata metadata)
        {
            Contracts.AssertValue(callNode);
            Contracts.AssertValue(binding);
            Contracts.AssertValue(metadata);

            return(base.IsRowScopedServerDelegatable(callNode, binding, metadata));
        }
Exemple #24
0
        public CallInfo(TexlFunction function, CallNode node)
        {
            Contracts.AssertValue(function);
            Contracts.AssertValue(node);

            Function = function;
            Node     = node;
        }
 public override void PostWalk(CallNode node)
 {
     base.PostWalk(node);
     if (!node.InBrackets)
     {
         HasSideEffects = true;
     }
 }
        public override bool IsServerDelegatable(CallNode callNode, TexlBinding binding)
        {
            Contracts.AssertValue(callNode);
            Contracts.AssertValue(binding);

            if (FunctionDelegationCapability.Capabilities == DelegationCapability.None)
            {
                return(false);
            }

            if (!CheckArgsCount(callNode, binding))
            {
                return(false);
            }

            IExternalDataSource dataSource;

            if (!TryGetValidDataSourceForDelegation(callNode, binding, FunctionDelegationCapability, out dataSource))
            {
                if (dataSource != null && dataSource.IsDelegatable)
                {
                    binding.ErrorContainer.EnsureError(DocumentErrorSeverity.Warning, callNode, TexlStrings.OpNotSupportedByServiceSuggestionMessage_OpNotSupportedByService, Name);
                }

                return(false);
            }

            var args = callNode.Args.Children.VerifyValue();

            if (binding.GetType(args[0]).HasExpandInfo ||
                (!binding.IsFullRecordRowScopeAccess(args[1]) && args[1].Kind != NodeKind.FirstName) ||
                !binding.IsRowScope(args[1]) ||
                binding.GetType(args[1]) != DType.Number ||
                ExpressionContainsView(callNode, binding))
            {
                SuggestDelegationHint(callNode, binding);

                if (binding.GetType(args[1]) != DType.Number)
                {
                    DelegationTrackerCore.SetDelegationTrackerStatus(DelegationStatus.NotANumberArgType, callNode, binding, this, DelegationTelemetryInfo.CreateEmptyDelegationTelemetryInfo());
                }
                else
                {
                    DelegationTrackerCore.SetDelegationTrackerStatus(DelegationStatus.InvalidArgType, callNode, binding, this, DelegationTelemetryInfo.CreateEmptyDelegationTelemetryInfo());
                }

                return(false);
            }

            if (binding.IsFullRecordRowScopeAccess(args[1]))
            {
                return(GetDottedNameNodeDelegationStrategy().IsValidDottedNameNode(args[1].AsDottedName(), binding, null, null));
            }

            var firstNameStrategy = GetFirstNameNodeDelegationStrategy().VerifyValue();

            return(firstNameStrategy.IsValidFirstNameNode(args[1].AsFirstName(), binding, null));
        }
        private SymbolNode createSymbolNode(CallNode parent, ParseNode s)
        {
            if (!s.Equals("<symbol>"))
            {
                return(null);
            }

            return(new SymbolNode(parent.type.VarNames[s.terminals], s.terminals));
        }
Exemple #28
0
            public override void Visit(CallNode node)
            {
                base.Visit(node);

                if (ShouldInsertModulePathArgument(node))
                {
                    insertionIndex = node.Arguments[0].Context.StartPosition;
                }
            }
        public IEnumerable <ASTNode> Transform(CallNode item)
        {
            yield return(item);

            foreach (var child in TransformAll(item.Contents))
            {
                yield return(child);
            }
        }
Exemple #30
0
 /// <summary>
 /// This method prints the callNode and make an indentation
 /// It accepts the ID number of the node and all the parameters of the call node
 /// Then outdent
 /// </summary>
 /// <param name="callNode">The node to print.</param>
 /// <returns>Returns null</returns>
 public override object Visit(CallNode callNode)
 {
     Print("CallNode");
     Indent++;
     callNode.Id.Accept(this);
     callNode.Parameters.ForEach(node => node.Accept(this));
     Indent--;
     return(null);
 }
Exemple #31
0
        // Gets the inner most function and the current arg index from the current node, if any.
        // If there is no inner most function, current arg index will be -1
        // and argument count will be -1.
        internal static bool TryGetInnerMostFunction(TexlNode nodeCur, TexlBinding bind, out TexlFunction funcCur, out int iarg, out int carg)
        {
            Contracts.AssertValue(nodeCur);
            Contracts.AssertValue(bind);

            TexlNode nodeParent  = nodeCur.Parent;
            TexlNode nodeCallArg = nodeCur;
            CallNode callNode    = null;

            while (nodeParent != null)
            {
                if (nodeParent.Kind == NodeKind.Call)
                {
                    callNode = nodeParent.AsCall();
                    break;
                }
                // The last node before a call's list node is the call arg.
                if (nodeParent.Kind != NodeKind.List)
                {
                    nodeCallArg = nodeParent;
                }

                nodeParent = nodeParent.Parent;
            }

            if (callNode == null)
            {
                iarg    = -1;
                carg    = -1;
                funcCur = null;
                return(false);
            }

            Contracts.AssertValue(nodeCallArg);

            CallInfo info = bind.GetInfo(callNode);

            if (info.Function != null)
            {
                carg = callNode.Args.Count;
                for (iarg = 0; iarg < carg; iarg++)
                {
                    if (callNode.Args.Children[iarg] == nodeCallArg)
                    {
                        break;
                    }
                }
                Contracts.Assert(iarg < carg);
                funcCur = (TexlFunction)info.Function;
                return(true);
            }

            iarg    = -1;
            carg    = -1;
            funcCur = null;
            return(false);
        }
Exemple #32
0
 public virtual bool Walk(CallNode node) { return true; }
Exemple #33
0
 public virtual void PostWalk(CallNode node) { }
        public virtual void Visit(CallNode node)
        {
            if (node != null)
            {
                if (node.Function != null)
                {
                    node.Function.Accept(this);
                }

                if (node.Arguments != null)
                {
                    node.Arguments.Accept(this);
                }
            }
        }