예제 #1
0
 public override void visit(assign _assign)
 {
     _assign.from.visit(this);
     if (ret_val.prim_val == null && ret_val.obj_val == null && eval_stack.Count > 0)
     {
         ret_val = eval_stack.Peek();
     }
     if (_assign.to is ident)
     {
         NamedValue nv = GetValue((_assign.to as ident).name);
         if (ret_val.prim_val != null)
             nv.SetValue(DebugUtils.MakeValue(ret_val.prim_val));
         else if (ret_val.obj_val != null)
             nv.SetValue(ret_val.obj_val);
     }
 }
예제 #2
0
 public override void visit(uint64_const _uint64_const)
 {
     RetValue val = new RetValue();
     val.prim_val = _uint64_const.val;
     names.Add(_uint64_const.val.ToString());
 }
예제 #3
0
 public override void visit(typeof_operator _typeof_operator)
 {
     RetValue rv = new RetValue();
     StringBuilder sb = new StringBuilder();
     for (int i = 0; i < _typeof_operator.type_name.names.Count; i++)
     {
         sb.Append(_typeof_operator.type_name.names[i].name);
         if (i < _typeof_operator.type_name.names.Count - 1)
             sb.Append('.');
     }
     Type t = AssemblyHelper.GetType(sb.ToString());
     if (t != null && t.FullName != null)
     {
         Value v = DebugUtils.MakeValue(t.FullName);
         //DebugType dt = DebugType.Create(this.debuggedProcess.GetModule(typeof(Type).Assembly.ManifestModule.ScopeName),(uint)typeof(Type).MetadataToken);
         MethodInfo mi = MethodInfo.GetFromName(this.debuggedProcess, typeof(Type), "GetType", 1);
         rv.obj_val = mi.Invoke(null, new Value[1] { v });
     }
     eval_stack.Push(rv);
 }
예제 #4
0
 public override void visit(nil_const _nil_const)
 {
     RetValue res = new RetValue();
     res.is_null = true;
     eval_stack.Push(res);
 }
예제 #5
0
 public override void visit(format_expr _format_expr)
 {
     if (_format_expr.format2 == null)
         throw new NotImplementedException();
     RetValue res = new RetValue();
     _format_expr.expr.visit(this);
     RetValue expr = eval_stack.Pop();
     _format_expr.format1.visit(this);
     RetValue format1 = eval_stack.Pop();
     RetValue format2 = new RetValue();
     if (_format_expr.format2 != null)
     {
         _format_expr.format2.visit(this);
         format2 = eval_stack.Pop();
     }
     Type t = AssemblyHelper.GetType("PABCSystem.PABCSystem");
     string name = t.Assembly.ManifestModule.ScopeName;
     DebugType dt = DebugType.Create(this.debuggedProcess.GetModule(name), (uint)AssemblyHelper.GetType("PABCSystem.PABCSystem").MetadataToken);
     IList<MemberInfo> meths = dt.GetMember("FormatValue", BindingFlags.All);
     MethodInfo mi = selectFormatMethod(meths, _format_expr.format2 == null ? 2 : 3);
     if (_format_expr.format2 == null)
         res.obj_val = mi.Invoke(null, new Value[2] { MakeValue(expr), MakeValue(format1) });
     else
         res.obj_val = mi.Invoke(null, new Value[3] { MakeValue(expr), MakeValue(format1), MakeValue(format2) });
     eval_stack.Push(res);
 }
예제 #6
0
 public override void visit(pascal_set_constant _pascal_set_constant)
 {
     //throw new NotImplementedException();
     List<object> args = new List<object>();
     if (_pascal_set_constant.values != null)
     {
         foreach (expression e in _pascal_set_constant.values.expressions)
         {
             e.visit(this);
             RetValue rv = eval_stack.Pop();
             if (rv.prim_val != null)
                 args.Add(rv.prim_val);
             else if (rv.obj_val != null)
             {
                 args.Add(rv.obj_val);
             }
         }
     }
     List<Value> vargs = new List<Value>();
     foreach (object o in args)
         if (o is Value) vargs.Add(box(o as Value));
         else vargs.Add(box(DebugUtils.MakeValue(o)));
     RetValue res = new RetValue();
     Type t = AssemblyHelper.GetType("PABCSystem.TypedSet");
     string name = t.Assembly.ManifestModule.ScopeName;
     DebugType dt = DebugType.Create(this.debuggedProcess.GetModule(name), (uint)t.MetadataToken);
     res.obj_val = Eval.NewObject(this.debuggedProcess, dt.CorClass);
     MethodInfo mi = res.obj_val.Type.GetMember("CreateIfNeed", BindingFlags.All)[0] as MethodInfo;
     mi.Invoke(res.obj_val, new Value[0]);
     mi = res.obj_val.Type.GetMember("IncludeElement", BindingFlags.All)[0] as MethodInfo;
     foreach (Value v in vargs)
         mi.Invoke(res.obj_val, new Value[] { v });
     eval_stack.Push(res);
 }
예제 #7
0
 public override void visit(sharp_char_const _sharp_char_const)
 {
     RetValue val = new RetValue();
     val.prim_val = Convert.ToChar(_sharp_char_const.char_num);
     eval_stack.Push(val);
     names.Add("#" + _sharp_char_const.char_num.ToString());
 }
예제 #8
0
 private void EvalUnmin()
 {
     RetValue left = eval_stack.Pop();
     RetValue res = new RetValue();
     if (left.prim_val == null && left.obj_val != null)
     {
         if (left.obj_val.IsPrimitive)
             left.prim_val = left.obj_val.PrimitiveValue;
     }
     if (left.prim_val != null)
     {
         TypeCode lcode = Type.GetTypeCode(left.prim_val.GetType());
         switch (lcode)
         {
             case TypeCode.Byte: res.prim_val = -(byte)left.prim_val; break;
             case TypeCode.Int16: res.prim_val = -(System.Int16)left.prim_val; break;
             case TypeCode.Int32: res.prim_val = -(System.Int32)left.prim_val; break;
             case TypeCode.Int64: res.prim_val = -(System.Int64)left.prim_val; break;
             case TypeCode.SByte: res.prim_val = -(sbyte)left.prim_val; break;
             case TypeCode.UInt16: res.prim_val = -(System.UInt16)left.prim_val; break;
             case TypeCode.UInt32: res.prim_val = -(System.UInt32)left.prim_val; break;
             //case TypeCode.UInt64: res.prim_val = -(System.UInt64)left.prim_val; break;
             case TypeCode.Double: res.prim_val = -(double)left.prim_val; break;
             case TypeCode.Single: res.prim_val = -(System.Single)left.prim_val; break;
             default: throw new NoOperatorForThisType("-");
         }
         eval_stack.Push(res);
     }
 }
예제 #9
0
 public override void visit(double_const _double_const)
 {
     RetValue val = new RetValue();
     val.prim_val = _double_const.val;
     names.Add(_double_const.val.ToString());
     eval_stack.Push(val);
 }
