From 37c83821ec5529c2d348ba54103c53a4c77f871f Mon Sep 17 00:00:00 2001
From: npcdoom <venccsralph@gmail.com>
Date: Sat, 12 Mar 2011 10:56:41 -0430
Subject: [PATCH 3/4] Remove DECLARE_LIST (SvTokenList,SvToken*)

---
 idl/inc/lex.hxx             |  248 ++++++++++++++++++++++++-------------------
 idl/source/cmptools/lex.cxx |   26 ++---
 2 files changed, 146 insertions(+), 128 deletions(-)

diff --git a/idl/inc/lex.hxx b/idl/inc/lex.hxx
index eb667a2..658a576 100644
--- a/idl/inc/lex.hxx
+++ b/idl/inc/lex.hxx
@@ -29,10 +29,11 @@
 #ifndef _LEX_HXX
 #define _LEX_HXX
 
+#include <boost/ptr_container/ptr_vector.hpp>
+
 #include <hash.hxx>
 #include <tools/gen.hxx>
 #include <tools/stream.hxx>
-#include <tools/list.hxx>
 
 enum SVTOKEN_ENUM { SVTOKEN_EMPTY,      SVTOKEN_COMMENT,
                     SVTOKEN_INTEGER,    SVTOKEN_STRING,
@@ -127,8 +128,6 @@ inline SvToken::SvToken( SVTOKEN_ENUM nTypeP, const ByteString & rStr )
 inline SvToken::SvToken( SVTOKEN_ENUM nTypeP )
 : nType( nTypeP ) {}
 
-DECLARE_LIST( SvTokenList, SvToken * )
-
 class SvTokenStream
 {
     ULONG       nLine, nColumn;
@@ -144,115 +143,142 @@ class SvTokenStream
     SvFileStream *  pInStream;
     SvStream &      rInStream;
     String          aFileName;
-    SvTokenList     aTokList;
-    SvToken *		pCurToken;
-
-    void        InitCtor();
-
-    ByteString      	aBufStr;
-    int         	GetNextChar();
-    int         	GetFastNextChar()
-                    {
-                        return aBufStr.GetChar((USHORT)nBufPos++);
-                    }
-
-    void			FillTokenList();
-    ULONG       	GetNumber();
-    BOOL        	MakeToken( SvToken & );
-    BOOL			IsEof() const { return rInStream.IsEof(); }
-    void			SetMax()
-                    {
-                        ULONG n = Tell();
-                        if( n > nMaxPos )
-                            nMaxPos = n;
-                    }
-    void			CalcColumn()
-                    {
-                        // if end of line spare calculation
-                        if( 0 != c )
-                        {
-                            USHORT n = 0;
-                            nColumn = 0;
-                            while( n < nBufPos )
-                                nColumn += aBufStr.GetChar(n++) == '\t' ? nTabSize : 1;
-                        }
-                    }
+    boost::ptr_vector<SvToken> aTokList;
+    boost::ptr_vector<SvToken>::iterator pCurToken;
+
+    ByteString aBufStr;
+
+    void InitCtor();
+
+    int GetNextChar();
+
+    int GetFastNextChar()
+    {
+        return aBufStr.GetChar((USHORT)nBufPos++);
+    }
+
+    void FillTokenList();
+
+    ULONG GetNumber();
+
+    BOOL MakeToken( SvToken & );
+
+    BOOL IsEof() const { return rInStream.IsEof(); }
+
+    void SetMax()
+    {
+        ULONG n = Tell();
+        if( n > nMaxPos )
+            nMaxPos = n;
+    }
+
+    void CalcColumn()
+    {
+        // if end of line spare calculation
+        if( 0 != c )
+        {
+            USHORT n = 0;
+            nColumn = 0;
+            while( n < nBufPos )
+                nColumn += aBufStr.GetChar(n++) == '\t' ? nTabSize : 1;
+        }
+    }
 public:
-                    SvTokenStream( const String & rFileName );
-                    SvTokenStream( SvStream & rInStream, const String & rFileName );
-                    ~SvTokenStream();
-
-    const String &  GetFileName() const { return aFileName; }
-    SvStream &      GetStream() { return rInStream; }
-
-    void            SetCharSet( CharSet nSet );
-    CharSet         GetCharSet() const { return nCharSet; }
-
-    void            SetTabSize( USHORT nTabSizeP )
-                    { nTabSize = nTabSizeP; }
-    USHORT          GetTabSize() const { return nTabSize; }
-
-    SvToken *       GetToken_PrevAll()
-                    {
-                        SvToken * pRetToken = pCurToken;
-                        if( NULL == (pCurToken = aTokList.Prev()) )
-                            // current pointer never null
-                            pCurToken = pRetToken;
-
-                        return pRetToken;
-                    }
-    SvToken *       GetToken_NextAll()
-                    {
-                        SvToken * pRetToken = pCurToken;
-                        if( NULL == (pCurToken = aTokList.Next()) )
-                            // current pointer never null
-                            pCurToken = pRetToken;
-                        SetMax();
-                        return pRetToken;
-                    }
-    SvToken *       GetToken_Next()
-                    {
-                        // comments get removed initially
-                        return GetToken_NextAll();
-                    }
-    SvToken *       GetToken() const { return pCurToken; }
-    BOOL            Read( char cChar )
-                    {
-                        if( pCurToken->IsChar()
-                          && cChar == pCurToken->GetChar() )
-                        {
-                            GetToken_Next();
-                            return TRUE;
-                        }
-                        else
-                            return FALSE;
-                    }
-    void            ReadDelemiter()
-                    {
-                        if( pCurToken->IsChar()
-                          && (';' == pCurToken->GetChar()
-                                || ',' == pCurToken->GetChar()) )
-                        {
-                            GetToken_Next();
-                        }
-                    }
-
-    UINT32          Tell() const
-                    { return aTokList.GetCurPos(); }
-    void            Seek( UINT32 nPos )
-                    {
-                        pCurToken = aTokList.Seek( nPos );
-                        SetMax();
-                    }
-    void            SeekRel( INT32 nRelPos )
-                    {
-                        pCurToken = aTokList.Seek( Tell() + nRelPos );
-                        SetMax();
-                    }
-    void            SeekEnd()
-                    {
-                        pCurToken = aTokList.Seek( nMaxPos );
-                    }
+
+    SvTokenStream ( const String & rFileName );
+
+    SvTokenStream ( SvStream & rInStream, const String & rFileName );
+
+    ~SvTokenStream ();
+
+    const String&  GetFileName() const { return aFileName; }
+
+    SvStream& GetStream() { return rInStream; }
+
+    void SetCharSet( CharSet nSet );
+
+    CharSet GetCharSet() const { return nCharSet; }
+
+    void SetTabSize( USHORT nTabSizeP ) { nTabSize = nTabSizeP; }
+
+    USHORT GetTabSize() const { return nTabSize; }
+
+    SvToken* GetToken_PrevAll()
+    {
+        boost::ptr_vector<SvToken>::iterator pRetToken = pCurToken;
+
+        // current iterator always valid
+        if(pCurToken != aTokList.begin())
+            --pCurToken;
+
+        return &(*pRetToken);
+    }
+
+    SvToken* GetToken_NextAll()
+    {
+        boost::ptr_vector<SvToken>::iterator pRetToken = pCurToken++;
+
+        if (pCurToken == aTokList.end())
+            pCurToken = pRetToken;
+
+        SetMax();
+
+        return &(*pRetToken);
+    }
+
+    SvToken* GetToken_Next()
+    {
+        // comments get removed initially
+        return GetToken_NextAll();
+    }
+
+    SvToken* GetToken() const { return &(*pCurToken); }
+
+    BOOL Read( char cChar )
+    {
+        if( pCurToken->IsChar()
+          && cChar == pCurToken->GetChar() )
+        {
+            GetToken_Next();
+            return TRUE;
+        }
+        else
+            return FALSE;
+    }
+
+    void ReadDelemiter()
+    {
+        if( pCurToken->IsChar()
+          && (';' == pCurToken->GetChar()
+                || ',' == pCurToken->GetChar()) )
+        {
+            GetToken_Next();
+        }
+    }
+
+    UINT32 Tell() const { return pCurToken-aTokList.begin(); }
+
+    void Seek( UINT32 nPos )
+    {
+        pCurToken = aTokList.begin() + nPos;
+        SetMax();
+    }
+
+    void SeekRel( INT32 nRelPos )
+    {
+        UINT32 relIdx = Tell() + nRelPos;
+
+        if ( relIdx < aTokList.size())
+        {
+            pCurToken = aTokList.begin()+ (Tell() + nRelPos );
+            SetMax();
+        }
+    }
+
+    void SeekEnd()
+    {
+        pCurToken = aTokList.begin()+nMaxPos;
+    }
 };
 
 
diff --git a/idl/source/cmptools/lex.cxx b/idl/source/cmptools/lex.cxx
index 25feb28..865c260 100644
--- a/idl/source/cmptools/lex.cxx
+++ b/idl/source/cmptools/lex.cxx
@@ -105,7 +105,6 @@ void SvTokenStream::InitCtor()
     nLine       = nColumn = 0;
     nBufPos     = 0;
     nTabSize    = 4;
-    pCurToken	= NULL;
     nMaxPos		= 0;
     c           = GetNextChar();
     FillTokenList();
@@ -115,7 +114,6 @@ SvTokenStream::SvTokenStream( const String & rFileName )
     : pInStream( new SvFileStream( rFileName, STREAM_STD_READ | STREAM_NOCREATE ) )
     , rInStream( *pInStream )
     , aFileName( rFileName )
-    , aTokList( 0x8000, 0x8000 )
 {
     InitCtor();
 }
@@ -124,7 +122,6 @@ SvTokenStream::SvTokenStream( SvStream & rStream, const String & rFileName )
     : pInStream( NULL )
     , rInStream( rStream )
     , aFileName( rFileName )
-    , aTokList( 0x8000, 0x8000 )
 {
     InitCtor();
 }
@@ -132,28 +129,23 @@ SvTokenStream::SvTokenStream( SvStream & rStream, const String & rFileName )
 SvTokenStream::~SvTokenStream()
 {
     delete pInStream;
-    SvToken * pTok = aTokList.Last();
-    while( pTok )
-    {
-        delete pTok;
-        pTok = aTokList.Prev();
-    }
 }
 
 void SvTokenStream::FillTokenList()
 {
     SvToken * pToken = new SvToken();
-    aTokList.Insert( pToken, LIST_APPEND );
+    aTokList.push_back(pToken);
     do
     {
         if( !MakeToken( *pToken ) )
         {
-            SvToken * p = aTokList.Prev();
-            *pToken = SvToken();
-            if( p )
+            if (!aTokList.empty())
             {
-                pToken->SetLine( p->GetLine() );
-                pToken->SetColumn( p->GetColumn() );
+                *pToken = SvToken();
+                boost::ptr_vector<SvToken>::const_iterator it = aTokList.begin();
+
+                pToken->SetLine(it->GetLine());
+                pToken->SetColumn(it->GetColumn());
             }
             break;
         }
@@ -164,11 +156,11 @@ void SvTokenStream::FillTokenList()
         else
         {
             pToken = new SvToken();
-            aTokList.Insert( pToken, LIST_APPEND );
+            aTokList.push_back(pToken);
         }
     }
     while( !pToken->IsEof() );
-    pCurToken = aTokList.First();
+    pCurToken = aTokList.begin();
 }
 
 void SvTokenStream::SetCharSet( CharSet nSet )
-- 
1.7.3.4

