void FuncReturningFoo(SLType type, SLConstant val) { SLLine line = SLReturn.ReturnLine(val); SLCodeBlock block = new SLCodeBlock(new ICodeElement [] { line }); SLFunc func = new SLFunc(Visibility.Public, type, new SLIdentifier("simpleFunc"), null, block); string code = CodeWriter.WriteToString(func); Compiler.CompileStringUsing(null, XCodeCompiler.SwiftcCustom, code, null); }
public SLDeclaration(bool isLet, SLBinding binding, Visibility vis = Visibility.Private, bool isStatic = false) : base(null, false, true) { IsLet = isLet; IsStatic = isStatic; And(new SimpleElememt(SLFunc.ToVisibilityString(vis))).And(SimpleElememt.Spacer); if (IsStatic) { Add(new SimpleElememt("static ", true)); } And(new SimpleElememt(isLet ? "let" : "var")).And(SimpleElememt.Spacer); Binding = binding; Add(Binding); }
static SLFunc MetadataFuncForType(PlatformName platform, TypeDefinition type, TypeType entityType) { var name = type.Name; var moduleName = type.Namespace; // typename based on C# type name, not remapped name var funcID = new SLIdentifier(FuncIDForTypeDefinition(type)); TypeAggregator.RemapModuleAndName(platform, ref moduleName, ref name, entityType); var value = new SLIdentifier($"{name}.self"); var returnLine = SLReturn.ReturnLine(value); var body = new SLCodeBlock(null); body.Add(returnLine); var func = new SLFunc(Visibility.Public, new SLSimpleType("Any.Type"), funcID, null, body); new SLComment(type.FullName, true).AttachBefore(func); var attr = AvailableAttributeForType(platform, type); if (attr != null) { attr.AttachBefore(func); } return(func); }