• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef OHOS_HDI_ASTPARAMETER_H
10 #define OHOS_HDI_ASTPARAMETER_H
11 
12 #include "ast/ast_node.h"
13 #include "ast/ast_type.h"
14 #include "util/autoptr.h"
15 #include "util/string.h"
16 
17 namespace OHOS {
18 namespace HDI {
19 // parameter attribute
20 enum class ParamAttr {
21     PARAM_IN,
22     PARAM_OUT,
23 };
24 
25 class ASTParameter : public ASTNode {
26 public:
ASTParameter()27     ASTParameter() : ASTNode() {}
ASTParameter(const String & name,ParamAttr attribute,const AutoPtr<ASTType> & type)28     ASTParameter(const String& name, ParamAttr attribute, const AutoPtr<ASTType>& type)
29         : ASTNode(), name_(name), attribute_(attribute), type_(type) {}
30 
SetName(const String & name)31     inline void SetName(const String& name)
32     {
33         name_ = name;
34     }
35 
GetName()36     inline String GetName()
37     {
38         return name_;
39     }
40 
SetType(const AutoPtr<ASTType> & type)41     inline void SetType(const AutoPtr<ASTType>& type)
42     {
43         type_ = type;
44     }
45 
GetType()46     inline AutoPtr<ASTType> GetType()
47     {
48         return type_;
49     }
50 
SetAttribute(ParamAttr attribute)51     inline void SetAttribute(ParamAttr attribute)
52     {
53         attribute_ = attribute;
54     }
55 
GetAttribute()56     inline ParamAttr GetAttribute()
57     {
58         return attribute_;
59     }
60 
61     String Dump(const String& prefix) override;
62 
63     String EmitCParameter();
64 
65     String EmitCppParameter();
66 
67     String EmitJavaParameter();
68 
69     String EmitCLocalVar();
70 
71     String EmitCppLocalVar();
72 
73     String EmitJavaLocalVar();
74 
75     void EmitCWriteVar(const String& parcelName, const String& ecName, const String& gotoLabel, StringBuilder& sb,
76         const String& prefix) const;
77 
78     bool EmitCProxyWriteOutVar(const String& parcelName, const String& ecName, const String& gotoLabel,
79         StringBuilder& sb, const String& prefix) const;
80 
81     bool EmitCStubReadOutVar(const String& parcelName, const String& ecName, const String& gotoLabel,
82         StringBuilder& sb, const String& prefix) const;
83 
84     void EmitJavaWriteVar(const String& parcelName, StringBuilder& sb, const String& prefix) const;
85 
86     void EmitJavaReadVar(const String& parcelName, StringBuilder& sb, const String& prefix) const;
87 private:
88     String name_;
89     AutoPtr<ASTType> type_ = nullptr;
90     ParamAttr attribute_ = ParamAttr::PARAM_IN;
91 };
92 } // namespace HDI
93 } // namespace OHOS
94 
95 #endif // OHOS_HDI_ASTPARAMETER_H