public override void EnterAmbiguousIdentifier(VBAParser.AmbiguousIdentifierContext context)
        {
            if (_skipIdentifiers || IsDeclarativeContext(context))
            {
                return;
            }

            var selection = context.GetSelection();

            if (IsAssignmentContext(context))
            {
                EnterIdentifier(context, selection, true);
            }
            else
            {
                EnterIdentifier(context, selection);
            }
        }
        private Declaration Resolve(VBAParser.ICS_S_MembersCallContext context, out VBAParser.AmbiguousIdentifierContext identifierContext, DeclarationType accessorType)
        {
            if (context == null)
            {
                identifierContext = null;
                return(null);
            }

            var members = context.iCS_S_MemberCall();

            for (var index = 0; index < members.Count; index++)
            {
                var member = members[index];
                if (index < members.Count - 1)
                {
                    var parent = Resolve(member.iCS_S_ProcedureOrArrayCall())
                                 ?? Resolve(member.iCS_S_VariableOrProcedureCall());

                    if (parent == null)
                    {
                        // return early if we can't resolve the whole member chain
                        identifierContext = null;
                        return(null);
                    }
                }
                else
                {
                    var result = Resolve(member.iCS_S_ProcedureOrArrayCall())
                                 ?? Resolve(member.iCS_S_VariableOrProcedureCall());

                    identifierContext = result == null
                        ? null
                        : result.Context == null
                            ? null
                            : ((dynamic)result.Context).ambiguousIdentifier();
                    return(result);
                }
            }

            identifierContext = null;
            return(null);
        }
        private Declaration Resolve(VBAParser.ICS_S_DictionaryCallContext context, out VBAParser.AmbiguousIdentifierContext identifierContext, DeclarationType accessorType, VBAParser.AmbiguousIdentifierContext parentIdentifier = null)
        {
            if (context == null)
            {
                identifierContext = null;
                return(null);
            }

            var identifier = EnterDictionaryCall(context.dictionaryCallStmt(), parentIdentifier, accessorType);
            var name       = identifier.GetText();

            var result = FindVariableDeclaration(name, identifier, accessorType);

            identifierContext = result == null
                ? null
                : result.Context == null
                    ? null
                    : ((dynamic)result.Context).ambiguousIdentifier();
            return(result);
        }
Пример #4
0
        private ProcedureNode(ParserRuleContext context, string scope, string localScope,
                              VBProcedureKind kind,
                              VBAParser.VisibilityContext visibility,
                              VBAParser.AmbiguousIdentifierContext name,
                              Func <VBAParser.AsTypeClauseContext> asType)
            : base(context, scope, localScope)
        {
            _kind              = kind;
            _name              = name.GetText();
            _accessibility     = visibility.GetAccessibility();
            _visibilityContext = visibility;

            if (asType != null)
            {
                var returnTypeClause = asType();
                _isImplicitReturnType = returnTypeClause == null;

                _returnType = returnTypeClause == null
                                ? Tokens.Variant
                                : returnTypeClause.type().GetText();
            }
        }
 private bool IsDeclarativeContext(VBAParser.AmbiguousIdentifierContext context)
 {
     return(IsDeclarativeParentContext(context.Parent));
 }
 private Declaration Resolve(VBAParser.ICS_S_DictionaryCallContext context, VBAParser.AmbiguousIdentifierContext parentIdentifier = null)
 {
     VBAParser.AmbiguousIdentifierContext discarded;
     return(Resolve(context, out discarded, DeclarationType.PropertyGet, parentIdentifier));
 }
        private Declaration Resolve(VBAParser.ICS_S_VariableOrProcedureCallContext context, out VBAParser.AmbiguousIdentifierContext identifierContext, DeclarationType accessorType)
        {
            if (context == null)
            {
                identifierContext = null;
                return(null);
            }

            var identifier = context.ambiguousIdentifier();
            var name       = identifier.GetText();

            var procedure = FindProcedureDeclaration(name, identifier, accessorType);
            var result    = procedure ?? FindVariableDeclaration(name, identifier, accessorType);

            identifierContext = result == null
                ? null
                : result.Context == null
                    ? null
                    : ((dynamic)result.Context).ambiguousIdentifier();
            return(result);
        }
        private VBAParser.AmbiguousIdentifierContext EnterDictionaryCall(VBAParser.DictionaryCallStmtContext dictionaryCall, VBAParser.AmbiguousIdentifierContext parentIdentifier = null, DeclarationType accessorType = DeclarationType.PropertyGet)
        {
            if (dictionaryCall == null)
            {
                return(null);
            }

            if (parentIdentifier != null)
            {
                var isTarget = accessorType == DeclarationType.PropertyLet || accessorType == DeclarationType.PropertySet;
                if (!EnterIdentifier(parentIdentifier, parentIdentifier.GetSelection(), isTarget, accessorType: accessorType))
                // we're referencing "member" in "member!field"
                {
                    return(null);
                }
            }

            var identifier = dictionaryCall.ambiguousIdentifier();

            if (_declarations.Items.Any(item => item.IdentifierName == identifier.GetText()))
            {
                return(identifier);
            }

            return(null);
        }