Example #1
0
        ///
        /// <summary>
        ///		Parses logical expressions
        /// </summary>
        ///
        /// <param name="leftOp">Left operand</param>
        /// <param name="rightOp">Right operand</param>
        /// <param name="type">Logical expression type</param>
        ///
        /// <returns>The result of applying the given logical expression operator</returns>
        ///
        public static CseObject Parse(CseObject leftOp, CseObject rightOp, LogicalType type)
        {
            CseObject obj = null;

            if (type == LogicalType.NOT)
            {
                obj = new CseObject(null)
                {
                    IsLiteral = leftOp.IsLiteral
                };
            }
            else
            {
                obj = new CseObject(null)
                {
                    IsLiteral = leftOp.IsLiteral && rightOp.IsLiteral
                };
            }

            try {
                switch (type)
                {
                case LogicalType.AND:
                    // TODO: lazy eval if exception thrown
                    obj.Value = leftOp.Value && rightOp.Value;
                    break;

                case LogicalType.OR:
                    // TODO: lazy eval if exception thrown
                    obj.Value = leftOp.Value || rightOp.Value;
                    break;

                case LogicalType.NOT: {
                    //try {
                    obj.Value = !leftOp.Value;

                    /*}
                     * catch {
                     *      MethodInfo mi = obj.Value.GetType().GetMethod(OpOverloadNames.FALSE);
                     *      if (mi != null)
                     *              obj.Value = obj.Value.GetType().InvokeMember(OpOverloadNames.FALSE, OpOverloadNames.Flags, null, CsEval.evalEnvironment, new object[] { obj.Value });
                     *      else
                     *              obj.Value = null;
                     * }*/
                }
                break;

                default:
                    throw new System.NotImplementedException("Not implemented.");
                }
            }
            catch {
                // TODO: Fill this out!
            }

            return(obj);
        }
Example #2
0
        ///
        /// <summary>
        ///		Parses xor expressions
        /// </summary>
        ///
        /// <param name="leftOp">Left operand</param>
        /// <param name="rightOp">Right operand</param>
        ///
        /// <returns>The result of applying the xor operator</returns>
        ///
        public static CseObject Parse(CseObject leftOp, CseObject rightOp)
        {
            CseObject obj = new CseObject(null)
            {
                IsLiteral = leftOp.IsLiteral && rightOp.IsLiteral
            };

            obj.Value = leftOp.Value ^ rightOp.Value;
            return(obj);
        }
Example #3
0
        ///
        /// <summary>
        ///		Used for quick evaluation.
        ///		Use this when the evaluation environment changes often.
        ///		If the environment is consistent, set CsEval.EvalEnvironment
        ///		then call CsEval.Eval(string data).
        /// </summary>
        ///
        /// <param name="evalEnvironment">
        ///		Provides an evaluation environment for the given expression.
        ///		The stored evaluation environment is temporarily replaced
        ///		when the given statement is evaluated and restored afterwards.
        ///	</param>
        /// <param name="data">The expression to evaluate</param>
        ///
        /// <returns>The return result of evaluating the expression</returns>
        ///
        public static object Eval(object evalEnvironment, string data)
        {
            CseObject saveDebugInstance = CsEval.evalEnvironment;

            CsEval.evalEnvironment = new CseObject(evalEnvironment);
            object result = Eval(data);

            CsEval.evalEnvironment = saveDebugInstance;

            return(result);
        }
