aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Link/ResolveReferencesCommand.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/Link/ResolveReferencesCommand.cs')
-rw-r--r--src/WixToolset.Core/Link/ResolveReferencesCommand.cs104
1 files changed, 52 insertions, 52 deletions
diff --git a/src/WixToolset.Core/Link/ResolveReferencesCommand.cs b/src/WixToolset.Core/Link/ResolveReferencesCommand.cs
index 4ffb5443..d2be0699 100644
--- a/src/WixToolset.Core/Link/ResolveReferencesCommand.cs
+++ b/src/WixToolset.Core/Link/ResolveReferencesCommand.cs
@@ -6,7 +6,7 @@ namespace WixToolset.Core.Link
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.Linq; 7 using System.Linq;
8 using WixToolset.Data; 8 using WixToolset.Data;
9 using WixToolset.Data.Tuples; 9 using WixToolset.Data.Symbols;
10 using WixToolset.Extensibility.Services; 10 using WixToolset.Extensibility.Services;
11 11
12 /// <summary> 12 /// <summary>
@@ -15,19 +15,19 @@ namespace WixToolset.Core.Link
15 internal class ResolveReferencesCommand 15 internal class ResolveReferencesCommand
16 { 16 {
17 private readonly IntermediateSection entrySection; 17 private readonly IntermediateSection entrySection;
18 private readonly IDictionary<string, TupleWithSection> tuplesWithSections; 18 private readonly IDictionary<string, SymbolWithSection> symbolsWithSections;
19 private HashSet<TupleWithSection> referencedTuples; 19 private HashSet<SymbolWithSection> referencedSymbols;
20 private HashSet<IntermediateSection> resolvedSections; 20 private HashSet<IntermediateSection> resolvedSections;
21 21
22 public ResolveReferencesCommand(IMessaging messaging, IntermediateSection entrySection, IDictionary<string, TupleWithSection> tuplesWithSections) 22 public ResolveReferencesCommand(IMessaging messaging, IntermediateSection entrySection, IDictionary<string, SymbolWithSection> symbolsWithSections)
23 { 23 {
24 this.Messaging = messaging; 24 this.Messaging = messaging;
25 this.entrySection = entrySection; 25 this.entrySection = entrySection;
26 this.tuplesWithSections = tuplesWithSections; 26 this.symbolsWithSections = symbolsWithSections;
27 this.BuildingMergeModule = (SectionType.Module == entrySection.Type); 27 this.BuildingMergeModule = (SectionType.Module == entrySection.Type);
28 } 28 }
29 29
30 public IEnumerable<TupleWithSection> ReferencedTupleWithSections => this.referencedTuples; 30 public IEnumerable<SymbolWithSection> ReferencedSymbolWithSections => this.referencedSymbols;
31 31
32 public IEnumerable<IntermediateSection> ResolvedSections => this.resolvedSections; 32 public IEnumerable<IntermediateSection> ResolvedSections => this.resolvedSections;
33 33
@@ -41,7 +41,7 @@ namespace WixToolset.Core.Link
41 public void Execute() 41 public void Execute()
42 { 42 {
43 this.resolvedSections = new HashSet<IntermediateSection>(); 43 this.resolvedSections = new HashSet<IntermediateSection>();
44 this.referencedTuples = new HashSet<TupleWithSection>(); 44 this.referencedSymbols = new HashSet<SymbolWithSection>();
45 45
46 this.RecursivelyResolveReferences(this.entrySection); 46 this.RecursivelyResolveReferences(this.entrySection);
47 } 47 }
@@ -60,10 +60,10 @@ namespace WixToolset.Core.Link
60 } 60 }
61 61
62 // Process all of the references contained in this section using the collection of 62 // Process all of the references contained in this section using the collection of
63 // tuples provided. Then recursively call this method to process the 63 // symbols provided. Then recursively call this method to process the
64 // located tuple's section. All in all this is a very simple depth-first 64 // located symbol's section. All in all this is a very simple depth-first
65 // search of the references per-section. 65 // search of the references per-section.
66 foreach (var wixSimpleReferenceRow in section.Tuples.OfType<WixSimpleReferenceTuple>()) 66 foreach (var wixSimpleReferenceRow in section.Symbols.OfType<WixSimpleReferenceSymbol>())
67 { 67 {
68 // If we're building a Merge Module, ignore all references to the Media table 68 // If we're building a Merge Module, ignore all references to the Media table
69 // because Merge Modules don't have Media tables. 69 // because Merge Modules don't have Media tables.
@@ -72,44 +72,44 @@ namespace WixToolset.Core.Link
72 continue; 72 continue;
73 } 73 }
74 74
75 if (!this.tuplesWithSections.TryGetValue(wixSimpleReferenceRow.SymbolicName, out var tupleWithSection)) 75 if (!this.symbolsWithSections.TryGetValue(wixSimpleReferenceRow.SymbolicName, out var symbolWithSection))
76 { 76 {
77 this.Messaging.Write(ErrorMessages.UnresolvedReference(wixSimpleReferenceRow.SourceLineNumbers, wixSimpleReferenceRow.SymbolicName)); 77 this.Messaging.Write(ErrorMessages.UnresolvedReference(wixSimpleReferenceRow.SourceLineNumbers, wixSimpleReferenceRow.SymbolicName));
78 } 78 }
79 else // see if the tuple (and any of its duplicates) are appropriately accessible. 79 else // see if the symbol (and any of its duplicates) are appropriately accessible.
80 { 80 {
81 var accessible = this.DetermineAccessibleTuples(section, tupleWithSection); 81 var accessible = this.DetermineAccessibleSymbols(section, symbolWithSection);
82 if (!accessible.Any()) 82 if (!accessible.Any())
83 { 83 {
84 this.Messaging.Write(ErrorMessages.UnresolvedReference(wixSimpleReferenceRow.SourceLineNumbers, wixSimpleReferenceRow.SymbolicName, tupleWithSection.Access)); 84 this.Messaging.Write(ErrorMessages.UnresolvedReference(wixSimpleReferenceRow.SourceLineNumbers, wixSimpleReferenceRow.SymbolicName, symbolWithSection.Access));
85 } 85 }
86 else if (1 == accessible.Count) 86 else if (1 == accessible.Count)
87 { 87 {
88 var accessibleTuple = accessible[0]; 88 var accessibleSymbol = accessible[0];
89 this.referencedTuples.Add(accessibleTuple); 89 this.referencedSymbols.Add(accessibleSymbol);
90 90
91 if (null != accessibleTuple.Section) 91 if (null != accessibleSymbol.Section)
92 { 92 {
93 this.RecursivelyResolveReferences(accessibleTuple.Section); 93 this.RecursivelyResolveReferences(accessibleSymbol.Section);
94 } 94 }
95 } 95 }
96 else // display errors for the duplicate tuples. 96 else // display errors for the duplicate symbols.
97 { 97 {
98 var accessibleTuple = accessible[0]; 98 var accessibleSymbol = accessible[0];
99 var referencingSourceLineNumber = wixSimpleReferenceRow.SourceLineNumbers?.ToString(); 99 var referencingSourceLineNumber = wixSimpleReferenceRow.SourceLineNumbers?.ToString();
100 100
101 if (String.IsNullOrEmpty(referencingSourceLineNumber)) 101 if (String.IsNullOrEmpty(referencingSourceLineNumber))
102 { 102 {
103 this.Messaging.Write(ErrorMessages.DuplicateSymbol(accessibleTuple.Tuple.SourceLineNumbers, accessibleTuple.Name)); 103 this.Messaging.Write(ErrorMessages.DuplicateSymbol(accessibleSymbol.Symbol.SourceLineNumbers, accessibleSymbol.Name));
104 } 104 }
105 else 105 else
106 { 106 {
107 this.Messaging.Write(ErrorMessages.DuplicateSymbol(accessibleTuple.Tuple.SourceLineNumbers, accessibleTuple.Name, referencingSourceLineNumber)); 107 this.Messaging.Write(ErrorMessages.DuplicateSymbol(accessibleSymbol.Symbol.SourceLineNumbers, accessibleSymbol.Name, referencingSourceLineNumber));
108 } 108 }
109 109
110 foreach (var accessibleDuplicate in accessible.Skip(1)) 110 foreach (var accessibleDuplicate in accessible.Skip(1))
111 { 111 {
112 this.Messaging.Write(ErrorMessages.DuplicateSymbol2(accessibleDuplicate.Tuple.SourceLineNumbers)); 112 this.Messaging.Write(ErrorMessages.DuplicateSymbol2(accessibleDuplicate.Symbol.SourceLineNumbers));
113 } 113 }
114 } 114 }
115 } 115 }
@@ -117,67 +117,67 @@ namespace WixToolset.Core.Link
117 } 117 }
118 118
119 /// <summary> 119 /// <summary>
120 /// Determine if the tuple and any of its duplicates are accessbile by referencing section. 120 /// Determine if the symbol and any of its duplicates are accessbile by referencing section.
121 /// </summary> 121 /// </summary>
122 /// <param name="referencingSection">Section referencing the tuple.</param> 122 /// <param name="referencingSection">Section referencing the symbol.</param>
123 /// <param name="tupleWithSection">Tuple being referenced.</param> 123 /// <param name="symbolWithSection">Symbol being referenced.</param>
124 /// <returns>List of tuples accessible by referencing section.</returns> 124 /// <returns>List of symbols accessible by referencing section.</returns>
125 private List<TupleWithSection> DetermineAccessibleTuples(IntermediateSection referencingSection, TupleWithSection tupleWithSection) 125 private List<SymbolWithSection> DetermineAccessibleSymbols(IntermediateSection referencingSection, SymbolWithSection symbolWithSection)
126 { 126 {
127 var accessibleTuples = new List<TupleWithSection>(); 127 var accessibleSymbols = new List<SymbolWithSection>();
128 128
129 if (this.AccessibleTuple(referencingSection, tupleWithSection)) 129 if (this.AccessibleSymbol(referencingSection, symbolWithSection))
130 { 130 {
131 accessibleTuples.Add(tupleWithSection); 131 accessibleSymbols.Add(symbolWithSection);
132 } 132 }
133 133
134 foreach (var dupe in tupleWithSection.PossiblyConflicts) 134 foreach (var dupe in symbolWithSection.PossiblyConflicts)
135 { 135 {
136 // don't count overridable WixActionTuples 136 // don't count overridable WixActionSymbols
137 var tupleAction = tupleWithSection.Tuple as WixActionTuple; 137 var symbolAction = symbolWithSection.Symbol as WixActionSymbol;
138 var dupeAction = dupe.Tuple as WixActionTuple; 138 var dupeAction = dupe.Symbol as WixActionSymbol;
139 if (tupleAction?.Overridable != dupeAction?.Overridable) 139 if (symbolAction?.Overridable != dupeAction?.Overridable)
140 { 140 {
141 continue; 141 continue;
142 } 142 }
143 143
144 if (this.AccessibleTuple(referencingSection, dupe)) 144 if (this.AccessibleSymbol(referencingSection, dupe))
145 { 145 {
146 accessibleTuples.Add(dupe); 146 accessibleSymbols.Add(dupe);
147 } 147 }
148 } 148 }
149 149
150 foreach (var dupe in tupleWithSection.Redundants) 150 foreach (var dupe in symbolWithSection.Redundants)
151 { 151 {
152 if (this.AccessibleTuple(referencingSection, dupe)) 152 if (this.AccessibleSymbol(referencingSection, dupe))
153 { 153 {
154 accessibleTuples.Add(dupe); 154 accessibleSymbols.Add(dupe);
155 } 155 }
156 } 156 }
157 157
158 return accessibleTuples; 158 return accessibleSymbols;
159 } 159 }
160 160
161 /// <summary> 161 /// <summary>
162 /// Determine if a single tuple is accessible by the referencing section. 162 /// Determine if a single symbol is accessible by the referencing section.
163 /// </summary> 163 /// </summary>
164 /// <param name="referencingSection">Section referencing the tuple.</param> 164 /// <param name="referencingSection">Section referencing the symbol.</param>
165 /// <param name="tupleWithSection">Tuple being referenced.</param> 165 /// <param name="symbolWithSection">Symbol being referenced.</param>
166 /// <returns>True if tuple is accessible.</returns> 166 /// <returns>True if symbol is accessible.</returns>
167 private bool AccessibleTuple(IntermediateSection referencingSection, TupleWithSection tupleWithSection) 167 private bool AccessibleSymbol(IntermediateSection referencingSection, SymbolWithSection symbolWithSection)
168 { 168 {
169 switch (tupleWithSection.Access) 169 switch (symbolWithSection.Access)
170 { 170 {
171 case AccessModifier.Public: 171 case AccessModifier.Public:
172 return true; 172 return true;
173 case AccessModifier.Internal: 173 case AccessModifier.Internal:
174 return tupleWithSection.Section.CompilationId.Equals(referencingSection.CompilationId) || (null != tupleWithSection.Section.LibraryId && tupleWithSection.Section.LibraryId.Equals(referencingSection.LibraryId)); 174 return symbolWithSection.Section.CompilationId.Equals(referencingSection.CompilationId) || (null != symbolWithSection.Section.LibraryId && symbolWithSection.Section.LibraryId.Equals(referencingSection.LibraryId));
175 case AccessModifier.Protected: 175 case AccessModifier.Protected:
176 return tupleWithSection.Section.CompilationId.Equals(referencingSection.CompilationId); 176 return symbolWithSection.Section.CompilationId.Equals(referencingSection.CompilationId);
177 case AccessModifier.Private: 177 case AccessModifier.Private:
178 return referencingSection == tupleWithSection.Section; 178 return referencingSection == symbolWithSection.Section;
179 default: 179 default:
180 throw new ArgumentOutOfRangeException(nameof(tupleWithSection.Access)); 180 throw new ArgumentOutOfRangeException(nameof(symbolWithSection.Access));
181 } 181 }
182 } 182 }
183 } 183 }