static TextSpan? CalculateMethodSpan(SourceStatement[] statements) { int min = int.MaxValue; int max = int.MinValue; foreach (var statement in statements) { if (min > statement.TextSpan.Start) min = statement.TextSpan.Start; if (max < statement.TextSpan.End) max = statement.TextSpan.End; } return min <= max ? TextSpan.FromBounds(min, max) : (TextSpan?)null; }
/// <summary> /// Constructor /// </summary> /// <param name="method">Method</param> /// <param name="statements">Statements</param> /// <param name="locals">Locals</param> /// <param name="methodSpan">Method span or null to calculate it from <paramref name="statements"/></param> public MethodDebugInfo(MethodDef method, SourceStatement[] statements, SourceLocal[] locals, TextSpan? methodSpan) { if (method == null) throw new ArgumentNullException(nameof(method)); if (statements == null) throw new ArgumentNullException(nameof(statements)); if (locals == null) throw new ArgumentNullException(nameof(locals)); Method = method; if (statements.Length > 1) Array.Sort(statements, SourceStatement.SpanStartComparer); Statements = statements; Locals = locals; Span = methodSpan ?? CalculateMethodSpan(statements) ?? new TextSpan(0, 0); }
/// <summary> /// Adds a <see cref="SourceStatement"/> /// </summary> /// <param name="statement">Statement</param> public void Add(SourceStatement statement) => statements.Add(statement);
/// <summary> /// Gets step ranges /// </summary> /// <param name="sourceStatement">Source statement</param> /// <returns></returns> public uint[] GetRanges(SourceStatement sourceStatement) { var list = new List<BinSpan>(GetUnusedBinSpans().Length + 1); list.Add(sourceStatement.BinSpan); list.AddRange(GetUnusedBinSpans()); var orderedList = BinSpan.OrderAndCompactList(list); if (orderedList.Count == 0) return Array.Empty<uint>(); var binSpanArray = new uint[orderedList.Count * 2]; for (int i = 0; i < orderedList.Count; i++) { binSpanArray[i * 2 + 0] = orderedList[i].Start; binSpanArray[i * 2 + 1] = orderedList[i].End; } return binSpanArray; }
public override Statement EmitStatement(EmitMode mode) { if (mode == EmitMode.ForStorage) { SaveObjectID(); SaveLocator(); } else { RemoveObjectID(); RemoveLocator(); } try { IMetaData result; if ((mode != EmitMode.ForRemote) && (DeclarationText != null)) { SourceStatement statement = new SourceStatement(); statement.Source = DeclarationText + InitializationText + AggregationText + FinalizationText; result = statement; } else { CreateAggregateOperatorStatement statement = new CreateAggregateOperatorStatement(); statement.OperatorName = Schema.Object.EnsureRooted(OperatorName); foreach (Operand operand in Operands) { FormalParameter formalParameter = new FormalParameter(); formalParameter.Identifier = operand.Name; formalParameter.TypeSpecifier = operand.DataType.EmitSpecifier(mode); formalParameter.Modifier = operand.Modifier; statement.FormalParameters.Add(formalParameter); } statement.ReturnType = ReturnDataType.EmitSpecifier(mode); #if USEVIRTUAL statement.IsVirtual = IsVirtual; statement.IsAbstract = IsAbstract; statement.IsOverride = IsOverride; statement.IsReintroduced = IsReintroduced; #endif if ((mode == EmitMode.ForRemote) && !IsRemotable) { statement.Initialization.Block = new Block(); statement.Aggregation.Block = new Block(); statement.Finalization.Block = new Block(); } else { Initialization.EmitStatement(mode, statement.Initialization); Aggregation.EmitStatement(mode, statement.Aggregation); Finalization.EmitStatement(mode, statement.Finalization); } result = statement; } result.MetaData = MetaData == null ? null : MetaData.Copy(); if (SessionObjectName != null) { if (result.MetaData == null) { result.MetaData = new MetaData(); } result.MetaData.Tags.AddOrUpdate("DAE.GlobalObjectName", OperatorName, true); } return((Statement)result); } finally { if (mode == EmitMode.ForStorage) { RemoveObjectID(); RemoveLocator(); } } }