Alexandria.Engines.GoldBox.Resources.ScriptOperand.MatchTypeCode C# (CSharp) Method

MatchTypeCode() private method

private MatchTypeCode ( ScriptArgument value ) : bool
value ScriptArgument
return bool
        internal bool MatchTypeCode(ScriptArgument value)
        {
            switch (value) {
                case ScriptArgument.Address: return Type == ScriptOperandType.Address;
                case ScriptArgument.Comparison: return Type == ScriptOperandType.Comparison;
                case ScriptArgument.Literal:
                case ScriptArgument.Value: return Type == ScriptOperandType.Value;
                case ScriptArgument.ValueOrVariable: return Type == ScriptOperandType.Value || Type == ScriptOperandType.Variable || Type == ScriptOperandType.UnknownVariable;
                case ScriptArgument.String: return Type == ScriptOperandType.String || Type == ScriptOperandType.StringVariable;
                case ScriptArgument.Variable: return Type == ScriptOperandType.Variable || Type == ScriptOperandType.UnknownVariable;

                case ScriptArgument.Opcode:
                case ScriptArgument.Optional: throw new InvalidOperationException();
                default: throw new NotImplementedException();
            }
        }

Usage Example

Ejemplo n.º 1
0
        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);
        }
All Usage Examples Of Alexandria.Engines.GoldBox.Resources.ScriptOperand::MatchTypeCode