private static IList <ClassStatement> GenerateClassFromList( AbstractSyntaxTree ast, string projectAssembly, IList <string> generationList, IList <string> notGeneratedClassNames, IDictionary <string, string> typeOverrideMap, IList <ClassStatement> generatedStatements ) { var stopwatch = Stopwatch.StartNew(); foreach (var classIdentifier in generationList) { if (generatedStatements.Any(a => a.Name == classIdentifier) || notGeneratedClassNames.Contains(classIdentifier)) { continue; } stopwatch.Restart(); var generated = GenerateInteropClassStatement.Generate( projectAssembly, classIdentifier, ast, typeOverrideMap ); stopwatch.Stop(); GlobalLogger.Info( $"Took {stopwatch.ElapsedMilliseconds}ms to generate {classIdentifier}" ); if (generated == null) { if (!notGeneratedClassNames.Contains(classIdentifier)) { GlobalLogger.Warning( $"Was not found in AST. Adding to Shim Generation List. classIdentifier: {classIdentifier}" ); notGeneratedClassNames.Add( classIdentifier ); } continue; } generatedStatements.Add(generated); // Add Used Classes and add Generated List var usesClasses = GetAllUsedClasses(generated); var toGenerateList = new List <string>(); foreach (var className in usesClasses) { if (!generatedStatements.Any(a => a.Name == className)) { toGenerateList.Add(className); } } generatedStatements = GenerateClassFromList( ast, projectAssembly, toGenerateList, notGeneratedClassNames, typeOverrideMap, generatedStatements ); } return(generatedStatements); }
private static int GenerateSources( IList <string> source, IList <string> classToGenerate, string projectAssembly = "Generated.WASM", string projectGenerationLocation = "_generated", bool force = false ) { try { var stopwatch = Stopwatch.StartNew(); ValidateArguments( source, classToGenerate, projectAssembly, projectGenerationLocation ); GlobalLogger.Info($"projectAssembly: {projectAssembly}"); GlobalLogger.Info($"projectGenerationLocation: {projectGenerationLocation}"); GlobalLogger.Info($"classToGenerate.Length: {classToGenerate.Count}"); foreach (var classToGenerateItem in classToGenerate) { GlobalLogger.Info($"classToGenerateItem: {classToGenerateItem}"); } GlobalLogger.Info($"sourceFile.Length: {source.Count}"); foreach (var sourceFileItem in source) { GlobalLogger.Info($"sourceFile: {sourceFileItem}"); } projectGenerationLocation = Path.Combine( ".", projectGenerationLocation ); var sourceDirectory = Path.Combine( ".", SOURCE_FILES_DIRECTORY_NAME ); var sourceFiles = CopyAndDownloadSourceFiles( source ); var generationList = classToGenerate; // Check for already Generated Source. var projectAssemblyDirectory = Path.Combine( projectGenerationLocation, projectAssembly ); if (Directory.Exists( projectAssemblyDirectory )) { if (!force) { GlobalLogger.Error( $"Project Assembly Directory was not empty: {projectAssemblyDirectory}" ); GlobalLogger.Error( $"Use --force to replace directory." ); return(502); } GlobalLogger.Warning( $"Deleting existing projectAssemblyDirectory: {projectAssemblyDirectory}" ); Directory.Delete( projectAssemblyDirectory, true ); } var textFormatter = new NoFormattingTextFormatter(); var writer = new ProjectWriter( projectGenerationLocation, projectAssembly ); new GenerateSource().Run( projectAssembly, sourceDirectory, sourceFiles, generationList, writer, textFormatter, new Dictionary <string, string> { { "BABYLON.PointerInfoBase | type", "int" } } ); stopwatch.Stop(); GlobalLogger.Success($"Took {stopwatch.ElapsedMilliseconds}ms to Generate Source Project."); return(0); } catch (ArgumentException ex) { GlobalLogger.Error( $"Argument failure: {ex.ParamName} -> {ex.Message}" ); return(404); } catch (InvalidSourceFileException ex) { GlobalLogger.Error( $"Invalid Source File Exception: {ex.Message}" ); return(501); } }