コード例 #1
0
 JsStatement ExportDescription(string Description)
 {
     if (String.IsNullOrEmpty(Description))
     {
         return(null);
     }
     string[] lines = Description.Split('\n');
     if (lines.Length > 0)
     {
         var sb = new StringBuilder();
         sb.AppendLine("/// <summary>");
         foreach (string l in lines)
         {
             sb.AppendLine("/// " + l.Replace("\r", ""));
         }
         sb.AppendLine("/// </summary>");
         return(Js.CodeStatement(sb.ToString()));
     }
     return(null);
 }
コード例 #2
0
        JsUnit ConvertTypeDefinition(ITypeDefinition ce)
        {
            var unit = new JsUnit {
                Statements = new List <JsStatement>()
            };

            var att = ce.GetJsTypeAttribute();

            if (att != null && att.PreCode != null)
            {
                unit.Statements.Add(Js.CodeStatement(att.PreCode));
            }

            var isGlobal = att != null && att.GlobalObject;
            var isNative = att != null && att.Native;
            var isClr    = !isGlobal && !isNative;


            var mc    = GetMemberConverter(ce);
            var unit2 = (JsUnit)mc.Visit(ce);

            if (unit2 != null && unit2.Statements.IsNotNullOrEmpty())
            {
                unit.Statements.AddRange(unit2.Statements);
            }
            else
            {
                Log.Warn(ce, "No code was generated for type: " + ce.FullName);
            }

            if (att != null && att.PostCode != null)
            {
                unit.Statements.Add(Js.CodeStatement(att.PostCode));
            }
            return(unit);
        }
コード例 #3
0
        protected JsBlock ExportMethodBody(IMethod me)
        {
            if (CompilerConfiguration.Current.EnableLogging)
            {
                Log.Debug("JsTypeImporter: Visit Method: " + me.ToString());
            }
            var nativeCode = Sk.GetNativeCode(me);

            if (nativeCode != null)
            {
                var block = Js.Block().Add(Js.CodeStatement(nativeCode)); //TODO: double semicolon?
                return(block);
            }
            var def = me.GetDefinition();

            if (def == null || def.IsNull)
            {
                if (me.IsAutomaticEventAccessor())
                {
                    if (me.IsEventAddAccessor())
                    {
                        var node = GenerateAutomaticEventAccessor((IEvent)me.GetOwner(), false);
                        return(node.Block);
                    }
                    else if (me.IsEventRemoveAccessor())
                    {
                        var node = GenerateAutomaticEventAccessor((IEvent)me.GetOwner(), true);
                        return(node.Block);
                    }
                }
                else if (me.IsAutomaticPropertyAccessor())
                {
                    var bf = Js.Member(AutoPropertyPrefix + SkJs.GetEntityJsName(me.AccessorOwner));
                    if (!me.IsStatic)
                    {
                        bf.PreviousMember = Js.This();
                    }
                    else if (!Sk.IsGlobalMethod(me))
                    {
                        bf.PreviousMember = SkJs.EntityToMember(me.DeclaringTypeDefinition);
                    }
                    if (me.IsGetter())
                    {
                        return(Js.Block().Add(Js.Return(bf)));
                    }
                    else
                    {
                        return(Js.Block().Add(bf.Assign(Js.Member("value")).Statement()));
                    }
                }
                return(null);
            }
            var block2 = (JsBlock)AstNodeConverter.Visit(def);

            block2.ContainsYield = false;
            if (def.Descendants.OfType <YieldReturnStatement>().FirstOrDefault() != null)
            {
                block2.ContainsYield = true;
                if (!AstNodeConverter.SupportClrYield)
                {
                    if (block2.Statements == null)
                    {
                        block2.Statements = new List <JsStatement>();
                    }
                    //block2.Statements.Insert(0, Js.Var("$yield", Js.NewJsonArray()).Statement());
                    //block2.Statements.Add(AstNodeConverter.GenerateYieldReturnStatement(me));
                }
            }
            return(block2);
        }