• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 MAPLEIR_VERIFY_PRAGMA_INFO_H
17 #define MAPLEIR_VERIFY_PRAGMA_INFO_H
18 #include <string>
19 #include <utility>
20 
21 namespace maple {
22 enum PragmaInfoType { kThrowVerifyError, kAssignableCheck, kExtendFinalCheck, kOverrideFinalCheck };
23 
24 class VerifyPragmaInfo {
25 public:
26     VerifyPragmaInfo() = default;
27     ;
28     virtual ~VerifyPragmaInfo() = default;
29 
30     virtual PragmaInfoType GetPragmaType() const = 0;
IsEqualTo(const VerifyPragmaInfo & pragmaInfo)31     bool IsEqualTo(const VerifyPragmaInfo &pragmaInfo) const
32     {
33         return GetPragmaType() == pragmaInfo.GetPragmaType();
34     }
IsVerifyError()35     bool IsVerifyError() const
36     {
37         return GetPragmaType() == kThrowVerifyError;
38     }
IsAssignableCheck()39     bool IsAssignableCheck() const
40     {
41         return GetPragmaType() == kAssignableCheck;
42     }
IsExtendFinalCheck()43     bool IsExtendFinalCheck() const
44     {
45         return GetPragmaType() == kExtendFinalCheck;
46     }
IsOverrideFinalCheck()47     bool IsOverrideFinalCheck() const
48     {
49         return GetPragmaType() == kOverrideFinalCheck;
50     }
51 };
52 
53 class ThrowVerifyErrorPragma : public VerifyPragmaInfo {
54 public:
ThrowVerifyErrorPragma(std::string errorMessage)55     explicit ThrowVerifyErrorPragma(std::string errorMessage)
56         : VerifyPragmaInfo(), errorMessage(std::move(errorMessage))
57     {
58     }
59     ~ThrowVerifyErrorPragma() = default;
60 
GetPragmaType()61     PragmaInfoType GetPragmaType() const override
62     {
63         return kThrowVerifyError;
64     }
65 
GetMessage()66     const std::string &GetMessage() const
67     {
68         return errorMessage;
69     }
70 
71 private:
72     std::string errorMessage;
73 };
74 
75 class AssignableCheckPragma : public VerifyPragmaInfo {
76 public:
AssignableCheckPragma(std::string fromType,std::string toType)77     AssignableCheckPragma(std::string fromType, std::string toType)
78         : VerifyPragmaInfo(), fromType(std::move(fromType)), toType(std::move(toType))
79     {
80     }
81     ~AssignableCheckPragma() = default;
82 
GetPragmaType()83     PragmaInfoType GetPragmaType() const override
84     {
85         return kAssignableCheck;
86     }
87 
IsEqualTo(const AssignableCheckPragma & pragma)88     bool IsEqualTo(const AssignableCheckPragma &pragma) const
89     {
90         return fromType == pragma.GetFromType() && toType == pragma.GetToType();
91     }
92 
GetFromType()93     const std::string &GetFromType() const
94     {
95         return fromType;
96     }
97 
GetToType()98     const std::string &GetToType() const
99     {
100         return toType;
101     }
102 
103 private:
104     std::string fromType;
105     std::string toType;
106 };
107 
108 class ExtendFinalCheckPragma : public VerifyPragmaInfo {
109 public:
ExtendFinalCheckPragma()110     ExtendFinalCheckPragma() : VerifyPragmaInfo() {}
111     ~ExtendFinalCheckPragma() = default;
112 
GetPragmaType()113     PragmaInfoType GetPragmaType() const override
114     {
115         return kExtendFinalCheck;
116     }
117 };
118 
119 class OverrideFinalCheckPragma : public VerifyPragmaInfo {
120 public:
OverrideFinalCheckPragma()121     OverrideFinalCheckPragma() : VerifyPragmaInfo() {}
122     ~OverrideFinalCheckPragma() = default;
123 
GetPragmaType()124     PragmaInfoType GetPragmaType() const override
125     {
126         return kOverrideFinalCheck;
127     }
128 };
129 }  // namespace maple
130 #endif  // MAPLEIR_VERIFY_PRAGMA_INFO_H
131