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

Represents the parsed command-line arguments given to the compiler. More...

#include <parse_arguments.h>

Collaboration diagram for Arguments:
Collaboration graph
[legend]

Public Member Functions

constexpr Arguments ()
 
 ~Arguments ()=default
 
 Arguments (const Arguments &)=delete
 
Argumentsoperator= (const Arguments &)=delete
 
 Arguments (Arguments &&)=default
 
Argumentsoperator= (Arguments &&)=default
 
void set_program_arguments (int argc, char **argv)
 Sets the program arguments to be passed to the compiled program.
 
const std::vector< char * > & program_arguments () const
 
void set_input_file (const std::string_view &input_file)
 Sets the input file for the compiler.
 
const std::optional< std::string > & input_file () const
 
void set_output_file (const std::string_view &output_file_arg)
 Parses a given output_file argument and updates the Arguments object accordingly.
 
const std::optional< std::string > & output_file () const
 
void set_target_bash_version (const std::string_view &version_arg)
 Parses a given target Bash version argument and updates the Arguments object accordingly.
 
const BashVersiontarget_bash_version () const
 
void add_include_path (const std::string_view &path)
 Adds a directory to the include paths.
 
const std::shared_ptr< std::vector< std::string > > & include_paths () const
 
void set_suppress_warnings (bool suppress)
 
bool suppress_warnings () const
 
void set_display_tokens (bool display)
 
bool display_tokens () const
 
void set_display_parse_tree (bool display)
 
bool display_parse_tree () const
 
void set_exit_early (bool exit)
 
bool exit_early () const
 

Private Attributes

std::vector< char * > m_program_arguments
 
std::optional< std::string > m_input_file
 
std::optional< std::string > m_output_file
 
BashVersion m_target_bash_version = {5, 2}
 
std::shared_ptr< std::vector< std::string > > m_include_paths = std::make_shared<std::vector<std::string>>()
 
bool f_suppress_warnings = false
 
bool f_display_tokens = false
 
bool f_display_parse_tree = false
 
bool f_exit_early = false
 

Detailed Description

Represents the parsed command-line arguments given to the compiler.

This struct holds the parsed command-line arguments for the Bash++ compiler. It includes options for input/output files, target Bash version, include paths, warning suppression, and flags for displaying tokens or parse trees.

Constructor & Destructor Documentation

◆ Arguments() [1/3]

constexpr Arguments::Arguments ( )
inlineconstexpr

◆ ~Arguments()

Arguments::~Arguments ( )
default

◆ Arguments() [2/3]

Arguments::Arguments ( const Arguments )
delete

◆ Arguments() [3/3]

Arguments::Arguments ( Arguments &&  )
default

Member Function Documentation

◆ add_include_path()

void Arguments::add_include_path ( const std::string_view &  path)
inline

Adds a directory to the include paths.

The include paths are directories that the compiler will search for included files. The first include path is always /usr/lib/bpp/stdlib/, which contains the standard library for Bash++. Additional include paths are searched in the order they are given

Parameters
pathThe directory path to add to the include paths
Exceptions
std::runtime_errorif the provided path is not a directory

◆ display_parse_tree()

bool Arguments::display_parse_tree ( ) const
inline

◆ display_tokens()

bool Arguments::display_tokens ( ) const
inline

◆ exit_early()

bool Arguments::exit_early ( ) const
inline

◆ include_paths()

const std::shared_ptr< std::vector< std::string > > & Arguments::include_paths ( ) const
inline

◆ input_file()

const std::optional< std::string > & Arguments::input_file ( ) const
inline

◆ operator=() [1/2]

Arguments & Arguments::operator= ( Arguments &&  )
default

◆ operator=() [2/2]

Arguments & Arguments::operator= ( const Arguments )
delete

◆ output_file()

const std::optional< std::string > & Arguments::output_file ( ) const
inline

◆ program_arguments()

const std::vector< char * > & Arguments::program_arguments ( ) const
inline

◆ set_display_parse_tree()

void Arguments::set_display_parse_tree ( bool  display)
inline

◆ set_display_tokens()

void Arguments::set_display_tokens ( bool  display)
inline

◆ set_exit_early()

void Arguments::set_exit_early ( bool  exit)
inline

◆ set_input_file()

void Arguments::set_input_file ( const std::string_view &  input_file)
inline

Sets the input file for the compiler.

If no input file is set, the compiler will read from stdin. The method verifies that the provided input file exists and is a regular file.

Parameters
input_fileThe path to the input file to compile
Exceptions
std::runtime_errorif the input file does not exist or is not a regular file

◆ set_output_file()

void Arguments::set_output_file ( const std::string_view &  output_file_arg)
inline

Parses a given output_file argument and updates the Arguments object accordingly.

If '-' is given, compiled code will be written to stdout. Otherwise, the output file path is resolved and verified for write permissions. Exceptions are thrown if the output file is invalid or not writable.

Parameters
output_file_argThe output file argument string to parse
Exceptions
std::runtime_errorif the output file argument is invalid or not writable

◆ set_program_arguments()

void Arguments::set_program_arguments ( int  argc,
char **  argv 
)
inline

Sets the program arguments to be passed to the compiled program.

The program arguments are all of the arguments provided after the input file. e.g.: bpp -a -b -c source.bpp -x -y -z In this case, -x -y -z are the program arguments (passed to the compiled program)

The argv pointers are expected to be borrowed from the original argv passed to main

Parameters
argcThe count of program arguments
argvThe array of program argument strings (borrowed from main's argv)

◆ set_suppress_warnings()

void Arguments::set_suppress_warnings ( bool  suppress)
inline

◆ set_target_bash_version()

void Arguments::set_target_bash_version ( const std::string_view &  version_arg)
inline

Parses a given target Bash version argument and updates the Arguments object accordingly.

The version argument should be in the format "<major>.<minor>", e.g. "5.2". The method validates the format and updates the target_bash_version member.

Parameters
version_argThe target Bash version argument string to parse
Exceptions
std::runtime_errorif the version argument is in an invalid format

◆ suppress_warnings()

bool Arguments::suppress_warnings ( ) const
inline

◆ target_bash_version()

const BashVersion & Arguments::target_bash_version ( ) const
inline

Member Data Documentation

◆ f_display_parse_tree

bool Arguments::f_display_parse_tree = false
private

◆ f_display_tokens

bool Arguments::f_display_tokens = false
private

◆ f_exit_early

bool Arguments::f_exit_early = false
private

◆ f_suppress_warnings

bool Arguments::f_suppress_warnings = false
private

◆ m_include_paths

std::shared_ptr<std::vector<std::string> > Arguments::m_include_paths = std::make_shared<std::vector<std::string>>()
private

◆ m_input_file

std::optional<std::string> Arguments::m_input_file
private

◆ m_output_file

std::optional<std::string> Arguments::m_output_file
private

◆ m_program_arguments

std::vector<char*> Arguments::m_program_arguments
private

◆ m_target_bash_version

BashVersion Arguments::m_target_bash_version = {5, 2}
private

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