Esempio n. 1
0
            public void FormatMethod(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext)
            {
                String methodName = GetMethodName(formatterContext);

                sw.AppendLine($"public void {methodName}()");
                {
                    sw.AppendLine("{");
                    sw.Indent++;

                    FormatMethodBody(sw, formatterContext, executionContext);

                    sw.Indent--;
                    sw.AppendLine("}");
                }
            }
Esempio n. 2
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.Append("else if(");
     ((JPF)_list[0]).Format(sw, formatterContext, services);
     sw.AppendLine(")");
     FormatBranch(sw, formatterContext, services, GetBodyInstructions());
 }
Esempio n. 3
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.Append($"R{_index.ResultId}");
     sw.Append(" = ");
     _value.Format(sw, formatterContext, services);
     sw.AppendLine(";");
 }
Esempio n. 4
0
            protected void FormatBranch(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext, IEnumerable <IJsmInstruction> items)
            {
                sw.AppendLine("{");
                sw.Indent++;

                var state = sw.RememberState();

                FormatItems(sw, formatterContext, executionContext, items);
                if (!state.IsChanged)
                {
                    sw.AppendLine("// do nothing");
                }

                sw.Indent--;
                sw.AppendLine("}");
            }
Esempio n. 5
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.Append("while(");
     ((JPF)_list[0]).Format(sw, formatterContext, services);
     sw.AppendLine(")");
     FormatBranch(sw, formatterContext, services, _list.Skip(1));
 }
Esempio n. 6
0
        /// <nodoc />
        public static void WriteObject(ScriptWriter writer, ImmutableContextBase context, object value)
        {
            if (value == null)
            {
                writer.AppendToken("undefined");
                return;
            }

            if (value is EvaluationResult result)
            {
                WriteObject(writer, context, result.Value);
                return;
            }

            // One of the types in the map is generic (ObjectLiteralLight<>).
            // To get a match from the dictionary we need to get open generic type
            // from already constructed type that would be provided by value.GetType().
            var type = value.GetType();

            if (type.IsGenericType)
            {
                type = type.GetGenericTypeDefinition();
            }

            if (s_toStringMap.TryGetValue(type, out WriteObjectFunction writeFunction))
            {
                writeFunction(writer, context, value);
            }
            else
            {
                writer.AppendLine(I($"Don't know how to get a string representation of '{type}'"));
            }
        }
                    public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
                    {
                        sw.Append("if(");
                        Jpf.Format(sw, formatterContext, services);
                        sw.AppendLine(")");
                        FormatBranch(sw, formatterContext, services, GetBodyInstructions());

                        foreach (var item in _aggregator.EnumerateElseBlocks())
                        {
                            item.Format(sw, formatterContext, services);
                        }
                    }
Esempio n. 8
0
            public void FormatType(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext)
            {
                formatterContext.GetObjectScriptNamesById(Id, out String typeName, out _);
                sw.AppendLine($"public sealed class {typeName}");
                {
                    sw.AppendLine("{");
                    sw.Indent++;

                    if (Scripts.Count > 0)
                    {
                        FormatConstructor(typeName, sw, formatterContext, executionContext);

                        foreach (var script in Scripts.Skip(1))
                        {
                            sw.AppendLine();
                            script.FormatMethod(sw, formatterContext, executionContext);
                        }
                    }

                    sw.Indent--;
                    sw.AppendLine("}");
                }
            }
Esempio n. 9
0
 private static void FormatItems(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext, IEnumerable <IJsmInstruction> items)
 {
     foreach (var item in items)
     {
         if (item is IFormattableScript formattable)
         {
             formattable.Format(sw, formatterContext, executionContext);
         }
         else
         {
             sw.AppendLine(item.ToString());
         }
     }
 }
Esempio n. 10
0
            private void FormatConstructor(String typeName, ScriptWriter sw, IScriptFormatterContext formatterContext, IServices executionContext)
            {
                sw.AppendLine($"private readonly {nameof(IServices)} _ctx;");
                sw.AppendLine();

                sw.AppendLine($"public {typeName}({nameof(IServices)} executionContext)");
                {
                    sw.AppendLine("{");
                    sw.Indent++;

                    sw.AppendLine("_ctx = executionContext;");
                    Scripts[0].FormatMethodBody(sw, formatterContext, executionContext);

                    sw.Indent--;
                    sw.AppendLine("}");
                }
            }
Esempio n. 11
0
        public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
        {
            formatterContext.GetObjectScriptNamesById(ScriptID, out var typeName, out var methodName);

            sw.AppendLine($"{nameof(PREQEW)}(priority: {Priority}, GetObject<{typeName}>().{methodName}());");
        }
Esempio n. 12
0
 public virtual void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine(this.ToString());
 }
Esempio n. 13
0
        public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
        {
            formatterContext.GetObjectScriptNamesById(_scriptId, out String typeName, out String methodName);

            sw.AppendLine($"{nameof(REQSW)}(priority: {_priority}, GetObject<{typeName}>().{methodName}());");
        }
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine("else");
     FormatBranch(sw, formatterContext, services, GetBodyInstructions());
 }
Esempio n. 15
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine($"// ScriptId: {Label}");
 }
Esempio n. 16
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine($"return {nameof(IRET)}({Unknown});");
 }
Esempio n. 17
0
 public void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine($"goto LABEL{_label};");
 }
Esempio n. 18
0
 public override void Format(ScriptWriter sw, IScriptFormatterContext formatterContext, IServices services)
 {
     sw.AppendLine($"R{ResultVariable.ResultId} = {nameof(Rnd)}.{nameof(Rnd.NextByte)}();");
 }