1/* 2* Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3* Licensed under the Apache License, Version 2.0 (the "License"); 4* you may not use this file except in compliance with the License. 5* You may obtain a copy of the License at 6* 7* http://www.apache.org/licenses/LICENSE-2.0 8* 9* Unless required by applicable law or agreed to in writing, software 10* distributed under the License is distributed on an "AS IS" BASIS, 11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12* See the License for the specific language governing permissions and 13* limitations under the License. 14*/ 15import * as vscode from 'vscode'; 16import * as path from 'path'; 17import { IModel } from "./imodel"; 18import { parseHeaderFile } from '../parse/parsec'; 19import { GenInfo } from '../gen/datatype'; 20import { genDtsFile } from '../gen/gendts'; 21import { GEN_COMPLETE, PARSE_COMPLETE } from '../common/constants'; 22import { Logger } from '../common/log'; 23import { 24 EVENT_ERROR, 25 EVENT_INFORMATION, 26 EVENT_PROGRESS, 27 EVENT_WARNING 28} from '../common/eventtype'; 29 30export class CrossCompileMod extends IModel { 31 name: string; 32 private static instance: CrossCompileMod; 33 constructor() { 34 super(); 35 this.name = 'h2dtsmod'; 36 } 37 38 static getInstance(): IModel { 39 if (!CrossCompileMod.instance) { 40 CrossCompileMod.instance = new CrossCompileMod(); 41 } 42 return CrossCompileMod.instance; 43 } 44 45 init(uri: vscode.Uri): void { 46 this.uri = uri; 47 } 48 49 async doStart(): Promise<void> { 50 try { 51 if (this.uri) { 52 // parse 53 let parseRes = await parseHeaderFile(this.uri.fsPath); 54 Logger.getInstance().debug('parse header file res: ' + parseRes); 55 this.emmitEventForKey(EVENT_PROGRESS, 50, PARSE_COMPLETE); 56 57 let rootInfo: GenInfo = { 58 parseObj: parseRes, 59 rawFilePath: this.uri.fsPath, // e://xxx.h 60 fileName: path.basename(this.uri.fsPath, '.h') // xxx 61 }; 62 // generator 63 let outPath = genDtsFile(rootInfo); 64 this.emmitEventForKey(EVENT_PROGRESS, 100, PARSE_COMPLETE); 65 } else { 66 Logger.getInstance().error('parse header file error with undefine uri.'); 67 } 68 } catch (e) { 69 let errmsg = 'parse header file error: ' + JSON.stringify(e); 70 Logger.getInstance().error(errmsg); 71 this.emmitEventForKey(EVENT_ERROR, -1, errmsg); 72 } 73 } 74 75 async doStop(): Promise<void> { 76 throw new Error("Method not implemented."); 77 } 78 79 async doPause(): Promise<void> { 80 throw new Error("Method not implemented."); 81 } 82 83 async doResume(): Promise<void> { 84 throw new Error("Method not implemented."); 85 } 86}