-
Notifications
You must be signed in to change notification settings - Fork 40
feat(backend/sdoc_source_code): Linux Kernel Template proposal: auto-generate SPDX-Req-ID and SPDX-Req-HKey #2555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| from typing import Any | ||
|
|
||
| from strictdoc.backend.sdoc_source_code.models.source_node import SourceNode | ||
|
|
||
|
|
||
| class MarkerWriter: | ||
| def write( | ||
| self, | ||
| source_node: SourceNode, | ||
| rewrites: dict[Any, bytes], | ||
| comment_file_bytes: bytes, | ||
| ) -> bytes: | ||
| output = bytearray() | ||
| prev_end = 0 | ||
|
|
||
| for field_name_ in source_node.fields.keys(): | ||
| if field_name_ not in rewrites: | ||
| continue | ||
|
|
||
| rewrite = rewrites[field_name_] | ||
| location = source_node.fields_locations[field_name_] | ||
|
|
||
| output += comment_file_bytes[prev_end : location[0]] | ||
|
|
||
| output += bytes(field_name_, encoding="utf8") + b": " | ||
| output += rewrite | ||
|
|
||
| prev_end = location[1] | ||
|
|
||
| # Possible trailing whitespace after last token. | ||
| if prev_end < len(comment_file_bytes): | ||
| output += comment_file_bytes[prev_end:] | ||
|
|
||
| return bytes(output) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
strictdoc/backend/sdoc_source_code/models/source_location.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| from dataclasses import dataclass | ||
|
|
||
| from tree_sitter import Node | ||
|
|
||
|
|
||
| @dataclass | ||
| class ByteRange: | ||
| start: int | ||
| end: int | ||
|
|
||
| @classmethod | ||
| def create_from_ts_node(cls, node: Node) -> "ByteRange": | ||
| return cls( | ||
| start=node.start_byte, | ||
| end=node.end_byte, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from strictdoc.backend.sdoc_source_code.models.source_file_info import ( | ||
| SourceFileTraceabilityInfo, | ||
| ) | ||
| from strictdoc.backend.sdoc_source_code.models.source_node import SourceNode | ||
|
|
||
|
|
||
| class SourceWriter: | ||
| def write( | ||
| self, | ||
| trace_info: SourceFileTraceabilityInfo, | ||
| rewrites: dict[SourceNode, bytes], | ||
| file_bytes: bytes, | ||
| ) -> bytes: | ||
| output = bytearray() | ||
| prev_end = 0 | ||
|
|
||
| for source_node_ in trace_info.source_nodes: | ||
| if source_node_.comment_byte_range is None: | ||
| continue | ||
|
|
||
| if source_node_ not in rewrites: | ||
| continue | ||
|
|
||
| rewrite = rewrites[source_node_] | ||
| output += file_bytes[ | ||
| prev_end : source_node_.comment_byte_range.start | ||
| ] | ||
|
|
||
| output += rewrite | ||
|
|
||
| prev_end = source_node_.comment_byte_range.end | ||
|
|
||
| # Possible trailing whitespace after last token. | ||
| if prev_end < len(file_bytes): | ||
| output += file_bytes[prev_end:] | ||
|
|
||
| return bytes(output) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.