コード例 #1
0
        public bool Handle(TemplateParameter parameter, ISemantic argumentToAnalyze)
        {
            // Packages aren't allowed at all
            if (argumentToAnalyze is PackageSymbol)
            {
                return(false);
            }

            // Module symbols can be used as alias only
            if (argumentToAnalyze is ModuleSymbol &&
                !(parameter is TemplateAliasParameter))
            {
                return(false);
            }

            //TODO: Handle __FILE__ and __LINE__ correctly - so don't evaluate them at the template declaration but at the point of instantiation

            /*
             * Introduce previously deduced parameters into current resolution context
             * to allow value parameter to be of e.g. type T whereas T is already set somewhere before
             */
            DeducedTypeDictionary _prefLocalsBackup = null;

            if (ctxt != null && ctxt.CurrentContext != null)
            {
                _prefLocalsBackup = ctxt.CurrentContext.DeducedTemplateParameters;

                var d = new DeducedTypeDictionary();
                foreach (var kv in TargetDictionary)
                {
                    if (kv.Value != null)
                    {
                        d[kv.Key] = kv.Value;
                    }
                }
                ctxt.CurrentContext.DeducedTemplateParameters = d;
            }

            bool res = false;

            if (parameter is TemplateAliasParameter)
            {
                res = Handle((TemplateAliasParameter)parameter, argumentToAnalyze);
            }
            else if (parameter is TemplateThisParameter)
            {
                res = Handle((TemplateThisParameter)parameter, argumentToAnalyze);
            }
            else if (parameter is TemplateTypeParameter)
            {
                res = Handle((TemplateTypeParameter)parameter, argumentToAnalyze);
            }
            else if (parameter is TemplateValueParameter)
            {
                res = Handle((TemplateValueParameter)parameter, argumentToAnalyze);
            }
            else if (parameter is TemplateTupleParameter)
            {
                res = Handle((TemplateTupleParameter)parameter, new[] { argumentToAnalyze });
            }

            if (ctxt != null && ctxt.CurrentContext != null)
            {
                ctxt.CurrentContext.DeducedTemplateParameters = _prefLocalsBackup;
            }

            return(res);
        }
コード例 #2
0
 public TemplateParameterDeduction(DeducedTypeDictionary DeducedParameters, ResolutionContext ctxt)
 {
     this.ctxt             = ctxt;
     this.TargetDictionary = DeducedParameters;
 }