Use shared_ptr and references for Actions.
This slows terminal emulation slightly.
This commit is contained in:
@@ -40,15 +40,13 @@
|
||||
|
||||
const Parser::StateFamily Parser::family;
|
||||
|
||||
static void append_or_delete( Parser::Action *act,
|
||||
static void append_or_delete( Parser::ActionPointer act,
|
||||
Parser::Actions &vec )
|
||||
{
|
||||
assert( act );
|
||||
|
||||
if ( !act->ignore() ) {
|
||||
vec.push_back( act );
|
||||
} else {
|
||||
delete act;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +59,6 @@ void Parser::Parser::input( wchar_t ch, Actions &ret )
|
||||
}
|
||||
|
||||
append_or_delete( tx.action, ret );
|
||||
tx.action = NULL;
|
||||
|
||||
if ( tx.next_state != NULL ) {
|
||||
append_or_delete( tx.next_state->enter(), ret );
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "shared.h"
|
||||
|
||||
namespace Terminal {
|
||||
class Emulator;
|
||||
}
|
||||
@@ -59,7 +61,8 @@ namespace Parser {
|
||||
virtual bool operator==( const Action &other ) const;
|
||||
};
|
||||
|
||||
typedef std::vector<Action *> Actions;
|
||||
typedef shared::shared_ptr<Action> ActionPointer;
|
||||
typedef std::vector<ActionPointer> Actions;
|
||||
|
||||
class Ignore : public Action {
|
||||
public:
|
||||
|
||||
+46
-45
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "parserstate.h"
|
||||
#include "parserstatefamily.h"
|
||||
#include "shared.h"
|
||||
|
||||
using namespace Parser;
|
||||
|
||||
@@ -41,7 +42,7 @@ Transition State::anywhere_rule( wchar_t ch ) const
|
||||
|| ((0x80 <= ch) && (ch <= 0x8F))
|
||||
|| ((0x91 <= ch) && (ch <= 0x97))
|
||||
|| (ch == 0x99) || (ch == 0x9A) ) {
|
||||
return Transition( new Execute, &family->s_Ground );
|
||||
return Transition( shared::make_shared<Execute>(), &family->s_Ground );
|
||||
} else if ( ch == 0x9C ) {
|
||||
return Transition( &family->s_Ground );
|
||||
} else if ( ch == 0x1B ) {
|
||||
@@ -56,7 +57,7 @@ Transition State::anywhere_rule( wchar_t ch ) const
|
||||
return Transition( &family->s_CSI_Entry );
|
||||
}
|
||||
|
||||
return Transition(( State * )NULL, NULL ); /* don't allocate an Ignore action */
|
||||
return Transition(( State * )NULL, ActionPointer() ); /* don't allocate an Ignore action */
|
||||
}
|
||||
|
||||
Transition State::input( wchar_t ch ) const
|
||||
@@ -92,29 +93,29 @@ static bool GLGR ( wchar_t ch )
|
||||
Transition Ground::input_state_rule( wchar_t ch ) const
|
||||
{
|
||||
if ( C0_prime( ch ) ) {
|
||||
return Transition( new Execute );
|
||||
return Transition( shared::make_shared< Execute >() );
|
||||
}
|
||||
|
||||
if ( GLGR( ch ) ) {
|
||||
return Transition( new Print );
|
||||
return Transition( shared::make_shared< Print >() );
|
||||
}
|
||||
|
||||
return Transition();
|
||||
}
|
||||
|
||||
Action *Escape::enter( void ) const
|
||||
ActionPointer Escape::enter( void ) const
|
||||
{
|
||||
return new Clear;
|
||||
return shared::make_shared< Clear >();
|
||||
}
|
||||
|
||||
Transition Escape::input_state_rule( wchar_t ch ) const
|
||||
{
|
||||
if ( C0_prime( ch ) ) {
|
||||
return Transition( new Execute );
|
||||
return Transition( shared::make_shared< Execute >() );
|
||||
}
|
||||
|
||||
if ( (0x20 <= ch) && (ch <= 0x2F) ) {
|
||||
return Transition( new Collect, &family->s_Escape_Intermediate );
|
||||
return Transition( shared::make_shared< Collect >(), &family->s_Escape_Intermediate );
|
||||
}
|
||||
|
||||
if ( ( (0x30 <= ch) && (ch <= 0x4F) )
|
||||
@@ -123,7 +124,7 @@ Transition Escape::input_state_rule( wchar_t ch ) const
|
||||
|| ( ch == 0x5A )
|
||||
|| ( ch == 0x5C )
|
||||
|| ( (0x60 <= ch) && (ch <= 0x7E) ) ) {
|
||||
return Transition( new Esc_Dispatch, &family->s_Ground );
|
||||
return Transition( shared::make_shared< Esc_Dispatch >(), &family->s_Ground );
|
||||
}
|
||||
|
||||
if ( ch == 0x5B ) {
|
||||
@@ -148,42 +149,42 @@ Transition Escape::input_state_rule( wchar_t ch ) const
|
||||
Transition Escape_Intermediate::input_state_rule( wchar_t ch ) const
|
||||
{
|
||||
if ( C0_prime( ch ) ) {
|
||||
return Transition( new Execute );
|
||||
return Transition( shared::make_shared< Execute >() );
|
||||
}
|
||||
|
||||
if ( (0x20 <= ch) && (ch <= 0x2F) ) {
|
||||
return Transition( new Collect );
|
||||
return Transition( shared::make_shared< Collect >() );
|
||||
}
|
||||
|
||||
if ( (0x30 <= ch) && (ch <= 0x7E) ) {
|
||||
return Transition( new Esc_Dispatch, &family->s_Ground );
|
||||
return Transition( shared::make_shared< Esc_Dispatch >(), &family->s_Ground );
|
||||
}
|
||||
|
||||
return Transition();
|
||||
}
|
||||
|
||||
Action *CSI_Entry::enter( void ) const
|
||||
ActionPointer CSI_Entry::enter( void ) const
|
||||
{
|
||||
return new Clear;
|
||||
return shared::make_shared< Clear >();
|
||||
}
|
||||
|
||||
Transition CSI_Entry::input_state_rule( wchar_t ch ) const
|
||||
{
|
||||
if ( C0_prime( ch ) ) {
|
||||
return Transition( new Execute );
|
||||
return Transition( shared::make_shared< Execute >() );
|
||||
}
|
||||
|
||||
if ( (0x40 <= ch) && (ch <= 0x7E) ) {
|
||||
return Transition( new CSI_Dispatch, &family->s_Ground );
|
||||
return Transition( shared::make_shared< CSI_Dispatch >(), &family->s_Ground );
|
||||
}
|
||||
|
||||
if ( ( (0x30 <= ch) && (ch <= 0x39) )
|
||||
|| ( ch == 0x3B ) ) {
|
||||
return Transition( new Param, &family->s_CSI_Param );
|
||||
return Transition( shared::make_shared< Param >(), &family->s_CSI_Param );
|
||||
}
|
||||
|
||||
if ( (0x3C <= ch) && (ch <= 0x3F) ) {
|
||||
return Transition( new Collect, &family->s_CSI_Param );
|
||||
return Transition( shared::make_shared< Collect >(), &family->s_CSI_Param );
|
||||
}
|
||||
|
||||
if ( ch == 0x3A ) {
|
||||
@@ -191,7 +192,7 @@ Transition CSI_Entry::input_state_rule( wchar_t ch ) const
|
||||
}
|
||||
|
||||
if ( (0x20 <= ch) && (ch <= 0x2F) ) {
|
||||
return Transition( new Collect, &family->s_CSI_Intermediate );
|
||||
return Transition( shared::make_shared< Collect >(), &family->s_CSI_Intermediate );
|
||||
}
|
||||
|
||||
return Transition();
|
||||
@@ -200,11 +201,11 @@ Transition CSI_Entry::input_state_rule( wchar_t ch ) const
|
||||
Transition CSI_Param::input_state_rule( wchar_t ch ) const
|
||||
{
|
||||
if ( C0_prime( ch ) ) {
|
||||
return Transition( new Execute );
|
||||
return Transition( shared::make_shared< Execute >() );
|
||||
}
|
||||
|
||||
if ( ( (0x30 <= ch) && (ch <= 0x39) ) || ( ch == 0x3B ) ) {
|
||||
return Transition( new Param );
|
||||
return Transition( shared::make_shared< Param >() );
|
||||
}
|
||||
|
||||
if ( ( ch == 0x3A ) || ( (0x3C <= ch) && (ch <= 0x3F) ) ) {
|
||||
@@ -212,11 +213,11 @@ Transition CSI_Param::input_state_rule( wchar_t ch ) const
|
||||
}
|
||||
|
||||
if ( (0x20 <= ch) && (ch <= 0x2F) ) {
|
||||
return Transition( new Collect, &family->s_CSI_Intermediate );
|
||||
return Transition( shared::make_shared< Collect >(), &family->s_CSI_Intermediate );
|
||||
}
|
||||
|
||||
if ( (0x40 <= ch) && (ch <= 0x7E) ) {
|
||||
return Transition( new CSI_Dispatch, &family->s_Ground );
|
||||
return Transition( shared::make_shared< CSI_Dispatch >(), &family->s_Ground );
|
||||
}
|
||||
|
||||
return Transition();
|
||||
@@ -225,15 +226,15 @@ Transition CSI_Param::input_state_rule( wchar_t ch ) const
|
||||
Transition CSI_Intermediate::input_state_rule( wchar_t ch ) const
|
||||
{
|
||||
if ( C0_prime( ch ) ) {
|
||||
return Transition( new Execute );
|
||||
return Transition( shared::make_shared< Execute >() );
|
||||
}
|
||||
|
||||
if ( (0x20 <= ch) && (ch <= 0x2F) ) {
|
||||
return Transition( new Collect );
|
||||
return Transition( shared::make_shared< Collect >() );
|
||||
}
|
||||
|
||||
if ( (0x40 <= ch) && (ch <= 0x7E) ) {
|
||||
return Transition( new CSI_Dispatch, &family->s_Ground );
|
||||
return Transition( shared::make_shared< CSI_Dispatch >(), &family->s_Ground );
|
||||
}
|
||||
|
||||
if ( (0x30 <= ch) && (ch <= 0x3F) ) {
|
||||
@@ -246,7 +247,7 @@ Transition CSI_Intermediate::input_state_rule( wchar_t ch ) const
|
||||
Transition CSI_Ignore::input_state_rule( wchar_t ch ) const
|
||||
{
|
||||
if ( C0_prime( ch ) ) {
|
||||
return Transition( new Execute );
|
||||
return Transition( shared::make_shared< Execute >() );
|
||||
}
|
||||
|
||||
if ( (0x40 <= ch) && (ch <= 0x7E) ) {
|
||||
@@ -256,15 +257,15 @@ Transition CSI_Ignore::input_state_rule( wchar_t ch ) const
|
||||
return Transition();
|
||||
}
|
||||
|
||||
Action *DCS_Entry::enter( void ) const
|
||||
ActionPointer DCS_Entry::enter( void ) const
|
||||
{
|
||||
return new Clear;
|
||||
return shared::make_shared< Clear >();
|
||||
}
|
||||
|
||||
Transition DCS_Entry::input_state_rule( wchar_t ch ) const
|
||||
{
|
||||
if ( (0x20 <= ch) && (ch <= 0x2F) ) {
|
||||
return Transition( new Collect, &family->s_DCS_Intermediate );
|
||||
return Transition( shared::make_shared< Collect >(), &family->s_DCS_Intermediate );
|
||||
}
|
||||
|
||||
if ( ch == 0x3A ) {
|
||||
@@ -272,11 +273,11 @@ Transition DCS_Entry::input_state_rule( wchar_t ch ) const
|
||||
}
|
||||
|
||||
if ( ( (0x30 <= ch) && (ch <= 0x39) ) || ( ch == 0x3B ) ) {
|
||||
return Transition( new Param, &family->s_DCS_Param );
|
||||
return Transition( shared::make_shared< Param >(), &family->s_DCS_Param );
|
||||
}
|
||||
|
||||
if ( (0x3C <= ch) && (ch <= 0x3F) ) {
|
||||
return Transition( new Collect, &family->s_DCS_Param );
|
||||
return Transition( shared::make_shared< Collect >(), &family->s_DCS_Param );
|
||||
}
|
||||
|
||||
if ( (0x40 <= ch) && (ch <= 0x7E) ) {
|
||||
@@ -289,7 +290,7 @@ Transition DCS_Entry::input_state_rule( wchar_t ch ) const
|
||||
Transition DCS_Param::input_state_rule( wchar_t ch ) const
|
||||
{
|
||||
if ( ( (0x30 <= ch) && (ch <= 0x39) ) || ( ch == 0x3B ) ) {
|
||||
return Transition( new Param );
|
||||
return Transition( shared::make_shared< Param >() );
|
||||
}
|
||||
|
||||
if ( ( ch == 0x3A ) || ( (0x3C <= ch) && (ch <= 0x3F) ) ) {
|
||||
@@ -297,7 +298,7 @@ Transition DCS_Param::input_state_rule( wchar_t ch ) const
|
||||
}
|
||||
|
||||
if ( (0x20 <= ch) && (ch <= 0x2F) ) {
|
||||
return Transition( new Collect, &family->s_DCS_Intermediate );
|
||||
return Transition( shared::make_shared< Collect >(), &family->s_DCS_Intermediate );
|
||||
}
|
||||
|
||||
if ( (0x40 <= ch) && (ch <= 0x7E) ) {
|
||||
@@ -310,7 +311,7 @@ Transition DCS_Param::input_state_rule( wchar_t ch ) const
|
||||
Transition DCS_Intermediate::input_state_rule( wchar_t ch ) const
|
||||
{
|
||||
if ( (0x20 <= ch) && (ch <= 0x2F) ) {
|
||||
return Transition( new Collect );
|
||||
return Transition( shared::make_shared< Collect >() );
|
||||
}
|
||||
|
||||
if ( (0x40 <= ch) && (ch <= 0x7E) ) {
|
||||
@@ -324,20 +325,20 @@ Transition DCS_Intermediate::input_state_rule( wchar_t ch ) const
|
||||
return Transition();
|
||||
}
|
||||
|
||||
Action *DCS_Passthrough::enter( void ) const
|
||||
ActionPointer DCS_Passthrough::enter( void ) const
|
||||
{
|
||||
return new Hook;
|
||||
return shared::make_shared< Hook >();
|
||||
}
|
||||
|
||||
Action *DCS_Passthrough::exit( void ) const
|
||||
ActionPointer DCS_Passthrough::exit( void ) const
|
||||
{
|
||||
return new Unhook;
|
||||
return shared::make_shared< Unhook >();
|
||||
}
|
||||
|
||||
Transition DCS_Passthrough::input_state_rule( wchar_t ch ) const
|
||||
{
|
||||
if ( C0_prime( ch ) || ( (0x20 <= ch) && (ch <= 0x7E) ) ) {
|
||||
return Transition( new Put );
|
||||
return Transition( shared::make_shared< Put >() );
|
||||
}
|
||||
|
||||
if ( ch == 0x9C ) {
|
||||
@@ -356,20 +357,20 @@ Transition DCS_Ignore::input_state_rule( wchar_t ch ) const
|
||||
return Transition();
|
||||
}
|
||||
|
||||
Action *OSC_String::enter( void ) const
|
||||
ActionPointer OSC_String::enter( void ) const
|
||||
{
|
||||
return new OSC_Start;
|
||||
return shared::make_shared< OSC_Start >();
|
||||
}
|
||||
|
||||
Action *OSC_String::exit( void ) const
|
||||
ActionPointer OSC_String::exit( void ) const
|
||||
{
|
||||
return new OSC_End;
|
||||
return shared::make_shared< OSC_End >();
|
||||
}
|
||||
|
||||
Transition OSC_String::input_state_rule( wchar_t ch ) const
|
||||
{
|
||||
if ( (0x20 <= ch) && (ch <= 0x7F) ) {
|
||||
return Transition( new OSC_Put );
|
||||
return Transition( shared::make_shared< OSC_Put >() );
|
||||
}
|
||||
|
||||
if ( (ch == 0x9C) || (ch == 0x07) ) { /* 0x07 is xterm non-ANSI variant */
|
||||
|
||||
@@ -50,8 +50,8 @@ namespace Parser {
|
||||
public:
|
||||
void setfamily( StateFamily *s_family ) { family = s_family; }
|
||||
Transition input( wchar_t ch ) const;
|
||||
virtual Action *enter( void ) const { return new Ignore; }
|
||||
virtual Action *exit( void ) const { return new Ignore; }
|
||||
virtual ActionPointer enter( void ) const { return shared::make_shared< Ignore >(); }
|
||||
virtual ActionPointer exit( void ) const { return shared::make_shared< Ignore >(); }
|
||||
|
||||
State() : family( NULL ) {};
|
||||
virtual ~State() {};
|
||||
@@ -65,7 +65,7 @@ namespace Parser {
|
||||
};
|
||||
|
||||
class Escape : public State {
|
||||
Action *enter( void ) const;
|
||||
ActionPointer enter( void ) const;
|
||||
Transition input_state_rule( wchar_t ch ) const;
|
||||
};
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace Parser {
|
||||
};
|
||||
|
||||
class CSI_Entry : public State {
|
||||
Action *enter( void ) const;
|
||||
ActionPointer enter( void ) const;
|
||||
Transition input_state_rule( wchar_t ch ) const;
|
||||
};
|
||||
class CSI_Param : public State {
|
||||
@@ -88,7 +88,7 @@ namespace Parser {
|
||||
};
|
||||
|
||||
class DCS_Entry : public State {
|
||||
Action *enter( void ) const;
|
||||
ActionPointer enter( void ) const;
|
||||
Transition input_state_rule( wchar_t ch ) const;
|
||||
};
|
||||
class DCS_Param : public State {
|
||||
@@ -98,18 +98,18 @@ namespace Parser {
|
||||
Transition input_state_rule( wchar_t ch ) const;
|
||||
};
|
||||
class DCS_Passthrough : public State {
|
||||
Action *enter( void ) const;
|
||||
ActionPointer enter( void ) const;
|
||||
Transition input_state_rule( wchar_t ch ) const;
|
||||
Action *exit( void ) const;
|
||||
ActionPointer exit( void ) const;
|
||||
};
|
||||
class DCS_Ignore : public State {
|
||||
Transition input_state_rule( wchar_t ch ) const;
|
||||
};
|
||||
|
||||
class OSC_String : public State {
|
||||
Action *enter( void ) const;
|
||||
ActionPointer enter( void ) const;
|
||||
Transition input_state_rule( wchar_t ch ) const;
|
||||
Action *exit( void ) const;
|
||||
ActionPointer exit( void ) const;
|
||||
};
|
||||
class SOS_PM_APC_String : public State {
|
||||
Transition input_state_rule( wchar_t ch ) const;
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Parser {
|
||||
public:
|
||||
// Transition is only a courier for an Action; it should
|
||||
// never create/delete one on its own.
|
||||
Action *action;
|
||||
ActionPointer action;
|
||||
State *next_state;
|
||||
|
||||
Transition( const Transition &x )
|
||||
@@ -58,20 +58,14 @@ namespace Parser {
|
||||
|
||||
return *this;
|
||||
}
|
||||
virtual ~Transition()
|
||||
{
|
||||
// Indicate to checkers that we don't own *action anymore
|
||||
action = NULL;
|
||||
}
|
||||
|
||||
Transition( Action *s_action=new Ignore, State *s_next_state=NULL )
|
||||
Transition( ActionPointer s_action=shared::make_shared< Ignore >(), State *s_next_state=NULL )
|
||||
: action( s_action ), next_state( s_next_state )
|
||||
{}
|
||||
|
||||
// This is only ever used in the 1-argument form;
|
||||
// we use this instead of an initializer to
|
||||
// tell Coverity the object never owns *action.
|
||||
Transition( State *s_next_state, Action *s_action=new Ignore )
|
||||
Transition( State *s_next_state, ActionPointer s_action=shared::make_shared< Ignore >() )
|
||||
: action( s_action ), next_state( s_next_state )
|
||||
{}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user