public override void ExpandTree(InteriorNode parent, SymbolsDictionary symbols, Positions positions) { SyntaxTreeNode node = null; foreach (int num in this.GetResolvedSymbols(symbols)) { if (symbols.GetParticle(num) != this.particle) { symbols.IsUpaEnforced = false; } LeafNode node2 = new LeafNode(positions.Add(num, this.particle)); if (node == null) { node = node2; } else { InteriorNode node3 = new ChoiceNode { LeftChild = node, RightChild = node2 }; node = node3; } } if (parent.LeftChild == this) { parent.LeftChild = node; } else { parent.RightChild = node; } }
public override void ExpandTree(InteriorNode parent, SymbolsDictionary symbols, Positions positions) { SyntaxTreeNode replacementNode = null; foreach(int symbol in GetResolvedSymbols(symbols)) { if (symbols.GetParticle(symbol) != particle) { symbols.IsUpaEnforced = false; } LeafNode node = new LeafNode(positions.Add(symbol, particle)); if (replacementNode == null) { replacementNode = node; } else { InteriorNode choice = new ChoiceNode(); choice.LeftChild = replacementNode; choice.RightChild = node; replacementNode = choice; } } if (parent.LeftChild == this) { parent.LeftChild = replacementNode; } else { parent.RightChild = replacementNode; } }
public ContentValidator Finish(bool useDFA) { Debug.Assert(ContentType == XmlSchemaContentType.ElementOnly || ContentType == XmlSchemaContentType.Mixed); if (contentNode == null) { if (ContentType == XmlSchemaContentType.Mixed) { string ctype = IsOpen ? "Any" : "TextOnly"; Debug.WriteLineIf(DiagnosticsSwitches.XmlSchemaContentModel.Enabled, "\t\t\tContentType: " + ctype); return IsOpen ? ContentValidator.Any : ContentValidator.TextOnly; } else { Debug.WriteLineIf(DiagnosticsSwitches.XmlSchemaContentModel.Enabled, "\t\t\tContent: EMPTY"); Debug.Assert(!IsOpen); return ContentValidator.Empty; } } #if DEBUG StringBuilder bb = new StringBuilder(); contentNode.Dump(bb, symbols, positions); Debug.WriteLineIf(DiagnosticsSwitches.XmlSchemaContentModel.Enabled, "\t\t\tContent : " + bb.ToString()); #endif // Add end marker InteriorNode contentRoot = new SequenceNode(); contentRoot.LeftChild = contentNode; LeafNode endMarker = new LeafNode(positions.Add(symbols.AddName(XmlQualifiedName.Empty, null), null)); contentRoot.RightChild = endMarker; // Eliminate NamespaceListNode(s) and RangeNode(s) contentNode.ExpandTree(contentRoot, symbols, positions); #if DEBUG bb = new StringBuilder(); contentRoot.LeftChild.Dump(bb, symbols, positions); Debug.WriteLineIf(DiagnosticsSwitches.XmlSchemaContentModel.Enabled, "\t\t\tExpended: " + bb.ToString()); #endif // calculate followpos int symbolsCount = symbols.Count; int positionsCount = positions.Count; BitSet firstpos = new BitSet(positionsCount); BitSet lastpos = new BitSet(positionsCount); BitSet[] followpos = new BitSet[positionsCount]; for (int i = 0; i < positionsCount; i++) { followpos[i] = new BitSet(positionsCount); } contentRoot.ConstructPos(firstpos, lastpos, followpos); #if DEBUG Debug.WriteLineIf(DiagnosticsSwitches.XmlSchemaContentModel.Enabled, "firstpos, lastpos, followpos"); SequenceNode.WritePos(firstpos, lastpos, followpos); #endif if (minMaxNodesCount > 0) { //If the tree has any terminal range nodes BitSet positionsWithRangeTerminals; BitSet[] minMaxFollowPos = CalculateTotalFollowposForRangeNodes(firstpos, followpos, out positionsWithRangeTerminals); if (enableUpaCheck) { CheckCMUPAWithLeafRangeNodes(GetApplicableMinMaxFollowPos(firstpos, positionsWithRangeTerminals, minMaxFollowPos)); for (int i = 0; i < positionsCount; i++) { CheckCMUPAWithLeafRangeNodes(GetApplicableMinMaxFollowPos(followpos[i], positionsWithRangeTerminals, minMaxFollowPos)); } } return new RangeContentValidator(firstpos, followpos, symbols, positions, endMarker.Pos, this.ContentType, contentRoot.LeftChild.IsNullable, positionsWithRangeTerminals, minMaxNodesCount); } else { int[][] transitionTable = null; // if each symbol has unique particle we are golden if (!symbols.IsUpaEnforced) { if (enableUpaCheck) { // multiple positions that match the same symbol have different particles, but they never follow the same position CheckUniqueParticleAttribution(firstpos, followpos); } } else if (useDFA) { // Can return null if the number of states reaches higher than 8192 / positionsCount transitionTable = BuildTransitionTable(firstpos, followpos, endMarker.Pos); } #if DEBUG bb = new StringBuilder(); Dump(bb, followpos, transitionTable); Debug.WriteLineIf(DiagnosticsSwitches.XmlSchemaContentModel.Enabled, bb.ToString()); #endif if (transitionTable != null) { return new DfaContentValidator(transitionTable, symbols,this.ContentType, this.IsOpen, contentRoot.LeftChild.IsNullable); } else { return new NfaContentValidator(firstpos, followpos, symbols, positions, endMarker.Pos, this.ContentType, this.IsOpen, contentRoot.LeftChild.IsNullable); } } }
public ContentValidator Finish(bool useDFA) { if (this.contentNode == null) { if (base.ContentType != XmlSchemaContentType.Mixed) { return ContentValidator.Empty; } bool isOpen = base.IsOpen; if (!base.IsOpen) { return ContentValidator.TextOnly; } return ContentValidator.Any; } InteriorNode parent = new SequenceNode { LeftChild = this.contentNode }; LeafNode node2 = new LeafNode(this.positions.Add(this.symbols.AddName(XmlQualifiedName.Empty, null), null)); parent.RightChild = node2; this.contentNode.ExpandTree(parent, this.symbols, this.positions); int count = this.symbols.Count; int num = this.positions.Count; BitSet firstpos = new BitSet(num); BitSet lastpos = new BitSet(num); BitSet[] followpos = new BitSet[num]; for (int i = 0; i < num; i++) { followpos[i] = new BitSet(num); } parent.ConstructPos(firstpos, lastpos, followpos); if (this.minMaxNodesCount > 0) { BitSet set3; BitSet[] minmaxFollowPos = this.CalculateTotalFollowposForRangeNodes(firstpos, followpos, out set3); if (this.enableUpaCheck) { this.CheckCMUPAWithLeafRangeNodes(this.GetApplicableMinMaxFollowPos(firstpos, set3, minmaxFollowPos)); for (int j = 0; j < num; j++) { this.CheckCMUPAWithLeafRangeNodes(this.GetApplicableMinMaxFollowPos(followpos[j], set3, minmaxFollowPos)); } } return new RangeContentValidator(firstpos, followpos, this.symbols, this.positions, node2.Pos, base.ContentType, parent.LeftChild.IsNullable, set3, this.minMaxNodesCount); } int[][] transitionTable = null; if (!this.symbols.IsUpaEnforced) { if (this.enableUpaCheck) { this.CheckUniqueParticleAttribution(firstpos, followpos); } } else if (useDFA) { transitionTable = this.BuildTransitionTable(firstpos, followpos, node2.Pos); } if (transitionTable != null) { return new DfaContentValidator(transitionTable, this.symbols, base.ContentType, base.IsOpen, parent.LeftChild.IsNullable); } return new NfaContentValidator(firstpos, followpos, this.symbols, this.positions, node2.Pos, base.ContentType, base.IsOpen, parent.LeftChild.IsNullable); }
public ContentValidator Finish(bool useDFA) { if (this.contentNode == null) { if (base.ContentType != XmlSchemaContentType.Mixed) { return(ContentValidator.Empty); } bool isOpen = base.IsOpen; if (!base.IsOpen) { return(ContentValidator.TextOnly); } return(ContentValidator.Any); } InteriorNode parent = new SequenceNode { LeftChild = this.contentNode }; LeafNode node2 = new LeafNode(this.positions.Add(this.symbols.AddName(XmlQualifiedName.Empty, null), null)); parent.RightChild = node2; this.contentNode.ExpandTree(parent, this.symbols, this.positions); int count = this.symbols.Count; int num = this.positions.Count; BitSet firstpos = new BitSet(num); BitSet lastpos = new BitSet(num); BitSet[] followpos = new BitSet[num]; for (int i = 0; i < num; i++) { followpos[i] = new BitSet(num); } parent.ConstructPos(firstpos, lastpos, followpos); if (this.minMaxNodesCount > 0) { BitSet set3; BitSet[] minmaxFollowPos = this.CalculateTotalFollowposForRangeNodes(firstpos, followpos, out set3); if (this.enableUpaCheck) { this.CheckCMUPAWithLeafRangeNodes(this.GetApplicableMinMaxFollowPos(firstpos, set3, minmaxFollowPos)); for (int j = 0; j < num; j++) { this.CheckCMUPAWithLeafRangeNodes(this.GetApplicableMinMaxFollowPos(followpos[j], set3, minmaxFollowPos)); } } return(new RangeContentValidator(firstpos, followpos, this.symbols, this.positions, node2.Pos, base.ContentType, parent.LeftChild.IsNullable, set3, this.minMaxNodesCount)); } int[][] transitionTable = null; if (!this.symbols.IsUpaEnforced) { if (this.enableUpaCheck) { this.CheckUniqueParticleAttribution(firstpos, followpos); } } else if (useDFA) { transitionTable = this.BuildTransitionTable(firstpos, followpos, node2.Pos); } if (transitionTable != null) { return(new DfaContentValidator(transitionTable, this.symbols, base.ContentType, base.IsOpen, parent.LeftChild.IsNullable)); } return(new NfaContentValidator(firstpos, followpos, this.symbols, this.positions, node2.Pos, base.ContentType, base.IsOpen, parent.LeftChild.IsNullable)); }