/// <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 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); } }
public IfCastNode(VariableNode name, ITypeNode declare, IEvaluableNode cond, IScopeNode then) { Name = name; Declare = declare; Condition = cond; Then = then; }
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; }
protected CommonLibraryNode(CommonLibraryNode node, string newFullName) : base(node, newFullName) { _scope = node._scope; _fileId = node._fileId; _ownerHierarchy = node._ownerHierarchy; _fileMoniker = node._fileMoniker; _sourceSpan = node._sourceSpan; }
/// <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; }
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); } }
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); });
protected abstract LibraryNode CreateLibraryNode(IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy, uint itemid);
protected override LibraryNode CreateLibraryNode(LibraryNode parent, IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy, uint itemid) { return(new NodeLibraryNode(parent, subItem, namePrefix, hierarchy, itemid)); }
/// <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 } }
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)); }
public static IfNode CreateIfNode(IEvaluableNode cond, IScopeNode then) => new IfNode(cond, then).R(cond);
public IfNode(IEvaluableNode cond, IScopeNode then) { Condition = cond; Then = then; }
private static LibraryNodeType GetLibraryNodeTypeFromScope(IScopeNode scope) { return scope.IsFunction ? LibraryNodeType.Members : LibraryNodeType.Classes; }
public PythonLibraryNode(IScopeNode scope, string namePrefix, IVsHierarchy hierarchy, uint itemId) : base(scope, namePrefix, hierarchy, itemId) { }
private static string GetLibraryNodeName(IScopeNode node, string namePrefix) { return node.IsFunction ? node.Name : string.Format(CultureInfo.InvariantCulture, "{0}{1}", namePrefix, node.Name); }
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) { }
/// <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); }
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); } }
protected override LibraryNode CreateLibraryNode(LibraryNode parent, IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy, uint itemid) { return new PythonLibraryNode(parent, subItem, namePrefix, hierarchy, itemid); }
public static IfCastNode CreateIfCastNode(VariableNode name, ITypeNode declare, IEvaluableNode cond, IScopeNode then) => new IfCastNode(name, declare, cond, then).R(cond);
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; }
protected override LibraryNode CreateLibraryNode(LibraryNode parent, IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy, uint itemid) { throw new NotImplementedException(); }
protected override LibraryNode CreateLibraryNode(IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy, uint itemid) { return new JLibraryNode(subItem, namePrefix, hierarchy, itemid); }
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); }
public NodeLibraryNode(LibraryNode parent, IScopeNode scope, string namePrefix, IVsHierarchy hierarchy, uint itemId) : base(parent, scope, namePrefix, hierarchy, itemId) { }
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; }
protected abstract LibraryNode CreateLibraryNode(LibraryNode parent, IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy, uint itemid);
protected override LibraryNode CreateLibraryNode(LibraryNode parent, IScopeNode subItem, string namePrefix, IVsHierarchy hierarchy, uint itemid) { Trace.WriteLine("PowerShellLibraryManager.CreateLibraryNode"); return(null); }