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

The main listener class for the Bash++ compiler. More...

#include <BashppListener.h>

Inheritance diagram for BashppListener:
Inheritance graph
[legend]
Collaboration diagram for BashppListener:
Collaboration graph
[legend]

Public Member Functions

void set_source_file (std::string source_file)
 
void set_include_paths (std::shared_ptr< std::vector< std::string > > include_paths)
 
void set_included (bool included)
 
void set_included_from (BashppListener *included_from)
 Sets the included_from pointer to the given listener.
 
void set_included_files (std::shared_ptr< std::set< std::string > > included_files)
 Sets the included_files pointer to the given set of included files.
 
void set_code_buffer (std::shared_ptr< std::ostream > code_buffer)
 
void set_output_stream (std::shared_ptr< std::ostream > output_stream)
 
void set_output_file (std::string output_file)
 
void set_run_on_exit (bool run_on_exit)
 
void set_suppress_warnings (bool suppress_warnings)
 
void set_target_bash_version (BashVersion target_bash_version)
 
void set_arguments (std::vector< char * > arguments)
 
void set_lsp_mode (bool lsp_mode)
 
void set_replacement_file_contents (const std::string &file_path, const std::string &contents)
 
std::shared_ptr< bpp::bpp_programget_program ()
 
std::shared_ptr< std::set< std::string > > get_included_files ()
 
const std::vector< std::string > & get_include_stack ()
 
std::string get_source_file ()
 
bool get_lsp_mode ()
 
std::shared_ptr< bpp::bpp_code_entitylatest_code_entity ()
 
void enterProgram (std::shared_ptr< AST::Program > node)
 
void exitProgram (std::shared_ptr< AST::Program > node)
 
void enterArrayAssignment (std::shared_ptr< AST::ArrayAssignment > node)
 
void exitArrayAssignment (std::shared_ptr< AST::ArrayAssignment > node)
 
void enterArrayIndex (std::shared_ptr< AST::ArrayIndex > node)
 
void exitArrayIndex (std::shared_ptr< AST::ArrayIndex > node)
 
void enterBash53NativeSupershell (std::shared_ptr< AST::Bash53NativeSupershell > node)
 
void exitBash53NativeSupershell (std::shared_ptr< AST::Bash53NativeSupershell > node)
 
void enterBashArithmeticForCondition (std::shared_ptr< AST::BashArithmeticForCondition > node)
 
void exitBashArithmeticForCondition (std::shared_ptr< AST::BashArithmeticForCondition > node)
 
void enterBashArithmeticForStatement (std::shared_ptr< AST::BashArithmeticForStatement > node)
 
void exitBashArithmeticForStatement (std::shared_ptr< AST::BashArithmeticForStatement > node)
 
void enterBashArithmeticSubstitution (std::shared_ptr< AST::BashArithmeticSubstitution > node)
 
void exitBashArithmeticSubstitution (std::shared_ptr< AST::BashArithmeticSubstitution > node)
 
void enterBashCasePattern (std::shared_ptr< AST::BashCasePattern > node)
 
void exitBashCasePattern (std::shared_ptr< AST::BashCasePattern > node)
 
void enterBashCasePatternHeader (std::shared_ptr< AST::BashCasePatternHeader > node)
 
void exitBashCasePatternHeader (std::shared_ptr< AST::BashCasePatternHeader > node)
 
void enterBashCaseStatement (std::shared_ptr< AST::BashCaseStatement > node)
 
void exitBashCaseStatement (std::shared_ptr< AST::BashCaseStatement > node)
 
void enterBashCommandSequence (std::shared_ptr< AST::BashCommandSequence > node)
 
void exitBashCommandSequence (std::shared_ptr< AST::BashCommandSequence > node)
 
void enterBashForStatement (std::shared_ptr< AST::BashForStatement > node)
 
void exitBashForStatement (std::shared_ptr< AST::BashForStatement > node)
 
void enterBashIfCondition (std::shared_ptr< AST::BashIfCondition > node)
 
void exitBashIfCondition (std::shared_ptr< AST::BashIfCondition > node)
 
void enterBashIfElseBranch (std::shared_ptr< AST::BashIfElseBranch > node)
 
void exitBashIfElseBranch (std::shared_ptr< AST::BashIfElseBranch > node)
 
void enterBashIfRootBranch (std::shared_ptr< AST::BashIfRootBranch > node)
 
void exitBashIfRootBranch (std::shared_ptr< AST::BashIfRootBranch > node)
 
void enterBashIfStatement (std::shared_ptr< AST::BashIfStatement > node)
 
void exitBashIfStatement (std::shared_ptr< AST::BashIfStatement > node)
 
void enterBashInCondition (std::shared_ptr< AST::BashInCondition > node)
 
void exitBashInCondition (std::shared_ptr< AST::BashInCondition > node)
 
void enterBashPipeline (std::shared_ptr< AST::BashPipeline > node)
 
void exitBashPipeline (std::shared_ptr< AST::BashPipeline > node)
 
void enterBashRedirection (std::shared_ptr< AST::BashRedirection > node)
 
void exitBashRedirection (std::shared_ptr< AST::BashRedirection > node)
 
