idlize
68 строк · 2.5 Кб
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 MesonVisitor {
24printer = new IndentedPrinter()
25
26constructor(
27protected library: PeerLibrary
28) { }
29
30printPeerClassSourcePaths(clazz: PeerClass): void {
31const className = makeFileNameFromClassName(clazz.componentName)
32// TODO use names from Libace;
33this.printer.print(`'implementation/${className}_delegate.cpp',`)
34this.printer.print(`'generated/interface/${className}_modifier.cpp',`)
35}
36
37printMaterializedClassSourcePaths(clazz: MaterializedClass) {
38const className = makeFileNameFromClassName(clazz.className)
39// TODO use names from Libace;
40this.printer.print(`'implementation/${className}_delegate.cpp',`)
41this.printer.print(`'generated/interface/${className}_modifier.cpp',`)
42}
43
44// TODO: have a proper Peer module visitor
45printMesonBuildContent() {
46this.printer.print("generated_sources = files(")
47this.printer.pushIndent()
48this.printer.print(`'generated/interface/all_modifiers.cpp',`)
49this.library.files.forEach(file => {
50file.peers.forEach(clazz => this.printPeerClassSourcePaths(clazz))
51})
52this.library.materializedClasses.forEach(clazz => {
53this.printMaterializedClassSourcePaths(clazz)
54})
55this.printer.popIndent()
56this.printer.print(")")
57
58this.printer.print("")
59
60this.printer.print("generated_include_directories = include_directories('generated/interface')")
61}
62}
63
64export function printMesonBuild(peerLibrary: PeerLibrary): string {
65const visitor = new MesonVisitor(peerLibrary)
66visitor.printMesonBuildContent()
67return visitor.printer.getOutput().join("\n")
68}