diff options
Diffstat (limited to 'src/WixToolset.Core/CompilerCore.cs')
| -rw-r--r-- | src/WixToolset.Core/CompilerCore.cs | 134 |
1 files changed, 62 insertions, 72 deletions
diff --git a/src/WixToolset.Core/CompilerCore.cs b/src/WixToolset.Core/CompilerCore.cs index 8f4703f7..46a2e435 100644 --- a/src/WixToolset.Core/CompilerCore.cs +++ b/src/WixToolset.Core/CompilerCore.cs | |||
| @@ -15,7 +15,7 @@ namespace WixToolset | |||
| 15 | using System.Text.RegularExpressions; | 15 | using System.Text.RegularExpressions; |
| 16 | using System.Xml.Linq; | 16 | using System.Xml.Linq; |
| 17 | using WixToolset.Data; | 17 | using WixToolset.Data; |
| 18 | using WixToolset.Data.Rows; | 18 | using WixToolset.Data.Tuples; |
| 19 | using WixToolset.Extensibility; | 19 | using WixToolset.Extensibility; |
| 20 | using Wix = WixToolset.Data.Serialize; | 20 | using Wix = WixToolset.Data.Serialize; |
| 21 | 21 | ||
| @@ -40,7 +40,7 @@ namespace WixToolset | |||
| 40 | /// <summary> | 40 | /// <summary> |
| 41 | /// Core class for the compiler. | 41 | /// Core class for the compiler. |
| 42 | /// </summary> | 42 | /// </summary> |
| 43 | internal sealed class CompilerCore : ICompilerCore | 43 | internal sealed class CompilerCore //: ICompilerCore |
| 44 | { | 44 | { |
| 45 | internal static readonly XNamespace W3SchemaPrefix = "http://www.w3.org/"; | 45 | internal static readonly XNamespace W3SchemaPrefix = "http://www.w3.org/"; |
| 46 | internal static readonly XNamespace WixNamespace = "http://wixtoolset.org/schemas/v4/wxs"; | 46 | internal static readonly XNamespace WixNamespace = "http://wixtoolset.org/schemas/v4/wxs"; |
| @@ -140,10 +140,9 @@ namespace WixToolset | |||
| 140 | "REMOVE" | 140 | "REMOVE" |
| 141 | }); | 141 | }); |
| 142 | 142 | ||
| 143 | private TableDefinitionCollection tableDefinitions; | ||
| 144 | private Dictionary<XNamespace, ICompilerExtension> extensions; | 143 | private Dictionary<XNamespace, ICompilerExtension> extensions; |
| 144 | private ITupleDefinitionCreator creator; | ||
| 145 | private Intermediate intermediate; | 145 | private Intermediate intermediate; |
| 146 | private bool showPedanticMessages; | ||
| 147 | 146 | ||
| 148 | private HashSet<string> activeSectionInlinedDirectoryIds; | 147 | private HashSet<string> activeSectionInlinedDirectoryIds; |
| 149 | private HashSet<string> activeSectionSimpleReferences; | 148 | private HashSet<string> activeSectionSimpleReferences; |
| @@ -152,12 +151,11 @@ namespace WixToolset | |||
| 152 | /// Constructor for all compiler core. | 151 | /// Constructor for all compiler core. |
| 153 | /// </summary> | 152 | /// </summary> |
| 154 | /// <param name="intermediate">The Intermediate object representing compiled source document.</param> | 153 | /// <param name="intermediate">The Intermediate object representing compiled source document.</param> |
| 155 | /// <param name="tableDefinitions">The loaded table definition collection.</param> | ||
| 156 | /// <param name="extensions">The WiX extensions collection.</param> | 154 | /// <param name="extensions">The WiX extensions collection.</param> |
| 157 | internal CompilerCore(Intermediate intermediate, TableDefinitionCollection tableDefinitions, Dictionary<XNamespace, ICompilerExtension> extensions) | 155 | internal CompilerCore(Intermediate intermediate, ITupleDefinitionCreator creator, Dictionary<XNamespace, ICompilerExtension> extensions) |
| 158 | { | 156 | { |
| 159 | this.tableDefinitions = tableDefinitions; | ||
| 160 | this.extensions = extensions; | 157 | this.extensions = extensions; |
| 158 | this.creator = creator; | ||
| 161 | this.intermediate = intermediate; | 159 | this.intermediate = intermediate; |
| 162 | } | 160 | } |
| 163 | 161 | ||
| @@ -165,7 +163,7 @@ namespace WixToolset | |||
| 165 | /// Gets the section the compiler is currently emitting symbols into. | 163 | /// Gets the section the compiler is currently emitting symbols into. |
| 166 | /// </summary> | 164 | /// </summary> |
| 167 | /// <value>The section the compiler is currently emitting symbols into.</value> | 165 | /// <value>The section the compiler is currently emitting symbols into.</value> |
| 168 | public Section ActiveSection { get; private set; } | 166 | public IntermediateSection ActiveSection { get; private set; } |
| 169 | 167 | ||
| 170 | /// <summary> | 168 | /// <summary> |
| 171 | /// Gets or sets the platform which the compiler will use when defaulting 64-bit attributes and elements. | 169 | /// Gets or sets the platform which the compiler will use when defaulting 64-bit attributes and elements. |
| @@ -177,29 +175,13 @@ namespace WixToolset | |||
| 177 | /// Gets whether the compiler core encountered an error while processing. | 175 | /// Gets whether the compiler core encountered an error while processing. |
| 178 | /// </summary> | 176 | /// </summary> |
| 179 | /// <value>Flag if core encountered an error during processing.</value> | 177 | /// <value>Flag if core encountered an error during processing.</value> |
| 180 | public bool EncounteredError | 178 | public bool EncounteredError => Messaging.Instance.EncounteredError; |
| 181 | { | ||
| 182 | get { return Messaging.Instance.EncounteredError; } | ||
| 183 | } | ||
| 184 | 179 | ||
| 185 | /// <summary> | 180 | /// <summary> |
| 186 | /// Gets or sets the option to show pedantic messages. | 181 | /// Gets or sets the option to show pedantic messages. |
| 187 | /// </summary> | 182 | /// </summary> |
| 188 | /// <value>The option to show pedantic messages.</value> | 183 | /// <value>The option to show pedantic messages.</value> |
| 189 | public bool ShowPedanticMessages | 184 | public bool ShowPedanticMessages { get; set; } |
| 190 | { | ||
| 191 | get { return this.showPedanticMessages; } | ||
| 192 | set { this.showPedanticMessages = value; } | ||
| 193 | } | ||
| 194 | |||
| 195 | /// <summary> | ||
| 196 | /// Gets the table definitions used by the compiler core. | ||
| 197 | /// </summary> | ||
| 198 | /// <value>Table definition collection.</value> | ||
| 199 | public TableDefinitionCollection TableDefinitions | ||
| 200 | { | ||
| 201 | get { return this.tableDefinitions; } | ||
| 202 | } | ||
| 203 | 185 | ||
| 204 | /// <summary> | 186 | /// <summary> |
| 205 | /// Convert a bit array into an int value. | 187 | /// Convert a bit array into an int value. |
| @@ -483,32 +465,39 @@ namespace WixToolset | |||
| 483 | /// Creates a row in the active section. | 465 | /// Creates a row in the active section. |
| 484 | /// </summary> | 466 | /// </summary> |
| 485 | /// <param name="sourceLineNumbers">Source and line number of current row.</param> | 467 | /// <param name="sourceLineNumbers">Source and line number of current row.</param> |
| 486 | /// <param name="tableName">Name of table to create row in.</param> | 468 | /// <param name="tupleType">Name of table to create row in.</param> |
| 487 | /// <returns>New row.</returns> | 469 | /// <returns>New row.</returns> |
| 488 | public Row CreateRow(SourceLineNumber sourceLineNumbers, string tableName, Identifier identifier = null) | 470 | public IntermediateTuple CreateRow(SourceLineNumber sourceLineNumbers, TupleDefinitionType tupleType, Identifier identifier = null) |
| 489 | { | 471 | { |
| 490 | return this.CreateRow(sourceLineNumbers, tableName, this.ActiveSection, identifier); | 472 | return this.CreateRow(sourceLineNumbers, tupleType, this.ActiveSection, identifier); |
| 491 | } | 473 | } |
| 492 | 474 | ||
| 493 | /// <summary> | 475 | /// <summary> |
| 494 | /// Creates a row in the active given <paramref name="section"/>. | 476 | /// Creates a row in the active given <paramref name="section"/>. |
| 495 | /// </summary> | 477 | /// </summary> |
| 496 | /// <param name="sourceLineNumbers">Source and line number of current row.</param> | 478 | /// <param name="sourceLineNumbers">Source and line number of current row.</param> |
| 497 | /// <param name="tableName">Name of table to create row in.</param> | 479 | /// <param name="tupleType">Name of table to create row in.</param> |
| 498 | /// <param name="section">The section to which the row is added. If null, the row is added to the active section.</param> | 480 | /// <param name="section">The section to which the row is added. If null, the row is added to the active section.</param> |
| 499 | /// <returns>New row.</returns> | 481 | /// <returns>New row.</returns> |
| 500 | internal Row CreateRow(SourceLineNumber sourceLineNumbers, string tableName, Section section, Identifier identifier = null) | 482 | internal IntermediateTuple CreateRow(SourceLineNumber sourceLineNumbers, TupleDefinitionType tupleType, IntermediateSection section, Identifier identifier = null) |
| 501 | { | 483 | { |
| 502 | TableDefinition tableDefinition = this.tableDefinitions[tableName]; | 484 | var tupleDefinition = TupleDefinitions.ByType(tupleType); |
| 503 | Table table = section.EnsureTable(tableDefinition); | 485 | var row = tupleDefinition.CreateTuple(sourceLineNumbers, identifier); |
| 504 | Row row = table.CreateRow(sourceLineNumbers); | ||
| 505 | 486 | ||
| 506 | if (null != identifier) | 487 | if (null != identifier) |
| 507 | { | 488 | { |
| 508 | row.Access = identifier.Access; | 489 | if (row.Definition.FieldDefinitions[0].Type == IntermediateFieldType.Number) |
| 509 | row[0] = identifier.Id; | 490 | { |
| 491 | row.Set(0, Convert.ToInt32(identifier.Id)); | ||
| 492 | } | ||
| 493 | else | ||
| 494 | { | ||
| 495 | row.Set(0, identifier.Id); | ||
| 496 | } | ||
| 510 | } | 497 | } |
| 511 | 498 | ||
| 499 | section.Tuples.Add(row); | ||
| 500 | |||
| 512 | return row; | 501 | return row; |
| 513 | } | 502 | } |
| 514 | 503 | ||
| @@ -572,9 +561,9 @@ namespace WixToolset | |||
| 572 | /// <returns>New row.</returns> | 561 | /// <returns>New row.</returns> |
| 573 | public void CreatePatchFamilyChildReference(SourceLineNumber sourceLineNumbers, string tableName, params string[] primaryKeys) | 562 | public void CreatePatchFamilyChildReference(SourceLineNumber sourceLineNumbers, string tableName, params string[] primaryKeys) |
| 574 | { | 563 | { |
| 575 | Row patchReferenceRow = this.CreateRow(sourceLineNumbers, "WixPatchRef"); | 564 | var patchReferenceRow = this.CreateRow(sourceLineNumbers, TupleDefinitionType.WixPatchRef); |
| 576 | patchReferenceRow[0] = tableName; | 565 | patchReferenceRow.Set(0, tableName); |
| 577 | patchReferenceRow[1] = String.Join("/", primaryKeys); | 566 | patchReferenceRow.Set(1, String.Join("/", primaryKeys)); |
| 578 | } | 567 | } |
| 579 | 568 | ||
| 580 | /// <summary> | 569 | /// <summary> |
| @@ -615,12 +604,13 @@ namespace WixToolset | |||
| 615 | } | 604 | } |
| 616 | 605 | ||
| 617 | id = this.CreateIdentifier("reg", componentId, root.ToString(CultureInfo.InvariantCulture.NumberFormat), key.ToLowerInvariant(), (null != name ? name.ToLowerInvariant() : name)); | 606 | id = this.CreateIdentifier("reg", componentId, root.ToString(CultureInfo.InvariantCulture.NumberFormat), key.ToLowerInvariant(), (null != name ? name.ToLowerInvariant() : name)); |
| 618 | Row row = this.CreateRow(sourceLineNumbers, "Registry", id); | 607 | |
| 619 | row[1] = root; | 608 | var row = this.CreateRow(sourceLineNumbers, TupleDefinitionType.Registry, id); |
| 620 | row[2] = key; | 609 | row.Set(1, root); |
| 621 | row[3] = name; | 610 | row.Set(2, key); |
| 622 | row[4] = value; | 611 | row.Set(3, name); |
| 623 | row[5] = componentId; | 612 | row.Set(4, value); |
| 613 | row.Set(5, componentId); | ||
| 624 | } | 614 | } |
| 625 | 615 | ||
| 626 | return id; | 616 | return id; |
| @@ -656,8 +646,8 @@ namespace WixToolset | |||
| 656 | // If this simple reference hasn't been added to the active section already, add it. | 646 | // If this simple reference hasn't been added to the active section already, add it. |
| 657 | if (this.activeSectionSimpleReferences.Add(id)) | 647 | if (this.activeSectionSimpleReferences.Add(id)) |
| 658 | { | 648 | { |
| 659 | WixSimpleReferenceRow wixSimpleReferenceRow = (WixSimpleReferenceRow)this.CreateRow(sourceLineNumbers, "WixSimpleReference"); | 649 | var wixSimpleReferenceRow = (WixSimpleReferenceTuple)this.CreateRow(sourceLineNumbers, TupleDefinitionType.WixSimpleReference); |
| 660 | wixSimpleReferenceRow.TableName = tableName; | 650 | wixSimpleReferenceRow.Table = tableName; |
| 661 | wixSimpleReferenceRow.PrimaryKeys = joinedKeys; | 651 | wixSimpleReferenceRow.PrimaryKeys = joinedKeys; |
| 662 | } | 652 | } |
| 663 | } | 653 | } |
| @@ -685,11 +675,11 @@ namespace WixToolset | |||
| 685 | throw new ArgumentNullException("childId"); | 675 | throw new ArgumentNullException("childId"); |
| 686 | } | 676 | } |
| 687 | 677 | ||
| 688 | WixGroupRow WixGroupRow = (WixGroupRow)this.CreateRow(sourceLineNumbers, "WixGroup"); | 678 | var row = (WixGroupTuple)this.CreateRow(sourceLineNumbers, TupleDefinitionType.WixGroup); |
| 689 | WixGroupRow.ParentId = parentId; | 679 | row.ParentId = parentId; |
| 690 | WixGroupRow.ParentType = parentType; | 680 | row.ParentType = parentType; |
| 691 | WixGroupRow.ChildId = childId; | 681 | row.ChildId = childId; |
| 692 | WixGroupRow.ChildType = childType; | 682 | row.ChildType = childType; |
| 693 | } | 683 | } |
| 694 | } | 684 | } |
| 695 | 685 | ||
| @@ -703,13 +693,13 @@ namespace WixToolset | |||
| 703 | { | 693 | { |
| 704 | if (!this.EncounteredError) | 694 | if (!this.EncounteredError) |
| 705 | { | 695 | { |
| 706 | Row row = this.CreateRow(sourceLineNumbers, "WixEnsureTable"); | 696 | var row = this.CreateRow(sourceLineNumbers, TupleDefinitionType.WixEnsureTable); |
| 707 | row[0] = tableName; | 697 | row.Set(0, tableName); |
| 708 | 698 | ||
| 709 | // We don't add custom table definitions to the tableDefinitions collection, | 699 | // We don't add custom table definitions to the tableDefinitions collection, |
| 710 | // so if it's not in there, it better be a custom table. If the Id is just wrong, | 700 | // so if it's not in there, it better be a custom table. If the Id is just wrong, |
| 711 | // instead of a custom table, we get an unresolved reference at link time. | 701 | // instead of a custom table, we get an unresolved reference at link time. |
| 712 | if (!this.tableDefinitions.Contains(tableName)) | 702 | if (!this.creator.TryGetTupleDefinitionByName(tableName, out var ignored)) |
| 713 | { | 703 | { |
| 714 | this.CreateSimpleReference(sourceLineNumbers, "WixCustomTable", tableName); | 704 | this.CreateSimpleReference(sourceLineNumbers, "WixCustomTable", tableName); |
| 715 | } | 705 | } |
| @@ -1016,7 +1006,7 @@ namespace WixToolset | |||
| 1016 | 1006 | ||
| 1017 | string uppercaseGuid = guid.ToString().ToUpper(CultureInfo.InvariantCulture); | 1007 | string uppercaseGuid = guid.ToString().ToUpper(CultureInfo.InvariantCulture); |
| 1018 | 1008 | ||
| 1019 | if (this.showPedanticMessages) | 1009 | if (this.ShowPedanticMessages) |
| 1020 | { | 1010 | { |
| 1021 | if (uppercaseGuid != value) | 1011 | if (uppercaseGuid != value) |
| 1022 | { | 1012 | { |
| @@ -1505,8 +1495,7 @@ namespace WixToolset | |||
| 1505 | return; | 1495 | return; |
| 1506 | } | 1496 | } |
| 1507 | 1497 | ||
| 1508 | ICompilerExtension extension; | 1498 | if (this.TryFindExtension(attribute.Name.NamespaceName, out var extension)) |
| 1509 | if (this.TryFindExtension(attribute.Name.NamespaceName, out extension)) | ||
| 1510 | { | 1499 | { |
| 1511 | extension.ParseAttribute(element, attribute, context); | 1500 | extension.ParseAttribute(element, attribute, context); |
| 1512 | } | 1501 | } |
| @@ -1525,8 +1514,7 @@ namespace WixToolset | |||
| 1525 | /// <param name="context">Extra information about the context in which this element is being parsed.</param> | 1514 | /// <param name="context">Extra information about the context in which this element is being parsed.</param> |
| 1526 | public void ParseExtensionElement(XElement parentElement, XElement element, IDictionary<string, string> context = null) | 1515 | public void ParseExtensionElement(XElement parentElement, XElement element, IDictionary<string, string> context = null) |
| 1527 | { | 1516 | { |
| 1528 | ICompilerExtension extension; | 1517 | if (this.TryFindExtension(element.Name.Namespace, out var extension)) |
| 1529 | if (this.TryFindExtension(element.Name.Namespace, out extension)) | ||
| 1530 | { | 1518 | { |
| 1531 | SourceLineNumber sourceLineNumbers = Preprocessor.GetSourceLineNumbers(parentElement); | 1519 | SourceLineNumber sourceLineNumbers = Preprocessor.GetSourceLineNumbers(parentElement); |
| 1532 | extension.ParseElement(parentElement, element, context); | 1520 | extension.ParseElement(parentElement, element, context); |
| @@ -1651,9 +1639,9 @@ namespace WixToolset | |||
| 1651 | /// <param name="type">Type of section to create.</param> | 1639 | /// <param name="type">Type of section to create.</param> |
| 1652 | /// <param name="codepage">Codepage for the resulting database for this ection.</param> | 1640 | /// <param name="codepage">Codepage for the resulting database for this ection.</param> |
| 1653 | /// <returns>New section.</returns> | 1641 | /// <returns>New section.</returns> |
| 1654 | internal Section CreateActiveSection(string id, SectionType type, int codepage) | 1642 | internal IntermediateSection CreateActiveSection(string id, SectionType type, int codepage, string compilationId) |
| 1655 | { | 1643 | { |
| 1656 | this.ActiveSection = this.CreateSection(id, type, codepage); | 1644 | this.ActiveSection = this.CreateSection(id, type, codepage, compilationId); |
| 1657 | 1645 | ||
| 1658 | this.activeSectionInlinedDirectoryIds = new HashSet<string>(); | 1646 | this.activeSectionInlinedDirectoryIds = new HashSet<string>(); |
| 1659 | this.activeSectionSimpleReferences = new HashSet<string>(); | 1647 | this.activeSectionSimpleReferences = new HashSet<string>(); |
| @@ -1668,12 +1656,14 @@ namespace WixToolset | |||
| 1668 | /// <param name="type">Type of section to create.</param> | 1656 | /// <param name="type">Type of section to create.</param> |
| 1669 | /// <param name="codepage">Codepage for the resulting database for this ection.</param> | 1657 | /// <param name="codepage">Codepage for the resulting database for this ection.</param> |
| 1670 | /// <returns>New section.</returns> | 1658 | /// <returns>New section.</returns> |
| 1671 | internal Section CreateSection(string id, SectionType type, int codepage) | 1659 | internal IntermediateSection CreateSection(string id, SectionType type, int codepage, string compilationId) |
| 1672 | { | 1660 | { |
| 1673 | Section newSection = new Section(id, type, codepage); | 1661 | var section = new IntermediateSection(id, type, codepage); |
| 1674 | this.intermediate.AddSection(newSection); | 1662 | section.CompilationId = compilationId; |
| 1663 | |||
| 1664 | this.intermediate.Sections.Add(section); | ||
| 1675 | 1665 | ||
| 1676 | return newSection; | 1666 | return section; |
| 1677 | } | 1667 | } |
| 1678 | 1668 | ||
| 1679 | /// <summary> | 1669 | /// <summary> |
| @@ -1690,11 +1680,11 @@ namespace WixToolset | |||
| 1690 | { | 1680 | { |
| 1691 | if (!this.EncounteredError) | 1681 | if (!this.EncounteredError) |
| 1692 | { | 1682 | { |
| 1693 | WixComplexReferenceRow wixComplexReferenceRow = (WixComplexReferenceRow)this.CreateRow(sourceLineNumbers, "WixComplexReference"); | 1683 | var wixComplexReferenceRow = (WixComplexReferenceTuple)this.CreateRow(sourceLineNumbers, TupleDefinitionType.WixComplexReference); |
| 1694 | wixComplexReferenceRow.ParentId = parentId; | 1684 | wixComplexReferenceRow.Parent = parentId; |
| 1695 | wixComplexReferenceRow.ParentType = parentType; | 1685 | wixComplexReferenceRow.ParentType = parentType; |
| 1696 | wixComplexReferenceRow.ParentLanguage = parentLanguage; | 1686 | wixComplexReferenceRow.ParentLanguage = parentLanguage; |
| 1697 | wixComplexReferenceRow.ChildId = childId; | 1687 | wixComplexReferenceRow.Child = childId; |
| 1698 | wixComplexReferenceRow.ChildType = childType; | 1688 | wixComplexReferenceRow.ChildType = childType; |
| 1699 | wixComplexReferenceRow.IsPrimary = isPrimary; | 1689 | wixComplexReferenceRow.IsPrimary = isPrimary; |
| 1700 | } | 1690 | } |
| @@ -1775,9 +1765,9 @@ namespace WixToolset | |||
| 1775 | } | 1765 | } |
| 1776 | } | 1766 | } |
| 1777 | 1767 | ||
| 1778 | Row row = this.CreateRow(sourceLineNumbers, "Directory", id); | 1768 | var row = this.CreateRow(sourceLineNumbers, TupleDefinitionType.Directory, id); |
| 1779 | row[1] = parentId; | 1769 | row.Set(1, parentId); |
| 1780 | row[2] = defaultDir; | 1770 | row.Set(2, defaultDir); |
| 1781 | return id; | 1771 | return id; |
| 1782 | } | 1772 | } |
| 1783 | 1773 | ||
