Ejemplo n.º 1
0
        /// <summary>
        /// Checks if a variable with the given identifier is
        /// available in the dictionary or the related wider
        /// scopes.
        /// </summary>
        /// <param name="strIdentifier">True if the variable
        /// is declared, or false otherwise.</param>
        /// <returns></returns>
        public bool IsDeclared(String strIdentifier)
        {
            switch (m_variableScope)
            {
            case VariableScope.Global:
                return(m_dictVariables.ContainsKey(strIdentifier));

            case VariableScope.Script:
                if (m_dictVariables.ContainsKey(strIdentifier))
                {
                    return(true);
                }
                else
                {
                    return(m_variableDicitonaryGlobal.IsDeclared(strIdentifier));
                }

            case VariableScope.Local:
                if (m_dictVariables.ContainsKey(strIdentifier))
                {
                    return(true);
                }
                else
                {
                    return(m_variableDicitonaryScript.IsDeclared(strIdentifier));
                }

            default:
                throw new ExecutionException("Variable scope '"
                                             + m_variableScope + "' not supported.");
            }
        }
Ejemplo n.º 2
0
        private void AssignVariable(Operand operandDest, object objectValue)
        {
            // dest id
            String strIdentifierDest = (String)operandDest.Value;

            switch (operandDest.Type)
            {
            case OperandType.Variable:
                // copy value (or assoc array ref)
                m_variableDictionaryLocal[strIdentifierDest]
                    = objectValue;
                break;

            case OperandType.LiteralIndexedVariable:
            case OperandType.VariableIndexedVariable:
                // copy into array element
                AssociativeArray associativeArray = null;

                // dest value
                object objectValueDest = null;
                if (m_variableDictionaryLocal.IsDeclared(strIdentifierDest))
                {
                    objectValueDest
                        = m_variableDictionaryLocal[strIdentifierDest];
                }
                else
                {
                    objectValueDest = NullReference.Instance;
                }

                if (objectValueDest.GetType() != typeof(AssociativeArray))
                {
                    // if old type not array and non-null assigned, throw error
                    throw new ExecutionException("Indexed destination "
                                                 + operandDest + " is not an associative array.");
                }
                else
                {
                    associativeArray = (AssociativeArray)objectValueDest;
                }

                // assign into array
                if (operandDest.Type == OperandType.LiteralIndexedVariable)
                {
                    // literal-indexed array
                    object objectIndex = operandDest.IndexLiteral;
                    associativeArray[objectIndex] = objectValue;
                }
                else
                {
                    // variable-indexed arrau
                    String strIdentifierIndex = operandDest.IndexIdentifier;
                    object objectIndex        = m_variableDictionaryLocal[strIdentifierIndex];
                    associativeArray[objectIndex] = objectValue;
                }
                break;

            case OperandType.Literal:
                throw new ExecutionException("MOV destination operand cannot be a literal.");
            }
        }