From 2bb37beda887d120a0ddabf874ad25357101faa1 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 1 Nov 2017 10:59:45 -0700 Subject: Update to WiX Intermediate Representation --- .../Link/ResolveReferencesCommand.cs | 99 ++++++++++------------ 1 file changed, 46 insertions(+), 53 deletions(-) (limited to 'src/WixToolset.Core/Link/ResolveReferencesCommand.cs') diff --git a/src/WixToolset.Core/Link/ResolveReferencesCommand.cs b/src/WixToolset.Core/Link/ResolveReferencesCommand.cs index 5a985f3f..9c3b2765 100644 --- a/src/WixToolset.Core/Link/ResolveReferencesCommand.cs +++ b/src/WixToolset.Core/Link/ResolveReferencesCommand.cs @@ -4,22 +4,21 @@ namespace WixToolset.Link { using System; using System.Collections.Generic; - using System.Diagnostics; using System.Linq; using WixToolset.Data; - using WixToolset.Data.Rows; + using WixToolset.Data.Tuples; /// /// Resolves all the simple references in a section. /// internal class ResolveReferencesCommand : ICommand { - private Section entrySection; + private IntermediateSection entrySection; private IDictionary symbols; private HashSet referencedSymbols; - private HashSet
resolvedSections; + private HashSet resolvedSections; - public ResolveReferencesCommand(Section entrySection, IDictionary symbols) + public ResolveReferencesCommand(IntermediateSection entrySection, IDictionary symbols) { this.entrySection = entrySection; this.symbols = symbols; @@ -29,14 +28,14 @@ namespace WixToolset.Link public IEnumerable ReferencedSymbols { get { return this.referencedSymbols; } } - public IEnumerable
ResolvedSections { get { return this.resolvedSections; } } + public IEnumerable ResolvedSections { get { return this.resolvedSections; } } /// /// Resolves all the simple references in a section. /// public void Execute() { - this.resolvedSections = new HashSet
(); + this.resolvedSections = new HashSet(); this.referencedSymbols = new HashSet(); this.RecursivelyResolveReferences(this.entrySection); @@ -47,7 +46,7 @@ namespace WixToolset.Link /// /// Section with references to resolve. /// Note: recursive function. - private void RecursivelyResolveReferences(Section section) + private void RecursivelyResolveReferences(IntermediateSection section) { // If we already resolved this section, move on to the next. if (!this.resolvedSections.Add(section)) @@ -59,59 +58,53 @@ namespace WixToolset.Link // symbols provided. Then recursively call this method to process the // located symbol's section. All in all this is a very simple depth-first // search of the references per-section. - Table wixSimpleReferenceTable; - if (section.Tables.TryGetTable("WixSimpleReference", out wixSimpleReferenceTable)) + foreach (var wixSimpleReferenceRow in section.Tuples.OfType()) { - foreach (WixSimpleReferenceRow wixSimpleReferenceRow in wixSimpleReferenceTable.Rows) + // If we're building a Merge Module, ignore all references to the Media table + // because Merge Modules don't have Media tables. + if (this.BuildingMergeModule && wixSimpleReferenceRow.Definition.Type == TupleDefinitionType.Media) { - Debug.Assert(wixSimpleReferenceRow.Section == section); + continue; + } - // If we're building a Merge Module, ignore all references to the Media table - // because Merge Modules don't have Media tables. - if (this.BuildingMergeModule && "Media" == wixSimpleReferenceRow.TableName) + if (!this.symbols.TryGetValue(wixSimpleReferenceRow.SymbolicName, out var symbol)) + { + Messaging.Instance.OnMessage(WixErrors.UnresolvedReference(wixSimpleReferenceRow.SourceLineNumbers, wixSimpleReferenceRow.SymbolicName)); + } + else // see if the symbol (and any of its duplicates) are appropriately accessible. + { + IList accessible = DetermineAccessibleSymbols(section, symbol); + if (!accessible.Any()) { - continue; + Messaging.Instance.OnMessage(WixErrors.UnresolvedReference(wixSimpleReferenceRow.SourceLineNumbers, wixSimpleReferenceRow.SymbolicName, symbol.Access)); } - - Symbol symbol; - if (!this.symbols.TryGetValue(wixSimpleReferenceRow.SymbolicName, out symbol)) + else if (1 == accessible.Count) { - Messaging.Instance.OnMessage(WixErrors.UnresolvedReference(wixSimpleReferenceRow.SourceLineNumbers, wixSimpleReferenceRow.SymbolicName)); + var accessibleSymbol = accessible[0]; + this.referencedSymbols.Add(accessibleSymbol); + + if (null != accessibleSymbol.Section) + { + RecursivelyResolveReferences(accessibleSymbol.Section); + } } - else // see if the symbol (and any of its duplicates) are appropriately accessible. + else // display errors for the duplicate symbols. { - IList accessible = DetermineAccessibleSymbols(section, symbol); - if (!accessible.Any()) + var accessibleSymbol = accessible[0]; + var referencingSourceLineNumber = wixSimpleReferenceRow.SourceLineNumbers.ToString(); + + if (String.IsNullOrEmpty(referencingSourceLineNumber)) { - Messaging.Instance.OnMessage(WixErrors.UnresolvedReference(wixSimpleReferenceRow.SourceLineNumbers, wixSimpleReferenceRow.SymbolicName, symbol.Access)); + Messaging.Instance.OnMessage(WixErrors.DuplicateSymbol(accessibleSymbol.Row.SourceLineNumbers, accessibleSymbol.Name)); } - else if (1 == accessible.Count) + else { - Symbol accessibleSymbol = accessible[0]; - this.referencedSymbols.Add(accessibleSymbol); - - if (null != accessibleSymbol.Section) - { - RecursivelyResolveReferences(accessibleSymbol.Section); - } + Messaging.Instance.OnMessage(WixErrors.DuplicateSymbol(accessibleSymbol.Row.SourceLineNumbers, accessibleSymbol.Name, referencingSourceLineNumber)); } - else // display errors for the duplicate symbols. + + foreach (Symbol accessibleDuplicate in accessible.Skip(1)) { - Symbol accessibleSymbol = accessible[0]; - string referencingSourceLineNumber = wixSimpleReferenceRow.SourceLineNumbers.ToString(); - if (String.IsNullOrEmpty(referencingSourceLineNumber)) - { - Messaging.Instance.OnMessage(WixErrors.DuplicateSymbol(accessibleSymbol.Row.SourceLineNumbers, accessibleSymbol.Name)); - } - else - { - Messaging.Instance.OnMessage(WixErrors.DuplicateSymbol(accessibleSymbol.Row.SourceLineNumbers, accessibleSymbol.Name, referencingSourceLineNumber)); - } - - foreach (Symbol accessibleDuplicate in accessible.Skip(1)) - { - Messaging.Instance.OnMessage(WixErrors.DuplicateSymbol2(accessibleDuplicate.Row.SourceLineNumbers)); - } + Messaging.Instance.OnMessage(WixErrors.DuplicateSymbol2(accessibleDuplicate.Row.SourceLineNumbers)); } } } @@ -124,7 +117,7 @@ namespace WixToolset.Link /// Section referencing the symbol. /// Symbol being referenced. /// List of symbols accessible by referencing section. - private IList DetermineAccessibleSymbols(Section referencingSection, Symbol symbol) + private IList DetermineAccessibleSymbols(IntermediateSection referencingSection, Symbol symbol) { List symbols = new List(); @@ -158,20 +151,20 @@ namespace WixToolset.Link /// Section referencing the symbol. /// Symbol being referenced. /// True if symbol is accessible. - private bool AccessibleSymbol(Section referencingSection, Symbol symbol) + private bool AccessibleSymbol(IntermediateSection referencingSection, Symbol symbol) { switch (symbol.Access) { case AccessModifier.Public: return true; case AccessModifier.Internal: - return symbol.Row.Section.IntermediateId.Equals(referencingSection.IntermediateId) || (null != symbol.Row.Section.LibraryId && symbol.Row.Section.LibraryId.Equals(referencingSection.LibraryId)); + return symbol.Section.CompilationId.Equals(referencingSection.CompilationId) || (null != symbol.Section.LibraryId && symbol.Section.LibraryId.Equals(referencingSection.LibraryId)); case AccessModifier.Protected: - return symbol.Row.Section.IntermediateId.Equals(referencingSection.IntermediateId); + return symbol.Section.CompilationId.Equals(referencingSection.CompilationId); case AccessModifier.Private: return referencingSection == symbol.Section; default: - throw new InvalidOperationException(); + throw new ArgumentOutOfRangeException(nameof(symbol.Access)); } } } -- cgit v1.2.3-55-g6feb