void enterBashSelectStatement (std::shared_ptr< AST::BashSelectStatement > node)
 
void exitBashSelectStatement (std::shared_ptr< AST::BashSelectStatement > node)
 
void enterBashTestConditionCommand (std::shared_ptr< AST::BashTestConditionCommand > node)
 
void exitBashTestConditionCommand (std::shared_ptr< AST::BashTestConditionCommand > node)
 
void enterBashUntilStatement (std::shared_ptr< AST::BashUntilStatement > node)
 
void exitBashUntilStatement (std::shared_ptr< AST::BashUntilStatement > node)
 
void enterBashVariable (std::shared_ptr< AST::BashVariable > node)
 
void exitBashVariable (std::shared_ptr< AST::BashVariable > node)
 
void enterBashWhileOrUntilCondition (std::shared_ptr< AST::BashWhileOrUntilCondition > node)
 
void exitBashWhileOrUntilCondition (std::shared_ptr< AST::BashWhileOrUntilCondition > node)
 
void enterBashWhileStatement (std::shared_ptr< AST::BashWhileStatement > node)
 
void exitBashWhileStatement (std::shared_ptr< AST::BashWhileStatement > node)
 
void enterBashFunction (std::shared_ptr< AST::BashFunction > node)
 
void exitBashFunction (std::shared_ptr< AST::BashFunction > node)
 
void enterBlock (std::shared_ptr< AST::Block > node)
 
void exitBlock (std::shared_ptr< AST::Block > node)
 
void enterClassDefinition (std::shared_ptr< AST::ClassDefinition > node)
 
void exitClassDefinition (std::shared_ptr< AST::ClassDefinition > node)
 
void enterConnective (std::shared_ptr< AST::Connective > node)
 
void exitConnective (std::shared_ptr< AST::Connective > node)
 
void enterConstructorDefinition (std::shared_ptr< AST::ConstructorDefinition > node)
 
void exitConstructorDefinition (std::shared_ptr< AST::ConstructorDefinition > node)
 
void enterDatamemberDeclaration (std::shared_ptr< AST::DatamemberDeclaration > node)
 
void exitDatamemberDeclaration (std::shared_ptr< AST::DatamemberDeclaration > node)
 
void enterDeleteStatement (std::shared_ptr< AST::DeleteStatement > node)
 
void exitDeleteStatement (std::shared_ptr< AST::DeleteStatement > node)
 
void enterDestructorDefinition (std::shared_ptr< AST::DestructorDefinition > node)
 
void exitDestructorDefinition (std::shared_ptr< AST::DestructorDefinition > node)
 
void enterDoublequotedString (std::shared_ptr< AST::DoublequotedString > node)
 
void exitDoublequotedString (std::shared_ptr< AST::DoublequotedString > node)
 
void enterDynamicCast (std::shared_ptr< AST::DynamicCast > node)
 
void exitDynamicCast (std::shared_ptr< AST::DynamicCast > node)
 
void enterDynamicCastTarget (std::shared_ptr< AST::DynamicCastTarget > node)
 
void exitDynamicCastTarget (std::shared_ptr< AST::DynamicCastTarget > node)
 
void enterHeredocBody (std::shared_ptr< AST::HeredocBody > node)
 
void exitHeredocBody (std::shared_ptr< AST::HeredocBody > node)
 
void enterHereString (std::shared_ptr< AST::HereString > node)
 
void exitHereString (std::shared_ptr< AST::HereString > node)
 
void enterIncludeStatement (std::shared_ptr< AST::IncludeStatement > node)
 Handles.
 
void exitIncludeStatement (std::shared_ptr< AST::IncludeStatement > node)
 
void enterMethodDefinition (std::shared_ptr< AST::MethodDefinition > node)
 
void exitMethodDefinition (std::shared_ptr< AST::MethodDefinition > node)
 
void enterNewStatement (std::shared_ptr< AST::NewStatement > node)
 
void exitNewStatement (std::shared_ptr< AST::NewStatement > node)
 
void enterObjectAssignment (std::shared_ptr< AST::ObjectAssignment > node)
 
void exitObjectAssignment (std::shared_ptr< AST::ObjectAssignment > node)
 
void enterObjectInstantiation (std::shared_ptr< AST::ObjectInstantiation > node)
 
void exitObjectInstantiation (std::shared_ptr< AST::ObjectInstantiation > node)
 
void enterObjectReference (std::shared_ptr< AST::ObjectReference > node)
 
void exitObjectReference (std::shared_ptr< AST::ObjectReference > node)
 
void enterParameterExpansion (std::shared_ptr< AST::ParameterExpansion > node)
 
void exitParameterExpansion (std::shared_ptr< AST::ParameterExpansion > node)
 
void enterPointerDeclaration (std::shared_ptr< AST::PointerDeclaration > node)
 
void exitPointerDeclaration (std::shared_ptr< AST::PointerDeclaration > node)
 
void enterPrimitiveAssignment (std::shared_ptr< AST::PrimitiveAssignment > node)
 
void exitPrimitiveAssignment (std::shared_ptr< AST::PrimitiveAssignment > node)
 
void enterProcessSubstitution (std::shared_ptr< AST::ProcessSubstitution > node)
 
