Пример #1
0
 void TransformBinaryOperator(ExpressionType exprType, ref Expression right)
 {
     sb.Append(' ');
     if (IsNull(right))
     {
         if (exprType == ExpressionType.NotEqual)
         {
             sb.Append("IS NOT");
             right = Expression.Constant(null);
         }
         else if (exprType == ExpressionType.Equal)
         {
             sb.Append("IS");
             right = Expression.Constant(null);
         }
         else
         {
             OperatorEntry oe = FindOperator(exprType);
             sb.Append(oe.Replacement);
         }
     }
     else
     {
         OperatorEntry oe = FindOperator(exprType);
         sb.Append(oe.Replacement);
     }
     sb.Append(' ');
 }
Пример #2
0
        public override object CreateNewInstance(SelectItem item)
        {
            OperatorEntry   operatorEntry = item.Value as OperatorEntry;
            ActivityFactory factory       = Parent.EditingContext.Services.GetService <ActivityFactory>();
            Activity        _operator     = factory.CreateActivity(operatorEntry.Create, Parent.GetModelProperty());

            // Create InArgument instance wrapping the activity
            Type       genericType = typeof(InArgument <>).MakeGenericType(operatorEntry.ReturnType);
            InArgument argument    = Activator.CreateInstance(genericType, _operator) as InArgument;

            return(argument);
        }
Пример #3
0
        public static MethodInfo[] GetOperatorMethods(Type type, Operator op)
        {
            OperatorEntry entry = GetOperatorEntry(type);

            List <MethodInfo> methods;

            if (!entry.OperatorMethods.TryGetValue(op.MethodName, out methods))
            {
                return(new MethodInfo[0]);
            }

            return(methods.ToArray());
        }
Пример #4
0
        private static OperatorEntry GetOperatorEntry(Type type)
        {
            OperatorEntry result;

            if (!_typeOperatorHashtable.TryGetValue(type, out result))
            {
                lock (_typeOperatorHashtable)
                {
                    if (!_typeOperatorHashtable.TryGetValue(type, out result))
                    {
                        result = new OperatorEntry();
                        result.OperatorMethods = new Dictionary <string, List <MethodInfo> >();

                        MethodInfo[] methodInfos = type.GetMethods(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static);
                        Array.Sort(methodInfos, (x, y) => String.Compare(x.ToString(), y.ToString(), StringComparison.Ordinal));

                        foreach (MethodInfo methodInfo in methodInfos)
                        {
                            Operator op = GetOverloadableOperator(methodInfo.Name);

                            if (op != null ||
                                methodInfo.Name == OP_IMPLICIT_METHOD_NAME ||
                                methodInfo.Name == OP_EXPLICIT_METHOD_NAME)
                            {
                                List <MethodInfo> operatorMethods;
                                if (!result.OperatorMethods.TryGetValue(methodInfo.Name, out operatorMethods))
                                {
                                    operatorMethods = new List <MethodInfo>();
                                    result.OperatorMethods.Add(methodInfo.Name, operatorMethods);
                                }

                                operatorMethods.Add(methodInfo);
                            }
                        }

                        _typeOperatorHashtable.Add(type, result);
                    }
                }
            }

            return(result);
        }
Пример #5
0
		private static OperatorEntry GetOperatorEntry(Type type)
		{
		    OperatorEntry result;
            if (!_typeOperatorHashtable.TryGetValue(type, out result))
            {
                lock (_typeOperatorHashtable)
                {
                    if (!_typeOperatorHashtable.TryGetValue(type, out result))
                    {
                        result = new OperatorEntry();
                    	result.OperatorMethods = new Dictionary<string, List<MethodInfo>>();

                        MethodInfo[] methodInfos = type.GetMethods(BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static);
                        Array.Sort(methodInfos, (x, y) => String.Compare(x.ToString(), y.ToString(), StringComparison.Ordinal));

                        foreach (MethodInfo methodInfo in methodInfos)
                        {
                            Operator op = GetOverloadableOperator(methodInfo.Name);

                            if (op != null ||
                                methodInfo.Name == OP_IMPLICIT_METHOD_NAME ||
                                methodInfo.Name == OP_EXPLICIT_METHOD_NAME)
                            {
                                List<MethodInfo> operatorMethods;
                                if (!result.OperatorMethods.TryGetValue(methodInfo.Name, out operatorMethods))
                                {
                                    operatorMethods = new List<MethodInfo>();
                                    result.OperatorMethods.Add(methodInfo.Name, operatorMethods);
                                }

                                operatorMethods.Add(methodInfo);
                            }
                        }

                        _typeOperatorHashtable.Add(type, result);
                    }
                }
            }
		    
		    return result;
		}
