16#include <unordered_map>
79 std::shared_ptr<std::set<std::string>>
included_files = std::make_shared<std::set<std::string>>();
109 std::shared_ptr<bpp::bpp_program>
program = std::make_shared<bpp::bpp_program>();
150 #define show_warning(token, msg) \
151 if (!suppress_warnings) { \
152 bpp::ErrorHandling::Warning _msg(this, token, msg); \
183 void exitProgram(std::shared_ptr<AST::Program> node);
236 void enterBlock(std::shared_ptr<AST::Block> node);
237 void exitBlock(std::shared_ptr<AST::Block> node);
283 void exitRawText(std::shared_ptr<AST::RawText> node);
CRTP base class for AST listeners. CRTP is a kind of language hack that makes static polymorphism pos...
Definition BaseListener.h:110
The main listener class for the Bash++ compiler.
Definition BashppListener.h:57
void enterDoublequotedString(std::shared_ptr< AST::DoublequotedString > node)
Definition DoublequotedString.cpp:8
void exitArrayAssignment(std::shared_ptr< AST::ArrayAssignment > node)
Definition ArrayAssignment.cpp:30
void exitBashFunction(std::shared_ptr< AST::BashFunction > node)
Definition BashFunction.cpp:49
bool in_class
Definition BashppListener.h:113
bool in_method
Definition BashppListener.h:111
void enterDestructorDefinition(std::shared_ptr< AST::DestructorDefinition > node)
Definition DestructorDefinition.cpp:8
void enterClassDefinition(std::shared_ptr< AST::ClassDefinition > node)
Definition ClassDefinition.cpp:8
void enterBashCasePattern(std::shared_ptr< AST::BashCasePattern > node)
Definition BashCaseStatement.cpp:63
void enterDynamicCastTarget(std::shared_ptr< AST::DynamicCastTarget > node)
Definition DynamicCastTarget.cpp:8
void exitBashTestConditionCommand(std::shared_ptr< AST::BashTestConditionCommand > node)
Definition BashTestConditionCommand.cpp:30
void exitBashIfElseBranch(std::shared_ptr< AST::BashIfElseBranch > node)
Definition BashIfStatement.cpp:192
void exitBashSelectStatement(std::shared_ptr< AST::BashSelectStatement > node)
Definition BashForOrSelectStatement.cpp:90
void enterBashInCondition(std::shared_ptr< AST::BashInCondition > node)
Definition BashForOrSelectStatement.cpp:121
void enterDeleteStatement(std::shared_ptr< AST::DeleteStatement > node)
Definition DeleteStatement.cpp:8
void exitDoublequotedString(std::shared_ptr< AST::DoublequotedString > node)
Definition DoublequotedString.cpp:29
void exitProcessSubstitution(std::shared_ptr< AST::ProcessSubstitution > node)
Definition ProcessSubstitution.cpp:18
bool run_on_exit
Definition BashppListener.h:95
std::vector< std::string > include_stack
A chain of included files, from the main file to the current file (used for error reporting)
Definition BashppListener.h:86
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 pr...
Definition BashppListener.h:144
void set_output_file(std::string output_file)
Definition BashppListener.cpp:44
void exitPointerDeclaration(std::shared_ptr< AST::PointerDeclaration > node)
Definition PointerDeclaration.cpp:80
void set_target_bash_version(BashVersion target_bash_version)
Definition BashppListener.cpp:56
void enterDynamicCast(std::shared_ptr< AST::DynamicCast > node)
Definition DynamicCast.cpp:8
void enterBashArithmeticSubstitution(std::shared_ptr< AST::BashArithmeticSubstitution > node)
Definition BashArithmeticSubstitution.cpp:8
void enterBashPipeline(std::shared_ptr< AST::BashPipeline > node)
Definition BashPipeline.cpp:8
void exitDynamicCast(std::shared_ptr< AST::DynamicCast > node)
Definition DynamicCast.cpp:39
void set_run_on_exit(bool run_on_exit)
Definition BashppListener.cpp:48
void exitBash53NativeSupershell(std::shared_ptr< AST::Bash53NativeSupershell > node)
Definition Bash53NativeSupershell.cpp:41
void exitBashPipeline(std::shared_ptr< AST::BashPipeline > node)
Definition BashPipeline.cpp:20
std::shared_ptr< std::ostream > code_buffer
Definition BashppListener.h:92
void exitConnective(std::shared_ptr< AST::Connective > node)
Definition Connective.cpp:18
bool in_supershell
Definition BashppListener.h:114
BashVersion target_bash_version
The target Bash version to compile for (default is 5.2)
Definition BashppListener.h:101
void enterBashTestConditionCommand(std::shared_ptr< AST::BashTestConditionCommand > node)
Definition BashTestConditionCommand.cpp:8
std::vector< char * > arguments
Command-line arguments to pass to the compiled program if run_on_exit is true.
Definition BashppListener.h:107
void enterBashCommandSequence(std::shared_ptr< AST::BashCommandSequence > node)
Definition BashCommandSequence.cpp:8
void enterHereString(std::shared_ptr< AST::HereString > node)
Definition HereString.cpp:8
void set_include_paths(std::shared_ptr< std::vector< std::string > > include_paths)
Definition BashppListener.cpp:12
void enterBashCaseStatement(std::shared_ptr< AST::BashCaseStatement > node)
Definition BashCaseStatement.cpp:15
void exitDeleteStatement(std::shared_ptr< AST::DeleteStatement > node)
Definition DeleteStatement.cpp:29
void enterObjectInstantiation(std::shared_ptr< AST::ObjectInstantiation > node)
Definition ObjectInstantiation.cpp:8
void enterIncludeStatement(std::shared_ptr< AST::IncludeStatement > node)
Handles.
Definition IncludeStatement.cpp:28
void exitBashCasePattern(std::shared_ptr< AST::BashCasePattern > node)
Definition BashCaseStatement.cpp:85
bool get_lsp_mode()
Definition BashppListener.cpp:84
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.
Definition BashppListener.cpp:32
void enterBashIfCondition(std::shared_ptr< AST::BashIfCondition > node)
Definition BashIfStatement.cpp:219
void exitConstructorDefinition(std::shared_ptr< AST::ConstructorDefinition > node)
Definition ConstructorDefinition.cpp:51
void exitBashVariable(std::shared_ptr< AST::BashVariable > node)
Definition BashVariable.cpp:20
void set_source_file(std::string source_file)
Definition BashppListener.cpp:8
void exitBashIfStatement(std::shared_ptr< AST::BashIfStatement > node)
Definition BashIfStatement.cpp:88
void exitBashArithmeticSubstitution(std::shared_ptr< AST::BashArithmeticSubstitution > node)
Definition BashArithmeticSubstitution.cpp:33
std::string get_source_file()
Definition BashppListener.cpp:80
void set_output_stream(std::shared_ptr< std::ostream > output_stream)
Definition BashppListener.cpp:40
void enterBash53NativeSupershell(std::shared_ptr< AST::Bash53NativeSupershell > node)
Definition Bash53NativeSupershell.cpp:8
void enterConnective(std::shared_ptr< AST::Connective > node)
Definition Connective.cpp:8
void enterArrayIndex(std::shared_ptr< AST::ArrayIndex > node)
Definition ArrayIndex.cpp:8
void enterBashIfRootBranch(std::shared_ptr< AST::BashIfRootBranch > node)
Definition BashIfStatement.cpp:112
void enterBashArithmeticForCondition(std::shared_ptr< AST::BashArithmeticForCondition > node)
Definition BashArithmeticForStatement.cpp:48
void enterBashIfElseBranch(std::shared_ptr< AST::BashIfElseBranch > node)
Definition BashIfStatement.cpp:163
void exitRawText(std::shared_ptr< AST::RawText > node)
Definition RawText.cpp:20
const std::vector< std::string > & get_include_stack()
Definition BashppListener.cpp:76
void set_included(bool included)
Definition BashppListener.cpp:16
void exitBlock(std::shared_ptr< AST::Block > node)
Definition Block.cpp:38
std::shared_ptr< std::ostream > output_stream
Pointer to the output stream to write the compiled code to.
Definition BashppListener.h:93
void set_included_from(BashppListener *included_from)
Sets the included_from pointer to the given listener.
Definition BashppListener.cpp:23
std::string output_file
Definition BashppListener.h:94
void exitSupershell(std::shared_ptr< AST::Supershell > node)
Definition Supershell.cpp:36
void enterBashArithmeticForStatement(std::shared_ptr< AST::BashArithmeticForStatement > node)
Definition BashArithmeticForStatement.cpp:8
void exitBashCommandSequence(std::shared_ptr< AST::BashCommandSequence > node)
Definition BashCommandSequence.cpp:21
void exitClassDefinition(std::shared_ptr< AST::ClassDefinition > node)
Definition ClassDefinition.cpp:68
void exitObjectReference(std::shared_ptr< AST::ObjectReference > node)
Definition ObjectReference.cpp:40
void exitValueAssignment(std::shared_ptr< AST::ValueAssignment > node)
Definition ValueAssignment.cpp:39
void set_lsp_mode(bool lsp_mode)
Definition BashppListener.cpp:64
void enterValueAssignment(std::shared_ptr< AST::ValueAssignment > node)
Definition ValueAssignment.cpp:8
bool included
Definition BashppListener.h:65
void exitRawSubshell(std::shared_ptr< AST::RawSubshell > node)
Definition Subshell.cpp:83
void exitBashWhileOrUntilCondition(std::shared_ptr< AST::BashWhileOrUntilCondition > node)
Definition BashWhileOrUntilStatement.cpp:131
std::stack< std::monostate > bash_function_stack
Definition BashppListener.h:115
bool suppress_warnings
Definition BashppListener.h:73
void enterBashUntilStatement(std::shared_ptr< AST::BashUntilStatement > node)
Definition BashWhileOrUntilStatement.cpp:65
void set_arguments(std::vector< char * > arguments)
Definition BashppListener.cpp:60
void enterBashIfStatement(std::shared_ptr< AST::BashIfStatement > node)
Definition BashIfStatement.cpp:16
void enterBashVariable(std::shared_ptr< AST::BashVariable > node)
Definition BashVariable.cpp:8
void exitTypeofExpression(std::shared_ptr< AST::TypeofExpression > node)
Definition TypeofExpression.cpp:28
void enterBashWhileOrUntilCondition(std::shared_ptr< AST::BashWhileOrUntilCondition > node)
Definition BashWhileOrUntilStatement.cpp:116
void exitSubshellSubstitution(std::shared_ptr< AST::SubshellSubstitution > node)
Definition Subshell.cpp:35
std::stack< std::shared_ptr< bpp::bpp_entity > > entity_stack
A stack to keep track of the current entity being processed.
Definition BashppListener.h:135
void set_code_buffer(std::shared_ptr< std::ostream > code_buffer)
Definition BashppListener.cpp:36
std::shared_ptr< std::set< std::string > > included_files
A set of (unique) included files (used for '@include_once' directives)
Definition BashppListener.h:79
void enterProcessSubstitution(std::shared_ptr< AST::ProcessSubstitution > node)
Definition ProcessSubstitution.cpp:8
void enterProgram(std::shared_ptr< AST::Program > node)
Definition Program.cpp:12
void exitIncludeStatement(std::shared_ptr< AST::IncludeStatement > node)
Definition IncludeStatement.cpp:187
void exitMethodDefinition(std::shared_ptr< AST::MethodDefinition > node)
Definition MethodDefinition.cpp:127
void exitArrayIndex(std::shared_ptr< AST::ArrayIndex > node)
Definition ArrayIndex.cpp:33
void enterBashWhileStatement(std::shared_ptr< AST::BashWhileStatement > node)
Definition BashWhileOrUntilStatement.cpp:16
void enterTypeofExpression(std::shared_ptr< AST::TypeofExpression > node)
Definition TypeofExpression.cpp:8
void exitBashIfCondition(std::shared_ptr< AST::BashIfCondition > node)
Definition BashIfStatement.cpp:235
void enterBlock(std::shared_ptr< AST::Block > node)
Definition Block.cpp:8
std::stack< std::monostate > dynamic_cast_stack
Definition BashppListener.h:119
void enterObjectAssignment(std::shared_ptr< AST::ObjectAssignment > node)
Definition ObjectAssignment.cpp:8
void exitBashWhileStatement(std::shared_ptr< AST::BashWhileStatement > node)
Definition BashWhileOrUntilStatement.cpp:35
void exitBashInCondition(std::shared_ptr< AST::BashInCondition > node)
Definition BashForOrSelectStatement.cpp:133
void exitDatamemberDeclaration(std::shared_ptr< AST::DatamemberDeclaration > node)
Definition DatamemberDeclaration.cpp:66
BashppListener * included_from
Definition BashppListener.h:80
void exitBashCasePatternHeader(std::shared_ptr< AST::BashCasePatternHeader > node)
Definition BashCaseStatement.cpp:130
void enterBashSelectStatement(std::shared_ptr< AST::BashSelectStatement > node)
Definition BashForOrSelectStatement.cpp:68
std::shared_ptr< bpp::bpp_code_entity > latest_code_entity()
Definition BashppListener.cpp:92
std::shared_ptr< std::vector< std::string > > include_paths
A list of paths to search for included files.
Definition BashppListener.h:71
void exitBashArithmeticForStatement(std::shared_ptr< AST::BashArithmeticForStatement > node)
Definition BashArithmeticForStatement.cpp:20
void enterBashFunction(std::shared_ptr< AST::BashFunction > node)
Definition BashFunction.cpp:8
void enterRawText(std::shared_ptr< AST::RawText > node)
Definition RawText.cpp:8
void enterObjectReference(std::shared_ptr< AST::ObjectReference > node)
Definition ObjectReference.cpp:8
void set_suppress_warnings(bool suppress_warnings)
Definition BashppListener.cpp:52
void exitObjectInstantiation(std::shared_ptr< AST::ObjectInstantiation > node)
Definition ObjectInstantiation.cpp:85
void enterBashCasePatternHeader(std::shared_ptr< AST::BashCasePatternHeader > node)
Definition BashCaseStatement.cpp:116
void exitDestructorDefinition(std::shared_ptr< AST::DestructorDefinition > node)
Definition DestructorDefinition.cpp:36
void enterBashForStatement(std::shared_ptr< AST::BashForStatement > node)
Definition BashForOrSelectStatement.cpp:15
void exitBashRedirection(std::shared_ptr< AST::BashRedirection > node)
Definition BashRedirection.cpp:18
void enterArrayAssignment(std::shared_ptr< AST::ArrayAssignment > node)
Definition ArrayAssignment.cpp:8
void exitParameterExpansion(std::shared_ptr< AST::ParameterExpansion > node)
Definition ParameterExpansion.cpp:19
std::shared_ptr< bpp::bpp_class > primitive
Definition BashppListener.h:146
std::stack< std::monostate > typeof_stack
Definition BashppListener.h:120
void exitPrimitiveAssignment(std::shared_ptr< AST::PrimitiveAssignment > node)
Definition PrimitiveAssignment.cpp:20
void enterRawSubshell(std::shared_ptr< AST::RawSubshell > node)
Definition Subshell.cpp:60
void enterPrimitiveAssignment(std::shared_ptr< AST::PrimitiveAssignment > node)
Definition PrimitiveAssignment.cpp:8
void exitObjectAssignment(std::shared_ptr< AST::ObjectAssignment > node)
Definition ObjectAssignment.cpp:16
bool should_declare_local() const
Definition BashppListener.cpp:88
void enterPointerDeclaration(std::shared_ptr< AST::PointerDeclaration > node)
Definition PointerDeclaration.cpp:8
void enterSubshellSubstitution(std::shared_ptr< AST::SubshellSubstitution > node)
Definition Subshell.cpp:8
void enterNewStatement(std::shared_ptr< AST::NewStatement > node)
Definition NewStatement.cpp:8
std::shared_ptr< std::set< std::string > > get_included_files()
Definition BashppListener.cpp:72
bool lsp_mode
Definition BashppListener.h:148
std::shared_ptr< bpp::bpp_program > program
Definition BashppListener.h:109
void enterParameterExpansion(std::shared_ptr< AST::ParameterExpansion > node)
Definition ParameterExpansion.cpp:8
std::string source_file
Path to the source file being compiled (used for error reporting)
Definition BashppListener.h:63
void exitBashForStatement(std::shared_ptr< AST::BashForStatement > node)
Definition BashForOrSelectStatement.cpp:37
void enterMethodDefinition(std::shared_ptr< AST::MethodDefinition > node)
Definition MethodDefinition.cpp:8
void exitBashArithmeticForCondition(std::shared_ptr< AST::BashArithmeticForCondition > node)
Definition BashArithmeticForStatement.cpp:60
void exitBashCaseStatement(std::shared_ptr< AST::BashCaseStatement > node)
Definition BashCaseStatement.cpp:39
void enterSupershell(std::shared_ptr< AST::Supershell > node)
Definition Supershell.cpp:8
void exitBashUntilStatement(std::shared_ptr< AST::BashUntilStatement > node)
Definition BashWhileOrUntilStatement.cpp:84
std::shared_ptr< bpp::bpp_program > get_program()
Definition BashppListener.cpp:68
void enterConstructorDefinition(std::shared_ptr< AST::ConstructorDefinition > node)
Definition ConstructorDefinition.cpp:8
void exitDynamicCastTarget(std::shared_ptr< AST::DynamicCastTarget > node)
Definition DynamicCastTarget.cpp:26
void enterDatamemberDeclaration(std::shared_ptr< AST::DatamemberDeclaration > node)
Definition DatamemberDeclaration.cpp:8
void set_replacement_file_contents(const std::string &file_path, const std::string &contents)
Definition BashppListener.cpp:115
void exitBashIfRootBranch(std::shared_ptr< AST::BashIfRootBranch > node)
Definition BashIfStatement.cpp:135
void exitHereString(std::shared_ptr< AST::HereString > node)
Definition HereString.cpp:21
void enterHeredocBody(std::shared_ptr< AST::HeredocBody > node)
Definition HeredocBody.cpp:8
void enterBashRedirection(std::shared_ptr< AST::BashRedirection > node)
Definition BashRedirection.cpp:8
void exitProgram(std::shared_ptr< AST::Program > node)
Definition Program.cpp:39
ExpectationsStack context_expectations_stack
Definition BashppListener.h:122
void exitHeredocBody(std::shared_ptr< AST::HeredocBody > node)
Definition HeredocBody.cpp:21
void exitNewStatement(std::shared_ptr< AST::NewStatement > node)
Definition NewStatement.cpp:63
A stack to manage ContextExpectations during AST traversal.
Definition ContextExpectations.h:51
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.
Definition bpp_codegen.cpp:27
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.
Definition bpp_codegen.cpp:235
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.
Definition bpp_codegen.cpp:83
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.
Definition bpp_codegen.cpp:133
Represents a Bash version to target for code generation.
Definition BashVersion.h:20
A struct to hold (compiled) code segments.
Definition bpp_codegen.h:38