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