コード例 #1
0
 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
     );
 }
コード例 #2
0
ファイル: JsAst.cs プロジェクト: lioaphy/nodejstools
 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
     );
 }
コード例 #3
0
        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;
                }
            }
        }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
ファイル: ModuleTable.cs プロジェクト: Weflac/nodejstools
        // 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);
                }
            }
        }
コード例 #6
0
        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);
        }
コード例 #7
0
 public bool AddTypes(AnalysisUnit unit, IAnalysisSet newTypes, bool enqueue = true, ProjectEntry declaringScope = null)
 {
     return(AddTypes(unit.ProjectEntry, newTypes, enqueue, declaringScope));
 }
コード例 #8
0
ファイル: AnalysisValue.cs プロジェクト: Weflac/nodejstools
 internal virtual Dictionary <string, IAnalysisSet> GetAllMembers(ProjectEntry accessor)
 {
     return(new Dictionary <string, IAnalysisSet>());
 }
コード例 #9
0
ファイル: AnalysisValue.cs プロジェクト: Weflac/nodejstools
 /// <summary>
 /// Implements the internal [[Prototype]] property
 /// </summary>
 internal virtual IAnalysisSet GetPrototype(ProjectEntry accessor)
 {
     return(null);
 }
コード例 #10
0
 public abstract AnalysisValue Specialize(ProjectEntry projectEntry, string name);
コード例 #11
0
 public abstract FunctionValue Specialize(ProjectEntry projectEntry, string name, string doc, AnalysisValue returnValue, ParameterResult[] parameters);
コード例 #12
0
 internal virtual Dictionary<string, IAnalysisSet> GetAllMembers(ProjectEntry accessor) {
     return new Dictionary<string, IAnalysisSet>();
 }
コード例 #13
0
 /// <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 abstract FunctionValue Specialize(ProjectEntry projectEntry, string name, string doc, AnalysisValue returnValue, ParameterResult[] parameters);
コード例 #16
0
 public override void EnqueueDependents(ProjectEntry assigner = null, ProjectEntry declaringScope = null)
 {
 }
コード例 #17
0
 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
     );
 }
コード例 #21
0
 internal bool IsVisible(ProjectEntry projectEntry) {
     return projectEntry == this || (_visibleEntries != null && _visibleEntries.Contains(projectEntry));
 }
コード例 #22
0
        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);
        }
コード例 #23
0
 public ProjectItem(ProjectEntry entry) {
     Entry = entry;
 }
コード例 #24
0
 /// <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));
 }
コード例 #25
0
 internal virtual Dictionary<string, IAnalysisSet> GetOwnProperties(ProjectEntry accessor) {
     return new Dictionary<string, IAnalysisSet>();
 }
コード例 #26
0
        public IAnalysisSet GetTypesNoCopy(ProjectEntry accessor = null, ProjectEntry declaringScope = null)
        {
            bool needsCopy;

            return(GetTypesWorker(accessor, declaringScope, out needsCopy));
        }
コード例 #27
0
 internal AnalysisValue(ProjectEntry projectEntry) {
     _proxy = projectEntry.WrapAnalysisValue(this);
 }
コード例 #28
0
 public bool AddReference(EncodedSpan location, ProjectEntry module)
 {
     return(GetDependentItems(module).AddReference(location));
 }
コード例 #29
0
 public override AnalysisValue Specialize(ProjectEntry projectEntry, string name)
 {
     return(projectEntry.Analyzer.GetConstant(_value));
 }
コード例 #30
0
 public bool AddAssignment(EncodedSpan location, ProjectEntry entry)
 {
     return(GetDependentItems(entry).AddAssignment(location));
 }
コード例 #31
0
 public ReadDirSyncArrayValue(ProjectEntry projectEntry, Node node)
     : base(new[] { new TypedDef() }, projectEntry, node)
 {
 }
コード例 #32
0
 public LocatedVariableDef(ProjectEntry entry, Node location)
 {
     _entry            = entry;
     _location         = location;
     _declaringVersion = entry.AnalysisVersion;
 }
コード例 #33
0
ファイル: AnalysisValue.cs プロジェクト: Weflac/nodejstools
 internal virtual Dictionary <string, IAnalysisSet> GetOwnProperties(ProjectEntry accessor)
 {
     return(new Dictionary <string, IAnalysisSet>());
 }
コード例 #34
0
 internal LocationInfo(ProjectEntry entry, int line, int column)
 {
     _entry  = entry;
     _line   = line;
     _column = column;
 }
コード例 #35
0
ファイル: AnalysisValue.cs プロジェクト: Weflac/nodejstools
 internal AnalysisValue(ProjectEntry projectEntry)
 {
     _proxy = projectEntry.WrapAnalysisValue(this);
 }
コード例 #36
0
 public override int GetHashCode()
 {
     return(Line.GetHashCode() ^ ProjectEntry.GetHashCode());
 }
コード例 #37
0
        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 abstract AnalysisValue Specialize(ProjectEntry projectEntry, string name);
コード例 #39
0
 public TestAnalysisValue(ProjectEntry project)
     : base(project) {
 }
コード例 #40
0
 internal bool IsVisible(ProjectEntry projectEntry)
 {
     return(projectEntry == this || (_visibleEntries != null && _visibleEntries.Contains(projectEntry)));
 }
コード例 #41
0
ファイル: JsAnalyzer.cs プロジェクト: lioaphy/nodejstools
 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);
 }