Пример #6
0
        public static MethodInfo[] GetOperatorMethods(Type type, CastingOperatorType op)
        {
            string opMethodName;

            if (op == CastingOperatorType.Implicit)
            {
                opMethodName = OP_IMPLICIT_METHOD_NAME;
            }
            else
            {
                opMethodName = OP_EXPLICIT_METHOD_NAME;
            }

            OperatorEntry entry = GetOperatorEntry(type);

            List <MethodInfo> methods;

            if (!entry.OperatorMethods.TryGetValue(opMethodName, out methods))
            {
                return(new MethodInfo[0]);
            }

            return(methods.ToArray());
        }
Пример #7
0
		//
		// Checks that some operators come in pairs:
		//  == and !=
		// > and <
		// >= and <=
		// true and false
		//
		// They are matched based on the return type and the argument types
		//
		void CheckPairedOperators ()
		{
			Hashtable pairs = new Hashtable (null, null);
			Operator true_op = null;
			Operator false_op = null;
			
			// Register all the operators we care about.
			foreach (Operator op in operators){
				int reg = 0;
				
				switch (op.OperatorType){
				case Operator.OpType.Equality:
					reg = 1; break;
				case Operator.OpType.Inequality:
					reg = 2; break;

				case Operator.OpType.True:
					true_op = op;
					break;
				case Operator.OpType.False:
					false_op = op;
					break;
					
				case Operator.OpType.GreaterThan:
					reg = 1; break;
				case Operator.OpType.LessThan:
					reg = 2; break;
					
				case Operator.OpType.GreaterThanOrEqual:
					reg = 1; break;
				case Operator.OpType.LessThanOrEqual:
					reg = 2; break;
				}
				if (reg == 0)
					continue;

				OperatorEntry oe = new OperatorEntry (reg, op);

				object o = pairs [oe];
				if (o == null)
					pairs [oe] = oe;
				else {
					oe = (OperatorEntry) o;
					oe.flags |= reg;
				}
			}

			if (true_op != null){
				if (false_op == null)
					Report.Error (216, true_op.Location, "operator true requires a matching operator false");
			} else if (false_op != null)
				Report.Error (216, false_op.Location, "operator false requires a matching operator true");
			
			//
			// Look for the mistakes.
			//
			foreach (DictionaryEntry de in pairs){
				OperatorEntry oe = (OperatorEntry) de.Key;

				if (oe.flags == 3)
					continue;

				string s = "";
				switch (oe.ot){
				case Operator.OpType.Equality:
					s = "!=";
					break;
				case Operator.OpType.Inequality: 
					s = "==";
					break;
				case Operator.OpType.GreaterThan: 
					s = "<";
					break;
				case Operator.OpType.LessThan:
					s = ">";
					break;
				case Operator.OpType.GreaterThanOrEqual:
					s = "<=";
					break;
				case Operator.OpType.LessThanOrEqual:
					s = ">=";
					break;
				}
				Report.Error (216, oe.op.Location,
					      "The operator `" + oe.op + "' requires a matching operator `" + s + "' to also be defined");
			}
		}
Пример #8
0
        int GetPrecedence(ExpressionType exprType)
        {
            OperatorEntry oe = FindOperator(exprType);

            return(oe.Precedence);
        }