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.cs100
1 files changed, 50 insertions, 50 deletions
diff --git a/src/WixToolset.Core/Link/ResolveReferencesCommand.cs b/src/WixToolset.Core/Link/ResolveReferencesCommand.cs
index 6dcd36d3..4ffb5443 100644
--- a/src/WixToolset.Core/Link/ResolveReferencesCommand.cs
+++ b/src/WixToolset.Core/Link/ResolveReferencesCommand.cs
@@ -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, Symbol> symbols; 18 private readonly IDictionary<string, TupleWithSection> tuplesWithSections;
19 private HashSet<Symbol> referencedSymbols; 19 private HashSet<TupleWithSection> referencedTuples;
20 private HashSet<IntermediateSection> resolvedSections; 20 private HashSet<IntermediateSection> resolvedSections;
21 21
22 public ResolveReferencesCommand(IMessaging messaging, IntermediateSection entrySection, IDictionary<string, Symbol> symbols) 22 public ResolveReferencesCommand(IMessaging messaging, IntermediateSection entrySection, IDictionary<string, TupleWithSection> tuplesWithSections)
23 { 23 {
24 this.Messaging = messaging; 24 this.Messaging = messaging;
25 this.entrySection = entrySection; 25 this.entrySection = entrySection;
26 this.symbols = symbols; 26 this.tuplesWithSections = tuplesWithSections;
27 this.BuildingMergeModule = (SectionType.Module == entrySection.Type); 27 this.BuildingMergeModule = (SectionType.Module == entrySection.Type);
28 } 28 }
29 29
30 public IEnumerable<Symbol> ReferencedSymbols => this.referencedSymbols; 30 public IEnumerable<TupleWithSection> ReferencedTupleWithSections => this.referencedTuples;
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.referencedSymbols = new HashSet<Symbol>(); 44 this.referencedTuples = new HashSet<TupleWithSection>();
45 45
46 this.RecursivelyResolveReferences(this.entrySection); 46 this.RecursivelyResolveReferences(this.entrySection);
47 } 47 }
@@ -60,8 +60,8 @@ 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 // symbols provided. Then recursively call this method to process the 63 // tuples provided. Then recursively call this method to process the
64 // located symbol's section. All in all this is a very simple depth-first 64 // located tuple'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.Tuples.OfType<WixSimpleReferenceTuple>())
67 { 67 {
@@ -72,44 +72,44 @@ namespace WixToolset.Core.Link
72 continue; 72 continue;
73 } 73 }
74 74
75 if (!this.symbols.TryGetValue(wixSimpleReferenceRow.SymbolicName, out var symbol)) 75 if (!this.tuplesWithSections.TryGetValue(wixSimpleReferenceRow.SymbolicName, out var tupleWithSection))
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 symbol (and any of its duplicates) are appropriately accessible. 79 else // see if the tuple (and any of its duplicates) are appropriately accessible.
80 { 80 {
81 IList<Symbol> accessible = this.DetermineAccessibleSymbols(section, symbol); 81 var accessible = this.DetermineAccessibleTuples(section, tupleWithSection);
82 if (!accessible.Any()) 82 if (!accessible.Any())
83 { 83 {
84 this.Messaging.Write(ErrorMessages.UnresolvedReference(wixSimpleReferenceRow.SourceLineNumbers, wixSimpleReferenceRow.SymbolicName, symbol.Access)); 84 this.Messaging.Write(ErrorMessages.UnresolvedReference(wixSimpleReferenceRow.SourceLineNumbers, wixSimpleReferenceRow.SymbolicName, tupleWithSection.Access));
85 } 85 }
86 else if (1 == accessible.Count) 86 else if (1 == accessible.Count)
87 { 87 {
88 var accessibleSymbol = accessible[0]; 88 var accessibleTuple = accessible[0];
89 this.referencedSymbols.Add(accessibleSymbol); 89 this.referencedTuples.Add(accessibleTuple);
90 90
91 if (null != accessibleSymbol.Section) 91 if (null != accessibleTuple.Section)
92 { 92 {
93 this.RecursivelyResolveReferences(accessibleSymbol.Section); 93 this.RecursivelyResolveReferences(accessibleTuple.Section);
94 } 94 }
95 } 95 }
96 else // display errors for the duplicate symbols. 96 else // display errors for the duplicate tuples.
97 { 97 {
98 var accessibleSymbol = accessible[0]; 98 var accessibleTuple = 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(accessibleSymbol.Row.SourceLineNumbers, accessibleSymbol.Name)); 103 this.Messaging.Write(ErrorMessages.DuplicateSymbol(accessibleTuple.Tuple.SourceLineNumbers, accessibleTuple.Name));
104 } 104 }
105 else 105 else
106 { 106 {
107 this.Messaging.Write(ErrorMessages.DuplicateSymbol(accessibleSymbol.Row.SourceLineNumbers, accessibleSymbol.Name, referencingSourceLineNumber)); 107 this.Messaging.Write(ErrorMessages.DuplicateSymbol(accessibleTuple.Tuple.SourceLineNumbers, accessibleTuple.Name, referencingSourceLineNumber));
108 } 108 }
109 109
110 foreach (Symbol accessibleDuplicate in accessible.Skip(1)) 110 foreach (var accessibleDuplicate in accessible.Skip(1))
111 { 111 {
112 this.Messaging.Write(ErrorMessages.DuplicateSymbol2(accessibleDuplicate.Row.SourceLineNumbers)); 112 this.Messaging.Write(ErrorMessages.DuplicateSymbol2(accessibleDuplicate.Tuple.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 symbol and any of its duplicates are accessbile by referencing section. 120 /// Determine if the tuple and any of its duplicates are accessbile by referencing section.
121 /// </summary> 121 /// </summary>
122 /// <param name="referencingSection">Section referencing the symbol.</param> 122 /// <param name="referencingSection">Section referencing the tuple.</param>
123 /// <param name="symbol">Symbol being referenced.</param> 123 /// <param name="tupleWithSection">Tuple being referenced.</param>
124 /// <returns>List of symbols accessible by referencing section.</returns> 124 /// <returns>List of tuples accessible by referencing section.</returns>
125 private IList<Symbol> DetermineAccessibleSymbols(IntermediateSection referencingSection, Symbol symbol) 125 private List<TupleWithSection> DetermineAccessibleTuples(IntermediateSection referencingSection, TupleWithSection tupleWithSection)
126 { 126 {
127 List<Symbol> symbols = new List<Symbol>(); 127 var accessibleTuples = new List<TupleWithSection>();
128 128
129 if (this.AccessibleSymbol(referencingSection, symbol)) 129 if (this.AccessibleTuple(referencingSection, tupleWithSection))
130 { 130 {
131 symbols.Add(symbol); 131 accessibleTuples.Add(tupleWithSection);
132 } 132 }
133 133
134 foreach (Symbol dupe in symbol.PossiblyConflictingSymbols) 134 foreach (var dupe in tupleWithSection.PossiblyConflicts)
135 { 135 {
136 // don't count overridable WixActionTuples 136 // don't count overridable WixActionTuples
137 WixActionTuple symbolAction = symbol.Row as WixActionTuple; 137 var tupleAction = tupleWithSection.Tuple as WixActionTuple;
138 WixActionTuple dupeAction = dupe.Row as WixActionTuple; 138 var dupeAction = dupe.Tuple as WixActionTuple;
139 if (symbolAction?.Overridable != dupeAction?.Overridable) 139 if (tupleAction?.Overridable != dupeAction?.Overridable)
140 { 140 {
141 continue; 141 continue;
142 } 142 }
143 143
144 if (this.AccessibleSymbol(referencingSection, dupe)) 144 if (this.AccessibleTuple(referencingSection, dupe))
145 { 145 {
146 symbols.Add(dupe); 146 accessibleTuples.Add(dupe);
147 } 147 }
148 } 148 }
149 149
150 foreach (Symbol dupe in symbol.RedundantSymbols) 150 foreach (var dupe in tupleWithSection.Redundants)
151 { 151 {
152 if (this.AccessibleSymbol(referencingSection, dupe)) 152 if (this.AccessibleTuple(referencingSection, dupe))
153 { 153 {
154 symbols.Add(dupe); 154 accessibleTuples.Add(dupe);
155 } 155 }
156 } 156 }
157 157
158 return symbols; 158 return accessibleTuples;
159 } 159 }
160 160
161 /// <summary> 161 /// <summary>
162 /// Determine if a single symbol is accessible by the referencing section. 162 /// Determine if a single tuple is accessible by the referencing section.
163 /// </summary> 163 /// </summary>
164 /// <param name="referencingSection">Section referencing the symbol.</param> 164 /// <param name="referencingSection">Section referencing the tuple.</param>
165 /// <param name="symbol">Symbol being referenced.</param> 165 /// <param name="tupleWithSection">Tuple being referenced.</param>
166 /// <returns>True if symbol is accessible.</returns> 166 /// <returns>True if tuple is accessible.</returns>
167 private bool AccessibleSymbol(IntermediateSection referencingSection, Symbol symbol) 167 private bool AccessibleTuple(IntermediateSection referencingSection, TupleWithSection tupleWithSection)
168 { 168 {
169 switch (symbol.Access) 169 switch (tupleWithSection.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 symbol.Section.CompilationId.Equals(referencingSection.CompilationId) || (null != symbol.Section.LibraryId && symbol.Section.LibraryId.Equals(referencingSection.LibraryId)); 174 return tupleWithSection.Section.CompilationId.Equals(referencingSection.CompilationId) || (null != tupleWithSection.Section.LibraryId && tupleWithSection.Section.LibraryId.Equals(referencingSection.LibraryId));
175 case AccessModifier.Protected: 175 case AccessModifier.Protected:
176 return symbol.Section.CompilationId.Equals(referencingSection.CompilationId); 176 return tupleWithSection.Section.CompilationId.Equals(referencingSection.CompilationId);
177 case AccessModifier.Private: 177 case AccessModifier.Private:
178 return referencingSection == symbol.Section; 178 return referencingSection == tupleWithSection.Section;
179 default: 179 default:
180 throw new ArgumentOutOfRangeException(nameof(symbol.Access)); 180 throw new ArgumentOutOfRangeException(nameof(tupleWithSection.Access));
181 } 181 }
182 } 182 }
183 } 183 }