예제 #10
0
 private void EvalIn()
 {
     RetValue right = eval_stack.Pop();
     RetValue left = eval_stack.Pop();
     RetValue res = new RetValue();
     if (right.obj_val != null && right.obj_val.Type.FullName == "PABCSystem.TypedSet")
     {
         MethodInfo mi = right.obj_val.Type.GetMember("Contains", BindingFlags.All)[0] as MethodInfo;
         Value tmp = box(MakeValue(left));
         Value v = mi.Invoke(right.obj_val, new Value[1] { tmp });
         res.prim_val = v.PrimitiveValue;
         //res.prim_val = MakeValue(left).PrimitiveValue;//v.PrimitiveValue;
         //Value v = mi.Invoke(right.obj_val,new Value[1]{right.obj_val});
         //res.prim_val = MakeValue(left).PrimitiveValue;
     }
     else throw new NoOperatorForThisType("in");
     eval_stack.Push(res);
 }
예제 #11
0
 private void EvalNot()
 {
     RetValue left = eval_stack.Pop();
     RetValue res = new RetValue();
     if (left.prim_val == null && left.obj_val != null)
     {
         if (left.obj_val.IsPrimitive)
             left.prim_val = left.obj_val.PrimitiveValue;
     }
     if (left.prim_val != null)
     {
         TypeCode lcode = Type.GetTypeCode(left.prim_val.GetType());
         switch (lcode)
         {
             case TypeCode.Boolean: res.prim_val = !(bool)left.prim_val; break;
             case TypeCode.Byte: res.prim_val = ~(byte)left.prim_val; break;
             case TypeCode.Int16: res.prim_val = ~(System.Int16)left.prim_val; break;
             case TypeCode.Int32: res.prim_val = ~(System.Int32)left.prim_val; break;
             case TypeCode.Int64: res.prim_val = ~(System.Int64)left.prim_val; break;
             case TypeCode.SByte: res.prim_val = ~(sbyte)left.prim_val; break;
             case TypeCode.UInt16: res.prim_val = ~(System.UInt16)left.prim_val; break;
             case TypeCode.UInt32: res.prim_val = ~(System.UInt32)left.prim_val; break;
             case TypeCode.UInt64: res.prim_val = ~(System.UInt64)left.prim_val; break;
             default: throw new NoOperatorForThisType("not");
         }
         eval_stack.Push(res);
     }
     else
     {
         string op = PascalABCCompiler.TreeConverter.compiler_string_consts.GetNETOperName(PascalABCCompiler.TreeConverter.compiler_string_consts.not_name);
         {
             IList<MemberInfo> mems = left.obj_val.Type.GetMember(op, Debugger.BindingFlags.All);
             if (mems != null && mems.Count == 1 && mems[0] is MethodInfo)
             {
                 MethodInfo mi = mems[0] as MethodInfo;
                 res.obj_val = mi.Invoke(null, new Value[1] { left.obj_val });
             }
             else
                 throw new NoOperatorForThisType("not");
         }
     }
 }
예제 #12
0
 public Value MakeValue(RetValue val)
 {
     if (val.obj_val != null) return val.obj_val;
     return DebugUtils.MakeValue(val.prim_val);
 }
예제 #13
0
        private void EvalIs()
        {
            RetValue right = eval_stack.Pop();
            RetValue left = eval_stack.Pop();
            RetValue res = new RetValue();
            if (right.type != null && (left.obj_val != null || left.prim_val != null))
            {
                if (left.obj_val != null)
                {
                    DebugType t = left.obj_val.Type;
                    while (t != null && t != right.type)
                    {
                        t = t.BaseType;
                    }
                    res.prim_val = t == right.type;
                }
                else if (right.managed_type != null)
                    res.prim_val = left.prim_val.GetType().IsSubclassOf(right.managed_type);
                else
                    res.prim_val = false;
            }
            else if (left.managed_type != null)
                throw new VariableExpectedTypeFound(left.managed_type.Name);

            eval_stack.Push(res);
        }
