Ejemplo n.º 1
0
        internal override ResolvedTraitSet FetchResolvedTraits(ResolveOptions resOpt = null)
        {
            if (resOpt == null)
            {
                resOpt = new ResolveOptions(this, this.Ctx.Corpus.DefaultResolutionDirectives);
            }

            const string kind = "rtsb";
            var          ctx  = this.Ctx as ResolveContext;
            // get referenced trait
            var trait = this.FetchObjectDefinition <CdmTraitDefinition>(resOpt);
            ResolvedTraitSet rtsTrait = null;

            if (trait == null)
            {
                return(ctx.Corpus.CreateEmptyResolvedTraitSet(resOpt));
            }

            // see if one is already cached
            // cache by name unless there are parameter
            if (trait.ThisIsKnownToHaveParameters == null)
            {
                // never been resolved, it will happen soon, so why not now?
                rtsTrait = trait.FetchResolvedTraits(resOpt);
            }

            bool cacheByPath = true;

            if (trait.ThisIsKnownToHaveParameters != null)
            {
                cacheByPath = !((bool)trait.ThisIsKnownToHaveParameters);
            }

            string  cacheTag  = ctx.Corpus.CreateDefinitionCacheTag(resOpt, this, kind, "", cacheByPath, trait.AtCorpusPath);
            dynamic rtsResult = null;

            if (cacheTag != null)
            {
                ctx.Cache.TryGetValue(cacheTag, out rtsResult);
            }

            // store the previous reference symbol set, we will need to add it with
            // children found from the constructResolvedTraits call
            SymbolSet currSymRefSet = resOpt.SymbolRefSet;

            if (currSymRefSet == null)
            {
                currSymRefSet = new SymbolSet();
            }
            resOpt.SymbolRefSet = new SymbolSet();

            // if not, then make one and save it
            if (rtsResult == null)
            {
                // get the set of resolutions, should just be this one trait
                if (rtsTrait == null)
                {
                    // store current symbol ref set
                    SymbolSet newSymbolRefSet = resOpt.SymbolRefSet;
                    resOpt.SymbolRefSet = new SymbolSet();

                    rtsTrait = trait.FetchResolvedTraits(resOpt);

                    // bubble up symbol reference set from children
                    if (newSymbolRefSet != null)
                    {
                        newSymbolRefSet.Merge(resOpt.SymbolRefSet);
                    }
                    resOpt.SymbolRefSet = newSymbolRefSet;
                }
                if (rtsTrait != null)
                {
                    rtsResult = rtsTrait.DeepCopy();
                }

                // now if there are argument for this application, set the values in the array
                if (this.Arguments != null && rtsResult != null)
                {
                    // if never tried to line up arguments with parameters, do that
                    if (!this.ResolvedArguments)
                    {
                        this.ResolvedArguments = true;
                        ParameterCollection    param      = trait.FetchAllParameters(resOpt);
                        CdmParameterDefinition paramFound = null;
                        dynamic aValue = null;

                        int iArg = 0;
                        if (this.Arguments != null)
                        {
                            foreach (CdmArgumentDefinition argument in this.Arguments)
                            {
                                paramFound = param.ResolveParameter(iArg, argument.Name);
                                argument.ResolvedParameter = paramFound;
                                aValue         = argument.Value;
                                aValue         = ctx.Corpus.ConstTypeCheck(resOpt, this.InDocument, paramFound, aValue);
                                argument.Value = aValue;
                                iArg++;
                            }
                        }
                    }
                    if (this.Arguments != null)
                    {
                        foreach (CdmArgumentDefinition a in this.Arguments)
                        {
                            rtsResult.SetParameterValueFromArgument(trait, a);
                        }
                    }
                }

                // register set of possible symbols
                ctx.Corpus.RegisterDefinitionReferenceSymbols(this.FetchObjectDefinition <CdmObjectDefinition>(resOpt), kind, resOpt.SymbolRefSet);

                // get the new cache tag now that we have the list of symbols
                cacheTag = ctx.Corpus.CreateDefinitionCacheTag(resOpt, this, kind, "", cacheByPath, trait.AtCorpusPath);
                if (!string.IsNullOrWhiteSpace(cacheTag))
                {
                    ctx.Cache[cacheTag] = rtsResult;
                }
            }
            else
            {
                // cache was found
                // get the SymbolSet for this cached object
                string key = CdmCorpusDefinition.CreateCacheKeyFromObject(this, kind);
                ctx.Corpus.DefinitionReferenceSymbols.TryGetValue(key, out SymbolSet tempDocRefSet);
                resOpt.SymbolRefSet = tempDocRefSet;
            }

            // merge child document set with current
            currSymRefSet.Merge(resOpt.SymbolRefSet);
            resOpt.SymbolRefSet = currSymRefSet;

            return(rtsResult);
        }
        internal virtual ResolvedTraitSet FetchResolvedTraits(ResolveOptions resOpt = null)
        {
            bool wasPreviouslyResolving = this.Ctx.Corpus.isCurrentlyResolving;

            this.Ctx.Corpus.isCurrentlyResolving = true;
            if (resOpt == null)
            {
                resOpt = new ResolveOptions(this, this.Ctx.Corpus.DefaultResolutionDirectives);
            }

            const string            kind      = "rtsb";
            ResolveContext          ctx       = this.Ctx as ResolveContext;
            string                  cacheTagA = ctx.Corpus.CreateDefinitionCacheTag(resOpt, this, kind);
            ResolvedTraitSetBuilder rtsbAll   = null;

            if (this.TraitCache == null)
            {
                this.TraitCache = new Dictionary <string, ResolvedTraitSetBuilder>();
            }
            else if (!string.IsNullOrWhiteSpace(cacheTagA))
            {
                this.TraitCache.TryGetValue(cacheTagA, out rtsbAll);
            }

            // store the previous document set, we will need to add it with
            // children found from the constructResolvedTraits call
            SymbolSet currDocRefSet = resOpt.SymbolRefSet;

            if (currDocRefSet == null)
            {
                currDocRefSet = new SymbolSet();
            }
            resOpt.SymbolRefSet = new SymbolSet();

            if (rtsbAll == null)
            {
                rtsbAll = new ResolvedTraitSetBuilder();

                if (!resolvingTraits)
                {
                    resolvingTraits = true;
                    this.ConstructResolvedTraits(rtsbAll, resOpt);
                    resolvingTraits = false;
                }

                CdmObjectDefinitionBase objDef = this.FetchObjectDefinition <CdmObjectDefinitionBase>(resOpt);
                if (objDef != null)
                {
                    // register set of possible docs
                    ctx.Corpus.RegisterDefinitionReferenceSymbols(objDef, kind, resOpt.SymbolRefSet);

                    if (rtsbAll.ResolvedTraitSet == null)
                    {
                        // nothing came back, but others will assume there is a set in this builder
                        rtsbAll.ResolvedTraitSet = new ResolvedTraitSet(resOpt);
                    }
                    // get the new cache tag now that we have the list of docs
                    cacheTagA = ctx.Corpus.CreateDefinitionCacheTag(resOpt, this, kind);
                    if (!string.IsNullOrWhiteSpace(cacheTagA))
                    {
                        this.TraitCache[cacheTagA] = rtsbAll;
                    }
                }
            }
            else
            {
                // cache was found
                // get the SymbolSet for this cached object
                string key = CdmCorpusDefinition.CreateCacheKeyFromObject(this, kind);
                ((CdmCorpusDefinition)ctx.Corpus).DefinitionReferenceSymbols.TryGetValue(key, out SymbolSet tempDocRefSet);
                resOpt.SymbolRefSet = tempDocRefSet;
            }

            // merge child document set with current
            currDocRefSet.Merge(resOpt.SymbolRefSet);
            resOpt.SymbolRefSet = currDocRefSet;

            this.Ctx.Corpus.isCurrentlyResolving = wasPreviouslyResolving;
            return(rtsbAll.ResolvedTraitSet);
        }
