Ejemplo n.º 1
1
        // Initialize for searching a list of values
		public InElement(ExpressionElement operand, IList listElements)
		{
			MyOperand = operand;

			ExpressionElement[] arr = new ExpressionElement[listElements.Count];
			listElements.CopyTo(arr, 0);

			MyArguments = new List<ExpressionElement>(arr);
			this.ResolveForListSearch();
		}
Ejemplo n.º 2
0
		public void SetChild(ExpressionElement child)
		{
			MyChild = child;
			MyResultType = this.GetResultType(child.ResultType);

			if (MyResultType == null) {
				base.ThrowCompileException(CompileErrorResourceKeys.OperationNotDefinedForType, CompileExceptionReason.TypeMismatch, MyChild.ResultType.Name);
			}
		}
Ejemplo n.º 3
0
		private void SetupArrayIndexer()
		{
			MyIndexerElement = MyIndexerElements[0];

			if (MyIndexerElements.Count > 1) {
				base.ThrowCompileException(CompileErrorResourceKeys.MultiArrayIndexNotSupported, CompileExceptionReason.TypeMismatch);
			} else if (ImplicitConverter.EmitImplicitConvert(MyIndexerElement.ResultType, typeof(Int32), null) == false) {
				base.ThrowCompileException(CompileErrorResourceKeys.ArrayIndexersMustBeOfType, CompileExceptionReason.TypeMismatch, typeof(Int32).Name);
			}
		}
Ejemplo n.º 4
0
		public CastElement(ExpressionElement castExpression, string[] destTypeParts, bool isArray, IServiceProvider services)
		{
			MyCastExpression = castExpression;

			MyDestType = GetDestType(destTypeParts, services);

			if (MyDestType == null) {
				base.ThrowCompileException(CompileErrorResourceKeys.CouldNotResolveType, CompileExceptionReason.UndefinedName, GetDestTypeString(destTypeParts, isArray));
			}

			if (isArray == true) {
				MyDestType = MyDestType.MakeArrayType();
			}

			if (this.IsValidCast(MyCastExpression.ResultType, MyDestType) == false) {
				this.ThrowInvalidCastException();
			}
		}
Ejemplo n.º 5
0
		public ConditionalElement(ExpressionElement condition, ExpressionElement whenTrue, ExpressionElement whenFalse)
		{
			MyCondition = condition;
			MyWhenTrue = whenTrue;
			MyWhenFalse = whenFalse;

			if ((!object.ReferenceEquals(MyCondition.ResultType, typeof(bool)))) {
				base.ThrowCompileException(CompileErrorResourceKeys.FirstArgNotBoolean, CompileExceptionReason.TypeMismatch);
			}

			// The result type is the type that is common to the true/false operands
			if (ImplicitConverter.EmitImplicitConvert(MyWhenFalse.ResultType, MyWhenTrue.ResultType, null) == true) {
				MyResultType = MyWhenTrue.ResultType;
			} else if (ImplicitConverter.EmitImplicitConvert(MyWhenTrue.ResultType, MyWhenFalse.ResultType, null) == true) {
				MyResultType = MyWhenFalse.ResultType;
			} else {
				base.ThrowCompileException(CompileErrorResourceKeys.NeitherArgIsConvertibleToTheOther, CompileExceptionReason.TypeMismatch, MyWhenTrue.ResultType.Name, MyWhenFalse.ResultType.Name);
			}
		}
Ejemplo n.º 6
0
		public ExpressionElement[] ToArray()
		{
			ExpressionElement[] arr = new ExpressionElement[MyElements.Count];
			MyElements.CopyTo(arr, 0);
			return arr;
		}
Ejemplo n.º 7
0
		public ArgumentList(ICollection elements)
		{
			ExpressionElement[] arr = new ExpressionElement[elements.Count];
			elements.CopyTo(arr, 0);
			MyElements = arr;
		}
Ejemplo n.º 8
0
 public void Initialize(ExpressionElement leftChild, ExpressionElement rightChild, LogicalCompareOperation op)
 {
     MyLeftChild = leftChild;
     MyRightChild = rightChild;
     MyOperation = op;
 }
Ejemplo n.º 9
0
		private bool FindIndexer(Type targetType)
		{
			// Get the default members
			MemberInfo[] members = targetType.GetDefaultMembers();

			List<MethodInfo> methods = new List<MethodInfo>();

			// Use the first one that's valid for our indexer type
			foreach (MemberInfo mi in members) {
				PropertyInfo pi = mi as PropertyInfo;
				if ((pi != null)) {
					methods.Add(pi.GetGetMethod(true));
				}
			}

			FunctionCallElement func = new FunctionCallElement("Indexer", methods.ToArray(), MyIndexerElements);
			func.Resolve(MyServices);
			MyIndexerElement = func;

			return true;
		}
Ejemplo n.º 10
0
		protected static void EmitChildWithConvert(ExpressionElement child, Type resultType, FleeILGenerator ilg, IServiceProvider services)
		{
			child.Emit(ilg, services);
			var converted = ImplicitConverter.EmitImplicitConvert(child.ResultType, resultType, ilg);
			Debug.Assert(converted, "convert failed");
		}
