// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using UnrealBuildBase;
namespace UnrealBuildTool
{
///
/// Represents a context that the preprocessor is working in. Used to form error messages, and determine things like the __FILE__ and __LINE__ directives.
///
abstract class PreprocessorContext
{
///
/// The outer context
///
public readonly PreprocessorContext? Outer;
///
/// Constructor
///
/// The outer context
public PreprocessorContext(PreprocessorContext? outer)
{
Outer = outer;
}
}
///
/// Context for a command line argument
///
class PreprocessorCommandLineContext : PreprocessorContext
{
///
/// Constructor
///
public PreprocessorCommandLineContext()
: base(null)
{
}
///
/// Formats this context for error messages
///
/// String describing this context
public override string ToString()
{
return "From command line";
}
}
///
/// Represents a context that the preprocessor is reading from
///
class PreprocessorFileContext : PreprocessorContext
{
///
/// The source file being read
///
public readonly SourceFile SourceFile;
///
/// The directory containing this file. When searching for included files, MSVC will check this directory.
///
public readonly DirectoryItem Directory;
///
/// Index of the current markup object being processed
///
public int MarkupIdx { get; set; }
///
/// Index of the next fragment to be read
///
public int FragmentIdx { get; set; }
///
/// Constructor
///
/// The source file being parsed
/// The outer context
public PreprocessorFileContext(SourceFile sourceFile, PreprocessorContext? outer)
: base(outer)
{
SourceFile = sourceFile;
Directory = DirectoryItem.GetItemByDirectoryReference(sourceFile.Location.Directory);
MarkupIdx = 0;
FragmentIdx = 0;
}
///
/// Format this file for the debugger, and error messages
///
///
public override string ToString()
{
return String.Format("{0}({1})", SourceFile.Location, SourceFile.Markup[MarkupIdx].LineNumber);
}
}
}