idlize
65 строк · 2.3 Кб
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
16import { IndentedPrinter } from "../../IndentedPrinter"
17import { makeFileNameFromClassName } from "../FileGenerators"
18import { MaterializedClass } from "../Materialized"
19import { PeerClass } from "../PeerClass"
20import { PeerLibrary } from "../PeerLibrary"
21
22
23export class GniVisitor {
24gni = new IndentedPrinter()
25
26constructor(
27protected library: PeerLibrary
28) { }
29
30printGniEntries(clazz: PeerClass): void {
31const className = makeFileNameFromClassName(clazz.componentName)
32this.gni.print(`"../arkoala/implementation/${className}_modifier.cpp",`)
33}
34
35printMaterializedClassSourcePaths(clazz: MaterializedClass) {
36const className = makeFileNameFromClassName(clazz.className)
37this.gni.print(`"../arkoala/implementation/${className}_modifier.cpp",`)
38}
39
40// TODO: have a proper Peer module visitor
41printGniSource() {
42this.gni.print("generated_sources = [")
43this.gni.pushIndent()
44this.library.files.forEach(file => {
45file.peers.forEach(clazz => this.printGniEntries(clazz))
46})
47this.library.materializedClasses.forEach(clazz => {
48this.printMaterializedClassSourcePaths(clazz)
49})
50
51this.gni.print(`"../arkoala/utility/converter.cpp",`)
52this.gni.print(`"../arkoala/implementation/view_model_bridge.cpp",`)
53this.gni.print(`"../arkoala/implementation/all_modifiers.cpp",`)
54this.gni.print(`"../arkoala/implementation/all_events.cpp",`)
55
56this.gni.popIndent()
57this.gni.print("]")
58}
59}
60
61export function printGniSources(peerLibrary: PeerLibrary): string {
62const visitor = new GniVisitor(peerLibrary)
63visitor.printGniSource()
64return visitor.gni.getOutput().join("\n")
65}