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#ifndef PANDA_VERIFIER_COMPAT_CHECKS_HPP_ 17#define PANDA_VERIFIER_COMPAT_CHECKS_HPP_ 18 19#include "verification/verification_status.h" 20#include "verification/type/type_system.h" 21#include "verification/util/str.h" 22 23% checks = Verification.compatibility_checks 24namespace ark::verifier { 25struct CheckResult { 26 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) 27 VerificationStatus status; 28 // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) 29 const char* msg; 30 31 bool IsOk() const { 32 return status == VerificationStatus::OK; 33 } 34 bool IsWarning() const { 35 return status == VerificationStatus::WARNING; 36 } 37 bool IsError() const { 38 return status == VerificationStatus::ERROR; 39 } 40 41% checks.results.ok.to_h.merge(checks.results.warnings.to_h).merge(checks.results.errors.to_h).each do |name, _| 42 // NOLINTNEXTLINE(readability-identifier-naming) 43 static const CheckResult <%= name.to_s %>; 44% end 45}; 46 47% checks.results.each_pair do |status, values| 48% values.each_pair do |name, msg| 49inline const CheckResult CheckResult::<%= name.to_s %> = {VerificationStatus::<%= status.to_s.delete_suffix('s').upcase %>, "<%= msg %>"}; 50% end 51% end 52 53% checks.domains.each_pair do |_, domain| 54% if domain.new_enum 55enum class <%= domain.new_enum %> { 56% domain.values.each do |value| 57 <%= value.upcase %>, 58% end 59}; 60 61% end 62% end 63% checks.checks.each_pair do |check_name, check| 64% type1, type2 = Verification.domain_types(check) 65inline const CheckResult& Check<%= check_name.to_s %>(<%= type1 %> x, <%= type2 %> y) { 66 // NOLINTNEXTLINE(hicpp-multiway-paths-covered) 67 switch(x) { 68% check.each_pair do |name, value| 69% name = name.to_s 70% if !name.start_with?('_') # those are special like _domains and _default 71 case <%= type1 %>::<%= name.upcase %>: 72 // NOLINTNEXTLINE(hicpp-multiway-paths-covered) 73 switch(y) { 74% value.each_pair do |name2, value2| 75% name2 = name2.to_s 76% if !name2.start_with?('_') 77% Array(value2).each do |value2| 78 case <%= type2 %>::<%= value2.upcase %>: 79% end 80 return CheckResult::<%= name2 %>; 81% end 82% end 83 default: 84 return CheckResult::<%= value._default || check._default %>; 85 } 86% end 87% end 88 default: 89 return CheckResult::<%= check._default %>; 90 } 91} 92% end 93 94} // namespace ark::verifier 95 96#endif // PANDA_VERIFIER_COMPAT_CHECKS_HPP_ 97