idlize

Форк
0
/
FileGenerators.ts 
619 строк · 21.0 Кб
1
/*
2
 * Copyright (c) 2024 Huawei Device 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
 */
15
import * as fs from "fs"
16
import * as path from "path"
17
import { IndentedPrinter } from "../IndentedPrinter"
18
import { PrimitiveType } from "./DeclarationTable"
19
import { Language } from "../util"
20
import { CppLanguageWriter, createLanguageWriter, LanguageWriter, Method, MethodSignature, NamedMethodSignature, PrinterLike, Type } from "./LanguageWriters"
21
import { PeerGeneratorConfig } from "./PeerGeneratorConfig";
22
import { PeerEventKind } from "./printers/EventsPrinter"
23
import { writeDeserializer, writeSerializer } from "./printers/SerializerPrinter"
24
import { writeConvertors } from "./printers/ConvertorsPrinter"
25
import { PeerLibrary } from "./PeerLibrary"
26
import { ArkoalaInstall, LibaceInstall } from "../Install"
27

28
export const warning = "WARNING! THIS FILE IS AUTO-GENERATED, DO NOT MAKE CHANGES, THEY WILL BE LOST ON NEXT GENERATION!"
29

30
function dateChunk(): string {
31
    const currentYear = (new Date()).getFullYear()
32
    if (currentYear > 2024) return `2024-${currentYear}`
33
    return `${currentYear}`
34
}
35

36
export const cStyleCopyright =
37
`/*
38
 * Copyright (c) ${dateChunk()} Huawei Device Co., Ltd.
39
 * Licensed under the Apache License, Version 2.0 (the "License");
40
 * you may not use this file except in compliance with the License.
41
 * You may obtain a copy of the License at
42
 *
43
 * http://www.apache.org/licenses/LICENSE-2.0
44
 *
45
 * Unless required by applicable law or agreed to in writing, software
46
 * distributed under the License is distributed on an "AS IS" BASIS,
47
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
48
 * See the License for the specific language governing permissions and
49
 * limitations under the License.
50
 */
51
`
52

53
export const sharpCopyright =
54
`# Copyright (c) ${dateChunk()} Huawei Device Co., Ltd.
55
# Licensed under the Apache License, Version 2.0 (the "License");
56
# you may not use this file except in compliance with the License.
57
# You may obtain a copy of the License at
58
#
59
# http://www.apache.org/licenses/LICENSE-2.0
60
#
61
# Unless required by applicable law or agreed to in writing, software
62
# distributed under the License is distributed on an "AS IS" BASIS,
63
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
64
# See the License for the specific language governing permissions and
65
# limitations under the License.
66
`
67

68
const importTsInteropTypes = `
69
import {
70
    int32,
71
    float32
72
} from "@koalaui/common"
73
import {
74
    KInt,
75
    KBoolean,
76
    KFloat,
77
    KUInt,
78
    KStringPtr,
79
    KPointer,
80
    KNativePointer,
81
    KInt32ArrayPtr,
82
    KUint8ArrayPtr,
83
    KFloat32ArrayPtr,
84
    pointer
85
} from "@koalaui/interop"
86
`.trim()
87

88
export function nativeModuleDeclaration(methods: LanguageWriter, nativeBridgePath: string, useEmpty: boolean, language: Language): string {
89
    return `
90
  ${language == Language.TS ? importTsInteropTypes : ""}
91

92
${readLangTemplate("NativeModule_template", language)
93
    .replace("%NATIVE_BRIDGE_PATH%", nativeBridgePath)
94
    .replace("%USE_EMPTY%", useEmpty.toString())
95
    .replaceAll("%GENERATED_METHODS%", methods.getOutput().join('\n'))}
96
`
97
}
98

99
export function nativeModuleEmptyDeclaration(methods: string[]): string {
100
    return `
101
${importTsInteropTypes}
102
import { NativeModule, NativeModuleIntegrated, NodePointer, PipelineContext } from "./NativeModule"
103
import { nullptr } from "@koalaui/interop"
104

105
${readTemplate('NativeModuleEmpty_template.ts')
106
    .replaceAll("%GENERATED_EMPTY_METHODS%", methods.join('\n'))}
107
`
108
}
109

110
export function libraryCcDeclaration(): string {
111
    return readTemplate('library_template.cc')
112
        .replaceAll(`%CPP_PREFIX%`, PeerGeneratorConfig.cppPrefix)
113
}
114

