Beispiel #1
0
        public static ExprDeclaredNodeImpl GetExistsDeclaredExpr(
            IContainer container,
            String name,
            IList <ExprNode> parameters,
            ICollection <ExpressionDeclItem> expressionDeclarations,
            ExprDeclaredService exprDeclaredService,
            ContextDescriptor contextDescriptor)
        {
            // Find among local expressions
            if (expressionDeclarations.IsNotEmpty())
            {
                foreach (ExpressionDeclItem declNode in expressionDeclarations)
                {
                    if (declNode.Name.Equals(name))
                    {
                        return(new ExprDeclaredNodeImpl(
                                   container, declNode, parameters, contextDescriptor));
                    }
                }
            }

            // find among global expressions
            ExpressionDeclItem found = exprDeclaredService.GetExpression(name);

            if (found != null)
            {
                return(new ExprDeclaredNodeImpl(
                           container, found, parameters, contextDescriptor));
            }
            return(null);
        }
Beispiel #2
0
        public ExprDeclaredNodeImpl(
            ExpressionDeclItem prototype,
            IList<ExprNode> chainParameters,
            ContextCompileTimeDescriptor contextDescriptor,
            ExprNode expressionBodyCopy)
        {
            PrototypeWVisibility = prototype;
            ChainParameters = chainParameters;
            ExpressionBodyCopy = expressionBodyCopy;

            // replace context-properties where they are currently identifiers
            if (contextDescriptor == null) {
                return;
            }

            var visitorWParent = new ExprNodeIdentVisitorWParent();
            expressionBodyCopy.Accept(visitorWParent);
            foreach (var pair in visitorWParent.IdentNodes) {
                var streamOrProp = pair.Second.StreamOrPropertyName;
                if (streamOrProp != null &&
                    contextDescriptor.ContextPropertyRegistry.IsContextPropertyPrefix(streamOrProp)) {
                    var context =
                        new ExprContextPropertyNodeImpl(pair.Second.UnresolvedPropertyName);
                    if (pair.First == null) {
                        ExpressionBodyCopy = context;
                    }
                    else {
                        ExprNodeUtilityModify.ReplaceChildNode(pair.First, pair.Second, context);
                    }
                }
            }
        }
Beispiel #3
0
        public ExpressionDeclItem Resolve(string name)
        {
            // try self-originated protected types first
            ExpressionDeclItem localExpr = _locals.Expressions.Get(name);
            if (localExpr != null) {
                return localExpr;
            }

            try {
                var expression = _path.GetAnyModuleExpectSingle(name, _moduleUses);
                if (expression != null) {
                    if (!_isFireAndForget && !NameAccessModifierExtensions.Visible(
                        expression.First.Visibility,
                        expression.First.ModuleName,
                        _moduleName)) {
                        return null;
                    }

                    _moduleDependencies.AddPathExpression(name, expression.Second);
                    return expression.First;
                }
            }
            catch (PathException e) {
                throw CompileTimeResolverUtil.MakePathAmbiguous(PathRegistryObjectType.EXPRDECL, name, e);
            }

            return null;
        }
Beispiel #4
0
        public void AddExpressionDeclarations(ExpressionDeclItem item)
        {
            if (expressionDeclarations == null) {
                expressionDeclarations = new Dictionary<string, ExpressionDeclItem>();
            }

            expressionDeclarations.Put(item.Name, item);
        }
        public void RegisterExprDeclared(
            string expressionName,
            ExpressionDeclItem meta)
        {
            if (expressions.ContainsKey(expressionName)) {
                throw new IllegalStateException("Expression name already found '" + expressionName + "'");
            }

            expressions.Put(expressionName, meta);
        }
        public void NewExprDeclared(ExpressionDeclItem detail)
        {
            if (!detail.Visibility.IsModuleProvidedAccessModifier()) {
                throw new IllegalStateException("Invalid visibility for contexts");
            }

            var name = detail.Name;
            var existing = Expressions.Get(name);
            if (existing != null) {
                throw new IllegalStateException("Duplicate declared expression encountered for name '" + name + "'");
            }

            Expressions.Put(name, detail);
        }