void exitProcessSubstitution (std::shared_ptr< AST::ProcessSubstitution > node)
 
void enterRawSubshell (std::shared_ptr< AST::RawSubshell > node)
 
void exitRawSubshell (std::shared_ptr< AST::RawSubshell > node)
 
void enterRawText (std::shared_ptr< AST::RawText > node)
 
void exitRawText (std::shared_ptr< AST::RawText > node)
 
void enterSubshellSubstitution (std::shared_ptr< AST::SubshellSubstitution > node)
 
void exitSubshellSubstitution (std::shared_ptr< AST::SubshellSubstitution > node)
 
void enterSupershell (std::shared_ptr< AST::Supershell > node)
 
void exitSupershell (std::shared_ptr< AST::Supershell > node)
 
void enterTypeofExpression (std::shared_ptr< AST::TypeofExpression > node)
 
void exitTypeofExpression (std::shared_ptr< AST::TypeofExpression > node)
 
void enterValueAssignment (std::shared_ptr< AST::ValueAssignment > node)
 
void exitValueAssignment (std::shared_ptr< AST::ValueAssignment > node)
 
- Public Member Functions inherited from AST::BaseListener< BashppListener >
virtual ~BaseListener ()=default
 
void walk (std::shared_ptr< AST::ASTNode > node)
 
void set_has_errors (bool has_errors)
 
void set_parser_errors (const std::vector< AST::ParserError > &errors)
 

Private Member Functions

bool should_declare_local () const
 

Private Attributes

std::string source_file
 Path to the source file being compiled (used for error reporting)
 
bool included = false
 
std::shared_ptr< std::vector< std::string > > include_paths = nullptr
 A list of paths to search for included files.
 
bool suppress_warnings = false
 
std::shared_ptr< std::set< std::string > > included_files = std::make_shared<std::set<std::string>>()
 A set of (unique) included files (used for '@include_once' directives)
 
BashppListenerincluded_from = nullptr
 
std::vector< std::string > include_stack
 A chain of included files, from the main file to the current file (used for error reporting)
 
std::shared_ptr< std::ostream > code_buffer
 
std::shared_ptr< std::ostream > output_stream
 Pointer to the output stream to write the compiled code to.
 
std::string output_file
 
bool run_on_exit = false
 
BashVersion target_bash_version = {5, 2}
 The target Bash version to compile for (default is 5.2)
 
std::vector< char * > arguments = {}
 Command-line arguments to pass to the compiled program if run_on_exit is true.
 
std::shared_ptr< bpp::bpp_programprogram = std::make_shared<bpp::bpp_program>()
 
bool in_method = false
 
bool in_class = false
 
bool in_supershell = false
 
std::stack< std::monostate > bash_function_stack
 
std::stack< std::monostate > dynamic_cast_stack
 
std::stack< std::monostate > typeof_stack
 
ExpectationsStack context_expectations_stack
 
std::stack< std::shared_ptr< bpp::bpp_entity > > entity_stack
 A stack to keep track of the current entity being processed.
 
std::unordered_map< std::string, std::string > replacement_file_contents
 A map of file paths to replacement contents for those files This is used by the language server to provide unsaved changes to the listener so that we can report diagnostics/completions/etc based on the unsaved changes.
 
std::shared_ptr< bpp::bpp_classprimitive
 
bool lsp_mode = false
 

Additional Inherited Members

- Protected Attributes inherited from AST::BaseListener< BashppListener >
bool program_has_errors
 
std::vector< AST::ParserErrorparser_errors
 

Detailed Description

The main listener class for the Bash++ compiler.

This class is the main listener for the Bash++ compiler. This is where the main logic for the compiler is implemented by walking the parse tree.

The listener is responsible for generating the compiled Bash code from the parsed Bash++ code. The listener is also responsible for handling errors and warnings.

A brief run-down of how the parse tree works:

When we enter a node in the parse tree, we execute the enter* function for that node. When we exit a node in the parse tree, we execute the exit* function for that node.

Member Function Documentation

◆ enterArrayAssignment()

void BashppListener::enterArrayAssignment ( std::shared_ptr< AST::ArrayAssignment node)

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

◆ enterArrayIndex()

void BashppListener::enterArrayIndex ( std::shared_ptr< AST::ArrayIndex node)

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

Array indices take the form: [...] Where the contents of the brackets are the array index And can be any valid sequence of statements

◆ enterBash53NativeSupershell()

void BashppListener::enterBash53NativeSupershell ( std::shared_ptr< AST::Bash53NativeSupershell node)

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

◆ enterBashArithmeticForCondition()

void BashppListener::enterBashArithmeticForCondition ( std::shared_ptr< AST::BashArithmeticForCondition node)

◆ enterBashArithmeticForStatement()

void BashppListener::enterBashArithmeticForStatement ( std::shared_ptr< AST::BashArithmeticForStatement node)

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

◆ enterBashArithmeticSubstitution()

void BashppListener::enterBashArithmeticSubstitution ( std::shared_ptr< AST::BashArithmeticSubstitution node)

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

Bash arithmetic is a series of arithmetic operations that are enclosed in $((...)) They do not run in a subshell. So, unlike with the subshell rule, We can preserve objects instantiated within the arithmetic context, etc

