private SerializableDeclarationTree SerializableTree(Declaration declaration,
                                                             IDictionary <Declaration, List <Declaration> > declarationsByParent)
        {
            var serializableDeclaration = new SerializableDeclarationTree(declaration);
            var childTrees = ChildTrees(declaration, declarationsByParent);

            serializableDeclaration.AddChildTrees(childTrees);

            return(serializableDeclaration);
        }
Пример #2
0
        private IEnumerable <Declaration> UnwrapTree(SerializableDeclarationTree tree, Declaration parent = null)
        {
            var current = tree.Node.Unwrap(parent);

            yield return(current);

            foreach (var serializableDeclarationTree in tree.Children)
            {
                var unwrapped = UnwrapTree(serializableDeclarationTree, current);
                foreach (var declaration in unwrapped)
                {
                    yield return(declaration);
                }
            }
        }
Пример #3
0
        private void CreateMemberDeclarations(IEnumerable <ComMember> members, QualifiedModuleName moduleName, Declaration declaration,
                                              SerializableDeclarationTree moduleTree, ComMember defaultMember, bool eventHandlers = false)
        {
            foreach (var item in members.Where(m => !m.IsRestricted && !IgnoredInterfaceMembers.Contains(m.Name)))
            {
                var memberDeclaration = CreateMemberDeclaration(item, moduleName, declaration, eventHandlers);
                _declarations.Add(memberDeclaration);

                var memberTree = new SerializableDeclarationTree(memberDeclaration);
                moduleTree.AddChildTree(memberTree);

                var hasParams = memberDeclaration as IParameterizedDeclaration;
                if (hasParams != null)
                {
                    _declarations.AddRange(hasParams.Parameters);
                    memberTree.AddChildren(hasParams.Parameters);
                }
                var coClass = memberDeclaration as ClassModuleDeclaration;
                if (coClass != null && item == defaultMember)
                {
                    coClass.DefaultMember = memberDeclaration;
                }
            }
        }
Пример #4
0
        public List <Declaration> LoadDeclarationsFromLibrary()
        {
            ITypeLib typeLibrary;

            // Failure to load might mean that it's a "normal" VBProject that will get parsed by us anyway.
            LoadTypeLibEx(_path, REGKIND.REGKIND_NONE, out typeLibrary);
            if (typeLibrary == null)
            {
                return(_declarations);
            }

            var type = new ComProject(typeLibrary)
            {
                Path = _path
            };

            var projectName = new QualifiedModuleName(type.Name, _path, type.Name);
            var project     = new ProjectDeclaration(type, projectName);

            _serialized = new SerializableProject(project);
            _declarations.Add(project);

            foreach (var alias in type.Aliases.Select(item => new AliasDeclaration(item, project, projectName)))
            {
                _declarations.Add(alias);
                _serialized.AddDeclaration(new SerializableDeclarationTree(alias));
            }

            foreach (var module in type.Members)
            {
                var moduleName = new QualifiedModuleName(_referenceName, _path,
                                                         module.Type == DeclarationType.Enumeration || module.Type == DeclarationType.UserDefinedType
                        ? string.Format("_{0}", module.Name)
                        : module.Name);

                var declaration = CreateModuleDeclaration(module, moduleName, project, GetModuleAttributes(module));
                var moduleTree  = new SerializableDeclarationTree(declaration);
                _declarations.Add(declaration);
                _serialized.AddDeclaration(moduleTree);

                var membered = module as IComTypeWithMembers;
                if (membered != null)
                {
                    CreateMemberDeclarations(membered.Members, moduleName, declaration, moduleTree, membered.DefaultMember);
                    var coClass = membered as ComCoClass;
                    if (coClass != null)
                    {
                        CreateMemberDeclarations(coClass.SourceMembers, moduleName, declaration, moduleTree, coClass.DefaultMember, true);
                    }
                }

                var enumeration = module as ComEnumeration;
                if (enumeration != null)
                {
                    var enumDeclaration = new Declaration(enumeration, declaration, moduleName);
                    _declarations.Add(enumDeclaration);
                    var members = enumeration.Members.Select(e => new Declaration(e, enumDeclaration, moduleName)).ToList();
                    _declarations.AddRange(members);

                    var enumTree = new SerializableDeclarationTree(enumDeclaration);
                    moduleTree.AddChildTree(enumTree);
                    enumTree.AddChildren(members);
                }

                var structure = module as ComStruct;
                if (structure != null)
                {
                    var typeDeclaration = new Declaration(structure, declaration, moduleName);
                    _declarations.Add(typeDeclaration);
                    var members = structure.Fields.Select(f => new Declaration(f, typeDeclaration, moduleName)).ToList();
                    _declarations.AddRange(members);

                    var typeTree = new SerializableDeclarationTree(typeDeclaration);
                    moduleTree.AddChildTree(typeTree);
                    typeTree.AddChildren(members);
                }

                var fields = module as IComTypeWithFields;
                if (fields == null || !fields.Fields.Any())
                {
                    continue;
                }
                var declarations = fields.Fields.Select(f => new Declaration(f, declaration, projectName)).ToList();
                _declarations.AddRange(declarations);
                moduleTree.AddChildren(declarations);
            }
            _state.BuiltInDeclarationTrees.TryAdd(_serialized);
            return(_declarations);
        }
Пример #5
0
 public void AddChildTree(SerializableDeclarationTree tree)
 {
     _children.Add(tree);
 }
Пример #6
0
 public void AddDeclaration(SerializableDeclarationTree tree)
 {
     _declarations.Add(tree);
 }