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