private async Task RegisterAttributesAsync(CancellationToken cancellationToken = default(CancellationToken)) { using (new LogHelper("loading attributes from project", Log, 3)) { var attributeLoader = new AttributeLoader(Compilation); await attributeLoader.LoadAsync(cancellationToken); Attributes = attributeLoader.Attributes; Compilation = attributeLoader.Compilation; } }
public CompilerExtensionInterpreter(AttributeRegistry attributes, SemanticModel semanticModel, BlockSyntax body) { Attributes = attributes; _semanticModel = semanticModel; _body = body; _variables = new Dictionary <string, AttributeBuilderDetails>(); AttributesBuilderType = semanticModel.Compilation.GetTypeByMetadataName("Phase.CompilerServices.IAttributesBuilder"); AttributesContextType = semanticModel.Compilation.GetTypeByMetadataName("Phase.CompilerServices.IAttributesContext"); _attributeTargetType = semanticModel.Compilation.GetTypeByMetadataName("Phase.CompilerServices.AttributeTarget"); }
public async Task LoadAsync(CancellationToken cancellationToken) { _cancellationToken = cancellationToken; // add all compiler extensions to the project var trees = new ConcurrentBag <SyntaxTree>(); Parallel.ForEach(Compilation.References.OfType <PortableExecutableReference>(), r => { foreach (var source in LoadCompilerExtensionsFromAssembly(r.FilePath)) { try { trees.Add(CSharpSyntaxTree.ParseText(source.source, CSharpParseOptions.Default.WithLanguageVersion(Compilation.LanguageVersion))); } catch (Exception e) { Log.Error(e, "Failed to parse C# source from resource {0} in assembly {1}", source.name, r.FilePath); } } }); var assemblyName = Compilation.AssemblyName.EndsWith(".dll") ? Compilation.AssemblyName.Substring(0, Compilation.AssemblyName.Length - 4) : Compilation.AssemblyName; Compilation = Compilation .AddSyntaxTrees(trees) .WithAssemblyName(assemblyName); _semanticModel = new ConcurrentDictionary <SyntaxTree, SemanticModel>(SyntaxTreeComparer.Instance); Attributes = new AttributeRegistry(); LoadAttributes(Compilation, cancellationToken); foreach (var reference in Compilation.References.OfType <CompilationReference>()) { LoadAttributes(reference.Compilation, cancellationToken); } Attributes = Attributes; }