mirror of
https://gitee.com/openharmony/ability_idl_tool
synced 2024-11-23 07:20:29 +00:00
Description:init ability_idl
Sig: SIG_ApplicationFramework Feature or Bugfix:Feature Binary Source:No Signed-off-by: dy_study <dingyao5@huawei.com>
This commit is contained in:
parent
d664d848d6
commit
f005cf0f66
86
BUILD.gn
Normal file
86
BUILD.gn
Normal file
@ -0,0 +1,86 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
config("idl_config") {
|
||||
include_dirs = [
|
||||
"./",
|
||||
"//third_party/bounds_checking_function/include/",
|
||||
]
|
||||
}
|
||||
|
||||
common_sources = [
|
||||
"ast/ast_array_type.cpp",
|
||||
"ast/ast_boolean_type.cpp",
|
||||
"ast/ast_byte_type.cpp",
|
||||
"ast/ast_char_type.cpp",
|
||||
"ast/ast_double_type.cpp",
|
||||
"ast/ast_float_type.cpp",
|
||||
"ast/ast_integer_type.cpp",
|
||||
"ast/ast_interface_type.cpp",
|
||||
"ast/ast_list_type.cpp",
|
||||
"ast/ast_long_type.cpp",
|
||||
"ast/ast_map_type.cpp",
|
||||
"ast/ast_method.cpp",
|
||||
"ast/ast_module.cpp",
|
||||
"ast/ast_namespace.cpp",
|
||||
"ast/ast_node.cpp",
|
||||
"ast/ast_parameter.cpp",
|
||||
"ast/ast_sequenceable_type.cpp",
|
||||
"ast/ast_short_type.cpp",
|
||||
"ast/ast_string_type.cpp",
|
||||
"ast/ast_type.cpp",
|
||||
"ast/ast_void_type.cpp",
|
||||
]
|
||||
|
||||
common_sources += [
|
||||
"codegen/code_emitter.cpp",
|
||||
"codegen/code_generator.cpp",
|
||||
"codegen/cpp_code_emitter.cpp",
|
||||
"codegen/ts_code_emitter.cpp",
|
||||
]
|
||||
|
||||
common_sources += [
|
||||
"metadata/metadata_builder.cpp",
|
||||
"metadata/metadata_dumper.cpp",
|
||||
"metadata/metadata_reader.cpp",
|
||||
"metadata/metadata_serializer.cpp",
|
||||
]
|
||||
|
||||
common_sources += [
|
||||
"parser/lexer.cpp",
|
||||
"parser/parser.cpp",
|
||||
]
|
||||
|
||||
common_sources += [
|
||||
"util/file.cpp",
|
||||
"util/light_refcount_base.cpp",
|
||||
"util/logger.cpp",
|
||||
"util/options.cpp",
|
||||
"util/string.cpp",
|
||||
"util/string_builder.cpp",
|
||||
"util/string_pool.cpp",
|
||||
]
|
||||
|
||||
ohos_executable("idl") {
|
||||
sources = [ "main.cpp" ]
|
||||
sources += common_sources
|
||||
|
||||
configs = [ ":idl_config" ]
|
||||
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_static" ]
|
||||
|
||||
part_name = "idl"
|
||||
subsystem_name = "aafwk"
|
||||
}
|
177
LICENSE
Normal file
177
LICENSE
Normal file
@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
69
OAT.xml
Normal file
69
OAT.xml
Normal file
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
-->
|
||||
<!-- OAT(OSS Audit Tool) configuration guide:
|
||||
basedir: Root dir, the basedir + project path is the real source file location.
|
||||
licensefile:
|
||||
1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule.
|
||||
|
||||
tasklist(only for batch mode):
|
||||
1. task: Define oat check thread, each task will start a new thread.
|
||||
2. task name: Only an name, no practical effect.
|
||||
3. task policy: Default policy for projects under this task, this field is required and the specified policy must defined in policylist.
|
||||
4. task filter: Default filefilter for projects under this task, this field is required and the specified filefilter must defined in filefilterlist.
|
||||
5. task project: Projects to be checked, the path field define the source root dir of the project.
|
||||
|
||||
|
||||
policyList:
|
||||
1. policy: All policyitems will be merged to default OAT.xml rules, the name of policy doesn't affect OAT check process.
|
||||
2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is:
|
||||
<policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/>
|
||||
3. policyitem type:
|
||||
"compatibility" is used to check license compatibility in the specified path;
|
||||
"license" is used to check source license header in the specified path;
|
||||
"copyright" is used to check source copyright header in the specified path;
|
||||
"import" is used to check source dependency in the specified path, such as import ... ,include ...
|
||||
"filetype" is used to check file type in the specified path, supported file types: archive, binary
|
||||
"filename" is used to check whether the specified file exists in the specified path(support projectroot in default OAT.xml), supported file names: LICENSE, README, README.OpenSource
|
||||
|
||||
4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license.
|
||||
5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem.
|
||||
6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed.
|
||||
7. policyitem filefilter: Used to bind filefilter which define filter rules.
|
||||
8. filefilter: Filter rules, the type filename is used to filter file name, the type filepath is used to filter file path.
|
||||
|
||||
Note:If the text contains special characters, please escape them according to the following rules:
|
||||
" == >
|
||||
& == >
|
||||
' == >
|
||||
< == >
|
||||
> == >
|
||||
-->
|
||||
<configuration>
|
||||
<oatconfig>
|
||||
<licensefile></licensefile>
|
||||
<policylist>
|
||||
<policy name="projectPolicy" desc="">
|
||||
</policy>
|
||||
</policylist>
|
||||
<filefilterlist>
|
||||
<filefilter name="defaultFilter" desc="Files not to check">
|
||||
<filteritem type="filename" name="zidl/test/zidlgen/zidl" desc="zidl binary file"/>
|
||||
<filteritem type="filepath" name="zidl/test/zidlgen/zidl" desc="zidl binary file"/>
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
</oatconfig>
|
||||
</configuration>
|
81
README.md
Normal file → Executable file
81
README.md
Normal file → Executable file
@ -1,39 +1,58 @@
|
||||
# ability_idl
|
||||
# IDL工具
|
||||
|
||||
#### 介绍
|
||||
{**以下是 Gitee 平台说明,您可以替换此简介**
|
||||
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台
|
||||
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
|
||||
## 简介
|
||||
|
||||
#### 软件架构
|
||||
软件架构说明
|
||||
在OpenHarmony中,当客户端和服务器进行IPC通信时,需要定义双方都认可的接口,以保障双方可以成功通信,OpenHarmony IDL(OpenHarmony Interface Definition Language)则是一种定义此类接口的工具。OpenHarmony IDL先把需要传递的对象分解成操作系统能够理解的基本类型,并根据开发者的需要封装跨边界的对象。
|
||||
|
||||
**图1** IDL接口描述
|
||||
![IDL-interface-description](./figures/IDL-interface-description.png)
|
||||
|
||||
OpenHarmony IDL接口描述语言主要用于:
|
||||
|
||||
- 声明系统服务对外提供的服务接口,根据接口声明在编译时生成跨进程调用(IPC)或跨设备调用(RPC)的代理(Proxy)和桩(Stub)的C/C++代码或JS/TS代码。
|
||||
|
||||
- 声明Ability对外提供的服务接口,根据接口声明在编译时生成跨进程调用(IPC)或跨设备调用(RPC)的代理(Proxy)和桩(Stub)的C/C++代码或JS/TS代码。
|
||||
|
||||
**图2** IPC/RPC通信模型
|
||||
|
||||
![IPC-RPC-communication-model](./figures/IPC-RPC-communication-model.png)
|
||||
|
||||
使用OpenHarmony IDL接口描述语言声明接口具有以下优点:
|
||||
|
||||
- OpenHarmony IDL中是以接口的形式定义服务,可以专注于定义而隐藏实现细节。
|
||||
|
||||
- OpenHarmony IDL中定义的接口可以支持跨进程调用或跨设备调用。根据OpenHarmony IDL中的定义生成的信息或代码可以简化跨进程或跨设备调用接口的实现。
|
||||
|
||||
## 部件内子模块职责
|
||||
|
||||
| 子模块名称 | 职责 |
|
||||
| ---------------- | ------------------------------------------------------------|
|
||||
| 接口文件解析模块 | 解析校验接口定义文件。 |
|
||||
| stub/proxy自动生成模块 | 根据IPC/RPC规格自动生成Stub服务端和Proxy客户端代码 |
|
||||
|
||||
## 目录
|
||||
|
||||
```
|
||||
foundation/ability/idl
|
||||
├── ast # idl语法解析定义代码
|
||||
├── codegen # 跨进程通信模板生成模块代码
|
||||
├── metadata # matedata自定义数据解析模块代码
|
||||
├── parser # idl解析模块代码
|
||||
├── test # 测试目录
|
||||
└── util # 公共方法代码
|
||||
```
|
||||
|
||||
## 开发步骤
|
||||
开发步骤可参考[开发指导](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/IDL/idl-guidelines.md#31-c%E5%BC%80%E5%8F%91%E6%AD%A5%E9%AA%A4)
|
||||
|
||||
|
||||
#### 安装教程
|
||||
## 相关仓
|
||||
元能力子系统
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
ability_base
|
||||
|
||||
#### 使用说明
|
||||
ability_runtime
|
||||
|
||||
1. xxxx
|
||||
2. xxxx
|
||||
3. xxxx
|
||||
form_runtime
|
||||
|
||||
#### 参与贡献
|
||||
|
||||
1. Fork 本仓库
|
||||
2. 新建 Feat_xxx 分支
|
||||
3. 提交代码
|
||||
4. 新建 Pull Request
|
||||
|
||||
|
||||
#### 特技
|
||||
|
||||
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
|
||||
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
|
||||
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
|
||||
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
|
||||
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
|
||||
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
|
||||
[**idl**]
|
||||
|
35
ast/ast_array_type.cpp
Normal file
35
ast/ast_array_type.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_array_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
String ASTArrayType::GetSignature()
|
||||
{
|
||||
return String::Format("[%s", elementType_->GetSignature().string());
|
||||
}
|
||||
|
||||
bool ASTArrayType::IsArrayType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ASTArrayType::ToString()
|
||||
{
|
||||
return String::Format("%s[]", elementType_->ToString().string());
|
||||
}
|
||||
}
|
||||
}
|
47
ast/ast_array_type.h
Normal file
47
ast/ast_array_type.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTARRAYTYPE_H
|
||||
#define OHOS_IDL_ASTARRAYTYPE_H
|
||||
|
||||
#include "ast/ast_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTArrayType : public ASTType {
|
||||
public:
|
||||
void SetElementType(ASTType* elementType)
|
||||
{
|
||||
elementType_ = elementType;
|
||||
}
|
||||
|
||||
AutoPtr<ASTType> GetElementType()
|
||||
{
|
||||
return elementType_;
|
||||
}
|
||||
|
||||
String GetSignature() override;
|
||||
|
||||
bool IsArrayType() override;
|
||||
|
||||
String ToString() override;
|
||||
|
||||
private:
|
||||
AutoPtr<ASTType> elementType_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTARRAYTYPE_H
|
35
ast/ast_boolean_type.cpp
Normal file
35
ast/ast_boolean_type.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_boolean_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
String ASTBooleanType::GetSignature()
|
||||
{
|
||||
return "Z";
|
||||
}
|
||||
|
||||
bool ASTBooleanType::IsBooleanType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ASTBooleanType::ToString()
|
||||
{
|
||||
return "boolean";
|
||||
}
|
||||
}
|
||||
}
|
34
ast/ast_boolean_type.h
Normal file
34
ast/ast_boolean_type.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTBOOLEANTYPE_H
|
||||
#define OHOS_IDL_ASTBOOLEANTYPE_H
|
||||
|
||||
#include "ast/ast_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTBooleanType : public ASTType {
|
||||
public:
|
||||
String GetSignature() override;
|
||||
|
||||
bool IsBooleanType() override;
|
||||
|
||||
String ToString() override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTBOOLEANTYPE_H
|
35
ast/ast_byte_type.cpp
Normal file
35
ast/ast_byte_type.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_byte_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
String ASTByteType::GetSignature()
|
||||
{
|
||||
return "B";
|
||||
}
|
||||
|
||||
bool ASTByteType::IsByteType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ASTByteType::ToString()
|
||||
{
|
||||
return "byte";
|
||||
}
|
||||
}
|
||||
}
|
34
ast/ast_byte_type.h
Normal file
34
ast/ast_byte_type.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTBYTETYPE_H
|
||||
#define OHOS_IDL_ASTBYTETYPE_H
|
||||
|
||||
#include "ast/ast_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTByteType : public ASTType {
|
||||
public:
|
||||
String GetSignature() override;
|
||||
|
||||
bool IsByteType() override;
|
||||
|
||||
String ToString() override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTBYTETYPE_H
|
35
ast/ast_char_type.cpp
Normal file
35
ast/ast_char_type.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_char_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
String ASTCharType::GetSignature()
|
||||
{
|
||||
return "C";
|
||||
}
|
||||
|
||||
bool ASTCharType::IsCharType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ASTCharType::ToString()
|
||||
{
|
||||
return "char";
|
||||
}
|
||||
}
|
||||
}
|
34
ast/ast_char_type.h
Normal file
34
ast/ast_char_type.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTCHARTYPE_H
|
||||
#define OHOS_IDL_ASTCHARTYPE_H
|
||||
|
||||
#include "ast/ast_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTCharType : public ASTType {
|
||||
public:
|
||||
String GetSignature() override;
|
||||
|
||||
bool IsCharType() override;
|
||||
|
||||
String ToString() override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTCHARTYPE_H
|
35
ast/ast_double_type.cpp
Normal file
35
ast/ast_double_type.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_double_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
String ASTDoubleType::GetSignature()
|
||||
{
|
||||
return "D";
|
||||
}
|
||||
|
||||
bool ASTDoubleType::IsDoubleType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ASTDoubleType::ToString()
|
||||
{
|
||||
return "double";
|
||||
}
|
||||
}
|
||||
}
|
34
ast/ast_double_type.h
Normal file
34
ast/ast_double_type.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTDOUBLETYPE_H
|
||||
#define OHOS_IDL_ASTDOUBLETYPE_H
|
||||
|
||||
#include "ast/ast_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTDoubleType : public ASTType {
|
||||
public:
|
||||
String GetSignature() override;
|
||||
|
||||
bool IsDoubleType() override;
|
||||
|
||||
String ToString() override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTDOUBLETYPE_H
|
35
ast/ast_float_type.cpp
Normal file
35
ast/ast_float_type.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_float_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
String ASTFloatType::GetSignature()
|
||||
{
|
||||
return "F";
|
||||
}
|
||||
|
||||
bool ASTFloatType::IsFloatType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ASTFloatType::ToString()
|
||||
{
|
||||
return "float";
|
||||
}
|
||||
}
|
||||
}
|
34
ast/ast_float_type.h
Normal file
34
ast/ast_float_type.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTFLOATTYPE_H
|
||||
#define OHOS_IDL_ASTFLOATTYPE_H
|
||||
|
||||
#include "ast/ast_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTFloatType : public ASTType {
|
||||
public:
|
||||
String GetSignature() override;
|
||||
|
||||
bool IsFloatType() override;
|
||||
|
||||
String ToString() override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTFLOATTYPE_H
|
35
ast/ast_integer_type.cpp
Normal file
35
ast/ast_integer_type.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_integer_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
String ASTIntegerType::GetSignature()
|
||||
{
|
||||
return "I";
|
||||
}
|
||||
|
||||
bool ASTIntegerType::IsIntegerType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ASTIntegerType::ToString()
|
||||
{
|
||||
return "int";
|
||||
}
|
||||
}
|
||||
}
|
34
ast/ast_integer_type.h
Normal file
34
ast/ast_integer_type.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTINTEGERTYPE_H
|
||||
#define OHOS_IDL_ASTINTEGERTYPE_H
|
||||
|
||||
#include "ast/ast_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTIntegerType : public ASTType {
|
||||
public:
|
||||
String GetSignature() override;
|
||||
|
||||
bool IsIntegerType() override;
|
||||
|
||||
String ToString() override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTINTEGERTYPE_H
|
89
ast/ast_interface_type.cpp
Normal file
89
ast/ast_interface_type.cpp
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_interface_type.h"
|
||||
#include "util/string_builder.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
void ASTInterfaceType::SetNamespace(ASTNamespace* nspace)
|
||||
{
|
||||
ASTType::SetNamespace(nspace);
|
||||
if (namespace_ != nullptr) {
|
||||
namespace_->AddInterface(this);
|
||||
}
|
||||
}
|
||||
|
||||
void ASTInterfaceType::AddMethod(ASTMethod* method)
|
||||
{
|
||||
if (method == nullptr) {
|
||||
return;
|
||||
}
|
||||
methods_.push_back(method);
|
||||
}
|
||||
|
||||
AutoPtr<ASTMethod> ASTInterfaceType::GetMethod(size_t index)
|
||||
{
|
||||
if (index >= methods_.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return methods_[index];
|
||||
}
|
||||
|
||||
String ASTInterfaceType::GetSignature()
|
||||
{
|
||||
String fullName = namespace_ != nullptr ?
|
||||
namespace_->ToString() + name_ : name_;
|
||||
return "L" + fullName.Replace('.', '/') + ";";
|
||||
}
|
||||
|
||||
bool ASTInterfaceType::IsInterfaceType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ASTInterfaceType::ToString()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
String ASTInterfaceType::Dump(const String& prefix)
|
||||
{
|
||||
StringBuilder sb;
|
||||
|
||||
sb.Append(prefix).Append("interface ");
|
||||
if (namespace_ != nullptr) {
|
||||
sb.Append(namespace_->ToString());
|
||||
}
|
||||
sb.Append(name_);
|
||||
if (isExternal_) {
|
||||
sb.Append(";\n");
|
||||
} else {
|
||||
sb.Append(" {\n");
|
||||
for (auto method : methods_) {
|
||||
String info = method->Dump(prefix + " ");
|
||||
sb.Append(info);
|
||||
if (method != methods_[methods_.size() - 1]) {
|
||||
sb.Append('\n');
|
||||
}
|
||||
}
|
||||
sb.Append(prefix).Append("}\n");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
86
ast/ast_interface_type.h
Normal file
86
ast/ast_interface_type.h
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTINTERFACETYPE_H
|
||||
#define OHOS_IDL_ASTINTERFACETYPE_H
|
||||
|
||||
#include <vector>
|
||||
#include "ast/ast_method.h"
|
||||
#include "ast/ast_type.h"
|
||||
#include "util/autoptr.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTInterfaceType : public ASTType {
|
||||
public:
|
||||
void SetNamespace(ASTNamespace* nspace) override;
|
||||
|
||||
void SetLicense(const String& license)
|
||||
{
|
||||
license_ = license;
|
||||
}
|
||||
|
||||
String GetLicense() const
|
||||
{
|
||||
return license_;
|
||||
}
|
||||
|
||||
void SetOneway(bool oneway)
|
||||
{
|
||||
oneway_ = oneway;
|
||||
}
|
||||
|
||||
bool IsOneway()
|
||||
{
|
||||
return oneway_;
|
||||
}
|
||||
|
||||
void AddMethod(ASTMethod* method);
|
||||
|
||||
AutoPtr<ASTMethod> GetMethod(size_t index);
|
||||
|
||||
size_t GetMethodNumber()
|
||||
{
|
||||
return methods_.size();
|
||||
}
|
||||
|
||||
void SetExternal(bool external)
|
||||
{
|
||||
isExternal_ = external;
|
||||
}
|
||||
|
||||
bool IsExternal() const
|
||||
{
|
||||
return isExternal_;
|
||||
}
|
||||
|
||||
String GetSignature() override;
|
||||
|
||||
bool IsInterfaceType() override;
|
||||
|
||||
String ToString() override;
|
||||
|
||||
String Dump(const String& prefix) override;
|
||||
|
||||
private:
|
||||
String license_;
|
||||
bool oneway_ = false;
|
||||
std::vector<AutoPtr<ASTMethod>> methods_;
|
||||
bool isExternal_ = false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTINTERFACETYPE_H
|
35
ast/ast_list_type.cpp
Normal file
35
ast/ast_list_type.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_list_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
String ASTListType::GetSignature()
|
||||
{
|
||||
return String::Format("LList[%s];", elementType_->GetSignature().string());
|
||||
}
|
||||
|
||||
bool ASTListType::IsListType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ASTListType::ToString()
|
||||
{
|
||||
return String::Format("List<%s>", elementType_->ToString().string());
|
||||
}
|
||||
}
|
||||
}
|
48
ast/ast_list_type.h
Normal file
48
ast/ast_list_type.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTLISTTYPE_H
|
||||
#define OHOS_IDL_ASTLISTTYPE_H
|
||||
|
||||
#include "ast/ast_type.h"
|
||||
#include "util/autoptr.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTListType : public ASTType {
|
||||
public:
|
||||
void SetElementType(ASTType* elementType)
|
||||
{
|
||||
elementType_ = elementType;
|
||||
}
|
||||
|
||||
AutoPtr<ASTType> GetElementType()
|
||||
{
|
||||
return elementType_;
|
||||
}
|
||||
|
||||
String GetSignature() override;
|
||||
|
||||
bool IsListType() override;
|
||||
|
||||
String ToString() override;
|
||||
|
||||
private:
|
||||
AutoPtr<ASTType> elementType_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTLISTTYPE_H
|
35
ast/ast_long_type.cpp
Normal file
35
ast/ast_long_type.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_long_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
String ASTLongType::GetSignature()
|
||||
{
|
||||
return "J";
|
||||
}
|
||||
|
||||
bool ASTLongType::IsLongType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ASTLongType::ToString()
|
||||
{
|
||||
return "long";
|
||||
}
|
||||
}
|
||||
}
|
34
ast/ast_long_type.h
Normal file
34
ast/ast_long_type.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTLONGTYPE_H
|
||||
#define OHOS_IDL_ASTLONGTYPE_H
|
||||
|
||||
#include "ast/ast_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTLongType : public ASTType {
|
||||
public:
|
||||
String GetSignature() override;
|
||||
|
||||
bool IsLongType() override;
|
||||
|
||||
String ToString() override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTLONGTYPE_H
|
35
ast/ast_map_type.cpp
Normal file
35
ast/ast_map_type.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_map_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
String ASTMapType::GetSignature()
|
||||
{
|
||||
return String::Format("LMap[%s%s];", keyType_->GetSignature().string(), valueType_->GetSignature().string());
|
||||
}
|
||||
|
||||
bool ASTMapType::IsMapType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ASTMapType::ToString()
|
||||
{
|
||||
return String::Format("Map<%s, %s>", keyType_->ToString().string(), valueType_->ToString().string());
|
||||
}
|
||||
}
|
||||
}
|
59
ast/ast_map_type.h
Normal file
59
ast/ast_map_type.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTMAPTYPE_H
|
||||
#define OHOS_IDL_ASTMAPTYPE_H
|
||||
|
||||
#include "ast/ast_type.h"
|
||||
#include "util/autoptr.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTMapType : public ASTType {
|
||||
public:
|
||||
void SetKeyType(ASTType* keyType)
|
||||
{
|
||||
keyType_ = keyType;
|
||||
}
|
||||
|
||||
AutoPtr<ASTType> GetKeyType()
|
||||
{
|
||||
return keyType_;
|
||||
}
|
||||
|
||||
void SetValueType(ASTType* valueType)
|
||||
{
|
||||
valueType_ = valueType;
|
||||
}
|
||||
|
||||
AutoPtr<ASTType> GetValueType()
|
||||
{
|
||||
return valueType_;
|
||||
}
|
||||
|
||||
String GetSignature() override;
|
||||
|
||||
bool IsMapType() override;
|
||||
|
||||
String ToString() override;
|
||||
|
||||
private:
|
||||
AutoPtr<ASTType> keyType_;
|
||||
AutoPtr<ASTType> valueType_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTMAPTYPE_H
|
79
ast/ast_method.cpp
Normal file
79
ast/ast_method.cpp
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_method.h"
|
||||
#include "util/string_builder.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
String ASTMethod::GetSignature()
|
||||
{
|
||||
if (signature_.IsEmpty()) {
|
||||
BuildSignature();
|
||||
}
|
||||
return signature_;
|
||||
}
|
||||
|
||||
void ASTMethod::BuildSignature()
|
||||
{
|
||||
StringBuilder sb;
|
||||
|
||||
sb.AppendFormat("(%s)", returnType_->GetSignature().string());
|
||||
for (size_t i = 0; i < parameters_.size(); i++) {
|
||||
sb.Append(parameters_[i]->GetType()->GetSignature());
|
||||
}
|
||||
signature_ = sb.ToString();
|
||||
}
|
||||
|
||||
void ASTMethod::AddParameter(ASTParameter* parameter)
|
||||
{
|
||||
if (parameter == nullptr) {
|
||||
return;
|
||||
}
|
||||
parameters_.push_back(parameter);
|
||||
}
|
||||
|
||||
AutoPtr<ASTParameter> ASTMethod::GetParameter(size_t index)
|
||||
{
|
||||
if (index >= parameters_.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return parameters_[index];
|
||||
}
|
||||
|
||||
String ASTMethod::Dump(const String& prefix)
|
||||
{
|
||||
StringBuilder sb;
|
||||
|
||||
sb.Append(prefix);
|
||||
sb.Append(returnType_->ToString()).Append(' ');
|
||||
sb.Append(name_).Append('(');
|
||||
if (parameters_.size() != 0) {
|
||||
sb.Append('\n');
|
||||
for (auto parameter : parameters_) {
|
||||
String info = parameter->Dump(prefix + " ");
|
||||
sb.Append(info);
|
||||
if (parameter != parameters_[parameters_.size() - 1]) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
sb.Append(");\n");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
84
ast/ast_method.h
Normal file
84
ast/ast_method.h
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTMETHOD_H
|
||||
#define OHOS_IDL_ASTMETHOD_H
|
||||
|
||||
#include <vector>
|
||||
#include "ast/ast_node.h"
|
||||
#include "ast/ast_parameter.h"
|
||||
#include "util/autoptr.h"
|
||||
#include "util/string.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTMethod : public ASTNode {
|
||||
public:
|
||||
void SetName(const String& name)
|
||||
{
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
String GetName()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
String GetSignature();
|
||||
|
||||
void SetOneway(bool oneway)
|
||||
{
|
||||
oneway_ = oneway;
|
||||
}
|
||||
|
||||
bool IsOneway()
|
||||
{
|
||||
return oneway_;
|
||||
}
|
||||
|
||||
void SetReturnType(ASTType* type)
|
||||
{
|
||||
returnType_ = type;
|
||||
}
|
||||
|
||||
AutoPtr<ASTType> GetReturnType()
|
||||
{
|
||||
return returnType_;
|
||||
}
|
||||
|
||||
void AddParameter(ASTParameter* parameter);
|
||||
|
||||
AutoPtr<ASTParameter> GetParameter(size_t index);
|
||||
|
||||
size_t GetParameterNumber()
|
||||
{
|
||||
return parameters_.size();
|
||||
}
|
||||
|
||||
String Dump(const String& prefix) override;
|
||||
|
||||
private:
|
||||
void BuildSignature();
|
||||
|
||||
String name_;
|
||||
String signature_;
|
||||
bool oneway_ = false;
|
||||
AutoPtr<ASTType> returnType_;
|
||||
std::vector<AutoPtr<ASTParameter>> parameters_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTMETHOD_H
|
244
ast/ast_module.cpp
Normal file
244
ast/ast_module.cpp
Normal file
@ -0,0 +1,244 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_module.h"
|
||||
#include "util/string_builder.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
ASTModule::ASTModule()
|
||||
{
|
||||
booleanType_ = new ASTBooleanType();
|
||||
byteType_ = new ASTByteType();
|
||||
shortType_ = new ASTShortType();
|
||||
integerType_ = new ASTIntegerType();
|
||||
longType_ = new ASTLongType();
|
||||
floatType_ = new ASTFloatType();
|
||||
doubleType_ = new ASTDoubleType();
|
||||
charType_ = new ASTCharType();
|
||||
stringType_ = new ASTStringType();
|
||||
voidType_ = new ASTVoidType();
|
||||
|
||||
types_["boolean"] = booleanType_.Get();
|
||||
types_["byte"] = byteType_.Get();
|
||||
types_["short"] = shortType_.Get();
|
||||
types_["int"] = integerType_.Get();
|
||||
types_["long"] = longType_.Get();
|
||||
types_["float"] = floatType_.Get();
|
||||
types_["double"] = doubleType_.Get();
|
||||
types_["char"] = charType_.Get();
|
||||
types_["String"] = stringType_.Get();
|
||||
types_["void"] = voidType_.Get();
|
||||
}
|
||||
|
||||
void ASTModule::SetIdlFile(const String& idlFile)
|
||||
{
|
||||
idlFilePath_ = idlFile;
|
||||
#ifdef __MINGW32__
|
||||
int index = idlFilePath_.LastIndexOf('\\');
|
||||
#else
|
||||
int index = idlFilePath_.LastIndexOf('/');
|
||||
#endif
|
||||
int end = idlFilePath_.LastIndexOf(".idl") == -1 ?
|
||||
idlFilePath_.LastIndexOf(".idl") : idlFilePath_.LastIndexOf(".idl");
|
||||
name_ = idlFilePath_.Substring((index == -1) ? 0 : (index + 1), end);
|
||||
}
|
||||
|
||||
AutoPtr<ASTNamespace> ASTModule::ParseNamespace(const String& nspaceStr)
|
||||
{
|
||||
AutoPtr<ASTNamespace> currNspace;
|
||||
int begin = 0;
|
||||
int index = 0;
|
||||
while ((index = nspaceStr.IndexOf('.', begin)) != -1) {
|
||||
String ns = nspaceStr.Substring(begin, index);
|
||||
AutoPtr<ASTNamespace> nspace;
|
||||
if (currNspace == nullptr) {
|
||||
nspace = FindNamespace(ns);
|
||||
} else {
|
||||
nspace = currNspace->FindNamespace(ns);
|
||||
}
|
||||
if (nspace == nullptr) {
|
||||
nspace = new ASTNamespace(ns);
|
||||
if (currNspace == nullptr) {
|
||||
AddNamespace(nspace);
|
||||
} else {
|
||||
currNspace->AddNamespace(nspace);
|
||||
}
|
||||
}
|
||||
currNspace = nspace;
|
||||
begin = index + 1;
|
||||
}
|
||||
return currNspace;
|
||||
}
|
||||
|
||||
void ASTModule::AddNamespace(ASTNamespace* nspace)
|
||||
{
|
||||
if (nspace == nullptr) {
|
||||
return;
|
||||
}
|
||||
namespaces_.push_back(nspace);
|
||||
}
|
||||
|
||||
AutoPtr<ASTNamespace> ASTModule::FindNamespace(const String& nspaceStr)
|
||||
{
|
||||
for (auto nspace : namespaces_) {
|
||||
if (nspace->ToShortString().Equals(nspaceStr)) {
|
||||
return nspace;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AutoPtr<ASTNamespace> ASTModule::GetNamespace(size_t index)
|
||||
{
|
||||
if (index >= namespaces_.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return namespaces_[index];
|
||||
}
|
||||
|
||||
void ASTModule::AddInterface(ASTInterfaceType* interface)
|
||||
{
|
||||
if (interface == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
interfaces_.push_back(interface);
|
||||
types_[interface->ToString()] = (ASTType*)interface;
|
||||
}
|
||||
|
||||
AutoPtr<ASTInterfaceType> ASTModule::GetInterface(size_t index)
|
||||
{
|
||||
if (index >= interfaces_.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return interfaces_[index];
|
||||
}
|
||||
|
||||
int ASTModule::IndexOf(ASTInterfaceType* interface)
|
||||
{
|
||||
for (size_t i = 0; i < interfaces_.size(); i++) {
|
||||
if (interfaces_[i] == interface) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ASTModule::AddSequenceable(ASTSequenceableType* sequenceable)
|
||||
{
|
||||
if (sequenceable == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
sequenceables_.push_back(sequenceable);
|
||||
types_[sequenceable->ToString()] = (ASTType*)sequenceable;
|
||||
}
|
||||
|
||||
AutoPtr<ASTSequenceableType> ASTModule::GetSequenceable(size_t index)
|
||||
{
|
||||
if (index >= sequenceables_.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return sequenceables_[index];
|
||||
}
|
||||
|
||||
int ASTModule::IndexOf(ASTSequenceableType* sequenceable)
|
||||
{
|
||||
for (size_t i = 0; i < sequenceables_.size(); i++) {
|
||||
if (sequenceables_[i] == sequenceable) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ASTModule::AddType(ASTType* type)
|
||||
{
|
||||
if (type == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
types_[type->ToString()] = type;
|
||||
}
|
||||
|
||||
AutoPtr<ASTType> ASTModule::FindType(const String& typeName)
|
||||
{
|
||||
if (typeName.IsEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto it = types_.find(typeName);
|
||||
return it != types_.end() ? it->second : nullptr;
|
||||
}
|
||||
|
||||
int ASTModule::IndexOf(ASTType* type)
|
||||
{
|
||||
int i = 0;
|
||||
for (auto it = types_.begin(); it != types_.end(); ++it, ++i) {
|
||||
if (it->second == type) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool ASTModule::IsValid()
|
||||
{
|
||||
if (name_.IsEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return interfaces_.size() > 0;
|
||||
}
|
||||
|
||||
String ASTModule::Dump(const String& prefix)
|
||||
{
|
||||
StringBuilder sb;
|
||||
|
||||
sb.Append(prefix);
|
||||
sb.Append("Module[");
|
||||
sb.Append("name: ").Append(name_).Append(" ");
|
||||
sb.Append("file: ").Append(idlFilePath_);
|
||||
sb.Append("]\n");
|
||||
|
||||
for (auto sequenceable : sequenceables_) {
|
||||
String info = sequenceable->Dump(" ");
|
||||
sb.Append(info);
|
||||
}
|
||||
sb.Append('\n');
|
||||
|
||||
for (auto interface : interfaces_) {
|
||||
if (interface->IsExternal()) {
|
||||
String info = interface->Dump(" ");
|
||||
sb.Append(info);
|
||||
}
|
||||
}
|
||||
sb.Append('\n');
|
||||
|
||||
for (auto interface : interfaces_) {
|
||||
if (!interface->IsExternal()) {
|
||||
String info = interface->Dump(" ");
|
||||
sb.Append(info);
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
141
ast/ast_module.h
Normal file
141
ast/ast_module.h
Normal file
@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTMODULE_H
|
||||
#define OHOS_IDL_ASTMODULE_H
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "ast/ast_boolean_type.h"
|
||||
#include "ast/ast_byte_type.h"
|
||||
#include "ast/ast_char_type.h"
|
||||
#include "ast/ast_double_type.h"
|
||||
#include "ast/ast_float_type.h"
|
||||
#include "ast/ast_integer_type.h"
|
||||
#include "ast/ast_interface_type.h"
|
||||
#include "ast/ast_long_type.h"
|
||||
#include "ast/ast_namespace.h"
|
||||
#include "ast/ast_node.h"
|
||||
#include "ast/ast_sequenceable_type.h"
|
||||
#include "ast/ast_short_type.h"
|
||||
#include "ast/ast_string_type.h"
|
||||
#include "ast/ast_void_type.h"
|
||||
#include "util/autoptr.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTModule : public ASTNode {
|
||||
public:
|
||||
ASTModule();
|
||||
|
||||
void SetIdlFile(const String& idlFile);
|
||||
|
||||
String GetName()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
void SetLicense(const String& license)
|
||||
{
|
||||
license_ = license;
|
||||
}
|
||||
|
||||
String GetLicense()
|
||||
{
|
||||
return license_;
|
||||
}
|
||||
|
||||
AutoPtr<ASTNamespace> ParseNamespace(const String& nspaceStr);
|
||||
|
||||
void AddNamespace(ASTNamespace* nspace);
|
||||
|
||||
AutoPtr<ASTNamespace> FindNamespace(const String& nspaceStr);
|
||||
|
||||
AutoPtr<ASTNamespace> GetNamespace(size_t index);
|
||||
|
||||
size_t GetNamespaceNumber()
|
||||
{
|
||||
return namespaces_.size();
|
||||
}
|
||||
|
||||
void AddInterface(ASTInterfaceType* interface);
|
||||
|
||||
AutoPtr<ASTInterfaceType> GetInterface(size_t index);
|
||||
|
||||
size_t GetInterfaceNumber()
|
||||
{
|
||||
return interfaces_.size();
|
||||
}
|
||||
|
||||
int IndexOf(ASTInterfaceType* interface);
|
||||
|
||||
void AddSequenceable(ASTSequenceableType* sequenceable);
|
||||
|
||||
AutoPtr<ASTSequenceableType> GetSequenceable(size_t index);
|
||||
|
||||
size_t GetSequenceableNumber()
|
||||
{
|
||||
return sequenceables_.size();
|
||||
}
|
||||
|
||||
int IndexOf(ASTSequenceableType* sequenceable);
|
||||
|
||||
void AddType(ASTType* type);
|
||||
|
||||
AutoPtr<ASTType> FindType(const String& typeName);
|
||||
|
||||
using TypeStringMap = std::unordered_map<String, AutoPtr<ASTType>, StringHashFunc, StringEqualFunc>;
|
||||
|
||||
const TypeStringMap& GetTypes()
|
||||
{
|
||||
return types_;
|
||||
}
|
||||
|
||||
size_t GetTypeNumber()
|
||||
{
|
||||
return types_.size();
|
||||
}
|
||||
|
||||
int IndexOf(ASTType* type);
|
||||
|
||||
bool IsValid();
|
||||
|
||||
String Dump(const String& prefix) override;
|
||||
|
||||
private:
|
||||
String name_;
|
||||
String license_;
|
||||
std::vector<AutoPtr<ASTNamespace>> namespaces_;
|
||||
std::vector<AutoPtr<ASTInterfaceType>> interfaces_;
|
||||
std::vector<AutoPtr<ASTSequenceableType>> sequenceables_;
|
||||
TypeStringMap types_;
|
||||
|
||||
AutoPtr<ASTBooleanType> booleanType_;
|
||||
AutoPtr<ASTByteType> byteType_;
|
||||
AutoPtr<ASTShortType> shortType_;
|
||||
AutoPtr<ASTIntegerType> integerType_;
|
||||
AutoPtr<ASTLongType> longType_;
|
||||
AutoPtr<ASTFloatType> floatType_;
|
||||
AutoPtr<ASTDoubleType> doubleType_;
|
||||
AutoPtr<ASTCharType> charType_;
|
||||
AutoPtr<ASTStringType> stringType_;
|
||||
AutoPtr<ASTVoidType> voidType_;
|
||||
|
||||
String idlFilePath_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTMODULE_H
|
107
ast/ast_namespace.cpp
Normal file
107
ast/ast_namespace.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_namespace.h"
|
||||
#include "ast/ast_interface_type.h"
|
||||
#include "ast/ast_sequenceable_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
ASTNamespace::ASTNamespace(const String& nspaceStr)
|
||||
: name_(nspaceStr),
|
||||
outerNamespace_(nullptr)
|
||||
{}
|
||||
|
||||
void ASTNamespace::AddNamespace(ASTNamespace* innerNspace)
|
||||
{
|
||||
if (innerNspace == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
innerNamespaces_.push_back(innerNspace);
|
||||
innerNspace->outerNamespace_ = this;
|
||||
}
|
||||
|
||||
AutoPtr<ASTNamespace> ASTNamespace::FindNamespace(const String& nspaceStr)
|
||||
{
|
||||
if (nspaceStr.IsEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
for (auto nspace : innerNamespaces_) {
|
||||
if (nspace->name_.Equals(nspaceStr)) {
|
||||
return nspace;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
AutoPtr<ASTNamespace> ASTNamespace::GetNamespace(size_t index)
|
||||
{
|
||||
if (index >= innerNamespaces_.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return innerNamespaces_[index];
|
||||
}
|
||||
|
||||
void ASTNamespace::AddInterface(ASTInterfaceType* interface)
|
||||
{
|
||||
if (interface == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
interfaces_.push_back(interface);
|
||||
}
|
||||
|
||||
AutoPtr<ASTInterfaceType> ASTNamespace::GetInterface(size_t index)
|
||||
{
|
||||
if (index >= interfaces_.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return interfaces_[index];
|
||||
}
|
||||
|
||||
void ASTNamespace::AddSequenceable(ASTSequenceableType* sequenceable)
|
||||
{
|
||||
if (sequenceable == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
sequenceables_.push_back(sequenceable);
|
||||
}
|
||||
|
||||
AutoPtr<ASTSequenceableType> ASTNamespace::GetSequenceable(size_t index)
|
||||
{
|
||||
if (index >= sequenceables_.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return sequenceables_[index];
|
||||
}
|
||||
|
||||
String ASTNamespace::ToString()
|
||||
{
|
||||
String nspaceStr;
|
||||
ASTNamespace* nspace = this;
|
||||
while (nspace != nullptr) {
|
||||
nspaceStr = nspace->name_ + "." + nspaceStr;
|
||||
nspace = nspace->outerNamespace_;
|
||||
}
|
||||
return nspaceStr;
|
||||
}
|
||||
}
|
||||
}
|
82
ast/ast_namespace.h
Normal file
82
ast/ast_namespace.h
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTNAMESPACE_H
|
||||
#define OHOS_IDL_ASTNAMESPACE_H
|
||||
|
||||
#include <vector>
|
||||
#include "ast/ast_node.h"
|
||||
#include "util/autoptr.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTInterfaceType;
|
||||
class ASTSequenceableType;
|
||||
class ASTNamespace : public ASTNode {
|
||||
public:
|
||||
ASTNamespace(const String& nspaceStr);
|
||||
|
||||
String GetName()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
void AddNamespace(ASTNamespace* innerNspace);
|
||||
|
||||
AutoPtr<ASTNamespace> FindNamespace(const String& nspaceStr);
|
||||
|
||||
AutoPtr<ASTNamespace> GetNamespace(size_t index);
|
||||
|
||||
size_t GetNamespaceNumber()
|
||||
{
|
||||
return innerNamespaces_.size();
|
||||
}
|
||||
|
||||
void AddInterface(ASTInterfaceType* interface);
|
||||
|
||||
AutoPtr<ASTInterfaceType> GetInterface(size_t index);
|
||||
|
||||
size_t GetInterfaceNumber()
|
||||
{
|
||||
return interfaces_.size();
|
||||
}
|
||||
|
||||
void AddSequenceable(ASTSequenceableType* sequenceable);
|
||||
|
||||
AutoPtr<ASTSequenceableType> GetSequenceable(size_t index);
|
||||
|
||||
size_t GetSequenceableNumber()
|
||||
{
|
||||
return sequenceables_.size();
|
||||
}
|
||||
|
||||
String ToShortString()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
String ToString() override;
|
||||
|
||||
private:
|
||||
String name_;
|
||||
ASTNamespace* outerNamespace_;
|
||||
std::vector<AutoPtr<ASTNamespace>> innerNamespaces_;
|
||||
std::vector<AutoPtr<ASTInterfaceType>> interfaces_;
|
||||
std::vector<AutoPtr<ASTSequenceableType>> sequenceables_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTNAMESPACE_H
|
33
ast/ast_node.cpp
Normal file
33
ast/ast_node.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_node.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
ASTNode::~ASTNode()
|
||||
{}
|
||||
|
||||
String ASTNode::ToString()
|
||||
{
|
||||
return "ASTNode";
|
||||
}
|
||||
|
||||
String ASTNode::Dump(const String& prefix)
|
||||
{
|
||||
return prefix + "ASTNode";
|
||||
}
|
||||
}
|
||||
}
|
35
ast/ast_node.h
Normal file
35
ast/ast_node.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTNODE_H
|
||||
#define OHOS_IDL_ASTNODE_H
|
||||
|
||||
#include "util/light_refcount_base.h"
|
||||
#include "util/string.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTNode : public LightRefCountBase {
|
||||
public:
|
||||
virtual ~ASTNode();
|
||||
|
||||
virtual String ToString();
|
||||
|
||||
virtual String Dump(const String& prefix);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTNODE_H
|
43
ast/ast_parameter.cpp
Normal file
43
ast/ast_parameter.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_parameter.h"
|
||||
#include "util/string_builder.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
String ASTParameter::Dump(const String& prefix)
|
||||
{
|
||||
StringBuilder sb;
|
||||
|
||||
sb.Append(prefix);
|
||||
sb.Append('[');
|
||||
if (isInParameter_) {
|
||||
sb.Append("in");
|
||||
}
|
||||
if (isOutParameter_) {
|
||||
if (isInParameter_) {
|
||||
sb.Append(", ");
|
||||
}
|
||||
sb.Append("out");
|
||||
}
|
||||
sb.Append("] ");
|
||||
sb.Append(type_->ToString()).Append(' ');
|
||||
sb.Append(name_);
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
79
ast/ast_parameter.h
Normal file
79
ast/ast_parameter.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTPARAMETER_H
|
||||
#define OHOS_IDL_ASTPARAMETER_H
|
||||
|
||||
#include "ast/ast_node.h"
|
||||
#include "ast/ast_type.h"
|
||||
#include "util/autoptr.h"
|
||||
#include "util/string.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTParameter : public ASTNode {
|
||||
public:
|
||||
void SetName(const String& name)
|
||||
{
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
String GetName()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
void SetType(ASTType* type)
|
||||
{
|
||||
type_ = type;
|
||||
}
|
||||
|
||||
AutoPtr<ASTType> GetType()
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
|
||||
void SetInParameter(bool inParameter)
|
||||
{
|
||||
isInParameter_ = inParameter;
|
||||
}
|
||||
|
||||
bool IsInParameter()
|
||||
{
|
||||
return isInParameter_;
|
||||
}
|
||||
|
||||
void SetOutParameter(bool outParameter)
|
||||
{
|
||||
isOutParameter_ = outParameter;
|
||||
}
|
||||
|
||||
bool IsOutParameter()
|
||||
{
|
||||
return isOutParameter_;
|
||||
}
|
||||
|
||||
String Dump(const String& prefix) override;
|
||||
|
||||
private:
|
||||
String name_;
|
||||
AutoPtr<ASTType> type_;
|
||||
bool isInParameter_ = false;
|
||||
bool isOutParameter_ = false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTPARAMETER_H
|
60
ast/ast_sequenceable_type.cpp
Normal file
60
ast/ast_sequenceable_type.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_sequenceable_type.h"
|
||||
#include "util/string_builder.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
void ASTSequenceableType::SetNamespace(ASTNamespace* nspace)
|
||||
{
|
||||
ASTType::SetNamespace(nspace);
|
||||
if (namespace_ != nullptr) {
|
||||
namespace_->AddSequenceable(this);
|
||||
}
|
||||
}
|
||||
|
||||
String ASTSequenceableType::GetSignature()
|
||||
{
|
||||
String fullName = namespace_ != nullptr ?
|
||||
namespace_->ToString() + name_ : name_;
|
||||
return "L" + fullName.Replace('.', '/') + ";";
|
||||
}
|
||||
|
||||
bool ASTSequenceableType::IsSequenceableType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ASTSequenceableType::ToString()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
String ASTSequenceableType::Dump(const String& prefix)
|
||||
{
|
||||
StringBuilder sb;
|
||||
|
||||
sb.Append(prefix).Append("sequenceable ");
|
||||
if (namespace_ != nullptr) {
|
||||
sb.Append(namespace_->ToString());
|
||||
}
|
||||
sb.Append(name_);
|
||||
sb.Append(";\n");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
38
ast/ast_sequenceable_type.h
Normal file
38
ast/ast_sequenceable_type.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTSEQUENCEABLETYPE_H
|
||||
#define OHOS_IDL_ASTSEQUENCEABLETYPE_H
|
||||
|
||||
#include "ast/ast_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTSequenceableType : public ASTType {
|
||||
public:
|
||||
void SetNamespace(ASTNamespace* nspace) override;
|
||||
|
||||
String GetSignature() override;
|
||||
|
||||
bool IsSequenceableType() override;
|
||||
|
||||
String ToString() override;
|
||||
|
||||
String Dump(const String& prefix) override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTSEQUENCEABLETYPE_H
|
35
ast/ast_short_type.cpp
Normal file
35
ast/ast_short_type.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_short_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
String ASTShortType::GetSignature()
|
||||
{
|
||||
return "S";
|
||||
}
|
||||
|
||||
bool ASTShortType::IsShortType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ASTShortType::ToString()
|
||||
{
|
||||
return "short";
|
||||
}
|
||||
}
|
||||
}
|
34
ast/ast_short_type.h
Normal file
34
ast/ast_short_type.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTSHORTTYPE_H
|
||||
#define OHOS_IDL_ASTSHORTTYPE_H
|
||||
|
||||
#include "ast/ast_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTShortType : public ASTType {
|
||||
public:
|
||||
String GetSignature() override;
|
||||
|
||||
bool IsShortType() override;
|
||||
|
||||
String ToString() override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTSHORTTYPE_H
|
35
ast/ast_string_type.cpp
Normal file
35
ast/ast_string_type.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_string_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
String ASTStringType::GetSignature()
|
||||
{
|
||||
return "T";
|
||||
}
|
||||
|
||||
bool ASTStringType::IsStringType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ASTStringType::ToString()
|
||||
{
|
||||
return "String";
|
||||
}
|
||||
}
|
||||
}
|
33
ast/ast_string_type.h
Normal file
33
ast/ast_string_type.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTSTRINGTYPE_H
|
||||
#define OHOS_IDL_ASTSTRINGTYPE_H
|
||||
|
||||
#include "ast/ast_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTStringType : public ASTType {
|
||||
public:
|
||||
String GetSignature() override;
|
||||
|
||||
bool IsStringType() override;
|
||||
|
||||
String ToString() override;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // OHOS_IDL_ASTSTRINGTYPE_H
|
125
ast/ast_type.cpp
Normal file
125
ast/ast_type.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
void ASTType::SetName(const String& name)
|
||||
{
|
||||
name_ = name;
|
||||
}
|
||||
|
||||
String ASTType::GetName()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
void ASTType::SetNamespace(ASTNamespace* nspace)
|
||||
{
|
||||
namespace_ = nspace;
|
||||
}
|
||||
|
||||
AutoPtr<ASTNamespace> ASTType::GetNamespace()
|
||||
{
|
||||
return namespace_;
|
||||
}
|
||||
|
||||
bool ASTType::IsBooleanType()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ASTType::IsByteType()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ASTType::IsShortType()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ASTType::IsIntegerType()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ASTType::IsLongType()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ASTType::IsFloatType()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ASTType::IsDoubleType()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ASTType::IsCharType()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ASTType::IsStringType()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ASTType::IsListType()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ASTType::IsMapType()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ASTType::IsInterfaceType()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ASTType::IsSequenceableType()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ASTType::IsVoidType()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ASTType::IsArrayType()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
String ASTType::ToShortString()
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
String ASTType::ToString()
|
||||
{
|
||||
return namespace_ == nullptr ? name_ : namespace_->ToString() + name_;
|
||||
}
|
||||
}
|
||||
}
|
79
ast/ast_type.h
Normal file
79
ast/ast_type.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTTYPE_H
|
||||
#define OHOS_IDL_ASTTYPE_H
|
||||
|
||||
#include "ast/ast_namespace.h"
|
||||
#include "ast/ast_node.h"
|
||||
#include "util/autoptr.h"
|
||||
#include "util/string.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTType : public ASTNode {
|
||||
public:
|
||||
virtual void SetName(const String& name);
|
||||
|
||||
virtual String GetName();
|
||||
|
||||
virtual void SetNamespace(ASTNamespace* nspace);
|
||||
|
||||
virtual AutoPtr<ASTNamespace> GetNamespace();
|
||||
|
||||
virtual String GetSignature() = 0;
|
||||
|
||||
virtual bool IsBooleanType();
|
||||
|
||||
virtual bool IsByteType();
|
||||
|
||||
virtual bool IsShortType();
|
||||
|
||||
virtual bool IsIntegerType();
|
||||
|
||||
virtual bool IsLongType();
|
||||
|
||||
virtual bool IsFloatType();
|
||||
|
||||
virtual bool IsDoubleType();
|
||||
|
||||
virtual bool IsCharType();
|
||||
|
||||
virtual bool IsStringType();
|
||||
|
||||
virtual bool IsListType();
|
||||
|
||||
virtual bool IsMapType();
|
||||
|
||||
virtual bool IsInterfaceType();
|
||||
|
||||
virtual bool IsSequenceableType();
|
||||
|
||||
virtual bool IsVoidType();
|
||||
|
||||
virtual bool IsArrayType();
|
||||
|
||||
virtual String ToShortString();
|
||||
|
||||
String ToString() override;
|
||||
|
||||
protected:
|
||||
String name_;
|
||||
AutoPtr<ASTNamespace> namespace_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTTYPE_H
|
35
ast/ast_void_type.cpp
Normal file
35
ast/ast_void_type.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ast/ast_void_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
String ASTVoidType::GetSignature()
|
||||
{
|
||||
return "V";
|
||||
}
|
||||
|
||||
bool ASTVoidType::IsVoidType()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
String ASTVoidType::ToString()
|
||||
{
|
||||
return "void";
|
||||
}
|
||||
}
|
||||
}
|
34
ast/ast_void_type.h
Normal file
34
ast/ast_void_type.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_ASTVOIDTYPE_H
|
||||
#define OHOS_IDL_ASTVOIDTYPE_H
|
||||
|
||||
#include "ast/ast_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class ASTVoidType : public ASTType {
|
||||
public:
|
||||
String GetSignature() override;
|
||||
|
||||
bool IsVoidType() override;
|
||||
|
||||
String ToString() override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_ASTBOOLEANTYPE_H
|
40
bundle.json
Normal file
40
bundle.json
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "@ohos/idl",
|
||||
"description": "提供自动生成Extension 服务端及客户端接口文件的能力",
|
||||
"version": "3.1",
|
||||
"license": "Apache License 2.0",
|
||||
"publishAs": "code-segment",
|
||||
"segment": {
|
||||
"destPath": "foundation/ability/ability_runtime/idl"
|
||||
},
|
||||
"dirs": {},
|
||||
"scripts": {},
|
||||
"component": {
|
||||
"name": "idl",
|
||||
"subsystem": "aafwk",
|
||||
"syscap": [],
|
||||
"features": [],
|
||||
"adapted_system_type": [
|
||||
"standard"
|
||||
],
|
||||
"rom": "",
|
||||
"ram": "",
|
||||
"deps": {
|
||||
"components": [
|
||||
"hiviewdfx_hilog_native",
|
||||
"ipc",
|
||||
"samgr_standard",
|
||||
"utils_base"
|
||||
],
|
||||
"third_party": []
|
||||
},
|
||||
"build": {
|
||||
"sub_component": [],
|
||||
"inner_kits": [],
|
||||
"test": [
|
||||
"//foundation/ability/ability_runtime/idl/test/ts/moduletest:moduletest",
|
||||
"//foundation/ability/ability_runtime/idl/test/ts/unittest:unittest"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
44
codegen/code_emitter.cpp
Normal file
44
codegen/code_emitter.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "codegen/code_emitter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
const char* CodeEmitter::TAB = " ";
|
||||
CodeEmitter::CodeEmitter(MetaComponent* mc)
|
||||
: metaComponent_(mc)
|
||||
{
|
||||
metaInterface_ = nullptr;
|
||||
for (int i = 0; i < metaComponent_->interfaceNumber_; i++) {
|
||||
metaInterface_ = metaComponent_->interfaces_[i];
|
||||
if (!metaInterface_->external_) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (metaInterface_ != nullptr) {
|
||||
interfaceName_ = metaInterface_->name_;
|
||||
interfaceFullName_ = metaInterface_->namespace_ + interfaceName_;
|
||||
proxyName_ = interfaceName_.StartsWith("I") ?
|
||||
interfaceName_.Substring(1) + "Proxy" : interfaceName_ + "Proxy";
|
||||
proxyFullName_ = metaInterface_->namespace_ + proxyName_;
|
||||
stubName_ = interfaceName_.StartsWith("I") ?
|
||||
interfaceName_.Substring(1) + "Stub" : interfaceName_ + "Stub";
|
||||
stubFullName_ = metaInterface_->namespace_ + stubName_;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
codegen/code_emitter.h
Normal file
56
codegen/code_emitter.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_CODEEMITTER_H
|
||||
#define OHOS_IDL_CODEEMITTER_H
|
||||
|
||||
#include "metadata/meta_component.h"
|
||||
#include "util/light_refcount_base.h"
|
||||
#include "util/string.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class CodeEmitter : public LightRefCountBase {
|
||||
public:
|
||||
CodeEmitter(MetaComponent* mc);
|
||||
|
||||
void SetDirectory(const String& directory)
|
||||
{
|
||||
directory_ = directory;
|
||||
}
|
||||
|
||||
virtual void EmitInterface() = 0;
|
||||
|
||||
virtual void EmitInterfaceProxy() = 0;
|
||||
|
||||
virtual void EmitInterfaceStub() = 0;
|
||||
|
||||
protected:
|
||||
static const char* TAB;
|
||||
|
||||
MetaComponent* metaComponent_;
|
||||
MetaInterface* metaInterface_;
|
||||
String directory_;
|
||||
String interfaceName_;
|
||||
String interfaceFullName_;
|
||||
String proxyName_;
|
||||
String proxyFullName_;
|
||||
String stubName_;
|
||||
String stubFullName_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_CODEEMITTER_H
|
86
codegen/code_generator.cpp
Normal file
86
codegen/code_generator.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "codegen/code_generator.h"
|
||||
#include <cstdlib>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include "codegen/cpp_code_emitter.h"
|
||||
#include "codegen/ts_code_emitter.h"
|
||||
#include "util/logger.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
const char* CodeGenerator::TAG = "CodeGenerator";
|
||||
CodeGenerator::CodeGenerator(MetaComponent* mc, const String& language, const String& dir)
|
||||
: targetLanguage_(language),
|
||||
targetDirectory_(dir),
|
||||
metaComponent_(mc)
|
||||
{
|
||||
if (language.Equals("cpp")) {
|
||||
emitter_ = new CppCodeEmitter(metaComponent_);
|
||||
} else if (language.Equals("ts")) {
|
||||
emitter_ = new TsCodeEmitter(metaComponent_);
|
||||
}
|
||||
}
|
||||
|
||||
bool CodeGenerator::ResolveDirectory()
|
||||
{
|
||||
#ifdef __MINGW32__
|
||||
if (targetDirectory_.IndexOf(":\\") == -1) {
|
||||
char* cmd = getcwd(nullptr, 0);
|
||||
targetDirectory_ = String::Format("%s\\%s", cmd, targetDirectory_.string());
|
||||
free(cmd);
|
||||
}
|
||||
#else
|
||||
if (!targetDirectory_.StartsWith("/")) {
|
||||
char* cwd = getcwd(nullptr, 0);
|
||||
targetDirectory_ = String::Format("%s/%s", cwd, targetDirectory_.string());
|
||||
free(cwd);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!access(targetDirectory_.string(), R_OK | W_OK)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __MINGW32__
|
||||
if (mkdir(targetDirectory_.string()) != 0) {
|
||||
#else
|
||||
if (mkdir(targetDirectory_.string(), S_IRWXU | S_IRWXG | S_IRWXO) != 0) {
|
||||
#endif
|
||||
Logger::E(TAG, "Create \"%s\" directory failed.", targetDirectory_.string());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CodeGenerator::Generate()
|
||||
{
|
||||
if (!ResolveDirectory()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
emitter_->SetDirectory(targetDirectory_);
|
||||
|
||||
emitter_->EmitInterface();
|
||||
emitter_->EmitInterfaceProxy();
|
||||
emitter_->EmitInterfaceStub();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
46
codegen/code_generator.h
Normal file
46
codegen/code_generator.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_CODEGENERATOR_H
|
||||
#define OHOS_IDL_CODEGENERATOR_H
|
||||
|
||||
#include "codegen/code_emitter.h"
|
||||
#include "metadata/meta_component.h"
|
||||
#include "util/autoptr.h"
|
||||
#include "util/string.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class CodeGenerator {
|
||||
public:
|
||||
CodeGenerator(MetaComponent* mc, const String& language, const String& dir);
|
||||
|
||||
~CodeGenerator() = default;
|
||||
|
||||
bool Generate();
|
||||
|
||||
private:
|
||||
bool ResolveDirectory();
|
||||
|
||||
static const char* TAG;
|
||||
String targetLanguage_;
|
||||
String targetDirectory_;
|
||||
MetaComponent* metaComponent_;
|
||||
AutoPtr<CodeEmitter> emitter_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_CODEGENERATOR_H
|
1078
codegen/cpp_code_emitter.cpp
Normal file
1078
codegen/cpp_code_emitter.cpp
Normal file
File diff suppressed because it is too large
Load Diff
144
codegen/cpp_code_emitter.h
Normal file
144
codegen/cpp_code_emitter.h
Normal file
@ -0,0 +1,144 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_CPPCODEEMITTER_H
|
||||
#define OHOS_IDL_CPPCODEEMITTER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "codegen/code_emitter.h"
|
||||
#include "util/string_builder.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class CppCodeEmitter : public CodeEmitter {
|
||||
public:
|
||||
CppCodeEmitter(MetaComponent* mc)
|
||||
: CodeEmitter(mc)
|
||||
{}
|
||||
|
||||
void EmitInterface() override;
|
||||
|
||||
void EmitInterfaceProxy() override;
|
||||
|
||||
void EmitInterfaceStub() override;
|
||||
|
||||
private:
|
||||
void EmitInterfaceHeaderFile();
|
||||
|
||||
void EmitInterfaceInclusions(StringBuilder& sb);
|
||||
|
||||
void EmitInterfaceStdlibInclusions(StringBuilder& sb);
|
||||
|
||||
void EmitInterfaceDBinderInclusions(StringBuilder& sb);
|
||||
|
||||
void EmitInterfaceSelfDefinedTypeInclusions(StringBuilder& sb);
|
||||
|
||||
bool EmitInterfaceUsings(StringBuilder& sb);
|
||||
|
||||
void EmitInterfaceSelfDefinedTypeUsings(StringBuilder& sb);
|
||||
|
||||
void EmitInterfaceDefinition(StringBuilder& sb);
|
||||
|
||||
void EmitInterfaceBody(StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitInterfaceMethods(StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitInterfaceMethod(MetaMethod* mm, StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitInterfaceMethodParameter(MetaParameter* mp, StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitInterfaceMethodReturn(MetaType* mt, StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitInterfaceProxyHeaderFile();
|
||||
|
||||
void EmitInterfaceProxyInHeaderFile(StringBuilder& sb);
|
||||
|
||||
void EmitInterfaceProxyConstructor(StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitInterfaceProxyMethodDecls(StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitInterfaceProxyMethodDecl(MetaMethod* mm, StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitInterfaceProxyConstants(StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitInterfaceProxyCppFile();
|
||||
|
||||
void EmitInterfaceProxyMethodImpls(StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitInterfaceProxyMethodImpl(MetaMethod* mm, StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitInterfaceProxyMethodBody(MetaMethod* mm, StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitWriteMethodParameter(MetaParameter* mp, const String& parcelName, StringBuilder& sb,
|
||||
const String& prefix);
|
||||
|
||||
void EmitReadMethodParameter(MetaParameter* mp, const String& parcelName, StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitInterfaceStubHeaderFile();
|
||||
|
||||
void EmitInterfaceStubInHeaderFile(StringBuilder& sb);
|
||||
|
||||
void EmitInterfaceStubMethodDecls(StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitInterfaceStubConstants(StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitInterfaceStubCppFile();
|
||||
|
||||
void EmitInterfaceStubMethodImpls(StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitInterfaceStubMethodImpl(MetaMethod* mm, StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitInterfaceMethodCommands(StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitLicense(StringBuilder& sb);
|
||||
|
||||
void EmitHeadMacro(StringBuilder& sb, const String& fullName);
|
||||
|
||||
void EmitTailMacro(StringBuilder& sb, const String& fullName);
|
||||
|
||||
void EmitBeginNamespace(StringBuilder& sb);
|
||||
|
||||
void EmitEndNamespace(StringBuilder& sb);
|
||||
|
||||
void EmitWriteVariable(const String& parcelName, const std::string& name, MetaType* mt, StringBuilder& sb,
|
||||
const String& prefix);
|
||||
|
||||
void EmitReadVariable(const String& parcelName, const std::string& name, MetaType* mt, StringBuilder& sb,
|
||||
const String& prefix, bool emitType = true);
|
||||
|
||||
void EmitLocalVariable(MetaParameter* mp, StringBuilder& sb, const String& prefix);
|
||||
|
||||
void EmitReturnParameter(const String& name, MetaType* mt, StringBuilder& sb);
|
||||
|
||||
String EmitType(MetaType* mt, unsigned int attributes, bool isInnerType);
|
||||
|
||||
String FileName(const String& name);
|
||||
|
||||
String GetFilePath(const String& fpnp);
|
||||
|
||||
String GetNamespace(const String& fpnp);
|
||||
|
||||
String MacroName(const String& name);
|
||||
|
||||
String CppFullName(const String& name);
|
||||
|
||||
String ConstantName(const String& name);
|
||||
|
||||
const std::string UnderlineAdded(const String& name);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // OHOS_IDL_CPPCODEEMITTER_H
|
1143
codegen/ts_code_emitter.cpp
Normal file
1143
codegen/ts_code_emitter.cpp
Normal file
File diff suppressed because it is too large
Load Diff
157
codegen/ts_code_emitter.h
Normal file
157
codegen/ts_code_emitter.h
Normal file
@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_TSCODEEMITTER_H
|
||||
#define OHOS_IDL_TSCODEEMITTER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "codegen/code_emitter.h"
|
||||
#include "util/string_builder.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class TsCodeEmitter : public CodeEmitter {
|
||||
public:
|
||||
TsCodeEmitter(MetaComponent* mc)
|
||||
: CodeEmitter(mc)
|
||||
{}
|
||||
|
||||
void EmitInterface() override;
|
||||
|
||||
void EmitInterfaceProxy() override;
|
||||
|
||||
void EmitInterfaceStub() override;
|
||||
|
||||
struct Parameter {
|
||||
bool operator< (const Parameter ¶) const
|
||||
{
|
||||
if (this->attr_ == ATTR_IN) {
|
||||
return this->attr_ < para.attr_;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
std::string name_;
|
||||
std::string type_;
|
||||
unsigned int attr_ = 0;
|
||||
};
|
||||
|
||||
struct Method {
|
||||
Parameter retParameter_;
|
||||
std::vector<Parameter> parameters_;
|
||||
std::string callbackName_;
|
||||
std::string name_;
|
||||
std::string exportFunction_;
|
||||
unsigned int properties_;
|
||||
};
|
||||
|
||||
private:
|
||||
void EmitInterfaceImports(StringBuilder& stringBuilder);
|
||||
|
||||
void EmitInterfaceProxyImports(StringBuilder& stringBuilder);
|
||||
|
||||
void EmitInterfaceSelfDefinedTypeImports(StringBuilder& stringBuilder);
|
||||
|
||||
void EmitInterfaceDefinition(StringBuilder& stringBuilder);
|
||||
|
||||
void EmitInterfaceMethods(StringBuilder& stringBuilder, const String& prefix);
|
||||
|
||||
void EmitInterfaceMethod(MetaMethod* metaMethod, StringBuilder& stringBuilder, const String& prefix);
|
||||
|
||||
void EmitInterfaceMethodParameter(MetaParameter* mp, StringBuilder& stringBuilder, const String& prefix);
|
||||
|
||||
void EmitMethodInParameter(StringBuilder& stringBuilder, const std::string& name, const std::string& type,
|
||||
const String& prefix);
|
||||
|
||||
void EmitInterfaceMethodExportCallback(Method& m, const Parameter& para, bool isLast);
|
||||
|
||||
void EmitInterfaceProxyImpl(StringBuilder& stringBuilder);
|
||||
|
||||
void EmitInterfaceProxyConstructor(StringBuilder& stringBuilder, const String& prefix);
|
||||
|
||||
void EmitInterfaceProxyMethodImpls(StringBuilder& stringBuilder, const String& prefix);
|
||||
|
||||
void EmitInterfaceProxyMethodImpl(MetaMethod* metaMethod, int methodIndex, StringBuilder& stringBuilder,
|
||||
const String& prefix);
|
||||
|
||||
void EmitInterfaceProxyMethodBody(MetaMethod* metaMethod, int methodIndex, StringBuilder& stringBuilder,
|
||||
const String& prefix);
|
||||
|
||||
void EmitWriteMethodParameter(MetaParameter* mp, const String& parcelName, StringBuilder& stringBuilder,
|
||||
const String& prefix);
|
||||
|
||||
void EmitReadMethodParameter(MetaParameter* mp, const String& parcelName, StringBuilder& stringBuilder,
|
||||
const String& prefix);
|
||||
|
||||
void EmitInterfaceStubImpl(StringBuilder& stringBuilder);
|
||||
|
||||
void EmitInterfaceStubConstructor(StringBuilder& stringBuilder, const String& prefix);
|
||||
|
||||
void EmitInterfaceStubMethodImpls(StringBuilder& stringBuilder, const String& prefix);
|
||||
|
||||
void EmitInterfaceStubMethodImpl(MetaMethod* metaMethod, int methodIndex, StringBuilder& stringBuilder,
|
||||
const String& prefix);
|
||||
|
||||
void EmitInterfaceMethodCommands(StringBuilder& stringBuilder);
|
||||
|
||||
void EmitLicense(StringBuilder& stringBuilder);
|
||||
|
||||
void EmitWriteVariable(const String& parcelName, const std::string& name, MetaType* mt,
|
||||
StringBuilder& stringBuilder,
|
||||
const String& prefix);
|
||||
|
||||
void EmitReadVariable(const String& parcelName, const std::string& name, MetaType* mt, unsigned int attributes,
|
||||
StringBuilder& stringBuilder,
|
||||
const String& prefix);
|
||||
|
||||
void EmitReadOutVariable(const String& parcelName, const std::string& name, MetaType* mt,
|
||||
StringBuilder& stringBuilder,
|
||||
const String& prefix);
|
||||
|
||||
void EmitReadArrayVariable(const String& parcelName, const std::string& name, MetaType* mt,
|
||||
unsigned int attributes,
|
||||
StringBuilder& stringBuilder,
|
||||
const String& prefix);
|
||||
|
||||
void EmitWriteArrayVariable(const String& parcelName, const std::string& name, MetaType* mt,
|
||||
StringBuilder& stringBuilder,
|
||||
const String& prefix);
|
||||
|
||||
void EmitReadOutArrayVariable(const String& parcelName, const std::string& name, MetaType* mt,
|
||||
StringBuilder& stringBuilder,
|
||||
const String& prefix);
|
||||
|
||||
String EmitType(MetaType* mt);
|
||||
|
||||
String FileName(const String& name);
|
||||
|
||||
String MethodName(const String& name);
|
||||
|
||||
String ConstantName(const String& name);
|
||||
|
||||
String StubName(const String& name);
|
||||
|
||||
bool CheckInterfaceType();
|
||||
|
||||
const std::string UnderlineAdded(const String& name);
|
||||
|
||||
std::vector<Method> methods_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_TSCODEEMITTER_H
|
BIN
figures/IDL-interface-description.png
Executable file
BIN
figures/IDL-interface-description.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
BIN
figures/IPC-RPC-communication-model.png
Executable file
BIN
figures/IPC-RPC-communication-model.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
16
idl.gni
Executable file
16
idl.gni
Executable file
@ -0,0 +1,16 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
aafwk_path = "//foundation/ability/ability_runtime"
|
||||
IPC_SUBSYSTEM_DIR = "//foundation/communication/ipc"
|
||||
IDL_TEST_DIR = "${aafwk_path}/idl/test/native"
|
106
main.cpp
Normal file
106
main.cpp
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "codegen/code_generator.h"
|
||||
#include "metadata/metadata_builder.h"
|
||||
#include "metadata/metadata_dumper.h"
|
||||
#include "metadata/metadata_reader.h"
|
||||
#include "metadata/metadata_serializer.h"
|
||||
#include "parser/parser.h"
|
||||
#include "util/logger.h"
|
||||
#include "util/options.h"
|
||||
|
||||
using namespace OHOS::Idl;
|
||||
|
||||
static const char* TAG = "idl";
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
Options options(argc, argv);
|
||||
|
||||
if (options.DoShowUsage()) {
|
||||
options.ShowUsage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (options.DoShowVersion()) {
|
||||
options.ShowVersion();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (options.HasErrors()) {
|
||||
options.ShowErrors();
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::shared_ptr<MetaComponent> metadata;
|
||||
|
||||
if (options.DoCompile()) {
|
||||
Parser parser(options);
|
||||
if (!parser.Parse(options.GetSourceFile())) {
|
||||
Logger::E(TAG, "Parsing .idl failed.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
MetadataBuilder builder(parser.GetModule());
|
||||
metadata = builder.Build();
|
||||
if (metadata == nullptr) {
|
||||
Logger::E(TAG, "Generate metadata failed.");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.DoDumpMetadata()) {
|
||||
MetadataDumper dumper(metadata.get());
|
||||
dumper.Dump("");
|
||||
}
|
||||
|
||||
if (options.DoSaveMetadata()) {
|
||||
File metadataFile(options.GetMetadataFile(), File::WRITE);
|
||||
if (!metadataFile.IsValid()) {
|
||||
Logger::E(TAG, "Create metadata file failed.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
MetadataSerializer serializer(metadata.get());
|
||||
serializer.Serialize();
|
||||
uintptr_t data = serializer.GetData();
|
||||
int size = serializer.GetDataSize();
|
||||
|
||||
metadataFile.WriteData(reinterpret_cast<void*>(data), size);
|
||||
metadataFile.Flush();
|
||||
metadataFile.Close();
|
||||
}
|
||||
|
||||
if (options.DoGenerateCode()) {
|
||||
if (metadata == nullptr) {
|
||||
String metadataFile = options.GetMetadataFile();
|
||||
metadata = MetadataReader::ReadMetadataFromFile(metadataFile);
|
||||
if (metadata == nullptr) {
|
||||
Logger::E(TAG, "Get metadata from \"%s\" failed.", metadataFile.string());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
CodeGenerator codeGen(metadata.get(), options.GetTargetLanguage(),
|
||||
options.GetGenerationDirectory());
|
||||
if (!codeGen.Generate()) {
|
||||
Logger::E(TAG, "Generate \"%s\" codes failed.", options.GetTargetLanguage().string());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
56
metadata/meta_component.h
Normal file
56
metadata/meta_component.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_METADATA_H
|
||||
#define OHOS_IDL_METADATA_H
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "meta_interface.h"
|
||||
#include "meta_namespace.h"
|
||||
#include "meta_sequenceable.h"
|
||||
#include "meta_type.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
static constexpr int METADATA_MAGIC_NUMBER = 0x1DF02ED1;
|
||||
|
||||
struct MetaComponent {
|
||||
int magic_;
|
||||
int size_;
|
||||
char* name_;
|
||||
int namespaceNumber_;
|
||||
int sequenceableNumber_;
|
||||
int interfaceNumber_;
|
||||
int typeNumber_;
|
||||
MetaNamespace** namespaces_;
|
||||
MetaSequenceable** sequenceables_;
|
||||
MetaInterface** interfaces_;
|
||||
MetaType** types_;
|
||||
int stringPoolSize_;
|
||||
char* stringPool_;
|
||||
};
|
||||
|
||||
static constexpr unsigned int INTERFACE_PROPERTY_ONEWAY = 0x1;
|
||||
|
||||
static constexpr unsigned int METHOD_PROPERTY_ONEWAY = 0x1;
|
||||
|
||||
static constexpr unsigned int ATTR_IN = 0x1;
|
||||
static constexpr unsigned int ATTR_OUT = 0x2;
|
||||
static constexpr unsigned int ATTR_MASK = 0x3;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_METADATA_H
|
35
metadata/meta_interface.h
Normal file
35
metadata/meta_interface.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_METAINTERFACE_H
|
||||
#define OHOS_IDL_METAINTERFACE_H
|
||||
|
||||
#include "meta_method.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
struct MetaInterface {
|
||||
char* license_;
|
||||
char* name_;
|
||||
char* namespace_;
|
||||
unsigned int properties_;
|
||||
int methodNumber_;
|
||||
MetaMethod** methods_;
|
||||
bool external_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_METAINTERFACE_H
|
34
metadata/meta_method.h
Normal file
34
metadata/meta_method.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_METAMETHOD_H
|
||||
#define OHOS_IDL_METAMETHOD_H
|
||||
|
||||
#include "meta_patameter.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
struct MetaMethod {
|
||||
char* name_;
|
||||
char* signature_;
|
||||
unsigned int properties_;
|
||||
int returnTypeIndex_;
|
||||
int parameterNumber_;
|
||||
MetaParameter** parameters_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_METAMETHOD_H
|
33
metadata/meta_namespace.h
Normal file
33
metadata/meta_namespace.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_METANAMESPACE_H
|
||||
#define OHOS_IDL_METANAMESPACE_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
struct MetaNamespace {
|
||||
char* name_;
|
||||
int sequenceableNumber_;
|
||||
int interfaceNumber_;
|
||||
int namespaceNumber_;
|
||||
int* sequenceableIndexes_;
|
||||
int* interfaceIndexes_;
|
||||
MetaNamespace** namespaces_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_METANAMESPACE_H
|
29
metadata/meta_patameter.h
Normal file
29
metadata/meta_patameter.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_METAPARAMETER_H
|
||||
#define OHOS_IDL_METAPARAMETER_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
struct MetaParameter {
|
||||
char* name_;
|
||||
unsigned int attributes_;
|
||||
int typeIndex_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_METAPARAMETER_H
|
28
metadata/meta_sequenceable.h
Normal file
28
metadata/meta_sequenceable.h
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_METASEQUENCEABLE_H
|
||||
#define OHOS_IDL_METASEQUENCEABLE_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
struct MetaSequenceable {
|
||||
char* name_;
|
||||
char* namespace_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_METASEQUENCEABLE_H
|
49
metadata/meta_type.h
Normal file
49
metadata/meta_type.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_METATYPE_H
|
||||
#define OHOS_IDL_METATYPE_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
enum class TypeKind {
|
||||
Unknown = 0,
|
||||
Char = 1,
|
||||
Boolean = 2,
|
||||
Byte = 3,
|
||||
Short = 4,
|
||||
Integer = 5,
|
||||
Long = 6,
|
||||
Float = 7,
|
||||
Double = 8,
|
||||
String = 9,
|
||||
Void = 10,
|
||||
Sequenceable = 11,
|
||||
Interface = 12,
|
||||
List = 13,
|
||||
Map = 14,
|
||||
Array = 15,
|
||||
};
|
||||
|
||||
struct MetaType {
|
||||
TypeKind kind_;
|
||||
int index_;
|
||||
int nestedTypeNumber_;
|
||||
int* nestedTypeIndexes_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_METATYPE_H
|
488
metadata/metadata_builder.cpp
Normal file
488
metadata/metadata_builder.cpp
Normal file
@ -0,0 +1,488 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "metadata/metadata_builder.h"
|
||||
#include <cstring>
|
||||
#include "securec.h"
|
||||
#include "ast/ast_array_type.h"
|
||||
#include "ast/ast_list_type.h"
|
||||
#include "ast/ast_map_type.h"
|
||||
#include "util/logger.h"
|
||||
|
||||
#define ALIGN8(v) (((v) + 7) & ~7)
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
const char* MetadataBuilder::TAG = "MetadataBuilder";
|
||||
std::shared_ptr<MetaComponent> MetadataBuilder::Build()
|
||||
{
|
||||
if (!module_->IsValid()) {
|
||||
Logger::E(TAG, "The module is not validate.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
size_ = CalculateMetadataSize();
|
||||
if (size_ > 0) {
|
||||
void* metadata = calloc(size_, 1);
|
||||
if (metadata == nullptr) {
|
||||
Logger::E(TAG, "Out of memory.");
|
||||
return nullptr;
|
||||
}
|
||||
metaComponent_.reset(
|
||||
new(metadata) MetaComponent, [](MetaComponent* p) { free(p); });
|
||||
|
||||
WriteMetadata(reinterpret_cast<uintptr_t>(metadata));
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return metaComponent_;
|
||||
}
|
||||
|
||||
size_t MetadataBuilder::CalculateMetadataSize()
|
||||
{
|
||||
baseAddr_ = 0;
|
||||
CalculateMetaComponent(module_);
|
||||
return baseAddr_;
|
||||
}
|
||||
|
||||
void MetadataBuilder::CalculateMetaComponent(ASTModule* module)
|
||||
{
|
||||
int namespaceNumber = module->GetNamespaceNumber();
|
||||
int sequenceableNumber = module->GetSequenceableNumber();
|
||||
int interfaceNumber = module->GetInterfaceNumber();
|
||||
int typeNumber = module->GetTypeNumber();
|
||||
|
||||
// begin address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
stringPool_.Add(module_->GetName());
|
||||
// namespaces_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(MetaComponent));
|
||||
// sequenceables_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(MetaNamespace*) * namespaceNumber);
|
||||
// interfaces_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(MetaSequenceable*) * sequenceableNumber);
|
||||
// types_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(MetaInterface*) * interfaceNumber);
|
||||
// stringPool_'s address
|
||||
baseAddr_ = baseAddr_ + sizeof(MetaType*) * typeNumber;
|
||||
|
||||
for (int i = 0; i < namespaceNumber; i++) {
|
||||
CalculateMetaNamespace(module->GetNamespace(i));
|
||||
}
|
||||
|
||||
for (int i = 0; i < sequenceableNumber; i++) {
|
||||
CalculateMetaSequenceable(module->GetSequenceable(i));
|
||||
}
|
||||
|
||||
for (int i = 0; i < interfaceNumber; i++) {
|
||||
CalculateMetaInterface(module->GetInterface(i));
|
||||
}
|
||||
|
||||
const ASTModule::TypeStringMap& types = module_->GetTypes();
|
||||
for (const auto& pair : types) {
|
||||
CalculateMetaType(pair.second);
|
||||
}
|
||||
|
||||
// end address
|
||||
CalculateStringPool();
|
||||
}
|
||||
|
||||
void MetadataBuilder::CalculateMetaNamespace(ASTNamespace* nspace)
|
||||
{
|
||||
int sequenceableNumber = nspace->GetSequenceableNumber();
|
||||
int interfaceNumber = nspace->GetInterfaceNumber();
|
||||
int namespaceNumber = nspace->GetNamespaceNumber();
|
||||
|
||||
// begin address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
stringPool_.Add(nspace->GetName());
|
||||
// sequenceables_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(MetaNamespace));
|
||||
// interfaces_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(int) * sequenceableNumber);
|
||||
// namespaces_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(int) * interfaceNumber);
|
||||
// end address
|
||||
baseAddr_ = baseAddr_ + sizeof(MetaNamespace*) * namespaceNumber;
|
||||
|
||||
for (int i = 0; i < namespaceNumber; i++) {
|
||||
CalculateMetaNamespace(nspace->GetNamespace(i));
|
||||
}
|
||||
}
|
||||
|
||||
void MetadataBuilder::CalculateMetaSequenceable(ASTSequenceableType* sequenceable)
|
||||
{
|
||||
// begin address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
stringPool_.Add(sequenceable->GetName());
|
||||
stringPool_.Add(sequenceable->GetNamespace()->ToString());
|
||||
// end address
|
||||
baseAddr_ = baseAddr_ + sizeof(MetaSequenceable);
|
||||
}
|
||||
|
||||
void MetadataBuilder::CalculateMetaInterface(ASTInterfaceType* interface)
|
||||
{
|
||||
int methodNumber = interface->GetMethodNumber();
|
||||
|
||||
// begin address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
stringPool_.Add(interface->GetLicense());
|
||||
stringPool_.Add(interface->GetName());
|
||||
stringPool_.Add(interface->GetNamespace()->ToString());
|
||||
// methods_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(MetaInterface));
|
||||
// end address
|
||||
baseAddr_ = baseAddr_ + sizeof(MetaMethod*) * methodNumber;
|
||||
|
||||
for (int i = 0; i < methodNumber; i++) {
|
||||
CalculateMetaMethod(interface->GetMethod(i));
|
||||
}
|
||||
}
|
||||
|
||||
void MetadataBuilder::CalculateMetaMethod(ASTMethod* method)
|
||||
{
|
||||
int parameterNumber = method->GetParameterNumber();
|
||||
|
||||
// begin address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
stringPool_.Add(method->GetName());
|
||||
stringPool_.Add(method->GetSignature());
|
||||
// parameters_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(MetaMethod));
|
||||
// end address
|
||||
baseAddr_ = baseAddr_ + sizeof(MetaParameter*) * parameterNumber;
|
||||
|
||||
for (int i = 0; i < parameterNumber; i++) {
|
||||
CalculateMetaParameter(method->GetParameter(i));
|
||||
}
|
||||
}
|
||||
|
||||
void MetadataBuilder::CalculateMetaParameter(ASTParameter* parameter)
|
||||
{
|
||||
// begin address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
stringPool_.Add(parameter->GetName());
|
||||
// end address
|
||||
baseAddr_ = baseAddr_ + sizeof(MetaParameter);
|
||||
}
|
||||
|
||||
void MetadataBuilder::CalculateMetaType(ASTType* type)
|
||||
{
|
||||
// begin address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
// nestedTypeIndexes_'s address
|
||||
baseAddr_ = baseAddr_ + sizeof(MetaType);
|
||||
if (type->IsListType()) {
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
// end address
|
||||
baseAddr_ = baseAddr_ + sizeof(int*);
|
||||
} else if (type->IsMapType()) {
|
||||
// end address
|
||||
int typeNumber = 2;
|
||||
baseAddr_ = baseAddr_ + sizeof(int*) * typeNumber;
|
||||
} else if (type->IsArrayType()) {
|
||||
baseAddr_ = baseAddr_ + sizeof(int*);
|
||||
}
|
||||
}
|
||||
|
||||
void MetadataBuilder::CalculateStringPool()
|
||||
{
|
||||
// begin address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
// end address
|
||||
baseAddr_ = baseAddr_ + stringPool_.GetSize();
|
||||
}
|
||||
|
||||
void MetadataBuilder::WriteMetadata(uintptr_t base)
|
||||
{
|
||||
baseAddr_ = base;
|
||||
WriteMetaComponent(module_);
|
||||
}
|
||||
|
||||
void MetadataBuilder::WriteMetaComponent(ASTModule* module)
|
||||
{
|
||||
int namespaceNumber = module->GetNamespaceNumber();
|
||||
int sequenceableNumber = module->GetSequenceableNumber();
|
||||
int interfaceNumber = module->GetInterfaceNumber();
|
||||
int typeNumber = module->GetTypeNumber();
|
||||
|
||||
// begin address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
MetaComponent* mc = reinterpret_cast<MetaComponent*>(baseAddr_);
|
||||
mc->magic_ = METADATA_MAGIC_NUMBER;
|
||||
mc->size_ = size_;
|
||||
mc->namespaceNumber_ = namespaceNumber;
|
||||
mc->sequenceableNumber_ = sequenceableNumber;
|
||||
mc->interfaceNumber_ = interfaceNumber;
|
||||
mc->typeNumber_ = typeNumber;
|
||||
mc->stringPoolSize_ = stringPool_.GetSize();
|
||||
// namespaces_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(MetaComponent));
|
||||
mc->namespaces_ = reinterpret_cast<MetaNamespace**>(baseAddr_);
|
||||
// sequenceables_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(MetaNamespace*) * namespaceNumber);
|
||||
mc->sequenceables_ = reinterpret_cast<MetaSequenceable**>(baseAddr_);
|
||||
// interfaces_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(MetaSequenceable*) * sequenceableNumber);
|
||||
mc->interfaces_ = reinterpret_cast<MetaInterface**>(baseAddr_);
|
||||
// types_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(MetaInterface*) * interfaceNumber);
|
||||
mc->types_ = reinterpret_cast<MetaType**>(baseAddr_);
|
||||
// stringPool_'s address
|
||||
baseAddr_ = baseAddr_ + sizeof(MetaType*) * typeNumber;
|
||||
mc->stringPool_ = reinterpret_cast<char*>(baseAddr_);
|
||||
// end address
|
||||
baseAddr_ = baseAddr_ + stringPool_.GetSize();
|
||||
(void)memcpy_s(mc->stringPool_, stringPool_.GetSize(), stringPool_.GetData(), stringPool_.GetSize());
|
||||
|
||||
mc->name_ = WriteString(module->GetName());
|
||||
|
||||
for (int i = 0; i < namespaceNumber; i++) {
|
||||
mc->namespaces_[i] = WriteMetaNamespace(module->GetNamespace(i));
|
||||
}
|
||||
|
||||
for (int i = 0; i < sequenceableNumber; i++) {
|
||||
mc->sequenceables_[i] = WriteMetaSequenceable(module->GetSequenceable(i));
|
||||
}
|
||||
|
||||
for (int i = 0; i < interfaceNumber; i++) {
|
||||
mc->interfaces_[i] = WriteMetaInterface(module->GetInterface(i));
|
||||
}
|
||||
|
||||
const ASTModule::TypeStringMap& types = module->GetTypes();
|
||||
int i = 0;
|
||||
for (const auto& pair : types) {
|
||||
mc->types_[i++] = WriteMetaType(pair.second);
|
||||
}
|
||||
}
|
||||
|
||||
MetaNamespace* MetadataBuilder::WriteMetaNamespace(ASTNamespace* nspace)
|
||||
{
|
||||
int sequenceableNumber = nspace->GetSequenceableNumber();
|
||||
int interfaceNumber = nspace->GetInterfaceNumber();
|
||||
int namespaceNumber = nspace->GetNamespaceNumber();
|
||||
|
||||
// begin address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
MetaNamespace* mn = reinterpret_cast<MetaNamespace*>(baseAddr_);
|
||||
mn->name_ = WriteString(nspace->GetName());
|
||||
mn->sequenceableNumber_ = sequenceableNumber;
|
||||
mn->interfaceNumber_ = interfaceNumber;
|
||||
mn->namespaceNumber_ = namespaceNumber;
|
||||
// sequenceables_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(MetaNamespace));
|
||||
mn->sequenceableIndexes_ = reinterpret_cast<int*>(baseAddr_);
|
||||
// interfaces_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(int) * sequenceableNumber);
|
||||
mn->interfaceIndexes_ = reinterpret_cast<int*>(baseAddr_);
|
||||
// namespaces_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(int) * interfaceNumber);
|
||||
mn->namespaces_ = reinterpret_cast<MetaNamespace**>(baseAddr_);
|
||||
// end address
|
||||
baseAddr_ = baseAddr_ + sizeof(MetaNamespace*) * namespaceNumber;
|
||||
|
||||
for (int i = 0; i < sequenceableNumber; i++) {
|
||||
AutoPtr<ASTSequenceableType> sequenceable = nspace->GetSequenceable(i);
|
||||
mn->sequenceableIndexes_[i] = module_->IndexOf(sequenceable);
|
||||
}
|
||||
|
||||
for (int i = 0; i < interfaceNumber; i++) {
|
||||
AutoPtr<ASTInterfaceType> interface = nspace->GetInterface(i);
|
||||
mn->interfaceIndexes_[i] = module_->IndexOf(interface);
|
||||
}
|
||||
|
||||
for (int i = 0; i < namespaceNumber; i++) {
|
||||
AutoPtr<ASTNamespace> inner = nspace->GetNamespace(i);
|
||||
mn->namespaces_[i] = WriteMetaNamespace(inner);
|
||||
}
|
||||
|
||||
return mn;
|
||||
}
|
||||
|
||||
MetaSequenceable* MetadataBuilder::WriteMetaSequenceable(ASTSequenceableType* parcelabe)
|
||||
{
|
||||
// begin address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
MetaSequenceable* mp = reinterpret_cast<MetaSequenceable*>(baseAddr_);
|
||||
mp->name_ = WriteString(parcelabe->GetName());
|
||||
mp->namespace_ = WriteString(parcelabe->GetNamespace()->ToString());
|
||||
// end address
|
||||
baseAddr_ = baseAddr_ + sizeof(MetaSequenceable);
|
||||
|
||||
return mp;
|
||||
}
|
||||
|
||||
MetaInterface* MetadataBuilder::WriteMetaInterface(ASTInterfaceType* interface)
|
||||
{
|
||||
int methodNumber = interface->GetMethodNumber();
|
||||
|
||||
// begin address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
MetaInterface* mi = reinterpret_cast<MetaInterface*>(baseAddr_);
|
||||
mi->license_ = WriteString(interface->GetLicense());
|
||||
mi->name_ = WriteString(interface->GetName());
|
||||
mi->namespace_ = WriteString(interface->GetNamespace()->ToString());
|
||||
mi->properties_ = interface->IsOneway() ? INTERFACE_PROPERTY_ONEWAY : 0;
|
||||
mi->methodNumber_ = methodNumber;
|
||||
mi->external_ = interface->IsExternal();
|
||||
// methods_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(MetaInterface));
|
||||
mi->methods_ = reinterpret_cast<MetaMethod**>(baseAddr_);
|
||||
// end address
|
||||
baseAddr_ = baseAddr_ + sizeof(MetaMethod*) * methodNumber;
|
||||
|
||||
for (int i = 0; i < methodNumber; i++) {
|
||||
mi->methods_[i] = WriteMetaMethod(interface->GetMethod(i));
|
||||
}
|
||||
|
||||
return mi;
|
||||
}
|
||||
|
||||
MetaMethod* MetadataBuilder::WriteMetaMethod(ASTMethod* method)
|
||||
{
|
||||
int parameterNumber = method->GetParameterNumber();
|
||||
|
||||
// begin address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
MetaMethod* mm = reinterpret_cast<MetaMethod*>(baseAddr_);
|
||||
mm->name_ = WriteString(method->GetName());
|
||||
mm->signature_ = WriteString(method->GetSignature());
|
||||
mm->properties_ = method->IsOneway() ? METHOD_PROPERTY_ONEWAY : 0;
|
||||
mm->returnTypeIndex_ = module_->IndexOf(method->GetReturnType());
|
||||
mm->parameterNumber_ = parameterNumber;
|
||||
// parameters_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_ + sizeof(MetaMethod));
|
||||
mm->parameters_ = reinterpret_cast<MetaParameter**>(baseAddr_);
|
||||
// end address
|
||||
baseAddr_ = baseAddr_ + sizeof(MetaParameter*) * parameterNumber;
|
||||
|
||||
for (int i = 0; i < parameterNumber; i++) {
|
||||
mm->parameters_[i] = WriteMetaParameter(method->GetParameter(i));
|
||||
}
|
||||
|
||||
return mm;
|
||||
}
|
||||
|
||||
MetaParameter* MetadataBuilder::WriteMetaParameter(ASTParameter* parameter)
|
||||
{
|
||||
// begin address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
MetaParameter* mp = reinterpret_cast<MetaParameter*>(baseAddr_);
|
||||
mp->name_ = WriteString(parameter->GetName());
|
||||
if (parameter->IsInParameter()) {
|
||||
mp->attributes_ |= ATTR_IN;
|
||||
}
|
||||
if (parameter->IsOutParameter()) {
|
||||
mp->attributes_ |= ATTR_OUT;
|
||||
}
|
||||
mp->typeIndex_ = module_->IndexOf(parameter->GetType());
|
||||
// end address
|
||||
baseAddr_ = baseAddr_ + sizeof(MetaParameter);
|
||||
|
||||
return mp;
|
||||
}
|
||||
|
||||
MetaType* MetadataBuilder::WriteMetaType(ASTType* type)
|
||||
{
|
||||
// begin address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
MetaType* mt = reinterpret_cast<MetaType*>(baseAddr_);
|
||||
mt->kind_ = Type2Kind(type);
|
||||
if (type->IsSequenceableType()) {
|
||||
mt->index_ = module_->IndexOf(static_cast<ASTSequenceableType*>(type));
|
||||
} else if (type->IsInterfaceType()) {
|
||||
mt->index_ = module_->IndexOf(static_cast<ASTInterfaceType*>(type));
|
||||
} else {
|
||||
mt->index_ = module_->IndexOf(type);
|
||||
}
|
||||
baseAddr_ = baseAddr_ + sizeof(MetaType);
|
||||
if (type->IsListType()) {
|
||||
mt->nestedTypeNumber_ = 1;
|
||||
// nestedTypeIndexes_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
mt->nestedTypeIndexes_ = reinterpret_cast<int*>(baseAddr_);
|
||||
AutoPtr<ASTType> elementType = (static_cast<ASTListType*>(type))->GetElementType();
|
||||
mt->nestedTypeIndexes_[0] = module_->IndexOf(elementType);
|
||||
// end address
|
||||
baseAddr_ = baseAddr_ + sizeof(int*);
|
||||
} else if (type->IsMapType()) {
|
||||
int typeNumber = 2;
|
||||
mt->nestedTypeNumber_ = typeNumber;
|
||||
// nestedTypeIndexes_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
mt->nestedTypeIndexes_ = reinterpret_cast<int*>(baseAddr_);
|
||||
AutoPtr<ASTType> keyType = (static_cast<ASTMapType*>(type))->GetKeyType();
|
||||
AutoPtr<ASTType> valueType = (static_cast<ASTMapType*>(type))->GetValueType();
|
||||
mt->nestedTypeIndexes_[0] = module_->IndexOf(keyType);
|
||||
mt->nestedTypeIndexes_[1] = module_->IndexOf(valueType);
|
||||
// end address
|
||||
baseAddr_ = baseAddr_ + sizeof(int*) * typeNumber;
|
||||
} else if (type->IsArrayType()) {
|
||||
mt->nestedTypeNumber_ = 1;
|
||||
// nestedTypeIndexes_'s address
|
||||
baseAddr_ = ALIGN8(baseAddr_);
|
||||
mt->nestedTypeIndexes_ = reinterpret_cast<int*>(baseAddr_);
|
||||
AutoPtr<ASTType> elementType = (static_cast<ASTArrayType*>(type))->GetElementType();
|
||||
mt->nestedTypeIndexes_[0] = module_->IndexOf(elementType);
|
||||
// end address
|
||||
baseAddr_ = baseAddr_ + sizeof(int*);
|
||||
}
|
||||
|
||||
return mt;
|
||||
}
|
||||
|
||||
char* MetadataBuilder::WriteString(const String& string)
|
||||
{
|
||||
return string.IsNull() ? nullptr : metaComponent_->stringPool_ + stringPool_.GetOffset(string);
|
||||
}
|
||||
|
||||
TypeKind MetadataBuilder::Type2Kind(ASTType* type)
|
||||
{
|
||||
if (type->IsCharType()) {
|
||||
return TypeKind::Char;
|
||||
} else if (type->IsBooleanType()) {
|
||||
return TypeKind::Boolean;
|
||||
} else if (type->IsByteType()) {
|
||||
return TypeKind::Byte;
|
||||
} else if (type->IsShortType()) {
|
||||
return TypeKind::Short;
|
||||
} else if (type->IsIntegerType()) {
|
||||
return TypeKind::Integer;
|
||||
} else if (type->IsLongType()) {
|
||||
return TypeKind::Long;
|
||||
} else if (type->IsFloatType()) {
|
||||
return TypeKind::Float;
|
||||
} else if (type->IsDoubleType()) {
|
||||
return TypeKind::Double;
|
||||
} else if (type->IsStringType()) {
|
||||
return TypeKind::String;
|
||||
} else if (type->IsVoidType()) {
|
||||
return TypeKind::Void;
|
||||
} else if (type->IsSequenceableType()) {
|
||||
return TypeKind::Sequenceable;
|
||||
} else if (type->IsInterfaceType()) {
|
||||
return TypeKind::Interface;
|
||||
} else if (type->IsListType()) {
|
||||
return TypeKind::List;
|
||||
} else if (type->IsMapType()) {
|
||||
return TypeKind::Map;
|
||||
} else if (type->IsArrayType()) {
|
||||
return TypeKind::Array;
|
||||
}
|
||||
return TypeKind::Unknown;
|
||||
}
|
||||
}
|
||||
}
|
87
metadata/metadata_builder.h
Normal file
87
metadata/metadata_builder.h
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_METADATABUILDER_H
|
||||
#define OHOS_IDL_METADATABUILDER_H
|
||||
|
||||
#include <memory>
|
||||
#include "ast/ast_module.h"
|
||||
#include "metadata/meta_component.h"
|
||||
#include "util/autoptr.h"
|
||||
#include "util/string.h"
|
||||
#include "util/string_pool.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class MetadataBuilder {
|
||||
public:
|
||||
explicit MetadataBuilder(ASTModule* module)
|
||||
: module_(module)
|
||||
{}
|
||||
|
||||
~MetadataBuilder() = default;
|
||||
|
||||
std::shared_ptr<MetaComponent> Build();
|
||||
|
||||
private:
|
||||
size_t CalculateMetadataSize();
|
||||
|
||||
void CalculateMetaComponent(ASTModule* module);
|
||||
|
||||
void CalculateMetaNamespace(ASTNamespace* nspace);
|
||||
|
||||
void CalculateMetaSequenceable(ASTSequenceableType* sequenceable);
|
||||
|
||||
void CalculateMetaInterface(ASTInterfaceType* interface);
|
||||
|
||||
void CalculateMetaMethod(ASTMethod* method);
|
||||
|
||||
void CalculateMetaParameter(ASTParameter* parameter);
|
||||
|
||||
void CalculateMetaType(ASTType* type);
|
||||
|
||||
void CalculateStringPool();
|
||||
|
||||
void WriteMetadata(uintptr_t base);
|
||||
|
||||
void WriteMetaComponent(ASTModule* module);
|
||||
|
||||
MetaNamespace* WriteMetaNamespace(ASTNamespace* nspace);
|
||||
|
||||
MetaSequenceable* WriteMetaSequenceable(ASTSequenceableType* parcelabe);
|
||||
|
||||
MetaInterface* WriteMetaInterface(ASTInterfaceType* interface);
|
||||
|
||||
MetaMethod* WriteMetaMethod(ASTMethod* method);
|
||||
|
||||
MetaParameter* WriteMetaParameter(ASTParameter* parameter);
|
||||
|
||||
MetaType* WriteMetaType(ASTType* type);
|
||||
|
||||
char* WriteString(const String& string);
|
||||
|
||||
TypeKind Type2Kind(ASTType* type);
|
||||
|
||||
static const char* TAG;
|
||||
AutoPtr<ASTModule> module_;
|
||||
std::shared_ptr<MetaComponent> metaComponent_;
|
||||
uintptr_t baseAddr_ = 0;
|
||||
size_t size_ = 0;
|
||||
StringPool stringPool_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_METADATABUILDER_H
|
275
metadata/metadata_dumper.cpp
Normal file
275
metadata/metadata_dumper.cpp
Normal file
@ -0,0 +1,275 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "metadata/metadata_dumper.h"
|
||||
#include "util/string_builder.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
const char* MetadataDumper::TAB = " ";
|
||||
void MetadataDumper::Dump(const String& prefix)
|
||||
{
|
||||
if (metaComponent_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
String dumpStr = DumpMetaComponent(metaComponent_, prefix);
|
||||
}
|
||||
|
||||
String MetadataDumper::DumpMetaComponent(MetaComponent* mc, const String& prefix)
|
||||
{
|
||||
StringBuilder sb;
|
||||
|
||||
sb.Append(prefix).Append("MetaComponent\n");
|
||||
sb.Append(prefix).Append("{\n");
|
||||
sb.Append(prefix + TAB).AppendFormat("\"magic_\" : \"0x%x\",\n", mc->magic_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"size_\" : \"%d\",\n", mc->size_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"name_\" : \"%s\",\n", mc->name_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"namespaceNumber_\" : \"%d\",\n", mc->namespaceNumber_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"sequenceableNumber_\" : \"%d\",\n", mc->sequenceableNumber_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"interfaceNumber_\" : \"%d\",\n", mc->interfaceNumber_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"typeNumber_\" : \"%d\",\n", mc->typeNumber_);
|
||||
|
||||
if (mc->namespaceNumber_ == 0) {
|
||||
sb.Append(prefix + TAB).Append("\"namespaces_\" : [],\n");
|
||||
} else {
|
||||
sb.Append(prefix + TAB).Append("\"namespaces_\" : [\n");
|
||||
for (int i = 0; i < mc->namespaceNumber_; i++) {
|
||||
DumpMetaNamespace(sb, mc->namespaces_[i], prefix + TAB + TAB);
|
||||
if (i != mc->namespaceNumber_ - 1) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n" + prefix + TAB).Append("],\n");
|
||||
}
|
||||
|
||||
if (mc->sequenceableNumber_ == 0) {
|
||||
sb.Append(prefix + TAB).Append("\"sequenceables_\" : [],\n");
|
||||
} else {
|
||||
sb.Append(prefix + TAB).Append("\"sequenceables_\" : [\n");
|
||||
for (int i = 0; i < mc->sequenceableNumber_; i++) {
|
||||
DumpMetaSequenceable(sb, mc->sequenceables_[i], prefix + TAB + TAB);
|
||||
if (i != mc->sequenceableNumber_ - 1) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n" + prefix + TAB).Append("],\n");
|
||||
}
|
||||
|
||||
if (mc->interfaceNumber_ == 0) {
|
||||
sb.Append(prefix + TAB).Append("\"interfaces_\" : [],\n");
|
||||
} else {
|
||||
sb.Append(prefix + TAB).Append("\"interfaces_\" : [\n");
|
||||
for (int i = 0; i < mc->interfaceNumber_; i++) {
|
||||
DumpMetaInterface(sb, mc->interfaces_[i], prefix + TAB + TAB);
|
||||
if (i != mc->interfaceNumber_ - 1) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n" + prefix + TAB).Append("],\n");
|
||||
}
|
||||
|
||||
sb.Append(prefix + TAB).AppendFormat("\"stringPoolSize_\" : \"%d\"\n", mc->stringPoolSize_);
|
||||
|
||||
sb.Append(prefix).Append("}\n");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
void MetadataDumper::DumpMetaNamespace(StringBuilder& sb, MetaNamespace* mn, const String& prefix)
|
||||
{
|
||||
sb.Append(prefix).Append("{\n");
|
||||
sb.Append(prefix + TAB).AppendFormat("\"name_\" : \"%s\",\n", mn->name_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"sequenceableNumber_\" : \"%d\",\n", mn->sequenceableNumber_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"interfaceNumber_\" : \"%d\",\n", mn->interfaceNumber_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"namespaceNumber_\" : \"%d\",\n", mn->namespaceNumber_);
|
||||
|
||||
if (mn->sequenceableNumber_ == 0) {
|
||||
sb.Append(prefix + TAB).Append("\"sequenceableIndexes_\" : [],\n");
|
||||
} else {
|
||||
sb.Append(prefix + TAB).Append("\"sequenceableIndexes_\" : [\n");
|
||||
for (int i = 0; i < mn->sequenceableNumber_; i++) {
|
||||
MetaSequenceable* mp = metaComponent_->sequenceables_[mn->sequenceableIndexes_[i]];
|
||||
sb.Append(prefix + TAB + TAB).AppendFormat("{ \"name\" : \"%s\" }", mp->name_);
|
||||
if (i != mn->sequenceableNumber_ - 1) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n" + prefix + TAB).Append("],\n");
|
||||
}
|
||||
|
||||
if (mn->interfaceNumber_ == 0) {
|
||||
sb.Append(prefix + TAB).Append("\"interfaceIndexes_\" : [],\n");
|
||||
} else {
|
||||
sb.Append(prefix + TAB).Append("\"interfaceIndexes_\" : [\n");
|
||||
for (int i = 0; i < mn->interfaceNumber_; i++) {
|
||||
MetaInterface* mi = metaComponent_->interfaces_[mn->interfaceIndexes_[i]];
|
||||
sb.Append(prefix + TAB + TAB).AppendFormat("{ \"name\" : \"%s\" }", mi->name_);
|
||||
if (i != mn->interfaceNumber_ - 1) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n" + prefix + TAB).Append("],\n");
|
||||
}
|
||||
|
||||
if (mn->namespaceNumber_ == 0) {
|
||||
sb.Append(prefix + TAB).Append("\"namespaces_\" : []\n");
|
||||
} else {
|
||||
sb.Append(prefix + TAB).Append("\"namespaces_\" : [\n");
|
||||
for (int i = 0; i < mn->namespaceNumber_; i++) {
|
||||
MetaNamespace* innermn = mn->namespaces_[i];
|
||||
DumpMetaNamespace(sb, innermn, prefix + TAB + TAB);
|
||||
if (i != mn->namespaceNumber_ - 1) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n" + prefix + TAB).Append("]\n");
|
||||
}
|
||||
|
||||
sb.Append(prefix).Append("}");
|
||||
}
|
||||
|
||||
void MetadataDumper::DumpMetaSequenceable(StringBuilder& sb, MetaSequenceable* mp, const String& prefix)
|
||||
{
|
||||
sb.Append(prefix).Append("{\n");
|
||||
sb.Append(prefix + TAB).AppendFormat("\"name_\" : \"%s\",\n", mp->name_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"namespace_\" : \"%s\"\n", mp->namespace_);
|
||||
sb.Append(prefix).Append("}");
|
||||
}
|
||||
|
||||
void MetadataDumper::DumpMetaInterface(StringBuilder& sb, MetaInterface* mi, const String& prefix)
|
||||
{
|
||||
sb.Append(prefix).Append("{\n");
|
||||
sb.Append(prefix + TAB).AppendFormat("\"name_\" : \"%s\",\n", mi->name_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"namespace_\" : \"%s\",\n", mi->namespace_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"properties_\" : \"%s\",\n",
|
||||
(mi->properties_ & INTERFACE_PROPERTY_ONEWAY) != 0 ? "oneway" : "");
|
||||
sb.Append(prefix + TAB).AppendFormat("\"methodNumber_\" : \"%d\",\n", mi->methodNumber_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"external_\" : \"%d\",\n", mi->external_);
|
||||
|
||||
if (mi->methodNumber_ == 0) {
|
||||
sb.Append(prefix + TAB).Append("\"methods_\" : []\n");
|
||||
} else {
|
||||
sb.Append(prefix + TAB).Append("\"methods_\" : [\n");
|
||||
for (int i = 0; i < mi->methodNumber_; i++) {
|
||||
DumpMetaMethod(sb, mi->methods_[i], prefix + TAB + TAB);
|
||||
if (i != mi->methodNumber_ - 1) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n" + prefix + TAB).Append("]\n");
|
||||
}
|
||||
|
||||
sb.Append(prefix).Append("}");
|
||||
}
|
||||
|
||||
void MetadataDumper::DumpMetaMethod(StringBuilder& sb, MetaMethod* mm, const String& prefix)
|
||||
{
|
||||
sb.Append(prefix).Append("{\n");
|
||||
sb.Append(prefix + TAB).AppendFormat("\"name_\" : \"%s\",\n", mm->name_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"signature_\" : \"%s\",\n", mm->signature_);
|
||||
sb.Append(prefix + TAB).AppendFormat("\"properties_\" : \"%s\",\n",
|
||||
(mm->properties_ & METHOD_PROPERTY_ONEWAY) != 0 ? "oneway" : "");
|
||||
MetaType* type = metaComponent_->types_[mm->returnTypeIndex_];
|
||||
sb.Append(prefix + TAB).AppendFormat("\"returnType_\" : \"%s\",\n", DumpMetaType(type).string());
|
||||
sb.Append(prefix + TAB).AppendFormat("\"parameterNumber_\" : \"%d\",\n", mm->parameterNumber_);
|
||||
|
||||
if (mm->parameterNumber_ == 0) {
|
||||
sb.Append(prefix + TAB).Append("\"parameters_\" : []\n");
|
||||
} else {
|
||||
sb.Append(prefix + TAB).Append("\"parameters_\" : [\n");
|
||||
for (int i = 0; i < mm->parameterNumber_; i++) {
|
||||
DumpMetaParameter(sb, mm->parameters_[i], prefix + TAB + TAB);
|
||||
if (i != mm->parameterNumber_ - 1) {
|
||||
sb.Append(",\n");
|
||||
}
|
||||
}
|
||||
sb.Append("\n" + prefix + TAB).Append("]\n");
|
||||
}
|
||||
|
||||
sb.Append(prefix).Append("}");
|
||||
}
|
||||
|
||||
void MetadataDumper::DumpMetaParameter(StringBuilder& sb, MetaParameter* mp, const String& prefix)
|
||||
{
|
||||
sb.Append(prefix).Append("{\n");
|
||||
sb.Append(prefix + TAB).AppendFormat("\"name_\" : \"%s\",\n", mp->name_);
|
||||
sb.Append(prefix + TAB).Append("\"attributes_\" : \"");
|
||||
bool addComma = false;
|
||||
if ((mp->attributes_ & ATTR_IN) == ATTR_IN) {
|
||||
sb.Append("in");
|
||||
addComma = true;
|
||||
}
|
||||
if ((mp->attributes_ & ATTR_OUT) == ATTR_OUT) {
|
||||
sb.Append(addComma ? ", out" : "out");
|
||||
}
|
||||
sb.Append("\",\n");
|
||||
MetaType* type = metaComponent_->types_[mp->typeIndex_];
|
||||
sb.Append(prefix + TAB).AppendFormat("\"type_\" : \"%s\"\n", DumpMetaType(type).string());
|
||||
|
||||
sb.Append(prefix).Append("}");
|
||||
}
|
||||
|
||||
String MetadataDumper::DumpMetaType(MetaType* mt)
|
||||
{
|
||||
switch (mt->kind_) {
|
||||
case TypeKind::Char:
|
||||
return "char";
|
||||
case TypeKind::Boolean:
|
||||
return "boolean";
|
||||
case TypeKind::Byte:
|
||||
return "byte";
|
||||
case TypeKind::Short:
|
||||
return "short";
|
||||
case TypeKind::Integer:
|
||||
return "int";
|
||||
case TypeKind::Long:
|
||||
return "long";
|
||||
case TypeKind::Float:
|
||||
return "float";
|
||||
case TypeKind::Double:
|
||||
return "double";
|
||||
case TypeKind::String:
|
||||
return "String";
|
||||
case TypeKind::Void:
|
||||
return "void";
|
||||
case TypeKind::Sequenceable: {
|
||||
MetaSequenceable* mp = metaComponent_->sequenceables_[mt->index_];
|
||||
return mp->name_;
|
||||
}
|
||||
case TypeKind::Interface: {
|
||||
MetaInterface* mi = metaComponent_->interfaces_[mt->index_];
|
||||
return mi->name_;
|
||||
}
|
||||
case TypeKind::List: {
|
||||
MetaType* elementMt = metaComponent_->types_[mt->nestedTypeIndexes_[0]];
|
||||
return "List<" + DumpMetaType(elementMt) + ">";
|
||||
}
|
||||
case TypeKind::Map: {
|
||||
MetaType* keyMt = metaComponent_->types_[mt->nestedTypeIndexes_[0]];
|
||||
MetaType* valueMt = metaComponent_->types_[mt->nestedTypeIndexes_[1]];
|
||||
return "Map<" + DumpMetaType(keyMt) + ", " + DumpMetaType(valueMt) + ">";
|
||||
}
|
||||
case TypeKind::Array: {
|
||||
MetaType* elementMt = metaComponent_->types_[mt->nestedTypeIndexes_[0]];
|
||||
return DumpMetaType(elementMt) + "[]";
|
||||
}
|
||||
case TypeKind::Unknown:
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
metadata/metadata_dumper.h
Normal file
56
metadata/metadata_dumper.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_METADATADUMPER_H
|
||||
#define OHOS_IDL_METADATADUMPER_H
|
||||
|
||||
#include "metadata/meta_component.h"
|
||||
#include "util/string.h"
|
||||
#include "util/string_builder.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class MetadataDumper {
|
||||
public:
|
||||
explicit MetadataDumper(MetaComponent* mc)
|
||||
: metaComponent_(mc)
|
||||
{}
|
||||
|
||||
~MetadataDumper() = default;
|
||||
|
||||
void Dump(const String& prefix);
|
||||
|
||||
private:
|
||||
String DumpMetaComponent(MetaComponent* mc, const String& prefix);
|
||||
|
||||
void DumpMetaNamespace(StringBuilder& sb, MetaNamespace* mn, const String& prefix);
|
||||
|
||||
void DumpMetaSequenceable(StringBuilder& sb, MetaSequenceable* mp, const String& prefix);
|
||||
|
||||
void DumpMetaInterface(StringBuilder& sb, MetaInterface* mi, const String& prefix);
|
||||
|
||||
void DumpMetaMethod(StringBuilder& sb, MetaMethod* mm, const String& prefix);
|
||||
|
||||
void DumpMetaParameter(StringBuilder& sb, MetaParameter* mp, const String& prefix);
|
||||
|
||||
String DumpMetaType(MetaType* mt);
|
||||
|
||||
static const char* TAB;
|
||||
MetaComponent* metaComponent_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_METADATADUMPER_H
|
76
metadata/metadata_reader.cpp
Normal file
76
metadata/metadata_reader.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "metadata/metadata_reader.h"
|
||||
#include "metadata/metadata_serializer.h"
|
||||
#include "util/file.h"
|
||||
#include "util/logger.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
const char* MetadataReader::TAG = "MetadataReader";
|
||||
|
||||
std::shared_ptr<MetaComponent> MetadataReader::ReadMetadataFromFile(const String& filePath)
|
||||
{
|
||||
File file(filePath, File::READ);
|
||||
if (!file.IsValid()) {
|
||||
Logger::E(TAG, "Open \"%s\" file failed.", filePath.string());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!file.Reset()) {
|
||||
Logger::E(TAG, "Reset \"%s\" file failed.", filePath.string());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MetaComponent header;
|
||||
|
||||
if (!file.ReadData((void*)&header, sizeof(MetaComponent))) {
|
||||
Logger::E(TAG, "Read \"%s\" file failed.", filePath.string());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (header.magic_ != METADATA_MAGIC_NUMBER || header.size_ < 0) {
|
||||
Logger::E(TAG, "The metadata in \"%s\" file is bad.", filePath.string());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!file.Reset()) {
|
||||
Logger::E(TAG, "Reset \"%s\" file failed.", filePath.string());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void* data = malloc(header.size_);
|
||||
if (data == nullptr) {
|
||||
Logger::E(TAG, "Malloc metadata failed.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!file.ReadData(data, header.size_)) {
|
||||
Logger::E(TAG, "Read \"%s\" file failed.", filePath.string());
|
||||
free(data);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<MetaComponent> metadata(
|
||||
(MetaComponent*)data, [](MetaComponent* p) { free(p); });
|
||||
|
||||
MetadataSerializer serializer((uintptr_t)data);
|
||||
serializer.Deserialize();
|
||||
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
}
|
35
metadata/metadata_reader.h
Normal file
35
metadata/metadata_reader.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_METADATAREADER_H
|
||||
#define OHOS_IDL_METADATAREADER_H
|
||||
|
||||
#include <memory>
|
||||
#include "metadata/meta_component.h"
|
||||
#include "util/string.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class MetadataReader {
|
||||
public:
|
||||
static std::shared_ptr<MetaComponent> ReadMetadataFromFile(const String& filePath);
|
||||
|
||||
private:
|
||||
static const char* TAG;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_METADATAREADER_H
|
224
metadata/metadata_serializer.cpp
Normal file
224
metadata/metadata_serializer.cpp
Normal file
@ -0,0 +1,224 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "metadata/metadata_serializer.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
void MetadataSerializer::Serialize()
|
||||
{
|
||||
SerializeMetaComponent(metaComponent_);
|
||||
}
|
||||
|
||||
void MetadataSerializer::SerializeMetaComponent(MetaComponent* mc)
|
||||
{
|
||||
mc->name_ = reinterpret_cast<char*>(SerializeAdjust(mc->name_));
|
||||
|
||||
for (int i = 0; i < mc->namespaceNumber_; i++) {
|
||||
MetaNamespace* mn = mc->namespaces_[i];
|
||||
SerializeMetaNamespace(mn);
|
||||
mc->namespaces_[i] = reinterpret_cast<MetaNamespace*>(SerializeAdjust(mn));
|
||||
}
|
||||
mc->namespaces_ = reinterpret_cast<MetaNamespace**>(SerializeAdjust(mc->namespaces_));
|
||||
|
||||
for (int i = 0; i < mc->sequenceableNumber_; i++) {
|
||||
MetaSequenceable* mp = mc->sequenceables_[i];
|
||||
SerializeMetaSequenceable(mp);
|
||||
mc->sequenceables_[i] = reinterpret_cast<MetaSequenceable*>(SerializeAdjust(mp));
|
||||
}
|
||||
mc->sequenceables_ = reinterpret_cast<MetaSequenceable**>(SerializeAdjust(mc->sequenceables_));
|
||||
|
||||
for (int i = 0; i < mc->interfaceNumber_; i++) {
|
||||
MetaInterface* mi = mc->interfaces_[i];
|
||||
SerializeMetaInterface(mi);
|
||||
mc->interfaces_[i] = reinterpret_cast<MetaInterface*>(SerializeAdjust(mi));
|
||||
}
|
||||
mc->interfaces_ = reinterpret_cast<MetaInterface**>(SerializeAdjust(mc->interfaces_));
|
||||
|
||||
for (int i = 0; i < mc->typeNumber_; i++) {
|
||||
MetaType* mt = mc->types_[i];
|
||||
SerializeMetaType(mt);
|
||||
mc->types_[i] = reinterpret_cast<MetaType*>(SerializeAdjust(mt));
|
||||
}
|
||||
mc->types_ = reinterpret_cast<MetaType**>(SerializeAdjust(mc->types_));
|
||||
|
||||
mc->stringPool_ = reinterpret_cast<char*>(SerializeAdjust(mc->stringPool_));
|
||||
}
|
||||
|
||||
void MetadataSerializer::SerializeMetaNamespace(MetaNamespace* mn)
|
||||
{
|
||||
mn->name_ = reinterpret_cast<char*>(SerializeAdjust(mn->name_));
|
||||
mn->sequenceableIndexes_ = reinterpret_cast<int*>(SerializeAdjust(mn->sequenceableIndexes_));
|
||||
mn->interfaceIndexes_ = reinterpret_cast<int*>(SerializeAdjust(mn->interfaceIndexes_));
|
||||
|
||||
for (int i = 0; i < mn->namespaceNumber_; i++) {
|
||||
MetaNamespace* innermn = mn->namespaces_[i];
|
||||
SerializeMetaNamespace(innermn);
|
||||
mn->namespaces_[i] = reinterpret_cast<MetaNamespace*>(SerializeAdjust(innermn));
|
||||
}
|
||||
mn->namespaces_ = reinterpret_cast<MetaNamespace**>(SerializeAdjust(mn->namespaces_));
|
||||
}
|
||||
|
||||
void MetadataSerializer::SerializeMetaSequenceable(MetaSequenceable* mp)
|
||||
{
|
||||
mp->name_ = reinterpret_cast<char*>(SerializeAdjust(mp->name_));
|
||||
mp->namespace_ = reinterpret_cast<char*>(SerializeAdjust(mp->namespace_));
|
||||
}
|
||||
|
||||
void MetadataSerializer::SerializeMetaInterface(MetaInterface* mi)
|
||||
{
|
||||
mi->license_ = reinterpret_cast<char*>(SerializeAdjust(mi->license_));
|
||||
mi->name_ = reinterpret_cast<char*>(SerializeAdjust(mi->name_));
|
||||
mi->namespace_ = reinterpret_cast<char*>(SerializeAdjust(mi->namespace_));
|
||||
|
||||
for (int i = 0; i < mi->methodNumber_; i++) {
|
||||
MetaMethod* mm = mi->methods_[i];
|
||||
SerializeMetaMethod(mm);
|
||||
mi->methods_[i] = reinterpret_cast<MetaMethod*>(SerializeAdjust(mm));
|
||||
}
|
||||
mi->methods_ = reinterpret_cast<MetaMethod**>(SerializeAdjust(mi->methods_));
|
||||
}
|
||||
|
||||
void MetadataSerializer::SerializeMetaMethod(MetaMethod* mm)
|
||||
{
|
||||
mm->name_ = reinterpret_cast<char*>(SerializeAdjust(mm->name_));
|
||||
mm->signature_ = reinterpret_cast<char*>(SerializeAdjust(mm->signature_));
|
||||
|
||||
for (int i = 0; i < mm->parameterNumber_; i++) {
|
||||
MetaParameter* mp = mm->parameters_[i];
|
||||
SerializeMetaParameter(mp);
|
||||
mm->parameters_[i] = reinterpret_cast<MetaParameter*>(SerializeAdjust(mp));
|
||||
}
|
||||
mm->parameters_ = reinterpret_cast<MetaParameter**>(SerializeAdjust(mm->parameters_));
|
||||
}
|
||||
|
||||
void MetadataSerializer::SerializeMetaParameter(MetaParameter* mp)
|
||||
{
|
||||
mp->name_ = reinterpret_cast<char*>(SerializeAdjust(mp->name_));
|
||||
}
|
||||
|
||||
void MetadataSerializer::SerializeMetaType(MetaType* mt)
|
||||
{
|
||||
mt->nestedTypeIndexes_ = reinterpret_cast<int*>(SerializeAdjust(mt->nestedTypeIndexes_));
|
||||
}
|
||||
|
||||
ptrdiff_t MetadataSerializer::SerializeAdjust(const void* addr)
|
||||
{
|
||||
return reinterpret_cast<uintptr_t>(addr) - baseAddr_;
|
||||
}
|
||||
|
||||
void MetadataSerializer::Deserialize()
|
||||
{
|
||||
DeserializeMetaComponent(metaComponent_);
|
||||
}
|
||||
|
||||
void MetadataSerializer::DeserializeMetaComponent(MetaComponent* mc)
|
||||
{
|
||||
mc->name_ = reinterpret_cast<char*>(DeserializeAdjust(mc->name_));
|
||||
|
||||
mc->namespaces_ = reinterpret_cast<MetaNamespace**>(DeserializeAdjust(mc->namespaces_));
|
||||
for (int i = 0; i < mc->namespaceNumber_; i++) {
|
||||
mc->namespaces_[i] = reinterpret_cast<MetaNamespace*>(DeserializeAdjust(mc->namespaces_[i]));
|
||||
MetaNamespace* mn = mc->namespaces_[i];
|
||||
DeserializeMetaNamespace(mn);
|
||||
}
|
||||
|
||||
mc->sequenceables_ = reinterpret_cast<MetaSequenceable**>(DeserializeAdjust(mc->sequenceables_));
|
||||
for (int i = 0; i < mc->sequenceableNumber_; i++) {
|
||||
mc->sequenceables_[i] = reinterpret_cast<MetaSequenceable*>(DeserializeAdjust(mc->sequenceables_[i]));
|
||||
MetaSequenceable* mp = mc->sequenceables_[i];
|
||||
DeserializeMetaSequenceable(mp);
|
||||
}
|
||||
|
||||
mc->interfaces_ = reinterpret_cast<MetaInterface**>(DeserializeAdjust(mc->interfaces_));
|
||||
for (int i = 0; i < mc->interfaceNumber_; i++) {
|
||||
mc->interfaces_[i] = reinterpret_cast<MetaInterface*>(DeserializeAdjust(mc->interfaces_[i]));
|
||||
MetaInterface* mi = mc->interfaces_[i];
|
||||
DeserializeMetaInterface(mi);
|
||||
}
|
||||
|
||||
mc->types_ = reinterpret_cast<MetaType**>(DeserializeAdjust(mc->types_));
|
||||
for (int i = 0; i < mc->typeNumber_; i++) {
|
||||
mc->types_[i] = reinterpret_cast<MetaType*>(DeserializeAdjust(mc->types_[i]));
|
||||
MetaType* mt = mc->types_[i];
|
||||
DeserializeMetaType(mt);
|
||||
}
|
||||
|
||||
mc->stringPool_ = reinterpret_cast<char*>(DeserializeAdjust(mc->stringPool_));
|
||||
}
|
||||
|
||||
void MetadataSerializer::DeserializeMetaNamespace(MetaNamespace* mn)
|
||||
{
|
||||
mn->name_ = reinterpret_cast<char*>(DeserializeAdjust(mn->name_));
|
||||
mn->sequenceableIndexes_ = reinterpret_cast<int*>(DeserializeAdjust(mn->sequenceableIndexes_));
|
||||
mn->interfaceIndexes_ = reinterpret_cast<int*>(DeserializeAdjust(mn->interfaceIndexes_));
|
||||
|
||||
mn->namespaces_ = reinterpret_cast<MetaNamespace**>(DeserializeAdjust(mn->namespaces_));
|
||||
for (int i = 0; i < mn->namespaceNumber_; i++) {
|
||||
mn->namespaces_[i] = reinterpret_cast<MetaNamespace*>(DeserializeAdjust(mn->namespaces_[i]));
|
||||
MetaNamespace* innermn = mn->namespaces_[i];
|
||||
DeserializeMetaNamespace(innermn);
|
||||
}
|
||||
}
|
||||
|
||||
void MetadataSerializer::DeserializeMetaSequenceable(MetaSequenceable* mp)
|
||||
{
|
||||
mp->name_ = reinterpret_cast<char*>(DeserializeAdjust(mp->name_));
|
||||
mp->namespace_ = reinterpret_cast<char*>(DeserializeAdjust(mp->namespace_));
|
||||
}
|
||||
|
||||
void MetadataSerializer::DeserializeMetaInterface(MetaInterface* mi)
|
||||
{
|
||||
mi->license_ = reinterpret_cast<char*>(DeserializeAdjust(mi->license_));
|
||||
mi->name_ = reinterpret_cast<char*>(DeserializeAdjust(mi->name_));
|
||||
mi->namespace_ = reinterpret_cast<char*>(DeserializeAdjust(mi->namespace_));
|
||||
|
||||
mi->methods_ = reinterpret_cast<MetaMethod**>(DeserializeAdjust(mi->methods_));
|
||||
for (int i = 0; i < mi->methodNumber_; i++) {
|
||||
mi->methods_[i] = reinterpret_cast<MetaMethod*>(DeserializeAdjust(mi->methods_[i]));
|
||||
MetaMethod* mm = mi->methods_[i];
|
||||
DeserializeMetaMethod(mm);
|
||||
}
|
||||
}
|
||||
|
||||
void MetadataSerializer::DeserializeMetaMethod(MetaMethod* mm)
|
||||
{
|
||||
mm->name_ = reinterpret_cast<char*>(DeserializeAdjust(mm->name_));
|
||||
mm->signature_ = reinterpret_cast<char*>(DeserializeAdjust(mm->signature_));
|
||||
|
||||
mm->parameters_ = reinterpret_cast<MetaParameter**>(DeserializeAdjust(mm->parameters_));
|
||||
for (int i = 0; i < mm->parameterNumber_; i++) {
|
||||
mm->parameters_[i] = reinterpret_cast<MetaParameter*>(DeserializeAdjust(mm->parameters_[i]));
|
||||
MetaParameter* mp = mm->parameters_[i];
|
||||
DeserializeMetaParameter(mp);
|
||||
}
|
||||
}
|
||||
|
||||
void MetadataSerializer::DeserializeMetaParameter(MetaParameter* mp)
|
||||
{
|
||||
mp->name_ = reinterpret_cast<char*>(DeserializeAdjust(mp->name_));
|
||||
}
|
||||
|
||||
void MetadataSerializer::DeserializeMetaType(MetaType* mt)
|
||||
{
|
||||
mt->nestedTypeIndexes_ = reinterpret_cast<int*>(DeserializeAdjust(mt->nestedTypeIndexes_));
|
||||
}
|
||||
|
||||
uintptr_t MetadataSerializer::DeserializeAdjust(const void* addr)
|
||||
{
|
||||
return reinterpret_cast<ptrdiff_t>(addr) + baseAddr_;
|
||||
}
|
||||
}
|
||||
}
|
92
metadata/metadata_serializer.h
Normal file
92
metadata/metadata_serializer.h
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_METADATASERIALIZER_H
|
||||
#define OHOS_IDL_METADATASERIALIZER_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include "metadata/meta_component.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class MetadataSerializer {
|
||||
public:
|
||||
explicit MetadataSerializer(MetaComponent* mc)
|
||||
: metaComponent_(mc),
|
||||
baseAddr_(reinterpret_cast<uintptr_t>(mc))
|
||||
{}
|
||||
|
||||
explicit MetadataSerializer(uintptr_t addr)
|
||||
: metaComponent_(reinterpret_cast<MetaComponent*>(addr)),
|
||||
baseAddr_(addr)
|
||||
{}
|
||||
|
||||
~MetadataSerializer() = default;
|
||||
|
||||
void Serialize();
|
||||
|
||||
void Deserialize();
|
||||
|
||||
uintptr_t GetData() const
|
||||
{
|
||||
return baseAddr_;
|
||||
}
|
||||
|
||||
int GetDataSize() const
|
||||
{
|
||||
return metaComponent_->size_;
|
||||
}
|
||||
|
||||
private:
|
||||
void SerializeMetaComponent(MetaComponent* mc);
|
||||
|
||||
void SerializeMetaNamespace(MetaNamespace* mn);
|
||||
|
||||
void SerializeMetaSequenceable(MetaSequenceable* mp);
|
||||
|
||||
void SerializeMetaInterface(MetaInterface* mi);
|
||||
|
||||
void SerializeMetaMethod(MetaMethod* mm);
|
||||
|
||||
void SerializeMetaParameter(MetaParameter* mp);
|
||||
|
||||
void SerializeMetaType(MetaType* mt);
|
||||
|
||||
ptrdiff_t SerializeAdjust(const void* addr);
|
||||
|
||||
void DeserializeMetaComponent(MetaComponent* mc);
|
||||
|
||||
void DeserializeMetaNamespace(MetaNamespace* mn);
|
||||
|
||||
void DeserializeMetaSequenceable(MetaSequenceable* mp);
|
||||
|
||||
void DeserializeMetaInterface(MetaInterface* mi);
|
||||
|
||||
void DeserializeMetaMethod(MetaMethod* mm);
|
||||
|
||||
void DeserializeMetaParameter(MetaParameter* mp);
|
||||
|
||||
void DeserializeMetaType(MetaType* mt);
|
||||
|
||||
uintptr_t DeserializeAdjust(const void* addr);
|
||||
|
||||
MetaComponent* metaComponent_;
|
||||
uintptr_t baseAddr_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_METADATASERIALIZER_H
|
372
parser/lexer.cpp
Normal file
372
parser/lexer.cpp
Normal file
@ -0,0 +1,372 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "parser/lexer.h"
|
||||
|
||||
#include <utility>
|
||||
#include "util/string_builder.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
static struct Keywords {
|
||||
String key_;
|
||||
Token token_;
|
||||
} g_keywords[] = {
|
||||
{String("boolean"), Token::BOOLEAN},
|
||||
{String("byte"), Token::BYTE},
|
||||
{String("char"), Token::CHAR},
|
||||
{String("double"), Token::DOUBLE},
|
||||
{String("float"), Token::FLOAT},
|
||||
{String("in"), Token::IN},
|
||||
{String("inout"), Token::INOUT},
|
||||
{String("int"), Token::INTEGER},
|
||||
{String("interface"), Token::INTERFACE},
|
||||
{String("List"), Token::LIST},
|
||||
{String("long"), Token::LONG},
|
||||
{String("Map"), Token::MAP},
|
||||
{String("oneway"), Token::ONEWAY},
|
||||
{String("out"), Token::OUT},
|
||||
{String("sequenceable"), Token::SEQUENCEABLE},
|
||||
{String("short"), Token::SHORT},
|
||||
{String("String"), Token::STRING},
|
||||
};
|
||||
|
||||
Lexer::Lexer()
|
||||
{
|
||||
InitializeKeywords();
|
||||
}
|
||||
|
||||
Lexer::~Lexer()
|
||||
{
|
||||
if (currentFile_ != nullptr) {
|
||||
currentFile_->Close();
|
||||
}
|
||||
}
|
||||
|
||||
void Lexer::InitializeKeywords()
|
||||
{
|
||||
for (size_t i = 0; i < sizeof(g_keywords) / sizeof(struct Keywords); i++) {
|
||||
keywords_[g_keywords[i].key_] = g_keywords[i].token_;
|
||||
}
|
||||
}
|
||||
|
||||
bool Lexer::OpenSourceFile(const String& filePath)
|
||||
{
|
||||
currentFile_ = std::make_shared<File>(filePath, File::READ);
|
||||
if (!currentFile_->IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Token Lexer::GetToken(bool skipComment)
|
||||
{
|
||||
if (!havePeek_) {
|
||||
currentToken_ = ReadToken(skipComment);
|
||||
}
|
||||
havePeek_ = false;
|
||||
return currentToken_;
|
||||
}
|
||||
|
||||
Token Lexer::PeekToken(bool skipComment)
|
||||
{
|
||||
if (!havePeek_) {
|
||||
currentToken_ = ReadToken(skipComment);
|
||||
havePeek_ = true;
|
||||
}
|
||||
return currentToken_;
|
||||
}
|
||||
|
||||
Token Lexer::ReadToken(bool skipComment)
|
||||
{
|
||||
while (!currentFile_->IsEof()) {
|
||||
char c = currentFile_->GetChar();
|
||||
tokenLineNo_ = currentFile_->GetCharLineNumber();
|
||||
tokenColumnNo_ = currentFile_->GetCharColumnNumber();
|
||||
if (IsSpace(c)) {
|
||||
continue;
|
||||
} else if (IsAlphabet(c) || c == '_') {
|
||||
return ReadIdentifier(c);
|
||||
}
|
||||
switch (c) {
|
||||
case '<':
|
||||
currentToken_ = Token::ANGLE_BRACKETS_LEFT;
|
||||
return currentToken_;
|
||||
case '>':
|
||||
currentToken_ = Token::ANGLE_BRACKETS_RIGHT;
|
||||
return currentToken_;
|
||||
case '{':
|
||||
currentToken_ = Token::BRACES_LEFT;
|
||||
return currentToken_;
|
||||
case '}':
|
||||
currentToken_ = Token::BRACES_RIGHT;
|
||||
return currentToken_;
|
||||
case '[':
|
||||
currentToken_ = Token::BRACKETS_LEFT;
|
||||
return currentToken_;
|
||||
case ']':
|
||||
currentToken_ = Token::BRACKETS_RIGHT;
|
||||
return currentToken_;
|
||||
case ',':
|
||||
currentToken_ = Token::COMMA;
|
||||
return currentToken_;
|
||||
case '/':
|
||||
if (currentFile_->PeekChar() == '/') {
|
||||
ReadLineComment(c);
|
||||
if (!skipComment) {
|
||||
return currentToken_;
|
||||
}
|
||||
continue;
|
||||
} else if (currentFile_->PeekChar() == '*') {
|
||||
ReadBlockComment(c);
|
||||
if (!skipComment) {
|
||||
return currentToken_;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
currentToken_ = Token::UNKNOWN;
|
||||
return currentToken_;
|
||||
case '(':
|
||||
currentToken_ = Token::PARENTHESES_LEFT;
|
||||
return currentToken_;
|
||||
case ')':
|
||||
currentToken_ = Token::PARENTHESES_RIGHT;
|
||||
return currentToken_;
|
||||
case '.':
|
||||
currentToken_ = Token::DOT;
|
||||
return currentToken_;
|
||||
case ';':
|
||||
currentToken_ = Token::SEMICOLON;
|
||||
return currentToken_;
|
||||
default:
|
||||
currentToken_ = Token::UNKNOWN;
|
||||
return currentToken_;
|
||||
}
|
||||
}
|
||||
currentToken_ = Token::END_OF_FILE;
|
||||
return currentToken_;
|
||||
}
|
||||
|
||||
Token Lexer::ReadIdentifier(char c)
|
||||
{
|
||||
StringBuilder sb;
|
||||
|
||||
sb.Append(c);
|
||||
while (!currentFile_->IsEof()) {
|
||||
c = currentFile_->PeekChar();
|
||||
if (IsAlphabet(c) || c == '_' || IsDecimalDigital(c) || c == '.') {
|
||||
c = currentFile_->GetChar();
|
||||
sb.Append(c);
|
||||
continue;
|
||||
}
|
||||
if (IsSpace(c)) {
|
||||
currentFile_->GetChar();
|
||||
}
|
||||
break;
|
||||
}
|
||||
String key = sb.ToString();
|
||||
auto it = keywords_.find(key);
|
||||
if (it == keywords_.end()) {
|
||||
identifier_ = key;
|
||||
currentToken_ = Token::IDENTIFIER;
|
||||
} else {
|
||||
currentToken_ = it->second;
|
||||
}
|
||||
return currentToken_;
|
||||
}
|
||||
|
||||
Token Lexer::ReadLineComment(char c)
|
||||
{
|
||||
StringBuilder sb;
|
||||
|
||||
sb.Append(c);
|
||||
while (!currentFile_->IsEof()) {
|
||||
c = currentFile_->GetChar();
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
sb.Append(c);
|
||||
}
|
||||
comment_ = sb.ToString();
|
||||
currentToken_ = Token::COMMENT_LINE;
|
||||
return currentToken_;
|
||||
}
|
||||
|
||||
Token Lexer::ReadBlockComment(char c)
|
||||
{
|
||||
StringBuilder sb;
|
||||
|
||||
sb.Append(c);
|
||||
while (!currentFile_->IsEof()) {
|
||||
c = currentFile_->GetChar();
|
||||
sb.Append(c);
|
||||
if (c == '*' && currentFile_->PeekChar() == '/') {
|
||||
c = currentFile_->GetChar();
|
||||
sb.Append(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
comment_ = sb.ToString();
|
||||
currentToken_ = Token::COMMENT_BLOCK;
|
||||
return currentToken_;
|
||||
}
|
||||
|
||||
void Lexer::SkipCurrentLine()
|
||||
{
|
||||
while (!currentFile_->IsEof()) {
|
||||
char c = currentFile_->GetChar();
|
||||
if (c == '\n') {
|
||||
currentFile_->GetChar();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Lexer::SkipCurrentLine(char untilChar)
|
||||
{
|
||||
while (!currentFile_->IsEof()) {
|
||||
int c = currentFile_->GetChar();
|
||||
if (c == untilChar) {
|
||||
return true;
|
||||
}
|
||||
if (c == '\n') {
|
||||
currentFile_->GetChar();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int Lexer::TokenToChar(Token token)
|
||||
{
|
||||
switch (token) {
|
||||
case Token::ANGLE_BRACKETS_LEFT:
|
||||
return '<';
|
||||
case Token::ANGLE_BRACKETS_RIGHT:
|
||||
return '>';
|
||||
case Token::BRACES_LEFT:
|
||||
return '{';
|
||||
case Token::BRACES_RIGHT:
|
||||
return '}';
|
||||
case Token::BRACKETS_LEFT:
|
||||
return '[';
|
||||
case Token::BRACKETS_RIGHT:
|
||||
return ']';
|
||||
case Token::COMMA:
|
||||
return ',';
|
||||
case Token::DOT:
|
||||
return '.';
|
||||
case Token::PARENTHESES_LEFT:
|
||||
return '(';
|
||||
case Token::PARENTHESES_RIGHT:
|
||||
return ')';
|
||||
case Token::SEMICOLON:
|
||||
return ';';
|
||||
case Token::BOOLEAN:
|
||||
case Token::BYTE:
|
||||
case Token::CHAR:
|
||||
case Token::COMMENT_BLOCK:
|
||||
case Token::COMMENT_LINE:
|
||||
case Token::DOUBLE:
|
||||
case Token::END_OF_FILE:
|
||||
case Token::FLOAT:
|
||||
case Token::IDENTIFIER:
|
||||
case Token::IN:
|
||||
case Token::INOUT:
|
||||
case Token::INTEGER:
|
||||
case Token::LIST:
|
||||
case Token::LONG:
|
||||
case Token::MAP:
|
||||
case Token::ONEWAY:
|
||||
case Token::OUT:
|
||||
case Token::SEQUENCEABLE:
|
||||
case Token::SHORT:
|
||||
case Token::STRING:
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
String Lexer::DumpToken() const
|
||||
{
|
||||
switch (currentToken_) {
|
||||
case Token::ANGLE_BRACKETS_LEFT:
|
||||
return "<";
|
||||
case Token::ANGLE_BRACKETS_RIGHT:
|
||||
return ">";
|
||||
case Token::BOOLEAN:
|
||||
return "boolean";
|
||||
case Token::BRACES_LEFT:
|
||||
return "{";
|
||||
case Token::BRACES_RIGHT:
|
||||
return "}";
|
||||
case Token::BRACKETS_LEFT:
|
||||
return "[";
|
||||
case Token::BRACKETS_RIGHT:
|
||||
return "]";
|
||||
case Token::BYTE:
|
||||
return "byte";
|
||||
case Token::CHAR:
|
||||
return "char";
|
||||
case Token::COMMA:
|
||||
return ",";
|
||||
case Token::COMMENT_BLOCK:
|
||||
case Token::COMMENT_LINE:
|
||||
return comment_;
|
||||
case Token::DOT:
|
||||
return ".";
|
||||
case Token::DOUBLE:
|
||||
return "double";
|
||||
case Token::END_OF_FILE:
|
||||
return "eof";
|
||||
case Token::FLOAT:
|
||||
return "float";
|
||||
case Token::IDENTIFIER:
|
||||
return identifier_;
|
||||
case Token::IN:
|
||||
return "in";
|
||||
case Token::INOUT:
|
||||
return "inout";
|
||||
case Token::INTEGER:
|
||||
return "int";
|
||||
case Token::LIST:
|
||||
return "List";
|
||||
case Token::LONG:
|
||||
return "long";
|
||||
case Token::MAP:
|
||||
return "Map";
|
||||
case Token::ONEWAY:
|
||||
return "oneway";
|
||||
case Token::OUT:
|
||||
return "out";
|
||||
case Token::SEQUENCEABLE:
|
||||
return "sequenceable";
|
||||
case Token::PARENTHESES_LEFT:
|
||||
return "(";
|
||||
case Token::PARENTHESES_RIGHT:
|
||||
return ")";
|
||||
case Token::SEMICOLON:
|
||||
return ";";
|
||||
case Token::SHORT:
|
||||
return "short";
|
||||
case Token::STRING:
|
||||
return "String";
|
||||
default:
|
||||
return "unknown token";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
113
parser/lexer.h
Normal file
113
parser/lexer.h
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_LEXER_H
|
||||
#define OHOS_IDL_LEXER_H
|
||||
|
||||
#include <ctype.h>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "parser/token.h"
|
||||
#include "util/file.h"
|
||||
#include "util/string.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class Lexer {
|
||||
public:
|
||||
Lexer();
|
||||
|
||||
~Lexer();
|
||||
|
||||
bool OpenSourceFile(const String& filePath);
|
||||
|
||||
Token GetToken(bool skipComment = true);
|
||||
|
||||
Token PeekToken(bool skipComment = true);
|
||||
|
||||
String GetIdentifier() const
|
||||
{
|
||||
return identifier_;
|
||||
}
|
||||
|
||||
String GetComment() const
|
||||
{
|
||||
return comment_;
|
||||
}
|
||||
|
||||
void SkipCurrentLine();
|
||||
|
||||
bool SkipCurrentLine(char untilChar);
|
||||
|
||||
std::shared_ptr<File> GetSourceFile() const
|
||||
{
|
||||
return currentFile_;
|
||||
}
|
||||
|
||||
String DumpToken() const;
|
||||
|
||||
int GetTokenLineNumber() const
|
||||
{
|
||||
return tokenLineNo_;
|
||||
}
|
||||
|
||||
int GetTokenColumnNumber() const
|
||||
{
|
||||
return tokenColumnNo_;
|
||||
}
|
||||
|
||||
static int TokenToChar(Token token);
|
||||
|
||||
private:
|
||||
void InitializeKeywords();
|
||||
|
||||
Token ReadToken(bool skipComment);
|
||||
|
||||
Token ReadIdentifier(char c);
|
||||
|
||||
Token ReadLineComment(char c);
|
||||
|
||||
Token ReadBlockComment(char c);
|
||||
|
||||
static bool IsAlphabet(char c)
|
||||
{
|
||||
return isalpha(c);
|
||||
}
|
||||
|
||||
static bool IsDecimalDigital(char c)
|
||||
{
|
||||
return isdigit(c);
|
||||
}
|
||||
|
||||
static bool IsSpace(char c)
|
||||
{
|
||||
return isspace(c);
|
||||
}
|
||||
|
||||
static const char* TAG;
|
||||
std::unordered_map<String, Token, StringHashFunc, StringEqualFunc> keywords_;
|
||||
Token currentToken_ = Token::UNKNOWN;
|
||||
int tokenLineNo_ = 0;
|
||||
int tokenColumnNo_ = 0;
|
||||
String identifier_;
|
||||
String comment_;
|
||||
bool havePeek_ = false;
|
||||
std::shared_ptr<File> currentFile_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_LEXER_H
|
705
parser/parser.cpp
Normal file
705
parser/parser.cpp
Normal file
@ -0,0 +1,705 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "parser/parser.h"
|
||||
#include <cstdio>
|
||||
#include "ast/ast_array_type.h"
|
||||
#include "ast/ast_list_type.h"
|
||||
#include "ast/ast_map_type.h"
|
||||
#include "ast/ast_parameter.h"
|
||||
#include "ast/ast_sequenceable_type.h"
|
||||
#include "util/logger.h"
|
||||
#include "util/string_builder.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
const char* Parser::TAG = "Parser";
|
||||
|
||||
Parser::Parser(const Options& options)
|
||||
: options_(options)
|
||||
{}
|
||||
|
||||
bool Parser::Parse(const String& sourceFile)
|
||||
{
|
||||
bool ret = lexer_.OpenSourceFile(sourceFile);
|
||||
if (!ret) {
|
||||
Logger::E(TAG, "Fail to open file \"%s\".", sourceFile.string());
|
||||
return false;
|
||||
}
|
||||
ret = ParseFile();
|
||||
ret = CheckIntegrity() && ret;
|
||||
if (!ret) {
|
||||
ShowError();
|
||||
return false;
|
||||
}
|
||||
if (options_.DoDumpAST()) {
|
||||
String astStr = module_->Dump("");
|
||||
printf("%s\n", astStr.string());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Parser::ParseFile()
|
||||
{
|
||||
bool ret = true;
|
||||
|
||||
module_ = new ASTModule();
|
||||
module_->SetIdlFile(lexer_.GetSourceFile()->GetPath());
|
||||
|
||||
ParseLicense();
|
||||
|
||||
Token token;
|
||||
while ((token = lexer_.PeekToken()) != Token::END_OF_FILE) {
|
||||
switch (token) {
|
||||
case Token::BRACKETS_LEFT:
|
||||
case Token::INTERFACE:
|
||||
ret = ParseInterface() && ret;
|
||||
continue;
|
||||
case Token::SEQUENCEABLE:
|
||||
ret = ParseSequenceable() && ret;
|
||||
continue;
|
||||
case Token::COMMENT_LINE:
|
||||
lexer_.GetToken();
|
||||
continue;
|
||||
default:
|
||||
LogError(token, String::Format("%s is not expected.", lexer_.DumpToken().string()));
|
||||
lexer_.GetToken();
|
||||
ret = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
lexer_.GetToken();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Parser::ParseLicense()
|
||||
{
|
||||
Token token = lexer_.PeekToken(false);
|
||||
if (token != Token::COMMENT_BLOCK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
lexer_.GetToken(false);
|
||||
|
||||
module_->SetLicense(lexer_.GetComment());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Parser::ParseInterface()
|
||||
{
|
||||
bool ret = true;
|
||||
bool hasProperties = false;
|
||||
bool oneway = false;
|
||||
Token token = lexer_.GetToken();
|
||||
if (token == Token::BRACKETS_LEFT) {
|
||||
token = lexer_.PeekToken();
|
||||
if (token != Token::ONEWAY) {
|
||||
LogError(Token::IDENTIFIER,
|
||||
String::Format("\"%s\" is an illegal interface property.", lexer_.DumpToken().string()));
|
||||
if (token != Token::BRACKETS_RIGHT) {
|
||||
lexer_.SkipCurrentLine(Lexer::TokenToChar(Token::BRACKETS_RIGHT));
|
||||
}
|
||||
ret = false;
|
||||
}
|
||||
lexer_.GetToken();
|
||||
oneway = true;
|
||||
hasProperties = true;
|
||||
token = lexer_.PeekToken();
|
||||
if (token != Token::BRACKETS_RIGHT) {
|
||||
LogError(Token::IDENTIFIER, String("\"]\" is expected."));
|
||||
while (token != Token::BRACKETS_RIGHT && token != Token::INTERFACE && token != Token::END_OF_FILE) {
|
||||
lexer_.GetToken();
|
||||
token = lexer_.PeekToken();
|
||||
}
|
||||
ret = false;
|
||||
} else {
|
||||
lexer_.GetToken();
|
||||
}
|
||||
|
||||
token = lexer_.PeekToken();
|
||||
if (token != Token::INTERFACE) {
|
||||
LogError(Token::IDENTIFIER, String("\"interface\" is expected."));
|
||||
ret = false;
|
||||
} else {
|
||||
lexer_.GetToken();
|
||||
}
|
||||
}
|
||||
String interfaceFullName;
|
||||
token = lexer_.PeekToken();
|
||||
if (token != Token::IDENTIFIER) {
|
||||
LogError(token, String::Format("%s is not expected.", lexer_.DumpToken().string()));
|
||||
lexer_.SkipCurrentLine();
|
||||
return false;
|
||||
} else {
|
||||
lexer_.GetToken();
|
||||
interfaceFullName = lexer_.GetIdentifier();
|
||||
token = lexer_.PeekToken();
|
||||
}
|
||||
if (token != Token::SEMICOLON && token != Token::BRACES_LEFT) {
|
||||
LogError(token, String::Format("%s is not expected.", lexer_.DumpToken().string()));
|
||||
lexer_.SkipCurrentLine();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (interfaceFullName.IsEmpty()) {
|
||||
LogError(Token::IDENTIFIER, String("Interface name is expected."));
|
||||
return false;
|
||||
} else if (!IsValidTypeName(interfaceFullName)) {
|
||||
LogError(Token::IDENTIFIER, String::Format("Interface name \"%s\" is illegal.", interfaceFullName.string()));
|
||||
return false;
|
||||
} else if (interfaceFullName.IndexOf(".") == -1) {
|
||||
if (!(options_.GetTargetLanguage().Equals("ts"))) {
|
||||
LogError(Token::IDENTIFIER, String::Format("Interface name \"%s\" does not have namespace.",
|
||||
interfaceFullName.string()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
AutoPtr<ASTInterfaceType> interface = new ASTInterfaceType();
|
||||
parsingInterface_ = interface;
|
||||
int index = interfaceFullName.LastIndexOf('.');
|
||||
if (index != -1) {
|
||||
interface->SetName(interfaceFullName.Substring(index + 1));
|
||||
interface->SetNamespace(module_->ParseNamespace(interfaceFullName.Substring(0, index + 1)));
|
||||
} else {
|
||||
interface->SetName(interfaceFullName);
|
||||
interface->SetNamespace(NameSpaceEmpty());
|
||||
}
|
||||
|
||||
// read ';'
|
||||
lexer_.GetToken();
|
||||
if (token == Token::SEMICOLON) {
|
||||
if (hasProperties) {
|
||||
LogError(Token::IDENTIFIER, String("Interface forward declaration should not have properties."));
|
||||
return false;
|
||||
}
|
||||
interface->SetExternal(true);
|
||||
module_->AddInterface(interface);
|
||||
return true;
|
||||
} else {
|
||||
if (!interface->GetName().Equals(module_->GetName())) {
|
||||
LogError(Token::IDENTIFIER, String::Format("Module name \"%s\" is not equal to interface name \"%s\".",
|
||||
module_->GetName().string(), interface->GetName().string()));
|
||||
return false;
|
||||
}
|
||||
|
||||
interface->SetLicense(module_->GetLicense());
|
||||
interface->SetOneway(oneway);
|
||||
|
||||
while (token != Token::BRACES_RIGHT && token != Token::END_OF_FILE) {
|
||||
ret = ParseMethod(interface) && ret;
|
||||
token = lexer_.PeekToken();
|
||||
}
|
||||
|
||||
if (token != Token::BRACES_RIGHT) {
|
||||
ret = false;
|
||||
} else {
|
||||
lexer_.GetToken();
|
||||
module_->AddInterface(interface);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
bool Parser::ParseMethod(ASTInterfaceType* interface)
|
||||
{
|
||||
bool ret = true;
|
||||
bool oneway = false;
|
||||
Token token;
|
||||
|
||||
token = lexer_.PeekToken();
|
||||
if (token == Token::BRACKETS_LEFT) {
|
||||
lexer_.GetToken();
|
||||
token = lexer_.PeekToken();
|
||||
if (token != Token::ONEWAY) {
|
||||
LogError(Token::IDENTIFIER, String::Format("\"%s\" is an illegal method property.",
|
||||
lexer_.DumpToken().string()));
|
||||
|
||||
if (token != Token::BRACKETS_RIGHT) {
|
||||
lexer_.SkipCurrentLine(Lexer::TokenToChar(Token::BRACKETS_RIGHT));
|
||||
}
|
||||
ret = false;
|
||||
}
|
||||
lexer_.GetToken();
|
||||
|
||||
oneway = true;
|
||||
|
||||
token = lexer_.PeekToken();
|
||||
if (token != Token::BRACKETS_RIGHT) {
|
||||
LogError(Token::IDENTIFIER, String("\"]\" is expected."));
|
||||
ret = false;
|
||||
} else {
|
||||
lexer_.GetToken();
|
||||
}
|
||||
}
|
||||
AutoPtr<ASTType> type = ParseType();
|
||||
if (type == nullptr) {
|
||||
token = lexer_.PeekToken();
|
||||
if (token != Token::BRACES_RIGHT) {
|
||||
// jump over colon
|
||||
lexer_.GetToken();
|
||||
while (token != Token::SEMICOLON && token != Token::END_OF_FILE) {
|
||||
token = lexer_.PeekToken();
|
||||
if (token == Token::BRACES_RIGHT) {
|
||||
break;
|
||||
}
|
||||
lexer_.GetToken();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (interface->IsOneway()) {
|
||||
if (!type->IsVoidType()) {
|
||||
LogError(token, String("void return type expected in oneway interface."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
token = lexer_.PeekToken();
|
||||
if (token != Token::IDENTIFIER) {
|
||||
LogError(token, String("Method name is expected."));
|
||||
if (token != Token::BRACES_RIGHT) {
|
||||
// jump over colon
|
||||
lexer_.GetToken();
|
||||
while (token != Token::SEMICOLON && token != Token::END_OF_FILE) {
|
||||
token = lexer_.PeekToken();
|
||||
if (token == Token::BRACES_RIGHT) {
|
||||
break;
|
||||
}
|
||||
lexer_.GetToken();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
token = lexer_.GetToken();
|
||||
|
||||
AutoPtr<ASTMethod> method = new ASTMethod();
|
||||
method->SetName(lexer_.GetIdentifier());
|
||||
method->SetOneway(oneway);
|
||||
method->SetReturnType(type);
|
||||
if (method->IsOneway()) {
|
||||
if (!method->GetReturnType()->IsVoidType()) {
|
||||
LogError(token, String("void return type expected in oneway method."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
token = lexer_.PeekToken();
|
||||
if (token != Token::PARENTHESES_LEFT) {
|
||||
LogError(token, String("\"(\" is expected."));
|
||||
if (token != Token::BRACES_RIGHT) {
|
||||
// jump over colon
|
||||
lexer_.GetToken();
|
||||
while (token != Token::SEMICOLON && token != Token::END_OF_FILE) {
|
||||
token = lexer_.PeekToken();
|
||||
if (token == Token::BRACES_RIGHT) {
|
||||
break;
|
||||
}
|
||||
lexer_.GetToken();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
token = lexer_.GetToken();
|
||||
|
||||
token = lexer_.PeekToken();
|
||||
while (token != Token::PARENTHESES_RIGHT && token != Token::END_OF_FILE) {
|
||||
ret = ParseParameter(method) && ret;
|
||||
token = lexer_.PeekToken();
|
||||
if (token == Token::COMMA) {
|
||||
lexer_.GetToken();
|
||||
token = lexer_.PeekToken();
|
||||
}
|
||||
}
|
||||
|
||||
if (interface->IsOneway() || method->IsOneway()) {
|
||||
for (size_t i = 0; i< method->GetParameterNumber(); i++) {
|
||||
auto parameter = method->GetParameter(i);
|
||||
if (parameter->IsOutParameter()) {
|
||||
LogError(token, String("out parameter type not expected in oneway method."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
lexer_.GetToken();
|
||||
if (!ret) {
|
||||
lexer_.SkipCurrentLine();
|
||||
return false;
|
||||
}
|
||||
|
||||
token = lexer_.PeekToken();
|
||||
if (token != Token::SEMICOLON) {
|
||||
LogError(token, String("\";\" is expected."));
|
||||
if (token != Token::BRACES_RIGHT) {
|
||||
lexer_.SkipCurrentLine(Lexer::TokenToChar(Token::BRACES_RIGHT));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
lexer_.GetToken();
|
||||
|
||||
interface->AddMethod(method);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Parser::ParseParameter(ASTMethod* method)
|
||||
{
|
||||
Token token = lexer_.PeekToken();
|
||||
if (token != Token::BRACKETS_LEFT) {
|
||||
LogError(token, String("\"[\" is expected."));
|
||||
// jump to ',' or ')'
|
||||
while (token != Token::COMMA && token != Token::PARENTHESES_RIGHT && token != Token::END_OF_FILE) {
|
||||
lexer_.GetToken();
|
||||
token = lexer_.PeekToken();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
lexer_.GetToken();
|
||||
|
||||
AutoPtr<ASTParameter> parameter = new ASTParameter();
|
||||
|
||||
token = lexer_.PeekToken();
|
||||
while (token != Token::BRACKETS_RIGHT && token != Token::END_OF_FILE) {
|
||||
switch (token) {
|
||||
case Token::IN:
|
||||
lexer_.GetToken();
|
||||
parameter->SetInParameter(true);
|
||||
break;
|
||||
case Token::OUT:
|
||||
lexer_.GetToken();
|
||||
parameter->SetOutParameter(true);
|
||||
break;
|
||||
case Token::INOUT:
|
||||
lexer_.GetToken();
|
||||
parameter->SetInParameter(true);
|
||||
parameter->SetOutParameter(true);
|
||||
break;
|
||||
default:
|
||||
LogError(token, String("\"in\" or \"out\" or \"inout\" is expected."));
|
||||
break;
|
||||
}
|
||||
token = lexer_.PeekToken();
|
||||
if (token == Token::COMMA) {
|
||||
lexer_.GetToken();
|
||||
token = lexer_.PeekToken();
|
||||
continue;
|
||||
}
|
||||
if (token != Token::BRACKETS_RIGHT) {
|
||||
LogError(token, String("\",\" or \"]\" is expected."));
|
||||
// jump to ',' or ')'
|
||||
while (token != Token::COMMA && token != Token::PARENTHESES_RIGHT && token != Token::END_OF_FILE) {
|
||||
lexer_.GetToken();
|
||||
token = lexer_.PeekToken();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// read ']'
|
||||
lexer_.GetToken();
|
||||
|
||||
AutoPtr<ASTType> type = ParseType();
|
||||
if (type == nullptr) {
|
||||
// jump to ',' or ')'
|
||||
while (token != Token::COMMA && token != Token::PARENTHESES_RIGHT && token != Token::END_OF_FILE) {
|
||||
lexer_.GetToken();
|
||||
token = lexer_.PeekToken();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
token = lexer_.PeekToken();
|
||||
if (token != Token::IDENTIFIER) {
|
||||
LogError(token, String("Parameter name is expected."));
|
||||
// jump to ',' or ')'
|
||||
while (token != Token::COMMA && token != Token::PARENTHESES_RIGHT && token != Token::END_OF_FILE) {
|
||||
lexer_.GetToken();
|
||||
token = lexer_.PeekToken();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
lexer_.GetToken();
|
||||
|
||||
parameter->SetName(lexer_.GetIdentifier());
|
||||
parameter->SetType(type);
|
||||
method->AddParameter(parameter);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
AutoPtr<ASTType> Parser::ParseType()
|
||||
{
|
||||
AutoPtr<ASTType> type;
|
||||
|
||||
Token token = lexer_.PeekToken();
|
||||
if (IsPrimitiveType(token)) {
|
||||
lexer_.GetToken();
|
||||
type = module_->FindType(lexer_.DumpToken());
|
||||
} else if (token == Token::LIST) {
|
||||
type = ParseList();
|
||||
} else if (token == Token::MAP) {
|
||||
type = ParseMap();
|
||||
} else if (token == Token::IDENTIFIER) {
|
||||
lexer_.GetToken();
|
||||
if (parsingInterface_ != nullptr &&
|
||||
parsingInterface_->GetName().Equals(lexer_.GetIdentifier())) {
|
||||
type = parsingInterface_.Get();
|
||||
} else {
|
||||
type = module_->FindType(lexer_.GetIdentifier());
|
||||
}
|
||||
} else {
|
||||
LogError(token, String("Type name is expected."));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (type == nullptr) {
|
||||
LogError(token, String::Format("Type \"%s\" was not declared in the module.", lexer_.DumpToken().string()));
|
||||
}
|
||||
|
||||
token = lexer_.PeekToken();
|
||||
if (token == Token::BRACKETS_LEFT) {
|
||||
lexer_.GetToken();
|
||||
token = lexer_.PeekToken();
|
||||
if (token != Token::BRACKETS_RIGHT) {
|
||||
LogError(token, String("\"]\" is expected."));
|
||||
return nullptr;
|
||||
}
|
||||
lexer_.GetToken();
|
||||
|
||||
AutoPtr<ASTArrayType> arrayType = new ASTArrayType();
|
||||
arrayType->SetElementType(type);
|
||||
|
||||
type = module_->FindType(arrayType->ToString());
|
||||
if (type == nullptr) {
|
||||
module_->AddType(arrayType);
|
||||
type = static_cast<ASTType*>(arrayType.Get());
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
AutoPtr<ASTType> Parser::ParseList()
|
||||
{
|
||||
lexer_.GetToken();
|
||||
|
||||
Token token = lexer_.PeekToken();
|
||||
if (token != Token::ANGLE_BRACKETS_LEFT) {
|
||||
LogError(token, String("\"<\" is expected."));
|
||||
return nullptr;
|
||||
}
|
||||
lexer_.GetToken();
|
||||
|
||||
AutoPtr<ASTType> type = ParseType();
|
||||
if (type == nullptr) {
|
||||
lexer_.SkipCurrentLine('>');
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
token = lexer_.PeekToken();
|
||||
if (token != Token::ANGLE_BRACKETS_RIGHT) {
|
||||
LogError(token, String("\">\" is expected."));
|
||||
return nullptr;
|
||||
}
|
||||
lexer_.GetToken();
|
||||
|
||||
AutoPtr<ASTListType> list = new ASTListType();
|
||||
list->SetElementType(type);
|
||||
|
||||
AutoPtr<ASTType> ret = module_->FindType(list->ToString());
|
||||
if (ret == nullptr) {
|
||||
module_->AddType(list);
|
||||
ret = list.Get();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
AutoPtr<ASTType> Parser::ParseMap()
|
||||
{
|
||||
lexer_.GetToken();
|
||||
|
||||
Token token = lexer_.PeekToken();
|
||||
if (token != Token::ANGLE_BRACKETS_LEFT) {
|
||||
LogError(token, String("\"<\" is expected."));
|
||||
return nullptr;
|
||||
}
|
||||
lexer_.GetToken();
|
||||
|
||||
AutoPtr<ASTType> keyType = ParseType();
|
||||
if (keyType == nullptr) {
|
||||
lexer_.SkipCurrentLine('>');
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
token = lexer_.PeekToken();
|
||||
if (token != Token::COMMA) {
|
||||
LogError(token, String("\",\" is expected."));
|
||||
return nullptr;
|
||||
}
|
||||
lexer_.GetToken();
|
||||
|
||||
AutoPtr<ASTType> valueType = ParseType();
|
||||
if (valueType == nullptr) {
|
||||
lexer_.SkipCurrentLine('>');
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
token = lexer_.PeekToken();
|
||||
if (token != Token::ANGLE_BRACKETS_RIGHT) {
|
||||
LogError(token, String("\">\" is expected."));
|
||||
return nullptr;
|
||||
}
|
||||
lexer_.GetToken();
|
||||
|
||||
AutoPtr<ASTMapType> map = new ASTMapType();
|
||||
map->SetKeyType(keyType);
|
||||
map->SetValueType(valueType);
|
||||
|
||||
AutoPtr<ASTType> ret = module_->FindType(map->ToString());
|
||||
if (ret == nullptr) {
|
||||
module_->AddType(map);
|
||||
ret = map.Get();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool Parser::ParseSequenceable()
|
||||
{
|
||||
lexer_.GetToken();
|
||||
|
||||
String classFullName;
|
||||
|
||||
Token token = lexer_.PeekToken();
|
||||
if (token != Token::IDENTIFIER) {
|
||||
LogError(token, String::Format("%s is not expected.", lexer_.DumpToken().string()));
|
||||
lexer_.SkipCurrentLine();
|
||||
return false;
|
||||
} else {
|
||||
lexer_.GetToken();
|
||||
classFullName = lexer_.GetIdentifier();
|
||||
token = lexer_.PeekToken();
|
||||
}
|
||||
|
||||
if (token != Token::SEMICOLON) {
|
||||
LogError(token, String::Format("%s is not expected.", lexer_.DumpToken().string()));
|
||||
lexer_.SkipCurrentLine();
|
||||
return false;
|
||||
}
|
||||
|
||||
// read ';'
|
||||
lexer_.GetToken();
|
||||
|
||||
if (classFullName.IsEmpty()) {
|
||||
LogError(Token::IDENTIFIER, String("Class name is expected."));
|
||||
return false;
|
||||
} else if (!IsValidTypeName(classFullName)) {
|
||||
LogError(Token::IDENTIFIER, String::Format("Class name \"%s\" is illegal.", classFullName.string()));
|
||||
return false;
|
||||
}
|
||||
|
||||
AutoPtr<ASTSequenceableType> sequenceable = new ASTSequenceableType();
|
||||
int index = classFullName.LastIndexOf('.');
|
||||
if (index != -1) {
|
||||
sequenceable->SetName(classFullName.Substring(index + 1));
|
||||
sequenceable->SetNamespace(module_->ParseNamespace(classFullName.Substring(0, index + 1)));
|
||||
} else {
|
||||
sequenceable->SetName(classFullName);
|
||||
sequenceable->SetNamespace(NameSpaceEmpty());
|
||||
}
|
||||
module_->AddSequenceable(sequenceable);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Parser::CheckIntegrity()
|
||||
{
|
||||
bool definedInterface = false;
|
||||
int interfaceNumber = module_->GetInterfaceNumber();
|
||||
for (int i = 0; i < interfaceNumber; i++) {
|
||||
if (!module_->GetInterface(i)->IsExternal()) {
|
||||
definedInterface = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!definedInterface) {
|
||||
LogError(Token::UNKNOWN, String("An interface is not defined."));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Parser::IsValidTypeName(const String& typeName)
|
||||
{
|
||||
if (typeName[0] == '.') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeName[typeName.GetLength() - 1] == '.') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Parser::LogError(Token token, const String& message)
|
||||
{
|
||||
AutoPtr<ErrorInfo> error = new ErrorInfo();
|
||||
|
||||
String sourceFile = lexer_.GetSourceFile()->GetPath();
|
||||
#ifdef __MINGW32__
|
||||
error->file_ = sourceFile.Substring(sourceFile.LastIndexOf('\\') + 1);
|
||||
#else
|
||||
error->file_ = sourceFile.Substring(sourceFile.LastIndexOf('/') + 1);
|
||||
#endif
|
||||
error->lineNo_ = lexer_.GetTokenLineNumber();
|
||||
error->columnNo_ = lexer_.GetTokenColumnNumber();
|
||||
error->message_ = message;
|
||||
|
||||
if (errors_ == nullptr) {
|
||||
errors_ = error;
|
||||
} else {
|
||||
ErrorInfo* pos = errors_;
|
||||
while (pos->next_ != nullptr) {
|
||||
pos = pos->next_;
|
||||
}
|
||||
pos->next_ = error;
|
||||
}
|
||||
}
|
||||
|
||||
void Parser::ShowError()
|
||||
{
|
||||
ErrorInfo* error = errors_;
|
||||
while (error != nullptr) {
|
||||
Logger::E(TAG, "%s[line %d, column %d] %s", error->file_.string(),
|
||||
error->lineNo_, error->columnNo_, error->message_.string());
|
||||
error = error->next_;
|
||||
}
|
||||
}
|
||||
|
||||
AutoPtr<ASTNamespace> Parser::NameSpaceEmpty()
|
||||
{
|
||||
AutoPtr<ASTNamespace> currNspace = nullptr;
|
||||
currNspace = module_->FindNamespace("");
|
||||
if (currNspace == nullptr) {
|
||||
currNspace = new ASTNamespace("");
|
||||
module_->AddNamespace(currNspace);
|
||||
}
|
||||
return currNspace;
|
||||
}
|
||||
}
|
||||
}
|
99
parser/parser.h
Normal file
99
parser/parser.h
Normal file
@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_PARSER_H
|
||||
#define OHOS_IDL_PARSER_H
|
||||
|
||||
#include "ast/ast_interface_type.h"
|
||||
#include "ast/ast_method.h"
|
||||
#include "ast/ast_module.h"
|
||||
#include "ast/ast_type.h"
|
||||
#include "parser/lexer.h"
|
||||
#include "parser/token.h"
|
||||
#include "util/autoptr.h"
|
||||
#include "util/light_refcount_base.h"
|
||||
#include "util/options.h"
|
||||
#include "util/string.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
class Parser {
|
||||
public:
|
||||
explicit Parser(const Options& options);
|
||||
|
||||
~Parser() = default;
|
||||
|
||||
bool Parse(const String& sourceFile);
|
||||
|
||||
AutoPtr<ASTModule> GetModule() const
|
||||
{
|
||||
return module_;
|
||||
}
|
||||
|
||||
private:
|
||||
class ErrorInfo : public LightRefCountBase {
|
||||
public:
|
||||
String file_;
|
||||
Token token_;
|
||||
int lineNo_;
|
||||
int columnNo_;
|
||||
String message_;
|
||||
AutoPtr<ErrorInfo> next_;
|
||||
};
|
||||
|
||||
bool ParseFile();
|
||||
|
||||
bool ParseLicense();
|
||||
|
||||
bool ParseInterface();
|
||||
|
||||
bool ParseMethod(ASTInterfaceType* interface);
|
||||
|
||||
bool ParseParameter(ASTMethod* method);
|
||||
|
||||
AutoPtr<ASTNamespace> NameSpaceEmpty();
|
||||
|
||||
AutoPtr<ASTType> ParseType();
|
||||
|
||||
AutoPtr<ASTType> ParseList();
|
||||
|
||||
AutoPtr<ASTType> ParseMap();
|
||||
|
||||
bool ParseSequenceable();
|
||||
|
||||
bool CheckIntegrity();
|
||||
|
||||
bool IsValidTypeName(const String& typeName);
|
||||
|
||||
static bool IsPrimitiveType(Token token)
|
||||
{
|
||||
return token >= Token::BOOLEAN && token <= Token::STRING;
|
||||
}
|
||||
|
||||
void LogError(Token token, const String& message);
|
||||
|
||||
void ShowError();
|
||||
|
||||
static const char* TAG;
|
||||
|
||||
const Options& options_;
|
||||
AutoPtr<ASTModule> module_;
|
||||
AutoPtr<ASTInterfaceType> parsingInterface_;
|
||||
Lexer lexer_;
|
||||
AutoPtr<ErrorInfo> errors_;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // OHOS_IDL_PARSER_H
|
63
parser/token.h
Normal file
63
parser/token.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_TOKEN_H
|
||||
#define OHOS_IDL_TOKEN_H
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
enum class Token {
|
||||
UNKNOWN = 0,
|
||||
// types
|
||||
BOOLEAN,
|
||||
CHAR,
|
||||
BYTE,
|
||||
SHORT,
|
||||
INTEGER,
|
||||
LONG,
|
||||
FLOAT,
|
||||
DOUBLE,
|
||||
STRING,
|
||||
LIST,
|
||||
MAP,
|
||||
// keywords
|
||||
IN,
|
||||
INTERFACE,
|
||||
ONEWAY,
|
||||
OUT,
|
||||
INOUT,
|
||||
SEQUENCEABLE,
|
||||
// symbols
|
||||
DOT, // '.'
|
||||
COMMA, // ','
|
||||
SEMICOLON, // ';'
|
||||
BRACES_LEFT, // '{'
|
||||
BRACES_RIGHT, // '}'
|
||||
BRACKETS_LEFT, // '['
|
||||
BRACKETS_RIGHT, // ']'
|
||||
PARENTHESES_LEFT, // '('
|
||||
PARENTHESES_RIGHT, // ')'
|
||||
ANGLE_BRACKETS_LEFT, // '<'
|
||||
ANGLE_BRACKETS_RIGHT, // '>'
|
||||
// others
|
||||
IDENTIFIER,
|
||||
COMMENT_BLOCK,
|
||||
COMMENT_LINE,
|
||||
END_OF_FILE,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OHOS_IDL_TOKEN_H
|
66
test/native/BUILD.gn
Normal file
66
test/native/BUILD.gn
Normal file
@ -0,0 +1,66 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/ability/ability_runtime/idl/idl.gni")
|
||||
|
||||
config("ipc_test_config") {
|
||||
include_dirs = [
|
||||
"//utils/native/base/include",
|
||||
"${IDL_TEST_DIR}/include",
|
||||
"${IPC_SUBSYSTEM_DIR}/utils/include",
|
||||
"${IPC_SUBSYSTEM_DIR}/ipc/native/src/mock/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_executable("idl_server_test") {
|
||||
sources = [
|
||||
"./src/idl_test_service_stub.cpp",
|
||||
"./src/main_server.cpp",
|
||||
"./src/test_service.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":ipc_test_config" ]
|
||||
|
||||
deps = [ "//utils/native/base:utils" ]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
|
||||
subsystem_name = "aafwk"
|
||||
part_name = "idl"
|
||||
}
|
||||
|
||||
ohos_executable("idl_client_test") {
|
||||
sources = [
|
||||
"./src/idl_test_service_proxy.cpp",
|
||||
"./src/main_client.cpp",
|
||||
"./src/test_client.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":ipc_test_config" ]
|
||||
|
||||
deps = [ "//utils/native/base:utils" ]
|
||||
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"samgr_standard:samgr_proxy",
|
||||
]
|
||||
|
||||
subsystem_name = "aafwk"
|
||||
part_name = "idl"
|
||||
}
|
19
test/native/IIdlTestService.idl
Normal file
19
test/native/IIdlTestService.idl
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
interface OHOS.IIdlTestService {
|
||||
int TestIntTransaction([in] int data);
|
||||
void TestStringTransaction([in] String data);
|
||||
}
|
45
test/native/include/idl_test_service_proxy.h
Normal file
45
test/native/include/idl_test_service_proxy.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDLTESTSERVICEPROXY_H
|
||||
#define OHOS_IDLTESTSERVICEPROXY_H
|
||||
|
||||
#include <iremote_proxy.h>
|
||||
|
||||
#include "iidl_test_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
class IdlTestServiceProxy : public IRemoteProxy<IIdlTestService> {
|
||||
public:
|
||||
explicit IdlTestServiceProxy(const sptr<IRemoteObject>& remote)
|
||||
: IRemoteProxy<IIdlTestService>(remote)
|
||||
{}
|
||||
|
||||
virtual ~IdlTestServiceProxy()
|
||||
{}
|
||||
|
||||
ErrCode TestIntTransaction(int _data, int& result) override;
|
||||
|
||||
ErrCode TestStringTransaction(const std::string& _data) override;
|
||||
|
||||
private:
|
||||
static constexpr int COMMAND_TEST_INT_TRANSACTION = MIN_TRANSACTION_ID + 0;
|
||||
static constexpr int COMMAND_TEST_STRING_TRANSACTION = MIN_TRANSACTION_ID + 1;
|
||||
|
||||
static inline BrokerDelegator<IdlTestServiceProxy> delegator_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_IDLTESTSERVICEPROXY_H
|
||||
|
34
test/native/include/idl_test_service_stub.h
Normal file
34
test/native/include/idl_test_service_stub.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDLTESTSERVICESTUB_H
|
||||
#define OHOS_IDLTESTSERVICESTUB_H
|
||||
|
||||
#include <iremote_stub.h>
|
||||
|
||||
#include "iidl_test_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
class IdlTestServiceStub : public IRemoteStub<IIdlTestService> {
|
||||
public:
|
||||
int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) override;
|
||||
|
||||
private:
|
||||
static constexpr int COMMAND_TEST_INT_TRANSACTION = MIN_TRANSACTION_ID + 0;
|
||||
static constexpr int COMMAND_TEST_STRING_TRANSACTION = MIN_TRANSACTION_ID + 1;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_IDLTESTSERVICESTUB_H
|
||||
|
33
test/native/include/iidl_test_service.h
Normal file
33
test/native/include/iidl_test_service.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IIDLTESTSERVICE_H
|
||||
#define OHOS_IIDLTESTSERVICE_H
|
||||
|
||||
#include <string_ex.h>
|
||||
#include <iremote_broker.h>
|
||||
|
||||
namespace OHOS {
|
||||
class IIdlTestService : public IRemoteBroker {
|
||||
public:
|
||||
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IIdlTestService");
|
||||
|
||||
virtual ErrCode TestIntTransaction(int _data, int& result) = 0;
|
||||
|
||||
virtual ErrCode TestStringTransaction(const std::string& _data) = 0;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_IIDLTESTSERVICE_H
|
||||
|
34
test/native/include/test_client.h
Normal file
34
test/native/include/test_client.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IPC_TEST_SERVICE_CLIENT_H
|
||||
#define OHOS_IPC_TEST_SERVICE_CLIENT_H
|
||||
|
||||
#include "ipc_debug.h"
|
||||
#include "log_tags.h"
|
||||
#include "idl_test_service_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
class TestClient {
|
||||
public:
|
||||
int ConnectService();
|
||||
void StartIntTransaction();
|
||||
void StartStringTransaction();
|
||||
private:
|
||||
static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "TestClient" };
|
||||
sptr<IdlTestServiceProxy> testService_;
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_IPC_TEST_SERVICE_CLIENT_H
|
36
test/native/include/test_service.h
Normal file
36
test/native/include/test_service.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IPC_TEST_SERVICE_H
|
||||
#define OHOS_IPC_TEST_SERVICE_H
|
||||
|
||||
#include "hilog/log.h"
|
||||
#include "log_tags.h"
|
||||
#include "idl_test_service_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
class TestService : public IdlTestServiceStub {
|
||||
public:
|
||||
TestService();
|
||||
~TestService();
|
||||
static int Instantiate();
|
||||
ErrCode TestIntTransaction(int data, int &rep) override;
|
||||
ErrCode TestStringTransaction(const std::string& data) override;
|
||||
private:
|
||||
static constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "TestService" };
|
||||
};
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_IPC_TEST_SERVICE_H
|
||||
|
75
test/native/src/idl_test_service_proxy.cpp
Normal file
75
test/native/src/idl_test_service_proxy.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "idl_test_service_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
ErrCode IdlTestServiceProxy::TestIntTransaction(int _data, int& result)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
data.WriteInt32(_data);
|
||||
|
||||
if (Remote() == nullptr) {
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
int32_t st = Remote()->SendRequest(COMMAND_TEST_INT_TRANSACTION, data, reply, option);
|
||||
if (st != ERR_NONE) {
|
||||
return st;
|
||||
}
|
||||
|
||||
ErrCode ec = reply.ReadInt32();
|
||||
if (FAILED(ec)) {
|
||||
return ec;
|
||||
}
|
||||
|
||||
result = reply.ReadInt32();
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
ErrCode IdlTestServiceProxy::TestStringTransaction(const std::string& _data)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
data.WriteString16(Str8ToStr16(_data));
|
||||
|
||||
if (Remote() == nullptr) {
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
int32_t st = Remote()->SendRequest(COMMAND_TEST_STRING_TRANSACTION, data, reply, option);
|
||||
if (st != ERR_NONE) {
|
||||
return st;
|
||||
}
|
||||
|
||||
ErrCode ec = reply.ReadInt32();
|
||||
if (FAILED(ec)) {
|
||||
return ec;
|
||||
}
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace OHOS
|
48
test/native/src/idl_test_service_stub.cpp
Normal file
48
test/native/src/idl_test_service_stub.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "idl_test_service_stub.h"
|
||||
|
||||
namespace OHOS {
|
||||
int IdlTestServiceStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
|
||||
MessageParcel& reply, MessageOption& option)
|
||||
{
|
||||
if (data.ReadInterfaceToken() != GetDescriptor()) {
|
||||
return ERR_TRANSACTION_FAILED;
|
||||
}
|
||||
switch (code) {
|
||||
case COMMAND_TEST_INT_TRANSACTION: {
|
||||
int _data = data.ReadInt32();
|
||||
int result;
|
||||
ErrCode ec = TestIntTransaction(_data, result);
|
||||
reply.WriteInt32(ec);
|
||||
if (SUCCEEDED(ec)) {
|
||||
reply.WriteInt32(result);
|
||||
}
|
||||
return ERR_NONE;
|
||||
}
|
||||
case COMMAND_TEST_STRING_TRANSACTION: {
|
||||
std::string _data = Str16ToStr8(data.ReadString16());
|
||||
ErrCode ec = TestStringTransaction(_data);
|
||||
reply.WriteInt32(ec);
|
||||
return ERR_NONE;
|
||||
}
|
||||
default:
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
}
|
||||
|
||||
return ERR_TRANSACTION_FAILED;
|
||||
}
|
||||
} // namespace OHOS
|
75
test/native/src/main_client.cpp
Normal file
75
test/native/src/main_client.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ipc_debug.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "log_tags.h"
|
||||
#include "test_client.h"
|
||||
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "IPCTestClient" };
|
||||
|
||||
enum class TestCommand {
|
||||
TEST_CMD_NONE = 0,
|
||||
TEST_CMD_INT_TRANS = 1,
|
||||
TEST_CMD_STRING_TRANS = 2
|
||||
};
|
||||
|
||||
namespace {
|
||||
std::vector<std::string> GetArgvOptions(int argc, char **argv)
|
||||
{
|
||||
std::vector<std::string> argvOptions;
|
||||
for (int i = 1; i < argc; i++) {
|
||||
argvOptions.emplace_back(std::string(argv[i]));
|
||||
}
|
||||
return argvOptions;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
TestCommand commandId = TestCommand::TEST_CMD_INT_TRANS;
|
||||
if (argc > 1) {
|
||||
commandId = TestCommand(atoi(argv[1]));
|
||||
} else {
|
||||
ZLOGE(LABEL, "unknown command");
|
||||
}
|
||||
std::vector<std::string> argvOptions;
|
||||
argvOptions = GetArgvOptions(argc, argv);
|
||||
std::unique_ptr<TestClient> testClient = std::make_unique<TestClient>();
|
||||
if (testClient->ConnectService()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ZLOGE(LABEL, "commandId= : %{public}d", commandId);
|
||||
switch (commandId) {
|
||||
case TestCommand::TEST_CMD_INT_TRANS:
|
||||
testClient->StartIntTransaction();
|
||||
break;
|
||||
case TestCommand::TEST_CMD_STRING_TRANS:
|
||||
testClient->StartStringTransaction();
|
||||
break;
|
||||
default:
|
||||
ZLOGI(LABEL, "main arg error");
|
||||
break;
|
||||
}
|
||||
|
||||
IPCSkeleton::JoinWorkThread();
|
||||
return 0;
|
||||
}
|
31
test/native/src/main_server.cpp
Normal file
31
test/native/src/main_server.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ipc_debug.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "log_tags.h"
|
||||
#include "test_service.h"
|
||||
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
[[maybe_unused]]static constexpr HiLogLabel LABEL = { LOG_CORE, LOG_ID_IPC, "IPCTestServer" };
|
||||
|
||||
int main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
|
||||
{
|
||||
TestService::Instantiate();
|
||||
ZLOGI(LABEL, "call StartThreadPool");
|
||||
IPCSkeleton::JoinWorkThread();
|
||||
}
|
64
test/native/src/test_client.cpp
Normal file
64
test/native/src/test_client.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "test_client.h"
|
||||
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_debug.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
int TestClient::ConnectService()
|
||||
{
|
||||
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (saMgr == nullptr) {
|
||||
ZLOGE(LABEL, "get registry fail");
|
||||
return -1;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> object = saMgr->GetSystemAbility(IPC_TEST_SERVICE);
|
||||
if (object != nullptr) {
|
||||
ZLOGE(LABEL, "Got test Service object");
|
||||
testService_ = (new (std::nothrow) IdlTestServiceProxy(object));
|
||||
}
|
||||
|
||||
if (testService_ == nullptr) {
|
||||
ZLOGE(LABEL, "Could not find Test Service!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void TestClient::StartIntTransaction()
|
||||
{
|
||||
if (testService_ != nullptr) {
|
||||
ZLOGE(LABEL, "StartIntTransaction");
|
||||
[[maybe_unused]] int result = 0;
|
||||
testService_->TestIntTransaction(1234, result); // 1234 : test number
|
||||
ZLOGE(LABEL, "Rec result from server %{public}d.", result);
|
||||
}
|
||||
}
|
||||
|
||||
void TestClient::StartStringTransaction()
|
||||
{
|
||||
if (testService_ != nullptr) {
|
||||
ZLOGI(LABEL, "StartIntTransaction");
|
||||
testService_->TestStringTransaction("IDL Test");
|
||||
}
|
||||
}
|
||||
} // namespace OHOS
|
64
test/native/src/test_service.cpp
Normal file
64
test/native/src/test_service.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "test_service.h"
|
||||
|
||||
#include <string_ex.h>
|
||||
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_debug.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
namespace OHOS {
|
||||
using namespace OHOS::HiviewDFX;
|
||||
|
||||
int TestService::Instantiate()
|
||||
{
|
||||
ZLOGI(LABEL, "%{public}s call in", __func__);
|
||||
auto saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (saMgr == nullptr) {
|
||||
ZLOGE(LABEL, "%{public}s:fail to get Registry", __func__);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> newInstance = new TestService();
|
||||
int result = saMgr->AddSystemAbility(IPC_TEST_SERVICE, newInstance);
|
||||
ZLOGI(LABEL, "%{public}s: IPC_TEST_SERVICE result = %{public}d", __func__, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
TestService::TestService()
|
||||
{
|
||||
}
|
||||
|
||||
TestService::~TestService()
|
||||
{
|
||||
}
|
||||
|
||||
ErrCode TestService::TestIntTransaction(int data, int &rep)
|
||||
{
|
||||
ZLOGE(LABEL, " TestService:read from client data = %{public}d", data);
|
||||
rep = data + data;
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
ErrCode TestService::TestStringTransaction(const std::string &data)
|
||||
{
|
||||
ZLOGE(LABEL, "TestService:read string from client data = %{public}s", data.c_str());
|
||||
return data.size();
|
||||
}
|
||||
} // namespace OHOS
|
174
test/ts/common/idl_common.h
Normal file
174
test/ts/common/idl_common.h
Normal file
@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_MODULE_TEST_IDL_COMMON_H
|
||||
#define OHOS_IDL_MODULE_TEST_IDL_COMMON_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <string>
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "codegen/code_emitter.h"
|
||||
#include "codegen/code_generator.h"
|
||||
#include "codegen/ts_code_emitter.h"
|
||||
#undef private
|
||||
#undef protected
|
||||
#include "metadata/metadata_builder.h"
|
||||
#include "metadata/metadata_dumper.h"
|
||||
#include "metadata/metadata_reader.h"
|
||||
#include "metadata/metadata_serializer.h"
|
||||
#include "parser/parser.h"
|
||||
#include "util/file.h"
|
||||
#include "util/logger.h"
|
||||
#include "util/options.h"
|
||||
#include "util/string.h"
|
||||
#include "util/string_builder.h"
|
||||
#include "idl_file.h"
|
||||
#include "securec.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
namespace TestCommon {
|
||||
const int ERR_FAIL = -1;
|
||||
const int ERR_OK = 0;
|
||||
|
||||
class IdlCommon {
|
||||
public:
|
||||
IdlCommon() = default;
|
||||
~IdlCommon() = default;
|
||||
|
||||
int Ready(int argc, char** argv)
|
||||
{
|
||||
Options options(argc, argv);
|
||||
std::shared_ptr<MetaComponent> metadata = nullptr;
|
||||
|
||||
if (options.DoCompile()) {
|
||||
Parser parser(options);
|
||||
if (!parser.Parse(options.GetSourceFile())) {
|
||||
return ERR_FAIL;
|
||||
}
|
||||
|
||||
MetadataBuilder builder(parser.GetModule());
|
||||
metadata = builder.Build();
|
||||
metadata_ = metadata;
|
||||
if (metadata == nullptr) {
|
||||
return ERR_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.DoDumpMetadata()) {
|
||||
MetadataDumper dumper(metadata.get());
|
||||
dumper.Dump("");
|
||||
}
|
||||
|
||||
if (options.DoSaveMetadata()) {
|
||||
File metadataFile(options.GetMetadataFile(), File::WRITE);
|
||||
if (!metadataFile.IsValid()) {
|
||||
return ERR_FAIL;
|
||||
}
|
||||
|
||||
MetadataSerializer serializer(metadata.get());
|
||||
serializer.Serialize();
|
||||
uintptr_t data = serializer.GetData();
|
||||
int size = serializer.GetDataSize();
|
||||
|
||||
metadataFile.WriteData(reinterpret_cast<void*>(data), size);
|
||||
metadataFile.Flush();
|
||||
metadataFile.Close();
|
||||
}
|
||||
|
||||
if (options.DoGenerateCode()) {
|
||||
if (metadata == nullptr) {
|
||||
String metadataFile = options.GetMetadataFile();
|
||||
metadata = MetadataReader::ReadMetadataFromFile(metadataFile);
|
||||
if (metadata == nullptr) {
|
||||
return ERR_FAIL;
|
||||
}
|
||||
}
|
||||
if (options.GetTargetLanguage().Equals("ts")) {
|
||||
this->tsCodeGen_ = std::make_shared<TsCodeEmitter>(metadata.get());
|
||||
this->tsCodeGen_->SetDirectory(options.GetGenerationDirectory());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int PrepareIdlFile(
|
||||
const std::string &fileName, const std::string &fileContent, const std::string &fileLicense = LICENSE_CONTENT)
|
||||
{
|
||||
String filePath = String::Format("%s/%s", "./", fileName.c_str());
|
||||
File file(filePath, File::WRITE);
|
||||
if (!file.IsValid()) {
|
||||
GTEST_LOG_(INFO) << "OPEN FILE FAIL";
|
||||
return ERR_FAIL;
|
||||
}
|
||||
|
||||
StringBuilder stringBuilder;
|
||||
stringBuilder.Append(fileLicense.c_str());
|
||||
stringBuilder.Append(fileContent.c_str());
|
||||
|
||||
String data = stringBuilder.ToString();
|
||||
file.WriteData(data.string(), data.GetLength());
|
||||
file.Flush();
|
||||
file.Close();
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
std::shared_ptr<MetaComponent> metadata_ = nullptr;
|
||||
std::shared_ptr<TsCodeEmitter> tsCodeGen_ = nullptr;
|
||||
};
|
||||
|
||||
class ParameterArgv {
|
||||
public:
|
||||
ParameterArgv(const char** args, const int argc) : argc_(argc)
|
||||
{
|
||||
argv_ = new char* [argc_] {nullptr};
|
||||
for (int i = 0; i < argc_; ++i) {
|
||||
const int itemSize = strlen(args[i]);
|
||||
argv_[i] = new char[itemSize + 1] {0};
|
||||
if (strcpy_s(argv_[i], itemSize + 1, args[i])) {
|
||||
GTEST_LOG_(ERROR) << "strcpy_s error [!EOK]";
|
||||
}
|
||||
}
|
||||
};
|
||||
~ParameterArgv()
|
||||
{
|
||||
if (argv_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < argc_; ++i) {
|
||||
if (argv_[i] == nullptr) {
|
||||
continue;
|
||||
}
|
||||
delete[] argv_[i];
|
||||
argv_[i] = nullptr;
|
||||
}
|
||||
delete[] argv_;
|
||||
argv_ = nullptr;
|
||||
};
|
||||
|
||||
char** GetArgv()
|
||||
{
|
||||
return argv_;
|
||||
};
|
||||
|
||||
char** argv_;
|
||||
const int argc_;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // OHOS_IDL_MODULE_TEST_IDL_COMMON_H
|
545
test/ts/common/idl_file.h
Normal file
545
test/ts/common/idl_file.h
Normal file
@ -0,0 +1,545 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_IDL_MODULE_TEST_IDL_FILE_H
|
||||
#define OHOS_IDL_MODULE_TEST_IDL_FILE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
namespace TestCommon {
|
||||
const std::string LICENSE_CONTENT =
|
||||
"/*\n"
|
||||
" * Copyright (C) 2022 Device Co., Ltd.\n"
|
||||
" * Licensed under the Apache License, Version 2.0 (the \"License\");\n"
|
||||
" * you may not use this file except in compliance with the License.\n"
|
||||
" * You may obtain a copy of the License at\n"
|
||||
" *\n"
|
||||
" * http://www.apache.org/licenses/LICENSE-2.0\n"
|
||||
" *\n"
|
||||
" * Unless required by applicable law or agreed to in writing, software\n"
|
||||
" * distributed under the License is distributed on an \"AS IS\" BASIS,\n"
|
||||
" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
|
||||
" * See the License for the specific language governing permissions and\n"
|
||||
" * limitations under the License.\n"
|
||||
" */\n"
|
||||
"\n";
|
||||
const std::string UNKNOW_TYPE_IDL_NAME = "IIdlTest.idl";
|
||||
|
||||
const std::string UNKNOW_TYPE_CASE1_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" void voidOrderOutChar([in] char param1, [out] char param2);\n"
|
||||
"}";
|
||||
|
||||
const std::string UNKNOW_TYPE_CASE2_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" void voidOrderOutList([in] List<int> param1, [out] List<int> param2);\n"
|
||||
"}";
|
||||
|
||||
const std::string UNKNOW_TYPE_CASE3_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" void voidOrderOutMapChar([in] Map<int, char> param1, [out] Map<int, char> param2);\n"
|
||||
"}";
|
||||
|
||||
const std::string UNKNOW_TYPE_CASE4_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" void voidOrderOutMapList([in] Map<int, List<int>> param1, [out] Map<int, List<int>> param2);\n"
|
||||
"}";
|
||||
|
||||
const std::string UNKNOW_TYPE_CASE5_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" char voidOrderReturnChar();\n"
|
||||
"}";
|
||||
|
||||
const std::string UNKNOW_TYPE_CASE6_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" List<int> voidOrderReturnList();\n"
|
||||
"}";
|
||||
|
||||
const std::string UNKNOW_TYPE_CASE7_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" Map<int, char> voidOrderReturnMapChar();\n"
|
||||
"}";
|
||||
|
||||
const std::string UNKNOW_TYPE_CASE8_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" Map<int, List<int>> voidOrderReturnMapList();\n"
|
||||
"}";
|
||||
|
||||
const std::string NORMAL_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.IInterfaceDeclare;\n"
|
||||
"sequenceable idl.systemtest.MySequenceable;\n"
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" int voidOrderOutInt([in] int param1, [out] int param2);\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_RETURN_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" voidOrderNoReturn();\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_FUNCTION_NAME_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" int ([in] int param1, [out] int param2);\n"
|
||||
"}";
|
||||
|
||||
const std::string SAME_FUNCTION_NAME_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" int voidOrderOutInt([in] int param1, [out] int param2);\n"
|
||||
" int voidOrderOutInt([in] int param1);\n"
|
||||
"}";
|
||||
|
||||
const std::string UNSIGNED_CHAR_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" unsigned char voidOrderOutUnsignedChar([in] unsigned char param1, [out] unsigned char param2);\n"
|
||||
"}";
|
||||
|
||||
const std::string UNSIGNED_SHORT_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" unsigned short voidOrderOutUnsignedShort([in] unsigned short param1, [out] unsigned short param2);\n"
|
||||
"}";
|
||||
|
||||
const std::string UNSIGNED_INT_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" unsigned int voidOrderOutUnsignedInt([in] unsigned int param1, [out] unsigned int param2);\n"
|
||||
"}";
|
||||
|
||||
const std::string MULTIPLE_NAMESPACES_IDL_CONTENT =
|
||||
"interface idl.systemtest.namespace3.namespace4.IIdlTest {\n"
|
||||
" void voidParameterTypeVoid([in] int param1);\n"
|
||||
"}";
|
||||
|
||||
const std::string INOUT_SEPARATE_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" void voidParameterTypeVoid([inout] int param1);\n"
|
||||
"}";
|
||||
|
||||
const std::string INTERFACE_NO_CONTENT_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
"}";
|
||||
|
||||
const std::string PARAM_NO_INOUT_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" void voidParameterTypeVoid(int param1);\n"
|
||||
"}";
|
||||
|
||||
const std::string INOUT_NO_BIGPARANTHESES_IDL_CONTENT =
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" void voidParameterTypeVoid(in int param1);\n"
|
||||
"}";
|
||||
|
||||
const std::string NORMAL_TYPE_IN_IDL_CONTENT =
|
||||
"interface idl.systemtest.IInterfaceDeclare;\n"
|
||||
"sequenceable idl.systemtest.MySequenceable;\n"
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" void voidParameterTypeVoid([in] void param1);\n"
|
||||
" void voidParameterTypeShort([in] short param1);\n"
|
||||
" void voidParameterTypeByte([in] byte param2);\n"
|
||||
" void voidParameterTypeInt([in] int param1);\n"
|
||||
" void voidParameterTypeLong([in] long param1);\n"
|
||||
" void voidParameterTypeFloat([in] float param1);\n"
|
||||
" void voidParameterTypeString([in] String param1);\n"
|
||||
" void voidParameterTypeDouble([in] double param1);\n"
|
||||
" void voidParameterTypeBoolean([in] boolean param1);\n"
|
||||
" void voidParameterTypeShortArray([in] short[] param1);\n"
|
||||
" void voidParameterTypeByteArray([in] byte[] param2);\n"
|
||||
" void voidParameterTypeIntArray([in] int[] param1);\n"
|
||||
" void voidParameterTypeLongArray([in] long[] param1);\n"
|
||||
" void voidParameterTypeFloatArray([in] float[] param1);\n"
|
||||
" void voidParameterTypeStringArray([in] String[] param1);\n"
|
||||
" void voidParameterTypeDoubleArray([in] double[] param1);\n"
|
||||
" void voidParameterTypeBooleanArray([in] boolean[] param1);\n"
|
||||
" void voidParameterTypeMySequenceable([in] MySequenceable mysequenceable);\n"
|
||||
" void voidParameterTypeMySequenceableArray([in] MySequenceable[] mysequenceable);\n"
|
||||
" void voidParameterTypeInterface([in] IInterfaceDeclare myInterface);\n"
|
||||
" void voidMap([in] Map<String, MySequenceable> data);\n"
|
||||
"}";
|
||||
|
||||
const std::string NORMAL_TYPE_OUT_IDL_CONTENT =
|
||||
"interface idl.systemtest.IInterfaceDeclare;\n"
|
||||
"sequenceable idl.systemtest.MySequenceable;\n"
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" void voidParameterTypeVoid([out] void param2);\n"
|
||||
" void voidParameterTypeShort([out] short param2);\n"
|
||||
" void voidParameterTypeByte([out] byte param2);\n"
|
||||
" void voidParameterTypeInt([out] int param2);\n"
|
||||
" void voidParameterTypeLong([out] long param2);\n"
|
||||
" void voidParameterTypeFloat([out] float param2);\n"
|
||||
" void voidParameterTypeString([out] String param2);\n"
|
||||
" void voidParameterTypeDouble([out] double param2);\n"
|
||||
" void voidParameterTypeBoolean([out] boolean param2);\n"
|
||||
" void voidParameterTypeShortArray([out] short[] param2);\n"
|
||||
" void voidParameterTypeByteArray([out] byte[] param2);\n"
|
||||
" void voidParameterTypeIntArray([out] int[] param2);\n"
|
||||
" void voidParameterTypeLongArray([out] long[] param2);\n"
|
||||
" void voidParameterTypeFloatArray([out] float[] param2);\n"
|
||||
" void voidParameterTypeStringArray([out] String[] param2);\n"
|
||||
" void voidParameterTypeDoubleArray([out] double[] param2);\n"
|
||||
" void voidParameterTypeBooleanArray([out] boolean[] param2);\n"
|
||||
" void voidParameterTypeMySequenceable([out] MySequenceable mysequenceable);\n"
|
||||
" void voidParameterTypeMySequenceableArray([out] MySequenceable[] mysequenceable);\n"
|
||||
" void voidParameterTypeInterface([out] IInterfaceDeclare myInterface);\n"
|
||||
" void voidMap([out] Map<String, MySequenceable> data);\n"
|
||||
"}";
|
||||
|
||||
const std::string NORMAL_TYPE_IN_AND_OUT_IDL_CONTENT =
|
||||
"interface idl.systemtest.IInterfaceDeclare;\n"
|
||||
"sequenceable idl.systemtest.MySequenceable;\n"
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" void voidParameterTypeVoid([inout] void param2);\n"
|
||||
" void voidParameterTypeShort([inout] short param2);\n"
|
||||
" void voidParameterTypeByte([inout] byte param2);\n"
|
||||
" void voidParameterTypeInt([inout] int param2);\n"
|
||||
" void voidParameterTypeLong([inout] long param2);\n"
|
||||
" void voidParameterTypeFloat([inout] float param2);\n"
|
||||
" void voidParameterTypeString([inout] String param2);\n"
|
||||
" void voidParameterTypeDouble([inout] double param2);\n"
|
||||
" void voidParameterTypeBoolean([inout] boolean param2);\n"
|
||||
" void voidParameterTypeShortArray([inout] short[] param2);\n"
|
||||
" void voidParameterTypeByteArray([inout] byte[] param2);\n"
|
||||
" void voidParameterTypeIntArray([inout] int[] param2);\n"
|
||||
" void voidParameterTypeLongArray([inout] long[] param2);\n"
|
||||
" void voidParameterTypeFloatArray([inout] float[] param2);\n"
|
||||
" void voidParameterTypeStringArray([inout] String[] param2);\n"
|
||||
" void voidParameterTypeDoubleArray([inout] double[] param2);\n"
|
||||
" void voidParameterTypeBooleanArray([inout] boolean[] param2);\n"
|
||||
" void voidParameterTypeMySequenceable([inout] MySequenceable mysequenceable);\n"
|
||||
" void voidParameterTypeMySequenceableArray([inout] MySequenceable[] mysequenceable);\n"
|
||||
" void voidParameterTypeInterface([inout] IInterfaceDeclare myInterface);\n"
|
||||
" void voidMap([inout] Map<String, MySequenceable> data);\n"
|
||||
"}";
|
||||
|
||||
const std::string NORMAL_TYPE_RETURN_IDL_CONTENT =
|
||||
"interface idl.systemtest.IInterfaceDeclare;\n"
|
||||
"sequenceable idl.systemtest.MySequenceable;\n"
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" void voidParameterTypeVoid();\n"
|
||||
" short voidParameterTypeShort();\n"
|
||||
" byte voidParameterTypeByte();\n"
|
||||
" int voidParameterTypeInt();\n"
|
||||
" long voidParameterTypeLong();\n"
|
||||
" float voidParameterTypeFloat();\n"
|
||||
" String voidParameterTypeString();\n"
|
||||
" double voidParameterTypeDouble();\n"
|
||||
" boolean voidParameterTypeBoolean();\n"
|
||||
" short[] voidParameterTypeShortArray();\n"
|
||||
" byte[] voidParameterTypeByteArray();\n"
|
||||
" int[] voidParameterTypeIntArray();\n"
|
||||
" long[] voidParameterTypeLongArray();\n"
|
||||
" float[] voidParameterTypeFloatArray();\n"
|
||||
" String[] voidParameterTypeStringArray();\n"
|
||||
" double[] voidParameterTypeDoubleArray();\n"
|
||||
" boolean[] voidParameterTypeBooleanArray();\n"
|
||||
" MySequenceable voidParameterTypeMySequenceable();\n"
|
||||
" MySequenceable[] voidParameterTypeMySequenceableArray();\n"
|
||||
" Map<String, MySequenceable> voidMap();\n"
|
||||
"}";
|
||||
|
||||
const std::string NORMAL_TYPE_COMBINATION_IDL_CONTENT =
|
||||
"interface idl.systemtest.IInterfaceDeclare;\n"
|
||||
"sequenceable idl.systemtest.MySequenceable;\n"
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" short voidParameterTypeShort([in] short param1, [out] short param2, [inout] short param3);\n"
|
||||
" byte voidParameterTypeByte([in] byte param1, [out] byte param2, [inout] byte param3);\n"
|
||||
" short[] voidParameterTypeShortArray([in] short[] param1, [out] short[] param2, [inout] short[] param3);\n"
|
||||
" int[] voidParameterTypeIntArray([in] int[] param1, [inout] int[] param2 , [out] int[] param3);\n"
|
||||
" long[] voidParameterTypeLongArray([in] long[] param1, [inout] long[] param2, [out] long[] param3);\n"
|
||||
" float[] voidParameterTypeFloatArray([in] float[] param1, [inout] float[] param2, [out] float[] param3);\n"
|
||||
" String[] voidParameterTypeStringArray([in] String[] param1, [inout] String[] param2, [out] String[] param3);\n"
|
||||
" double[] voidParameterTypeDoubleArray([in] double[] param1, [inout] double[] param2, [out] double[] param3);\n"
|
||||
" boolean[] voidParameterTypeBooleanArray([in] boolean[] param1,"
|
||||
"[inout] boolean[] param2, [out] boolean[] param3);\n"
|
||||
" byte[] voidParameterTypeByteArray([in] byte[] param1, [out] byte[] param2, [inout] byte[] param3);\n"
|
||||
" MySequenceable TestIntTransaction([in] MySequenceable mysequenceable1,"
|
||||
"[in, out] MySequenceable mysequenceable2, [out] MySequenceable mysequenceable3);\n"
|
||||
" MySequenceable[] voidParameterTypeMySequenceableArray([in] MySequenceable[] mysequenceable1,"
|
||||
"[inout] MySequenceable[] mysequenceable2, [out] MySequenceable[] mysequenceable3);\n"
|
||||
" void InOutMap([inout] Map<String, MySequenceable> data);\n"
|
||||
" void InOutMapArray([inout] Map<String, MySequenceable[]> data);\n"
|
||||
"}";
|
||||
|
||||
|
||||
const std::string NORMAL_TYPE_COMBINATION_IDL_CONTENT2 =
|
||||
"interface idl.systemtest.IInterfaceDeclare;\n"
|
||||
"sequenceable idl.systemtest.MySequenceable;\n"
|
||||
"interface idl.systemtest.IIdlTest {\n"
|
||||
" short voidParameterTypeShort([in] short param1, [out] short param2, [inout] short param3);\n"
|
||||
" byte voidParameterTypeByte([in] float param1, [out] byte param2, [inout] byte param3);\n"
|
||||
" short[] voidParameterTypeShortArray([in] short[] param1,"
|
||||
"[out] short[] param2, [inout] MySequenceable[] param3);\n"
|
||||
" int[] voidParameterTypeIntArray([in] int[] param1,"
|
||||
"[inout] int[] param2 , [out] int[] param3);\n"
|
||||
" long[] voidParameterTypeLongArray([in] short[] param1,"
|
||||
"[inout] MySequenceable[] param2, [out] long[] param3);\n"
|
||||
" float[] voidParameterTypeFloatArray([in] float[] param1,"
|
||||
"[inout] float[] param2, [out] float[] param3);\n"
|
||||
" String[] voidParameterTypeStringArray([in] MySequenceable[] param1,"
|
||||
"[inout] short[] param2, [out] String[] param3);\n"
|
||||
"}";
|
||||
|
||||
const std::string CAPITALIZATION_IDL_NAME = "CapitalizationIdlTest.idl";
|
||||
|
||||
const std::string CAPITALIZATION_VOID_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.CapitalizationIdlTest {\n"
|
||||
" VOID voidOrderReturnVoid();\n"
|
||||
"}";
|
||||
|
||||
const std::string CAPITALIZATION_BOOL_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.CapitalizationIdlTest {\n"
|
||||
" BOOLEAN voidOrderReturnBOOLEAN();\n"
|
||||
"}";
|
||||
|
||||
const std::string CAPITALIZATION_INT_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.CapitalizationIdlTest {\n"
|
||||
" INT voidOrderReturnINT();\n"
|
||||
"}";
|
||||
|
||||
const std::string CAPITALIZATION_STRING_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.CapitalizationIdlTest {\n"
|
||||
" STRING voidOrderReturnSTRING();\n"
|
||||
"}";
|
||||
|
||||
const std::string CAPITALIZATION_INTERFACE_TYPE_IDL_CONTENT =
|
||||
"INTERFACE idl.systemtest.CapitalizationIdlTest {\n"
|
||||
" int voidOrderReturnInt();\n"
|
||||
"}";
|
||||
|
||||
const std::string CAPITALIZATION_IN_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.CapitalizationIdlTest {\n"
|
||||
" int voidOrderReturnInt([IN] int param1);\n"
|
||||
"}";
|
||||
|
||||
const std::string CAPITALIZATION_OUT_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.CapitalizationIdlTest {\n"
|
||||
" void voidOrderReturnVoid([OUT] int param1);\n"
|
||||
"}";
|
||||
|
||||
const std::string CAPITALIZATION_ONEWAY_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.CapitalizationIdlTest {\n"
|
||||
" [ONEWAY] void voidOrderReturnVoid();\n"
|
||||
"}";
|
||||
|
||||
const std::string CAPITALIZATION_SEQUENCEABLE_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.IInterfaceDeclare;\n"
|
||||
"SEQUENCEABLE idl.systemtest.MySequenceable;\n"
|
||||
"interface idl.systemtest.CapitalizationIdlTest {\n"
|
||||
" void voidOrderReturnVoid([in] MySequenceable mysequenceable);\n"
|
||||
"}";
|
||||
|
||||
const std::string CAPITALIZATION_MAP_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.CapitalizationIdlTest {\n"
|
||||
" MAP<int, int> voidOrderReturnMap();\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_LICENSE_IDL_NAME = "NoLicenseIdlTest.idl";
|
||||
|
||||
const std::string NO_LICENSE_VOID_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.NoLicenseIdlTest {\n"
|
||||
" void voidOrderReturnVoid();\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_LICENSE_BOOL_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.NoLicenseIdlTest {\n"
|
||||
" boolean voidOrderReturnBOOLEAN();\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_LICENSE_INT_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.NoLicenseIdlTest {\n"
|
||||
" int voidOrderReturnINT();\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_LICENSE_STRING_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.NoLicenseIdlTest {\n"
|
||||
" String voidOrderReturnSTRING();\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_LICENSE_INTERFACE_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.IInterfaceDeclare;\n"
|
||||
"interface idl.systemtest.NoLicenseIdlTest {\n"
|
||||
" void inInterface([in] IInterfaceDeclare obj);\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_LICENSE_IN_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.NoLicenseIdlTest {\n"
|
||||
" int voidOrderReturnInt([in] int param1);\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_LICENSE_OUT_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.NoLicenseIdlTest {\n"
|
||||
" void voidOrderReturnVoid([out] int param1);\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_LICENSE_ONEWAY_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.NoLicenseIdlTest {\n"
|
||||
" [oneway] void voidOrderReturnVoid();\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_LICENSE_SEQUENCEABLE_TYPE_IDL_CONTENT =
|
||||
"sequenceable idl.systemtest.MySequenceable;\n"
|
||||
"interface idl.systemtest.NoLicenseIdlTest {\n"
|
||||
" void voidOrderReturnVoid([in] MySequenceable mysequenceable);\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_LICENSE_MAP_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.NoLicenseIdlTest {\n"
|
||||
" Map<int, int> voidOrderReturnMap();\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_INTERFACE_IDL_NAME = "NoInterfaceIdlTest.idl";
|
||||
|
||||
const std::string NO_INTERFACE_VOID_TYPE_IDL_CONTENT =
|
||||
"idl.systemtest.NoInterfaceIdlTest {\n"
|
||||
" void voidOrderReturnVoid();\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_INTERFACE_BOOL_TYPE_IDL_CONTENT =
|
||||
"idl.systemtest.NoInterfaceIdlTest {\n"
|
||||
" boolean voidOrderReturnBOOLEAN();\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_INTERFACE_INT_TYPE_IDL_CONTENT =
|
||||
"idl.systemtest.NoInterfaceIdlTest {\n"
|
||||
" int voidOrderReturnINT();\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_INTERFACE_STRING_TYPE_IDL_CONTENT =
|
||||
"idl.systemtest.NoInterfaceIdlTest {\n"
|
||||
" String voidOrderReturnSTRING();\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_INTERFACE_INTERFACE_TYPE_IDL_CONTENT =
|
||||
"interface idl.systemtest.IInterfaceDeclare;\n"
|
||||
"idl.systemtest.NoInterfaceIdlTest {\n"
|
||||
" int voidOrderReturnInt([in] IInterfaceDeclare obj);\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_INTERFACE_IN_TYPE_IDL_CONTENT =
|
||||
"idl.systemtest.NoInterfaceIdlTest {\n"
|
||||
" int voidOrderReturnInt([in] int param1);\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_INTERFACE_OUT_TYPE_IDL_CONTENT =
|
||||
"idl.systemtest.NoInterfaceIdlTest {\n"
|
||||
" void voidOrderReturnVoid([out] int param1);\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_INTERFACE_ONEWAY_TYPE_IDL_CONTENT =
|
||||
"idl.systemtest.NoInterfaceIdlTest {\n"
|
||||
" [oneway] void voidOrderReturnVoid();\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_INTERFACE_SEQUENCEABLE_TYPE_IDL_CONTENT =
|
||||
"sequenceable idl.systemtest.MySequenceable;\n"
|
||||
"idl.systemtest.NoInterfaceIdlTest {\n"
|
||||
" void voidOrderReturnVoid([in] MySequenceable mysequenceable);\n"
|
||||
"}";
|
||||
|
||||
const std::string NO_INTERFACE_MAP_TYPE_IDL_CONTENT =
|
||||
"idl.systemtest.NoInterfaceIdlTest {\n"
|
||||
" Map<int, int> voidOrderReturnMap();\n"
|
||||
"}";
|
||||
|
||||
const std::string I_ABNORMAL_IDL_NAME = "IAbnormalIdlTest.idl";
|
||||
|
||||
const std::string IN_KEYWORD_AFTER_TYPE_IDL_CONTENT =
|
||||
"interface idl.IAbnormalIdlTest {\n"
|
||||
" void voidReturn(int [in] data);\n"
|
||||
"}";
|
||||
|
||||
const std::string NOT_EQUAL_TO_FILENAME_IDL_CONTENT =
|
||||
"interface idl.NotEqualToFileNameTest {\n"
|
||||
" void voidReturn([in] int data);\n"
|
||||
"}";
|
||||
|
||||
const std::string I_ABNORMAL_SCENE_IDL_NAME = "IAbnormalIdlTest.abc";
|
||||
|
||||
const std::string ABNORMAL_SCENE_IDL_CONTENT =
|
||||
"interface idl.IAbnormalIdlTest {\n"
|
||||
" void voidReturn([in] int data);\n"
|
||||
"}";
|
||||
|
||||
const std::string UNSIGNED_CHAR_IDL_CONTENT =
|
||||
"interface idl.IAbnormalIdlTest {\n"
|
||||
" void voidReturn([in] unsigned char data);\n"
|
||||
"}";
|
||||
|
||||
const std::string UNSIGNED_SHORT_IDL_CONTENT =
|
||||
"interface idl.IAbnormalIdlTest {\n"
|
||||
" void voidReturn([in] unsigned short data);\n"
|
||||
"}";
|
||||
|
||||
const std::string UNSIGNED_INT_IDL_CONTENT =
|
||||
"interface idl.IAbnormalIdlTest {\n"
|
||||
" void voidReturn([in] unsigned int data);\n"
|
||||
"}";
|
||||
|
||||
const std::string UNSIGNED_LONG_IDL_CONTENT =
|
||||
"interface idl.IAbnormalIdlTest {\n"
|
||||
" void voidReturn([in] unsigned long data);\n"
|
||||
"}";
|
||||
|
||||
const std::string EMPTY_IDL_CONTENT = "";
|
||||
|
||||
const std::string NOT_RETURN_IDL_CONTENT =
|
||||
"interface idl.IAbnormalIdlTest {\n"
|
||||
" voidReturn([in] int data);\n"
|
||||
"}";
|
||||
|
||||
const std::string NOT_FUNCTION_IDL_CONTENT =
|
||||
"interface idl.IAbnormalIdlTest {\n"
|
||||
" void ([in] int data);\n"
|
||||
"}";
|
||||
|
||||
const std::string SAME_FUNCTION_IDL_CONTENT =
|
||||
"interface idl.IAbnormalIdlTest {\n"
|
||||
" void func([in] int data);\n"
|
||||
" void func([in] int data, [in] int size);\n"
|
||||
"}";
|
||||
|
||||
const std::string FUNCTION_NAME_TOO_LONG_IDL_CONTENT =
|
||||
"interface idl.IAbnormalIdlTest {\n"
|
||||
" void funcdsadasdsadasdasdasdasdasdasdassadasdasdasdasdasd\
|
||||
asdasdasdasdasdasdasddddddddddddddddddddddddddddddddddddddddd\
|
||||
dsaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaassddd\
|
||||
asddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
|
||||
saddddddddddddddddsssssssssssssssssssssssssssssssssssssssssss\
|
||||
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\
|
||||
sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\
|
||||
sssssssssssssssssssssssssssssssssssssssssss([in] int data);\n"
|
||||
"}";
|
||||
|
||||
const std::string VARIABLE_NAME_TOO_LONG_IDL_CONTENT =
|
||||
"interface idl.IAbnormalIdlTest {\n"
|
||||
" void func([in] int datadddddddddddddddddddddddddddddddddddd\
|
||||
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
|
||||
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
|
||||
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
|
||||
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
|
||||
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
|
||||
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\
|
||||
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd);\n"
|
||||
"}";
|
||||
|
||||
const std::string INTERFACE_SPECIAL_NAME_IDL_NAME = "SpecialNameTest.idl";
|
||||
|
||||
const std::string INTERFACE_SPECIAL_NAME_IDL_CONTENT =
|
||||
"interface idl.systemtest.SpecialNameTest {\n"
|
||||
" void voidParameterTypeShort([in] short param1);\n"
|
||||
"}";
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // OHOS_AAFWK_ABILITY_CONFIG_H
|
19
test/ts/moduletest/BUILD.gn
Normal file
19
test/ts/moduletest/BUILD.gn
Normal file
@ -0,0 +1,19 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
group("moduletest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ "ts_code_emitter_test:moduletest" ]
|
||||
}
|
91
test/ts/moduletest/ts_code_emitter_test/BUILD.gn
Normal file
91
test/ts/moduletest/ts_code_emitter_test/BUILD.gn
Normal file
@ -0,0 +1,91 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/test.gni")
|
||||
|
||||
IDL_DIR = "../../../.."
|
||||
|
||||
config("idl_module_test_config") {
|
||||
include_dirs = [
|
||||
"../../common",
|
||||
"${IDL_DIR}/",
|
||||
"//third_party/bounds_checking_function/include/",
|
||||
]
|
||||
}
|
||||
|
||||
common_sources = [
|
||||
"${IDL_DIR}/ast/ast_array_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_boolean_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_byte_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_char_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_double_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_float_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_integer_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_interface_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_list_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_long_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_map_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_method.cpp",
|
||||
"${IDL_DIR}/ast/ast_module.cpp",
|
||||
"${IDL_DIR}/ast/ast_namespace.cpp",
|
||||
"${IDL_DIR}/ast/ast_node.cpp",
|
||||
"${IDL_DIR}/ast/ast_parameter.cpp",
|
||||
"${IDL_DIR}/ast/ast_sequenceable_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_short_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_string_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_void_type.cpp",
|
||||
]
|
||||
|
||||
common_sources += [
|
||||
"${IDL_DIR}/codegen/code_emitter.cpp",
|
||||
"${IDL_DIR}/codegen/code_generator.cpp",
|
||||
"${IDL_DIR}/codegen/cpp_code_emitter.cpp",
|
||||
"${IDL_DIR}/codegen/ts_code_emitter.cpp",
|
||||
]
|
||||
|
||||
common_sources += [
|
||||
"${IDL_DIR}/metadata/metadata_builder.cpp",
|
||||
"${IDL_DIR}/metadata/metadata_dumper.cpp",
|
||||
"${IDL_DIR}/metadata/metadata_reader.cpp",
|
||||
"${IDL_DIR}/metadata/metadata_serializer.cpp",
|
||||
]
|
||||
|
||||
common_sources += [
|
||||
"${IDL_DIR}/parser/lexer.cpp",
|
||||
"${IDL_DIR}/parser/parser.cpp",
|
||||
]
|
||||
|
||||
common_sources += [
|
||||
"${IDL_DIR}/util/file.cpp",
|
||||
"${IDL_DIR}/util/light_refcount_base.cpp",
|
||||
"${IDL_DIR}/util/logger.cpp",
|
||||
"${IDL_DIR}/util/options.cpp",
|
||||
"${IDL_DIR}/util/string.cpp",
|
||||
"${IDL_DIR}/util/string_builder.cpp",
|
||||
"${IDL_DIR}/util/string_pool.cpp",
|
||||
]
|
||||
module_output_path = "idl/ts_moduletest"
|
||||
|
||||
ohos_moduletest("ts_code_emitter_test") {
|
||||
module_out_path = module_output_path
|
||||
configs = [ ":idl_module_test_config" ]
|
||||
sources = [ "ts_code_emitter_test.cpp" ]
|
||||
sources += common_sources
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_static" ]
|
||||
}
|
||||
|
||||
group("moduletest") {
|
||||
testonly = true
|
||||
deps = [ ":ts_code_emitter_test" ]
|
||||
}
|
868
test/ts/moduletest/ts_code_emitter_test/ts_code_emitter_test.cpp
Normal file
868
test/ts/moduletest/ts_code_emitter_test/ts_code_emitter_test.cpp
Normal file
@ -0,0 +1,868 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include "idl_common.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS::Idl::TestCommon;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Idl {
|
||||
namespace ModuleTest {
|
||||
class TsCodeEmitterTest : public testing::Test, public IdlCommon {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void TsCodeEmitterTest::SetUpTestCase()
|
||||
{}
|
||||
|
||||
void TsCodeEmitterTest::TearDownTestCase()
|
||||
{}
|
||||
|
||||
void TsCodeEmitterTest::SetUp()
|
||||
{}
|
||||
|
||||
void TsCodeEmitterTest::TearDown()
|
||||
{}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no license test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no license and void type resolution succeeded
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_001, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_LICENSE_IDL_NAME.c_str(), NO_LICENSE_VOID_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_LICENSE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_EQ(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no license test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no license and bool type resolution succeeded
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_002, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_LICENSE_IDL_NAME.c_str(), NO_LICENSE_BOOL_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_LICENSE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_EQ(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no license test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no license and return int type resolution succeeded
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_003, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_LICENSE_IDL_NAME.c_str(), NO_LICENSE_INT_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_LICENSE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_EQ(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no license test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no license and return string resolution succeeded
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_004, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_LICENSE_IDL_NAME.c_str(), NO_LICENSE_STRING_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_LICENSE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_EQ(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no license test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no license and interface type resolution succeeded
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_005, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_LICENSE_IDL_NAME.c_str(), NO_LICENSE_INTERFACE_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_LICENSE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_EQ(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no license test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no license and in keywords resolution succeeded
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_006, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_LICENSE_IDL_NAME.c_str(), NO_LICENSE_IN_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_LICENSE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_EQ(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no license test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no license and out keywords resolution succeeded
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_007, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_LICENSE_IDL_NAME.c_str(), NO_LICENSE_OUT_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_LICENSE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_EQ(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no license test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no license and oneway keywords resolution succeeded
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_008, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_LICENSE_IDL_NAME.c_str(), NO_LICENSE_ONEWAY_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_LICENSE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_EQ(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no license test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no license and sequenceable type resolution succeeded
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_009, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(
|
||||
NO_LICENSE_IDL_NAME.c_str(), NO_LICENSE_SEQUENCEABLE_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_LICENSE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_EQ(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no license test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no license and map type resolution succeeded
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_010, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_LICENSE_IDL_NAME.c_str(), NO_LICENSE_MAP_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_LICENSE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_EQ(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no interface test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no interface and void type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_011, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_IDL_NAME.c_str(), NO_INTERFACE_VOID_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_INTERFACE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no interface test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no interface and bool type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_012, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_IDL_NAME.c_str(), NO_INTERFACE_BOOL_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_INTERFACE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no interface test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no interface and int type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_013, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_IDL_NAME.c_str(), NO_INTERFACE_INT_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_INTERFACE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no interface test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no interface and string type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_014, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_IDL_NAME.c_str(), NO_INTERFACE_STRING_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_INTERFACE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no interface test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no interface and interface type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_015, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(
|
||||
NO_INTERFACE_IDL_NAME.c_str(), NO_INTERFACE_INTERFACE_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_INTERFACE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no interface test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no interface and in keywords parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_016, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_IDL_NAME.c_str(), NO_INTERFACE_IN_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_INTERFACE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no interface test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no interface and out keywords parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_017, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_IDL_NAME.c_str(), NO_INTERFACE_OUT_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_INTERFACE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no interface test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no interface and oneway keywords parsing failed.
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_018, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_IDL_NAME.c_str(), NO_INTERFACE_ONEWAY_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_INTERFACE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no interface test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no interface and sequenceable type parsing failed.
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_019, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(
|
||||
NO_INTERFACE_IDL_NAME.c_str(), NO_INTERFACE_SEQUENCEABLE_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_INTERFACE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: no interface test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no interface and map type parsing failed.
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_020, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(NO_INTERFACE_IDL_NAME.c_str(), NO_INTERFACE_MAP_TYPE_IDL_CONTENT.c_str(), ""), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", NO_INTERFACE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Detect keyword capitalization issues test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Uppercase void type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_021, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_IDL_NAME.c_str(), CAPITALIZATION_VOID_TYPE_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", CAPITALIZATION_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Detect keyword capitalization issues test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Uppercase bool type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_022, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_IDL_NAME.c_str(), CAPITALIZATION_BOOL_TYPE_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", CAPITALIZATION_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Detect keyword capitalization issues test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Uppercase int type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_023, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_IDL_NAME.c_str(), CAPITALIZATION_INT_TYPE_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", CAPITALIZATION_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Detect keyword capitalization issues test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Uppercase string type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_024, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_IDL_NAME.c_str(), CAPITALIZATION_STRING_TYPE_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", CAPITALIZATION_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Detect keyword capitalization issues test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Uppercase interface type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_025, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(
|
||||
CAPITALIZATION_IDL_NAME.c_str(), CAPITALIZATION_INTERFACE_TYPE_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", CAPITALIZATION_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Detect keyword capitalization issues test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Uppercase in keywords parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_026, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_IDL_NAME.c_str(), CAPITALIZATION_IN_TYPE_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", CAPITALIZATION_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Detect keyword capitalization issues test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Uppercase out keywords parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_027, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_IDL_NAME.c_str(), CAPITALIZATION_OUT_TYPE_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", CAPITALIZATION_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Detect keyword capitalization issues test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Uppercase oneway keywords parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_028, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_IDL_NAME.c_str(), CAPITALIZATION_ONEWAY_TYPE_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", CAPITALIZATION_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Detect keyword capitalization issues test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Uppercase sequenceable type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_029, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(
|
||||
CAPITALIZATION_IDL_NAME.c_str(), CAPITALIZATION_SEQUENCEABLE_TYPE_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", CAPITALIZATION_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Detect keyword capitalization issues test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Uppercase map type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_030, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(CAPITALIZATION_IDL_NAME.c_str(), CAPITALIZATION_MAP_TYPE_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", CAPITALIZATION_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: abnormal scene test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: in keyword after type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_031, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(I_ABNORMAL_IDL_NAME.c_str(), IN_KEYWORD_AFTER_TYPE_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", I_ABNORMAL_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: abnormal scene test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: not equal to filename parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_032, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(I_ABNORMAL_IDL_NAME.c_str(), NOT_EQUAL_TO_FILENAME_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", I_ABNORMAL_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: abnormal scene test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: The file name does not match the interface name
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_033, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(I_ABNORMAL_SCENE_IDL_NAME.c_str(), ABNORMAL_SCENE_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", I_ABNORMAL_SCENE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: abnormal scene test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: unsigned char type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_034, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(I_ABNORMAL_IDL_NAME.c_str(), UNSIGNED_CHAR_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", I_ABNORMAL_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: abnormal scene test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: unsigned short type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_035, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(I_ABNORMAL_IDL_NAME.c_str(), UNSIGNED_SHORT_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", I_ABNORMAL_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: abnormal scene test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: unsigned int type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_036, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(I_ABNORMAL_IDL_NAME.c_str(), UNSIGNED_INT_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", I_ABNORMAL_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: abnormal scene test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: unsigned long type parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_037, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(I_ABNORMAL_IDL_NAME.c_str(), UNSIGNED_LONG_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", I_ABNORMAL_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: abnormal scene test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: empty content parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_038, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(I_ABNORMAL_IDL_NAME.c_str(), EMPTY_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", I_ABNORMAL_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: abnormal scene test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: no return value parsing failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_039, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(I_ABNORMAL_IDL_NAME.c_str(), NOT_RETURN_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", I_ABNORMAL_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: abnormal scene test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: No function name resolution failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_040, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(I_ABNORMAL_IDL_NAME.c_str(), NOT_FUNCTION_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", I_ABNORMAL_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: abnormal scene test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Same function name prasing successed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_041, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(I_ABNORMAL_IDL_NAME.c_str(), SAME_FUNCTION_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", I_ABNORMAL_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_EQ(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: abnormal scene test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: The function name is too long and the parsing is successful
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_042, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(I_ABNORMAL_IDL_NAME.c_str(), FUNCTION_NAME_TOO_LONG_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", I_ABNORMAL_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_EQ(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: abnormal scene test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: The variable name is too long and the parsing succeeded
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_043, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(I_ABNORMAL_IDL_NAME.c_str(), VARIABLE_NAME_TOO_LONG_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", I_ABNORMAL_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_EQ(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Detect namespace issues test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Use multiple namespaces failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_044, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), MULTIPLE_NAMESPACES_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_EQ(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Detect Keyword grammar problems Test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Keyword 'in' 'out' sepatate failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_045, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), INOUT_SEPARATE_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_EQ(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Detect Keyword grammar problems Test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Interface no content failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_046, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), INTERFACE_NO_CONTENT_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Detect Keyword grammar problems Test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Paramter no keyword 'in' 'out' failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_047, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), PARAM_NO_INOUT_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: idl
|
||||
* Function: Ready
|
||||
* SubFunction: NA
|
||||
* FunctionPoints: Detect Keyword grammar problems Test
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Keyword 'in' 'out' not use big parentheses failed
|
||||
*/
|
||||
HWTEST_F(TsCodeEmitterTest, Ready_048, TestSize.Level1)
|
||||
{
|
||||
EXPECT_EQ(PrepareIdlFile(UNKNOW_TYPE_IDL_NAME.c_str(), INOUT_NO_BIGPARANTHESES_IDL_CONTENT.c_str()), ERR_OK);
|
||||
int argc = 6;
|
||||
const char* argvArray[] = {"./idl", "-c", UNKNOW_TYPE_IDL_NAME.c_str(), "-gen-ts", "-d", "."};
|
||||
ParameterArgv parameters(argvArray, argc);
|
||||
EXPECT_NE(Ready(argc, parameters.GetArgv()), ERR_OK);
|
||||
}
|
||||
} // namespace ModuleTest
|
||||
} // namespace Idl
|
||||
} // namespace OHOS
|
23
test/ts/unittest/BUILD.gn
Normal file
23
test/ts/unittest/BUILD.gn
Normal file
@ -0,0 +1,23 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
"ts_code_emitter_interface_test:unittest",
|
||||
"ts_code_emitter_proxy_test:unittest",
|
||||
"ts_code_emitter_stub_test:unittest",
|
||||
]
|
||||
}
|
91
test/ts/unittest/ts_code_emitter_interface_test/BUILD.gn
Normal file
91
test/ts/unittest/ts_code_emitter_interface_test/BUILD.gn
Normal file
@ -0,0 +1,91 @@
|
||||
# Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/test.gni")
|
||||
|
||||
IDL_DIR = "../../../.."
|
||||
|
||||
config("idl_unittest_test_config") {
|
||||
include_dirs = [
|
||||
"../../common/",
|
||||
"${IDL_DIR}/",
|
||||
"//third_party/bounds_checking_function/include/",
|
||||
]
|
||||
}
|
||||
|
||||
common_sources = [
|
||||
"${IDL_DIR}/ast/ast_array_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_boolean_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_byte_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_char_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_double_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_float_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_integer_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_interface_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_list_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_long_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_map_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_method.cpp",
|
||||
"${IDL_DIR}/ast/ast_module.cpp",
|
||||
"${IDL_DIR}/ast/ast_namespace.cpp",
|
||||
"${IDL_DIR}/ast/ast_node.cpp",
|
||||
"${IDL_DIR}/ast/ast_parameter.cpp",
|
||||
"${IDL_DIR}/ast/ast_sequenceable_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_short_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_string_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_type.cpp",
|
||||
"${IDL_DIR}/ast/ast_void_type.cpp",
|
||||
]
|
||||
|
||||
common_sources += [
|
||||
"${IDL_DIR}/codegen/code_emitter.cpp",
|
||||
"${IDL_DIR}/codegen/code_generator.cpp",
|
||||
"${IDL_DIR}/codegen/cpp_code_emitter.cpp",
|
||||
"${IDL_DIR}/codegen/ts_code_emitter.cpp",
|
||||
]
|
||||
|
||||
common_sources += [
|
||||
"${IDL_DIR}/metadata/metadata_builder.cpp",
|
||||
"${IDL_DIR}/metadata/metadata_dumper.cpp",
|
||||
"${IDL_DIR}/metadata/metadata_reader.cpp",
|
||||
"${IDL_DIR}/metadata/metadata_serializer.cpp",
|
||||
]
|
||||
|
||||
common_sources += [
|
||||
"${IDL_DIR}/parser/lexer.cpp",
|
||||
"${IDL_DIR}/parser/parser.cpp",
|
||||
]
|
||||
|
||||
common_sources += [
|
||||
"${IDL_DIR}/util/file.cpp",
|
||||
"${IDL_DIR}/util/light_refcount_base.cpp",
|
||||
"${IDL_DIR}/util/logger.cpp",
|
||||
"${IDL_DIR}/util/options.cpp",
|
||||
"${IDL_DIR}/util/string.cpp",
|
||||
"${IDL_DIR}/util/string_builder.cpp",
|
||||
"${IDL_DIR}/util/string_pool.cpp",
|
||||
]
|
||||
module_output_path = "idl/ts_unittest"
|
||||
|
||||
ohos_unittest("ts_code_emitter_interface_test") {
|
||||
module_out_path = module_output_path
|
||||
configs = [ ":idl_unittest_test_config" ]
|
||||
sources = [ "ts_code_emitter_interface_test.cpp" ]
|
||||
sources += common_sources
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_static" ]
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
deps = [ ":ts_code_emitter_interface_test" ]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user