Commit e607ac75 authored by Robert Bradshaw's avatar Robert Bradshaw

merge

parents 8e01c45d b0511036
......@@ -168,16 +168,9 @@ class ExprNode(Node):
saved_subexpr_nodes = None
is_temp = 0
def get_child_attrs(self): return self.subexprs
child_attrs = property(fget=get_child_attrs)
def get_child_attrs(self):
"""Automatically provide the contents of subexprs as children, unless child_attr
has been declared. See Nodes.Node.get_child_accessors."""
if self.child_attrs is not None:
return self.child_attrs
elif self.subexprs is not None:
return self.subexprs
return self.subexprs
child_attrs = property(fget=get_child_attrs)
def not_implemented(self, method_name):
print_call_chain(method_name, "not implemented") ###
......@@ -3289,6 +3282,8 @@ class CondExprNode(ExprNode):
# false_val ExprNode
temp_bool = None
true_val = None
false_val = None
subexprs = ['test', 'true_val', 'false_val']
......
......@@ -108,7 +108,7 @@ class Context:
if debug_find_module:
print("Context.find_module: Parsing %s" % pxd_pathname)
source_desc = FileSourceDescriptor(pxd_pathname)
pxd_tree = self.parse(source_desc, scope.type_names, pxd = 1,
pxd_tree = self.parse(source_desc, scope, pxd = 1,
full_module_name = module_name)
pxd_tree.analyse_declarations(scope)
except CompileError:
......@@ -242,7 +242,7 @@ class Context:
self.modules[name] = scope
return scope
def parse(self, source_desc, type_names, pxd, full_module_name):
def parse(self, source_desc, scope, pxd, full_module_name):
if not isinstance(source_desc, FileSourceDescriptor):
raise RuntimeError("Only file sources for code supported")
source_filename = Utils.encode_filename(source_desc.filename)
......@@ -251,7 +251,7 @@ class Context:
f = Utils.open_source_file(source_filename, "rU")
try:
s = PyrexScanner(f, source_desc, source_encoding = f.encoding,
type_names = type_names, context = self)
scope = scope, context = self)
tree = Parsing.p_module(s, pxd, full_module_name)
finally:
f.close()
......@@ -304,7 +304,7 @@ class Context:
c_suffix = ".cpp"
else:
c_suffix = ".c"
result.c_file = Utils .replace_suffix(source, c_suffix)
result.c_file = Utils.replace_suffix(source, c_suffix)
c_stat = None
if result.c_file:
try:
......@@ -317,7 +317,7 @@ class Context:
scope = self.find_module(module_name, pos = initial_pos, need_pxd = 0)
errors_occurred = False
try:
tree = self.parse(source, scope.type_names, pxd = 0,
tree = self.parse(source, scope, pxd = 0,
full_module_name = full_module_name)
tree.process_implementation(scope, options, result)
except CompileError:
......
......@@ -2217,6 +2217,7 @@ class CascadedAssignmentNode(AssignmentNode):
# coerced_rhs_list [ExprNode] RHS coerced to type of each LHS
child_attrs = ["lhs_list", "rhs", "coerced_rhs_list"]
coerced_rhs_list = None
def analyse_declarations(self, env):
for lhs in self.lhs_list:
......@@ -2353,6 +2354,7 @@ class InPlaceAssignmentNode(AssignmentNode):
# (it must be a NameNode, AttributeNode, or IndexNode).
child_attrs = ["lhs", "rhs", "dup"]
dup = None
def analyse_declarations(self, env):
self.lhs.analyse_target_declaration(env)
......@@ -2987,6 +2989,7 @@ class ForInStatNode(LoopNode, StatNode):
# item NextNode used internally
child_attrs = ["target", "iterator", "body", "else_clause", "item"]
item = None
def analyse_declarations(self, env):
self.target.analyse_target_declaration(env)
......@@ -3103,7 +3106,7 @@ class ForFromStatNode(LoopNode, StatNode):
# is_py_target bool
# loopvar_name string
# py_loopvar_node PyTempNode or None
child_attrs = ["target", "bound1", "bound2", "step", "body", "else_clause", "py_loopvar_node"]
child_attrs = ["target", "bound1", "bound2", "step", "body", "else_clause"]
def analyse_declarations(self, env):
self.target.analyse_target_declaration(env)
......@@ -3317,6 +3320,7 @@ class ExceptClauseNode(Node):
# exc_vars (string * 3) local exception variables
child_attrs = ["pattern", "target", "body", "exc_value"]
exc_value = None
def analyse_declarations(self, env):
if self.target:
......
......@@ -281,23 +281,26 @@ class StringSourceDescriptor(SourceDescriptor):
class PyrexScanner(Scanner):
# context Context Compilation context
# type_names set Identifiers to be treated as type names
# included_files [string] Files included with 'include' statement
# compile_time_env dict Environment for conditional compilation
# compile_time_eval boolean In a true conditional compilation context
# compile_time_expr boolean In a compile-time expression context
resword_dict = build_resword_dict()
def __init__(self, file, filename, parent_scanner = None,
type_names = None, context = None, source_encoding=None):
scope = None, context = None, source_encoding=None):
Scanner.__init__(self, get_lexicon(), file, filename)
if parent_scanner:
self.context = parent_scanner.context
self.type_names = parent_scanner.type_names
self.included_files = parent_scanner.included_files
self.compile_time_env = parent_scanner.compile_time_env
self.compile_time_eval = parent_scanner.compile_time_eval
self.compile_time_expr = parent_scanner.compile_time_expr
else:
self.context = context
self.type_names = type_names
self.type_names = scope.type_names
self.included_files = scope.included_files
self.compile_time_env = initial_compile_time_env()
self.compile_time_eval = 1
self.compile_time_expr = 0
......
......@@ -12,10 +12,10 @@ def test():
cdef long neg = -1
cdef unsigned long pos = -2 # will be a large positive number
print "neg", neg > 0
print "pos", pos > -
print u"neg", neg > 0
print u"pos", pos > 0
D = { neg: 'neg', pos: 'pos' }
D = { neg: u'neg', pos: u'pos' }
print D[<object>neg]
print D[<object>pos]
......
__doc__ = u"""
>>> f(5, 7)
29509034655744L
>>> str(f(5, 7))
'29509034655744'
>>> g(13, 4)
32
......@@ -9,10 +9,6 @@ __doc__ = u"""
105.0
"""
import sys
if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u"L", u"")
def f(a,b):
a += b
a *= b
......
......@@ -6,9 +6,14 @@ __doc__ = u"""
>>> modint(9,2)
1
"""
import sys
if sys.version_info[0] < 3:
__doc__ = __doc__ + u"""
>>> print modptr()
spameggs
>>> modptr()
'spameggs'
"""
def modobj(obj2, obj3):
......@@ -25,5 +30,5 @@ def modptr():
str2 = "spam%s"
str3 = "eggs"
obj1 = str2 % str3
return obj1.decode(u"ASCII")
obj1 = str2 % str3 # '%' operator doesn't work on byte strings in Py3
return obj1
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment