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

Namespaces

namespace  detail
 
namespace  ErrorHandling
 

Classes

class  bash_case
 A case statement in Bash++. More...
 
class  bash_case_pattern
 A pattern for a case statement in Bash++. More...
 
class  bash_command_sequence
 A sequence of bash commands connected by '&&' and '||'. More...
 
class  bash_for_or_select
 A for loop or select statement in Bash++. More...
 
class  bash_function
 A normal Bash function. 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_while_or_until_condition
 The condition for a while/until loop in Bash++. More...
 
class  bash_while_or_until_loop
 A while/until loop in Bash++. More...
 
class  BashppServer
 The main server class for handling LSP requests and notifications. More...
 
class  bpp_class
 A class in Bash++. More...
 
class  bpp_code_entity
 An entity which can contain code. More...
 
class  bpp_datamember
 A data member in a class. More...
 
class  bpp_delete_statement
 A delete statement in Bash++. More...
 
class  bpp_dynamic_cast_statement
 A dynamic_cast statement in Bash++. More...
 
class  bpp_dynamic_cast_target
 The target of a dynamic_cast in Bash++. More...
 
class  bpp_entity
 The base class for all entities in the Bash++ compiler. More...
 
class  bpp_method
 A method in a class. More...
 
class  bpp_method_parameter
 A parameter in a method. More...
 
class  bpp_object
 An object 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_program
 The main program. More...
 
class  bpp_string
 The practical difference between bpp_code_entity and bpp_string is how we handle the code buffers. More...
 
class  bpp_value_assignment
 A value assignment statement in Bash++. More...
 
struct  code_segment
 A struct to hold (compiled) code segments. More...
 
struct  diagnostic
 Represents a diagnostic message (error, warning, info, hint) More...
 
struct  entity_reference
 Represents the result of resolving a reference to an entity. More...
 
struct  SymbolPosition
 

Typedefs

using json = nlohmann::json
 

Enumerations

enum  bpp_scope { SCOPE_PUBLIC , SCOPE_PROTECTED , SCOPE_PRIVATE , SCOPE_INACCESSIBLE }
 
enum  reference_type { ref_primitive , ref_method , ref_object }
 
enum  diagnostic_type { DIAGNOSTIC_ERROR , DIAGNOSTIC_WARNING , DIAGNOSTIC_INFO , DIAGNOSTIC_HINT }
 

Functions

bool is_protected_keyword (const std::string &keyword)
 Check if a string matches any of our protected keywords.
 
bool is_valid_identifier (const std::string &identifier)
 Check if a string is a valid identifier in Bash++.
 
code_segment generate_supershell_code (const std::string &code_to_run, std::shared_ptr< bpp::bpp_program > program)
 Generates a supershell code segment for executing a bash command.
 
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.
 
code_segment _generate_virtual_method_call_code (const std::string &reference_code, const std::string &method_name, 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::bpp_class > assumed_class, bool force_static_reference, std::shared_ptr< bpp::bpp_program > program)
 Generates a code segment for calling a method.
 
code_segment generate_constructor_call_code (const std::string &reference_code, std::shared_ptr< bpp_class > assumed_class)
 
code_segment generate_destructor_call_code (const std::string &reference_code, std::shared_ptr< bpp_class > assumed_class, bool force_static_reference, std::shared_ptr< bpp::bpp_program > program)
 
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.
 
code_segment generate_typeof_code (const std::string &reference_code, std::shared_ptr< bpp::bpp_program > program)
 
code_segment generate_new_code (const std::string &new_address, std::shared_ptr< bpp::bpp_class > new_class, bool inline_new)
 Generate the assignments necessary to create a new object of a given class.
 
std::shared_ptr< bpp::bpp_methodgenerate_copy_method (std::shared_ptr< bpp::bpp_class > containing_class, std::shared_ptr< bpp::bpp_program > program)
 Generates a copy method for a class.
 
std::shared_ptr< bpp::bpp_methodgenerate_new_method (std::shared_ptr< bpp::bpp_class > containing_class)
 
std::shared_ptr< bpp::bpp_methodgenerate_delete_method (std::shared_ptr< bpp::bpp_class > containing_class)
 
std::string get_encased_ref (const std::string &ref, uint8_t indirection_level)
 Encases a temporary variable reference with the appropriate level of indirection.
 
