Example #1
0
def add_var_to_class(name: str, typ: Type, info: TypeInfo) -> None:
    """Add a variable with given name and type to the symbol table of a class.

    This also takes care about setting necessary attributes on the variable node.
    """
    var = Var(name)
    var.info = info
    var._fullname = fullname(info) + '.' + name
    var.type = typ
    info.names[name] = SymbolTableNode(MDEF, var)
def _add_var_to_class(name: str, typ: Type, info: TypeInfo) -> None:
    """
    Add a variable with given name and type to the symbol table of a class.
    This also takes care about setting necessary attributes on the variable node.
    """

    var = Var(name)
    var.info = info
    var._fullname = f'{info.fullname}.{name}'  # pylint: disable=protected-access
    var.type = typ
    info.names[name] = SymbolTableNode(MDEF, var)
Example #3
0
def _apply_placeholder_attr_to_class(
    api: SemanticAnalyzerPluginInterface,
    cls: ClassDef,
    qualified_name: str,
    attrname: str,
):
    sym = api.lookup_fully_qualified_or_none(qualified_name)
    if sym:
        assert isinstance(sym.node, TypeInfo)
        type_ = Instance(sym.node, [])
    else:
        type_ = AnyType(TypeOfAny.special_form)
    var = Var(attrname)
    var.info = cls.info
    var.type = type_
    cls.info.names[attrname] = SymbolTableNode(MDEF, var)
Example #4
0
def add_var_to_class(info: TypeInfo, name: str, typ: Type) -> None:
    var = Var(name)
    var.info = info
    var._fullname = get_fullname(info) + "." + name
    var.type = typ
    info.names[name] = SymbolTableNode(MDEF, var)
Example #5
0
 def add(self, name, type):
     v = Var(name)
     v.type = type
     self.names[name] = v
     return v
Example #6
0
        
        fdef.type = wrapper_sig
        return fdef

    Instance self_type(self):
        return self_type(self.tf.type_context())

    Scope make_scope(self):
        return Scope(self.tf.type_map)
        

class Scope:
    """Maintain a temporary local scope during transformation."""
    void __init__(self, dict<Node, Type> type_map):
        self.names = <str, Var> {}
        self.type_map = type_map

    Var add(self, str name, Type type):
        v = Var(name)
        v.type = type
        self.names[name] = v
        return v

    NameExpr name_expr(self, str name):
        nexpr = NameExpr(name)
        nexpr.kind = nodes.LDEF
        node = self.names[name]
        nexpr.node = node
        self.type_map[nexpr] = node.type
        return nexpr
Example #7
0
 def add(self, name: str, type: Type) -> Var:
     v = Var(name)
     v.type = type
     self.names[name] = v
     return v