115
export function bridgeCcGeneratedDeclaration(generatedApi: string[]): string {
116
    let prologue = readTemplate('bridge_generated_prologue.cc')
117
        .replaceAll(`%CPP_PREFIX%`, PeerGeneratorConfig.cppPrefix)
118

119
    return prologue.concat("\n")
120
        .concat(generatedApi.join("\n"))
121
}
122

123
export function bridgeCcCustomDeclaration(customApi: string[]): string {
124
    let prologue = readTemplate('bridge_custom_prologue.cc')
125
        .replaceAll(`%CPP_PREFIX%`, PeerGeneratorConfig.cppPrefix)
126

127
    return prologue.concat("\n")
128
        .concat(customApi.join("\n"))
129
}
130

131
export function appendModifiersCommonPrologue(): LanguageWriter {
132
    let result = createLanguageWriter(Language.CPP)
133
    let body = readTemplate('impl_prologue.cc')
134

135
    body = body.replaceAll("%CPP_PREFIX%", PeerGeneratorConfig.cppPrefix)
136

137
    result.writeLines(body)
138
    return result
139
}
140

141
export function appendViewModelBridge(): LanguageWriter {
142
    let result = createLanguageWriter(Language.CPP)
143
    let body = readTemplate('view_model_bridge.cc')
144

145
    body = body.replaceAll("%CPP_PREFIX%", PeerGeneratorConfig.cppPrefix)
146

147
    result.writeLines(body)
148
    return result
149
}
150

151
export function completeModifiersContent(content: PrinterLike, basicVersion: number, fullVersion: number, extendedVersion: number): LanguageWriter {
152
    let result = createLanguageWriter(Language.CPP)
153
    let epilogue = readTemplate('dummy_impl_epilogue.cc')
154

155
    epilogue = epilogue
156
        .replaceAll("%CPP_PREFIX%", PeerGeneratorConfig.cppPrefix)
157
        .replaceAll(`%ARKUI_BASIC_NODE_API_VERSION_VALUE%`, basicVersion.toString())
158
        .replaceAll(`%ARKUI_FULL_API_VERSION_VALUE%`, fullVersion.toString())
159
        .replaceAll(`%ARKUI_EXTENDED_NODE_API_VERSION_VALUE%`, extendedVersion.toString())
160
    result.writeLines(`
161
void SetAppendGroupedLog(void* pFunc) {}
162
`)
163
    result.concat(content)
164
    result.writeLines(epilogue)
165
    return result
166
}
167

168
export function completeDelegatesImpl(lines: string): string {
169
    return `
170
#include "delegates.h"
171

172
${lines}
173
`
174
}
175

176
export function dummyImplementations(modifiers: LanguageWriter, accessors: LanguageWriter, basicVersion: number, fullVersion: number, extendedVersion: number): LanguageWriter {
177
    let prologue = readTemplate('dummy_impl_prologue.cc')
178
    let epilogue = readTemplate('dummy_impl_epilogue.cc')
179

180
    prologue = prologue
181
        .replaceAll(`%CPP_PREFIX%`, PeerGeneratorConfig.cppPrefix)
182
    epilogue = epilogue
183
        .replaceAll("%CPP_PREFIX%", PeerGeneratorConfig.cppPrefix)
184
        .replaceAll(`%ARKUI_BASIC_NODE_API_VERSION_VALUE%`, basicVersion.toString())
185
        .replaceAll(`%ARKUI_FULL_API_VERSION_VALUE%`, fullVersion.toString())
186
        .replaceAll(`%ARKUI_EXTENDED_NODE_API_VERSION_VALUE%`, extendedVersion.toString())
187

188
    let result = createLanguageWriter(Language.CPP)
189
    result.writeLines(prologue)
190
    result.print("namespace OHOS::Ace::NG::GeneratedModifier {")
191
    result.pushIndent()
192
    result.concat(modifiers).concat(accessors)
193
    result.writeLines(epilogue)
194
    result.popIndent()
195
    result.print("}")
196

197
    return result
198
}
199

200
export function modifierStructList(lines: LanguageWriter): LanguageWriter {
201
    let result = createLanguageWriter(Language.CPP)
202
    result.print(`const ${PeerGeneratorConfig.cppPrefix}ArkUINodeModifiers* ${PeerGeneratorConfig.cppPrefix}GetArkUINodeModifiers() {`)
203
    result.pushIndent()
204

205
    result.print(`static const ${PeerGeneratorConfig.cppPrefix}ArkUINodeModifiers modifiersImpl = {`)
206
    result.pushIndent()
207
    result.concat(lines)
208
    result.popIndent()
209
    result.print(`};`)
210

211
    result.print(`return &modifiersImpl;`)
212
    result.popIndent()
213
    result.print(`}`)
214
    return result
215
}
216

