code_formatter: make it easier to insert whitespace

a newline by just doing "code()". indent() and dedent() now take a
"count" parameter to indent/dedent multiple levels.
This commit is contained in:
Nathan Binkert 2010-09-09 14:15:41 -07:00
parent 18ef1bcfa2
commit c514ad9b09
2 changed files with 15 additions and 11 deletions

View file

@ -559,17 +559,17 @@ $vid->setDescription("[Version " + to_string(m_version) + ", ${ident}, name=${{v
# Set the queue consumers # Set the queue consumers
code.insert_newline() code()
for port in self.in_ports: for port in self.in_ports:
code('${{port.code}}.setConsumer(this);') code('${{port.code}}.setConsumer(this);')
# Set the queue descriptions # Set the queue descriptions
code.insert_newline() code()
for port in self.in_ports: for port in self.in_ports:
code('${{port.code}}.setDescription("[Version " + to_string(m_version) + ", $ident, $port]");') code('${{port.code}}.setDescription("[Version " + to_string(m_version) + ", $ident, $port]");')
# Initialize the transition profiling # Initialize the transition profiling
code.insert_newline() code()
for trans in self.transitions: for trans in self.transitions:
# Figure out if we stall # Figure out if we stall
stall = False stall = False

View file

@ -131,12 +131,12 @@ class code_formatter(object):
if args: if args:
self.__call__(args) self.__call__(args)
def indent(self): def indent(self, count=1):
self._indent_level += self._indent_spaces self._indent_level += self._indent_spaces * count
def dedent(self): def dedent(self, count=1):
assert self._indent_level >= self._indent_spaces assert self._indent_level >= (self._indent_spaces * count)
self._indent_level -= self._indent_spaces self._indent_level -= self._indent_spaces * count
def fix(self, status): def fix(self, status):
previous = self._fix_newlines previous = self._fix_newlines
@ -200,10 +200,14 @@ class code_formatter(object):
initial_newline = False initial_newline = False
def insert_newline(self): def __call__(self, *args, **kwargs):
if not args:
self._data.append('\n') self._data.append('\n')
return
format = args[0]
args = args[1:]
def __call__(self, format, *args, **kwargs):
frame = inspect.currentframe().f_back frame = inspect.currentframe().f_back
l = lookup(self, frame, *args, **kwargs) l = lookup(self, frame, *args, **kwargs)