Commit fb4dc542 authored by Stefan Behnel's avatar Stefan Behnel

use new-style classes everywhere to prevent unexpected obstacles in getting 2to3 clean

parent f6fdecac
...@@ -170,7 +170,7 @@ def escape(raw_string): ...@@ -170,7 +170,7 @@ def escape(raw_string):
return raw_string return raw_string
class AnnotationItem: class AnnotationItem(object):
def __init__(self, style, text, tag="", size=0): def __init__(self, style, text, tag="", size=0):
self.style = style self.style = style
......
...@@ -929,7 +929,7 @@ class CCodeWriter(object): ...@@ -929,7 +929,7 @@ class CCodeWriter(object):
self.putln("__Pyx_FinishRefcountContext();") self.putln("__Pyx_FinishRefcountContext();")
class PyrexCodeWriter: class PyrexCodeWriter(object):
# f file output file # f file output file
# level int indentation level # level int indentation level
......
...@@ -15,7 +15,7 @@ import bisect, sys ...@@ -15,7 +15,7 @@ import bisect, sys
_END_POS = ((unichr(sys.maxunicode)*10),()) _END_POS = ((unichr(sys.maxunicode)*10),())
class ControlFlow: class ControlFlow(object):
def __init__(self, start_pos, incoming, parent): def __init__(self, start_pos, incoming, parent):
self.start_pos = start_pos self.start_pos = start_pos
......
...@@ -12,7 +12,7 @@ from Visitor import BasicVisitor ...@@ -12,7 +12,7 @@ from Visitor import BasicVisitor
from Errors import CompileError from Errors import CompileError
class EmptyScope: class EmptyScope(object):
def lookup(self, name): def lookup(self, name):
return None return None
......
...@@ -34,7 +34,7 @@ def dumptree(t): ...@@ -34,7 +34,7 @@ def dumptree(t):
print t.dump() print t.dump()
return t return t
class CompilationData: class CompilationData(object):
# Bundles the information that is passed from transform to transform. # Bundles the information that is passed from transform to transform.
# (For now, this is only) # (For now, this is only)
...@@ -48,7 +48,7 @@ class CompilationData: ...@@ -48,7 +48,7 @@ class CompilationData:
# result CompilationResult # result CompilationResult
pass pass
class Context: class Context(object):
# This class encapsulates the context needed for compiling # This class encapsulates the context needed for compiling
# one or more Cython implementation files along with their # one or more Cython implementation files along with their
# associated and imported declaration files. It includes # associated and imported declaration files. It includes
...@@ -556,7 +556,7 @@ class CompilationSource(object): ...@@ -556,7 +556,7 @@ class CompilationSource(object):
self.full_module_name = full_module_name self.full_module_name = full_module_name
self.cwd = cwd self.cwd = cwd
class CompilationOptions: class CompilationOptions(object):
""" """
Options to the Cython compiler: Options to the Cython compiler:
...@@ -597,7 +597,7 @@ class CompilationOptions: ...@@ -597,7 +597,7 @@ class CompilationOptions:
self.obj_only = 0 self.obj_only = 0
class CompilationResult: class CompilationResult(object):
""" """
Results from the Cython compiler: Results from the Cython compiler:
......
...@@ -3727,7 +3727,7 @@ class SwitchStatNode(StatNode): ...@@ -3727,7 +3727,7 @@ class SwitchStatNode(StatNode):
if self.else_clause is not None: if self.else_clause is not None:
self.else_clause.annotate(code) self.else_clause.annotate(code)
class LoopNode: class LoopNode(object):
def analyse_control_flow(self, env): def analyse_control_flow(self, env):
env.start_branching(self.pos) env.start_branching(self.pos)
......
...@@ -27,7 +27,7 @@ class NameNodeCollector(TreeVisitor): ...@@ -27,7 +27,7 @@ class NameNodeCollector(TreeVisitor):
self.name_nodes.append(node) self.name_nodes.append(node)
class SkipDeclarations: class SkipDeclarations(object):
""" """
Variable and function declarations can often have a deep tree structure, Variable and function declarations can often have a deep tree structure,
and yet most transformations don't need to descend to this depth. and yet most transformations don't need to descend to this depth.
......
...@@ -154,7 +154,7 @@ reserved_words = [ ...@@ -154,7 +154,7 @@ reserved_words = [
"cimport", "by", "with", "cpdef", "DEF", "IF", "ELIF", "ELSE" "cimport", "by", "with", "cpdef", "DEF", "IF", "ELIF", "ELSE"
] ]
class Method: class Method(object):
def __init__(self, name): def __init__(self, name):
self.name = name self.name = name
...@@ -176,7 +176,7 @@ resword_dict = build_resword_dict() ...@@ -176,7 +176,7 @@ resword_dict = build_resword_dict()
#------------------------------------------------------------------ #------------------------------------------------------------------
class CompileTimeScope: class CompileTimeScope(object):
def __init__(self, outer = None): def __init__(self, outer = None):
self.entries = {} self.entries = {}
...@@ -220,7 +220,7 @@ def initial_compile_time_env(): ...@@ -220,7 +220,7 @@ def initial_compile_time_env():
#------------------------------------------------------------------ #------------------------------------------------------------------
class SourceDescriptor: class SourceDescriptor(object):
""" """
A SourceDescriptor should be considered immutable. A SourceDescriptor should be considered immutable.
""" """
......
...@@ -23,7 +23,7 @@ except NameError: ...@@ -23,7 +23,7 @@ except NameError:
possible_identifier = re.compile(ur"(?![0-9])\w+$", re.U).match possible_identifier = re.compile(ur"(?![0-9])\w+$", re.U).match
nice_identifier = re.compile('^[a-zA-Z0-0_]+$').match nice_identifier = re.compile('^[a-zA-Z0-0_]+$').match
class BufferAux: class BufferAux(object):
writable_needed = False writable_needed = False
def __init__(self, buffer_info_var, stridevars, shapevars, def __init__(self, buffer_info_var, stridevars, shapevars,
...@@ -36,7 +36,7 @@ class BufferAux: ...@@ -36,7 +36,7 @@ class BufferAux:
def __repr__(self): def __repr__(self):
return "<BufferAux %r>" % self.__dict__ return "<BufferAux %r>" % self.__dict__
class Entry: class Entry(object):
# A symbol table entry in a Scope or ModuleNamespace. # A symbol table entry in a Scope or ModuleNamespace.
# #
# name string Python name of entity # name string Python name of entity
...@@ -158,7 +158,7 @@ class Entry: ...@@ -158,7 +158,7 @@ class Entry:
error(pos, "'%s' does not match previous declaration" % self.name) error(pos, "'%s' does not match previous declaration" % self.name)
error(self.pos, "Previous declaration is here") error(self.pos, "Previous declaration is here")
class Scope: class Scope(object):
# name string Unqualified name # name string Unqualified name
# outer_scope Scope or None Enclosing scope # outer_scope Scope or None Enclosing scope
# entries {string : Entry} Python name to entry, non-types # entries {string : Entry} Python name to entry, non-types
......
...@@ -85,7 +85,7 @@ class TestNormalizeTree(TransformTest): ...@@ -85,7 +85,7 @@ class TestNormalizeTree(TransformTest):
t = self.run_pipeline([NormalizeTree(None)], u"pass") t = self.run_pipeline([NormalizeTree(None)], u"pass")
self.assert_(len(t.stats) == 0) self.assert_(len(t.stats) == 0)
class TestWithTransform:#(TransformTest): Disabled class TestWithTransform(object): # (TransformTest): # Disabled!
def test_simplified(self): def test_simplified(self):
t = self.run_pipeline([WithTransform(None)], u""" t = self.run_pipeline([WithTransform(None)], u"""
......
...@@ -8,7 +8,7 @@ import PyrexTypes ...@@ -8,7 +8,7 @@ import PyrexTypes
import StringEncoding import StringEncoding
import sys import sys
class Signature: class Signature(object):
# Method slot signature descriptor. # Method slot signature descriptor.
# #
# has_dummy_arg boolean # has_dummy_arg boolean
...@@ -119,7 +119,7 @@ class Signature: ...@@ -119,7 +119,7 @@ class Signature:
return None return None
class SlotDescriptor: class SlotDescriptor(object):
# Abstract base class for type slot descriptors. # Abstract base class for type slot descriptors.
# #
# slot_name string Member name of the slot in the type object # slot_name string Member name of the slot in the type object
......
...@@ -10,7 +10,7 @@ import MacOS ...@@ -10,7 +10,7 @@ import MacOS
_code = 'misc' _code = 'misc'
class TS_Misc_Suite: class TS_Misc_Suite(object):
def DoScript(self, _object, _attributes={}, **_arguments): def DoScript(self, _object, _attributes={}, **_arguments):
"""DoScript: Execute an MPW command, any command that could be executed from the command line can be sent as a script. """DoScript: Execute an MPW command, any command that could be executed from the command line can be sent as a script.
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
# #
#======================================================================= #=======================================================================
class Action: class Action(object):
def same_as(self, other): def same_as(self, other):
return self is other return self is other
......
...@@ -83,7 +83,7 @@ def add_to_epsilon_closure(state_set, state): ...@@ -83,7 +83,7 @@ def add_to_epsilon_closure(state_set, state):
for state2 in state_set_2.keys(): for state2 in state_set_2.keys():
add_to_epsilon_closure(state_set, state2) add_to_epsilon_closure(state_set, state2)
class StateMap: class StateMap(object):
""" """
Helper class used by nfa_to_dfa() to map back and forth between Helper class used by nfa_to_dfa() to map back and forth between
sets of states from the old machine and states of the new machine. sets of states from the old machine and states of the new machine.
......
...@@ -18,7 +18,7 @@ import Regexps ...@@ -18,7 +18,7 @@ import Regexps
DUMP_NFA = 1 DUMP_NFA = 1
DUMP_DFA = 2 DUMP_DFA = 2
class State: class State(object):
""" """
This class is used as part of a Plex.Lexicon specification to This class is used as part of a Plex.Lexicon specification to
introduce a user-defined state. introduce a user-defined state.
...@@ -35,7 +35,7 @@ class State: ...@@ -35,7 +35,7 @@ class State:
self.name = name self.name = name
self.tokens = tokens self.tokens = tokens
class Lexicon: class Lexicon(object):
""" """
Lexicon(specification) builds a lexical analyser from the given Lexicon(specification) builds a lexical analyser from the given
|specification|. The specification consists of a list of |specification|. The specification consists of a list of
......
...@@ -15,7 +15,7 @@ from Transitions import TransitionMap ...@@ -15,7 +15,7 @@ from Transitions import TransitionMap
LOWEST_PRIORITY = -sys.maxint LOWEST_PRIORITY = -sys.maxint
class Machine: class Machine(object):
"""A collection of Nodes representing an NFA or DFA.""" """A collection of Nodes representing an NFA or DFA."""
states = None # [Node] states = None # [Node]
next_state_number = 1 next_state_number = 1
...@@ -59,7 +59,7 @@ class Machine: ...@@ -59,7 +59,7 @@ class Machine:
for s in self.states: for s in self.states:
s.dump(file) s.dump(file)
class Node: class Node(object):
"""A state of an NFA or DFA.""" """A state of an NFA or DFA."""
transitions = None # TransitionMap transitions = None # TransitionMap
action = None # Action action = None # Action
...@@ -101,13 +101,6 @@ class Node: ...@@ -101,13 +101,6 @@ class Node:
def get_action_priority(self): def get_action_priority(self):
return self.action_priority return self.action_priority
# def merge_actions(self, other_state):
# """Merge actions of other state into this state according
# to their priorities."""
# action = other_state.get_action()
# priority = other_state.get_action_priority()
# self.set_action(action, priority)
def is_accepting(self): def is_accepting(self):
return self.action is not None return self.action is not None
...@@ -128,7 +121,7 @@ class Node: ...@@ -128,7 +121,7 @@ class Node:
file.write(" %s [priority %d]\n" % (action, priority)) file.write(" %s [priority %d]\n" % (action, priority))
class FastMachine: class FastMachine(object):
""" """
FastMachine is a deterministic machine represented in a way that FastMachine is a deterministic machine represented in a way that
allows fast scanning. allows fast scanning.
...@@ -264,64 +257,3 @@ class FastMachine: ...@@ -264,64 +257,3 @@ class FastMachine:
return repr(c1) return repr(c1)
else: else:
return "%s..%s" % (repr(c1), repr(c2)) return "%s..%s" % (repr(c1), repr(c2))
##
## (Superseded by Machines.FastMachine)
##
## class StateTableMachine:
## """
## StateTableMachine is an alternative representation of a Machine
## that can be run more efficiently.
## """
## initial_states = None # {state_name:state_index}
## states = None # [([state] indexed by char code, Action)]
## special_map = {'bol':256, 'eol':257, 'eof':258}
## def __init__(self, m):
## """
## Initialise StateTableMachine from Machine |m|.
## """
## initial_states = self.initial_states = {}
## states = self.states = [None]
## old_to_new = {}
## i = 1
## for old_state in m.states:
## new_state = ([0] * 259, old_state.get_action())
## states.append(new_state)
## old_to_new[old_state] = i # new_state
## i = i + 1
## for name, old_state in m.initial_states.items():
## initial_states[name] = old_to_new[old_state]
## for old_state in m.states:
## new_state_index = old_to_new[old_state]
## new_table = states[new_state_index][0]
## transitions = old_state.transitions
## for c, old_targets in transitions.items():
## if old_targets:
## old_target = old_targets[0]
## new_target_index = old_to_new[old_target]
## if len(c) == 1:
## a = ord(c)
## else:
## a = self.special_map[c]
## new_table[a] = states[new_target_index]
## def dump(self, f):
## f.write("Plex.StateTableMachine:\n")
## f.write(" Initial states:\n")
## for name, index in self.initial_states.items():
## f.write(" %s: State %d\n" % (
## repr(name), id(self.states[index])))
## for i in xrange(1, len(self.states)):
## table, action = self.states[i]
## f.write(" State %d:" % i)
## if action:
## f.write("%s" % action)
## f.write("\n")
## f.write(" %s\n" % map(id,table))
...@@ -101,7 +101,7 @@ def CodeRange(code1, code2): ...@@ -101,7 +101,7 @@ def CodeRange(code1, code2):
# Abstract classes # Abstract classes
# #
class RE: class RE(object):
"""RE is the base class for regular expression constructors. """RE is the base class for regular expression constructors.
The following operators are defined on REs: The following operators are defined on REs:
......
...@@ -12,7 +12,7 @@ from Regexps import BOL, EOL, EOF ...@@ -12,7 +12,7 @@ from Regexps import BOL, EOL, EOF
import cython import cython
class Scanner: class Scanner(object):
""" """
A Scanner is used to read tokens from a stream of characters A Scanner is used to read tokens from a stream of characters
using the token set specified by a Plex.Lexicon. using the token set specified by a Plex.Lexicon.
......
...@@ -19,7 +19,7 @@ def re(s): ...@@ -19,7 +19,7 @@ def re(s):
""" """
return REParser(s).parse_re() return REParser(s).parse_re()
class REParser: class REParser(object):
def __init__(self, s): def __init__(self, s):
self.s = s self.s = s
......
...@@ -10,7 +10,7 @@ import string ...@@ -10,7 +10,7 @@ import string
from sys import maxint from sys import maxint
from types import TupleType from types import TupleType
class TransitionMap: class TransitionMap(object):
""" """
A TransitionMap maps an input event to a set of states. A TransitionMap maps an input event to a set of states.
An input event is one of: a range of character codes, An input event is one of: a range of character codes,
......
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