public void Store( ITypeInfoContainer typeInfoContainer, ProjectBindContainerXml projectXml ) { if (typeInfoContainer is null) { throw new ArgumentNullException(nameof(typeInfoContainer)); } if (projectXml is null) { throw new ArgumentNullException(nameof(projectXml)); } var sb = new StringBuilder(); foreach (var line in projectXml.GetXml().Split(new [] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) { sb.Append(SingleLineComment); sb.AppendLine(line); } var xml = sb.ToString(); typeInfoContainer.AddAdditionalFile(xml); }
public ExplicitBindExpressionFactory( ITypeInfoContainer typeInfoContainer, SemanticModelDecorator semanticModel, ConstructorArgumentFromSyntaxExtractor extractor, ConstructorArgumentDetector constructorArgumentDetector ) { if (typeInfoContainer is null) { throw new ArgumentNullException(nameof(typeInfoContainer)); } if (semanticModel is null) { throw new ArgumentNullException(nameof(semanticModel)); } if (extractor is null) { throw new ArgumentNullException(nameof(extractor)); } if (constructorArgumentDetector is null) { throw new ArgumentNullException(nameof(constructorArgumentDetector)); } _typeInfoContainer = typeInfoContainer; _semanticModel = semanticModel; _extractor = extractor; _constructorArgumentDetector = constructorArgumentDetector; }
public STCParsedBindExpression( ITypeInfoContainer typeInfoContainer, ConstructorArgumentFromSyntaxExtractor extractor, ConstructorArgumentDetector constructorArgumentDetector, ExpressionStatementSyntax expressionNode, List <Tuple <InvocationExpressionSyntax, IMethodSymbol> > invocationSymbols, in ImmutableArray <ITypeSymbol> fromTypes,
public ConventionalBindExpressionFactory( ITypeInfoContainer typeInfoContainer, ConstructorArgumentFromSyntaxExtractor extractor, ConstructorArgumentDetector constructorArgumentDetector, IDiagnosticReporter diagnosticReporter ) { if (typeInfoContainer is null) { throw new ArgumentNullException(nameof(typeInfoContainer)); } if (extractor is null) { throw new ArgumentNullException(nameof(extractor)); } if (constructorArgumentDetector is null) { throw new ArgumentNullException(nameof(constructorArgumentDetector)); } if (diagnosticReporter is null) { throw new ArgumentNullException(nameof(diagnosticReporter)); } _typeInfoContainer = typeInfoContainer; _extractor = extractor; _constructorArgumentDetector = constructorArgumentDetector; _diagnosticReporter = diagnosticReporter; }
public void Execute( ITypeInfoContainer typeInfoContainer, string?generatedFolder ) { using (new DTimer(_diagnosticReporter, "Dpdt total time taken")) { ExecutePrivate( typeInfoContainer, generatedFolder ); } }
private void DoGenerateBindingSourceCode( ITypeInfoContainer typeInfoContainer, IReadOnlyList <ClusterMethodBindings> clusterMethodBindings ) { if (typeInfoContainer is null) { throw new ArgumentNullException(nameof(typeInfoContainer)); } if (clusterMethodBindings is null) { throw new ArgumentNullException(nameof(clusterMethodBindings)); } var srIndex = 0; foreach (var clusterMethodBinding in clusterMethodBindings) { var clusterBindings = clusterMethodBinding.GetClusterBindings( ); clusterBindings.BuildFlags( ); clusterBindings.Analyze( _diagnosticReporter ); //build the cluster: var clusterProducer = new ClusterProducer( typeInfoContainer, clusterBindings, _doBeautify ); var moduleSourceCode = clusterProducer.Produce( clusterMethodBinding.ModuleUnitUsings ); var modificationDescription = new ModificationDescription( clusterMethodBinding.ClusterType, $"{clusterMethodBinding.ClusterType.Name}.Pregenerated{srIndex}.cs", moduleSourceCode ); typeInfoContainer.AddSources(new[] { modificationDescription }); srIndex++; } }
public virtual List<object> GetAnalysisDataList(Type targetObjectType) { List<object> cachedReports; if (analysisCache.TryGetValue(targetObjectType, out cachedReports)) { return cachedReports; } _typeInfoContainer = (ITypeInfoContainer)Application.Modules.Where(@base => typeof(ITypeInfoContainer).IsAssignableFrom(@base.GetType())).Single(); using (var objectSpace = Application.CreateObjectSpace()) { List<string> targetObjectTypeNames = GetTargetObjectTypeNames(targetObjectType); var result = new List<object>(); if (targetObjectTypeNames.Count > 0) { IList reports = objectSpace.CreateCollection(_typeInfoContainer.TypesInfo.AnalysisType, new InOperator("DataType", targetObjectTypeNames)); result.AddRange(reports.Cast<object>().Select(report => objectSpace.GetKeyValue(report))); } analysisCache.Add(targetObjectType, result); return result; } }
public void Execute( ITypeInfoContainer typeInfoContainer ) { if (typeInfoContainer is null) { throw new ArgumentNullException(nameof(typeInfoContainer)); } var clusterMethodBindings = DoExtraction( typeInfoContainer ); DoGenerateXml( typeInfoContainer, clusterMethodBindings ); DoGenerateBindingSourceCode(typeInfoContainer, clusterMethodBindings); }
public virtual List <object> GetAnalysisDataList(Type targetObjectType) { List <object> cachedReports; if (analysisCache.TryGetValue(targetObjectType, out cachedReports)) { return(cachedReports); } _typeInfoContainer = (ITypeInfoContainer)Application.Modules.Single(@base => @base is ITypeInfoContainer); using (var objectSpace = Application.CreateObjectSpace(_typeInfoContainer.TypesInfo.AnalysisType)) { List <string> targetObjectTypeNames = GetTargetObjectTypeNames(targetObjectType); var result = new List <object>(); if (targetObjectTypeNames.Count > 0) { IList reports = objectSpace.CreateCollection(_typeInfoContainer.TypesInfo.AnalysisType, new InOperator("ObjectTypeName", targetObjectTypeNames)); result.AddRange(reports.Cast <object>().Select(objectSpace.GetKeyValue)); } analysisCache.Add(targetObjectType, result); return(result); } }
private void ExecutePrivate( ITypeInfoContainer typeInfoContainer, string?generatedFolder ) { if (typeInfoContainer is null) { throw new ArgumentNullException(nameof(typeInfoContainer)); } var scanner = new TimedTypeScanner( _diagnosticReporter, new DefaultTypeScanner( ) ); var clusterTypes = scanner.Scan( typeInfoContainer ); for (var clusterTypeIndex = 0; clusterTypeIndex < clusterTypes.Count; clusterTypeIndex++) { var clusterType = clusterTypes[clusterTypeIndex]; MethodDeclarationSyntax loadMethodSyntax; CompilationUnitSyntax? compilationUnitSyntax; using (new DTimer(_diagnosticReporter, "unsorted time taken")) { var loadMethods = clusterType.GetMembers(nameof(DefaultCluster.Load)); if (loadMethods.Length != 1) { throw new Exception($"Something wrong with type {clusterType.ToDisplayString()}"); } var loadMethod = loadMethods[0]; var loadMethodRefs = loadMethod.DeclaringSyntaxReferences; if (loadMethodRefs.Length != 1) { throw new Exception($"Something wrong with method {loadMethod.ToDisplayString()} : {loadMethodRefs.Length}"); } var loadMethodRef = loadMethodRefs[0]; loadMethodSyntax = (MethodDeclarationSyntax)loadMethodRef.GetSyntax(); compilationUnitSyntax = loadMethodSyntax.Root <CompilationUnitSyntax>(); } if (compilationUnitSyntax == null) { throw new DpdtException( DpdtExceptionTypeEnum.InternalError, $"Unknown problem to access to compilation unit syntax" ); } var bindExtractor = new TimedBindExtractor( _diagnosticReporter, new DefaultBindExtractor( typeInfoContainer, compilationUnitSyntax ) ); bindExtractor.Visit(loadMethodSyntax); var clusterBindings = bindExtractor.GetClusterBindings( clusterType ); clusterBindings.BuildFlags( ); clusterBindings.Analyze( _diagnosticReporter ); var factoryProducer = new FactoryProducer( typeInfoContainer, clusterBindings ); foreach (var factoryProduct in factoryProducer.Produce()) { var fileName = $"{factoryProduct.FactoryType.ToDisplayString().EscapeSpecialTypeSymbols()}.Pregenerated.cs"; ModificationDescription factoryModificationDescription; using (new DTimer(_diagnosticReporter, $"Dpdt factory {factoryProduct.FactoryType.ToDisplayString()} beautify generated code time taken")) { factoryModificationDescription = new ModificationDescription( clusterType, fileName, factoryProduct.SourceCode, generatedFolder is not null ); } if (generatedFolder is not null) { var generatedFilePath = Path.Combine(generatedFolder, fileName); factoryModificationDescription.SaveToDisk( generatedFilePath ); } typeInfoContainer.AddSource(factoryModificationDescription); } var clusterProducer = new ClusterProducer( typeInfoContainer, clusterBindings ); var moduleSourceCode = clusterProducer.Produce(); ModificationDescription modificationDescription; using (new DTimer(_diagnosticReporter, "Dpdt cluster beautify generated code time taken")) { modificationDescription = new ModificationDescription( clusterType, clusterType.Name + Guid.NewGuid().RemoveMinuses() + "_1.cs", moduleSourceCode, generatedFolder is not null ); } if (generatedFolder is not null) { var generatedFilePath = Path.Combine(generatedFolder, $"{clusterType.Name}.Pregenerated{clusterTypeIndex}.cs"); modificationDescription.SaveToDisk( generatedFilePath ); } typeInfoContainer.AddSource(modificationDescription); } }
public IReadOnlyList <ClusterMethodBindings> DoExtraction( ITypeInfoContainer typeInfoContainer ) { if (typeInfoContainer is null) { throw new ArgumentNullException(nameof(typeInfoContainer)); } var scanner = new DefaultTypeScanner( ); var clusterTypes = scanner.ScanForClusterTypes( typeInfoContainer ); var stepResults = new List <ClusterMethodBindings>(); for (var clusterTypeIndex = 0; clusterTypeIndex < clusterTypes.Count; clusterTypeIndex++) { var clusterType = clusterTypes[clusterTypeIndex]; clusterType.ScanForRequiredSyntaxes( out List <MethodDeclarationSyntax> bindMethodSyntaxes, out List <CompilationUnitSyntax> compilationUnitSyntaxes ); if (compilationUnitSyntaxes.Count == 0) { throw new DpdtException( DpdtExceptionTypeEnum.InternalError, $"Unknown problem to access to compilation unit syntax" ); } var semanticModels = new List <SemanticModel>(); var moduleUnitUsings = new List <UsingDirectiveSyntax>(); foreach (var compilationUnitSyntax in compilationUnitSyntaxes) { var moduleUnitUsing = compilationUnitSyntax .DescendantNodes() .OfType <UsingDirectiveSyntax>() .ToList(); moduleUnitUsings.AddRange(moduleUnitUsing); var semanticModel = typeInfoContainer.GetSemanticModel(compilationUnitSyntax.SyntaxTree); semanticModels.Add(semanticModel); } var semanticModelDecorator = new SemanticModelDecorator( semanticModels ); var stepResult = new ClusterMethodBindings( clusterType, moduleUnitUsings ); foreach (var bindMethodSyntax in bindMethodSyntaxes) { var bindExtractor = new BindClauseExtractor( semanticModelDecorator, new DetermineBindExpressionFactory( new ExplicitBindExpressionFactory( typeInfoContainer, semanticModelDecorator, new ConstructorArgumentFromSyntaxExtractor( semanticModelDecorator ), new ConstructorArgumentDetector( BindConstructorChooser.Instance ) ), new ConventionalBindExpressionFactory( typeInfoContainer, new ConstructorArgumentFromSyntaxExtractor( semanticModelDecorator ), new ConstructorArgumentDetector( BindConstructorChooser.Instance ), _diagnosticReporter ) ) ); bindExtractor.Visit(bindMethodSyntax); stepResult.AddMethodBindings( bindMethodSyntax, bindExtractor.BindingContainers ); } stepResults.Add(stepResult); } return(stepResults); }
private void DoGenerateXml( ITypeInfoContainer typeInfoContainer, IReadOnlyList <ClusterMethodBindings> clusterMethodBindings ) { if (typeInfoContainer is null) { throw new ArgumentNullException(nameof(typeInfoContainer)); } if (clusterMethodBindings is null) { throw new ArgumentNullException(nameof(clusterMethodBindings)); } #region create xml representation var clusterXmls = new List <ClusterBindContainerXml>(); foreach (var clusterMethodBinding in clusterMethodBindings) { var clusterType = clusterMethodBinding.ClusterType; var clusterTypeXml = clusterType.ToXml(); var methodBindXmls = new List <MethodBindContainerXml>(); foreach (var methodBinding in clusterMethodBinding.MethodBindings) { var methodDeclaration = methodBinding.Item1; var methodDeclarationXml = new MethodDeclarationInfoXml( methodDeclaration.ToXml(), methodDeclaration.Identifier.Text ); var methodBindXml = new MethodBindContainerXml( clusterTypeXml, methodDeclarationXml, methodBinding.Item2.ConvertAll( bc => new BindingXml( bc.UniqueUnstableIdentifier.ToString(), bc.TargetRepresentation, bc.BindFromTypes.ConvertAll(s => s.ToXml()).ToArray(), bc.BindToType.ToXml(), bc.ConstructorArguments.ToXml(), bc.Scope.ToString(), (int)bc.Scope, bc.IsConditional, bc.IsConventional, bc.ExpressionNode.ToXml() ) ).ToArray() ); methodBindXmls.Add(methodBindXml); } var clusterXml = new ClusterBindContainerXml( clusterTypeXml, methodBindXmls.ToArray() ); clusterXmls.Add(clusterXml); } var projectXml = new ProjectBindContainerXml( clusterXmls.ToArray() ); #endregion var meta = new BuiltinMeta(); meta.Store( typeInfoContainer, projectXml ); }