当前位置: 首页>>代码示例>>C#>>正文


C# Compiler.AppendLine方法代码示例

本文整理汇总了C#中Compiler.AppendLine方法的典型用法代码示例。如果您正苦于以下问题:C# Compiler.AppendLine方法的具体用法?C# Compiler.AppendLine怎么用?C# Compiler.AppendLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Compiler的用法示例。


在下文中一共展示了Compiler.AppendLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compile

        public override void Compile(Compiler compiler, Node node, NodeParent parent)
        {
            if (node is IsDefinedExpression)
            {
                var ide = (IsDefinedExpression)node;
                switch(ide.Expression.NodeType)
                {
                    case NodeTypes.MethodCall:
                        compiler.AppendLine("$_stack[] = F_TrueClass::__from_bool(function_exists('{0}'));", Mangling.RubyMethodToPHP(((MethodCall)ide.Expression).MethodName));
                        return;
                    case NodeTypes.ConstantVariable:
                        compiler.AppendLine("$_stack[] = F_TrueClass::__from_bool(class_exists('{0}'));", Mangling.RubyMethodToPHP(((ConstantVariable)ide.Expression).Name));
                        return;
                    case NodeTypes.ClassVariable:
                    case NodeTypes.GlobalVariable:
                    case NodeTypes.InstanceVariable:
                    case NodeTypes.LocalVariable:
                        compiler.AppendLine("$_stack[] = F_TrueClass::__from_bool(isset({0}));", ((Variable)ide.Expression).ToPHPVariable());
                        return;
                    default:
                        throw new FructoseCompileException("Not supported yet: defined?( " + ide.Expression.NodeType.ToString() + " )", ide.Expression);
                }

            }
            else
                throw new FructoseCompileException("Not supported yet: " + node.ToString(), node);
        }
开发者ID:rzhw,项目名称:Fructose,代码行数:27,代码来源:DescriptionExpression.cs

示例2: Compile

        public override void Compile(Compiler compiler, IronRuby.Compiler.Ast.Node node, NodeParent parent)
        {
            var sae = (SimpleAssignmentExpression)node;

            // substitute a method call of []= rather than the crap that ironruby's parser produces:
            switch (sae.Left.NodeType)
            {
                case NodeTypes.ArrayItemAccess:
                    var aia = (ArrayItemAccess)sae.Left;
                    compiler.CompileNode(new MethodCall(aia.Array, "[]=", new Arguments(aia.Arguments.Expressions.Concat(new[] { sae.Right }).ToArray()), sae.Location), parent.CreateChild(node));
                    return;
                case NodeTypes.AttributeAccess:
                    var aa = (AttributeAccess)sae.Left;
                    compiler.CompileNode(new MethodCall(aa.Qualifier, aa.Name, new Arguments(sae.Right), aa.Location), parent.CreateChild(node));
                    return;
            }

            compiler.CompileNode(sae.Right, parent.CreateChild(node));
            if (sae.Operation != null)
            {
                compiler.AppendLine("$_stack[] = {0};", assignmentVar(sae.Left, parent));
                compiler.AppendLine("$_stack[] = array_pop($_stack)->{0}(NULL, array_pop($_stack));", Mangling.RubyMethodToPHP(sae.Operation));
            }
            compiler.AppendLine("{0} = $_stack[count($_stack)-1];", assignmentVar(sae.Left, parent));
        }
开发者ID:rzhw,项目名称:Fructose,代码行数:25,代码来源:Assignment.cs

示例3: Compile

        public override void Compile(Compiler compiler, Node node, NodeParent parent)
        {
            var pmethod = parent.OfType<MethodDefinition>().SingleOrDefault();
            var isInBlock = pmethod != null && pmethod.Name.Contains("__lambda_");

            if (((ReturnStatement)node).Arguments == null || ((ReturnStatement)node).Arguments.Expressions.Count() == 0)
            {
                compiler.AppendLine("$_stack[] = new F_NilClass;");
            }
            else if (((ReturnStatement)node).Arguments.Expressions.Count() > 0)
            {
                compiler.CompileNode(((ReturnStatement)node).Arguments.Expressions.First(), parent.CreateChild(node));
            }
            else
            {
                compiler.CompileNode(new ArrayConstructor(((ReturnStatement)node).Arguments, ((ReturnStatement)node).Location), parent.CreateChild(node));
            }

            if (!isInBlock)
            {
                compiler.AppendLine("return array_pop($_stack);");
            }
            else
            {
                compiler.AppendLine("throw new ReturnFromBlock(array_pop($_stack));");
            }
        }