Ejemplo n.º 11
0
    private static void EmitOperand(ExpressionElement operand, ShortCircuitInfo info, FleeILGenerator ilg, IServiceProvider services)
    {
        // Is this operand the target of a label?
        if (info.Branches.HasLabel(operand) == true)
        {
            // Yes, so mark it
            Label leftLabel = info.Branches.FindLabel(operand);
            ilg.MarkLabel(leftLabel);

            // Note the label's position
            MarkBranchTarget(info, leftLabel, ilg);
        }

        // Emit the operand
        operand.Emit(ilg, services);
    }
Ejemplo n.º 12
0
        // Emit the arguments to a regular method call
		private void EmitRegularFunctionInternal(ParameterInfo[] parameters, ExpressionElement[] elements, FleeILGenerator ilg, IServiceProvider services)
		{
			Debug.Assert(parameters.Length == elements.Length, "argument count mismatch");

			// Emit each element and any required conversions to the actual parameter type
			for (int i = 0; i <= parameters.Length - 1; i++) {
				var element = elements[i];
				var pi = parameters[i];
				element.Emit(ilg, services);
				bool success = ImplicitConverter.EmitImplicitConvert(element.ResultType, pi.ParameterType, ilg);
				Debug.Assert(success, "conversion failed");
			}
		}
Ejemplo n.º 13
0
        // Emit elements into an array
		private static void EmitElementArrayLoad(ExpressionElement[] elements, Type arrayElementType, FleeILGenerator ilg, IServiceProvider services)
		{
			// Load the array length
			LiteralElement.EmitLoad(elements.Length, ilg);

			// Create the array
			ilg.Emit(OpCodes.Newarr, arrayElementType);

			// Store the new array in a unique local and remember the index
			var local = ilg.DeclareLocal(arrayElementType.MakeArrayType());
			int arrayLocalIndex = local.LocalIndex;
			Utility.EmitStoreLocal(ilg, arrayLocalIndex);

			for (int i = 0; i <= elements.Length - 1; i++) {
				// Load the array
				Utility.EmitLoadLocal(ilg, arrayLocalIndex);
				// Load the index
				LiteralElement.EmitLoad(i, ilg);
				// Emit the element (with any required conversions)
				ExpressionElement element = elements[i];
				element.Emit(ilg, services);
				ImplicitConverter.EmitImplicitConvert(element.ResultType, arrayElementType, ilg);
				// Store it into the array
				Utility.EmitArrayStore(ilg, arrayElementType);
			}

			// Load the array
			Utility.EmitLoadLocal(ilg, arrayLocalIndex);
		}
Ejemplo n.º 14
0
        // Emit the arguments to a paramArray method call
		private void EmitParamArrayArguments(ParameterInfo[] parameters, ExpressionElement[] elements, FleeILGenerator ilg, IServiceProvider services)
		{
			// Get the fixed parameters
			ParameterInfo[] fixedParameters = new ParameterInfo[MyTargetMethodInfo.MyFixedArgTypes.Length];
			Array.Copy(parameters, fixedParameters, fixedParameters.Length);

			// Get the corresponding fixed parameters
			ExpressionElement[] fixedElements = new ExpressionElement[MyTargetMethodInfo.MyFixedArgTypes.Length];
			Array.Copy(elements, fixedElements, fixedElements.Length);

			// Emit the fixed arguments
			this.EmitRegularFunctionInternal(fixedParameters, fixedElements, ilg, services);

			// Get the paramArray arguments
			ExpressionElement[] paramArrayElements = new ExpressionElement[elements.Length - fixedElements.Length];
			Array.Copy(elements, fixedElements.Length, paramArrayElements, 0, paramArrayElements.Length);

			// Emit them into an array
			EmitElementArrayLoad(paramArrayElements, MyTargetMethodInfo.ParamArrayElementType, ilg, services);
		}
Ejemplo n.º 15
0
		private void EmitOnDemandFunction(ExpressionElement[] elements, FleeILGenerator ilg, IServiceProvider services)
		{
			// Load the variable collection
			EmitLoadVariables(ilg);
			// Load the function name
			ilg.Emit(OpCodes.Ldstr, MyName);
			// Load the arguments array
			EmitElementArrayLoad(elements, typeof(object), ilg, services);

			// Call the function to get the result
			MethodInfo mi = VariableCollection.GetFunctionInvokeMethod(MyOnDemandFunctionReturnType);

			this.EmitMethodCall(mi, ilg);
		}
Ejemplo n.º 16
0
		public ExpressionMemberElement(ExpressionElement element)
		{
			MyElement = element;
		}
Ejemplo n.º 17
0
		public RootExpressionElement(ExpressionElement child, Type resultType)
		{
			MyChild = child;
			MyResultType = resultType;
			this.Validate();
		}
Ejemplo n.º 18
0
		protected static bool IsChildOfType(ExpressionElement child, Type t)
		{
			return object.ReferenceEquals(child.ResultType, t);
		}
Ejemplo n.º 19
0
        // Initialize for searching a collection
		public InElement(ExpressionElement operand, ExpressionElement targetCollection)
		{
			MyOperand = operand;
			MyTargetCollectionElement = targetCollection;
			this.ResolveForCollectionSearch();
		}
Ejemplo n.º 20
0
        // Set the left and right operands, get the operation, and get the result type
		private void Configure(ExpressionElement leftChild, ExpressionElement rightChild, object op)
		{
			MyLeftChild = leftChild;
			MyRightChild = rightChild;
			this.GetOperation(op);

			this.ValidateInternal(op);
		}