1 /**
2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "types/scope.h"
17
18 #include "libpandabase/utils/json_builder.h"
19
20 namespace ark::tooling::inspector {
GetTypeString(Scope::Type type)21 static const char *GetTypeString(Scope::Type type)
22 {
23 switch (type) {
24 case Scope::Type::GLOBAL:
25 return "global";
26 case Scope::Type::LOCAL:
27 return "local";
28 default:
29 UNREACHABLE();
30 return nullptr;
31 }
32 }
33
Scope(Scope::Type type,RemoteObject object,std::optional<std::string> name)34 Scope::Scope(Scope::Type type, RemoteObject object, std::optional<std::string> name)
35 : type_(type), object_(std::move(object)), name_(std::move(name))
36 {
37 }
38
Serialize(JsonObjectBuilder & builder) const39 void Scope::Serialize(JsonObjectBuilder &builder) const
40 {
41 builder.AddProperty("type", GetTypeString(type_));
42 builder.AddProperty("object", object_);
43 if (name_) {
44 builder.AddProperty("name", *name_);
45 }
46 }
47 } // namespace ark::tooling::inspector
48