示例#1
0
 public override void Append(CSTWriter w)
 {
     Array.Append(w, 1);
     w.Append('[');
     Index.Append(w, 0);
     w.Append(']');
 }
示例#2
0
        public override void AppendModifiers(CSTWriter w)
        {
            switch (CodeFlavor)
            {
            case MethodCodeFlavor.Managed:
                break;

            case MethodCodeFlavor.ManagedExtern:
                w.Append("extern ");
                break;

            case MethodCodeFlavor.Native:
                w.Append("native ");
                break;

            case MethodCodeFlavor.Runtime:
                w.Append("runtime ");
                break;

            case MethodCodeFlavor.ForwardRef:
                w.Append("forwardref ");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            if (HasNewSlot)
            {
                w.Append("newslot ");
            }
            if (IsSyncronized)
            {
                w.Append("syncronized ");
            }
            if (NoInlining)
            {
                w.Append("noinline ");
            }
            if (IsInitLocals)
            {
                w.Append("initlocals ");
            }
            switch (MethodStyle)
            {
            case MethodStyle.Normal:
            case MethodStyle.Constructor:
                break;

            case MethodStyle.Virtual:
                w.Append("virtual ");
                break;

            case MethodStyle.Abstract:
                w.Append("abstract ");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#3
0
        public void Append(CSTWriter w)
        {
            w.Append('[');
            Type.Append(w);
            w.Append('(');
            var first = true;

            foreach (var o in PositionalProperties)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    w.Append(',');
                }
                w.AppendQuotedObject(o);
            }
            foreach (var kv in NamedProperties)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    w.Append(',');
                }
                w.Append(kv.Key);
                w.Append('=');
                w.AppendQuotedObject(kv.Value);
            }
            w.Append(")]");
        }
示例#4
0
 public void Append(CSTWriter w)
 {
     w.Append('B');
     w.Append(Id);
     w.Append(':');
     w.EndLine();
     w.Indented
         (w2 =>
     {
         if (Sources.Count > 0)
         {
             w2.Append("(* from ");
             for (var i = 0; i < Sources.Count; i++)
             {
                 if (i > 0)
                 {
                     w2.Append(", ");
                 }
                 w2.Append("B");
                 w2.Append(Sources[i].Id);
             }
             w2.Append(" *)");
             w2.EndLine();
         }
         for (var i = 0; i < Block.Body.Count; i++)
         {
             Block.Body[i].Append(w2);
             w2.EndLine();
         }
         AppendLast(w);
         w2.EndLine();
     });
 }
示例#5
0
 public override void AppendLast(CSTWriter w)
 {
     w.Append("POP STACK ");
     w.Append(StackPopCount);
     w.Append(" LEAVE B");
     w.Append(Target.Id);
 }
示例#6
0
 public void Append(CSTWriter w)
 {
     foreach (var customAttribute in CustomAttributes)
     {
         customAttribute.Append(w);
         w.EndLine();
     }
     w.Append("assembly ");
     Name.Append(w);
     w.Append(" {");
     w.EndLine();
     w.Indented(w2 => {
         foreach (var sn in References)
         {
             w2.Append(".reference ");
             sn.Append(w2);
             w2.EndLine();
         }
         if (EntryPoint != null)
         {
             w2.Append(".entry ");
             EntryPoint.Append(w2);
             w2.EndLine();
         }
         foreach (var namedTypeDef in Types)
         {
             namedTypeDef.AppendDefinition(w2);
             w2.EndLine();
         }
     });
     w.Append('}');
 }
示例#7
0
 public static MessageContext Env(MessageContext parent, AssemblyEnvironment assmEnv)
 {
     return(new MessageContext
                (parent,
                assmEnv.Loc,
                sb => CSTWriter.WithAppend(sb, assmEnv.Global, WriterStyle.Debug, assmEnv.Append)));
 }
示例#8
0
        public void SetupMetadata(CST.Global global)
        {
            NumWarnings = 0;
            NumErrors   = 0;

            Global = global;

            if (tracerStream != null)
            {
                Tracer = new CST.CSTWriter(global, CST.WriterStyle.Debug, tracerStream);
            }

            Validity = new ValidityContext(this);

            GenericEnumeratorTypeConstructorRef = MkRef(Constants.GenericEnumeratorTypeConstructorName);
            JSContextRef   = MkRef(Constants.JSContextName);
            JSObjectRef    = MkRef(Constants.JSObjectName);
            JSPropertyRef  = MkRef(Constants.JSPropertyName);
            JSExceptionRef = MkRef(Constants.JSExceptionName);

            GlobalMapping   = new GlobalMapping(this);
            AttributeHelper = new AttributeHelper(this);
            InteropManager  = new InteropManager(this);
            JSTHelpers      = new JSTHelpers(this);
            InlinedMethods  = new InlinedMethodCache(this);
            Traces          = new Traces(this);
        }
