FLANG

check-data.h
1 //===-------lib/Semantics/check-data.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_CHECK_DATA_H_
10 #define FORTRAN_SEMANTICS_CHECK_DATA_H_
11
12 #include "flang/Common/interval.h"
13 #include "flang/Evaluate/fold-designator.h"
14 #include "flang/Evaluate/initial-image.h"
15 #include "flang/Semantics/expression.h"
16 #include "flang/Semantics/semantics.h"
17 #include <list>
18 #include <map>
19 #include <vector>
20
21 namespace Fortran::parser {
22 struct DataStmtRepeat;
23 struct DataStmtObject;
24 struct DataIDoObject;
25 class DataStmtImpliedDo;
26 struct DataStmtSet;
27 } // namespace Fortran::parser
28
29 namespace Fortran::semantics {
30
31 struct SymbolDataInitialization {
32 using Range = common::Interval<ConstantSubscript>;
33 explicit SymbolDataInitialization(std::size_t bytes) : image{bytes} {}
34 evaluate::InitialImage image;
35 std::list<Range> inits;
36 };
37
38 using DataInitializations = std::map<SymbolRef, SymbolDataInitialization>;
39
40 class DataChecker : public virtual BaseChecker {
41 public:
42 explicit DataChecker(SemanticsContext &context) : exprAnalyzer_{context} {}
43 void Leave(const parser::DataStmtObject &);
44 void Leave(const parser::DataIDoObject &);
45 void Enter(const parser::DataImpliedDo &);
46 void Leave(const parser::DataImpliedDo &);
47 void Leave(const parser::DataStmtSet &);
48
49 // After all DATA statements have been processed, converts their
50 // initializations into per-symbol static initializers.
51 void CompileDataInitializationsIntoInitializers();
52
53 private:
54 ConstantSubscript GetRepetitionCount(const parser::DataStmtRepeat &);
55 template <typename T> void CheckIfConstantSubscript(const T &);
56 void CheckSubscript(const parser::SectionSubscript &);
57 bool CheckAllSubscriptsInDataRef(const parser::DataRef &, parser::CharBlock);
58 void ConstructInitializer(const Symbol &, SymbolDataInitialization &);
59
60 DataInitializations inits_;
61 evaluate::ExpressionAnalyzer exprAnalyzer_;
62 bool currentSetHasFatalErrors_{false};
63 };
64 } // namespace Fortran::semantics
65 #endif // FORTRAN_SEMANTICS_CHECK_DATA_H_
Fortran::semantics::DataChecker
Definition: check-data.h:40
Fortran::parser::DataStmtRepeat
Definition: parse-tree.h:1426
Fortran::semantics::SemanticsContext
Definition: semantics.h:60
Fortran::parser::DataIDoObject
Definition: parse-tree.h:1440
Fortran::semantics::Symbol
Definition: symbol.h:479
Fortran::evaluate::InitialImage
Definition: initial-image.h:23
Fortran::semantics::BaseChecker
Definition: semantics.h:227
Fortran::parser::SectionSubscript
Definition: parse-tree.h:1595
Fortran::parser::CharBlock
Definition: char-block.h:28
Fortran::common::Interval
Definition: interval.h:22
Fortran::parser::DataStmtObject
Definition: parse-tree.h:1460
Fortran::evaluate::ExpressionAnalyzer
Definition: expression.h:101
Fortran::parser::DataStmtSet
Definition: parse-tree.h:1466
Fortran::semantics::SymbolDataInitialization
Definition: check-data.h:31
Fortran::parser::DataRef
Definition: parse-tree.h:1742
Fortran::parser
Definition: check-expression.h:19
Fortran::parser::DataImpliedDo
Definition: parse-tree.h:1452