◆ enterBashCasePattern()

void BashppListener::enterBashCasePattern ( std::shared_ptr< AST::BashCasePattern node)

◆ enterBashCasePatternHeader()

void BashppListener::enterBashCasePatternHeader ( std::shared_ptr< AST::BashCasePatternHeader node)

◆ enterBashCaseStatement()

void BashppListener::enterBashCaseStatement ( std::shared_ptr< AST::BashCaseStatement node)

Copyright (C) 2025 rail5 Bash++: Bash with classes This file contains parser rules for all of:

  1. BashCaseStatement
  2. BashCasePattern
  3. BashCasePatternHeader

Bash case statements take the form case (something) in pattern1) ... ;; ... esac

◆ enterBashCommandSequence()

void BashppListener::enterBashCommandSequence ( std::shared_ptr< AST::BashCommandSequence node)

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

◆ enterBashForStatement()

void BashppListener::enterBashForStatement ( std::shared_ptr< AST::BashForStatement node)

Copyright (C) 2025 rail5 Bash++: Bash with classes This file contains parser rules for all of:

  1. BashForStatement
  2. BashSelectStatement
  3. BashInCondition

◆ enterBashFunction()

void BashppListener::enterBashFunction ( std::shared_ptr< AST::BashFunction node)

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

Bash functions take the format:

function function_name { ... }

Or: function function_name() { ... }

Or: function_name() { ... }

◆ enterBashIfCondition()

void BashppListener::enterBashIfCondition ( std::shared_ptr< AST::BashIfCondition node)

◆ enterBashIfElseBranch()

void BashppListener::enterBashIfElseBranch ( std::shared_ptr< AST::BashIfElseBranch node)

◆ enterBashIfRootBranch()

void BashppListener::enterBashIfRootBranch ( std::shared_ptr< AST::BashIfRootBranch node)

◆ enterBashIfStatement()

void BashppListener::enterBashIfStatement ( std::shared_ptr< AST::BashIfStatement node)

Copyright (C) 2025 rail5 Bash++: Bash with classes This file contains parser rules for all of:

  1. BashIfStatement
  2. BashIfCondition
  3. BashIfRootBranch
  4. BashIfElseBranch

Bash if statement take the form if CONDITION; then ... elif CONDITION; then ... else ... fi

The elif/else branches will be caught by the BashIfRootBranch and BashIfElseBranch contexts Both of those will be children of the BashIfStatement context in the parse tree

The only thing that we need to be careful about is this: All of the pre-code which is generated INSIDE of the if CONDITION Should be placed before the if statement altogether, not only before the condition Likewise all of the post-code for the condition should be placed after the if statement

For example, consider the following code: if [[ -f "@this.filePath" ]]; then ... elif [[ -f "@this.otherFilePath" ]]; then ... fi

Pre-code has to be generated in order to access @this.filePath and @this.otherFilePath The pre-code converts these references into ordinary variable references which we can substitute directly into the if condition As in, for example, swapping 'if [[ -f "@this.filePath" ]]' with 'if [[ -f "$filePath" ]]' Although we have better naming conventions for the variables, this is just an example

If we weren't careful, and just placed the pre-code the way we always do, we would end up with something like this: $filePath={whatever we need to do to access @this.filePath} if [[ -f "$filePath" ]]; then ... $otherFilePath={whatever we need to do to access @this.otherFilePath} elif [[ -f "$otherFilePath" ]]; then ... fi

As you can tell from the above, the $otherFilePath assignment is INSIDE the first branch of the if statement And therefore is completely useless – if the first branch is taken, the second branch will never be taken And in the event that the second branch IS taken, $otherFilePath will not be defined

So, what we have to do instead is a bit more like: $filePath={whatever we need to do to access @this.filePath} $otherFilePath={whatever we need to do to access @this.otherFilePath} if [[ -f "$filePath" ]]; then ... elif [[ -f "$otherFilePath" ]]; then ... fi

◆ enterBashInCondition()

void BashppListener::enterBashInCondition ( std::shared_ptr< AST::BashInCondition node)

◆ enterBashPipeline()

void BashppListener::enterBashPipeline ( std::shared_ptr< AST::BashPipeline node)

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

◆ enterBashRedirection()

void BashppListener::enterBashRedirection ( std::shared_ptr< AST::BashRedirection node)

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

◆ enterBashSelectStatement()

void BashppListener::enterBashSelectStatement ( std::shared_ptr< AST::BashSelectStatement node)

◆ enterBashTestConditionCommand()

void BashppListener::enterBashTestConditionCommand ( std::shared_ptr< AST::BashTestConditionCommand node)

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

◆ enterBashUntilStatement()

void BashppListener::enterBashUntilStatement ( std::shared_ptr< AST::BashUntilStatement node)

◆ enterBashVariable()

void BashppListener::enterBashVariable ( std::shared_ptr< AST::BashVariable node)

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

◆ enterBashWhileOrUntilCondition()

void BashppListener::enterBashWhileOrUntilCondition ( std::shared_ptr< AST::BashWhileOrUntilCondition node)

◆ enterBashWhileStatement()

void BashppListener::enterBashWhileStatement ( std::shared_ptr< AST::BashWhileStatement node)

