| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 2 | |
| 3 | namespace WixToolset.Core.Link |
| 4 | { |
| 5 | using System; |
| 6 | using System.Collections.Generic; |
| 7 | using System.Diagnostics; |
| 8 | using System.Linq; |
| 9 | using WixToolset.Data; |
| 10 | using WixToolset.Data.Symbols; |
| 11 | |
| 12 | /// <summary> |
| 13 | /// Symbol with section representing a single unique symbol. |
| 14 | /// </summary> |
| 15 | [DebuggerDisplay("{Symbol.DebuggerDisplay}")] |
| 16 | internal class SymbolWithSection |
| 17 | { |
| 18 | private List<WixSimpleReferenceSymbol> directReferences; |
| 19 | private HashSet<SymbolWithSection> possibleConflicts; |
| 20 | |
| 21 | /// <summary> |
| 22 | /// Creates a symbol for a symbol. |
| 23 | /// </summary> |
| 24 | /// <param name="section"></param> |
| 25 | /// <param name="symbol">Symbol for the symbol</param> |
| 26 | public SymbolWithSection(IntermediateSection section, IntermediateSymbol symbol) |
| 27 | { |
| 28 | this.Symbol = symbol; |
| 29 | this.Section = section; |
| 30 | } |
| 31 | |
| 32 | /// <summary> |
| 33 | /// Gets the accessibility of the symbol which is a direct reflection of the accessibility of the row's accessibility. |
| 34 | /// </summary> |
| 35 | /// <value>Accessbility of the symbol.</value> |
| 36 | public AccessModifier Access => this.Symbol.Id.Access; |
| 37 | |
| 38 | /// <summary> |
| 39 | /// Gets the symbol for this symbol. |
| 40 | /// </summary> |
| 41 | /// <value>Symbol for this symbol.</value> |
| 42 | public IntermediateSymbol Symbol { get; } |
| 43 | |
| 44 | /// <summary> |
| 45 | /// Gets the section for the symbol. |
| 46 | /// </summary> |
| 47 | /// <value>Section for the symbol.</value> |
| 48 | public IntermediateSection Section { get; } |
| 49 | |
| 50 | /// <summary> |
| 51 | /// Gets any duplicates of this symbol with sections that are possible conflicts. |
| 52 | /// </summary> |
| 53 | public IEnumerable<WixSimpleReferenceSymbol> DirectReferences => this.directReferences ?? Enumerable.Empty<WixSimpleReferenceSymbol>(); |
| 54 | |
| 55 | /// <summary> |
| 56 | /// Gets any duplicates of this symbol with sections that are possible conflicts. |
| 57 | /// </summary> |
| 58 | public IEnumerable<SymbolWithSection> PossiblyConflicts => this.possibleConflicts ?? Enumerable.Empty<SymbolWithSection>(); |
| 59 | |
| 60 | /// <summary> |
| 61 | /// Gets the virtual symbol that is overridden by this symbol. |
| 62 | /// </summary> |
| 63 | public SymbolWithSection Overrides { get; private set; } |
| 64 | |
| 65 | /// <summary> |
| 66 | /// Adds a duplicate symbol with sections that is a possible conflict. |
| 67 | /// </summary> |
| 68 | /// <param name="symbolWithSection">Symbol with section that is a possible conflict of this symbol.</param> |
| 69 | public void AddPossibleConflict(SymbolWithSection symbolWithSection) |
| 70 | { |
| 71 | if (null == this.possibleConflicts) |
| 72 | { |
| 73 | this.possibleConflicts = new HashSet<SymbolWithSection>(); |
| 74 | } |
| 75 | |
| 76 | this.possibleConflicts.Add(symbolWithSection); |
| 77 | } |
| 78 | |
| 79 | /// <summary> |
| 80 | /// Adds a reference that directly points to this symbol. |
| 81 | /// </summary> |
| 82 | /// <param name="reference">The direct reference.</param> |
| 83 | public void AddDirectReference(WixSimpleReferenceSymbol reference) |
| 84 | { |
| 85 | if (null == this.directReferences) |
| 86 | { |
| 87 | this.directReferences = new List<WixSimpleReferenceSymbol>(); |
| 88 | } |
| 89 | |
| 90 | this.directReferences.Add(reference); |
| 91 | } |
| 92 | |
| 93 | /// <summary> |
| 94 | /// Override a virtual symbol. |
| 95 | /// </summary> |
| 96 | /// <param name="virtualSymbolWithSection">Virtual symbol with section that is being overridden.</param> |
| 97 | public void OverrideVirtualSymbol(SymbolWithSection virtualSymbolWithSection) |
| 98 | { |
| 99 | if (virtualSymbolWithSection.Access != AccessModifier.Virtual) |
| 100 | { |
| 101 | throw new InvalidOperationException("Cannot override non-virtual symbols"); |
| 102 | } |
| 103 | |
| 104 | this.Overrides = virtualSymbolWithSection; |
| 105 | } |
| 106 | |
| 107 | /// <summary> |
| 108 | /// Gets the full name of the symbol. |
| 109 | /// </summary> |
| 110 | public string GetFullName() |
| 111 | { |
| 112 | return String.Concat(this.Symbol.Definition.Name, ":", this.Symbol.Id.Id); |
| 113 | } |
| 114 | } |
| 115 | } |