Beispiel #1
0
        /// <summary>
        /// Получает числовое значение данного токена, если он является примитивным или значение уже подсчитано
        /// </summary>
        private Constant Parse(RuntimeDataPackage package)
        {
            if (_valueSet)
            {
                return(Value);
            }

            if (_referenceSet && Reference.Type == ReferenceType.Define)
            {
                return(new Constant(PreprocessorDirective.defines.Exists(p => p.Name == RawValue)));
            }

            if (_referenceSet && package != null)
            {
                if (Reference.Type == ReferenceType.Variable)
                {
                    var variable = package.GetVariable(Reference.Index);
                    if (variable.Value.Type.Type != Runtime.Structures.TypeReferenceType.Integer)
                    {
                        throw new Exception("Wrong object type!");
                    }

                    return(new Constant(variable.Value.IntegerValue));
                }
                else
                {
                    switch (Reference.Object.Type)
                    {
                    case FlashElementType.Constant:
                        return((Reference.Object as FlashElementConstant).ToConstant());

                    case FlashElementType.Variable:
                    case FlashElementType.Instruction:
                    case FlashElementType.Expression:
                    case FlashElementType.Undefined:
                    default:
                        throw new Exception("Wrong reference object!");
                    }
                }
            }
            else
            {
                Constant constant;
                var      error = Constant.Parse(RawValue, out constant);

                if (error != null)
                {
                    if (error.Type == ParseErrorType.Syntax_Constant_TooLong || error.Type == ParseErrorType.Syntax_Constant_BaseOverflow)
                    {
                        throw new Exception("Wrong const format");
                    }

                    throw new WrongTokenException();
                }
                else
                {
                    return(constant);
                }
            }
        }
Beispiel #2
0
 protected Variable GetVar(Integer index, RuntimeDataPackage package)
 {
     return(package.GetVariable(index));
 }