Copyright (C) 2025 rail5 Bash++: Bash with classes This file contains parser rules for all of:

  1. BashWhileStatement

BashUntilStatement

  1. BashWhileOrUntilCondition

◆ enterBlock()

void BashppListener::enterBlock ( std::shared_ptr< AST::Block node)

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

Blocks are just groups of statements enclosed in curly-braces Sometimes, a block is a part of a larger construct, such as a method or class definition

◆ enterClassDefinition()

void BashppListener::enterClassDefinition ( std::shared_ptr< AST::ClassDefinition node)

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

◆ enterConnective()

void BashppListener::enterConnective ( std::shared_ptr< AST::Connective node)

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

◆ enterConstructorDefinition()

void BashppListener::enterConstructorDefinition ( std::shared_ptr< AST::ConstructorDefinition node)

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

Constructor definitions take the form @constructor { ... }

◆ enterDatamemberDeclaration()

void BashppListener::enterDatamemberDeclaration ( std::shared_ptr< AST::DatamemberDeclaration node)

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

This will either be:

  1. A primitive
  2. An object
  3. A pointer If it's a primitive, then IDENTIFIER will be set If it's an object, then object_instantiation will be set, and we'll handle that in the object_instantiation rule If it's a pointer, then pointer_declaration will be set, and we'll handle that in the pointer_declaration rule

◆ enterDeleteStatement()

void BashppListener::enterDeleteStatement ( std::shared_ptr< AST::DeleteStatement node)

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

Delete statements take the form @delete @object Where object is the name of the object to delete

This statement calls the __delete function for the object and the object's destructor if it exists If the destructor exists, it will be called first (before __delete) It then unsets the object

◆ enterDestructorDefinition()

void BashppListener::enterDestructorDefinition ( std::shared_ptr< AST::DestructorDefinition node)

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

Destructor definitions take the form @destructor { ... }

◆ enterDoublequotedString()

void BashppListener::enterDoublequotedString ( std::shared_ptr< AST::DoublequotedString node)

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

◆ enterDynamicCast()

void BashppListener::enterDynamicCast ( std::shared_ptr< AST::DynamicCast node)

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

Dynamic cast statements take the form @dynamic_cast<ClassName> Pointer or: @dynamic_cast<$shell_variable> Pointer or: @dynamic_cast<@object.reference> Pointer Where Pointer is what we're casting

If the cast is in the first form, ClassName refers to the class we're casting to If it's in the second or third form, we expect that the class we're casting to will be evaluated at runtime Ie, the class name is contained in the shell variable or object reference

This statement performs a runtime check to verify the cast is valid And substitutes either the address of the cast object or the @nullptr value

◆ enterDynamicCastTarget()

void BashppListener::enterDynamicCastTarget ( std::shared_ptr< AST::DynamicCastTarget node)

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

Dynamic cast targets are the part of a dynamic cast statement that specifies the class we're casting to This can be either an identifier (the name of the class), a shell variable (the name of the class is stored in the variable), or an object reference (the class is determined by the output of the object reference)

◆ enterHeredocBody()

void BashppListener::enterHeredocBody ( std::shared_ptr< AST::HeredocBody node)

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

◆ enterHereString()

void BashppListener::enterHereString ( std::shared_ptr< AST::HereString node)

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

◆ enterIncludeStatement()

void BashppListener::enterIncludeStatement ( std::shared_ptr< AST::IncludeStatement node)

Handles.

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

@include_once statements

This function is called when the parser enters an

@include_once statement.

The syntax of an include is:

| dynamic] {PATH} [as "{PATH}"]

For example:

@include_once dynamic <Stack> as "/usr/lib/Stack.sh"

Or:

◆ enterMethodDefinition()

void BashppListener::enterMethodDefinition ( std::shared_ptr< AST::MethodDefinition node)

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

◆ enterNewStatement()

void BashppListener::enterNewStatement ( std::shared_ptr< AST::NewStatement node)

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

New statements take the form @new ClassName Where ClassName is the name of the class to instantiate

This statement creates a new object of the specified class And replaces the "@new ClassName" statement with the address of the new object

◆ enterObjectAssignment()

void BashppListener::enterObjectAssignment ( std::shared_ptr< AST::ObjectAssignment node)

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

◆ enterObjectInstantiation()

void BashppListener::enterObjectInstantiation ( std::shared_ptr< AST::ObjectInstantiation node)

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

The object type will be stored in one of either IDENTIFIER_LVALUE or IDENTIFIER(0) If IDENTIFIER_LVALUE, then the object name will be in IDENTIFIER(0) If IDENTIFIER(0), then the object name will be in IDENTIFIER(1)

◆ enterObjectReference()

void BashppListener::enterObjectReference ( std::shared_ptr< AST::ObjectReference node)

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

Object references take the form [*|&]@IDENTIFIER.IDENTIFIER.IDENTIFIER... Where each IDENTIFIER following a dot is a member of the object referenced by the preceding IDENTIFIER

This reference may resolve to either an object or a method If it's a primitive object, treat this as an rvalue and get the value of the primitive object If it's a non-primitive object, this is a method call to .toPrimitive If it's a method, call the method in a supershell and substitute the result

