Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | List of all members
cpp_indexer._Indexer Class Reference

Public Member Functions

 __init__ (self)
 
 index (self, TranslationUnit unit)
 

Public Attributes

 symbols_index
 
 processed_files
 
 classes_by_usr
 
 files_index
 
 name_stack
 
 info_stack
 
 files_seen_in_unit
 

Static Public Attributes

SymbolsIndex symbols_index
 
Set processed_files [str]
 
Dict classes_by_usr [str, _ClassInfo]
 
list name_stack [str]
 
list info_stack [_ClassInfo]
 
Set files_seen_in_unit [str]
 

Protected Member Functions

 _recurse (self, Cursor cursor)
 
 _format_location (self, SourceLocation loc)
 
 _get_file_index (self, str file_name)
 

Detailed Description

Definition at line 128 of file cpp_indexer.py.

Constructor & Destructor Documentation

◆ __init__()

cpp_indexer._Indexer.__init__ (   self)

Definition at line 138 of file cpp_indexer.py.

138 def __init__(self):
139 self.symbols_index = SymbolsIndex(commit=_get_current_commit_hash())
140
141 self.processed_files = set()
142 self.classes_by_usr = {}
143 self.files_index = {}
144
145 self.name_stack = []
146 self.info_stack = []
147 self.files_seen_in_unit = set()
148

Member Function Documentation

◆ _format_location()

cpp_indexer._Indexer._format_location (   self,
SourceLocation  loc 
)
protected

Definition at line 217 of file cpp_indexer.py.

217 def _format_location(self, loc: SourceLocation):
218 file_name = loc.file.name
219 lineno = loc.line
220 return f'{self._get_file_index(file_name)}:{lineno}'
221

◆ _get_file_index()

cpp_indexer._Indexer._get_file_index (   self,
str  file_name 
)
protected

Definition at line 222 of file cpp_indexer.py.

222 def _get_file_index(self, file_name: str):
223 index = self.files_index.get(file_name)
224 if index is None:
225 index = len(self.symbols_index.files)
226 self.files_index[file_name] = index
227 self.symbols_index.files.append(
228 os.path.relpath(os.path.abspath(file_name),
229 os.path.abspath('../..')))
230 return index
231
232

◆ _recurse()

cpp_indexer._Indexer._recurse (   self,
Cursor  cursor 
)
protected

Definition at line 157 of file cpp_indexer.py.

157 def _recurse(self, cursor: Cursor):
158 name = ""
159 kind = cursor.kind
160
161 if cursor.location.file is not None:
162 name = cursor.location.file.name
163 if name in self.processed_files or not name.startswith('../..'):
164 return
165 self.files_seen_in_unit.add(name)
166
167 if kind == CursorKind.CLASS_DECL:
168 if not cursor.is_definition():
169 return
170 usr = cursor.get_usr()
171 if usr in self.classes_by_usr:
172 return
173 self.name_stack.append(cursor.spelling)
174 class_name = '::'.join(self.name_stack)
175 class_info = _ClassInfo(self._format_location(cursor.location))
176 self.info_stack.append(class_info)
177 self.symbols_index.classes[class_name] = class_info
178 self.classes_by_usr[usr] = class_info
179 elif kind == CursorKind.NAMESPACE:
180 self.name_stack.append(cursor.spelling)
181 elif kind == CursorKind.FUNCTION_DECL and cursor.is_definition():
182 namespace_prefix = ""
183 if cursor.semantic_parent.kind == CursorKind.NAMESPACE:
184 namespace_prefix = '::'.join(self.name_stack) + (
185 '::' if len(self.name_stack) > 0 else "")
186 function_name = namespace_prefix + cursor.spelling
187 self.symbols_index.functions[function_name] = self._format_location(
188 cursor.location)
189 return
190 elif kind == CursorKind.CXX_METHOD and cursor.is_definition():
191 parent = cursor.semantic_parent
192 if parent.kind == CursorKind.CLASS_DECL:
193 class_info_or_none = self.classes_by_usr.get(parent.get_usr())
194 if class_info_or_none is None:
195 return
196 class_info_or_none.members[
197 cursor.spelling] = self._format_location(cursor.location)
198 return
199 elif kind == CursorKind.VAR_DECL and cursor.is_definition():
200 parent = cursor.semantic_parent
201 if parent.kind == CursorKind.CLASS_DECL:
202 class_info_or_none = self.classes_by_usr.get(parent.get_usr())
203 if class_info_or_none is None:
204 return
205 class_info_or_none.members[
206 cursor.spelling] = self._format_location(cursor.location)
207
208 for child in cursor.get_children():
209 self._recurse(child)
210
211 if kind == CursorKind.NAMESPACE:
212 self.name_stack.pop()
213 elif kind == CursorKind.CLASS_DECL:
214 self.name_stack.pop()
215 self.info_stack.pop()
216
static std::function< void(void)> pop(std::deque< std::function< void(void)> > *list)
static void append(char **dst, size_t *count, const char *src, size_t n)
Definition editor.cpp:211

◆ index()

cpp_indexer._Indexer.index (   self,
TranslationUnit  unit 
)
Index the given translation unit and append new symbols to index.

Definition at line 149 of file cpp_indexer.py.

149 def index(self, unit: TranslationUnit):
150 """Index the given translation unit and append new symbols to index."""
151 self.name_stack.clear()
152 self.info_stack.clear()
153 self.files_seen_in_unit.clear()
154 self._recurse(unit.cursor)
155 self.processed_files |= self.files_seen_in_unit
156

Member Data Documentation

◆ classes_by_usr [1/2]

Dict cpp_indexer._Indexer.classes_by_usr [str, _ClassInfo]
static

Definition at line 132 of file cpp_indexer.py.

◆ classes_by_usr [2/2]

cpp_indexer._Indexer.classes_by_usr

Definition at line 142 of file cpp_indexer.py.

◆ files_index

cpp_indexer._Indexer.files_index

Definition at line 143 of file cpp_indexer.py.

◆ files_seen_in_unit [1/2]

Set cpp_indexer._Indexer.files_seen_in_unit [str]
static

Definition at line 136 of file cpp_indexer.py.

◆ files_seen_in_unit [2/2]

cpp_indexer._Indexer.files_seen_in_unit

Definition at line 147 of file cpp_indexer.py.

◆ info_stack [1/2]

list cpp_indexer._Indexer.info_stack [_ClassInfo]
static

Definition at line 135 of file cpp_indexer.py.

◆ info_stack [2/2]

cpp_indexer._Indexer.info_stack

Definition at line 146 of file cpp_indexer.py.

◆ name_stack [1/2]

list cpp_indexer._Indexer.name_stack [str]
static

Definition at line 134 of file cpp_indexer.py.

◆ name_stack [2/2]

cpp_indexer._Indexer.name_stack

Definition at line 145 of file cpp_indexer.py.

◆ processed_files [1/2]

Set cpp_indexer._Indexer.processed_files [str]
static

Definition at line 131 of file cpp_indexer.py.

◆ processed_files [2/2]

cpp_indexer._Indexer.processed_files

Definition at line 141 of file cpp_indexer.py.

◆ symbols_index [1/2]

SymbolsIndex cpp_indexer._Indexer.symbols_index
static

Definition at line 129 of file cpp_indexer.py.

◆ symbols_index [2/2]

cpp_indexer._Indexer.symbols_index

Definition at line 139 of file cpp_indexer.py.


The documentation for this class was generated from the following file: