internal AssemblyReference(AssemblySymbol assemblySymbol) { Debug.Assert((object)assemblySymbol != null); _targetAssembly = assemblySymbol; }
internal void CreateSourceAssemblyForCompilation(PhpCompilation compilation) { if (compilation._lazyAssemblySymbol != null) return; // TODO: lock Debug.Assert(_lazyExplicitReferences.IsDefault); Debug.Assert(_lazyCorLibrary == null); Debug.Assert(_lazyPhpCorLibrary == null); // var externalRefs = CorLibReferences.SelectMany(reference => compilation.Options.MetadataReferenceResolver.ResolveReference(reference, null, new MetadataReferenceProperties())) .Concat(compilation.ExternalReferences).AsImmutable(); var assemblies = new List<AssemblySymbol>(externalRefs.Length); var referencesMap = new Dictionary<MetadataReference, IAssemblySymbol>(); var metadataMap = new Dictionary<IAssemblySymbol, MetadataReference>(); var assembliesMap = new Dictionary<AssemblyIdentity, PEAssemblySymbol>(); var refmodules = new List<PEModuleSymbol>(); foreach (PortableExecutableReference pe in externalRefs) { var symbol = PEAssemblySymbol.Create(pe); if (symbol != null) { assemblies.Add(symbol); referencesMap[pe] = symbol; metadataMap[symbol] = pe; if (_lazyCorLibrary == null && symbol.IsCorLibrary) _lazyCorLibrary = symbol; if (_lazyPhpCorLibrary == null && symbol.IsPchpCorLibrary) _lazyPhpCorLibrary = symbol; // cache bound assembly symbol _assembliesMap.Add(symbol.Identity, symbol); // list of modules to initialize later refmodules.AddRange(symbol.Modules.Cast<PEModuleSymbol>()); } else { throw new Exception($"symbol '{pe.FilePath}' could not be created!"); } } // _lazyExplicitReferences = externalRefs; _lazyImplicitReferences = ImmutableArray<MetadataReference>.Empty; _metadataMap = metadataMap.ToImmutableDictionary(); _referencesMap = referencesMap.ToImmutableDictionary(); // var assembly = new SourceAssemblySymbol(compilation, compilation.Options.ModuleName, compilation.Options.ModuleName); assembly.SetCorLibrary(_lazyCorLibrary); compilation._lazyAssemblySymbol = assembly; assembly.SourceModule.SetReferences(new ModuleReferences<AssemblySymbol>( assemblies.Select(x => x.Identity).AsImmutable(), assemblies.AsImmutable(), ImmutableArray<UnifiedAssembly<AssemblySymbol>>.Empty), assembly); assemblies.ForEach(ass => ass.SetCorLibrary(_lazyCorLibrary)); // recursively initialize references of referenced modules SetReferencesOfReferencedModules(compilation.Options.MetadataReferenceResolver, refmodules); // set cor types for this compilation if (_lazyPhpCorLibrary == null) throw new DllNotFoundException("Peachpie.Runtime not found"); if (_lazyCorLibrary == null) throw new DllNotFoundException("A corlib not found"); compilation.CoreTypes.Update(_lazyPhpCorLibrary); compilation.CoreTypes.Update(_lazyCorLibrary); }
void SetReferencesOfReferencedModules(MetadataReferenceResolver resolver, List<PEModuleSymbol> modules) { for (int i = 0; i < modules.Count; i++) { var refs = modules[i].Module.ReferencedAssemblies; var symbols = new AssemblySymbol[refs.Length]; for (int j = 0; j < refs.Length; j++) { var symbol = CreateAssemblyFromIdentity(resolver, refs[j], null, modules); symbols[j] = symbol; } // modules[i].SetReferences(new ModuleReferences<AssemblySymbol>(refs, symbols.AsImmutable(), ImmutableArray<UnifiedAssembly<AssemblySymbol>>.Empty)); } }
/// <summary> /// A helper method for ReferenceManager to set the system assembly, which provides primitive /// types like Object, String, etc., e.g. mscorlib.dll. /// </summary> internal void SetCorLibrary(AssemblySymbol corLibrary) { Debug.Assert((object)_corLibrary == null || (object)_corLibrary == corLibrary); _corLibrary = corLibrary; }
/// <summary> /// A helper method for ReferenceManager to set the system assembly, which provides primitive /// types like Object, String, etc., e.g. mscorlib.dll. /// </summary> internal void SetCorLibrary(AssemblySymbol corLibrary) { Debug.Assert((object)_corLibrary == null); _corLibrary = corLibrary; }
private void ValidateReferencedAssembly(AssemblySymbol assembly, AssemblyReference asmRef, DiagnosticBag diagnostics) { //AssemblyIdentity asmIdentity = SourceModule.ContainingAssembly.Identity; //AssemblyIdentity refIdentity = asmRef.MetadataIdentity; //if (asmIdentity.IsStrongName && !refIdentity.IsStrongName && // ((Cci.IAssemblyReference)asmRef).ContentType != System.Reflection.AssemblyContentType.WindowsRuntime) //{ // // Dev12 reported error, we have changed it to a warning to allow referencing libraries // // built for platforms that don't support strong names. // diagnostics.Add(new CSDiagnosticInfo(ErrorCode.WRN_ReferencedAssemblyDoesNotHaveStrongName, assembly), NoLocation.Singleton); //} //if (OutputKind != OutputKind.NetModule && // !string.IsNullOrEmpty(refIdentity.CultureName) && // !string.Equals(refIdentity.CultureName, asmIdentity.CultureName, StringComparison.OrdinalIgnoreCase)) //{ // diagnostics.Add(new CSDiagnosticInfo(ErrorCode.WRN_RefCultureMismatch, assembly, refIdentity.CultureName), NoLocation.Singleton); //} //var refMachine = assembly.Machine; //// If other assembly is agnostic this is always safe //// Also, if no mscorlib was specified for back compat we add a reference to mscorlib //// that resolves to the current framework directory. If the compiler is 64-bit //// this is a 64-bit mscorlib, which will produce a warning if /platform:x86 is //// specified. A reference to the default mscorlib should always succeed without //// warning so we ignore it here. //if ((object)assembly != (object)assembly.CorLibrary && // !(refMachine == Machine.I386 && !assembly.Bit32Required)) //{ // var machine = SourceModule.Machine; // if (!(machine == Machine.I386 && !SourceModule.Bit32Required) && // machine != refMachine) // { // // Different machine types, and neither is agnostic // diagnostics.Add(new CSDiagnosticInfo(ErrorCode.WRN_ConflictingMachineAssembly, assembly), NoLocation.Singleton); // } //} //if (_embeddedTypesManagerOpt != null && _embeddedTypesManagerOpt.IsFrozen) //{ // _embeddedTypesManagerOpt.ReportIndirectReferencesToLinkedAssemblies(assembly, diagnostics); //} }