public MutableObjectBase GetModelObject(MutableObjectBase parentObject, MutableModel model, DiagnosticBag diagnostics) { if (_modelObject == null) { lock (this) // We must lock, we do not want to create multiple symbols for the same declaration { if (_modelObject != null) { return(_modelObject); } var modelObject = this.Kind.CreateMutable(model); modelObject.MName = this.Name; if (parentObject != null && !string.IsNullOrEmpty(this.ParentPropertyToAddTo)) { var property = parentObject.MGetProperty(this.ParentPropertyToAddTo); if (property != null) { try { parentObject.MAdd(property, modelObject); } catch (ModelException me) { diagnostics.Add(ModelErrorCode.ERR_CannotSetValueToProperty, this.NameLocations[0], property, modelObject, me.ToString()); } } } Interlocked.CompareExchange(ref _modelObject, modelObject, null); } } return(_modelObject); }
public SourceMemberContainerTypeSymbol( DeclaredSymbol containingSymbol, MergedDeclaration declaration, DiagnosticBag diagnostics) { _containingSymbol = containingSymbol; _declaration = declaration; if (declaration.Kind != null) { _modelObject = declaration.GetModelObject(containingSymbol?.ModelObject as MutableObjectBase, containingSymbol.ModelBuilder, diagnostics); Debug.Assert(_modelObject != null); } foreach (var singleDeclaration in declaration.Declarations) { diagnostics.AddRange(singleDeclaration.Diagnostics); } _state = SymbolCompletionState.Create(containingSymbol.Language); }
public SourceNamespaceSymbol( SourceModuleSymbol module, Symbol container, MergedDeclaration declaration, DiagnosticBag diagnostics) { Debug.Assert(declaration != null); _module = module; _container = container; _declaration = declaration; if (declaration.Kind != null) { _modelObject = declaration.GetModelObject(container?.ModelObject as MutableObjectBase, module.ModelBuilder, diagnostics); Debug.Assert(_modelObject != null); } foreach (var singleDeclaration in declaration.Declarations) { diagnostics.AddRange(singleDeclaration.Diagnostics); } _state = SymbolCompletionState.Create(module.Language); }