private MatchTypeCode ( ScriptArgument value ) : bool | ||
value | ScriptArgument | |
return | bool |
protected bool ReadOperand(BinaryReader reader, string operands, ref int operandIndex, ScriptArgument operandCode) { long offset = reader.BaseStream.Position; ScriptOperand token = new ScriptOperand(reader, operandCode); token.Instruction = this; int outputIndex = OperandsMutable.Count; OperandsMutable.Add(token); switch (operandCode) { case ScriptArgument.Address: case ScriptArgument.Value: case ScriptArgument.ValueOrVariable: case ScriptArgument.String: case ScriptArgument.Variable: case ScriptArgument.Literal: case ScriptArgument.UnknownVariable: case ScriptArgument.Comparison: token.IsValid = token.MatchTypeCode(operandCode); break; case ScriptArgument.Array: ScriptArgument arrayCountType = (ScriptArgument)operands[++operandIndex]; ScriptArgument arrayType = (ScriptArgument)operands[++operandIndex]; if (IsCompoundOperandCode(arrayCountType) || IsCompoundOperandCode(arrayType)) { throw new InvalidOperationException(); } token.IsValid = token.MatchTypeCode(arrayCountType); if (!token.IsValid) { OperandsMutable[outputIndex] = token; return(false); } for (int index = 0; index < token.AsValue; index++) { if (!ReadOperand(reader, operands, ref operandIndex, arrayType)) { return(false); } } break; case ScriptArgument.Optional: operandCode = (ScriptArgument)operands[++operandIndex]; if (!token.MatchTypeCode(operandCode)) { reader.BaseStream.Position = offset; OperandsMutable.RemoveAt(outputIndex); return(true); } break; default: throw new InvalidOperationException("Invalid operand type code '" + operandCode + "'."); } OperandsMutable[outputIndex] = token; return(true); }
protected bool ReadOperand(BinaryReader reader, string operands, ref int operandIndex, ScriptArgument operandCode) { long offset = reader.BaseStream.Position; ScriptOperand token = new ScriptOperand(reader, operandCode); token.Instruction = this; int outputIndex = OperandsMutable.Count; OperandsMutable.Add(token); switch (operandCode) { case ScriptArgument.Address: case ScriptArgument.Value: case ScriptArgument.ValueOrVariable: case ScriptArgument.String: case ScriptArgument.Variable: case ScriptArgument.Literal: case ScriptArgument.UnknownVariable: case ScriptArgument.Comparison: token.IsValid = token.MatchTypeCode(operandCode); break; case ScriptArgument.Array: ScriptArgument arrayCountType = (ScriptArgument)operands[++operandIndex]; ScriptArgument arrayType = (ScriptArgument)operands[++operandIndex]; if (IsCompoundOperandCode(arrayCountType) || IsCompoundOperandCode(arrayType)) throw new InvalidOperationException(); token.IsValid = token.MatchTypeCode(arrayCountType); if (!token.IsValid) { OperandsMutable[outputIndex] = token; return false; } for (int index = 0; index < token.AsValue; index++) if (!ReadOperand(reader, operands, ref operandIndex, arrayType)) return false; break; case ScriptArgument.Optional: operandCode = (ScriptArgument)operands[++operandIndex]; if (!token.MatchTypeCode(operandCode)) { reader.BaseStream.Position = offset; OperandsMutable.RemoveAt(outputIndex); return true; } break; default: throw new InvalidOperationException("Invalid operand type code '" + operandCode + "'."); } OperandsMutable[outputIndex] = token; return true; }