Inheritance: Rubberduck.Parsing.Symbols.Declaration
Esempio n. 1
0
 public void AddParameter(ParameterDeclaration parameter)
 {
     _parameters.Add(parameter);
 }
Esempio n. 2
0
        private static List <Declaration> AddSpecialFormDeclarations(Declaration parentProject, Declaration parentModule)
        {
            List <Declaration> declarations = new List <Declaration>();

            Debug.Assert(parentModule != null);
            var arrayFunction = new FunctionDeclaration(
                new QualifiedMemberName(parentModule.QualifiedName.QualifiedModuleName, "Array"),
                parentModule,
                parentModule,
                "Variant",
                null,
                null,
                Accessibility.Public,
                null,
                Selection.Home,
                false,
                true,
                null,
                new Attributes());
            var inputFunction   = new SubroutineDeclaration(new QualifiedMemberName(parentModule.QualifiedName.QualifiedModuleName, "Input"), parentModule, parentModule, "Variant", Accessibility.Public, null, Selection.Home, true, null, new Attributes());
            var numberParam     = new ParameterDeclaration(new QualifiedMemberName(parentModule.QualifiedName.QualifiedModuleName, "Number"), inputFunction, "Integer", null, null, false, false);
            var filenumberParam = new ParameterDeclaration(new QualifiedMemberName(parentModule.QualifiedName.QualifiedModuleName, "Filenumber"), inputFunction, "Integer", null, null, false, false);

            inputFunction.AddParameter(numberParam);
            inputFunction.AddParameter(filenumberParam);
            var inputBFunction   = new SubroutineDeclaration(new QualifiedMemberName(parentModule.QualifiedName.QualifiedModuleName, "InputB"), parentModule, parentModule, "Variant", Accessibility.Public, null, Selection.Home, true, null, new Attributes());
            var numberBParam     = new ParameterDeclaration(new QualifiedMemberName(parentModule.QualifiedName.QualifiedModuleName, "Number"), inputBFunction, "Integer", null, null, false, false);
            var filenumberBParam = new ParameterDeclaration(new QualifiedMemberName(parentModule.QualifiedName.QualifiedModuleName, "Filenumber"), inputBFunction, "Integer", null, null, false, false);

            inputBFunction.AddParameter(numberBParam);
            inputBFunction.AddParameter(filenumberBParam);
            var lboundFunction = new FunctionDeclaration(
                new QualifiedMemberName(parentModule.QualifiedName.QualifiedModuleName, "LBound"),
                parentModule,
                parentModule,
                "Long",
                null,
                null,
                Accessibility.Public,
                null,
                Selection.Home,
                false,
                true,
                null,
                new Attributes());
            var arrayNameParam = new ParameterDeclaration(new QualifiedMemberName(parentModule.QualifiedName.QualifiedModuleName, "Arrayname"), lboundFunction, "Integer", null, null, false, false);
            var dimensionParam = new ParameterDeclaration(new QualifiedMemberName(parentModule.QualifiedName.QualifiedModuleName, "Dimension"), lboundFunction, "Integer", null, null, true, false);

            lboundFunction.AddParameter(arrayNameParam);
            lboundFunction.AddParameter(dimensionParam);
            var uboundFunction = new FunctionDeclaration(
                new QualifiedMemberName(parentModule.QualifiedName.QualifiedModuleName, "UBound"),
                parentModule,
                parentModule,
                "Integer",
                null,
                null,
                Accessibility.Public,
                null,
                Selection.Home,
                false,
                true,
                null,
                new Attributes());
            var arrayParam = new ParameterDeclaration(new QualifiedMemberName(parentModule.QualifiedName.QualifiedModuleName, "Array"), uboundFunction, "Variant", null, null, false, false, true);
            var rankParam  = new ParameterDeclaration(new QualifiedMemberName(parentModule.QualifiedName.QualifiedModuleName, "Rank"), uboundFunction, "Integer", null, null, true, false);

            uboundFunction.AddParameter(arrayParam);
            uboundFunction.AddParameter(rankParam);
            declarations.Add(arrayFunction);
            declarations.Add(inputFunction);
            declarations.Add(inputBFunction);
            declarations.Add(lboundFunction);
            declarations.Add(uboundFunction);
            return(declarations);
        }
        private IReadOnlyList <Declaration> AddHiddenMSFormDeclarations(Declaration parentModule)
        {
            var userFormActivateEvent = new Declaration(
                new QualifiedMemberName(
                    new QualifiedModuleName("MSForms", "C:\\WINDOWS\\system32\\FM20.DLL", "FormEvents"), "Activate"),
                parentModule,
                "FM20.DLL;MSForms.FormEvents",
                string.Empty,
                string.Empty,
                false,
                false,
                Accessibility.Global,
                DeclarationType.Event,
                false,
                null);

            var userFormDeactivateEvent = new Declaration(
                new QualifiedMemberName(
                    new QualifiedModuleName("MSForms", "C:\\WINDOWS\\system32\\FM20.DLL", "FormEvents"), "Deactivate"),
                parentModule,
                "FM20.DLL;MSForms.FormEvents",
                string.Empty,
                string.Empty,
                false,
                false,
                Accessibility.Global,
                DeclarationType.Event,
                false,
                null);

            var userFormInitializeEvent = new Declaration(
                new QualifiedMemberName(
                    new QualifiedModuleName("MSForms", "C:\\WINDOWS\\system32\\FM20.DLL", "FormEvents"), "Initialize"),
                parentModule,
                "FM20.DLL;MSForms.FormEvents",
                string.Empty,
                string.Empty,
                false,
                false,
                Accessibility.Global,
                DeclarationType.Event,
                false,
                null);

            var userFormQueryCloseEvent = new Declaration(
                new QualifiedMemberName(
                    new QualifiedModuleName("MSForms", "C:\\WINDOWS\\system32\\FM20.DLL", "FormEvents"), "QueryClose"),
                parentModule,
                "FM20.DLL;MSForms.FormEvents",
                string.Empty,
                string.Empty,
                false,
                false,
                Accessibility.Global,
                DeclarationType.Event,
                false,
                null);

            var userFormQueryCloseEventCancelParameter = new ParameterDeclaration(
                new QualifiedMemberName(
                    new QualifiedModuleName("MSForms", "C:\\WINDOWS\\system32\\FM20.DLL", "FormEvents"), "Cancel"),
                userFormQueryCloseEvent,
                null,
                new Selection(),
                "Integer",
                null,
                string.Empty,
                false,
                true);

            var userFormQueryCloseEventCloseModeParameter = new ParameterDeclaration(
                new QualifiedMemberName(
                    new QualifiedModuleName("MSForms", "C:\\WINDOWS\\system32\\FM20.DLL", "FormEvents"), "CloseMode"),
                userFormQueryCloseEvent,
                null,
                new Selection(),
                "Integer",
                null,
                string.Empty,
                false,
                true);

            var userFormResizeEvent = new Declaration(
                new QualifiedMemberName(
                    new QualifiedModuleName("MSForms", "C:\\WINDOWS\\system32\\FM20.DLL", "FormEvents"), "Resize"),
                parentModule,
                "FM20.DLL;MSForms.FormEvents",
                string.Empty,
                string.Empty,
                false,
                false,
                Accessibility.Global,
                DeclarationType.Event,
                false,
                null);

            var userFormTerminateEvent = new Declaration(
                new QualifiedMemberName(
                    new QualifiedModuleName("MSForms", "C:\\WINDOWS\\system32\\FM20.DLL", "FormEvents"), "Terminate"),
                parentModule,
                "FM20.DLL;MSForms.FormEvents",
                string.Empty,
                string.Empty,
                false,
                false,
                Accessibility.Global,
                DeclarationType.Event,
                false,
                null);

            return(new List <Declaration>
            {
                userFormActivateEvent,
                userFormDeactivateEvent,
                userFormInitializeEvent,
                userFormQueryCloseEvent,
                userFormQueryCloseEventCancelParameter,
                userFormQueryCloseEventCloseModeParameter,
                userFormResizeEvent,
                userFormTerminateEvent
            });
        }
        private Declaration CreateDeclaration(
            string identifierName,
            string asTypeName,
            Accessibility accessibility,
            DeclarationType declarationType,
            ParserRuleContext context,
            Selection selection,
            bool isArray,
            VBAParser.AsTypeClauseContext asTypeContext,
            string typeHint,
            bool selfAssigned = false,
            bool withEvents   = false)
        {
            Declaration result;

            if (declarationType == DeclarationType.Parameter)
            {
                var argContext = (VBAParser.ArgContext)context;
                var isOptional = argContext.OPTIONAL() != null;

                var isByRef      = argContext.BYREF() != null;
                var isParamArray = argContext.PARAMARRAY() != null;
                result = new ParameterDeclaration(
                    new QualifiedMemberName(_qualifiedName, identifierName),
                    _parentDeclaration,
                    context,
                    selection,
                    asTypeName,
                    asTypeContext,
                    typeHint,
                    isOptional,
                    isByRef,
                    isArray,
                    isParamArray);
                if (_parentDeclaration is IDeclarationWithParameter)
                {
                    ((IDeclarationWithParameter)_parentDeclaration).AddParameter(result);
                }
            }
            else
            {
                var        key        = Tuple.Create(identifierName, declarationType);
                Attributes attributes = null;
                if (_attributes.ContainsKey(key))
                {
                    attributes = _attributes[key];
                }

                var annotations = FindAnnotations(selection.StartLine);
                if (declarationType == DeclarationType.Procedure)
                {
                    result = new SubroutineDeclaration(new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, _currentScopeDeclaration, asTypeName, accessibility, context, selection, false, annotations, attributes);
                }
                else if (declarationType == DeclarationType.Function)
                {
                    result = new FunctionDeclaration(
                        new QualifiedMemberName(_qualifiedName, identifierName),
                        _parentDeclaration,
                        _currentScopeDeclaration,
                        asTypeName,
                        asTypeContext,
                        typeHint,
                        accessibility,
                        context,
                        selection,
                        isArray,
                        false,
                        annotations,
                        attributes);
                }
                else if (declarationType == DeclarationType.LibraryProcedure || declarationType == DeclarationType.LibraryFunction)
                {
                    result = new ExternalProcedureDeclaration(new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, _currentScopeDeclaration, declarationType, asTypeName, asTypeContext, accessibility, context, selection, false, annotations);
                }
                else if (declarationType == DeclarationType.PropertyGet)
                {
                    result = new PropertyGetDeclaration(
                        new QualifiedMemberName(_qualifiedName, identifierName),
                        _parentDeclaration,
                        _currentScopeDeclaration,
                        asTypeName,
                        asTypeContext,
                        typeHint,
                        accessibility,
                        context,
                        selection,
                        isArray,
                        false,
                        annotations,
                        attributes);
                }
                else if (declarationType == DeclarationType.PropertySet)
                {
                    result = new PropertySetDeclaration(new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, _currentScopeDeclaration, asTypeName, accessibility, context, selection, false, annotations, attributes);
                }
                else if (declarationType == DeclarationType.PropertyLet)
                {
                    result = new PropertyLetDeclaration(new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, _currentScopeDeclaration, asTypeName, accessibility, context, selection, false, annotations, attributes);
                }
                else
                {
                    result = new Declaration(
                        new QualifiedMemberName(_qualifiedName, identifierName),
                        _parentDeclaration,
                        _currentScopeDeclaration,
                        asTypeName,
                        typeHint,
                        selfAssigned,
                        withEvents,
                        accessibility,
                        declarationType,
                        context,
                        selection,
                        isArray,
                        asTypeContext,
                        false,
                        annotations,
                        attributes);
                }
                if (_parentDeclaration.DeclarationType == DeclarationType.ClassModule && result is ICanBeDefaultMember && ((ICanBeDefaultMember)result).IsDefaultMember)
                {
                    ((ClassModuleDeclaration)_parentDeclaration).DefaultMember = result;
                }
            }
            return(result);
        }
        private Declaration CreateDeclaration(string identifierName, string asTypeName, Accessibility accessibility, DeclarationType declarationType, ParserRuleContext context, Selection selection, bool selfAssigned = false, bool withEvents = false)
        {
            Declaration result;
            if (declarationType == DeclarationType.Parameter)
            {
                var argContext = (VBAParser.ArgContext)context;
                var isOptional = argContext.OPTIONAL() != null;
                var isByRef = argContext.BYREF() != null;
                var isParamArray = argContext.PARAMARRAY() != null;
                var isArray = argContext.LPAREN() != null;
                result = new ParameterDeclaration(new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, context, selection, asTypeName, isOptional, isByRef, isArray, isParamArray);
            }
            else
            {
                var key = Tuple.Create(identifierName, declarationType);
                Attributes attributes = null;
                if (_attributes.ContainsKey(key))
                {
                    attributes = _attributes[key];
                }

                var annotations = FindAnnotations(selection.StartLine);
                result = new Declaration(new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, _currentScopeDeclaration, asTypeName, selfAssigned, withEvents, accessibility, declarationType, context, selection, false, annotations, attributes);
            }

            OnNewDeclaration(result);
            return result;
        }