示例#9
0
 public Peephole(IEnumerator <Instruction> source, CSTWriter trace)
 {
     this.source = source;
     eoi         = false;
     lookahead   = new Seq <Instruction>();
     this.trace  = trace;
 }
示例#10
0
 public void Append(CSTWriter w)
 {
     // Print from bottom to top to match argument order
     w.Append("{[");
     for (var i = Depth - 1; i >= 0; i--)
     {
         if (i < Depth - 1)
         {
             w.Append(',');
         }
         if (innerState.Value.Ids != null)
         {
             w.AppendName(innerState.Value.Ids[i].Value);
             w.Append(':');
         }
         innerState.Value.Stack[i].Append(w);
     }
     w.Append(']');
     if (!innerState.Value.ArgsLocalsState.IsBottom)
     {
         w.Append(' ');
         innerState.Value.ArgsLocalsState.Append(w);
     }
     w.Append('}');
 }
示例#11
0
        public void Append(CSTWriter w)
        {
            switch (w.Style)
            {
            case WriterStyle.ReflectionName:
            {
                w.AppendName(Types[Types.Count - 1]);
                break;
            }

            case WriterStyle.ReflectionFullName:
            case WriterStyle.Uniform:
            case WriterStyle.Debug:
            {
                if (!string.IsNullOrEmpty(Namespace))
                {
                    w.AppendName(Namespace);
                    w.Append('.');
                }
                for (var i = 0; i < Types.Count; i++)
                {
                    if (i > 0)
                    {
                        w.Append('+');
                    }
                    w.AppendName(Types[i]);
                }
                break;
            }
            }
        }
示例#12
0
 public override void Append(CSTWriter w)
 {
     w.Append("CATCH ");
     w.Append("(* ");
     Type.Append(w);
     w.Append(" *) B");
     w.Append(Body.Id);
 }
示例#13
0
 public void Teardown()
 {
     if (Tracer != null)
     {
         Tracer.Close();
         Tracer = null;
     }
 }
示例#14
0
        public static void WithAppend(StringBuilder sb, Global global, WriterStyle style, Action <CSTWriter> f)
        {
            var sw = new StringWriter(sb);
            var w  = new CSTWriter(global, style, sw);

            f(w);
            sw.Flush();
        }
示例#15
0
 public override void Append(CSTWriter w)
 {
     w.Append("box(");
     Box.Append(w, 0);
     w.Append(':');
     ValueType.Append(w);
     w.Append(')');
 }
示例#16
0
 public override void AppendLast(CSTWriter w)
 {
     w.Append("POP HANDLER ");
     w.Append(HandlerPopCount);
     w.Append(" POP STACK ");
     w.Append(StackPopCount);
     w.Append(" LEAVE CATCH B");
     w.Append(Target.Id);
 }
示例#17
0
 public override void AppendLast(CSTWriter w)
 {
     w.Append(Label.Value);
     w.Append(": ");
     w.Append("LOOP B");
     w.Append(Head.Id);
     w.Append(" BREAK TO B");
     w.Append(Break.Id);
 }
示例#18
0
 public void Append(CSTWriter w)
 {
     Type.Append(w);
     if (UpperBound != null)
     {
         w.Append("<:");
         UpperBound.Append(w);
     }
 }
示例#19
0
 public override void AppendLast(CSTWriter w)
 {
     w.Append("BRANCH ");
     Test.Append(w);
     w.Append(" B");
     w.Append(Target.Id);
     w.Append(" ELSE B");
     w.Append(Fallthrough.Id);
 }
示例#20
0
        public override void Append(CSTWriter w, IImSeq <TypeRef> methodTypeArguments)
        {
            if (methodTypeArguments != null)
            {
                throw new InvalidOperationException("signature does not accept type arguments");
            }

            w.Append("event ");
            w.AppendName(Name);
        }
示例#21
0
 public override void AppendLast(CSTWriter w)
 {
     w.Append("TRY B");
     w.Append(Body.Id);
     foreach (var h in Handlers)
     {
         w.Append(' ');
         h.Append(w);
     }
 }
示例#22
0
 public static MessageContext Assembly(MessageContext parent, Global global, AssemblyDef assemblyDef)
 {
     return(new MessageContext
                (parent,
                null,
                sb =>
     {
         sb.Append("Assembly ");
         CSTWriter.WithAppend(sb, global, WriterStyle.Debug, assemblyDef.Name.Append);
     }));
 }
示例#23
0
 public static MessageContext Instruction(MessageContext parent, Global global, Instruction instruction)
 {
     return(new MessageContext
                (parent,
                instruction.Loc,
                sb =>
     {
         sb.Append("Instruction ");
         CSTWriter.WithAppend(sb, global, WriterStyle.Debug, instruction.Append);
     }));
 }