Ejemplo n.º 3
0
        internal override ResolvedTraitSet FetchResolvedTraits(ResolveOptions resOpt = null)
        {
            if (resOpt == null)
            {
                resOpt = new ResolveOptions(this, this.Ctx.Corpus.DefaultResolutionDirectives);
            }

            const string   kind = "rtsb";
            ResolveContext ctx  = this.Ctx as ResolveContext;
            // this may happen 0, 1 or 2 times. so make it fast
            CdmTraitDefinition baseTrait  = null;
            ResolvedTraitSet   baseRts    = null;
            List <dynamic>     baseValues = null;

            System.Action GetBaseInfo = () =>
            {
                if (this.ExtendsTrait != null)
                {
                    baseTrait = this.ExtendsTrait.FetchObjectDefinition <CdmTraitDefinition>(resOpt);
                    if (baseTrait != null)
                    {
                        baseRts = this.ExtendsTrait.FetchResolvedTraits(resOpt);
                        if (baseRts?.Size == 1)
                        {
                            ParameterValueSet basePv = baseRts.Get(baseTrait)?.ParameterValues;
                            if (basePv != null)
                            {
                                baseValues = basePv.Values;
                            }
                        }
                    }
                }
            };

            // see if one is already cached
            // if this trait has parameters, then the base trait found through the reference might be a different reference
            // because trait references are unique per argument value set. so use the base as a part of the cache tag
            // since it is expensive to figure out the extra tag, cache that too!
            if (this.BaseIsKnownToHaveParameters == null)
            {
                GetBaseInfo();
                // is a cache tag needed? then make one
                this.BaseIsKnownToHaveParameters = false;
                if (baseValues?.Count > 0)
                {
                    this.BaseIsKnownToHaveParameters = true;
                }
            }
            string cacheTagExtra = "";

            if (this.BaseIsKnownToHaveParameters == true)
            {
                cacheTagExtra = this.ExtendsTrait.Id.ToString();
            }

            string  cacheTag         = ctx.Corpus.CreateDefinitionCacheTag(resOpt, this, kind, cacheTagExtra);
            dynamic rtsResultDynamic = null;

            if (cacheTag != null)
            {
                ctx.Cache.TryGetValue(cacheTag, out rtsResultDynamic);
            }
            ResolvedTraitSet rtsResult = rtsResultDynamic as ResolvedTraitSet;

            // store the previous reference symbol set, we will need to add it with
            // children found from the constructResolvedTraits call
            SymbolSet currSymbolRefSet = resOpt.SymbolRefSet;

            if (currSymbolRefSet == null)
            {
                currSymbolRefSet = new SymbolSet();
            }
            resOpt.SymbolRefSet = new SymbolSet();

            // if not, then make one and save it
            if (rtsResult == null)
            {
                GetBaseInfo();
                if (baseTrait != null)
                {
                    // get the resolution of the base class and use the values as a starting point for this trait's values
                    if (!this.HasSetFlags)
                    {
                        // inherit these flags
                        if (this.Elevated == null)
                        {
                            this.Elevated = baseTrait.Elevated;
                        }
                        if (this.Ugly == null)
                        {
                            this.Ugly = baseTrait.Ugly;
                        }
                        if (this.AssociatedProperties == null)
                        {
                            this.AssociatedProperties = baseTrait.AssociatedProperties;
                        }
                    }
                }
                this.HasSetFlags = true;
                ParameterCollection pc     = this.FetchAllParameters(resOpt);
                List <dynamic>      av     = new List <dynamic>();
                List <bool>         wasSet = new List <bool>();
                this.ThisIsKnownToHaveParameters = pc.Sequence.Count > 0;
                for (int i = 0; i < pc.Sequence.Count; i++)
                {
                    // either use the default value or (higher precidence) the value taken from the base reference
                    dynamic value     = (pc.Sequence[i] as CdmParameterDefinition).DefaultValue;
                    dynamic baseValue = null;
                    if (baseValues != null && i < baseValues.Count)
                    {
                        baseValue = baseValues[i];
                        if (baseValue != null)
                        {
                            value = baseValue;
                        }
                    }
                    av.Add(value);
                    wasSet.Add(false);
                }

                // save it
                ResolvedTrait resTrait = new ResolvedTrait(this, pc, av, wasSet);
                rtsResult = new ResolvedTraitSet(resOpt);
                rtsResult.Merge(resTrait, false);

                // register set of possible symbols
                ctx.Corpus.RegisterDefinitionReferenceSymbols(this.FetchObjectDefinition <CdmObjectDefinitionBase>(resOpt), kind, resOpt.SymbolRefSet);
                // get the new cache tag now that we have the list of docs
                cacheTag = ctx.Corpus.CreateDefinitionCacheTag(resOpt, this, kind, cacheTagExtra);
                if (!string.IsNullOrWhiteSpace(cacheTag))
                {
                    ctx.Cache[cacheTag] = rtsResult;
                }
            }
            else
            {
                // cache found
                // get the SymbolSet for this cached object
                string key = CdmCorpusDefinition.CreateCacheKeyFromObject(this, kind);
                ((CdmCorpusDefinition)ctx.Corpus).DefinitionReferenceSymbols.TryGetValue(key, out SymbolSet tempSymbolRefSet);
                resOpt.SymbolRefSet = tempSymbolRefSet;
            }
            // merge child document set with current
            currSymbolRefSet.Merge(resOpt.SymbolRefSet);
            resOpt.SymbolRefSet = currSymbolRefSet;

            return(rtsResult);
        }
