Bash++
Bash++ compiler internal documentation
Public Member Functions | Private Member Functions | Private Attributes | List of all members
bpp::bpp_method Class Reference

A method in a class. More...

#include <bpp.h>

Inheritance diagram for bpp::bpp_method:
Inheritance graph
[legend]
Collaboration diagram for bpp::bpp_method:
Collaboration graph
[legend]

Public Member Functions

 bpp_method ()
 
 bpp_method (const std::string &name)
 
 bpp_method (const std::string &name, bool is_virtual)
 
virtual bool add_parameter (std::shared_ptr< bpp_method_parameter > parameter)
 Add a parameter to the method. More...
 
void set_name (const std::string &name)
 
void set_scope (bpp_scope scope)
 
void set_virtual (bool is_virtual)
 
void set_inherited (bool is_inherited)
 
bool add_object (std::shared_ptr< bpp_object > object, bool make_local) override
 Add an object to the code entity. More...
 
std::string get_name () const override
 
std::vector< std::shared_ptr< bpp_method_parameter > > get_parameters () const
 
bpp_scope get_scope () const
 
bool is_virtual () const
 
bool is_inherited () const
 
void destruct_local_objects (std::shared_ptr< bpp_program > program)
 Destruct all local objects. More...
 
- Public Member Functions inherited from bpp::bpp_code_entity
 bpp_code_entity ()
 
virtual void add_code (const std::string &code, bool add_newline=true)
 Add code to the code entity. More...
 
virtual void add_code_to_previous_line (const std::string &code)
 Add code to the code entity's pre-code buffer. More...
 
virtual void add_code_to_next_line (const std::string &code)
 Add code to the code entity's post-code buffer. More...
 
virtual void flush_nextline_buffer ()
 
virtual void flush_postline_buffer ()
 
virtual void flush_code_buffers ()
 
virtual void clear_all_buffers ()
 
virtual std::string get_code () const
 Return the contents of the main code buffer as a string. More...
 
virtual std::string get_pre_code () const
 Return the contents of the pre-code buffer as a string. More...
 
virtual std::string get_post_code () const
 Return the contents of the post-code buffer as a string. More...
 
- Public Member Functions inherited from bpp::bpp_entity
virtual ~bpp_entity ()=default
 
virtual bool add_class (std::shared_ptr< bpp_class > class_)
 Add a class to this entity's list of classes. More...
 
virtual std::shared_ptr< bpp_classget_class () const
 
virtual std::string get_address () const
 
virtual std::weak_ptr< bpp::bpp_classget_containing_class () const
 Get the class which contains this entity. More...
 
virtual bool set_containing_class (std::weak_ptr< bpp::bpp_class > containing_class)
 
virtual void inherit (std::shared_ptr< bpp_entity > parent)
 Inherit from a parent entity. More...
 
virtual void inherit (std::shared_ptr< bpp_class > parent)
 
virtual std::unordered_map< std::string, std::shared_ptr< bpp_class > > get_classes () const
 
virtual std::unordered_map< std::string, std::shared_ptr< bpp_object > > get_objects () const
 
virtual std::shared_ptr< bpp_classget_class (const std::string &name)
 
virtual std::shared_ptr< bpp_objectget_object (const std::string &name)
 

Private Member Functions

bool add_object_as_parameter (std::shared_ptr< bpp_object > object)
 Add a pointer to a non-primitive object as a parameter to the method. More...
 

Private Attributes

std::string name
 
std::vector< std::shared_ptr< bpp_method_parameter > > parameters
 
bpp_scope scope = SCOPE_PUBLIC
 
bool m_is_virtual = false
 
bool inherited = false
 

Additional Inherited Members

- Protected Attributes inherited from bpp::bpp_code_entity
std::shared_ptr< std::ostream > code = std::make_shared<std::ostringstream>()
 
std::string nextline_buffer = ""
 
std::string postline_buffer = ""
 
