public override void Template(TemplateContext context, IGenerationElement concreteElement) { foreach (var(key, value) in context.TemplateVariables) { Block = Block.Replace(key, value.GetResultType(context).ToString()); } }
public override void Template(TemplateContext context, IGenerationElement concreteElement) { if (concreteElement == null) { _cppBlock.Template(context, null); } }
private static void GenerateAndCheck(IGenerationElement element, Context context) { element.ForwardDeclare(context); element.Declare(); element.Define(); element.Check(context); }
public override void Template(TemplateContext context, IGenerationElement concreteElement) { Object?.Template(context, concreteElement); foreach (var i in Parameter) { i.Template(context, concreteElement); } }
public override void Template(TemplateContext context, IGenerationElement concreteElement) { _context = context; foreach (var i in GetElements()) { i.Template(context, concreteElement); } }
public void AddGlobal(string name, IGenerationElement element) { var current = this; while (current.UpperContext != null) { current = current.UpperContext; } Add(name, element, current._symbols); }
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(); } }
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); } }
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); } }
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); } }
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); }
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); } } }
/// <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); } }
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; }
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]); } }
public override void Template(TemplateContext context, IGenerationElement concreteElement) { Expression.Template(context, concreteElement); }
public void Add(string name, IGenerationElement element) { Add(name, element, _symbols); }
public override void Template(TemplateContext context, IGenerationElement concreteElement) { Left.Template(context, concreteElement); Right.Template(context, concreteElement); }
public TemplateGenerationException(IGenerationElement element, string message) : base(element, $"Could not instantiate template for {element.Name}: {message}") { }
public override void Template(TemplateContext context, IGenerationElement concreteElement) { Type.Template(context, concreteElement); ForwardDeclare(context); }
public virtual void Template(TemplateContext context, IGenerationElement concreteElement) { }
public Context(Context upperContext, IGenerationElement element) : this(upperContext, element, new Dictionary <string, IGenerationElement>()) { }
public Context(Context upperContext, IGenerationElement element, IDictionary <string, IGenerationElement> symbols) { UpperContext = upperContext; Element = element; _symbols = new Dictionary <string, IGenerationElement>(symbols); }
public override void Template(TemplateContext context, IGenerationElement concreteElement) { _context = context; Value.Template(context, concreteElement); }