// Copyright Epic Games, Inc. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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)
{
this.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 SourceFile SourceFile;
///
/// The directory containing this file. When searching for included files, MSVC will check this directory.
///
public DirectoryItem Directory;
///
/// Index of the current markup object being processed
///
public int MarkupIdx;
///
/// Index of the next fragment to be read
///
public int FragmentIdx;
///
/// Constructor
///
/// The source file being parsed
/// The outer context
public PreprocessorFileContext(SourceFile SourceFile, PreprocessorContext Outer)
: base(Outer)
{
this.SourceFile = SourceFile;
this.Directory = DirectoryItem.GetItemByDirectoryReference(SourceFile.Location.Directory);
this.MarkupIdx = 0;
this.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);
}
}
}