Class CParser#

Nested Relationships#

Nested Types#

Inheritance Relationships#

Base Types#

Class Documentation#

class CParser : public CPreprocessor, public ILexerCallback, public sdv::idl::ICompilerInfo, public sdv::IInterfaceAccess#

SDV IDL lexer class.

Public Functions

CParser(const char *szCode, const CIdlCompilerEnvironment &renv = CIdlCompilerEnvironment())#

Constructor used to inject code directly into the parser (mainly for unit tests).

Attention

The pointer to the source file code needs to stay valid during the duration of the processing.

Parameters:
  • szCode[in] Zero terminated string containing the IDL code. Must not be NULL.

  • renv[in] Reference to the environment to start using as a base for search dirs and macros.

Throws:

ThrowsCCompileException on parse error.

CParser(const std::filesystem::path &rpath, const CIdlCompilerEnvironment &renv = CIdlCompilerEnvironment())#

Constructor.

Parameters:
  • rpath[in] Reference to the source file path. Must be a valid path.

  • renv[in] Reference to the environment to start using as a base for search dirs and macros.

Throws:

ThrowsCCompileException on parse error.

virtual ~CParser() = default#

Default destructor.

virtual sdv::interface_t GetInterface(sdv::interface_id idInterface) override#

Get access to another interface. Overload of IInterfaceAccess::GetInterface.

Parameters:

idInterface[in] The interface id to get access to.

Returns:

Returns a pointer to the interface or NULL when the interface is not supported.

virtual sdv::u8string GetFilePath() const override#

Get the path of the processed file. Overload of sdv::idl::ICompilerInfo::GetFilePath.

Returns:

The path string.

virtual sdv::u8string GetOutputDir() const override#

Return the path to the output directory. Overload of sdv::idl::ICompilerInfo::GetOutputDir.

Returns:

The directory string.

const CLexer &GetLexer() const#

Get access to the underlying lexer.

Returns:

Reference to the lexer.

virtual void IncludeFile(const std::filesystem::path &rpath, bool bLocal) override#

Include a file. Overload of CPreprocessor::IncludeFile.

Parameters:
  • rpath[in] Reference to the source file path. Must be a valid path.

  • bLocal[in] When set, the include file is a local include. Otherwise it represents a global include.

virtual CIdlCompilerEnvironment &GetEnvironment() override#

Get the environment. Overload of CPreprocessor::GetEnvironment.

Returns:

Reference to the environment.

CToken GetToken()#

Get a token from the lexer with moving the current position.

Check the token cache for any unprocessed tokens. If empty, get a token from the lexer for the currently open file. Preprocessor directives are automatically executed causing conditionally parsing the file, defining and undefining macros and opening include files.

Throws:

ThrowsCCompileException on parse error.

Returns:

Returns the token if there is any or an empty token when there is no token any more.

CToken GetLastValidToken() const#

Get the last valid token.

Returns:

Returns the last read token or an empty token when no token was read before.

CToken PeekToken(size_t nIndex = 0)#

Get a token from the parser without moving the current position.

Parameters:

nIndex[in] The amount of tokens to skip before returning the token.

Returns:

Returns the token if there is any or an empty token when there is no token any more.

CTokenList GetComments()#

Get the comment list gathered until the next token.

Returns:

Token list with comments.

void PrependToken(const CToken &rToken)#

Insert a token in from of the current token cache.

This function prepends the current token at the current position.

Parameters:

rToken[in] Reference to token object containing the code to insert.

void SkipAdjacentComments()#

Skip adjacent comments - this prevents succeeding comments to be interpreted as preceding comments for the next token.

CParser &LexicalCheck()#

Lexical check.

Parse through the file and belonging include files without interpretation to check for lexical errors.

Throws:

ThrowsCCompileException on parse error.

Returns:

Returns a reference to this parser.

CParser &Parse()#

Parse the code.

Parse through the file and belonging include files and build a parse tree.

Throws:

ThrowsCCompileException on parse error.

Returns:

Returns a reference to this parser.

const CRootEntity *Root() const#

Get the root entity (after parsing).

Returns:

Pointer to the root entity or NULL when there is no root entity.

std::string GenerateAnonymousEntityName(const std::string &rssPrefix)#

Generate a name for anonymous entities (structs, unions and enums with declarations can be anonymous; unions within structs can be transparent - having an anonymous declaration).

Parameters:

rssPrefix[in] The prefix to use to generate an automatic name.

Returns:

Returns the name of the anonymous entity consisting of a name part “prefix_” with a unique number.

std::list<SMetaToken> GetAndRemoveMeta()#

Get and remove the meta data collected until this point.

Returns:

List of meta tokens.

struct SMetaToken#

Structure containing the meta data token.

Public Members

CToken tokenMeta#

Meta data token.

CTokenList lstComments#

If available list of preceding comments.