@@ -4506,14 +4506,34 @@ class ArrayExprLowering {
4506
4506
TODO (getLoc (), " genarr ComplexConstructor<KIND>" );
4507
4507
}
4508
4508
4509
+ // / Fortran's concatenation operator `//`.
4509
4510
template <int KIND>
4510
4511
CC genarr (const Fortran::evaluate::Concat<KIND> &x) {
4511
- TODO (getLoc (), " genarr Concat<KIND>" );
4512
+ mlir::Location loc = getLoc ();
4513
+ auto lf = genarr (x.left ());
4514
+ auto rf = genarr (x.right ());
4515
+ return [=](IterSpace iters) -> ExtValue {
4516
+ auto lhs = lf (iters);
4517
+ auto rhs = rf (iters);
4518
+ const fir::CharBoxValue *lchr = lhs.getCharBox ();
4519
+ const fir::CharBoxValue *rchr = rhs.getCharBox ();
4520
+ if (lchr && rchr) {
4521
+ return fir::factory::CharacterExprHelper{builder, loc}
4522
+ .createConcatenate (*lchr, *rchr);
4523
+ }
4524
+ TODO (loc, " concat on unexpected extended values" );
4525
+ return mlir::Value{};
4526
+ };
4512
4527
}
4513
4528
4514
4529
template <int KIND>
4515
4530
CC genarr (const Fortran::evaluate::SetLength<KIND> &x) {
4516
- TODO (getLoc (), " genarr SetLength<KIND>" );
4531
+ auto lf = genarr (x.left ());
4532
+ mlir::Value rhs = fir::getBase (asScalar (x.right ()));
4533
+ return [=](IterSpace iters) -> ExtValue {
4534
+ mlir::Value lhs = fir::getBase (lf (iters));
4535
+ return fir::CharBoxValue{lhs, rhs};
4536
+ };
4517
4537
}
4518
4538
4519
4539
template <typename A>
@@ -5707,8 +5727,32 @@ class ArrayExprLowering {
5707
5727
};
5708
5728
}
5709
5729
5730
+ // / Lower a component path with or without rank.
5731
+ // / Example: <code>array%baz%qux%waldo</code>
5710
5732
CC genarr (const Fortran::evaluate::Component &x, ComponentPath &components) {
5711
- TODO (getLoc (), " genarr Component" );
5733
+ if (explicitSpaceIsActive ()) {
5734
+ if (x.base ().Rank () == 0 && x.Rank () > 0 )
5735
+ components.reversePath .push_back (ImplicitSubscripts{});
5736
+ if (fir::ArrayLoadOp load = explicitSpace->findBinding (&x))
5737
+ return applyPathToArrayLoad (load, components);
5738
+ } else {
5739
+ if (x.base ().Rank () == 0 )
5740
+ return genImplicitArrayAccess (x, components);
5741
+ }
5742
+ bool atEnd = pathIsEmpty (components);
5743
+ if (!getLastSym (x).test (Fortran::semantics::Symbol::Flag::ParentComp))
5744
+ // Skip parent components; their components are placed directly in the
5745
+ // object.
5746
+ components.reversePath .push_back (&x);
5747
+ auto result = genarr (x.base (), components);
5748
+ if (components.applied )
5749
+ return result;
5750
+ if (atEnd)
5751
+ return genAsScalar (x);
5752
+ mlir::Location loc = getLoc ();
5753
+ return [=](IterSpace) -> ExtValue {
5754
+ fir::emitFatalError (loc, " reached component with path" );
5755
+ };
5712
5756
}
5713
5757
5714
5758
// / Array reference with subscripts. If this has rank > 0, this is a form
@@ -5910,7 +5954,8 @@ class ArrayExprLowering {
5910
5954
5911
5955
CC genarr (const Fortran::evaluate::ComplexPart &x,
5912
5956
ComponentPath &components) {
5913
- TODO (getLoc (), " genarr ComplexPart" );
5957
+ components.reversePath .push_back (&x);
5958
+ return genarr (x.complex (), components);
5914
5959
}
5915
5960
5916
5961
CC genarr (const Fortran::evaluate::StaticDataObject::Pointer &,
@@ -5920,7 +5965,9 @@ class ArrayExprLowering {
5920
5965
5921
5966
// / Substrings (see 9.4.1)
5922
5967
CC genarr (const Fortran::evaluate::Substring &x, ComponentPath &components) {
5923
- TODO (getLoc (), " genarr Substring" );
5968
+ components.substring = &x;
5969
+ return std::visit ([&](const auto &v) { return genarr (v, components); },
5970
+ x.parent ());
5924
5971
}
5925
5972
5926
5973
// / Base case of generating an array reference,
0 commit comments