Exemplo n.º 1
0
 public bool Accepts(Reflection.IDataType dt)
 {
     if (PropertyType == Reflection.PropertyType.List)
     {
         var listElmType = GetListElementType(UnoType);
         return(((DataTypeReflector)dt.ActualIDataTypeImpl).UnoDataType.IsCompatibleWith(listElmType));
     }
     else if (PropertyType == Reflection.PropertyType.Reference || PropertyType == Reflection.PropertyType.Atomic)
     {
         return(((DataTypeReflector)dt.ActualIDataTypeImpl).UnoDataType.IsCompatibleWith(UnoType));
     }
     else
     {
         throw new Exception();
     }
 }
Exemplo n.º 2
0
        static AtomicValue ParseArbitraryValue(string s, Reflection.IDataType dt, FileSourceInfo src)
        {
            if (s.StartsWith('\'') && s.EndsWith('\''))
            {
                return(new String(s.Trim('\''), src));
            }
            if (s.StartsWith('"') && s.EndsWith('"'))
            {
                return(new String(s.Trim('"'), src));
            }
            if (s == "true")
            {
                return(new Bool(true, src));
            }
            if (s == "false")
            {
                return(new Bool(false, src));
            }
            var p = s.Split(',');

            if (p.Length > 1)
            {
                return(AtomicValueParser.ParseFloatVector <Single>(s, p.Length, src));
            }
            if (s.Contains("#"))
            {
                return(AtomicValueParser.ParseHexVector <float>(s, 4, src));
            }
            if (s.Contains("px") || s.Contains("%") || s.Contains("pt"))
            {
                if (p.Length == 2)
                {
                    return(AtomicValueParser.ParseSize2(s, src));
                }
                else
                {
                    return(AtomicValueParser.ParseSize(s, src));
                }
            }
            if (char.IsLetter(s[0]))
            {
                return(new GlobalReferenceValue(s, dt, src));
            }

            return(AtomicValueParser.ParseFloat <Double>(s, src));
        }
Exemplo n.º 3
0
        string GetDependenciesArgString(Reflection.IDataType cn, bool prefixes)
        {
            var deps = cn.Properties.Where(x => x.IsConstructorArgument && x.DeclaringType == cn).ToArray();

            var s = "";

            for (int i = 0; i < deps.Length; i++)
            {
                if (i > 0)
                {
                    s += ", ";
                }
                if (prefixes)
                {
                    s += "\n\t\t[global::Uno.UX.UXParameter(\"" + deps[i].Name + "\")] " + deps[i].DataType.FullName + " ";
                }
                s += deps[i].Name;
            }
            return(s);
        }
Exemplo n.º 4
0
 public GlobalReferenceValue(string identifier, Reflection.IDataType dt, FileSourceInfo src) : base(src)
 {
     Identifier = identifier;
     DataType   = dt;
 }