217
export function accessorStructList(lines: LanguageWriter): LanguageWriter {
218
    let result = createLanguageWriter(Language.CPP)
219
    result.print(`const ${PeerGeneratorConfig.cppPrefix}ArkUIAccessors* ${PeerGeneratorConfig.cppPrefix}GetArkUIAccessors() {`)
220
    result.pushIndent()
221

222
    result.print(`static const ${PeerGeneratorConfig.cppPrefix}ArkUIAccessors accessorsImpl = {`)
223
    result.pushIndent()
224
    result.concat(lines)
225
    result.popIndent()
226
    result.print(`};`)
227

228
    result.print(`return &accessorsImpl;`)
229
    result.popIndent()
230
    result.print('}')
231

232
    return result
233
}
234

235
export function makeTSSerializer(library: PeerLibrary): string {
236
    let printer = createLanguageWriter(library.declarationTable.language)
237
    const builderClassImports = Array.from(library.builderClasses.keys())
238
        .map(it => `import { ${it} } from "@arkoala/arkui/Ark${it}Builder"`)
239
    writeSerializer(library, printer)
240
    //TODO: need to determine imports when generating serializer
241
    const extraImports = library.declarationTable.language === Language.ARKTS ?
242
        'import { AdaptiveColor, BlurStyle, BorderStyle, DismissReason, DragPreviewMode, GradientDirection, ShadowStyle, ShadowType, SheetMode, SheetSize, SheetType, ThemeColorMode } from "./ArkCommonInterfaces"' : ''
243
    return `
244
${extraImports}
245
import { SerializerBase, Tags, RuntimeType, runtimeType, isPixelMap, isResource, isInstanceOf } from "./SerializerBase"
246
import { int32 } from "@koalaui/common"
247
import { unsafeCast } from "./generated-utils"
248

249
${builderClassImports.join("\n")}
250

251
${printer.getOutput().join("\n")}
252

253
export function createSerializer(): Serializer { return new Serializer() }
254
`
255
}
256

257
export function makeJavaSerializerWriter(library: PeerLibrary): LanguageWriter {
258
    let result = createLanguageWriter(library.declarationTable.language)
259
    result.print(`package org.koalaui.arkoala;\n`)
260
    writeSerializer(library, result)
261
    return result
262
}
263

264
export function makeConverterHeader(path: string, namespace: string, library: PeerLibrary): LanguageWriter {
265
    const converter = createLanguageWriter(Language.CPP) as CppLanguageWriter
266
    converter.writeLines(cStyleCopyright)
267
    converter.writeLines(`/*
268
 * ${warning}
269
 */
270
`)
271
    const includeGuardDefine = makeIncludeGuardDefine(path)
272
    converter.print(`#ifndef ${includeGuardDefine}`)
273
    converter.print(`#define ${includeGuardDefine}`)
274
    converter.print("")
275

276
    converter.writeGlobalInclude('optional')
277
    converter.writeGlobalInclude('cstdlib')
278
    converter.writeInclude('arkoala_api_generated.h')
279
    converter.writeInclude('base/log/log_wrapper.h')
280
    converter.print("")
281

282
    converter.pushNamespace(namespace)
283
    writeConvertors(library, converter)
284
    converter.popNamespace()
285
    converter.print(`\n#endif // ${includeGuardDefine}`)
286
    converter.print("")
287
    return converter
288
}
289

290
export function makeCSerializers(library: PeerLibrary, structs: IndentedPrinter, typedefs: IndentedPrinter): string {
291

292
    const serializers = createLanguageWriter(Language.CPP)
293
    const writeToString = createLanguageWriter(Language.CPP)
294
    serializers.print("\n// Serializers\n")
295
    writeSerializer(library, serializers)
296
    serializers.print("\n// Deserializers\n")
297
    writeDeserializer(library, serializers)
298
    library.declarationTable.generateStructs(structs, typedefs, writeToString)
299

300
    return `
301
#include "SerializerBase.h"
302
#include "DeserializerBase.h"
303
#include "arkoala_api_generated.h"
304
#include <string>
305

306
${writeToString.getOutput().join("\n")}
307

308
${serializers.getOutput().join("\n")}
309
`
310
}
311

