// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using EpicGames.Core; namespace UnrealBuildTool { /// /// Represents an fragment of a source file consisting of a sequence of includes followed by some arbitrary directives or source code. /// [Serializable] class SourceFileFragment { /// /// The file that this fragment is part of /// public readonly SourceFile File; /// /// Index into the file's markup array of the start of this fragment (inclusive) /// public readonly int MarkupMin; /// /// Index into the file's markup array of the end of this fragment (exclusive). Set to zero for external files. /// public readonly int MarkupMax; /// /// List of known transforms for this fragment /// public PreprocessorTransform[] Transforms = new PreprocessorTransform[0]; /// /// Constructor /// /// The source file that this fragment is part of /// Index into the file's markup array of the start of this fragment (inclusive) /// Index into the file's markup array of the end of this fragment (exclusive) public SourceFileFragment(SourceFile File, int MarkupMin, int MarkupMax) { this.File = File; this.MarkupMin = MarkupMin; this.MarkupMax = MarkupMax; } /// /// Constructor /// /// The source file that this fragment is part of /// Reader to deserialize this object from public SourceFileFragment(SourceFile File, BinaryArchiveReader Reader) { this.File = File; this.MarkupMin = Reader.ReadInt(); this.MarkupMax = Reader.ReadInt(); this.Transforms = Reader.ReadArray(() => new PreprocessorTransform(Reader))!; } /// /// Write this fragment to an archive /// /// The writer to serialize to public void Write(BinaryArchiveWriter Writer) { Writer.WriteInt(MarkupMin); Writer.WriteInt(MarkupMax); Writer.WriteArray(Transforms, x => x.Write(Writer)); } /// /// Summarize this fragment for the debugger /// /// String representation of this fragment for the debugger public override string ToString() { if(MarkupMax == 0) { return File.ToString(); } else { return String.Format("{0}: {1}-{2}", File.ToString(), File.Markup[MarkupMin].LineNumber, File.Markup[MarkupMax - 1].LineNumber + 1); } } } }