[Target] Use range-based for loops (NFC)
[llvm-project.git] / flang / lib / Semantics / data-to-inits.h
blobd8cc4601de26fa9ef6eedf67a2a26511b8176e3a
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 //===----------------------------------------------------------------------===//
9 #ifndef FORTRAN_SEMANTICS_DATA_TO_INITS_H_
10 #define FORTRAN_SEMANTICS_DATA_TO_INITS_H_
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>
19 namespace Fortran::parser {
20 struct DataStmtSet;
21 struct DataStmtValue;
22 } // namespace Fortran::parser
23 namespace Fortran::evaluate {
24 class ExpressionAnalyzer;
26 namespace Fortran::semantics {
28 class Symbol;
30 struct SymbolDataInitialization {
31 using Range = common::Interval<common::ConstantSubscript>;
32 explicit SymbolDataInitialization(std::size_t bytes) : image{bytes} {}
33 SymbolDataInitialization(SymbolDataInitialization &&) = default;
35 void NoteInitializedRange(Range range) {
36 if (initializedRanges.empty() ||
37 !initializedRanges.back().AnnexIfPredecessor(range)) {
38 initializedRanges.emplace_back(range);
41 void NoteInitializedRange(
42 common::ConstantSubscript offset, std::size_t size) {
43 NoteInitializedRange(Range{offset, size});
45 void NoteInitializedRange(evaluate::OffsetSymbol offsetSymbol) {
46 NoteInitializedRange(offsetSymbol.offset(), offsetSymbol.size());
49 evaluate::InitialImage image;
50 std::list<Range> initializedRanges;
53 using DataInitializations = std::map<const Symbol *, SymbolDataInitialization>;
55 // Matches DATA statement variables with their values and checks
56 // compatibility.
57 void AccumulateDataInitializations(DataInitializations &,
58 evaluate::ExpressionAnalyzer &, const parser::DataStmtSet &);
60 // For legacy DATA-style initialization extension: integer n(2)/1,2/
61 void AccumulateDataInitializations(DataInitializations &,
62 evaluate::ExpressionAnalyzer &, const Symbol &,
63 const std::list<common::Indirection<parser::DataStmtValue>> &);
65 void ConvertToInitializers(
66 DataInitializations &, evaluate::ExpressionAnalyzer &);
68 } // namespace Fortran::semantics
69 #endif // FORTRAN_SEMANTICS_DATA_TO_INITS_H_