Template Class CDefinitionGeneratorBase#

Inheritance Relationships#

Base Type#

Class Documentation#

template<typename TDefEntityContext>
class CDefinitionGeneratorBase : public CGenContext#

Definition code generator base.

Template Parameters:

TDefEntityContext – Type of definition entity context to use. Must derive from CDefEntityContext.

Public Functions

CDefinitionGeneratorBase(sdv::IInterfaceAccess *pParser)#

Constructor.

Parameters:

pParser[in] Pointer to the parser object.

virtual bool Generate()#

Generate the definition code.

Returns:

Returns whether generation was successful.

Protected Functions

virtual void GetTargetFileInfo(std::string &rssTargetSubDir, std::string &rssTargetFileEnding) = 0#

Return the information for target file creation.

Parameters:
  • rssTargetSubDir[out] Reference to the string containing the target sub-directory to be added to the output directory. Could be empty to target the output directory.

  • rssTargetFileEnding[out] Reference to string containing the file ending (file name and extension) to be placed at the end of the source file name replacing the extension.

virtual std::string GetFileHeaderText() const = 0#

Return the file header text for automatic file generation.

Returns:

The header text to place into the file.

virtual void StreamIntoFile(TDefEntityContext &rcontext, std::ofstream &rfstream)#

Stream the code into the file. Called once after processing.

Parameters:
  • rcontext[inout] Reference to the stream context.

  • rfstream[inout] Reference to the file stream to stream into

virtual void StreamIncludeSection(TDefEntityContext &rcontext)#

Stream the include section for the file.

Parameters:

rcontext[inout] Reference to the stream context to stream into.

virtual bool ProcessEntities(TDefEntityContext &rcontext, sdv::idl::IEntityIterator *pIterator)#

Process the entities.

Parameters:
  • rcontext[inout] Reference to the stream context to stream into.

  • pIterator[in] Pointer to the iterator interface.

Returns:

Returns true when the streaming of declarations was successful or false when streaming of declarations was not successful and should be canceled.

virtual void StreamMetaEntity(TDefEntityContext &rcontext, sdv::IInterfaceAccess *pEntity)#

Stream the meta entity.

Parameters:
  • rcontext[inout] Reference to the stream context to stream into.

  • pEntity[in] Pointer to the interface of the meta entity.

virtual bool StreamDeclaration(TDefEntityContext &rcontext, sdv::IInterfaceAccess *pEntity)#

Stream declaration if the entity is a declaration.

Parameters:
  • rcontext[inout] Reference to the stream context.

  • pEntity[in] Pointer to the IInterfaceAccess pointer of the entity.

Returns:

Returns true when the streaming was successful or false when streaming was not successful and should be canceled.

virtual void StreamDefinition(TDefEntityContext &rcontext, sdv::IInterfaceAccess *pEntity, bool bInline = false, bool bAnonymousDecl = false)#

Stream definition if the entity is a definition.

Parameters:
  • rcontext[inout] Reference to the stream context to stream into.

  • pEntity[in] Pointer to the IInterfaceAccess pointer of the entity.

  • bInline[in] When set the definition is part of a declaration.

  • bAnonymousDecl[in] When set, the definition is part of an anonymous declaration (only valid for unions).

std::shared_ptr<SSwitchVarContext> GetOrCreateVarBasedSwitch(sdv::IInterfaceAccess *pSwitchVarEntity)#

Check for the existence of the switch variable and add the variable if not existing.

Parameters:

pSwitchVarEntity[in] Interface pointer to the switch variable entity.

Returns:

Smart pointer to the switch variable.

virtual void DetectUnionContainerForProcessing(TDefEntityContext &rcontext, const std::string &rssMemberScope, sdv::IInterfaceAccess *pDeclEntity, const std::vector<SArrayIterationInfo> &rvecArrayIndices = {})#

Detect a declaration of a union using a variable based switch case. If the switch case variable is within the scope of the provided context, stream the functions needed to initialize and use the switch case. If the declaration is not a fitting union but is of a compound structure (struct, exception or union), go through the declaration members for further detection.

Parameters:
  • rcontext[inout] Reference to the stream context to stream into.

  • rssMemberScope[in] Reference to the string containing the declarative member scope. Each declaration is separated by a dot separator.

  • pDeclEntity[in] Interface pointer to the declarative entity to check.

  • rvecArrayIndices[in] Reference to the vector containing the array indices of the declaration to use for the detection. If the declaration is not declared as array, the vector should be empty. If the declaration is declared as an array and the amount of dimensions is below the amount of dimensions within the provided vector, the detection function is called for each array dimension extending the vector with the index to do the detection for.

