public CodegenMethod AddMethodWithSymbols( Type returnType, string methodName, IList<CodegenNamedParam> @params, Type generator, CodegenClassScope classScope, Consumer<CodegenMethod> code, CodegenSymbolProvider symbolProvider) { if (_methods == null) { _methods = new Dictionary<string, CodegenMethod>(); } var existing = _methods.Get(methodName); if (existing != null) { if (ListExtensions.AreEqual(@params, existing.LocalParams)) { return existing; } throw new IllegalStateException("Method by name '" + methodName + "' already registered"); } var method = CodegenMethod .MakeMethod(returnType, generator, symbolProvider, classScope) .AddParam(@params); method.Block.DebugStack(); _methods.Put(methodName, method); code.Invoke(method); return method; }
private static void MakeFactory( OrderByProcessorFactoryForge forge, CodegenClassScope classScope, IList<CodegenInnerClass> innerClasses, string providerClassName) { var instantiateMethod = CodegenMethod .MakeMethod( typeof(OrderByProcessor), typeof(OrderByProcessorCompiler), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(AgentInstanceContext), MEMBER_AGENTINSTANCECONTEXT.Ref); forge.InstantiateCodegen(instantiateMethod, classScope); var ctorParams = Collections.SingletonList(new CodegenTypedParam(providerClassName, "o")); var ctor = new CodegenCtor(typeof(OrderByProcessorCompiler), classScope, ctorParams); var methods = new CodegenClassMethods(); var properties = new CodegenClassProperties(); // -------------------------------------------------------------------------------- // Add statementFields // -------------------------------------------------------------------------------- var members = new List<CodegenTypedParam> { new CodegenTypedParam( classScope.NamespaceScope.FieldsClassName, null, "statementFields", false, false) }; ctor.Block.AssignRef( Ref("this.statementFields"), Ref("o.statementFields")); // -------------------------------------------------------------------------------- CodegenStackGenerator.RecursiveBuildStack(instantiateMethod, "Instantiate", methods, properties); var innerClass = new CodegenInnerClass( CLASSNAME_ORDERBYPROCESSORFACTORY, typeof(OrderByProcessorFactory), ctor, members, methods, properties); innerClasses.Add(innerClass); }
private static void MakeResultSetProcessorFactory( CodegenClassScope classScope, IList<CodegenInnerClass> innerClasses, IList<CodegenTypedParam> providerExplicitMembers, CodegenCtor providerCtor, string providerClassName) { var instantiateMethod = CodegenMethod.MakeMethod( typeof(ResultSetProcessor), typeof(StmtClassForgableRSPFactoryProvider), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(OrderByProcessor), NAME_ORDERBYPROCESSOR) .AddParam(typeof(AggregationService), NAME_AGGREGATIONSVC) .AddParam(typeof(AgentInstanceContext), NAME_AGENTINSTANCECONTEXT); instantiateMethod.Block.MethodReturn( NewInstance( CLASSNAME_RESULTSETPROCESSOR, Ref("o"), REF_ORDERBYPROCESSOR, REF_AGGREGATIONSVC, REF_AGENTINSTANCECONTEXT)); var properties = new CodegenClassProperties(); var methods = new CodegenClassMethods(); CodegenStackGenerator.RecursiveBuildStack(instantiateMethod, "Instantiate", methods, properties); var ctorParams = Collections.SingletonList(new CodegenTypedParam(providerClassName, "o")); var ctor = new CodegenCtor( typeof(StmtClassForgableRSPFactoryProvider), classScope, ctorParams); var innerClass = new CodegenInnerClass( CLASSNAME_RESULTSETPROCESSORFACTORY, typeof(ResultSetProcessorFactory), ctor, Collections.GetEmptyList<CodegenTypedParam>(), methods, properties); innerClasses.Add(innerClass); providerExplicitMembers.Add(new CodegenTypedParam(typeof(ResultSetProcessorFactory), "rspFactory")); providerCtor.Block.AssignRef( MEMBERNAME_RESULTSETPROCESSORFACTORY, NewInstance(CLASSNAME_RESULTSETPROCESSORFACTORY, Ref("this"))); }
private CodegenMethod MakeInitialize(CodegenClassScope classScope) { var method = CodegenMethod .MakeMethod(typeof(void), typeof(StmtClassForgeableStmtProvider), classScope) .AddParam(typeof(EPStatementInitServices), REF_STMTINITSVC.Ref); if (_namespaceScope.FieldsClassName != null) { method.Block.AssignRef( MEMBERNAME_STATEMENT_FIELDS, NewInstanceInner(_namespaceScope.FieldsClassName)); } method.Block.AssignMember( MEMBERNAME_FACTORY_PROVIDER, NewInstanceInner(_statementAiFactoryClassName, REF_STMTINITSVC, Ref(MEMBERNAME_STATEMENT_FIELDS))); return method; }
private static void MakeOPVFactory( CodegenClassScope classScope, ICollection<CodegenInnerClass> innerClasses, ICollection<CodegenTypedParam> providerExplicitMembers, CodegenCtor providerCtor, string providerClassName) { var makeViewMethod = CodegenMethod.MakeMethod( typeof(OutputProcessView), typeof(StmtClassForgableOPVFactoryProvider), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(ResultSetProcessor), NAME_RESULTSETPROCESSOR) .AddParam(typeof(AgentInstanceContext), NAME_AGENTINSTANCECONTEXT); makeViewMethod.Block.MethodReturn( NewInstance(CLASSNAME_OUTPUTPROCESSVIEW, Ref("o"), REF_RESULTSETPROCESSOR, REF_AGENTINSTANCECONTEXT)); var methods = new CodegenClassMethods(); var properties = new CodegenClassProperties(); CodegenStackGenerator.RecursiveBuildStack(makeViewMethod, "MakeView", methods, properties); var ctorParams = Collections.SingletonList(new CodegenTypedParam(providerClassName, "o")); var ctor = new CodegenCtor(typeof(StmtClassForgableOPVFactoryProvider), classScope, ctorParams); var innerClass = new CodegenInnerClass( CLASSNAME_OUTPUTPROCESSVIEWFACTORY, typeof(OutputProcessViewFactory), ctor, Collections.GetEmptyList<CodegenTypedParam>(), methods, properties); innerClasses.Add(innerClass); providerCtor.Block.AssignRef( MEMBERNAME_OPVFACTORY, NewInstance(CLASSNAME_OUTPUTPROCESSVIEWFACTORY, Ref("this"))) .AssignRef( MEMBERNAME_STATEMENTRESULTSVC, ExprDotName( EPStatementInitServicesConstants.REF, EPStatementInitServicesConstants.STATEMENTRESULTSERVICE)); }
public static void MakeSetter( string className, string memberName, IList<CodegenTypedParam> members, CodegenClassMethods methods, CodegenClassScope classScope, CodegenClassProperties properties) { members.Add(new CodegenTypedParam(className, memberName)); var method = CodegenMethod.MakeMethod( typeof(void), typeof(CodegenStackGenerator), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(className, "p"); method.Block.AssignRef(memberName, Ref("p")); var setterMethodName = "Set" + memberName.Substring(0, 1).ToUpperInvariant() + memberName.Substring(1); RecursiveBuildStack(method, setterMethodName, methods, properties); }
internal static CodegenMethod MakeInitEventTypes( CodegenClassScope classScope, ModuleCompileTimeServices compileTimeServices) { var symbolsEventTypeInit = new ModuleEventTypeInitializeSymbol(); var initializeEventTypesMethod = CodegenMethod .MakeMethod(typeof(void), typeof(EPCompilerImpl), symbolsEventTypeInit, classScope) .AddParam( typeof(EPModuleEventTypeInitServices), ModuleEventTypeInitializeSymbol.REF_INITSVC.Ref); foreach (var eventType in compileTimeServices.EventTypeCompileTimeRegistry.NewTypesAdded) { var addType = RegisterEventTypeCodegen( eventType, initializeEventTypesMethod, classScope, symbolsEventTypeInit); initializeEventTypesMethod.Block.Expression(LocalMethod(addType)); } return initializeEventTypesMethod; }
private static void MakeService( OrderByProcessorFactoryForge forge, CodegenClassScope classScope, IList<CodegenInnerClass> innerClasses, string providerClassName) { var namedMethods = new CodegenNamedMethods(); var sortPlainMethod = CodegenMethod.MakeMethod( typeof(EventBean[]), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(SORTPLAIN_PARAMS); forge.SortPlainCodegen(sortPlainMethod, classScope, namedMethods); var sortWGroupKeysMethod = CodegenMethod.MakeMethod( typeof(EventBean[]), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(SORTWGROUPKEYS_PARAMS); forge.SortWGroupKeysCodegen(sortWGroupKeysMethod, classScope, namedMethods); var sortRollupMethod = CodegenMethod.MakeMethod( typeof(EventBean[]), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(SORTROLLUP_PARAMS); forge.SortRollupCodegen(sortRollupMethod, classScope, namedMethods); var getSortKeyMethod = CodegenMethod .MakeMethod(typeof(object), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(EventBean[]), REF_EPS.Ref) .AddParam(typeof(bool), ExprForgeCodegenNames.REF_ISNEWDATA.Ref) .AddParam( typeof(ExprEvaluatorContext), REF_EXPREVALCONTEXT.Ref); forge.GetSortKeyCodegen(getSortKeyMethod, classScope, namedMethods); var getSortKeyRollupMethod = CodegenMethod .MakeMethod(typeof(object), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(EventBean[]), REF_EPS.Ref) .AddParam(typeof(bool), ExprForgeCodegenNames.REF_ISNEWDATA.Ref) .AddParam(typeof(ExprEvaluatorContext), REF_EXPREVALCONTEXT.Ref) .AddParam( typeof(AggregationGroupByRollupLevel), REF_ORDERROLLUPLEVEL.Ref); forge.GetSortKeyRollupCodegen(getSortKeyRollupMethod, classScope, namedMethods); var sortWOrderKeysMethod = CodegenMethod .MakeMethod(typeof(EventBean[]), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(EventBean[]), REF_OUTGOINGEVENTS.Ref) .AddParam(typeof(object[]), REF_ORDERKEYS.Ref) .AddParam(typeof(ExprEvaluatorContext), REF_EXPREVALCONTEXT.Ref); forge.SortWOrderKeysCodegen(sortWOrderKeysMethod, classScope, namedMethods); var sortTwoKeysMethod = CodegenMethod.MakeMethod( typeof(EventBean[]), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(SORTTWOKEYS_PARAMS); forge.SortTwoKeysCodegen(sortTwoKeysMethod, classScope, namedMethods); IList<CodegenTypedParam> members = new List<CodegenTypedParam>(); IList<CodegenTypedParam> ctorParams = new List<CodegenTypedParam>(); ctorParams.Add(new CodegenTypedParam(providerClassName, "o")); var ctor = new CodegenCtor(typeof(OrderByProcessorCompiler), classScope, ctorParams); // -------------------------------------------------------------------------------- // Add statementFields // -------------------------------------------------------------------------------- members.Add( new CodegenTypedParam( classScope.NamespaceScope.FieldsClassName, null, "statementFields", false, false)); ctor.Block.AssignRef( Ref("this.statementFields"), Ref("o.statementFields")); // -------------------------------------------------------------------------------- forge.CtorCodegen(ctor, members, classScope); CodegenClassProperties innerProperties = new CodegenClassProperties(); var innerMethods = new CodegenClassMethods(); CodegenStackGenerator.RecursiveBuildStack(sortPlainMethod, "SortPlain", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack(sortWGroupKeysMethod, "SortWGroupKeys", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack(sortRollupMethod, "SortRollup", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack(getSortKeyMethod, "GetSortKey", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack(getSortKeyRollupMethod, "GetSortKeyRollup", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack(sortWOrderKeysMethod, "SortWOrderKeys", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack(sortTwoKeysMethod, "SortTwoKeys", innerMethods, innerProperties); foreach (var methodEntry in namedMethods.Methods) { CodegenStackGenerator.RecursiveBuildStack(methodEntry.Value, methodEntry.Key, innerMethods, innerProperties); } var innerClass = new CodegenInnerClass( CLASSNAME_ORDERBYPROCESSOR, typeof(OrderByProcessor), ctor, members, innerMethods, innerProperties); innerClasses.Add(innerClass); }
public CodegenClass Forge(bool includeDebugSymbols) { var classScope = new CodegenClassScope(includeDebugSymbols, _namespaceScope, _className); // REGION: Constructor var ctorParams = new List<CodegenTypedParam>() { new CodegenTypedParam( typeof(EPStatementInitServices), EPStatementInitServicesConstants.REF.Ref, false) }; if (_namespaceScope.FieldsClassName != null) { ctorParams.Add( new CodegenTypedParam( _namespaceScope.FieldsClassName, MEMBERNAME_STATEMENT_FIELDS)); } var ctor = new CodegenCtor(GetType(), _className, includeDebugSymbols, ctorParams); ctor.Block.AssignRef( MEMBERNAME_ID, StaticMethod(typeof(Guid), "NewGuid")); if (_namespaceScope.FieldsClassName != null) { ctor.Block.ExprDotMethod( Ref(MEMBERNAME_STATEMENT_FIELDS), "Init", EPStatementInitServicesConstants.REF); } ctor.Block.AssignRef( MEMBERNAME_STATEMENTAIFACTORY, LocalMethod( CodegenConstructorInit(ctor, classScope), SAIFFInitializeSymbol.REF_STMTINITSVC)); // REGION: Members var members = new List<CodegenTypedParam>(); members.Add(new CodegenTypedParam(typeof(Guid), MEMBERNAME_ID)); members.Add(new CodegenTypedParam(TypeOfFactory(), MEMBERNAME_STATEMENTAIFACTORY)); // REGION: Properties var properties = new CodegenClassProperties(); var factoryProp = CodegenProperty.MakePropertyNode( typeof(StatementAgentInstanceFactory), GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope); factoryProp.GetterBlock.BlockReturn(Ref(MEMBERNAME_STATEMENTAIFACTORY)); // REGION: Methods var methods = new CodegenClassMethods(); var assignMethod = CodegenMethod .MakeMethod(typeof(void), GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(StatementAIFactoryAssignments), "assignments"); if (_namespaceScope.FieldsClassName != null) { assignMethod.Block.ExprDotMethod(Ref(MEMBERNAME_STATEMENT_FIELDS), "Assign", Ref("assignments")); //assignMethod.Block.StaticMethod(_namespaceScope.FieldsClassNameOptional, "Assign", @Ref("assignments")); } var unassignMethod = CodegenMethod .MakeMethod(typeof(void), GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope); if (_namespaceScope.FieldsClassName != null) { unassignMethod.Block.ExprDotMethod(Ref(MEMBERNAME_STATEMENT_FIELDS), "Unassign"); //unassignMethod.Block.StaticMethod(_namespaceScope.FieldsClassNameOptional, "Unassign"); } var setValueMethod = CodegenMethod .MakeMethod(typeof(void), typeof(StmtClassForgableStmtFields), classScope) .AddParam(typeof(int), "index") .AddParam(typeof(object), "value"); CodegenSubstitutionParamEntry.CodegenSetterBody( classScope, setValueMethod.Block, Ref(MEMBERNAME_STATEMENT_FIELDS)); // Assignment, not sure why this is being done... TBD - Burn this CodegenStackGenerator.RecursiveBuildStack(factoryProp, "Factory", methods, properties); CodegenStackGenerator.RecursiveBuildStack(assignMethod, "Assign", methods, properties); CodegenStackGenerator.RecursiveBuildStack(unassignMethod, "Unassign", methods, properties); CodegenStackGenerator.RecursiveBuildStack(setValueMethod, "SetValue", methods, properties); CodegenStackGenerator.RecursiveBuildStack(ctor, "Ctor", methods, properties); return new CodegenClass( typeof(StatementAIFactoryProvider), _namespaceScope.Namespace, _className, classScope, members, ctor, methods, properties, new EmptyList<CodegenInnerClass>()); }
public CodegenClass Forge(bool includeDebugSymbols) { // members IList<CodegenTypedParam> members = new List<CodegenTypedParam>(); // Add a reference to "self" members.Add(new CodegenTypedParam(_className, null, "statementFields", false, false)); GenerateNamedMembers(members); // numbered members foreach (var entry in _namespaceScope.FieldsUnshared) { var field = entry.Key; members.Add( new CodegenTypedParam(field.Type, field.Name) .WithStatic(false) .WithFinal(false)); } // substitution-parameter members GenerateSubstitutionParamMembers(members); var classScope = new CodegenClassScope(includeDebugSymbols, _namespaceScope, ClassName); // ctor var ctor = new CodegenCtor(GetType(), ClassName, includeDebugSymbols, Collections.GetEmptyList<CodegenTypedParam>()); ctor.Block.AssignRef(Ref("statementFields"), Ref("this")); //_namespaceScope var initMethod = _namespaceScope.InitMethod; foreach (var entry in _namespaceScope.FieldsUnshared) { initMethod.Block.AssignRef(entry.Key.Name, entry.Value); } // assignment methods CodegenMethod assignMethod = CodegenMethod .MakeMethod(typeof(void), GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(StatementAIFactoryAssignments), "assignments") .WithStatic(false); CodegenMethod unassignMethod = CodegenMethod .MakeMethod(typeof(void), GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .WithStatic(false); GenerateAssignAndUnassign(_numStreams, assignMethod, unassignMethod, _namespaceScope.FieldsNamed); // build methods var methods = new CodegenClassMethods(); var properties = new CodegenClassProperties(); CodegenStackGenerator.RecursiveBuildStack(initMethod, "Init", methods, properties); CodegenStackGenerator.RecursiveBuildStack(assignMethod, "Assign", methods, properties); CodegenStackGenerator.RecursiveBuildStack(unassignMethod, "Unassign", methods, properties); return new CodegenClass( typeof(StatementFields), _namespaceScope.Namespace, ClassName, classScope, members, ctor, methods, properties, Collections.GetEmptyList<CodegenInnerClass>()); }
private static void MakeOPV( CodegenClassScope classScope, IList<CodegenInnerClass> innerClasses, IList<CodegenTypedParam> factoryExplicitMembers, CodegenCtor factoryCtor, string classNameParent, OutputProcessViewFactoryForge forge, int numStreams) { IList<CodegenTypedParam> ctorParams = new List<CodegenTypedParam>(); ctorParams.Add(new CodegenTypedParam(classNameParent, "o")); ctorParams.Add(new CodegenTypedParam(typeof(ResultSetProcessor), NAME_RESULTSETPROCESSOR)); ctorParams.Add(new CodegenTypedParam(typeof(AgentInstanceContext), NAME_AGENTINSTANCECONTEXT)); // make ctor code var serviceCtor = new CodegenCtor(typeof(StmtClassForgableOPVFactoryProvider), classScope, ctorParams); // Get-Result-Type Method var eventTypeGetter = CodegenProperty .MakePropertyNode(typeof(EventType), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .WithOverride(); eventTypeGetter.GetterBlock.BlockReturn(ExprDotName(Ref(NAME_RESULTSETPROCESSOR), "ResultEventType")); // Process-View-Result Method var updateMethod = CodegenMethod .MakeMethod(typeof(void), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .WithOverride() .AddParam(typeof(EventBean[]), NAME_NEWDATA) .AddParam(typeof(EventBean[]), NAME_OLDDATA); if (numStreams == 1) { forge.UpdateCodegen(updateMethod, classScope); } else { updateMethod.Block.MethodThrowUnsupported(); } // Process-Join-Result Method var processMethod = CodegenMethod .MakeMethod(typeof(void), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .WithOverride() .AddParam(typeof(ISet<MultiKey<EventBean>>), NAME_NEWDATA) .AddParam(typeof(ISet<MultiKey<EventBean>>), NAME_OLDDATA) .AddParam( typeof(ExprEvaluatorContext), "notApplicable"); if (numStreams == 1) { processMethod.Block.MethodThrowUnsupported(); } else { forge.ProcessCodegen(processMethod, classScope); } // Stop-Method (generates last as other methods may allocate members) var enumeratorMethod = CodegenMethod .MakeMethod( typeof(IEnumerator<EventBean>), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .WithOverride(); forge.EnumeratorCodegen(enumeratorMethod, classScope); // NumChangesetRows (always zero for generated code) var numChangesetRowsProp = CodegenProperty .MakePropertyNode(typeof(int), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .WithOverride(); numChangesetRowsProp.GetterBlock.BlockReturn(Constant(0)); // OptionalOutputCondition (always null for generated code) var optionalOutputConditionProp = CodegenProperty .MakePropertyNode(typeof(OutputCondition), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .WithOverride(); optionalOutputConditionProp.GetterBlock.BlockReturn(ConstantNull()); // Stop-Method (no action for generated code) CodegenMethod stopMethod = CodegenMethod .MakeMethod(typeof(void), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .WithOverride() .AddParam(typeof(AgentInstanceStopServices), "svc"); // Terminate-Method (no action for generated code) CodegenMethod terminatedMethod = CodegenMethod .MakeMethod(typeof(void), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .WithOverride(); var innerProperties = new CodegenClassProperties(); var innerMethods = new CodegenClassMethods(); CodegenStackGenerator.RecursiveBuildStack( eventTypeGetter, "EventType", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( updateMethod, "Update", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( processMethod, "Process", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( enumeratorMethod, "GetEnumerator", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( numChangesetRowsProp, "NumChangesetRows", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( optionalOutputConditionProp, "OptionalOutputCondition", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( stopMethod, "Stop", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( terminatedMethod, "Terminated", innerMethods, innerProperties); var innerClass = new CodegenInnerClass( CLASSNAME_OUTPUTPROCESSVIEW, typeof(OutputProcessView), serviceCtor, Collections.GetEmptyList<CodegenTypedParam>(), innerMethods, innerProperties); innerClasses.Add(innerClass); }
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); }
private static void MakeResultSetProcessor( CodegenClassScope classScope, IList<CodegenInnerClass> innerClasses, IList<CodegenTypedParam> factoryExplicitMembers, CodegenCtor factoryCtor, string classNameParent, ResultSetProcessorDesc spec) { IList<CodegenTypedParam> ctorParams = new List<CodegenTypedParam>(); ctorParams.Add(new CodegenTypedParam(classNameParent, "o")); ctorParams.Add(new CodegenTypedParam(typeof(OrderByProcessor), "orderByProcessor")); ctorParams.Add(new CodegenTypedParam(typeof(AggregationService), "aggregationService")); ctorParams.Add(new CodegenTypedParam(typeof(AgentInstanceContext), "agentInstanceContext")); // make ctor code var serviceCtor = new CodegenCtor( typeof(StmtClassForgableRSPFactoryProvider), classScope, ctorParams); // Get-Result-Type Method var forge = spec.ResultSetProcessorFactoryForge; var resultEventTypeGetter = CodegenProperty.MakePropertyNode( typeof(EventType), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope); resultEventTypeGetter.GetterBlock.BlockReturn(Ref("o." + MEMBERNAME_RESULTEVENTTYPE)); // Instance members and methods var instance = new CodegenInstanceAux(serviceCtor); // -------------------------------------------------------------------------------- // Add statementFields // -------------------------------------------------------------------------------- instance.Members.Add( new CodegenTypedParam( classScope.NamespaceScope.FieldsClassName, null, "statementFields", false, false)); serviceCtor.Block.AssignRef( Ref("this.statementFields"), Ref("o.statementFields")); // -------------------------------------------------------------------------------- forge.InstanceCodegen(instance, classScope, factoryCtor, factoryExplicitMembers); // Process-View-Result Method var processViewResultMethod = CodegenMethod.MakeMethod( typeof(UniformPair<EventBean[]>), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(EventBean[]), NAME_NEWDATA) .AddParam(typeof(EventBean[]), NAME_OLDDATA) .AddParam(typeof(bool), NAME_ISSYNTHESIZE); if (!spec.IsJoin) { GenerateInstrumentedProcessView(forge, classScope, processViewResultMethod, instance); } else { processViewResultMethod.Block.MethodThrowUnsupported(); } // Process-Join-Result Method var processJoinResultMethod = CodegenMethod .MakeMethod( typeof(UniformPair<EventBean[]>), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(ISet<MultiKey<EventBean>>), NAME_NEWDATA) .AddParam(typeof(ISet<MultiKey<EventBean>>), NAME_OLDDATA) .AddParam(typeof(bool), NAME_ISSYNTHESIZE); processJoinResultMethod.Block.DebugStack(); if (!spec.IsJoin) { processJoinResultMethod.Block.MethodThrowUnsupported(); } else { GenerateInstrumentedProcessJoin(forge, classScope, processJoinResultMethod, instance); } // Clear-Method var clearMethod = CodegenMethod .MakeMethod(typeof(void), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope); forge.ClearMethodCodegen(classScope, clearMethod); // Get-Enumerator-View var getEnumeratorMethodView = CodegenMethod .MakeMethod( typeof(IEnumerator<EventBean>), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(Viewable), NAME_VIEWABLE); if (!spec.IsJoin) { forge.GetEnumeratorViewCodegen(classScope, getEnumeratorMethodView, instance); } else { getEnumeratorMethodView.Block.MethodThrowUnsupported(); } // Get-Enumerator-Join var getEnumeratorMethodJoin = CodegenMethod .MakeMethod( typeof(IEnumerator<EventBean>), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(ISet<MultiKey<EventBean>>), NAME_JOINSET); if (!spec.IsJoin) { getEnumeratorMethodJoin.Block.MethodThrowUnsupported(); } else { forge.GetEnumeratorJoinCodegen(classScope, getEnumeratorMethodJoin, instance); } // Process-output-rate-buffered-view var processOutputLimitedViewMethod = CodegenMethod .MakeMethod( typeof(UniformPair<EventBean[]>), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(IList<UniformPair<EventBean[]>>), NAME_VIEWEVENTSLIST) .AddParam(typeof(bool), NAME_ISSYNTHESIZE); if (!spec.IsJoin && spec.HasOutputLimit && !spec.HasOutputLimitSnapshot) { forge.ProcessOutputLimitedViewCodegen(classScope, processOutputLimitedViewMethod, instance); } else { processOutputLimitedViewMethod.Block.MethodThrowUnsupported(); } // Process-output-rate-buffered-join var processOutputLimitedJoinMethod = CodegenMethod .MakeMethod( typeof(UniformPair<EventBean[]>), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(IList<UniformPair<ISet<MultiKey<EventBean>>>>), NAME_JOINEVENTSSET) .AddParam(typeof(bool), NAME_ISSYNTHESIZE); if (!spec.IsJoin || !spec.HasOutputLimit || spec.HasOutputLimitSnapshot) { processOutputLimitedJoinMethod.Block.MethodThrowUnsupported(); } else { forge.ProcessOutputLimitedJoinCodegen(classScope, processOutputLimitedJoinMethod, instance); } // Set-Agent-Instance is supported for fire-and-forget queries only var setAgentInstanceContextMethod = CodegenMethod .MakeMethod(typeof(void), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(AgentInstanceContext), "value"); setAgentInstanceContextMethod.Block.AssignRef(NAME_AGENTINSTANCECONTEXT, Ref("value")); // Apply-view var applyViewResultMethod = CodegenMethod .MakeMethod(typeof(void), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(EventBean[]), NAME_NEWDATA) .AddParam(typeof(EventBean[]), NAME_OLDDATA); if (!spec.IsJoin && spec.HasOutputLimit && spec.HasOutputLimitSnapshot) { forge.ApplyViewResultCodegen(classScope, applyViewResultMethod, instance); } else { applyViewResultMethod.Block.MethodThrowUnsupported(); } // Apply-join var applyJoinResultMethod = CodegenMethod .MakeMethod(typeof(void), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(ISet<MultiKey<EventBean>>), NAME_NEWDATA) .AddParam(typeof(ISet<MultiKey<EventBean>>), NAME_OLDDATA); if (!spec.IsJoin || !spec.HasOutputLimit || !spec.HasOutputLimitSnapshot) { applyJoinResultMethod.Block.MethodThrowUnsupported(); } else { forge.ApplyJoinResultCodegen(classScope, applyJoinResultMethod, instance); } // Process-output-unbuffered-view var processOutputLimitedLastAllNonBufferedViewMethod = CodegenMethod .MakeMethod(typeof(void), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(EventBean[]), NAME_NEWDATA) .AddParam(typeof(EventBean[]), NAME_OLDDATA) .AddParam(typeof(bool), NAME_ISSYNTHESIZE); if (!spec.IsJoin && spec.HasOutputLimit && spec.OutputConditionType == POLICY_LASTALL_UNORDERED) { forge.ProcessOutputLimitedLastAllNonBufferedViewCodegen( classScope, processOutputLimitedLastAllNonBufferedViewMethod, instance); } else { processOutputLimitedLastAllNonBufferedViewMethod.Block.MethodThrowUnsupported(); } // Process-output-unbuffered-join var processOutputLimitedLastAllNonBufferedJoinMethod = CodegenMethod .MakeMethod(typeof(void), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(ISet<MultiKey<EventBean>>), NAME_NEWDATA) .AddParam(typeof(ISet<MultiKey<EventBean>>), NAME_OLDDATA) .AddParam(typeof(bool), NAME_ISSYNTHESIZE); if (!spec.IsJoin || !spec.HasOutputLimit || spec.OutputConditionType != POLICY_LASTALL_UNORDERED) { processOutputLimitedLastAllNonBufferedJoinMethod.Block.MethodThrowUnsupported(); } else { forge.ProcessOutputLimitedLastAllNonBufferedJoinCodegen( classScope, processOutputLimitedLastAllNonBufferedJoinMethod, instance); } // Continue-output-unbuffered-view var continueOutputLimitedLastAllNonBufferedViewMethod = CodegenMethod .MakeMethod( typeof(UniformPair<EventBean[]>), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(bool), NAME_ISSYNTHESIZE); if (!spec.IsJoin && spec.HasOutputLimit && spec.OutputConditionType == POLICY_LASTALL_UNORDERED) { forge.ContinueOutputLimitedLastAllNonBufferedViewCodegen( classScope, continueOutputLimitedLastAllNonBufferedViewMethod, instance); } else { continueOutputLimitedLastAllNonBufferedViewMethod.Block.MethodThrowUnsupported(); } // Continue-output-unbuffered-join var continueOutputLimitedLastAllNonBufferedJoinMethod = CodegenMethod .MakeMethod( typeof(UniformPair<EventBean[]>), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(bool), NAME_ISSYNTHESIZE); if (!spec.IsJoin || !spec.HasOutputLimit || spec.OutputConditionType != POLICY_LASTALL_UNORDERED) { continueOutputLimitedLastAllNonBufferedJoinMethod.Block.MethodThrowUnsupported(); } else { forge.ContinueOutputLimitedLastAllNonBufferedJoinCodegen( classScope, continueOutputLimitedLastAllNonBufferedJoinMethod, instance); } // Accept-Helper-Visitor var acceptHelperVisitorMethod = CodegenMethod .MakeMethod(typeof(void), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam(typeof(ResultSetProcessorOutputHelperVisitor), NAME_RESULTSETVISITOR); forge.AcceptHelperVisitorCodegen(classScope, acceptHelperVisitorMethod, instance); // Stop-Method (generates last as other methods may allocate members) var stopMethod = CodegenMethod.MakeMethod( typeof(void), forge.GetType(), CodegenSymbolProviderEmpty.INSTANCE, classScope); forge.StopMethodCodegen(classScope, stopMethod, instance); var innerProperties = new CodegenClassProperties(); var innerMethods = new CodegenClassMethods(); CodegenStackGenerator.RecursiveBuildStack( resultEventTypeGetter, "ResultEventType", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( processViewResultMethod, "ProcessViewResult", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( processJoinResultMethod, "ProcessJoinResult", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( getEnumeratorMethodView, "GetEnumerator", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( getEnumeratorMethodJoin, "GetEnumerator", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( clearMethod, "Clear", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( stopMethod, "Stop", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( processOutputLimitedJoinMethod, "ProcessOutputLimitedJoin", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( processOutputLimitedViewMethod, "ProcessOutputLimitedView", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( setAgentInstanceContextMethod, "SetAgentInstanceContext", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( applyViewResultMethod, "ApplyViewResult", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( applyJoinResultMethod, "ApplyJoinResult", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( processOutputLimitedLastAllNonBufferedViewMethod, "ProcessOutputLimitedLastAllNonBufferedView", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( processOutputLimitedLastAllNonBufferedJoinMethod, "ProcessOutputLimitedLastAllNonBufferedJoin", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( continueOutputLimitedLastAllNonBufferedViewMethod, "ContinueOutputLimitedLastAllNonBufferedView", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( continueOutputLimitedLastAllNonBufferedJoinMethod, "ContinueOutputLimitedLastAllNonBufferedJoin", innerMethods, innerProperties); CodegenStackGenerator.RecursiveBuildStack( acceptHelperVisitorMethod, "AcceptHelperVisitor", innerMethods, innerProperties); foreach (var propertyEntry in instance.Properties.Properties) { CodegenStackGenerator.RecursiveBuildStack( propertyEntry.Value, propertyEntry.Key, innerMethods, innerProperties); } foreach (var methodEntry in instance.Methods.Methods) { CodegenStackGenerator.RecursiveBuildStack( methodEntry.Value, methodEntry.Key, innerMethods, innerProperties); } var innerClass = new CodegenInnerClass( CLASSNAME_RESULTSETPROCESSOR, forge.InterfaceClass, serviceCtor, instance.Members, innerMethods, innerProperties); innerClasses.Add(innerClass); }
private static string MakeFAFProvider( string queryMethodProviderClassName, string classPostfix, ModuleCompileTimeServices compileTimeServices, out Assembly assembly) { var statementFieldsClassName = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(StatementFields), classPostfix); var namespaceScope = new CodegenNamespaceScope( compileTimeServices.Namespace, statementFieldsClassName, compileTimeServices.IsInstrumented()); var fafProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple(typeof(FAFProvider), classPostfix); var classScope = new CodegenClassScope(true, namespaceScope, fafProviderClassName); var methods = new CodegenClassMethods(); var properties = new CodegenClassProperties(); // -------------------------------------------------------------------------------- // Add statementFields // -------------------------------------------------------------------------------- var ctor = new CodegenCtor( typeof(CompilerHelperFAFProvider), classScope, new List<CodegenTypedParam>()); ctor.Block.AssignRef(Ref("statementFields"), NewInstanceInner(statementFieldsClassName)); // initialize-event-types var initializeEventTypesMethod = MakeInitEventTypes(classScope, compileTimeServices); // initialize-query var initializeQueryMethod = CodegenMethod .MakeMethod( typeof(void), typeof(EPCompilerImpl), CodegenSymbolProviderEmpty.INSTANCE, classScope) .AddParam( typeof(EPStatementInitServices), EPStatementInitServicesConstants.REF.Ref); initializeQueryMethod.Block.AssignMember( MEMBERNAME_QUERY_METHOD_PROVIDER, NewInstanceInner(queryMethodProviderClassName, EPStatementInitServicesConstants.REF, Ref("statementFields"))); // get-execute var queryMethodProviderProperty = CodegenProperty.MakePropertyNode( typeof(FAFQueryMethodProvider), typeof(EPCompilerImpl), CodegenSymbolProviderEmpty.INSTANCE, classScope); queryMethodProviderProperty.GetterBlock.BlockReturn(Ref(MEMBERNAME_QUERY_METHOD_PROVIDER)); // provide module dependencies var moduleDependenciesProperty = CodegenProperty.MakePropertyNode( typeof(ModuleDependenciesRuntime), typeof(EPCompilerImpl), CodegenSymbolProviderEmpty.INSTANCE, classScope); moduleDependenciesProperty.GetterBlock .BlockReturn(compileTimeServices.ModuleDependencies.Make( initializeQueryMethod, classScope)); // build stack CodegenStackGenerator.RecursiveBuildStack(moduleDependenciesProperty, "ModuleDependencies", methods, properties); CodegenStackGenerator.RecursiveBuildStack(initializeEventTypesMethod, "InitializeEventTypes", methods, properties); CodegenStackGenerator.RecursiveBuildStack(initializeQueryMethod, "InitializeQuery", methods, properties); CodegenStackGenerator.RecursiveBuildStack(queryMethodProviderProperty, "QueryMethodProvider", methods, properties); IList<CodegenTypedParam> members = new List<CodegenTypedParam>(); members.Add(new CodegenTypedParam(statementFieldsClassName, null, "statementFields")); var typedParam = new CodegenTypedParam(typeof(FAFQueryMethodProvider), MEMBERNAME_QUERY_METHOD_PROVIDER); typedParam.IsReadonly = false; members.Add(typedParam); var clazz = new CodegenClass( CodegenClassType.FAFPROVIDER, typeof(FAFProvider), fafProviderClassName, classScope, members, ctor, methods, properties, new EmptyList<CodegenInnerClass>()); var container = compileTimeServices.Container; var compiler = container .RoslynCompiler() .WithCodeLogging(compileTimeServices.Configuration.Compiler.Logging.IsEnableCode) .WithCodeAuditDirectory(compileTimeServices.Configuration.Compiler.Logging.AuditDirectory) .WithCodegenClasses(new List<CodegenClass>() { clazz }); assembly = compiler.Compile(); return CodeGenerationIDGenerator.GenerateClassNameWithNamespace( compileTimeServices.Namespace, typeof(FAFProvider), classPostfix); }
private static string CompileModule( string optionalModuleName, IDictionary<ModuleProperty, object> moduleProperties, IList<string> statementClassNames, string moduleIdentPostfix, ModuleCompileTimeServices compileTimeServices, out Assembly assembly) { // write code to create an implementation of StatementResource var statementFieldsClassName = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(StatementFields), moduleIdentPostfix); var namespaceScope = new CodegenNamespaceScope( compileTimeServices.Namespace, statementFieldsClassName, compileTimeServices.IsInstrumented()); var moduleClassName = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(ModuleProvider), moduleIdentPostfix); var classScope = new CodegenClassScope(true, namespaceScope, moduleClassName); var methods = new CodegenClassMethods(); var properties = new CodegenClassProperties(); // provide module name var moduleNameProp = CodegenProperty.MakePropertyNode( typeof(string), typeof(EPCompilerImpl), CodegenSymbolProviderEmpty.INSTANCE, classScope); moduleNameProp.GetterBlock.BlockReturn(Constant(optionalModuleName)); // provide module properties var modulePropertiesProp = CodegenProperty.MakePropertyNode( typeof(IDictionary<ModuleProperty, object>), typeof(EPCompilerImpl), CodegenSymbolProviderEmpty.INSTANCE, classScope); MakeModuleProperties(moduleProperties, modulePropertiesProp); // provide module dependencies var moduleDependenciesProp = CodegenProperty.MakePropertyNode( typeof(ModuleDependenciesRuntime), typeof(EPCompilerImpl), CodegenSymbolProviderEmpty.INSTANCE, classScope); compileTimeServices.ModuleDependencies.Inject(moduleDependenciesProp.GetterBlock); // register types var initializeEventTypesMethod = MakeInitEventTypes(classScope, compileTimeServices); // register named windows var symbolsNamedWindowInit = new ModuleNamedWindowInitializeSymbol(); var initializeNamedWindowsMethod = CodegenMethod .MakeMethod(typeof(void), typeof(EPCompilerImpl), symbolsNamedWindowInit, classScope) .AddParam( typeof(EPModuleNamedWindowInitServices), ModuleNamedWindowInitializeSymbol.REF_INITSVC.Ref); foreach (var namedWindow in compileTimeServices.NamedWindowCompileTimeRegistry.NamedWindows) { var addNamedWindow = RegisterNamedWindowCodegen( namedWindow, initializeNamedWindowsMethod, classScope, symbolsNamedWindowInit); initializeNamedWindowsMethod.Block.Expression(LocalMethod(addNamedWindow)); } // register tables var symbolsTableInit = new ModuleTableInitializeSymbol(); var initializeTablesMethod = CodegenMethod .MakeMethod(typeof(void), typeof(EPCompilerImpl), symbolsTableInit, classScope) .AddParam(typeof(EPModuleTableInitServices), ModuleTableInitializeSymbol.REF_INITSVC.Ref); foreach (var table in compileTimeServices.TableCompileTimeRegistry.Tables) { var addTable = RegisterTableCodegen(table, initializeTablesMethod, classScope, symbolsTableInit); initializeTablesMethod.Block.Expression(LocalMethod(addTable)); } // register indexes var symbolsIndexInit = new ModuleIndexesInitializeSymbol(); var initializeIndexesMethod = CodegenMethod .MakeMethod(typeof(void), typeof(EPCompilerImpl), symbolsIndexInit, classScope) .AddParam(typeof(EPModuleIndexInitServices), EPModuleIndexInitServicesConstants.REF.Ref); foreach (KeyValuePair<IndexCompileTimeKey, IndexDetailForge> index in compileTimeServices .IndexCompileTimeRegistry.Indexes) { var addIndex = RegisterIndexCodegen(index, initializeIndexesMethod, classScope, symbolsIndexInit); initializeIndexesMethod.Block.Expression(LocalMethod(addIndex)); } // register contexts var symbolsContextInit = new ModuleContextInitializeSymbol(); var initializeContextsMethod = CodegenMethod .MakeMethod(typeof(void), typeof(EPCompilerImpl), symbolsContextInit, classScope) .AddParam( typeof(EPModuleContextInitServices), ModuleContextInitializeSymbol.REF_INITSVC.Ref); foreach (var context in compileTimeServices.ContextCompileTimeRegistry.Contexts) { var addContext = RegisterContextCodegen( context, initializeContextsMethod, classScope, symbolsContextInit); initializeContextsMethod.Block.Expression(LocalMethod(addContext)); } // register variables var symbolsVariablesInit = new ModuleVariableInitializeSymbol(); var initializeVariablesMethod = CodegenMethod .MakeMethod(typeof(void), typeof(EPCompilerImpl), symbolsVariablesInit, classScope) .AddParam( typeof(EPModuleVariableInitServices), ModuleVariableInitializeSymbol.REF_INITSVC.Ref); foreach (var variable in compileTimeServices.VariableCompileTimeRegistry.Variables) { var addVariable = RegisterVariableCodegen( variable, initializeVariablesMethod, classScope, symbolsVariablesInit); initializeVariablesMethod.Block.Expression(LocalMethod(addVariable)); } // register expressions var symbolsExprDeclaredInit = new ModuleExpressionDeclaredInitializeSymbol(); var initializeExprDeclaredMethod = CodegenMethod .MakeMethod(typeof(void), typeof(EPCompilerImpl), symbolsExprDeclaredInit, classScope) .AddParam( typeof(EPModuleExprDeclaredInitServices), ModuleExpressionDeclaredInitializeSymbol.REF_INITSVC.Ref); foreach (var expression in compileTimeServices.ExprDeclaredCompileTimeRegistry.Expressions) { var addExpression = RegisterExprDeclaredCodegen( expression, initializeExprDeclaredMethod, classScope, symbolsExprDeclaredInit); initializeExprDeclaredMethod.Block.Expression(LocalMethod(addExpression)); } // register scripts var symbolsScriptInit = new ModuleScriptInitializeSymbol(); var initializeScriptsMethod = CodegenMethod .MakeMethod(typeof(void), typeof(EPCompilerImpl), symbolsScriptInit, classScope) .AddParam(typeof(EPModuleScriptInitServices), ModuleScriptInitializeSymbol.REF_INITSVC.Ref); foreach (var expression in compileTimeServices.ScriptCompileTimeRegistry.Scripts) { var addScript = RegisterScriptCodegen( expression, initializeScriptsMethod, classScope, symbolsScriptInit); initializeScriptsMethod.Block.Expression(LocalMethod(addScript)); } // register provided classes var symbolsClassProvidedInit = new ModuleClassProvidedInitializeSymbol(); var initializeClassProvidedMethod = CodegenMethod .MakeParentNode(typeof(void), typeof(EPCompilerImpl), symbolsClassProvidedInit, classScope) .AddParam(typeof(EPModuleClassProvidedInitServices), ModuleClassProvidedInitializeSymbol.REF_INITSVC.Ref); foreach (var currClazz in compileTimeServices.ClassProvidedCompileTimeRegistry.Classes) { var addClassProvided = RegisterClassProvidedCodegen( currClazz, initializeClassProvidedMethod, classScope, symbolsClassProvidedInit); initializeClassProvidedMethod.Block.Expression(LocalMethod(addClassProvided)); } // instantiate factories for statements var statementsProp = CodegenProperty.MakePropertyNode( typeof(IList<StatementProvider>), typeof(EPCompilerImpl), CodegenSymbolProviderEmpty.INSTANCE, classScope); statementsProp.GetterBlock.DeclareVar<IList<StatementProvider>>( "statements", NewInstance(typeof(List<StatementProvider>), Constant(statementClassNames.Count))); foreach (var statementClassName in statementClassNames) { statementsProp.GetterBlock.ExprDotMethod( Ref("statements"), "Add", NewInstanceInner(statementClassName)); } statementsProp.GetterBlock.BlockReturn(Ref("statements")); // build stack CodegenStackGenerator.RecursiveBuildStack( moduleNameProp, "ModuleName", methods, properties); CodegenStackGenerator.RecursiveBuildStack( modulePropertiesProp, "ModuleProperties", methods, properties); CodegenStackGenerator.RecursiveBuildStack( moduleDependenciesProp, "ModuleDependencies", methods, properties); CodegenStackGenerator.RecursiveBuildStack( initializeEventTypesMethod, "InitializeEventTypes", methods, properties); CodegenStackGenerator.RecursiveBuildStack( initializeNamedWindowsMethod, "InitializeNamedWindows", methods, properties); CodegenStackGenerator.RecursiveBuildStack( initializeTablesMethod, "InitializeTables", methods, properties); CodegenStackGenerator.RecursiveBuildStack( initializeIndexesMethod, "InitializeIndexes", methods, properties); CodegenStackGenerator.RecursiveBuildStack( initializeContextsMethod, "InitializeContexts", methods, properties); CodegenStackGenerator.RecursiveBuildStack( initializeVariablesMethod, "InitializeVariables", methods, properties); CodegenStackGenerator.RecursiveBuildStack( initializeExprDeclaredMethod, "InitializeExprDeclareds", methods, properties); CodegenStackGenerator.RecursiveBuildStack( initializeScriptsMethod, "InitializeScripts", methods, properties); CodegenStackGenerator.RecursiveBuildStack( initializeClassProvidedMethod, "InitializeClassProvided", methods, properties); CodegenStackGenerator.RecursiveBuildStack( statementsProp, "Statements", methods, properties); var clazz = new CodegenClass( CodegenClassType.MODULEPROVIDER, typeof(ModuleProvider), moduleClassName, classScope, new EmptyList<CodegenTypedParam>(), null, methods, properties, new EmptyList<CodegenInnerClass>()); var container = compileTimeServices.Container; var compiler = container .RoslynCompiler() .WithCodeLogging(compileTimeServices.Configuration.Compiler.Logging.IsEnableCode) .WithCodeAuditDirectory(compileTimeServices.Configuration.Compiler.Logging.AuditDirectory) .WithCodegenClasses(new[] {clazz}); assembly = compiler.Compile(); return CodeGenerationIDGenerator.GenerateClassNameWithNamespace( compileTimeServices.Namespace, typeof(ModuleProvider), moduleIdentPostfix); }