312
export function makeTSDeserializer(library: PeerLibrary): string {
313
    const deserializer = createLanguageWriter(Language.TS)
314
    writeDeserializer(library, deserializer)
315
    return `
316
import { runtimeType, Tags, RuntimeType } from "./SerializerBase"
317
import { DeserializerBase } from "./DeserializerBase"
318
import { int32 } from "@koalaui/common"
319
import { unsafeCast } from "./generated-utils"
320

321
${deserializer.getOutput().join("\n")}
322
`
323
}
324

325
export function makeApiModifiers(modifiers: string[], accessors: string[], events: string[]): string {
326

327
    let node_api = readTemplate('arkoala_node_api.h')
328
        .replaceAll(`%CPP_PREFIX%`, PeerGeneratorConfig.cppPrefix)
329

330

331
    return `
332
/**
333
 * An API to control an implementation. When making changes modifying binary
334
 * layout, i.e. adding new events - increase ARKUI_API_VERSION above for binary
335
 * layout checks.
336
 */
337
typedef struct ${PeerGeneratorConfig.cppPrefix}ArkUINodeModifiers {
338
${modifiers.join("\n")}
339
} ${PeerGeneratorConfig.cppPrefix}ArkUINodeModifiers;
340

341
typedef struct ${PeerGeneratorConfig.cppPrefix}ArkUIAccessors {
342
${accessors.join("\n")}
343
} ${PeerGeneratorConfig.cppPrefix}ArkUIAccessors;
344

345
typedef struct ${PeerGeneratorConfig.cppPrefix}ArkUIAnimation {
346
} ${PeerGeneratorConfig.cppPrefix}ArkUIAnimation;
347

348
typedef struct ${PeerGeneratorConfig.cppPrefix}ArkUINavigation {
349
} ${PeerGeneratorConfig.cppPrefix}ArkUINavigation;
350

351
typedef struct ${PeerGeneratorConfig.cppPrefix}ArkUIGraphicsAPI {
352
    ${PrimitiveType.Int32.getText()} version;
353
} ${PeerGeneratorConfig.cppPrefix}ArkUIGraphicsAPI;
354

355
typedef struct ${PeerGeneratorConfig.cppPrefix}ArkUIEventsAPI {
356
${events.join("\n")}
357
} ${PeerGeneratorConfig.cppPrefix}ArkUIEventsAPI;
358

359
${node_api}
360

361
/**
362
 * An API to control an implementation. When making changes modifying binary
363
 * layout, i.e. adding new events - increase ARKUI_NODE_API_VERSION above for binary
364
 * layout checks.
365
 */
366
typedef struct ${PeerGeneratorConfig.cppPrefix}ArkUIFullNodeAPI {
367
    ${PrimitiveType.Int32.getText()} version;
368
    const ${PeerGeneratorConfig.cppPrefix}ArkUINodeModifiers* (*getNodeModifiers)();
369
    const ${PeerGeneratorConfig.cppPrefix}ArkUIAccessors* (*getAccessors)();
370
    const ${PeerGeneratorConfig.cppPrefix}ArkUIAnimation* (*getAnimation)();
371
    const ${PeerGeneratorConfig.cppPrefix}ArkUINavigation* (*getNavigation)();
372
    const ${PeerGeneratorConfig.cppPrefix}ArkUIGraphicsAPI* (*getGraphicsAPI)();
373
    const ${PeerGeneratorConfig.cppPrefix}ArkUIEventsAPI* (*getEventsAPI)();
374
    const ${PeerGeneratorConfig.cppPrefix}ArkUIExtendedNodeAPI* (*getExtendedAPI)();
375
    void (*setArkUIEventsAPI)(const ${PeerGeneratorConfig.cppPrefix}ArkUIEventsAPI* api);
376
} ${PeerGeneratorConfig.cppPrefix}ArkUIFullNodeAPI;
377

378
typedef struct ${PeerGeneratorConfig.cppPrefix}ArkUIAnyAPI {
379
    ${PrimitiveType.Int32.getText()} version;
380
} ${PeerGeneratorConfig.cppPrefix}ArkUIAnyAPI;
381
`
382
}
383

384
export function makeApiHeaders(lines: string[]): string {
385
    return `
386

387
${lines.join("\n")}
388
`
389
}
390

391
const TEMPLATES_CACHE = new Map<string, string>()
392

