Program Listing for File preproc.h#
↰ Return to documentation for file (sdv_idl_compiler\preproc.h)
/********************************************************************************
* Copyright (c) 2025-2026 ZF Friedrichshafen AG
*
* This program and the accompanying materials are made available under the
* terms of the Apache License Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* Erik Verhoeven - initial API and implementation
********************************************************************************/
#ifndef PREPROC_H
#define PREPROC_H
#include "token.h"
#include "codepos.h"
#include "environment.h"
#include <filesystem>
// Forward declaration
class CLexer;
class CParser;
class CPreprocessor
{
public:
CPreprocessor(CParser& rParser);
CToken ProcessPreproc(CCodePos& rCode, const CContextPtr& rptrContext);
void FinalProcessing(const CCodePos& rCode);
bool CurrentSectionEnabled() const;
virtual void IncludeFile(const std::filesystem::path& rpath, bool bLocal) = 0;
virtual CIdlCompilerEnvironment& GetEnvironment() = 0;
private:
void ProcessDefine(CLexer& rLexer, CCodePos& rCode, const CContextPtr& rptrContext);
void ProcessUndef(CLexer& rLexer, CCodePos& rCode, const CContextPtr& rptrContext);
void ProcessInclude(CLexer& rLexer, CCodePos& rCode, const CContextPtr& rptrContext, bool& rbLocal);
void ProcessIf(CLexer& rLexer, CCodePos& rCode, const CContextPtr& rptrContext);
void ProcessIfDef(CLexer& rLexer, CCodePos& rCode, const CContextPtr& rptrContext, bool bInverted);
void ProcessElif(CLexer& rLexer, CCodePos& rCode, const CContextPtr& rptrContext);
void ProcessElse(CLexer& rLexer, const CCodePos& rCode, const CContextPtr& rptrContext);
void ProcessEndif(CLexer& rLexer, const CCodePos& rCode, const CContextPtr& rptrContext);
void ProcessVerbatim(CLexer& rLexer, CCodePos& rCode, const CContextPtr& rptrContext);
void ProcessVerbatimBlock(CLexer& rLexer, CCodePos& rCode, const CContextPtr& rptrContext);
int64_t ConditionalCalc(CLexer& rLexer, CCodePos& rCode, const CContextPtr& rptrContext, uint32_t uiPrecedence = 100);
enum class EConditionalInclusion
{
if_section,
else_section
};
enum class EConditionalProcessing
{
disabled,
current,
previous,
future
};
struct SConditionalControl
{
EConditionalInclusion m_eInclusionControl;
EConditionalProcessing m_eProcessingControl;
};
CParser& m_rParser;
std::stack<SConditionalControl> m_stackConditional;
};
#endif // !defined PREPROC_H