Exemplo n.º 1
0
        // --------------------------------------------------------------------------------

        public CodegenExpressionInstanceField AddOrGetDefaultFieldWellKnown(
            CodegenFieldName fieldName,
            Type type)
        {
            CodegenExpression instance = Ref("statementFields");
            CodegenExpressionField fieldExpression = AddOrGetFieldWellKnown(fieldName, type);
            return InstanceField(instance, fieldExpression.Field);
        }
Exemplo n.º 2
0
 public ExprAggregateNodeGroupKey(
     int numGroupKeys,
     int groupKeyIndex,
     Type returnType,
     CodegenFieldName aggregationResultFutureMemberName)
 {
     this.numGroupKeys = numGroupKeys;
     this.groupKeyIndex = groupKeyIndex;
     this.returnType = returnType;
     this.aggregationResultFutureMemberName = aggregationResultFutureMemberName;
 }
Exemplo n.º 3
0
        private static void Generate(
            CodegenExpression init,
            CodegenFieldName name,
            CodegenMethod assign,
            CodegenMethod unassign,
            bool generateUnassign)
        {
            assign.Block.AssignRef(name.Name, init);

            // Table strategies are not unassigned since they do not hold on to the table instance
            if (generateUnassign) {
                unassign.Block.AssignRef(name.Name, ConstantNull());
            }
        }
Exemplo n.º 4
0
        public override ExprNode Validate(ExprValidationContext validationContext)
        {
            ValidatePositionals(validationContext);
            aggregationMethodFactory = ValidateAggregationChild(validationContext);
            if (!validationContext.IsAggregationFutureNameAlreadySet) {
                aggregationResultFutureMemberName = validationContext.MemberNames.AggregationResultFutureRef();
            }
            else {
                if (aggregationResultFutureMemberName == null) {
                    throw new ExprValidationException("Aggregation future not set");
                }
            }

            return null;
        }
Exemplo n.º 5
0
        public override ExprNode Validate(ExprValidationContext validationContext)
        {
            if (ChildNodes.Length != 2) {
                throw new ExprValidationException("Prior node must have 2 parameters");
            }

            if (!ChildNodes[0].Forge.ForgeConstantType.IsCompileTimeConstant) {
                throw new ExprValidationException(
                    "Prior function requires a constant-value integer-typed index expression as the first parameter");
            }

            // Child identifier nodes receive optional event
            ExprNodeUtilityMake.SetChildIdentNodesOptionalEvent(this);

            var constantNode = ChildNodes[0];
            var constantNodeType = constantNode.Forge.EvaluationType;
            if (constantNodeType != typeof(int?) && constantNodeType != typeof(int)) {
                throw new ExprValidationException("Prior function requires an integer index parameter");
            }

            var value = constantNode.Forge.ExprEvaluator.Evaluate(null, false, null);
            ConstantIndexNumber = value.AsInt32();
            InnerForge = ChildNodes[1].Forge;

            // Determine stream number
            if (ChildNodes[1] is ExprIdentNode) {
                var identNode = (ExprIdentNode) ChildNodes[1];
                StreamNumber = identNode.StreamId;
                EvaluationType = InnerForge.EvaluationType.GetBoxedType();
            }
            else if (ChildNodes[1] is ExprStreamUnderlyingNode) {
                var streamNode = (ExprStreamUnderlyingNode) ChildNodes[1];
                StreamNumber = streamNode.StreamId;
                EvaluationType = InnerForge.EvaluationType.GetBoxedType();
            }
            else {
                throw new ExprValidationException("Previous function requires an event property as parameter");
            }

            // add request
            if (validationContext.ViewResourceDelegate == null) {
                throw new ExprValidationException("Prior function cannot be used in this context");
            }

            validationContext.ViewResourceDelegate.AddPriorNodeRequest(this);
            priorStrategyFieldName = validationContext.MemberNames.PriorStrategy(StreamNumber);
            return null;
        }