예제 #14
0
        private void EvalRem()
        {
            RetValue right = eval_stack.Pop();
            RetValue left = eval_stack.Pop();
            RetValue res = new RetValue();
            if (left.prim_val == null && left.obj_val != null)
            {
                if (left.obj_val.IsPrimitive)
                    left.prim_val = left.obj_val.PrimitiveValue;
            }
            if (right.prim_val == null && right.obj_val != null)
            {
                if (right.obj_val.IsPrimitive)
                    right.prim_val = right.obj_val.PrimitiveValue;
            }
            if (left.prim_val != null && right.prim_val != null)
            {
                TypeCode lcode = Type.GetTypeCode(left.prim_val.GetType());
                TypeCode rcode = Type.GetTypeCode(right.prim_val.GetType());
                switch (lcode)
                {
                    case TypeCode.Int32:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (int)left.prim_val % (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (int)left.prim_val % (int)right.prim_val; break;
                                //case TypeCode.Double : res.prim_val = (int)left.prim_val % (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (int)left.prim_val % (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((int)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (int)left.prim_val % (System.Int16)right.prim_val; break;
                                case TypeCode.SByte: res.prim_val = (int)left.prim_val % (sbyte)right.prim_val; break;
                                case TypeCode.UInt16: res.prim_val = (int)left.prim_val % (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (int)left.prim_val % (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (System.UInt64)((int)left.prim_val) % (System.UInt64)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                                //case TypeCode.Single : res.prim_val = (int)left.prim_val % (System.Single)right.prim_val; break;
                            }
                        }
                        break;
                    case TypeCode.Byte:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (byte)left.prim_val % (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (byte)left.prim_val % (int)right.prim_val; break;
                                //case TypeCode.Double : res.prim_val = (byte)left.prim_val % (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (byte)left.prim_val % (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((byte)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (byte)left.prim_val % (System.Int16)right.prim_val; break;
                                case TypeCode.SByte: res.prim_val = (byte)left.prim_val % (sbyte)right.prim_val; break;
                                case TypeCode.UInt16: res.prim_val = (byte)left.prim_val % (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (byte)left.prim_val % (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (byte)left.prim_val % (System.UInt64)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                                //case TypeCode.Single : res.prim_val = (byte)left.prim_val % (System.Single)right.prim_val; break;
                            }
                        }
                        break;
                    case TypeCode.Int16:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (System.Int16)left.prim_val % (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (System.Int16)left.prim_val % (int)right.prim_val; break;
                                //case TypeCode.Double : res.prim_val = (System.Int16)left.prim_val % (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (System.Int16)left.prim_val % (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((System.Int16)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (System.Int16)left.prim_val % (System.Int16)right.prim_val; break;
                                case TypeCode.SByte: res.prim_val = (System.Int16)left.prim_val % (sbyte)right.prim_val; break;
                                case TypeCode.UInt16: res.prim_val = (System.Int16)left.prim_val % (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (System.Int16)left.prim_val % (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (System.UInt64)((System.Int16)left.prim_val) % (System.UInt64)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                                //case TypeCode.Single : res.prim_val = (System.Int16)left.prim_val % (System.Single)right.prim_val; break;
                            }
                        }
                        break;
                    case TypeCode.Int64:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (System.Int64)left.prim_val % (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (System.Int64)left.prim_val % (int)right.prim_val; break;
                                //case TypeCode.Double : res.prim_val = (System.Int64)left.prim_val % (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (System.Int64)left.prim_val % (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((System.Int64)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (System.Int64)left.prim_val % (System.Int16)right.prim_val; break;
                                case TypeCode.SByte: res.prim_val = (System.Int64)left.prim_val % (sbyte)right.prim_val; break;
                                case TypeCode.UInt16: res.prim_val = (System.Int64)left.prim_val % (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (System.Int64)left.prim_val % (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (System.Int64)left.prim_val % (System.Int64)((System.UInt64)right.prim_val); break;
                                default: throw new IncompatibleTypesInExpression();
                                //case TypeCode.Single : res.prim_val = (System.Int64)left.prim_val % (System.Single)right.prim_val; break;
                            }
                        }
                        break;

                    case TypeCode.SByte:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (System.SByte)left.prim_val % (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (System.SByte)left.prim_val % (int)right.prim_val; break;
                                //case TypeCode.Double : res.prim_val = (System.SByte)left.prim_val % (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (System.SByte)left.prim_val % (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((System.SByte)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (System.SByte)left.prim_val % (System.Int16)right.prim_val; break;
                                case TypeCode.SByte: res.prim_val = (System.SByte)left.prim_val % (sbyte)right.prim_val; break;
                                case TypeCode.UInt16: res.prim_val = (System.SByte)left.prim_val % (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (System.SByte)left.prim_val % (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (System.UInt64)((System.SByte)left.prim_val) % (System.UInt64)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                                //case TypeCode.Single : res.prim_val = (System.SByte)left.prim_val % (System.Single)right.prim_val; break;
                            }
                        }
                        break;
                    case TypeCode.UInt16:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (System.UInt16)left.prim_val % (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (System.UInt16)left.prim_val % (int)right.prim_val; break;
                                //case TypeCode.Double : res.prim_val = (System.UInt16)left.prim_val % (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (System.UInt16)left.prim_val % (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((System.UInt16)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (System.UInt16)left.prim_val % (System.Int16)right.prim_val; break;
                                case TypeCode.SByte: res.prim_val = (System.UInt16)left.prim_val % (sbyte)right.prim_val; break;
                                case TypeCode.UInt16: res.prim_val = (System.UInt16)left.prim_val % (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (System.UInt16)left.prim_val % (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (System.UInt16)left.prim_val % (System.UInt64)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                                //case TypeCode.Single : res.prim_val = (System.UInt16)left.prim_val % (System.Single)right.prim_val; break;
                            }
                        }
                        break;
                    case TypeCode.UInt32:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (System.UInt32)left.prim_val % (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (System.UInt32)left.prim_val % (int)right.prim_val; break;
                                //case TypeCode.Double : res.prim_val = (System.UInt32)left.prim_val % (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (System.UInt32)left.prim_val % (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((System.UInt32)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (System.UInt32)left.prim_val % (System.Int16)right.prim_val; break;
                                case TypeCode.SByte: res.prim_val = (System.UInt32)left.prim_val % (sbyte)right.prim_val; break;
                                case TypeCode.UInt16: res.prim_val = (System.UInt32)left.prim_val % (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (System.UInt32)left.prim_val % (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (System.UInt32)left.prim_val % (System.UInt64)right.prim_val; break;
                                //case TypeCode.Single : res.prim_val = (System.UInt32)left.prim_val % (System.Single)right.prim_val; break;
                            }
                        }
                        break;
                    case TypeCode.UInt64:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (System.UInt64)left.prim_val % (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (System.UInt64)left.prim_val % (System.UInt64)((int)right.prim_val); break;
                                //case TypeCode.Double : res.prim_val = (System.UInt64)left.prim_val % (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (long)((System.UInt64)left.prim_val) % (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((System.UInt64)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (System.UInt64)left.prim_val % (System.UInt64)((System.Int16)right.prim_val); break;
                                case TypeCode.SByte: res.prim_val = (System.UInt64)left.prim_val % (System.UInt64)((sbyte)right.prim_val); break;
                                case TypeCode.UInt16: res.prim_val = (System.UInt64)left.prim_val % (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (System.UInt64)left.prim_val % (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (System.UInt64)left.prim_val % (System.UInt64)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                                //case TypeCode.Single : res.prim_val = (System.UInt64)left.prim_val % (System.Single)right.prim_val; break;
                            }
                        }
                        break;
                    default: throw new NoOperatorForThisType("rem");
                }

                eval_stack.Push(res);
            }
            else
            {
                if (left.obj_val == null && left.prim_val != null)
                    left.obj_val = DebugUtils.MakeValue(left.prim_val);
                if (right.obj_val == null && right.prim_val != null)
                    right.obj_val = DebugUtils.MakeValue(right.prim_val);
                res.obj_val = EvalCommonOperation(left.obj_val, right.obj_val, PascalABCCompiler.TreeConverter.compiler_string_consts.GetNETOperName(PascalABCCompiler.TreeConverter.compiler_string_consts.mod_name), "mod");
            }
        }
예제 #15
0
 public object GetSimpleValue(RetValue rv)
 {
     if (rv.prim_val != null) return rv.prim_val;
     else if (rv.obj_val != null && rv.obj_val.IsPrimitive) return rv.obj_val.PrimitiveValue;
     else if (rv.obj_val != null) return rv.obj_val;
     return null;
 }
예제 #16
0
 public override void visit(ident _ident)
 {
     RetValue val = new RetValue();
     if (string.Compare(_ident.name, "true", true) == 0)
     {
         val.prim_val = true;
     }
     else if (string.Compare(_ident.name, "false", true) == 0)
     {
         val.prim_val = false;
     }
     else
     {
         names.Add(_ident.name);
         val.obj_val = GetValue(_ident.name);
         if (val.obj_val == null)
         {
             val.prim_val = EvalStandFuncNoParam(_ident.name);
         }
         if (val.obj_val == null && val.prim_val == null)
         {
             Type t = AssemblyHelper.GetType(_ident.name);
             if (t != null)
             {
                 val.type = DebugUtils.GetDebugType(t);//DebugType.Create(this.debuggedProcess.GetModule(name),(uint)t.MetadataToken);
                 val.managed_type = t;
             }
         }
         if (val.obj_val == null && val.prim_val == null && val.type == null && !by_dot)
             throw new UnknownName(_ident.name);
     }
     eval_stack.Push(val);
 }
예제 #17
0
        public override void visit(method_call _method_call)
        {
            //throw new NotImplementedException();
            RetValue res = new RetValue();
            if (!for_immediate)
            {
                ident id = _method_call.dereferencing_value as ident;
                List<object> args = new List<object>();
                if (id != null)
                {
                    if (_method_call.parameters != null)
                        foreach (expression e in _method_call.parameters.expressions)
                        {
                            e.visit(this);
                            RetValue rv = eval_stack.Pop();
                            args.Add(GetSimpleValue(rv));
                        }
                    res.prim_val = EvalStandFuncWithParam(id.name, args.ToArray());
                }
                eval_stack.Push(res);
            }
            else
            {
                Value obj_val = null;
                MethodInfo[] meths = get_method(_method_call.dereferencing_value, out obj_val);
                //ret_val = eval_stack.Pop();
                //if (ret_val.obj_val == null && ret_val.prim_val == null)
                //	return;
                List<Value> args = new List<Value>();
                if (_method_call.parameters != null)
                    foreach (expression e in _method_call.parameters.expressions)
                    {
                        e.visit(this);
                        RetValue rv = eval_stack.Pop();
                        if (rv.obj_val != null)
                            args.Add(rv.obj_val);
                        else if (rv.prim_val != null)
                            args.Add(DebugUtils.MakeValue(rv.prim_val));

                    }
                MethodInfo mi = select_method(meths, get_values_types(args));
                if (mi == null)
                    throw new NoSuitableMethod();
                res.obj_val = mi.Invoke(obj_val, args.ToArray());
                eval_stack.Push(res);
            }
        }
예제 #18
0
 public override void visit(named_type_reference _named_type_reference)
 {
     StringBuilder sb = new StringBuilder();
     for (int i = 0; i < _named_type_reference.names.Count; i++)
     {
         sb.Append(_named_type_reference.names[i].name);
         if (i < _named_type_reference.names.Count - 1)
             sb.Append('.');
     }
     RetValue res = new RetValue();
     res.managed_type = AssemblyHelper.GetTypeForStatic(sb.ToString());
     if (res.managed_type != null)
         res.type = DebugUtils.GetDebugType(res.managed_type);
     else
         throw new UnknownName(sb.ToString());
     eval_stack.Push(res);
 }
예제 #19
0
 public override void visit(char_const _char_const)
 {
     RetValue val = new RetValue();
     val.prim_val = _char_const.cconst;
     eval_stack.Push(val);
     names.Add("'" + _char_const.cconst.ToString() + "'");
 }
예제 #20
0
 public override void visit(string_const _string_const)
 {
     RetValue val = new RetValue();
     val.prim_val = _string_const.Value;
     eval_stack.Push(val);
     names.Add("'" + _string_const.Value + "'");
 }
예제 #21
0
 public override void visit(literal_const_line _literal_const_line)
 {
     string s = "";
     string_const strc;
     sharp_char_const sharpcharconst;
     char_const charconst;
     syntax_tree_node tnf = _literal_const_line.literals[0], tnl = null;
     for (int i = 0; i < _literal_const_line.literals.Count; i++)
     {
         if ((strc = _literal_const_line.literals[i] as string_const) != null)
             s = s + strc.Value;
         else
             if ((sharpcharconst = _literal_const_line.literals[i] as sharp_char_const) != null)
                 s = s + Convert.ToChar(sharpcharconst.char_num);
             else
                 if ((charconst = _literal_const_line.literals[i] as char_const) != null)
                     s = s + charconst.cconst;
         if (i == _literal_const_line.literals.Count - 1)
             tnl = _literal_const_line.literals[i];
     }
     RetValue val = new RetValue();
     val.prim_val = s;
     eval_stack.Push(val);
 }
예제 #22
0
 public override void visit(roof_dereference _roof_dereference)
 {
     _roof_dereference.dereferencing_value.visit(this);
     RetValue rv = eval_stack.Pop();
     Value v = rv.obj_val.GetPermanentReference();
     rv = new RetValue();
     rv.obj_val = v;
     eval_stack.Push(rv);
 }
예제 #23
0
 public override void visit(diapason_expr _diapason_expr)
 {
     RetValue res = new RetValue();
     _diapason_expr.left.visit(this);
     RetValue left = eval_stack.Pop();
     _diapason_expr.right.visit(this);
     RetValue right = eval_stack.Pop();
     Type t = AssemblyHelper.GetType("PABCSystem.PABCSystem");
     string name = t.Assembly.ManifestModule.ScopeName;
     DebugType dt = DebugType.Create(this.debuggedProcess.GetModule(name), (uint)AssemblyHelper.GetType("PABCSystem.PABCSystem").MetadataToken);
     Value lv = null;
     Value rv = null;
     if (left.prim_val != null && right.prim_val != null)
     {
         Type left_type = left.prim_val.GetType();
         Type right_type = right.prim_val.GetType();
         if (left.prim_val is IComparable && right.prim_val is IComparable)
         {
             if ((left.prim_val as IComparable).CompareTo(right.prim_val) > 0)
                 throw new InvalidRangesInDiapason();
             switch (Type.GetTypeCode(left_type))
             {
                 case TypeCode.Boolean:
                 case TypeCode.Byte:
                 case TypeCode.Char:
                 case TypeCode.SByte:
                 case TypeCode.UInt16:
                 case TypeCode.Int16:
                 case TypeCode.Int32:
                 case TypeCode.UInt32:
                 case TypeCode.Int64:
                 case TypeCode.UInt64: break;
                 default:
                     throw new InvalidExpressionTypeInDiapason();
             }
             switch (Type.GetTypeCode(right_type))
             {
                 case TypeCode.Boolean:
                 case TypeCode.Byte:
                 case TypeCode.Char:
                 case TypeCode.SByte:
                 case TypeCode.UInt16:
                 case TypeCode.Int16:
                 case TypeCode.Int32:
                 case TypeCode.UInt32:
                 case TypeCode.Int64:
                 case TypeCode.UInt64: break;
                 default:
                     throw new InvalidExpressionTypeInDiapason();
             }
         }
         else
             throw new InvalidExpressionTypeInDiapason();
     }
     if (left.prim_val != null)
         lv = (DebugUtils.MakeValue(left.prim_val));
     else
         lv = (left.obj_val);
     if (right.prim_val != null)
         rv = (DebugUtils.MakeValue(right.prim_val));
     else
         rv = (right.obj_val);
     MethodInfo mi = null;
     if (lv.Type.ManagedType != typeof(char))
     {
         mi = dt.GetMember("CreateDiapason", BindingFlags.All)[0] as MethodInfo;
     }
     else
     {
         mi = dt.GetMember("CreateObjDiapason", BindingFlags.All)[0] as MethodInfo;
         lv = box(lv);
         rv = box(rv);
     }
     res.obj_val = mi.Invoke(null, new Value[2] { lv, rv });
     eval_stack.Push(res);
 }
예제 #24
0
        public override void visit(indexer _indexer)
        {
            bool tmp = by_dot;
            by_dot = true;
            _indexer.dereferencing_value.visit(this);
            by_dot = tmp;
            RetValue rv = eval_stack.Pop();
            List<object> indices = new List<object>();
            Value _val = null;
            names.Add("[");
            for (int i = 0; i < _indexer.indexes.expressions.Count; i++)
            {
                expression e = _indexer.indexes.expressions[i];
                by_dot = false;
                e.visit(this);
                if (i < _indexer.indexes.expressions.Count - 1)
                    names.Add(",");
                RetValue val = eval_stack.Pop();
                if (val.prim_val == null && val.obj_val != null)
                {
                    if (val.obj_val.IsPrimitive)
                        val.prim_val = val.obj_val.PrimitiveValue;
                }
                if (val.prim_val != null)
                {
                    TypeCode code = Type.GetTypeCode(val.prim_val.GetType());
                    switch (code)
                    {
                        //case TypeCode.Boolean : indices.Add((uint)((int)((bool)val.prim_val))); break;
                        case TypeCode.Byte: indices.Add((uint)((byte)val.prim_val)); break;
                        case TypeCode.Char: indices.Add((uint)((char)val.prim_val)); break;
                        case TypeCode.Int16: indices.Add((uint)((System.Int16)val.prim_val)); break;
                        case TypeCode.Int32: indices.Add((int)((System.Int32)val.prim_val)); break;
                        case TypeCode.Int64: indices.Add((uint)((System.Int64)val.prim_val)); break;
                        case TypeCode.SByte: indices.Add((uint)((sbyte)val.prim_val)); break;
                        case TypeCode.UInt16: indices.Add((uint)((System.UInt16)val.prim_val)); break;
                        case TypeCode.UInt32: indices.Add((uint)((System.UInt32)val.prim_val)); break;
                        case TypeCode.UInt64: indices.Add((uint)((System.UInt64)val.prim_val)); break;
                        default: indices.Add(val.prim_val); break;
                    }
                }
                else
                {
                    indices.Add(val.obj_val);
                }

            }
            by_dot = tmp;
            names.Add("]");
            if (rv.obj_val != null)
            {
                if (rv.obj_val is MemberValue && (rv.obj_val as MemberValue).MemberInfo is PropertyInfo)
                {
                    PropertyInfo pi = (rv.obj_val as MemberValue).MemberInfo as PropertyInfo;
                    Type t = AssemblyHelper.GetType(last_obj.Type.FullName);
                    System.Reflection.PropertyInfo rpi = t.GetProperty(pi.Name, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Instance);
                    /*System.Reflection.MemberInfo[] props = t.GetMembers(System.Reflection.BindingFlags.NonPublic|System.Reflection.BindingFlags.Public|System.Reflection.BindingFlags.Static|System.Reflection.BindingFlags.CreateInstance);
                    System.Reflection.PropertyInfo rpi = null;
                    foreach (System.Reflection.MemberInfo p in props)
                    if (p is System.Reflection.PropertyInfo && p.Name == pi.Name)
                    {
                        rpi = p as System.Reflection.PropertyInfo;
                        break;
                    }*/
                    RetValue res = new RetValue();
                    res.obj_val = ((rv.obj_val as MemberValue).MemberInfo as PropertyInfo).GetValue(last_obj,
                                                                                                    get_val_arr(indices, false, rpi.GetGetMethod(true)));
                    eval_stack.Push(res);
                    return;
                }
                if (rv.obj_val.IsArray)
                {
                    RetValue res = new RetValue();
                    res.obj_val = rv.obj_val.GetArrayElement(conv_to_uint_arr(indices));
                    check_for_out_of_range(res.obj_val);
                    eval_stack.Push(res);

                }
                else
                {
                    IList<MemberInfo> mis = rv.obj_val.Type.GetMember("get_val", BindingFlags.All);
                    if (mis.Count > 0)
                    {
                        MethodInfo cur_mi = null;
                        int low_bound = 0;
                        foreach (MemberInfo mi in mis)
                        {
                            if (mi is MethodInfo)
                            {
                                cur_mi = mi as MethodInfo;
                                //FieldInfo fi = rv.obj_val.Type.GetMember("LowerIndex",BindingFlags.All)[0] as FieldInfo;
                                System.Reflection.FieldInfo fi = AssemblyHelper.GetType(rv.obj_val.Type.FullName).GetField("LowerIndex");
                                low_bound = Convert.ToInt32(fi.GetRawConstantValue());
                            }
                        }
                        RetValue res = new RetValue();
                        uint[] tmp_indices = new uint[1];
                        int j = 0;
                        try
                        {
                            object obj = indices[j++];
                            int v = 0;
                            if (obj is Value && DebugUtils.IsEnum(obj as Value, out v))
                                tmp_indices[0] = (uint)(v - low_bound);
                            else
                                tmp_indices[0] = (uint)(Convert.ToInt32(obj) - low_bound);
                        }
                        catch (System.FormatException)
                        {
                            throw new WrongTypeInIndexer();
                        }
                        catch (System.InvalidCastException)
                        {
                            throw new WrongTypeInIndexer();
                        }
                        //res.obj_val = cur_mi.Invoke(rv.obj_val,indices.ToArray()) as NamedValue;
                        Value nv = rv.obj_val.GetMember("NullBasedArray");
                        res.obj_val = nv.GetArrayElement(tmp_indices);
                        check_for_out_of_range(res.obj_val);
                        nv = res.obj_val.GetMember("NullBasedArray");
                        while (nv != null && j < indices.Count)
                        {
                            System.Reflection.FieldInfo tmp_fi = AssemblyHelper.GetType(res.obj_val.Type.FullName).GetField("LowerIndex");
                            low_bound = Convert.ToInt32(tmp_fi.GetRawConstantValue());
                            try
                            {
                                object obj = indices[j++];
                                int v = 0;
                                if (obj is Value && DebugUtils.IsEnum(obj as Value, out v))
                                    tmp_indices[0] = (uint)(v - low_bound);
                                else
                                    tmp_indices[0] = (uint)(Convert.ToInt32(obj) - low_bound);
                            }
                            catch (System.FormatException)
                            {
                                throw new WrongTypeInIndexer();
                            }
                            catch (System.InvalidCastException)
                            {
                                throw new WrongTypeInIndexer();
                            }
                            res.obj_val = nv.GetArrayElement(tmp_indices);
                            check_for_out_of_range(res.obj_val);
                            nv = res.obj_val.GetMember("NullBasedArray");

                        }
                        if (j < indices.Count)
                            throw new WrongIndexersNumber();
                        eval_stack.Push(res);
                    }
                    else
                    {
                        string name = get_type_name(rv.obj_val.Type);
                        Type t = AssemblyHelper.GetType(name);
                        if (t == null && declaringType != null)
                            t = AssemblyHelper.GetType(declaringType.FullName + "+" + name);
                        DebugType[] gen_args = rv.obj_val.Type.GetGenericArguments();
                        if (gen_args.Length > 0)
                        {
                            List<Type> gens = new List<Type>();
                            for (int i = 0; i < gen_args.Length; i++)
                                gens.Add(AssemblyHelper.GetType(get_type_name(gen_args[i])));
                            t = t.MakeGenericType(gens.ToArray());
                        }
                        System.Reflection.MemberInfo[] def_members = t.GetDefaultMembers();
                        System.Reflection.PropertyInfo _default_property = null;
                        if (def_members != null && def_members.Length > 0)
                        {
                            foreach (System.Reflection.MemberInfo mi in def_members)
                            {
                                System.Reflection.PropertyInfo pi = mi as System.Reflection.PropertyInfo;
                                if (pi != null)
                                {
                                    _default_property = pi;
                                    break;
                                }
                            }
                        }
                        if (_default_property != null)
                        {
                            if (_default_property.GetGetMethod().GetParameters().Length != indices.Count)
                                throw new WrongIndexersNumber();
                            MethodInfo mi2 = rv.obj_val.Type.GetMember(_default_property.GetGetMethod().Name, Debugger.BindingFlags.All)[0] as MethodInfo;
                            RetValue res = new RetValue();
                            res.obj_val = mi2.Invoke(rv.obj_val, get_val_arr(indices, _default_property.DeclaringType == typeof(string), _default_property.GetGetMethod()));
                            check_for_out_of_range(res.obj_val);
                            eval_stack.Push(res);
                        }
                        else
                            throw new NoIndexerProperty();

                    }
                }
            }
        }
예제 #25
0
 public override void visit(template_type_reference _template_type_reference)
 {
     StringBuilder sb = new StringBuilder();
     for (int i = 0; i < _template_type_reference.name.names.Count; i++)
     {
         sb.Append(_template_type_reference.name.names[i].name);
         if (i < _template_type_reference.name.names.Count - 1)
             sb.Append('.');
     }
     List<DebugType> gen_args = new List<DebugType>();
     List<Type> gen_refl_args = new List<Type>();
     for (int i = 0; i < _template_type_reference.params_list.params_list.Count; i++)
     {
         _template_type_reference.params_list.params_list[i].visit(this);
         RetValue rv = eval_stack.Pop();
         gen_args.Add(rv.type);
         gen_refl_args.Add(rv.managed_type);
     }
     RetValue res = new RetValue();
     res.managed_type = AssemblyHelper.GetTypeForStatic(sb.ToString(), gen_refl_args);
     if (res.managed_type != null)
     {
         res.type = DebugUtils.GetDebugType(res.managed_type, gen_args);
         res.managed_type = res.managed_type.MakeGenericType(gen_refl_args.ToArray());
     }
     else
         throw new UnknownName(sb.ToString());
     eval_stack.Push(res);
 }
예제 #26
0
 public override void visit(hex_constant _hex_constant)
 {
     RetValue val = new RetValue();
     val.prim_val = _hex_constant.val;
     eval_stack.Push(val);
 }
예제 #27
0
        public override void visit(sizeof_operator _sizeof_operator)
        {
            RetValue rv = new RetValue();
            StringBuilder sb = new StringBuilder();

            if (_sizeof_operator.type_def != null && _sizeof_operator.type_def is named_type_reference)
            {
                named_type_reference ntr = _sizeof_operator.type_def as named_type_reference;
                for (int i = 0; i < ntr.names.Count; i++)
                {
                    sb.Append(ntr.names[i].name);
                    if (i < ntr.names.Count - 1)
                        sb.Append('.');
                }
            }
            Type t = AssemblyHelper.GetType(sb.ToString());
            if (t != null && t.FullName != null)
            {
                if (t == typeof(char))
                {
                    rv.prim_val = 2;
                }
                else if (t == typeof(bool))
                {
                    rv.prim_val = 1;
                }
                else
                {
                    Value v = DebugUtils.MakeValue(t.FullName);
                    //DebugType dt = DebugType.Create(this.debuggedProcess.GetModule(typeof(Type).Assembly.ManifestModule.ScopeName),(uint)typeof(Type).MetadataToken);
                    MethodInfo mi = MethodInfo.GetFromName(this.debuggedProcess, typeof(Type), "GetType", 1);
                    v = mi.Invoke(null, new Value[1] { v });
                    t = typeof(System.Runtime.InteropServices.Marshal);
                    DebugType dt = DebugUtils.GetDebugType(t);//DebugType.Create(this.debuggedProcess.GetModule(name),(uint)t.MetadataToken);
                    IList<MethodInfo> mis = dt.GetMethods();
                    System.Reflection.MethodInfo rmi = t.GetMethod("SizeOf", new Type[1] { typeof(Type) });
                    mi = null;
                    foreach (MethodInfo tmp_mi in mis)
                        if (tmp_mi.Name == "SizeOf" && rmi.MetadataToken == tmp_mi.MetadataToken)
                        {
                            mi = tmp_mi;
                            break;
                        }
                    if (mi != null)
                        rv.obj_val = mi.Invoke(null, new Value[1] { v });
                }
            }
            eval_stack.Push(rv);
        }
예제 #28
0
        public override void visit(dot_node _dot_node)
        {
            bool tmp2 = by_dot;
            by_dot = true;
            _dot_node.left.visit(this);
            by_dot = tmp2;
            RetValue rv = eval_stack.Pop();
            RetValue res = new RetValue();
            if (rv.obj_val != null)
            {
                if (rv.obj_val.Dereference != null)
                    rv.obj_val = rv.obj_val.Dereference;
                if (_dot_node.right is ident)
                {
                    if (rv.obj_val.IsNull)
                        throw new CommonEvaluationError(new NullReferenceException());
                    ident id = _dot_node.right as ident;
                    names.Add("." + id.name);
                    //IList<Debugger.MemberInfo> members = rv.obj_val.Type.GetMember(id.name, BindingFlags.All);
                    if (rv.obj_val.IsArray)
                    {
                        if (string.Compare(id.name, "Length", true) == 0)
                            res.prim_val = rv.obj_val.ArrayLenght;
                        else
                            if (string.Compare(id.name, "Rank", true) == 0)
                                res.prim_val = rv.obj_val.ArrayRank;
                    }
                    else
                    {
                        res.obj_val = rv.obj_val.GetMember(id.name);
                        if (res.obj_val == null)
                            throw new UnknownName(id.name);
                        if (res.obj_val is MemberValue && (res.obj_val as MemberValue).MemberInfo is PropertyInfo)
                            last_obj = rv.obj_val;
                    }
                    declaringType = rv.obj_val.Type;
                }
            }
            else if (_dot_node.right is ident)
            {
                ident id = _dot_node.right as ident;
                names.Add("." + id.name);
                string name = build_name(_dot_node.left);
                if (name != null)
                {
                    Type t = AssemblyHelper.GetType(name);
                    if (t != null)
                    {
                        //DebugType dt = DebugType.Create(this.debuggedProcess.GetModule(name),(uint)t.MetadataToken);
                        DebugType dt = DebugUtils.GetDebugType(t);
                        IList<MemberInfo> mis = new List<MemberInfo>();//dt.GetMember(id.name,BindingFlags.All);
                        declaringType = dt;
                        DebugType tmp = dt;
                        while (tmp != null && mis.Count == 0)
                        {
                            try
                            {
                                mis = tmp.GetMember(id.name, BindingFlags.All);
                                tmp = tmp.BaseType;
                            }
                            catch
                            {

                            }
                        }
                        if (mis.Count > 0)
                        {
                            if (mis[0] is FieldInfo)
                            {
                                FieldInfo fi = mis[0] as FieldInfo;
                                res.obj_val = fi.GetValue(null);
                                if (res.obj_val == null)
                                    throw new UnknownName(id.name);
                                check_for_static(res.obj_val, id.name);
                            }
                            else if (mis[0] is PropertyInfo)
                            {
                                PropertyInfo pi = mis[0] as PropertyInfo;
                                res.obj_val = pi.GetValue(null);
                                if (res.obj_val == null)
                                    throw new UnknownName(id.name);
                                check_for_static(res.obj_val, id.name);
                            }
                        }
                        else
                        {
                            System.Reflection.FieldInfo fi = t.GetField(id.name);
                            if (fi != null)
                                res.prim_val = fi.GetRawConstantValue();
                            else
                                throw new UnknownName(id.name);
                        }
                    }
                    else
                    {
                        t = AssemblyHelper.GetType(name + "." + id.name);
                        if (t != null)
                        {
                            res.type = DebugUtils.GetDebugType(t);//DebugType.Create(this.debuggedProcess.GetModule(name),(uint)t.MetadataToken);
                            res.managed_type = t;
                        }
                        //						else 
                        //							throw new UnknownName(id.name);
                    }
                }
            }
            eval_stack.Push(res);
        }
예제 #29
0
        private void EvalMinus()
        {
            RetValue right = eval_stack.Pop();
            RetValue left = eval_stack.Pop();
            RetValue res = new RetValue();
            if (left.prim_val == null && left.obj_val != null)
            {
                if (left.obj_val.IsPrimitive)
                    left.prim_val = left.obj_val.PrimitiveValue;
            }
            if (right.prim_val == null && right.obj_val != null)
            {
                if (right.obj_val.IsPrimitive)
                    right.prim_val = right.obj_val.PrimitiveValue;
            }
            if (left.prim_val != null && right.prim_val != null)
            {
                TypeCode lcode = Type.GetTypeCode(left.prim_val.GetType());
                TypeCode rcode = Type.GetTypeCode(right.prim_val.GetType());
                switch (lcode)
                {
                    case TypeCode.Int32:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (int)left.prim_val - (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (int)left.prim_val - (int)right.prim_val; break;
                                case TypeCode.Double: res.prim_val = (int)left.prim_val - (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (int)left.prim_val - (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((int)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (int)left.prim_val - (System.Int16)right.prim_val; break;
                                case TypeCode.SByte: res.prim_val = (int)left.prim_val - (sbyte)right.prim_val; break;
                                case TypeCode.UInt16: res.prim_val = (int)left.prim_val - (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (int)left.prim_val - (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (System.UInt64)((int)left.prim_val) - (System.UInt64)right.prim_val; break;
                                case TypeCode.Single: res.prim_val = (int)left.prim_val - (System.Single)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                            }
                        }
                        break;
                    case TypeCode.Double:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (double)left.prim_val - (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (double)left.prim_val - (int)right.prim_val; break;
                                case TypeCode.Double: res.prim_val = (double)left.prim_val - (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (double)left.prim_val - (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((double)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (double)left.prim_val - (System.Int16)right.prim_val; break;
                                case TypeCode.SByte: res.prim_val = (double)left.prim_val - (sbyte)right.prim_val; break;
                                case TypeCode.UInt16: res.prim_val = (double)left.prim_val - (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (double)left.prim_val - (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (double)left.prim_val - (System.UInt64)right.prim_val; break;
                                case TypeCode.Single: res.prim_val = (double)left.prim_val - (System.Single)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                            }
                        }
                        break;
                    case TypeCode.Byte:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (byte)left.prim_val - (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (byte)left.prim_val - (int)right.prim_val; break;
                                case TypeCode.Double: res.prim_val = (byte)left.prim_val - (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (byte)left.prim_val - (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((byte)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (byte)left.prim_val - (System.Int16)right.prim_val; break;
                                case TypeCode.SByte: res.prim_val = (byte)left.prim_val - (sbyte)right.prim_val; break;
                                case TypeCode.UInt16: res.prim_val = (byte)left.prim_val - (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (byte)left.prim_val - (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (byte)left.prim_val - (System.UInt64)right.prim_val; break;
                                case TypeCode.Single: res.prim_val = (byte)left.prim_val - (System.Single)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                            }
                        }
                        break;
                    case TypeCode.Int16:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (System.Int16)left.prim_val - (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (System.Int16)left.prim_val - (int)right.prim_val; break;
                                case TypeCode.Double: res.prim_val = (System.Int16)left.prim_val - (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (System.Int16)left.prim_val - (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((System.Int16)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (System.Int16)left.prim_val - (System.Int16)right.prim_val; break;
                                case TypeCode.SByte: res.prim_val = (System.Int16)left.prim_val - (sbyte)right.prim_val; break;
                                case TypeCode.UInt16: res.prim_val = (System.Int16)left.prim_val - (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (System.Int16)left.prim_val - (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (System.UInt64)((System.Int16)left.prim_val) - (System.UInt64)right.prim_val; break;
                                case TypeCode.Single: res.prim_val = (System.Int16)left.prim_val - (System.Single)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                            }
                        }
                        break;
                    case TypeCode.Int64:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (System.Int64)left.prim_val - (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (System.Int64)left.prim_val - (int)right.prim_val; break;
                                case TypeCode.Double: res.prim_val = (System.Int64)left.prim_val - (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (System.Int64)left.prim_val - (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((System.Int64)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (System.Int64)left.prim_val - (System.Int16)right.prim_val; break;
                                case TypeCode.SByte: res.prim_val = (System.Int64)left.prim_val - (sbyte)right.prim_val; break;
                                case TypeCode.UInt16: res.prim_val = (System.Int64)left.prim_val - (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (System.Int64)left.prim_val - (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (System.Int64)left.prim_val - (System.Int64)((System.UInt64)right.prim_val); break;
                                case TypeCode.Single: res.prim_val = (System.Int64)left.prim_val - (System.Single)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                            }
                        }
                        break;

                    case TypeCode.SByte:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (System.SByte)left.prim_val - (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (System.SByte)left.prim_val - (int)right.prim_val; break;
                                case TypeCode.Double: res.prim_val = (System.SByte)left.prim_val - (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (System.SByte)left.prim_val - (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((System.SByte)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (System.SByte)left.prim_val - (System.Int16)right.prim_val; break;
                                case TypeCode.SByte: res.prim_val = (System.SByte)left.prim_val - (sbyte)right.prim_val; break;
                                case TypeCode.UInt16: res.prim_val = (System.SByte)left.prim_val - (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (System.SByte)left.prim_val - (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (System.UInt64)((System.SByte)left.prim_val) - (System.UInt64)right.prim_val; break;
                                case TypeCode.Single: res.prim_val = (System.SByte)left.prim_val - (System.Single)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                            }
                        }
                        break;
                    case TypeCode.UInt16:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (System.UInt16)left.prim_val - (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (System.UInt16)left.prim_val - (int)right.prim_val; break;
                                case TypeCode.Double: res.prim_val = (System.UInt16)left.prim_val - (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (System.UInt16)left.prim_val - (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((System.UInt16)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (System.UInt16)left.prim_val - (System.Int16)right.prim_val; break;
                                case TypeCode.SByte: res.prim_val = (System.UInt16)left.prim_val - (sbyte)right.prim_val; break;
                                case TypeCode.UInt16: res.prim_val = (System.UInt16)left.prim_val - (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (System.UInt16)left.prim_val - (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (System.UInt16)left.prim_val - (System.UInt64)right.prim_val; break;
                                case TypeCode.Single: res.prim_val = (System.UInt16)left.prim_val - (System.Single)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                            }
                        }
                        break;
                    case TypeCode.UInt32:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (System.UInt32)left.prim_val - (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (System.UInt32)left.prim_val - (int)right.prim_val; break;
                                case TypeCode.Double: res.prim_val = (System.UInt32)left.prim_val - (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (System.UInt32)left.prim_val - (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((System.UInt32)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (System.UInt32)left.prim_val - (System.Int16)right.prim_val; break;
                                case TypeCode.SByte: res.prim_val = (System.UInt32)left.prim_val - (sbyte)right.prim_val; break;
                                case TypeCode.UInt16: res.prim_val = (System.UInt32)left.prim_val - (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (System.UInt32)left.prim_val - (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (System.UInt32)left.prim_val - (System.UInt64)right.prim_val; break;
                                case TypeCode.Single: res.prim_val = (System.UInt32)left.prim_val - (System.Single)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                            }
                        }
                        break;
                    case TypeCode.UInt64:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (System.UInt64)left.prim_val - (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (System.UInt64)left.prim_val - (System.UInt64)((int)right.prim_val); break;
                                case TypeCode.Double: res.prim_val = (System.UInt64)left.prim_val - (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (long)((System.UInt64)left.prim_val) - (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((System.UInt64)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (System.UInt64)left.prim_val - (System.UInt64)((System.Int16)right.prim_val); break;
                                case TypeCode.SByte: res.prim_val = (System.UInt64)left.prim_val - (System.UInt64)((sbyte)right.prim_val); break;
                                case TypeCode.UInt16: res.prim_val = (System.UInt64)left.prim_val - (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (System.UInt64)left.prim_val - (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (System.UInt64)left.prim_val - (System.UInt64)right.prim_val; break;
                                case TypeCode.Single: res.prim_val = (System.UInt64)left.prim_val - (System.Single)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                            }
                        }
                        break;
                    case TypeCode.Decimal:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (decimal)left.prim_val - (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (decimal)left.prim_val - (System.UInt64)((int)right.prim_val); break;
                                //case TypeCode.Double : res.prim_val = (System.UInt64)left.prim_val + (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (decimal)left.prim_val - (System.UInt64)((long)right.prim_val); break;
                                //case TypeCode.String : res.prim_val = ((decimal)left.prim_val).ToString() - (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (decimal)left.prim_val - (System.UInt64)((System.Int16)right.prim_val); break;
                                case TypeCode.SByte: res.prim_val = (decimal)left.prim_val - (System.UInt64)((sbyte)right.prim_val); break;
                                case TypeCode.UInt16: res.prim_val = (decimal)left.prim_val - (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (decimal)left.prim_val - (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (decimal)left.prim_val - (System.UInt64)right.prim_val; break;
                                //case TypeCode.Single : res.prim_val = (System.UInt64)left.prim_val + (System.Single)right.prim_val; break;
                                case TypeCode.Decimal: res.prim_val = (decimal)left.prim_val - (decimal)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                            }
                        }
                        break;
                    case TypeCode.Single:
                        {
                            switch (rcode)
                            {
                                case TypeCode.Byte: res.prim_val = (System.Single)left.prim_val - (byte)right.prim_val; break;
                                case TypeCode.Int32: res.prim_val = (System.Single)left.prim_val - (int)right.prim_val; break;
                                case TypeCode.Double: res.prim_val = (System.Single)left.prim_val - (double)right.prim_val; break;
                                case TypeCode.Int64: res.prim_val = (System.Single)left.prim_val - (long)right.prim_val; break;
                                //case TypeCode.String : res.prim_val = ((System.Single)left.prim_val).ToString() + (string)right.prim_val; break;
                                case TypeCode.Int16: res.prim_val = (System.Single)left.prim_val - (System.Int16)right.prim_val; break;
                                case TypeCode.SByte: res.prim_val = (System.Single)left.prim_val - (sbyte)right.prim_val; break;
                                case TypeCode.UInt16: res.prim_val = (System.Single)left.prim_val - (System.UInt16)right.prim_val; break;
                                case TypeCode.UInt32: res.prim_val = (System.Single)left.prim_val - (System.UInt32)right.prim_val; break;
                                case TypeCode.UInt64: res.prim_val = (System.Single)left.prim_val - (System.UInt64)right.prim_val; break;
                                case TypeCode.Single: res.prim_val = (System.Single)left.prim_val - (System.Single)right.prim_val; break;
                                default: throw new IncompatibleTypesInExpression();
                            }
                        }
                        break;
                    case TypeCode.Object:
                        {
                            if (left.obj_val.Type.FullName == "PABCSystem.TypedSet" && right.obj_val.Type.FullName == "PABCSystem.TypedSet")
                            {
                                res.obj_val = (left.obj_val.Type.GetMember("SubtractSet", BindingFlags.All)[0] as MethodInfo).Invoke(left.obj_val, new Value[1] { right.obj_val });
                            }
                        }
                        break;
                    default: throw new NoOperatorForThisType("-");
                }

            }
            else
            {
                if (left.obj_val == null && left.prim_val != null)
                    left.obj_val = DebugUtils.MakeValue(left.prim_val);
                if (right.obj_val == null && right.prim_val != null)
                    right.obj_val = DebugUtils.MakeValue(right.prim_val);
                if (left.obj_val.Type.FullName == "PABCSystem.TypedSet" && right.obj_val.Type.FullName == "PABCSystem.TypedSet")
                {
                    res.obj_val = (left.obj_val.Type.GetMember("SubtractSet", BindingFlags.All)[0] as MethodInfo).Invoke(left.obj_val, new Value[1] { right.obj_val });
                }
                else
                {
                    res.obj_val = EvalCommonOperation(left.obj_val, right.obj_val, PascalABCCompiler.TreeConverter.compiler_string_consts.GetNETOperName(PascalABCCompiler.TreeConverter.compiler_string_consts.minus_name), "-");
                }
            }
            eval_stack.Push(res);
        }
예제 #30
0
 public RetValue GetValueForExpression(string expr, out string preformat)
 {
     declaringType = null;
     for_immediate = false;
     ret_val = default(RetValue);
     preformat = expr.Trim(' ', '\n', '\r', '\t');
     names.Clear();
     string fileName = "test" + System.IO.Path.GetExtension(this.FileName);
     List<PascalABCCompiler.Errors.Error> Errors = new List<PascalABCCompiler.Errors.Error>();
     expression e = vec.StandartCompiler.ParsersController.GetExpression(fileName, expr, Errors);
     RetValue res = new RetValue(); res.syn_err = false;
     try
     {
         if (e != null && Errors.Count == 0)
         {
             e.visit(this);
             if (eval_stack.Count > 0)
             {
                 res = eval_stack.Pop();
                 preformat = string.Join("", names.ToArray());
                 return res;
             }
         }
     }
     catch (System.Exception ex)
     {
         //throw new System.Exception(ex.Message);
     }
     finally
     {
         if (eval_stack.Count > 0) eval_stack.Clear();
     }
     return new RetValue();
 }