entity_reference resolve_reference_impl (const std::string &file, std::shared_ptr< bpp::bpp_entity > context, std::deque< AST::Token< std::string > > *nodes, std::deque< std::string > *identifiers, bool declare_local, std::shared_ptr< bpp::bpp_program > program)
 Resolves a reference to an entity in a particular context.
 
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, bool force_static_reference, std::shared_ptr< bpp::bpp_program > program)
 
entity_reference resolve_reference (const std::string &file, std::shared_ptr< bpp::bpp_entity > context, auto identifiers, bool declare_local, std::shared_ptr< bpp::bpp_program > program)
 
template<typename T >
void printValue (std::ostream &os, const T &value)
 
template<typename... Ts>
void printValue (std::ostream &os, const std::variant< Ts... > &v)
 

Variables

const std::shared_ptr< bpp_entityinaccessible_entity = std::make_shared<bpp_entity>()
 A placeholder for an inaccessible entity (scope handling)
 
const std::shared_ptr< bpp_datamemberinaccessible_datamember = std::make_shared<bpp_datamember>()
 A placeholder for an inaccessible data member of a class (scope handling)
 
const std::shared_ptr< bpp_methodinaccessible_method = std::make_shared<bpp_method>()
 A placeholder for an inaccessible method of a class (scope handling)
 
static const char bpp_nullptr [] = "0"
 The secret internal value of '@nullptr' in Bash++.
 
constexpr const char * protected_keywords []
 A list of keywords that are reserved and cannot be used as identifiers in Bash++.
 

Detailed Description

Copyright (C) 2025 rail5 Bash++: Bash with classes Licensed under the GNU General Public License v3.0 or later (GPL-3.0-or-later)

Copyright (C) 2025 Andrew S. Rightenburg Bash++: Bash with classes Licensed under the GNU General Public License v3.0 or later (GPL-3.0-or-later)

Typedef Documentation

◆ json

using bpp::json = typedef nlohmann::json

Enumeration Type Documentation

◆ bpp_scope

Enumerator
SCOPE_PUBLIC 
SCOPE_PROTECTED 
SCOPE_PRIVATE 
SCOPE_INACCESSIBLE 

◆ diagnostic_type

Enumerator
DIAGNOSTIC_ERROR 
DIAGNOSTIC_WARNING 
DIAGNOSTIC_INFO 
DIAGNOSTIC_HINT 

◆ reference_type

Enumerator
ref_primitive 
ref_method 
ref_object 

Function Documentation

◆ _generate_virtual_method_call_code()

code_segment bpp::_generate_virtual_method_call_code ( const std::string &  reference_code,
const std::string &  method_name,
std::shared_ptr< bpp::bpp_program program 
)
inline

◆ generate_constructor_call_code()

code_segment bpp::generate_constructor_call_code ( const std::string &  reference_code,
std::shared_ptr< bpp_class assumed_class 
)

◆ generate_copy_method()

std::shared_ptr< bpp::bpp_method > bpp::generate_copy_method ( std::shared_ptr< bpp::bpp_class containing_class,
std::shared_ptr< bpp::bpp_program program 
)

Generates a copy method for a class.

The generated method will be named "__copy" and will be public and virtual. It takes, of course, the '@this' pointer as its implicit first parameter (as do all methods), and one explicit parameter: the address to copy from.

The copy-from address is dynamically cast to the containing class type, and therefore must point to an object which is convertible to the containing class type.

TODO(@rail5): This method duplicates some code from other portions of the compiler.

Parameters
containing_classThe class for which to generate the copy method
programThe program in which the class resides
Returns
std::shared_ptr<bpp::bpp_method> The generated copy method

◆ 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_delete_method()

std::shared_ptr< bpp::bpp_method > bpp::generate_delete_method ( std::shared_ptr< bpp::bpp_class containing_class)

◆ generate_destructor_call_code()

code_segment bpp::generate_destructor_call_code ( const std::string &  reference_code,
std::shared_ptr< bpp_class assumed_class,
bool  force_static_reference,
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,
bool  force_static_reference,
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,
bool  force_static_reference,
std::shared_ptr< bpp::bpp_program program 
)

◆ generate_new_code()

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

Generate the assignments necessary to create a new object of a given class.

This is used when generating the code for the __new method of a class, and also when inlining object creation in other contexts.

