예제 #1
0
        /// <summary>
        /// Called by derived class when a file has been parsed.  The caller should
        /// provide the LibraryTask received from the OnNewFile call and an IScopeNode
        /// which represents the contents of the library.
        ///
        /// It is safe to call this method from any thread.
        /// </summary>
        protected void FileParsed(LibraryTask task, IScopeNode scope)
        {
            LibraryNode module = new LibraryNode(
                System.IO.Path.GetFileName(task.FileName),
                LibraryNode.LibraryNodeType.PhysicalContainer
                );

            // TODO: Creating the module tree should be done lazily as needed
            // Currently we replace the entire tree and rely upon the libraries
            // update count to invalidate the whole thing.  We could do this
            // finer grained and only update the changed nodes.  But then we
            // need to make sure we're not mutating lists which are handed out.
            CreateModuleTree(module, module, scope, "", task.ModuleID);

            if (null != task.ModuleID)
            {
                LibraryNode previousItem = null;
                lock (_files) {
                    if (_files.TryGetValue(task.ModuleID, out previousItem))
                    {
                        _files.Remove(task.ModuleID);
                    }
                }
                _library.RemoveNode(previousItem);
            }
            _library.AddNode(module);
            if (null != task.ModuleID)
            {
                lock (_files) {
                    _files.Add(task.ModuleID, module);
                }
            }
        }
예제 #2
0
        private void CreateModuleTree(LibraryNode root, LibraryNode current, IScopeNode scope, string namePrefix, ModuleId moduleId)
        {
            if ((null == root) || (null == scope) || (null == scope.NestedScopes))
            {
                return;
            }
            foreach (IScopeNode subItem in scope.NestedScopes)
            {
                LibraryNode newNode       = CreateLibraryNode(subItem, namePrefix, moduleId.Hierarchy, moduleId.ItemID);
                string      newNamePrefix = namePrefix;

                // The classes are always added to the root node, the functions to the
                // current node.

                if ((newNode.NodeType & LibraryNodeType.Classes) != LibraryNodeType.None)
                {
                    // Classes are always added to the root.
                    root.AddNode(newNode);
                    newNamePrefix = namePrefix + newNode.Name + ".";
                }
                else
                {
                    current.AddNode(newNode);
                }

                // Now use recursion to get the other types.
                CreateModuleTree(root, newNode, subItem, newNamePrefix, moduleId);
            }
        }
예제 #3
0
파일: IfCastNode.cs 프로젝트: zenuas/Roku
 public IfCastNode(VariableNode name, ITypeNode declare, IEvaluableNode cond, IScopeNode then)
 {
     Name      = name;
     Declare   = declare;
     Condition = cond;
     Then      = then;
 }
예제 #4
0
        protected CommonLibraryNode(LibraryNode parent, IScopeNode scope, string namePrefix, IVsHierarchy hierarchy, uint itemId) :
            base(parent, GetLibraryNodeName(scope, namePrefix), namePrefix + scope.Name, scope.NodeType)
        {
            _ownerHierarchy = hierarchy;
            _fileId         = itemId;

            // Now check if we have all the information to navigate to the source location.
            if ((null != _ownerHierarchy) && (VSConstants.VSITEMID_NIL != _fileId))
            {
                if ((SourceLocation.Invalid != scope.Start) && (SourceLocation.Invalid != scope.End))
                {
                    _sourceSpan             = new TextSpan();
                    _sourceSpan.iStartIndex = scope.Start.Column - 1;
                    if (scope.Start.Line > 0)
                    {
                        _sourceSpan.iStartLine = scope.Start.Line - 1;
                    }
                    _sourceSpan.iEndIndex = scope.End.Column;
                    if (scope.End.Line > 0)
                    {
                        _sourceSpan.iEndLine = scope.End.Line - 1;
                    }
                    CanGoToSource = true;
                }
            }
            _scope = scope;
        }
예제 #5
0
 protected CommonLibraryNode(CommonLibraryNode node, string newFullName) :
     base(node, newFullName)
 {
     _scope          = node._scope;
     _fileId         = node._fileId;
     _ownerHierarchy = node._ownerHierarchy;
     _fileMoniker    = node._fileMoniker;
     _sourceSpan     = node._sourceSpan;
 }
