@@ -81,18 +81,19 @@ class TypeAndShape {
81
81
bool operator !=(const TypeAndShape &that) const { return !(*this == that); }
82
82
83
83
static std::optional<TypeAndShape> Characterize (
84
- const semantics::Symbol &, FoldingContext &, bool invariantOnly = false );
84
+ const semantics::Symbol &, FoldingContext &, bool invariantOnly = true );
85
85
static std::optional<TypeAndShape> Characterize (
86
86
const semantics::DeclTypeSpec &, FoldingContext &,
87
- bool invariantOnly = false );
87
+ bool invariantOnly = true );
88
88
static std::optional<TypeAndShape> Characterize (
89
- const ActualArgument &, FoldingContext &, bool invariantOnly = false );
89
+ const ActualArgument &, FoldingContext &, bool invariantOnly = true );
90
90
91
91
// General case for Expr<T>, &c.
92
92
template <typename A>
93
93
static std::optional<TypeAndShape> Characterize (
94
- const A &x, FoldingContext &context, bool invariantOnly = false ) {
95
- if (const auto *symbol{UnwrapWholeSymbolDataRef (x)}) {
94
+ const A &x, FoldingContext &context, bool invariantOnly = true ) {
95
+ const auto *symbol{UnwrapWholeSymbolOrComponentDataRef (x)};
96
+ if (symbol && !symbol->owner ().IsDerivedType ()) { // Whole variable
96
97
if (auto result{Characterize (*symbol, context, invariantOnly)}) {
97
98
return result;
98
99
}
@@ -106,6 +107,9 @@ class TypeAndShape {
106
107
}
107
108
}
108
109
}
110
+ if (symbol) { // component
111
+ result.AcquireAttrs (*symbol);
112
+ }
109
113
return std::move (result.Rewrite (context));
110
114
}
111
115
return std::nullopt;
@@ -116,15 +120,21 @@ class TypeAndShape {
116
120
static std::optional<TypeAndShape> Characterize (
117
121
const Designator<Type<TypeCategory::Character, KIND>> &x,
118
122
FoldingContext &context, bool invariantOnly = true ) {
119
- if (const auto *symbol{UnwrapWholeSymbolDataRef (x)}) {
123
+ const auto *symbol{UnwrapWholeSymbolOrComponentDataRef (x)};
124
+ if (symbol && !symbol->owner ().IsDerivedType ()) { // Whole variable
120
125
if (auto result{Characterize (*symbol, context, invariantOnly)}) {
121
126
return result;
122
127
}
123
128
}
124
129
if (auto type{x.GetType ()}) {
125
130
TypeAndShape result{*type, GetShape (context, x, invariantOnly)};
126
- if (auto length{x.LEN ()}) {
127
- result.set_LEN (std::move (*length));
131
+ if (type->category () == TypeCategory::Character) {
132
+ if (auto length{x.LEN ()}) {
133
+ result.set_LEN (std::move (*length));
134
+ }
135
+ }
136
+ if (symbol) { // component
137
+ result.AcquireAttrs (*symbol);
128
138
}
129
139
return std::move (result.Rewrite (context));
130
140
}
@@ -133,7 +143,7 @@ class TypeAndShape {
133
143
134
144
template <typename A>
135
145
static std::optional<TypeAndShape> Characterize (const std::optional<A> &x,
136
- FoldingContext &context, bool invariantOnly = false ) {
146
+ FoldingContext &context, bool invariantOnly = true ) {
137
147
if (x) {
138
148
return Characterize (*x, context, invariantOnly);
139
149
} else {
@@ -142,7 +152,7 @@ class TypeAndShape {
142
152
}
143
153
template <typename A>
144
154
static std::optional<TypeAndShape> Characterize (
145
- A *ptr, FoldingContext &context, bool invariantOnly = false ) {
155
+ A *ptr, FoldingContext &context, bool invariantOnly = true ) {
146
156
if (ptr) {
147
157
return Characterize (std::as_const (*ptr), context, invariantOnly);
148
158
} else {
0 commit comments