コード例 #1
0
 public override void GenerateCode(CodeGenerationContext ctx, TextWriter writer)
 {
     ctx.WriteHeaders (Headers, writer, false, this is ConstantDeclaration);
     var bak = ctx.KnownLValueType;
     foreach (var ntv in NameTypeValues) {
         // because AS3 variable types could differ within a line (unlike C#), they have to be declared in split form (or I have to do something more complicated.)
         if (this is ConstantDeclaration)
             writer.Write ("const ");
         if (ntv.Type != null)
             writer.Write (ntv.Type.ToCSharp ());
         else if (ntv.Value != null)
             writer.Write ("var");
         else
             writer.Write ("dynamic");
         ctx.KnownLValueType = ntv.Type;
         writer.Write (' ');
         writer.Write (ctx.SafeName (ntv.Name));
         if (ntv.Value != null) {
             writer.Write (" = ");
             ntv.Value.GenerateCode (ctx, writer);
         }
         writer.WriteLine (';');
         ctx.KnownLValueType = null;
     }
     ctx.KnownLValueType = bak;
 }
コード例 #2
0
 internal void OnGenerateCode(CodeGenerationContext ctx, TextWriter writer, bool returnVoid, string namePrefix)
 {
     // looks like only constructors have no return type.
     // Body is checked to distinguish class and interface.
     bool isInterface = Definition.Body == null;
     ctx.WriteHeaders (Headers, writer, Definition.ReturnTypeName != null && !isInterface, false);
     Definition.OnGenerateCode (ctx, writer, returnVoid, namePrefix);
     writer.WriteLine ();
 }
コード例 #3
0
        public void GenerateCode(CodeGenerationContext ctx, TextWriter writer)
        {
            var parentClassWriter = ctx.CurrentClassWriter;
            var sw = new StringWriter ();
            ctx.CurrentClassWriter = sw;
            var parentType = ctx.CurrentType;
            ctx.CurrentType = this;

            writer.WriteLine ("// class {0}", Name);
            foreach (var ev in Events)
                ev.GenerateCode (ctx, writer);
            ctx.WriteHeaders (Headers, writer, false, false);
            writer.WriteLine ("partial {3} {0}{1}{2}", Name, BaseClassName != null ? " : " : /*" : global::Object"*/String.Empty, BaseClassName, IsInterface ? "interface" : "class");
            writer.WriteLine ("{");
            foreach (var nsuse in NamespaceUses) {
                writer.WriteLine ("// FIXME: using directive inside class declaration is not allowed in C#");
                writer.WriteLine ("// using {0};", nsuse.Name);
            }
            foreach (var item in Members)
                item.GenerateCode (ctx, writer);

            // output temporarily saved members (such as local functions)
            writer.Write (sw.ToString ());

            writer.WriteLine ("}");
            writer.WriteLine ("// end of class {0}", Name);

            ctx.CurrentType = parentType;
            ctx.CurrentClassWriter = parentClassWriter;
        }