Пример #1
0
        public void Visit(PyAst.ImportStatement node)
        {
            if (node.AsNames.Count > 1 || node.Names.Count > 1)
            {
                throw CreateNotImplementedEx();
            }
            var modName = FormatDottedName(node.Names.Single());

            AppendLineWithIndentation($"import {modName} as {node.AsNames.Single()}");
        }
 public void PostWalk(ImportStatement node)
 {
     PostProcess(node);
 }
Пример #3
0
 // ImportStmt
 public override bool Walk(ImportStatement node) {
     for (int i = 0; i < node.Names.Count; i++) {
         Define(node.AsNames[i] !=  null ? node.AsNames[i] : node.Names[i].Names[0]);
     }
     return true;
 }
Пример #4
0
        private CodeGen CompileModuleInit(CompilerContext context, GlobalSuite gs, TypeGen tg, string moduleName)
        {
            CodeGen init;
            if (!AutoImportAll) {
                init = OutputGenerator.GenerateModuleInitialize(context, gs, tg);
            } else {
                // auto-import all compiled modules, useful for CodeDom scenarios.
                init = OutputGenerator.GenerateModuleInitialize(context, gs, tg, staticTypes, delegate(CodeGen cg) {

                    Location dummyLocation = new Location(1, 1);

                    for (int i = 0; i < sourceFiles.Count; i++) {
                        string otherModName = GetModuleFromFilename(sourceFiles[i]);
                        if (otherModName == moduleName) continue;

                        FromImportStatement stmt = new FromImportStatement(
                            new DottedName(new SymbolId[] { SymbolTable.StringToId(otherModName) }),
                            FromImportStatement.Star, null);
                        stmt.Start = dummyLocation;
                        stmt.End = dummyLocation;
                        stmt.Emit(cg);
                    }

                    // Import the first part of all namespaces in all referenced assemblies

                    // First, determine the set of unique such prefixes
                    Dictionary<string, object> nsPrefixes = new Dictionary<string, object>();
                    foreach (string name in ReferencedAssemblies) {
                        Assembly a = LoadAssembly(name);

                        foreach (Type t in a.GetTypes()) {
                            // We only care about public types
                            if (!t.IsPublic) continue;

                            // Ignore types that don't have a namespace
                            if (t.Namespace == null) continue;

                            string nsPrefix = t.Namespace.Split('.')[0];
                            nsPrefixes[nsPrefix] = null;
                        }
                    }

                    // Import all the uniquer prefixes we found
                    foreach (string nsPrefix in nsPrefixes.Keys) {
                        SymbolId symbolId = SymbolTable.StringToId(nsPrefix);
                        cg.Names.CreateGlobalSlot(symbolId);
                        DottedName dottedName = new DottedName(new SymbolId[] { symbolId });
                        ImportStatement importStmt = new ImportStatement(
                            new DottedName[] { dottedName },
                            new SymbolId[] { SymbolTable.Empty });
                        importStmt.Start = dummyLocation;
                        importStmt.End = dummyLocation;
                        importStmt.Emit(cg);
                    }
                });
            }
            return init;
        }
Пример #5
0
 public override void PostWalk(ImportStatement node)
 {
     CommonPostWalk(node);
 }
Пример #6
0
 internal Import(ImportStatement stmt)
     : this() {
     _names = ConvertAliases(stmt.Names, stmt.AsNames);
 }
        public override bool Walk(ImportStatement node)
        {
            var container = containers.Peek ();
            if (!container.SupportsImportStatements)
                return base.Walk (node);

            // import mod1, mod2, mod3,...
            for (int i = 0; i < node.Names.Count; i++) {
                var fullName = node.Names [i].MakeString ();
                var asname = node.AsNames [i];

                var import = new PythonImport () {
                    ModuleName = fullName,
                    AsName = asname,
                    Region = GetDomRegion (node)
                };

                container.Imports.Add (import);
            }

            return base.Walk (node);
        }
Пример #8
0
        // import_stmt: 'import' module ['as' name"] (',' module ['as' name])*        
        // name: identifier
        private ImportStatement ParseImportStmt() {
            Eat(TokenKind.KeywordImport);
            SourceLocation start = GetStart();

            List<ModuleName> l = new List<ModuleName>();
            List<SymbolId> las = new List<SymbolId>();
            l.Add(ParseModuleName());
            las.Add(MaybeParseAsName());
            while (MaybeEat(TokenKind.Comma)) {
                l.Add(ParseModuleName());
                las.Add(MaybeParseAsName());
            }
            ModuleName[] names = l.ToArray();
            SymbolId[] asNames = las.ToArray();

            ImportStatement ret = new ImportStatement(names, asNames, AbsoluteImports);
            ret.SetLoc(start, GetEnd());
            return ret;
        }
 public override bool Walk(ImportStatement node)
 {
     Emit(node); return false;
 }
