private TypeOrNamespaceModuleLiteral DoInstantiate(ModuleRegistry moduleRegistry, TypeOrNamespaceModuleLiteral module, QualifierValue qualifier, FileModuleLiteral outerScope) { Contract.Requires(module != null); Contract.Requires(qualifier != QualifierValue.Unqualified); Interlocked.CompareExchange(ref m_qualifier, qualifier, QualifierValue.Unqualified); // The outer scope of this should have the same qualifier. So if that's not the case we instantiate one and set the parent appropriately if (outerScope.Qualifier.QualifierId != qualifier.QualifierId) { var newOuterScope = moduleRegistry.InstantiateModule( (outerScope, moduleRegistry, qualifier), QualifiedModuleId.Create(outerScope.Id, qualifier.QualifierId), (state, qualifiedModuleId) => { var capturedOuterScope = state.outerScope; var capturedModuleRegistry = state.moduleRegistry; var capturedQualifier = state.qualifier; return(capturedOuterScope.InstantiateFileModuleLiteral(capturedModuleRegistry, capturedQualifier)); }); return(new TypeOrNamespaceModuleLiteral(module.Id, qualifier, newOuterScope, module.Location)); } if (m_qualifier.QualifierId == qualifier.QualifierId) { // Uninstantiated module becomes the first instance. return(this); } // Create a new file module instance. return(new TypeOrNamespaceModuleLiteral(module.Id, qualifier, outerScope, module.Location)); }
/// <nodoc /> public override ModuleLiteral Instantiate(ModuleRegistry moduleRegistry, QualifierValue qualifier) { Contract.Assert(moduleRegistry != null); Contract.Assert(qualifier != QualifierValue.Unqualified); // Due to sharing the following contract no longer holds: Contract.Requires(Qualifier == Unqualified); var moduleKey = QualifiedModuleId.Create(Id, qualifier.QualifierId); return(moduleRegistry.InstantiateModule( (moduleRegistry, @this: this, qualifier, CurrentFileModule), moduleKey, (state, k) => { var localModuleRegistry = state.moduleRegistry; var @this = state.@this; var localQualifier = state.qualifier; var localCurrentFileModule = state.CurrentFileModule; return @this.DoInstantiate(localModuleRegistry, @this, localQualifier, localCurrentFileModule); })); }
/// <summary> /// Instantiates this file module for with a given qualifier. /// </summary> public override ModuleLiteral Instantiate(ModuleRegistry moduleRegistry, QualifierValue qualifier) { Contract.Assert(moduleRegistry != null); Contract.Assert(qualifier != QualifierValue.Unqualified); // Due to sharing the following contract no longer holds: Contract.Requires(Qualifier == Unqualified); var moduleKey = QualifiedModuleId.Create(Id, qualifier.QualifierId); var globalOuterScope = OuterScope as GlobalModuleLiteral; Contract.Assert(globalOuterScope != null, "For a FileModuleLiteral, the outer scope should be always a global module literal"); return(moduleRegistry.InstantiateModule((this, qualifier, globalOuterScope), moduleKey, (state, k) => { // Avoid closure allocation. var @this = state.Item1; var capturedQualifier = state.Item2; var capturedGlobalOuterScope = state.Item3; return @this.DoInstantiate(@this, capturedQualifier, capturedGlobalOuterScope); })); }