Exemplo n.º 5
0
        public AtomicValue Parse(string value, Reflection.IDataType dt, FileSourceInfo src)
        {
            try
            {
                if (dt is Reflection.IEnum)
                {
                    return(ParseEnum(value, (Reflection.IEnum)dt, src));
                }

                if (dt.FullName == "string")
                {
                    return(new String(value, src));
                }

                if (dt.FullName == "Uno.UX.Selector")
                {
                    return(new Selector(value, src));
                }

                if (dt.FullName == "bool")
                {
                    return(new Bool(bool.Parse(value.ToLower()), src));
                }

                if (value.Length == 0)
                {
                    throw new Exception("Cannot parse empty string as " + dt.FullName);
                }

                if (char.IsLetter(value[0]))
                {
                    return(new GlobalReferenceValue(value, dt, src));
                }

                switch (dt.FullName)
                {
                case "sbyte": return(Markup.AtomicValueParser.ParseInteger(value, x => sbyte.Parse(value), src));

                case "sbyte2": return(Markup.AtomicValueParser.ParseIntegerVector(value, 2, x => sbyte.Parse(value), src));

                case "sbyte4": return(Markup.AtomicValueParser.ParseIntegerVector(value, 4, x => sbyte.Parse(value), src));

                case "byte": return(Markup.AtomicValueParser.ParseInteger(value, x => byte.Parse(value), src));

                case "byte2": return(Markup.AtomicValueParser.ParseIntegerVector(value, 2, x => byte.Parse(value), src));

                case "byte4": return(Markup.AtomicValueParser.ParseIntegerVector(value, 4, x => byte.Parse(value), src));

                case "short": return(Markup.AtomicValueParser.ParseInteger(value, x => short.Parse(value), src));

                case "short2": return(Markup.AtomicValueParser.ParseIntegerVector(value, 2, x => short.Parse(value), src));

                case "short4": return(Markup.AtomicValueParser.ParseIntegerVector(value, 4, x => short.Parse(value), src));

                case "ushort": return(Markup.AtomicValueParser.ParseInteger(value, x => ushort.Parse(value), src));

                case "ushort2": return(Markup.AtomicValueParser.ParseIntegerVector(value, 2, x => ushort.Parse(value), src));

                case "ushort4": return(Markup.AtomicValueParser.ParseIntegerVector(value, 4, x => ushort.Parse(value), src));

                case "int": return(Markup.AtomicValueParser.ParseInteger(value, x => int.Parse(value), src));

                case "int2": return(Markup.AtomicValueParser.ParseIntegerVector(value, 2, int.Parse, src));

                case "int3": return(Markup.AtomicValueParser.ParseIntegerVector(value, 3, int.Parse, src));

                case "int4": return(Markup.AtomicValueParser.ParseIntegerVector(value, 4, int.Parse, src));

                case "uint": return(Markup.AtomicValueParser.ParseInteger(value, x => uint.Parse(value), src));

                case "long": return(Markup.AtomicValueParser.ParseInteger(value, x => long.Parse(value), src));

                case "ulong": return(Markup.AtomicValueParser.ParseInteger(value, x => ulong.Parse(value), src));

                case "float": return(Markup.AtomicValueParser.ParseFloat <Single>(value, src));

                case "float2": return(Markup.AtomicValueParser.ParseFloatVector <Single>(value, 2, src));

                case "float3": return(Markup.AtomicValueParser.ParseFloatVector <Single>(value, 3, src));

                case "float4": return(Markup.AtomicValueParser.ParseFloatVector <Single>(value, 4, src));

                case "double": return(Markup.AtomicValueParser.ParseFloat <Double>(value, src));

                case "Uno.UX.Size": return(Markup.AtomicValueParser.ParseSize(value, src));

                case "Uno.UX.Size2": return(Markup.AtomicValueParser.ParseSize2(value, src));
                }
            }
            catch (Exception e)
            {
                string msg = "Cannot parse '" + value + "' as '" + dt.FullName + "': '" + e.Message + "'";

                if (value.Length > 0 && char.IsLetter(value[0]))
                {
                    msg += ". Note that value types can not be referenced by name";
                }

                ReportError(src, msg);
                return(null);
            }

            ReportError(src, "Cannot parse unrecognized atomic type: " + dt.FullName);
            return(null);
        }
