| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| //===-- Driver.h ------------------------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // In-house headers: | ||
| #include "MICmnConfig.h" | ||
| #if MICONFIG_COMPILE_MIDRIVER_WITH_LLDBDRIVER | ||
|
|
||
| #ifndef lldb_Driver_h_ | ||
| #define lldb_Driver_h_ | ||
|
|
||
| //#include "Platform.h" // IOR removed | ||
| #include <lldb/Utility/PseudoTerminal.h> | ||
|
|
||
| #include <set> | ||
| #include <bitset> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include <lldb/API/SBDefines.h> | ||
| #include <lldb/API/SBBroadcaster.h> | ||
| #include <lldb/API/SBDebugger.h> | ||
| #include <lldb/API/SBError.h> | ||
| #include "MIDriverMgr.h" | ||
| #include "MIDriverBase.h" | ||
|
|
||
| #define ASYNC true | ||
| #define NO_ASYNC false | ||
|
|
||
| class IOChannel; | ||
|
|
||
| class Driver : public lldb::SBBroadcaster, public CMIDriverBase, public CMIDriverMgr::IDriver | ||
| { | ||
| // MI required code: | ||
| // Static: | ||
| public: | ||
| static Driver * CreateSelf( void ); | ||
|
|
||
| // Methods: | ||
| public: | ||
| bool MISetup( CMIUtilString & vwErrMsg ); | ||
|
|
||
| // Overridden: | ||
| public: | ||
| // From CMIDriverMgr::IDriver | ||
| virtual bool DoInitialize( void ); | ||
| virtual bool DoShutdown( void ); | ||
| virtual bool DoMainLoop( void ); | ||
| virtual void DoResizeWindow( const uint32_t vWindowSizeWsCol ); | ||
| virtual lldb::SBError DoParseArgs( const int argc, const char * argv[], FILE * vpStdOut, bool & vwbExiting ); | ||
| virtual CMIUtilString GetError( void ) const; | ||
| virtual const CMIUtilString & GetName( void ) const; | ||
| virtual lldb::SBDebugger & GetTheDebugger( void ); | ||
| virtual bool GetDriverIsGDBMICompatibleDriver( void ) const; | ||
| virtual bool SetId( const CMIUtilString & vID ); | ||
| virtual const CMIUtilString & GetId( void ) const; | ||
| // From CMIDriverBase | ||
| virtual bool DoFallThruToAnotherDriver( const CMIUtilString & vCmd, CMIUtilString & vwErrMsg ); | ||
| virtual bool SetDriverParent( const CMIDriverBase & vrOtherDriver ); | ||
| virtual const CMIUtilString & GetDriverName( void ) const; | ||
| virtual const CMIUtilString & GetDriverId( void ) const; | ||
|
|
||
| // Original code: | ||
| public: | ||
| Driver (); | ||
|
|
||
| virtual | ||
| ~Driver (); | ||
|
|
||
| void | ||
| MainLoop (); | ||
|
|
||
| lldb::SBError | ||
| ParseArgs (int argc, const char *argv[], FILE *out_fh, bool &do_exit); | ||
|
|
||
| const char * | ||
| GetFilename() const; | ||
|
|
||
| const char * | ||
| GetCrashLogFilename() const; | ||
|
|
||
| const char * | ||
| GetArchName() const; | ||
|
|
||
| lldb::ScriptLanguage | ||
| GetScriptLanguage() const; | ||
|
|
||
| void | ||
| ExecuteInitialCommands (bool before_file); | ||
|
|
||
| bool | ||
| GetDebugMode() const; | ||
|
|
||
| class OptionData | ||
| { | ||
| public: | ||
| OptionData (); | ||
| ~OptionData (); | ||
|
|
||
| void | ||
| Clear(); | ||
|
|
||
| void | ||
| AddInitialCommand (const char *command, bool before_file, bool is_file, lldb::SBError &error); | ||
|
|
||
| //static OptionDefinition m_cmd_option_table[]; | ||
|
|
||
| std::vector<std::string> m_args; | ||
| lldb::ScriptLanguage m_script_lang; | ||
| std::string m_core_file; | ||
| std::string m_crash_log; | ||
| std::vector<std::pair<bool,std::string> > m_initial_commands; | ||
| std::vector<std::pair<bool,std::string> > m_after_file_commands; | ||
| bool m_debug_mode; | ||
| bool m_source_quietly; | ||
| bool m_print_version; | ||
| bool m_print_python_path; | ||
| bool m_print_help; | ||
| bool m_wait_for; | ||
| std::string m_process_name; | ||
| lldb::pid_t m_process_pid; | ||
| bool m_use_external_editor; // FIXME: When we have set/show variables we can remove this from here. | ||
| typedef std::set<char> OptionSet; | ||
| OptionSet m_seen_options; | ||
| }; | ||
|
|
||
|
|
||
| static lldb::SBError | ||
| SetOptionValue (int option_idx, | ||
| const char *option_arg, | ||
| Driver::OptionData &data); | ||
|
|
||
|
|
||
| lldb::SBDebugger & | ||
| GetDebugger() | ||
| { | ||
| return m_debugger; | ||
| } | ||
|
|
||
| void | ||
| ResizeWindow (unsigned short col); | ||
|
|
||
| private: | ||
| lldb::SBDebugger m_debugger; | ||
| OptionData m_option_data; | ||
|
|
||
| void | ||
| ResetOptionValues (); | ||
|
|
||
| void | ||
| ReadyForCommand (); | ||
| }; | ||
|
|
||
| extern Driver * g_driver; | ||
|
|
||
| #endif // lldb_Driver_h_ | ||
|
|
||
| #endif // MICONFIG_COMPILE_MIDRIVER_WITH_LLDBDRIVER |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| //===-- MICmnArgContext.cpp -------------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmnArgContext.cpp | ||
| // | ||
| // Overview: CMICmdArgContext implementation. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| // In-house headers: | ||
| #include "MICmdArgContext.h" | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgContext constructor. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgContext::CMICmdArgContext( void ) | ||
| : m_constCharSpace( ' ' ) | ||
| , m_constStrSpace( " " ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgContext constructor. | ||
| // Type: Method. | ||
| // Args: vrCmdLineArgsRaw - (R) The text description of the arguments options. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgContext::CMICmdArgContext( const CMIUtilString & vrCmdLineArgsRaw ) | ||
| : m_strCmdArgsAndOptions( vrCmdLineArgsRaw ) | ||
| , m_constCharSpace( ' ' ) | ||
| , m_constStrSpace( " " ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgContext destructor. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgContext::~CMICmdArgContext( void ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve the remainder of the command's argument options left to parse. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: CMIUtilString & - Argument options text. | ||
| // Throws: None. | ||
| //-- | ||
| const CMIUtilString & CMICmdArgContext::GetArgsLeftToParse( void ) const | ||
| { | ||
| return m_strCmdArgsAndOptions; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Ask if this arguments string has any arguments. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: bool - True = Has one or more arguments present, false = no arguments. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgContext::IsEmpty( void ) const | ||
| { | ||
| return m_strCmdArgsAndOptions.empty(); | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Remove the argument from the options text and any space after the argument | ||
| // if applicable. | ||
| // Type: Method. | ||
| // Args: vArg - (R) The name of the argument. | ||
| // Return: MIstatus::success - Functional succeeded. | ||
| // MIstatus::failure - Functional failed. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgContext::RemoveArg( const CMIUtilString & vArg ) | ||
| { | ||
| if( vArg.empty() ) | ||
| return MIstatus::success; | ||
|
|
||
| const MIuint nLen = vArg.length(); | ||
| const MIuint nLenCntxt = m_strCmdArgsAndOptions.length(); | ||
| if( nLen > nLenCntxt ) | ||
| return MIstatus::failure; | ||
|
|
||
| MIuint nExtraSpace = 0; | ||
| MIint nPos = m_strCmdArgsAndOptions.find( vArg ); | ||
| while( 1 ) | ||
| { | ||
| if( nPos == (MIint) std::string::npos ) | ||
| return MIstatus::success; | ||
|
|
||
| bool bPass1 = false; | ||
| if( nPos != 0 ) | ||
| { | ||
| if( m_strCmdArgsAndOptions[ nPos - 1 ] == m_constCharSpace ) | ||
| bPass1 = true; | ||
| } | ||
| else | ||
| bPass1 = true; | ||
|
|
||
| const MIuint nEnd = nPos + nLen; | ||
|
|
||
| if( bPass1 ) | ||
| { | ||
| bool bPass2 = false; | ||
| if( nEnd < nLenCntxt ) | ||
| { | ||
| if( m_strCmdArgsAndOptions[ nEnd ] == m_constCharSpace ) | ||
| { | ||
| bPass2 = true; | ||
| nExtraSpace = 1; | ||
| } | ||
| } | ||
| else | ||
| bPass2 = true; | ||
|
|
||
| if( bPass2 ) | ||
| break; | ||
| } | ||
|
|
||
| nPos = m_strCmdArgsAndOptions.find( vArg, nEnd ); | ||
| } | ||
|
|
||
| const MIuint nPosEnd = nLen + nExtraSpace; | ||
| m_strCmdArgsAndOptions = m_strCmdArgsAndOptions.replace( nPos, nPosEnd, "" ).c_str(); | ||
| m_strCmdArgsAndOptions = m_strCmdArgsAndOptions.Trim(); | ||
|
|
||
| return MIstatus::success; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve number of arguments or options present in the command's option text. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: MIuint - 0 to n arguments present. | ||
| // Throws: None. | ||
| //-- | ||
| MIuint CMICmdArgContext::GetNumberArgsPresent( void ) const | ||
| { | ||
| CMIUtilString::VecString_t vecOptions; | ||
| return m_strCmdArgsAndOptions.Split( m_constStrSpace, vecOptions ); | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve all the arguments or options remaining in *this context. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: MIUtilString::VecString_t - List of args remaining. | ||
| // Throws: None. | ||
| //-- | ||
| CMIUtilString::VecString_t CMICmdArgContext::GetArgs( void ) const | ||
| { | ||
| CMIUtilString::VecString_t vecOptions; | ||
| m_strCmdArgsAndOptions.Split( m_constStrSpace, vecOptions ); | ||
| return vecOptions; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Copy assignment operator. | ||
| // Type: Method. | ||
| // Args: vOther - (R) The variable to copy from. | ||
| // Return: CMIUtilString & - this object. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgContext & CMICmdArgContext::operator= ( const CMICmdArgContext & vOther ) | ||
| { | ||
| if( this != &vOther ) | ||
| { | ||
| m_strCmdArgsAndOptions = vOther.m_strCmdArgsAndOptions; | ||
| } | ||
|
|
||
| return *this; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| //===-- MICmdArgContext.h ---------------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgContext.h | ||
| // | ||
| // Overview: CMICmdArgContext interface. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| #pragma once | ||
|
|
||
| // In-house headers: | ||
| #include "MIUtilString.h" | ||
|
|
||
| //++ ============================================================================ | ||
| // Details: MI common code class. Command arguments and options string. Holds | ||
| // the context string. | ||
| // Based on the Interpreter pattern. | ||
| // Gotchas: None. | ||
| // Authors: Illya Rudkin 14/04/2014. | ||
| // Changes: None. | ||
| //-- | ||
| class CMICmdArgContext | ||
| { | ||
| // Methods: | ||
| public: | ||
| /* ctor */ CMICmdArgContext( void ); | ||
| /* ctor */ CMICmdArgContext( const CMIUtilString & vrCmdLineArgsRaw ); | ||
| // | ||
| const CMIUtilString & GetArgsLeftToParse( void ) const; | ||
| MIuint GetNumberArgsPresent( void ) const; | ||
| CMIUtilString::VecString_t GetArgs( void ) const; | ||
| bool IsEmpty( void ) const; | ||
| bool RemoveArg( const CMIUtilString & vArg ); | ||
| // | ||
| CMICmdArgContext & operator= ( const CMICmdArgContext & vOther ); | ||
|
|
||
| // Overridden: | ||
| public: | ||
| // From CMIUtilString | ||
| /* dtor */ virtual ~CMICmdArgContext( void ); | ||
|
|
||
| // Attributes: | ||
| private: | ||
| CMIUtilString m_strCmdArgsAndOptions; | ||
| const MIchar m_constCharSpace; | ||
| const CMIUtilString m_constStrSpace; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,390 @@ | ||
| //===-- MICmdArgSet.cpp -----------------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgSet.cpp | ||
| // | ||
| // Overview: CMICmdArgSet implementation. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| // In-house headers: | ||
| #include "MICmdArgSet.h" | ||
| #include "MICmdArgValBase.h" | ||
| #include "MICmnResources.h" | ||
| #include "MICmnLog.h" | ||
| #include "MICmnConfig.h" | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgSet constructor. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgSet::CMICmdArgSet( void ) | ||
| : m_bIsArgsPresentButNotHandledByCmd( false ) | ||
| , m_constStrCommaSpc( ", " ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgSet destructor. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgSet::~CMICmdArgSet( void ) | ||
| { | ||
| // Tidy up | ||
| Destroy(); | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Release resources used by *this container object. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| void CMICmdArgSet::Destroy( void ) | ||
| { | ||
| // Delete command argument objects | ||
| if( !m_setCmdArgs.empty() ) | ||
| { | ||
| SetCmdArgs_t::iterator it = m_setCmdArgs.begin(); | ||
| while( it != m_setCmdArgs.end() ) | ||
| { | ||
| CMICmdArgValBase * pArg( *it ); | ||
| delete pArg; | ||
|
|
||
| // Next | ||
| ++it; | ||
| } | ||
| m_setCmdArgs.clear(); | ||
| } | ||
|
|
||
| m_setCmdArgsThatNotValid.clear(); | ||
| m_setCmdArgsThatAreMissing.clear(); | ||
| m_setCmdArgsNotHandledByCmd.clear(); | ||
| m_setCmdArgsMissingInfo.clear(); | ||
| m_bIsArgsPresentButNotHandledByCmd = false; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve the state flag indicating that the command set up ready to parse | ||
| // command arguments or options found that one or more arguemnts was indeed | ||
| // present but not handled. This is given as a warning in the MI log file. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: bool - True = one or more args not handled, false = all args handled | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgSet::IsArgsPresentButNotHandledByCmd( void ) const | ||
| { | ||
| return m_bIsArgsPresentButNotHandledByCmd; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Add the the list of command's arguments to parse and validate another one. | ||
| // Type: Method. | ||
| // Args: vArg - (R) A command argument object. | ||
| // Return: MIstatus::success - Functional succeeded. | ||
| // MIstatus::failure - Functional failed. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgSet::Add( const CMICmdArgValBase & vArg ) | ||
| { | ||
| CMICmdArgValBase * pArg = const_cast< CMICmdArgValBase * >( &vArg ); | ||
| m_setCmdArgs.push_back( pArg ); | ||
|
|
||
| return MIstatus::success; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: After validating an options line of text (the context) and there is a failure, | ||
| // it is likely a mandatory command argument that is required is missing. This | ||
| // function returns the argument that should be present. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: SetCmdArgs_t & - Set of argument objects. | ||
| // Throws: None. | ||
| //-- | ||
| const CMICmdArgSet::SetCmdArgs_t & CMICmdArgSet::GetArgsThatAreMissing( void ) const | ||
| { | ||
| return m_setCmdArgsThatAreMissing; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: After validating an options line of text (the context) and there is a failure, | ||
| // it may be because one or more arguments were unable to extract a value. This | ||
| // function returns the argument that were found to be invalid. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: SetCmdArgs_t & - Set of argument objects. | ||
| // Throws: None. | ||
| //-- | ||
| const CMICmdArgSet::SetCmdArgs_t & CMICmdArgSet::GetArgsThatInvalid( void ) const | ||
| { | ||
| return m_setCmdArgsThatNotValid; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: The list of argument or option (objects) that were specified by the command | ||
| // and so recognised when parsed but were not handled. Ideally the command | ||
| // should handle all arguments and options presented to it. The command sends | ||
| // warning to the MI log file to say that these options were not handled. | ||
| // Used as one way to determine option that maybe should really be implemented | ||
| // and not just ignored. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: SetCmdArgs_t & - Set of argument objects. | ||
| // Throws: None. | ||
| //-- | ||
| const CMICmdArgSet::SetCmdArgs_t & CMICmdArgSet::GetArgsNotHandledByCmd( void ) const | ||
| { | ||
| return m_setCmdArgsNotHandledByCmd; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Given a set of command argument objects parse the context option string to | ||
| // find those argument and retrieve their value. If the function fails call | ||
| // GetArgsThatAreMissing() to see which commands that were manadatory were | ||
| // missing or failed to parse. | ||
| // Type: Method. | ||
| // Args: vStrMiCmd - (R) Command's name. | ||
| // vCmdArgsText - (RW) A command's options or argument. | ||
| // Return: MIstatus::success - Functional succeeded. | ||
| // MIstatus::failure - Functional failed. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgSet::Validate( const CMIUtilString & vStrMiCmd, CMICmdArgContext & vwCmdArgsText ) | ||
| { | ||
| m_cmdArgContext = vwCmdArgsText; | ||
|
|
||
| // Iterate all the arguments or options required by a command | ||
| const MIuint nArgs = vwCmdArgsText.GetNumberArgsPresent(); | ||
| MIuint nArgsMandatoryCnt = 0; | ||
| SetCmdArgs_t::const_iterator it = m_setCmdArgs.begin(); | ||
| while( it != m_setCmdArgs.end() ) | ||
| { | ||
| const CMICmdArgValBase * pArg( *it ); | ||
| if( pArg->GetIsMandatory() ) | ||
| nArgsMandatoryCnt++; | ||
| if( !const_cast< CMICmdArgValBase * >( pArg )->Validate( vwCmdArgsText ) ) | ||
| { | ||
| if( pArg->GetIsMandatory() && !pArg->GetFound() ) | ||
| m_setCmdArgsThatAreMissing.push_back( const_cast< CMICmdArgValBase * >( pArg ) ); | ||
| else if( pArg->GetFound() ) | ||
| { | ||
| if( pArg->GetIsMissingOptions() ) | ||
| m_setCmdArgsMissingInfo.push_back( const_cast< CMICmdArgValBase * >( pArg ) ); | ||
| else if( !pArg->GetValid() ) | ||
| m_setCmdArgsThatNotValid.push_back( const_cast< CMICmdArgValBase * >( pArg ) ); | ||
| } | ||
| } | ||
| if( pArg->GetFound() && !pArg->GetIsHandledByCmd() ) | ||
| { | ||
| m_bIsArgsPresentButNotHandledByCmd = true; | ||
| m_setCmdArgsNotHandledByCmd.push_back( const_cast< CMICmdArgValBase * >( pArg ) ); | ||
| } | ||
|
|
||
| // Next | ||
| ++it; | ||
| } | ||
|
|
||
| // Check that one or more argument objects have any issues to report... | ||
|
|
||
| if( nArgs < nArgsMandatoryCnt ) | ||
| { | ||
| SetErrorDescription( CMIUtilString::Format( MIRSRC( IDS_CMD_ARGS_ERR_N_OPTIONS_REQUIRED ), nArgsMandatoryCnt ) ); | ||
| return MIstatus::failure; | ||
| } | ||
|
|
||
| if( !vwCmdArgsText.IsEmpty() ) | ||
| { | ||
| SetErrorDescription( CMIUtilString::Format( MIRSRC( IDS_CMD_ARGS_ERR_CONTEXT_NOT_ALL_EATTEN ), vwCmdArgsText.GetArgsLeftToParse().c_str() ) ); | ||
| return MIstatus::failure; | ||
| } | ||
|
|
||
| if( IsArgsPresentButNotHandledByCmd() ) | ||
| WarningArgsNotHandledbyCmdLogFile( vStrMiCmd ); | ||
|
|
||
| CMIUtilString strListMissing; | ||
| CMIUtilString strListInvalid; | ||
| CMIUtilString strListMissingInfo; | ||
| const bool bArgsMissing = (m_setCmdArgsThatAreMissing.size() > 0); | ||
| const bool bArgsInvalid = (m_setCmdArgsThatNotValid.size() > 0); | ||
| const bool bArgsMissingInfo = (m_setCmdArgsMissingInfo.size() > 0); | ||
| if( !(bArgsMissing || bArgsInvalid || bArgsMissingInfo) ) | ||
| return MIstatus::success; | ||
| if( bArgsMissing ) | ||
| { | ||
| MIuint i = 0; | ||
| SetCmdArgs_t::const_iterator it = m_setCmdArgsThatAreMissing.begin(); | ||
| while( it != m_setCmdArgsThatAreMissing.end() ) | ||
| { | ||
| if( i++ > 0 ) | ||
| strListMissing += m_constStrCommaSpc; | ||
|
|
||
| const CMICmdArgValBase * pArg( *it ); | ||
| strListMissing += pArg->GetName(); | ||
|
|
||
| // Next | ||
| ++it; | ||
| } | ||
| } | ||
| if( bArgsInvalid ) | ||
| { | ||
| MIuint i = 0; | ||
| SetCmdArgs_t::const_iterator it = m_setCmdArgsThatNotValid.begin(); | ||
| while( it != m_setCmdArgsThatNotValid.end() ) | ||
| { | ||
| if( i++ > 0 ) | ||
| strListMissing += m_constStrCommaSpc; | ||
|
|
||
| const CMICmdArgValBase * pArg( *it ); | ||
| strListInvalid += pArg->GetName(); | ||
|
|
||
| // Next | ||
| ++it; | ||
| } | ||
| } | ||
| if( bArgsMissingInfo ) | ||
| { | ||
| MIuint i = 0; | ||
| SetCmdArgs_t::const_iterator it = m_setCmdArgsMissingInfo.begin(); | ||
| while( it != m_setCmdArgsMissingInfo.end() ) | ||
| { | ||
| if( i++ > 0 ) | ||
| strListMissingInfo += m_constStrCommaSpc; | ||
|
|
||
| const CMICmdArgValBase * pArg( *it ); | ||
| strListMissingInfo += pArg->GetName(); | ||
|
|
||
| // Next | ||
| ++it; | ||
| } | ||
| } | ||
| if( bArgsMissing && bArgsInvalid ) | ||
| { | ||
| SetErrorDescription( CMIUtilString::Format( MIRSRC( IDS_CMD_ARGS_ERR_VALIDATION_MAN_INVALID ), strListMissing.c_str(), strListInvalid.c_str() ) ); | ||
| return MIstatus::failure; | ||
| } | ||
| if( bArgsMissing ) | ||
| { | ||
| SetErrorDescription( CMIUtilString::Format( MIRSRC( IDS_CMD_ARGS_ERR_VALIDATION_MANDATORY ), strListMissing.c_str() ) ); | ||
| return MIstatus::failure; | ||
| } | ||
| if( bArgsMissingInfo ) | ||
| { | ||
| SetErrorDescription( CMIUtilString::Format( MIRSRC( IDS_CMD_ARGS_ERR_VALIDATION_MISSING_INF ), strListMissingInfo.c_str() ) ); | ||
| return MIstatus::failure; | ||
| } | ||
| if( bArgsInvalid ) | ||
| { | ||
| SetErrorDescription( CMIUtilString::Format( MIRSRC( IDS_CMD_ARGS_ERR_VALIDATION_INVALID ), strListInvalid.c_str() ) ); | ||
| return MIstatus::failure; | ||
| } | ||
|
|
||
| return MIstatus::success; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Ask if the command's argument options text had any arguments. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: bool - True = Has one or more arguments present, false = no arguments. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgSet::IsArgContextEmpty( void ) const | ||
| { | ||
| return m_cmdArgContext.IsEmpty(); | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve the number of arguments that are being used for the command. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: MIuint - Argument count. | ||
| // Throws: None. | ||
| //-- | ||
| MIuint CMICmdArgSet::GetCount( void ) const | ||
| { | ||
| return m_setCmdArgs.size(); | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Given a set of command argument objects retrieve the argument with the | ||
| // specified name. | ||
| // Type: Method. | ||
| // Args: vpArg - (W) A pointer to a command's argument object. | ||
| // Return: True - Argument found. | ||
| // False - Argument not found. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgSet::GetArg( const CMIUtilString & vArgName, CMICmdArgValBase *& vpArg ) const | ||
| { | ||
| bool bFound = false; | ||
| SetCmdArgs_t::const_iterator it = m_setCmdArgs.begin(); | ||
| while( it != m_setCmdArgs.end() ) | ||
| { | ||
| CMICmdArgValBase * pArg( *it ); | ||
| if( pArg->GetName() == vArgName ) | ||
| { | ||
| bFound = true; | ||
| vpArg = pArg; | ||
| break; | ||
| } | ||
|
|
||
| // Next | ||
| ++it; | ||
| } | ||
|
|
||
| return bFound; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Write a warning message to the MI Log file about the command's arguments or | ||
| // options that were found present but not handled. | ||
| // Type: Method. | ||
| // Args: vrCmdName - (R) The command's name. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| void CMICmdArgSet::WarningArgsNotHandledbyCmdLogFile( const CMIUtilString & vrCmdName ) | ||
| { | ||
| #if MICONFIG_GIVE_WARNING_CMD_ARGS_NOT_HANDLED | ||
|
|
||
| CMIUtilString strArgsNotHandled; | ||
| const CMICmdArgSet::SetCmdArgs_t & rSetArgs = GetArgsNotHandledByCmd(); | ||
| MIuint nCnt = 0; | ||
| CMICmdArgSet::SetCmdArgs_t::const_iterator it = rSetArgs.begin(); | ||
| while( it != rSetArgs.end() ) | ||
| { | ||
| if( nCnt++ > 0 ) | ||
| strArgsNotHandled += m_constStrCommaSpc; | ||
| const CMICmdArgValBase * pArg = *it; | ||
| strArgsNotHandled += pArg->GetName(); | ||
|
|
||
| // Next | ||
| ++it; | ||
| } | ||
|
|
||
| const CMIUtilString strWarningMsg( CMIUtilString::Format( MIRSRC( IDS_CMD_WRN_ARGS_NOT_HANDLED ), vrCmdName.c_str(), strArgsNotHandled.c_str() ) ); | ||
| m_pLog->WriteLog( strWarningMsg ); | ||
|
|
||
| #endif // MICONFIG_GIVE_WARNING_CMD_ARGS_NOT_HANDLED | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| //===-- MICmdArgSet.h -------------------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgSet.h | ||
| // | ||
| // Overview: CMICmdArgSet interface. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| #pragma once | ||
|
|
||
| // Third party headers: | ||
| #include <vector> | ||
|
|
||
| // In-house headers: | ||
| #include "MICmnBase.h" | ||
| #include "MICmdArgContext.h" | ||
|
|
||
| // Declarations: | ||
| class CMICmdArgValBase; | ||
|
|
||
| //++ ============================================================================ | ||
| // Details: MI common code class. Command arguments container class. | ||
| // A command may have one or more arguments of which some may be optional. | ||
| // *this class contains a list of the command's arguments which are | ||
| // validates against the commands argument options string (context string). | ||
| // Each argument tries to extract the value it is looking for. | ||
| // Argument objects added to *this container are owned by this container | ||
| // and are deleted when this container goes out of scope. Allocate argument | ||
| // objects on the heap. | ||
| // It is assummed the arguments to be parsed are read from left to right in | ||
| // order. The order added to *this container is the order they will parsed. | ||
| // Gotchas: None. | ||
| // Authors: Illya Rudkin 14/04/2014. | ||
| // Changes: None. | ||
| //-- | ||
| class CMICmdArgSet : public CMICmnBase | ||
| { | ||
| // Classes: | ||
| public: | ||
| //++ | ||
| // Description: ArgSet's interface for command arguments to implement. | ||
| //-- | ||
| class IArg | ||
| { | ||
| public: | ||
| virtual bool GetFound( void ) const = 0; | ||
| virtual bool GetIsHandledByCmd( void ) const = 0; | ||
| virtual bool GetIsMandatory( void ) const = 0; | ||
| virtual bool GetIsMissingOptions( void ) const = 0; | ||
| virtual const CMIUtilString & GetName( void ) const = 0; | ||
| virtual bool GetValid( void ) const = 0; | ||
| virtual bool Validate( CMICmdArgContext & vwArgContext ) = 0; | ||
|
|
||
| /* dtor */ virtual ~IArg( void ) {}; | ||
| }; | ||
|
|
||
| // Typedefs: | ||
| public: | ||
| typedef std::vector< CMICmdArgValBase * > SetCmdArgs_t; | ||
|
|
||
| // Methods: | ||
| public: | ||
| /* ctor */ CMICmdArgSet( void ); | ||
|
|
||
| bool Add( const CMICmdArgValBase & vArg ); | ||
| bool GetArg( const CMIUtilString & vArgName, CMICmdArgValBase *& vpArg ) const; | ||
| const SetCmdArgs_t & GetArgsThatAreMissing( void ) const; | ||
| const SetCmdArgs_t & GetArgsThatInvalid( void ) const; | ||
| MIuint GetCount( void ) const; | ||
| bool IsArgContextEmpty( void ) const; | ||
| bool IsArgsPresentButNotHandledByCmd( void ) const; | ||
| void WarningArgsNotHandledbyCmdLogFile( const CMIUtilString & vrCmdName ); | ||
| bool Validate( const CMIUtilString & vStrMiCmd, CMICmdArgContext & vwCmdArgsText ); | ||
|
|
||
| // Overrideable: | ||
| public: | ||
| /* dtor */ virtual ~CMICmdArgSet( void ); | ||
|
|
||
| // Methods: | ||
| private: | ||
| const SetCmdArgs_t & GetArgsNotHandledByCmd( void ) const; | ||
| void Destroy( void ); // Release resources used by *this object | ||
|
|
||
| // Attributes: | ||
| private: | ||
| bool m_bIsArgsPresentButNotHandledByCmd; // True = The driver's client presented the command with options recognised but not handled by a command, false = all args handled | ||
| SetCmdArgs_t m_setCmdArgs; // The set of arguments that are that the command is expecting to find in the options string | ||
| SetCmdArgs_t m_setCmdArgsThatAreMissing; // The set of arguments that are required by the command but are missing | ||
| SetCmdArgs_t m_setCmdArgsThatNotValid; // The set of arguments found in the text but for some reason unable to extract a value | ||
| SetCmdArgs_t m_setCmdArgsNotHandledByCmd; // The set of arguments specified by the command which were present to the command but not handled | ||
| SetCmdArgs_t m_setCmdArgsMissingInfo; // The set of arguments that were present but were found to be missing additional information i.e. --thread 3 but 3 is missing | ||
| CMICmdArgContext m_cmdArgContext; // Copy of the command's argument options text before validate takes place (empties it of content) | ||
| const CMIUtilString m_constStrCommaSpc; | ||
| }; | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| //===-- MICmdArgValBase.cpp -------------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgValBase.cpp | ||
| // | ||
| // Overview: CMICmdArgValBase implementation. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| // In-house headers: | ||
| #include "MICmdArgValBase.h" | ||
| #include "MIUtilString.h" | ||
| #include "MICmdArgContext.h" | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValBase constructor. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValBase::CMICmdArgValBase( void ) | ||
| : m_bFound( false ) | ||
| , m_bValid( false ) | ||
| , m_bMandatory( false ) | ||
| , m_bHandled( false ) | ||
| , m_bIsMissingOptions( false ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValBase constructor. | ||
| // Type: Method. | ||
| // Args: vrArgName - (R) Argument's name to search by. | ||
| // vbMandatory - (R) True = Yes must be present, false = optional argument. | ||
| // vbHandleByCmd - (R) True = Command processes *this option, false = not handled. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValBase::CMICmdArgValBase( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd ) | ||
| : m_bFound( false ) | ||
| , m_bValid( false ) | ||
| , m_bMandatory( vbMandatory ) | ||
| , m_strArgName( vrArgName ) | ||
| , m_bHandled( vbHandleByCmd ) | ||
| , m_bIsMissingOptions( false ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValBase destructor. | ||
| // Type: Overrideable. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValBase::~CMICmdArgValBase( void ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve the state flag of whether the argument is handled by the command or | ||
| // not. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: True - Command needs more information. | ||
| // False - All information is present as expected. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValBase::GetIsMissingOptions( void ) const | ||
| { | ||
| return m_bIsMissingOptions; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve the state flag of whether the argument is handled by the command or | ||
| // not. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: True - Command handles *this argument or option. | ||
| // False - Not handled (argument specified but ignored). | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValBase::GetIsHandledByCmd( void ) const | ||
| { | ||
| return m_bHandled; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve the name of *this argument. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: CMIUtilString & - Return the text name. | ||
| // Throws: None. | ||
| //-- | ||
| const CMIUtilString & CMICmdArgValBase::GetName( void ) const | ||
| { | ||
| return m_strArgName; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve the state flag of whether the argument was found in the command's | ||
| // argument / options string. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: True - Argument found. | ||
| // False - Argument not found. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValBase::GetFound( void ) const | ||
| { | ||
| return m_bFound; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve the state flag indicating whether the value was obtained from the | ||
| // text arguments string and is valid. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: True - Argument valid. | ||
| // False - Argument not valid. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValBase::GetValid( void ) const | ||
| { | ||
| return m_bValid; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve the state flag indicating whether *this argument is a mandatory | ||
| // argument for the command or is optional to be present. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: True - Mandatory. | ||
| // False - Optional. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValBase::GetIsMandatory( void ) const | ||
| { | ||
| return m_bMandatory; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Parse the command's argument options string and try to extract the value *this | ||
| // argument is looking for. | ||
| // Type: Overrideable. | ||
| // Args: vArgContext - (RW) The command's argument options string. | ||
| // Return: MIstatus::success - Functional succeeded. | ||
| // MIstatus::failure - Functional failed. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValBase::Validate( CMICmdArgContext & vwArgContext ) | ||
| { | ||
| MIunused( vwArgContext ); | ||
|
|
||
| // Override to implement | ||
|
|
||
| return MIstatus::failure; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| //===-- Platform.h ----------------------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgValBase.h | ||
| // | ||
| // Overview: CMICmdArgValBase interface. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| #pragma once | ||
|
|
||
| // In-house headers: | ||
| #include "MIUtilString.h" | ||
| #include "MICmdArgSet.h" | ||
|
|
||
| //++ ============================================================================ | ||
| // Details: MI common code class. Command argument base class. Arguments objects | ||
| // needing specialization derived from *this class. An argument knows | ||
| // what type of argument it is and how it is to interpret the options | ||
| // (context) string to find and validate a matching argument and so | ||
| // extract a value from it. | ||
| // Argument objects are added to the CMICmdArgSet container object. | ||
| // Once added the container they belong to that contain and will be | ||
| // deleted when the container goes out of scope. Allocate argument | ||
| // objects on the heap and pass in to the Add(). | ||
| // Note the code is written such that a command will produce an error | ||
| // should it be presented with arguments or options it does not understand. | ||
| // A command can recognise an option or argument then ignore if it | ||
| // wishes (a warning is sent to the MI's Log file). This is so it is | ||
| // hardwired to fail and catch arguments or options that presented by | ||
| // different driver clients. | ||
| // Based on the Interpreter pattern. | ||
| // Gotchas: None. | ||
| // Authors: Illya Rudkin 14/04/2014. | ||
| // Changes: None. | ||
| //-- | ||
| class CMICmdArgValBase : public CMICmdArgSet::IArg | ||
| { | ||
| // Methods: | ||
| public: | ||
| /* ctor */ CMICmdArgValBase( void ); | ||
| /* ctor */ CMICmdArgValBase( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd ); | ||
|
|
||
| // Overrideable: | ||
| public: | ||
| /* dtor */ virtual ~CMICmdArgValBase( void ); | ||
|
|
||
| // Overridden: | ||
| public: | ||
| // From CMICmdArgSet::IArg | ||
| virtual bool GetFound( void ) const; | ||
| virtual bool GetIsHandledByCmd( void ) const; | ||
| virtual bool GetIsMandatory( void ) const; | ||
| virtual bool GetIsMissingOptions( void ) const; | ||
| virtual const CMIUtilString & GetName( void ) const; | ||
| virtual bool GetValid( void ) const; | ||
| virtual bool Validate( CMICmdArgContext & vwArgContext ); | ||
|
|
||
| // Attributes: | ||
| protected: | ||
| bool m_bFound; // True = yes found in arguments options text, false = not found | ||
| bool m_bValid; // True = yes argument parsed and valid, false = not valid | ||
| bool m_bMandatory; // True = yes arg must be present, false = optional argument | ||
| CMIUtilString m_strArgName; | ||
| bool m_bHandled; // True = Command processes *this option, false = not handled | ||
| bool m_bIsMissingOptions; // True = Command needs more information, false = ok | ||
| }; | ||
|
|
||
| //++ ============================================================================ | ||
| // Details: MI common code class. Templated command argument base class. | ||
| // Gotchas: None. | ||
| // Authors: Illya Rudkin 14/04/2014. | ||
| // Changes: None. | ||
| //-- | ||
| template< class T > | ||
| class CMICmdArgValBaseTemplate : public CMICmdArgValBase | ||
| { | ||
| // Methods: | ||
| public: | ||
| /* ctor */ CMICmdArgValBaseTemplate( void ); | ||
| /* ctor */ CMICmdArgValBaseTemplate( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd ); | ||
| // | ||
| const T & GetValue( void ) const; | ||
|
|
||
| // Overrideable: | ||
| public: | ||
| /* dtor */ virtual ~CMICmdArgValBaseTemplate( void ); | ||
|
|
||
| // Attributes: | ||
| protected: | ||
| T m_argValue; | ||
| }; | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValBaseTemplate constructor. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| template< class T > | ||
| CMICmdArgValBaseTemplate< T >::CMICmdArgValBaseTemplate( void ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValBaseTemplate constructor. | ||
| // Type: Method. | ||
| // Args: vrArgName - (R) Argument's name to search by. | ||
| // vbMandatory - (R) True = Yes must be present, false = optional argument. | ||
| // vbHandleByCmd - (R) True = Command processes *this option, false = not handled. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| template< class T > | ||
| CMICmdArgValBaseTemplate< T >::CMICmdArgValBaseTemplate( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd ) | ||
| : CMICmdArgValBase( vrArgName, vbMandatory, vbHandleByCmd ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValBaseTemplate destructor. | ||
| // Type: Overrideable. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| template< class T > | ||
| CMICmdArgValBaseTemplate< T >::~CMICmdArgValBaseTemplate( void ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve the value the argument parsed from the command's argument / options | ||
| // text string. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: Template type & - The arg value of *this object. | ||
| // Throws: None. | ||
| //-- | ||
| template< class T > | ||
| const T & CMICmdArgValBaseTemplate< T >::GetValue( void ) const | ||
| { | ||
| return m_argValue; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| //===-- MICmdArgValFile.cpp -------------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgValFile.cpp | ||
| // | ||
| // Overview: CMICmdArgValFile implementation. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| // In-house headers: | ||
| #include "MICmdArgValFile.h" | ||
| #include "MICmdArgContext.h" | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValFile constructor. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValFile::CMICmdArgValFile( void ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValFile constructor. | ||
| // Type: Method. | ||
| // Args: vrArgName - (R) Argument's name to search by. | ||
| // vbMandatory - (R) True = Yes must be present, false = optional argument. | ||
| // vbHandleByCmd - (R) True = Command processes *this option, false = not handled. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValFile::CMICmdArgValFile( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd ) | ||
| : CMICmdArgValBaseTemplate( vrArgName, vbMandatory, vbHandleByCmd ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValFile destructor. | ||
| // Type: Overidden. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValFile::~CMICmdArgValFile( void ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Parse the command's argument options string and try to extract the value *this | ||
| // argument is looking for. | ||
| // Type: Overridden. | ||
| // Args: vwArgContext - (R) The command's argument options string. | ||
| // Return: MIstatus::success - Functional succeeded. | ||
| // MIstatus::failure - Functional failed. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValFile::Validate( CMICmdArgContext & vwArgContext ) | ||
| { | ||
| if( vwArgContext.IsEmpty() ) | ||
| return MIstatus::success; | ||
|
|
||
| // The GDB/MI spec suggests there is only parameter | ||
| if( vwArgContext.GetNumberArgsPresent() == 1 ) | ||
| { | ||
| const CMIUtilString & rFile( vwArgContext.GetArgsLeftToParse() ); | ||
| if( IsFilePath( rFile ) ) | ||
| { | ||
| m_bFound = true; | ||
| m_bValid = true; | ||
| m_argValue = rFile; | ||
| vwArgContext.RemoveArg( rFile ); | ||
| return MIstatus::success; | ||
| } | ||
| else | ||
| return MIstatus::failure; | ||
| } | ||
|
|
||
| // In reality there are more than one option, if so the file option | ||
| // is the last one (don't handle that here - find the best looking one) | ||
| const CMIUtilString::VecString_t vecOptions( vwArgContext.GetArgs() ); | ||
| CMIUtilString::VecString_t::const_iterator it = vecOptions.begin(); | ||
| while( it != vecOptions.end() ) | ||
| { | ||
| const CMIUtilString & rTxt( *it ); | ||
| if( IsFilePath( rTxt ) ) | ||
| { | ||
| m_bFound = true; | ||
|
|
||
| if( vwArgContext.RemoveArg( rTxt ) ) | ||
| { | ||
| m_bValid = true; | ||
| m_argValue = rTxt; | ||
| return MIstatus::success; | ||
| } | ||
| else | ||
| return MIstatus::success; | ||
| } | ||
|
|
||
| // Next | ||
| ++it; | ||
| } | ||
|
|
||
| return MIstatus::failure; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Given some text extract the file name path from it. | ||
| // Type: Method. | ||
| // Args: vrTxt - (R) The text to extract the file name path from. | ||
| // Return: CMIUtilString - File name and or path. | ||
| // Throws: None. | ||
| //-- | ||
| CMIUtilString CMICmdArgValFile::GetFileNamePath( const CMIUtilString & vrTxt ) const | ||
| { | ||
| return vrTxt; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Examine the string and determine if it is a valid file name path. | ||
| // Type: Method. | ||
| // Args: vrFileNamePath - (R) File's name and directory path. | ||
| // Return: bool - True = yes valid file path, false = no. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValFile::IsFilePath( const CMIUtilString & vrFileNamePath ) const | ||
| { | ||
| const bool bHavePosSlash = (vrFileNamePath.find_first_of( "/" ) != std::string::npos); | ||
| const bool bHaveBckSlash = (vrFileNamePath.find_first_of( "\\" ) != std::string::npos); | ||
|
|
||
| // Look for --someLongOption | ||
| MIint nPos = vrFileNamePath.find_first_of( "--" ); | ||
| const bool bLong = (nPos == 0); | ||
| if( bLong ) | ||
| return false; | ||
|
|
||
| // Look for -f type short parameters | ||
| nPos = vrFileNamePath.find_first_of( "-" ); | ||
| const bool bShort = (nPos == 0); | ||
| if( bShort ) | ||
| return false; | ||
|
|
||
| // Look for i1 i2 i3.... | ||
| nPos = vrFileNamePath.find_first_of( "i" ); | ||
| const bool bFoundI1 = ((nPos == 0) && (::isdigit( vrFileNamePath[ 1 ] )) ); | ||
| if( bFoundI1 ) | ||
| return false; | ||
|
|
||
| const bool bValidChars = CMIUtilString::IsAllValidAlphaAndNumeric( *vrFileNamePath.c_str() ); | ||
| if( bValidChars || bHavePosSlash || bHaveBckSlash ) | ||
| return true; | ||
|
|
||
| return false; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| //===-- MICmdArgValFile.h ---------------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgValFile.h | ||
| // | ||
| // Overview: CMICmdArgValFile interface. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| #pragma once | ||
|
|
||
| // In-house headers: | ||
| #include "MICmdArgValBase.h" | ||
|
|
||
| // Declarations: | ||
| class CMICmdArgContext; | ||
|
|
||
| //++ ============================================================================ | ||
| // Details: MI common code class. Command argument class. Arguments object | ||
| // needing specialization derived from the CMICmdArgValBase class. | ||
| // An argument knows what type of argument it is and how it is to | ||
| // interpret the options (context) string to find and validate a matching | ||
| // argument and so extract a value from it . | ||
| // Based on the Interpreter pattern. | ||
| // Gotchas: None. | ||
| // Authors: Illya Rudkin 15/04/2014. | ||
| // Changes: None. | ||
| //-- | ||
| class CMICmdArgValFile : public CMICmdArgValBaseTemplate< CMIUtilString > | ||
| { | ||
| // Methods: | ||
| public: | ||
| /* ctor */ CMICmdArgValFile( void ); | ||
| /* ctor */ CMICmdArgValFile( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd ); | ||
| // | ||
| bool IsFilePath( const CMIUtilString & vrFileNamePath ) const; | ||
| CMIUtilString GetFileNamePath( const CMIUtilString & vrTxt ) const; | ||
|
|
||
| // Overridden: | ||
| public: | ||
| // From CMICmdArgValBase | ||
| /* dtor */ virtual ~CMICmdArgValFile( void ); | ||
| // From CMICmdArgSet::IArg | ||
| virtual bool Validate( CMICmdArgContext & vwArgContext ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| //===-- MICmdArgValListBase.cpp ---------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgValListBase.cpp | ||
| // | ||
| // Overview: CMICmdArgValListBase implementation. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| // In-house headers: | ||
| #include "MICmdArgValListBase.h" | ||
| #include "MICmdArgContext.h" | ||
| #include "MICmdArgValFile.h" | ||
| #include "MICmdArgValNumber.h" | ||
| #include "MICmdArgValOptionLong.h" | ||
| #include "MICmdArgValOptionShort.h" | ||
| #include "MICmdArgValString.h" | ||
| #include "MICmdArgValThreadGrp.h" | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValListBase constructor. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValListBase::CMICmdArgValListBase( void ) | ||
| : m_eArgType( eArgValType_invalid ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValListBase constructor. | ||
| // Type: Method. | ||
| // Args: vrArgName - (R) Argument's name to search by. | ||
| // vbMandatory - (R) True = Yes must be present, false = optional argument. | ||
| // vbHandleByCmd - (R) True = Command processes *this option, false = not handled. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValListBase::CMICmdArgValListBase( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd ) | ||
| : CMICmdArgValBaseTemplate( vrArgName, vbMandatory, vbHandleByCmd ) | ||
| , m_eArgType( eArgValType_invalid ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValListBase constructor. | ||
| // Type: Method. | ||
| // Args: vrArgName - (R) Argument's name to search by. | ||
| // vbMandatory - (R) True = Yes must be present, false = optional argument. | ||
| // vbHandleByCmd - (R) True = Command processes *this option, false = not handled. | ||
| // veType - (R) The type of argument to look for and create argument object of a certain type. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValListBase::CMICmdArgValListBase( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd, const ArgValType_e veType ) | ||
| : CMICmdArgValBaseTemplate( vrArgName, vbMandatory, vbHandleByCmd ) | ||
| , m_eArgType( veType ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValListBase destructor. | ||
| // Type: Overidden. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValListBase::~CMICmdArgValListBase( void ) | ||
| { | ||
| // Tidy up | ||
| Destroy(); | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Tear down resources used by *this object. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| void CMICmdArgValListBase::Destroy( void ) | ||
| { | ||
| // Tidy up | ||
| VecArgObjPtr_t::const_iterator it = m_argValue.begin(); | ||
| while( it != m_argValue.end() ) | ||
| { | ||
| CMICmdArgValBase * pArgObj = *it; | ||
| delete pArgObj; | ||
|
|
||
| // Next | ||
| ++it; | ||
| } | ||
| m_argValue.clear(); | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Create an CMICmdArgValBase derived object matching the type specified | ||
| // and put the option or argument's value inside it. | ||
| // Type: Method. | ||
| // Args: vrTxt - (R) Text version the option or argument. | ||
| // veType - (R) The type of argument or option object to create. | ||
| // Return: CMICmdArgValBase * - Option object holding the value. | ||
| // - NULL = Functional failed. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValBase * CMICmdArgValListBase::CreationObj( const CMIUtilString & vrTxt, const ArgValType_e veType ) const | ||
| { | ||
| CMICmdArgValBase * pOptionObj = nullptr; | ||
| switch( veType ) | ||
| { | ||
| case eArgValType_File: | ||
| pOptionObj = new CMICmdArgValFile(); | ||
| break; | ||
| case eArgValType_Number: | ||
| pOptionObj = new CMICmdArgValNumber(); | ||
| break; | ||
| case eArgValType_OptionLong: | ||
| pOptionObj = new CMICmdArgValOptionLong(); | ||
| break; | ||
| case eArgValType_OptionShort: | ||
| pOptionObj = new CMICmdArgValOptionShort(); | ||
| break; | ||
| case eArgValType_String: | ||
| pOptionObj = new CMICmdArgValString(); | ||
| break; | ||
| case eArgValType_ThreadGrp: | ||
| pOptionObj = new CMICmdArgValThreadGrp(); | ||
| break; | ||
| default: | ||
| return nullptr; | ||
| } | ||
|
|
||
| CMICmdArgContext argCntxt( vrTxt ); | ||
| if( !pOptionObj->Validate( argCntxt ) ) | ||
| return nullptr; | ||
|
|
||
| return pOptionObj; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Validate the option or argument is the correct type. | ||
| // Type: Method. | ||
| // Args: vrTxt - (R) Text version the option or argument. | ||
| // veType - (R) The type of value to expect. | ||
| // Return: bool - True = Yes expected type present, False = no. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValListBase::IsExpectedCorrectType( const CMIUtilString & vrTxt, const ArgValType_e veType ) const | ||
| { | ||
| bool bValid = false; | ||
| switch( veType ) | ||
| { | ||
| case eArgValType_File: | ||
| bValid = CMICmdArgValFile().IsFilePath( vrTxt ); | ||
| break; | ||
| case eArgValType_Number: | ||
| bValid = CMICmdArgValNumber().IsArgNumber( vrTxt ); | ||
| break; | ||
| case eArgValType_OptionLong: | ||
| bValid = CMICmdArgValOptionLong().IsArgLongOption( vrTxt ); | ||
| break; | ||
| case eArgValType_OptionShort: | ||
| bValid = CMICmdArgValOptionShort().IsArgShortOption( vrTxt ); | ||
| break; | ||
| case eArgValType_String: | ||
| bValid = CMICmdArgValString().IsStringArg( vrTxt ); | ||
| break; | ||
| case eArgValType_ThreadGrp: | ||
| bValid = CMICmdArgValThreadGrp().IsArgThreadGrp( vrTxt ); | ||
| break; | ||
| default: | ||
| return false; | ||
| } | ||
|
|
||
| return bValid; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| //===-- MICmdArgValListBase.h -----------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgValListBase.h | ||
| // | ||
| // Overview: CMICmdArgValListBase interface. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| #pragma once | ||
|
|
||
| // Third party headers: | ||
| #include <vector> | ||
|
|
||
| // In-house headers: | ||
| #include "MICmdArgValBase.h" | ||
|
|
||
| // Declarations: | ||
| class CMICmdArgContext; | ||
|
|
||
| //++ ============================================================================ | ||
| // Details: MI common code class. Command argument with addition options class. | ||
| // For example --recurse 1 2 4 [group ...]. Arguments object that | ||
| // require a list of options associated with them derive from the | ||
| // CMICmdArgValListBase class. Additional options are also extracted from | ||
| // the command arguments text string. | ||
| // An argument knows what type of argument it is and how it is to | ||
| // interpret the options (context) string to find and validate a matching | ||
| // options and so extract a values from it . | ||
| // The CMICmdArgValBase objects are added to the derived argument class's | ||
| // container. The option arguments belong to that derived class and will | ||
| // be deleted that object goes out of scope. | ||
| // Based on the Interpreter pattern. | ||
| // Gotchas: None. | ||
| // Authors: Illya Rudkin 16/04/2014. | ||
| // Changes: None. | ||
| //-- | ||
| class CMICmdArgValListBase : public CMICmdArgValBaseTemplate< std::vector< CMICmdArgValBase * > > | ||
| { | ||
| // Typedef: | ||
| public: | ||
| typedef std::vector< CMICmdArgValBase * > VecArgObjPtr_t; | ||
|
|
||
| // Enums: | ||
| public: | ||
| //++ --------------------------------------------------------------------------------- | ||
| // Details: CMICmdArgValListBase needs to know what type of argument to look for in | ||
| // the command options text. It also needs to create argument objects of | ||
| // a specific type. | ||
| //-- | ||
| enum ArgValType_e | ||
| { | ||
| eArgValType_File = 0, | ||
| eArgValType_Number, | ||
| eArgValType_OptionLong, | ||
| eArgValType_OptionShort, | ||
| eArgValType_String, | ||
| eArgValType_ThreadGrp, | ||
| eArgValType_count, // Always the last one | ||
| eArgValType_invalid | ||
| }; | ||
|
|
||
| // Methods: | ||
| public: | ||
| /* ctor */ CMICmdArgValListBase( void ); | ||
| /* ctor */ CMICmdArgValListBase( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd ); | ||
| /* ctor */ CMICmdArgValListBase( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd, const ArgValType_e veType ); | ||
|
|
||
| // Overridden: | ||
| public: | ||
| // From CMICmdArgValBase | ||
| /* dtor */ virtual ~CMICmdArgValListBase( void ); | ||
|
|
||
| // Methods: | ||
| protected: | ||
| bool IsExpectedCorrectType( const CMIUtilString & vrTxt, const ArgValType_e veType ) const; | ||
| CMICmdArgValBase * CreationObj( const CMIUtilString & vrTxt, const ArgValType_e veType ) const; | ||
|
|
||
| // Attributes: | ||
| protected: | ||
| ArgValType_e m_eArgType; | ||
|
|
||
| // Methods: | ||
| private: | ||
| void Destroy( void ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| //===-- MICmdArgValListOfN.cpp ----------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgValListOfN.cpp | ||
| // | ||
| // Overview: CMICmdArgValListOfN implementation. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| // In-house headers: | ||
| #include "MICmdArgValListOfN.h" | ||
| #include "MICmdArgContext.h" | ||
| #include "MICmdArgValFile.h" | ||
| #include "MICmdArgValNumber.h" | ||
| #include "MICmdArgValOptionLong.h" | ||
| #include "MICmdArgValOptionShort.h" | ||
| #include "MICmdArgValString.h" | ||
| #include "MICmdArgValThreadGrp.h" | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValListOfN constructor. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValListOfN::CMICmdArgValListOfN( void ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValListOfN constructor. | ||
| // Type: Method. | ||
| // Args: vrArgName - (R) Argument's name to search by. | ||
| // vbMandatory - (R) True = Yes must be present, false = optional argument. | ||
| // vbHandleByCmd - (R) True = Command processes *this option, false = not handled. | ||
| // veType - (R) The type of argument to look for and create argument object of a certain type. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValListOfN::CMICmdArgValListOfN( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd, const ArgValType_e veType ) | ||
| : CMICmdArgValListBase( vrArgName, vbMandatory, vbHandleByCmd, veType ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValListOfN destructor. | ||
| // Type: Overidden. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValListOfN::~CMICmdArgValListOfN( void ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Parse the command's argument options string and try to extract the list of | ||
| // arguments based on the argument object type to look for. | ||
| // Type: Overridden. | ||
| // Args: vwArgContext - (RW) The command's argument options string. | ||
| // Return: MIstatus::success - Functional succeeded. | ||
| // MIstatus::failure - Functional failed. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValListOfN::Validate( CMICmdArgContext & vwArgContext ) | ||
| { | ||
| if( m_eArgType >= eArgValType_count ) | ||
| { | ||
| m_eArgType = eArgValType_invalid; | ||
| return MIstatus::failure; | ||
| } | ||
|
|
||
| if( vwArgContext.IsEmpty() ) | ||
| return MIstatus::success; | ||
|
|
||
| const CMIUtilString & rArg( vwArgContext.GetArgsLeftToParse() ); | ||
| if( IsListOfN( rArg ) && CreateList( rArg ) ) | ||
| { | ||
| m_bFound = true; | ||
| m_bValid = true; | ||
| vwArgContext.RemoveArg( rArg ); | ||
| return MIstatus::success; | ||
| } | ||
| else | ||
| return MIstatus::failure; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Create list of argument objects each holding a value extract from the command | ||
| // options line. | ||
| // Type: Method. | ||
| // Args: vrTxt - (R) Some options text. | ||
| // Return: bool - True = yes valid arg, false = no. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValListOfN::CreateList( const CMIUtilString & vrTxt ) | ||
| { | ||
| CMIUtilString::VecString_t vecOptions; | ||
| vrTxt.Split( " ", vecOptions ); | ||
| CMIUtilString::VecString_t::const_iterator it = vecOptions.begin(); | ||
| while( it != vecOptions.end() ) | ||
| { | ||
| const CMIUtilString & rOption = *it; | ||
| CMICmdArgValBase * pOption = CreationObj( rOption, m_eArgType ); | ||
| if( pOption != nullptr ) | ||
| m_argValue.push_back( pOption ); | ||
| else | ||
| return MIstatus::failure; | ||
|
|
||
| // Next | ||
| ++it; | ||
| } | ||
|
|
||
| return MIstatus::success; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Examine the string and determine if it is a valid string type argument. | ||
| // Type: Method. | ||
| // Args: vrTxt - (R) Some text. | ||
| // Return: bool - True = yes valid arg, false = no. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValListOfN::IsListOfN( const CMIUtilString & vrTxt ) const | ||
| { | ||
| CMIUtilString::VecString_t vecOptions; | ||
| if( vrTxt.Split( " ", vecOptions ) == 0 ) | ||
| return false; | ||
|
|
||
| CMIUtilString::VecString_t::const_iterator it = vecOptions.begin(); | ||
| while( it != vecOptions.end() ) | ||
| { | ||
| const CMIUtilString & rOption = *it; | ||
| if( !IsExpectedCorrectType( rOption, m_eArgType ) ) | ||
| break; | ||
|
|
||
| // Next | ||
| ++it; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve the list of CMICmdArgValBase derived option objects found following | ||
| // *this long option argument. For example "list-thread-groups [ --recurse 1 ]" | ||
| // where 1 is the list of expected option to follow. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: CMICmdArgValListBase::VecArgObjPtr_t & - List of options. | ||
| // Throws: None. | ||
| //-- | ||
| const CMICmdArgValListBase::VecArgObjPtr_t & CMICmdArgValListOfN::GetExpectedOptions( void ) const | ||
| { | ||
| return m_argValue; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| //===-- MICmdArgValListOfN.h ------------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgValListOfN.h | ||
| // | ||
| // Overview: CMICmdArgValListOfN interface. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| #pragma once | ||
|
|
||
| // Third party headers: | ||
| #include <vector> | ||
|
|
||
| // In-house headers: | ||
| #include "MICmdArgValListBase.h" | ||
|
|
||
| // Declarations: | ||
| class CMICmdArgContext; | ||
|
|
||
| //++ ============================================================================ | ||
| // Details: MI common code class. Command argument class. Arguments object | ||
| // needing specialization derived from the CMICmdArgValBase class. | ||
| // An argument knows what type of argument it is and how it is to | ||
| // interpret the options (context) string to find and validate a matching | ||
| // argument and so extract a value from it . | ||
| // The CMICmdArgValBase objects added to *this ListOfN container belong | ||
| // to this container and will be deleted when *this object goes out of | ||
| // scope. | ||
| // To parse arguments like 'thread-id ...' i.e. 1 10 12 13 ... | ||
| // If vbMandatory argument is true it takes on the (...)+ specfication | ||
| // otherwise assumed to be (...)* specification. | ||
| // Based on the Interpreter pattern. | ||
| // Gotchas: None. | ||
| // Authors: Illya Rudkin 16/04/2014. | ||
| // Changes: None. | ||
| //-- | ||
| class CMICmdArgValListOfN : public CMICmdArgValListBase | ||
| { | ||
| // Methods: | ||
| public: | ||
| /* ctor */ CMICmdArgValListOfN( void ); | ||
| /* ctor */ CMICmdArgValListOfN( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd, const ArgValType_e veType ); | ||
| // | ||
| const VecArgObjPtr_t & GetExpectedOptions( void ) const; | ||
| template< class T1, typename T2 > | ||
| bool GetExpectedOption( T2 & vrwValue ) const; | ||
|
|
||
| // Overridden: | ||
| public: | ||
| // From CMICmdArgValBase | ||
| /* dtor */ virtual ~CMICmdArgValListOfN( void ); | ||
| // From CMICmdArgSet::IArg | ||
| virtual bool Validate( CMICmdArgContext & vArgContext ); | ||
|
|
||
| // Methods: | ||
| private: | ||
| bool IsListOfN( const CMIUtilString & vrTxt ) const; | ||
| bool CreateList( const CMIUtilString & vrTxt ); | ||
| }; | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve the first argument or option value from the list of 1 or more options | ||
| // parsed from the command's options string. | ||
| // Type: Template method. | ||
| // Args: vrwValue - (W) Templated type return value. | ||
| // Return: MIstatus::success - Functional succeeded. | ||
| // MIstatus::failure - Functional failed. List of object was empty. | ||
| // Throws: None. | ||
| //-- | ||
| template< class T1, typename T2 > | ||
| bool CMICmdArgValListOfN::GetExpectedOption( T2 & vrwValue ) const | ||
| { | ||
| const VecArgObjPtr_t & rVecOptions( GetExpectedOptions() ); | ||
| VecArgObjPtr_t::const_iterator it2 = rVecOptions.begin(); | ||
| if( it2 != rVecOptions.end() ) | ||
| { | ||
| const T1 * pOption = static_cast< T1 * >( *it2 ); | ||
| vrwValue = pOption->GetValue(); | ||
| return MIstatus::success; | ||
| } | ||
|
|
||
| return MIstatus::failure; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| //===-- MICmdArgValNumber.cpp -----------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgValNumber.cpp | ||
| // | ||
| // Overview: CMICmdArgValNumber implementation. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| // In-house headers: | ||
| #include "MICmdArgValNumber.h" | ||
| #include "MICmdArgContext.h" | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValNumber constructor. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValNumber::CMICmdArgValNumber( void ) | ||
| : m_nNumber( 0 ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValNumber constructor. | ||
| // Type: Method. | ||
| // Args: vrArgName - (R) Argument's name to search by. | ||
| // vbMandatory - (R) True = Yes must be present, false = optional argument. | ||
| // vbHandleByCmd - (R) True = Command processes *this option, false = not handled. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValNumber::CMICmdArgValNumber( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd ) | ||
| : CMICmdArgValBaseTemplate( vrArgName, vbMandatory, vbHandleByCmd ) | ||
| , m_nNumber( 0 ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValNumber destructor. | ||
| // Type: Overidden. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValNumber::~CMICmdArgValNumber( void ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Parse the command's argument options string and try to extract the value *this | ||
| // argument is looking for. | ||
| // Type: Overridden. | ||
| // Args: vwArgContext - (RW) The command's argument options string. | ||
| // Return: MIstatus::success - Functional succeeded. | ||
| // MIstatus::failure - Functional failed. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValNumber::Validate( CMICmdArgContext & vwArgContext ) | ||
| { | ||
| if( vwArgContext.IsEmpty() ) | ||
| return MIstatus::success; | ||
|
|
||
| if( vwArgContext.GetNumberArgsPresent() == 1 ) | ||
| { | ||
| const CMIUtilString & rArg( vwArgContext.GetArgsLeftToParse() ); | ||
| if( IsArgNumber( rArg ) && ExtractNumber( rArg ) ) | ||
| { | ||
| m_bFound = true; | ||
| m_bValid = true; | ||
| m_argValue = GetNumber(); | ||
| vwArgContext.RemoveArg( rArg ); | ||
| return MIstatus::success; | ||
| } | ||
| else | ||
| return MIstatus::failure; | ||
| } | ||
|
|
||
| // More than one option... | ||
| const CMIUtilString::VecString_t vecOptions( vwArgContext.GetArgs() ); | ||
| CMIUtilString::VecString_t::const_iterator it = vecOptions.begin(); | ||
| while( it != vecOptions.end() ) | ||
| { | ||
| const CMIUtilString & rArg( *it ); | ||
| if( IsArgNumber( rArg ) && ExtractNumber( rArg ) ) | ||
| { | ||
| m_bFound = true; | ||
|
|
||
| if( vwArgContext.RemoveArg( rArg ) ) | ||
| { | ||
| m_bValid = true; | ||
| m_argValue = GetNumber(); | ||
| return MIstatus::success; | ||
| } | ||
| else | ||
| return MIstatus::failure; | ||
| } | ||
|
|
||
| // Next | ||
| ++it; | ||
| } | ||
|
|
||
| return MIstatus::failure; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Examine the string and determine if it is a valid string type argument. | ||
| // Type: Method. | ||
| // Args: vrTxt - (R) Some text. | ||
| // Return: bool - True = yes valid arg, false = no. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValNumber::IsArgNumber( const CMIUtilString & vrTxt ) const | ||
| { | ||
| return vrTxt.IsNumber(); | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Extract the thread group number from the thread group argument. | ||
| // Type: Method. | ||
| // Args: vrTxt - (R) Some text. | ||
| // Return: MIstatus::success - Functional succeeded. | ||
| // MIstatus::failure - Functional failed. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValNumber::ExtractNumber( const CMIUtilString & vrTxt ) | ||
| { | ||
| MIint64 nNumber = 0; | ||
| bool bOk = vrTxt.ExtractNumber( nNumber ); | ||
| if( bOk ) | ||
| { | ||
| m_nNumber = static_cast< MIint >( nNumber ); | ||
| } | ||
|
|
||
| return bOk; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve the thread group ID found in the argument. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: MIuint - Thread group ID. | ||
| // Throws: None. | ||
| //-- | ||
| MIint64 CMICmdArgValNumber::GetNumber( void ) const | ||
| { | ||
| return m_nNumber; | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| //===-- MICmdArgValNumber.h -------------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgValNumber.h | ||
| // | ||
| // Overview: CMICmdArgValNumber interface. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| #pragma once | ||
|
|
||
| // In-house headers: | ||
| #include "MICmdArgValBase.h" | ||
|
|
||
| // Declarations: | ||
| class CMICmdArgContext; | ||
|
|
||
| //++ ============================================================================ | ||
| // Details: MI common code class. Command argument class. Arguments object | ||
| // needing specialization derived from the CMICmdArgValBase class. | ||
| // An argument knows what type of argument it is and how it is to | ||
| // interpret the options (context) string to find and validate a matching | ||
| // argument and so extract a value from it . | ||
| // Based on the Interpreter pattern. | ||
| // Gotchas: None. | ||
| // Authors: Illya Rudkin 14/04/2014. | ||
| // Changes: None. | ||
| //-- | ||
| class CMICmdArgValNumber : public CMICmdArgValBaseTemplate< MIint64 > | ||
| { | ||
| // Methods: | ||
| public: | ||
| /* ctor */ CMICmdArgValNumber( void ); | ||
| /* ctor */ CMICmdArgValNumber( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd ); | ||
| // | ||
| bool IsArgNumber( const CMIUtilString & vrTxt ) const; | ||
|
|
||
| // Overridden: | ||
| public: | ||
| // From CMICmdArgValBase | ||
| /* dtor */ virtual ~CMICmdArgValNumber( void ); | ||
| // From CMICmdArgSet::IArg | ||
| virtual bool Validate( CMICmdArgContext & vwArgContext ); | ||
|
|
||
| // Methods: | ||
| private: | ||
| bool ExtractNumber( const CMIUtilString & vrTxt ); | ||
| MIint64 GetNumber( void ) const; | ||
|
|
||
| // Attributes: | ||
| private: | ||
| MIint64 m_nNumber; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,304 @@ | ||
| //===-- MICmdArgValOptionLong.cpp -------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgValOptionLong.cpp | ||
| // | ||
| // Overview: CMICmdArgValOptionLong implementation. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| // In-house headers: | ||
| #include "MICmdArgValOptionLong.h" | ||
| #include "MICmdArgContext.h" | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValOptionLong constructor. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValOptionLong::CMICmdArgValOptionLong( void ) | ||
| : m_nExpectingNOptions( 0 ) | ||
| , m_eExpectingOptionType( eArgValType_invalid ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValOptionLong constructor. | ||
| // Type: Method. | ||
| // Args: vrArgName - (R) Argument's name to search by. | ||
| // vbMandatory - (R) True = Yes must be present, false = optional argument. | ||
| // vbHandleByCmd - (R) True = Command processes *this option, false = not handled. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValOptionLong::CMICmdArgValOptionLong( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd ) | ||
| : CMICmdArgValListBase( vrArgName, vbMandatory, vbHandleByCmd ) | ||
| , m_nExpectingNOptions( 0 ) | ||
| , m_eExpectingOptionType( eArgValType_invalid ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValOptionLong constructor. | ||
| // Type: Method. | ||
| // Args: vrArgName - (R) Argument's name to search by. | ||
| // vbMandatory - (R) True = Yes must be present, false = optional argument. | ||
| // vbHandleByCmd - (R) True = Command processes *this option, false = not handled. | ||
| // veType - (R) The type of argument to look for and create argument object of a certain type. | ||
| // vnExpectingNOptions - (R) The number of options expected to read following *this argument. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValOptionLong::CMICmdArgValOptionLong( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd, const ArgValType_e veType, const MIuint vnExpectingNOptions ) | ||
| : CMICmdArgValListBase( vrArgName, vbMandatory, vbHandleByCmd ) | ||
| , m_nExpectingNOptions( vnExpectingNOptions ) | ||
| , m_eExpectingOptionType( veType ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValOptionLong destructor. | ||
| // Type: Overidden. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValOptionLong::~CMICmdArgValOptionLong( void ) | ||
| { | ||
| // Tidy up | ||
| Destroy(); | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Tear down resources used by *this object. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| void CMICmdArgValOptionLong::Destroy( void ) | ||
| { | ||
| // Tidy up | ||
| VecArgObjPtr_t::const_iterator it = m_vecArgsExpected.begin(); | ||
| while( it != m_vecArgsExpected.end() ) | ||
| { | ||
| CMICmdArgValBase * pOptionObj = *it; | ||
| delete pOptionObj; | ||
|
|
||
| // Next | ||
| ++it; | ||
| } | ||
| m_vecArgsExpected.clear(); | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Parse the command's argument options string and try to extract the long | ||
| // arguemnt *this argument type is looking for. | ||
| // Type: Overridden. | ||
| // Args: vwArgContext - (RW) The command's argument options string. | ||
| // Return: MIstatus::success - Functional succeeded. | ||
| // MIstatus::failure - Functional failed. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValOptionLong::Validate( CMICmdArgContext & vwArgContext ) | ||
| { | ||
| if( vwArgContext.IsEmpty() ) | ||
| return MIstatus::success; | ||
|
|
||
| if( vwArgContext.GetNumberArgsPresent() == 1 ) | ||
| { | ||
| const CMIUtilString & rArg( vwArgContext.GetArgsLeftToParse() ); | ||
| if( IsArgLongOption( rArg ) && ArgNameMatch( rArg ) ) | ||
| { | ||
| m_bFound = true; | ||
|
|
||
| if( !vwArgContext.RemoveArg( rArg ) ) | ||
| return MIstatus::failure; | ||
|
|
||
| if( m_nExpectingNOptions == 0 ) | ||
| { | ||
| m_bValid = true; | ||
| return MIstatus::success; | ||
| } | ||
|
|
||
| m_bIsMissingOptions = true; | ||
| return MIstatus::failure; | ||
| } | ||
| else | ||
| return MIstatus::failure; | ||
| } | ||
|
|
||
| // More than one option... | ||
| const CMIUtilString::VecString_t vecOptions( vwArgContext.GetArgs() ); | ||
| CMIUtilString::VecString_t::const_iterator it = vecOptions.begin(); | ||
| while( it != vecOptions.end() ) | ||
| { | ||
| const CMIUtilString & rArg( *it ); | ||
| if( IsArgOptionCorrect( rArg ) && ArgNameMatch( rArg ) ) | ||
| { | ||
| m_bFound = true; | ||
|
|
||
| if( !vwArgContext.RemoveArg( rArg ) ) | ||
| return MIstatus::failure; | ||
|
|
||
| if( m_nExpectingNOptions != 0 ) | ||
| { | ||
| if( ExtractExpectedOptions( vwArgContext ) ) | ||
| { | ||
| m_bValid = true; | ||
| return MIstatus::success; | ||
| } | ||
|
|
||
| m_bIsMissingOptions = true; | ||
| return MIstatus::failure; | ||
| } | ||
| else | ||
| { | ||
| m_bValid = true; | ||
| return MIstatus::success; | ||
| } | ||
| } | ||
|
|
||
| // Next | ||
| ++it; | ||
| } | ||
|
|
||
| return MIstatus::failure; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Parse the text following *this argument and extract the options the values of | ||
| // CMICmdArgValListBase::m_eArgType forming argument objects for each of those | ||
| // options extracted. | ||
| // Type: Method. | ||
| // Args: vrwTxt - (RW) The command's argument options string. | ||
| // Return: MIstatus::success - Functional succeeded. | ||
| // MIstatus::failure - Functional failed. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValOptionLong::ExtractExpectedOptions( CMICmdArgContext & vrwTxt ) | ||
| { | ||
| CMIUtilString::VecString_t vecOptions; | ||
| const MIuint nOptionsPresent = vrwTxt.GetArgsLeftToParse().Split( " ", vecOptions ); | ||
| if( nOptionsPresent == 0 ) | ||
| return MIstatus::failure; | ||
|
|
||
| MIuint nTypeCnt = 0; | ||
| MIuint nTypeCnt2 = 0; | ||
| MIuint nFoundNOptionsCnt = 0; | ||
| CMIUtilString::VecString_t::const_iterator it = vecOptions.begin(); | ||
| while( it != vecOptions.end() ) | ||
| { | ||
| nTypeCnt++; | ||
| const CMIUtilString & rOption( *it ); | ||
| if( IsExpectedCorrectType( rOption, m_eExpectingOptionType ) ) | ||
| { | ||
| nTypeCnt2++; | ||
| CMICmdArgValBase * pOptionObj = CreationObj( rOption, m_eExpectingOptionType ); | ||
| if( (pOptionObj != nullptr) && vrwTxt.RemoveArg( rOption ) ) | ||
| { | ||
| nFoundNOptionsCnt++; | ||
| m_vecArgsExpected.push_back( pOptionObj ); | ||
| } | ||
| } | ||
| // Is the sequence 'options' of same type broken. Expecting the same type until the | ||
| // next argument. | ||
| if( nTypeCnt != nTypeCnt2 ) | ||
| return MIstatus::failure; | ||
|
|
||
| if( nFoundNOptionsCnt == m_nExpectingNOptions ) | ||
| return MIstatus::success; | ||
|
|
||
| // Next | ||
| ++it; | ||
| } | ||
| if( nFoundNOptionsCnt != m_nExpectingNOptions ) | ||
| return MIstatus::failure; | ||
|
|
||
| return MIstatus::success; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Examine the string and determine if it is a valid long type option argument. | ||
| // Long type argument looks like --someLongOption. | ||
| // Type: Method. | ||
| // Args: vrTxt - (R) Some text. | ||
| // Return: bool - True = yes valid arg, false = no. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValOptionLong::IsArgLongOption( const CMIUtilString & vrTxt ) const | ||
| { | ||
| const bool bHavePosSlash = (vrTxt.find_first_of( "/" ) != std::string::npos); | ||
| const bool bHaveBckSlash = (vrTxt.find_first_of( "\\" ) != std::string::npos); | ||
| if( bHavePosSlash || bHaveBckSlash ) | ||
| return false; | ||
|
|
||
| const MIint nPos = vrTxt.find_first_of( "--" ); | ||
| if( nPos != 0 ) | ||
| return false; | ||
|
|
||
| if( vrTxt.length() < 3 ) | ||
| return false; | ||
|
|
||
| const CMIUtilString strArg = vrTxt.substr( 2 ).c_str(); | ||
| if( strArg.IsNumber() ) | ||
| return false; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Examine the string and determine if it is a valid long type option argument. | ||
| // Long type argument looks like --someLongOption. | ||
| // Type: Overideable. | ||
| // Args: vrTxt - (R) Some text. | ||
| // Return: bool - True = yes valid arg, false = no. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValOptionLong::IsArgOptionCorrect( const CMIUtilString & vrTxt ) const | ||
| { | ||
| return IsArgLongOption( vrTxt ); | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Does the argument name of the argument being parsed ATM match the name of | ||
| // *this argument object. | ||
| // Type: Method. | ||
| // Args: vrTxt - (R) Some text. | ||
| // Return: bool - True = yes arg name matched, false = no. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValOptionLong::ArgNameMatch( const CMIUtilString & vrTxt ) const | ||
| { | ||
| const CMIUtilString strArg = vrTxt.substr( 2 ).c_str(); | ||
| return (strArg == GetName() ); | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve the list of CMICmdArgValBase derived option objects found following | ||
| // *this long option argument. For example "list-thread-groups [ --recurse 1 ]" | ||
| // where 1 is the list of expected option to follow. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: CMICmdArgValListBase::VecArgObjPtr_t & - List of options. | ||
| // Throws: None. | ||
| //-- | ||
| const CMICmdArgValListBase::VecArgObjPtr_t & CMICmdArgValOptionLong::GetExpectedOptions( void ) const | ||
| { | ||
| return m_vecArgsExpected; | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| //===-- MICmdArgValOptionLong.h ---------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgValOptionLong.h | ||
| // | ||
| // Overview: CMICmdArgValOptionLong interface. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| #pragma once | ||
|
|
||
| // In-house headers: | ||
| #include "MICmdArgValListBase.h" | ||
|
|
||
| // Declarations: | ||
| class CMICmdArgContext; | ||
| class CMIUtilString; | ||
|
|
||
| //++ ============================================================================ | ||
| // Details: MI common code class. Command argument class. Arguments object | ||
| // needing specialization derived from the CMICmdArgValBase class. | ||
| // An argument knows what type of argument it is and how it is to | ||
| // interpret the options (context) string to find and validate a matching | ||
| // argument and so extract a value from it. | ||
| // If *this argument has expected options following it the option objects | ||
| // created to hold each of those option's values belong to *this argument | ||
| // object and so are deleted when *this object goes out of scope. | ||
| // Based on the Interpreter pattern. | ||
| // Gotchas: None. | ||
| // Authors: Illya Rudkin 16/04/2014. | ||
| // Changes: None. | ||
| //-- | ||
| class CMICmdArgValOptionLong : public CMICmdArgValListBase | ||
| { | ||
| // Methods: | ||
| public: | ||
| /* ctor */ CMICmdArgValOptionLong( void ); | ||
| /* ctor */ CMICmdArgValOptionLong( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd ); | ||
| /* ctor */ CMICmdArgValOptionLong( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd, const ArgValType_e veType, const MIuint vnExpectingNOptions ); | ||
| // | ||
| bool IsArgLongOption( const CMIUtilString & vrTxt ) const; | ||
| const VecArgObjPtr_t & GetExpectedOptions( void ) const; | ||
| template< class T1, typename T2 > | ||
| bool GetExpectedOption( T2 & vrwValue ) const; | ||
|
|
||
| // Overridden: | ||
| public: | ||
| // From CMICmdArgValBase | ||
| /* dtor */ virtual ~CMICmdArgValOptionLong( void ); | ||
| // From CMICmdArgSet::IArg | ||
| virtual bool Validate( CMICmdArgContext & vArgContext ); | ||
|
|
||
| // Methods: | ||
| protected: | ||
| bool ExtractExpectedOptions( CMICmdArgContext & vrwTxt ); | ||
|
|
||
| // Overrideable: | ||
| protected: | ||
| virtual bool IsArgOptionCorrect( const CMIUtilString & vrTxt ) const; | ||
| virtual bool ArgNameMatch( const CMIUtilString & vrTxt ) const; | ||
|
|
||
| // Methods: | ||
| private: | ||
| void Destroy( void ); | ||
|
|
||
| // Attributes: | ||
| private: | ||
| MIuint m_nExpectingNOptions; // The number of options expected to read following *this argument | ||
| VecArgObjPtr_t m_vecArgsExpected; // The option objects holding the value extracted following *this argument | ||
| ArgValType_e m_eExpectingOptionType; // The type of options expected to read following *this argument | ||
| }; | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Retrieve the first argument or option value from the list of 1 or more options | ||
| // parsed from the command's options string. | ||
| // Type: Template method. | ||
| // Args: vrwValue - (W) Templated type return value. | ||
| // Return: MIstatus::success - Functional succeeded. | ||
| // MIstatus::failure - Functional failed. List of object was empty. | ||
| // Throws: None. | ||
| //-- | ||
| template< class T1, typename T2 > | ||
| bool CMICmdArgValOptionLong::GetExpectedOption( T2 & vrwValue ) const | ||
| { | ||
| const VecArgObjPtr_t & rVecOptions( GetExpectedOptions() ); | ||
| VecArgObjPtr_t::const_iterator it2 = rVecOptions.begin(); | ||
| if( it2 != rVecOptions.end() ) | ||
| { | ||
| const T1 * pOption = static_cast< T1 * >( *it2 ); | ||
| vrwValue = pOption->GetValue(); | ||
| return MIstatus::success; | ||
| } | ||
|
|
||
| return MIstatus::failure; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| //===-- MICmdArgValOptionShort.cpp ------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgValOptionShort.cpp | ||
| // | ||
| // Overview: CMICmdArgValOptionShort implementation. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| // In-house headers: | ||
| #include "MICmdArgValOptionShort.h" | ||
| #include "MICmdArgContext.h" | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValOptionShort constructor. | ||
| // Type: Method. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValOptionShort::CMICmdArgValOptionShort( void ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValOptionShort constructor. | ||
| // Type: Method. | ||
| // Args: vrArgName - (R) Argument's name to search by. | ||
| // vbMandatory - (R) True = Yes must be present, false = optional argument. | ||
| // vbHandleByCmd - (R) True = Command processes *this option, false = not handled. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValOptionShort::CMICmdArgValOptionShort( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd ) | ||
| : CMICmdArgValOptionLong( vrArgName, vbMandatory, vbHandleByCmd ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValOptionLong constructor. | ||
| // Type: Method. | ||
| // Args: vrArgName - (R) Argument's name to search by. | ||
| // vbMandatory - (R) True = Yes must be present, false = optional argument. | ||
| // vbHandleByCmd - (R) True = Command processes *this option, false = not handled. | ||
| // veType - (R) The type of argument to look for and create argument object of a certain type. | ||
| // vnExpectingNOptions - (R) The number of options expected to read following *this argument. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValOptionShort::CMICmdArgValOptionShort( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd, const ArgValType_e veType, const MIuint vnExpectingNOptions ) | ||
| : CMICmdArgValOptionLong( vrArgName, vbMandatory, vbHandleByCmd, veType, vnExpectingNOptions ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: CMICmdArgValOptionShort destructor. | ||
| // Type: Overidden. | ||
| // Args: None. | ||
| // Return: None. | ||
| // Throws: None. | ||
| //-- | ||
| CMICmdArgValOptionShort::~CMICmdArgValOptionShort( void ) | ||
| { | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Examine the string and determine if it is a valid short type option argument. | ||
| // Type: Method. | ||
| // Args: vrTxt - (R) Some text. | ||
| // Return: bool - True = yes valid arg, false = no. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValOptionShort::IsArgShortOption( const CMIUtilString & vrTxt ) const | ||
| { | ||
| // Look for --someLongOption | ||
| MIint nPos = vrTxt.find( "--" ); | ||
| if( nPos == 0 ) | ||
| return false; | ||
|
|
||
| // Look for -f short option | ||
| nPos = vrTxt.find( "-" ); | ||
| if( nPos != 0 ) | ||
| return false; | ||
|
|
||
| if( vrTxt.length() > 2 ) | ||
| return false; | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Examine the string and determine if it is a valid short type option argument. | ||
| // Long type argument looks like -f some short option. | ||
| // Type: Overridden. | ||
| // Args: vrTxt - (R) Some text. | ||
| // Return: bool - True = yes valid arg, false = no. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValOptionShort::IsArgOptionCorrect( const CMIUtilString & vrTxt ) const | ||
| { | ||
| return IsArgShortOption( vrTxt ); | ||
| } | ||
|
|
||
| //++ ------------------------------------------------------------------------------------ | ||
| // Details: Does the argument name of the argument being parsed ATM match the name of | ||
| // *this argument object. | ||
| // Type: Overridden. | ||
| // Args: vrTxt - (R) Some text. | ||
| // Return: bool - True = yes arg name matched, false = no. | ||
| // Throws: None. | ||
| //-- | ||
| bool CMICmdArgValOptionShort::ArgNameMatch( const CMIUtilString & vrTxt ) const | ||
| { | ||
| const CMIUtilString strArg = vrTxt.substr( 1 ).c_str(); | ||
| return (strArg == GetName() ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| //===-- MICmdArgValOptionShort.h --------------------------------*- C++ -*-===// | ||
| // | ||
| // The LLVM Compiler Infrastructure | ||
| // | ||
| // This file is distributed under the University of Illinois Open Source | ||
| // License. See LICENSE.TXT for details. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| //++ | ||
| // File: MICmdArgValOptionShort.h | ||
| // | ||
| // Overview: CMICmdArgValOptionShort interface. | ||
| // | ||
| // Environment: Compilers: Visual C++ 12. | ||
| // gcc (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1 | ||
| // Libraries: See MIReadmetxt. | ||
| // | ||
| // Copyright: None. | ||
| //-- | ||
|
|
||
| #pragma once | ||
|
|
||
| // In-house headers: | ||
| #include "MICmdArgValOptionLong.h" | ||
|
|
||
| // Declarations: | ||
| class CMICmdArgContext; | ||
| class CMIUtilString; | ||
|
|
||
| //++ ============================================================================ | ||
| // Details: MI common code class. Command argument class. Arguments object | ||
| // needing specialization derived from the CMICmdArgValOptionLong class. | ||
| // An argument knows what type of argument it is and how it is to | ||
| // interpret the options (context) string to find and validate a matching | ||
| // argument and so extract a value from it. | ||
| // If *this argument has expected options following it the option objects | ||
| // created to hold each of those option's values belong to *this argument | ||
| // object and so are deleted when *this object goes out of scope. | ||
| // Based on the Interpreter pattern. | ||
| // Gotchas: None. | ||
| // Authors: Illya Rudkin 16/04/2014. | ||
| // Changes: None. | ||
| //-- | ||
| class CMICmdArgValOptionShort : public CMICmdArgValOptionLong | ||
| { | ||
| // Methods: | ||
| public: | ||
| /* ctor */ CMICmdArgValOptionShort( void ); | ||
| /* ctor */ CMICmdArgValOptionShort( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd ); | ||
| /* ctor */ CMICmdArgValOptionShort( const CMIUtilString & vrArgName, const bool vbMandatory, const bool vbHandleByCmd, const ArgValType_e veType, const MIuint vnExpectingNOptions ); | ||
| // | ||
| bool IsArgShortOption( const CMIUtilString & vrTxt ) const; | ||
|
|
||
| // Overridden: | ||
| public: | ||
| // From CMICmdArgValBase | ||
| /* dtor */ virtual ~CMICmdArgValOptionShort( void ); | ||
|
|
||
| // Overridden: | ||
| private: | ||
| // From CMICmdArgValOptionLong | ||
| virtual bool IsArgOptionCorrect( const CMIUtilString & vrTxt ) const; | ||
| virtual bool ArgNameMatch( const CMIUtilString & vrTxt ) const; | ||
| }; |