1 //===-- lib/Evaluate/common.cpp -------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "flang/Evaluate/common.h"
10 #include "flang/Common/idioms.h"
12 using namespace Fortran::parser::literals
;
14 namespace Fortran::evaluate
{
16 void RealFlagWarnings(
17 FoldingContext
&context
, const RealFlags
&flags
, const char *operation
) {
18 static constexpr auto warning
{common::UsageWarning::FoldingException
};
19 if (context
.languageFeatures().ShouldWarn(warning
)) {
20 if (flags
.test(RealFlag::Overflow
)) {
21 context
.messages().Say(warning
, "overflow on %s"_warn_en_US
, operation
);
23 if (flags
.test(RealFlag::DivideByZero
)) {
24 if (std::strcmp(operation
, "division") == 0) {
25 context
.messages().Say(warning
, "division by zero"_warn_en_US
);
27 context
.messages().Say(
28 warning
, "division by zero on %s"_warn_en_US
, operation
);
31 if (flags
.test(RealFlag::InvalidArgument
)) {
32 context
.messages().Say(
33 warning
, "invalid argument on %s"_warn_en_US
, operation
);
35 if (flags
.test(RealFlag::Underflow
)) {
36 context
.messages().Say(warning
, "underflow on %s"_warn_en_US
, operation
);
41 ConstantSubscript
&FoldingContext::StartImpliedDo(
42 parser::CharBlock name
, ConstantSubscript n
) {
43 auto pair
{impliedDos_
.insert(std::make_pair(name
, n
))};
45 return pair
.first
->second
;
48 std::optional
<ConstantSubscript
> FoldingContext::GetImpliedDo(
49 parser::CharBlock name
) const {
50 if (auto iter
{impliedDos_
.find(name
)}; iter
!= impliedDos_
.cend()) {
51 return {iter
->second
};
57 void FoldingContext::EndImpliedDo(parser::CharBlock name
) {
58 auto iter
{impliedDos_
.find(name
)};
59 if (iter
!= impliedDos_
.end()) {
60 impliedDos_
.erase(iter
);
63 } // namespace Fortran::evaluate