示例#24
0
 public override void AppendDefinition(CSTWriter w)
 {
     base.AppendDefinition(w);
     w.Append(':');
     FieldType.Append(w);
     if (Init != null)
     {
         w.Append('=');
         Init.Append(w);
     }
 }
示例#25
0
 public static MessageContext Type(MessageContext parent, Global global, TypeRef typeRef)
 {
     return(new MessageContext
                (parent,
                typeRef.Loc,
                sb =>
     {
         sb.Append("Type ");
         CSTWriter.WithAppend(sb, global, WriterStyle.Debug, typeRef.Append);
     }));
 }
示例#26
0
        public override void AppendDefinition(CSTWriter w)
        {
            base.AppendDefinition(w);
            if (TypeParameters.Count > 0)
            {
                w.Append('<');
                for (var i = 0; i < TypeParameters.Count; i++)
                {
                    if (i > 0)
                    {
                        w.Append(',');
                    }
                    w.Append("!!");
                    w.Append(TypeParameters[i].Index);
                }
                w.Append('>');
            }
            w.Append('(');
            for (var i = 0; i < ValueParameters.Count; i++)
            {
                if (i > 0)
                {
                    w.Append(',');
                }
                ValueParameters[i].Type.Append(w);
            }
            w.Append(')');
            if (Result != null)
            {
                w.Append(':');
                Result.Append(w);
            }
            var instructions = Instructions(w.Global);

            if (instructions != null)
            {
                w.Append(" {");
                w.EndLine();
                w.Indented
                    (w2 =>
                {
                    for (var i = 0; i < Locals.Count; i++)
                    {
                        w2.Append(".local ");
                        w2.Append(i);
                        w2.Append(':');
                        Locals[i].Type.Append(w2);
                        w2.EndLine();
                    }
                    instructions.Append(w2);
                });
                w.Append('}');
            }
        }
示例#27
0
 public static MessageContext Type(MessageContext parent, Global global, AssemblyDef assemblyDef, TypeDef typeDef)
 {
     return(new MessageContext
                (parent,
                typeDef.Loc,
                sb =>
     {
         sb.Append("Type ");
         CSTWriter.WithAppend
             (sb, global, WriterStyle.Debug, typeDef.PrimReference(global, assemblyDef, null).Append);
     }));
 }
示例#28
0
        //
        // Pretty printing
        //

        public virtual void AppendDefinition(CSTWriter w)
        {
            foreach (var annotation in CustomAttributes)
            {
                annotation.Append(w);
                w.EndLine();
            }
            AppendFlavor(w);
            w.Append(IsStatic ? "static " : "instance ");
            AppendModifiers(w);
            w.AppendName(Name);
        }
示例#29
0
 public static MessageContext Member <T>(MessageContext parent, Global global, AssemblyDef assemblyDef, TypeDef typeDef, T memberDef) where T : MemberDef
 {
     return(new MessageContext
                (parent,
                memberDef.Loc,
                sb =>
                CSTWriter.WithAppend
                    (sb,
                    global,
                    WriterStyle.Debug,
                    memberDef.PrimReference(global, assemblyDef, typeDef, null).Append)));
 }
示例#30
0
 private void AppendAllFrom(CSTWriter w, Set <int> printed)
 {
     if (!printed.Contains(Id))
     {
         printed.Add(Id);
         Append(w);
         foreach (var b in Targets)
         {
             b.AppendAllFrom(w, printed);
         }
     }
 }
示例#31
0
        public void SetupMetadata(CST.Global global)
        {
            NumWarnings = 0;
            NumErrors = 0;

            Global = global;

            if (tracerStream != null)
                Tracer = new CST.CSTWriter(global, CST.WriterStyle.Debug, tracerStream);

            Validity = new ValidityContext(this);

            GenericEnumeratorTypeConstructorRef = MkRef(Constants.GenericEnumeratorTypeConstructorName);
            JSContextRef = MkRef(Constants.JSContextName);
            JSObjectRef = MkRef(Constants.JSObjectName);
            JSPropertyRef = MkRef(Constants.JSPropertyName);
            JSExceptionRef = MkRef(Constants.JSExceptionName);

            GlobalMapping = new GlobalMapping(this);
            AttributeHelper = new AttributeHelper(this);
            InteropManager = new InteropManager(this);
            JSTHelpers = new JSTHelpers(this);
            InlinedMethods = new InlinedMethodCache(this);
            Traces = new Traces(this);
        }
示例#32
0
 public void Teardown()
 {
     if (Tracer != null)
     {
         Tracer.Close();
         Tracer = null;
     }
 }