public void TestForFinality() { string simpleClass = "public class Garble { public final func finalmethod() { }; public func virtmethod() { } }"; using (DisposableTempFile montyLib = new DisposableTempFile("libXython.dylib", false)) { Compiler.CompileStringToFileUsing(null, XCodeCompiler.SwiftcCustom, simpleClass, " -emit-library -module-name Xython", montyLib); var errors = new ErrorHandling(); ModuleInventory inventory = ModuleInventory.FromFile(montyLib.Filename, errors); Utils.CheckErrors(errors); ClassContents cl = inventory.ClassesForName(new SwiftName("Xython", false)).FirstOrDefault(); Assert.IsNotNull(cl); if (cl.WitnessTable == null || cl.WitnessTable.MangledNames == null || cl.WitnessTable.MangledNames.Count() == 0) { return; } foreach (var oi in cl.Methods.Values) { foreach (TLFunction f in oi.Functions) { if (f.MangledName.Contains("finalmethod")) { Assert.IsTrue(cl.IsFinal(f)); } else if (f.MangledName.Contains("virtmethod")) { Assert.IsFalse(cl.IsFinal(f)); } } } } }
public static TLFunction ToTLFunction(FunctionDeclaration decl, ClassContents classContents, TypeMapper typeMap) { string name = decl.IsProperty ? decl.PropertyName : decl.Name; var funcsToSearch = FuncsToSearch(classContents, decl, name); //decl.ParameterLists.Count == 2 ? classContents.Methods.MethodsWithName (decl.Name) //: classContents.StaticFunctions.MethodsWithName (decl.Name); return(MatchFunctionDecl(decl, funcsToSearch, typeMap)); }
public void SimpleConstructor() { string swiftcode = "public class None { public init() { } }"; using (Stream stm = Compiler.CompileStringUsing(null, XCodeCompiler.SwiftcCustom, swiftcode, "")) { var errors = new ErrorHandling(); ModuleInventory inventory = ModuleInventory.FromStream(stm, errors); Utils.CheckErrors(errors); Assert.AreEqual(1, inventory.Classes.Count()); ClassContents cl = inventory.Classes.First(); Assert.AreEqual("noname.None", cl.Name.ToFullyQualifiedName()); Assert.AreEqual(2, cl.Constructors.Values.Count()); } }
static List <TLFunction> FuncsToSearch(ClassContents theClass, FunctionDeclaration decl, string name) { List <TLFunction> funcs = null; if (theClass == null) { funcs = new List <TLFunction> (); } else { if (decl.IsProperty) { funcs = new List <TLFunction> (); if (decl.IsSubscript) { funcs.AddRange(theClass.Subscripts); } else { foreach (var pc in theClass.AllPropertiesWithName(name)) { var propType = pc.TLFGetter.Signature as SwiftPropertyType; if (propType == null) // should never happen, but... { continue; } if (propType.IsStatic != decl.IsStatic) { continue; } if (decl.IsGetter) { funcs.Add(pc.TLFGetter); } else if (decl.IsSetter && pc.TLFSetter != null) { funcs.Add(pc.TLFSetter); } else if (decl.IsMaterializer && pc.TLFMaterializer != null) { funcs.Add(pc.TLFMaterializer); } } } } else if (decl.IsConstructor) { funcs = theClass.Constructors.AllocatingConstructors(); } else if (decl.IsDestructor) { funcs = theClass.Destructors.DeallocatingDestructors(); } else { if (decl.IsStatic) { funcs = theClass.StaticFunctions.MethodsWithName(name); } else { funcs = theClass.Methods.MethodsWithName(name); } } } return(funcs); }