use of org.yinwang.pysonar.Binding in project pysonar2 by yinwang0.
the class ClassDef method addSpecialAttribute.
public void addSpecialAttribute(@NotNull State s, String name, Type proptype) {
Binding b = new Binding(name, Builtins.newTutUrl("classes.html"), proptype, Binding.Kind.ATTRIBUTE);
s.update(name, b);
b.markSynthetic();
b.markStatic();
}
use of org.yinwang.pysonar.Binding in project pysonar2 by yinwang0.
the class TypeInferencer method addReadOnlyAttr.
static void addReadOnlyAttr(@NotNull FunType fun, String name, @NotNull Type type, Binding.Kind kind) {
Node loc = Builtins.newDataModelUrl("the-standard-type-hierarchy");
Binding b = new Binding(name, loc, type, kind);
fun.table.update(name, b);
b.markSynthetic();
b.markStatic();
}
use of org.yinwang.pysonar.Binding in project pysonar2 by yinwang0.
the class TypeInferencer method visit.
@NotNull
@Override
public Type visit(Block node, State s) {
// first pass: mark global names
for (Node n : node.seq) {
if (n instanceof Global) {
for (Name name : ((Global) n).names) {
s.addGlobalName(name.id);
Set<Binding> nb = s.lookup(name.id);
if (nb != null) {
Analyzer.self.putRef(name, nb);
}
}
}
}
boolean returned = false;
Type retType = Types.UNKNOWN;
for (Node n : node.seq) {
Type t = visit(n, s);
if (!returned) {
retType = UnionType.union(retType, t);
if (!UnionType.contains(t, Types.CONT)) {
returned = true;
retType = UnionType.remove(retType, Types.CONT);
}
}
}
return retType;
}
use of org.yinwang.pysonar.Binding in project pysonar2 by yinwang0.
the class TypeInferencer method visit.
@NotNull
@Override
public Type visit(Call node, State s) {
Type fun;
Type selfType = null;
if (node.func instanceof Attribute) {
Node target = ((Attribute) node.func).target;
Name attr = ((Attribute) node.func).attr;
selfType = visit(target, s);
Set<Binding> b = selfType.table.lookupAttr(attr.id);
if (b != null) {
Analyzer.self.putRef(attr, b);
fun = State.makeUnion(b);
} else {
Analyzer.self.putProblem(attr, "Attribute is not found in type: " + attr.id);
fun = Types.UNKNOWN;
}
} else {
fun = visit(node.func, s);
}
// Infer positional argument types
List<Type> positional = visit(node.args, s);
// Infer keyword argument types
Map<String, Type> kwTypes = new HashMap<>();
if (node.keywords != null) {
for (Keyword k : node.keywords) {
kwTypes.put(k.arg, visit(k.value, s));
}
}
Type kwArg = node.kwargs == null ? null : visit(node.kwargs, s);
Type starArg = node.starargs == null ? null : visit(node.starargs, s);
if (fun instanceof UnionType) {
Set<Type> types = ((UnionType) fun).types;
Type resultType = Types.UNKNOWN;
for (Type funType : types) {
Type returnType = resolveCall(funType, selfType, positional, kwTypes, kwArg, starArg, node);
resultType = UnionType.union(resultType, returnType);
}
return resultType;
} else {
return resolveCall(fun, selfType, positional, kwTypes, kwArg, starArg, node);
}
}
use of org.yinwang.pysonar.Binding in project pysonar2 by yinwang0.
the class TypeInferencer method getAttrType.
public Type getAttrType(Attribute node, @NotNull Type targetType) {
Set<Binding> bs = targetType.table.lookupAttr(node.attr.id);
if (bs == null) {
addWarningToNode(node.attr, "attribute not found in type: " + targetType);
Type t = Types.UNKNOWN;
t.table.setPath(targetType.table.extendPath(node.attr.id));
return t;
} else {
for (Binding b : bs) {
Analyzer.self.putRef(node.attr, b);
}
return State.makeUnion(bs);
}
}
Aggregations