Esempio n. 1
0
        private void Add(string name, IGenerationElement element, IDictionary <string, IGenerationElement> symbols)
        {
            var current = Get(name);

            if (current != null &&
                current.GetType() == element.GetType())
            {
                if (current is Function extensionFunction &&
                    element is Function overload)
                {
                    extensionFunction.AddOverload(overload);
                }
                else if (current is Class c &&
                         element is Class variant)
                {
                    c.AddVariant(variant);
                }
Esempio n. 2
0
        public override void Template(TemplateContext context, IGenerationElement concreteElement)
        {
            var templateList = concreteElement as TemplateList;

            if (templateList == null)
            {
                throw new TemplateGenerationException(concreteElement,
                                                      $"TemplateList got {concreteElement.GetType().Name} as concrete element, expected TemplateList");
            }

            if (templateList.Types.Count != Types.Count)
            {
                throw new TemplateGenerationException(concreteElement,
                                                      $"Concrete TemplateList has {Types.Count} template parameter, expected {templateList.Types.Count}");
            }

            for (var i = 0; i < templateList.Types.Count; ++i)
            {
                var j = i;
                Types[i] = context.RegisterTemplateType(Types[j], templateList.Types[i]);
            }
        }
Esempio n. 3
0
        public override void Template(TemplateContext context, IGenerationElement concreteElement)
        {
            if (!(concreteElement is FunctionCall functionCall))
            {
                throw new TemplateGenerationException(this, $"Can not create a function from a {concreteElement.GetType().Name}");
            }

            Context = context;

            if (ExtensionBase != null)
            {
                AddThisPointer();
            }

            if (functionCall.Object != null)
            {
                var functionCallExtensionBase = functionCall.Object.GetResultType(context.CallerContext);

                if (ExtensionBase == null)
                {
                    throw new TemplateGenerationException(this, "Generated function has no extension base, " +
                                                          $"but the function call has the extension base {functionCallExtensionBase}");
                }

                ExtensionBase.Template(context, functionCallExtensionBase);
            }
            else if (ExtensionBase != null)
            {
                throw new TemplateGenerationException(this, $"Generated function has the extension base {ExtensionBase}," +
                                                      " but the function call has no extension base");
            }

            if (functionCall.Parameter.Count != Parameter.Count)
            {
                throw new TemplateGenerationException(this, $"Expected {functionCall.Parameter.Count} parameters, got {Parameter.Count}");
            }

            for (var i = 0; i < functionCall.Parameter.Count; ++i)
            {
                Parameter[i].Template(context, functionCall.Parameter[i].GetResultType(context.CallerContext));
            }

            ReturnType.Template(context, null);

            foreach (var i in Body)
            {
                i.Template(context, null);
            }
        }
Esempio n. 4
0
        public override void Template(TemplateContext context, IGenerationElement concreteElement)
        {
            if (!(concreteElement is SimpleType type))
            {
                throw new TemplateGenerationException(this, $"Can not create a class from a {concreteElement.GetType().Name}");
            }

            _context = context;

            Type.Template(context, type);

            foreach (var i in GetElements())
            {
                i.Template(context, null);
            }
        }