Exemplo n.º 6
0
        public CodegenExpressionField AddOrGetFieldWellKnown(
            CodegenFieldName fieldName,
            Type type)
        {
            var existing = _fieldsNamed.Get(fieldName);
            if (existing != null) {
                if (existing.Type != type) {
                    throw new IllegalStateException(
                        "Field '" +
                        fieldName +
                        "' already registered with a different type, registered with " +
                        existing.Type.GetSimpleName() +
                        " but provided " +
                        type.GetSimpleName());
                }

                return Field(existing);
            }

            var field = new CodegenField(FieldsClassName, fieldName.Name, type, null, false);
            _fieldsNamed.Put(fieldName, field);
            return Field(field);
        }
Exemplo n.º 7
0
 public CodegenExpressionField AddOrGetFieldWellKnown(
     CodegenFieldName fieldName,
     Type type)
 {
     return NamespaceScope.AddOrGetFieldWellKnown(fieldName, type);
 }
Exemplo n.º 8
0
        public override ExprNode Validate(ExprValidationContext validationContext)
        {
            if (ChildNodes.Length > 2 || ChildNodes.Length == 0) {
                throw new ExprValidationException("Previous node must have 1 or 2 parameters");
            }

            // add constant of 1 for previous index
            if (ChildNodes.Length == 1) {
                if (PreviousType == ExprPreviousNodePreviousType.PREV) {
                    AddChildNodeToFront(new ExprConstantNodeImpl(1));
                }
                else {
                    AddChildNodeToFront(new ExprConstantNodeImpl(0));
                }
            }

            // the row recognition patterns allows "prev(prop, index)", we switch index the first position
            if (ExprNodeUtilityQuery.IsConstant(ChildNodes[1])) {
                var first = ChildNodes[0];
                var second = ChildNodes[1];
                ChildNodes = new[] {second, first};
            }

            // Determine if the index is a constant value or an expression to evaluate
            if (ChildNodes[0].Forge.ForgeConstantType.IsCompileTimeConstant) {
                var constantNode = ChildNodes[0];
                var value = constantNode.Forge.ExprEvaluator.Evaluate(null, false, null);
                if (!value.IsNumber()) {
                    throw new ExprValidationException(
                        "Previous function requires an integer index parameter or expression");
                }

                var valueNumber = value;
                if (valueNumber.IsFloatingPointNumber()) {
                    throw new ExprValidationException(
                        "Previous function requires an integer index parameter or expression");
                }

                ConstantIndexNumber = valueNumber.AsInt32();
                IsConstantIndex = true;
            }

            // Determine stream number
            if (ChildNodes[1] is ExprIdentNode) {
                var identNode = (ExprIdentNode) ChildNodes[1];
                StreamNumber = identNode.StreamId;
                ResultType = ChildNodes[1].Forge.EvaluationType.GetBoxedType();
            }
            else if (ChildNodes[1] is ExprStreamUnderlyingNode) {
                var streamNode = (ExprStreamUnderlyingNode) ChildNodes[1];
                StreamNumber = streamNode.StreamId;
                ResultType = ChildNodes[1].Forge.EvaluationType.GetBoxedType();
                _enumerationMethodType = validationContext.StreamTypeService.EventTypes[streamNode.StreamId];
            }
            else {
                throw new ExprValidationException("Previous function requires an event property as parameter");
            }

            if (PreviousType == ExprPreviousNodePreviousType.PREVCOUNT) {
                ResultType = typeof(long?);
            }

            if (PreviousType == ExprPreviousNodePreviousType.PREVWINDOW) {
                ResultType = TypeHelper.GetArrayType(ResultType);
            }

            if (validationContext.ViewResourceDelegate == null) {
                throw new ExprValidationException("Previous function cannot be used in this context");
            }

            validationContext.ViewResourceDelegate.AddPreviousRequest(this);
            _previousStrategyFieldName = validationContext.MemberNames.PreviousStrategy(StreamNumber);
            return null;
        }