static List <BoundStatement> GetInitStatements(CSharpCompilation compilation, BoundStatement statement, bool localOnly) { var newstatements = new List <BoundStatement>(); var vcla = compilation.ClassLibraryType(); var refMan = compilation.GetBoundReferenceManager(); var init1 = new List <ISymbol>(); var init2 = new List <ISymbol>(); var init3 = new List <ISymbol>(); if (!localOnly) { foreach (var rkv in refMan.GetReferencedAssemblies()) { var r = rkv.Value; foreach (var attr in r.GetAttributes()) { if ((Symbol)attr.AttributeClass.ConstructedFrom == vcla) { var attargs = attr.CommonConstructorArguments; if (attargs.Length == 2) { var functionsClassName = attargs[0].Value.ToString(); if (!string.IsNullOrEmpty(functionsClassName)) { var type = r.GetTypeByMetadataName(functionsClassName); if (type != null) { init1.AddRange(type.GetMembers(XSharpSpecialNames.InitProc1)); init2.AddRange(type.GetMembers(XSharpSpecialNames.InitProc2)); init3.AddRange(type.GetMembers(XSharpSpecialNames.InitProc3)); } } } } } } } var members = FindMembers(compilation, XSharpSpecialNames.InitProc1); init1.AddRange(members); members = FindMembers(compilation, XSharpSpecialNames.InitProc2); init2.AddRange(members); members = FindMembers(compilation, XSharpSpecialNames.InitProc3); init3.AddRange(members); // Now join all 3 lists to one list init1.AddRange(init2); init1.AddRange(init3); foreach (MethodSymbol sym in init1) { CreateMethodCall(compilation, statement.Syntax, sym, newstatements); } return(newstatements); }
internal static bool HandleXSharpImport(UsingDirectiveSyntax usingDirective, Binder usingsBinder, ArrayBuilder <NamespaceOrTypeAndUsingDirective> usings, PooledHashSet <NamespaceOrTypeSymbol> uniqueUsings, ConsList <Symbol> basesBeingResolved, CSharpCompilation compilation) { // The usingDirective name contains spaces when it is nested and the GlobalClassName not , so we must eliminate them here // nvk: usingDirective.Name.ToString() ONLY has spaces if it is nested. This is not supposed to be nested, as it is "Functions" even for the non-core dialects !!! if (usingDirective.Name.ToString().EndsWith(XSharpSpecialNames.FunctionsClass)) { var result = LookupResult.GetInstance(); LookupOptions options = LookupOptions.AllNamedTypesOnArityZero; HashSet <DiagnosticInfo> useSiteDiagnostics = null; usingsBinder.LookupSymbolsSimpleName(result, null, XSharpSpecialNames.FunctionsClass, 0, basesBeingResolved, options, false, useSiteDiagnostics: ref useSiteDiagnostics); foreach (var sym in result.Symbols) { if (sym.Kind == SymbolKind.NamedType) { var ts = (NamedTypeSymbol)sym; AddNs(usingDirective, ts, usings, uniqueUsings); } } var opts = ((CSharpSyntaxTree)usingDirective.SyntaxTree).Options; if (opts.CommandLineArguments != null) { string functionsClass = null; if (compilation.Options.HasRuntime) { functionsClass = Syntax.InternalSyntax.XSharpTreeTransformationRT.VOGlobalClassName(opts); } else { functionsClass = Syntax.InternalSyntax.XSharpTreeTransformationCore.GlobalFunctionClassName(opts.TargetDLL); } if (!string.IsNullOrEmpty(functionsClass)) { var declbinder = usingsBinder.WithAdditionalFlags(BinderFlags.SuppressConstraintChecks); var diagnostics = DiagnosticBag.GetInstance(); var name = Syntax.InternalSyntax.XSharpTreeTransformationCore.ExtGenerateQualifiedName(functionsClass); var imported = declbinder.BindNamespaceOrTypeSymbol(name, diagnostics, basesBeingResolved); if (imported.Kind == SymbolKind.NamedType) { var importedType = (NamedTypeSymbol)imported; AddNs(usingDirective, importedType, usings, uniqueUsings); } } } if (!compilation.ClassLibraryType().IsErrorType() && !compilation.ImplicitNamespaceType().IsErrorType()) { var declbinder = usingsBinder.WithAdditionalFlags(BinderFlags.SuppressConstraintChecks); var diagnostics = DiagnosticBag.GetInstance(); string[] defNs; if (compilation.Options.XSharpRuntime) { defNs = new string[] { OurNameSpaces.XSharp } } ; else { defNs = new string[] { OurNameSpaces.Vulcan } }; foreach (var n in defNs) { var name = Syntax.InternalSyntax.XSharpTreeTransformationCore.ExtGenerateQualifiedName(n); var imported = declbinder.BindNamespaceOrTypeSymbol(name, diagnostics, basesBeingResolved); if (imported.Kind == SymbolKind.Namespace) { AddNs(usingDirective, imported, usings, uniqueUsings); } else if (imported.Kind == SymbolKind.NamedType) { var importedType = (NamedTypeSymbol)imported; AddNs(usingDirective, importedType, usings, uniqueUsings); } } var vcla = compilation.ClassLibraryType(); var vins = compilation.ImplicitNamespaceType(); var refMan = compilation.GetBoundReferenceManager(); foreach (var r in refMan.ReferencedAssemblies) { foreach (var attr in r.GetAttributes()) { // Check for VulcanImplicitNameSpace attribute if (attr.AttributeClass.ConstructedFrom == vins && compilation.Options.ImplicitNameSpace) { var args = attr.CommonConstructorArguments; if (args != null && args.Length == 1) { // only one argument, must be default namespace var defaultNamespace = args[0].Value.ToString(); if (!string.IsNullOrEmpty(defaultNamespace)) { var name = Syntax.InternalSyntax.XSharpTreeTransformationCore.ExtGenerateQualifiedName(defaultNamespace); var imported = declbinder.BindNamespaceOrTypeSymbol(name, diagnostics, basesBeingResolved); if (imported.Kind == SymbolKind.Namespace) { AddNs(usingDirective, imported, usings, uniqueUsings); } } } } // Check for VulcanClasslibrary attribute else if (attr.AttributeClass.ConstructedFrom == vcla) { var args = attr.CommonConstructorArguments; if (args != null && args.Length == 2) { // first element is the Functions class var globalClassName = args[0].Value.ToString(); if (!string.IsNullOrEmpty(globalClassName)) { var name = Syntax.InternalSyntax.XSharpTreeTransformationCore.ExtGenerateQualifiedName(globalClassName); var imported = declbinder.BindNamespaceOrTypeSymbol(name, diagnostics, basesBeingResolved); if (imported.Kind == SymbolKind.NamedType) { var importedType = (NamedTypeSymbol)imported; AddNs(usingDirective, importedType, usings, uniqueUsings); } } // second element is the default namespace var defaultNamespace = args[1].Value.ToString(); if (!string.IsNullOrEmpty(defaultNamespace) && compilation.Options.ImplicitNameSpace) { var name = Syntax.InternalSyntax.XSharpTreeTransformationCore.ExtGenerateQualifiedName(defaultNamespace); var imported = declbinder.BindNamespaceOrTypeSymbol(name, diagnostics, basesBeingResolved); if (imported.Kind == SymbolKind.Namespace) { AddNs(usingDirective, imported, usings, uniqueUsings); } } } } } } } return(true); } return(false); } }