public static CodegenMethod ComputeMultiKeyCodegen( int idNumber, ExprForge[] partitionForges, CodegenClassScope classScope, CodegenNamedMethods namedMethods) { var exprSymbol = new ExprForgeCodegenSymbol(true, null); Consumer<CodegenMethod> code = method => { if (partitionForges.Length == 1) { CodegenExpression expression = partitionForges[0] .EvaluateCodegen( typeof(object), method, exprSymbol, classScope); exprSymbol.DerivedSymbolsCodegen(method, method.Block, classScope); method.Block.MethodReturn(expression); } else { var expressions = new CodegenExpression[partitionForges.Length]; for (var i = 0; i < partitionForges.Length; i++) { expressions[i] = partitionForges[i] .EvaluateCodegen( typeof(object), method, exprSymbol, classScope); } exprSymbol.DerivedSymbolsCodegen(method, method.Block, classScope); method.Block.DeclareVar<object[]>( "keys", NewArrayByLength(typeof(object), Constant(partitionForges.Length))); for (var i = 0; i < expressions.Length; i++) { method.Block.AssignArrayElement("keys", Constant(i), expressions[i]); } method.Block.MethodReturn(NewInstance<HashableMultiKey>(Ref("keys"))); } }; return namedMethods.AddMethodWithSymbols( typeof(object), "ComputeKeyArrayCodegen_" + idNumber, CodegenNamedParam.From( typeof(EventBean[]), NAME_EPS, typeof(bool), NAME_ISNEWDATA, typeof(ExprEvaluatorContext), NAME_EXPREVALCONTEXT), typeof(AggregationServiceCodegenUtil), classScope, code, exprSymbol); }
public static CodegenMethod ComputeMultiKeyCodegen( int idNumber, ExprNode[] partitionForges, MultiKeyClassRef optionalMultiKey, CodegenClassScope classScope, CodegenNamedMethods namedMethods) { var exprSymbol = new ExprForgeCodegenSymbol(true, null); Consumer<CodegenMethod> code = method => { if (optionalMultiKey == null || optionalMultiKey.ClassNameMK == null) { var expression = partitionForges[0].Forge.EvaluateCodegen(typeof(object), method, exprSymbol, classScope); exprSymbol.DerivedSymbolsCodegen(method, method.Block, classScope); method.Block.MethodReturn(expression); return; } var expressions = new CodegenExpression[partitionForges.Length]; for (var i = 0; i < partitionForges.Length; i++) { expressions[i] = partitionForges[i].Forge .EvaluateCodegen( typeof(object), method, exprSymbol, classScope); } var instance = optionalMultiKey.ClassNameMK.Type != null ? NewInstance(optionalMultiKey.ClassNameMK.Type, expressions) : NewInstanceInner(optionalMultiKey.ClassNameMK.Name, expressions); exprSymbol.DerivedSymbolsCodegen(method, method.Block, classScope); method.Block.MethodReturn(instance); }; return namedMethods.AddMethodWithSymbols( typeof(object), "ComputeKeyArrayCodegen_" + idNumber, CodegenNamedParam.From( typeof(EventBean[]), NAME_EPS, typeof(bool), NAME_ISNEWDATA, typeof(ExprEvaluatorContext), NAME_EXPREVALCONTEXT), typeof(AggregationServiceCodegenUtil), classScope, code, exprSymbol); }
public CodegenExpression MakeTimePeriodAnonymous( CodegenMethod method, CodegenClassScope classScope) { //var timeClass = NewAnonymousClass(method.Block, typeof(TimePeriodEval)); //var evalMethod = CodegenMethod.MakeMethod(typeof(TimePeriod), GetType(), classScope) // .AddParam(PARAMS); //timeClass.AddMethod("timePeriodEval", evalMethod); var evalMethod = new CodegenExpressionLambda(method.Block).WithParams(PARAMS); var timeClass = NewInstance<ProxyTimePeriodEval>(evalMethod); var exprSymbol = new ExprForgeCodegenSymbol(true, true); //var exprMethod = evalMethod.MakeChildWithScope(typeof(TimePeriod), GetType(), exprSymbol, classScope); var exprMethod = method.MakeChild(typeof(TimePeriod), GetType(), classScope) .AddParam(PARAMS); CodegenExpression expression = forge.EvaluateGetTimePeriodCodegen(exprMethod, exprSymbol, classScope); //exprSymbol.DerivedSymbolsCodegen(evalMethod, exprMethod.Block, classScope); exprSymbol.DerivedSymbolsCodegen(exprMethod, exprMethod.Block, classScope); exprMethod.Block.MethodReturn(expression); evalMethod.Block.BlockReturn(LocalMethod(exprMethod, REF_EPS, REF_ISNEWDATA, REF_EXPREVALCONTEXT)); return timeClass; }
public static CodegenMethod CodegenMethod( ExprNode[] expressionNodes, MultiKeyClassRef multiKeyClassRef, CodegenMethodScope parent, CodegenClassScope classScope) { var eventUnpackMethod = parent .MakeChildWithScope(typeof(object), typeof(CodegenLegoMethodExpression), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(ExprForgeCodegenNames.PARAMS); var exprSymbol = new ExprForgeCodegenSymbol(true, null); var exprMethod = eventUnpackMethod .MakeChildWithScope(typeof(object), typeof(CodegenLegoMethodExpression), exprSymbol, classScope) .AddParam(ExprForgeCodegenNames.PARAMS); var expressions = new CodegenExpression[expressionNodes.Length]; for (var i = 0; i < expressionNodes.Length; i++) { var forge = expressionNodes[i].Forge; expressions[i] = CodegenExpressionMayCoerce(forge, multiKeyClassRef.MKTypes[i], exprMethod, exprSymbol, classScope); } var instance = multiKeyClassRef.ClassNameMK.Type != null ? NewInstance(multiKeyClassRef.ClassNameMK.Type, expressions) : NewInstanceInner(multiKeyClassRef.ClassNameMK.Name, expressions); exprSymbol.DerivedSymbolsCodegen(eventUnpackMethod, exprMethod.Block, classScope); exprMethod.Block.MethodReturn(instance); eventUnpackMethod.Block.MethodReturn(LocalMethod(exprMethod, REF_EPS, REF_ISNEWDATA, REF_EXPREVALCONTEXT)); return(eventUnpackMethod); }
private CodegenMethod EvaluateGetROCollectionScalarCodegenRewritten( CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { var nodeObject = GetNodeObject(codegenClassScope); var scope = new ExprForgeCodegenSymbol(true, null); var methodNode = codegenMethodScope .MakeChildWithScope( typeof(ICollection<object>), typeof(ExprDeclaredForgeBase), scope, codegenClassScope) .AddParam(ExprForgeCodegenNames.PARAMS); CodegenExpression refEPS = scope.GetAddEPS(methodNode); CodegenExpression refExprEvalCtx = scope.GetAddExprEvalCtx(methodNode); // generate code for the inner value so we know its symbols and derived symbols var innerValue = ((ExprEnumerationForge) InnerForge).EvaluateGetROCollectionScalarCodegen( methodNode, scope, codegenClassScope); // produce derived symbols var block = methodNode.Block; scope.DerivedSymbolsCodegen(methodNode, block, codegenClassScope); if (isCache) { block .DeclareVar<ExpressionResultCacheForDeclaredExprLastColl>( "cache", ExprDotMethodChain(refExprEvalCtx) .Get("ExpressionResultCacheService") .Get("AllocateDeclaredExprLastColl")) .DeclareVar<ExpressionResultCacheEntryEventBeanArrayAndCollBean>( "entry", ExprDotMethod( Ref("cache"), "GetDeclaredExpressionLastColl", nodeObject, refEPS)) .IfCondition(NotEqualsNull(Ref("entry"))) .BlockReturn( Unwrap<object>(ExprDotName(Ref("entry"), "Result"))) .DeclareVar<ICollection<object>>("result", innerValue) .Expression( ExprDotMethod( Ref("cache"), "SaveDeclaredExpressionLastColl", nodeObject, refEPS, FlexWrap(Unwrap<EventBean>(Ref("result"))))); } else { block.DeclareVar<ICollection<object>>("result", innerValue); } block.MethodReturn(FlexWrap(Ref("result"))); return methodNode; }
public CodegenMethod EvaluateRowCodegen( CodegenMethodScope parent, CodegenClassScope classScope) { var symbols = new ExprForgeCodegenSymbol(true, true); var method = parent.MakeChildWithScope( typeof(IDictionary<string, object>), typeof(CodegenLegoMethodExpression), symbols, classScope) .AddParam(ExprForgeCodegenNames.PARAMS); var selectClause = SelectClause; var selectAsNames = SelectAsNames; var expressions = new CodegenExpression[selectClause.Length]; for (var i = 0; i < selectClause.Length; i++) { expressions[i] = selectClause[i].Forge.EvaluateCodegen(typeof(object), method, symbols, classScope); } symbols.DerivedSymbolsCodegen(method, method.Block, classScope); method.Block.DeclareVar<IDictionary<string, object>>( "map", NewInstance(typeof(HashMap<string, object>))); for (var i = 0; i < selectClause.Length; i++) { method.Block.ExprDotMethod(Ref("map"), "Put", Constant(selectAsNames[i]), expressions[i]); } method.Block.MethodReturn(Ref("map")); return method; }
public static CodegenMethod CodegenMapSelect( IList<ExprNode> selectClause, string[] selectAsNames, Type generator, CodegenMethodScope parent, CodegenClassScope classScope) { var exprSymbol = new ExprForgeCodegenSymbol(true, null); var method = parent.MakeChildWithScope( typeof(IDictionary<string, object>), generator, exprSymbol, classScope) .AddParam(PARAMS); method.Block.DeclareVar<IDictionary<string, object>>( "map", NewInstance(typeof(HashMap<string, object>), Constant(selectAsNames.Length + 2))); var expressions = new CodegenExpression[selectAsNames.Length]; for (var i = 0; i < selectClause.Count; i++) { expressions[i] = selectClause[i].Forge.EvaluateCodegen(typeof(object), method, exprSymbol, classScope); } exprSymbol.DerivedSymbolsCodegen(method, method.Block, classScope); for (var i = 0; i < selectClause.Count; i++) { method.Block.ExprDotMethod(Ref("map"), "Put", Constant(selectAsNames[i]), expressions[i]); } method.Block.MethodReturn(Ref("map")); return method; }
private CodegenMethod EvaluateCodegenRewritten( Type requiredType, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { var nodeObject = GetNodeObject(codegenClassScope); var evaluationType = DetermineEvaluationType(requiredType); var scope = new ExprForgeCodegenSymbol(true, null); var methodNode = codegenMethodScope .MakeChildWithScope(evaluationType, typeof(ExprDeclaredForgeBase), scope, codegenClassScope) .AddParam(ExprForgeCodegenNames.PARAMS); CodegenExpression refEPS = scope.GetAddEPS(methodNode); CodegenExpression refExprEvalCtx = scope.GetAddExprEvalCtx(methodNode); // generate code for the inner value so we know its symbols and derived symbols var innerValue = InnerForge.EvaluateCodegen( requiredType, methodNode, scope, codegenClassScope); // produce derived symbols var block = methodNode.Block; scope.DerivedSymbolsCodegen(methodNode, block, codegenClassScope); if (isCache) { CodegenExpression eval = ExprDotName(Ref("entry"), "Result"); if (evaluationType != typeof(object)) { eval = Cast(InnerForge.EvaluationType, eval); } block .DeclareVar<ExpressionResultCacheForDeclaredExprLastValue>( "cache", ExprDotMethodChain(refExprEvalCtx) .Get("ExpressionResultCacheService") .Get("AllocateDeclaredExprLastValue")) .DeclareVar<ExpressionResultCacheEntryEventBeanArrayAndObj>( "entry", ExprDotMethod(Ref("cache"), "GetDeclaredExpressionLastValue", nodeObject, refEPS)) .IfCondition(NotEqualsNull(Ref("entry"))) .BlockReturn(eval) .DeclareVar(evaluationType, "result", innerValue) .Expression( ExprDotMethod( Ref("cache"), "SaveDeclaredExpressionLastValue", nodeObject, refEPS, Ref("result"))); } else { block.DeclareVar(evaluationType, "result", innerValue); } block.MethodReturn(Ref("result")); return methodNode; }
private static CodegenMethod GetComparableWMultiKeyCodegen( ExprNode[] criteria, CodegenExpressionRef @ref, CodegenNamedMethods namedMethods, CodegenClassScope classScope) { var methodName = "GetComparable_" + @ref.Ref; Consumer<CodegenMethod> code = method => { if (criteria.Length == 1) { method.Block.MethodReturn( LocalMethod( CodegenLegoMethodExpression.CodegenExpression( criteria[0].Forge, method, classScope, true), REF_EPS, REF_ISNEWDATA, REF_EXPREVALCONTEXT)); } else { var exprSymbol = new ExprForgeCodegenSymbol(true, null); var expressions = new CodegenExpression[criteria.Length]; for (var i = 0; i < criteria.Length; i++) { expressions[i] = criteria[i] .Forge.EvaluateCodegen( typeof(object), method, exprSymbol, classScope); } exprSymbol.DerivedSymbolsCodegen(method, method.Block, classScope); method.Block.DeclareVar<object[]>( "result", NewArrayByLength(typeof(object), Constant(criteria.Length))); for (var i = 0; i < criteria.Length; i++) { method.Block.AssignArrayElement(Ref("result"), Constant(i), expressions[i]); } method.Block.MethodReturn(NewInstance<HashableMultiKey>(Ref("result"))); } }; return namedMethods.AddMethod( typeof(object), methodName, CodegenNamedParam.From( typeof(EventBean[]), NAME_EPS, typeof(bool), NAME_ISNEWDATA, typeof(ExprEvaluatorContext), NAME_EXPREVALCONTEXT), typeof(AggregatorAccessSortedImpl), classScope, code); }
public static CodegenExpression CodegenEvaluatorObjectArray( IList<ExprForge> forges, CodegenMethod method, Type generator, CodegenClassScope classScope) { var exprSymbol = new ExprForgeCodegenSymbol(true, null); //var evaluator = NewAnonymousClass(method.Block, typeof(ExprEvaluator)); //var evaluate = CodegenMethod.MakeParentNode<object>(generator, classScope) // .AddParam(PARAMS); //evaluator.AddMethod("Evaluate", evaluate); var exprMethod = method .MakeChildWithScope( typeof(object), typeof(CodegenLegoMethodExpression), exprSymbol, classScope) .AddParam(PARAMS); var expressions = new CodegenExpression[forges.Count]; for (var i = 0; i < forges.Count; i++) { expressions[i] = forges[i] .EvaluateCodegen( forges[i].EvaluationType, exprMethod, exprSymbol, classScope); } exprSymbol.DerivedSymbolsCodegen(exprMethod, exprMethod.Block, classScope); exprMethod.Block.DeclareVar<object[]>( "values", NewArrayByLength(typeof(object), Constant(forges.Count))); for (var i = 0; i < forges.Count; i++) { var result = expressions[i]; exprMethod.Block.AssignArrayElement("values", Constant(i), result); } exprMethod.Block.MethodReturn(Ref("values")); var evaluate = new CodegenExpressionLambda(method.Block) .WithParams(PARAMS) .WithBody( block => block .BlockReturn( LocalMethod( exprMethod, REF_EPS, REF_ISNEWDATA, REF_EXPREVALCONTEXT))); return NewInstance<ProxyExprEvaluator>(evaluate); }
public static CodegenExpression CodegenGet( CodegenExpression beanExpression, ExprDotNodeForgeStaticMethod forge, CodegenMethodScope codegenMethodScope, CodegenClassScope codegenClassScope) { var exprSymbol = new ExprForgeCodegenSymbol(true, null); var methodNode = codegenMethodScope.MakeChildWithScope( forge.EvaluationType, typeof(ExprDotNodeForgeStaticMethodEval), exprSymbol, codegenClassScope) .AddParam(ExprForgeCodegenNames.PARAMS); var args = AllArgumentExpressions( forge.ChildForges, forge.StaticMethod, methodNode, exprSymbol, codegenClassScope); exprSymbol.DerivedSymbolsCodegen(methodNode, methodNode.Block, codegenClassScope); AppendArgExpressions(args, methodNode.Block); // try block var tryBlock = methodNode.Block.TryCatch(); var invoke = CodegenInvokeExpression( forge.TargetObject, forge.StaticMethod, args, codegenClassScope); tryBlock.BlockReturn(invoke); // exception handling AppendCatch( tryBlock, forge.StaticMethod, forge.OptionalStatementName, forge.ClassOrPropertyName, forge.IsRethrowExceptions, args); // end method methodNode.Block.MethodReturn(ConstantNull()); return LocalMethod( methodNode, NewArrayWithInit(typeof(EventBean), beanExpression), ConstantTrue(), ConstantNull()); }
public CodegenExpression EventBeanGetCodegen( CodegenExpression beanExpression, CodegenMethodScope parent, CodegenClassScope classScope) { var method = parent.MakeChild(typeof(object), GetType(), classScope) .AddParam(typeof(EventBean), "eventBean"); method.Block.DeclareVar<EventBean[]>( "events", NewArrayWithInit(typeof(EventBean), Ref("eventBean"))); // method to evaluate expressions and compute hash var exprSymbol = new ExprForgeCodegenSymbol(true, true); var exprMethod = method .MakeChildWithScope(typeof(object), typeof(CodegenLegoMethodExpression), exprSymbol, classScope) .AddParam(ExprForgeCodegenNames.PARAMS); var expressions = new CodegenExpression[nodes.Length]; for (var i = 0; i < nodes.Length; i++) { expressions[i] = nodes[i].Forge.EvaluateCodegen(typeof(object), exprMethod, exprSymbol, classScope); } exprSymbol.DerivedSymbolsCodegen(method, exprMethod.Block, classScope); var hashCode = Ref("hashCode"); exprMethod.Block.DeclareVar<int>(hashCode.Ref, Constant(0)); for (var i = 0; i < nodes.Length; i++) { var result = Ref("result" + i); exprMethod.Block .DeclareVar<object>(result.Ref, expressions[i]) .IfRefNotNull(result.Ref) .AssignRef(hashCode, Op(Op(Constant(31), "*", hashCode), "+", ExprDotMethod(result, "GetHashCode"))) .BlockEnd(); } exprMethod.Block .IfCondition(Relational(hashCode, CodegenExpressionRelational.CodegenRelational.GE, Constant(0))) .BlockReturn(Op(hashCode, "%", Constant(granularity))) .MethodReturn(Op(Op(hashCode, "%", Constant(granularity)), "*", Constant(-1))); method.Block.MethodReturn(LocalMethod(exprMethod, Ref("events"), ConstantTrue(), ConstantNull())); return LocalMethod(method, beanExpression); }
private static CodegenExpression CodegenMultiKeyExprEvaluator( ExprForge[] expressionNodes, MultiKeyClassRef multiKeyClassRef, CodegenMethod method, CodegenClassScope classScope) { var evaluate = new CodegenExpressionLambda(method.Block) .WithParams(PARAMS); var evaluator = NewInstance <ProxyExprEvaluator>(evaluate); // CodegenExpressionNewAnonymousClass evaluator = NewAnonymousClass(method.Block, typeof(ExprEvaluator)); // CodegenMethod evaluate = CodegenMethod // .MakeParentNode(typeof(object), typeof(StmtClassForgeableMultiKey), classScope) // .AddParam(ExprForgeCodegenNames.PARAMS); // // evaluator.AddMethod("evaluate", evaluate); var exprSymbol = new ExprForgeCodegenSymbol(true, null); var exprMethod = method .MakeChildWithScope(typeof(object), typeof(CodegenLegoMethodExpression), exprSymbol, classScope) .AddParam(ExprForgeCodegenNames.PARAMS); var expressions = new CodegenExpression[expressionNodes.Length]; for (var i = 0; i < expressionNodes.Length; i++) { expressions[i] = CodegenExpressionMayCoerce(expressionNodes[i], multiKeyClassRef.MKTypes[i], exprMethod, exprSymbol, classScope); } var instance = multiKeyClassRef.ClassNameMK.Type != null ? NewInstance(multiKeyClassRef.ClassNameMK.Type, expressions) : NewInstanceInner(multiKeyClassRef.ClassNameMK.Name, expressions); exprSymbol.DerivedSymbolsCodegen(method, exprMethod.Block, classScope); exprMethod.Block.MethodReturn(instance); evaluate.Block.BlockReturn(LocalMethod(exprMethod, REF_EPS, REF_ISNEWDATA, REF_EXPREVALCONTEXT)); return(evaluator); }
private static CodegenInnerClass MakeSelectExprProcessor( string className, string classNameParent, CodegenClassScope classScope, SelectExprProcessorForge forge) { var exprSymbol = new ExprForgeCodegenSymbol(true, null); var selectEnv = new SelectExprProcessorCodegenSymbol(); CodegenSymbolProvider symbolProvider = new ProxyCodegenSymbolProvider { ProcProvide = symbols => { exprSymbol.Provide(symbols); selectEnv.Provide(symbols); } }; IList<CodegenTypedParam> members = new List<CodegenTypedParam>(2); members.Add(new CodegenTypedParam(classScope.NamespaceScope.FieldsClassName, NAME_STATEMENT_FIELDS)); members.Add(new CodegenTypedParam(typeof(EventBeanTypedEventFactory), "factory")); IList<CodegenTypedParam> ctorParams = new List<CodegenTypedParam>(2); ctorParams.Add(new CodegenTypedParam(classNameParent, "o")); ctorParams.Add( new CodegenTypedParam( typeof(EPStatementInitServices), EPStatementInitServicesConstants.REF.Ref, false)); var ctor = new CodegenCtor(typeof(StmtClassForgableRSPFactoryProvider), classScope, ctorParams); ctor.Block.AssignRef( NAME_STATEMENT_FIELDS, ExprDotName(Ref("o"), NAME_STATEMENT_FIELDS)); ctor.Block.AssignRef( "factory", ExprDotName(EPStatementInitServicesConstants.REF, "EventBeanTypedEventFactory")); var processMethod = CodegenMethod.MakeMethod( typeof(EventBean), typeof(StmtClassForgableRSPFactoryProvider), symbolProvider, classScope) .AddParam(typeof(EventBean[]), NAME_EPS) .AddParam(typeof(bool), ExprForgeCodegenNames.NAME_ISNEWDATA) .AddParam(typeof(bool), SelectExprProcessorCodegenSymbol.NAME_ISSYNTHESIZE) .AddParam(typeof(ExprEvaluatorContext), NAME_EXPREVALCONTEXT); processMethod.Block.Apply( InstrumentationCode.Instblock( classScope, "qSelectClause", REF_EPS, ResultSetProcessorCodegenNames.REF_ISNEWDATA, REF_ISSYNTHESIZE, REF_EXPREVALCONTEXT)); var performMethod = forge.ProcessCodegen( Ref("o." + MEMBERNAME_RESULTEVENTTYPE), Ref("factory"), processMethod, selectEnv, exprSymbol, classScope); exprSymbol.DerivedSymbolsCodegen(processMethod, processMethod.Block, classScope); processMethod.Block .DeclareVar<EventBean>("@out", LocalMethod(performMethod)) .Apply( InstrumentationCode.Instblock( classScope, "aSelectClause", ResultSetProcessorCodegenNames.REF_ISNEWDATA, Ref("@out"), ConstantNull())) .MethodReturn(Ref("@out")); var allProperties = new CodegenClassProperties(); var allMethods = new CodegenClassMethods(); CodegenStackGenerator.RecursiveBuildStack( processMethod, "Process", allMethods, allProperties); return new CodegenInnerClass( className, typeof(SelectExprProcessor), ctor, members, allMethods, allProperties); }
public static CodegenExpression MakeAnonymous( SelectExprProcessorForge insertHelper, CodegenMethod method, CodegenExpressionRef initSvc, CodegenClassScope classScope) { var resultType = classScope.AddDefaultFieldUnshared( true, typeof(EventType), EventTypeUtility.ResolveTypeCodegen(insertHelper.ResultEventType, initSvc)); var eventBeanFactory = classScope.AddOrGetDefaultFieldSharable(EventBeanTypedEventFactoryCodegenField.INSTANCE); var exprSymbol = new ExprForgeCodegenSymbol(true, true); var selectEnv = new SelectExprProcessorCodegenSymbol(); CodegenSymbolProvider symbolProvider = new ProxyCodegenSymbolProvider { ProcProvide = symbols => { exprSymbol.Provide(symbols); selectEnv.Provide(symbols); } }; var processMethod = method .MakeChildWithScope(typeof(EventBean), typeof(SelectExprProcessorUtil), symbolProvider, classScope) .AddParam(typeof(EventBean[]), NAME_EPS) .AddParam(typeof(bool), ExprForgeCodegenNames.NAME_ISNEWDATA) .AddParam(typeof(bool), SelectExprProcessorCodegenSymbol.NAME_ISSYNTHESIZE) .AddParam(typeof(ExprEvaluatorContext), NAME_EXPREVALCONTEXT); //var anonymousSelect = NewAnonymousClass(method.Block, typeof(ProxySelectExprProcessor)); //var processMethod = CodegenMethod.MakeMethod( // typeof(EventBean), // typeof(SelectExprProcessorUtil), // symbolProvider, // classScope) // .AddParam(typeof(EventBean[]), NAME_EPS) // .AddParam(typeof(bool), ExprForgeCodegenNames.NAME_ISNEWDATA) // .AddParam(typeof(bool), SelectExprProcessorCodegenSymbol.NAME_ISSYNTHESIZE) // .AddParam(typeof(ExprEvaluatorContext), NAME_EXPREVALCONTEXT); //anonymousSelect.AddMethod("Process", processMethod); processMethod.Block.Apply( Instblock( classScope, "qSelectClause", REF_EPS, ResultSetProcessorCodegenNames.REF_ISNEWDATA, REF_ISSYNTHESIZE, REF_EXPREVALCONTEXT)); var performMethod = insertHelper.ProcessCodegen( resultType, eventBeanFactory, processMethod, selectEnv, exprSymbol, classScope); exprSymbol.DerivedSymbolsCodegen(method, processMethod.Block, classScope); //exprSymbol.DerivedSymbolsCodegen(processMethod, processMethod.Block, classScope); processMethod.Block .DeclareVar<EventBean>("result", LocalMethod(performMethod)) .Apply( Instblock( classScope, "aSelectClause", ResultSetProcessorCodegenNames.REF_ISNEWDATA, Ref("result"), ConstantNull())) .MethodReturn(Ref("result")); var processLambda = new CodegenExpressionLambda(method.Block) .WithParam(typeof(EventBean[]), NAME_EPS) .WithParam(typeof(bool), ExprForgeCodegenNames.NAME_ISNEWDATA) .WithParam(typeof(bool), SelectExprProcessorCodegenSymbol.NAME_ISSYNTHESIZE) .WithParam(typeof(ExprEvaluatorContext), NAME_EXPREVALCONTEXT) .WithBody( block => { block.DebugStack(); block.BlockReturn( LocalMethod( processMethod, ExprForgeCodegenNames.REF_EPS, ExprForgeCodegenNames.REF_ISNEWDATA, SelectExprProcessorCodegenSymbol.REF_ISSYNTHESIZE, ExprForgeCodegenNames.REF_EXPREVALCONTEXT)); }); var anonymousSelect = NewInstance<ProxySelectExprProcessor>(processLambda); return anonymousSelect; }
public static CodegenExpression CodegenEvaluatorMayMultiKeyWCoerce( IList<ExprForge> forges, IList<Type> optCoercionTypes, CodegenMethod method, Type generator, CodegenClassScope classScope) { if (forges.Count == 1) { return CodegenEvaluatorWCoerce( forges[0], optCoercionTypes?[0], method, generator, classScope); } var evaluate = new CodegenExpressionLambda(method.Block).WithParams(PARAMS); var evaluator = NewInstance<ProxyExprEvaluator>(evaluate); //var evaluator = NewAnonymousClass(method.Block, typeof(ExprEvaluator)); //var evaluate = CodegenMethod.MakeParentNode<object>(generator, classScope).AddParam(PARAMS); //evaluator.AddMethod("Evaluate", evaluate); var exprSymbol = new ExprForgeCodegenSymbol(true, null); var exprMethod = method.MakeChildWithScope( typeof(object), typeof(CodegenLegoMethodExpression), exprSymbol, classScope) .AddParam(PARAMS); var exprBlock = exprMethod.Block; var expressions = new CodegenExpression[forges.Count]; for (var i = 0; i < forges.Count; i++) { expressions[i] = forges[i].EvaluateCodegen( forges[i].EvaluationType, exprMethod, exprSymbol, classScope); } exprSymbol.DerivedSymbolsCodegen(exprMethod, exprBlock, classScope); exprBlock.DeclareVar<object[]>( "values", NewArrayByLength(typeof(object), Constant(forges.Count))) .DeclareVar<HashableMultiKey>("valuesMk", NewInstance<HashableMultiKey>(Ref("values"))); for (var i = 0; i < forges.Count; i++) { var result = expressions[i]; if (optCoercionTypes != null && forges[i].EvaluationType.GetBoxedType() != optCoercionTypes[i].GetBoxedType()) { var coercer = SimpleNumberCoercerFactory.GetCoercer( forges[i].EvaluationType, optCoercionTypes[i].GetBoxedType()); var name = "result_" + i; exprBlock.DeclareVar(forges[i].EvaluationType, name, expressions[i]); result = coercer.CoerceCodegen(Ref(name), forges[i].EvaluationType); } exprBlock.AssignArrayElement("values", Constant(i), result); } exprBlock.ReturnMethodOrBlock(Ref("valuesMk")); evaluate.Block.ReturnMethodOrBlock( LocalMethod(exprMethod, REF_EPS, REF_ISNEWDATA, REF_EXPREVALCONTEXT)); return evaluator; }
public static CodegenExpression CodegenEvaluatorReturnObjectOrArrayWCoerce( ExprForge[] forges, Type[] targetTypes, bool arrayMultikeyWhenSingleEvaluator, CodegenMethod method, Type generator, CodegenClassScope classScope) { var evaluate = new CodegenExpressionLambda(method.Block) .WithParams(PARAMS); var evaluator = NewInstance <ProxyExprEvaluator>(evaluate); // CodegenMethod evaluate = CodegenMethod // .MakeParentNode(typeof(object), generator, classScope) // .AddParam(ExprForgeCodegenNames.PARAMS); // evaluator.AddMethod("evaluate", evaluate); var exprSymbol = new ExprForgeCodegenSymbol(true, null); var exprMethod = method .MakeChildWithScope(typeof(object), typeof(CodegenLegoMethodExpression), exprSymbol, classScope) .AddParam(ExprForgeCodegenNames.PARAMS); var expressions = new CodegenExpression[forges.Length]; for (var i = 0; i < forges.Length; i++) { expressions[i] = forges[i].EvaluateCodegen(forges[i].EvaluationType, exprMethod, exprSymbol, classScope); } exprSymbol.DerivedSymbolsCodegen(method, exprMethod.Block, classScope); if (forges.Length == 0) { exprMethod.Block.MethodReturn(ConstantNull()); } else if (forges.Length == 1) { var evaluationType = forges[0].EvaluationType; CodegenExpression coerced; if (arrayMultikeyWhenSingleEvaluator && evaluationType.IsArray) { var clazz = MultiKeyPlanner.GetMKClassForComponentType(evaluationType.GetElementType()); coerced = NewInstance(clazz, expressions[0]); } else { coerced = ExprNodeUtilityCodegen.CodegenCoerce(expressions[0], evaluationType, targetTypes?[0], false); } exprMethod.Block.MethodReturn(coerced); } else { exprMethod.Block.DeclareVar <object[]>("values", NewArrayByLength(typeof(object), Constant(forges.Length))); for (var i = 0; i < forges.Length; i++) { var coerced = ExprNodeUtilityCodegen.CodegenCoerce( expressions[i], forges[i].EvaluationType, targetTypes?[i], false); exprMethod.Block.AssignArrayElement("values", Constant(i), coerced); } exprMethod.Block.MethodReturn(Ref("values")); } evaluate.Block.BlockReturn(LocalMethod(exprMethod, REF_EPS, REF_ISNEWDATA, REF_EXPREVALCONTEXT)); return(evaluator); }
private CodegenMethod MakeUpdateInternal( CodegenMethodScope scope, CodegenClassScope classScope) { var method = scope.MakeChildWithScope( typeof(void), GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(EventBean[]), NAME_EPS) .AddParam(typeof(ExprEvaluatorContext), NAME_EXPREVALCONTEXT) .AddParam(typeof(EventBean), "target"); var exprSymbol = new ExprForgeCodegenSymbol(true, true); var exprMethod = method.MakeChildWithScope( typeof(void), typeof(CodegenLegoMethodExpression), exprSymbol, classScope) .AddParam(PARAMS); var updateItems = UpdateItems; var types = new Type[updateItems.Length]; for (var i = 0; i < updateItems.Length; i++) { types[i] = updateItems[i].Expression.EvaluationType; } var forgeExpressions = new EventBeanUpdateItemForgeWExpressions[updateItems.Length]; for (var i = 0; i < updateItems.Length; i++) { var targetType = updateItems[i].IsUseUntypedAssignment ? typeof(object) : types[i]; forgeExpressions[i] = updateItems[i].ToExpression(targetType, exprMethod, exprSymbol, classScope); } exprSymbol.DerivedSymbolsCodegen(method, method.Block, classScope); method.Block.DeclareVar( _eventType.UnderlyingType, "und", Cast(_eventType.UnderlyingType, ExprDotUnderlying(Ref("target")))); for (var i = 0; i < updateItems.Length; i++) { var targetType = updateItems[i].IsUseUntypedAssignment ? typeof(object) : types[i]; var updateItem = updateItems[i]; var rhs = forgeExpressions[i].RhsExpression; if (updateItems[i].IsUseTriggeringEvent) { rhs = ArrayAtIndex(Ref(NAME_EPS), Constant(1)); } method.Block.Apply(Instblock(classScope, "qInfraUpdateRHSExpr", Constant(i))); if (types[i] == null && updateItem.OptionalWriter != null) { method.Block.Expression( updateItem.OptionalWriter.WriteCodegen( ConstantNull(), Ref("und"), Ref("target"), method, classScope)); continue; } if (types[i] == typeof(void) || (updateItem.OptionalWriter == null && updateItem.OptionalArray == null)) { method.Block .Expression(rhs) .Apply(Instblock(classScope, "aInfraUpdateRHSExpr", ConstantNull())); continue; } var @ref = Ref("r" + i); method.Block.DeclareVar(targetType, @ref.Ref, rhs); CodegenExpression assigned = @ref; var assignedType = types[i]; if (updateItem.OptionalWidener != null) { assigned = updateItem.OptionalWidener.WidenCodegen(@ref, method, classScope); assignedType = updateItem.OptionalWidener.WidenResultType; } if (updateItem.OptionalArray != null) { // handle array value with array index expression var index = Ref("i" + i); var array = Ref("a" + i); var arraySet = updateItem.OptionalArray; CodegenBlock arrayBlock; var elementType = arraySet.ArrayType.GetElementType(); var arrayOfPrimitiveNullRHS = elementType.IsPrimitive && (assignedType == null || assignedType.CanBeNull()); if (arrayOfPrimitiveNullRHS) { assigned = Unbox(assigned, assignedType); arrayBlock = method.Block .IfNull(@ref) .StaticMethod(typeof(EventBeanUpdateHelperForge), "LogWarnWhenNullAndNotNullable", Constant(updateItem.OptionalPropertyName)) .IfElse(); } else { arrayBlock = method.Block; } arrayBlock .DeclareVar<int?>(index.Ref, forgeExpressions[i].OptionalArrayExpressions.Index) .IfRefNotNull(index.Ref) .DeclareVar(arraySet.ArrayType, array.Ref, forgeExpressions[i].OptionalArrayExpressions.ArrayGet) .IfRefNotNull(array.Ref) .IfCondition(Relational(index, CodegenExpressionRelational.CodegenRelational.LT, ArrayLength(array))) .CommentFullLine("MakeUpdateInternal//AssignArrayElement") .AssignArrayElement(array, Cast<int>(index), assigned) .IfElse() .BlockThrow( NewInstance<EPException>( Concat( Constant("Array length "), ArrayLength(array), Constant(" less than index "), index, Constant(" for property '" + updateItems[i].OptionalArray.PropertyName + "'")))) .BlockEnd() .BlockEnd(); if (arrayOfPrimitiveNullRHS) { arrayBlock.BlockEnd(); } } else { if (types[i].CanBeNull() && updateItem.IsNotNullableField) { method.Block .IfNull(@ref) .StaticMethod( typeof(EventBeanUpdateHelperForge), "LogWarnWhenNullAndNotNullable", Constant(updateItem.OptionalPropertyName)) .IfElse() .Expression( updateItem.OptionalWriter.WriteCodegen( Unbox(assigned, assignedType), Ref("und"), Ref("target"), method, classScope)) .BlockEnd(); } else { method.Block.Expression( updateItem.OptionalWriter.WriteCodegen( assigned, Ref("und"), Ref("target"), method, classScope)); } } method.Block.Apply(Instblock(classScope, "aInfraUpdateRHSExpr", assigned)); } return method; }
public CodegenExpression EventBeanGetCodegen( CodegenExpression beanExpression, CodegenMethodScope parent, CodegenClassScope classScope) { var serializers = classScope.AddDefaultFieldUnshared( true, typeof(Serializer[]), StaticMethod( typeof(SerializerFactory), "GetSerializers", Constant(ExprNodeUtilityQuery.GetExprResultTypes(nodes)))); CodegenMethod method = parent.MakeChild(typeof(object), this.GetType(), classScope) .AddParam(typeof(EventBean), "eventBean"); method.Block .DeclareVar<EventBean[]>("events", NewArrayWithInit(typeof(EventBean), Ref("eventBean"))); // method to return object-array from expressions ExprForgeCodegenSymbol exprSymbol = new ExprForgeCodegenSymbol(true, null); CodegenMethod exprMethod = method .MakeChildWithScope(typeof(object), typeof(CodegenLegoMethodExpression), exprSymbol, classScope) .AddParam(ExprForgeCodegenNames.PARAMS); CodegenExpression[] expressions = new CodegenExpression[nodes.Length]; for (int i = 0; i < nodes.Length; i++) { expressions[i] = nodes[i] .Forge.EvaluateCodegen( nodes[i].Forge.EvaluationType, exprMethod, exprSymbol, classScope); } exprSymbol.DerivedSymbolsCodegen(method, exprMethod.Block, classScope); if (nodes.Length == 1) { exprMethod.Block.MethodReturn(expressions[0]); } else { exprMethod.Block.DeclareVar<object[]>( "values", NewArrayByLength(typeof(object), Constant(nodes.Length))); for (int i = 0; i < nodes.Length; i++) { CodegenExpression result = expressions[i]; exprMethod.Block.AssignArrayElement("values", Constant(i), result); } exprMethod.Block.MethodReturn(Ref("values")); } method.Block .DeclareVar<object>( "values", LocalMethod(exprMethod, Ref("events"), ConstantTrue(), ConstantNull())) .MethodReturn( StaticMethod( typeof(ContextControllerHashedGetterCRC32SerializedForge), "SerializeAndCRC32Hash", Ref("values"), Constant(granularity), serializers)); return LocalMethod(method, beanExpression); }