Пример #1
0
        //private StiParserDataType get_category2(object par)
        //{
        //    //if (par == null) return StiParserDataType.None;
        //    if (par == null) return StiParserDataType.Object;
        //    Type type = par.GetType();
        //    if (type == typeof(double)) return StiParserDataType.zDouble;
        //    if (type == typeof(decimal)) return StiParserDataType.zDecimal;
        //    if (type == typeof(Int32)) return StiParserDataType.Int32;
        //    if (type == typeof(string)) return StiParserDataType.String;
        //    if (type == typeof(bool)) return StiParserDataType.Bool;
        //    if (type == typeof(float)) return StiParserDataType.zFloat;
        //    if (type == typeof(UInt32)) return StiParserDataType.UInt32;
        //    if (type == typeof(byte)) return StiParserDataType.Byte;
        //    if (type == typeof(sbyte)) return StiParserDataType.SByte;
        //    if (type == typeof(Int16)) return StiParserDataType.Int16;
        //    if (type == typeof(UInt16)) return StiParserDataType.UInt16;
        //    if (type == typeof(Int64)) return StiParserDataType.Int64;
        //    if (type == typeof(UInt64)) return StiParserDataType.UInt64;
        //    if (type == typeof(char)) return StiParserDataType.Char;
        //    if (type == typeof(DateTime)) return StiParserDataType.DateTime;
        //    if (type == typeof(TimeSpan)) return StiParserDataType.TimeSpan;
        //    if (type == typeof(System.Drawing.Image)) return StiParserDataType.Image;
        //    if (type == typeof(object)) return StiParserDataType.Object;
        //    return StiParserDataType.None;
        //}

        #region CheckParserMethodInfo
        private int CheckParserMethodInfo(ProryvFunctionType type, ArrayList args)
        {
            int count = args.Count;

            Type[] types = new Type[count];
            for (int index = 0; index < count; index++)
            {
                if (args[index] == null)
                {
                    types[index] = typeof(object);
                }
                else
                {
                    types[index] = args[index].GetType();
                }
            }

            StiParserMethodInfo methodInfo = GetParserMethodInfo(type, types);

            if (methodInfo != null)
            {
                return(methodInfo.Number);
            }

            return(0);
        }