Example #4
0
        ///
        /// <summary>
        ///		Parses bitwise expressions
        /// </summary>
        ///
        /// <param name="leftOp">Left operand</param>
        /// <param name="rightOp">Right operand</param>
        /// <param name="type">Bitwise expression type</param>
        ///
        /// <returns>The result of applying the given bitwise operand</returns>
        ///
        public static CseObject Parse(CseObject leftOp, CseObject rightOp, BitwiseType type)
        {
            CseObject obj = null;

            if (type == BitwiseType.NOT)
            {
                obj = new CseObject(null)
                {
                    IsLiteral = leftOp.IsLiteral
                };
            }
            else
            {
                obj = new CseObject(null)
                {
                    IsLiteral = leftOp.IsLiteral && rightOp.IsLiteral
                };
            }

            try {
                switch (type)
                {
                case BitwiseType.AND:
                    obj.Value = leftOp.Value & rightOp.Value;
                    break;

                case BitwiseType.OR:
                    obj.Value = leftOp.Value | rightOp.Value;
                    break;

                case BitwiseType.NOT:
                    obj.Value = ~leftOp.Value;
                    break;

                case BitwiseType.SHL:
                    obj.Value = leftOp.Value << rightOp.Value;
                    break;

                case BitwiseType.SHR:
                    obj.Value = leftOp.Value >> rightOp.Value;
                    break;

                default:
                    throw new System.NotImplementedException("Not implemented.");
                }
            }
            catch {
                // TODO: Fill this out!
            }

            return(obj);
        }
Example #5
0
		///
		/// <summary>
		///		Parses logical expressions
		/// </summary>
		/// 
		/// <param name="leftOp">Left operand</param>
		/// <param name="rightOp">Right operand</param>
		/// <param name="type">Logical expression type</param>
		/// 
		/// <returns>The result of applying the given logical expression operator</returns>
		/// 
		public static CseObject Parse(CseObject leftOp, CseObject rightOp, LogicalType type) {
			CseObject obj = null;

			if (type == LogicalType.NOT) {
				obj = new CseObject(null) { IsLiteral = leftOp.IsLiteral };
			}
			else {
				obj = new CseObject(null) { IsLiteral = leftOp.IsLiteral && rightOp.IsLiteral };
			}

			try {
				switch (type) {
					case LogicalType.AND:
						// TODO: lazy eval if exception thrown
						obj.Value = leftOp.Value && rightOp.Value;
						break;
					case LogicalType.OR:
						// TODO: lazy eval if exception thrown
						obj.Value = leftOp.Value || rightOp.Value;
						break;
					case LogicalType.NOT: {
							//try {
							obj.Value = !leftOp.Value;
							/*}
							catch {
								MethodInfo mi = obj.Value.GetType().GetMethod(OpOverloadNames.FALSE);
								if (mi != null)
									obj.Value = obj.Value.GetType().InvokeMember(OpOverloadNames.FALSE, OpOverloadNames.Flags, null, CsEval.evalEnvironment, new object[] { obj.Value });
								else
									obj.Value = null;
							}*/
						}
						break;
					default:
						throw new System.NotImplementedException("Not implemented.");
				}
			}
			catch {
				// TODO: Fill this out!
			}

			return obj;
		}
Example #6
0
		///
		/// <summary>
		///		Parses bitwise expressions
		/// </summary>
		/// 
		/// <param name="leftOp">Left operand</param>
		/// <param name="rightOp">Right operand</param>
		/// <param name="type">Bitwise expression type</param>
		/// 
		/// <returns>The result of applying the given bitwise operand</returns>
		/// 
		public static CseObject Parse(CseObject leftOp, CseObject rightOp, BitwiseType type) {
			CseObject obj = null;

			if (type == BitwiseType.NOT) {
				obj = new CseObject(null) { IsLiteral = leftOp.IsLiteral };
			}
			else {
				obj = new CseObject(null) { IsLiteral = leftOp.IsLiteral && rightOp.IsLiteral };
			}

			try {
				switch (type) {
					case BitwiseType.AND:
						obj.Value = leftOp.Value & rightOp.Value;
						break;
					case BitwiseType.OR:
						obj.Value = leftOp.Value | rightOp.Value;
						break;
					case BitwiseType.NOT:
						obj.Value = ~leftOp.Value;
						break;
					case BitwiseType.SHL:
						obj.Value = leftOp.Value << rightOp.Value;
						break;
					case BitwiseType.SHR:
						obj.Value = leftOp.Value >> rightOp.Value;
						break;
					default:
						throw new System.NotImplementedException("Not implemented.");
				}
			}
			catch {
				// TODO: Fill this out!
			}

			return obj;
		}
