예제 #1
0
파일: Context.cs 프로젝트: Creepsky/Nexus
        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);
                }
예제 #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]);
            }
        }
예제 #3
0
파일: Function.cs 프로젝트: Creepsky/Nexus
        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);
            }
        }
예제 #4
0
파일: Class.cs 프로젝트: Creepsky/Nexus
        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);
            }
        }