retdec
Public Member Functions | Private Member Functions | Private Attributes | List of all members
retdec::llvmir2hll::FunctionBuilder Class Reference

A builder providing a simple way of creating functions. More...

#include <function_builder.h>

Inheritance diagram for retdec::llvmir2hll::FunctionBuilder:
Inheritance graph
[legend]
Collaboration diagram for retdec::llvmir2hll::FunctionBuilder:
Collaboration graph
[legend]

Public Member Functions

 FunctionBuilder (const std::string &funcName="")
 Constructs a builder providing the default function named funcName. More...
 
ShPtr< Functionbuild ()
 Returns the built function. More...
 
Specifiers
FunctionBuilderdefinitionWithEmptyBody ()
 Makes the function a definition with an empty body. More...
 
FunctionBuilderdefinitionWithBody (ShPtr< Statement > body)
 Makes the function a definition with the given body. More...
 
FunctionBuilderwithRetType (ShPtr< Type > retType)
 Makes the function to have the given return type. More...
 
FunctionBuilderwithParam (ShPtr< Variable > param)
 Adds the given parameter to the function. More...
 
FunctionBuilderwithLocalVar (ShPtr< Variable > var)
 Adds the given local variable to the function. More...
 
FunctionBuilderwithVarArg ()
 Makes the function taking a variable number of arguments. More...
 

Private Member Functions

ShPtr< FunctionreleaseFuncAndInvalidateBuilder ()
 Releases the built function and invalidates the builder. More...
 
- Private Member Functions inherited from retdec::utils::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
 NonCopyable ()=default
 
 ~NonCopyable ()=default
 

Private Attributes

ShPtr< Functionfunc
 A function that is being built. More...
 

Detailed Description

A builder providing a simple way of creating functions.

It implements a simplified version of the Builder design pattern with a fluent interface.

Usage Example
The following code constructs a definition of a function named "myFunc" with an empty body and the single given parameter:
ShPtr<Function> myFunc(
FunctionBuilder("myFunc")
.withParam(param)
.build()
);
FunctionBuilder & withParam(ShPtr< Variable > param)
Adds the given parameter to the function.
Definition: function_builder.cpp:105
FunctionBuilder(const std::string &funcName="")
Constructs a builder providing the default function named funcName.
Definition: function_builder.cpp:40
FunctionBuilder & definitionWithEmptyBody()
Makes the function a definition with an empty body.
Definition: function_builder.cpp:49
ShPtr< Function > build()
Returns the built function.
Definition: function_builder.cpp:77
Since the return type has not been specified, the default one is used (see the description of FunctionBuilder() for more information).

Constructor & Destructor Documentation

◆ FunctionBuilder()

retdec::llvmir2hll::FunctionBuilder::FunctionBuilder ( const std::string &  funcName = "")

Constructs a builder providing the default function named funcName.

If you call build() right after the builder is created, it will return a function declaration named funcName with the void return type and without any parameters.

Member Function Documentation

◆ build()

ShPtr< Function > retdec::llvmir2hll::FunctionBuilder::build ( )

Returns the built function.

This function can be called at most once. It is an error to call it once again after it has already been called.

◆ definitionWithBody()

FunctionBuilder & retdec::llvmir2hll::FunctionBuilder::definitionWithBody ( ShPtr< Statement body)

Makes the function a definition with the given body.

Preconditions
  • build() has not yet been called
  • body has to be non-null

◆ definitionWithEmptyBody()

FunctionBuilder & retdec::llvmir2hll::FunctionBuilder::definitionWithEmptyBody ( )

Makes the function a definition with an empty body.

Preconditions

◆ releaseFuncAndInvalidateBuilder()

ShPtr< Function > retdec::llvmir2hll::FunctionBuilder::releaseFuncAndInvalidateBuilder ( )
private

Releases the built function and invalidates the builder.

◆ withLocalVar()

FunctionBuilder & retdec::llvmir2hll::FunctionBuilder::withLocalVar ( ShPtr< Variable var)

Adds the given local variable to the function.

Preconditions
  • build() has not yet been called
  • var has to be non-null

◆ withParam()

FunctionBuilder & retdec::llvmir2hll::FunctionBuilder::withParam ( ShPtr< Variable param)

Adds the given parameter to the function.

Preconditions
  • build() has not yet been called
  • param has to be non-null

◆ withRetType()

FunctionBuilder & retdec::llvmir2hll::FunctionBuilder::withRetType ( ShPtr< Type retType)

Makes the function to have the given return type.

Preconditions
  • build() has not yet been called
  • retType has to be non-null

◆ withVarArg()

FunctionBuilder & retdec::llvmir2hll::FunctionBuilder::withVarArg ( )

Makes the function taking a variable number of arguments.

Preconditions

Member Data Documentation

◆ func

ShPtr<Function> retdec::llvmir2hll::FunctionBuilder::func
private

A function that is being built.


The documentation for this class was generated from the following files: