Răsfoiți Sursa

Fix proposed by frosch to correct line number info in stack dumps
Several white spaces wiped out.

mingodad 13 ani în urmă
părinte
comite
a032bbb5aa
1 a modificat fișierele cu 44 adăugiri și 42 ștergeri
  1. 44 42
      squirrel/sqcompiler.cpp

+ 44 - 42
squirrel/sqcompiler.cpp

@@ -271,11 +271,11 @@ public:
 				_fs->_returnexp = retexp;
 				_fs->_returnexp = retexp;
 				_fs->AddInstruction(op, 1, _fs->PopTarget(),_fs->GetStackSize());
 				_fs->AddInstruction(op, 1, _fs->PopTarget(),_fs->GetStackSize());
 			}
 			}
-			else{ 
+			else{
 				if(op == _OP_RETURN && _fs->_traps > 0)
 				if(op == _OP_RETURN && _fs->_traps > 0)
 					_fs->AddInstruction(_OP_POPTRAP, _fs->_traps ,0);
 					_fs->AddInstruction(_OP_POPTRAP, _fs->_traps ,0);
 				_fs->_returnexp = -1;
 				_fs->_returnexp = -1;
-				_fs->AddInstruction(op, 0xFF,0,_fs->GetStackSize()); 
+				_fs->AddInstruction(op, 0xFF,0,_fs->GetStackSize());
 			}
 			}
 			break;}
 			break;}
 		case TK_BREAK:
 		case TK_BREAK:
@@ -336,7 +336,7 @@ public:
 			SQObject val = ExpectScalar();
 			SQObject val = ExpectScalar();
 			OptionalSemicolon();
 			OptionalSemicolon();
 			SQTable *enums = _table(_ss(_vm)->_consts);
 			SQTable *enums = _table(_ss(_vm)->_consts);
-			SQObjectPtr strongid = id; 
+			SQObjectPtr strongid = id;
 			enums->NewSlot(strongid,SQObjectPtr(val));
 			enums->NewSlot(strongid,SQObjectPtr(val));
 			strongid.Null();
 			strongid.Null();
 			}
 			}
@@ -569,7 +569,7 @@ public:
 		case TK_EQ: BIN_EXP(_OP_EQ, &SQCompiler::CompExp); break;
 		case TK_EQ: BIN_EXP(_OP_EQ, &SQCompiler::CompExp); break;
 		case TK_NE: BIN_EXP(_OP_NE, &SQCompiler::CompExp); break;
 		case TK_NE: BIN_EXP(_OP_NE, &SQCompiler::CompExp); break;
 		case TK_3WAYSCMP: BIN_EXP(_OP_CMP, &SQCompiler::CompExp,CMP_3W); break;
 		case TK_3WAYSCMP: BIN_EXP(_OP_CMP, &SQCompiler::CompExp,CMP_3W); break;
-		default: return;	
+		default: return;
 		}
 		}
 	}
 	}
 	void CompExp()
 	void CompExp()
@@ -580,7 +580,7 @@ public:
 		case _SC('<'): BIN_EXP(_OP_CMP, &SQCompiler::ShiftExp,CMP_L); break;
 		case _SC('<'): BIN_EXP(_OP_CMP, &SQCompiler::ShiftExp,CMP_L); break;
 		case TK_GE: BIN_EXP(_OP_CMP, &SQCompiler::ShiftExp,CMP_GE); break;
 		case TK_GE: BIN_EXP(_OP_CMP, &SQCompiler::ShiftExp,CMP_GE); break;
 		case TK_LE: BIN_EXP(_OP_CMP, &SQCompiler::ShiftExp,CMP_LE); break;
 		case TK_LE: BIN_EXP(_OP_CMP, &SQCompiler::ShiftExp,CMP_LE); break;
-		default: return;	
+		default: return;
 		}
 		}
 	}
 	}
 	void ShiftExp()
 	void ShiftExp()
