/// <summary> /// /// </summary> /// <param name="localDefinition"></param> /// <param name="isCompilerGenerated"></param> /// <returns></returns> public string GetSourceNameFor(ILocalDefinition localDefinition, out bool isCompilerGenerated) { isCompilerGenerated = true; PdbFunction /*?*/ pdbFunction = this.GetPdbFunctionFor(localDefinition); if (pdbFunction != null) { uint index = 0; foreach (ILocation location in localDefinition.Locations) { IILLocation /*?*/ mbLocation = location as IILLocation; if (mbLocation != null) { index = mbLocation.Offset; break; } } PdbSlot /*?*/ slot = this.GetSlotFor(pdbFunction.scopes, index); if (slot != null) { isCompilerGenerated = (slot.flags & 0x4) != 0; return(slot.name); } } return(localDefinition.Name.Value); }
private ITypeReference GetTypeForConstant() { foreach (ILocation location in this.methodDefinition.Locations) { IILLocation /*?*/ mbLocation = location as IILLocation; if (mbLocation != null) { var doc = mbLocation.Document as MethodBodyDocument; if (doc != null) { ITypeReference result = doc.GetTypeFromToken(this.pdbConstant.token); if (result is Dummy) { //TODO: error continue; } return(result); } } } IPlatformType platformType = this.methodDefinition.Type.PlatformType; IConvertible ic = this.pdbConstant.value as IConvertible; if (ic == null) { return(platformType.SystemObject); } switch (ic.GetTypeCode()) { case TypeCode.Boolean: return(platformType.SystemBoolean); case TypeCode.Byte: return(platformType.SystemUInt8); case TypeCode.Char: return(platformType.SystemChar); case TypeCode.Decimal: return(platformType.SystemDecimal); case TypeCode.Double: return(platformType.SystemFloat64); case TypeCode.Int16: return(platformType.SystemInt16); case TypeCode.Int32: return(platformType.SystemInt32); case TypeCode.Int64: return(platformType.SystemInt64); case TypeCode.SByte: return(platformType.SystemInt8); case TypeCode.Single: return(platformType.SystemFloat64); case TypeCode.String: return(platformType.SystemString); case TypeCode.UInt16: return(platformType.SystemUInt16); case TypeCode.UInt32: return(platformType.SystemUInt32); case TypeCode.UInt64: return(platformType.SystemUInt64); default: return(platformType.SystemObject); } }
/// <summary> /// Return zero or more locations in primary source documents that correspond to one or more of the given derived (non primary) document locations. /// </summary> /// <param name="locations">Zero or more locations in documents that have been derived from one or more source documents.</param> public IEnumerable <IPrimarySourceLocation> GetPrimarySourceLocationsFor(IEnumerable <ILocation> locations) { foreach (ILocation location in locations) { IPrimarySourceLocation /*?*/ psloc = location as IPrimarySourceLocation; if (psloc != null) { yield return(psloc); } IILLocation /*?*/ mbLocation = location as IILLocation; if (mbLocation != null) { psloc = this.MapMethodBodyLocationToSourceLocation(mbLocation, true); if (psloc != null) { yield return(psloc); } } else { var mdLocation = location as IMetadataLocation; if (mdLocation != null) { PdbTokenLine lineInfo; if (!this.tokenToSourceMapping.TryGetValue(mdLocation.Definition.TokenValue, out lineInfo)) { yield break; } PdbSourceDocument psDoc = this.GetPrimarySourceDocumentFor(lineInfo.sourceFile); yield return(new PdbSourceLineLocation(psDoc, (int)lineInfo.line, (int)lineInfo.column, (int)lineInfo.endLine, (int)lineInfo.endColumn)); } } } }
private ILocalScopeProvider /*?*/ GetProvider(IILLocation /*?*/ mbLocation) { if (mbLocation == null) { return(null); } return(this.GetProvider(mbLocation.MethodDefinition)); }
private IPrimarySourceLocation /*?*/ MapMethodBodyLocationToSourceLocation(IILLocation mbLocation, bool exact) { PdbFunction pdbFunction; var doc = mbLocation.Document as MethodBodyDocument; if (doc == null || !this.pdbFunctionMap.TryGetValue(doc.MethodToken, out pdbFunction)) { return(null); } if (pdbFunction.lines == null) { return(null); } foreach (PdbLines pdbLines in pdbFunction.lines) { PdbSource pdbSourceFile = pdbLines.file; if (pdbSourceFile == null) { return(null); } PdbLine[] array = pdbLines.lines; int minIndex = 0; int maxIndex = array.Length - 1; uint desiredOffset = mbLocation.Offset; while (minIndex <= maxIndex) { int midPointIndex = (minIndex + maxIndex) >> 1; PdbLine mid = array[midPointIndex]; if (midPointIndex == maxIndex || (mid.offset <= desiredOffset && desiredOffset < array[midPointIndex + 1].offset)) { if (exact && desiredOffset != mid.offset) { return(null); } PdbLine line = mid; PdbSourceDocument psDoc = this.GetPrimarySourceDocumentFor(pdbSourceFile); return(new PdbSourceLineLocation(psDoc, (int)line.lineBegin, line.colBegin, (int)line.lineEnd, line.colEnd)); } if (mid.offset < desiredOffset) { minIndex = midPointIndex + 1; } else { maxIndex = midPointIndex - 1; } } } return(null); }
public IEnumerable <IPrimarySourceLocation> GetAllPrimarySourceLocationsFor(ILocation location) { IILLocation /*?*/ mbLocation = location as IILLocation; if (mbLocation == null) { return(GetPrimarySourceLocationsFor(location)); } return(MapMethodBodyLocationToSourceLocations(mbLocation)); }
private IEnumerable <IPrimarySourceLocation /*?*/> MapLocationToSourceLocations(ILocation location) { IILLocation /*?*/ mbLocation = location as IILLocation; ISourceLocationProvider provider = this.GetProvider(mbLocation); if (provider != null) { return(provider.GetPrimarySourceLocationsFor(location)); } return(Enumerable <IPrimarySourceLocation> .Empty); }
private IEnumerable <IPrimarySourceLocation /*?*/> MapLocationToSourceLocations(ILocation location) { IILLocation /*?*/ mbLocation = location as IILLocation; ISourceLocationProvider provider = this.GetProvider(mbLocation); if (provider != null) { foreach (var psloc in provider.GetPrimarySourceLocationsFor(location)) { yield return(psloc); } } }
private static uint GetTokenFor(IMethodBody methodBody) { foreach (ILocation location in methodBody.MethodDefinition.Locations) { IILLocation /*?*/ mbLocation = location as IILLocation; if (mbLocation != null) { var doc = mbLocation.Document as MethodBodyDocument; if (doc != null) { return(doc.MethodToken); } } } return(0); }
private static ITokenDecoder /*?*/ GetTokenDecoderFor(IMethodBody methodBody, out uint methodToken) { foreach (ILocation location in methodBody.MethodDefinition.Locations) { IILLocation /*?*/ mbLocation = location as IILLocation; if (mbLocation != null) { var doc = mbLocation.Document as MethodBodyDocument; if (doc != null) { methodToken = doc.MethodToken; return(doc.TokenDecoder); } } } methodToken = 0; return(null); }
private PdbFunction GetPdbFunctionFor(ILocalDefinition localDefinition) { PdbFunction /*?*/ result = null; foreach (ILocation location in localDefinition.Locations) { IILLocation /*?*/ mbLocation = location as IILLocation; if (mbLocation != null) { var doc = mbLocation.Document as MethodBodyDocument; if (doc != null) { this.pdbFunctionMap.TryGetValue(doc.MethodToken, out result); break; } } } return(result); }
internal void AddILError( IMethodDefinition methodDefinition, uint offset, MetadataReaderErrorKind errorKind ) { foreach (MetadataReaderErrorMessage errMessage in this.ErrorList.GetValuesFor((uint)errorKind)) { IILLocation /*?*/ ilLocation = errMessage.Location as IILLocation; if (ilLocation == null) { continue; } if (ilLocation.Offset == offset && ilLocation.MethodDefinition.Equals(methodDefinition)) { return; } } this.AddMetadataReaderErrorMessage(new MetadataReaderErrorMessage(this.MetadataReader.ErrorsReporter, new ILLocation(this.BinaryDocument, methodDefinition, offset), errorKind)); }
/// <summary> /// Return zero or more locations in primary source documents that are the closest to corresponding to one or more of the given derived (non primary) document locations. /// </summary> /// <param name="locations">Zero or more locations in documents that have been derived from one or more source documents.</param> public IEnumerable <IPrimarySourceLocation> GetClosestPrimarySourceLocationsFor(IEnumerable <ILocation> locations) { foreach (ILocation location in locations) { IPrimarySourceLocation /*?*/ psloc = location as IPrimarySourceLocation; if (psloc != null) { yield return(psloc); } IILLocation /*?*/ mbLocation = location as IILLocation; if (mbLocation != null) { psloc = this.MapMethodBodyLocationToSourceLocation(mbLocation, false); if (psloc != null) { yield return(psloc); } } } }
/// <summary> /// Return zero or more locations in primary source documents that correspond to the given derived (non primary) document location. /// </summary> /// <param name="location">A location in a document that have been derived from one or more source documents.</param> public IEnumerable <IPrimarySourceLocation> GetPrimarySourceLocationsFor(ILocation location) { var psloc = location as IPrimarySourceLocation; if (psloc != null) { yield return(psloc); } else { IILLocation /*?*/ mbLocation = location as IILLocation; if (mbLocation != null) { psloc = this.MapMethodBodyLocationToSourceLocation(mbLocation, true); if (psloc != null) { yield return(psloc); } } } }
private ITypeReference GetTypeForVariable() { foreach (ILocation location in this.methodDefinition.Locations) { IILLocation /*?*/ mbLocation = location as IILLocation; if (mbLocation != null) { var doc = mbLocation.Document as MethodBodyDocument; if (doc != null) { ITypeReference result = doc.GetTypeFromToken(this.pdbSlot.typeToken); if (result is Dummy) { //TODO: error continue; } return(result); } } } return(this.host.PlatformType.SystemBoolean); }
/// <summary> /// Return zero or more locations in primary source documents that correspond to the definition of the given local. /// </summary> public IEnumerable <IPrimarySourceLocation> GetPrimarySourceLocationsForDefinitionOf(ILocalDefinition localDefinition) { PdbFunction /*?*/ pdbFunction = this.GetPdbFunctionFor(localDefinition); if (pdbFunction != null) { uint index = 0; foreach (ILocation location in localDefinition.Locations) { IILLocation /*?*/ mbLocation = location as IILLocation; if (mbLocation != null) { index = mbLocation.Offset; break; } } PdbSlot /*?*/ slot = this.GetSlotFor(pdbFunction.scopes, index); if (slot != null && (slot.flags & 0x4) == 0) { return(IteratorHelper.GetSingletonEnumerable <IPrimarySourceLocation>(new LocalNameSourceLocation(slot.name))); } } return(Enumerable <IPrimarySourceLocation> .Empty); }
/*?*/ private ISourceLocationProvider GetProvider(IILLocation/*?*/ mbLocation) { if (mbLocation == null) return null; return this.GetProvider(mbLocation.MethodDefinition); }
private IEnumerable <IPrimarySourceLocation> MapMethodBodyLocationToSourceLocations(IILLocation mbLocation) { PdbFunction pdbFunction = null; var doc = mbLocation.Document as MethodBodyDocument; if (doc == null || !this.pdbFunctionMap.TryGetValue(doc.MethodToken, out pdbFunction)) { yield break; } if (pdbFunction.lines == null) { yield break; } foreach (PdbLines pdbLines in pdbFunction.lines) { foreach (var pdbLine in pdbLines.lines) { PdbSource pdbSourceFile = pdbLines.file; if (pdbSourceFile == null) { continue; } PdbSourceDocument psDoc = this.GetPrimarySourceDocumentFor(pdbSourceFile); yield return(new PdbSourceLineLocation(psDoc, (int)pdbLine.lineBegin, pdbLine.colBegin, (int)pdbLine.lineEnd, pdbLine.colEnd)); } } }
private IEnumerable<IPrimarySourceLocation> MapMethodBodyLocationToSourceLocations(IILLocation mbLocation) { PdbFunction pdbFunction = null; var doc = mbLocation.Document as MethodBodyDocument; if (doc == null || !this.pdbFunctionMap.TryGetValue(doc.MethodToken, out pdbFunction)) yield break; if (pdbFunction.lines == null) yield break; foreach (PdbLines pdbLines in pdbFunction.lines) { foreach (var pdbLine in pdbLines.lines) { PdbSource pdbSourceFile = pdbLines.file; if (pdbSourceFile == null) continue; PdbSourceDocument psDoc = this.GetPrimarySourceDocumentFor(pdbSourceFile); yield return new PdbSourceLineLocation(psDoc, (int)pdbLine.lineBegin, pdbLine.colBegin, (int)pdbLine.lineEnd, pdbLine.colEnd); } } }
private IPrimarySourceLocation/*?*/ MapMethodBodyLocationToSourceLocation(IILLocation mbLocation, bool exact) { PdbFunction/*?*/ pdbFunction; var doc = mbLocation.Document as MethodBodyDocument; if (doc == null || !this.pdbFunctionMap.TryGetValue(doc.MethodToken, out pdbFunction)) return null; if (pdbFunction.lines == null) return null; foreach (PdbLines pdbLines in pdbFunction.lines) { PdbSource pdbSourceFile = pdbLines.file; if (pdbSourceFile == null) return null; PdbLine[] array = pdbLines.lines; int minIndex = 0; int maxIndex = array.Length - 1; uint desiredOffset = mbLocation.Offset; while (minIndex <= maxIndex) { int midPointIndex = (minIndex + maxIndex) >> 1; PdbLine mid = array[midPointIndex]; if (midPointIndex == maxIndex || (mid.offset <= desiredOffset && desiredOffset < array[midPointIndex + 1].offset)) { if (exact && desiredOffset != mid.offset) return null; PdbLine line = mid; PdbSourceDocument psDoc = this.GetPrimarySourceDocumentFor(pdbSourceFile); return new PdbSourceLineLocation(psDoc, (int)line.lineBegin, line.colBegin, (int)line.lineEnd, line.colEnd); } if (mid.offset < desiredOffset) minIndex = midPointIndex + 1; else maxIndex = midPointIndex - 1; } } return null; }
private ILocalScopeProvider/*?*/ GetProvider(IILLocation/*?*/ mbLocation) { if (mbLocation == null) return null; return this.GetProvider(mbLocation.MethodDefinition); }