Ejemplo n.º 4
0
        internal override ResolvedTraitSet FetchResolvedTraits(ResolveOptions resOpt = null)
        {
            if (resOpt == null)
            {
                resOpt = new ResolveOptions(this);
            }

            if (this.NamedReference != null && this.AppliedTraits == null)
            {
                const string   kind             = "rts";
                ResolveContext ctx              = this.Ctx as ResolveContext;
                string         objDefName       = this.FetchObjectDefinitionName();
                string         cacheTag         = ((CdmCorpusDefinition)ctx.Corpus).CreateDefinitionCacheTag(resOpt, this, kind, "", true);
                dynamic        rtsResultDynamic = null;
                if (cacheTag != null)
                {
                    ctx.Cache.TryGetValue(cacheTag, out rtsResultDynamic);
                }
                ResolvedTraitSet rtsResult = rtsResultDynamic as ResolvedTraitSet;

                // store the previous document set, we will need to add it with
                // children found from the constructResolvedTraits call
                SymbolSet currSymRefSet = resOpt.SymbolRefSet;
                if (currSymRefSet == null)
                {
                    currSymRefSet = new SymbolSet();
                }
                resOpt.SymbolRefSet = new SymbolSet();

                if (rtsResult == null)
                {
                    CdmObjectDefinition objDef = this.FetchObjectDefinition <CdmObjectDefinition>(resOpt);
                    if (objDef != null)
                    {
                        rtsResult = (objDef as CdmObjectDefinitionBase).FetchResolvedTraits(resOpt);
                        if (rtsResult != null)
                        {
                            rtsResult = rtsResult.DeepCopy();
                        }

                        // register set of possible docs
                        ((CdmCorpusDefinition)ctx.Corpus).RegisterDefinitionReferenceSymbols(objDef, kind, resOpt.SymbolRefSet);

                        // get the new cache tag now that we have the list of docs
                        cacheTag = ((CdmCorpusDefinition)ctx.Corpus).CreateDefinitionCacheTag(resOpt, this, kind, "", true);
                        if (!string.IsNullOrWhiteSpace(cacheTag))
                        {
                            ctx.Cache[cacheTag] = rtsResult;
                        }
                    }
                }
                else
                {
                    // cache was found
                    // get the SymbolSet for this cached object
                    string key = CdmCorpusDefinition.CreateCacheKeyFromObject(this, kind);
                    ((CdmCorpusDefinition)ctx.Corpus).DefinitionReferenceSymbols.TryGetValue(key, out SymbolSet tempDocRefSet);
                    resOpt.SymbolRefSet = tempDocRefSet;
                }

                // merge child document set with current
                currSymRefSet.Merge(resOpt.SymbolRefSet);
                resOpt.SymbolRefSet = currSymRefSet;

                return(rtsResult);
            }
            else
            {
                return(base.FetchResolvedTraits(resOpt));
            }
        }