virtual void ProcessUnionInContainerContext(TDefEntityContext &rcontext, std::string rssMemberScopeUnionDecl, std::string rssMemberScopeSwitchVar, sdv::IInterfaceAccess *pUnionDef, const std::vector<SArrayIterationInfo> &rvecArrayIndices = std::vector<SArrayIterationInfo>())#

Process the union member that, together with the switch variable, has a mutual container from the entity in the context.

Union definitions and declarations are to be treated differently, dependable on the switch type and the way of the integration. The following differences are to be distingueshed:

  • Unions can be defined as named or as unnamed unions. Unnamed unions can only occur when followed by a declaration. They cannot be declared at global level due to the missing possibility to initialize/uninitialize using a member constructor/destructor.

  • Union declarations can be explicit or anonymous (not existing, but due to the unnamed nature of the union implicitly present). Anonymous declaration only occur for unnamed unions and are not allowed at root level. For named unions, there are no anonymous declarations.

The following table defines the different types: +—————&#8212;+——————————————————————&#8212;+——————————————————————&#8212;+ | | switch type base | switch var based | | +——————————-&#8212;+——————————-&#8212;+——————————-&#8212;+——————————-&#8212;+ | | named | unnamed | named | unnamed | | +————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+ | | explicit decl. | anonymous decl. | explicit decl. | anonymous decl. | explicit decl. | anonymous decl. | explicit decl. | anonymous decl. | +==================+================+=================+================+=================+================+=================+================+=================+ | definition code | Use struct to | Not existing | Use struct to | Not allowed/ | Define named | Not existing | Must be | Define unnamed | | | encapsulate | | encapsulate | not occurring. | union as | | followed by | union as part | | | switch var and | | switch var and | | member. | | decl. Cannot | of struct. | | | union def. | | union def. | | | | be global. | Will not be | | | | | Auto generate | | | | | followed by | | | | | struct name. | | | | | decl. | +—————&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+ | declaration code | Normal decl. | N.a. | Following def. | N.a. | Normal | N.a. | Following def. | Absent | +—————&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+ | switch variable | Part of struct | N.a. | Part of struct | N.a. | Part of | N.a. | Part of | Part of | | | | | | | container | | container | container | +—————&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+ | constructor | Part of struct | N.a. | Part of struct | N.a. | Part of | N.a. | Part of | Part of | | | | | | | container | | container | container | +—————&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+ | destructor | Part of struct | N.a. | Part of struct | N.a. | Part of | N.a. | Part of | Part of | | | | | | | container | | container | container | +—————&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+ | switch function | Part of struct | N.a. | Part of struct | N.a. | Part of | N.a. | Part of | Part of | | | | | | | container | | container | container | +—————&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+ | element access | Internal | N.a. | Internal | N.a. | Over member | N.a. | Over member | Direct access | | | | | | | var | | var | to elements | +—————&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+————-&#8212;+————–&#8212;+

In case of a switch case based on a variable, this variable might be defined in a sub-structure of a mutual container of a union. The union content depends on the switch variable. Both need to be processed together in the same context of one of the containers.

Parameters:
  • rcontext[inout] Reference to the stream context to stream into.

  • rssMemberScopeUnionDecl[in] Reference to the member scope of the union declaration (could be empty when the union switch is not variable based).

  • rssMemberScopeSwitchVar[in] Reference to the member scope of the switch variable (could be empty when the union switch is not variable based).

  • pUnionDef[in] Pointer to the union definition entity.

  • rvecArrayIndices[in] Reference to the vector containing the array indices of the declaration to use for the detection. If the declaration is not declared as array, the vector should be empty. If the declaration is declared as an array and the amount of dimensions is below the amount of dimensions within the provided vector, the detection function is called for each array dimension extending the vector with the index to do the detection for.

void DetectUnionJointContainerForSwitchVar(TDefEntityContext &rcontext, sdv::IInterfaceAccess *pSwitchVarEntity, sdv::IInterfaceAccess *pEntity)#

For a switch variable, detect the joint container of both switch variable and union. Start with the highest parent running through all children.

Parameters:
  • rcontext[inout] Reference to the definition stream context of the switch variable to stream into.

  • pSwitchVarEntity[in] Interface to the switch var declaration.

  • pEntity[in] Interface to the definition to detect for the container.

virtual void ProcessUnionJointContainerForSwitchVar(TDefEntityContext &rcontext, sdv::IInterfaceAccess *pSwitchVarEntity, sdv::IInterfaceAccess *pContainerEntity)#

For a switch variable, process the joint container of both switch variable and union. Start with the highest parent running through all children.

Parameters:
  • rcontext[inout] Reference to the definition stream context of the switch variable to stream into.

  • pSwitchVarEntity[in] Interface to the switch var declaration.

  • pContainerEntity[in] Interface to the container definition.