Skip to content

Commit 30408ec

Browse files
committed
fix serious bug
1 parent 8bff192 commit 30408ec

File tree

6 files changed

+41
-40
lines changed

6 files changed

+41
-40
lines changed

include/FunctionCompiler.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,11 @@ class CLeftPartCompiler : public CFunctionCompilerBase {
103103
void matchRightDuplicateVE();
104104

105105
TTableIndex top;
106-
TTableIndex left;
107-
TTableIndex right;
108106
TTableIndex maxTableSize;
109107

110108
CHoleList holes;
111109
CHoleNode* hole;
110+
CHoleNode* lastUsedHole;
112111

113112
#if 0
114113
CVariablesMask markedVariables;

include/OperationsBuilder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum TOperationType {
1717
OT_SetLeftBorder, // TTableIndex
1818
OT_SetRightBorder, // TTableIndex
1919
OT_DecrementStackDepth, // TStackIndex
20+
OT_SaveLeftRight,
2021
// matching empty expression
2122
OT_MatchEmptyExpression,
2223
// matching symbols
@@ -169,6 +170,7 @@ class COperationsBuilder {
169170
void AddDecrementStackDepth( TStackIndex size );
170171
void AddSetLeftBorder( TTableIndex );
171172
void AddSetRightBorder( TTableIndex );
173+
void AddSaveLeftRight();
172174
// matching empty expression
173175
void AddMatchEmptyExpression();
174176
// matching symbols

include/OperationsExecuter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ inline bool COperationsExecuter::matchRightNumber( const TNumber number )
362362
inline bool COperationsExecuter::matchLeftParens()
363363
{
364364
if( shiftLeft() && left->IsLeftParen() ) {
365+
saveToTable( left->PairedParen(), right );
365366
right = left->PairedParen();
366-
saveToTable( left, right );
367367
return true;
368368
} else {
369369
return false;
@@ -373,8 +373,8 @@ inline bool COperationsExecuter::matchLeftParens()
373373
inline bool COperationsExecuter::matchRightParens()
374374
{
375375
if( shiftRight() && right->IsRightParen() ) {
376+
saveToTable( left, right->PairedParen() );
376377
left = right->PairedParen();
377-
saveToTable( left, right );
378378
return true;
379379
} else {
380380
return false;

src/FunctionCompiler.cpp

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ CHole& CHole::operator=( const CHole& hole )
3737

3838
CLeftPartCompiler::CLeftPartCompiler() :
3939
top( 0 ),
40-
left( 0 ),
41-
right( 0 ),
4240
maxTableSize( 0 ),
4341
hole( 0 )
4442
{
@@ -111,19 +109,17 @@ void CLeftPartCompiler::splitIntoClasses(CHole* const holes)
111109
void CLeftPartCompiler::CompileLeftPart( CUnitList& leftPart,
112110
bool isRightDirection )
113111
{
114-
left = 0;
115-
right = 1;
116112
top = 2;
117-
holes.Append( CHole( leftPart, left, right ) );
113+
holes.Append( CHole( leftPart, 0 /* left */, 1 /* right */ ) );
114+
lastUsedHole = holes.GetFirst();
118115

119116
while( true ) {
120117
hole = holes.GetFirst();
121118

122119
while( hole != 0 ) {
123-
CUnitNode* left = hole->GetFirst();
124-
CUnitNode* right = hole->GetLast();
125-
126-
if( left != right && isFreeVE( left ) && isFreeVE( right ) ) {
120+
if( hole->GetFirst() != hole->GetLast()
121+
&& isFreeVE( hole->GetFirst() ) && isFreeVE( hole->GetLast() ) )
122+
{
127123
hole = hole->Next();
128124
} else {
129125
matchElement();
@@ -146,6 +142,10 @@ void CLeftPartCompiler::CompileLeftPart( CUnitList& leftPart,
146142

147143
void CLeftPartCompiler::removeHole()
148144
{
145+
if( lastUsedHole == hole ) {
146+
lastUsedHole = 0;
147+
}
148+
149149
CHoleNode* nextHole = hole->Next();
150150
holes.Remove( hole );
151151
hole = nextHole;
@@ -180,14 +180,19 @@ void CLeftPartCompiler::matchDuplicateVariable(
180180

181181
void CLeftPartCompiler::checkBorders()
182182
{
183-
if( left != hole->GetLeft() ) {
184-
left = hole->GetLeft();
185-
COperationsBuilder::AddSetLeftBorder( left );
186-
}
187-
if( right != hole->GetRight() ) {
188-
right = hole->GetRight();
189-
COperationsBuilder::AddSetRightBorder( right );
183+
assert( hole != 0 );
184+
if( hole != lastUsedHole ) {
185+
if( lastUsedHole != 0 ) {
186+
COperationsBuilder::AddSaveLeftRight();
187+
lastUsedHole->SetLeft( top );
188+
top++;
189+
lastUsedHole->SetRight( top );
190+
top++;
191+
}
192+
COperationsBuilder::AddSetLeftBorder( hole->GetLeft() );
193+
COperationsBuilder::AddSetRightBorder( hole->GetRight() );
190194
}
195+
lastUsedHole = hole;
191196
}
192197

193198
void CLeftPartCompiler::matchVE(const bool isRightDirection)
@@ -387,16 +392,9 @@ void CLeftPartCompiler::matchLeftParens()
387392

388393
hole->RemoveFirst();
389394
hole->RemoveLast();
390-
391-
TTableIndex oldRight = right;
392-
left = top;
393-
top++;
394-
right = top;
395-
top++;
396-
hole->SetLeft( left );
397-
hole->SetRight( right );
398-
399-
holes.InsertAfter( hole, CHole( newHole, right, oldRight ) );
395+
396+
holes.InsertAfter( hole, CHole( newHole, top, top + 1 ) );
397+
top += 2;
400398
}
401399

402400
void CLeftPartCompiler::matchRightParens()
@@ -417,16 +415,9 @@ void CLeftPartCompiler::matchRightParens()
417415

418416
hole->RemoveFirst();
419417
hole->RemoveLast();
420-
421-
TTableIndex oldLeft = left;
422-
left = top;
423-
top++;
424-
right = top;
425-
top++;
426-
hole->SetLeft( left );
427-
hole->SetRight( right );
428-
429-
holes.InsertBefore( hole, CHole( newHole, oldLeft, left ) );
418+
419+
holes.InsertBefore( hole, CHole( newHole, top, top + 1 ) );
420+
top += 2;
430421
}
431422

432423
void CLeftPartCompiler::matchLeftSymbol()

src/OperationsBuilder.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ void COperationsBuilder::AddSetRightBorder( TTableIndex tableIndex )
6161
addTableIndexOperation( OT_SetRightBorder, tableIndex );
6262
}
6363

64+
void COperationsBuilder::AddSaveLeftRight()
65+
{
66+
DEBUG_PRINT( __FUNCTION__ )
67+
addNoArgumensOperation( OT_SaveLeftRight );
68+
}
69+
6470
/* matching operation */
6571
void COperationsBuilder::AddMatchEmptyExpression()
6672
{

src/OperationsExecuter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ void COperationsExecuter::doFunctionBody()
262262
case OT_DecrementStackDepth: // TUint32
263263
decrementStackDepth( operation->stackDecrement );
264264
break;
265+
case OT_SaveLeftRight:
266+
saveToTable( left, right );
267+
break;
265268
// matching empty expression
266269
case OT_MatchEmptyExpression:
267270
success = matchEmptyExpression();

0 commit comments

Comments
 (0)