systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
PortDecl.cpp
Go to the documentation of this file.
1#include "clang/AST/DeclCXX.h"
2
3#include "FindTemplateTypes.h"
4#include "PortDecl.h"
5#include "llvm/Support/Debug.h"
6
7#include "APIntUtils.h"
8
9using namespace systemc_clang;
10
12 // Only delete the template_type_
13 DEBUG_WITH_TYPE("DebugDestructors", llvm::dbgs() << "~PortDecl\n";);
14
15 if (template_type_ != nullptr) {
16 delete template_type_;
17 template_type_ = nullptr;
18 }
19 field_decl_ = nullptr;
20}
21
23 : port_name_{"NONE"},
24 template_type_{nullptr},
25 field_decl_{nullptr},
26 is_array_{false} {}
27
28PortDecl::PortDecl(const std::string &name, FindTemplateTypes *tt)
29 : port_name_{name},
30 template_type_{tt},
31 field_decl_{nullptr},
32 is_array_{false} {}
33
34PortDecl::PortDecl(const std::string &name, const clang::Decl *fd,
36 : port_name_{name},
37 template_type_{tt},
38 field_decl_{const_cast<clang::Decl *>(fd)},
39 is_array_{false} {}
40
49
50void PortDecl::addArraySize(llvm::APInt sz) { array_sizes_.push_back(sz); }
51
53
54bool PortDecl::getArrayType() const { return is_array_; }
55
57 if (const clang::FieldDecl *fd = getAsFieldDecl()) {
58 if (auto ptr_type = fd->getType().getTypePtr()) {
59 return ptr_type->isPointerType();
60 }
61 }
62
63 if (const clang::VarDecl *vd = getAsVarDecl()) {
64 if (auto ptr_type = vd->getType().getTypePtr()) {
65 return ptr_type->isPointerType();
66 }
67 }
68 return false;
69}
70
71void PortDecl::setModuleName(const std::string &name) { port_name_ = name; }
72
73std::vector<llvm::APInt> PortDecl::getArraySizes() const {
74 return array_sizes_;
75}
76
77std::string PortDecl::getName() const { return port_name_; }
78
79clang::FieldDecl *PortDecl::getAsFieldDecl() const {
80 return clang::dyn_cast<clang::FieldDecl>(field_decl_);
81}
82
83clang::VarDecl *PortDecl::getAsVarDecl() const {
84 return clang::dyn_cast<clang::VarDecl>(field_decl_);
85}
86
88
89std::string PortDecl::asString() const {
90 std::string str{};
91 std::string class_name{};
92 if (auto fd = getAsFieldDecl()) {
93 class_name = fd->getParent()->getName().str();
94 }
95
96 str += "signal_port_name: " + class_name + "::" + getName() + "\n";
97 str += "signal_port_arguments: " + template_type_->asString() + "\n";
98 if (getArrayType()) {
99 str += "is_array_type: true\n";
100 }
101 else {
102 str += "is_array_type: false\n";
103 }
104 if (isPointerType()) {
105 str += "is_pointer_type: true \n";
106 } else {
107 str += "is_pointer_type: false\n";
108 }
109
110 if (getArrayType()) {
111 str += "array_sizes: ";
112 for (const auto sz : getArraySizes()) {
113 std::size_t i{0};
114 // std::string s = systemc_clang::utils::apint::toString(sz);
115
117 }
118 }
119 str += "\n";
120
121 if (getAsFieldDecl()) {
122 str += "decl_type: FieldDecl";
123 } else {
124 if (getAsVarDecl()) {
125 str += "decl_type: VarDecl";
126 }
127 }
128
129 str += "\n";
130 return str;
131}
std::string asString()
Returns the TemplateType data as a std::string.
std::string port_name_
Name of the port.
Definition PortDecl.h:52
std::vector< llvm::APInt > array_sizes_
Definition PortDecl.h:61
clang::VarDecl * getAsVarDecl() const
Definition PortDecl.cpp:83
std::string getName() const
Definition PortDecl.cpp:77
bool getArrayType() const
Get parameters.
Definition PortDecl.cpp:54
std::string asString() const
Produce dump.
Definition PortDecl.cpp:89
void setModuleName(const std::string &)
Set parameters.
Definition PortDecl.cpp:71
void addArraySize(llvm::APInt size)
Definition PortDecl.cpp:50
clang::FieldDecl * getAsFieldDecl() const
Definition PortDecl.cpp:79
FindTemplateTypes * getTemplateType()
Definition PortDecl.cpp:87
bool is_array_
Is it an array type.
Definition PortDecl.h:60
clang::Decl * field_decl_
Definition PortDecl.h:57
std::vector< llvm::APInt > getArraySizes() const
Definition PortDecl.cpp:73
FindTemplateTypes * template_type_
This holds the types for the port declaration.
Definition PortDecl.h:54
bool isPointerType() const
Definition PortDecl.cpp:56
Clang forward declarations.
Definition FindArgument.h:6
std::string toString(const T &i)
Definition APIntUtils.h:14