예제 #6
0
        /// <summary>
        /// Called by derived class when a file has been parsed.  The caller should
        /// provide the LibraryTask received from the OnNewFile call and an IScopeNode
        /// which represents the contents of the library.
        ///
        /// It is safe to call this method from any thread.
        /// </summary>
        protected void FileParsed(LibraryTask task, IScopeNode scope)
        {
            try
            {
                var project = task.ModuleID.Hierarchy.GetProject().GetCommonProject();

                HierarchyNode fileNode = fileNode = project.NodeFromItemId(task.ModuleID.ItemID);
                HierarchyInfo parent;
                if (fileNode == null || !this._hierarchies.TryGetValue(task.ModuleID.Hierarchy, out parent))
                {
                    return;
                }

                var module = CreateFileLibraryNode(
                    parent.ProjectLibraryNode,
                    fileNode,
                    System.IO.Path.GetFileName(task.FileName),
                    task.FileName,
                    LibraryNodeType.Package | LibraryNodeType.Classes
                    );

                // TODO: Creating the module tree should be done lazily as needed
                // Currently we replace the entire tree and rely upon the libraries
                // update count to invalidate the whole thing.  We could do this
                // finer grained and only update the changed nodes.  But then we
                // need to make sure we're not mutating lists which are handed out.

                CreateModuleTree(module, scope, task.FileName + ":", task.ModuleID);
                if (null != task.ModuleID)
                {
                    LibraryNode previousItem = null;
                    lock (this._files)
                    {
                        if (this._files.TryGetValue(task.ModuleID, out previousItem))
                        {
                            this._files.Remove(task.ModuleID);
                            parent.ProjectLibraryNode.RemoveNode(previousItem);
                        }
                    }
                }
                parent.ProjectLibraryNode.AddNode(module);
                this._library.Update();
                if (null != task.ModuleID)
                {
                    lock (this._files)
                    {
                        this._files.Add(task.ModuleID, module);
                    }
                }
            }
            catch (COMException)
            {
                // we're shutting down and can't get the project
            }
        }
        protected CommonLibraryNode(LibraryNode parent, IScopeNode scope, string namePrefix, IVsHierarchy hierarchy, uint itemId) :
            base(parent, GetLibraryNodeName(scope, namePrefix), namePrefix + scope.Name, scope.NodeType) {
            _ownerHierarchy = hierarchy;
            _fileId = itemId;

            // Now check if we have all the information to navigate to the source location.
            if ((null != _ownerHierarchy) && (VSConstants.VSITEMID_NIL != _fileId)) {
                if ((SourceLocation.Invalid != scope.Start) && (SourceLocation.Invalid != scope.End)) {
                    _sourceSpan = new TextSpan();
                    _sourceSpan.iStartIndex = scope.Start.Column - 1;
                    if (scope.Start.Line > 0) {
                        _sourceSpan.iStartLine = scope.Start.Line - 1;
                    }
                    _sourceSpan.iEndIndex = scope.End.Column;
                    if (scope.End.Line > 0) {
                        _sourceSpan.iEndLine = scope.End.Line - 1;
                    }
                    CanGoToSource = true;
                }
            }
            _scope = scope;
        }
예제 #8
0
        private void CreateModuleTree(LibraryNode current, IScopeNode scope, string namePrefix, ModuleId moduleId)
        {
            if ((null == scope) || (null == scope.NestedScopes))
            {
                return;
            }

            foreach (IScopeNode subItem in scope.NestedScopes)
            {
                LibraryNode newNode       = CreateLibraryNode(current, subItem, namePrefix, moduleId.Hierarchy, moduleId.ItemID);
                string      newNamePrefix = namePrefix;

                current.AddNode(newNode);
                if ((newNode.NodeType & LibraryNodeType.Classes) != LibraryNodeType.None)
                {
                    newNamePrefix = namePrefix + newNode.Name + ".";
                }

                // Now use recursion to get the other types.
                CreateModuleTree(newNode, subItem, newNamePrefix, moduleId);
            }
        }
