public static string CompileQuery( FAFQueryMethodForge query, string classPostfix, ModuleCompileTimeServices compileTimeServices, out Assembly assembly) { var statementFieldsClassName = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(StatementFields), classPostfix); var packageScope = new CodegenNamespaceScope( compileTimeServices.Namespace, statementFieldsClassName, compileTimeServices.IsInstrumented()); var queryMethodProviderClassName = CodeGenerationIDGenerator.GenerateClassNameSimple( typeof(FAFQueryMethodProvider), classPostfix); var forgeablesQueryMethod = query.MakeForgeables(queryMethodProviderClassName, classPostfix, packageScope); IList<StmtClassForgeable> forgeables = new List<StmtClassForgeable>(forgeablesQueryMethod); forgeables.Add(new StmtClassForgeableStmtFields(statementFieldsClassName, packageScope, 0)); // forge with statement-fields last var classes = new List<CodegenClass>(forgeables.Count); foreach (var forgeable in forgeables) { var clazz = forgeable.Forge(true, true); classes.Add(clazz); } // assign the assembly (required for completeness) assembly = null; // compile with statement-field first classes = classes .OrderBy(c => c.ClassType.GetSortCode()) .ToList(); var container = compileTimeServices.Container; var compiler = container .RoslynCompiler() .WithCodeLogging(compileTimeServices.Configuration.Compiler.Logging.IsEnableCode) .WithCodeAuditDirectory(compileTimeServices.Configuration.Compiler.Logging.AuditDirectory) .WithCodegenClasses(classes); assembly = compiler.Compile(); return queryMethodProviderClassName; }
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); }