Commit 75ab0c6e authored by Robert Bradshaw's avatar Robert Bradshaw

Verbose type inference directive.

parent 58e5be5f
...@@ -63,6 +63,7 @@ directive_defaults = { ...@@ -63,6 +63,7 @@ directive_defaults = {
'callspec' : "", 'callspec' : "",
'profile': False, 'profile': False,
'infer_types': False, 'infer_types': False,
'infer_types.verbose': False,
'autotestdict': True, 'autotestdict': True,
'warn': None, 'warn': None,
......
from Errors import error, warning, warn_once, InternalError
import ExprNodes import ExprNodes
import Nodes import Nodes
import Builtin import Builtin
...@@ -132,6 +133,7 @@ class SimpleAssignmentTypeInferer: ...@@ -132,6 +133,7 @@ class SimpleAssignmentTypeInferer:
# (Something more powerful than just extending this one...) # (Something more powerful than just extending this one...)
def infer_types(self, scope): def infer_types(self, scope):
enabled = scope.directives['infer_types'] enabled = scope.directives['infer_types']
verbose = scope.directives['infer_types.verbose']
if enabled == True: if enabled == True:
spanning_type = aggressive_spanning_type spanning_type = aggressive_spanning_type
elif enabled is None: # safe mode elif enabled is None: # safe mode
...@@ -178,6 +180,8 @@ class SimpleAssignmentTypeInferer: ...@@ -178,6 +180,8 @@ class SimpleAssignmentTypeInferer:
# FIXME: raise a warning? # FIXME: raise a warning?
# print "No assignments", entry.pos, entry # print "No assignments", entry.pos, entry
entry.type = py_object_type entry.type = py_object_type
if verbose:
warning(entry.pos, "inferred '%s' to be of type '%s'" % (entry.name, entry.type), 1)
resolve_dependancy(entry) resolve_dependancy(entry)
# Deal with simple circular dependancies... # Deal with simple circular dependancies...
for entry, deps in dependancies_by_entry.items(): for entry, deps in dependancies_by_entry.items():
...@@ -197,6 +201,8 @@ class SimpleAssignmentTypeInferer: ...@@ -197,6 +201,8 @@ class SimpleAssignmentTypeInferer:
# We can't figure out the rest with this algorithm, let them be objects. # We can't figure out the rest with this algorithm, let them be objects.
for entry in dependancies_by_entry: for entry in dependancies_by_entry:
entry.type = py_object_type entry.type = py_object_type
if verbose:
warning(entry.pos, "inferred '%s' to be of type '%s' (default)" % (entry.name, entry.type), 1)
def find_spanning_type(type1, type2): def find_spanning_type(type1, type2):
if type1 is type2: if type1 is type2:
......
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