예제 #9
0
파일: Definition.cs 프로젝트: zenuas/Roku
        public static void FunctionDefinition(INamespaceBody ns, IScopeNode scope)
        {
            if (scope.Statements.Count > 0)
            {
                var body = MakeFunction(ns, "main");
                body.SpecializationMapper[new GenericsMapper()] = new TypeMapper();
                FunctionBodyDefinition(body, scope.Statements);
            }

            scope.Functions.Each(f =>
            {
                var body  = MakeFunction(ns, f.Name.Name);
                var types = new Dictionary <string, TypeGenericsParameter>();
                ITypeDefinition create_type(ITypeNode s) => types.ContainsKey(s.Name) ? types[s.Name] : CreateType(body, s).Return(x => { if (x is TypeGenericsParameter g)
                                                                                                                                          {
                                                                                                                                              body.Generics.Add(types[g.Name] = g);
                                                                                                                                          }
                                                                                                                                   });

                f.Arguments.Each(x =>
                {
                    var name = new VariableValue(x.Name.Name);
                    body.Arguments.Add((name, create_type(x.Type)));
                    body.LexicalScope.Add(x.Name.Name, name);
                });
                if (f.Return is { })
                {
                    body.Return = create_type(f.Return);
                }

                if (body.Generics.Count == 0)
                {
                    body.SpecializationMapper[new GenericsMapper()] = new TypeMapper();
                }
                FunctionBodyDefinition(body, f.Statements);
            });
예제 #10
0
 protected abstract LibraryNode CreateLibraryNode(IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy, uint itemid);
예제 #11
0
 protected override LibraryNode CreateLibraryNode(LibraryNode parent, IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy, uint itemid)
 {
     return(new NodeLibraryNode(parent, subItem, namePrefix, hierarchy, itemid));
 }
예제 #12
0
        /// <summary>
        /// Called by derived class when a file has been parsed.  The caller should
        /// provide the LibraryTask received from the OnNewFile call and an IScopeNode
        /// which represents the contents of the library.
        /// 
        /// It is safe to call this method from any thread.
        /// </summary>
        protected void FileParsed(LibraryTask task, IScopeNode scope) {
            try {
                var project = task.ModuleID.Hierarchy.GetProject().GetCommonProject();

                HierarchyNode fileNode = fileNode = project.NodeFromItemId(task.ModuleID.ItemID);
                HierarchyInfo parent;
                if (fileNode == null || !_hierarchies.TryGetValue(task.ModuleID.Hierarchy, out parent)) {
                    return;
                }

                LibraryNode module = CreateFileLibraryNode(
                    parent.ProjectLibraryNode,
                    fileNode,
                    System.IO.Path.GetFileName(task.FileName),
                    task.FileName,
                    LibraryNodeType.Classes
                );

                // TODO: Creating the module tree should be done lazily as needed
                // Currently we replace the entire tree and rely upon the libraries
                // update count to invalidate the whole thing.  We could do this
                // finer grained and only update the changed nodes.  But then we
                // need to make sure we're not mutating lists which are handed out.

                CreateModuleTree(module, scope, task.FileName + ":", task.ModuleID);
                if (null != task.ModuleID) {
                    LibraryNode previousItem = null;
                    lock (_files) {
                        if (_files.TryGetValue(task.ModuleID, out previousItem)) {
                            _files.Remove(task.ModuleID);
                            parent.ProjectLibraryNode.RemoveNode(previousItem);
                        }
                    }
                }
                parent.ProjectLibraryNode.AddNode(module);
                _library.Update();
                if (null != task.ModuleID) {
                    lock (_files) {
                        _files.Add(task.ModuleID, module);
                    }
                }
            } catch (COMException) {
                // we're shutting down and can't get the project
            }
        }
예제 #13
0
 private static string GetLibraryNodeName(IScopeNode node, string namePrefix)
 {
     namePrefix = namePrefix.Substring(namePrefix.LastIndexOf(':') + 1); // remove filename prefix
     return(node.NodeType == LibraryNodeType.Members ? node.Name : string.Format(CultureInfo.InvariantCulture, "{0}{1}", namePrefix, node.Name));
 }
 private static string GetLibraryNodeName(IScopeNode node, string namePrefix)
 {
     return(node.IsFunction ? node.Name : string.Format(CultureInfo.InvariantCulture, "{0}{1}", namePrefix, node.Name));
 }
예제 #15
0
파일: Parser.1.cs 프로젝트: zenuas/Roku
 public static IfNode CreateIfNode(IEvaluableNode cond, IScopeNode then) => new IfNode(cond, then).R(cond);
예제 #16
0
 public IfNode(IEvaluableNode cond, IScopeNode then)
 {
     Condition = cond;
     Then      = then;
 }
예제 #17
0
 private static LibraryNodeType GetLibraryNodeTypeFromScope(IScopeNode scope)
 {
     return scope.IsFunction ? LibraryNodeType.Members : LibraryNodeType.Classes;
 }
예제 #18
0
 public PythonLibraryNode(IScopeNode scope, string namePrefix, IVsHierarchy hierarchy, uint itemId)
     : base(scope, namePrefix, hierarchy, itemId)
 {
 }
예제 #19
0
 private static string GetLibraryNodeName(IScopeNode node, string namePrefix)
 {
     return node.IsFunction ? node.Name : string.Format(CultureInfo.InvariantCulture, "{0}{1}", namePrefix, node.Name);
 }
예제 #20
0
 protected override LibraryNode CreateLibraryNode(IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy, uint itemid)
 {
     return(new PythonLibraryNode(subItem, namePrefix, hierarchy, itemid));
 }
 public NodeLibraryNode(LibraryNode parent, IScopeNode scope, string namePrefix, IVsHierarchy hierarchy, uint itemId) :
     base(parent, scope, namePrefix, hierarchy, itemId) {
 }
예제 #22
0
        /// <summary>
        /// Called by derived class when a file has been parsed.  The caller should
        /// provide the LibraryTask received from the OnNewFile call and an IScopeNode
        /// which represents the contents of the library.
        /// 
        /// It is safe to call this method from any thread.
        /// </summary>
        protected void FileParsed(LibraryTask task, IScopeNode scope)
        {
            LibraryNode module = new LibraryNode(
                System.IO.Path.GetFileName(task.FileName),
                LibraryNode.LibraryNodeType.PhysicalContainer
            );

            // TODO: Creating the module tree should be done lazily as needed
            // Currently we replace the entire tree and rely upon the libraries
            // update count to invalidate the whole thing.  We could do this
            // finer grained and only update the changed nodes.  But then we
            // need to make sure we're not mutating lists which are handed out.
            CreateModuleTree(module, module, scope, "", task.ModuleID);

            if (null != task.ModuleID) {
                LibraryNode previousItem = null;
                lock (_files) {
                    if (_files.TryGetValue(task.ModuleID, out previousItem)) {
                        _files.Remove(task.ModuleID);
                    }
                }
                _library.RemoveNode(previousItem);
            }
            _library.AddNode(module);
            if (null != task.ModuleID) {
                lock (_files) {
                    _files.Add(task.ModuleID, module);
                }
            }
        }
 private static string GetLibraryNodeName(IScopeNode node, string namePrefix) {
     namePrefix = namePrefix.Substring(namePrefix.LastIndexOf(':') + 1); // remove filename prefix
     return node.NodeType == LibraryNodeType.Members ? node.Name : string.Format(CultureInfo.InvariantCulture, "{0}{1}", namePrefix, node.Name);
 }
예제 #24
0
        private void CreateModuleTree(LibraryNode root, LibraryNode current, IScopeNode scope, string namePrefix, ModuleId moduleId)
        {
            if ((null == root) || (null == scope) || (null == scope.NestedScopes)) {
                return;
            }
            foreach (IScopeNode subItem in scope.NestedScopes) {
                LibraryNode newNode = CreateLibraryNode(subItem, namePrefix, moduleId.Hierarchy, moduleId.ItemID);
                string newNamePrefix = namePrefix;

                // The classes are always added to the root node, the functions to the
                // current node.
                if ((newNode.NodeType & LibraryNode.LibraryNodeType.Members) != LibraryNode.LibraryNodeType.None) {
                    current.AddNode(newNode);
                } else if ((newNode.NodeType & LibraryNode.LibraryNodeType.Classes) != LibraryNode.LibraryNodeType.None) {
                    // Classes are always added to the root.
                    root.AddNode(newNode);
                    newNamePrefix = newNode.Name + ".";
                }

                // Now use recursion to get the other types.
                CreateModuleTree(root, newNode, subItem, newNamePrefix, moduleId);
            }
        }
예제 #25
0
 protected override LibraryNode CreateLibraryNode(LibraryNode parent, IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy, uint itemid) {
     return new PythonLibraryNode(parent, subItem, namePrefix, hierarchy, itemid);            
 }
예제 #26
0
파일: Parser.1.cs 프로젝트: zenuas/Roku
 public static IfCastNode CreateIfCastNode(VariableNode name, ITypeNode declare, IEvaluableNode cond, IScopeNode then) => new IfCastNode(name, declare, cond, then).R(cond);
예제 #27
0
        private void CreateModuleTree(LibraryNode current, IScopeNode scope, string namePrefix, ModuleId moduleId) {
            if ((null == scope) || (null == scope.NestedScopes)) {
                return;
            }

            foreach (IScopeNode subItem in scope.NestedScopes) {                
                LibraryNode newNode = CreateLibraryNode(current, subItem, namePrefix, moduleId.Hierarchy, moduleId.ItemID);
                string newNamePrefix = namePrefix;

                current.AddNode(newNode);
                if ((newNode.NodeType & LibraryNodeType.Classes) != LibraryNodeType.None) {
                    newNamePrefix = namePrefix + newNode.Name + ".";
                }

                // Now use recursion to get the other types.
                CreateModuleTree(newNode, subItem, newNamePrefix, moduleId);
            }
        }
 protected CommonLibraryNode(CommonLibraryNode node, string newFullName) :
     base(node, newFullName) {
     _scope = node._scope;
     _fileId = node._fileId;
     _ownerHierarchy = node._ownerHierarchy;
     _fileMoniker = node._fileMoniker;
     _sourceSpan = node._sourceSpan;
 }
예제 #29
0
 protected override LibraryNode CreateLibraryNode(LibraryNode parent, IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy, uint itemid)
 {
     throw new NotImplementedException();
 }
예제 #30
0
 protected override LibraryNode CreateLibraryNode(IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy, uint itemid)
 {
     return new JLibraryNode(subItem, namePrefix, hierarchy, itemid);
 }
예제 #31
0
 public PythonLibraryNode(IScopeNode scope, string namePrefix, IVsHierarchy hierarchy, uint itemId)
     : base(scope, namePrefix, hierarchy, itemId)
 {
 }
 private static LibraryNodeType GetLibraryNodeTypeFromScope(IScopeNode scope)
 {
     return(scope.IsFunction ? LibraryNodeType.Members : LibraryNodeType.Classes);
 }
예제 #33
0
 public NodeLibraryNode(LibraryNode parent, IScopeNode scope, string namePrefix, IVsHierarchy hierarchy, uint itemId) :
     base(parent, scope, namePrefix, hierarchy, itemId)
 {
 }
예제 #34
0
파일: Parser.1.cs 프로젝트: zenuas/Roku
 public static IIfNode AddElse(IIfNode if_, IScopeNode else_) => if_.Return(x => x.Else = else_);
 protected override LibraryNode CreateLibraryNode(LibraryNode parent, IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy,
     uint itemid)
 {
     Trace.WriteLine("PowerShellLibraryManager.CreateLibraryNode");
     return null;
 }
예제 #36
0
 protected abstract LibraryNode CreateLibraryNode(LibraryNode parent, IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy, uint itemid);
예제 #37
0
 protected override LibraryNode CreateLibraryNode(LibraryNode parent, IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy,
                                                  uint itemid)
 {
     Trace.WriteLine("PowerShellLibraryManager.CreateLibraryNode");
     return(null);
 }