public static FunctionDeclaration FuncFromXElement(XElement elem, ModuleDeclaration module, BaseDeclaration parent)
        {
            FunctionDeclaration decl = new FunctionDeclaration {
                Name              = (string)elem.Attribute("name"),
                Module            = module,
                Parent            = parent,
                Access            = TypeDeclaration.AccessibilityFromString((string)elem.Attribute("accessibility")),
                ReturnTypeName    = Ex.ThrowOnNull((string)elem.Attribute("returnType"), "returnType"),
                IsProperty        = elem.BoolAttribute("isProperty"),
                IsStatic          = elem.BoolAttribute("isStatic"),
                IsFinal           = elem.BoolAttribute("isFinal"),
                OperatorType      = OperatorTypeFromElement((string)elem.Attribute("operatorKind")),
                HasThrows         = elem.BoolAttribute("hasThrows"),
                IsDeprecated      = elem.BoolAttribute("isDeprecated"),
                IsUnavailable     = elem.BoolAttribute("isUnavailable"),
                IsOptional        = elem.BoolAttribute("isOptional"),
                ObjCSelector      = (string)elem.Attribute("objcSelector"),
                IsRequired        = elem.BoolAttribute("isRequired"),
                IsConvenienceInit = elem.BoolAttribute("isConvenienceInit")
            };

            decl.ParameterLists.AddRange(ParameterItem.ParameterListListFromXElement(elem.Element("parameterlists")));
            if (decl.IsProperty && (decl.IsSetter || decl.IsSubscriptSetter))
            {
                decl.ParameterLists [decl.ParameterLists.Count - 1] =
                    MassageLastPropertySetterParameterList(decl.ParameterLists.Last());
            }
            return(decl);
        }
Exemplo n.º 2
0
        public ShamDeclaration(string fullName, EntityType type)
        {
            fullUnrootedName = fullName;
            Tuple <string, string> modName = fullName.SplitModuleFromName();

            unrootedName = modName.Item2;
            IsUnrooted   = true;
            TypeKind kind = TypeKind.Unknown;

            switch (type)
            {
            case EntityType.Scalar:
                kind = TypeKind.Struct;
                break;

            case EntityType.Class:
                kind = TypeKind.Class;
                break;

            case EntityType.Struct:
                kind = TypeKind.Struct;
                break;

            case EntityType.Enum:
            case EntityType.TrivialEnum:
                kind = TypeKind.Enum;
                break;

            default:
                break;
            }
            Kind        = kind;
            Module      = new ModuleDeclaration();
            Module.Name = modName.Item1;
        }
        public static BaseDeclaration FromXElement(XElement elem, ModuleDeclaration module, BaseDeclaration parent)
        {
            var             generics = GenericDeclaration.FromXElement(elem.Element("genericparameters"));
            BaseDeclaration decl     = null;

            switch (elem.Name.ToString())
            {
            case "func":
                decl = FunctionDeclaration.FuncFromXElement(elem, module, parent);
                break;

            case "typedeclaration":
                decl = TypeDeclaration.TypeFromXElement(elem, module, parent);
                break;

            case "property":
                decl = PropertyDeclaration.PropFromXElement(elem, module, parent);
                break;

            default:
                decl = new BaseDeclaration {
                    Name   = (string)elem.Attribute("name"),
                    Access = TypeDeclaration.AccessibilityFromString((string)elem.Attribute("accessibility"))
                };
                break;
            }
            decl.Generics.AddRange(generics);
            return(decl);
        }
Exemplo n.º 4
0
        public static ExtensionDeclaration FromXElement(XElement elem, ModuleDeclaration module)
        {
            var decl = new ExtensionDeclaration();

            decl.Module = module;
            decl.ExtensionOnTypeName = (string)elem.Attribute("onType");
            if (elem.Element("members") != null)
            {
                var members = from mem in elem.Element("members").Elements()
                              select Member.FromXElement(mem, module, null) as Member;

                decl.Members.AddRange(members);
                foreach (var member in decl.Members)
                {
                    member.ParentExtension = decl;
                }
            }
            if (elem.Element("inherits") != null)
            {
                var inherits = from inherit in elem.Element("inherits").Elements()
                               select SwiftReflector.SwiftXmlReflection.Inheritance.FromXElement(inherit) as Inheritance;

                decl.Inheritance.AddRange(inherits);
            }
            return(decl);
        }
Exemplo n.º 5
0
        static IEnumerable <T> InnerFoo <T> (XElement parent, string innerName, ModuleDeclaration module, BaseDeclaration parDecl) where T : TypeDeclaration
        {
            var inner     = parent.Elements(innerName).SelectMany(el => el.Elements("typedeclaration"));
            var innerList = inner.Select(elem => FromXElement(elem, module, parDecl)).ToList();
            var innerCast = innerList.Cast <T> ().ToList();

            return(innerCast);
        }
