Beispiel #1
0
            public override void EnterInvocationCall(IsblParser.InvocationCallContext context)
            {
                var callMethod = context.GetChild <IsblParser.IdentifierContext>(0);

                if (callMethod == null)
                {
                    return;
                }

                var invokeStatement = context.Parent as IsblParser.InvokeStatementContext;

                if (invokeStatement == null)
                {
                    return;
                }

                var callMethodName = callMethod.GetText();
                var isOpenMethod   = complementMethodNames
                                     .Any(m => m.Key.Equals(callMethodName, StringComparison.OrdinalIgnoreCase));
                var isCloseMethod = complementMethodNames
                                    .Any(m => m.Value.Equals(callMethodName, StringComparison.OrdinalIgnoreCase));

                if (!isOpenMethod && !isCloseMethod)
                {
                    return;
                }

                var invokerName = invokeStatement.children
                                  .TakeWhile(ctx => ctx != context)
                                  .Select(ctx => ctx.GetText())
                                  .Aggregate((accumulate, text) => accumulate + text);

                // Удаляем последнюю точку.
                invokerName = invokerName.Remove(invokerName.Length - 1, 1);

                if (isOpenMethod)
                {
                    var isCachedReference = this.cachedReferenceVariableNames.Contains(invokerName);
                    if (!isCachedReference || !callMethodName.Equals("Open", StringComparison.OrdinalIgnoreCase))
                    {
                        var objectStateDefinition = new ObjectStateDefinition
                        {
                            CallMethodName   = callMethodName,
                            InvokerName      = invokerName,
                            StatementContext = invokeStatement
                        };
                        this.NotRestoredObjectDefinitions.Add(objectStateDefinition);
                    }
                }
                else
                {
                    var openMethodName = complementMethodNames
                                         .First(m => m.Value.Equals(callMethodName, StringComparison.OrdinalIgnoreCase))
                                         .Key;

                    var objectStateDefinitions = this.NotRestoredObjectDefinitions
                                                 .Where(d => d.CallMethodName.Equals(openMethodName, StringComparison.OrdinalIgnoreCase) &&
                                                        d.InvokerName.Equals(invokerName, StringComparison.OrdinalIgnoreCase))
                                                 .ToList();
                    foreach (var objectStateDefinition in objectStateDefinitions)
                    {
                        this.NotRestoredObjectDefinitions.Remove(objectStateDefinition);
                    }
                }
            }
Beispiel #2
0
            /// <summary>
            /// Вход в COM вызов.
            /// </summary>
            /// <param name="context">Контекст.</param>
            public override void EnterInvocationCall(IsblParser.InvocationCallContext context)
            {
                var callMethod = context.GetChild <IsblParser.IdentifierContext>(0);

                if (callMethod == null)
                {
                    return;
                }

                var callMethodName = callMethod.GetText();
                var isOpenMethod   = callMethods
                                     .Any(m => m.Key.Equals(callMethodName, StringComparison.OrdinalIgnoreCase));
                var isCloseMethod = callMethods
                                    .Any(m => m.Value.Equals(callMethodName, StringComparison.OrdinalIgnoreCase));

                if (isOpenMethod)
                {
                    var operand = context.Parent as IsblParser.OperandContext;
                    if (operand == null)
                    {
                        return;
                    }

                    var invokerName = operand.children
                                      .TakeWhile(ctx => ctx != context)
                                      .Select(ctx => ctx.GetText())
                                      .Aggregate((accumulate, text) => accumulate + text);
                    // Удаляем последнюю точку.
                    invokerName = invokerName.Remove(invokerName.Length - 1, 1);

                    var assingStatement = GetParentAssignStatementContext(context);
                    if (assingStatement == null)
                    {
                        return;
                    }

                    var identifierState = assingStatement.GetChild <IsblParser.VariableContext>(0);
                    if (identifierState == null)
                    {
                        return;
                    }

                    var identifierStateName = identifierState.GetText();

                    var objectStateDefinition = new ObjectStateDefinition
                    {
                        CallMethodName      = callMethodName,
                        InvokerName         = invokerName,
                        IdentifierStateName = identifierStateName,
                        StatementContext    = assingStatement
                    };
                    this.NotRestoredObjectDefinitions.Add(objectStateDefinition);
                }
                else if (isCloseMethod)
                {
                    var invokeStatement = context.Parent as IsblParser.InvokeStatementContext;
                    if (invokeStatement == null)
                    {
                        return;
                    }

                    var invokerName = invokeStatement.children
                                      .TakeWhile(ctx => ctx != context)
                                      .Select(ctx => ctx.GetText())
                                      .Aggregate((accumulate, text) => accumulate + text);
                    // Удаляем последнюю точку.
                    invokerName = invokerName.Remove(invokerName.Length - 1, 1);

                    var openMethodName = callMethods
                                         .First(m => m.Value.Equals(callMethodName, StringComparison.OrdinalIgnoreCase))
                                         .Key;

                    var parameterList = context.GetChild <IsblParser.ParameterListContext>(0);
                    if (parameterList == null)
                    {
                        return;
                    }

                    var identifierState = parameterList.GetChild <IsblParser.ExpressionContext>(0);
                    if (identifierState == null)
                    {
                        return;
                    }

                    var identifierStateName = identifierState.GetText();

                    var objectStateDefinitions = this.NotRestoredObjectDefinitions
                                                 .Where(d => d.CallMethodName.Equals(openMethodName, StringComparison.OrdinalIgnoreCase) &&
                                                        d.InvokerName.Equals(invokerName, StringComparison.OrdinalIgnoreCase) &&
                                                        d.IdentifierStateName.Equals(identifierStateName, StringComparison.OrdinalIgnoreCase))
                                                 .ToList();
                    foreach (var objectStateDefinition in objectStateDefinitions)
                    {
                        this.NotRestoredObjectDefinitions.Remove(objectStateDefinition);
                    }
                }
            }