diff options
author | Ed Maste <emaste@FreeBSD.org> | 2014-11-25 21:00:58 +0000 |
---|---|---|
committer | Ed Maste <emaste@FreeBSD.org> | 2014-11-25 21:00:58 +0000 |
commit | 0cac4ca3916ac24ab6139d03cbfd18db9e715bfe (patch) | |
tree | c94307da318be46e5aeea1a325c1e91749506e4f /tools/lldb-mi/MICmdArgValOptionLong.cpp | |
parent | 03b99097822ca3ac69252d9afae716a584ed56c4 (diff) | |
download | src-0cac4ca3916ac24ab6139d03cbfd18db9e715bfe.tar.gz src-0cac4ca3916ac24ab6139d03cbfd18db9e715bfe.zip |
Import LLDB as of upstream SVN r216948 (git 50f7fe44)vendor/lldb/lldb-r216948
This corresponds with the branchpoint for the 3.5 release.
A number of files not required for the FreeBSD build have been removed.
Sponsored by: DARPA, AFRL
Notes
Notes:
svn path=/vendor/lldb/dist/; revision=275072
svn path=/vendor/lldb/lldb-r216948/; revision=275074; tag=vendor/lldb/lldb-r216948
Diffstat (limited to 'tools/lldb-mi/MICmdArgValOptionLong.cpp')
-rw-r--r-- | tools/lldb-mi/MICmdArgValOptionLong.cpp | 319 |
1 files changed, 319 insertions, 0 deletions
diff --git a/tools/lldb-mi/MICmdArgValOptionLong.cpp b/tools/lldb-mi/MICmdArgValOptionLong.cpp new file mode 100644 index 000000000000..6c87984ba811 --- /dev/null +++ b/tools/lldb-mi/MICmdArgValOptionLong.cpp @@ -0,0 +1,319 @@ +//===-- 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: Overridden. +// 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 +// argument *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... + MIuint nArgIndex = 0; + 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, nArgIndex ) ) + { + m_bValid = true; + return MIstatus::success; + } + + m_bIsMissingOptions = true; + return MIstatus::failure; + } + else + { + m_bValid = true; + return MIstatus::success; + } + } + + // Next + ++it; + ++nArgIndex; + } + + 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. +// nArgIndex - (R) The Nth arg position in argument context from the left. +// Return: MIstatus::success - Functional succeeded. +// MIstatus::failure - Functional failed. +// Throws: None. +//-- +bool CMICmdArgValOptionLong::ExtractExpectedOptions( CMICmdArgContext & vrwTxt, const MIuint nArgIndex ) +{ + CMIUtilString::VecString_t vecOptions; + MIuint nOptionsPresent = 0; + if( (m_eExpectingOptionType != eArgValType_StringQuoted) && + (m_eExpectingOptionType != eArgValType_StringQuotedNumber) && + (m_eExpectingOptionType != eArgValType_StringQuotedNumberPath) ) + nOptionsPresent = vrwTxt.GetArgsLeftToParse().Split( " ", vecOptions ); + else + nOptionsPresent = vrwTxt.GetArgsLeftToParse().SplitConsiderQuotes( " ", vecOptions ); + if( nOptionsPresent == 0 ) + return MIstatus::failure; + + MIuint nArgIndexCnt = 0; + MIuint nTypeCnt = 0; + MIuint nTypeCnt2 = 0; + MIuint nFoundNOptionsCnt = 0; + CMIUtilString::VecString_t::const_iterator it = vecOptions.begin(); + while( it != vecOptions.end() ) + { + // Move to the Nth argument position from left before do validation/checking + if( nArgIndexCnt++ == nArgIndex ) + { + nTypeCnt++; + const CMIUtilString & rOption( *it ); + if( IsExpectedCorrectType( rOption, m_eExpectingOptionType ) ) + { + nTypeCnt2++; + CMICmdArgValBase * pOptionObj = CreationObj( rOption, m_eExpectingOptionType ); + if( (pOptionObj != nullptr) && vrwTxt.RemoveArgAtPos( rOption, nArgIndex ) ) + { + 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; +} + |