2020-02-25 23:11:52 +08:00
|
|
|
//===-------lib/Semantics/check-data.h ------------------------------------===//
|
2020-02-21 14:19:14 +08:00
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef FORTRAN_SEMANTICS_CHECK_DATA_H_
|
|
|
|
#define FORTRAN_SEMANTICS_CHECK_DATA_H_
|
|
|
|
|
2020-06-20 00:16:21 +08:00
|
|
|
#include "flang/Common/interval.h"
|
|
|
|
#include "flang/Evaluate/fold-designator.h"
|
|
|
|
#include "flang/Evaluate/initial-image.h"
|
Rework DATA statement semantics to use typed expressions
Summary:
Updates recent work on DATA statement semantic checking in
flang/lib/Semantics/check-data.{h,cpp} to use the compiler's
internal representation for typed expressions rather than working
on the raw parse tree. Saves the analyzed expressions for DATA
statement values as parse tree decorations because they'll soon be
needed in lowering. Corrects wording of some error messages.
Fixes a bug in constant expression checking: structure constructors
are not constant expressions if they set an allocatable component
to anything other than NULL.
Includes infrastructure changes to make this work, some renaming
to reflect the fact that the implied DO loop indices tracked by
expression analysis are not (just) from array constructors, remove
some dead code, and improve some comments.
Reviewers: tskeith, sscalpone, jdoerfert, DavidTruby, anchu-rajendran, schweitz
Reviewed By: tskeith, anchu-rajendran, schweitz
Subscribers: llvm-commits, flang-commits
Tags: #flang, #llvm
Differential Revision: https://reviews.llvm.org/D78834
2020-04-25 04:54:11 +08:00
|
|
|
#include "flang/Semantics/expression.h"
|
2020-02-25 23:11:52 +08:00
|
|
|
#include "flang/Semantics/semantics.h"
|
2020-06-20 00:16:21 +08:00
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace Fortran::parser {
|
|
|
|
struct DataStmtRepeat;
|
|
|
|
struct DataStmtObject;
|
|
|
|
struct DataIDoObject;
|
|
|
|
class DataStmtImpliedDo;
|
|
|
|
struct DataStmtSet;
|
|
|
|
} // namespace Fortran::parser
|
2020-02-21 14:19:14 +08:00
|
|
|
|
|
|
|
namespace Fortran::semantics {
|
2020-06-20 00:16:21 +08:00
|
|
|
|
|
|
|
struct SymbolDataInitialization {
|
|
|
|
using Range = common::Interval<ConstantSubscript>;
|
|
|
|
explicit SymbolDataInitialization(std::size_t bytes) : image{bytes} {}
|
|
|
|
evaluate::InitialImage image;
|
|
|
|
std::list<Range> inits;
|
|
|
|
};
|
|
|
|
|
|
|
|
using DataInitializations = std::map<SymbolRef, SymbolDataInitialization>;
|
|
|
|
|
2020-02-21 14:19:14 +08:00
|
|
|
class DataChecker : public virtual BaseChecker {
|
|
|
|
public:
|
Rework DATA statement semantics to use typed expressions
Summary:
Updates recent work on DATA statement semantic checking in
flang/lib/Semantics/check-data.{h,cpp} to use the compiler's
internal representation for typed expressions rather than working
on the raw parse tree. Saves the analyzed expressions for DATA
statement values as parse tree decorations because they'll soon be
needed in lowering. Corrects wording of some error messages.
Fixes a bug in constant expression checking: structure constructors
are not constant expressions if they set an allocatable component
to anything other than NULL.
Includes infrastructure changes to make this work, some renaming
to reflect the fact that the implied DO loop indices tracked by
expression analysis are not (just) from array constructors, remove
some dead code, and improve some comments.
Reviewers: tskeith, sscalpone, jdoerfert, DavidTruby, anchu-rajendran, schweitz
Reviewed By: tskeith, anchu-rajendran, schweitz
Subscribers: llvm-commits, flang-commits
Tags: #flang, #llvm
Differential Revision: https://reviews.llvm.org/D78834
2020-04-25 04:54:11 +08:00
|
|
|
explicit DataChecker(SemanticsContext &context) : exprAnalyzer_{context} {}
|
2020-04-18 14:09:34 +08:00
|
|
|
void Leave(const parser::DataStmtObject &);
|
2020-06-20 00:16:21 +08:00
|
|
|
void Leave(const parser::DataIDoObject &);
|
Rework DATA statement semantics to use typed expressions
Summary:
Updates recent work on DATA statement semantic checking in
flang/lib/Semantics/check-data.{h,cpp} to use the compiler's
internal representation for typed expressions rather than working
on the raw parse tree. Saves the analyzed expressions for DATA
statement values as parse tree decorations because they'll soon be
needed in lowering. Corrects wording of some error messages.
Fixes a bug in constant expression checking: structure constructors
are not constant expressions if they set an allocatable component
to anything other than NULL.
Includes infrastructure changes to make this work, some renaming
to reflect the fact that the implied DO loop indices tracked by
expression analysis are not (just) from array constructors, remove
some dead code, and improve some comments.
Reviewers: tskeith, sscalpone, jdoerfert, DavidTruby, anchu-rajendran, schweitz
Reviewed By: tskeith, anchu-rajendran, schweitz
Subscribers: llvm-commits, flang-commits
Tags: #flang, #llvm
Differential Revision: https://reviews.llvm.org/D78834
2020-04-25 04:54:11 +08:00
|
|
|
void Enter(const parser::DataImpliedDo &);
|
2020-04-18 14:09:34 +08:00
|
|
|
void Leave(const parser::DataImpliedDo &);
|
2020-06-20 00:16:21 +08:00
|
|
|
void Leave(const parser::DataStmtSet &);
|
|
|
|
|
|
|
|
// After all DATA statements have been processed, converts their
|
|
|
|
// initializations into per-symbol static initializers.
|
|
|
|
void CompileDataInitializationsIntoInitializers();
|
2020-02-21 14:19:14 +08:00
|
|
|
|
|
|
|
private:
|
2020-06-20 00:16:21 +08:00
|
|
|
ConstantSubscript GetRepetitionCount(const parser::DataStmtRepeat &);
|
2020-04-18 14:09:34 +08:00
|
|
|
template <typename T> void CheckIfConstantSubscript(const T &);
|
|
|
|
void CheckSubscript(const parser::SectionSubscript &);
|
|
|
|
bool CheckAllSubscriptsInDataRef(const parser::DataRef &, parser::CharBlock);
|
2020-06-20 00:16:21 +08:00
|
|
|
void ConstructInitializer(const Symbol &, SymbolDataInitialization &);
|
|
|
|
|
|
|
|
DataInitializations inits_;
|
|
|
|
evaluate::ExpressionAnalyzer exprAnalyzer_;
|
|
|
|
bool currentSetHasFatalErrors_{false};
|
2020-02-21 14:19:14 +08:00
|
|
|
};
|
2020-03-29 12:00:16 +08:00
|
|
|
} // namespace Fortran::semantics
|
|
|
|
#endif // FORTRAN_SEMANTICS_CHECK_DATA_H_
|