/*
 * Copyright (c) Contributors to the Open 3D Engine Project.
 * For complete copyright and license terms please see the LICENSE at the root of this distribution.
 * 
 * SPDX-License-Identifier: Apache-2.0 OR MIT
 *
 */
#pragma once

#include "StdUtils.h"

namespace AZ::ShaderCompiler
{
    //! Describes a preprocessor line directive.
    //! this is not part of the AST, that is why this is not in AzslcUtils.h
    struct LineDirectiveInfo
    {
        size_t m_physicalTokenLine;  //!< line where the preprocessor token appears
        size_t m_forcedLineNumber;   //!< the line number as specified (parsed from syntax input)
        string m_containingFilename;
    };

    //! An interface capable of finding the original line in the source file
    //! for the given flat file that is being compiled.
    //! A preprocessed azsl file is the file generated by MCPP after all #include and macro definitions
    //! have been resolved in a single flat file.
    //! If an error is observed at any given line in the flat file, you can use this interface to find the original file
    //! and line number where the error is coming from.
    class PreprocessorLineDirectiveFinder
    {
    public:
        virtual ~PreprocessorLineDirectiveFinder() {};

        virtual const LineDirectiveInfo* GetNearestPreprocessorLineDirective(size_t azslLineNumber) const = 0;

        virtual size_t GetLineNumberInOriginalSourceFile(const LineDirectiveInfo& lineInfo, size_t azslLineNumber) const
        {
            const size_t lineNumberOfDirectiveinAzslSource = lineInfo.m_physicalTokenLine;
            const size_t relativeLineNumber = azslLineNumber - lineNumberOfDirectiveinAzslSource;
            const size_t absoluteLineNumberInIncludedFile = lineInfo.m_forcedLineNumber + relativeLineNumber - 1;
            return absoluteLineNumberInIncludedFile;
        }
    };
}