當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。