Skip to content

Commit 1e92493

Browse files
committed
Refactor ClangAnalyzer and implement
Signed-off-by: Rahul Krishna <[email protected]>
1 parent 5e70eb3 commit 1e92493

File tree

2 files changed

+1
-58
lines changed

2 files changed

+1
-58
lines changed

cldk/analysis/c/c_analysis.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ def get_C_compilation_unit(self, file_path: str) -> CTranslationUnit:
188188
Returns:
189189
CTranslationUnit: Compilation unit object for C source file
190190
"""
191-
if self.analysis_backend in [AnalysisEngine.CODEQL, AnalysisEngine.TREESITTER]:
192-
raise NotImplementedError("Support for this functionality has not been implemented yet.")
193-
return self.backend.get_C_compilation_unit(file_path)
191+
return self.c_application.translation_units.get(file_path)
194192

195193
def get_functions_in_file(self, file_name: str) -> List[CFunction]:
196194
"""Returns a dictionary of all methods of the given class.

cldk/analysis/c/clang/clang_analyzer.py

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -81,61 +81,6 @@ def __init__(self, compilation_database_path: Optional[Path] = None):
8181
if compilation_database_path:
8282
self.compilation_database = CompilationDatabase.fromDirectory(str(compilation_database_path))
8383

84-
@staticmethod
85-
def __find_libclang(self) -> str:
86-
"""
87-
Find libclang library on the system. This function detects the operating system
88-
and searches in platform-specific locations.
89-
90-
Returns:
91-
str: Path to the libclang library
92-
93-
Raises:
94-
RuntimeError: If libclang cannot be found in any of the expected locations
95-
"""
96-
system = platform.system()
97-
98-
if system == "Darwin": # macOS
99-
possible_paths = [
100-
# Apple Silicon Mac paths
101-
"/opt/homebrew/opt/llvm/lib/libclang.dylib",
102-
# Intel Mac paths
103-
"/usr/local/opt/llvm/lib/libclang.dylib",
104-
# Xcode path
105-
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib",
106-
]
107-
install_instructions = (
108-
"Could not find libclang. Please install LLVM using Homebrew:\n"
109-
" 1. Run: brew install llvm\n"
110-
" 2. Make sure the installation succeeded\n"
111-
" 3. You might need to restart your terminal"
112-
)
113-
elif system == "Linux":
114-
possible_paths = [
115-
# Common Linux paths for different LLVM versions
116-
"/usr/lib/llvm-14/lib/libclang.so",
117-
"/usr/lib/llvm-13/lib/libclang.so",
118-
"/usr/lib/llvm-12/lib/libclang.so",
119-
"/usr/lib/x86_64-linux-gnu/libclang-14.so.1",
120-
"/usr/lib/libclang.so",
121-
]
122-
install_instructions = (
123-
"Could not find libclang. Please install LLVM development libraries:\n"
124-
" Ubuntu/Debian: sudo apt-get install libclang-dev\n"
125-
" Fedora: sudo dnf install clang-devel\n"
126-
" Arch Linux: sudo pacman -S clang"
127-
)
128-
else:
129-
raise RuntimeError(f"Unsupported operating system: {system}")
130-
131-
# Try to find the library in the possible locations
132-
for path in possible_paths:
133-
if os.path.exists(path):
134-
logger.info(f"Found libclang at: {path}")
135-
return path
136-
137-
raise RuntimeError(install_instructions)
138-
13984
def analyze_file(self, file_path: Path) -> CTranslationUnit:
14085
"""Analyzes a single C source file using Clang."""
14186

0 commit comments

Comments
 (0)