Пример #1
0
 public static void EmitEndContinue(AbstractEmitterBlock block)
 {
     block.Write("continue = true");
     block.WriteNewLine();
     block.Outdent();
     block.Write("until 1");
     block.WriteNewLine();
     block.Write("if not continue then break end");
     block.WriteNewLine();
 }
Пример #2
0
 public static void EmitYieldReturn(AbstractEmitterBlock block, IType returnType)
 {
     block.EndFunctionBlock();
     block.WriteComma();
     if (returnType.TypeArguments.Count > 0)
     {
         block.Write(BridgeTypes.ToJsName(returnType.TypeArguments[0], block.Emitter));
     }
     else
     {
         block.Write("System.Object");
     }
     block.WriteCloseParentheses();
     block.WriteNewLine();
 }
Пример #3
0
 /// <summary>
 /// http://lua-users.org/wiki/ContinueProposal
 /// </summary>
 /// <param name="block"></param>
 private static void EmitBeginContinue(AbstractEmitterBlock block)
 {
     block.WriteVar(true);
     block.Write("continue");
     block.WriteNewLine();
     block.BeginBlock("repeat");
 }
Пример #4
0
 public static void EmitYield(AbstractEmitterBlock block, IType returnType)
 {
     block.WriteReturn(true);
     block.Write(LuaHelper.Root + ".yieldEnumerator");
     block.WriteOpenParentheses();
     block.WriteFunction();
     block.WriteOpenCloseParentheses();
     block.BeginFunctionBlock();
 }
Пример #5
0
 public static void EmitYield(AbstractEmitterBlock block, IType returnType)
 {
     block.WriteReturn(true);
     block.Write(LuaHelper.Root + ".yieldEnumerator");
     block.WriteOpenParentheses();
     block.WriteFunction();
     block.WriteOpenCloseParentheses();
     block.BeginFunctionBlock();
 }
        public static string ReplaceInlineArgs(AbstractEmitterBlock block, string inline, Expression[] args)
        {
            var emitter = block.Emitter;

            inline = _formatArg.Replace(inline, delegate(Match m)
            {
                int count       = emitter.Writers.Count;
                string separate = m.Groups[1].Value;
                string key      = m.Groups[3].Value;
                string modifier = m.Groups[2].Success ? m.Groups[5].Value : null;

                StringBuilder oldSb = emitter.Output;
                emitter.Output      = new StringBuilder();

                Expression expr = null;

                if (Regex.IsMatch(key, "^\\d+$"))
                {
                    expr = args.Skip(int.Parse(key)).FirstOrDefault();
                }
                else
                {
                    expr = args.FirstOrDefault(e => e.ToString() == key);
                }

                string s = "";
                if (expr != null)
                {
                    var writer = block.SaveWriter();
                    block.NewWriter();
                    expr.AcceptVisitor(emitter);
                    s = emitter.Output.ToString();
                    block.RestoreWriter(writer);

                    if (modifier == "raw")
                    {
                        s = s.Trim('"');
                    }
                }

                block.Write(block.WriteIndentToString(s));

                if (emitter.Writers.Count != count)
                {
                    block.PopWriter();
                }

                string replacement = emitter.Output.ToString();
                emitter.Output     = oldSb;

                return(replacement);
            });

            return(inline);
        }
Пример #7
0
 public static void EmitYield(AbstractEmitterBlock block, IType returnType, MethodDeclaration methodDeclaration)
 {
     block.WriteReturn(true);
     block.Write(LuaHelper.Root, ".yield", returnType.Name);
     block.WriteOpenParentheses();
     block.WriteFunction();
     block.WriteOpenParentheses();
     AbstractMethodBlock.EmitMethodParameters(block, methodDeclaration.Parameters, methodDeclaration);
     block.WriteCloseParentheses();
     block.BeginFunctionBlock();
 }
Пример #8
0
        public static void EmitMethodParameters(AbstractEmitterBlock block, IEnumerable <ParameterDeclaration> declarations, AstNode context)
        {
            bool needComma = false;

            EntityDeclaration entityDeclaration = context as EntityDeclaration;

            if (entityDeclaration != null)
            {
                if (!entityDeclaration.HasModifier(Modifiers.Static))
                {
                    block.WriteThis();
                    if (declarations.Any())
                    {
                        block.WriteComma();
                    }
                }
            }

            foreach (ParameterDeclaration p in declarations)
            {
                string name = p.Name;
                name = name.Replace(Bridge.Translator.Emitter.FIX_ARGUMENT_NAME, "");
                if (block.Emitter.LocalsNamesMap != null && block.Emitter.LocalsNamesMap.ContainsKey(name))
                {
                    name = block.Emitter.LocalsNamesMap[name];
                }

                if (needComma)
                {
                    block.WriteComma();
                }

                needComma = true;
                block.Write(name);
            }
        }
Пример #9
0
        public static string ReplaceInlineArgs(AbstractEmitterBlock block, string inline, Expression[] args)
        {
            var emitter = block.Emitter;
            inline = _formatArg.Replace(inline, delegate(Match m)
            {
                int count = emitter.Writers.Count;
                string key = m.Groups[2].Value;
                string modifier = m.Groups[1].Success ? m.Groups[4].Value : null;

                StringBuilder oldSb = emitter.Output;
                emitter.Output = new StringBuilder();

                Expression expr = null;

                if (Regex.IsMatch(key, "^\\d+$"))
                {
                    expr = args.Skip(int.Parse(key)).FirstOrDefault();
                }
                else
                {
                    expr = args.FirstOrDefault(e => e.ToString() == key);
                }

                string s = "";
                if (expr != null)
                {
                    var writer = block.SaveWriter();
                    block.NewWriter();
                    expr.AcceptVisitor(emitter);
                    s = emitter.Output.ToString();
                    block.RestoreWriter(writer);

                    if (modifier == "raw")
                    {
                        s = s.Trim('"');
                    }
                }

                block.Write(block.WriteIndentToString(s));

                if (emitter.Writers.Count != count)
                {
                    block.PopWriter();
                }

                string replacement = emitter.Output.ToString();
                emitter.Output = oldSb;

                return replacement;
            });

            return inline;
        }
Пример #10
0
 public static void EmitEndContinue(AbstractEmitterBlock block) {
     block.Write("continue = true");
     block.WriteNewLine();
     block.Outdent();
     block.Write("until 1");
     block.WriteNewLine();
     block.Write("if not continue then break end");
     block.WriteNewLine();
 }
Пример #11
0
 /// <summary>
 /// http://lua-users.org/wiki/ContinueProposal
 /// </summary>
 /// <param name="block"></param>
 private static void EmitBeginContinue(AbstractEmitterBlock block) {
     block.WriteVar(true);
     block.Write("continue");
     block.WriteNewLine();
     block.BeginBlock("repeat");
 }