Exemplo n.º 1
0
 public EnumForgeDesc(
     EPType type,
     EnumForge forge)
 {
     Type = type;
     Forge = forge;
 }
        public EnumForgeDesc MakeEnumForgeDesc(
            IList <ExprDotEvalParam> bodiesAndParameters,
            int streamCountIncoming,
            StatementCompileTimeServices services)
        {
            ExprDotEvalParamLambda first  = (ExprDotEvalParamLambda)bodiesAndParameters[0];
            ExprDotEvalParamLambda second = (ExprDotEvalParamLambda)bodiesAndParameters[1];
            EnumForge forge = function.Invoke(first, second, streamCountIncoming, returnType, services);

            return(new EnumForgeDesc(returnType, forge));
        }
        public EnumForgeDesc MakeEnumForgeDesc(
            IList <ExprDotEvalParam> bodiesAndParameters,
            int streamCountIncoming,
            StatementCompileTimeServices services)
        {
            ExprDotEvalParamLambda key   = (ExprDotEvalParamLambda)bodiesAndParameters[0];
            ExprDotEvalParamLambda value = (ExprDotEvalParamLambda)bodiesAndParameters[1];
            EnumForge forge = function.Invoke(key, value, streamCountIncoming, typeKey, typeValue, numParams, returnType, services);

            return(new EnumForgeDesc(returnType, forge));
        }
Exemplo n.º 4
0
        public EnumForgeDesc MakeEnumForgeDesc(
            IList <ExprDotEvalParam> bodiesAndParameters,
            int streamCountIncoming,
            StatementCompileTimeServices services)
        {
            if (bodiesAndParameters.IsEmpty())
            {
                throw new UnsupportedOperationException();
            }

            ExprDotEvalParamLambda first = (ExprDotEvalParamLambda)bodiesAndParameters[0];
            EPType    typeInfo           = _returnType.Invoke(first);
            EnumForge forge = MakeForgeWithParam(first, typeInfo, services);

            return(new EnumForgeDesc(typeInfo, forge));
        }
Exemplo n.º 5
0
            public EnumForgeDesc MakeEnumForgeDesc(
                IList<ExprDotEvalParam> bodiesAndParameters,
                int streamCountIncoming,
                StatementCompileTimeServices services)
            {
                var scalar = _type is ClassMultiValuedEPType;
                EnumForge forge = _enumMethod switch {
                    EnumMethodEnum.UNION => new EnumUnionForge(streamCountIncoming, _enumSrc.Enumeration, scalar),
                    EnumMethodEnum.INTERSECT => new EnumIntersectForge(streamCountIncoming, _enumSrc.Enumeration, scalar),
                    EnumMethodEnum.EXCEPT => new EnumExceptForge(streamCountIncoming, _enumSrc.Enumeration, scalar),
                    _ => throw new ArgumentException("Invalid enumeration method for this factory: " + _enumMethod)
                };

                return new EnumForgeDesc(_type, forge);
            }
        }
