def _Name(self, t): if getattr(t, "is_attribute", False): # This name is taking part in an attribute reference, and we don't # have the LHS of the dot here, so we check later return sym = self._symbol_table.get(t.value, namespace=t.namespace) if sym is None: raise symbols.UnknownSymbolError( "{0}: Could not resolve symbol name {1!r} " "within namespace {2!r}".format(t.lineno, t.value, symbols.stringify_tuple(t.namespace)) ) # Now that we've resolved this type symbol, we can update this node's # namespace t.namespace = sym.namespace # Either this variable has already been declared, in which case its # symbol's var_type is set, or it's about to be set in a declaration. # In either case, this setting is okay. if type(sym) == symbols.VariableSymbol: t.type = sym.var_type
def _correct_symbol_table(self): for sym in self._symbol_table.as_dict().itervalues(): if getattr(sym, 'var_type', False): # Fix VariableSymbol.var_type temp_namespace = sym.var_type[0] temp_name = sym.var_type[1] temp_sym = self._symbol_table.get( temp_name, namespace=temp_namespace, symbol_type=symbols.TypeSymbol) if not temp_sym: break sym.var_type = temp_sym.full_name type_params = [] for temp in sym.var_type_params: temp_namespace = temp[0] temp_name = temp[1] temp_sym = self._symbol_table.get( temp_name, namespace=temp_namespace, symbol_type=symbols.TypeSymbol) if not temp_sym: break type_params.append(temp_sym.full_name) sym.var_type_params = tuple(type_params) elif getattr(sym, 'base', False): # Fix TypeSymbol.base temp_namespace = sym.base[0] temp_name = sym.base[1] temp_sym = self._symbol_table.get( temp_name, namespace=temp_namespace, symbol_type=symbols.TypeSymbol) if not temp_sym: break sym.base = temp_sym.full_name elif getattr(sym, 'return_type', False): # Fix FunctionSymbol.return_type and FunctionSymbol.param_types temp_namespace = sym.return_type[0] temp_name = sym.return_type[1] temp_sym = self._symbol_table.get( temp_name, namespace=temp_namespace, symbol_type=symbols.TypeSymbol) if not temp_sym: break sym.return_type = temp_sym.full_name param_types = [] for temp in sym.param_types: temp_namespace = temp[0] temp_name = temp[1] temp_sym = self._symbol_table.get( temp_name, namespace=temp_namespace, symbol_type=symbols.TypeSymbol) if not temp_sym: break param_types.append(temp_sym.full_name) sym.param_types = tuple(param_types) else: # We've iterated through the table without errors return # We've broken from the for-loop due to an error raise symbols.UnknownSymbolError( '{2}: Could not resolve symbol name {0!r} ' 'within namespace {1!r}'.format( temp_name, symbols.stringify_tuple(temp_namespace), sym.token.lineno))