Exemplo n.º 1
0
 public override void Template(TemplateContext context, IGenerationElement concreteElement)
 {
     foreach (var(key, value) in context.TemplateVariables)
     {
         Block = Block.Replace(key, value.GetResultType(context).ToString());
     }
 }
Exemplo n.º 2
0
 public override void Template(TemplateContext context, IGenerationElement concreteElement)
 {
     if (concreteElement == null)
     {
         _cppBlock.Template(context, null);
     }
 }
Exemplo n.º 3
0
 private static void GenerateAndCheck(IGenerationElement element, Context context)
 {
     element.ForwardDeclare(context);
     element.Declare();
     element.Define();
     element.Check(context);
 }
Exemplo n.º 4
0
 public override void Template(TemplateContext context, IGenerationElement concreteElement)
 {
     Object?.Template(context, concreteElement);
     foreach (var i in Parameter)
     {
         i.Template(context, concreteElement);
     }
 }
Exemplo n.º 5
0
        public override void Template(TemplateContext context, IGenerationElement concreteElement)
        {
            _context = context;

            foreach (var i in GetElements())
            {
                i.Template(context, concreteElement);
            }
        }
Exemplo n.º 6
0
        public void AddGlobal(string name, IGenerationElement element)
        {
            var current = this;

            while (current.UpperContext != null)
            {
                current = current.UpperContext;
            }

            Add(name, element, current._symbols);
        }
Exemplo n.º 7
0
        public override void Template(TemplateContext context, IGenerationElement concreteElement)
        {
            if (concreteElement != null)
            {
                throw new TemplateGenerationException(this, $"Can not template {this} from {concreteElement}");
            }

            if (context.TemplateVariables.ContainsKey(Name))
            {
                Name = context.TemplateVariables[Name].GetResultType(context).ToString();
            }
        }
Exemplo n.º 8
0
        public override void Template(TemplateContext context, IGenerationElement concreteElement)
        {
            _context = context;

            Type.Template(context, concreteElement);

            SingleParameter?.Template(context, concreteElement);

            foreach (var i in Parameter)
            {
                i.Value.Template(context, concreteElement);
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
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);
                }
Exemplo n.º 12
0
        public override void Template(TemplateContext context, IGenerationElement concreteElement)
        {
            Condition.Template(context, concreteElement);

            foreach (var i in Then)
            {
                i.Template(context, concreteElement);
            }

            if (Else != null)
            {
                foreach (var i in Else)
                {
                    i.Template(context, concreteElement);
                }
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Tries to generate the template function.
 /// </summary>
 /// <param name="concreteElement">The function call, that initially created the </param>
 /// <returns>true, if the template was properly created and also valid in the given context, false otherwise.</returns>
 public bool Generate(IGenerationElement concreteElement)
 {
     try
     {
         Element.Template(this, concreteElement);
         Element.Declare();
         Element.Define();
         Element.Check(this);
         AddGlobal(Element.Name, Element);
         _logger.Debug($"Template {Element} generated from {_generator}");
         return(true);
     }
     catch (Exception e)
     {
         _logger.Debug($"Template {Element} failed for {concreteElement}");
         _logger.Debug(e);
         Element.Remove();
         return(false);
     }
 }
Exemplo n.º 14
0
        public override void Template(TemplateContext context, IGenerationElement concreteElement)
        {
            if (concreteElement == null)
            {
                var tmp1 = context.LookupTemplateType(this);
                Name         = tmp1.Name;
                TemplateList = tmp1.TemplateList;
                return;
            }

            // get the resulting type of the concrete element
            var concreteSimpleType = concreteElement.GetResultType(context.CallerContext);

            if (concreteSimpleType == null)
            {
                throw new TemplateGenerationException(this, $"Could not get the result type of {concreteElement}");
            }

            // check the template list of both types
            if (TemplateList == null)
            {
                if (concreteSimpleType.TemplateList != null)
                {
                    throw new TemplateGenerationException(this, $"Expected an empty template list ({this}), but got {concreteSimpleType}");
                }
            }
            // if the concrete type has a template list, we have to check if it fits to the template type template list
            else if (!TemplateList.Equals(concreteSimpleType.TemplateList))
            {
                throw new TemplateGenerationException(this, $"Expected the template list to be {TemplateList} but got {concreteSimpleType.TemplateList}");
            }

            TemplateList?.Template(context, concreteSimpleType.TemplateList);

            var tmp2 = context.RegisterTemplateType(this, concreteSimpleType);

            Name         = tmp2.Name;
            TemplateList = tmp2.TemplateList;
        }
Exemplo n.º 15
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]);
            }
        }
Exemplo n.º 16
0
 public override void Template(TemplateContext context, IGenerationElement concreteElement)
 {
     Expression.Template(context, concreteElement);
 }
Exemplo n.º 17
0
 public void Add(string name, IGenerationElement element)
 {
     Add(name, element, _symbols);
 }
Exemplo n.º 18
0
 public override void Template(TemplateContext context, IGenerationElement concreteElement)
 {
     Left.Template(context, concreteElement);
     Right.Template(context, concreteElement);
 }
Exemplo n.º 19
0
 public TemplateGenerationException(IGenerationElement element, string message)
     : base(element, $"Could not instantiate template for {element.Name}: {message}")
 {
 }
Exemplo n.º 20
0
 public override void Template(TemplateContext context, IGenerationElement concreteElement)
 {
     Type.Template(context, concreteElement);
     ForwardDeclare(context);
 }
Exemplo n.º 21
0
 public virtual void Template(TemplateContext context, IGenerationElement concreteElement)
 {
 }
Exemplo n.º 22
0
 public Context(Context upperContext, IGenerationElement element)
     : this(upperContext, element, new Dictionary <string, IGenerationElement>())
 {
 }
Exemplo n.º 23
0
 public Context(Context upperContext, IGenerationElement element, IDictionary <string, IGenerationElement> symbols)
 {
     UpperContext = upperContext;
     Element      = element;
     _symbols     = new Dictionary <string, IGenerationElement>(symbols);
 }
Exemplo n.º 24
0
 public override void Template(TemplateContext context, IGenerationElement concreteElement)
 {
     _context = context;
     Value.Template(context, concreteElement);
 }