开发者ID:rzhw,项目名称:Fructose,代码行数:27,代码来源:Return.cs

示例4: Compile

        public override void Compile(Compiler compiler, Node node, NodeParent parent)
        {
            if (((Literal)node).Value == null)
            {
                // nil
                compiler.AppendLine("$_stack[] = new F_NilClass;");
                return;
            }
            if (((Literal)node).Value is bool)
            {
                // True or False
                compiler.AppendLine("$_stack[] = new F_{0}Class;", ((Literal)node).Value.ToString());
                return;
            }
            if (((Literal)node).Value is string)
            {
                switch (((Literal)node).Value.ToString())
                {
                    case "self":
                        compiler.AppendLine("$_stack[] = $_locals->self;", ((Literal)node).Value.ToString());
                        break;
                    case "__FILE__":
                    case "__LINE__":
                        compiler.AppendLine("$_stack[] = F_String::__from_string({0});", ((Literal)node).Value.ToString());
                        break;
                }
                return;
            }

            compiler.AppendLine("$_stack[] = F_Number::__from_number({0});", ((Literal)node).Value.ToString());
        }
开发者ID:rzhw,项目名称:Fructose,代码行数:31,代码来源:Literal.cs

示例5: Compile

 public override void Compile(Compiler compiler, Node node, NodeParent parent)
 {
     YieldCall yield = (YieldCall)node;
     if(yield.Arguments != null)
         foreach (var arg in yield.Arguments.Expressions.Reverse())
         {
             compiler.CompileNode(arg, parent.CreateChild(node));
         }
     compiler.AppendLine("$_blockfn = $_locals->block;");
     compiler.AppendLine("$_stack[] = $_blockfn(NULL" + string.Join("", (yield.Arguments ?? new Arguments()).Expressions.Select(ex => ", array_pop($_stack)").ToArray()) + ");");
 }
开发者ID:rzhw,项目名称:Fructose,代码行数:11,代码来源:Yield.cs

示例6: Compile

        public override void Compile(Compiler compiler, Node node, NodeParent parent)
        {
            compiler.CompileNode(((AndExpression)node).Left, parent.CreateChild(node));

            compiler.AppendLine("$_and_tmp = get_class($_stack[count($_stack)-1]);");
            compiler.AppendLine("if($_and_tmp !== 'F_NilClass' && $_and_tmp !== 'F_FalseClass')");
            compiler.AppendLine("{");
            compiler.Indent();

                compiler.CompileNode(((AndExpression)node).Right, parent.CreateChild(node));

            compiler.Dedent();
            compiler.AppendLine("}");
        }
开发者ID:rzhw,项目名称:Fructose,代码行数:14,代码来源:BooleanLogic.cs

示例7: Compile

        public override void Compile(Compiler compiler, Node node, NodeParent parent)
        {
            compiler.AppendLine("while(true)");
            compiler.AppendLine("{");
            compiler.Indent();

            if(((WhileLoopExpression)node).IsPostTest)
            {
                foreach(var stmt in ((WhileLoopExpression)node).Statements)
                    compiler.CompileNode(stmt, parent.CreateChild(node));
            }

            if (((WhileLoopExpression)node).IsWhileLoop)
                compiler.CompileNode(((WhileLoopExpression)node).Condition, parent.CreateChild(node));
            else
                compiler.CompileNode(new NotExpression(((WhileLoopExpression)node).Condition, node.Location), parent.CreateChild(node));

            compiler.AppendLine("$_cond = array_pop($_stack);");
            compiler.AppendLine("if(get_class($_cond) === 'F_NilClass' || get_class($_cond) === 'F_FalseClass' || is_subclass_of($_cond, 'F_NilClass') || is_subclass_of($_cond, 'F_FalseClass'))");
            compiler.AppendLine("{");
            compiler.Indent();
            compiler.AppendLine("break;");
            compiler.Dedent();
            compiler.AppendLine("}");

            if (!((WhileLoopExpression)node).IsPostTest)
            {
                foreach (var stmt in ((WhileLoopExpression)node).Statements)
                    compiler.CompileNode(stmt, parent.CreateChild(node));
            }

            compiler.Dedent();
            compiler.AppendLine("}");
        }
开发者ID:rzhw,项目名称:Fructose,代码行数:34,代码来源:While.cs

