public static bool CheckMightNeedLocalsDictionary(Stmt s)
        {
            MightNeedLocalsWalker w = new MightNeedLocalsWalker();

            s.Walk(w);
            return(w.MightNeedLocals);
        }
示例#2
0
        private GlobalSuite DoBind(Stmt root)
        {
            GlobalSuite global = new GlobalSuite(root);

            current = global;

            // Detect all local names
            root.Walk(this);

            // Binding the free variables
            foreach (ScopeStatement scope in processed)
            {
                scope.BindNames(global, this);
            }

            // Validate
            foreach (ScopeStatement scope in processed)
            {
                if ((scope.ScopeInfo &
                     (ScopeStatement.ScopeFlags.ContainsFreeVariables |
                      ScopeStatement.ScopeFlags.ContainsImportStar |
                      ScopeStatement.ScopeFlags.ContainsUnqualifiedExec |
                      ScopeStatement.ScopeFlags.ContainsNestedFreeVariables)) == 0)
                {
                    continue;
                }

                FuncDef func;
                if ((func = scope as FuncDef) != null)
                {
                    if (func.ContainsImportStar && func.IsClosure)
                    {
                        ReportSyntaxError(String.Format("import * is not allowed in function '{0}' because it is a nested function", func.name.GetString()), func);
                    }
                    if (func.ContainsImportStar && func.parent is FuncDef)
                    {
                        ReportSyntaxError(String.Format("import * is not allowed in function '{0}' because it is a nested function", func.name.GetString()), func);
                    }
                    if (func.ContainsImportStar && func.ContainsNestedFreeVariables)
                    {
                        ReportSyntaxError(String.Format("import * is not allowed in function '{0}' because it contains a nested function with free variables", func.name.GetString()), func);
                    }
                    if (func.ContainsUnqualifiedExec && func.ContainsNestedFreeVariables)
                    {
                        ReportSyntaxError(String.Format("unqualified exec is not allowed in function '{0}' it contains a nested function with free variables", func.name.GetString()), func);
                    }
                }

                ClassDef cls;
                if ((cls = scope as ClassDef) != null)
                {
                    if (cls.ContainsImportStar)
                    {
                        // warning
                    }
                }
            }
            return(global);
        }
示例#3
0
 public override void Walk(IAstWalker w)
 {
     if (w.Walk(this))
     {
         body.Walk(w);
         finallyStmt.Walk(w);
     }
     w.PostWalk(this);
 }
示例#4
0
 public override void Walk(IAstWalker w)
 {
     if (w.Walk(this))
     {
         test.Walk(w);
         body.Walk(w);
     }
     w.PostWalk(this);
 }
示例#5
0
 public override void Walk(IAstWalker w)
 {
     if (w.Walk(this))
     {
         test.Walk(w);
         body.Walk(w);
         if (elseStmt != null)
         {
             elseStmt.Walk(w);
         }
     }
     w.PostWalk(this);
 }
示例#6
0
 public override void Walk(IAstWalker w)
 {
     if (w.Walk(this))
     {
         foreach (IfStmtTest t in tests)
         {
             t.Walk(w);
         }
         if (elseStmt != null)
         {
             elseStmt.Walk(w);
         }
     }
     w.PostWalk(this);
 }
示例#7
0
 public override void Walk(IAstWalker w)
 {
     if (w.Walk(this))
     {
         if (test != null)
         {
             test.Walk(w);
         }
         if (target != null)
         {
             target.Walk(w);
         }
         body.Walk(w);
     }
     w.PostWalk(this);
 }
示例#8
0
 public override void Walk(IAstWalker w)
 {
     if (w.Walk(this))
     {
         body.Walk(w);
         foreach (TryStmtHandler handler in handlers)
         {
             handler.Walk(w);
         }
         if (elseStmt != null)
         {
             elseStmt.Walk(w);
         }
     }
     w.PostWalk(this);
 }