14#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>();
178 #define show_warning(token, msg) \
179 if (!suppress_warnings) { \
180 bpp::ErrorHandling::Warning _msg(this, token, msg); \
202 std::shared_ptr<bpp::bpp_program>
get_program()
const;
214 void exitProgram(std::shared_ptr<AST::Program> node);
267 void enterBlock(std::shared_ptr<AST::Block> node);
268 void exitBlock(std::shared_ptr<AST::Block> node);
314 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:111
The main listener class for the Bash++ compiler.
Definition BashppListener.h:50
bool get_lsp_mode() const
Definition BashppListener.cpp:93
void enterDoublequotedString(std::shared_ptr< AST::DoublequotedString > node)
Definition DoublequotedString.cpp:9
void exitArrayAssignment(std::shared_ptr< AST::ArrayAssignment > node)
Definition ArrayAssignment.cpp:31
void exitBashFunction(std::shared_ptr< AST::BashFunction > node)
Definition BashFunction.cpp:50
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:9
void enterClassDefinition(std::shared_ptr< AST::ClassDefinition > node)
Definition ClassDefinition.cpp:9
void enterBashCasePattern(std::shared_ptr< AST::BashCasePattern > node)
Definition BashCaseStatement.cpp:64
void enterDynamicCastTarget(std::shared_ptr< AST::DynamicCastTarget > node)
Definition DynamicCastTarget.cpp:9
void exitBashTestConditionCommand(std::shared_ptr< AST::BashTestConditionCommand > node)
Definition BashTestConditionCommand.cpp:31
void exitBashIfElseBranch(std::shared_ptr< AST::BashIfElseBranch > node)
Definition BashIfStatement.cpp:196
void exitBashSelectStatement(std::shared_ptr< AST::BashSelectStatement > node)
Definition BashForOrSelectStatement.cpp:92
bool utf16_mode
Definition BashppListener.h:176
void enterBashInCondition(std::shared_ptr< AST::BashInCondition > node)
Definition BashForOrSelectStatement.cpp:125
void enterDeleteStatement(std::shared_ptr< AST::DeleteStatement > node)
Definition DeleteStatement.cpp:9
void exitDoublequotedString(std::shared_ptr< AST::DoublequotedString > node)
Definition DoublequotedString.cpp:30
void exitProcessSubstitution(std::shared_ptr< AST::ProcessSubstitution > node)
Definition ProcessSubstitution.cpp:30
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:173
void set_output_file(std::string output_file)
Definition BashppListener.cpp:49
void exitPointerDeclaration(std::shared_ptr< AST::PointerDeclaration > node)
Definition PointerDeclaration.cpp:82
void set_target_bash_version(BashVersion target_bash_version)
Definition BashppListener.cpp:61
void enterDynamicCast(std::shared_ptr< AST::DynamicCast > node)
Definition DynamicCast.cpp:9
void enterBashArithmeticSubstitution(std::shared_ptr< AST::BashArithmeticSubstitution > node)
Definition BashArithmeticSubstitution.cpp:9
void enterBashPipeline(std::shared_ptr< AST::BashPipeline > node)
Definition BashPipeline.cpp:9
void exitDynamicCast(std::shared_ptr< AST::DynamicCast > node)
Definition DynamicCast.cpp:40
void set_run_on_exit(bool run_on_exit)
Definition BashppListener.cpp:53
void exitBash53NativeSupershell(std::shared_ptr< AST::Bash53NativeSupershell > node)
Definition Bash53NativeSupershell.cpp:42
void exitBashPipeline(std::shared_ptr< AST::BashPipeline > node)
Definition BashPipeline.cpp:21
std::shared_ptr< std::ostream > code_buffer
Definition BashppListener.h:92
void exitConnective(std::shared_ptr< AST::Connective > node)
Definition Connective.cpp:19
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:9
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:9
void enterHereString(std::shared_ptr< AST::HereString > node)
Definition HereString.cpp:9
void set_include_paths(std::shared_ptr< std::vector< std::string > > include_paths)
Definition BashppListener.cpp:13
void enterBashCaseStatement(std::shared_ptr< AST::BashCaseStatement > node)
Definition BashCaseStatement.cpp:16
void exitDeleteStatement(std::shared_ptr< AST::DeleteStatement > node)
Definition DeleteStatement.cpp:30
void enterObjectInstantiation(std::shared_ptr< AST::ObjectInstantiation > node)
Definition ObjectInstantiation.cpp:9
void enterIncludeStatement(std::shared_ptr< AST::IncludeStatement > node)
Handles.
Definition IncludeStatement.cpp:31
void exitBashCasePattern(std::shared_ptr< AST::BashCasePattern > node)
Definition BashCaseStatement.cpp:86
bool should_localize_object_instantiation() const
Whether an instantiated object should be made 'local' in the generated Bash code.
Definition BashppListener.cpp:109
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:37
void enterBashIfCondition(std::shared_ptr< AST::BashIfCondition > node)
Definition BashIfStatement.cpp:226
void exitConstructorDefinition(std::shared_ptr< AST::ConstructorDefinition > node)
Definition ConstructorDefinition.cpp:52
void exitBashVariable(std::shared_ptr< AST::BashVariable > node)
Definition BashVariable.cpp:21
void set_source_file(std::string source_file)
Definition BashppListener.cpp:9
void exitBashIfStatement(std::shared_ptr< AST::BashIfStatement > node)
Definition BashIfStatement.cpp:89
std::stack< std::monostate > supershell_stack
Definition BashppListener.h:114
void exitBashArithmeticSubstitution(std::shared_ptr< AST::BashArithmeticSubstitution > node)
Definition BashArithmeticSubstitution.cpp:34
void set_output_stream(std::shared_ptr< std::ostream > output_stream)
Definition BashppListener.cpp:45
void enterBash53NativeSupershell(std::shared_ptr< AST::Bash53NativeSupershell > node)
Definition Bash53NativeSupershell.cpp:9
void enterConnective(std::shared_ptr< AST::Connective > node)
Definition Connective.cpp:9
void set_utf16_mode(bool utf16_mode)
Definition BashppListener.cpp:73
void enterArrayIndex(std::shared_ptr< AST::ArrayIndex > node)
Definition ArrayIndex.cpp:9
void enterBashIfRootBranch(std::shared_ptr< AST::BashIfRootBranch > node)
Definition BashIfStatement.cpp:113
bool get_utf16_mode() const
Definition BashppListener.cpp:97
void enterBashArithmeticForCondition(std::shared_ptr< AST::BashArithmeticForCondition > node)
Definition BashArithmeticForStatement.cpp:49
void enterBashIfElseBranch(std::shared_ptr< AST::BashIfElseBranch > node)
Definition BashIfStatement.cpp:167
void exitRawText(std::shared_ptr< AST::RawText > node)
Definition RawText.cpp:21
void set_included(bool included)
Definition BashppListener.cpp:21
void exitBlock(std::shared_ptr< AST::Block > node)
Definition Block.cpp:51
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:28
std::string output_file
Definition BashppListener.h:94
void exitSupershell(std::shared_ptr< AST::Supershell > node)
Definition Supershell.cpp:37
void enterBashArithmeticForStatement(std::shared_ptr< AST::BashArithmeticForStatement > node)
Definition BashArithmeticForStatement.cpp:9
void exitBashCommandSequence(std::shared_ptr< AST::BashCommandSequence > node)
Definition BashCommandSequence.cpp:22
void exitClassDefinition(std::shared_ptr< AST::ClassDefinition > node)
Definition ClassDefinition.cpp:69
void exitObjectReference(std::shared_ptr< AST::ObjectReference > node)
Definition ObjectReference.cpp:41
void exitValueAssignment(std::shared_ptr< AST::ValueAssignment > node)
Definition ValueAssignment.cpp:40
void set_lsp_mode(bool lsp_mode)
Definition BashppListener.cpp:69
void enterValueAssignment(std::shared_ptr< AST::ValueAssignment > node)
Definition ValueAssignment.cpp:9
bool included
Definition BashppListener.h:65
void exitRawSubshell(std::shared_ptr< AST::RawSubshell > node)
Definition Subshell.cpp:129
void exitBashWhileOrUntilCondition(std::shared_ptr< AST::BashWhileOrUntilCondition > node)
Definition BashWhileOrUntilStatement.cpp:138
std::stack< std::monostate > bash_function_stack
Definition BashppListener.h:115
std::string get_source_file() const
Definition BashppListener.cpp:89
bool suppress_warnings
Definition BashppListener.h:73
void enterBashUntilStatement(std::shared_ptr< AST::BashUntilStatement > node)
Definition BashWhileOrUntilStatement.cpp:69
void set_arguments(std::vector< char * > arguments)
Definition BashppListener.cpp:65
void enterBashIfStatement(std::shared_ptr< AST::BashIfStatement > node)
Definition BashIfStatement.cpp:17
void enterBashVariable(std::shared_ptr< AST::BashVariable > node)
Definition BashVariable.cpp:9
void exitTypeofExpression(std::shared_ptr< AST::TypeofExpression > node)
Definition TypeofExpression.cpp:29
void enterBashWhileOrUntilCondition(std::shared_ptr< AST::BashWhileOrUntilCondition > node)
Definition BashWhileOrUntilStatement.cpp:123
void exitSubshellSubstitution(std::shared_ptr< AST::SubshellSubstitution > node)
Definition Subshell.cpp:41
std::stack< std::shared_ptr< bpp::bpp_entity > > entity_stack
A stack to keep track of the current entity being processed.
Definition BashppListener.h:164
void set_code_buffer(std::shared_ptr< std::ostream > code_buffer)
Definition BashppListener.cpp:41
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:9
void enterProgram(std::shared_ptr< AST::Program > node)
Definition Program.cpp:13
void exitIncludeStatement(std::shared_ptr< AST::IncludeStatement > node)
Definition IncludeStatement.cpp:192
void exitMethodDefinition(std::shared_ptr< AST::MethodDefinition > node)
Definition MethodDefinition.cpp:129
void exitArrayIndex(std::shared_ptr< AST::ArrayIndex > node)
Definition ArrayIndex.cpp:34
void enterBashWhileStatement(std::shared_ptr< AST::BashWhileStatement > node)
Definition BashWhileOrUntilStatement.cpp:17
void enterTypeofExpression(std::shared_ptr< AST::TypeofExpression > node)
Definition TypeofExpression.cpp:9
void exitBashIfCondition(std::shared_ptr< AST::BashIfCondition > node)
Definition BashIfStatement.cpp:242
void enterBlock(std::shared_ptr< AST::Block > node)
Definition Block.cpp:9
std::stack< std::monostate > dynamic_cast_stack
Definition BashppListener.h:148
void enterObjectAssignment(std::shared_ptr< AST::ObjectAssignment > node)
Definition ObjectAssignment.cpp:9
void exitBashWhileStatement(std::shared_ptr< AST::BashWhileStatement > node)
Definition BashWhileOrUntilStatement.cpp:36
void exitBashInCondition(std::shared_ptr< AST::BashInCondition > node)
Definition BashForOrSelectStatement.cpp:137
void exitDatamemberDeclaration(std::shared_ptr< AST::DatamemberDeclaration > node)
Definition DatamemberDeclaration.cpp:67
BashppListener * included_from
Definition BashppListener.h:80
void exitBashCasePatternHeader(std::shared_ptr< AST::BashCasePatternHeader > node)
Definition BashCaseStatement.cpp:134
void enterBashSelectStatement(std::shared_ptr< AST::BashSelectStatement > node)
Definition BashForOrSelectStatement.cpp:70
std::shared_ptr< bpp::bpp_code_entity > latest_code_entity()
Definition BashppListener.cpp:113
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:21
void enterBashFunction(std::shared_ptr< AST::BashFunction > node)
Definition BashFunction.cpp:9
void enterRawText(std::shared_ptr< AST::RawText > node)
Definition RawText.cpp:9
void enterObjectReference(std::shared_ptr< AST::ObjectReference > node)
Definition ObjectReference.cpp:9
void set_suppress_warnings(bool suppress_warnings)
Definition BashppListener.cpp:57
void exitObjectInstantiation(std::shared_ptr< AST::ObjectInstantiation > node)
Definition ObjectInstantiation.cpp:87
void enterBashCasePatternHeader(std::shared_ptr< AST::BashCasePatternHeader > node)
Definition BashCaseStatement.cpp:120
void exitDestructorDefinition(std::shared_ptr< AST::DestructorDefinition > node)
Definition DestructorDefinition.cpp:37
void enterBashForStatement(std::shared_ptr< AST::BashForStatement > node)
Definition BashForOrSelectStatement.cpp:16
void exitBashRedirection(std::shared_ptr< AST::BashRedirection > node)
Definition BashRedirection.cpp:19
void enterArrayAssignment(std::shared_ptr< AST::ArrayAssignment > node)
Definition ArrayAssignment.cpp:9
void exitParameterExpansion(std::shared_ptr< AST::ParameterExpansion > node)
Definition ParameterExpansion.cpp:20
int exit_code
The exit code to return when the compiler finishes (default is 0, which means success)
Definition BashppListener.h:57
std::stack< std::monostate > typeof_stack
Definition BashppListener.h:149
void exitPrimitiveAssignment(std::shared_ptr< AST::PrimitiveAssignment > node)
Definition PrimitiveAssignment.cpp:21
void enterRawSubshell(std::shared_ptr< AST::RawSubshell > node)
Definition Subshell.cpp:102
void enterPrimitiveAssignment(std::shared_ptr< AST::PrimitiveAssignment > node)
Definition PrimitiveAssignment.cpp:9
void exitObjectAssignment(std::shared_ptr< AST::ObjectAssignment > node)
Definition ObjectAssignment.cpp:17
bool should_declare_local() const
Whether the compiler should declare its temporary variables to be 'local' in the generated Bash code.
Definition BashppListener.cpp:105
int get_exit_code() const
Definition BashppListener.cpp:101
void enterPointerDeclaration(std::shared_ptr< AST::PointerDeclaration > node)
Definition PointerDeclaration.cpp:9
void enterSubshellSubstitution(std::shared_ptr< AST::SubshellSubstitution > node)
Definition Subshell.cpp:9
void enterNewStatement(std::shared_ptr< AST::NewStatement > node)
Definition NewStatement.cpp:9
std::shared_ptr< bpp::bpp_program > get_program() const
Definition BashppListener.cpp:77
bool lsp_mode
Definition BashppListener.h:175
std::shared_ptr< bpp::bpp_program > program
Definition BashppListener.h:109
std::shared_ptr< std::set< std::string > > get_included_files() const
Definition BashppListener.cpp:81
void enterParameterExpansion(std::shared_ptr< AST::ParameterExpansion > node)
Definition ParameterExpansion.cpp:9
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:38
void enterMethodDefinition(std::shared_ptr< AST::MethodDefinition > node)
Definition MethodDefinition.cpp:9
void exitBashArithmeticForCondition(std::shared_ptr< AST::BashArithmeticForCondition > node)
Definition BashArithmeticForStatement.cpp:61
void exitBashCaseStatement(std::shared_ptr< AST::BashCaseStatement > node)
Definition BashCaseStatement.cpp:40
void enterSupershell(std::shared_ptr< AST::Supershell > node)
Definition Supershell.cpp:9
void exitBashUntilStatement(std::shared_ptr< AST::BashUntilStatement > node)
Definition BashWhileOrUntilStatement.cpp:88
void enterConstructorDefinition(std::shared_ptr< AST::ConstructorDefinition > node)
Definition ConstructorDefinition.cpp:9
void exitDynamicCastTarget(std::shared_ptr< AST::DynamicCastTarget > node)
Definition DynamicCastTarget.cpp:27
void enterDatamemberDeclaration(std::shared_ptr< AST::DatamemberDeclaration > node)
Definition DatamemberDeclaration.cpp:9
void set_replacement_file_contents(const std::string &file_path, const std::string &contents)
Definition BashppListener.cpp:136
void exitBashIfRootBranch(std::shared_ptr< AST::BashIfRootBranch > node)
Definition BashIfStatement.cpp:136
const std::vector< std::string > & get_include_stack() const
Definition BashppListener.cpp:85
void exitHereString(std::shared_ptr< AST::HereString > node)
Definition HereString.cpp:22
void enterHeredocBody(std::shared_ptr< AST::HeredocBody > node)
Definition HeredocBody.cpp:9
void enterBashRedirection(std::shared_ptr< AST::BashRedirection > node)
Definition BashRedirection.cpp:9
void exitProgram(std::shared_ptr< AST::Program > node)
Definition Program.cpp:47
ExpectationsStack context_expectations_stack
Definition BashppListener.h:151
void exitHeredocBody(std::shared_ptr< AST::HeredocBody > node)
Definition HeredocBody.cpp:22
void exitNewStatement(std::shared_ptr< AST::NewStatement > node)
Definition NewStatement.cpp:64
A stack to manage ContextExpectations during AST traversal.
Definition ContextExpectations.h:52
Represents a Bash version to target for code generation.
Definition BashVersion.h:22