• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_attribute.h"
13 #include "ast/ast_node.h"
14 #include "ast/ast_type.h"
15 #include "util/autoptr.h"
16 
17 namespace OHOS {
18 namespace HDI {
19 class ASTParameter : public ASTNode {
20 public:
ASTParameter(const std::string & name,ParamAttr attribute,const AutoPtr<ASTType> & type)21     ASTParameter(const std::string &name, ParamAttr attribute, const AutoPtr<ASTType> &type)
22         : ASTNode(), name_(name), attr_(new ASTParamAttr(attribute)), type_(type)
23     {
24     }
25 
ASTParameter(const std::string & name,const AutoPtr<ASTParamAttr> & attribute,const AutoPtr<ASTType> & type)26     ASTParameter(const std::string &name, const AutoPtr<ASTParamAttr> &attribute, const AutoPtr<ASTType> &type)
27         : ASTNode(), name_(name), attr_(attribute), type_(type)
28     {
29     }
30 
GetName()31     inline std::string GetName()
32     {
33         return name_;
34     }
35 
GetType()36     inline AutoPtr<ASTType> GetType()
37     {
38         return type_;
39     }
40 
GetAttribute()41     inline ParamAttr GetAttribute()
42     {
43         return attr_->value_;
44     }
45 
46     std::string Dump(const std::string &prefix) override;
47 
48     std::string EmitCParameter();
49 
50     std::string EmitCppParameter();
51 
52     std::string EmitJavaParameter();
53 
54     std::string EmitCLocalVar();
55 
56     std::string EmitCppLocalVar();
57 
58     std::string EmitJavaLocalVar() const;
59 
60     void EmitCWriteVar(const std::string &parcelName, const std::string &ecName, const std::string &gotoLabel,
61         StringBuilder &sb, const std::string &prefix) const;
62 
63     bool EmitCProxyWriteOutVar(const std::string &parcelName, const std::string &ecName, const std::string &gotoLabel,
64         StringBuilder &sb, const std::string &prefix) const;
65 
66     void EmitCStubReadOutVar(const std::string &buffSizeName, const std::string &memFlagName,
67         const std::string &parcelName, const std::string &ecName, const std::string &gotoLabel, StringBuilder &sb,
68         const std::string &prefix) const;
69 
70     void EmitJavaWriteVar(const std::string &parcelName, StringBuilder &sb, const std::string &prefix) const;
71 
72     void EmitJavaReadVar(const std::string &parcelName, StringBuilder &sb, const std::string &prefix) const;
73 
74 private:
75     std::string name_;
76     AutoPtr<ASTParamAttr> attr_;
77     AutoPtr<ASTType> type_;
78 };
79 } // namespace HDI
80 } // namespace OHOS
81 
82 #endif // OHOS_HDI_ASTPARAMETER_H