1ca0551cfSopenharmony_ci/*
2ca0551cfSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3ca0551cfSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4ca0551cfSopenharmony_ci * you may not use this file except in compliance with the License.
5ca0551cfSopenharmony_ci * You may obtain a copy of the License at
6ca0551cfSopenharmony_ci *
7ca0551cfSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8ca0551cfSopenharmony_ci *
9ca0551cfSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10ca0551cfSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11ca0551cfSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12ca0551cfSopenharmony_ci * See the License for the specific language governing permissions and
13ca0551cfSopenharmony_ci * limitations under the License.
14ca0551cfSopenharmony_ci */
15ca0551cfSopenharmony_ci
16ca0551cfSopenharmony_ci#include "codegen/code_emitter.h"
17ca0551cfSopenharmony_ci
18ca0551cfSopenharmony_cinamespace OHOS {
19ca0551cfSopenharmony_cinamespace Idl {
20ca0551cfSopenharmony_ciconst char* CodeEmitter::TAB = "    ";
21ca0551cfSopenharmony_ciCodeEmitter::CodeEmitter(MetaComponent* mc)
22ca0551cfSopenharmony_ci    : metaComponent_(mc)
23ca0551cfSopenharmony_ci{
24ca0551cfSopenharmony_ci    metaInterface_ = nullptr;
25ca0551cfSopenharmony_ci    for (int i = 0; i < metaComponent_->interfaceNumber_; i++) {
26ca0551cfSopenharmony_ci        metaInterface_ = metaComponent_->interfaces_[i];
27ca0551cfSopenharmony_ci        if (metaInterface_ == nullptr) {
28ca0551cfSopenharmony_ci            continue;
29ca0551cfSopenharmony_ci        }
30ca0551cfSopenharmony_ci        if (!metaInterface_->external_) {
31ca0551cfSopenharmony_ci            break;
32ca0551cfSopenharmony_ci        }
33ca0551cfSopenharmony_ci    }
34ca0551cfSopenharmony_ci
35ca0551cfSopenharmony_ci    if (metaInterface_ != nullptr) {
36ca0551cfSopenharmony_ci        interfaceName_ = metaInterface_->name_;
37ca0551cfSopenharmony_ci        interfaceFullName_ = metaInterface_->namespace_ + interfaceName_;
38ca0551cfSopenharmony_ci        proxyName_ = interfaceName_.StartsWith("I") ?
39ca0551cfSopenharmony_ci                interfaceName_.Substring(1) + "Proxy" : interfaceName_ + "Proxy";
40ca0551cfSopenharmony_ci        proxyFullName_ = metaInterface_->namespace_ + proxyName_;
41ca0551cfSopenharmony_ci        stubName_ = interfaceName_.StartsWith("I") ?
42ca0551cfSopenharmony_ci                interfaceName_.Substring(1) + "Stub" : interfaceName_ + "Stub";
43ca0551cfSopenharmony_ci        stubFullName_ = metaInterface_->namespace_ + stubName_;
44ca0551cfSopenharmony_ci        deathRecipientName_ = interfaceName_.StartsWith("I") ?
45ca0551cfSopenharmony_ci                interfaceName_.Substring(1) + "Recipient" : interfaceName_ + "Recipient";
46ca0551cfSopenharmony_ci    }
47ca0551cfSopenharmony_ci}
48ca0551cfSopenharmony_ci} // namespace Idl
49ca0551cfSopenharmony_ci} // namespace OHOS