Beispiel #1
0
        public override bool Walk(ImportStatement node)
        {
            var iinfo = new ImportInfo("", node.Span);

            GlobalScope.Imports[node] = iinfo;
            int len = Math.Min(node.Names.Count, node.AsNames.Count);

            for (int i = 0; i < len; i++)
            {
                var impNode    = node.Names[i];
                var newName    = node.AsNames[i];
                var strImpName = impNode.MakeString();
                iinfo.Types.Add(new[] { strImpName, newName });

                if (strImpName == "clr")
                {
                    GlobalScope.ShowClr = true;
                }
                else if (strImpName == "wpf")
                {
                    AddWpfReferences();
                }

                var             saveName = (String.IsNullOrEmpty(newName)) ? strImpName : newName;
                ModuleReference modRef;

                var def = Scopes[Scopes.Length - 1].CreateVariable(impNode, _unit, saveName);

                if (ProjectState.Modules.TryGetValue(strImpName, out modRef))
                {
                    if (modRef.Module != null)
                    {
                        ModuleInfo mi = modRef.Module as ModuleInfo;
                        if (mi != null)
                        {
                            mi.ModuleDefinition.AddDependency(_unit);
                        }
                        def.AddTypes(impNode, _unit, modRef.Module.SelfSet);
                        continue;
                    }
                    else
                    {
                        modRef.References.Add(_unit);
                    }
                }
                else
                {
                    ProjectState.Modules[strImpName] = modRef = new ModuleReference();
                    if (modRef.References == null)
                    {
                        modRef.References = new HashSet <AnalysisUnit>();
                    }
                    modRef.References.Add(_unit);
                }

                var builtinRefs = ProjectState.GetReflectedNamespaces(impNode.Names, impNode.Names.Count > 1 && !String.IsNullOrEmpty(newName));
                if (builtinRefs != null && builtinRefs.Length > 0)
                {
                    GlobalScope.ShowClr = true;
                    var ns = ProjectState.GetNamespaceFromObjects(builtinRefs);

                    // TODO: Should we pony up a fake module for the module we failed to resolve?
                    if (ns != null)
                    {
                        def.AddTypes(impNode, _unit, ns.SelfSet);
                    }
                }
                else
                {
                }
            }
            return(true);
        }
Beispiel #2
0
        public override bool Walk(FromImportStatement node)
        {
            var             mods = ProjectState.GetReflectedNamespaces(node.Root.Names, true);
            ModuleReference moduleRef;
            Namespace       userMod = null;
            var             modName = node.Root.MakeString();

            if (ProjectState.Modules.TryGetValue(modName, out moduleRef))
            {
                userMod = moduleRef.Module;
                if (userMod == null)
                {
                    moduleRef.References.Add(_unit);
                }
            }
            else
            {
                moduleRef = ProjectState.Modules[modName] = new ModuleReference();
                if (moduleRef.References == null)
                {
                    moduleRef.References = new HashSet <AnalysisUnit>();
                }
                moduleRef.References.Add(_unit);
            }

            var asNames = node.AsNames ?? node.Names;
            var impInfo = new ImportInfo(node.Root.MakeString(), node.Span);

            GlobalScope.Imports[node] = impInfo;

            int len = Math.Min(node.Names.Count, asNames.Count);

            for (int i = 0; i < len; i++)
            {
                var impName = node.Names[i];
                var newName = asNames[i];

                if (impName == null)
                {
                    // incomplete import statement
                    continue;
                }
                else if (impName == "*")
                {
                    // Handle "import *"
                    if (userMod != null)
                    {
                        foreach (var varName in GetModuleKeys(userMod))
                        {
                            WalkFromImportWorker(node, userMod, mods, varName, null);
                        }
                    }
                    if (mods != null)
                    {
                        foreach (var mod in mods)
                        {
                            foreach (var name in Utils.DirHelper(mod, true))
                            {
                                WalkFromImportWorker(node, null, mods, name, null);
                            }
                        }
                    }
                }
                else
                {
                    WalkFromImportWorker(node, userMod, mods, impName, newName);
                }
            }

            return(true);
        }