Exemplo n.º 6
0
        public void Init(
            int? streamOfProviderIfApplicable,
            EnumMethodEnum enumMethodEnum,
            string enumMethodUsedName,
            EPType typeInfo,
            IList<ExprNode> parameters,
            ExprValidationContext validationContext)
        {
            var eventTypeColl = typeInfo.GetEventTypeMultiValued();
            var eventTypeBean = typeInfo.GetEventTypeSingleValued();
            var collectionComponentType = typeInfo.GetClassMultiValued();

            this.enumMethodEnum = enumMethodEnum;
            this.enumMethodUsedName = enumMethodUsedName;
            streamCountIncoming = validationContext.StreamTypeService.EventTypes.Length;

            if (eventTypeColl == null && collectionComponentType == null && eventTypeBean == null) {
                throw new ExprValidationException(
                    "Invalid input for built-in enumeration method '" +
                    enumMethodUsedName +
                    "', expecting collection of event-type or scalar values as input, received " +
                    typeInfo.ToTypeDescriptive());
            }

            // compile parameter abstract for validation against available footprints
            DotMethodFPProvided footprintProvided = DotMethodUtil.GetProvidedFootprint(parameters);

            // validate parameters
            DotMethodInputTypeMatcher inputTypeMatcher = new ProxyDotMethodInputTypeMatcher {
                ProcMatches = fp => {
                    if (fp.Input == DotMethodFPInputEnum.EVENTCOLL &&
                        eventTypeBean == null &&
                        eventTypeColl == null) {
                        return false;
                    }

                    if (fp.Input == DotMethodFPInputEnum.SCALAR_ANY && collectionComponentType == null) {
                        return false;
                    }

                    return true;
                }
            };

            DotMethodFP footprint = DotMethodUtil.ValidateParametersDetermineFootprint(
                enumMethodEnum.GetFootprints(),
                DotMethodTypeEnum.ENUM,
                enumMethodUsedName,
                footprintProvided,
                inputTypeMatcher);

            // validate input criteria met for this footprint
            if (footprint.Input != DotMethodFPInputEnum.ANY) {
                var message = "Invalid input for built-in enumeration method '" +
                              enumMethodUsedName +
                              "' and " +
                              footprint.Parameters.Length +
                              "-parameter footprint, expecting collection of ";
                var received = " as input, received " + EPTypeHelper.ToTypeDescriptive(typeInfo);
                if (footprint.Input == DotMethodFPInputEnum.EVENTCOLL && eventTypeColl == null) {
                    throw new ExprValidationException(message + "events" + received);
                }

                if (footprint.Input.IsScalar() && collectionComponentType == null) {
                    throw new ExprValidationException(message + "values (typically scalar values)" + received);
                }

                if (footprint.Input == DotMethodFPInputEnum.SCALAR_NUMERIC && !collectionComponentType.IsNumeric()) {
                    throw new ExprValidationException(message + "numeric values" + received);
                }
            }

            // manage context of this lambda-expression in regards to outer lambda-expression that may call this one.
            var enumCallStackHelper = validationContext.EnumMethodCallStackHelper;
            enumCallStackHelper.PushStack(this);

            IList<ExprDotEvalParam> bodiesAndParameters = new List<ExprDotEvalParam>();
            var count = 0;
            var inputEventType = eventTypeBean == null ? eventTypeColl : eventTypeBean;
            foreach (var node in parameters) {
                var bodyAndParameter = GetBodyAndParameter(
                    enumMethodUsedName,
                    count++,
                    node,
                    inputEventType,
                    collectionComponentType,
                    validationContext,
                    bodiesAndParameters,
                    footprint);
                bodiesAndParameters.Add(bodyAndParameter);
            }

            enumForge = GetEnumForge(
                validationContext.StreamTypeService,
                enumMethodUsedName,
                bodiesAndParameters,
                inputEventType, // TBD: collectionType, may not be applicable
                collectionComponentType,
                streamCountIncoming,
                validationContext.IsDisablePropertyExpressionEventCollCache,
                validationContext.StatementRawInfo,
                validationContext.StatementCompileTimeService);
            enumEvalNumRequiredEvents = enumForge.StreamNumSize;

            // determine the stream ids of event properties asked for in the evaluator(s)
            var streamsRequired = new HashSet<int>();
            var visitor = new ExprNodeIdentifierCollectVisitor();
            foreach (var desc in bodiesAndParameters) {
                desc.Body.Accept(visitor);
                foreach (var ident in visitor.ExprProperties) {
                    streamsRequired.Add(ident.StreamId);
                }
            }

            if (streamOfProviderIfApplicable != null) {
                streamsRequired.Add(streamOfProviderIfApplicable.Value);
            }

            // We turn on caching if the stack is not empty (we are an inner lambda) and the dependency does not include the stream.
            var isInner = !enumCallStackHelper.PopLambda();
            if (isInner) {
                // If none of the properties that the current lambda uses comes from the ultimate parent(s) or subsequent streams, then cache.
                Deque<ExpressionResultCacheStackEntry> parents = enumCallStackHelper.GetStack();
                var found = false;
                foreach (var req in streamsRequired) {
                    var first = (ExprDotForgeEnumMethodBase) parents.First;
                    var parentIncoming = first.streamCountIncoming - 1;
                    var selfAdded = streamCountIncoming; // the one we use ourselfs
                    if (req > parentIncoming && req < selfAdded) {
                        found = true;
                    }
                }

                cache = !found;
            }
        }