Lines Matching +full:child +full:- +full:ref
2 # SPDX-License-Identifier: BSD-3-Clause
10 The top-level entry point of the library is the DT class. DT.__init__() takes a
30 "Exception raised for devicetree-related errors"
34 Represents a node in the devicetree ('node-name { ... };').
62 stored in big-endian format.
113 def name(self) -> str:
117 # Converted to a property to discourage renaming -- that has to be done
122 def unit_addr(self) -> str:
129 def path(self) -> str:
144 def node_iter(self) -> Iterable['Node']:
159 def _get_prop(self, name: str) -> 'Property':
169 def _del(self) -> None:
191 for child in self.nodes.values():
192 s += textwrap.indent(child.__str__(), "\t") + "\n"
245 big-endian format, and strings are null-terminated. Putting multiple
246 comma-separated values in an assignment (e.g., 'x = < 1 >, "foo"') will
257 ----------------------------+------------------------
329 def type(self) -> Type:
370 def to_num(self, signed=False) -> int:
391 def to_nums(self, signed=False) -> List[int]:
413 def to_bytes(self) -> bytes:
431 def to_string(self) -> str:
441 not valid UTF-8.
450 ret = self.value.decode("utf-8")[:-1] # Strip null
454 "is not valid UTF-8")
458 def to_strings(self) -> List[str]:
467 Also raises DTError if any of the strings are not valid UTF-8.
476 ret = self.value.decode("utf-8").split("\0")[:-1]
480 "is not valid UTF-8")
484 def to_node(self) -> Node:
501 def to_nodes(self) -> List[Node]:
529 def to_path(self) -> Node:
548 path = self.value.decode("utf-8")[:-1]
552 "is not valid UTF-8")
558 f"{self.node.dt.filename} points to the non-existent node "
570 for i, (pos, marker_type, ref) in enumerate(self._markers):
571 if i < len(self._markers) - 1:
580 # end - 1 to strip off the null terminator
581 s += f' "{_decode_and_escape(self.value[pos:end - 1])}"'
585 s += " &" + ref
592 s += f" {ref}:"
594 s += " &" + ref
664 REF = 13 variable in _T
780 def root(self) -> Node:
785 # treat self._root as a non-None value until it's initialized
789 def get_node(self, path: str) -> Node:
794 For example, both dt.get_node("/foo/bar") and dt.get_node("bar-alias")
797 /dts-v1/;
808 bar-alias = &bar-label;
813 dt.get_node("bar-alias/baz") returns the 'baz' node.
821 _err(f"no alias '{alias}' found -- did you forget the leading "
826 def has_node(self, path: str) -> bool:
883 def node_iter(self) -> Iterable[Node]:
901 s = "/dts-v1/;\n\n"
1026 with open(filename, encoding="utf-8") as f:
1048 # Parses /dts-v1/ (expected) and /plugin/ (unsupported) at the start of
1049 # files. There may be multiple /dts-v1/ at the start of a file.
1057 # /plugin/ always comes after /dts-v1/
1062 self._parse_error("expected '/dts-v1/;' at start of file")
1065 # Parses /memreserve/, which appears after /dts-v1/
1085 # Top-level parsing loop
1096 elif tok.id in (_T.LABEL, _T.REF):
1103 if tok.id != _T.REF:
1134 # Parses the '{ ... };' part of 'node-name { ... };'.
1136 # We need to track which child nodes were defined in this set
1151 child = node.nodes.get(tok.val)
1152 if child:
1153 if child.name in current_child_names:
1154 self._parse_error(f'{child.path}: duplicate node name')
1156 child = Node(name=tok.val, parent=node, dt=self)
1160 _append_no_dup(child.labels, label)
1163 child._omit_if_no_ref = True
1165 node.nodes[child.name] = child
1166 self._parse_node(child)
1173 "/omit-if-no-ref/ can only be used on nodes")
1209 # _parse_node() helpers for parsing labels and /omit-if-no-ref/s before
1210 # nodes and properties. Returns a (<label list>, <omit-if-no-ref bool>)
1230 # Parses the right-hand side of property assignment
1235 # Remove any old value, path/phandle references, and in-value labels,
1261 prop.value += self._unescape(tok.val.encode("utf-8")) + b"\0"
1263 elif tok.id == _T.REF:
1289 if tok.id == _T.REF:
1293 "arrays with 32-bit elements")
1333 self._parse_error("expected two-digit byte or ']'")
1376 # comma-separated value
1388 # self-referential phandles (which get set to b'\0\0\0\0' initially).
1389 # Self-referential phandles must be rewritten instead of recreated, so
1502 elif self._check_token("-"):
1503 val -= self._eval_mul()
1526 if self._check_token("-"):
1527 return -self._eval_unary()
1562 val = self._unescape(match.group(tok_id).encode("utf-8"))
1621 filename = tok_val[tok_val.find('"') + 1:-1]
1627 self._lineno = int(tok_val.split()[0]) - 1
1628 self.filename = tok_val[tok_val.find('"') + 1:-1]
1672 # returns -1
1673 column = self._tok_i - self._file_contents.rfind("\n", 0,
1687 filename = self._unescape(filename.encode("utf-8"))
1689 filename = filename.decode("utf-8")
1691 self._parse_error("filename is not valid UTF-8")
1693 with self._open(filename, encoding="utf-8") as f:
1702 self._parse_error("recursive /include/:\n" + " ->\n".join(
1723 if label.id != _T.REF:
1736 path = s[1:-1]
1753 # Post-processing
1757 # Registers any manually-inserted phandle properties in
1771 _, marker_type, ref = marker
1774 if self._ref2node(ref) is node:
1817 pos, marker_type, ref = marker
1834 _append_no_dup(prop._label_offset_lst, (ref, len(res)))
1838 ref_node = self._ref2node(ref)
1842 # For /omit-if-no-ref/
1846 res += ref_node.path.encode("utf-8") + b'\0'
1854 # Store the final fixed-up value. Add the data after the last
1866 alias_re = re.compile("[0-9a-z-]+$")
1873 "should include only characters from [0-9a-z-]")
1888 # Removes any unreferenced nodes marked with /omit-if-no-ref/ from the
1948 # the string level, because the result might not be valid UTF-8 when
1972 # Return <char> as-is for other \<char>
1982 # The C tools support specifying stdin with '-' too
1983 if filename == "-":
2010 signed: bool = False) -> int:
2013 in big-endian format, which is standard in devicetree.
2030 def to_nums(data: bytes, length: int = 4, signed: bool = False) -> List[int]:
2033 are assumed to be in big-endian format, which is standard in devicetree.
2065 # Decodes the 'bytes' array 'b' as UTF-8 and backslash-escapes special
2068 # Hacky but robust way to avoid double-escaping any '\' spit out by
2072 return (b.decode("utf-8", "surrogateescape")
2074 .encode("utf-8", "surrogateescape")
2075 .decode("utf-8", "backslashreplace"))
2096 def _err(msg) -> NoReturn:
2115 _num_re = re.compile(r"(0[xX][0-9a-fA-F]+|[0-9]+)(?:ULL|UL|LL|U|L)?")
2119 _propnodename_re = re.compile(r"\\?([a-zA-Z0-9,._+*#?@-]+)")
2122 _nodename_chars = set(string.ascii_letters + string.digits + ',._+-@')
2128 "==", "!=", "!", "=", ",", ";", "+", "-", "*", "/", "%", "~", "?", ":",
2132 _byte_re = re.compile(r"[0-9a-fA-F]{2}")
2136 _unescape_re = re.compile(br'\\([0-7]{1,3}|x[0-9A-Fa-f]{1,2}|.)')
2150 r'^#(?:line)?[ \t]+([0-9]+[ \t]+"(?:[^\\"]|\\.)*")(?:[ \t]+[0-9]+){0,4}',
2153 _T.DTS_V1: r"(/dts-v1/)",
2157 _T.DEL_PROP: r"(/delete-property/)",
2158 _T.DEL_NODE: r"(/delete-node/)",
2159 _T.OMIT_IF_NO_REF: r"(/omit-if-no-ref/)",
2160 _T.LABEL: r"([a-zA-Z_][a-zA-Z0-9_]*):",
2162 _T.REF: r"&([a-zA-Z_][a-zA-Z0-9_]*|{[a-zA-Z0-9,._+*#?@/-]*})",
2166 # Return a token for end-of-file so that the parsing code can