Пример #2
0
        private void CheckTypes(List <StiAsmCommand> asmList)
        {
            if (asmList == null || asmList.Count == 0)
            {
                return;
            }
            Stack <StiCheckTypeData> stack    = new Stack <StiCheckTypeData>();
            List <StiCheckTypeData>  argsList = null;

            Type[]           types = null;
            StiCheckTypeData par1;
            StiCheckTypeData par2;

            foreach (StiAsmCommand asmCommand in asmList)
            {
                Type type = typeof(object);

                switch (asmCommand.Type)
                {
                case StiAsmCommandType.PushValue:
                    stack.Push(new StiCheckTypeData(asmCommand.Parameter1.GetType(), asmCommand.Position, asmCommand.Length));
                    break;

                //case StiAsmCommandType.PushVariable:
                //    #region push variable type
                //    string varName = (string)asmCommand.Parameter1;
                //    StiVariable var = report.Dictionary.Variables[varName];
                //    if (var != null)
                //    {
                //        type = var.Type;
                //    }
                //    else
                //    {
                //        if (report.Variables != null && report.Variables.ContainsKey(varName))
                //        {
                //            object varValue = report.Variables[varName];
                //            if (varValue != null) type = varValue.GetType();
                //        }
                //    }
                //    stack.Push(new StiCheckTypeData(type, asmCommand.Position, asmCommand.Length));
                //    #endregion
                //    break;

                //case StiAsmCommandType.PushSystemVariable:
                //    object systemVariableValue = get_systemVariable(asmCommand.Parameter1);
                //    if (systemVariableValue != null) type = systemVariableValue.GetType();
                //    stack.Push(new StiCheckTypeData(type, asmCommand.Position, asmCommand.Length));
                //    break;

                case StiAsmCommandType.PushComponent:
                    stack.Push(new StiCheckTypeData((asmCommand.Parameter1 == null ? typeof(object) : asmCommand.Parameter1.GetType()), asmCommand.Position, asmCommand.Length));
                    break;

                case StiAsmCommandType.CopyToVariable:
                    stack.Peek();
                    break;

                case StiAsmCommandType.PushFunction:
                    #region Push function value
                    argsList = new List <StiCheckTypeData>();
                    for (int index = 0; index < (int)asmCommand.Parameter2; index++)
                    {
                        argsList.Add(stack.Pop());
                    }
                    argsList.Reverse();
                    types = new Type[argsList.Count];
                    for (int index = 0; index < argsList.Count; index++)
                    {
                        types[index] = argsList[index].TypeCode;
                    }
                    StiParserMethodInfo methodInfo = GetParserMethodInfo((ProryvFunctionType)asmCommand.Parameter1, types);
                    type = methodInfo != null ? methodInfo.ReturnType : typeof(object);
                    stack.Push(new StiCheckTypeData(type, asmCommand.Position, asmCommand.Length));
                    #endregion
                    break;

                case StiAsmCommandType.PushMethod:
                    #region Push method value
                    argsList = new List <StiCheckTypeData>();
                    for (int index = 0; index < (int)asmCommand.Parameter2; index++)
                    {
                        argsList.Add(stack.Pop() as StiCheckTypeData);
                    }
                    argsList.Reverse();
                    types = new Type[argsList.Count];
                    for (int index = 0; index < argsList.Count; index++)
                    {
                        types[index] = argsList[index].TypeCode;
                    }
                    type = GetMethodResultType((StiMethodType)asmCommand.Parameter1, types);
                    stack.Push(new StiCheckTypeData(type, asmCommand.Position, asmCommand.Length));
                    #endregion
                    break;

                case StiAsmCommandType.PushProperty:
                    type = GetPropertyType((StiPropertyType)asmCommand.Parameter1, stack.Pop().TypeCode);
                    stack.Push(new StiCheckTypeData(type, asmCommand.Position, asmCommand.Length));
                    break;

                case StiAsmCommandType.PushArrayElement:
                    #region Push array value
                    argsList = new List <StiCheckTypeData>();
                    for (int index = 0; index < (int)asmCommand.Parameter1; index++)
                    {
                        argsList.Add(stack.Pop());
                    }
                    argsList.Reverse();
                    types = new Type[argsList.Count];
                    for (int index = 0; index < argsList.Count; index++)
                    {
                        types[index] = argsList[index].TypeCode;
                    }
                    type = GetArrayElementType(types);
                    stack.Push(new StiCheckTypeData(type, asmCommand.Position, asmCommand.Length));
                    #endregion
                    break;

                case StiAsmCommandType.Add:
                case StiAsmCommandType.Sub:
                case StiAsmCommandType.Mult:
                case StiAsmCommandType.Div:
                case StiAsmCommandType.Mod:
                case StiAsmCommandType.Shl:
                case StiAsmCommandType.Shr:
                case StiAsmCommandType.And:
                case StiAsmCommandType.Or:
                case StiAsmCommandType.Xor:
                case StiAsmCommandType.And2:
                case StiAsmCommandType.Or2:
                    par2  = stack.Pop();
                    par1  = stack.Pop();
                    types = new Type[2] {
                        par1.TypeCode, par2.TypeCode
                    };
                    StiParserMethodInfo methodInfo2 = GetParserMethodInfo((ProryvFunctionType)asmCommand.Type, types);
                    type = methodInfo2 != null ? methodInfo2.ReturnType : typeof(object);
                    stack.Push(new StiCheckTypeData(type, asmCommand.Position, asmCommand.Length));
                    break;

                case StiAsmCommandType.Neg:
                case StiAsmCommandType.Not:
                    par1  = stack.Pop();
                    types = new Type[1] {
                        par1.TypeCode
                    };
                    StiParserMethodInfo methodInfo3 = GetParserMethodInfo((ProryvFunctionType)asmCommand.Type, types);
                    type = methodInfo3 != null ? methodInfo3.ReturnType : typeof(object);
                    stack.Push(new StiCheckTypeData(type, asmCommand.Position, asmCommand.Length));
                    break;

                //case StiAsmCommandType.Power:

                case StiAsmCommandType.CompareLeft:
                case StiAsmCommandType.CompareLeftEqual:
                case StiAsmCommandType.CompareRight:
                case StiAsmCommandType.CompareRightEqual:
                case StiAsmCommandType.CompareEqual:
                case StiAsmCommandType.CompareNotEqual:
                    par2 = stack.Pop();
                    par1 = stack.Pop();
                    //
                    // need to check type equality; todo
                    //
                    type = typeof(bool);
                    stack.Push(new StiCheckTypeData(type, asmCommand.Position, asmCommand.Length));
                    break;

                case StiAsmCommandType.Cast:
                    par1 = stack.Pop();
                    type = Type.GetType("System." + asmCommand.Parameter1);
                    stack.Push(new StiCheckTypeData(type, asmCommand.Position, asmCommand.Length));
                    break;
                }
            }
        }