rokojori-godot/rokojori-cpp-generator/builds/cpp-creation/members/Method.js

69 lines
2.6 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Method = void 0;
const MemberType_1 = require("../MemberType");
const Member_1 = require("./Member");
class Method extends Member_1.Member {
constructor(memberInitializer) {
super(MemberType_1.MemberType.Method, memberInitializer);
this.implementation = null;
}
get hasMethodImplementation() {
return this.implementation != null;
}
getMethodImplementation(className) {
let lines = [];
lines.push(this.info());
lines.push(`${this.type} ${className}::${this.name}${this.parameterWithBrackets}`);
lines.push("{");
this.implementation.forEach(l => lines.push(" " + l));
lines.push("}");
return lines.join("\n") + "\n";
}
parseBody(body) {
if (Array.isArray(body)) {
let parameters = body[0];
let lines = body[1];
this.parseMethodParameters(parameters);
this.implementation = lines;
}
else {
return this.parseMethodParameters(body);
}
}
get parameterWithBrackets() {
let parameters = this.parametersDefinition === "" ? "()" :
`( ${this.parametersDefinition} )`;
return parameters;
}
getHeaderDefinition() {
let methodInfo = "\n " + this.info() + "\n ";
if (this.isVirtual) {
let numParameters = this.parameters.length;
let methodReturnType = this.type === "void" ? "" : "R";
let returnTypeDefinition = this.type === "void" ? "" : (this.type + ", ");
let parametersDefinition = "";
if (numParameters > 0) {
parametersDefinition = ", " + this.parameters.map(p => p.type).join(", ");
}
return `${methodInfo}GDVIRTUAL${numParameters}${methodReturnType}( ${returnTypeDefinition}${this.name}${parametersDefinition} );`;
}
let parameters = this.parameterWithBrackets;
return `${methodInfo}${this.type} ${this.name}${parameters};`;
}
getBindings(className) {
if (this.isVirtual) {
let parameterInfos = "";
for (let i = 0; i < this.parameters.length; i++) {
let name = `, "${this.parameters[i].name}"`;
parameterInfos += name;
}
return `GDVIRTUAL_BIND( ${this.name}${parameterInfos} );`;
}
else {
return `ClassDB::bind_method( D_METHOD( "${this.name}" ) , &${className}::${this.name} );`;
}
}
}
exports.Method = Method;
//# sourceMappingURL=Method.js.map