Bash++
Bash++ compiler internal documentation
Classes | Enumerations | Functions | Variables
bpp Namespace Reference

Classes

class  bpp_entity
 The base class for all entities in the Bash++ compiler. More...
 
class  bpp_code_entity
 An entity which can contain code. More...
 
class  bpp_string
 The practical difference between bpp_code_entity and bpp_string is how we handle the code buffers. More...
 
class  bpp_method
 A method in a class. More...
 
class  bpp_method_parameter
 A parameter in a method. More...
 
class  bpp_class
 A class in Bash++. More...
 
class  bpp_object
 An object in Bash++. More...
 
class  bpp_datamember
 A data member in a class. More...
 
class  bpp_program
 The main program. More...
 
class  bash_while_loop
 A while loop in Bash++. More...
 
class  bash_while_condition
 The condition for a while loop in Bash++. More...
 
class  bash_if
 An if statement in Bash++. More...
 
class  bash_if_branch
 A branch of an if statement in Bash++. More...
 
class  bash_case
 A case statement in Bash++. More...
 
class  bash_case_pattern
 A pattern for a case statement in Bash++. More...
 
class  bash_for
 A for loop in Bash++. More...
 
class  bash_function
 
class  bpp_delete_statement
 A delete statement in Bash++. More...
 
class  bpp_dynamic_cast_statement
 A dynamic_cast statement in Bash++. More...
 
class  bpp_pointer_dereference
 A pointer dereference in Bash++. More...
 
class  bpp_value_assignment
 A value assignment statement in Bash++. More...
 
class  bpp_object_assignment
 An object assignment statement in Bash++. More...
 
class  bpp_object_reference
 An object reference in Bash++. More...
 
class  bpp_object_address
 A statement which takes the address of an object in Bash++. More...
 
struct  code_segment
 A struct to hold (compiled) code segments. More...
 

Enumerations

enum  bpp_scope { SCOPE_PUBLIC , SCOPE_PROTECTED , SCOPE_PRIVATE , SCOPE_INACCESSIBLE }
 
enum  reference_type { ref_primitive , ref_method , ref_object }
 

Functions

code_segment generate_supershell_code (const std::string &code_to_run, bool in_while_condition, std::shared_ptr< bash_while_condition > current_while_condition, std::shared_ptr< bpp::bpp_program > program)
 Generates a supershell code segment for executing a bash command. More...
 
code_segment generate_delete_code (std::shared_ptr< bpp::bpp_object > object, const std::string &object_ref, std::shared_ptr< bpp::bpp_program > program)
 Generates a code segment for deleting an object. More...
 
code_segment generate_method_call_code (const std::string &reference_code, const std::string &method_name, std::shared_ptr< bpp::bpp_class > assumed_class, std::shared_ptr< bpp::bpp_program > program)
 Generates a code segment for calling a method. More...
 
code_segment generate_dynamic_cast_code (const std::string &reference_code, const std::string &class_name, std::shared_ptr< bpp::bpp_program > program)
 Generates a code segment for performing a dynamic cast. More...
 
code_segment inline_new (const std::string &new_address, std::shared_ptr< bpp::bpp_class > new_class)
 Generates a code segment to INLINE class's "new" function within a method. More...
 
code_segment generate_delete_code (std::shared_ptr< bpp_object > object, const std::string &object_ref, std::shared_ptr< bpp::bpp_program > program)
 
code_segment generate_method_call_code (const std::string &reference_code, const std::string &method_name, std::shared_ptr< bpp_class > assumed_class, std::shared_ptr< bpp::bpp_program > program)
 

Variables

static const std::shared_ptr< bpp_entityinaccessible_entity = std::make_shared<bpp_entity>()
 A placeholder for an inaccessible entity (scope handling) More...
 
static const std::shared_ptr< bpp_datamemberinaccessible_datamember = std::make_shared<bpp_datamember>()
 A placeholder for an inaccessible data member of a class (scope handling) More...
 
static const std::shared_ptr< bpp_methodinaccessible_method = std::make_shared<bpp_method>()
 A placeholder for an inaccessible method of a class (scope handling) More...
 
static const char bpp_nullptr [] = "0"
 The secret internal value of '@nullptr' in Bash++. More...
 

Detailed Description

Copyright (C) 2025 rail5 Bash++: Bash with classes

Enumeration Type Documentation

◆ bpp_scope

Enumerator
SCOPE_PUBLIC 
SCOPE_PROTECTED 
SCOPE_PRIVATE 
SCOPE_INACCESSIBLE 

◆ reference_type

Enumerator
ref_primitive 
ref_method 
ref_object 

Function Documentation

◆ generate_delete_code() [1/2]

code_segment bpp::generate_delete_code ( std::shared_ptr< bpp::bpp_object object,
const std::string &  object_ref,
std::shared_ptr< bpp::bpp_program program 
)

Generates a code segment for deleting an object.

