Skip to content

Commit f713aab

Browse files
Merge branch '77_array_params' into main
2 parents 97dcf32 + 360490a commit f713aab

File tree

5 files changed

+81
-22
lines changed

5 files changed

+81
-22
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ add_subdirectory(test/imath)
4444
# add_subdirectory(test/openexr)
4545
add_subdirectory(test/oiio)
4646
add_subdirectory(test/usd)
47+
add_subdirectory(test/array_params)

astgen/src/process_binding.cpp

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,32 @@ NodeId process_function_proto_type(const FunctionProtoType* fpt,
10741074
/// Create a QType from the given QualType. Recursively processes the contained
10751075
/// types.
10761076
QType process_qtype(const QualType& qt) {
1077-
if (qt->isPointerType() || qt->isReferenceType()) {
1077+
if (const auto* dt = qt->getAs<DecayedType>()) {
1078+
// if it's a decayed type, get back the original type
1079+
const auto ot = dt->getOriginalType();
1080+
return process_qtype(ot);
1081+
} else if (qt->isConstantArrayType()) {
1082+
// e.g. float[3]
1083+
const std::string type_name = qt.getCanonicalType().getAsString();
1084+
const std::string type_node_name = "TYPE:" + type_name;
1085+
auto it = NODE_MAP.find(type_node_name);
1086+
NodeId id;
1087+
if (it == NODE_MAP.end()) {
1088+
const ConstantArrayType* cat =
1089+
dyn_cast<ConstantArrayType>(qt.getTypePtr());
1090+
QType element_type = process_qtype(cat->getElementType());
1091+
id = NODES.size();
1092+
auto node_type = std::make_unique<NodeConstantArrayType>(
1093+
type_node_name, id, 0, type_name, element_type,
1094+
cat->getSize().getLimitedValue());
1095+
NODES.emplace_back(std::move(node_type));
1096+
NODE_MAP[type_node_name] = id;
1097+
} else {
1098+
id = it->second;
1099+
}
1100+
1101+
return QType{id, qt.isConstQualified()};
1102+
} else if (qt->isPointerType() || qt->isReferenceType()) {
10781103
// first, figure out what kind of pointer we have
10791104
auto pointer_kind = PointerKind::Pointer;
10801105
if (qt->isRValueReferenceType()) {
@@ -1106,27 +1131,6 @@ QType process_qtype(const QualType& qt) {
11061131
id = it->second;
11071132
}
11081133

1109-
return QType{id, qt.isConstQualified()};
1110-
} else if (qt->isConstantArrayType()) {
1111-
// e.g. float[3]
1112-
const std::string type_name = qt.getCanonicalType().getAsString();
1113-
const std::string type_node_name = "TYPE:" + type_name;
1114-
auto it = NODE_MAP.find(type_node_name);
1115-
NodeId id;
1116-
if (it == NODE_MAP.end()) {
1117-
const ConstantArrayType* cat =
1118-
dyn_cast<ConstantArrayType>(qt.getTypePtr());
1119-
QType element_type = process_qtype(cat->getElementType());
1120-
id = NODES.size();
1121-
auto node_type = std::make_unique<NodeConstantArrayType>(
1122-
type_node_name, id, 0, type_name, element_type,
1123-
cat->getSize().getLimitedValue());
1124-
NODES.emplace_back(std::move(node_type));
1125-
NODE_MAP[type_node_name] = id;
1126-
} else {
1127-
id = it->second;
1128-
}
1129-
11301134
return QType{id, qt.isConstQualified()};
11311135
} else {
11321136
// regular type, let's get a nice name for it by removing the

test/array_params/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
set(testname array_params)
2+
3+
add_test(NAME ${testname}
4+
COMMAND
5+
python
6+
${CMAKE_SOURCE_DIR}/test/runtest.py
7+
$<TARGET_FILE:astgen>
8+
$<TARGET_FILE:asttoc>
9+
${CMAKE_CURRENT_SOURCE_DIR}/bind
10+
${CMAKE_BINARY_DIR}/test/${testname}/output
11+
${testname}
12+
${CMAKE_CURRENT_SOURCE_DIR}/ref
13+
-I${CMAKE_CURRENT_SOURCE_DIR}/include
14+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
15+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <array_params.hpp>
2+
3+
#include <cppmm_bind.hpp>
4+
5+
namespace cppmm_bind {
6+
7+
namespace imath {
8+
9+
template <typename T> struct Matrix44 {
10+
using BoundType = ::imath::Matrix44<T>;
11+
12+
Matrix44(const T a[4][4]) CPPMM_RENAME(from_array);
13+
} CPPMM_VALUETYPE;
14+
15+
template class Matrix44<float>;
16+
using M44f = ::imath::Matrix44<float>;
17+
18+
} // namespace imath
19+
20+
} // namespace cppmm_bind
21+
22+
template class imath::Matrix44<float>;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
namespace imath {
4+
5+
template <typename T> struct Matrix44 {
6+
T data[4][4];
7+
8+
Matrix44(const T a[4][4]) {
9+
for (int r = 0; r < 4; ++r) {
10+
for (int c = 0; c < 4; ++c) {
11+
data[r][c] = a[r][c];
12+
}
13+
}
14+
}
15+
};
16+
17+
} // namespace imath

0 commit comments

Comments
 (0)