393
function readTemplate(name: string): string {
394
    let template = TEMPLATES_CACHE.get(name);
395
    if (template == undefined) {
396
        template = fs.readFileSync(path.join(__dirname, `../templates/${name}`), 'utf8')
397
        TEMPLATES_CACHE.set(name, template)
398
    }
399
    return template
400
}
401

402
function readLangTemplate(name: string, lang: Language): string {
403
    return fs.readFileSync(path.join(__dirname, `../templates/${name + lang.extension}`), 'utf8')
404
}
405

406

407
export function makeAPI(
408
    apiVersion: string,
409
    headers: string[], modifiers: string[], accessors: string[], events: string[],
410
    structs: IndentedPrinter, typedefs: IndentedPrinter
411
): string {
412

413
    let prologue = readTemplate('arkoala_api_prologue.h')
414
    let epilogue = readTemplate('arkoala_api_epilogue.h')
415

416
    prologue = prologue
417
        .replaceAll(`%ARKUI_FULL_API_VERSION_VALUE%`, apiVersion)
418
        .replaceAll(`%CPP_PREFIX%`, PeerGeneratorConfig.cppPrefix)
419
    epilogue = epilogue
420
        .replaceAll("%CPP_PREFIX%", PeerGeneratorConfig.cppPrefix)
421

422
    return `
423
${prologue}
424

425
${structs.getOutput().join("\n")}
426

427
${typedefs.getOutput().join("\n")}
428

429
${makeApiHeaders(headers)}
430

431
${makeApiModifiers(modifiers, accessors, events)}
432

433
${epilogue}
434
`
435
}
436

437
export function copyToArkoala(from: string, arkoala: ArkoalaInstall, filters?: string[]) {
438
    filters = filters?.map(it => path.join(from, it))
439
    copyDir(path.join(from, 'koala-ui'), arkoala.koala, true, filters)
440
    const macros = path.join(from, 'shared', 'arkoala-macros.h')
441
    copyFile(macros, path.join(arkoala.nativeDir, 'arkoala-macros.h'), filters)
442
}
443

444
export function copyToLibace(from: string, libace: LibaceInstall) {
445
    const macros = path.join(from, 'shared', 'arkoala-macros.h')
446
    fs.copyFileSync(macros, libace.arkoalaMacros)
447
}
448

449
function copyDir(from: string, to: string, recursive: boolean, filters?: string[]) {
450
    fs.readdirSync(from).forEach(it => {
451
        const sourcePath = path.join(from, it)
452
        const targetPath = path.join(to, it)
453
        const statInfo = fs.statSync(sourcePath)
454
        if (statInfo.isFile()) {
455
            copyFile(sourcePath, targetPath, filters)
456
        }
457
        else if (recursive && statInfo.isDirectory()) {
458
            if (!fs.existsSync(targetPath)) {
459
                fs.mkdirSync(targetPath)
460
            }
461
            copyDir(sourcePath, targetPath, recursive, filters)
462
        }
463
    })
464
}
465
function copyFile(from: string, to: string, filters?: string[]) {
466
    if (filters && !filters.includes(from))
467
        return
468
    fs.copyFileSync(from, to)
469
}
470
export function makeNodeTypes(types: string[]): string {
471
    const enumValues = types.map(it => `  ${it},`).join("\n")
472
    return `
473
export enum ArkUINodeType {
474
${enumValues}
475
}
476
`.trim()
477
}
478

479
export function makeArkuiModule(componentsFiles: string[]): string {
480
    return componentsFiles.map(file => {
481
        const basename = path.basename(file)
482
        const basenameNoExt = basename.replaceAll(path.extname(basename), "")
483
        return `export * from "./${basenameNoExt}"`
484
    }).join("\n")
485
}
486

487
export function makeMaterializedPrologue(lang: Language): string {
488
    let prologue = readLangTemplate('materialized_class_prologue', lang)
489
    return `
490
${prologue}
491

492
${importTsInteropTypes}
493

494
`
495
}
496

497
export function tsCopyrightAndWarning(content: string): string {
498
    return `${cStyleCopyright}
499

500
// ${warning}
501

502
${content}
503
`
504
}
505

506

507
export function peerFileTemplate(content: string): string {
508
    return tsCopyrightAndWarning(content)
509
}
510

511
export function componentFileTemplate(content: string): string {
512
    return tsCopyrightAndWarning(content)
513
}
514

