// Copyright Epic Games, Inc. All Rights Reserved. using System; 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 { get; set; } = Array.Empty(); /// /// 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) { File = file; MarkupMin = markupMin; MarkupMax = markupMax; } /// /// Constructor /// /// The source file that this fragment is part of /// Reader to deserialize this object from public SourceFileFragment(SourceFile file, BinaryArchiveReader reader) { File = file; MarkupMin = reader.ReadInt(); MarkupMax = reader.ReadInt(); 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); } } } }