本文整理汇总了C#中CodeBlock.AddVariable方法的典型用法代码示例。如果您正苦于以下问题:C# CodeBlock.AddVariable方法的具体用法?C# CodeBlock.AddVariable怎么用?C# CodeBlock.AddVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CodeBlock
的用法示例。
在下文中一共展示了CodeBlock.AddVariable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InlineCall
protected internal static Expression InlineCall(CodeBlock parent, CodeBlockExpression cbe, bool istailpostion, params Expression[] pp)
{
// all var names are unique.
CodeBlock cb = cbe.Block;
if (parent.IsGlobal)
{
return CallNormal(cbe, pp);
}
List<Statement> assigns = new List<Statement>();
int i = 0;
cb.Inlined = true;
if (parent.Filename == null && cb.Filename != null)
{
parent.Filename = cb.Filename;
}
var parentvars = new List<Variable>(parent.Variables);
foreach (Variable p in cb.Parameters)
{
SymbolId origname = p.Name;
p.Name = (SymbolId)Builtins.GenSym(p.Name);
p.Block = parent;
p.Kind = Variable.VariableKind.Local;
parent.AddVariable(p);
Expression val = Unwrap(pp[i]);
if (val.Type != typeof(SymbolId) && !Generator.assigns.ContainsKey(origname))
{
if (p.Type == typeof(object))
{
p.Type = val.Type;
assigns.Add(Ast.Write(p, val));
}
else
{
assigns.Add(Ast.Write(p, Ast.ConvertHelper(val, p.Type)));
}
}
else
{
if (p.Type == typeof(object))
{
assigns.Add(Ast.Write(p, pp[i]));
}
else
{
assigns.Add(Ast.Write(p, Ast.ConvertHelper(pp[i], p.Type)));
}
}
if (p.Lift)
{
parent.HasEnvironment = true;
}
i++;
}
foreach (Variable l in cb.Variables)
{
if (l.DefaultValue == null && l.Kind != Variable.VariableKind.Global)
{
l.Name = (SymbolId)Builtins.GenSym(l.Name);
}
l.Block = parent;
parent.AddVariable(l);
if (l.Lift)
{
parent.HasEnvironment = true;
}
}
Expression body = RewriteReturn(cb.Body);
if (assigns.Count > 0)
{
return Ast.Comma(Ast.Void(Ast.Block(assigns)), body);
}
else
{
return body;
}
}
示例2: InlineCall
static Expression InlineCall(CodeBlock parent, CodeBlockExpression cbe, params Expression[] pp)
{
// all var names are unique.
CodeBlock cb = cbe.Block;
List<Statement> assigns = new List<Statement>();
int i = 0;
cb.Inlined = true;
var parentvars = new List<Variable>(parent.Variables);
foreach (Variable p in cb.Parameters)
{
SymbolId origname = p.Name;
p.Name = (SymbolId)Builtins.GenSym(p.Name);
p.Block = parent;
p.Kind = Variable.VariableKind.Local;
parent.AddVariable(p);
assigns.Add(Ast.Write(p, pp[i]));
if (p.Lift)
{
parent.HasEnvironment = true;
}
i++;
}
foreach (Variable l in cb.Variables)
{
if (l.DefaultValue == null && l.Kind != Variable.VariableKind.Global)
{
l.Name = (SymbolId)Builtins.GenSym(l.Name);
}
l.Block = parent;
parent.AddVariable(l);
if (l.Lift)
{
parent.HasEnvironment = true;
}
}
assigns.Add(cb.Body);
return Ast.Void(Ast.Block(assigns));
}