mirror of
https://gitee.com/openharmony/napi_generator
synced 2024-11-27 10:40:37 +00:00
"modifile src/cli/dts2cpp/src/gen/generate/enum.js 修改js格式问题 和cpp头文件问题"
Signed-off-by: huruitao <huruitao@kaihong.com>
This commit is contained in:
parent
6e709c3e56
commit
f26c85b84c
@ -12,51 +12,51 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
const re = require("../tools/re");
|
||||
const { EnumValueType, getLogErrInfo } = require("../tools/common");
|
||||
const { NapiLog } = require("../tools/NapiLog");
|
||||
const re = require('../tools/re');
|
||||
const { EnumValueType, getLogErrInfo } = require('../tools/common');
|
||||
const { NapiLog } = require('../tools/NapiLog');
|
||||
function generateEnum(name, data, inNamespace, nameSpaceName, toolNamespace) {
|
||||
let implH = ""
|
||||
let implCpp = ""
|
||||
let midInitEnum = ""
|
||||
let midInitEnumDefine = ""
|
||||
let implH = '';
|
||||
let implCpp = '';
|
||||
let midInitEnum = '';
|
||||
let midInitEnumDefine = '';
|
||||
|
||||
if (data.enumValueType == EnumValueType.ENUM_VALUE_TYPE_STRING) {
|
||||
implH = `\nclass %s {\npublic:\n`.format(name, implH)
|
||||
implH = `\nclass %s {\npublic:\n`.format(name, implH);
|
||||
} else if (data.enumValueType == EnumValueType.ENUM_VALUE_TYPE_NUMBER){
|
||||
implH = `\nenum class %s {\n`.format(name, implH)
|
||||
implH = `\nenum class %s {\n`.format(name, implH);
|
||||
} else {
|
||||
NapiLog.logError(`The enum type[%s] is not support.`.format(data.enumValueType), getLogErrInfo());
|
||||
return {implH: "", implCpp: ""}
|
||||
return {implH: '', implCpp: ''};
|
||||
}
|
||||
for (let i in data.element) {
|
||||
let v = data.element[i]
|
||||
if(midInitEnumDefine == "") {
|
||||
midInitEnumDefine += 'std::map<const char *, std::any> enumMap%s;\n'.format(name)
|
||||
let v = data.element[i];
|
||||
if(midInitEnumDefine == '') {
|
||||
midInitEnumDefine += 'std::map<const char *, std::any> enumMap%s;\n'.format(name);
|
||||
}
|
||||
|
||||
if (data.enumValueType == EnumValueType.ENUM_VALUE_TYPE_STRING) {
|
||||
implH += ` static const std::string %s;\n`.format(v.name)
|
||||
implCpp += `\nconst std::string %s::%s = "%s";\n`.format(name, v.name, v.value)
|
||||
midInitEnum += ' %s%s::%senumMap%s["%s"] = "%s";\n'.format(inNamespace, nameSpaceName, toolNamespace, name, v.name, v.value)
|
||||
implH += ` static const std::string %s;\n`.format(v.name);
|
||||
implCpp += `\nconst std::string %s::%s = "%s";\n`.format(name, v.name, v.value);
|
||||
midInitEnum += ' %s%s::%senumMap%s["%s"] = "%s";\n'.format(inNamespace, nameSpaceName, toolNamespace, name, v.name, v.value);
|
||||
} else {
|
||||
if (v.value == '') {
|
||||
v.value = 0
|
||||
v.value = 0;
|
||||
}
|
||||
implH += ` %s = %s,\n`.format(v.name, v.value)
|
||||
midInitEnum += ' %s%s::%senumMap%s["%s"] = %s;\n'.format(inNamespace, nameSpaceName, toolNamespace, name, v.name, v.value)
|
||||
implH += ` %s = %s,\n`.format(v.name, v.value);
|
||||
midInitEnum += ' %s%s::%senumMap%s["%s"] = %s;\n'.format(inNamespace, nameSpaceName, toolNamespace, name, v.name, v.value);
|
||||
}
|
||||
}
|
||||
midInitEnum += ' pxt->CreateEnumObject("%s", %s%s::%senumMap%s);\n'.format(name, inNamespace, nameSpaceName, toolNamespace, name)
|
||||
implH += `};\n`
|
||||
midInitEnum += ' pxt->CreateEnumObject("%s", %s%s::%senumMap%s);\n'.format(name, inNamespace, nameSpaceName, toolNamespace, name);
|
||||
implH += `};\n`;
|
||||
let result = {
|
||||
implH: implH,
|
||||
implCpp: implCpp,
|
||||
midInitEnum: midInitEnum,
|
||||
midInitEnumDefine: midInitEnumDefine
|
||||
}
|
||||
return result
|
||||
};
|
||||
return result;
|
||||
}
|
||||
module.exports = {
|
||||
generateEnum
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user