9#ifndef FORTRAN_EVALUATE_INITIAL_IMAGE_H_
10#define FORTRAN_EVALUATE_INITIAL_IMAGE_H_
16#include "expression.h"
34 explicit InitialImage(std::size_t bytes) : data_(bytes) {}
37 std::size_t size()
const {
return data_.size(); }
44 Result
Add(ConstantSubscript offset, std::size_t bytes,
const Constant<T> &x,
46 if (offset < 0 || offset + bytes > data_.size()) {
49 auto elementBytes{ToInt64(x.GetType().MeasureSizeInBytes(context,
true))};
52 x.values().size() *
static_cast<std::size_t
>(*elementBytes)) {
54 }
else if (bytes == 0) {
58 std::memcpy(&data_.at(offset), &x.values().at(0), bytes);
64 Result
Add(ConstantSubscript offset, std::size_t bytes,
67 if (offset < 0 || offset + bytes > data_.size()) {
70 auto optElements{TotalElementCount(x.shape())};
74 auto elements{*optElements};
75 auto elementBytes{bytes > 0 ? bytes / elements : 0};
76 if (elements * elementBytes != bytes) {
78 }
else if (bytes == 0) {
82 for (
auto at{x.lbounds()}; elements-- > 0; x.IncrementSubscripts(at)) {
83 auto scalar{x.At(at)};
84 auto scalarBytes{scalar.size() * KIND};
85 if (scalarBytes != elementBytes) {
86 result = LengthMismatch;
89 for (; scalarBytes < elementBytes; scalarBytes += KIND) {
93 std::memcpy(&data_.at(offset), scalar.data(), elementBytes);
94 offset += elementBytes;
102 template <
typename T>
103 Result
Add(ConstantSubscript offset, std::size_t bytes,
const Expr<T> &x,
105 return common::visit(
106 [&](
const auto &y) {
return Add(offset, bytes, y, c); }, x.u);
111 void Incorporate(ConstantSubscript toOffset,
const InitialImage &from,
112 ConstantSubscript fromOffset, ConstantSubscript bytes);
116 const DynamicType &, std::optional<std::int64_t> charLength,
117 const ConstantSubscripts &,
bool padWithZero =
false,
118 ConstantSubscript offset = 0)
const;
119 std::optional<Expr<SomeType>> AsConstantPointer(
120 ConstantSubscript offset = 0)
const;
125 std::vector<char> data_;
126 std::map<ConstantSubscript, Expr<SomeType>> pointers_;
Definition: initial-image.cpp:73
Definition: constant.h:141
Definition: initial-image.h:23
Definition: expression.h:296