summaryrefslogtreecommitdiff
path: root/rsc/source/parser/rsclex.cxx
diff options
context:
space:
mode:
authorJens-Heiner Rechtien <hr@openoffice.org>2004-09-08 14:34:31 +0000
committerJens-Heiner Rechtien <hr@openoffice.org>2004-09-08 14:34:31 +0000
commitbcad5181c793c82603e5e43f6dc126d511d4ede7 (patch)
treea6cc2e8e23e7d7b6db9dff5dd8d9e217ac5fb3a1 /rsc/source/parser/rsclex.cxx
parent932714214bb78566f415f1837707d738e7c1c2d8 (diff)
INTEGRATION: CWS vcl25 (1.6.10); FILE MERGED
2004/07/15 17:20:51 pl 1.6.10.1: #i31409# do not waste unbeleviable amounts of memory
Diffstat (limited to 'rsc/source/parser/rsclex.cxx')
-rw-r--r--rsc/source/parser/rsclex.cxx243
1 files changed, 75 insertions, 168 deletions
diff --git a/rsc/source/parser/rsclex.cxx b/rsc/source/parser/rsclex.cxx
index 5012d9630516..675e2548c3ca 100644
--- a/rsc/source/parser/rsclex.cxx
+++ b/rsc/source/parser/rsclex.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: rsclex.cxx,v $
*
- * $Revision: 1.6 $
+ * $Revision: 1.7 $
*
- * last change: $Author: hjs $ $Date: 2004-06-26 20:25:47 $
+ * last change: $Author: hr $ $Date: 2004-09-08 15:34:31 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -93,13 +93,24 @@
#include <rtl/textcvt.h>
#include <rtl/textenc.h>
-DECLARE_LIST( RscCharList, char * );
+using namespace rtl;
+
+const char* StringContainer::putString( const char* pString )
+{
+ OString aString( static_cast<const sal_Char*>(pString) );
+ std::pair<
+ std::hash_set< OString, OStringHash >::iterator,
+ bool > aInsert =
+ m_aStrings.insert( aString );
+
+ return aInsert.first->getStr();
+}
+
/*************************************************************************/
int c;
BOOL bLastInclude;// War letztes Symbol INCLUDE
RscFileInst* pFI;
RscTypCont* pTC;
-RscCharStack * pCS;
RscExpression * pExp;
struct {
int nKeyWord;
@@ -107,6 +118,8 @@ struct {
} aKeyVal[ 1 ];
BOOL bTargetDefined;
+StringContainer* pStringContainer = NULL;
+
/****************** C O D E **********************************************/
UINT32 GetNumber(){
@@ -146,24 +159,8 @@ UINT32 GetNumber(){
return( l );
}
-char * MallocString(){
- char * pRet;
-
- if( NULL == (pRet = pCS->Pop()) )
- pRet = (char *)RscMem::Malloc( MINBUF );
-
- *pRet = '\0';
-
- return( pRet );
-}
-
-void PutStringBack( char * pStr ){
- //pCS->Push( pStr );
-}
-
int MakeToken( YYSTYPE * pTokenVal ){
int c1;
- USHORT i;
char * pStr;
while( TRUE ){ // Kommentare und Leerzeichen ueberlesen
@@ -200,68 +197,48 @@ int MakeToken( YYSTYPE * pTokenVal ){
if( bLastInclude ){
bLastInclude = FALSE; //Zuruecksetzten
if( '<' == c ){
- USHORT nBufLen = MINBUF;
- char * pBuf = MallocString();
-
- i = 0;
+ OStringBuffer aBuf( 256 );
c = pFI->GetFastChar();
while( '>' != c && !pFI->IsEof() )
{
- if( nBufLen <= (USHORT)(i +1) )
- {
- nBufLen += MINBUF;
- pBuf = (char *)RscMem::Realloc( pBuf, nBufLen );
- }
- pBuf[i++] = c;
+ aBuf.append( sal_Char(c) );
c = pFI->GetFastChar();
};
c = pFI->GetFastChar();
- pBuf[i] = '\0';
- pTokenVal->string = pBuf;
+ pTokenVal->string = const_cast<char*>(pStringContainer->putString( aBuf.getStr() ));
return( INCLUDE_STRING );
};
}
if( c == '"' )
{
- USHORT nBufLen = MINBUF;
- char * pBuf = MallocString();
-
- i = 0;
+ OStringBuffer aBuf( 256 );
BOOL bDone = FALSE;
while( !bDone && !pFI->IsEof() && c )
{
- if( nBufLen <= (USHORT)(i +2) )
- {
- nBufLen += MINBUF;
- pBuf = (char *)RscMem::Realloc( pBuf, nBufLen );
- }
c = pFI->GetFastChar();
if( c == '"' )
{
c = pFI->GetFastChar();
if( c == '"' )
{
- pBuf[i++] = '"';
- pBuf[i++] = '"';
+ aBuf.append( '"' );
+ aBuf.append( '"' );
}
else
bDone = TRUE;
}
else if( c == '\\' )
{
- pBuf[i++] = '\\';
+ aBuf.append( '\\' );
c = pFI->GetFastChar();
if( c )
- {
- pBuf[i++] = c;
- }
+ aBuf.append( sal_Char(c) );
}
else
- pBuf[i++] = c;
+ aBuf.append( sal_Char(c) );
}
- pBuf[i++] = '\0';
- pStr = pTokenVal->string = pBuf;
+ pStr = pTokenVal->string = const_cast<char*>(pStringContainer->putString( aBuf.getStr() ));
return( STRING );
}
if (isdigit (c)){
@@ -271,124 +248,65 @@ int MakeToken( YYSTYPE * pTokenVal ){
if( isalpha (c) || (c == '_') ){
HASHID nHashId;
- USHORT nBufLen = MINBUF;
- char * pBuf = MallocString();
+ OStringBuffer aBuf( 256 );
-
- i = 0;
while( isalnum (c) || (c == '_') || (c == '-') )
{
- if( nBufLen <= (USHORT)(i +1) )
- {
- nBufLen += MINBUF;
- pBuf = (char *)RscMem::Realloc( pBuf, nBufLen );
- }
- pBuf[i++] = c;
+ aBuf.append( sal_Char(c) );
c = pFI->GetFastChar();
}
- /*
- if( pBuf[0] == 'L' && i == 1 && c == '"' )
- {
- // it is an L string
- i = 0;
- BOOL bDone = FALSE;
- while( !bDone && !pFI->IsEof() && c )
- {
- if( nBufLen <= (USHORT)(i +2) )
- {
- nBufLen += MINBUF;
- pBuf = (char *)RscMem::Realloc( pBuf, nBufLen );
- }
- c = pFI->GetFastChar();
- if( c == '"' )
- {
- c = pFI->GetFastChar();
- if( c == '"' )
- {
- pBuf[i++] = '"';
- pBuf[i++] = '"';
- }
- else
- bDone = TRUE;
- }
- else if( c == '\\' )
- {
- pBuf[i++] = '\\';
- c = pFI->GetFastChar();
- if( c )
- {
- pBuf[i++] = c;
- }
- }
- else
- pBuf[i++] = c;
- }
- pBuf[i++] = '\0';
- pStr = pTokenVal->string = RscChar::MakeUTF8FromL( pBuf );
- PutStringBack( pBuf );
- return( STRING );
- }
- else
- */
+ nHashId = pHS->Test( aBuf.getStr() );
+ if( HASH_NONAME != nHashId )
{
- pBuf[i++] = '\0';
+ KEY_STRUCT aKey;
- nHashId = pHS->Test( pBuf );
- if( HASH_NONAME != nHashId )
+ // Suche nach dem Schluesselwort
+ if( pTC->aNmTb.Get( nHashId, &aKey ) )
{
- KEY_STRUCT aKey;
- // Suche nach dem Schluesselwort
- if( pTC->aNmTb.Get( nHashId, &aKey ) )
+ // Schluesselwort gefunden
+ switch( aKey.nTyp )
{
+ case CLASSNAME:
+ pTokenVal->pClass = (RscTop *)aKey.yylval;
+ break;
+ case VARNAME:
+ pTokenVal->varid = aKey.nName;
+ break;
+ case CONSTNAME:
+ pTokenVal->constname.hashid = aKey.nName;
+ pTokenVal->constname.nValue = aKey.yylval;
+ break;
+ case BOOLEAN:
+ pTokenVal->svbool = (BOOL)aKey.yylval;
+ break;
+ case INCLUDE:
+ bLastInclude = TRUE;
+ default:
+ pTokenVal->value = aKey.yylval;
+ };
- // Schluesselwort gefunden
- switch( aKey.nTyp )
- {
- case CLASSNAME:
- pTokenVal->pClass = (RscTop *)aKey.yylval;
- break;
- case VARNAME:
- pTokenVal->varid = aKey.nName;
- break;
- case CONSTNAME:
- pTokenVal->constname.hashid = aKey.nName;
- pTokenVal->constname.nValue = aKey.yylval;
- break;
- case BOOLEAN:
- pTokenVal->svbool = (BOOL)aKey.yylval;
- break;
- case INCLUDE:
- bLastInclude = TRUE;
- default:
- pTokenVal->value = aKey.yylval;
- };
-
- // String zurueckgeben
- PutStringBack( pBuf );
- return( aKey.nTyp );
- }
- else{
- pTokenVal->string = pBuf;
- return( SYMBOL );
- }
+ return( aKey.nTyp );
}
- else{ // Symbol
- RscDefine * pDef;
+ else
+ {
+ pTokenVal->string = const_cast<char*>(pStringContainer->putString( aBuf.getStr() ));
+ return( SYMBOL );
+ }
+ }
+ else{ // Symbol
+ RscDefine * pDef;
- pDef = pTC->aFileTab.FindDef( pBuf );
- if( pDef ){
- pTokenVal->defineele = pDef;
+ pDef = pTC->aFileTab.FindDef( aBuf.getStr() );
+ if( pDef ){
+ pTokenVal->defineele = pDef;
- // String zurueckgeben
- PutStringBack( pBuf );
- return( RSCDEFINE );
- }
-
- pTokenVal->string = pBuf;
- return( SYMBOL );
+ return( RSCDEFINE );
}
+
+ pTokenVal->string = const_cast<char*>(pStringContainer->putString( aBuf.getStr() ));
+ return( SYMBOL );
}
}
@@ -454,7 +372,7 @@ void InitParser( RscFileInst * pFileInst )
{
pTC = pFileInst->pTypCont; // Datenkontainer setzten
pFI = pFileInst;
- pCS = new RscCharStack(); //Puffer Vorrat
+ pStringContainer = new StringContainer();
pExp = NULL; //fuer MacroParser
bTargetDefined = FALSE;
@@ -464,21 +382,18 @@ void InitParser( RscFileInst * pFileInst )
}
void EndParser(){
- char * pStr;
-
// Stack abraeumen
while( ! S.IsEmpty() )
S.Pop();
- // Speicher freigeben
- while( NULL != (pStr = pCS->Pop()) )
- RscMem::Free( pStr );
- delete pCS;
+ // free string container
+ delete pStringContainer;
+ pStringContainer = NULL;
+
if( pExp )
delete pExp;
pTC = NULL;
pFI = NULL;
- pCS = NULL;
pExp = NULL;
}
@@ -510,14 +425,6 @@ void IncludeParser( RscFileInst * pFileInst )
};
};
};
- switch( nToken ){
- case STRING:
- case INCLUDE_STRING:
- case SYMBOL:
- // String zurueckgeben
- pCS->Push( aYYSType.string );
- break;
- };
nToken = MakeToken( &aYYSType );
};