bool buffers_flushed = false
 
- Protected Attributes inherited from bpp::bpp_entity
std::unordered_map< std::string, std::shared_ptr< bpp_class > > classes
 A map of class names to class objects within this entity. More...
 
std::unordered_map< std::string, std::shared_ptr< bpp_object > > objects
 A map of object names to bpp_objects within this entity. More...
 
std::unordered_map< std::string, std::shared_ptr< bpp_object > > local_objects
 Like objects, but only for objects whose scope is local to this entity. More...
 
std::shared_ptr< bpp_classtype = nullptr
 
std::weak_ptr< bpp_classcontaining_class
 
std::vector< std::shared_ptr< bpp_class > > parents
 

Detailed Description

A method in a class.

Constructor & Destructor Documentation

◆ bpp_method() [1/3]

bpp::bpp_method::bpp_method ( )

◆ bpp_method() [2/3]

bpp::bpp_method::bpp_method ( const std::string &  name)
explicit

◆ bpp_method() [3/3]

bpp::bpp_method::bpp_method ( const std::string &  name,
bool  is_virtual 
)

Member Function Documentation

◆ add_object()

bool bpp::bpp_method::add_object ( std::shared_ptr< bpp_object object,
bool  make_local 
)
overridevirtual

Add an object to the code entity.

Adding an object to a code entity involves adding the necessary code to create the object. Unlike in the case where we add an object to a non-code entity, where we only need to update the object map.

This function generates the code necessary to create the object, including calling its constructor if it exists.

Parameters
objectThe object to add

Reimplemented from bpp::bpp_code_entity.

◆ add_object_as_parameter()

bool bpp::bpp_method::add_object_as_parameter ( std::shared_ptr< bpp_object object)
private

Add a pointer to a non-primitive object as a parameter to the method.

This function ensures that code within the scope of the method is able to access an object passed as an argument to the method, by adding the object to the local_objects map.

◆ add_parameter()

bool bpp::bpp_method::add_parameter ( std::shared_ptr< bpp_method_parameter parameter)
virtual

Add a parameter to the method.

This function adds a parameter to the method. If the passed bpp_method_parameter is not a primitive type, it will also add the object to the local_objects map by calling add_object_as_parameter.

◆ destruct_local_objects()

void bpp::bpp_method::destruct_local_objects ( std::shared_ptr< bpp_program program)

Destruct all local objects.

This function destructs all local objects in the method by calling their destructors (if they exist) and then deleting them.

This is called as we exit the method, to ensure that all local objects are cleaned up.

◆ get_name()

std::string bpp::bpp_method::get_name ( ) const
overridevirtual

Reimplemented from bpp::bpp_entity.

◆ get_parameters()

std::vector< std::shared_ptr< bpp_method_parameter > > bpp::bpp_method::get_parameters ( ) const

◆ get_scope()

bpp_scope bpp::bpp_method::get_scope ( ) const

◆ is_inherited()

bool bpp::bpp_method::is_inherited ( ) const

◆ is_virtual()

bool bpp::bpp_method::is_virtual ( ) const

◆ set_inherited()

void bpp::bpp_method::set_inherited ( bool  is_inherited)

◆ set_name()

void bpp::bpp_method::set_name ( const std::string &  name)

◆ set_scope()

void bpp::bpp_method::set_scope ( bpp_scope  scope)

◆ set_virtual()

void bpp::bpp_method::set_virtual ( bool  is_virtual)

Member Data Documentation

◆ inherited

bool bpp::bpp_method::inherited = false
private

◆ m_is_virtual

bool bpp::bpp_method::m_is_virtual = false
private

◆ name

std::string bpp::bpp_method::name
private

◆ parameters

std::vector<std::shared_ptr<bpp_method_parameter> > bpp::bpp_method::parameters
private

◆ scope

bpp_scope bpp::bpp_method::scope = SCOPE_PUBLIC
private

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