in lib/generator.js [3723:3763]
eachFunc(ast, level, predefined, apis) {
const env = {
predefined,
apis,
local: new Map(),
returnType: ast.returnType,
hasThrow: ast.isAsync || ast.hasThrow,
yieldFunc: _isIterator(ast.returnType),
nestFuncParamName: new Map(),
nestFuncParamNameSubscript: { 'count': 0 }
};
const functionName = _name(ast.functionName);
this.visitAnnotation(ast.annotation, level);
let comments = DSL.comment.getFrontComments(this.comments, ast.tokenRange[0]);
this.visitComments(comments, level);
const name = _format(functionName);
env.funcName = name;
if (this.exec && name === 'Main') {
this.emit(`func _main `, level);
} else if(name.startsWith('$') && this.builtin[name]){
const method = name.replace('$', '');
this.builtin[name][method](ast.args, level);
return;
} else if (ast.isStatic) {
this.emit(`func ${name} `, level);
} else {
this.emit(`func (client *${this.structName}) ${name} `, level);
}
this.visitParams(ast.params, level, env);
this.visitReturnType(ast, level, env);
if (ast.functionBody) {
if(_isIterator(ast.returnType)) {
this.visitYieldFunction(ast, level + 1, env);
} else {
this.visitFunctionBody(ast.functionBody, level + 1, env);
}
} else {
this.emit(`panic("No Support!")\n`, level + 1);
}
this.emit(`}\n`, level);