void EmitProperties(Scope scope, UXIL.Node n) { if (n is UXIL.BoxedValueNode || n is UXIL.NewObjectNode) { EmitAtomicPropertyValues(scope, n); EmitEventHandlers(scope, n); } foreach (var dp in n.DelegatePropertiesWithValues) { EmitAssign(scope, n, (Reflection.IMutableProperty)dp.Facet, dp.Method); } foreach (var rp in n.MutableReferencePropertiesWithValues) { var s = rp.Source as ReferenceSource; if (s != null) { var value = ReferenceSourceToString(scope, s); EmitAssign(scope, n, (Reflection.IMutableProperty)rp.Facet, value); } } foreach (var lp in n.ListPropertiesWithValues) { foreach (var s in lp.Sources.OfType <ReferenceSource>()) { EmitAddToList(scope, n, lp, ReferenceSourceToString(scope, s)); } } }
string GetUnique(UXIL.Node n, string baseId, Node pathOrigin) { var id = baseId; if ((n.InstanceType == InstanceType.Local || n.InstanceType == InstanceType.None) && !DocumentScope.ContainsNode(n) && (pathOrigin != null)) { var ps = pathOrigin.ParentScope; if (n == ps && ps is TemplateNode) { return("__parentInstance"); } var prefix = "__parent"; while (ps != null) { if (n == ps) { return(prefix); } if (ps.ContainsNode(n)) { return(prefix + "." + id); } ps = ps.ParentScope; prefix = prefix + ".__parent"; } throw new Exception(id + " cannot be accessed from this scope"); } var c = 0; while (true) { if (!_identifiers.ContainsIdentifier(id) && !reservedWords.Contains(id) && (id != DocumentScope.GeneratedClassName.Surname)) { if (_identifiers.ContainsNode(n)) { return(_identifiers.Get(n)); } _identifiers.Add(n, id); return(id); } c++; id = baseId + c; } }
void EmitEventHandlers(Scope scope, UXIL.Node node) { foreach (var e in node.EventsWithHandler) { if (e.Facet is Reflection.IRegularEvent) { Emit(scope.GetUniqueIdentifier(node) + "." + e.Facet.Name + " += " + EventHandlerToString(scope, e.Handler) + ";"); } else if (e.Facet is Reflection.IAttachedEvent) { var iae = (Reflection.IAttachedEvent)e.Facet; Emit("global::" + iae.DeclaringType.FullName + "." + iae.AddMethodName + "(" + scope.GetUniqueIdentifier(node) + ", " + EventHandlerToString(scope, e.Handler) + ");"); } } }
string GetUniqueNodeName(UXIL.Node template, string baseId) { var id = baseId; var c = 0; while (true) { if (IsIdentifierUnused(id)) { _templateIdentifiers.Add(template, id); return(id); } c++; id = baseId + c; } }
void EmitAssign(Scope scope, UXIL.Node on, Reflection.IMutableProperty p, string value) { if (p is Reflection.IAttachedProperty) { var iap = (Reflection.IAttachedProperty)p; if (iap.CanSet) { Emit("global::" + iap.DeclaringType.FullName + "." + iap.SetMethodName + "(" + scope.GetUniqueIdentifier(on) + ", " + value + ");"); } else { ReportError(on, "Property '" + iap.Name + "' is read-only"); } } else { Emit(scope.GetUniqueIdentifier(on) + "." + p.Name + " = " + value + ";"); } }
void EmitAtomicPropertyValues(Scope scope, UXIL.Node on) { foreach (var p in on.MutableAtomicPropertiesWithValues) { if (p.Value is ReferenceValue) { EmitAssign(scope, on, (Reflection.IMutableProperty)p.Facet, ReferenceSourceToString(scope, (p.Value as ReferenceValue).Value)); } else { if (p.Value is Selector) { var handle = scope.Register((Selector)p.Value); EmitAssign(scope, on, (Reflection.IMutableProperty)p.Facet, handle); } else { EmitAssign(scope, on, (Reflection.IMutableProperty)p.Facet, p.Value.ToLiteral()); } } } }
public string GetUniqueIdentifier(UXIL.Node n, Node pathOrigin = null) { if (n == DocumentScope) { return(Self); } var on = n as PropertyNode; if (@on?.Name != null) { return(on.Name); } if (n is UXIL.ResourceRefNode) { return(((UXIL.ResourceRefNode)n).StaticRefId); } if (_identifiers.ContainsNode(n)) { if (pathOrigin != null) { return(GetUnique(n, n.Name.ToIdentifier(), pathOrigin)); } return(_identifiers.Get(n)); } if (n.Name == null) { return(GetUnique(n, "temp", null)); } else { return(GetUnique(n, n.Name.ToIdentifier(), pathOrigin)); } }
void EmitAddToList(Scope scope, UXIL.Node parent, UXIL.ListProperty prop, string value) { var facet = prop.Facet as Markup.Reflection.IMutableProperty; Emit(scope.GetUniqueIdentifier(parent) + "." + prop.Facet.Name + ".Add(" + value + ");"); }
void ReportWarning(UXIL.Node node, string message) { _log.ReportWarning(node.Source.FileName, node.Source.LineNumber, message); }