1//===-- lib/Semantics/data-to-inits.h -------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef FORTRAN_SEMANTICS_DATA_TO_INITS_H_
10#define FORTRAN_SEMANTICS_DATA_TO_INITS_H_
11
12#include "flang/Common/default-kinds.h"
13#include "flang/Common/interval.h"
14#include "flang/Evaluate/fold-designator.h"
15#include "flang/Evaluate/initial-image.h"
16#include <list>
17#include <map>
18
19namespace Fortran::parser {
20struct DataStmtSet;
21struct DataStmtValue;
22} // namespace Fortran::parser
23namespace Fortran::evaluate {
24class ExpressionAnalyzer;
25}
26namespace Fortran::semantics {
27
28class Symbol;
29
30struct SymbolDataInitialization {
31 using Range = common::Interval<common::ConstantSubscript>;
32 explicit SymbolDataInitialization(std::size_t bytes) : image{bytes} {}
33 SymbolDataInitialization(SymbolDataInitialization &&) = default;
34
35 void NoteInitializedRange(Range range) {
36 if (initializedRanges.empty() ||
37 !initializedRanges.back().AnnexIfPredecessor(range)) {
38 initializedRanges.emplace_back(range);
39 }
40 }
41 void NoteInitializedRange(
42 common::ConstantSubscript offset, std::size_t size) {
43 NoteInitializedRange(Range{offset, size});
44 }
45 void NoteInitializedRange(evaluate::OffsetSymbol offsetSymbol) {
46 NoteInitializedRange(offsetSymbol.offset(), offsetSymbol.size());
47 }
48
49 evaluate::InitialImage image;
50 std::list<Range> initializedRanges;
51};
52
53using DataInitializations = std::map<const Symbol *, SymbolDataInitialization>;
54
55// Matches DATA statement variables with their values and checks
56// compatibility.
57void AccumulateDataInitializations(DataInitializations &,
58 evaluate::ExpressionAnalyzer &, const parser::DataStmtSet &);
59
60// For legacy DATA-style initialization extension: integer n(2)/1,2/
61void AccumulateDataInitializations(DataInitializations &,
62 evaluate::ExpressionAnalyzer &, const Symbol &,
63 const std::list<common::Indirection<parser::DataStmtValue>> &);
64
65void ConvertToInitializers(
66 DataInitializations &, evaluate::ExpressionAnalyzer &);
67
68} // namespace Fortran::semantics
69#endif // FORTRAN_SEMANTICS_DATA_TO_INITS_H_
70

source code of flang/lib/Semantics/data-to-inits.h