예제 #1
0
파일: UxlParser.cs 프로젝트: mortend/uno
        void ParseType(string elmName, UxlDocument doc)
        {
            SourceValue?typeName = null;
            SourceValue?cond     = null;
            var         elms     = new List <UxlElement>();
            var         def      = false;

            ParseAttributes(
                name =>
            {
                switch (name)
                {
                case "Name":
                    typeName = GetValue();
                    return(true);

                case "Condition":
                    cond = GetValue();
                    return(true);

                case "IsDefault":
                    def = GetBool();
                    return(true);

                default:
                    elms.Add(new UxlElement(UxlElementType.Set, new SourceValue(GetSource(), name), GetValue(), null, false));
                    return(true);
                }
            });

            var result = new UxlType(typeName ?? new SourceValue(), cond, def, elms);

            ParseElements(
                name =>
            {
                switch (name)
                {
                case "Method":
                    ParseMethod(name, result);
                    return(true);

                case "TypeProperty":
                    Log.Warning(GetSource(), ErrorCode.W0000, "<TypeProperty> is deprecated, replace with <Set>");
                    ParseSet(name, result.Elements);
                    return(true);

                default:
                    return(TryParseTypeEntity(name, result));
                }
            });

            if (typeName == null)
            {
                Log.Error(GetSource(), ErrorCode.E0000, "Expected 'Name' attribute on <" + elmName + "> element");
            }
            else
            {
                doc.Types.Add(result);
            }
        }
예제 #2
0
파일: UxlParser.cs 프로젝트: mortend/uno
        void ParseMethod(string elmName, UxlType parent)
        {
            SourceValue?sig  = null;
            SourceValue?cond = null;
            var         elms = new List <UxlElement>();
            var         def  = false;

            ParseAttributes(
                name =>
            {
                switch (name)
                {
                case "Signature":
                    sig = GetValue();
                    return(true);

                case "Condition":
                    cond = GetValue();
                    return(true);

                case "IsDefault":
                    def = GetBool();
                    return(true);

                default:
                    elms.Add(new UxlElement(UxlElementType.Set, new SourceValue(GetSource(), name), GetValue(), null, false));
                    return(true);
                }
            });

            var result = new UxlMethod(sig ?? new SourceValue(), cond, def, elms);

            ParseElements(
                name =>
            {
                switch (name)
                {
                case "Body":
                    ParseImplementation(ImplementationType.Body, result.Implementations);
                    return(true);

                case "EmptyBody":
                    ParseImplementation(ImplementationType.EmptyBody, result.Implementations);
                    return(true);

                case "Expression":
                    ParseImplementation(ImplementationType.Expression, result.Implementations);
                    return(true);

                case "MethodProperty":
                    Log.Warning(GetSource(), ErrorCode.W0000, "<MethodProperty> is deprecated, replace with <Set>");
                    ParseSet(name, result.Elements);
                    return(true);

                default:
                    return(TryParseTypeEntity(name, result));
                }
            });

            if (sig == null)
            {
                Log.Error(GetSource(), ErrorCode.E0000, "Expected 'Signature' attribute on <" + elmName + "> element");
            }
            else
            {
                parent.Methods.Add(result);
            }
        }
예제 #3
0
        void CompileType(UxlType uxl, SourcePackage upk, Namescope[] usings)
        {
            if (!Test(uxl.Condition))
            {
                return;
            }

            var dt = _ilf.GetEntity(uxl.Name.Source, uxl.Name.String, usings) as DataType;

            if (dt == DataType.Invalid)
            {
                return;
            }

            if (dt == null)
            {
                Log.Error(uxl.Name.Source, ErrorCode.E0000, uxl.Name.String.Quote() + " is not a type name");
                return;
            }

            if (!dt.IsIntrinsic &&
                !dt.HasAttribute(_ilf.Essentials.TargetSpecificImplementationAttribute) &&
                !dt.HasAttribute(_ilf.Essentials.TargetSpecificTypeAttribute))
            {
                Log.Error(uxl.Name.Source, ErrorCode.E0000, dt.Quote() + " cannot be extended because it does not specify " + _ilf.Essentials.TargetSpecificImplementationAttribute.AttributeString);
            }

            if (upk != dt.Source.Package)
            {
                Log.Error(uxl.Name.Source, ErrorCode.E0000, dt.Quote() + " cannot be extended from outside its package " + dt.Source.Package.Quote());
            }

            if (!Test(uxl.Condition))
            {
                return;
            }

            var typeScopes = GetTypeScopes(dt, usings);
            var typeExt    = new TypeExtension(uxl.Name.Source, dt, uxl.Disambiguation);

            Apply("Type", dt, typeExt, _root.TypeExtensions);

            foreach (var e in uxl.Methods)
            {
                CompileMethod(e, dt, typeExt, typeScopes);
            }

            foreach (var e in uxl.Elements)
            {
                string key;
                if (!TryGetKey(e, out key) || !Test(e.Condition))
                {
                    continue;
                }

                if (e.Type == UxlElementType.Set && _root.TypePropertyDefinitions.Contains(key))
                {
                    Apply("Set", key, new Element(e.Value.Source, e.Value.String, e.Disambiguation, typeScopes), typeExt.Properties);
                }
                else
                {
                    CompileTypeElement(typeExt, "Type", key, e, typeScopes);
                }
            }

            CompileFiles(typeExt, uxl);
        }