Beispiel #7
0
 protected ExprDeclaredEvalBase(ExprEvaluator innerEvaluator, ExpressionDeclItem prototype, bool isCache)
 {
     _innerEvaluator = innerEvaluator;
     _prototype      = prototype;
     if (innerEvaluator is ExprEvaluatorEnumeration)
     {
         _innerEvaluatorLambda = (ExprEvaluatorEnumeration)innerEvaluator;
     }
     else
     {
         _innerEvaluatorLambda = null;
     }
     _isCache = isCache;
 }
Beispiel #8
0
 public ExprDeclaredForgeConstant(
     ExprDeclaredNodeImpl parent,
     Type returnType,
     ExpressionDeclItem prototype,
     object value,
     bool audit,
     string statementName)
 {
     this.parent = parent;
     EvaluationType = returnType;
     this.prototype = prototype;
     this.value = value;
     this.audit = audit;
     this.statementName = statementName;
 }
Beispiel #9
0
        public String AddExpressionOrScript(CreateExpressionDesc expressionDesc)
        {
            using (_iLock.Acquire())
            {
                if (expressionDesc.Expression != null)
                {
                    ExpressionDeclItem expression = expressionDesc.Expression;
                    String             name       = expression.Name;
                    if (_globalExpressions.ContainsKey(name))
                    {
                        throw new ExprValidationException("Expression '" + name + "' has already been declared");
                    }
                    _globalExpressions.Put(name, expression);
                    return(name);
                }
                else
                {
                    ExpressionScriptProvided newScript = expressionDesc.Script;
                    String name = newScript.Name;

                    List <ExpressionScriptProvided> scripts = _globalScripts.Get(name);
                    if (scripts != null)
                    {
                        foreach (ExpressionScriptProvided script in scripts)
                        {
                            if (script.ParameterNames.Count == newScript.ParameterNames.Count)
                            {
                                throw new ExprValidationException(
                                          "Script '" + name +
                                          "' that takes the same number of parameters has already been declared");
                            }
                        }
                    }
                    else
                    {
                        scripts = new List <ExpressionScriptProvided>(2);
                        _globalScripts.Put(name, scripts);
                    }
                    scripts.Add(newScript);

                    return(name);
                }
            }
        }
Beispiel #10
0
        public ExprDeclaredNodeImpl(
            IContainer container,
            ExpressionDeclItem prototype,
            IList <ExprNode> chainParameters,
            ContextDescriptor contextDescriptor)
        {
            _prototype       = prototype;
            _chainParameters = chainParameters;

            // copy expression - we do it at this time and not later
            try {
                _expressionBodyCopy = (ExprNode)SerializableObjectCopier.Copy(container, prototype.Inner);
            } catch (Exception e) {
                throw new Exception("Internal error providing expression tree: " + e.Message, e);
            }

            // replace context-properties where they are currently identifiers
            if (contextDescriptor == null)
            {
                return;
            }
            var visitorWParent = new ExprNodeIdentVisitorWParent();

            _expressionBodyCopy.Accept(visitorWParent);
            foreach (var pair in visitorWParent.IdentNodes)
            {
                var streamOrProp = pair.Second.StreamOrPropertyName;
                if (streamOrProp != null && contextDescriptor.ContextPropertyRegistry.IsContextPropertyPrefix(streamOrProp))
                {
                    var context = new ExprContextPropertyNode(pair.Second.UnresolvedPropertyName);
                    if (pair.First == null)
                    {
                        _expressionBodyCopy = context;
                    }
                    else
                    {
                        ExprNodeUtility.ReplaceChildNode(pair.First, pair.Second, context);
                    }
                }
            }
        }
