private void WriteUsedNameSpace(UsedNamespace uns) { if (uns == null) { return; } this.writer.WriteStartElement("Using"); this.WriteSourceContext(uns.SourceContext); this.writer.WriteEndElement(); // Using }
public virtual UsedNamespace VisitUsedNamespace(UsedNamespace usedNamespace, UsedNamespace changes, UsedNamespace deletions, UsedNamespace insertions){ this.UpdateSourceContext(usedNamespace, changes); if (usedNamespace == null) return changes; if (changes != null){ if (deletions == null || insertions == null) Debug.Assert(false); else{ } }else if (deletions != null) return null; return usedNamespace; }
public virtual UsedNamespace GetClosestMatch(UsedNamespace/*!*/ nd1, UsedNamespaceList/*!*/ list1, UsedNamespaceList list2, int list1pos, ref int list2start, TrivialHashtable/*!*/ matchedNodes, out Differences closestDifferences, out int list2pos) { closestDifferences = null; list2pos = -1; if (list2 == null) return null; if (nd1 == null || list1 == null || matchedNodes == null || list1pos < 0 || list1pos >= list1.Count || list2start < 0 || list2start >= list2.Count) { Debug.Assert(false); return null; } UsedNamespace closest = null; Differences winnerSoFar = null; for (int j = list2start, m = list2.Count; j < m; j++){ UsedNamespace nd2 = list2[j]; if (list2start == j) list2start++; if (nd2 == null) continue; if (matchedNodes[nd2.UniqueKey] != null) continue; Differences diff = this.GetDifferences(nd1, nd2); if (diff == null){Debug.Assert(false); continue;} if (diff.Similarity <= 0.5){ //Not a good enough match if (list2start == j+1) list2start--; //The next call to GetClosestMatch will start looking at list2start, so this node will be considered then continue; //ignore it for the rest of this call } if (winnerSoFar != null && winnerSoFar.Similarity >= diff.Similarity) continue; winnerSoFar = closestDifferences = diff; closest = nd2; list2pos = j; if (diff.NumberOfDifferences == 0) return closest; //Perfect match, no need to look for other matches } if (closest != null){ //^ assert winnerSoFar != null; //closest is closer to nd1 than any other node in list2, but this is no good if some other node in list1 has a better claim on closest for (int i = list1pos+1, n = list1.Count; i < n; i++){ UsedNamespace nd1alt = list1[i]; if (nd1alt == null) continue; if (matchedNodes[nd1alt.UniqueKey] != null) continue; Differences diff = this.GetDifferences(nd1alt, closest); if (diff == null){Debug.Assert(false); continue;} if (diff.Similarity <= winnerSoFar.Similarity) continue; //nd1alt has a better claim on closest. See if it wants closest. Differences diff2; int j, k = list2start; UsedNamespace nd2alt = this.GetClosestMatch(nd1alt, list1, list2, i, ref k, matchedNodes, out diff2, out j); if (nd2alt != closest){ Debug.Assert(nd2alt != null && diff2 != null && diff2.Similarity >= diff.Similarity); continue; //nd1alt prefers nd2alt to closest, so closest is still available } //nd1alt wants closest, take it out of the running matchedNodes[closest.UniqueKey] = nd1alt; //Now that closest is out of the running, try again k = list2start; UsedNamespace newClosest = this.GetClosestMatch(nd1, list1, list2, i, ref k, matchedNodes, out winnerSoFar, out list2pos); //put closest back in the running so that the next call to this routine will pick it up matchedNodes[closest.UniqueKey] = closest; closest = newClosest; break; } } closestDifferences = winnerSoFar; return closest; }
public virtual Differences VisitUsedNamespace(UsedNamespace usedNamespace1, UsedNamespace usedNamespace2){ Differences differences = new Differences(usedNamespace1, usedNamespace2); if (usedNamespace1 == null || usedNamespace2 == null){ if (usedNamespace1 != usedNamespace2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++; return differences; } UsedNamespace changes = (UsedNamespace)usedNamespace2.Clone(); UsedNamespace deletions = (UsedNamespace)usedNamespace2.Clone(); UsedNamespace insertions = (UsedNamespace)usedNamespace2.Clone(); Differences diff = this.VisitIdentifier(usedNamespace1.Namespace, usedNamespace2.Namespace); if (diff == null){Debug.Assert(false); return differences;} changes.Namespace = diff.Changes as Identifier; deletions.Namespace = diff.Deletions as Identifier; insertions.Namespace = diff.Insertions as Identifier; Debug.Assert(diff.Changes == changes.Namespace && diff.Deletions == deletions.Namespace && diff.Insertions == insertions.Namespace); differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; diff = this.VisitIdentifier(usedNamespace1.URI, usedNamespace2.URI); if (diff == null){Debug.Assert(false); return differences;} changes.URI = diff.Changes as Identifier; deletions.URI = diff.Deletions as Identifier; insertions.URI = diff.Insertions as Identifier; Debug.Assert(diff.Changes == changes.URI && diff.Deletions == deletions.URI && diff.Insertions == insertions.URI); differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; if (differences.NumberOfDifferences == 0){ differences.Changes = null; differences.Deletions = null; differences.Insertions = null; }else{ differences.Changes = changes; differences.Deletions = deletions; differences.Insertions = insertions; } return differences; }
public virtual UsedNamespace VisitUsedNamespace(UsedNamespace usedNamespace){ return usedNamespace; }
public virtual void VisitUsedNamespace(UsedNamespace usedNamespace) { }
public override UsedNamespace VisitUsedNamespace(UsedNamespace usedNamespace) { if (usedNamespace == null) return null; return base.VisitUsedNamespace((UsedNamespace)usedNamespace.Clone()); }
public override UsedNamespace VisitUsedNamespace(UsedNamespace usedNamespace) { throw new ApplicationException("unimplemented"); }
public virtual UsedNamespace VisitUsedNamespace(UsedNamespace usedNamespace1, UsedNamespace usedNamespace2) { return usedNamespace1; }
private void ParseUsingDirective(Namespace ns, TokenSet followers){ Debug.Assert(this.currentToken == Token.Using); SourceContext sctx = this.scanner.CurrentSourceContext; this.GetNextToken(); Identifier id = this.scanner.GetIdentifier(); if (!Parser.IdentifierOrNonReservedKeyword[this.currentToken]) { this.SkipTo(followers, Error.ExpectedIdentifier); if (this.currentToken == Token.EndOfFile){ id.SourceContext.StartPos -= 2; UsedNamespace usedNS = new UsedNamespace(id, sctx); ns.UsedNamespaces.Add(usedNS); } return; } this.GetNextToken(); TokenSet followersOrSemicolon = followers|Token.Semicolon; if (this.currentToken == Token.Assign){ this.GetNextToken(); Expression aliasedId = this.ParseNamespaceOrTypeName(Identifier.Empty, true, followersOrSemicolon); sctx.EndPos = this.scanner.endPos; ns.AliasDefinitions.Add(new AliasDefinition(id, aliasedId, sctx)); }else{ tryAgain: if (this.currentToken == Token.Dot){ this.GetNextToken(); id = this.ParseNamespaceName(id, false, followersOrSemicolon); }else if (id.Prefix == null && this.currentToken == Token.DoubleColon){ this.GetNextToken(); Identifier ident = this.scanner.GetIdentifier(); this.SkipIdentifierOrNonReservedKeyword(); ident.Prefix = id; ident.SourceContext.StartPos = id.SourceContext.StartPos; id = ident; goto tryAgain; } UsedNamespace usedNS = new UsedNamespace(id); //TODO: used namespaces should use structured expressions so that they can expand root aliases sctx.EndPos = this.scanner.endPos; usedNS.SourceContext = sctx; ns.UsedNamespaces.Add(usedNS); } this.SkipSemiColon(followers); }
private UsedNamespace Translate(CodeNamespaceImport nsImport){ if (nsImport == null) return null; UsedNamespace usedNS = new UsedNamespace(); usedNS.Namespace = Identifier.For(nsImport.Namespace); return usedNS; }
public override UsedNamespace VisitUsedNamespace(UsedNamespace usedNamespace) { throw new ApplicationException("unimplemented"); }
private void WriteUsedNameSpace(UsedNamespace uns) { if (uns == null) return; this.writer.WriteStartElement("Using"); this.WriteSourceContext(uns.SourceContext); this.writer.WriteEndElement(); // Using }