Search in sources :

Example 6 with FunType

use of org.yinwang.pysonar.types.FunType in project pysonar2 by yinwang0.

the class TypeInferencer method visit.

@NotNull
@Override
public Type visit(FunctionDef node, State s) {
    State env = s.getForwarding();
    FunType fun = new FunType(node, env);
    fun.table.setParent(s);
    fun.table.setPath(s.extendPath(node.name.id));
    fun.setDefaultTypes(visit(node.defaults, s));
    Analyzer.self.addUncalled(fun);
    Binding.Kind funkind;
    if (node.isLamba) {
        return fun;
    } else {
        if (s.stateType == State.StateType.CLASS) {
            if ("__init__".equals(node.name.id)) {
                funkind = CONSTRUCTOR;
            } else {
                funkind = METHOD;
            }
        } else {
            funkind = FUNCTION;
        }
        Type outType = s.type;
        if (outType instanceof ClassType) {
            fun.setCls((ClassType) outType);
        }
        bind(s, node.name, fun, funkind);
        return Types.CONT;
    }
}
Also used : Binding(org.yinwang.pysonar.Binding) ClassType(org.yinwang.pysonar.types.ClassType) ListType(org.yinwang.pysonar.types.ListType) DictType(org.yinwang.pysonar.types.DictType) InstanceType(org.yinwang.pysonar.types.InstanceType) Type(org.yinwang.pysonar.types.Type) UnionType(org.yinwang.pysonar.types.UnionType) TupleType(org.yinwang.pysonar.types.TupleType) FunType(org.yinwang.pysonar.types.FunType) ModuleType(org.yinwang.pysonar.types.ModuleType) State(org.yinwang.pysonar.State) FunType(org.yinwang.pysonar.types.FunType) ClassType(org.yinwang.pysonar.types.ClassType) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with FunType

use of org.yinwang.pysonar.types.FunType in project pysonar2 by yinwang0.

the class TypeInferencer method bindMethodAttrs.

static void bindMethodAttrs(@NotNull FunType cl) {
    if (cl.table.parent != null) {
        Type cls = cl.table.parent.type;
        if (cls != null && cls instanceof ClassType) {
            addReadOnlyAttr(cl, "im_class", cls, CLASS);
            addReadOnlyAttr(cl, "__class__", cls, CLASS);
            addReadOnlyAttr(cl, "im_self", cls, ATTRIBUTE);
            addReadOnlyAttr(cl, "__self__", cls, ATTRIBUTE);
        }
    }
}
Also used : ClassType(org.yinwang.pysonar.types.ClassType) ListType(org.yinwang.pysonar.types.ListType) DictType(org.yinwang.pysonar.types.DictType) InstanceType(org.yinwang.pysonar.types.InstanceType) Type(org.yinwang.pysonar.types.Type) UnionType(org.yinwang.pysonar.types.UnionType) TupleType(org.yinwang.pysonar.types.TupleType) FunType(org.yinwang.pysonar.types.FunType) ModuleType(org.yinwang.pysonar.types.ModuleType) ClassType(org.yinwang.pysonar.types.ClassType)

Aggregations

FunType (org.yinwang.pysonar.types.FunType)7 Type (org.yinwang.pysonar.types.Type)5 UnionType (org.yinwang.pysonar.types.UnionType)5 ClassType (org.yinwang.pysonar.types.ClassType)4 DictType (org.yinwang.pysonar.types.DictType)4 InstanceType (org.yinwang.pysonar.types.InstanceType)4 ListType (org.yinwang.pysonar.types.ListType)4 ModuleType (org.yinwang.pysonar.types.ModuleType)4 TupleType (org.yinwang.pysonar.types.TupleType)4 NotNull (org.jetbrains.annotations.NotNull)3 ArrayList (java.util.ArrayList)2 Binding (org.yinwang.pysonar.Binding)2 State (org.yinwang.pysonar.State)2 HashMap (java.util.HashMap)1 CallStackEntry (org.yinwang.pysonar.CallStackEntry)1 FunctionDef (org.yinwang.pysonar.ast.FunctionDef)1