refator h2dts,h2dtscpp,h2sa,h2hdf,dts2cpp

Signed-off-by: wangshi <wangshi@kaihong.com>
This commit is contained in:
wangshi 2025-02-07 17:08:40 +08:00
parent e016893bd6
commit e015596d2f
7 changed files with 708 additions and 54 deletions

View File

@ -0,0 +1,86 @@
/*
* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as vscode from 'vscode';
import * as path from 'path';
import { IModel } from "./imodel";
import { parseHeaderFile } from '../parse/parsec';
import { GenInfo } from '../gen/datatype';
import { genDtsFile } from '../gen/gendts';
import { GEN_COMPLETE, PARSE_COMPLETE } from '../common/constants';
import {
EVENT_ERROR,
EVENT_INFORMATION,
EVENT_PROGRESS,
EVENT_WARNING
} from '../common/eventtype';
export class CrossCompileMod extends IModel {
name: string;
private static instance: CrossCompileMod;
constructor() {
super();
this.name = 'h2dtsmod';
}
static getInstance(): IModel {
if (!CrossCompileMod.instance) {
CrossCompileMod.instance = new CrossCompileMod();
}
return CrossCompileMod.instance;
}
init(uri: vscode.Uri): void {
this.uri = uri;
}
async doStart(): Promise<void> {
try {
if (this.uri) {
// parse
let parseRes = await parseHeaderFile(this.uri.fsPath);
console.log('parse header file res: ', parseRes);
this.emmitEventForKey(EVENT_PROGRESS, 50, PARSE_COMPLETE);
let rootInfo: GenInfo = {
parseObj: parseRes,
rawFilePath: this.uri.fsPath, // e://xxx.h
fileName: path.basename(this.uri.fsPath, '.h') // xxx
};
// generator
let outPath = genDtsFile(rootInfo);
this.emmitEventForKey(EVENT_PROGRESS, 100, PARSE_COMPLETE);
} else {
console.error('parse header file error with undefine uri.');
}
} catch (e) {
let errmsg = 'parse header file error: ' + JSON.stringify(e);
console.error(errmsg);
this.emmitEventForKey(EVENT_ERROR, -1, errmsg);
}
}
async doStop(): Promise<void> {
throw new Error("Method not implemented.");
}
async doPause(): Promise<void> {
throw new Error("Method not implemented.");
}
async doResume(): Promise<void> {
throw new Error("Method not implemented.");
}
}

View File

@ -0,0 +1,107 @@
/*
* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as vscode from 'vscode';
import * as path from 'path';
import { IModel } from "./imodel";
import { parseHeaderFile } from '../parse/parsec';
import { GenInfo } from '../gen/datatype';
import { genDtsFile } from '../gen/gendts';
import { GEN_COMPLETE, OPEN_IN_EXPLORER, PARSE_COMPLETE } from '../common/constants';
import {
EVENT_ERROR,
EVENT_INFORMATION,
EVENT_PROGRESS,
EVENT_WARNING
} from '../common/eventtype';
import { parseTsFile } from '../parse/parsets';
import { genCppFile } from '../gen/gendtscpp';
export class Dts2cppMod extends IModel {
name: string;
private static instance: Dts2cppMod;
constructor() {
super();
this.name = 'dts2cppmod';
}
static getInstance(): IModel {
if (!Dts2cppMod.instance) {
Dts2cppMod.instance = new Dts2cppMod();
}
return Dts2cppMod.instance;
}
init(uri: vscode.Uri): void {
this.uri = uri;
}
async doStart(): Promise<void> {
try {
if (this.uri) {
const filename = path.basename(this.uri.fsPath);
console.log('get filename ' );
if (filename.endsWith('.d.ts')) {
// Display a message box to the user
// analyze
let res = parseTsFile(this.uri.fsPath);
console.info('res: ' + JSON.stringify(res));
// progress.report({ increment: 50, message: PARSE_COMPLETE });
this.emmitEventForKey(EVENT_PROGRESS, 50, PARSE_COMPLETE);
// generator
let out = path.dirname(this.uri.fsPath);
genCppFile(res, this.uri.fsPath, out);
// progress.report({ increment: 100, message: GEN_COMPLETE + out });
this.emmitEventForKey(EVENT_PROGRESS, 100, PARSE_COMPLETE + out);
// show genarate path
const choice = await vscode.window.showInformationMessage(
'outPath:', path.dirname(this.uri.fsPath), OPEN_IN_EXPLORER);
if (choice === OPEN_IN_EXPLORER) {
// open the folder
vscode.commands.executeCommand(
'revealFileInOS', vscode.Uri.file(this.uri.fsPath));
}
} else {
let errmsg = 'not dts uri is : ' + this.uri.fsPath;
console.error(errmsg);
// Display a message box to the user
//vscode.window.showInformationMessage(`${this.uri.fsPath} is not a .d.ts file!`);
this.emmitEventForKey(EVENT_ERROR, -1, errmsg);
}
} else {
let errmsg = 'parse header file error with undefine uri';
console.error(errmsg);
this.emmitEventForKey(EVENT_ERROR, -1, errmsg);
}
} catch (e) {
let errmsg = 'parse header file error: ' + JSON.stringify(e);
console.error(errmsg);
this.emmitEventForKey(EVENT_ERROR, -1, errmsg);
}
}
async doStop(): Promise<void> {
throw new Error("Method not implemented.");
}
async doPause(): Promise<void> {
throw new Error("Method not implemented.");
}
async doResume(): Promise<void> {
throw new Error("Method not implemented.");
}
}

View File

@ -0,0 +1,105 @@
/*
* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as vscode from 'vscode';
import * as path from 'path';
import { IModel } from "./imodel";
import { parseHeaderFile } from '../parse/parsec';
import { DtscppRootInfo, GenInfo } from '../gen/datatype';
import { genDtsFile } from '../gen/gendts';
import { GEN_COMPLETE, OPEN_IN_EXPLORER, PARSE_COMPLETE } from '../common/constants';
import {
EVENT_ERROR,
EVENT_INFORMATION,
EVENT_PROGRESS,
EVENT_WARNING
} from '../common/eventtype';
import { genDtsCppFile } from '../gen/gendtscpp';
export class H2dtscppMod extends IModel {
name: string;
private static instance: H2dtscppMod;
constructor() {
super();
this.name = 'h2dtscppmod';
}
static getInstance(): IModel {
if (!H2dtscppMod.instance) {
H2dtscppMod.instance = new H2dtscppMod();
}
return H2dtscppMod.instance;
}
init(uri: vscode.Uri): void {
this.uri = uri;
}
async doStart(): Promise<void> {
try {
if (this.uri) {
// analyze
let funDescList = await parseHeaderFile(this.uri.fsPath);
let fileName = path.basename(this.uri.fsPath, '.h');
console.log('parse header file res: ', funDescList);
console.log('parse header file jsonstr: ', JSON.stringify(funDescList));
// progress.report({ increment: 50, message: PARSE_COMPLETE });
this.emmitEventForKey(EVENT_PROGRESS, 50, PARSE_COMPLETE);
let rootInfo: DtscppRootInfo = {
funcs: funDescList.funcs,
rawFilePath: this.uri.fsPath,
fileName: fileName // xxx
};
// generator
let out = path.dirname(this.uri.fsPath);
genDtsCppFile(rootInfo, out);
// progress.report({ increment: 100, message: GEN_COMPLETE + out });
this.emmitEventForKey(EVENT_PROGRESS, 100, PARSE_COMPLETE + out);
// show genarate path
const choice = await vscode.window.showInformationMessage(
'outPath:', path.dirname(this.uri.fsPath), OPEN_IN_EXPLORER);
if (choice === OPEN_IN_EXPLORER) {
// open the folder
vscode.commands.executeCommand(
'revealFileInOS', vscode.Uri.file(this.uri.fsPath));
}
} else {
let errmsg = 'parse header file error with undefine uri';
console.error(errmsg);
this.emmitEventForKey(EVENT_ERROR, -1, errmsg);
}
} catch (e) {
let errmsg = 'parse header file error: ' + JSON.stringify(e);
console.error(errmsg);
this.emmitEventForKey(EVENT_ERROR, -1, errmsg);
}
}
async doStop(): Promise<void> {
throw new Error("Method not implemented.");
}
async doPause(): Promise<void> {
throw new Error("Method not implemented.");
}
async doResume(): Promise<void> {
throw new Error("Method not implemented.");
}
}

View File

@ -20,68 +20,67 @@ import { GenInfo } from '../gen/datatype';
import { genDtsFile } from '../gen/gendts';
import { GEN_COMPLETE, PARSE_COMPLETE } from '../common/constants';
import {
EVENT_ERROR,
EVENT_INFORMATION,
EVENT_PROGRESS,
EVENT_WARNING
import {
EVENT_ERROR,
EVENT_INFORMATION,
EVENT_PROGRESS,
EVENT_WARNING
} from '../common/eventtype';
export class H2dtsMod extends IModel {
name: string;
private static instance: H2dtsMod;
constructor() {
super();
this.name = 'h2dtsmod';
}
name: string;
private static instance: H2dtsMod;
constructor() {
super();
this.name = 'h2dtsmod';
}
static getInstance(): IModel {
if (!H2dtsMod.instance) {
H2dtsMod.instance = new H2dtsMod();
}
return H2dtsMod.instance;
static getInstance(): IModel {
if (!H2dtsMod.instance) {
H2dtsMod.instance = new H2dtsMod();
}
return H2dtsMod.instance;
}
init(uri: vscode.Uri): void {
this.uri = uri;
init(uri: vscode.Uri): void {
this.uri = uri;
}
async doStart(): Promise<void> {
try {
if (this.uri) {
// parse
let parseRes = await parseHeaderFile(this.uri.fsPath);
console.log('parse header file res: ', parseRes);
this.emmitEventForKey(EVENT_PROGRESS, 50, PARSE_COMPLETE);
let rootInfo: GenInfo = {
parseObj: parseRes,
rawFilePath: this.uri.fsPath, // e://xxx.h
fileName: path.basename(this.uri.fsPath, '.h') // xxx
};
// generator
let outPath = genDtsFile(rootInfo);
this.emmitEventForKey(EVENT_PROGRESS, 100, PARSE_COMPLETE);
} else {
console.error('parse header file error with undefine uri.');
}
} catch (e) {
let errmsg = 'parse header file error: ' + JSON.stringify(e);
console.error(errmsg);
this.emmitEventForKey(EVENT_ERROR, -1, errmsg);
}
}
async doStart(): Promise<void> {
try {
if (this.uri) {
// parse
let parseRes = await parseHeaderFile(this.uri.fsPath);
console.log('parse header file res: ', parseRes);
this.emmitEventForKey(EVENT_PROGRESS, 50, PARSE_COMPLETE);
let rootInfo: GenInfo = {
parseObj: parseRes,
rawFilePath: this.uri.fsPath, // e://xxx.h
fileName: path.basename(this.uri.fsPath, '.h') // xxx
};
// generator
let outPath = genDtsFile(rootInfo);
this.emmitEventForKey(EVENT_PROGRESS, 100, PARSE_COMPLETE);
} else {
console.error('parse header file error with undefine uri.');
}
} catch (e) {
let errmsg = 'parse header file error: ' + JSON.stringify(e);
console.error(errmsg);
this.emmitEventForKey(EVENT_ERROR, -1, errmsg);
}
}
async doStop(): Promise<void> {
throw new Error("Method not implemented.");
}
async doStop(): Promise<void> {
throw new Error("Method not implemented.");
}
async doPause(): Promise<void> {
throw new Error("Method not implemented.");
}
async doResume(): Promise<void> {
throw new Error("Method not implemented.");
}
async doPause(): Promise<void> {
throw new Error("Method not implemented.");
}
async doResume(): Promise<void> {
throw new Error("Method not implemented.");
}
}

View File

@ -0,0 +1,115 @@
/*
* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as vscode from 'vscode';
import * as path from 'path';
import { IModel } from "./imodel";
import { parseHeaderFile } from '../parse/parsec';
import { GenInfo } from '../gen/datatype';
import { genDtsFile } from '../gen/gendts';
import { GEN_COMPLETE, OPEN_IN_EXPLORER, PARSE_COMPLETE } from '../common/constants';
import {
EVENT_ERROR,
EVENT_INFORMATION,
EVENT_PROGRESS,
EVENT_WARNING
} from '../common/eventtype';
import { genHdfFile } from '../gen/genhdf';
export class H2hdfMod extends IModel {
name: string;
versionTag: string = '4.1';
serviceId: string = '19000';
private static instance: H2hdfMod;
constructor() {
super();
this.name = 'h2dtsmod';
}
static getInstance(): IModel {
if (!H2hdfMod.instance) {
H2hdfMod.instance = new H2hdfMod();
}
return H2hdfMod.instance;
}
setVersionTag(version: string) {
this.versionTag = version;
}
setServiceId(id: string) {
this.serviceId = id;
}
init(uri: vscode.Uri): void {
this.uri = uri;
}
async generateHdf(hdfInputPath: string, versionTag: string) {
// analyze
let funDescList = await parseHeaderFile(hdfInputPath);
console.log('parse header file res: ', funDescList);
console.log('parse header file jsonstr: ', JSON.stringify(funDescList));
this.emmitEventForKey(EVENT_PROGRESS, 50, PARSE_COMPLETE);
// generator
let out = path.dirname(hdfInputPath);
let driverName = path.basename(hdfInputPath, '.h').toLocaleLowerCase();
let rootInfo = {
driverName: driverName,
funcs: funDescList.funcs,
versionTag: versionTag
};
genHdfFile(rootInfo, out);
// progress.report({ increment: 100, message: GEN_COMPLETE + out});
this.emmitEventForKey(EVENT_PROGRESS, 100, GEN_COMPLETE + out);
// toast the message of output dir
const choice = await vscode.window.showInformationMessage('outPath:', path.dirname(hdfInputPath), OPEN_IN_EXPLORER);
if (choice === OPEN_IN_EXPLORER) {
// open the output in folder
vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hdfInputPath));
}
}
async doStart(): Promise<void> {
try {
if (this.uri) {
this.generateHdf(this.uri.fsPath, this.versionTag);
} else {
let errmsg = 'parse header file error with undefine uri.';
console.error(errmsg);
this.emmitEventForKey(EVENT_ERROR, -1, errmsg);
}
} catch (e) {
let errmsg = 'parse header file error: ' + JSON.stringify(e);
console.error(errmsg);
this.emmitEventForKey(EVENT_ERROR, -1, errmsg);
}
}
async doStop(): Promise<void> {
throw new Error("Method not implemented.");
}
async doPause(): Promise<void> {
throw new Error("Method not implemented.");
}
async doResume(): Promise<void> {
throw new Error("Method not implemented.");
}
}

View File

@ -0,0 +1,115 @@
/*
* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as vscode from 'vscode';
import * as path from 'path';
import { IModel } from "./imodel";
import { parseHeaderFile } from '../parse/parsec';
import { GenInfo } from '../gen/datatype';
import { genDtsFile } from '../gen/gendts';
import { GEN_COMPLETE, OPEN_IN_EXPLORER, PARSE_COMPLETE } from '../common/constants';
import { genServiceFile } from '../gen/gensa';
import {
EVENT_ERROR,
EVENT_INFORMATION,
EVENT_PROGRESS,
EVENT_WARNING
} from '../common/eventtype';
export class H2saMod extends IModel {
name: string;
private static instance: H2saMod;
versionTag: string = '3.2';
serviceId: string = '19000';
constructor() {
super();
this.name = 'h2dtsmod';
}
static getInstance(): IModel {
if (!H2saMod.instance) {
H2saMod.instance = new H2saMod();
}
return H2saMod.instance;
}
init(uri: vscode.Uri): void {
this.uri = uri;
}
setVersionTag(version: string) {
this.versionTag = version;
}
setServiceId(id: string) {
this.serviceId = id;
}
async generateSa(hPath: string, versionTag: string, serviceId: string) {
// analyze
let funDescList = await parseHeaderFile(hPath);
console.log('parse header file res: ', funDescList);
console.log('parse header file jsonstr: ', JSON.stringify(funDescList));
this.emmitEventForKey(EVENT_PROGRESS, 50, PARSE_COMPLETE);
// generator
let out = path.dirname(hPath);
let serviceName = path.basename(hPath, '.h');
let rootInfo = {
serviceName: serviceName,
funcs: funDescList.funcs,
serviceId: serviceId,
versionTag: versionTag
};
genServiceFile(rootInfo, out);
// progress.report({ increment: 100, message: GEN_COMPLETE + out });
this.emmitEventForKey(EVENT_PROGRESS, 100, GEN_COMPLETE + out);
// select output dir
const choice = await vscode.window.showInformationMessage('outPath:', path.dirname(hPath), OPEN_IN_EXPLORER);
if (choice === OPEN_IN_EXPLORER) {
// open the folder
vscode.commands.executeCommand('revealFileInOS', vscode.Uri.file(hPath));
}
}
async doStart(): Promise<void> {
try {
if (this.uri) {
this.generateSa(this.uri.fsPath, this.versionTag, this.serviceId);
} else {
console.error('parse header file error with undefine uri.');
}
} catch (e) {
let errmsg = 'parse header file error: ' + JSON.stringify(e);
console.error(errmsg);
this.emmitEventForKey(EVENT_ERROR, -1, errmsg);
}
}
async doStop(): Promise<void> {
throw new Error("Method not implemented.");
}
async doPause(): Promise<void> {
throw new Error("Method not implemented.");
}
async doResume(): Promise<void> {
throw new Error("Method not implemented.");
}
}

View File

@ -0,0 +1,127 @@
/*
* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as vscode from 'vscode';
import * as path from 'path';
import { IModel } from "./imodel";
import { parseHeaderFile } from '../parse/parsec';
import { GenInfo } from '../gen/datatype';
import { genDtsFile } from '../gen/gendts';
import { GEN_COMPLETE, HDF_FRAMEWORK, NAPI_FRAMEWORK, PARSE_COMPLETE, SA_FRAMEWORK } from '../common/constants';
import {
EVENT_ERROR,
EVENT_INFORMATION,
EVENT_PROGRESS,
EVENT_WARNING
} from '../common/eventtype';
import { generateFuncTestCase } from '../gen/gentest';
import { H2hdfMod } from './h2hdfmod';
import { H2saMod } from './h2samod';
import { Dts2cppMod } from './dts2cppmod';
export class WelcomeMod extends IModel {
name: string;
versionTag: string = '4.1';
serviceId: string = '19000';
genType: string = HDF_FRAMEWORK;
private static instance: WelcomeMod;
constructor() {
super();
this.name = 'welcomemod';
}
static getInstance(): IModel {
if (!WelcomeMod.instance) {
WelcomeMod.instance = new WelcomeMod();
}
return WelcomeMod.instance;
}
setVersionTag(version: string) {
this.versionTag = version;
}
setServiceId(id: string) {
this.serviceId = id;
}
setGenType(value: string) {
this.genType = value;
}
init(uri: vscode.Uri): void {
this.uri = uri;
}
async doStart(): Promise<void> {
try {
if (this.uri) {
switch (this.genType) {
case NAPI_FRAMEWORK:
{
let dts2cppmod = Dts2cppMod.getInstance() as Dts2cppMod;
dts2cppmod.init(this.uri);
dts2cppmod.callbacks = this.callbacks;
dts2cppmod.doStart();
}
// generateDtscpp(this.uri.fsPath);
break;
case SA_FRAMEWORK:
{
let samod = H2saMod.getInstance() as H2saMod;
samod.init(this.uri);
samod.callbacks = this.callbacks;
samod.setServiceId(this.serviceId);
samod.setVersionTag(this.versionTag);
samod.doStart();
}
// generateSa(this.uri.fsPath, this.versionTag, this.serviceId);
break;
case HDF_FRAMEWORK:
let hdfmod = H2hdfMod.getInstance() as H2hdfMod;
hdfmod.init(this.uri);
hdfmod.callbacks = this.callbacks;
hdfmod.setServiceId(this.serviceId);
hdfmod.setVersionTag(this.versionTag);
hdfmod.doStart();
// generateHdf(this.uri.fsPath, this.versionTag);
break;
default:
console.error('unknown gen type: ', this.genType);
break;
}
} else {
console.error('parse header file error with undefine uri.');
}
} catch (e) {
let errmsg = 'parse header file error: ' + JSON.stringify(e);
console.error(errmsg);
this.emmitEventForKey(EVENT_ERROR, -1, errmsg);
}
}
async doStop(): Promise<void> {
throw new Error("Method not implemented.");
}
async doPause(): Promise<void> {
throw new Error("Method not implemented.");
}
async doResume(): Promise<void> {
throw new Error("Method not implemented.");
}
}