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


C# CodeBlock.AddVariable方法代码示例

本文整理汇总了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;
      }
    }
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:89,代码来源:Generator.cs

示例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));
                }
开发者ID:robertlj,项目名称:IronScheme,代码行数:49,代码来源:Optimizer.LoopHoist.cs


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