addSpecialsAndClearOriginal(funcDefReturnAnn, actualReturnAnnotation);
}
argumentsType arguments = makeArguments(arity - 1);
NameTok nameTok = makeName(NameTok.FunctionName);
//decorator is always null at this point... it's decorated later on
FunctionDef funcDef = new FunctionDef(nameTok, arguments, body, null, actualReturnAnnotation);
addSpecialsAndClearOriginal(suite, funcDef);
setParentForFuncOrClass(body, funcDef);
return funcDef;
case JJTTFPDEF:
Name tfpdefName = null;
exprType typeDef = null;
if (arity == 1) {
tfpdefName = (Name) stack.popNode();
} else if (arity == 2) {
typeDef = (exprType) stack.popNode();
tfpdefName = (Name) stack.popNode();
} else {
throw new RuntimeException("Unexpected arity: " + arity);
}
return new JfpDef(tfpdefName, typeDef);
case JJTONLYKEYWORDARG2:
case JJTDEFAULTARG2:
DefaultArg defaultArg;
JfpDef jfpDef;
if (arity == 1) {
jfpDef = (JfpDef) stack.popNode();
defaultArg = new DefaultArg(jfpDef.nameNode, null, jfpDef.typeDef, n.getId());
} else if (arity == 2) {
exprType defaultValue = (exprType) stack.popNode();
jfpDef = (JfpDef) stack.popNode();
defaultArg = new DefaultArg(jfpDef.nameNode, defaultValue, jfpDef.typeDef, n.getId());
} else {
throw new RuntimeException("Unexpected arity: " + arity);
}
return defaultArg;
case JJTONLYKEYWORDARG:
case JJTDEFAULTARG:
//no type definition in this case
if (arity == 1) {
return new DefaultArg(((exprType) stack.popNode()), null, null, n.getId());
}
exprType parameter = (exprType) stack.popNode();
return new DefaultArg((exprType) stack.popNode(), parameter, null, n.getId());
case JJTEXTRAARGLIST:
if (arity == 0) {
//nothing here (just '*')
return new ExtraArg(null, JJTEXTRAARGLIST, null);
}
return new ExtraArg(makeName(NameTok.VarArg), JJTEXTRAARGLIST);
case JJTEXTRAKEYWORDLIST:
return new ExtraArg(makeName(NameTok.KwArg), JJTEXTRAKEYWORDLIST);
case JJTEXTRAARGLIST2: //with type declaration
if (arity == 0) {
//nothing here (just '*')
return new ExtraArg(null, JJTEXTRAARGLIST, null);
}
jfpDef = (JfpDef) stack.popNode();
NameTok jfpDefName = makeName(NameTok.VarArg, jfpDef.nameNode);
ExtraArg extra = new ExtraArg(jfpDefName, JJTEXTRAARGLIST, jfpDef.typeDef);
return extra;
case JJTEXTRAKEYWORDLIST2: //with type declaration
jfpDef = (JfpDef) stack.popNode();
return new ExtraArg(makeName(NameTok.KwArg, jfpDef.nameNode), JJTEXTRAKEYWORDLIST, jfpDef.typeDef);
case JJTDECORATED:
if (stack.nodeArity() != 2) {
throw new RuntimeException("Expected 2 nodes at this context, found: " + arity);
}
SimpleNode def = stack.popNode();
Decorators decorators = (Decorators) stack.popNode();
if (def instanceof ClassDef) {
ClassDef classDef = (ClassDef) def;
classDef.decs = decorators.exp;
} else {
FunctionDef fDef = (FunctionDef) def;
fDef.decs = decorators.exp;
}
return def;
case JJTCLASSDEF:
suite = (Suite) stack.popNode();