Commit 80ad0b6f authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

bind-gen: Rename SequenceNode to ListNode

Renames SequenceNode to ListNode so that we can introduce another
SequenceNode that represents a "sequence of C++ code", where
SymbolDefinitionNodes can be inserted.

We'll have three list-ish code node.

- ListNode = a list of CodeNodes, nothing related to C++ code

- SequenceNode (new) = a list of C++ code where
  SymbolDefinitionNodes can be inserted

- SymbolScopeNode = a SequenceNode that represents a C++ block
  (= a scope of C++ variables)

Bug: 839389
Change-Id: I9478012b0449e754a953f4f02b2afbaaaaecb5e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1946175Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720788}
parent 5a043322
......@@ -42,7 +42,7 @@ class CodeNode(object):
- Graph structure
CodeNode can be nested and |outer| points to the nesting CodeNode. Also
CodeNode can make a sequence and |prev| points to the previous CodeNode.
See also |SequenceNode|.
See also |ListNode|.
- Template rendering
CodeNode has template text and template variable bindings. Either of
......@@ -358,9 +358,9 @@ class TextNode(CodeNode):
CodeNode.__init__(self, template_text=template_text)
class SequenceNode(CodeNode):
class ListNode(CodeNode):
"""
Represents a sequence of nodes.
Represents a list of nodes.
append, extend, insert, and remove work just like built-in list's methods
except that addition and removal of None have no effect.
......@@ -458,7 +458,7 @@ ${node}\\
node.reset_prev(None)
class SymbolScopeNode(SequenceNode):
class SymbolScopeNode(ListNode):
"""
Represents a sequence of nodes.
......@@ -467,7 +467,7 @@ class SymbolScopeNode(SequenceNode):
"""
def __init__(self, code_nodes=None, separator="\n", separator_last=""):
SequenceNode.__init__(
ListNode.__init__(
self,
code_nodes=code_nodes,
separator=separator,
......@@ -833,11 +833,11 @@ ${{{return_type}}} ${{{name}}}(${{{arg_decls}}})\
gensyms["name"]:
name,
gensyms["arg_decls"]:
SequenceNode(arg_decls, separator=", "),
ListNode(arg_decls, separator=", "),
gensyms["return_type"]:
return_type,
gensyms["member_initializer_list"]:
SequenceNode(member_initializer_list, separator=", "),
ListNode(member_initializer_list, separator=", "),
gensyms["body"]:
body,
gensyms["comment"]:
......
......@@ -7,7 +7,7 @@ import unittest
from .code_node import FunctionDefinitionNode
from .code_node import LikelyExitNode
from .code_node import LiteralNode
from .code_node import SequenceNode
from .code_node import ListNode
from .code_node import SymbolNode
from .code_node import SymbolScopeNode
from .code_node import TextNode
......@@ -57,10 +57,10 @@ class CodeNodeTest(unittest.TestCase):
def test_list_operations_of_sequence_node(self):
"""
Tests that list operations (insert, append, and extend) of SequenceNode
Tests that list operations (insert, append, and extend) of ListNode
work just same as Python built-in list.
"""
root = SequenceNode(separator=",")
root = ListNode(separator=",")
root.extend([
LiteralNode("2"),
LiteralNode("4"),
......@@ -76,9 +76,9 @@ class CodeNodeTest(unittest.TestCase):
self.assertRenderResult(root, "2,3,5")
def test_nested_sequence(self):
"""Tests nested SequenceNodes."""
root = SequenceNode(separator=",")
nested = SequenceNode(separator=",")
"""Tests nested ListNodes."""
root = ListNode(separator=",")
nested = ListNode(separator=",")
nested.extend([
LiteralNode("2"),
LiteralNode("3"),
......
......@@ -121,10 +121,10 @@ def _guess_caller_name(caller):
if value is caller:
return name
try:
# Outer SequenceNode may contain the caller.
# Outer ListNode may contain the caller.
for index, value in enumerate(caller.outer, 1):
if value is caller:
return "{}-of-{}-in-seq".format(index, len(caller.outer))
return "{}-of-{}-in-list".format(index, len(caller.outer))
except:
pass
return "<no name>"
......
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