This function constructs a code segment to delete an object. The generated code includes:

  • A call to the object's destructor if it has one.
  • A call to the object's delete function.
Parameters
objectThe object to be deleted.
object_refThe string representing the object's reference in the compiled code.
Returns
A code_segment structure containing the complete deletion code:
  • pre_code: The setup code including the destructor call.
  • post_code: Empty
  • code: Empty

◆ generate_delete_code() [2/2]

code_segment bpp::generate_delete_code ( std::shared_ptr< bpp_object object,
const std::string &  object_ref,
std::shared_ptr< bpp::bpp_program program 
)

◆ generate_dynamic_cast_code()

code_segment bpp::generate_dynamic_cast_code ( const std::string &  reference_code,
const std::string &  class_name,
std::shared_ptr< bpp::bpp_program program 
)

Generates a code segment for performing a dynamic cast.

This function constructs a code segment to perform a dynamic cast on an object. The generated code includes:

  • A runtime check to verify the cast is valid.
  • A substitution of either the address of the cast object or the nullptr value.
Parameters
reference_codeThe code representing the object reference
class_nameThe type to which we want to cast
Returns
A code segment structure containing the complete dynamic cast code:
  • pre_code: Call to the runtime dynamic cast function
  • post_code: Code for cleaning up the dynamic cast's temporary variable
  • code: The temporary variable containing the result of the dynamic cast (either the address or the @nullptr value)

◆ generate_method_call_code() [1/2]

code_segment bpp::generate_method_call_code ( const std::string &  reference_code,
const std::string &  method_name,
std::shared_ptr< bpp::bpp_class assumed_class,
std::shared_ptr< bpp::bpp_program program 
)

Generates a code segment for calling a method.

This function constructs a code segment to call a method on an object. The generated code includes:

  • A lookup in the object's vTable if the method is virtual.
  • A call to the method.
Parameters
reference_codeThe code representing the object reference.
method_nameThe name of the method to be called.
assumed_classThe class to which the object is assumed to belong at compile-time.
Returns
A code_segment structure containing the complete method call code:
  • pre_code: The setup code including the vTable lookup.
  • post_code: The code for cleaning up the vTable lookup.
  • code: The expression to call the method.

◆ generate_method_call_code() [2/2]

code_segment bpp::generate_method_call_code ( const std::string &  reference_code,
const std::string &  method_name,
std::shared_ptr< bpp_class assumed_class,
std::shared_ptr< bpp::bpp_program program 
)

◆ generate_supershell_code()

code_segment bpp::generate_supershell_code ( const std::string &  code_to_run,
bool  in_while_condition,
std::shared_ptr< bash_while_condition current_while_condition,
std::shared_ptr< bpp::bpp_program program 
)

Generates a supershell code segment for executing a bash command.

This function constructs a code segment to run a specified command in a supershell. It creates a unique function name and output variable using a global counter. The generated code includes:

  • A bash function definition wrapping the given command.
  • A command to invoke the function and store its output, either appended to a while condition or added to the precode.
  • Cleanup commands that unset the dynamically created function and output variable.
Parameters
code_to_runThe bash command to be executed within the supershell.
Returns
A code_segment structure containing the complete supershell execution code:
  • pre_code: The setup code including the function definition and invocation.
  • post_code: The code for cleaning up the defined environment.
  • code: An expression referencing the supershell output variable.

◆ inline_new()

code_segment bpp::inline_new ( const std::string &  new_address,
std::shared_ptr< bpp::bpp_class new_class 
)

Generates a code segment to INLINE class's "new" function within a method.

This is only to be used inside a method.

Rather than calling the class's "new" function, by inlining it, we can ensure that all instantiated objects are purely local to the method. This eliminates any issues with scope and recursion.

However, this change has resulted in some significant code duplication:

  1. This function duplicates code in bpp_program::add_class, with the difference that the created variables are declared 'local'
  2. bpp_method now has an override for add_object which is identical to that in its parent class bpp_code_entity, with the difference that rather than adding code which will call the class's "new" function at runtime, it adds the code generated by this function.

This will have to be handled soon.

Parameters
new_addressThe address of the new object
new_classThe class of the new object
Returns
A code segment structure containing the complete new code:
  • pre_code: All of the code necessary to create the object
  • post_code: Empty
  • code: Empty

Variable Documentation

◆ bpp_nullptr

bpp::bpp_nullptr = "0"
static

The secret internal value of '@nullptr' in Bash++.

◆ inaccessible_datamember

bpp::inaccessible_datamember = std::make_shared<bpp_datamember>()
static

A placeholder for an inaccessible data member of a class (scope handling)

◆ inaccessible_entity

bpp::inaccessible_entity = std::make_shared<bpp_entity>()
static

A placeholder for an inaccessible entity (scope handling)

◆ inaccessible_method

bpp::inaccessible_method = std::make_shared<bpp_method>()
static

A placeholder for an inaccessible method of a class (scope handling)