internal static IPrimarySourceLocation GetPrimarySourceLocationFrom(IEnumerable <ILocation> locations) { IPrimarySourceLocation /*?*/ ploc = null; foreach (ILocation location in locations) { ploc = location as IPrimarySourceLocation; if (ploc != null) { break; } IDerivedSourceLocation /*?*/ dloc = location as IDerivedSourceLocation; if (dloc != null) { foreach (IPrimarySourceLocation dploc in dloc.PrimarySourceLocations) { ploc = dploc; break; } } } if (ploc == null) { ploc = SourceDummy.PrimarySourceLocation; } return(ploc); }
public IEnumerable<IPrimarySourceLocation> GetPrimarySourceLocationsFor(ILocation location) { IPrimarySourceLocation/*?*/ psloc = location as IPrimarySourceLocation; if (psloc != null) { IIncludedSourceLocation /*?*/ iloc = psloc as IncludedSourceLocation; if (iloc != null) yield return new OriginalSourceLocation(iloc); else yield return psloc; } else { IDerivedSourceLocation/*?*/ dsloc = location as IDerivedSourceLocation; if (dsloc != null) { foreach (IPrimarySourceLocation psl in dsloc.PrimarySourceLocations) { IIncludedSourceLocation /*?*/ iloc = psl as IncludedSourceLocation; if (iloc != null) yield return new OriginalSourceLocation(iloc); else yield return psl; } } var esloc = location as IExpressionSourceLocation; if (esloc != null) { yield return esloc.PrimarySourceLocation; } } }
public Token GetToken() { foreach (ILocation loc in locations) { IPrimarySourceLocation /*?*/ sloc = loc as IPrimarySourceLocation; if (sloc != null) { return(new SourceLocationWrapper(sloc, sloc, () => sloc.Source)); } IDerivedSourceLocation /*?*/ dloc = loc as IDerivedSourceLocation; if (dloc != null) { IPrimarySourceLocation fLoc = null, lLoc = null; foreach (IPrimarySourceLocation ploc in dloc.PrimarySourceLocations) { if (fLoc == null) { fLoc = ploc; } lLoc = ploc; } if (fLoc != null) { return(new SourceLocationWrapper(fLoc, lLoc, () => dloc.Source)); } } } return(Token.NoToken); }
/// <summary> /// Returns zero or more primary source locations that correspond to the given derived location. /// </summary> /// <param name="derivedSourceLocation">A source location in this derived document</param> //^ [Pure] public IEnumerable<IPrimarySourceLocation> GetPrimarySourceLocationsFor(IDerivedSourceLocation derivedSourceLocation) //^^ requires 0 <= position && (position < this.Length || position == 0); //^^ requires 0 <= length; //^^ requires length <= this.Length; //^^ requires position+length <= this.Length; //^^ ensures result.SourceDocument == this; //^^ ensures result.StartIndex == position; //^^ ensures result.Length == length; { foreach (ISourceLocation sourceLocation in this.GetFragmentLocationsFor(derivedSourceLocation)) { IPrimarySourceLocation/*?*/ primarySourceLocation = sourceLocation as IPrimarySourceLocation; if (primarySourceLocation != null) yield return primarySourceLocation; else { IDerivedSourceLocation/*?*/ dLoc = sourceLocation as IDerivedSourceLocation; if (dLoc != null) { foreach (IPrimarySourceLocation pLoc in dLoc.PrimarySourceLocations) yield return pLoc; } } } }
public IEnumerable<IPrimarySourceLocation> GetPrimarySourceLocationsFor(IDerivedSourceLocation derivedSourceLocation) { Contract.Requires(derivedSourceLocation != null); Contract.Requires(derivedSourceLocation.DerivedSourceDocument == this); Contract.Ensures(Contract.Result<IEnumerable<IPrimarySourceLocation>>() != null); throw new NotImplementedException(); }
//^^ requires 0 <= position && (position < this.Length || position == 0); //^^ requires 0 <= length; //^^ requires length <= this.Length; //^^ requires position+length <= this.Length; //^^ ensures result.SourceDocument == this; //^^ ensures result.StartIndex == position; //^^ ensures result.Length == length; /// <summary> /// Returns zero or more primary source locations that correspond to the given derived location. /// </summary> /// <param name="derivedSourceLocation">A source location in this derived document</param> //^ [Pure] public IEnumerable<IPrimarySourceLocation> GetPrimarySourceLocationsFor(IDerivedSourceLocation derivedSourceLocation) { foreach (ISourceLocation sourceLocation in this.GetFragmentLocationsFor(derivedSourceLocation)) { IPrimarySourceLocation/*?*/ primarySourceLocation = sourceLocation as IPrimarySourceLocation; if (primarySourceLocation != null) yield return primarySourceLocation; else { IDerivedSourceLocation/*?*/ dLoc = sourceLocation as IDerivedSourceLocation; if (dLoc != null) { foreach (IPrimarySourceLocation pLoc in dLoc.PrimarySourceLocations) yield return pLoc; } } } }