def _analyse_module_to_import(self, origin_node: ast.AST, target: str) -> Optional[ImportAnalyser]: analyser = ImportAnalyser(target) if analyser.can_be_imported: return analyser else: self._log_unresolved_import(origin_node, target)
def update_symbol_table_with_imports(self): if self._included_imported_files: return import os from boa3.analyser.importanalyser import ImportAnalyser from boa3.model.imports.importsymbol import Import imports = self._imported_files.copy() paths_already_imported = [ imported.origin for imported in self.symbol_table.values() if isinstance(imported, Import) and isinstance(imported.origin, str) ] if isinstance(self.path, str): paths_already_imported.append( self.path.replace(os.path.sep, constants.PATH_SEPARATOR)) for file_path, analyser in imports.items(): if file_path not in paths_already_imported: import_analyser = ImportAnalyser( file_path, self.root, already_imported_modules=imports, log=False, get_entry=True) import_symbol = Import(file_path, analyser.ast_tree, import_analyser, {}) self.symbol_table[file_path] = import_symbol self._included_imported_files = True
def __init__(self, origin: str, syntax_tree: ast.AST, import_analyser: ImportAnalyser, imported_symbols: Dict[str, ISymbol] = None): if imported_symbols is None: symbols = import_analyser.symbols else: symbols = import_analyser.export_symbols( list(imported_symbols.keys())) self.variables = { var_id: var for var_id, var in symbols.items() if isinstance(var, Variable) } self.methods = { fun_id: fun for fun_id, fun in symbols.items() if isinstance(fun, Method) } self.types = { type_id: tpe for type_id, tpe in symbols.items() if isinstance(tpe, IType) } self.imports = { alias: imprt for alias, imprt in symbols.items() if isinstance(imprt, Import) } self._other_symbols = { alias: symbol for alias, symbol in symbols.items() if not isinstance(symbol, (Variable, Method, IType, Import)) } self._symbols_not_imported = { alias: symbol for alias, symbol in import_analyser.symbols.items() if alias not in symbols } for method in self.methods.values(): if not isinstance(method, IBuiltinCallable) and hasattr( method, 'defined_by_entry'): # methods imported are treated as methods defined in the entry file method.defined_by_entry = True self.analyser = import_analyser.analyser self.origin: str = origin self.ast: ast.AST = syntax_tree
def __init__(self, origin: str, syntax_tree: ast.AST, import_analyser: ImportAnalyser, imported_symbols: Dict[str, ISymbol] = None): if imported_symbols is None: symbols = import_analyser.symbols else: symbols = import_analyser.export_symbols( list(imported_symbols.keys())) self.variables = { var_id: var for var_id, var in symbols.items() if isinstance(var, Variable) } self.methods = { fun_id: fun for fun_id, fun in symbols.items() if isinstance(fun, Method) } self.types = { type_id: tpe for type_id, tpe in symbols.items() if isinstance(tpe, IType) } self.imports = { alias: imprt for alias, imprt in symbols.items() if isinstance(imprt, Import) } self._other_symbols = { alias: symbol for alias, symbol in symbols.items() if not isinstance(symbol, (Variable, Method, IType, Import)) } self._symbols_not_imported = { alias: symbol for alias, symbol in import_analyser.symbols.items() if alias not in symbols } self.origin: str = origin self.ast: ast.AST = syntax_tree