Bash++
Bash++ compiler internal documentation
BashppListener.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Andrew S. Rightenburg
3 * Bash++: Bash with classes
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7#pragma once
8
9#include <iostream>
10#include <vector>
11#include <set>
12#include <memory>
13#include <stack>
14#include <unordered_map>
15
17
18class BashppListener;
19
21#include <bpp_include/bpp.h>
22#include <include/BashVersion.h>
24
25#include <error/detail.h>
26#include <error/SyntaxError.h>
27#include <error/InternalError.h>
28
49class BashppListener : public AST::BaseListener<BashppListener>, std::enable_shared_from_this<BashppListener> {
50 private:
56 int exit_code = 0;
57
62 std::string source_file;
63
64 bool included = false;
65
70 std::shared_ptr<std::vector<std::string>> include_paths = nullptr;
71
72 bool suppress_warnings = false;
73
78 std::shared_ptr<std::set<std::string>> included_files = std::make_shared<std::set<std::string>>();
80
85 std::vector<std::string> include_stack;
86
91 std::shared_ptr<std::ostream> code_buffer;
92 std::shared_ptr<std::ostream> output_stream;
93 std::string output_file;
94 bool run_on_exit = false;
95
101
106 std::vector<char*> arguments;
107
108 std::shared_ptr<bpp::bpp_program> program;
109
110 bool in_method = false;
111
112 bool in_class = false;
113 std::stack<std::monostate> supershell_stack;
114 std::stack<std::monostate> bash_function_stack;
115
124 bool should_declare_local() const;
125
145
146 // Diagnostic information (not used for compilation):
147 std::stack<std::monostate> dynamic_cast_stack; // Used to track whether we're inside a dynamic_cast statement
148 std::stack<std::monostate> typeof_stack; // Used to track whether we're inside a typeof expression
149
151
163 std::stack<std::shared_ptr<bpp::bpp_entity>> entity_stack;
164
172 std::unordered_map<std::string, std::string> replacement_file_contents;
173
174 bool lsp_mode = false; // Whether this listener is just running as part of the language server (i.e., not really compiling anything)
175 bool utf16_mode = false; // If we're in a language server, whether the client has demanded UTF-16 position encoding
176
177 #define show_warning(token, msg) \
178 if (!suppress_warnings) { \
179 bpp::ErrorHandling::Warning _msg(this, token, msg); \
180 _msg.print(); \
181 }
182
183 public:
185 void set_source_file(std::string source_file);
186 void set_include_paths(std::shared_ptr<std::vector<std::string>> include_paths);
187 void set_included(bool included);
189 void set_included_files(std::shared_ptr<std::set<std::string>> included_files);
190 void set_code_buffer(std::shared_ptr<std::ostream> code_buffer);
191 void set_output_stream(std::shared_ptr<std::ostream> output_stream);
192 void set_output_file(std::string output_file);
193 void set_run_on_exit(bool run_on_exit);
196 void set_arguments(std::vector<char*> arguments);
197 void set_lsp_mode(bool lsp_mode);
198 void set_utf16_mode(bool utf16_mode);
199
200 void set_replacement_file_contents(const std::string& file_path, const std::string& contents);
201
202 std::shared_ptr<bpp::bpp_program> get_program() const;
203 std::shared_ptr<std::set<std::string>> get_included_files() const;
204 const std::vector<std::string>& get_include_stack() const;
205 std::string get_source_file() const;
206 bool get_lsp_mode() const;
207 bool get_utf16_mode() const;
208
209 int get_exit_code() const;
210
211 std::shared_ptr<bpp::bpp_code_entity> latest_code_entity();
212
220 template <class T>
221 bool topmost_entity_is() const {
222 if (entity_stack.empty()) return false;
223 return std::dynamic_pointer_cast<T>(entity_stack.top()) != nullptr;
224 }
225
226 void enterProgram(std::shared_ptr<AST::Program> node);
227 void exitProgram(std::shared_ptr<AST::Program> node);
228 void enterArrayAssignment(std::shared_ptr<AST::ArrayAssignment> node);
229 void exitArrayAssignment(std::shared_ptr<AST::ArrayAssignment> node);
230 void enterArrayIndex(std::shared_ptr<AST::ArrayIndex> node);
231 void exitArrayIndex(std::shared_ptr<AST::ArrayIndex> node);
232 void enterBash53NativeSupershell(std::shared_ptr<AST::Bash53NativeSupershell> node);
233 void exitBash53NativeSupershell(std::shared_ptr<AST::Bash53NativeSupershell> node);
234 void enterBashArithmeticForCondition(std::shared_ptr<AST::BashArithmeticForCondition> node);
235 void exitBashArithmeticForCondition(std::shared_ptr<AST::BashArithmeticForCondition> node);
236 void enterBashArithmeticForStatement(std::shared_ptr<AST::BashArithmeticForStatement> node);
237 void exitBashArithmeticForStatement(std::shared_ptr<AST::BashArithmeticForStatement> node);
238 void enterBashArithmeticSubstitution(std::shared_ptr<AST::BashArithmeticSubstitution> node);
239 void exitBashArithmeticSubstitution(std::shared_ptr<AST::BashArithmeticSubstitution> node);
240 void enterBashCasePattern(std::shared_ptr<AST::BashCasePattern> node);
241 void exitBashCasePattern(std::shared_ptr<AST::BashCasePattern> node);
242 void enterBashCasePatternHeader(std::shared_ptr<AST::BashCasePatternHeader> node);
243 void exitBashCasePatternHeader(std::shared_ptr<AST::BashCasePatternHeader> node);
244 void enterBashCaseStatement(std::shared_ptr<AST::BashCaseStatement> node);
245 void exitBashCaseStatement(std::shared_ptr<AST::BashCaseStatement> node);
246 //void enterBashCommand(std::shared_ptr<AST::BashCommand> node);
247 //void exitBashCommand(std::shared_ptr<AST::BashCommand> node);
248 void enterBashCommandSequence(std::shared_ptr<AST::BashCommandSequence> node);
249 void exitBashCommandSequence(std::shared_ptr<AST::BashCommandSequence> node);
250 void enterBashForStatement(std::shared_ptr<AST::BashForStatement> node);
251 void exitBashForStatement(std::shared_ptr<AST::BashForStatement> node);
252 void enterBashIfCondition(std::shared_ptr<AST::BashIfCondition> node);
253 void exitBashIfCondition(std::shared_ptr<AST::BashIfCondition> node);
254 void enterBashIfElseBranch(std::shared_ptr<AST::BashIfElseBranch> node);
255 void exitBashIfElseBranch(std::shared_ptr<AST::BashIfElseBranch> node);
256 void enterBashIfRootBranch(std::shared_ptr<AST::BashIfRootBranch> node);
257 void exitBashIfRootBranch(std::shared_ptr<AST::BashIfRootBranch> node);
258 void enterBashIfStatement(std::shared_ptr<AST::BashIfStatement> node);
259 void exitBashIfStatement(std::shared_ptr<AST::BashIfStatement> node);
260 void enterBashInCondition(std::shared_ptr<AST::BashInCondition> node);
261 void exitBashInCondition(std::shared_ptr<AST::BashInCondition> node);
262 void enterBashPipeline(std::shared_ptr<AST::BashPipeline> node);
263 void exitBashPipeline(std::shared_ptr<AST::BashPipeline> node);
264 void enterBashRedirection(std::shared_ptr<AST::BashRedirection> node);
265 void exitBashRedirection(std::shared_ptr<AST::BashRedirection> node);
266 void enterBashSelectStatement(std::shared_ptr<AST::BashSelectStatement> node);
267 void exitBashSelectStatement(std::shared_ptr<AST::BashSelectStatement> node);
268 void enterBashTestConditionCommand(std::shared_ptr<AST::BashTestConditionCommand> node);
269 void exitBashTestConditionCommand(std::shared_ptr<AST::BashTestConditionCommand> node);
270 void enterBashUntilStatement(std::shared_ptr<AST::BashUntilStatement> node);
271 void exitBashUntilStatement(std::shared_ptr<AST::BashUntilStatement> node);
272 void enterBashVariable(std::shared_ptr<AST::BashVariable> node);
273 void exitBashVariable(std::shared_ptr<AST::BashVariable> node);
274 void enterBashWhileOrUntilCondition(std::shared_ptr<AST::BashWhileOrUntilCondition> node);
275 void exitBashWhileOrUntilCondition(std::shared_ptr<AST::BashWhileOrUntilCondition> node);
276 void enterBashWhileStatement(std::shared_ptr<AST::BashWhileStatement> node);
277 void exitBashWhileStatement(std::shared_ptr<AST::BashWhileStatement> node);
278 void enterBashFunction(std::shared_ptr<AST::BashFunction> node);
279 void exitBashFunction(std::shared_ptr<AST::BashFunction> node);
280 void enterBlock(std::shared_ptr<AST::Block> node);
281 void exitBlock(std::shared_ptr<AST::Block> node);
282 void enterClassDefinition(std::shared_ptr<AST::ClassDefinition> node);
283 void exitClassDefinition(std::shared_ptr<AST::ClassDefinition> node);
284 void enterConnective(std::shared_ptr<AST::Connective> node);
285 void exitConnective(std::shared_ptr<AST::Connective> node);
286 void enterConstructorDefinition(std::shared_ptr<AST::ConstructorDefinition> node);
287 void exitConstructorDefinition(std::shared_ptr<AST::ConstructorDefinition> node);
288 void enterDatamemberDeclaration(std::shared_ptr<AST::DatamemberDeclaration> node);
289 void exitDatamemberDeclaration(std::shared_ptr<AST::DatamemberDeclaration> node);
290 void enterDeleteStatement(std::shared_ptr<AST::DeleteStatement> node);
291 void exitDeleteStatement(std::shared_ptr<AST::DeleteStatement> node);
292 void enterDestructorDefinition(std::shared_ptr<AST::DestructorDefinition> node);
293 void exitDestructorDefinition(std::shared_ptr<AST::DestructorDefinition> node);
294 void enterDoublequotedString(std::shared_ptr<AST::DoublequotedString> node);
295 void exitDoublequotedString(std::shared_ptr<AST::DoublequotedString> node);
296 void enterDynamicCast(std::shared_ptr<AST::DynamicCast> node);
297 void exitDynamicCast(std::shared_ptr<AST::DynamicCast> node);
298 void enterDynamicCastTarget(std::shared_ptr<AST::DynamicCastTarget> node);
299 void exitDynamicCastTarget(std::shared_ptr<AST::DynamicCastTarget> node);
300 void enterHeredocBody(std::shared_ptr<AST::HeredocBody> node);
301 void exitHeredocBody(std::shared_ptr<AST::HeredocBody> node);
302 void enterHereString(std::shared_ptr<AST::HereString> node);
303 void exitHereString(std::shared_ptr<AST::HereString> node);
304 void enterIncludeStatement(std::shared_ptr<AST::IncludeStatement> node);
305 void exitIncludeStatement(std::shared_ptr<AST::IncludeStatement> node);
306 void enterMethodDefinition(std::shared_ptr<AST::MethodDefinition> node);
307 void exitMethodDefinition(std::shared_ptr<AST::MethodDefinition> node);
308 void enterNewStatement(std::shared_ptr<AST::NewStatement> node);
309 void exitNewStatement(std::shared_ptr<AST::NewStatement> node);
310 void enterObjectAssignment(std::shared_ptr<AST::ObjectAssignment> node);
311 void exitObjectAssignment(std::shared_ptr<AST::ObjectAssignment> node);
312 void enterObjectInstantiation(std::shared_ptr<AST::ObjectInstantiation> node);
313 void exitObjectInstantiation(std::shared_ptr<AST::ObjectInstantiation> node);
314 void enterObjectReference(std::shared_ptr<AST::ObjectReference> node);
315 void exitObjectReference(std::shared_ptr<AST::ObjectReference> node);
316 void enterParameterExpansion(std::shared_ptr<AST::ParameterExpansion> node);
317 void exitParameterExpansion(std::shared_ptr<AST::ParameterExpansion> node);
318 void enterPointerDeclaration(std::shared_ptr<AST::PointerDeclaration> node);
319 void exitPointerDeclaration(std::shared_ptr<AST::PointerDeclaration> node);
320 void enterPrimitiveAssignment(std::shared_ptr<AST::PrimitiveAssignment> node);
321 void exitPrimitiveAssignment(std::shared_ptr<AST::PrimitiveAssignment> node);
322 void enterProcessSubstitution(std::shared_ptr<AST::ProcessSubstitution> node);
323 void exitProcessSubstitution(std::shared_ptr<AST::ProcessSubstitution> node);
324 void enterRawSubshell(std::shared_ptr<AST::RawSubshell> node);
325 void exitRawSubshell(std::shared_ptr<AST::RawSubshell> node);
326 void enterRawText(std::shared_ptr<AST::RawText> node);
327 void exitRawText(std::shared_ptr<AST::RawText> node);
328 //void enterRvalue(std::shared_ptr<AST::Rvalue> node);
329 //void exitRvalue(std::shared_ptr<AST::Rvalue> node);
330 void enterSubshellSubstitution(std::shared_ptr<AST::SubshellSubstitution> node);
331 void exitSubshellSubstitution(std::shared_ptr<AST::SubshellSubstitution> node);
332 void enterSupershell(std::shared_ptr<AST::Supershell> node);
333 void exitSupershell(std::shared_ptr<AST::Supershell> node);
334 void enterTypeofExpression(std::shared_ptr<AST::TypeofExpression> node);
335 void exitTypeofExpression(std::shared_ptr<AST::TypeofExpression> node);
336 void enterValueAssignment(std::shared_ptr<AST::ValueAssignment> node);
337 void exitValueAssignment(std::shared_ptr<AST::ValueAssignment> node);
338};
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