P4C
The P4 Compiler
Loading...
Searching...
No Matches
P4::Util::Options Class Referenceabstract
Inheritance diagram for P4::Util::Options:
[legend]

Classes

struct  Option
 

Public Types

enum  OptionFlags { Default = 0 , Hide = 1 << 0 , OptionalArgument = 1 << 1 }
 
using OptionProcessor = std::function<bool(const char *)>
 

Public Member Functions

cstring getBinaryName ()
 
cstring getBuildDate ()
 
cstring getCompileCommand ()
 
virtual const char * getIncludePath () const =0
 
virtual std::vector< const char * > * process (int argc, char *const argv[])
 
virtual void usage ()
 

Protected Member Functions

 Options (std::string_view message)
 
void registerOption (const char *option, const char *argName, OptionProcessor processor, const char *description, OptionFlags flags=OptionFlags::Default)
 
void registerUsage (const char *msg)
 
void setOutStream (std::ostream *out)
 
virtual bool validateOptions () const
 

Protected Attributes

std::vector< const char * > additionalUsage
 
const char * binaryName
 
cstring buildDate
 
bool collectUnknownOptions = false
 
cstring compileCommand
 
cstring message
 
std::vector< cstringoptionOrder
 
std::map< cstring, const Option * > options
 
std::ostream * outStream = &std::cerr
 
std::vector< const char * > remainingOptions
 

Class Documentation

◆ P4::Util::Options::Option

struct P4::Util::Options::Option
Class Members
const char * argName
const char * description
OptionFlags flags
cstring option
OptionProcessor processor

Member Enumeration Documentation

◆ OptionFlags

Enumerator
Default 

The default option flags.

Hide 

Hide this option from –help message.

OptionalArgument 

If this option requires an argument, it may be omitted. Options with this flag set can only accept their argument with the syntax --foo=bar; --foo bar will be treated as if the argument to --foo were omitted. If the argument is omitted, null will be passed to the OptionProcessor.

Member Function Documentation

◆ getIncludePath()

virtual const char * P4::Util::Options::getIncludePath ( ) const
nodiscardpure virtual

Implemented in P4::ParserOptions.

◆ process()

std::vector< const char * > * P4::Util::Options::process ( int argc,
char *const argv[] )
virtual

Process options; return list of remaining options.

If subclasses override this method, they should call the superclass implementation.

Returns
'nullptr' if an error is signaled.

Reimplemented in P4::BMV2::PortableOptions, P4::DPDK::DpdkOptions, P4::P4Tools::AbstractP4cToolOptions, and P4::ParserOptions.

◆ validateOptions()

bool P4::Util::Options::validateOptions ( ) const
nodiscardprotectedvirtual

Checks if parsed options make sense with respect to each-other.

Returns
true if the validation was successful and false otherwise.

Reimplemented in P4::CompilerOptions, P4::P4Tools::AbstractP4cToolOptions, and P4::P4Tools::P4Testgen::TestgenOptions.