class ArraySpecAnalyzer {
public:
- ArraySpecAnalyzer(ArraySpec &arraySpec, SemanticsContext &context)
- : context_{context}, arraySpec_{arraySpec} {
- CHECK(arraySpec.empty());
- }
- void Analyze(const parser::ArraySpec &);
- void Analyze(const parser::CoarraySpec &);
+ ArraySpecAnalyzer(SemanticsContext &context) : context_{context} {}
+ ArraySpec Analyze(const parser::ArraySpec &);
+ ArraySpec Analyze(const parser::CoarraySpec &);
private:
SemanticsContext &context_;
- ArraySpec &arraySpec_;
+ ArraySpec arraySpec_;
template<typename T> void Analyze(const std::list<T> &list) {
for (const auto &elem : list) {
Bound GetBound(const parser::SpecificationExpr &);
};
-void AnalyzeArraySpec(ArraySpec &result, SemanticsContext &context,
- const parser::ArraySpec &arraySpec) {
- ArraySpecAnalyzer{result, context}.Analyze(arraySpec);
+ArraySpec AnalyzeArraySpec(
+ SemanticsContext &context, const parser::ArraySpec &arraySpec) {
+ return ArraySpecAnalyzer{context}.Analyze(arraySpec);
}
-void AnalyzeCoarraySpec(ArraySpec &result, SemanticsContext &context,
- const parser::CoarraySpec &coarraySpec) {
- ArraySpecAnalyzer{result, context}.Analyze(coarraySpec);
+ArraySpec AnalyzeCoarraySpec(
+ SemanticsContext &context, const parser::CoarraySpec &coarraySpec) {
+ return ArraySpecAnalyzer{context}.Analyze(coarraySpec);
}
-void ArraySpecAnalyzer::Analyze(const parser::ArraySpec &x) {
+ArraySpec ArraySpecAnalyzer::Analyze(const parser::ArraySpec &x) {
std::visit(
common::visitors{
[&](const parser::DeferredShapeSpecList &y) { MakeDeferred(y.v); },
[&](const auto &y) { Analyze(y); },
},
x.u);
+ return arraySpec_;
}
-void ArraySpecAnalyzer::Analyze(const parser::CoarraySpec &x) {
+ArraySpec ArraySpecAnalyzer::Analyze(const parser::CoarraySpec &x) {
std::visit(
common::visitors{
[&](const parser::DeferredCoshapeSpecList &y) { MakeDeferred(y.v); },
},
},
x.u);
+ return arraySpec_;
}
void ArraySpecAnalyzer::Analyze(const parser::AssumedShapeSpec &x) {
void Analyze(const parser::GenericSpec &);
};
-// Analyze a parser::ArraySpec or parser::CoarraySpec into the provide ArraySpec
-void AnalyzeArraySpec(
- ArraySpec &, SemanticsContext &, const parser::ArraySpec &);
-void AnalyzeCoarraySpec(
- ArraySpec &, SemanticsContext &, const parser::CoarraySpec &);
+// Analyze a parser::ArraySpec or parser::CoarraySpec
+ArraySpec AnalyzeArraySpec(SemanticsContext &, const parser::ArraySpec &);
+ArraySpec AnalyzeCoarraySpec(
+ SemanticsContext &context, const parser::CoarraySpec &);
}
// ArraySpecVisitor implementation
void ArraySpecVisitor::Post(const parser::ArraySpec &x) {
- AnalyzeArraySpec(arraySpec_, context(), x);
+ CHECK(arraySpec_.empty());
+ arraySpec_ = AnalyzeArraySpec(context(), x);
}
void ArraySpecVisitor::Post(const parser::CoarraySpec &x) {
- AnalyzeCoarraySpec(coarraySpec_, context(), x);
+ CHECK(coarraySpec_.empty());
+ coarraySpec_ = AnalyzeCoarraySpec(context(), x);
}
const ArraySpec &ArraySpecVisitor::arraySpec() {