14#include <unordered_map>
78 std::shared_ptr<std::set<std::string>>
included_files = std::make_shared<std::set<std::string>>();
177 #define show_warning(token, msg) \
178 if (!suppress_warnings) { \
179 bpp::ErrorHandling::Warning _msg(this, token, msg); \
202 std::shared_ptr<bpp::bpp_program>
get_program()
const;
223 return std::dynamic_pointer_cast<T>(
entity_stack.top()) !=
nullptr;
227 void exitProgram(std::shared_ptr<AST::Program> node);
280 void enterBlock(std::shared_ptr<AST::Block> node);
281 void exitBlock(std::shared_ptr<AST::Block> node);
327 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:49
bool get_lsp_mode() const
Definition BashppListener.cpp:99
void enterDoublequotedString(std::shared_ptr< AST::DoublequotedString > node)
Definition DoublequotedString.cpp:13
void exitArrayAssignment(std::shared_ptr< AST::ArrayAssignment > node)
Definition ArrayAssignment.cpp:35
void exitBashFunction(std::shared_ptr< AST::BashFunction > node)
Definition BashFunction.cpp:54
bool in_class
Definition BashppListener.h:112
bool in_method
Definition BashppListener.h:110
void enterDestructorDefinition(std::shared_ptr< AST::DestructorDefinition > node)
Definition DestructorDefinition.cpp:13
void enterClassDefinition(std::shared_ptr< AST::ClassDefinition > node)
Definition ClassDefinition.cpp:12
void enterBashCasePattern(std::shared_ptr< AST::BashCasePattern > node)
Definition BashCaseStatement.cpp:61
void enterDynamicCastTarget(std::shared_ptr< AST::DynamicCastTarget > node)
Definition DynamicCastTarget.cpp:12
void exitBashTestConditionCommand(std::shared_ptr< AST::BashTestConditionCommand > node)
Definition BashTestConditionCommand.cpp:34
void exitBashIfElseBranch(std::shared_ptr< AST::BashIfElseBranch > node)
Definition BashIfStatement.cpp:185
void exitBashSelectStatement(std::shared_ptr< AST::BashSelectStatement > node)
Definition BashForOrSelectStatement.cpp:93
bool utf16_mode
Definition BashppListener.h:175
void enterBashInCondition(std::shared_ptr< AST::BashInCondition > node)
Definition BashForOrSelectStatement.cpp:122
void enterDeleteStatement(std::shared_ptr< AST::DeleteStatement > node)
Definition DeleteStatement.cpp:12
void exitDoublequotedString(std::shared_ptr< AST::DoublequotedString > node)
Definition DoublequotedString.cpp:34
void exitProcessSubstitution(std::shared_ptr< AST::ProcessSubstitution > node)
Definition ProcessSubstitution.cpp:32
bool run_on_exit
Definition BashppListener.h:94
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:85
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:172
void set_output_file(std::string output_file)
Definition BashppListener.cpp:55
void exitPointerDeclaration(std::shared_ptr< AST::PointerDeclaration > node)
Definition PointerDeclaration.cpp:89
void set_target_bash_version(BashVersion target_bash_version)
Definition BashppListener.cpp:67
void enterDynamicCast(std::shared_ptr< AST::DynamicCast > node)
Definition DynamicCast.cpp:11
void enterBashArithmeticSubstitution(std::shared_ptr< AST::BashArithmeticSubstitution > node)
Definition BashArithmeticSubstitution.cpp:11
void enterBashPipeline(std::shared_ptr< AST::BashPipeline > node)
Definition BashPipeline.cpp:11
void exitDynamicCast(std::shared_ptr< AST::DynamicCast > node)
Definition DynamicCast.cpp:42
void set_run_on_exit(bool run_on_exit)
Definition BashppListener.cpp:59
void exitBash53NativeSupershell(std::shared_ptr< AST::Bash53NativeSupershell > node)
Definition Bash53NativeSupershell.cpp:45
void exitBashPipeline(std::shared_ptr< AST::BashPipeline > node)
Definition BashPipeline.cpp:23
std::shared_ptr< std::ostream > code_buffer
Definition BashppListener.h:91
void exitConnective(std::shared_ptr< AST::Connective > node)
Definition Connective.cpp:19
bool topmost_entity_is() const
Helper function to check the type of the top of the entity stack.
Definition BashppListener.h:221
BashVersion target_bash_version
The target Bash version to compile for (default is 5.2)
Definition BashppListener.h:100
void enterBashTestConditionCommand(std::shared_ptr< AST::BashTestConditionCommand > node)
Definition BashTestConditionCommand.cpp:12
std::vector< char * > arguments
Command-line arguments to pass to the compiled program if run_on_exit is true.
Definition BashppListener.h:106
void enterBashCommandSequence(std::shared_ptr< AST::BashCommandSequence > node)
Definition BashCommandSequence.cpp:12
void enterHereString(std::shared_ptr< AST::HereString > node)
Definition HereString.cpp:11
void set_include_paths(std::shared_ptr< std::vector< std::string > > include_paths)
Definition BashppListener.cpp:19
void enterBashCaseStatement(std::shared_ptr< AST::BashCaseStatement > node)
Definition BashCaseStatement.cpp:19
void exitDeleteStatement(std::shared_ptr< AST::DeleteStatement > node)
Definition DeleteStatement.cpp:33
void enterObjectInstantiation(std::shared_ptr< AST::ObjectInstantiation > node)
Definition ObjectInstantiation.cpp:15
void enterIncludeStatement(std::shared_ptr< AST::IncludeStatement > node)
Handles.
Definition IncludeStatement.cpp:34
void exitBashCasePattern(std::shared_ptr< AST::BashCasePattern > node)
Definition BashCaseStatement.cpp:80
bool should_localize_object_instantiation() const
Whether an instantiated object should be made 'local' in the generated Bash code.
Definition BashppListener.cpp:115
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:43
void enterBashIfCondition(std::shared_ptr< AST::BashIfCondition > node)
Definition BashIfStatement.cpp:211
void exitConstructorDefinition(std::shared_ptr< AST::ConstructorDefinition > node)
Definition ConstructorDefinition.cpp:54
void exitBashVariable(std::shared_ptr< AST::BashVariable > node)
Definition BashVariable.cpp:23
void set_source_file(std::string source_file)
Definition BashppListener.cpp:15
void exitBashIfStatement(std::shared_ptr< AST::BashIfStatement > node)
Definition BashIfStatement.cpp:92
std::stack< std::monostate > supershell_stack
Definition BashppListener.h:113
void exitBashArithmeticSubstitution(std::shared_ptr< AST::BashArithmeticSubstitution > node)
Definition BashArithmeticSubstitution.cpp:36
void set_output_stream(std::shared_ptr< std::ostream > output_stream)
Definition BashppListener.cpp:51
void enterBash53NativeSupershell(std::shared_ptr< AST::Bash53NativeSupershell > node)
Definition Bash53NativeSupershell.cpp:12
void enterConnective(std::shared_ptr< AST::Connective > node)
Definition Connective.cpp:11
void set_utf16_mode(bool utf16_mode)
Definition BashppListener.cpp:79
void enterArrayIndex(std::shared_ptr< AST::ArrayIndex > node)
Definition ArrayIndex.cpp:12
void enterBashIfRootBranch(std::shared_ptr< AST::BashIfRootBranch > node)
Definition BashIfStatement.cpp:110
bool get_utf16_mode() const
Definition BashppListener.cpp:103
void enterBashArithmeticForCondition(std::shared_ptr< AST::BashArithmeticForCondition > node)
Definition BashArithmeticForStatement.cpp:50
void enterBashIfElseBranch(std::shared_ptr< AST::BashIfElseBranch > node)
Definition BashIfStatement.cpp:158
void exitRawText(std::shared_ptr< AST::RawText > node)
Definition RawText.cpp:23
void set_included(bool included)
Definition BashppListener.cpp:27
void exitBlock(std::shared_ptr< AST::Block > node)
Definition Block.cpp:57
std::shared_ptr< std::ostream > output_stream
Pointer to the output stream to write the compiled code to.
Definition BashppListener.h:92
void set_included_from(BashppListener *included_from)
Sets the included_from pointer to the given listener.
Definition BashppListener.cpp:34
std::string output_file
Definition BashppListener.h:93
void exitSupershell(std::shared_ptr< AST::Supershell > node)
Definition Supershell.cpp:42
void enterBashArithmeticForStatement(std::shared_ptr< AST::BashArithmeticForStatement > node)
Definition BashArithmeticForStatement.cpp:14
void exitBashCommandSequence(std::shared_ptr< AST::BashCommandSequence > node)
Definition BashCommandSequence.cpp:25
void exitClassDefinition(std::shared_ptr< AST::ClassDefinition > node)
Definition ClassDefinition.cpp:72
void exitObjectReference(std::shared_ptr< AST::ObjectReference > node)
Definition ObjectReference.cpp:51
void exitValueAssignment(std::shared_ptr< AST::ValueAssignment > node)
Definition ValueAssignment.cpp:47
void set_lsp_mode(bool lsp_mode)
Definition BashppListener.cpp:75
void enterValueAssignment(std::shared_ptr< AST::ValueAssignment > node)
Definition ValueAssignment.cpp:16
bool included
Definition BashppListener.h:64
void exitRawSubshell(std::shared_ptr< AST::RawSubshell > node)
Definition Subshell.cpp:130
void exitBashWhileOrUntilCondition(std::shared_ptr< AST::BashWhileOrUntilCondition > node)
Definition BashWhileOrUntilStatement.cpp:130
std::stack< std::monostate > bash_function_stack
Definition BashppListener.h:114
std::string get_source_file() const
Definition BashppListener.cpp:95
bool suppress_warnings
Definition BashppListener.h:72
void enterBashUntilStatement(std::shared_ptr< AST::BashUntilStatement > node)
Definition BashWhileOrUntilStatement.cpp:67
void set_arguments(std::vector< char * > arguments)
Definition BashppListener.cpp:71
void enterBashIfStatement(std::shared_ptr< AST::BashIfStatement > node)
Definition BashIfStatement.cpp:20
void enterBashVariable(std::shared_ptr< AST::BashVariable > node)
Definition BashVariable.cpp:11
void exitTypeofExpression(std::shared_ptr< AST::TypeofExpression > node)
Definition TypeofExpression.cpp:31
void enterBashWhileOrUntilCondition(std::shared_ptr< AST::BashWhileOrUntilCondition > node)
Definition BashWhileOrUntilStatement.cpp:117
void exitSubshellSubstitution(std::shared_ptr< AST::SubshellSubstitution > node)
Definition Subshell.cpp:45
std::stack< std::shared_ptr< bpp::bpp_entity > > entity_stack
A stack to keep track of the current entity being processed.
Definition BashppListener.h:163
void set_code_buffer(std::shared_ptr< std::ostream > code_buffer)
Definition BashppListener.cpp:47
std::shared_ptr< std::set< std::string > > included_files
A set of (unique) included files (used for '@include_once' directives)
Definition BashppListener.h:78
void enterProcessSubstitution(std::shared_ptr< AST::ProcessSubstitution > node)
Definition ProcessSubstitution.cpp:11
void enterProgram(std::shared_ptr< AST::Program > node)
Definition Program.cpp:15
void exitIncludeStatement(std::shared_ptr< AST::IncludeStatement > node)
Definition IncludeStatement.cpp:208
void exitMethodDefinition(std::shared_ptr< AST::MethodDefinition > node)
Definition MethodDefinition.cpp:133
void exitArrayIndex(std::shared_ptr< AST::ArrayIndex > node)
Definition ArrayIndex.cpp:35
void enterBashWhileStatement(std::shared_ptr< AST::BashWhileStatement > node)
Definition BashWhileOrUntilStatement.cpp:19
void enterTypeofExpression(std::shared_ptr< AST::TypeofExpression > node)
Definition TypeofExpression.cpp:11
void exitBashIfCondition(std::shared_ptr< AST::BashIfCondition > node)
Definition BashIfStatement.cpp:225
void enterBlock(std::shared_ptr< AST::Block > node)
Definition Block.cpp:15
std::stack< std::monostate > dynamic_cast_stack
Definition BashppListener.h:147
void enterObjectAssignment(std::shared_ptr< AST::ObjectAssignment > node)
Definition ObjectAssignment.cpp:14
void exitBashWhileStatement(std::shared_ptr< AST::BashWhileStatement > node)
Definition BashWhileOrUntilStatement.cpp:38
void exitBashInCondition(std::shared_ptr< AST::BashInCondition > node)
Definition BashForOrSelectStatement.cpp:132
void exitDatamemberDeclaration(std::shared_ptr< AST::DatamemberDeclaration > node)
Definition DatamemberDeclaration.cpp:68
BashppListener * included_from
Definition BashppListener.h:79
void exitBashCasePatternHeader(std::shared_ptr< AST::BashCasePatternHeader > node)
Definition BashCaseStatement.cpp:119
void enterBashSelectStatement(std::shared_ptr< AST::BashSelectStatement > node)
Definition BashForOrSelectStatement.cpp:71
std::shared_ptr< bpp::bpp_code_entity > latest_code_entity()
Definition BashppListener.cpp:119
std::shared_ptr< std::vector< std::string > > include_paths
A list of paths to search for included files.
Definition BashppListener.h:70
void exitBashArithmeticForStatement(std::shared_ptr< AST::BashArithmeticForStatement > node)
Definition BashArithmeticForStatement.cpp:26
void enterBashFunction(std::shared_ptr< AST::BashFunction > node)
Definition BashFunction.cpp:13
void enterRawText(std::shared_ptr< AST::RawText > node)
Definition RawText.cpp:11
void enterObjectReference(std::shared_ptr< AST::ObjectReference > node)
Definition ObjectReference.cpp:19
void set_suppress_warnings(bool suppress_warnings)
Definition BashppListener.cpp:63
void exitObjectInstantiation(std::shared_ptr< AST::ObjectInstantiation > node)
Definition ObjectInstantiation.cpp:93
void enterBashCasePatternHeader(std::shared_ptr< AST::BashCasePatternHeader > node)
Definition BashCaseStatement.cpp:108
void exitDestructorDefinition(std::shared_ptr< AST::DestructorDefinition > node)
Definition DestructorDefinition.cpp:41
void enterBashForStatement(std::shared_ptr< AST::BashForStatement > node)
Definition BashForOrSelectStatement.cpp:21
void exitBashRedirection(std::shared_ptr< AST::BashRedirection > node)
Definition BashRedirection.cpp:21
void enterArrayAssignment(std::shared_ptr< AST::ArrayAssignment > node)
Definition ArrayAssignment.cpp:13
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:56
std::stack< std::monostate > typeof_stack
Definition BashppListener.h:148
void exitPrimitiveAssignment(std::shared_ptr< AST::PrimitiveAssignment > node)
Definition PrimitiveAssignment.cpp:24
void enterRawSubshell(std::shared_ptr< AST::RawSubshell > node)
Definition Subshell.cpp:103
void enterPrimitiveAssignment(std::shared_ptr< AST::PrimitiveAssignment > node)
Definition PrimitiveAssignment.cpp:12
void exitObjectAssignment(std::shared_ptr< AST::ObjectAssignment > node)
Definition ObjectAssignment.cpp:22
bool should_declare_local() const
Whether the compiler should declare its temporary variables to be 'local' in the generated Bash code.
Definition BashppListener.cpp:111
int get_exit_code() const
Definition BashppListener.cpp:107
void enterPointerDeclaration(std::shared_ptr< AST::PointerDeclaration > node)
Definition PointerDeclaration.cpp:16
void enterSubshellSubstitution(std::shared_ptr< AST::SubshellSubstitution > node)
Definition Subshell.cpp:13
void enterNewStatement(std::shared_ptr< AST::NewStatement > node)
Definition NewStatement.cpp:13
std::shared_ptr< bpp::bpp_program > get_program() const
Definition BashppListener.cpp:83
BashppListener()
Definition BashppListener.cpp:11
bool lsp_mode
Definition BashppListener.h:174
std::shared_ptr< bpp::bpp_program > program
Definition BashppListener.h:108
std::shared_ptr< std::set< std::string > > get_included_files() const
Definition BashppListener.cpp:87
void enterParameterExpansion(std::shared_ptr< AST::ParameterExpansion > node)
Definition ParameterExpansion.cpp:11
std::string source_file
Path to the source file being compiled (used for error reporting)
Definition BashppListener.h:62
void exitBashForStatement(std::shared_ptr< AST::BashForStatement > node)
Definition BashForOrSelectStatement.cpp:43
void enterMethodDefinition(std::shared_ptr< AST::MethodDefinition > node)
Definition MethodDefinition.cpp:13
void exitBashArithmeticForCondition(std::shared_ptr< AST::BashArithmeticForCondition > node)
Definition BashArithmeticForStatement.cpp:60
void exitBashCaseStatement(std::shared_ptr< AST::BashCaseStatement > node)
Definition BashCaseStatement.cpp:43
void enterSupershell(std::shared_ptr< AST::Supershell > node)
Definition Supershell.cpp:14
void exitBashUntilStatement(std::shared_ptr< AST::BashUntilStatement > node)
Definition BashWhileOrUntilStatement.cpp:86
void enterConstructorDefinition(std::shared_ptr< AST::ConstructorDefinition > node)
Definition ConstructorDefinition.cpp:13
void exitDynamicCastTarget(std::shared_ptr< AST::DynamicCastTarget > node)
Definition DynamicCastTarget.cpp:28
void enterDatamemberDeclaration(std::shared_ptr< AST::DatamemberDeclaration > node)
Definition DatamemberDeclaration.cpp:12
void set_replacement_file_contents(const std::string &file_path, const std::string &contents)
Definition BashppListener.cpp:144
void exitBashIfRootBranch(std::shared_ptr< AST::BashIfRootBranch > node)
Definition BashIfStatement.cpp:131
const std::vector< std::string > & get_include_stack() const
Definition BashppListener.cpp:91
void exitHereString(std::shared_ptr< AST::HereString > node)
Definition HereString.cpp:24
void enterHeredocBody(std::shared_ptr< AST::HeredocBody > node)
Definition HeredocBody.cpp:12
void enterBashRedirection(std::shared_ptr< AST::BashRedirection > node)
Definition BashRedirection.cpp:11
void exitProgram(std::shared_ptr< AST::Program > node)
Definition Program.cpp:49
ExpectationsStack context_expectations_stack
Definition BashppListener.h:150
void exitHeredocBody(std::shared_ptr< AST::HeredocBody > node)
Definition HeredocBody.cpp:25
void exitNewStatement(std::shared_ptr< AST::NewStatement > node)
Definition NewStatement.cpp:68
A stack to manage ContextExpectations during AST traversal.
Definition ContextExpectations.h:52
Represents a Bash version to target for code generation.
Definition BashVersion.h:23