예제 #1
0
파일: Linq.cs 프로젝트: hansdude/Phalanger
		internal override PhpTypeCode Emit(CodeGenerator/*!*/ codeGenerator)
		{
			ILEmitter il = codeGenerator.IL;
			LinqBuilder builder = new LinqBuilder(codeGenerator);

			builder.DefineContextType();
			builder.EmitNewLinqContext();

			codeGenerator.LinqBuilder = builder;

			LinqOpChain chain = body.BuildChain();
			var typecode = chain.Emit(codeGenerator);

			// the result is IEnumerable<object>, let's wrap it and pass out
            il.Emit(OpCodes.Call, Methods.ClrObject_WrapRealObject);

			builder.BakeContextType();

			return PhpTypeCode.Object;
		}
예제 #2
0
파일: Linq.cs 프로젝트: hansdude/Phalanger
			public override PhpTypeCode Emit(LinqBuilder codeGenerator)
			{
				ILEmitter il = codeGenerator.IL;

				// NEW Func[object,object](<linq context>, <&lambda>);
				codeGenerator.EmitLoadLinqContext();
				il.Emit(OpCodes.Ldftn, codeGenerator.EmitLambda(string.Format("<Selector_{0}>",
					codeGenerator.GetNextSelectorNum()), valueVar, byExpr, PhpTypeCode.Object));
				il.Emit(OpCodes.Newobj, LinqExterns.Func2_object_object_ctor);

				DirectVarUse groupByVar = groupExpr as DirectVarUse;
				if ((groupByVar != null) && (groupByVar.VarName == valueVar.VarName))
				{
					// LOAD Select[object,object](<source>, <delegate>);
					// Simplified version - no element selector
					il.Emit(OpCodes.Call, LinqExterns.GroupBy);
				}
				else
				{
					// with element selector
					codeGenerator.EmitLoadLinqContext();
					il.Emit(OpCodes.Ldftn, codeGenerator.EmitLambda(string.Format("<Selector_{0}>",
						codeGenerator.GetNextSelectorNum()), valueVar, groupExpr, PhpTypeCode.Object));
					il.Emit(OpCodes.Newobj, LinqExterns.Func2_object_object_ctor);

					il.Emit(OpCodes.Call, LinqExterns.GroupByElementSel);
				}

				// Conversion from IEnumerable<IGrouping<..>> to IEnumerable<object> 
				il.Emit(OpCodes.Call, Methods.ClrObject_WrapRealObject); 
				codeGenerator.CodeGenerator.EmitLoadClassContext();
				il.Emit(OpCodes.Call, Methods.Convert.ObjectToLinqSource);
				return base.Emit(codeGenerator);
			}
예제 #3
0
파일: Linq.cs 프로젝트: hansdude/Phalanger
			public override PhpTypeCode Emit(LinqBuilder builder)
			{
				ILEmitter il = builder.IL;

				// source expected on stack

				// NEW Func[object,object](<linq context>, <&lambda>);
				builder.EmitLoadLinqContext();
				il.Emit(OpCodes.Ldftn, builder.EmitLambda(string.Format("<MultiSelector_{0}>",
					builder.GetNextMultiSelectorNum()), valueVar, innerChain, PhpTypeCode.LinqSource));
				il.Emit(OpCodes.Newobj, LinqExterns.Func2_object_IEnumerable_object_ctor);

				// LOAD Select[object,object](<source>, <delegate>);
				il.Emit(OpCodes.Call, LinqExterns.SelectMany);

				return base.Emit(builder);
			}
예제 #4
0
파일: Linq.cs 프로젝트: hansdude/Phalanger
			/// <summary>
			/// Emit lambda function that implements projection and call to
			/// IEnumerable.Select function (with current LINQ context as 
			/// first and generated lambda as a second parameter)
			/// </summary>
			public override PhpTypeCode Emit(LinqBuilder/*!*/ builder)
			{
				ILEmitter il = builder.IL;

				// source expected on stack

				// NEW Func[object,object](<linq context>, <&lambda>);
				builder.EmitLoadLinqContext();
				il.Emit(OpCodes.Ldftn, builder.EmitLambda(string.Format("<Selector_{0}>",
					builder.GetNextSelectorNum()), valueVar, selector, PhpTypeCode.Object));
				il.Emit(OpCodes.Newobj, LinqExterns.Func2_object_object_ctor);

				// LOAD Select[object,object](<source>, <delegate>);
				il.Emit(OpCodes.Call, LinqExterns.Select);
				//il.Emit(OpCodes.Call, Methods.Operators.Select);

				return base.Emit(builder);
			}
예제 #5
0
파일: Linq.cs 프로젝트: hansdude/Phalanger
			/// <summary>
			/// Emit lambda function that returns values used for sorting and
			/// call to OrderedSequence.OrderBy method (with current LINQ context as 
			/// first and generated lambda as a second parameter)
			/// </summary>
			public override PhpTypeCode Emit(LinqBuilder codeGenerator)
			{
				ILEmitter il = codeGenerator.IL;

				// NEW Func[object,object](<linq context>, <&lambda>);
				codeGenerator.EmitLoadLinqContext();
				il.Emit(OpCodes.Ldftn, codeGenerator.EmitLambda(string.Format("<Comparer_{0}>",
					codeGenerator.GetNextComparerNum()), valueVar, expression, PhpTypeCode.Object));
				il.Emit(OpCodes.Newobj, LinqExterns.Func2_object_object_ctor);

				// LOAD Select[object,object](<source>, <delegate>);
				if (isThenBy)
					il.Emit(OpCodes.Call, ordering == Ordering.Descending ? LinqExterns.ThenByDescending : LinqExterns.ThenBy);
				else
					il.Emit(OpCodes.Call, ordering == Ordering.Descending ? LinqExterns.OrderByDescending : LinqExterns.OrderBy);

				return base.Emit(codeGenerator);
			}
예제 #6
0
파일: Linq.cs 프로젝트: hansdude/Phalanger
		/// <summary>
		/// Emit next operation in the chain or nothing if next operation is null.
		/// To be used from inherited operations.
		/// </summary>
		public virtual PhpTypeCode Emit(LinqBuilder/*!*/ builder)
		{
			if (Next != null) return Next.Emit(builder); else return PhpTypeCode.LinqSource;
		}