internal static string GetFullName(INamespaceOrTypeSymbol namespaceOrTypeSymbol) { StringBuilder sb = new StringBuilder(); sb.Append(namespaceOrTypeSymbol.ContainingAssembly.Name); sb.Append("!"); var ns = Utilities.GetValue(namespaceOrTypeSymbol.ContainingNamespace, false); if (ns != null) { sb.Append(ns); sb.Append("."); } sb.Append(namespaceOrTypeSymbol.Name); return(sb.ToString()); }
internal void GenerateCode(INamedTypeSymbol entryPoint) { var context = new CompilationContext(); context.MainAssembly = entryPoint.ContainingAssembly; context.LibraryAssembly = entryPoint.BaseType.ContainingAssembly; context.Uglify = false; foreach (var declaration in this.classDictionary.Values) { context.MakeUglified(declaration.Symbol); if (declaration.Symbol is INamedTypeSymbol typeSymbol) { bool hasAnythingButFields = false; foreach (var member in typeSymbol.GetMembers()) { context.MakeUglified(member); if (member is IMethodSymbol methodSymbol) { if (methodSymbol.DeclaringSyntaxReferences.Length > 0) { hasAnythingButFields = true; } else { // Auto-generated. } } else if (!(member is IFieldSymbol)) { hasAnythingButFields = true; } } if ((typeSymbol.TypeKind == TypeKind.Class) && !hasAnythingButFields) { context.MarkAsAnonymous(declaration.Symbol); } } if (declaration.Declaration is ClassDeclarationSyntax classDeclarationSyntax) { foreach (var local in classDeclarationSyntax.DescendantNodes().OfType <VariableDeclaratorSyntax>()) { var symbol = declaration.SemanticModel.GetDeclaredSymbol(local); context.MakeUglified(symbol); } } } var entry = this.classDictionary[GetFullName(entryPoint)]; this.mainText.Append(@"import(""queue.fibonacci_heap"", ""FibonacciHeap"", 2);"); if (!context.Uglify) { this.mainText.AppendLine(); } GenerateInfo(entryPoint, context); foreach (var declaration in this.classDictionary.Values) { NodeWriter writer = new NodeWriter(declaration.SemanticModel, mainText, context); if (declaration.Declaration is EnumDeclarationSyntax enumDeclarationSyntax) { writer.Write(enumDeclarationSyntax, declaration.Symbol); } } foreach (var declaration in this.classDictionary.Values) { NodeWriter writer = new NodeWriter(declaration.SemanticModel, mainText, context); if (declaration.Declaration is ClassDeclarationSyntax classDeclarationSyntax) { writer.Write(classDeclarationSyntax, declaration.Symbol); } } context.AddToScript(mainText); var entryNs = Utilities.GetValue(entryPoint.ContainingNamespace, true); if (!string.IsNullOrEmpty(entryNs)) { mainText.Append($"class {entryPoint.Name} extends {entryNs}.{entryPoint.Name}{{}}"); } }