This rule handles:

  • Normal object references (@obj.member)
  • Self-references (@this.member or @super.member)
  • Pointer dereferences (*@ptr)
  • Object addresses (&@obj)

◆ enterParameterExpansion()

void BashppListener::enterParameterExpansion ( std::shared_ptr< AST::ParameterExpansion node)

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

◆ enterPointerDeclaration()

void BashppListener::enterPointerDeclaration ( std::shared_ptr< AST::PointerDeclaration node)

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

◆ enterPrimitiveAssignment()

void BashppListener::enterPrimitiveAssignment ( std::shared_ptr< AST::PrimitiveAssignment node)

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

◆ enterProcessSubstitution()

void BashppListener::enterProcessSubstitution ( std::shared_ptr< AST::ProcessSubstitution node)

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

◆ enterProgram()

void BashppListener::enterProgram ( std::shared_ptr< AST::Program node)

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

◆ enterRawSubshell()

void BashppListener::enterRawSubshell ( std::shared_ptr< AST::RawSubshell node)

◆ enterRawText()

void BashppListener::enterRawText ( std::shared_ptr< AST::RawText node)

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

◆ enterSubshellSubstitution()

void BashppListener::enterSubshellSubstitution ( std::shared_ptr< AST::SubshellSubstitution node)

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

◆ enterSupershell()

void BashppListener::enterSupershell ( std::shared_ptr< AST::Supershell node)

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

Supershells take the form @(...) Where ... is a series of commands to be executed in a supershell Supershells can be nested

◆ enterTypeofExpression()

void BashppListener::enterTypeofExpression ( std::shared_ptr< AST::TypeofExpression node)

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

The typeof statement is used to determine the type of a value at runtime. It takes the form: @typeof

Where

is a valid rvalue.

◆ enterValueAssignment()

void BashppListener::enterValueAssignment ( std::shared_ptr< AST::ValueAssignment node)

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

◆ exitArrayAssignment()

void BashppListener::exitArrayAssignment ( std::shared_ptr< AST::ArrayAssignment node)

◆ exitArrayIndex()

void BashppListener::exitArrayIndex ( std::shared_ptr< AST::ArrayIndex node)

◆ exitBash53NativeSupershell()

void BashppListener::exitBash53NativeSupershell ( std::shared_ptr< AST::Bash53NativeSupershell node)

◆ exitBashArithmeticForCondition()

void BashppListener::exitBashArithmeticForCondition ( std::shared_ptr< AST::BashArithmeticForCondition node)

◆ exitBashArithmeticForStatement()

void BashppListener::exitBashArithmeticForStatement ( std::shared_ptr< AST::BashArithmeticForStatement node)

◆ exitBashArithmeticSubstitution()

void BashppListener::exitBashArithmeticSubstitution ( std::shared_ptr< AST::BashArithmeticSubstitution node)

◆ exitBashCasePattern()

void BashppListener::exitBashCasePattern ( std::shared_ptr< AST::BashCasePattern node)

◆ exitBashCasePatternHeader()

void BashppListener::exitBashCasePatternHeader ( std::shared_ptr< AST::BashCasePatternHeader node)

◆ exitBashCaseStatement()

void BashppListener::exitBashCaseStatement ( std::shared_ptr< AST::BashCaseStatement node)

◆ exitBashCommandSequence()

void BashppListener::exitBashCommandSequence ( std::shared_ptr< AST::BashCommandSequence node)

◆ exitBashForStatement()

void BashppListener::exitBashForStatement ( std::shared_ptr< AST::BashForStatement node)

◆ exitBashFunction()

void BashppListener::exitBashFunction ( std::shared_ptr< AST::BashFunction node)

◆ exitBashIfCondition()

void BashppListener::exitBashIfCondition ( std::shared_ptr< AST::BashIfCondition node)

◆ exitBashIfElseBranch()

void BashppListener::exitBashIfElseBranch ( std::shared_ptr< AST::BashIfElseBranch node)

◆ exitBashIfRootBranch()

void BashppListener::exitBashIfRootBranch ( std::shared_ptr< AST::BashIfRootBranch node)

◆ exitBashIfStatement()

void BashppListener::exitBashIfStatement ( std::shared_ptr< AST::BashIfStatement node)

◆ exitBashInCondition()

void BashppListener::exitBashInCondition ( std::shared_ptr< AST::BashInCondition node)

◆ exitBashPipeline()

void BashppListener::exitBashPipeline ( std::shared_ptr< AST::BashPipeline node)

◆ exitBashRedirection()

void BashppListener::exitBashRedirection ( std::shared_ptr< AST::BashRedirection node)

◆ exitBashSelectStatement()

void BashppListener::exitBashSelectStatement ( std::shared_ptr< AST::BashSelectStatement node)

◆ exitBashTestConditionCommand()

void BashppListener::exitBashTestConditionCommand ( std::shared_ptr< AST::BashTestConditionCommand node)

◆ exitBashUntilStatement()

void BashppListener::exitBashUntilStatement ( std::shared_ptr< AST::BashUntilStatement node)

◆ exitBashVariable()

void BashppListener::exitBashVariable ( std::shared_ptr< AST::BashVariable node)

◆ exitBashWhileOrUntilCondition()