Exemplo n.º 6
0
        public static TypeDeclaration TypeFromXElement(XElement elem, ModuleDeclaration module, BaseDeclaration parent /* can be null */)
        {
            var  decl       = FromKind((string)elem.Attribute("kind"));
            bool isUnrooted = elem.Attribute("module") != null;

            decl.Module = module;
            decl.Parent = parent;
            if (isUnrooted)
            {
                decl.IsUnrooted       = true;
                decl.fullUnrootedName = (string)elem.Attribute("name");
                decl.unrootedName     = decl.fullUnrootedName.NameWithoutModule();
                decl.Name             = decl.fullUnrootedName.Contains('.') ? decl.fullUnrootedName.Substring(decl.fullUnrootedName.LastIndexOf('.') + 1)
                                        : decl.fullUnrootedName;
            }
            else
            {
                decl.Name = (string)elem.Attribute("name");
            }
            decl.Access        = AccessibilityFromString((string)elem.Attribute("accessibility"));
            decl.IsObjC        = elem.BoolAttribute("isObjC");
            decl.IsFinal       = elem.BoolAttribute("isFinal");
            decl.IsDeprecated  = elem.BoolAttribute("isDeprecated");
            decl.IsUnavailable = elem.BoolAttribute("isUnavailable");

            decl.InnerClasses.AddRange(InnerFoo <ClassDeclaration> (elem, "innerclasses", module, decl));
            decl.InnerStructs.AddRange(InnerFoo <StructDeclaration> (elem, "innerstructs", module, decl));
            decl.InnerEnums.AddRange(InnerFoo <EnumDeclaration> (elem, "innerenums", module, decl));
            if (elem.Element("members") != null)
            {
                var members = from mem in elem.Element("members").Elements()
                              select Member.FromXElement(mem, module, decl) as Member;

                decl.Members.AddRange(members);
            }
            if (elem.Element("inherits") != null)
            {
                var inherits = from inherit in elem.Element("inherits").Elements()
                               select SwiftReflector.SwiftXmlReflection.Inheritance.FromXElement(inherit) as Inheritance;

                decl.Inheritance.AddRange(inherits);
            }
            EnumDeclaration edecl = decl as EnumDeclaration;

            if (edecl != null)
            {
                var enumElements = (from enumElement in elem.Element("elements").Elements()
                                    select new EnumElement((string)enumElement.Attribute("name"), (string)enumElement.Attribute("type"),
                                                           (long?)enumElement.Attribute("intValue"))).ToList();;
                edecl.Elements.AddRange(enumElements);
                if (elem.Attribute("rawType") != null)
                {
                    edecl.RawTypeName = (string)elem.Attribute("rawType");
                }
            }

            return(decl);
        }
        public ModuleDeclaration MakeUnrooted()
        {
            if (IsUnrooted)
            {
                return(this);
            }
            ModuleDeclaration unrooted = new ModuleDeclaration();

            unrooted.IsUnrooted = true;
            unrooted.Name       = Name;
            return(unrooted);
        }
 public static PropertyDeclaration PropFromXElement(XElement elem, ModuleDeclaration module, BaseDeclaration parent)
 {
     return(new PropertyDeclaration {
         Name = (string)elem.Attribute("name"),
         Module = module,
         Parent = parent,
         Access = TypeDeclaration.AccessibilityFromString((string)elem.Attribute("accessibility")),
         TypeName = (string)elem.Attribute("type"),
         Storage = StorageKindFromString((string)elem.Attribute("storage")),
         IsStatic = elem.BoolAttribute("isStatic"),
         IsLet = elem.BoolAttribute("isLet"),
         IsDeprecated = elem.BoolAttribute("isDeprecated"),
         IsUnavailable = elem.BoolAttribute("isUnavailable"),
         IsOptional = elem.BoolAttribute("isOptional")
     });
 }
Exemplo n.º 9
0
        public static List <ModuleDeclaration> FromXml(XDocument doc)
        {
            var xamreflect = doc.Element("xamreflect");
            var version    = xamreflect.DoubleAttribute("version");

            if (version < kCurrentVersion || version >= kNextMajorVersion)
            {
                throw ErrorHelper.CreateError(ReflectorError.kReflectionErrorBase + 5, $"Unsupported xamreflect version {version}. Current is {kCurrentVersion}");
            }

            try {
                List <ModuleDeclaration> modules = (from module in xamreflect.Descendants("module")
                                                    select ModuleDeclaration.FromXElement(module)).ToList();
                return(modules);
            } catch (Exception e) {
                throw ErrorHelper.CreateError(ReflectorError.kReflectionErrorBase + 6, $"Error while reading XML reflection information: {e.Message}");
            }
        }
        public static ModuleDeclaration FromXElement(XElement elem)
        {
            ModuleDeclaration decl = new ModuleDeclaration {
                Name = (string)elem.Attribute("name"),
                SwiftCompilerVersion = new Version((string)elem.Attribute("swiftVersion") ?? "3.1")
            };

            // non extensions
            foreach (var child in elem.Elements())
            {
                if (child.Name == "extension")
                {
                    decl.Extensions.Add(ExtensionDeclaration.FromXElement(child, decl));
                }
                else
                {
                    decl.Declarations.Add(BaseDeclaration.FromXElement(child, decl, null));
                }
            }
            return(decl);
        }