Skip to content
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

[Frontend] Generalise SourceCodeFile class #1997

Merged
merged 4 commits into from
Jan 18, 2025

Conversation

arthurscchan
Copy link
Contributor

This PR generalise the SourceCodeFile classes and simplify some of the frontend logic.

@arthurscchan arthurscchan marked this pull request as ready for review January 17, 2025 22:06
@arthurscchan arthurscchan marked this pull request as draft January 17, 2025 22:30
@arthurscchan arthurscchan marked this pull request as ready for review January 17, 2025 22:30
Copy link
Contributor

@DavidKorczynski DavidKorczynski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will land this and adjust some of these things myself


class SourceCodeFile():
"""Class for holding file-specific information."""
LANGUAGE: dict[str, Language] = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LANGUAGE is too generic of a name here

LANGUAGE: dict[str, Language] = {
'c': Language(tree_sitter_c.language()),
'cpp': Language(tree_sitter_cpp.language()),
'c++': Language(tree_sitter_cpp.language()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use language constants from constants.py here

with open(self.source_file, 'rb') as f:
self.source_content = f.read()

# Initialization ruotines
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

self.root = self.parser.parse(self.source_content).root_node

def language_specific_process(self):
"""Dummy function to perform some specific processes in subclasses."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

am not sure if we should use dummy here, or just give documentation as how classes inherit from here should use the function


logger = logging.getLogger(name=__name__)


class SourceCodeFile():
class CppSourceCodeFile(SourceCodeFile):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to have the language post SourceCodeFile here, this applies to the other classes as well.

@DavidKorczynski DavidKorczynski merged commit 8cf9aef into ossf:main Jan 18, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants