[Scummvm-git-logs] scummvm master -> ea0eca9327336813794a0f06d89b434dfdb8f992

Strangerke noreply at scummvm.org
Mon Jun 17 20:53:33 UTC 2024


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
ea0eca9327 BAGEL: Constify more variables, change a switch in if/else in CBagExpression::setInfo()


Commit: ea0eca9327336813794a0f06d89b434dfdb8f992
    https://github.com/scummvm/scummvm/commit/ea0eca9327336813794a0f06d89b434dfdb8f992
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2024-06-17T21:53:27+01:00

Commit Message:
BAGEL: Constify more variables, change a switch in if/else in CBagExpression::setInfo()

Changed paths:
    engines/bagel/baglib/event_sdev.cpp
    engines/bagel/baglib/exam.cpp
    engines/bagel/baglib/expression.cpp
    engines/bagel/baglib/expression_object.cpp


diff --git a/engines/bagel/baglib/event_sdev.cpp b/engines/bagel/baglib/event_sdev.cpp
index 692c300d576..e5696d813d4 100644
--- a/engines/bagel/baglib/event_sdev.cpp
+++ b/engines/bagel/baglib/event_sdev.cpp
@@ -28,7 +28,7 @@ namespace Bagel {
 bool CBagEventSDev::_evalTurnEventsFl;
 
 ErrorCode CBagEventSDev::attach() {
-	ErrorCode errorCode = CBagStorageDev::attach();
+	const ErrorCode errorCode = CBagStorageDev::attach();
 
 	// Set the firstpaint flag and attach objects to allow
 	// for immediate run objects to run
@@ -47,7 +47,7 @@ ErrorCode CBagEventSDev::evaluateExpressions() {
 		return ERR_NONE;
 
 	ErrorCode errorCode = ERR_NONE;
-	int count = getObjectCount();
+	const int count = getObjectCount();
 	for (int i = 0; i < count; ++i) {
 
 		CBagObject *posObj = getObjectByPos(i);
@@ -80,7 +80,7 @@ ErrorCode CBagTurnEventSDev::evaluateExpressions() {
 	}
 
 	ErrorCode errorCode = ERR_NONE;
-	int count = getObjectCount();
+	const int count = getObjectCount();
 	for (int i = 0; i < count; ++i) {
 		CBagObject *posObj = getObjectByPos(i);
 		if (posObj != nullptr) {
diff --git a/engines/bagel/baglib/exam.cpp b/engines/bagel/baglib/exam.cpp
index 11b6a401316..841ec5b2d5f 100644
--- a/engines/bagel/baglib/exam.cpp
+++ b/engines/bagel/baglib/exam.cpp
@@ -61,7 +61,7 @@ void CBagExam::onReSize(CBofSize *size) {
 
 bool CBagExam::setRotationRects() {
 	// Get the  windows rect
-	CBofRect clientRect = getClientRect();
+	const CBofRect clientRect = getClientRect();
 
 	// Left quarter of the video window
 	_leftRect.left = clientRect.left;
diff --git a/engines/bagel/baglib/expression.cpp b/engines/bagel/baglib/expression.cpp
index 39655002cbd..7d60b6e7765 100644
--- a/engines/bagel/baglib/expression.cpp
+++ b/engines/bagel/baglib/expression.cpp
@@ -151,10 +151,10 @@ CBagVar *CBagExpression::getVariable(int itemPos) {
 			Common::strcpy_s(backStr, p + 2);
 			*p = '\0';
 
-			CBofString stringObject(frontStr, 256);
-			CBofString stringProperty(backStr, 256);
+			const CBofString stringObject(frontStr, 256);
+			const CBofString stringProperty(backStr, 256);
 
-			int newVal = g_SDevManager->getObjectValue(stringObject, stringProperty);
+			const int newVal = g_SDevManager->getObjectValue(stringObject, stringProperty);
 			curVar->setValue(newVal);
 		}
 	}
@@ -250,7 +250,7 @@ bool CBagExpression::evalLeftToRight(bool negFl, CBagVar &result) {
 		while (varCount < _varList.getCount()) {
 			CBagVar compLeftHandOper;
 			CBagVar *rightHandOper = getVariable(varCount++);
-			OPERATION prevOper = oper;      // save previous operator
+			const OPERATION prevOper = oper;      // save previous operator
 			oper = _operList.getNodeItem(nodeCount++);
 
 			if (bFirstTime) {
@@ -335,7 +335,7 @@ bool CBagExpression::onAssign(CBagVar *leftHandOper, CBagVar *rightHandOper, CBa
 	char buffer[256];
 	Common::strcpy_s(buffer, rightHandOper->getValue());
 	assert(strlen(buffer) < 256);
-	CBofString newLeftHandValue(buffer, 256);
+	const CBofString newLeftHandValue(buffer, 256);
 
 	leftHandOper->setValue(newLeftHandValue);
 
@@ -346,7 +346,7 @@ bool CBagExpression::onAssign(CBagVar *leftHandOper, CBagVar *rightHandOper, CBa
 bool CBagExpression::onEqual(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper) {
 	assert((leftHandOper != nullptr) && (rightHandOper != nullptr));
 
-	bool retVal = leftHandOper->getValue() == rightHandOper->getValue();
+	const bool retVal = leftHandOper->getValue() == rightHandOper->getValue();
 	resultOper.setBoolValue(retVal);
 
 	return retVal;
@@ -355,7 +355,7 @@ bool CBagExpression::onEqual(CBagVar *leftHandOper, CBagVar *rightHandOper, CBag
 
 bool CBagExpression::onNotEqual(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper) {
 	assert((leftHandOper != nullptr) && (rightHandOper != nullptr));
-	bool retVal = leftHandOper->getValue() != rightHandOper->getValue();
+	const bool retVal = leftHandOper->getValue() != rightHandOper->getValue();
 	resultOper.setBoolValue(retVal);
 
 	return retVal;
@@ -364,7 +364,7 @@ bool CBagExpression::onNotEqual(CBagVar *leftHandOper, CBagVar *rightHandOper, C
 
 bool CBagExpression::onLessThan(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper) {
 	assert((leftHandOper != nullptr) && (rightHandOper != nullptr));
-	bool retVal = leftHandOper->getNumValue() < rightHandOper->getNumValue();
+	const bool retVal = leftHandOper->getNumValue() < rightHandOper->getNumValue();
 	resultOper.setBoolValue(retVal);
 	return retVal;
 }
@@ -372,7 +372,7 @@ bool CBagExpression::onLessThan(CBagVar *leftHandOper, CBagVar *rightHandOper, C
 
 bool CBagExpression::onGreaterThan(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper) {
 	assert((leftHandOper != nullptr) && (rightHandOper != nullptr));
-	bool retVal = leftHandOper->getNumValue() > rightHandOper->getNumValue();
+	const bool retVal = leftHandOper->getNumValue() > rightHandOper->getNumValue();
 	resultOper.setBoolValue(retVal);
 	return retVal;
 }
@@ -380,7 +380,7 @@ bool CBagExpression::onGreaterThan(CBagVar *leftHandOper, CBagVar *rightHandOper
 
 bool CBagExpression::onLessThanEqual(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper) {
 	assert((leftHandOper != nullptr) && (rightHandOper != nullptr));
-	bool retVal = leftHandOper->getNumValue() <= rightHandOper->getNumValue();
+	const bool retVal = leftHandOper->getNumValue() <= rightHandOper->getNumValue();
 	resultOper.setBoolValue(retVal);
 	return retVal;
 }
@@ -389,7 +389,7 @@ bool CBagExpression::onLessThanEqual(CBagVar *leftHandOper, CBagVar *rightHandOp
 bool CBagExpression::onGreaterThanEqual(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVar &resultOper) {
 	assert((leftHandOper != nullptr) && (rightHandOper != nullptr));
 
-	bool retVal = leftHandOper->getNumValue() >= rightHandOper->getNumValue();
+	const bool retVal = leftHandOper->getNumValue() >= rightHandOper->getNumValue();
 	resultOper.setBoolValue(retVal);
 	return retVal;
 }
@@ -399,8 +399,8 @@ bool CBagExpression::onPlusAssign(CBagVar *leftHandOper, CBagVar *rightHandOper,
 	assert((leftHandOper != nullptr) && (rightHandOper != nullptr));
 
 	if (leftHandOper->isNumeric() && rightHandOper->isNumeric()) {
-		int leftHandNum = leftHandOper->getNumValue();
-		int rightHandNum = rightHandOper->getNumValue();
+		const int leftHandNum = leftHandOper->getNumValue();
+		const int rightHandNum = rightHandOper->getNumValue();
 		leftHandOper->setValue(leftHandNum + rightHandNum);
 		resultOper.setValue(leftHandOper->getNumValue());
 	}
@@ -413,8 +413,8 @@ bool CBagExpression::onMinusAssign(CBagVar *leftHandOper, CBagVar *rightHandOper
 	assert((leftHandOper != nullptr) && (rightHandOper != nullptr));
 
 	if (leftHandOper->isNumeric() && rightHandOper->isNumeric()) {
-		int leftHandNum = leftHandOper->getNumValue();
-		int rightHandNum = rightHandOper->getNumValue();
+		const int leftHandNum = leftHandOper->getNumValue();
+		const int rightHandNum = rightHandOper->getNumValue();
 		leftHandOper->setValue(leftHandNum - rightHandNum);
 		resultOper.setValue(leftHandOper->getNumValue());
 	}
@@ -474,8 +474,8 @@ bool CBagExpression::onPlus(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagV
 	assert((leftHandOper != nullptr) && (rightHandOper != nullptr));
 
 	if (leftHandOper->isNumeric() && rightHandOper->isNumeric()) {
-		int leftHandNum = leftHandOper->getNumValue();
-		int rightHandNum = rightHandOper->getNumValue();
+		const int leftHandNum = leftHandOper->getNumValue();
+		const int rightHandNum = rightHandOper->getNumValue();
 		resultOper.setValue(leftHandNum + rightHandNum);
 	}
 
@@ -487,8 +487,8 @@ bool CBagExpression::onMinus(CBagVar *leftHandOper, CBagVar *rightHandOper, CBag
 	assert((leftHandOper != nullptr) && (rightHandOper != nullptr));
 
 	if (leftHandOper->isNumeric() && rightHandOper->isNumeric()) {
-		int leftHandNum = leftHandOper->getNumValue();
-		int rightHandNum = rightHandOper->getNumValue();
+		const int leftHandNum = leftHandOper->getNumValue();
+		const int rightHandNum = rightHandOper->getNumValue();
 		resultOper.setValue(leftHandNum - rightHandNum);
 	}
 
@@ -500,8 +500,8 @@ bool CBagExpression::onMultiply(CBagVar *leftHandOper, CBagVar *rightHandOper, C
 	assert((leftHandOper != nullptr) && (rightHandOper != nullptr));
 
 	if (leftHandOper->isNumeric() && rightHandOper->isNumeric()) {
-		int leftHandNum = leftHandOper->getNumValue();
-		int rightHandNum = rightHandOper->getNumValue();
+		const int leftHandNum = leftHandOper->getNumValue();
+		const int rightHandNum = rightHandOper->getNumValue();
 
 		resultOper.setValue(leftHandNum * rightHandNum);
 	}
@@ -514,8 +514,8 @@ bool CBagExpression::onDivide(CBagVar *leftHandOper, CBagVar *rightHandOper, CBa
 	assert((leftHandOper != nullptr) && (rightHandOper != nullptr));
 
 	if (leftHandOper->isNumeric() && rightHandOper->isNumeric()) {
-		int leftHandNum = leftHandOper->getNumValue();
-		int rightHandNum = rightHandOper->getNumValue();
+		const int leftHandNum = leftHandOper->getNumValue();
+		const int rightHandNum = rightHandOper->getNumValue();
 
 		// Divide by Zero error?
 		assert(rightHandNum != 0);
@@ -531,8 +531,8 @@ bool CBagExpression::onMod(CBagVar *leftHandOper, CBagVar *rightHandOper, CBagVa
 	assert((leftHandOper != nullptr) && (rightHandOper != nullptr));
 
 	if (leftHandOper->isNumeric() && rightHandOper->isNumeric()) {
-		int leftHandNum = leftHandOper->getNumValue();
-		int rightHandNum = rightHandOper->getNumValue();
+		const int leftHandNum = leftHandOper->getNumValue();
+		const int rightHandNum = rightHandOper->getNumValue();
 
 		// Divide by Zero error?
 		assert(rightHandNum != 0);
diff --git a/engines/bagel/baglib/expression_object.cpp b/engines/bagel/baglib/expression_object.cpp
index cbd58f78b7b..14c1bc3b8f4 100644
--- a/engines/bagel/baglib/expression_object.cpp
+++ b/engines/bagel/baglib/expression_object.cpp
@@ -50,11 +50,11 @@ bool CBagExpressionObject::runObject() {
 			if (getFileName().isEmpty())
 				return false;
 
-			int nIndex = getFileName().find("~~");
+			const int nIndex = getFileName().find("~~");
 			if (nIndex > 0) {
 				// This is a reference
-				CBofString objectStr = getFileName().left(nIndex);
-				CBofString propertyStr = getFileName().mid(nIndex + 2);
+				const CBofString objectStr = getFileName().left(nIndex);
+				const CBofString propertyStr = getFileName().mid(nIndex + 2);
 
 				g_SDevManager->setObjectValue(objectStr, propertyStr, localVar.getNumValue());
 
@@ -73,21 +73,16 @@ ParseCodes CBagExpressionObject::setInfo(CBagIfstream &istr) {
 	bool objectUpdatedFl = false;
 
 	while (!istr.eof()) {
-		char ch = (char)istr.peek();
-		switch (ch) {
-		//
-		//  AS  - n number of slides in sprite
-		//
-		case '(':
+		const char ch = (char)istr.peek();
+		if (ch == '(') {
+			//
+			//  AS  - n number of slides in sprite
+			//
 			_expression = new CBagExpression();
 			_expression->setInfo(istr);
 			objectUpdatedFl = true;
-			break;
-		//
-		//  No match return from function
-		//
-		default: {
-			ParseCodes parseCode = CBagObject::setInfo(istr);
+		} else {
+			const ParseCodes parseCode = CBagObject::setInfo(istr);
 			if (parseCode == PARSING_DONE) {
 				return PARSING_DONE;
 			}
@@ -101,8 +96,6 @@ ParseCodes CBagExpressionObject::setInfo(CBagIfstream &istr) {
 				return UNKNOWN_TOKEN;
 			}
 		}
-		break;
-		}
 	}
 	return PARSING_DONE;
 }




More information about the Scummvm-git-logs mailing list