List<exprType> params = new ArrayList<exprType>();
for (exprType expr : args.args) { //note: self should be there already!
params.add((exprType) expr);
}
exprType starargs = args.vararg != null ? new Name(((NameTok) args.vararg).id, Name.Load, false) : null;
exprType kwargs = args.kwarg != null ? new Name(((NameTok) args.kwarg).id, Name.Load, false) : null;
List<keywordType> keywords = new ArrayList<keywordType>();
if (args.defaults != null) {
int diff = args.args.length - args.defaults.length;
FastStack<Integer> removePositions = new FastStack<Integer>(args.defaults.length);
for (int i = 0; i < args.defaults.length; i++) {
exprType expr = args.defaults[i];
if (expr != null) {
exprType name = params.get(i + diff);
if (name instanceof Name) {
removePositions.push(i + diff); //it's removed backwards, that's why it's a stack
keywords.add(new keywordType(new NameTok(((Name) name).id, NameTok.KeywordName), name, false));
} else {
Log.log("Expected: " + name + " to be a Name instance.");
}
}
}
while (removePositions.size() > 0) {
Integer pop = removePositions.pop();
params.remove((int) pop);
}
}
Call call;
if (isClassMethod && params.size() > 0) {
//We need to use the super() construct
//Something as:
//Expr[value=
// Call[func=
// Attribute[value=
// Call[func=Name[id=super, ctx=Load, reserved=false], args=[Name[id=Current, ctx=Load, reserved=false], Name[id=cls, ctx=Load, reserved=false]], keywords=[], starargs=null, kwargs=null],
// attr=NameTok[id=test, ctx=Attrib], ctx=Load],
// args=[], keywords=[], starargs=null, kwargs=null]
//]
exprType firstParam = params.remove(0);
Call innerCall = createCall("super", currentClassName, NodeUtils.getRepresentationString(firstParam));
Attribute attr = new Attribute(innerCall, new NameTok(NodeUtils.getRepresentationString(functionDef),
NameTok.Attrib), Attribute.Load);
call = new Call(attr, params.toArray(new Name[params.size()]), keywords.toArray(new keywordType[keywords