コード例 #1
0
        private static ISignatureInfo ParseSignature(string functionName, ParseContext context)
        {
            var info = new SignatureInfo(functionName);
            var signatureArguments = new List <IArgumentInfo>();

            // RD data may contain function name(s) without braces
            if (context.Tokens.CurrentToken.TokenType == RTokenType.OpenBrace)
            {
                var functionCall = new FunctionCall();
                functionCall.Parse(context, context.AstRoot);

                foreach (var arg in functionCall.Arguments)
                {
                    string argName         = null;
                    string argDefaultValue = null;
                    var    isEllipsis      = false;

                    if (arg is ExpressionArgument expArg)
                    {
                        argName = context.TextProvider.GetText(expArg.ArgumentValue);
                    }
                    else
                    {
                        if (arg is NamedArgument nameArg)
                        {
                            argName         = context.TextProvider.GetText(nameArg.NameRange);
                            argDefaultValue = nameArg.DefaultValue != null?
                                              RdText.CleanRawRdText(context.TextProvider.GetText(nameArg.DefaultValue)) : string.Empty;
                        }
                        else if (arg is MissingArgument)
                        {
                            argName = string.Empty;
                        }
                        else if (arg is EllipsisArgument)
                        {
                            argName    = "...";
                            isEllipsis = true;
                        }
                    }

                    if (!string.IsNullOrEmpty(argName))
                    {
                        var argInfo = new ArgumentInfo(argName)
                        {
                            DefaultValue = argDefaultValue,
                            IsEllipsis   = isEllipsis,
                            IsOptional   = false
                        };
                        // TODO: actually parse
                        signatureArguments.Add(argInfo);
                    }
                }
            }

            info.Arguments = signatureArguments;
            return(info);
        }
コード例 #2
0
        internal static void OnMessageEvent(MessageEventArgs args)
        {
            if (args == null || args.data == null)
            {
                return;
            }
            _lastPayloadSize = (UInt32)args.data.Length;
            _frameCount      = 0;
            saveToFile.AddRange(args.data);
            try
            {
                using (MemoryStream ms = new MemoryStream(args.data))
                {
                    using (BinaryReader r = new BinaryReader(ms, Encoding.UTF8))
                    {
                        while (r.BaseStream.Position != r.BaseStream.Length)
                        {
                            var command = (Command)r.ReadUInt32();
                            switch (command)
                            {
                            case Command.kStartFunctionCall:
                                var thread   = ReadString(r);
                                var funcName = ReadString(r);
                                var funcCall = new FunctionCall(thread, funcName);
                                _functionCalls.Add(funcCall);
                                funcCall.Parse(r);

                                if (funcName == "xrBeginFrame")
                                {
                                    ++_frameCount;
                                }
                                break;

                            case Command.kCacheNotLargeEnough:
                                funcCall = new FunctionCall(r.ReadUInt32().ToString(), ReadString(r));
                                _functionCalls.Add(funcCall);
                                var result = ReadString(r);
                                funcCall.displayName += " = " + result + " (cache not large enough)";
                                break;

                            default:
                                throw new ArgumentOutOfRangeException();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            _doneCallback?.Invoke();
        }
コード例 #3
0
ファイル: ExpressionParser.cs プロジェクト: gbull122/vscode-r
        private OperationType HandleOpenBrace(ParseContext context, out ParseErrorType errorType)
        {
            var tokens = context.Tokens;

            errorType = ParseErrorType.None;

            // Separate expression from function call. In case of
            // function call previous token is either closing indexer
            // brace or closing function brace. Identifier with brace
            // is handled up above.
            // Indentifier followed by a brace needs to be analyzed
            // so we can tell between previous expression that ended
            // with identifier and identifier that is a function name:
            //
            //      a <- 2*b
            //      (expression)
            //
            // in this case b is not a function name. Similarly,
            //
            //      a <- 2*b[1]
            //      (expression)
            //
            // is not a function call operator over b[1].

            if (_operators.Count > 1 || _operands.Count > 0)
            {
                // We are not in the beginning of the expression
                if (tokens.PreviousToken.TokenType == RTokenType.CloseBrace ||
                    tokens.PreviousToken.TokenType == RTokenType.CloseSquareBracket ||
                    tokens.PreviousToken.TokenType == RTokenType.CloseDoubleSquareBracket ||
                    tokens.PreviousToken.IsVariableKind())
                {
                    var functionCall = new FunctionCall();
                    functionCall.Parse(context, null);

                    errorType = HandleOperatorPrecedence(context, functionCall);
                    return(OperationType.Function);
                }
            }

            var group = new Group();

            group.Parse(context, null);

            _operands.Push(group);
            return(OperationType.Operand);
        }
コード例 #4
0
ファイル: RdFunctionSignature.cs プロジェクト: nomada2/RTVS
        private static ISignatureInfo ParseSignature(string functionName, ParseContext context, IReadOnlyDictionary <string, string> argumentsDescriptions = null)
        {
            SignatureInfo        info = new SignatureInfo(functionName);
            List <IArgumentInfo> signatureArguments = new List <IArgumentInfo>();

            // RD data may contain function name(s) without braces
            if (context.Tokens.CurrentToken.TokenType == RTokenType.OpenBrace)
            {
                FunctionCall functionCall = new FunctionCall();
                functionCall.Parse(context, context.AstRoot);

                for (int i = 0; i < functionCall.Arguments.Count; i++)
                {
                    IAstNode arg = functionCall.Arguments[i];

                    string argName         = null;
                    string argDefaultValue = null;
                    bool   isEllipsis      = false;
                    bool   isOptional      = false;

                    ExpressionArgument expArg = arg as ExpressionArgument;
                    if (expArg != null)
                    {
                        argName = context.TextProvider.GetText(expArg.ArgumentValue);
                    }
                    else
                    {
                        NamedArgument nameArg = arg as NamedArgument;
                        if (nameArg != null)
                        {
                            argName         = context.TextProvider.GetText(nameArg.NameRange);
                            argDefaultValue = RdText.CleanRawRdText(context.TextProvider.GetText(nameArg.DefaultValue));
                        }
                        else
                        {
                            MissingArgument missingArg = arg as MissingArgument;
                            if (missingArg != null)
                            {
                                argName = string.Empty;
                            }
                            else
                            {
                                EllipsisArgument ellipsisArg = arg as EllipsisArgument;
                                if (ellipsisArg != null)
                                {
                                    argName    = "...";
                                    isEllipsis = true;
                                }
                            }
                        }
                    }

                    ArgumentInfo argInfo = new ArgumentInfo(argName);
                    argInfo.DefaultValue = argDefaultValue;
                    argInfo.IsEllipsis   = isEllipsis;
                    argInfo.IsOptional   = isOptional; // TODO: actually parse

                    if (argumentsDescriptions != null)
                    {
                        string description;
                        if (argumentsDescriptions.TryGetValue(argName, out description))
                        {
                            argInfo.Description = description;
                        }
                    }
                    signatureArguments.Add(argInfo);
                }
            }

            info.Arguments = signatureArguments;
            return(info);
        }