515
export function makePeerEvents(data: string): string {
516
    return `
517
import { Deserializer } from './Deserializer'
518
import { RuntimeType } from "./SerializerBase"
519
import { int32 } from "@koalaui/common"
520

521
interface PeerEvent {
522
    readonly kind: ${PeerEventKind}
523
    readonly nodeId: number
524
}
525

526
${data}
527
`
528
}
529

530
export function makeCEventsArkoalaImpl(implData: LanguageWriter, receiversList: LanguageWriter): string {
531
    const writer = new CppLanguageWriter(new IndentedPrinter())
532
    writer.print(cStyleCopyright)
533
    writer.writeInclude("arkoala_api_generated.h")
534
    writer.writeInclude("events.h")
535
    writer.writeInclude("Serializers.h")
536
    writer.print("")
537

538
    writer.pushNamespace("Generated")
539
    writer.concat(implData)
540
    writer.writeMethodImplementation(new Method(
541
        `GetArkUiEventsAPI`,
542
        new MethodSignature(new Type(`const ${PeerGeneratorConfig.cppPrefix}ArkUIEventsAPI*`), []),
543
    ), (writer) => {
544
        writer.print(`static const ${PeerGeneratorConfig.cppPrefix}ArkUIEventsAPI eventsImpl = {`)
545
        writer.pushIndent()
546
        writer.concat(receiversList)
547
        writer.popIndent()
548
        writer.print(`};`)
549
        writer.writeStatement(writer.makeReturn(writer.makeString(`&eventsImpl`)))
550
    })
551
    writer.popNamespace()
552
    return writer.getOutput().join('\n')
553
}
554

555
export function makeCEventsLibaceImpl(implData: PrinterLike, receiversList: PrinterLike, namespace: string): string {
556
    const writer = new CppLanguageWriter(new IndentedPrinter())
557
    writer.writeLines(cStyleCopyright)
558
    writer.print("")
559
    writer.writeInclude(`arkoala_api_generated.h`)
560
    writer.print("")
561
    writer.pushNamespace(namespace)
562

563
    writer.concat(implData)
564

565
    writer.print(`const ${PeerGeneratorConfig.cppPrefix}ArkUIEventsAPI* g_OverriddenEventsImpl = nullptr;`)
566
    writer.writeMethodImplementation(new Method(
567
        `${PeerGeneratorConfig.cppPrefix}SetArkUiEventsAPI`,
568
        new NamedMethodSignature(Type.Void, [new Type(`const ${PeerGeneratorConfig.cppPrefix}ArkUIEventsAPI*`)], [`api`]),
569
    ), (writer) => {
570
        writer.writeStatement(writer.makeAssign(`g_OverriddenEventsImpl`, undefined, writer.makeString(`api`), false))
571
    })
572

573
    writer.writeMethodImplementation(new Method(
574
        `${PeerGeneratorConfig.cppPrefix}GetArkUiEventsAPI`,
575
        new MethodSignature(new Type(`const ${PeerGeneratorConfig.cppPrefix}ArkUIEventsAPI*`), []),
576
    ), (writer) => {
577
        writer.print(`static const ${PeerGeneratorConfig.cppPrefix}ArkUIEventsAPI eventsImpl = {`)
578
        writer.pushIndent()
579
        writer.concat(receiversList)
580
        writer.popIndent()
581
        writer.print(`};`)
582
        writer.writeStatement(writer.makeCondition(
583
            writer.makeNaryOp("!=", [writer.makeString(`g_OverriddenEventsImpl`), writer.makeString(`nullptr`)]),
584
            writer.makeReturn(writer.makeString(`g_OverriddenEventsImpl`)),
585
        ))
586
        writer.writeStatement(writer.makeReturn(writer.makeString(`&eventsImpl`)))
587
    })
588

589
    writer.popNamespace()
590
    return writer.getOutput().join('\n')
591
}
592

593
export function gniFile(gniSources: string): string {
594
return `${sharpCopyright}
595

596
# ${warning}
597

598
${gniSources}
599
`
600
}
601

602
export function mesonBuildFile(content: string): string {
603
return `${sharpCopyright}
604

605
# ${warning}
606

607
${content}
608
`
609
}
610

611
export function makeIncludeGuardDefine(filePath: string) {
612
    let basename = path.basename(filePath);
613
    return basename.replace(/[.\- ]/g, "_").toUpperCase()
614
}
615

616
export function makeFileNameFromClassName(className: string) {
617
    // transfroms camel-case name to snake-case
618
    return className.split(/(?=[A-Z][a-z])/g).join("_").toLowerCase()
619
}

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.