• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 OHOS_IDL_ASTPTRTYPE_H
17 #define OHOS_IDL_ASTPTRTYPE_H
18 
19 #include "ast/ast_type.h"
20 #include "lexer/token.h"
21 
22 namespace OHOS {
23 namespace Idl {
24 class ASTPtrType : public ASTType {
25 public:
ASTPtrType(TokenType type)26     ASTPtrType(TokenType type) : ASTType(false), elementType_()
27     {
28         switch (type) {
29             case TokenType::SHAREDPTR:
30                 typeKind_ = TypeKind::TYPE_SHAREDPTR;
31                 ptrTypeName_ = "std::shared_ptr";
32                 return;
33             case TokenType::UNIQUEPTR:
34                 typeKind_ = TypeKind::TYPE_UNIQUEPTR;
35                 ptrTypeName_ = "std::unique_ptr";
36                 return;
37             case TokenType::SPTR:
38                 typeKind_ = TypeKind::TYPE_SPTR;
39                 ptrTypeName_ = "sptr";
40                 return;
41             case TokenType::NULL_SHAREDPTR:
42                 typeKind_ = TypeKind::TYPE_NULL_SHAREDPTR;
43                 ptrTypeName_ = "std::nullshared_ptr";
44                 return;
45             case TokenType::NULL_UNIQUEPTR:
46                 typeKind_ = TypeKind::TYPE_NULL_UNIQUEPTR;
47                 ptrTypeName_ = "std::nullunique_ptr";
48                 return;
49             case TokenType::NULL_SPTR:
50                 typeKind_ = TypeKind::TYPE_NULL_SPTR;
51                 ptrTypeName_ = "nullsptr";
52                 return;
53             default:
54                 return;
55         }
56     }
57 
SetElementType(const AutoPtr<ASTType> & elementType)58     inline void SetElementType(const AutoPtr<ASTType> &elementType)
59     {
60         elementType_ = elementType;
61     }
62 
GetElementType()63     inline AutoPtr<ASTType> GetElementType()
64     {
65         return elementType_;
66     }
67 
68     std::string GetSignature() override;
69 
70     std::string ToString() const override;
71 
72     TypeKind GetTypeKind() override;
73 
74 protected:
75     AutoPtr<ASTType> elementType_;
76 
77 private:
78     TypeKind typeKind_;
79     std::string ptrTypeName_;
80 };
81 } // namespace Idl
82 } // namespace OHOS
83 
84 #endif // OHOS_IDL_ASTPTRTYPE_H