|
18 | 18 |
|
19 | 19 | import logging
|
20 | 20 | import re
|
21 |
| -from typing import Any, Generator, Iterable |
| 21 | +import string |
| 22 | +from typing import Any, Generator, Iterable, List, Tuple, Type |
22 | 23 |
|
23 | 24 | from .elements.dependency_spec import (
|
24 | 25 | BaseDependencySpec,
|
|
35 | 36 |
|
36 | 37 | _logger = logging.getLogger(__name__)
|
37 | 38 |
|
38 |
| -_VERILOG_IDENTIFIER = r"[a-zA-Z_][a-zA-Z0-9_$]+" |
| 39 | +_VERILOG_IDENTIFIER = "|".join( |
| 40 | + [r"[a-zA-Z_][a-zA-Z0-9_$]+", r"\\[%s]+(?=\s)" % string.printable.replace(" ", "")] |
| 41 | +) |
| 42 | + |
39 | 43 | _COMMENT = r"(?:\/\*.*?\*\/|//[^(?:\r\n?|\n)]*)"
|
40 | 44 |
|
41 | 45 |
|
|
55 | 59 | "|".join(
|
56 | 60 | [
|
57 | 61 | r"(?P<package>\b{0})\s*::\s*(?:{0}|\*)".format(_VERILOG_IDENTIFIER),
|
58 |
| - r"\bvirtual\s+class\s+(?P<class>\b{0})".format( |
| 62 | + r"(\bvirtual\b)?\s*\bclass\s+(?:static|automatic)?(?P<class>\b{0})".format( |
59 | 63 | _VERILOG_IDENTIFIER
|
60 | 64 | ),
|
61 | 65 | r"(?<=`include\b)\s*\"(?P<include>.*?)\"",
|
@@ -100,49 +104,38 @@ def _iterDesignUnitMatches(self):
|
100 | 104 | def _getDependencies(self): # type: () -> Iterable[BaseDependencySpec]
|
101 | 105 | text = self.getSourceContent()
|
102 | 106 |
|
103 |
| - for match in _DEPENDENCIES.finditer(text): |
104 |
| - include_name = match.groupdict().get("include", None) |
105 |
| - |
106 |
| - # package 'std' seems to be built-in. Need to have a look a this |
107 |
| - if include_name is not None: |
108 |
| - line_number = text[: match.end()].count("\n") |
109 |
| - column_number = len(text[: match.start()].split("\n")[-1]) |
110 |
| - |
111 |
| - yield IncludedPath( |
112 |
| - owner=self.filename, |
113 |
| - name=VerilogIdentifier(include_name), |
114 |
| - locations=(Location(line_number, column_number),), |
115 |
| - ) |
116 |
| - |
117 |
| - # Only SystemVerilog has imports |
118 |
| - if self.filetype is FileType.verilog: |
119 |
| - continue |
120 |
| - |
121 |
| - name = match.groupdict().get("package", None) |
| 107 | + match_groups = [ |
| 108 | + ("include", IncludedPath) |
| 109 | + ] # type: List[Tuple[str, Type[BaseDependencySpec]]] |
122 | 110 |
|
123 |
| - # package 'std' seems to be built-in. Need to have a look a this |
124 |
| - # if include_name is not None and include_name != 'std': |
125 |
| - if name not in (None, "std"): |
126 |
| - line_number = text[: match.end()].count("\n") |
127 |
| - column_number = len(text[: match.start()].split("\n")[-1]) |
| 111 | + # Only SystemVerilog has imports or classes |
| 112 | + if self.filetype is FileType.systemverilog: |
| 113 | + match_groups += [ |
| 114 | + ("package", RequiredDesignUnit), |
| 115 | + ("class", RequiredDesignUnit), |
| 116 | + ] |
128 | 117 |
|
129 |
| - yield RequiredDesignUnit( |
130 |
| - owner=self.filename, |
131 |
| - name=VerilogIdentifier(name), # type: ignore |
132 |
| - locations=(Location(line_number, column_number),), |
133 |
| - ) |
| 118 | + for match in _DEPENDENCIES.finditer(text): |
| 119 | + for match_group, klass in match_groups: |
| 120 | + name = match.groupdict().get(match_group, None) |
| 121 | + # package 'std' seems to be built-in. Need to have a look a |
| 122 | + # this if include_name is not None and include_name != 'std': |
| 123 | + if match_group == "package" and name == "std": |
| 124 | + continue |
134 | 125 |
|
135 |
| - name = match.groupdict().get("class", None) |
| 126 | + # package 'std' seems to be built-in. Need to have a look a this |
| 127 | + if name is None: |
| 128 | + continue |
136 | 129 |
|
137 |
| - if name is not None: |
138 | 130 | line_number = text[: match.end()].count("\n")
|
139 | 131 | column_number = len(text[: match.start()].split("\n")[-1])
|
140 | 132 |
|
141 |
| - yield RequiredDesignUnit( |
| 133 | + yield klass( |
142 | 134 | owner=self.filename,
|
143 | 135 | name=VerilogIdentifier(name),
|
144 | 136 | locations=(Location(line_number, column_number),),
|
145 | 137 | )
|
| 138 | + break |
146 | 139 |
|
147 | 140 | def _getDesignUnits(self): # type: () -> Generator[VerilogDesignUnit, None, None]
|
148 | 141 | for match, locations in self._iterDesignUnitMatches():
|
|
0 commit comments