示例8: Compile

        public override void Compile(Compiler compiler, Node node, NodeParent parent)
        {
            var hash = (HashConstructor)node;
            compiler.AppendLine("$_tmp_pairs[] = array();");

            foreach (var maplet in hash.Maplets)
            {
                compiler.CompileNode(maplet.Key, parent.CreateChild(node));
                compiler.AppendLine("$_tmp_pairs[count($_tmp_pairs)-1][] = array_pop($_stack);");
                compiler.CompileNode(maplet.Value, parent.CreateChild(node));
                compiler.AppendLine("$_tmp_pairs[count($_tmp_pairs)-1][] = array_pop($_stack);");
            }

            compiler.AppendLine("$_stack[] = F_Hash::__from_flatpairs(array_pop($_tmp_pairs));");
        }
开发者ID:rzhw,项目名称:Fructose,代码行数:15,代码来源:Hash.cs

示例9: Compile

 public override void Compile(Compiler compiler, Node node, NodeParent parent)
 {
     var method = parent.OfType<MethodDefinition>().ToArray();
     if (method.Length > 0 && method[0].Parameters != null
         && method[0].Parameters.Mandatory.Where(p => p.ToString() == ((LocalVariable)node).Name).Count() > 0)
     {
         compiler.AppendLine("$_stack[] = isset(${0}) ? (${0}) : (new F_NilClass);", Mangling.RubyIdentifierToPHP(((Variable)node).Name));
         return;
     }
     if (parent.OfType<ClassDefinition>().Count() == 0)
     {
         compiler.AppendLine("$_stack[] = isset($_locals->{0}) ? ($_locals->{0}) : (new F_NilClass);", Mangling.RubyIdentifierToPHP(((Variable)node).Name));
         return;
     }
     compiler.AppendLine("$_stack[] = isset({0}) ? ({0}) : (new F_NilClass);", ((Variable)node).ToPHPVariable());
 }
开发者ID:rzhw,项目名称:Fructose,代码行数:16,代码来源:Variables.cs

示例10: Compile

 public override void Compile(Compiler compiler, Node node, NodeParent parent)
 {
     var re = (RangeExpression)node;
     compiler.CompileNode(re.End, parent.CreateChild(node));
     compiler.CompileNode(re.Begin, parent.CreateChild(node));
     compiler.AppendLine("$_stack[] = F_Range::SF_new(NULL, array_pop($_stack), array_pop($_stack), new F_{0}Class);", re.IsExclusive.ToString());
 }
开发者ID:rzhw,项目名称:Fructose,代码行数:7,代码来源:Range.cs

示例11: Compile

        public override void Compile(Compiler compiler, Node node, NodeParent parent)
        {
            var body = (Body)node;
            if (body.RescueClauses != null)
            {
                for(int i = 0; i < body.RescueClauses.Count; i++)
                {
                    compiler.AppendLine("try");
                    compiler.AppendLine("{");
                    compiler.Indent();
                }
            }

            foreach (var stmt in body.Statements)
                compiler.CompileNode(stmt, parent.CreateChild(node));

            if (body.RescueClauses != null)
            {
                foreach (var rescue in body.RescueClauses)
                {
                    compiler.Dedent();
                    compiler.AppendLine("}");
                    compiler.AppendLine("catch(ErrorCarrier $err)");
                    compiler.AppendLine("{");
                    compiler.Indent();
                    StringBuilder clause = new StringBuilder();
                    bool first = true;
                    foreach (var t in rescue.Types)
                    {
                        if (t.NodeType != NodeTypes.ConstantVariable)
                            throw new FructoseCompileException("Type constant must be supplied in rescue expression", rescue);

                        if (!first)
                            clause.Append(" && ");
                        first = false;
                        clause.Append(string.Format("!is_a($err->val, '{0}')", Mangling.RubyIdentifierToPHP(((ConstantVariable)t).Name)));
                    }
                    compiler.AppendLine("if({0})", clause.ToString());
                    compiler.Indent();
                    compiler.AppendLine("throw $err;");
                    compiler.Dedent();
                    compiler.AppendLine("{0} = $err->val;", ((Variable)(rescue.Target ?? new GlobalVariable("!", rescue.Location))).ToPHPVariable());

                    foreach (var stmt in rescue.Statements)
                        compiler.CompileNode(stmt, parent.CreateChild(node));

                    compiler.Dedent();
                    compiler.AppendLine("}");
                }
            }
        }
开发者ID:rzhw,项目名称:Fructose,代码行数:51,代码来源:Body.cs

示例12: Compile

        public override void Compile(Compiler compiler, Node node, NodeParent parent)
        {
            var ac = (ArrayConstructor)node;

            foreach (var exp in ac.Arguments.Expressions.Reverse())
                compiler.CompileNode(exp, parent.CreateChild(node));

            compiler.AppendLine("$_stack[] = F_Array::S__operator_arrayget(NULL" + string.Join("", ac.Arguments.Expressions.Select(e => ", array_pop($_stack)").ToArray()) + ");");
        }