@@ -590,7 +590,7 @@ public:
 		case TK_USHIFTR: BIN_EXP(_OP_BITW, &SQCompiler::PlusExp,BW_USHIFTR); break;
 		case TK_USHIFTR: BIN_EXP(_OP_BITW, &SQCompiler::PlusExp,BW_USHIFTR); break;
 		case TK_SHIFTL: BIN_EXP(_OP_BITW, &SQCompiler::PlusExp,BW_SHIFTL); break;
 		case TK_SHIFTL: BIN_EXP(_OP_BITW, &SQCompiler::PlusExp,BW_SHIFTL); break;
 		case TK_SHIFTR: BIN_EXP(_OP_BITW, &SQCompiler::PlusExp,BW_SHIFTR); break;
 		case TK_SHIFTR: BIN_EXP(_OP_BITW, &SQCompiler::PlusExp,BW_SHIFTR); break;
-		default: return;	
+		default: return;
 		}
 		}
 	}
 	}
 	SQOpcode ChooseArithOpByToken(SQInteger tok)
 	SQOpcode ChooseArithOpByToken(SQInteger tok)
@@ -628,7 +628,7 @@ public:
 		default: return;
 		default: return;
 		}
 		}
 	}
 	}
-	
+
 	void MultExp()
 	void MultExp()
 	{
 	{
 		PrefixedExpr();
 		PrefixedExpr();
@@ -646,7 +646,7 @@ public:
 			switch(_token) {
 			switch(_token) {
 			case _SC('.'):
 			case _SC('.'):
 				pos = -1;
 				pos = -1;
-				Lex(); 
+				Lex();
 
 
 				_fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetConstant(Expect(TK_IDENTIFIER)));
 				_fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetConstant(Expect(TK_IDENTIFIER)));
 				if(_es.etype==BASE) {
 				if(_es.etype==BASE) {
@@ -664,7 +664,7 @@ public:
 				break;
 				break;
 			case _SC('['):
 			case _SC('['):
 				if(_lex._prevtoken == _SC('\n')) Error(_SC("cannot brake deref/or comma needed after [exp]=exp slot declaration"));
 				if(_lex._prevtoken == _SC('\n')) Error(_SC("cannot brake deref/or comma needed after [exp]=exp slot declaration"));
-				Lex(); Expression(); Expect(_SC(']')); 
+				Lex(); Expression(); Expect(_SC(']'));
 				pos = -1;
 				pos = -1;
 				if(_es.etype==BASE) {
 				if(_es.etype==BASE) {
 					Emit2ArgsOP(_OP_GET);
 					Emit2ArgsOP(_OP_GET);
@@ -708,8 +708,8 @@ public:
 					}
 					}
 				}
 				}
 				return;
 				return;
-				break;	
-			case _SC('('): 
+				break;
+			case _SC('('):
 				switch(_es.etype) {
 				switch(_es.etype) {
 					case OBJECT: {
 					case OBJECT: {
 						SQInteger key     = _fs->PopTarget();  /* location of the key */
 						SQInteger key     = _fs->PopTarget();  /* location of the key */
@@ -745,7 +745,7 @@ public:
 		{
 		{
 		case TK_STRING_LITERAL:
 		case TK_STRING_LITERAL:
 			_fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetConstant(_fs->CreateString(_lex._svalue,_lex._longstr.size()-1)));
 			_fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetConstant(_fs->CreateString(_lex._svalue,_lex._longstr.size()-1)));
-			Lex(); 
+			Lex();
 			break;
 			break;
 		case TK_BASE:
 		case TK_BASE:
 			Lex();
 			Lex();
@@ -779,7 +779,7 @@ public:
 					/* Handle a free var */
 					/* Handle a free var */
 					if(NeedGet()) {
 					if(NeedGet()) {
 						_es.epos  = _fs->PushTarget();
 						_es.epos  = _fs->PushTarget();
-						_fs->AddInstruction(_OP_GETOUTER, _es.epos, pos);	
+						_fs->AddInstruction(_OP_GETOUTER, _es.epos, pos);
 						/* _es.etype = EXPR; already default value */
 						/* _es.etype = EXPR; already default value */
 					}
 					}
 					else {
 					else {
@@ -838,7 +838,7 @@ public:
 			_es.epos = -1;
 			_es.epos = -1;
 			return _es.epos;
 			return _es.epos;
 			break;
 			break;
-		case TK_NULL: 
+		case TK_NULL:
 			_fs->AddInstruction(_OP_LOADNULLS, _fs->PushTarget(),1);
 			_fs->AddInstruction(_OP_LOADNULLS, _fs->PushTarget(),1);
 			Lex();
 			Lex();
 			break;
 			break;
@@ -853,7 +853,7 @@ public:
 				SQInteger apos = _fs->GetCurrentPos(),key = 0;
 				SQInteger apos = _fs->GetCurrentPos(),key = 0;
 				Lex();
 				Lex();
 				while(_token != _SC(']')) {
 				while(_token != _SC(']')) {
-                    Expression(); 
+                    Expression();
 					if(_token == _SC(',')) Lex();
 					if(_token == _SC(',')) Lex();
 					SQInteger val = _fs->PopTarget();
 					SQInteger val = _fs->PopTarget();
 					SQInteger array = _fs->TopTarget();
 					SQInteger array = _fs->TopTarget();
@@ -871,8 +871,8 @@ public:
 		case TK_FUNCTION: FunctionExp(_token);break;
 		case TK_FUNCTION: FunctionExp(_token);break;
 		case _SC('@'): FunctionExp(_token,true);break;
 		case _SC('@'): FunctionExp(_token,true);break;
 		case TK_CLASS: Lex(); ClassExp();break;
 		case TK_CLASS: Lex(); ClassExp();break;
-		case _SC('-'): 
-			Lex(); 
+		case _SC('-'):
+			Lex();
 			switch(_token) {
 			switch(_token) {
 			case TK_INTEGER: EmitLoadConstInt(-_lex._nvalue,-1); Lex(); break;
 			case TK_INTEGER: EmitLoadConstInt(-_lex._nvalue,-1); Lex(); break;
 			case TK_FLOAT: EmitLoadConstFloat(-_lex._fvalue,-1); Lex(); break;
 			case TK_FLOAT: EmitLoadConstFloat(-_lex._fvalue,-1); Lex(); break;
@@ -880,15 +880,15 @@ public:
 			}
 			}
 			break;
 			break;
 		case _SC('!'): Lex(); UnaryOP(_OP_NOT); break;
 		case _SC('!'): Lex(); UnaryOP(_OP_NOT); break;
-		case _SC('~'): 
-			Lex(); 
+		case _SC('~'):
+			Lex();
 			if(_token == TK_INTEGER)  { EmitLoadConstInt(~_lex._nvalue,-1); Lex(); break; }
 			if(_token == TK_INTEGER)  { EmitLoadConstInt(~_lex._nvalue,-1); Lex(); break; }
-			UnaryOP(_OP_BWNOT); 
+			UnaryOP(_OP_BWNOT);
 			break;
 			break;
 		case TK_TYPEOF : Lex() ;UnaryOP(_OP_TYPEOF); break;
 		case TK_TYPEOF : Lex() ;UnaryOP(_OP_TYPEOF); break;
 		case TK_RESUME : Lex(); UnaryOP(_OP_RESUME); break;
 		case TK_RESUME : Lex(); UnaryOP(_OP_RESUME); break;
 		case TK_CLONE : Lex(); UnaryOP(_OP_CLONE); break;
 		case TK_CLONE : Lex(); UnaryOP(_OP_CLONE); break;
-		case TK_MINUSMINUS : 
+		case TK_MINUSMINUS :
 		case TK_PLUSPLUS :PrefixIncDec(_token); break;
 		case TK_PLUSPLUS :PrefixIncDec(_token); break;
 		case TK_DELETE : DeleteExpr(); break;
 		case TK_DELETE : DeleteExpr(); break;
 		case _SC('('): Lex(); CommaExpr(); Expect(_SC(')'));
 		case _SC('('): Lex(); CommaExpr(); Expect(_SC(')'));
@@ -952,9 +952,9 @@ public:
 		 while(_token != _SC(')')) {
 		 while(_token != _SC(')')) {
 			 Expression();
 			 Expression();
 			 MoveIfCurrentTargetIsLocal();
 			 MoveIfCurrentTargetIsLocal();
-			 nargs++; 
-			 if(_token == _SC(',')){ 
-				 Lex(); 
+			 nargs++;
+			 if(_token == _SC(',')){
+				 Lex();
 				 if(_token == ')') Error(_SC("expression expected, found ')'"));
 				 if(_token == ')') Error(_SC("expression expected, found ')'"));
 			 }
 			 }
 		 }
 		 }
@@ -1126,7 +1126,7 @@ public:
 		_fs->AddInstruction(_OP_JZ, _fs->PopTarget());
 		_fs->AddInstruction(_OP_JZ, _fs->PopTarget());
 		SQInteger jnepos = _fs->GetCurrentPos();
 		SQInteger jnepos = _fs->GetCurrentPos();
 		BEGIN_SCOPE();
 		BEGIN_SCOPE();
-		
+
         //there is a situation where the if statement has a statement enclosed by {}
         //there is a situation where the if statement has a statement enclosed by {}
         //and after the closing "}" there is no newline or semicolom
         //and after the closing "}" there is no newline or semicolom
         //it's a valid construction but the compiler was complaining about it
         //it's a valid construction but the compiler was complaining about it
@@ -1140,7 +1140,7 @@ if(color == "yellow"){
 		Statement();
 		Statement();
 		//
 		//
 		if(_token != _SC('}') && _token != TK_ELSE && _token != TK_IDENTIFIER) OptionalSemicolon();
 		if(_token != _SC('}') && _token != TK_ELSE && _token != TK_IDENTIFIER) OptionalSemicolon();
-		
+
 		END_SCOPE();
 		END_SCOPE();
 		SQInteger endifblock = _fs->GetCurrentPos();
 		SQInteger endifblock = _fs->GetCurrentPos();
 		if(_token == TK_ELSE){
 		if(_token == TK_ELSE){
@@ -1165,13 +1165,13 @@ if(color == "yellow"){
 		_fs->AddInstruction(_OP_JZ, _fs->PopTarget());
 		_fs->AddInstruction(_OP_JZ, _fs->PopTarget());
 		jzpos = _fs->GetCurrentPos();
 		jzpos = _fs->GetCurrentPos();
 		BEGIN_SCOPE();
 		BEGIN_SCOPE();
-		
+
 		Statement();
 		Statement();
-		
+
 		END_SCOPE();
 		END_SCOPE();
 		_fs->AddInstruction(_OP_JMP, 0, jmppos - _fs->GetCurrentPos() - 1);
 		_fs->AddInstruction(_OP_JMP, 0, jmppos - _fs->GetCurrentPos() - 1);
 		_fs->SetIntructionParam(jzpos, 1, _fs->GetCurrentPos() - jzpos);
 		_fs->SetIntructionParam(jzpos, 1, _fs->GetCurrentPos() - jzpos);
-		
+
 		END_BREAKBLE_BLOCK(jmppos);
 		END_BREAKBLE_BLOCK(jmppos);
 	}
 	}
 	void DoWhileStatement()
 	void DoWhileStatement()
@@ -1181,7 +1181,9 @@ if(color == "yellow"){
 		BEGIN_BREAKBLE_BLOCK()
 		BEGIN_BREAKBLE_BLOCK()
 		BEGIN_SCOPE();
 		BEGIN_SCOPE();
 		Statement();
 		Statement();
-		END_SCOPE();
+		END_SCOPE();
+		//fix proposed by frosch to correct line number info in stack dumps
+		_fs->AddLineInfos(_lex._currentline, _lineinfo, true);
 		Expect(TK_WHILE);
 		Expect(TK_WHILE);
 		SQInteger continuetrg = _fs->GetCurrentPos();
 		SQInteger continuetrg = _fs->GetCurrentPos();
 		Expect(_SC('(')); CommaExpr(true); Expect(_SC(')'));
 		Expect(_SC('(')); CommaExpr(true); Expect(_SC(')'));
@@ -1255,7 +1257,7 @@ if(color == "yellow"){
 		_fs->AddInstruction(_OP_JMP, 0, jmppos - _fs->GetCurrentPos() - 1, 0);
 		_fs->AddInstruction(_OP_JMP, 0, jmppos - _fs->GetCurrentPos() - 1, 0);
 		if(jzpos>  0) _fs->SetIntructionParam(jzpos, 1, _fs->GetCurrentPos() - jzpos);
 		if(jzpos>  0) _fs->SetIntructionParam(jzpos, 1, _fs->GetCurrentPos() - jzpos);
 		END_SCOPE();
 		END_SCOPE();
-		
+
 		END_BREAKBLE_BLOCK(continuetrg);
 		END_BREAKBLE_BLOCK(continuetrg);
 	}
 	}
 	void ForEachStatement()
 	void ForEachStatement()
@@ -1270,7 +1272,7 @@ if(color == "yellow"){
 			idxname = _fs->CreateString(_SC("@INDEX@"));
 			idxname = _fs->CreateString(_SC("@INDEX@"));
 		}
 		}
 		Expect(TK_IN);
 		Expect(TK_IN);
-		
+
 		//save the stack size
 		//save the stack size
 		BEGIN_SCOPE();
 		BEGIN_SCOPE();
 		//put the table in the stack(evaluate the table expression)
 		//put the table in the stack(evaluate the table expression)
@@ -1352,7 +1354,7 @@ if(color == "yellow"){
 		_fs->PushTarget(0);
 		_fs->PushTarget(0);
 		_fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetConstant(id));
 		_fs->AddInstruction(_OP_LOAD, _fs->PushTarget(), _fs->GetConstant(id));
 		if(_token == TK_DOUBLE_COLON) Emit2ArgsOP(_OP_GET);
 		if(_token == TK_DOUBLE_COLON) Emit2ArgsOP(_OP_GET);
-		
+
 		while(_token == TK_DOUBLE_COLON) {
 		while(_token == TK_DOUBLE_COLON) {
 			Lex();
 			Lex();
 			id = Expect(TK_IDENTIFIER);
 			id = Expect(TK_IDENTIFIER);
@@ -1425,10 +1427,10 @@ if(color == "yellow"){
 	}
 	}
 	void EnumStatement()
 	void EnumStatement()
 	{
 	{
-		Lex(); 
+		Lex();
 		SQObject id = Expect(TK_IDENTIFIER);
 		SQObject id = Expect(TK_IDENTIFIER);
 		Expect(_SC('{'));
 		Expect(_SC('{'));
-		
+
 		SQObject table = _fs->CreateTable();
 		SQObject table = _fs->CreateTable();
 		SQInteger nval = 0;
 		SQInteger nval = 0;
 		while(_token != _SC('}')) {
 		while(_token != _SC('}')) {
@@ -1446,7 +1448,7 @@ if(color == "yellow"){
 			if(_token == ',') Lex();
 			if(_token == ',') Lex();
 		}
 		}
 		SQTable *enums = _table(_ss(_vm)->_consts);
 		SQTable *enums = _table(_ss(_vm)->_consts);
-		SQObjectPtr strongid = id; 
+		SQObjectPtr strongid = id;
 		enums->NewSlot(SQObjectPtr(strongid),SQObjectPtr(table));
 		enums->NewSlot(SQObjectPtr(strongid),SQObjectPtr(table));
 		strongid.Null();
 		strongid.Null();
 		Lex();
 		Lex();
@@ -1542,7 +1544,7 @@ if(color == "yellow"){
 		else if(_es.etype==LOCAL) {
 		else if(_es.etype==LOCAL) {
 			SQInteger src = _fs->TopTarget();
 			SQInteger src = _fs->TopTarget();
 			_fs->AddInstruction(_OP_INCL, src, src, 0, diff);
 			_fs->AddInstruction(_OP_INCL, src, src, 0, diff);
-			
+
 		}
 		}
 		else if(_es.etype==OUTER) {
 		else if(_es.etype==OUTER) {
 			SQInteger tmp = _fs->PushTarget();
 			SQInteger tmp = _fs->PushTarget();
@@ -1589,14 +1591,14 @@ if(color == "yellow"){
 		for(SQInteger n = 0; n < defparams; n++) {
 		for(SQInteger n = 0; n < defparams; n++) {
 			_fs->PopTarget();
 			_fs->PopTarget();
 		}
 		}
-				
+
 		SQFuncState *currchunk = _fs;
 		SQFuncState *currchunk = _fs;
 		_fs = funcstate;
 		_fs = funcstate;
-		if(lambda) { 
-			Expression(); 
+		if(lambda) {
+			Expression();
 			_fs->AddInstruction(_OP_RETURN, 1, _fs->PopTarget());}
 			_fs->AddInstruction(_OP_RETURN, 1, _fs->PopTarget());}
-		else { 
-			Statement(false); 
+		else {
+			Statement(false);
 		}
 		}
 		funcstate->AddLineInfos(_lex._prevtoken == _SC('\n')?_lex._lasttokenline:_lex._currentline, _lineinfo, true);
 		funcstate->AddLineInfos(_lex._prevtoken == _SC('\n')?_lex._lasttokenline:_lex._currentline, _lineinfo, true);
         funcstate->AddInstruction(_OP_RETURN, -1);
         funcstate->AddInstruction(_OP_RETURN, -1);