File size: 2,162 Bytes
3ea44ec | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
#
# qooxdoo - the new era of web development
#
# http://qooxdoo.org
#
# Copyright:
# 2006-2012 1&1 Internet AG, Germany, http://www.1und1.de
#
# License:
# LGPL: http://www.gnu.org/licenses/lgpl.html
# EPL: http://www.eclipse.org/org/documents/epl-v10.php
# See the LICENSE file in the project's top-level directory for details.
#
# Authors:
# * Thomas Herchenroeder (thron7)
#
################################################################################
##
# Annotate AST scopes with a flag whether their symbols are evaluated at load
# time.
##
from ecmascript.frontend import treeutil
from ecmascript.transform.check import scopes
class LoadTimeAnnotator(scopes.ScopeVisitor):
def visit_file(self, scopeNode):
scopeNode.is_load_time = True
for cld in scopeNode.children:
self.visit(cld)
def visit_function(self, scopeNode):
node = scopeNode.node
# immediate-call functions are load-time = <inherit>
if (node.hasParentContext("call/operand") or
node.hasParentContext("call/operand/group")):
scopeNode.is_load_time = scopeNode.parent.is_load_time if scopeNode.parent else False
# 'defer' function is load-time = True
elif treeutil.isDeferFunction(node):
scopeNode.is_load_time = True
scopeNode.is_defer = True
else:
scopeNode.is_load_time = False
for cld in scopeNode.children:
self.visit(cld)
# ideally, we would traverse the ast of this scope, identify call sites
# of local functions, and propagate the own load-time info to the scope
# of those functions. this might become interesting for code
# outside the qx closed form.
# - ---------------------------------------------------------------------------
def load_time_check(scope_node):
load_time_checker = LoadTimeAnnotator()
scope_node.is_load_time = True # assume this is file-level
load_time_checker.visit(scope_node)
|