• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-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 "verification/public_internal.h"
17 #include "verification/config/process/config_process.h"
18 #include "verification/config/options/method_group_parser.h"
19 #include "verification/util/parser/parser.h"
20 
21 #include "verifier_messages.h"
22 
23 #include "runtime/include/mem/panda_string.h"
24 
25 #include "literal_parser.h"
26 
27 #include "runtime/include/method.h"
28 #include "runtime/include/runtime.h"
29 
30 #include "utils/logger.h"
31 
32 #include <string>
33 #include <cstring>
34 #include <cstdint>
35 #include <unordered_map>
36 
37 #include <type_traits>
38 
39 namespace ark::verifier::debug {
40 
41 using ark::parser::Parser;
42 using ark::verifier::config::Section;
43 
RegisterConfigHandlerMethodGroups(Config * dcfg)44 void RegisterConfigHandlerMethodGroups(Config *dcfg)
45 {
46     static const auto CONFIG_DEBUG_METHOD_GROUPS_VERIFIER_OPTIONS = [](Config *cfg, const Section &section) {
47         auto &verifOptions = cfg->opts;
48 
49         for (const auto &item : section.items) {
50             struct Context {
51                 PandaString group;
52                 PandaString options;
53             };
54 
55             using P = Parser<Context, const char, const char *>;
56             const auto ws = P::OfCharset(" \t");
57 
58             const auto groupHandler = [](Context &c, PandaString &&group) {
59                 c.group = std::move(group);
60                 return true;
61             };
62 
63             const auto optionsHandler = [](Context &c, PandaString &&options) {
64                 c.options = std::move(options);
65                 return true;
66             };
67 
68             const auto line =
69                 ~ws >> MethodGroupParser<P>(groupHandler) >> ws >> LiteralParser<P>(optionsHandler) >> ~ws >> P::End();
70 
71             const char *start = item.c_str();
72             const char *end = item.c_str() + item.length();  // NOLINT
73 
74             Context ctx;
75 
76             if (!line(ctx, start, end)) {
77                 LOG(DEBUG, VERIFIER) << "  Error: cannot parse config line '" << item << "'";
78                 return false;
79             }
80 
81             if (!verifOptions.debug.GetMethodOptions().AddOptionsForGroup(ctx.group, ctx.options)) {
82                 LOG(DEBUG, VERIFIER) << "  Error: cannot set options for method group '" << ctx.group << "', options '"
83                                      << ctx.options << "'";
84                 return false;
85             }
86 
87             LOG(DEBUG, VERIFIER) << "  Set options for method group '" << ctx.group << "' : '" << ctx.options << "'";
88         }
89 
90         return true;
91     };
92 
93     config::RegisterConfigHandler(dcfg, "config.debug.method_groups.verifier.options",
94                                   CONFIG_DEBUG_METHOD_GROUPS_VERIFIER_OPTIONS);
95 }
96 
97 }  // namespace ark::verifier::debug
98