Commit dfa643cf authored by Stefan Behnel's avatar Stefan Behnel

implement #686: turn 'undeclared builtin' error into a visible warning, look...

implement #686: turn 'undeclared builtin' error into a visible warning, look up unknown builtins at runtime when (and if) they are needed
parent a0a27779
...@@ -1339,7 +1339,7 @@ class NameNode(AtomicExprNode): ...@@ -1339,7 +1339,7 @@ class NameNode(AtomicExprNode):
if entry and entry.is_cfunction: if entry and entry.is_cfunction:
var_entry = entry.as_variable var_entry = entry.as_variable
if var_entry: if var_entry:
if var_entry.is_builtin and Options.cache_builtins: if var_entry.is_builtin and var_entry.is_const:
var_entry = env.declare_builtin(var_entry.name, self.pos) var_entry = env.declare_builtin(var_entry.name, self.pos)
node = NameNode(self.pos, name = self.name) node = NameNode(self.pos, name = self.name)
node.entry = var_entry node.entry = var_entry
...@@ -1436,7 +1436,7 @@ class NameNode(AtomicExprNode): ...@@ -1436,7 +1436,7 @@ class NameNode(AtomicExprNode):
if entry.is_declared_generic: if entry.is_declared_generic:
self.result_ctype = py_object_type self.result_ctype = py_object_type
if entry.is_pyglobal or entry.is_builtin: if entry.is_pyglobal or entry.is_builtin:
if Options.cache_builtins and entry.is_builtin: if entry.is_builtin and entry.is_const:
self.is_temp = 0 self.is_temp = 0
else: else:
self.is_temp = 1 self.is_temp = 1
...@@ -1447,7 +1447,7 @@ class NameNode(AtomicExprNode): ...@@ -1447,7 +1447,7 @@ class NameNode(AtomicExprNode):
if self.is_used_as_rvalue: if self.is_used_as_rvalue:
entry = self.entry entry = self.entry
if entry.is_builtin: if entry.is_builtin:
if not Options.cache_builtins: # cached builtins are ok if not entry.is_const: # cached builtins are ok
self.gil_error() self.gil_error()
elif entry.is_pyglobal: elif entry.is_pyglobal:
self.gil_error() self.gil_error()
...@@ -1525,7 +1525,7 @@ class NameNode(AtomicExprNode): ...@@ -1525,7 +1525,7 @@ class NameNode(AtomicExprNode):
entry = self.entry entry = self.entry
if entry is None: if entry is None:
return # There was an error earlier return # There was an error earlier
if entry.is_builtin and Options.cache_builtins: if entry.is_builtin and entry.is_const:
return # Lookup already cached return # Lookup already cached
elif entry.is_pyclass_attr: elif entry.is_pyclass_attr:
assert entry.type.is_pyobject, "Python global or builtin not a Python object" assert entry.type.is_pyobject, "Python global or builtin not a Python object"
......
...@@ -760,7 +760,7 @@ class BuiltinScope(Scope): ...@@ -760,7 +760,7 @@ class BuiltinScope(Scope):
if self.outer_scope is not None: if self.outer_scope is not None:
return self.outer_scope.declare_builtin(name, pos) return self.outer_scope.declare_builtin(name, pos)
else: else:
error(pos, "undeclared name not builtin: %s"%name) warning(pos, "undeclared name not builtin: %s" % name, 2)
def declare_builtin_cfunction(self, name, type, cname, python_equiv = None, def declare_builtin_cfunction(self, name, type, cname, python_equiv = None,
utility_code = None): utility_code = None):
...@@ -916,10 +916,16 @@ class ModuleScope(Scope): ...@@ -916,10 +916,16 @@ class ModuleScope(Scope):
if self.has_import_star: if self.has_import_star:
entry = self.declare_var(name, py_object_type, pos) entry = self.declare_var(name, py_object_type, pos)
return entry return entry
elif self.outer_scope is not None: ## elif self.outer_scope is not None:
return self.outer_scope.declare_builtin(name, pos) ## entry = self.outer_scope.declare_builtin(name, pos)
## print entry
## return entry
else: else:
error(pos, "undeclared name not builtin: %s"%name) # unknown - assume it's builtin and look it up at runtime
warning(pos, "undeclared name not builtin: %s" % name, 2)
entry = self.declare(name, None, py_object_type, pos, 'private')
entry.is_builtin = 1
return entry
if Options.cache_builtins: if Options.cache_builtins:
for entry in self.cached_builtins: for entry in self.cached_builtins:
if entry.name == name: if entry.name == name:
......
...@@ -56,14 +56,3 @@ def test_for_in_range(arg): ...@@ -56,14 +56,3 @@ def test_for_in_range(arg):
for c in range(arg): for c in range(arg):
l.append(c) l.append(c)
return l return l
def raise_and_catch_BaseException():
"""
>>> raise_and_catch_BaseException()
1
"""
try:
raise BaseException
except BaseException:
return 1
return 2
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