本文整理汇总了C#中Compiler.CompileNode方法的典型用法代码示例。如果您正苦于以下问题:C# Compiler.CompileNode方法的具体用法?C# Compiler.CompileNode怎么用?C# Compiler.CompileNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Compiler
的用法示例。
在下文中一共展示了Compiler.CompileNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compile
public override void Compile(Compiler compiler, Node node, NodeParent parent)
{
var pa = (ParallelAssignmentExpression)node;
if (pa.Left.HasUnsplattedValue)
throw new FructoseCompileException("Unsplats not yet supported.", node);
if (pa.Right.Length == 1)
{
compiler.CompileNode(pa.Right[0], parent.CreateChild(node));
compiler.AppendLine("if(get_class($_stack[count($_stack)-1]) !== 'F_Array')");
compiler.Indent();
compiler.AppendLine("$_stack[] = F_Array::__from_array(array(array_pop($_stack)));");
compiler.Dedent();
}
else
{
compiler.AppendLine("$ptmp = array();");
foreach (var rval in pa.Right)
{
compiler.CompileNode(rval, parent.CreateChild(node));
compiler.AppendLine("$ptmp[] = array_pop($_stack);");
}
compiler.AppendLine("$_stack[] = F_Array::__from_array($ptmp);");
}
var sb = new StringBuilder();
foreach (var lval in pa.Left.LeftValues)
sb.Append(SimpleAssignment.assignmentVar(lval, parent) + ",");
compiler.AppendLine("@list({0}) = array_pop($_stack)->__ARRAY;", sb.ToString());
foreach (var lval in pa.Left.LeftValues.Reverse())
compiler.AppendLine("if({0} === NULL) {0} = new F_NilClass;", SimpleAssignment.assignmentVar(lval, parent));
}
示例2: 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("}");
}
示例3: 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());
}
示例4: 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));");
}
}
示例5: 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("}");
}
}
}
示例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("}");
}
示例7: 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));");
}
示例8: 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()) + ");");
}
示例9: 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()) + ");");
}
示例10: Compile
public override void Compile(Compiler compiler, Node node, NodeParent parent)
{
var cond = (ConditionalStatement)node;
Expression cond_expr = cond.Condition;
if(cond.IsUnless)
cond_expr = new NotExpression(cond_expr, cond.Location);
var elseif = cond.ElseStatement != null
? new List<ElseIfClause>() { new ElseIfClause(null, new Statements(cond.ElseStatement), cond.ElseStatement.Location) }
: new List<ElseIfClause>();
compiler.CompileNode(new IfExpression(cond_expr, new Statements(cond.Body), elseif, cond.Location), parent.CreateChild(node));
}
示例11: 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("}");
}
}
示例12: 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);
}
示例13: Compile
public override void Compile(Compiler compiler, Node node, NodeParent parent)
{
var sc = (StringConstructor)node;
switch (sc.Kind)
{
case StringKind.Symbol:
if (sc.Parts.Count != 1 || sc.Parts[0].NodeType != NodeTypes.StringLiteral)
throw new FructoseCompileException("Symbol interpolation not supported _yet_", node);
compiler.AppendLine("$_stack[] = F_Symbol::__from_string('{0}');", ((StringLiteral)sc.Parts[0]).Value.ToString().Replace("'", "\\'"));
break;
case StringKind.Command:
if (sc.Parts.Count != 1)
throw new FructoseCompileException("`` is escape-to-PHP operator, and only works with a string literal.", node);
if (sc.Parts[0].NodeType != NodeTypes.StringLiteral)
throw new FructoseCompileException("`` is escape-to-PHP operator, and only works with a string literal.", node);
compiler.AppendLine("// BEGIN: escape-to-PHP");
compiler.AppendLine(((StringLiteral)sc.Parts[0]).Value.ToString());
compiler.AppendLine("// END: escape-to-PHP");
break;
case StringKind.Mutable:
foreach (var part in ((IEnumerable<Expression>)sc.Parts).Reverse())
compiler.CompileNode(part, parent.CreateChild(node));
compiler.AppendLine("$_stack[] = F_String::__from_string('');");
for(int i = 0; i < sc.Parts.Count; i++)
compiler.AppendLine("$_stack[] = array_pop($_stack)->__operator_lshift(NULL, array_pop($_stack));");
break;
}
}
示例14: Compile
public override void Compile(Compiler compiler, Node node, NodeParent parent)
{
if (parent.OfType<MethodDefinition>().Count() > 0)
throw new FructoseCompileException("Nested methods are not supported.", node);
if (((MethodDefinition)node).Parameters.Mandatory.Length > ((MethodDefinition)node).Parameters.LeadingMandatoryCount)
throw new FructoseCompileException("Additional arguments after splats in methods are currently unsupported.", node);
string visibility = parent.OfType<ClassDefinition>().Count() > 0 ?
"public " : "";
string signature = visibility + "function " + Mangling.RubyMethodToPHP(((MethodDefinition)node).Name) + "(";
List<string> compiledParams = new List<string>();
if (((MethodDefinition)node).Name.Contains("__lambda_"))
compiledParams.Add("$_locals");
compiledParams.Add("$block");
foreach (var arg in ((MethodDefinition)node).Parameters.Mandatory)
compiledParams.Add("$" + Mangling.RubyIdentifierToPHP(arg.ToString()));
foreach (var arg in ((MethodDefinition)node).Parameters.Optional)
compiledParams.Add("$" + Mangling.RubyIdentifierToPHP(arg.Left.ToString()) + "=NULL");
signature += String.Join(", ", compiledParams);
signature += ")";
compiler.AppendLine(signature);
compiler.AppendLine("{");
compiler.Indent();
compiler.AppendLine("$_stack = array();");
compiler.AppendLine("if(!isset($_locals)) $_locals = new stdClass;");
if (parent.OfType<ClassDefinition>().Count() > 0)
{
compiler.AppendLine("if(!isset($_locals->self)) $_locals->self = $this;");
}
else
{
compiler.AppendLine("global $_gthis;");
compiler.AppendLine("if(!isset($_locals->self)) $_locals->self = $_gthis;");
}
compiler.AppendLine("if(!isset($_locals->block)) $_locals->block = $block;");
compiler.AppendLine("foreach(array(" + string.Join(", ", ((MethodDefinition)node).Parameters.Mandatory
.Select(arg => "\"" + Mangling.RubyIdentifierToPHP(arg.ToString()) + "\"")
.ToArray()) + ") as $parm)");
compiler.Indent();
compiler.AppendLine("$_locals->$parm = $$parm;");
compiler.Dedent();
foreach (var arg in ((MethodDefinition)node).Parameters.Optional)
{
string parm = Mangling.RubyIdentifierToPHP(arg.Left.ToString());
compiler.AppendLine("if($" + parm + " === NULL) {");
compiler.Indent();
compiler.CompileNode(arg.Right, parent.CreateChild(node));
compiler.AppendLine("$_locals->" + parm + " = array_pop($_stack);");
compiler.Dedent();
compiler.AppendLine("} else {");
compiler.Indent();
compiler.AppendLine("$_locals->" + parm + " = $" + parm + ";");
compiler.Dedent();
compiler.AppendLine("}");
}
if (((MethodDefinition)node).Parameters.Unsplat != null)
compiler.AppendLine("$_locals->" + Mangling.RubyIdentifierToPHP(((MethodDefinition)node).Parameters.Unsplat.ToString()) + " = "
+ "F_Array::__from_array(array_slice(func_get_args(), " + compiledParams.Count + "));");
compiler.AppendLine("global $_lambda_objs;");
compiler.AppendLine("global $_globals;");
foreach (var child in ((MethodDefinition)node).Body.Statements)
compiler.CompileNode(child, parent.CreateChild(node));
if (((MethodDefinition)node).Name.Contains("__lambda_"))
compiler.AppendLine("return array( 'locals' => $_locals, 'retval' => array_pop($_stack) );");
else
compiler.AppendLine("return array_pop($_stack);");
compiler.Dedent();
compiler.AppendLine("}");
}
示例15: Compile
public override void Compile(Compiler compiler, MethodCall node, NodeParent parent)
{
AssertParameters(node, 1);
compiler.CompileNode(node.Arguments.Expressions.First(), parent.CreateChild(node));
compiler.AppendLine("include array_pop($_stack)->F_to_s(NULL)->__STRING;");
}