开发者ID:rzhw,项目名称:Fructose,代码行数:9,代码来源:Array.cs

示例13: Compile

        public override void Compile(Compiler compiler, Node node, NodeParent parent)
        {
            var regex = (RegularExpression)node;

            string rstr = "";
            if(regex.Options.HasFlag(RubyRegexOptions.IgnoreCase))
                rstr += "i";
            if(regex.Options.HasFlag(RubyRegexOptions.Multiline))
                rstr += "m";
            if(regex.Options.HasFlag(RubyRegexOptions.Extended))
                rstr += "x";

            compiler.CompileNode(new StringConstructor(regex.Pattern, StringKind.Mutable, regex.Location));

            compiler.AppendLine("$_stack[] = F_Regexp::SF_new(NULL, array_pop($_stack), F_String::__from_string('{0}'));", rstr);
        }
开发者ID:rzhw,项目名称:Fructose,代码行数:16,代码来源:Regex.cs

示例14: Compile

        public override void Compile(Compiler compiler, Node node, NodeParent parent)
        {
            CaseExpression c = (CaseExpression)node;
            compiler.CompileNode(c.Value, parent.CreateChild(node));
            compiler.AppendLine("$_caseval = array_pop($_stack);");

            foreach(var when in c.WhenClauses)
            {
                var sb = new StringBuilder();
                compiler.AppendLine("$_comparisons = array();");
                foreach(var compar in when.Comparisons)
                {
                    if(sb.Length > 0)
                        sb.Append(" || ");
                    sb.Append("_isTruthy(array_pop($_comparisons))");
                    compiler.CompileNode(compar, parent.CreateChild(node).CreateChild(when));
                    compiler.AppendLine("$_comparisons[] = array_pop($_stack)->__operator_stricteq(NULL, $_caseval);");
                }
                compiler.AppendLine("if({0})", sb.ToString());
                compiler.AppendLine("{");
                compiler.Indent();
                foreach(var stmt in when.Statements)
                    compiler.CompileNode(stmt, parent.CreateChild(node).CreateChild(when));
                compiler.Dedent();
                compiler.AppendLine("}");
                compiler.AppendLine("else");
                compiler.AppendLine("{");
                compiler.Indent();
            }
            if(c.ElseStatements != null)
                foreach(var stmt in c.ElseStatements)
                    compiler.CompileNode(stmt, parent.CreateChild(node));
            for(int i = 0; i < c.WhenClauses.Length; i++)
            {
                compiler.Dedent();
                compiler.AppendLine("}");
            }
        }
开发者ID:rzhw,项目名称:Fructose,代码行数:38,代码来源:Case.cs

示例15: Compile

        public override void Compile(Compiler compiler, Node node, NodeParent parent)
        {
            compiler.CompileNode(((IfExpression)node).Condition, parent.CreateChild(node));

            compiler.AppendLine("$_cond = array_pop($_stack);");
            compiler.AppendLine("if(get_class($_cond) !== 'F_NilClass' && get_class($_cond) !== 'F_FalseClass' && !is_subclass_of($_cond, 'F_NilClass') && !is_subclass_of($_cond, 'F_FalseClass'))");
            compiler.AppendLine("{");
            compiler.Indent();

            foreach (var stmt in ((IfExpression)node).Body)
                compiler.CompileNode(stmt, parent.CreateChild(node));

            compiler.Dedent();
            compiler.AppendLine("}");

            if (((IfExpression)node).ElseIfClauses.Count > 0)
            {
                compiler.AppendLine("else");
                compiler.AppendLine("{");
                compiler.Indent();

                var firstelseif = ((IfExpression)node).ElseIfClauses.First();
                var rest = ((IfExpression)node).ElseIfClauses.Skip(1).ToList();
                if (firstelseif.Condition == null)
                {
                    foreach (var stmt in firstelseif.Statements)
                        compiler.CompileNode(stmt, parent.CreateChild(node));
                }
                else
                {
                    compiler.CompileNode(new IfExpression(firstelseif.Condition, firstelseif.Statements, rest,
                        new SourceSpan(firstelseif.Location.Start, (rest.Count > 0 ? rest.Last() : firstelseif).Location.End)), parent.CreateChild(node));
                }

                compiler.Dedent();
                compiler.AppendLine("}");
            }
        }
开发者ID:rzhw,项目名称:Fructose,代码行数:38,代码来源:IfUnless.cs


注:本文中的Compiler.AppendLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。