src.org.python.indexer.ast.NCall Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jython-installer Show documentation
Show all versions of jython-installer Show documentation
Jython is an implementation of the high-level, dynamic, object-oriented
language Python written in 100% Pure Java, and seamlessly integrated with
the Java platform. It thus allows you to run Python on any Java platform.
/**
* Copyright 2009, Google Inc. All rights reserved.
* Licensed to PSF under a Contributor Agreement.
*/
package org.python.indexer.ast;
import org.python.indexer.Scope;
import org.python.indexer.types.NClassType;
import org.python.indexer.types.NFuncType;
import org.python.indexer.types.NInstanceType;
import org.python.indexer.types.NType;
import org.python.indexer.types.NUnionType;
import org.python.indexer.types.NUnknownType;
import java.util.ArrayList;
import java.util.List;
public class NCall extends NNode {
static final long serialVersionUID = 5212954751978100639L;
public NNode func;
public List args;
public List keywords;
public NNode kwargs;
public NNode starargs;
public NCall(NNode func, List args, List keywords,
NNode kwargs, NNode starargs) {
this(func, args, keywords, kwargs, starargs, 0, 1);
}
public NCall(NNode func, List args, List keywords,
NNode kwargs, NNode starargs, int start, int end) {
super(start, end);
this.func = func;
this.args = args;
this.keywords = keywords;
this.kwargs = kwargs;
this.starargs = starargs;
addChildren(func, kwargs, starargs);
addChildren(args);
addChildren(keywords);
}
@Override
public NType resolve(Scope s) throws Exception {
NType ft = resolveExpr(func, s);
List argTypes = new ArrayList();
for (NNode a : args) {
argTypes.add(resolveExpr(a, s));
}
resolveList(keywords, s);
resolveExpr(starargs, s);
resolveExpr(kwargs, s);
if (ft.isClassType()) {
return setType(ft); // XXX: was new NInstanceType(ft)
}
if (ft.isFuncType()) {
return setType(ft.asFuncType().getReturnType().follow());
}
if (ft.isUnknownType()) {
NUnknownType to = new NUnknownType();
NFuncType at = new NFuncType(to);
NUnionType.union(ft, at);
return setType(to);
}
addWarning("calling non-function " + ft);
return setType(new NUnknownType());
}
@Override
public String toString() {
return "";
}
@Override
public void visit(NNodeVisitor v) {
if (v.visit(this)) {
visitNode(func, v);
visitNodeList(args, v);
visitNodeList(keywords, v);
visitNode(kwargs, v);
visitNode(starargs, v);
}
}
}