in src/langs/cpp/combinator.js [842:899]
emitConstruct(emitter, node) {
if (!node.params.length && !node.body.length) {
emitter.emitln(`${this.namespace}::Client::Client(){}`, this.level);
return;
}
// has super call
const hasSuperCall = function (item) {
if (item instanceof GrammerValue && item.type === 'call') {
return hasSuperCall(item.value);
}
return item instanceof GrammerCall && item.type === 'super';
};
const hasSuper = node.body.some(item => hasSuperCall(item));
// emit construct header
emitter.emit(`${this.namespace}::Client::Client(`);
if (node.params.length) {
let tmp = [];
node.params.forEach(param => {
tmp.push(`const shared_ptr<${this.emitType(param.type)}>& ${_avoidKeywords(param.key)}`);
this.addStatement(param.key, param.type, true);
});
let emit = new Emitter(this.config);
let str;
if (tmp.length > 3) {
let curr_row_len = emitter.currRow().length;
str = tmp.join(`,${emit.eol}${' '.repeat(curr_row_len)}`);
} else {
str = tmp.join(', ');
}
if (emitter instanceof Emitter) {
emitter.emit(str);
}
emitter.emit(')', this.level);
if (hasSuper) {
let tmp = [];
node.params.forEach(p => {
tmp.push(p.key);
});
emitter.emit(` : ${this.resolveName(this.object.extends[0])}(${tmp.join(', ')})`);
}
} else {
emitter.emit(')');
}
const nodes = node.body.filter(node => !hasSuperCall(node));
if (nodes.length) {
emitter.emitln(' {');
this.levelUp();
node.body.filter(node => !hasSuperCall(node)).forEach(node => {
this.grammer(emitter, node);
});
this.levelDown();
emitter.emitln('};', this.level);
emitter.emitln();
} else {
emitter.emitln(' {};');
}
}