void BashppListener::exitBashWhileOrUntilCondition ( std::shared_ptr< AST::BashWhileOrUntilCondition node)

◆ exitBashWhileStatement()

void BashppListener::exitBashWhileStatement ( std::shared_ptr< AST::BashWhileStatement node)

◆ exitBlock()

void BashppListener::exitBlock ( std::shared_ptr< AST::Block node)

◆ exitClassDefinition()

void BashppListener::exitClassDefinition ( std::shared_ptr< AST::ClassDefinition node)

◆ exitConnective()

void BashppListener::exitConnective ( std::shared_ptr< AST::Connective node)

◆ exitConstructorDefinition()

void BashppListener::exitConstructorDefinition ( std::shared_ptr< AST::ConstructorDefinition node)

◆ exitDatamemberDeclaration()

void BashppListener::exitDatamemberDeclaration ( std::shared_ptr< AST::DatamemberDeclaration node)

◆ exitDeleteStatement()

void BashppListener::exitDeleteStatement ( std::shared_ptr< AST::DeleteStatement node)

◆ exitDestructorDefinition()

void BashppListener::exitDestructorDefinition ( std::shared_ptr< AST::DestructorDefinition node)

◆ exitDoublequotedString()

void BashppListener::exitDoublequotedString ( std::shared_ptr< AST::DoublequotedString node)

◆ exitDynamicCast()

void BashppListener::exitDynamicCast ( std::shared_ptr< AST::DynamicCast node)

◆ exitDynamicCastTarget()

void BashppListener::exitDynamicCastTarget ( std::shared_ptr< AST::DynamicCastTarget node)

◆ exitHeredocBody()

void BashppListener::exitHeredocBody ( std::shared_ptr< AST::HeredocBody node)

◆ exitHereString()

void BashppListener::exitHereString ( std::shared_ptr< AST::HereString node)

◆ exitIncludeStatement()

void BashppListener::exitIncludeStatement ( std::shared_ptr< AST::IncludeStatement node)

◆ exitMethodDefinition()

void BashppListener::exitMethodDefinition ( std::shared_ptr< AST::MethodDefinition node)

◆ exitNewStatement()

void BashppListener::exitNewStatement ( std::shared_ptr< AST::NewStatement node)

◆ exitObjectAssignment()

void BashppListener::exitObjectAssignment ( std::shared_ptr< AST::ObjectAssignment node)

◆ exitObjectInstantiation()

void BashppListener::exitObjectInstantiation ( std::shared_ptr< AST::ObjectInstantiation node)

◆ exitObjectReference()

void BashppListener::exitObjectReference ( std::shared_ptr< AST::ObjectReference node)

There are 12 possible combinations here: LVALUE SELF_REF POINTER_DEREF OBJ_ADDRESS

  1. 0 0 0 0 -> Object reference as rvalue
  2. 0 0 0 1 -> Object address as rvalue
  3. 0 0 1 0 -> Pointer dereference as rvalue
  4. 0 1 0 0 -> Self reference as rvalue
  5. 0 1 0 1 -> Self reference as rvalue (address of)
  6. 0 1 1 0 -> Self reference as rvalue (pointer deref)
  7. 1 0 0 0 -> Object reference as lvalue
  8. 1 0 0 1 -> Object address as lvalue
  9. 1 0 1 0 -> Pointer dereference as lvalue
  10. 1 1 0 0 -> Self reference as lvalue
  11. 1 1 0 1 -> Self reference as lvalue (address of)
  12. 1 1 1 0 -> Self reference as lvalue (pointer deref)

POINTER_DEREF and OBJ_ADDRESS are mutually exclusive, so combinations where both are 1 are invalid

◆ exitParameterExpansion()

void BashppListener::exitParameterExpansion ( std::shared_ptr< AST::ParameterExpansion node)

◆ exitPointerDeclaration()

void BashppListener::exitPointerDeclaration ( std::shared_ptr< AST::PointerDeclaration node)

◆ exitPrimitiveAssignment()

void BashppListener::exitPrimitiveAssignment ( std::shared_ptr< AST::PrimitiveAssignment node)

◆ exitProcessSubstitution()

void BashppListener::exitProcessSubstitution ( std::shared_ptr< AST::ProcessSubstitution node)

◆ exitProgram()

void BashppListener::exitProgram ( std::shared_ptr< AST::Program node)

◆ exitRawSubshell()

void BashppListener::exitRawSubshell ( std::shared_ptr< AST::RawSubshell node)

◆ exitRawText()

void BashppListener::exitRawText ( std::shared_ptr< AST::RawText node)

◆ exitSubshellSubstitution()

void BashppListener::exitSubshellSubstitution ( std::shared_ptr< AST::SubshellSubstitution node)

◆ exitSupershell()

void BashppListener::exitSupershell ( std::shared_ptr< AST::Supershell node)

◆ exitTypeofExpression()

void BashppListener::exitTypeofExpression ( std::shared_ptr< AST::TypeofExpression node)

◆ exitValueAssignment()

void BashppListener::exitValueAssignment ( std::shared_ptr< AST::ValueAssignment node)

Value assignments will appear in the following contexts:

  1. Member declarations
  2. Object instantiations
  3. Pointer declarations
  4. Object assignments

