internal static LocationInfo GetLocationInfo(this EncodedSpan span, ProjectEntry project) { var location = project.Tree.IndexToLocation(span.GetStartIndex(project.Tree.LocationResolver)); return new LocationInfo( project, location.Line, location.Column ); }
internal LocationInfo ResolveLocation(ProjectEntry project, object location) { var loc = _locationResolver.IndexToLocation(((Node)location).GetSpan(project.Tree.LocationResolver).Start); return new LocationInfo( project, loc.Line, loc.Column ); }
public void Build() { Dictionary<string, ExportsValue> exportsTable = new Dictionary<string, ExportsValue>(); // run through and initialize all of the modules. foreach (var module in _all["modules"]) { var moduleName = FixModuleName((string)module["name"]); var entry = new ProjectEntry(_analyzer, moduleName, null, true); var documentation = ParseDocumentation(module["desc"]); _analyzer.Modules.AddModule(moduleName, entry); exportsTable[moduleName] = entry.InitNodejsVariables(documentation); } // next create all of the classes foreach (var module in _all["modules"]) { var moduleName = FixModuleName((string)module["name"]); var exports = exportsTable[moduleName]; if (module.ContainsKey("classes")) { foreach (var klass in module["classes"]) { GenerateClass(exports, klass); } } if (module.ContainsKey("properties")) { foreach (var property in module["properties"]) { if (property.ContainsKey("methods")) { GenerateClass(exports, property); } } } } foreach (var module in _all["modules"]) { var moduleName = FixModuleName((string)module["name"]); var exports = exportsTable[moduleName]; Dictionary<string, FunctionSpecializer> specialMethods; _moduleSpecializations.TryGetValue(moduleName, out specialMethods); if (module.ContainsKey("methods")) { foreach (var method in module["methods"]) { GenerateMethod(exports, specialMethods, method); } } } foreach (var misc in _all["miscs"]) { if (misc["name"] == "Global Objects") { GenerateGlobals(misc["globals"]); foreach (var method in misc["methods"]) { GenerateMethod(_analyzer._globalObject, null, method); } break; } } }
public void AddModule(string name, ProjectEntry value) { lock (_lock) { var tree = GetModuleTree(name); tree.ProjectEntry = value; // Update visibility.. AddVisibility(tree, value, true); value._enqueueModuleDependencies = true; if (value.IsBuiltin) { //We found a new builtin, replace our current tree; _builtins.Add(value); } } }
// Visibility rules: // My peers can see my assignments/I can see my peers assignments // Everything up to the next node_modules and terminating at child node_modules // folders is a set of peers. They can easily require each other using relative // paths. We make all of the assignments made by these modules available to // see by all the other modules. // // My parent and its peers can see my assignments // A folder which contains node_modules is presumably using those modules. ANy // peers within that folder structure can see all of the changes by the children // in node_modules. // // We share hashsets of visible nodes. They're stored in the ModuleTree and when a // new module is added we assign it's _visibleEntries field to the one shared by all // of it's peers. We then update the relevant entries with the new values. internal void AddVisibility(ModuleTree tree, ProjectEntry newModule) { // My peers can see my assignments/I can see my peers assignments. Update // ourselves and our peers so we can see each others writes. var curTree = tree; while (curTree.Parent != null && curTree.Parent.Name != AnalysisConstants.NodeModulesFolder) { curTree = curTree.Parent; } if (curTree.VisibleEntries == null) { curTree.VisibleEntries = new HashSet <ProjectEntry>(); curTree.VisibleEntries.Add(newModule.Analyzer._builtinEntry); } curTree.VisibleEntries.Add(newModule); newModule._visibleEntries = curTree.VisibleEntries; // My parent and its peers can see my assignments. Update existing parents // so they can see the newly added modules writes. if (curTree.Parent != null) { Debug.Assert(curTree.Parent.Name == AnalysisConstants.NodeModulesFolder); var grandParent = curTree.Parent.Parent; if (grandParent != null) { while (grandParent.Parent != null && !String.Equals(grandParent.Parent.Name, AnalysisConstants.NodeModulesFolder, StringComparison.OrdinalIgnoreCase)) { grandParent = grandParent.Parent; } if (grandParent.VisibleEntries == null) { grandParent.VisibleEntries = new HashSet <ProjectEntry>(); } grandParent.VisibleEntries.Add(newModule); } } }
private IAnalysisSet GetTypesWorker(ProjectEntry accessor, ProjectEntry declaringScope, out bool needsCopy) { needsCopy = false; var res = _emptySet; if (_dependencies.Count != 0) { SingleDict <ProjectEntry, T> .SingleDependency oneDependency; if (_dependencies.TryGetSingleDependency(out oneDependency)) { if (oneDependency.Value.Types.Count > 0 && IsVisible(accessor, declaringScope, oneDependency.Key)) { var types = oneDependency.Value.Types; if (types != null) { needsCopy = !(types is IImmutableAnalysisSet); res = types; } } } else { foreach (var kvp in (AnalysisDictionary <ProjectEntry, T>)_dependencies._data) { if (kvp.Value.Types.Count > 0 && IsVisible(accessor, declaringScope, kvp.Key)) { res = res.Union(kvp.Value.Types); } } } } if (res.Count > HARD_TYPE_LIMIT) { ExceedsTypeLimit(); } return(res); }
public bool AddTypes(AnalysisUnit unit, IAnalysisSet newTypes, bool enqueue = true, ProjectEntry declaringScope = null) { return(AddTypes(unit.ProjectEntry, newTypes, enqueue, declaringScope)); }
internal virtual Dictionary <string, IAnalysisSet> GetAllMembers(ProjectEntry accessor) { return(new Dictionary <string, IAnalysisSet>()); }
/// <summary> /// Implements the internal [[Prototype]] property /// </summary> internal virtual IAnalysisSet GetPrototype(ProjectEntry accessor) { return(null); }
public abstract AnalysisValue Specialize(ProjectEntry projectEntry, string name);
public abstract FunctionValue Specialize(ProjectEntry projectEntry, string name, string doc, AnalysisValue returnValue, ParameterResult[] parameters);
internal virtual Dictionary<string, IAnalysisSet> GetAllMembers(ProjectEntry accessor) { return new Dictionary<string, IAnalysisSet>(); }
/// <summary> /// Implements the internal [[Prototype]] property /// </summary> internal virtual IAnalysisSet GetPrototype(ProjectEntry accessor) { return null; }
public override FunctionValue Specialize(ProjectEntry projectEntry, string name, string doc, AnalysisValue returnValue, ParameterResult[] parameters) { return new SpecializedFunctionValue( projectEntry, name, _delegate, doc, null, parameters ); }
public override void EnqueueDependents(ProjectEntry assigner = null, ProjectEntry declaringScope = null) { }
protected static bool IsVisible(ProjectEntry accessor, ProjectEntry declaringScope, ProjectEntry assigningScope) { if (accessor != null && accessor.IsVisible(assigningScope)) { return(true); } if (declaringScope != null && declaringScope.IsVisible(assigningScope)) { return(true); } return(false); }
public ReadDirSyncArrayValue(ProjectEntry projectEntry, Node node) : base(new[] { new TypedDef() }, projectEntry, node) { }
public override FunctionValue Specialize(ProjectEntry projectEntry, string name, string doc, AnalysisValue returnValue, ParameterResult[] parameters) { return new ReturningFunctionValue( projectEntry, name, GetReturnValue(projectEntry.Analyzer), doc, parameters ); }
public override FunctionValue Specialize(ProjectEntry projectEntry, string name, string doc, AnalysisValue returnValue, ParameterResult[] parameters) { return new CallbackReturningFunctionValue( projectEntry, name, returnValue != null ? returnValue.SelfSet : AnalysisSet.Empty, _index, _args, doc, parameters ); }
internal bool IsVisible(ProjectEntry projectEntry) { return projectEntry == this || (_visibleEntries != null && _visibleEntries.Contains(projectEntry)); }
public bool AddTypes(ProjectEntry projectEntry, IAnalysisSet newTypes, bool enqueue = true, ProjectEntry declaringScope = null) { object dummy; if (LockedVariableDefs.TryGetValue(this, out dummy)) { return(false); } bool added = false; if (newTypes.Count > 0) { var dependencies = GetDependentItems(projectEntry); foreach (var value in newTypes) { #if DEBUG || FULL_VALIDATION if (ENABLE_SET_CHECK) { bool testAdded; var original = dependencies.ToImmutableTypeSet(); var afterAdded = new AnalysisHashSet(original, original.Comparer).Add(value, out testAdded); if (afterAdded.Comparer == original.Comparer) { if (testAdded) { Validation.Assert(!ObjectComparer.Instance.Equals(afterAdded, original)); } else { Validation.Assert(ObjectComparer.Instance.Equals(afterAdded, original)); } } } #endif if (dependencies.AddType(value)) { added = true; } } if (added && enqueue) { EnqueueDependents(projectEntry, declaringScope); } } return(added); }
public ProjectItem(ProjectEntry entry) { Entry = entry; }
/// <summary> /// Returns a possibly mutable hash set of types. Because the set may be mutable /// you can only use this version if you are directly consuming the set and know /// that this VariableDef will not be mutated while you would be enumerating over /// the resulting set. /// </summary> public IAnalysisSet GetTypesNoCopy(AnalysisUnit accessor, ProjectEntry declaringScope = null) { return(GetTypesNoCopy(accessor.ProjectEntry, declaringScope)); }
internal virtual Dictionary<string, IAnalysisSet> GetOwnProperties(ProjectEntry accessor) { return new Dictionary<string, IAnalysisSet>(); }
public IAnalysisSet GetTypesNoCopy(ProjectEntry accessor = null, ProjectEntry declaringScope = null) { bool needsCopy; return(GetTypesWorker(accessor, declaringScope, out needsCopy)); }
internal AnalysisValue(ProjectEntry projectEntry) { _proxy = projectEntry.WrapAnalysisValue(this); }
public bool AddReference(EncodedSpan location, ProjectEntry module) { return(GetDependentItems(module).AddReference(location)); }
public override AnalysisValue Specialize(ProjectEntry projectEntry, string name) { return(projectEntry.Analyzer.GetConstant(_value)); }
public bool AddAssignment(EncodedSpan location, ProjectEntry entry) { return(GetDependentItems(entry).AddAssignment(location)); }
public LocatedVariableDef(ProjectEntry entry, Node location) { _entry = entry; _location = location; _declaringVersion = entry.AnalysisVersion; }
internal virtual Dictionary <string, IAnalysisSet> GetOwnProperties(ProjectEntry accessor) { return(new Dictionary <string, IAnalysisSet>()); }
internal LocationInfo(ProjectEntry entry, int line, int column) { _entry = entry; _line = line; _column = column; }
public override int GetHashCode() { return(Line.GetHashCode() ^ ProjectEntry.GetHashCode()); }
public void Build() { Dictionary <string, ExportsValue> exportsTable = new Dictionary <string, ExportsValue>(); // run through and initialize all of the modules. foreach (var module in _all["modules"]) { var moduleName = FixModuleName((string)module["name"]); var entry = new ProjectEntry(_analyzer, moduleName, null, true); var documentation = ParseDocumentation(module["desc"]); _analyzer.Modules.AddModule(moduleName, entry); exportsTable[moduleName] = entry.InitNodejsVariables(documentation); } // next create all of the classes foreach (var module in _all["modules"]) { var moduleName = FixModuleName((string)module["name"]); var exports = exportsTable[moduleName]; if (module.ContainsKey("classes")) { foreach (var klass in module["classes"]) { GenerateClass(exports, klass); } } if (module.ContainsKey("properties")) { foreach (var property in module["properties"]) { if (property.ContainsKey("methods")) { GenerateClass(exports, property); } } } } foreach (var module in _all["modules"]) { var moduleName = FixModuleName((string)module["name"]); var exports = exportsTable[moduleName]; Dictionary <string, FunctionSpecializer> specialMethods; _moduleSpecializations.TryGetValue(moduleName, out specialMethods); if (module.ContainsKey("methods")) { foreach (var method in module["methods"]) { GenerateMethod(exports, specialMethods, method); } } } foreach (var misc in _all["miscs"]) { if (misc["name"] == "Global Objects") { GenerateGlobals(misc["globals"]); foreach (var method in misc["methods"]) { GenerateMethod(_analyzer._globalObject, null, method); } break; } } }
public TestAnalysisValue(ProjectEntry project) : base(project) { }
internal bool IsVisible(ProjectEntry projectEntry) { return(projectEntry == this || (_visibleEntries != null && _visibleEntries.Contains(projectEntry))); }
public TreeUpdateAnalysis(ModuleTree tree, IEnumerable <string> dependencies = null, ProjectEntry projectEntry = null, ModuleTable modules = null) { _tree = tree; _dependencies = dependencies; _projectEntry = projectEntry; _modules = modules; }
public override AnalysisValue Specialize(ProjectEntry projectEntry, string name) { return projectEntry.Analyzer.GetConstant(_value); }