Example #7
0
		///
		/// <summary>
		///		Constructor for MethResSettings objects
		/// </summary>
		/// 
		/// <param name="env">The environment to use</param>
		/// <param name="name">The name of the method</param>
		/// <param name="args">Arguments to pass to the method</param>
		/// <param name="isExtInvocation">True if this is an extended invocation, false otherwise</param>
		/// 

		public MethResSettings(object env, string name, CseObject[] args, bool isExtInvocation) {
			Env = env;
			Name = name;
			Args = args;
			IsExtInvocation = isExtInvocation;
		}
Example #8
0
        public static void Main2(string[] comArgs)
        {
            MethOverloads mo = new MethOverloads();
            A             a  = new A();
            //var t = a.GetType().GetMethod("Foo", BindingFlags.Public | BindingFlags.Instance).GetGenericArguments()[0].GetGenericParameterConstraints();//.GenericParameterAttributes;
            //mo.Baz(3);
            //mo.Foo( new int[] { 3, 1} );

            int?nullableint = null;

            CseObject from = new CseObject(new String[, ] {
                { "1" }
            });
            Type to = a.GetType().GetMethod("Foo", BindingFlags.Public | BindingFlags.Instance).GetParameters()[0].ParameterType;

            //Console.Out.WriteLine(MethRes.CanConvertType(from, to));

            MethRes.GetBestInvocableMember(new MethResSettings(new A(), "Foo", new CseObject[] { new CseObject(3) }, false));

            Console.Out.WriteLine(MethRes.ImpRefConv(from, to));
            return;

            Console.WindowHeight = 20;
            Console.WindowWidth  = 80;

            object env  = new MethOverloads();
            string name = "Bar";

            CseObject[] args = new CseObject[] {
                /*new CseObject('x') {
                 *      CallMod = CallArgMod.REF
                 * },
                 * new CseObject(3) {
                 *      CallMod = CallArgMod.OUT
                 * }*/
                new CseObject(3)
            };

            MethResObject bestMember = MethRes.GetBestInvocableMember(new MethResSettings(env, name, args, false));


            Console.ForegroundColor = ConsoleColor.White;
            Console.Out.WriteLine("CALL");
            Console.Out.Write("\t{0}: {1}(", env.GetType().FullName, name);
            foreach (object arg in args)
            {
                if (arg == null)
                {
                    Console.Out.Write("null, ");
                }
                else
                {
                    Console.Out.Write(arg.GetType().Name + ", ");
                }
            }
            Console.Out.WriteLine("\b\b)\n", env.GetType().Name);

            Console.ForegroundColor = ConsoleColor.Green;
            Console.Out.WriteLine("MATCH ");
            //foreach (MethodInfo appMember in appMembers)
            if (bestMember.MethInfo == null)
            {
                Console.Out.WriteLine("\tNo matches found!");
            }
            else
            {
                Console.Out.WriteLine("\t" + bestMember.MethInfo.ReflectedType.ToString() + ": " + bestMember.MethInfo.ToString());
            }
            Console.Out.WriteLine("");

            Console.ForegroundColor = ConsoleColor.Black;
        }
Example #9
0
		///
		/// <summary>
		///		Parses xor expressions
		/// </summary>
		/// 
		/// <param name="leftOp">Left operand</param>
		/// <param name="rightOp">Right operand</param>
		/// 
		/// <returns>The result of applying the xor operator</returns>
		/// 
		public static CseObject Parse(CseObject leftOp, CseObject rightOp) {
			CseObject obj = new CseObject(null) { IsLiteral = leftOp.IsLiteral && rightOp.IsLiteral };
			obj.Value = leftOp.Value ^ rightOp.Value;
			return obj;
		}