◆ get_include_stack()

const std::vector< std::string > & BashppListener::get_include_stack ( )

◆ get_included_files()

std::shared_ptr< std::set< std::string > > BashppListener::get_included_files ( )

◆ get_lsp_mode()

bool BashppListener::get_lsp_mode ( )

◆ get_program()

std::shared_ptr< bpp::bpp_program > BashppListener::get_program ( )

◆ get_source_file()

std::string BashppListener::get_source_file ( )

◆ latest_code_entity()

std::shared_ptr< bpp::bpp_code_entity > BashppListener::latest_code_entity ( )

◆ set_arguments()

void BashppListener::set_arguments ( std::vector< char * >  arguments)

◆ set_code_buffer()

void BashppListener::set_code_buffer ( std::shared_ptr< std::ostream >  code_buffer)

◆ set_include_paths()

void BashppListener::set_include_paths ( std::shared_ptr< std::vector< std::string > >  include_paths)

◆ set_included()

void BashppListener::set_included ( bool  included)

◆ set_included_files()

void BashppListener::set_included_files ( std::shared_ptr< std::set< std::string > >  included_files)

Sets the included_files pointer to the given set of included files.

◆ set_included_from()

void BashppListener::set_included_from ( BashppListener included_from)

Sets the included_from pointer to the given listener.

◆ set_lsp_mode()

void BashppListener::set_lsp_mode ( bool  lsp_mode)

◆ set_output_file()

void BashppListener::set_output_file ( std::string  output_file)

◆ set_output_stream()

void BashppListener::set_output_stream ( std::shared_ptr< std::ostream >  output_stream)

◆ set_replacement_file_contents()

void BashppListener::set_replacement_file_contents ( const std::string &  file_path,
const std::string &  contents 
)

◆ set_run_on_exit()

void BashppListener::set_run_on_exit ( bool  run_on_exit)

◆ set_source_file()

void BashppListener::set_source_file ( std::string  source_file)

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

◆ set_suppress_warnings()

void BashppListener::set_suppress_warnings ( bool  suppress_warnings)

◆ set_target_bash_version()

void BashppListener::set_target_bash_version ( BashVersion  target_bash_version)

◆ should_declare_local()

bool BashppListener::should_declare_local ( ) const
private

Member Data Documentation

◆ arguments

BashppListener::arguments = {}
private

Command-line arguments to pass to the compiled program if run_on_exit is true.

◆ bash_function_stack

std::stack<std::monostate> BashppListener::bash_function_stack
private

◆ code_buffer

std::shared_ptr<std::ostream> BashppListener::code_buffer
private

◆ context_expectations_stack

ExpectationsStack BashppListener::context_expectations_stack
private

◆ dynamic_cast_stack

std::stack<std::monostate> BashppListener::dynamic_cast_stack
private

◆ entity_stack

BashppListener::entity_stack
private

A stack to keep track of the current entity being processed.

For example, when we encounter a class definition, we push the class onto the entity_stack. Then, inside that class, when we encounter a method definition, we push the method onto the entity_stack. Inside that method, when we encounter a value assignment, we push the value assignment onto the entity_stack. When we're done with the value assignment, we pop it off the entity_stack, so that the method is now at the top of the stack. When we're done with the method, we pop it off the entity_stack, so that the class is now at the top of the stack. When we're done with the class, we pop it off the entity_stack, so that the program is now at the top of the stack.

◆ in_class

bool BashppListener::in_class = false
private

◆ in_method

bool BashppListener::in_method = false
private

◆ in_supershell

bool BashppListener::in_supershell = false
private

◆ include_paths

BashppListener::include_paths = nullptr
private

A list of paths to search for included files.

◆ include_stack

BashppListener::include_stack
private

A chain of included files, from the main file to the current file (used for error reporting)

◆ included

bool BashppListener::included = false
private

◆ included_files

BashppListener::included_files = std::make_shared<std::set<std::string>>()
private

A set of (unique) included files (used for '@include_once' directives)

◆ included_from

BashppListener* BashppListener::included_from = nullptr
private

◆ lsp_mode

bool BashppListener::lsp_mode = false
private

◆ output_file

std::string BashppListener::output_file
private

◆ output_stream

BashppListener::output_stream
private

Pointer to the output stream to write the compiled code to.

◆ primitive

std::shared_ptr<bpp::bpp_class> BashppListener::primitive
private

◆ program

std::shared_ptr<bpp::bpp_program> BashppListener::program = std::make_shared<bpp::bpp_program>()
private

◆ replacement_file_contents

BashppListener::replacement_file_contents
private

A map of file paths to replacement contents for those files This is used by the language server to provide unsaved changes to the listener so that we can report diagnostics/completions/etc based on the unsaved changes.

◆ run_on_exit

bool BashppListener::run_on_exit = false
private

◆ source_file

BashppListener::source_file
private

Path to the source file being compiled (used for error reporting)

◆ suppress_warnings

bool BashppListener::suppress_warnings = false
private

◆ target_bash_version

BashppListener::target_bash_version = {5, 2}
private

The target Bash version to compile for (default is 5.2)

◆ typeof_stack

std::stack<std::monostate> BashppListener::typeof_stack
private

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