Пример #10
0
 public static string Format(ImportStatement node)
 {
     return("import " + string.Join(",", node.Names.Select(n => string.Join(".", n.Names)).ToArray()) + " as " + string.Join(", ", node.AsNames));
 }
 public virtual void PostWalk(ImportStatement node)
 {
 }
 // ImportStatement
 public virtual bool Walk(ImportStatement node)
 {
     return true;
 }
Пример #13
0
        //import_stmt: 'import' dotted_as_name (',' dotted_as_name)*
        private ImportStatement ParseImportStmt()
        {
            Eat(TokenKind.KeywordImport);
            Location start = GetStart();

            List<DottedName> l = new List<DottedName>();
            List<SymbolId> las = new List<SymbolId>();
            l.Add(ParseDottedName());
            las.Add(MaybeParseAsName());
            while (MaybeEat(TokenKind.Comma)) {
                l.Add(ParseDottedName());
                las.Add(MaybeParseAsName());
            }
            DottedName[] names = l.ToArray();
            SymbolId[] asNames = las.ToArray();

            ImportStatement ret = new ImportStatement(names, asNames);
            ret.SetLoc(GetExternal(), start, GetEnd());
            return ret;
        }
 // ImportStatement
 public bool Walk(ImportStatement node)
 {
     return Process(node);
 }
Пример #15
0
 // ImportStatement
 public override bool Walk(ImportStatement node) {
     PythonVariable[] variables = new PythonVariable[node.Names.Count];
     for (int i = 0; i < node.Names.Count; i++) {
         SymbolId name = node.AsNames[i] != SymbolId.Empty ? node.AsNames[i] : node.Names[i].Names[0];
         variables[i] = DefineName(name);
     }
     node.Variables = variables;
     return true;
 }
Пример #16
0
 // ImportStatement
 public override bool Walk(ImportStatement node)
 {
     for (int i = 0; i < node.Names.Count; i++) {
         SymbolId name = node.AsNames[i] != SymbolTable.Empty ? node.AsNames[i] : node.Names[i].Names[0];
         Define(name, new ImportDefinition(node.Names[i], node));
     }
     return true;
 }
 public ImportDefinition(DottedName name, ImportStatement import)
 {
     this.name = name;
     this.importStatement = import;
 }
Пример #18
0
 public override bool Walk(ImportStatement node)
 {
     CommonWalk(node);
     return true;
 }
Пример #19
0
		public PythonImport(IProjectContent projectContent, ImportStatement importStatement)
			: base(projectContent)
		{
			this.importStatement = importStatement;
			AddUsings();
		}
Пример #20
0
        // ImportStatement
        public override bool Walk(ImportStatement node)
        {
            node.Parent = _currentScope;

            PythonVariable[] variables = new PythonVariable[node.Names.Count];
            for (int i = 0; i < node.Names.Count; i++) {
                string name = node.AsNames[i] != null ? node.AsNames[i] : node.Names[i].Names[0];
                variables[i] = DefineName(name);
                node.Names[i].Parent = _currentScope;
            }
            node.Variables = variables;
            return true;
        }
		/// <summary>
		/// Walks an import statement and adds it to the compilation unit's
		/// Usings.
		/// </summary>
		public override bool Walk(ImportStatement node)
		{
			PythonImport import = new PythonImport(compilationUnit.ProjectContent, node);
			compilationUnit.UsingScope.Usings.Add(import);
			return false;
		}
Пример #22
0
        // import_stmt: 'import' module ['as' name"] (',' module ['as' name])*        
        // name: identifier
        private ImportStatement ParseImportStmt() {
            Eat(TokenKind.KeywordImport);
            var start = GetStart();

            List<ModuleName> l = new List<ModuleName>();
            List<string> las = new List<string>();
            l.Add(ParseModuleName());
            las.Add(MaybeParseAsName());
            while (MaybeEat(TokenKind.Comma)) {
                l.Add(ParseModuleName());
                las.Add(MaybeParseAsName());
            }
            ModuleName[] names = l.ToArray();
            var asNames = las.ToArray();

            ImportStatement ret = new ImportStatement(names, asNames, AbsoluteImports);
            ret.SetLoc(_globalParent, start, GetEnd());
            return ret;
        }
Пример #23
0
		public override bool Walk(ImportStatement node)
		{
			writer.WriteLine("Import: " + GetImports(node.Names));
			return base.Walk(node);
		}