Beispiel #11
0
        public static CodegenExpressionInstanceField MakeRuntimeCacheKeyField(
            CodegenExpression instance,
            ExpressionDeclItem expression,
            CodegenClassScope classScope,
            Type generator)
        {
            if (expression.Visibility == NameAccessModifier.TRANSIENT) {
                // for private expression that cache key is simply an Object shared by the name of the
                // expression (fields are per-statement already so its safe)
                return classScope.NamespaceScope.AddOrGetInstanceFieldSharable(
                    instance, new ExprDeclaredCacheKeyLocalCodegenField(expression.Name));
            }

            // global expressions need a cache key that derives from the deployment id of the expression and the expression name
            CodegenMethod keyInit = classScope.NamespaceScope.InitMethod
                .MakeChild(typeof(ExprDeclaredCacheKeyGlobal), generator, classScope)
                .AddParam(
                    typeof(EPStatementInitServices),
                    EPStatementInitServicesConstants.REF.Ref);
            keyInit.Block.DeclareVar<string>(
                    "deploymentId",
                    StaticMethod(
                        typeof(ExpressionDeployTimeResolver),
                        "ResolveDeploymentId",
                        Constant(expression.Name),
                        Constant(expression.Visibility),
                        Constant(expression.ModuleName),
                        EPStatementInitServicesConstants.REF))
                .MethodReturn(
                    NewInstance<ExprDeclaredCacheKeyGlobal>(
                        Ref("deploymentId"),
                        Constant(expression.Name)));

            return classScope.NamespaceScope.AddInstanceFieldUnshared(
                instance,
                true,
                typeof(ExprDeclaredCacheKeyGlobal),
                LocalMethod(keyInit, EPStatementInitServicesConstants.REF));
        }
Beispiel #12
0
 public ExprDeclaredEvalRewrite(ExprEvaluator innerEvaluator, ExpressionDeclItem prototype, bool isCache, int[] streamAssignments)
     : base(innerEvaluator, prototype, isCache)
 {
     _streamAssignments = streamAssignments;
 }
Beispiel #13
0
 public ExprDeclaredEvalConstant(Type returnType, ExpressionDeclItem prototype, Object value)
 {
     _returnType = returnType;
     _prototype  = prototype;
     _value      = value;
 }
Beispiel #14
0
 public void QExprDeclared(ExpressionDeclItem parent)
 {
 }
Beispiel #15
0
 public void RegisterExprDeclared(
     string expressionName,
     ExpressionDeclItem meta)
 {
     moduleExpressions.Put(expressionName, meta);
 }
 public ExprDeclaredEvalNoRewrite(ExprEvaluator innerEvaluator, ExpressionDeclItem prototype, bool isCache)
     : base(innerEvaluator, prototype, isCache)
 {
 }
