diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 7574657da8..e234358042 100755 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -4604,7 +4604,7 @@ Label_GroupsDone: sp.Name, sp.UUID, Name); return false; } - if (cAgentData.SessionID != sp.ControllingClient.SessionId) + if (cAgentData.SessionID.NotEqual(sp.ControllingClient.SessionId)) { m_log.WarnFormat( "[SCENE]: Attempt to update agent {0} with diferent session id {1} != {2}", diff --git a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptCodeGen.cs b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptCodeGen.cs index d4659e8929..a2fcdeeaff 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptCodeGen.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptCodeGen.cs @@ -76,8 +76,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine // Static tables that there only needs to be one copy of for all. private static VarDict legalEventHandlers = CreateLegalEventHandlers(); - private static CompValu[] zeroCompValus = new CompValu[0]; - private static TokenType[] zeroArgs = new TokenType[0]; + private static CompValu[] zeroCompValus = Array.Empty(); + private static TokenType[] zeroArgs = Array.Empty(); private static TokenTypeBool tokenTypeBool = new TokenTypeBool(null); private static TokenTypeExc tokenTypeExc = new TokenTypeExc(null); private static TokenTypeFloat tokenTypeFlt = new TokenTypeFloat(null); @@ -115,12 +115,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine private static FieldInfo vectorYFieldInfo = typeof(LSL_Vector).GetField("y"); private static FieldInfo vectorZFieldInfo = typeof(LSL_Vector).GetField("z"); - private static MethodInfo arrayClearMethodInfo = typeof(XMR_Array).GetMethod("__pub_clear", new Type[] { }); - private static MethodInfo arrayCountMethodInfo = typeof(XMR_Array).GetMethod("__pub_count", new Type[] { }); + private static MethodInfo arrayClearMethodInfo = typeof(XMR_Array).GetMethod("__pub_clear", Array.Empty()); + private static MethodInfo arrayCountMethodInfo = typeof(XMR_Array).GetMethod("__pub_count", Array.Empty()); private static MethodInfo arrayIndexMethodInfo = typeof(XMR_Array).GetMethod("__pub_index", new Type[] { typeof(int) }); private static MethodInfo arrayValueMethodInfo = typeof(XMR_Array).GetMethod("__pub_value", new Type[] { typeof(int) }); - private static MethodInfo checkRunStackMethInfo = typeof(XMRInstAbstract).GetMethod("CheckRunStack", new Type[] { }); - private static MethodInfo checkRunQuickMethInfo = typeof(XMRInstAbstract).GetMethod("CheckRunQuick", new Type[] { }); + private static MethodInfo checkRunStackMethInfo = typeof(XMRInstAbstract).GetMethod("CheckRunStack", Array.Empty()); + private static MethodInfo checkRunQuickMethInfo = typeof(XMRInstAbstract).GetMethod("CheckRunQuick", Array.Empty()); private static MethodInfo ehArgUnwrapFloat = GetStaticMethod(typeof(TypeCast), "EHArgUnwrapFloat", new Type[] { typeof(object) }); private static MethodInfo ehArgUnwrapInteger = GetStaticMethod(typeof(TypeCast), "EHArgUnwrapInteger", new Type[] { typeof(object) }); private static MethodInfo ehArgUnwrapRotation = GetStaticMethod(typeof(TypeCast), "EHArgUnwrapRotation", new Type[] { typeof(object) }); @@ -142,8 +142,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine private static MethodInfo consoleWriteMethodInfo = GetStaticMethod(typeof(ScriptCodeGen), "ConsoleWrite", new Type[] { typeof(object) }); public static void ConsoleWrite(object o) { - if(o == null) - o = "<>"; + o ??= "<>"; Console.Write(o.ToString()); } @@ -217,7 +216,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine } finally { - objFileWriter = null; } } @@ -277,9 +275,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine foreach(TokenDeclSDType sdType in tokenScript.sdSrcTypesValues) { itIsAGoodDayToDie = false; - if(sdType is TokenDeclSDTypeClass) + if(sdType is TokenDeclSDTypeClass sdtClass) { - TokenDeclSDTypeClass sdtClass = (TokenDeclSDTypeClass)sdType; foreach(TokenDeclVar declFunc in sdtClass.members) { if(declFunc.retType != null) @@ -295,9 +292,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine } } } - if(sdType is TokenDeclSDTypeInterface) + if(sdType is TokenDeclSDTypeInterface sdtIFace) { - TokenDeclSDTypeInterface sdtIFace = (TokenDeclSDTypeInterface)sdType; foreach(TokenDeclVar declFunc in sdtIFace.methsNProps) { if(declFunc.retType != null) @@ -344,7 +340,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine // GenerateFromLValSField(). foreach(TokenDeclSDType sdType in tokenScript.sdSrcTypesValues) { - if(!(sdType is TokenDeclSDTypeClass)) + if(sdType is not TokenDeclSDTypeClass) continue; TokenDeclSDTypeClass sdtClass = (TokenDeclSDTypeClass)sdType; @@ -375,7 +371,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine // $get() and $set() methods are in the table and they each get a slot. foreach(TokenDeclSDType sdType in tokenScript.sdSrcTypesValues) { - if(!(sdType is TokenDeclSDTypeInterface)) + if(sdType is not TokenDeclSDTypeInterface) continue; TokenDeclSDTypeInterface sdtIFace = (TokenDeclSDTypeInterface)sdType; int vti = 0; @@ -396,7 +392,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine didOne = false; foreach(TokenDeclSDType sdType in tokenScript.sdSrcTypesValues) { - if(!(sdType is TokenDeclSDTypeClass)) + if(sdType is not TokenDeclSDTypeClass) continue; TokenDeclSDTypeClass sdtClass = (TokenDeclSDTypeClass)sdType; if(sdtClass.slotsAssigned) @@ -667,19 +663,19 @@ namespace OpenSim.Region.ScriptEngine.Yengine didOne = false; foreach(TokenDeclVar tdv in tokenScript.variablesStack) { - if(tdv.constant && !(tdv.init is TokenRValConst)) + if(tdv.constant && tdv.init is not TokenRValConst) { tdv.init = tdv.init.TryComputeConstant(LookupInitConstants, ref didOne); } } foreach(TokenDeclSDType sdType in tokenScript.sdSrcTypesValues) { - if(!(sdType is TokenDeclSDTypeClass)) + if(sdType is not TokenDeclSDTypeClass) continue; currentSDTClass = (TokenDeclSDTypeClass)sdType; foreach(TokenDeclVar tdv in currentSDTClass.members) { - if(tdv.constant && !(tdv.init is TokenRValConst)) + if(tdv.constant && tdv.init is not TokenRValConst) { tdv.init = tdv.init.TryComputeConstant(LookupInitConstants, ref didOne); } @@ -693,9 +689,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine { if(tdv.constant) { - if(tdv.init is TokenRValConst) + if (tdv.init is TokenRValConst rvc) { - TokenRValConst rvc = (TokenRValConst)tdv.init; tdv.type = rvc.tokType; tdv.location = rvc.GetCompValu(); } @@ -707,16 +702,15 @@ namespace OpenSim.Region.ScriptEngine.Yengine } foreach(TokenDeclSDType sdType in tokenScript.sdSrcTypesValues) { - if(!(sdType is TokenDeclSDTypeClass)) + if(sdType is not TokenDeclSDTypeClass) continue; currentSDTClass = (TokenDeclSDTypeClass)sdType; foreach(TokenDeclVar tdv in currentSDTClass.members) { if(tdv.constant) { - if(tdv.init is TokenRValConst) + if (tdv.init is TokenRValConst rvc) { - TokenRValConst rvc = (TokenRValConst)tdv.init; tdv.type = rvc.tokType; tdv.location = rvc.GetCompValu(); } @@ -734,7 +728,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine // class to be instantiated via the new operator. foreach(TokenDeclSDType sdType in tokenScript.sdSrcTypesValues) { - if(!(sdType is TokenDeclSDTypeClass)) + if(sdType is not TokenDeclSDTypeClass) continue; TokenDeclSDTypeClass sdtClass = (TokenDeclSDTypeClass)sdType; @@ -799,7 +793,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine } foreach(TokenDeclSDType sdType in tokenScript.sdSrcTypesValues) { - if(!(sdType is TokenDeclSDTypeClass)) + if(sdType is not TokenDeclSDTypeClass) continue; TokenDeclSDTypeClass sdtClass = (TokenDeclSDTypeClass)sdType; foreach(TokenDeclVar declVar in sdtClass.members) @@ -834,12 +828,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine } foreach(TokenDeclSDType sdType in tokenScript.sdSrcTypesValues) { - if(sdType is TokenDeclSDTypeClass) + if (sdType is TokenDeclSDTypeClass sdtClass) { - TokenDeclSDTypeClass sdtClass = (TokenDeclSDTypeClass)sdType; - foreach(TokenDeclVar declFunc in sdtClass.members) + foreach (TokenDeclVar declFunc in sdtClass.members) { - if((declFunc.retType != null) && ((declFunc.sdtFlags & ScriptReduce.SDT_ABSTRACT) == 0)) + if ((declFunc.retType != null) && ((declFunc.sdtFlags & ScriptReduce.SDT_ABSTRACT) == 0)) GenerateMethodHeader(declFunc); } } @@ -853,12 +846,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine } foreach(TokenDeclSDType sdType in tokenScript.sdSrcTypesValues) { - if(sdType is TokenDeclSDTypeClass) + if (sdType is TokenDeclSDTypeClass sdtClass) { - TokenDeclSDTypeClass sdtClass = (TokenDeclSDTypeClass)sdType; - foreach(TokenDeclVar declFunc in sdtClass.members) + foreach (TokenDeclVar declFunc in sdtClass.members) { - if((declFunc.retType != null) && ((declFunc.sdtFlags & ScriptReduce.SDT_ABSTRACT) == 0)) + if ((declFunc.retType != null) && ((declFunc.sdtFlags & ScriptReduce.SDT_ABSTRACT) == 0)) GenerateMethodBody(declFunc); } } @@ -877,11 +869,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine } if(defaultStateEntry == null) { - defaultStateEntry = new TokenDeclVar(tokenScript.defaultState.body, null, tokenScript); - defaultStateEntry.name = new TokenName(tokenScript.defaultState.body, "state_entry"); - defaultStateEntry.retType = new TokenTypeVoid(tokenScript.defaultState.body); - defaultStateEntry.argDecl = new TokenArgDecl(tokenScript.defaultState.body); - defaultStateEntry.body = new TokenStmtBlock(tokenScript.defaultState.body); + defaultStateEntry = new TokenDeclVar(tokenScript.defaultState.body, null, tokenScript) + { + name = new TokenName(tokenScript.defaultState.body, "state_entry"), + retType = new TokenTypeVoid(tokenScript.defaultState.body), + argDecl = new TokenArgDecl(tokenScript.defaultState.body), + body = new TokenStmtBlock(tokenScript.defaultState.body) + }; defaultStateEntry.body.function = defaultStateEntry; defaultStateEntry.nextToken = tokenScript.defaultState.body.eventFuncs; @@ -1183,56 +1177,70 @@ namespace OpenSim.Region.ScriptEngine.Yengine newobjDeclFunc.sdtClass = ctorDeclFunc.sdtClass; newobjDeclFunc.sdtFlags = ScriptReduce.SDT_STATIC | ctorDeclFunc.sdtFlags; - // Declare local variable named '$objptr' in a frame just under - // what the '$new(...)' function's arguments are declared in. - TokenDeclVar objptrVar = new TokenDeclVar(newobjDeclFunc, newobjDeclFunc, tokenScript); - objptrVar.type = newobjDeclFunc.retType; - objptrVar.name = new TokenName(newobjDeclFunc, "$objptr"); - VarDict newFrame = new VarDict(false); - newFrame.outerVarDict = ctorDeclFunc.argDecl.varDict; + // Declare local variable named '$objptr' in a frame just under + // what the '$new(...)' function's arguments are declared in. + TokenDeclVar objptrVar = new TokenDeclVar(newobjDeclFunc, newobjDeclFunc, tokenScript) + { + type = newobjDeclFunc.retType, + name = new TokenName(newobjDeclFunc, "$objptr") + }; + VarDict newFrame = new VarDict(false) + { + outerVarDict = ctorDeclFunc.argDecl.varDict + }; newFrame.AddEntry(objptrVar); // Set up '$objptr.$ctor' TokenLValName objptrLValName = new TokenLValName(objptrVar.name, newFrame); // ref a var by giving its name - TokenLValIField objptrDotCtor = new TokenLValIField(newobjDeclFunc); // an instance member reference - objptrDotCtor.baseRVal = objptrLValName; // '$objptr' - objptrDotCtor.fieldName = ctorDeclFunc.name; // '.' '$ctor' + TokenLValIField objptrDotCtor = new TokenLValIField(newobjDeclFunc) + { + baseRVal = objptrLValName, // '$objptr' + fieldName = ctorDeclFunc.name // '.' '$ctor' + }; // an instance member reference - // Set up '$objptr.$ctor(arglist)' call for use in the '$new(...)' body. - // Copy the arglist from the constructor declaration so triviality - // processing will pick the correct overloaded constructor. - TokenRValCall callCtorRVal = new TokenRValCall(newobjDeclFunc); // doing a call of some sort - callCtorRVal.meth = objptrDotCtor; // calling $objptr.$ctor() + // Set up '$objptr.$ctor(arglist)' call for use in the '$new(...)' body. + // Copy the arglist from the constructor declaration so triviality + // processing will pick the correct overloaded constructor. + TokenRValCall callCtorRVal = new TokenRValCall(newobjDeclFunc) + { + meth = objptrDotCtor // calling $objptr.$ctor() + }; // doing a call of some sort TokenDeclVar[] argList = newobjDeclFunc.argDecl.vars; // get args $new() was declared with callCtorRVal.nArgs = argList.Length; // ...that is nArgs we are passing to $objptr.$ctor() for(int i = argList.Length; --i >= 0;) { TokenDeclVar arg = argList[i]; // find out about one of the args - TokenLValName argLValName = new TokenLValName(arg.name, ctorDeclFunc.argDecl.varDict); - // pass arg of that name to $objptr.$ctor() - argLValName.nextToken = callCtorRVal.args; // link to list of args passed to $objptr.$ctor() + TokenLValName argLValName = new TokenLValName(arg.name, ctorDeclFunc.argDecl.varDict) + { + // pass arg of that name to $objptr.$ctor() + nextToken = callCtorRVal.args // link to list of args passed to $objptr.$ctor() + }; callCtorRVal.args = argLValName; } - // Set up a funky call to the constructor for the code body. - // This will let code generator know there is some craziness. - // See GenerateStmtNewobj(). - // - // This is in essence: - // { - // classname $objptr = newobj (classname); - // $objptr.$ctor (...); - // return $objptr; - // } - TokenStmtNewobj newobjStmtBody = new TokenStmtNewobj(ctorDeclFunc); - newobjStmtBody.objptrVar = objptrVar; - newobjStmtBody.rValCall = callCtorRVal; - TokenStmtBlock newobjBody = new TokenStmtBlock(ctorDeclFunc); - newobjBody.statements = newobjStmtBody; + // Set up a funky call to the constructor for the code body. + // This will let code generator know there is some craziness. + // See GenerateStmtNewobj(). + // + // This is in essence: + // { + // classname $objptr = newobj (classname); + // $objptr.$ctor (...); + // return $objptr; + // } + TokenStmtNewobj newobjStmtBody = new TokenStmtNewobj(ctorDeclFunc) + { + objptrVar = objptrVar, + rValCall = callCtorRVal + }; + TokenStmtBlock newobjBody = new TokenStmtBlock(ctorDeclFunc) + { + statements = newobjStmtBody + }; - // Link that code as the body of the function. + // Link that code as the body of the function. newobjDeclFunc.body = newobjBody; // Say the function calls '$objptr.$ctor(arglist)' so we will inherit ctor's triviality. @@ -1281,7 +1289,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine // after putting return value in __retval. retLabel = ilGen.DefineLabel("__retlbl"); retValue = null; - if(!(curDeclFunc.retType is TokenTypeVoid)) + if(curDeclFunc.retType is not TokenTypeVoid) { retValue = ilGen.DeclareLocal(curDeclFunc.retType.ToSysType(), "__retval"); } @@ -1341,10 +1349,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine // various $staticfieldinit(); foreach(TokenDeclSDType sdType in tokenScript.sdSrcTypesValues) { - if(sdType is TokenDeclSDTypeClass) + if(sdType is TokenDeclSDTypeClass sdTypeClass) { - TokenDeclVar sfiFunc = ((TokenDeclSDTypeClass)sdType).staticFieldInit; - if((sfiFunc != null) && (sfiFunc.body.statements != null)) + TokenDeclVar sfiFunc = sdTypeClass.staticFieldInit; + if((sfiFunc is not null) && (sfiFunc.body.statements is not null)) { sfiFunc.location.CallPre(this, sfiFunc); sfiFunc.location.CallPost(this, sfiFunc); @@ -1399,7 +1407,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine // returns 'void'. if (mightGetHere) { - if(!(curDeclFunc.retType is TokenTypeVoid)) + if(curDeclFunc.retType is not TokenTypeVoid) { ErrorMsg(curDeclFunc.body, "missing final return statement"); } @@ -1413,7 +1421,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine // list below to look for active locals and temps. collector.Optimize(); _ilGen = collector.WriteOutAll(); - collector = null; List activeTemps = null; if (!isTrivial) @@ -1447,7 +1454,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine // GenerateFrameCaptureCode(); // __endFin: // } - ScriptMyLabel endFin = null; if(!isTrivial) { ilGen.BeginFinallyBlock(); @@ -1457,7 +1463,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine ilGen.Emit(curDeclFunc, OpCodes.Ldc_I4, stackframesize); ilGen.Emit(curDeclFunc, OpCodes.Add); ilGen.Emit(curDeclFunc, OpCodes.Stfld, stackLeftFieldInfo); - endFin = ilGen.DefineLabel("__endFin"); + ScriptMyLabel endFin = ilGen.DefineLabel("__endFin"); PushXMRInst(); ilGen.Emit(curDeclFunc, OpCodes.Ldfld, callModeFieldInfo); ilGen.Emit(curDeclFunc, OpCodes.Ldc_I4, XMRInstAbstract.CallMode_SAVE); @@ -1479,7 +1485,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine ilGen.Emit(curDeclFunc, OpCodes.Stfld, heapUsedFieldInfo); } - if (!(curDeclFunc.retType is TokenTypeVoid)) + if (curDeclFunc.retType is not TokenTypeVoid) { ilGen.Emit(curDeclFunc, OpCodes.Ldloc, retValue); } @@ -1757,103 +1763,103 @@ namespace OpenSim.Region.ScriptEngine.Yengine private void GenerateStmt(TokenStmt stmt) { errorMessageToken = stmt; - if(stmt is TokenDeclVar) + if(stmt is TokenDeclVar TokenDeclVarstmt) { - GenerateDeclVar((TokenDeclVar)stmt); + GenerateDeclVar(TokenDeclVarstmt); return; } - if(stmt is TokenStmtBlock) + if(stmt is TokenStmtBlock TokenStmtBlockstmt) { - GenerateStmtBlock((TokenStmtBlock)stmt); + GenerateStmtBlock(TokenStmtBlockstmt); return; } - if(stmt is TokenStmtBreak) + if(stmt is TokenStmtBreak TokenStmtBreakstmt) { - GenerateStmtBreak((TokenStmtBreak)stmt); + GenerateStmtBreak(TokenStmtBreakstmt); return; } - if(stmt is TokenStmtCont) + if(stmt is TokenStmtCont TokenStmtContstmt) { - GenerateStmtCont((TokenStmtCont)stmt); + GenerateStmtCont(TokenStmtContstmt); return; } - if(stmt is TokenStmtDo) + if(stmt is TokenStmtDo TokenStmtDostmt) { - GenerateStmtDo((TokenStmtDo)stmt); + GenerateStmtDo(TokenStmtDostmt); return; } - if(stmt is TokenStmtFor) + if(stmt is TokenStmtFor TokenStmtForstmt) { - GenerateStmtFor((TokenStmtFor)stmt); + GenerateStmtFor(TokenStmtForstmt); return; } - if(stmt is TokenStmtForEach) + if(stmt is TokenStmtForEach TokenStmtForEachstmt) { - GenerateStmtForEach((TokenStmtForEach)stmt); + GenerateStmtForEach(TokenStmtForEachstmt); return; } - if(stmt is TokenStmtIf) + if(stmt is TokenStmtIf TokenStmtIfstmt) { - GenerateStmtIf((TokenStmtIf)stmt); + GenerateStmtIf(TokenStmtIfstmt); return; } - if(stmt is TokenStmtJump) + if(stmt is TokenStmtJump TokenStmtJumpstmt) { - GenerateStmtJump((TokenStmtJump)stmt); + GenerateStmtJump(TokenStmtJumpstmt); return; } - if(stmt is TokenStmtLabel) + if(stmt is TokenStmtLabel TokenStmtLabelstmt) { - GenerateStmtLabel((TokenStmtLabel)stmt); + GenerateStmtLabel(TokenStmtLabelstmt); return; } - if(stmt is TokenStmtNewobj) + if(stmt is TokenStmtNewobj TokenStmtNewobjstmt) { - GenerateStmtNewobj((TokenStmtNewobj)stmt); + GenerateStmtNewobj(TokenStmtNewobjstmt); return; } if(stmt is TokenStmtNull) { return; } - if(stmt is TokenStmtRet) + if(stmt is TokenStmtRet TokenStmtRetstmt) { - GenerateStmtRet((TokenStmtRet)stmt); + GenerateStmtRet(TokenStmtRetstmt); return; } - if(stmt is TokenStmtRVal) + if(stmt is TokenStmtRVal TokenStmtRValstmt) { - GenerateStmtRVal((TokenStmtRVal)stmt); + GenerateStmtRVal(TokenStmtRValstmt); return; } - if(stmt is TokenStmtState) + if(stmt is TokenStmtState TokenStmtStatestmt) { - GenerateStmtState((TokenStmtState)stmt); + GenerateStmtState(TokenStmtStatestmt); return; } - if(stmt is TokenStmtSwitch) + if(stmt is TokenStmtSwitch TokenStmtSwitchstmt) { - GenerateStmtSwitch((TokenStmtSwitch)stmt); + GenerateStmtSwitch(TokenStmtSwitchstmt); return; } - if(stmt is TokenStmtThrow) + if(stmt is TokenStmtThrow TokenStmtThrowstmt) { - GenerateStmtThrow((TokenStmtThrow)stmt); + GenerateStmtThrow(TokenStmtThrowstmt); return; } - if(stmt is TokenStmtTry) + if(stmt is TokenStmtTry TokenStmtTrystmt) { - GenerateStmtTry((TokenStmtTry)stmt); + GenerateStmtTry(TokenStmtTrystmt); return; } - if(stmt is TokenStmtVarIniDef) + if(stmt is TokenStmtVarIniDef TokenStmtVarIniDefstmt) { - GenerateStmtVarIniDef((TokenStmtVarIniDef)stmt); + GenerateStmtVarIniDef(TokenStmtVarIniDefstmt); return; } - if(stmt is TokenStmtWhile) + if(stmt is TokenStmtWhile TokenStmtWhilestmt) { - GenerateStmtWhile((TokenStmtWhile)stmt); + GenerateStmtWhile(TokenStmtWhilestmt); return; } throw new Exception("unknown TokenStmt type " + stmt.GetType().ToString()); @@ -2063,7 +2069,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine if(forEachStmt.keyLVal != null) { keyLVal = GenerateFromLVal(forEachStmt.keyLVal); - if(!(keyLVal.type is TokenTypeObject)) + if(keyLVal.type is not TokenTypeObject) { ErrorMsg(forEachStmt.arrayRVal, "must be object"); } @@ -2071,12 +2077,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine if(forEachStmt.valLVal != null) { valLVal = GenerateFromLVal(forEachStmt.valLVal); - if(!(valLVal.type is TokenTypeObject)) + if(valLVal.type is not TokenTypeObject) { ErrorMsg(forEachStmt.arrayRVal, "must be object"); } } - if(!(arrayRVal.type is TokenTypeArray)) + if(arrayRVal.type is not TokenTypeArray) { ErrorMsg(forEachStmt.arrayRVal, "must be an array"); } @@ -2165,11 +2171,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine if(!mightGetHere) return; - bool constVal; - - // Test condition and see if constant test expression. + // Test condition and see if constant test expression. CompValu testRVal = GenerateFromRVal(ifStmt.testRVal); - if(IsConstBoolExpr(testRVal, out constVal)) + if (IsConstBoolExpr(testRVal, out bool constVal)) { // Constant, output just either the true or else part. if(constVal) @@ -2217,14 +2221,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine if(!mightGetHere) return; - // Make sure the target label is defined somewhere in the function. - TokenStmtLabel stmtLabel; - if(!curDeclFunc.labels.TryGetValue(jumpStmt.label.val, out stmtLabel)) + // Make sure the target label is defined somewhere in the function. + if (!curDeclFunc.labels.TryGetValue(jumpStmt.label.val, out TokenStmtLabel stmtLabel)) { ErrorMsg(jumpStmt, "undefined label " + jumpStmt.label.val); return; } - if(!stmtLabel.labelTagged) + if (!stmtLabel.labelTagged) { stmtLabel.labelStruct = ilGen.DefineLabel("jump_" + stmtLabel.name.val); stmtLabel.labelTagged = true; @@ -2318,12 +2321,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine { TokenStmtTry finallyBlock = finallyBlocksCalled.Pop(); string intername = "intr" + (++level) + "_" + target.name; - IntermediateLeave iLeave; - if(!finallyBlock.iLeaves.TryGetValue(intername, out iLeave)) + if (!finallyBlock.iLeaves.TryGetValue(intername, out IntermediateLeave iLeave)) { - iLeave = new IntermediateLeave(); - iLeave.jumpIntoLabel = ilGen.DefineLabel(intername); - iLeave.jumpAwayLabel = target; + iLeave = new IntermediateLeave + { + jumpIntoLabel = ilGen.DefineLabel(intername), + jumpAwayLabel = target + }; finallyBlock.iLeaves.Add(intername, iLeave); } target = iLeave.jumpIntoLabel; @@ -2608,10 +2612,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine } } - if(defaultLabel == null) - { - defaultLabel = ilGen.DefineLabel("default_" + switchStmt.Unique); - } + defaultLabel ??= ilGen.DefineLabel("default_" + switchStmt.Unique); // Output code to jump to the case statement's labels based on integer index on stack. // Note that each case still has the integer index on stack when jumped to. @@ -2754,7 +2755,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine curBreakTarg = new BreakContTarg(this, "switchbreak_" + switchStmt.Unique); // Make sure value is in a temp so we don't compute it more than once. - if(!(testRVal is CompValuTemp)) + if(testRVal is not CompValuTemp) { CompValuTemp temp = new CompValuTemp(testRVal.type, this); testRVal.PushVal(this, switchStmt); @@ -2814,10 +2815,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine caseTreeTop = BalanceTree(caseTreeTop); // Output compare and branch instructions in a tree-like fashion so we do O(log2 n) comparisons. - if(defaultLabel == null) - { - defaultLabel = ilGen.DefineLabel("default"); - } + defaultLabel ??= ilGen.DefineLabel("default"); OutputStrCase(testRVal, caseTreeTop, defaultLabel); // Output code for the cases themselves, in the order given by the programmer, @@ -3534,16 +3532,16 @@ namespace OpenSim.Region.ScriptEngine.Yengine } private CompValu GenerateFromLVal(TokenLVal lVal, TokenType[] argsig) { - if(lVal is TokenLValArEle) - return GenerateFromLValArEle((TokenLValArEle)lVal); - if(lVal is TokenLValBaseField) - return GenerateFromLValBaseField((TokenLValBaseField)lVal, argsig); - if(lVal is TokenLValIField) - return GenerateFromLValIField((TokenLValIField)lVal, argsig); - if(lVal is TokenLValName) - return GenerateFromLValName((TokenLValName)lVal, argsig); - if(lVal is TokenLValSField) - return GenerateFromLValSField((TokenLValSField)lVal, argsig); + if(lVal is TokenLValArEle TokenLValArElelVal) + return GenerateFromLValArEle(TokenLValArElelVal); + if(lVal is TokenLValBaseField TokenLValBaseFieldlVal) + return GenerateFromLValBaseField(TokenLValBaseFieldlVal, argsig); + if(lVal is TokenLValIField TokenLValIFieldlVal) + return GenerateFromLValIField(TokenLValIFieldlVal, argsig); + if(lVal is TokenLValName TokenLValNamelVal) + return GenerateFromLValName(TokenLValNamelVal, argsig); + if(lVal is TokenLValSField TokenLValSFieldlVal) + return GenerateFromLValSField(TokenLValSFieldlVal, argsig); throw new Exception("bad lval class"); } @@ -3564,10 +3562,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine { TokenRVal subRVal = lVal.subRVal; int nSubs = 1; - if(subRVal is TokenRValList) + if(subRVal is TokenRValList list) { - nSubs = ((TokenRValList)subRVal).nItems; - subRVal = ((TokenRValList)subRVal).rVal; + nSubs = list.nItems; + subRVal = list.rVal; } int rank = basetypestring.IndexOf(']') - basetypestring.IndexOf('['); @@ -3588,10 +3586,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine } // Maybe it is accessing the $idxprop property of a script-defined class. - if(baseCompValu.type is TokenTypeSDTypeClass) + if(baseCompValu.type is TokenTypeSDTypeClass typeclass) { TokenName name = new TokenName(lVal, "$idxprop"); - TokenTypeSDTypeClass sdtType = (TokenTypeSDTypeClass)baseCompValu.type; + TokenTypeSDTypeClass sdtType = typeclass; TokenDeclSDTypeClass sdtDecl = sdtType.decl; TokenDeclVar idxProp = FindThisMember(sdtDecl, name, null); if(idxProp == null) @@ -3613,10 +3611,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine } // Maybe they are accessing $idxprop property of a script-defined interface. - if(baseCompValu.type is TokenTypeSDTypeInterface) + if(baseCompValu.type is TokenTypeSDTypeInterface TokenTypeSDTypeInterfacebaseCompValutype) { TokenName name = new TokenName(lVal, "$idxprop"); - TokenTypeSDTypeInterface sdtType = (TokenTypeSDTypeInterface)baseCompValu.type; + TokenTypeSDTypeInterface sdtType = TokenTypeSDTypeInterfacebaseCompValutype; TokenDeclVar idxProp = FindInterfaceMember(sdtType, name, null, ref baseCompValu); if(idxProp == null) { @@ -3644,7 +3642,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine } // Access should be to XMR_Array otherwise. - if(!(baseCompValu.type is TokenTypeArray)) + if(baseCompValu.type is not TokenTypeArray) { ErrorMsg(lVal, "taking subscript of non-array"); return baseCompValu; @@ -3694,10 +3692,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine { TokenRVal subRVal = lVal.subRVal; int nSubs = 1; - if(subRVal is TokenRValList) + if(subRVal is TokenRValList list) { - nSubs = ((TokenRValList)subRVal).nItems; - subRVal = ((TokenRValList)subRVal).rVal; + nSubs = list.nItems; + subRVal = list.rVal; } if(nSubs != nArgs) @@ -3944,15 +3942,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine TokenType stType = lVal.baseType; string fieldName = lVal.fieldName.val + ArgSigString(argsig); - // Maybe they are accessing a static member of a script-defined class. - if(stType is TokenTypeSDTypeClass) + // Maybe they are accessing a static member of a script-defined class. + if (stType is TokenTypeSDTypeClass sdtType) { - TokenTypeSDTypeClass sdtType = (TokenTypeSDTypeClass)stType; TokenDeclVar declVar = FindThisMember(sdtType.decl, lVal.fieldName, argsig); - if(declVar != null) + if (declVar != null) { CheckAccess(declVar, lVal.fieldName); - if((declVar.sdtFlags & ScriptReduce.SDT_STATIC) == 0) + if ((declVar.sdtFlags & ScriptReduce.SDT_STATIC) == 0) { ErrorMsg(lVal.fieldName, "static reference to non-static member " + fieldName); return new CompValuVoid(lVal.fieldName); @@ -4002,42 +3999,42 @@ namespace OpenSim.Region.ScriptEngine.Yengine // Generate code for the computation and return resulting type and location. CompValu cVal = null; - if(rVal is TokenRValAsnPost) - cVal = GenerateFromRValAsnPost((TokenRValAsnPost)rVal); - else if (rVal is TokenRValAsnPre) - cVal = GenerateFromRValAsnPre((TokenRValAsnPre)rVal); - else if (rVal is TokenRValCall) - cVal = GenerateFromRValCall((TokenRValCall)rVal); - else if (rVal is TokenRValCast) - cVal = GenerateFromRValCast((TokenRValCast)rVal); - else if (rVal is TokenRValCondExpr) - cVal = GenerateFromRValCondExpr((TokenRValCondExpr)rVal); - else if (rVal is TokenRValConst) - cVal = GenerateFromRValConst((TokenRValConst)rVal); - else if (rVal is TokenRValInitDef) - cVal = GenerateFromRValInitDef((TokenRValInitDef)rVal); - else if (rVal is TokenRValIsType) - cVal = GenerateFromRValIsType((TokenRValIsType)rVal); - else if (rVal is TokenRValList) - cVal = GenerateFromRValList((TokenRValList)rVal); - else if (rVal is TokenRValNewArIni) - cVal = GenerateFromRValNewArIni((TokenRValNewArIni)rVal); - else if (rVal is TokenRValOpBin) - cVal = GenerateFromRValOpBin((TokenRValOpBin)rVal); - else if (rVal is TokenRValOpUn) - cVal = GenerateFromRValOpUn((TokenRValOpUn)rVal); - else if (rVal is TokenRValParen) - cVal = GenerateFromRValParen((TokenRValParen)rVal); - else if (rVal is TokenRValRot) - cVal = GenerateFromRValRot((TokenRValRot)rVal); - else if (rVal is TokenRValThis) - cVal = GenerateFromRValThis((TokenRValThis)rVal); - else if (rVal is TokenRValUndef) - cVal = GenerateFromRValUndef((TokenRValUndef)rVal); - else if (rVal is TokenRValVec) - cVal = GenerateFromRValVec((TokenRValVec)rVal); - else if (rVal is TokenLVal) - cVal = GenerateFromLVal((TokenLVal)rVal, argsig); + if(rVal is TokenRValAsnPost TokenRValAsnPostrVal) + cVal = GenerateFromRValAsnPost(TokenRValAsnPostrVal); + else if (rVal is TokenRValAsnPre TokenRValAsnPrerVal) + cVal = GenerateFromRValAsnPre(TokenRValAsnPrerVal); + else if (rVal is TokenRValCall TokenRValCallrVal) + cVal = GenerateFromRValCall(TokenRValCallrVal); + else if (rVal is TokenRValCast TokenRValCastrVal) + cVal = GenerateFromRValCast(TokenRValCastrVal); + else if (rVal is TokenRValCondExpr TokenRValCondExprrVal) + cVal = GenerateFromRValCondExpr(TokenRValCondExprrVal); + else if (rVal is TokenRValConst TokenRValConstrVal) + cVal = GenerateFromRValConst(TokenRValConstrVal); + else if (rVal is TokenRValInitDef TokenRValInitDefrVal) + cVal = GenerateFromRValInitDef(TokenRValInitDefrVal); + else if (rVal is TokenRValIsType TokenRValIsTyperVal) + cVal = GenerateFromRValIsType(TokenRValIsTyperVal); + else if (rVal is TokenRValList TokenRValListrVal) + cVal = GenerateFromRValList(TokenRValListrVal); + else if (rVal is TokenRValNewArIni TokenRValNewArInirVal) + cVal = GenerateFromRValNewArIni(TokenRValNewArInirVal); + else if (rVal is TokenRValOpBin TokenRValOpBinrVal) + cVal = GenerateFromRValOpBin(TokenRValOpBinrVal); + else if (rVal is TokenRValOpUn TokenRValOpUnrVal) + cVal = GenerateFromRValOpUn(TokenRValOpUnrVal); + else if (rVal is TokenRValParen TokenRValParenrVal) + cVal = GenerateFromRValParen(TokenRValParenrVal); + else if (rVal is TokenRValRot TokenRValRotrVal) + cVal = GenerateFromRValRot(TokenRValRotrVal); + else if (rVal is TokenRValThis TokenRValThisrVal) + cVal = GenerateFromRValThis(TokenRValThisrVal); + else if (rVal is TokenRValUndef TokenRValUndefrVal) + cVal = GenerateFromRValUndef(TokenRValUndefrVal); + else if (rVal is TokenRValVec TokenRValVecrVal) + cVal = GenerateFromRValVec(TokenRValVecrVal); + else if (rVal is TokenLVal TokenLValrVal) + cVal = GenerateFromLVal(TokenLValrVal, argsig); if(cVal == null) throw new Exception("bad rval class " + rVal.GetType().ToString()); @@ -4090,7 +4087,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine // of the delegate to select which overloaded method to use. if(opcodeIndex == "=") { - if(!(token.rValLeft is TokenLVal)) + if(token.rValLeft is not TokenLVal) { ErrorMsg(token, "invalid L-value for ="); return GenerateFromRVal(token.rValLeft); @@ -4180,9 +4177,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine // Compute left-hand operand and if true, compute right-hand operand. if(opcodeIndex == "&&&") { - bool leftVal, rightVal; + bool rightVal; left = GenerateFromRVal(token.rValLeft); - if(!IsConstBoolExpr(left, out leftVal)) + if(!IsConstBoolExpr(left, out bool leftVal)) { ScriptMyLabel falseLabel = ilGen.DefineLabel("ssandfalse"); left.PushVal(this, tokenTypeBool); @@ -4230,9 +4227,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine // Compute left-hand operand and if false, compute right-hand operand. if(opcodeIndex == "|||") { - bool leftVal, rightVal; + bool rightVal; left = GenerateFromRVal(token.rValLeft); - if(!IsConstBoolExpr(left, out leftVal)) + if(!IsConstBoolExpr(left, out bool leftVal)) { ScriptMyLabel trueLabel = ilGen.DefineLabel("ssortrue"); left.PushVal(this, tokenTypeBool); @@ -4284,9 +4281,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine // convert this to a call to that method with the right value as its single parameter. // Except don't if the right value is 'undef' so they can always compare to undef. TokenType leftType = token.rValLeft.GetRValType(this, null); - if((leftType is TokenTypeSDTypeClass) && !(right.type is TokenTypeUndef)) + if((leftType is TokenTypeSDTypeClass sdtType) && right.type is not TokenTypeUndef) { - TokenTypeSDTypeClass sdtType = (TokenTypeSDTypeClass)leftType; TokenDeclSDTypeClass sdtDecl = sdtType.decl; TokenType[] argsig = new TokenType[] { right.type }; TokenName funcName = new TokenName(token.opcode, "$op" + opcodeIndex); @@ -4306,19 +4302,18 @@ namespace OpenSim.Region.ScriptEngine.Yengine string rightIndex = right.type.ToString(); string key = leftIndex + opcodeIndex + rightIndex; - // If that key exists in table, then the operation is defined between those types - // ... and it produces an R-value of type as given in the table. - BinOpStr binOpStr; - if(BinOpStr.defined.TryGetValue(key, out binOpStr)) + // If that key exists in table, then the operation is defined between those types + // ... and it produces an R-value of type as given in the table. + if (BinOpStr.defined.TryGetValue(key, out BinOpStr binOpStr)) { - // If table contained an explicit assignment type like +=, output the statement without - // casting the L-value, then return the L-value as the resultant value. - // - // Make sure we don't include comparisons (such as ==, >=, etc). - // Nothing like +=, -=, %=, etc, generate a boolean, only the comparisons. - if((binOpStr.outtype != typeof(bool)) && opcodeIndex.EndsWith("=") && (opcodeIndex != "!=")) + // If table contained an explicit assignment type like +=, output the statement without + // casting the L-value, then return the L-value as the resultant value. + // + // Make sure we don't include comparisons (such as ==, >=, etc). + // Nothing like +=, -=, %=, etc, generate a boolean, only the comparisons. + if ((binOpStr.outtype != typeof(bool)) && opcodeIndex.EndsWith("=") && (opcodeIndex != "!=")) { - if(!(token.rValLeft is TokenLVal)) + if (token.rValLeft is not TokenLVal) { ErrorMsg(token.rValLeft, "invalid L-value"); return GenerateFromRVal(token.rValLeft); @@ -4328,18 +4323,18 @@ namespace OpenSim.Region.ScriptEngine.Yengine return left; } - // It's of the form left binop right. - // Compute left, perform operation then put result in a temp. + // It's of the form left binop right. + // Compute left, perform operation then put result in a temp. left = GenerateFromRVal(token.rValLeft); CompValu retRVal = new CompValuTemp(TokenType.FromSysType(token.opcode, binOpStr.outtype), this); binOpStr.emitBO(this, token, left, right, retRVal); return retRVal; } - // Nothing in the table, check for comparing object pointers because of the myriad of types possible. - // This will compare list pointers, null pointers, script-defined type pointers, array pointers, etc. - // It will show equal iff the memory addresses are equal and that is good enough. - if(!leftType.ToSysType().IsValueType && !right.type.ToSysType().IsValueType && ((opcodeIndex == "==") || (opcodeIndex == "!="))) + // Nothing in the table, check for comparing object pointers because of the myriad of types possible. + // This will compare list pointers, null pointers, script-defined type pointers, array pointers, etc. + // It will show equal iff the memory addresses are equal and that is good enough. + if (!leftType.ToSysType().IsValueType && !right.type.ToSysType().IsValueType && ((opcodeIndex == "==") || (opcodeIndex == "!="))) { CompValuTemp retRVal = new CompValuTemp(new TokenTypeInt(token), this); left = GenerateFromRVal(token.rValLeft); @@ -4361,11 +4356,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine // Likewise, integer += float not allowed because result is float, but float += integer is ok. if(opcodeIndex.EndsWith("=")) { - string op = opcodeIndex.Substring(0, opcodeIndex.Length - 1); + string op = opcodeIndex[..^1]; key = leftIndex + op + rightIndex; if(BinOpStr.defined.TryGetValue(key, out binOpStr)) { - if(!(token.rValLeft is TokenLVal)) + if(token.rValLeft is not TokenLVal) { ErrorMsg(token, "invalid L-value for ="); return GenerateFromRVal(token.rValLeft); @@ -4420,7 +4415,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine */ TokenType leftType = leftRVal.GetRValType(this, null); TokenType rightType = rightRVal.GetRValType(this, null); - if(!(leftType is TokenTypeStr) && !(rightType is TokenTypeStr)) + if(leftType is not TokenTypeStr && rightType is not TokenTypeStr) return false; // Also, list+string => list so reject that too. @@ -4476,12 +4471,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine rVal = rVal.TryComputeConstant(LookupBodyConstants, ref didOne); } while(didOne); - if(!(type is TokenTypeStr)) + if(type is not TokenTypeStr) goto pushasis; - if(!(rVal is TokenRValOpBin)) + if(rVal is not TokenRValOpBin) goto pushasis; TokenRValOpBin rValOpBin = (TokenRValOpBin)rVal; - if(!(rValOpBin.opcode is TokenKwAdd)) + if(rValOpBin.opcode is not TokenKwAdd) goto pushasis; if(StringConcatOperands(rValOpBin.rValLeft, rValOpBin.rValRight, scos, rValOpBin.opcode)) return; @@ -4498,14 +4493,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine { CompValu inRVal = GenerateFromRVal(token.rVal); - // Script-defined types can define their own methods to handle unary operators. - if(inRVal.type is TokenTypeSDTypeClass) + // Script-defined types can define their own methods to handle unary operators. + if (inRVal.type is TokenTypeSDTypeClass sdtType) { - TokenTypeSDTypeClass sdtType = (TokenTypeSDTypeClass)inRVal.type; TokenDeclSDTypeClass sdtDecl = sdtType.decl; TokenName funcName = new TokenName(token.opcode, "$op" + token.opcode.ToString()); TokenDeclVar declFunc = FindThisMember(sdtDecl, funcName, zeroArgs); - if(declFunc != null) + if (declFunc != null) { CheckAccess(declFunc, funcName); CompValu method = AccessInstanceMember(declFunc, inRVal, token, false); @@ -4513,7 +4507,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine } } - // Otherwise use the default. + // Otherwise use the default. return UnOpGenerate(inRVal, token.opcode); } @@ -4709,15 +4703,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine } } - // Inline functions know how to generate their own call. - if(method is CompValuInline) + // Inline functions know how to generate their own call. + if (method is CompValuInline inline) { - CompValuInline inline = (CompValuInline)method; inline.declInline.CodeGen(this, call, result, argRVals); return result; } - // Push whatever the function/method needs as a this argument, if anything. + // Push whatever the function/method needs as a this argument, if anything. method.CallPre(this, call); // Push the script-visible args, left-to-right. @@ -4771,9 +4764,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine // instaead of 'string ToString(float x)' or anything else TokenType[] argsig = null; TokenType outType = cast.castTo; - if(outType is TokenTypeSDTypeDelegate) + if(outType is TokenTypeSDTypeDelegate TokenTypeSDTypeDelegateoutType) { - argsig = ((TokenTypeSDTypeDelegate)outType).decl.GetArgTypes(); + argsig = TokenTypeSDTypeDelegateoutType.decl.GetArgTypes(); } // Generate the value that is being cast. @@ -4796,9 +4789,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine */ private CompValu GenerateFromRValCondExpr(TokenRValCondExpr rValCondExpr) { - bool condVal; CompValu condValu = GenerateFromRVal(rValCondExpr.condExpr); - if(IsConstBoolExpr(condValu, out condVal)) + if (IsConstBoolExpr(condValu, out bool condVal)) { return GenerateFromRVal(condVal ? rValCondExpr.trueExpr : rValCondExpr.falseExpr); } @@ -5028,9 +5020,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine // its size is the size of the largest initializer list at the next inner level foreach(Token val in values.tl) { - if(val is TokenList) + if (val is TokenList subvals) { - TokenList subvals = (TokenList)val; FillInDimSizes(dimSizes, dimNo, rank, subvals); } } @@ -5057,32 +5048,31 @@ namespace OpenSim.Region.ScriptEngine.Yengine { CompValu initValue = null; - // If it is a sublist, process it. - // If we don't have enough subscripts yet, hopefully that sublist will have enough. - // If we already have enough subscripts, then that sublist can be for an element of this supposedly jagged array. - if(val is TokenList) + // If it is a sublist, process it. + // If we don't have enough subscripts yet, hopefully that sublist will have enough. + // If we already have enough subscripts, then that sublist can be for an element of this supposedly jagged array. + if (val is TokenList sublist) { - TokenList sublist = (TokenList)val; - if(dimNo + 1 < rank) + if (dimNo + 1 < rank) { - // We don't have enough subscripts yet, hopefully the sublist has the rest. + // We don't have enough subscripts yet, hopefully the sublist has the rest. FillInInitVals(array, setMeth, subscripts, dimNo + 1, rank, sublist, eleType); } - else if((eleType is TokenTypeSDTypeClass) && (((TokenTypeSDTypeClass)eleType).decl.arrayOfType == null)) + else if ((eleType is TokenTypeSDTypeClass eleTypeclass) && (eleTypeclass.decl.arrayOfType is null)) { - // If we aren't a jagged array either, we can't do anything with the sublist. + // If we aren't a jagged array either, we can't do anything with the sublist. ErrorMsg(val, "too many brace levels"); } else { - // We are a jagged array, so malloc a subarray and initialize it with the sublist. - // Then we can use that subarray to fill this array's element. + // We are a jagged array, so malloc a subarray and initialize it with the sublist. + // Then we can use that subarray to fill this array's element. initValue = MallocAndInitArray(eleType, sublist); } } - // If it is a value expression, then output code to compute the value. - if(val is TokenRVal) + // If it is a value expression, then output code to compute the value. + if (val is TokenRVal val1) { if(dimNo + 1 < rank) { @@ -5090,7 +5080,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine } else { - initValue = GenerateFromRVal((TokenRVal)val); + initValue = GenerateFromRVal(val1); } } @@ -5252,14 +5242,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine */ private CompValu GenerateFromTypeExp(CompValu val, TokenTypeExp typeExp) { - if(typeExp is TokenTypeExpBinOp) + if(typeExp is TokenTypeExpBinOp op1) { - CompValu left = GenerateFromTypeExp(val, ((TokenTypeExpBinOp)typeExp).leftOp); - CompValu right = GenerateFromTypeExp(val, ((TokenTypeExpBinOp)typeExp).rightOp); + CompValu left = GenerateFromTypeExp(val, op1.leftOp); + CompValu right = GenerateFromTypeExp(val, op1.rightOp); CompValuTemp result = new CompValuTemp(tokenTypeBool, this); - Token op = ((TokenTypeExpBinOp)typeExp).binOp; - left.PushVal(this, ((TokenTypeExpBinOp)typeExp).leftOp); - right.PushVal(this, ((TokenTypeExpBinOp)typeExp).rightOp); + Token op = op1.binOp; + left.PushVal(this, op1.leftOp); + right.PushVal(this, op1.rightOp); if(op is TokenKwAnd) { ilGen.Emit(typeExp, OpCodes.And); @@ -5275,25 +5265,25 @@ namespace OpenSim.Region.ScriptEngine.Yengine result.Pop(this, typeExp); return result; } - if(typeExp is TokenTypeExpNot) + if(typeExp is TokenTypeExpNot expnot) { - CompValu interm = GenerateFromTypeExp(val, ((TokenTypeExpNot)typeExp).typeExp); + CompValu interm = GenerateFromTypeExp(val, expnot.typeExp); CompValuTemp result = new CompValuTemp(tokenTypeBool, this); - interm.PushVal(this, ((TokenTypeExpNot)typeExp).typeExp, tokenTypeBool); + interm.PushVal(this, expnot.typeExp, tokenTypeBool); ilGen.Emit(typeExp, OpCodes.Ldc_I4_1); ilGen.Emit(typeExp, OpCodes.Xor); result.Pop(this, typeExp); return result; } - if(typeExp is TokenTypeExpPar) + if(typeExp is TokenTypeExpPar TokenTypeExpPartypeExp) { - return GenerateFromTypeExp(val, ((TokenTypeExpPar)typeExp).typeExp); + return GenerateFromTypeExp(val, TokenTypeExpPartypeExp.typeExp); } - if(typeExp is TokenTypeExpType) + if(typeExp is TokenTypeExpType TokenTypeExpTypetypeExp) { CompValuTemp result = new CompValuTemp(tokenTypeBool, this); val.PushVal(this, typeExp); - ilGen.Emit(typeExp, OpCodes.Isinst, ((TokenTypeExpType)typeExp).typeToken.ToSysType()); + ilGen.Emit(typeExp, OpCodes.Isinst, TokenTypeExpTypetypeExp.typeToken.ToSysType()); ilGen.Emit(typeExp, OpCodes.Ldnull); ilGen.Emit(typeExp, OpCodes.Ceq); ilGen.Emit(typeExp, OpCodes.Ldc_I4_1); @@ -5411,30 +5401,29 @@ namespace OpenSim.Region.ScriptEngine.Yengine */ private bool IsConstBoolExprTrue(CompValu expr) { - bool constVal; - return IsConstBoolExpr(expr, out constVal) && constVal; + return IsConstBoolExpr(expr, out bool constVal) && constVal; } private bool IsConstBoolExpr(CompValu expr, out bool constVal) { - if(expr is CompValuChar) + if(expr is CompValuChar CompValuCharexpr) { - constVal = ((CompValuChar)expr).x != 0; + constVal = CompValuCharexpr.x != 0; return true; } - if(expr is CompValuFloat) + if(expr is CompValuFloat CompValuFloatexpr) { constVal = ((CompValuFloat)expr).x != (double)0; return true; } - if(expr is CompValuInteger) + if(expr is CompValuInteger CompValuIntegerexpr) { - constVal = ((CompValuInteger)expr).x != 0; + constVal = CompValuIntegerexpr.x != 0; return true; } - if(expr is CompValuString) + if(expr is CompValuString CompValuStringexpr) { - string s = ((CompValuString)expr).x; + string s = CompValuStringexpr.x; constVal = s != ""; if(constVal && (expr.type is TokenTypeKey)) { @@ -5456,14 +5445,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine */ private bool IsConstIntExpr(CompValu expr, out int constVal) { - if(expr is CompValuChar) + if(expr is CompValuChar CompValuCharexpr) { - constVal = (int)((CompValuChar)expr).x; + constVal = (int)CompValuCharexpr.x; return true; } - if(expr is CompValuInteger) + if(expr is CompValuInteger CompValuIntegerexpr) { - constVal = ((CompValuInteger)expr).x; + constVal = CompValuIntegerexpr.x; return true; } @@ -5480,9 +5469,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine */ private bool IsConstStrExpr(CompValu expr, out string constVal) { - if(expr is CompValuString) + if(expr is CompValuString exprstring) { - constVal = ((CompValuString)expr).x; + constVal = exprstring.x; return true; } constVal = ""; @@ -5518,10 +5507,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine TokenDeclVar var = fal.vars[j]; shortArgList.AddArg(var.type, var.name); } - TokenDeclVar shortArgProto = new TokenDeclVar(null, null, null); - shortArgProto.name = new TokenName(null, fap.GetSimpleName()); - shortArgProto.retType = fap.retType; - shortArgProto.argDecl = shortArgList; + TokenDeclVar shortArgProto = new TokenDeclVar(null, null, null) + { + name = new TokenName(null, fap.GetSimpleName()), + retType = fap.retType, + argDecl = shortArgList + }; leh.AddEntry(shortArgProto); } } @@ -5676,16 +5667,15 @@ namespace OpenSim.Region.ScriptEngine.Yengine { // If it is a static field of a script-defined type, look it up and hopefully we find a constant there. TokenDeclVar gblVar; - if(rVal is TokenLValSField) + if (rVal is TokenLValSField lvsf) { - TokenLValSField lvsf = (TokenLValSField)rVal; - if(lvsf.baseType is TokenTypeSDTypeClass) + if (lvsf.baseType is TokenTypeSDTypeClass basetypeclass) { - TokenDeclSDTypeClass sdtClass = ((TokenTypeSDTypeClass)lvsf.baseType).decl; + TokenDeclSDTypeClass sdtClass = basetypeclass.decl; gblVar = sdtClass.members.FindExact(lvsf.fieldName.val, null); - if(gblVar != null) + if (gblVar != null) { - if(gblVar.constant && (gblVar.init is TokenRValConst)) + if (gblVar.constant && (gblVar.init is TokenRValConst)) { didOne = true; return gblVar.init; @@ -5695,8 +5685,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine return rVal; } - // Only other thing we handle is stand-alone names. - if(!(rVal is TokenLValName)) + // Only other thing we handle is stand-alone names. + if (rVal is not TokenLValName) return rVal; string name = ((TokenLValName)rVal).name.val; @@ -5754,12 +5744,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine { // If it is a static field of a script-defined type, look it up and hopefully we find a constant there. TokenDeclVar gblVar; - if(rVal is TokenLValSField) + if(rVal is TokenLValSField lvsf) { - TokenLValSField lvsf = (TokenLValSField)rVal; - if(lvsf.baseType is TokenTypeSDTypeClass) + if(lvsf.baseType is TokenTypeSDTypeClass TokenTypeSDTypeClasslvsfbaseType) { - TokenDeclSDTypeClass sdtClass = ((TokenTypeSDTypeClass)lvsf.baseType).decl; + TokenDeclSDTypeClass sdtClass = TokenTypeSDTypeClasslvsfbaseType.decl; gblVar = sdtClass.members.FindExact(lvsf.fieldName.val, null); if((gblVar != null) && gblVar.constant && (gblVar.init is TokenRValConst)) { @@ -5771,7 +5760,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine } // Only other thing we handle is stand-alone names. - if(!(rVal is TokenLValName)) + if(rVal is not TokenLValName) return rVal; string name = ((TokenLValName)rVal).name.val; @@ -5826,14 +5815,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine private static TokenRVal CompValuConst2RValConst(CompValu val, TokenRVal rVal) { - if(val is CompValuChar) - rVal = new TokenRValConst(rVal, ((CompValuChar)val).x); - if(val is CompValuFloat) - rVal = new TokenRValConst(rVal, ((CompValuFloat)val).x); - if(val is CompValuInteger) - rVal = new TokenRValConst(rVal, ((CompValuInteger)val).x); - if(val is CompValuString) - rVal = new TokenRValConst(rVal, ((CompValuString)val).x); + if(val is CompValuChar CompValuCharval) + rVal = new TokenRValConst(rVal, CompValuCharval.x); + if(val is CompValuFloat CompValuFloatval) + rVal = new TokenRValConst(rVal, CompValuFloatval.x); + if(val is CompValuInteger CompValuIntegerval) + rVal = new TokenRValConst(rVal, CompValuIntegerval.x); + if(val is CompValuString CompValuStringval) + rVal = new TokenRValConst(rVal, CompValuStringval.x); return rVal; } @@ -5914,10 +5903,12 @@ namespace OpenSim.Region.ScriptEngine.Yengine ScriptConst scriptConst = ScriptConst.Lookup(lValName.name.val); if(scriptConst != null) { - TokenDeclVar var = new TokenDeclVar(lValName.name, null, tokenScript); - var.name = lValName.name; - var.type = scriptConst.rVal.type; - var.location = scriptConst.rVal; + TokenDeclVar var = new TokenDeclVar(lValName.name, null, tokenScript) + { + name = lValName.name, + type = scriptConst.rVal.type, + location = scriptConst.rVal + }; return var; } } @@ -5945,9 +5936,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine private TokenDeclVar FindInterfaceMember(TokenTypeSDTypeInterface sdtType, TokenName name, TokenType[] argsig, ref CompValu baseRVal) { TokenDeclSDTypeInterface sdtDecl = sdtType.decl; - TokenDeclSDTypeInterface impl; - TokenDeclVar declVar = sdtDecl.FindIFaceMember(this, name, argsig, out impl); - if((declVar != null) && (impl != sdtDecl)) + TokenDeclVar declVar = sdtDecl.FindIFaceMember(this, name, argsig, out TokenDeclSDTypeInterface impl); + if ((declVar != null) && (impl != sdtDecl)) { // Accessing a method or propterty of another interface that the primary interface says it implements. // In this case, we have to cast from the primary interface to that secondary interface. @@ -6214,10 +6204,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine for(int i = 0; i < argsig.Length; i++) { if(i > 0) - sb.Append(","); + sb.Append(','); sb.Append(argsig[i].ToString()); } - sb.Append(")"); + sb.Append(')'); return sb.ToString(); } @@ -6382,8 +6372,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine { if(o is IXMRUncatchable) return null; - if(o is ScriptRestoreCatchException) - return ((ScriptRestoreCatchException)o).e; + if(o is ScriptRestoreCatchException oe) + return oe.e; return o; } @@ -6397,8 +6387,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine { if(oo is IXMRUncatchable) return null; - if(oo is ScriptRestoreCatchException) - return ((ScriptRestoreCatchException)oo).ee; + if(oo is ScriptRestoreCatchException ooe) + return ooe.ee; return oo; } } diff --git a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptReduce.cs b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptReduce.cs index 869628d8c2..f2d9cfd52b 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptReduce.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptReduce.cs @@ -88,56 +88,57 @@ namespace OpenSim.Region.ScriptEngine.Yengine */ private static Dictionary PrecedenceInit() { - Dictionary p = new Dictionary(); + Dictionary p = new Dictionary + { + // http://www.lslwiki.net/lslwiki/wakka.php?wakka=operators - // http://www.lslwiki.net/lslwiki/wakka.php?wakka=operators + { typeof(TokenKwComma), 30 }, - p.Add(typeof(TokenKwComma), 30); + { typeof(TokenKwAsnLSh), ASNPR }, // all assignment operators of equal precedence + { typeof(TokenKwAsnRSh), ASNPR }, // ... so they get processed strictly right-to-left + { typeof(TokenKwAsnAdd), ASNPR }, + { typeof(TokenKwAsnAnd), ASNPR }, + { typeof(TokenKwAsnSub), ASNPR }, + { typeof(TokenKwAsnMul), ASNPR }, + { typeof(TokenKwAsnDiv), ASNPR }, + { typeof(TokenKwAsnMod), ASNPR }, + { typeof(TokenKwAsnOr), ASNPR }, + { typeof(TokenKwAsnXor), ASNPR }, + { typeof(TokenKwAssign), ASNPR }, - p.Add(typeof(TokenKwAsnLSh), ASNPR); // all assignment operators of equal precedence - p.Add(typeof(TokenKwAsnRSh), ASNPR); // ... so they get processed strictly right-to-left - p.Add(typeof(TokenKwAsnAdd), ASNPR); - p.Add(typeof(TokenKwAsnAnd), ASNPR); - p.Add(typeof(TokenKwAsnSub), ASNPR); - p.Add(typeof(TokenKwAsnMul), ASNPR); - p.Add(typeof(TokenKwAsnDiv), ASNPR); - p.Add(typeof(TokenKwAsnMod), ASNPR); - p.Add(typeof(TokenKwAsnOr), ASNPR); - p.Add(typeof(TokenKwAsnXor), ASNPR); - p.Add(typeof(TokenKwAssign), ASNPR); + { typeof(TokenKwQMark), 60 }, - p.Add(typeof(TokenKwQMark), 60); + { typeof(TokenKwOrOrOr), 70 }, + { typeof(TokenKwAndAndAnd), 80 }, - p.Add(typeof(TokenKwOrOrOr), 70); - p.Add(typeof(TokenKwAndAndAnd), 80); + { typeof(TokenKwOrOr), 100 }, - p.Add(typeof(TokenKwOrOr), 100); + { typeof(TokenKwAndAnd), 120 }, - p.Add(typeof(TokenKwAndAnd), 120); + { typeof(TokenKwOr), 140 }, - p.Add(typeof(TokenKwOr), 140); + { typeof(TokenKwXor), 160 }, - p.Add(typeof(TokenKwXor), 160); + { typeof(TokenKwAnd), 180 }, - p.Add(typeof(TokenKwAnd), 180); + { typeof(TokenKwCmpEQ), 200 }, + { typeof(TokenKwCmpNE), 200 }, - p.Add(typeof(TokenKwCmpEQ), 200); - p.Add(typeof(TokenKwCmpNE), 200); + { typeof(TokenKwCmpLT), 240 }, + { typeof(TokenKwCmpLE), 240 }, + { typeof(TokenKwCmpGT), 240 }, + { typeof(TokenKwCmpGE), 240 }, - p.Add(typeof(TokenKwCmpLT), 240); - p.Add(typeof(TokenKwCmpLE), 240); - p.Add(typeof(TokenKwCmpGT), 240); - p.Add(typeof(TokenKwCmpGE), 240); + { typeof(TokenKwRSh), 260 }, + { typeof(TokenKwLSh), 260 }, - p.Add(typeof(TokenKwRSh), 260); - p.Add(typeof(TokenKwLSh), 260); + { typeof(TokenKwAdd), 280 }, + { typeof(TokenKwSub), 280 }, - p.Add(typeof(TokenKwAdd), 280); - p.Add(typeof(TokenKwSub), 280); - - p.Add(typeof(TokenKwMul), 320); - p.Add(typeof(TokenKwDiv), 320); - p.Add(typeof(TokenKwMod), 320); + { typeof(TokenKwMul), 320 }, + { typeof(TokenKwDiv), 320 }, + { typeof(TokenKwMod), 320 } + }; return p; } @@ -713,17 +714,15 @@ namespace OpenSim.Region.ScriptEngine.Yengine public Token CatalogSDTypeDecl(TokenDeclSDType decl) { string longName = decl.longName.val; - TokenDeclSDType dupDecl; - if(!tokenScript.sdSrcTypesTryGetValue(longName, out dupDecl)) + if (!tokenScript.sdSrcTypesTryGetValue(longName, out TokenDeclSDType dupDecl)) { tokenScript.sdSrcTypesAdd(longName, decl); - if(decl.outerSDType != null) - decl.outerSDType.innerSDTypes.Add(decl.shortName.val, decl); + decl.outerSDType?.innerSDTypes.Add(decl.shortName.val, decl); return null; } - if(!dupDecl.isPartial || !decl.isPartial) + if (!dupDecl.isPartial || !decl.isPartial) { ErrorMsg(decl, "duplicate definition of type " + longName); ErrorMsg(dupDecl, "previous definition here"); @@ -3649,7 +3648,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine condExpr.falseExpr = ParseRVal(ref token, termTokenTypes); condExpr.prevToken = operands.prevToken; operands = condExpr; - termTokenTypes = new Type[0]; + termTokenTypes = Array.Empty(); goto done; } @@ -4458,15 +4457,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine // Splice instantiation (instdecl) in just before the beginning token of prototype (this.begToken). SpliceSourceToken(instdecl); - // Now for the fun part... Copy the rest of the prototype body to the - // instantiated body, replacing all generic parameter type tokens with - // the corresponding generic argument types. Note that the parameters - // are numbered starting with the outermost so we need the full genArgs - // array. Eg if we are doing 'Converter' from - // 'Dictionary.Converter', any V's are - // numbered [2]. Any [0]s or [1]s should be gone by now but it doesn't - // matter. - int index; + // Now for the fun part... Copy the rest of the prototype body to the + // instantiated body, replacing all generic parameter type tokens with + // the corresponding generic argument types. Note that the parameters + // are numbered starting with the outermost so we need the full genArgs + // array. Eg if we are doing 'Converter' from + // 'Dictionary.Converter', any V's are + // numbered [2]. Any [0]s or [1]s should be gone by now but it doesn't + // matter. Token it, pt; TokenDeclSDType innerProto = this; TokenDeclSDType innerInst = instdecl; @@ -4479,10 +4477,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine // if generic, eg doing Converter of Dictionary.Converter, we have to manually copy the W as well. // 2) outerSDType is transformed from Dictionary to Dictionary. // 3) innerSDTypes is rebuilt when/if we find classes that are inner to this one. - if(pt is TokenDeclSDType) + if(pt is TokenDeclSDType ptSDType) { // Make a new TokenDeclSDType{Class,Delegate,Interface}. - TokenDeclSDType ptSDType = (TokenDeclSDType)pt; TokenDeclSDType itSDType = ptSDType.MakeBlank(new TokenName(ptSDType.shortName, ptSDType.shortName.val)); // Set up the transformed outerSDType. @@ -4507,7 +4504,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine } // Check for an generic parameter to substitute out. - else if((pt is TokenName) && this.genParams.TryGetValue(((TokenName)pt).val, out index)) + else if((pt is TokenName) && this.genParams.TryGetValue(((TokenName)pt).val, out int index)) { it = genArgs[index].CopyToken(pt); } @@ -4602,8 +4599,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine */ protected TokenType MakeTypeToken(string name) { - TokenDeclSDType sdtdecl; - if(sdTypes.TryGetValue(name, out sdtdecl)) + if (sdTypes.TryGetValue(name, out TokenDeclSDType sdtdecl)) return sdtdecl.MakeRefToken(this); return TokenType.FromLSLType(this, name); } @@ -4890,8 +4886,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine { int i = sm.methVTI; string methName = sm.methName; - DynamicMethod dm; - if(scriptObjCode.dynamicMethods.TryGetValue(methName, out dm)) + if (scriptObjCode.dynamicMethods.TryGetValue(methName, out DynamicMethod dm)) { // method is not abstract vDynMeths[i] = dm; @@ -5112,10 +5107,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine { retStr = objFileReader.ReadString(); int nArgs = objFileReader.ReadInt32(); - if(asmFileWriter != null) - { - asmFileWriter.Write(" delegate " + retStr + " " + longName.val + "("); - } + asmFileWriter?.Write(" delegate " + retStr + " " + longName.val + "("); argStrs = new string[nArgs]; for(int i = 0; i < nArgs; i++) { @@ -5127,10 +5119,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine asmFileWriter.Write(argStrs[i]); } } - if(asmFileWriter != null) - { - asmFileWriter.WriteLine(");"); - } + asmFileWriter?.WriteLine(");"); } /** @@ -5188,9 +5177,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine */ public static TokenDeclSDTypeDelegate CreateInline(TokenType retType, TokenType[] argTypes) { - TokenDeclSDTypeDelegate decldel; - - // Name it after the whole signature string. + // Name it after the whole signature string. StringBuilder sb = new StringBuilder("$inline"); sb.Append(retType.ToString()); sb.Append('('); @@ -5204,7 +5191,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine } sb.Append(')'); string inlname = sb.ToString(); - if(!inlines.TryGetValue(inlname, out decldel)) + if(!inlines.TryGetValue(inlname, out TokenDeclSDTypeDelegate decldel)) { // Create the corresponding declaration and link to it TokenName name = new TokenName(null, inlname); @@ -5219,18 +5206,16 @@ namespace OpenSim.Region.ScriptEngine.Yengine public static string TryGetInlineName(Type sysType) { - string name; - if(!inlrevs.TryGetValue(sysType, out name)) - return null; - return name; + if(inlrevs.TryGetValue(sysType, out string name)) + return name; + return null; } public static Type TryGetInlineSysType(string name) { - TokenDeclSDTypeDelegate decl; - if(!inlines.TryGetValue(name, out decl)) - return null; - return decl.GetSysType(); + if (inlines.TryGetValue(name, out TokenDeclSDTypeDelegate decl)) + return decl.GetSysType(); + return null; } } @@ -5479,11 +5464,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine int nArgs = argTypes.Length; foreach(TokenDeclSDType decl in tokenScript.sdSrcTypesValues) { - if(decl is TokenDeclSDTypeDelegate) + if(decl is TokenDeclSDTypeDelegate decldelg) { - decldel = (TokenDeclSDTypeDelegate)decl; - TokenType rt = decldel.GetRetType(); - TokenType[] ats = decldel.GetArgTypes(); + TokenType rt = decldelg.GetRetType(); + TokenType[] ats = decldelg.GetArgTypes(); if((rt.ToString() == retType.ToString()) && (ats.Length == nArgs)) { for(int i = 0; i < nArgs; i++) @@ -5491,7 +5475,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine if(ats[i].ToString() != argTypes[i].ToString()) goto nomatch; } - this.decl = decldel; + this.decl = decldelg; return; } } @@ -5766,10 +5750,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine */ public TokenDeclVar(Token original, TokenDeclVar func, TokenScript ts) : base(original) { - if(func != null) - { - func.localVars.AddLast(this); - } + func?.localVars.AddLast(this); tokenScript = ts; } @@ -7283,8 +7264,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine // Everything else depends on both operands. string key = lType + opstr + rType; - BinOpStr binOpStr; - if(BinOpStr.defined.TryGetValue(key, out binOpStr)) + if(BinOpStr.defined.TryGetValue(key, out BinOpStr binOpStr)) { return TokenType.FromSysType(opcode, binOpStr.outtype); } @@ -7877,11 +7857,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine initStmt.DebString(sb); else sb.Append(';'); - if(testRVal != null) - testRVal.DebString(sb); + testRVal?.DebString(sb); sb.Append(';'); - if(incrRVal != null) - incrRVal.DebString(sb); + incrRVal?.DebString(sb); sb.Append(") "); bodyStmt.DebString(sb); } @@ -7903,11 +7881,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine public override void DebString(StringBuilder sb) { sb.Append("foreach ("); - if(keyLVal != null) - keyLVal.DebString(sb); + keyLVal?.DebString(sb); sb.Append(','); - if(valLVal != null) - valLVal.DebString(sb); + valLVal?.DebString(sb); sb.Append(" in "); arrayRVal.DebString(sb); sb.Append(')'); diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs index 754c950ede..79e2a67145 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstAbstract.cs @@ -557,18 +557,18 @@ namespace OpenSim.Region.ScriptEngine.Yengine // CallMode_NORMAL: run event handler from the beginning normally // CallMode_RESTORE: restore event handler stack from stackFrames - callMode = (stackFrames == null) ? XMRInstAbstract.CallMode_NORMAL : + callMode = (stackFrames is null) ? XMRInstAbstract.CallMode_NORMAL : XMRInstAbstract.CallMode_RESTORE; while(true) { - if(this.newStateCode < 0) + if(newStateCode < 0) { // Process event given by 'stateCode' and 'eventCode'. // The event handler should call CheckRun() as often as convenient. - int newState = this.stateCode; - seh = this.m_ObjCode.scriptEventHandlerTable[newState, (int)this.eventCode]; - if(seh != null) + int newState = stateCode; + seh = m_ObjCode.scriptEventHandlerTable[newState, (int)eventCode]; + if(seh is not null) { try { @@ -579,25 +579,25 @@ namespace OpenSim.Region.ScriptEngine.Yengine newState = scse.newState; } } - this.ehArgs = null; // we are done with them and no args for + ehArgs = null; // we are done with them and no args for // exit_state()/enter_state() anyway // The usual case is no state change. // Even a 'state ;' statement has no effect except to exit out. // It does not execute the state_exit() or state_entry() handlers. // See http://wiki.secondlife.com/wiki/State - if(newState == this.stateCode) + if(newState == stateCode) break; // Save new state in a more permanent location in case we // get serialized out while in the state_exit() handler. - this.newStateCode = newState; + newStateCode = newState; } // Call old state's state_exit() handler. - this.eventCode = ScriptEventCode.state_exit; - seh = this.m_ObjCode.scriptEventHandlerTable[this.stateCode, (int)ScriptEventCode.state_exit]; - if(seh != null) + eventCode = ScriptEventCode.state_exit; + seh = m_ObjCode.scriptEventHandlerTable[stateCode, (int)ScriptEventCode.state_exit]; + if(seh is not null) { try { @@ -605,24 +605,25 @@ namespace OpenSim.Region.ScriptEngine.Yengine } catch(ScriptChangeStateException scse) { - this.newStateCode = scse.newState; + newStateCode = scse.newState; } } // Switch over to the new state's state_entry() handler. - this.stateCode = this.newStateCode; - this.eventCode = ScriptEventCode.state_entry; - this.newStateCode = -1; + stateCode = newStateCode; + eventCode = ScriptEventCode.state_entry; + newStateCode = -1; // Now that the old state can't possibly start any more activity, // cancel any listening handlers, etc, of the old state. - this.StateChange(); + StateChange(); // Loop back to execute new state's state_entry() handler. } // Event no longer being processed. - this.eventCode = ScriptEventCode.None; + stackFrames = null; + eventCode = ScriptEventCode.None; } /** diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRInstRun.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstRun.cs index fe6be35bc8..f50e9a2b7a 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/XMRInstRun.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstRun.cs @@ -284,11 +284,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine try { - //m_RunOnePhase = "check entry invariants"; - CheckRunLockInvariants(true); - - // Maybe it has been Disposed() - if(m_Part is null || m_Part.Inventory is null) + // Maybe it has been Disposed() + if (m_Part is null || m_Part.Inventory is null) { //m_RunOnePhase = "runone saw it disposed"; return XMRInstState.DISPOSED; @@ -312,12 +309,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine m_Suspended = true; m_DetachReady.Set(); //m_RunOnePhase = "detach quantum went zero"; - CheckRunLockInvariants(true); return XMRInstState.FINISHED; } } //m_RunOnePhase = "resume old event handler"; + CheckRunLockInvariants(true); + m_LastRanAt = now; m_InstEHSlice++; callMode = CallMode_NORMAL; @@ -345,7 +343,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine if(m_Suspended) { //m_RunOnePhase = "m_Suspended is set"; - CheckRunLockInvariants(true); return XMRInstState.FINISHED; } @@ -365,7 +362,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine m_DetachReady.Set(); m_DetachQuantum = 0; //m_RunOnePhase = "nothing to do #3"; - CheckRunLockInvariants(true); return XMRInstState.FINISHED; } } @@ -387,14 +383,16 @@ namespace OpenSim.Region.ScriptEngine.Yengine m_DetachQuantum = 0; } //m_RunOnePhase = "nothing to do #4"; - CheckRunLockInvariants(true); return XMRInstState.FINISHED; } } - // Dequeued an event, so start it going until it either - // finishes or it calls CheckRun(). + // Dequeued an event, so start it going until it either + // finishes or it calls CheckRun(). //m_RunOnePhase = "start event handler"; + + CheckRunLockInvariants(true); + m_DetectParams = evt.DetectParams; m_LastRanAt = now; m_InstEHEvent++; @@ -404,12 +402,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine m_CPUTime += DateTime.UtcNow.Subtract(now).TotalMilliseconds; // Maybe it puqued. - if(e != null) + if(e is not null) { //m_RunOnePhase = "handling exception " + e.Message; HandleScriptException(e); //m_RunOnePhase = "return had exception " + e.Message; - CheckRunLockInvariants(true); return XMRInstState.FINISHED; } } @@ -432,28 +429,28 @@ namespace OpenSim.Region.ScriptEngine.Yengine /** * @brief Immediately after taking m_RunLock or just before releasing it, check invariants. */ - //private ScriptEventCode lastEventCode = ScriptEventCode.None; - //private bool lastActive = false; - //private string lastRunPhase = ""; - public void CheckRunLockInvariants(bool throwIt) { - // If not executing any event handler, there shouldn't be any saved stack frames. - // If executing an event handler, there should be some saved stack frames. - bool active = (stackFrames is not null); - if((active && (eventCode == ScriptEventCode.None)) || - (!active && (eventCode != ScriptEventCode.None))) + // If not executing any event handler, there shouldn't be any saved stack frames. + // If executing an event handler, there should be some saved stack frames. + if (eventCode == ScriptEventCode.None) { - m_log.Error("CheckRunLockInvariants: script=" + m_DescName); - m_log.Error("CheckRunLockInvariants: eventcode=" + eventCode.ToString() + ", active=" + active.ToString()); - //m_log.Error("CheckRunLockInvariants: m_RunOnePhase=" + m_RunOnePhase); - //m_log.Error("CheckRunLockInvariants: lastec=" + lastEventCode + ", lastAct=" + lastActive + ", lastPhase=" + lastRunPhase); - if(throwIt) - throw new Exception("CheckRunLockInvariants: eventcode=" + eventCode.ToString() + ", active=" + active.ToString()); + if (stackFrames is not null) + { + m_log.Error($"CheckRunLockInvariants: script {m_DescName}, eventcode: None, stackFrame not null"); + if (throwIt) + throw new Exception("CheckRunLockInvariants: eventcode=None, stackFrame not null"); + } + } + else + { + if (stackFrames is null) + { + m_log.Error($"CheckRunLockInvariants: script {m_DescName}, eventcode {eventCode}, stackFrame null"); + if (throwIt) + throw new Exception("CheckRunLockInvariants: eventcode=" + eventCode.ToString() + ", stackFrame null"); + } } - //lastEventCode = eventCode; - //lastActive = active; - //lastRunPhase = m_RunOnePhase; } /* @@ -483,7 +480,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine throw new Exception("still processing event " + this.eventCode.ToString()); // Silly to even try if there is no handler defined for this event. - if ((newEventCode >= 0) && (m_ObjCode.scriptEventHandlerTable[stateCode, (int)newEventCode] == null)) + if ((newEventCode >= 0) && (m_ObjCode.scriptEventHandlerTable[stateCode, (int)newEventCode] is null)) return null; // Save eventCode so we know what event handler to run in the microthread. @@ -813,10 +810,6 @@ namespace OpenSim.Region.ScriptEngine.Yengine // Reset everything and queue up default's start_entry() event. ClearQueue(); ResetLocked("external Reset"); - - // Mark it idle now so it can get queued to process new stuff. - - CheckRunLockInvariants(true); } } @@ -833,10 +826,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine } m_EventQueue.Clear(); - for(int i = m_EventCounts.Length; --i >= 0;) + for (int i = 0; i < m_EventCounts.Length; ++i) m_EventCounts[i] = 0; - for(int i = 0; i < n; i++) + for (int i = 0; i < n; i++) m_EventQueue.AddLast(linkMessages[i]); m_EventCounts[(int)ScriptEventCode.link_message] = n; @@ -848,7 +841,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine lock(m_QueueLock) { m_EventQueue.Clear(); // no events queued - for(int i = m_EventCounts.Length; --i >= 0;) + for (int i = 0; i < m_EventCounts.Length; ++i) m_EventCounts[i] = 0; } } @@ -876,7 +869,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine AsyncCommandManager.RemoveScript(m_Engine, m_LocalID, m_ItemID); //m_RunOnePhase = "ResetLocked: clearing current event"; - this.eventCode = ScriptEventCode.None; // not processing an event + eventCode = ScriptEventCode.None; // not processing an event m_DetectParams = null; // not processing an event m_SleepUntil = DateTime.MinValue; // not doing llSleep() m_ResetCount++; // has been reset once more @@ -1008,8 +1001,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine m_Suspended = false; m_DetachQuantum = 0; m_DetachReady.Set(); - if ((m_EventQueue != null) && - (m_EventQueue.First != null) && + if ((m_EventQueue is not null) && + (m_EventQueue.First is not null) && (m_IState == XMRInstState.IDLE)) { m_IState = XMRInstState.ONSTARTQ; diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index 4ad6930d86..2f64bca803 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -59,10 +59,10 @@ ; PrivatePort should closed at the firewall. ;# {PublicPort} {} {PublicPort} {8002 9000} "9000" - ; in case of a standalone this needs to match the parameter http_listener_port in section [Network] below - ; in that case the default is 9000 + ; in case of a standalone this needs to match the parameter http_listener_port in section [Network] below + ; in that case the default is 9000 PublicPort = "9000" - ; for a region on a grid, the grid services public port should be used, normal default is 8002 + ; for a region on a grid, the grid services public port should be used, normal default is 8002 ;PublicPort = "8002" ; you can also have them on a diferent url / IP @@ -641,6 +641,8 @@ ;# {ExternalHostNameForLSL} {} {Hostname to use for HTTP-IN URLs. This should be reachable from the internet.} {} ;; Hostname to use in llRequestURL/llRequestSecureURL ;; if not defined - llRequestURL/llRequestSecureURL are disabled + ;; this should be reachable from internet and point this machine + ;; for standalones it can be ExternalHostNameForLSL = ${Const|BaseHostname} ;# {shard} {} {Name to use for X-Secondlife-Shard header? (press enter if unsure)} {} OpenSim