Esempio n. 1
0
 public override void Append(CSTWriter w)
 {
     Array.Append(w, 1);
     w.Append('[');
     Index.Append(w, 0);
     w.Append(']');
 }
Esempio n. 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();
            }
        }
Esempio n. 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(")]");
        }
Esempio n. 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();
     });
 }
Esempio n. 5
0
 public override void AppendLast(CSTWriter w)
 {
     w.Append("POP STACK ");
     w.Append(StackPopCount);
     w.Append(" LEAVE B");
     w.Append(Target.Id);
 }
Esempio n. 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('}');
 }
Esempio n. 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)));
 }
Esempio n. 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);
        }
Esempio n. 9
0
 public Peephole(IEnumerator <Instruction> source, CSTWriter trace)
 {
     this.source = source;
     eoi         = false;
     lookahead   = new Seq <Instruction>();
     this.trace  = trace;
 }
Esempio n. 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('}');
 }
Esempio n. 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;
            }
            }
        }
Esempio n. 12
0
 public override void Append(CSTWriter w)
 {
     w.Append("CATCH ");
     w.Append("(* ");
     Type.Append(w);
     w.Append(" *) B");
     w.Append(Body.Id);
 }
Esempio n. 13
0
 public void Teardown()
 {
     if (Tracer != null)
     {
         Tracer.Close();
         Tracer = null;
     }
 }
Esempio n. 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();
        }
Esempio n. 15
0
 public override void Append(CSTWriter w)
 {
     w.Append("box(");
     Box.Append(w, 0);
     w.Append(':');
     ValueType.Append(w);
     w.Append(')');
 }
Esempio n. 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);
 }
Esempio n. 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);
 }
Esempio n. 18
0
 public void Append(CSTWriter w)
 {
     Type.Append(w);
     if (UpperBound != null)
     {
         w.Append("<:");
         UpperBound.Append(w);
     }
 }
Esempio n. 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);
 }
Esempio n. 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);
        }
Esempio n. 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);
     }
 }
Esempio n. 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);
     }));
 }
Esempio n. 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);
     }));
 }
Esempio n. 24
0
 public override void AppendDefinition(CSTWriter w)
 {
     base.AppendDefinition(w);
     w.Append(':');
     FieldType.Append(w);
     if (Init != null)
     {
         w.Append('=');
         Init.Append(w);
     }
 }
Esempio n. 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);
     }));
 }
Esempio n. 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('}');
            }
        }
Esempio n. 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);
     }));
 }
Esempio n. 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);
        }
Esempio n. 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)));
 }
Esempio n. 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);
         }
     }
 }
Esempio n. 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);
        }
Esempio n. 32
0
 public void Teardown()
 {
     if (Tracer != null)
     {
         Tracer.Close();
         Tracer = null;
     }
 }