Beispiel #17
0
        public static Pair <ExpressionDeclItem, ExpressionScriptProvided> WalkExpressionDecl(
            EsperEPL2GrammarParser.ExpressionDeclContext ctx,
            IList <String> scriptBodies,
            IDictionary <ITree, ExprNode> astExprNodeMap,
            CommonTokenStream tokenStream)
        {
            var name = ctx.name.Text;

            if (ctx.alias != null)
            {
                if (ctx.alias.Text.ToLower().Trim() != "alias")
                {
                    throw ASTWalkException.From("For expression alias '" + name + "' expecting 'alias' keyword but received '" + ctx.alias.Text + "'");
                }
                if (ctx.columnList() != null)
                {
                    throw ASTWalkException.From("For expression alias '" + name + "' expecting no parameters but received '" + tokenStream.GetText(ctx.columnList()) + "'");
                }
                if (ctx.expressionDef() != null && ctx.expressionDef().expressionLambdaDecl() != null)
                {
                    throw ASTWalkException.From("For expression alias '" + name + "' expecting an expression without parameters but received '" + tokenStream.GetText(ctx.expressionDef().expressionLambdaDecl()) + "'");
                }
                if (ctx.expressionDef().stringconstant() != null)
                {
                    throw ASTWalkException.From("For expression alias '" + name + "' expecting an expression but received a script");
                }
                var exprNode = ASTExprHelper.ExprCollectSubNodes(ctx, 0, astExprNodeMap)[0];
                var alias    = ctx.name.Text;
                var decl     = new ExpressionDeclItem(alias, Collections.GetEmptyList <String>(), exprNode, true);
                return(new Pair <ExpressionDeclItem, ExpressionScriptProvided>(decl, null));
            }

            if (ctx.expressionDef().stringconstant() != null)
            {
                var expressionText = scriptBodies[0];
                scriptBodies.RemoveAt(0);
                var parameters         = ASTUtil.GetIdentList(ctx.columnList());
                var optionalReturnType = ctx.classIdentifier() == null
                    ? null
                    : ASTUtil.UnescapeClassIdent(ctx.classIdentifier());
                var optionalReturnTypeArray = ctx.array != null;
                var optionalDialect         = ctx.expressionDialect() == null ? null : ctx.expressionDialect().d.Text;
                var script = new ExpressionScriptProvided(
                    name, expressionText, parameters,
                    optionalReturnType, optionalReturnTypeArray, optionalDialect);
                return(new Pair <ExpressionDeclItem, ExpressionScriptProvided>(null, script));
            }

            var ctxexpr = ctx.expressionDef();
            var inner   = ASTExprHelper.ExprCollectSubNodes(ctxexpr.expression(), 0, astExprNodeMap)[0];

            var parametersNames = Collections.GetEmptyList <string>();
            var lambdactx       = ctxexpr.expressionLambdaDecl();

            if (ctxexpr.expressionLambdaDecl() != null)
            {
                parametersNames = ASTLibFunctionHelper.GetLambdaGoesParams(lambdactx);
            }

            var expr = new ExpressionDeclItem(name, parametersNames, inner, false);

            return(new Pair <ExpressionDeclItem, ExpressionScriptProvided>(expr, null));
        }
        public static MyPair WalkExpressionDecl(
            EsperEPL2GrammarParser.ExpressionDeclContext ctx,
            IList<string> scriptBodies,
            IDictionary<ITree, ExprNode> astExprNodeMap,
            CommonTokenStream tokenStream)
        {
            var name = ctx.name.Text;

            if (ctx.alias != null)
            {
                if (!ctx.alias.Text.ToLowerInvariant().Trim().Equals("alias"))
                {
                    throw ASTWalkException.From(
                        "For expression alias '" + name + "' expecting 'alias' keyword but received '" + ctx.alias.Text + "'");
                }

                if (ctx.columnList() != null)
                {
                    throw ASTWalkException.From(
                        "For expression alias '" + name + "' expecting no parameters but received '" + tokenStream.GetText(ctx.columnList()) + "'");
                }

                if (ctx.expressionDef() != null && ctx.expressionDef().expressionLambdaDecl() != null)
                {
                    throw ASTWalkException.From(
                        "For expression alias '" + name + "' expecting an expression without parameters but received '" +
                        tokenStream.GetText(ctx.expressionDef().expressionLambdaDecl()) + "'");
                }

                if (ctx.expressionDef().stringconstant() != null)
                {
                    throw ASTWalkException.From("For expression alias '" + name + "' expecting an expression but received a script");
                }

                var node = ASTExprHelper.ExprCollectSubNodes(ctx, 0, astExprNodeMap)[0];
                var alias = ctx.name.Text;
                var expressionUnmap = StatementSpecMapper.Unmap(node);
                var decl = new ExpressionDeclItem(alias, new string[0], true);
                decl.OptionalSoda = expressionUnmap;
                return new MyPair(decl, null);
            }

            if (ctx.expressionDef().stringconstant() != null)
            {
                var expressionText = scriptBodies.DeleteAt(0);
                var parameters = ASTUtil.GetIdentList(ctx.columnList());
                var optionalReturnType = ctx.classIdentifier() == null ? null : ASTUtil.UnescapeClassIdent(ctx.classIdentifier());
                var optionalReturnTypeArray = ctx.array != null;
                var optionalDialect = ctx.expressionDialect() == null ? null : ctx.expressionDialect().d.Text;
                var optionalEventTypeName = ASTTypeExpressionAnnoHelper.ExpectMayTypeAnno(ctx.typeExpressionAnnotation(), tokenStream);
                var script = new ExpressionScriptProvided(
                    name, expressionText, parameters.ToArray(),
                    optionalReturnType, optionalReturnTypeArray, optionalEventTypeName, optionalDialect);
                return new MyPair(null, script);
            }

            var ctxexpr = ctx.expressionDef();
            var inner = ASTExprHelper.ExprCollectSubNodes(ctxexpr.expression(), 0, astExprNodeMap)[0];

            IList<string> parametersNames = new EmptyList<string>();
            var lambdactx = ctxexpr.expressionLambdaDecl();
            if (ctxexpr.expressionLambdaDecl() != null)
            {
                parametersNames = ASTLambdaHelper.GetLambdaGoesParams(lambdactx);
            }

            var expression = StatementSpecMapper.Unmap(inner);
            var expr = new ExpressionDeclItem(name, parametersNames.ToArray(), false);
            expr.OptionalSoda = expression;
            return new MyPair(expr, null);
        }