Exemplo n.º 1
0
 CompileCallable(
     CompilableItem compilableItem,
     ModuleCompileTimeServices compileTimeServices,
     Semaphore semaphore,
     ICollection <Assembly> statementAssemblies)
 {
     _compilableItem      = compilableItem;
     _compileTimeServices = compileTimeServices;
     _semaphore           = semaphore;
     _statementAssemblies = statementAssemblies;
 }
        private static EPCompiledManifest CompileToModules(
            ICollection<Assembly> assemblies,
            IList<Compilable> compilables,
            string optionalModuleName,
            IDictionary<ModuleProperty, object> moduleProperties,
            ModuleCompileTimeServices compileTimeServices,
            CompilerOptions compilerOptions,
            out Assembly assembly)
        {
            var moduleAssignedName = optionalModuleName ?? Guid.NewGuid().ToString();
            var moduleIdentPostfix = IdentifierUtil.GetIdentifierMayStartNumeric(moduleAssignedName);

            // compile each statement
            var statementNumber = 0;
            IList<string> statementClassNames = new List<string>();
            ISet<string> statementNames = new HashSet<string>();
            IList<EPCompileExceptionItem> exceptions = new List<EPCompileExceptionItem>();
            IList<EPCompileExceptionItem> postLatchExceptions = new List<EPCompileExceptionItem>();

            foreach (var compilable in compilables) {
                string className = null;
                EPCompileExceptionItem exception = null;

                try {
                    CompilableItem compilableItem = CompilerHelperStatementProvider.CompileItem(
                        compilable,
                        optionalModuleName,
                        moduleIdentPostfix,
                        statementNumber,
                        statementNames,
                        compileTimeServices,
                        compilerOptions,
                        out assembly);

                    assemblies.Add(assembly);
                    className = compilableItem.ProviderClassName;
                    compilableItem.PostCompileLatch.Completed(assemblies);
                    
                    // there can be a post-compile step, which may block submitting further compilables
                    try {
                        compilableItem.PostCompileLatch.AwaitAndRun();
                    } catch (Exception e) {
                        postLatchExceptions.Add(
                            new EPCompileExceptionItem(
                                e.Message,
                                e,
                                compilable.ToEPL(),
                                -1));
                    }
                }
                catch (StatementSpecCompileException ex) {
                    if (ex is StatementSpecCompileSyntaxException) {
                        exception = new EPCompileExceptionSyntaxItem(ex.Message, ex.Expression, -1);
                    }
                    else {
                        exception = new EPCompileExceptionItem(
                            ex.Message,
                            ex,
                            ex.Expression,
                            -1);
                    }

                    exceptions.Add(exception);
                }

                if (exception == null) {
                    statementClassNames.Add(className);
                    statementNumber++;
                }
            }
            
            exceptions.AddAll(postLatchExceptions);
            if (!exceptions.IsEmpty()) {
                var ex = exceptions[0];
                throw new EPCompileException(
                    "Error during compilation: " + ex.Message + " [" + ex.Expression + "]", ex, exceptions);
            }

            // compile module resource
            var moduleProviderClassName = CompileModule(
                optionalModuleName,
                moduleProperties,
                statementClassNames,
                moduleIdentPostfix,
                compileTimeServices,
                out assembly);
            
#if TBD // revisit
            // remove path create-class class-provided byte code
            compileTimeServices.ClassProvidedCompileTimeResolver.RemoveFrom(moduleBytes);

            // add class-provided create-class classes to module bytes
            foreach (var entry in compileTimeServices.ClassProvidedCompileTimeRegistry.Classes) {
                moduleBytes.Put(entry.Value.Assembly);
            }
#endif

            // create module XML
            return new EPCompiledManifest(COMPILER_VERSION, moduleProviderClassName, null, compileTimeServices.SerdeResolver.IsTargetHA);
        }