In the latter cases, inline_new is set to true to ensure that the created object's data members are local variables.

Parameters
new_addressWhere to store the new object
new_classThe class of the new object
inline_newWhether to inline this new operation (make data members local variables)
Returns
code_segment The code segment to create the new object

◆ generate_new_method()

std::shared_ptr< bpp::bpp_method > bpp::generate_new_method ( std::shared_ptr< bpp::bpp_class containing_class)

◆ generate_supershell_code()

code_segment bpp::generate_supershell_code ( const std::string &  code_to_run,
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.

◆ generate_typeof_code()

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

◆ get_encased_ref()

std::string bpp::get_encased_ref ( const std::string &  ref,
uint8_t  indirection_level 
)

Encases a temporary variable reference with the appropriate level of indirection.

This function takes a std::string which is the name of a shell variable we would like to use, (for example, a temporary variable created during reference resolution), and an indirection level (0, 1, or 2), and returns the variable name encased in the appropriate amount of indirection.

0: Returns 'var' (as-is, no encasing) 1: Returns '${var}' 2: Returns '${!var}'

Any other indirection level is treated as 0.

Parameters
refThe reference string
indirection_levelThe level of indirection (0, 1, or 2)
Returns
std::string The encased reference string

◆ is_protected_keyword()

bool bpp::is_protected_keyword ( const std::string &  keyword)
inline

Check if a string matches any of our protected keywords.

Parameters
keywordThe string to check

◆ is_valid_identifier()

bool bpp::is_valid_identifier ( const std::string &  identifier)
inline

Check if a string is a valid identifier in Bash++.

Parameters
identifierThe string to check
Returns
true if the string is a valid identifier, false otherwise

◆ printValue() [1/2]

template<typename... Ts>
void bpp::printValue ( std::ostream &  os,
const std::variant< Ts... > &  v 
)

◆ printValue() [2/2]

template<typename T >
void bpp::printValue ( std::ostream &  os,
const T &  value 
)

◆ resolve_reference()

entity_reference bpp::resolve_reference ( const std::string &  file,
std::shared_ptr< bpp::bpp_entity context,
auto  identifiers,
bool  declare_local,
std::shared_ptr< bpp::bpp_program program 
)
inline

◆ resolve_reference_impl()

entity_reference bpp::resolve_reference_impl ( const std::string &  file,
std::shared_ptr< bpp::bpp_entity context,
std::deque< AST::Token< std::string > > *  nodes,
std::deque< std::string > *  identifiers,
bool  declare_local,
std::shared_ptr< bpp::bpp_program program 
)

Resolves a reference to an entity in a particular context.

This function resolves a reference to an entity (object, method, or data member) based on a sequence of identifiers.

It does this by recursively scanning the current context for the requested identifier, and then setting a new context based on the resolution of that identifier. I.e., for {object, method}, it will first scan the current context for 'object', and then scan the 'object' context for 'method'.

If passing a self-reference (@this.... or @super....), The self-referential keyword should be the first node in the identifiers deque.

Parameters
fileThe source file in which the reference is being resolved.
contextThe context (code_entity) in which to resolve the reference.
nodesA deque of TerminalNode pointers representing the identifiers in the reference.
identifiersA deque of strings representing the identifiers in the reference.
programThe program in which the reference is being resolved.
Returns
An entity_reference structure containing:
  • entity: A shared pointer to the resolved entity (object, method, or data member).
  • reference_code: A code_segment containing the code to access the entity.
  • created_first_temporary_variable: Whether a first temporary variable was necessary in the compiled code
  • created_second_temporary_variable: Whether a second temporary variable was necessary in the compiled code
  • class_containing_the_method: The class containing the method, if applicable.
  • error: An optional reference_error structure containing an error message and relevant token if the reference could not be resolved.

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>()
inline

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

◆ inaccessible_entity

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

A placeholder for an inaccessible entity (scope handling)

◆ inaccessible_method

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

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

◆ protected_keywords

bpp::protected_keywords
inlineconstexpr
Initial value:
= {
"class", "constructor", "delete", "destructor",
"dynamic_cast", "include", "include_once", "local", "method",
"new", "nullptr", "primitive", "private",
"protected", "public", "super", "this",
"typeof", "virtual"
}

A list of keywords that are reserved and cannot be used as identifiers in Bash++.