Exemplo n.º 6
0
        internal Node ResolveNode(FileSourceInfo src, Node owner, string name, Reflection.IDataType targetType, Predicate <Reflection.IDataType> acceptFunction = null, string notAcceptedMessage = null, Predicate <Reflection.IDataType> prioritizeFunction = null)
        {
            if (targetType != null)
            {
                var special = TryResolveSpecialTypes(owner, name, targetType);
                if (special != null)
                {
                    return(special);
                }
            }

            // First priority - nodes in the scope with the given name
            var n = owner.Scope.FindNode(name);

            if (n != null)
            {
                if (acceptFunction == null || acceptFunction(n.DeclaredType))
                {
                    return(n);
                }

                // Ugly hack for allowing circular dependencies between UX and code-behind (needed by fuselibs' ManualTestApp -- remove once we've cleaned it up)
                if (targetType.FullName == n.DeclaredType.FullName)
                {
                    return(n);
                }

                ReportError(src, "The node '" + name + "' can not be used here: " + notAcceptedMessage);
                return(null);
            }

            // Second priority - global resources
            var resources = _globalResourceCache.TryFindNode(name);

            var acceptable = new List <Node>();



            if (resources != null)
            {
                foreach (var r in resources)
                {
                    if (acceptFunction == null || acceptFunction(r.ResultingType))
                    {
                        acceptable.Add(r);
                    }
                }

                // Prioritized project-local resources
                // to avoid aliasing with symbols from generated code
                if (acceptable.Count > 1)
                {
                    var filtered = acceptable.Where(x => x is BoxedValueNode).ToArray();
                    if (filtered.Count() > 0)
                    {
                        acceptable.Clear();
                        acceptable.AddRange(filtered);
                    }
                }

                if (acceptable.Count > 1)
                {
                    var filtered = acceptable.Where(x => x is NewObjectNode).ToArray();
                    if (filtered.Count() > 0)
                    {
                        acceptable.Clear();
                        acceptable.AddRange(filtered);
                    }
                }

                if (acceptable.Count == 0)
                {
                    if (!resources.Any())
                    {
                        var m = "";
                        foreach (var g in _nodes.Values)
                        {
                            if (g.Name == name)
                            {
                                if (g.ContainingClass.GeneratedClassName.FullName != owner.ContainingClass.GeneratedClassName.FullName)
                                {
                                    ReportError(src, "'" + name + "' declared in " + Path.GetFileName(g.Source.FileName) + "(" + g.Source.LineNumber + ") is a member of '" + g.ContainingClass.GeneratedClassName.FullName + "' and cannot be accessed from '" + owner.ContainingClass.GeneratedClassName.FullName + "'. To make this work, consider making '" + owner.ContainingClass.GeneratedClassName.FullName + "' an ux:InnerClass of '" + g.ContainingClass.GeneratedClassName.FullName + "'.");
                                    return(null);
                                }
                                else
                                {
                                    ReportError(src, "'" + name + "' declared in " + Path.GetFileName(g.Source.FileName) + "(" + g.Source.LineNumber + ") cannot be accessed from this scope.");
                                }
                            }
                        }

                        ReportError(src, "There is nothing named '" + name + "' in this scope, and no global resources with that alias. " + m);
                        return(null);
                    }

                    var msg = "";
                    foreach (var r in resources)
                    {
                        msg += "'" + NodeToPath(r) + "' is of type '" + r.ResultingType.FullName + "'. ";

                        if (acceptFunction == null || acceptFunction(r.ResultingType))
                        {
                            acceptable.Add(r);
                        }
                    }

                    ReportError(src, "There is nothing named '" + name + "' in this scope, and none of the global resources with alias '" + name + "' can be used here: " + notAcceptedMessage + ". " + msg);
                    return(null);
                }
                else if (acceptable.Count > 1)
                {
                    if (prioritizeFunction != null)
                    {
                        var prioritized = acceptable.Where(x => prioritizeFunction(x.DeclaredType)).ToArray();
                        if (prioritized.Length == 1)
                        {
                            return(prioritized[0]);
                        }
                    }

                    ReportError(src, "Multiple global resources with alias '" + name + "' can be used here, please qualify with full name: " + acceptable.Select(NodeToPath).Aggregate((x, y) => x + ", " + y));
                    return(null);
                }
                else
                {
                    return(acceptable[0]);
                }
            }

            ReportError(src, "'" + name + "' could not be found. It is not an ux:Name in this scope nor a global resource");
            return(null);
        }
Exemplo n.º 7
0
        void ParseGenericAtomic(Node owner, AtomicProperty p, string value, FileSourceInfo src, Reflection.IDataType optionalType)
        {
            var dt = optionalType ?? p.Facet.DataType;

            if (dt.IsValueType || dt.IsString || dt.FullName == "Uno.UX.Value")
            {
                p.Value = Parse(value, dt, src);
            }
            else
            {
                p.Value = new ReferenceValue(src, new NodeSource(ResolveNode(src, owner, value, dt)));
            }
        }
Exemplo n.º 8
0
        string Instantiation(Scope scope, Node src, Reflection.IDataType dataType, IEnumerable <Property> properties)
        {
            var args = dataType.Properties.Where(x => x.IsConstructorArgument);

            if (args.Any())
            {
                var mp = new List <string>();
                foreach (var arg in args)
                {
                    var p = properties.FirstOrDefault(x => x.Facet == arg);

                    if (p is AtomicProperty)
                    {
                        var ap = (AtomicProperty)p;
                        if (ap.Value != null) // Assume error message is already generated. If null, this is a ux:Dependency
                        {
                            if (ap.Value is ReferenceValue)
                            {
                                mp.Add(ReferenceSourceToString(scope, (ap.Value as ReferenceValue).Value));
                            }
                            else
                            {
                                mp.Add(ap.Value.ToLiteral());
                            }
                        }
                    }
                    else if (p is ReferenceProperty)
                    {
                        var rp = (ReferenceProperty)p;
                        if (rp.Source != null)// Assume error message is already generated. If null, this is a ux:Dependency
                        {
                            mp.Add(ReferenceSourceToString(scope, rp.Source));
                        }
                    }
                    else
                    {
                        throw new Exception("Unhandled constructor argument type: " + p.GetType().FullName);
                    }
                }

                if (mp.Count > 0)
                {
                    return("new global::" + dataType.QualifiedName + "(" + mp.Aggregate((x, y) => x + ", " + y) + ")");
                }
                else
                {
                    return("new global::" + dataType.QualifiedName + "()");
                }
            }
            else
            {
                if (dataType.IsInnerClass)
                {
                    var path = FindParentScopePath(dataType as ClassNode, scope);

                    return("new global::" + dataType.QualifiedName + "(" + path + ")");
                }
                else
                {
                    return("new global::" + dataType.QualifiedName + "()");
                }
            }
        }