173
|
1 //===-- lib/Evaluate/common.cpp -------------------------------------------===//
|
|
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 #include "flang/Evaluate/common.h"
|
|
10 #include "flang/Common/idioms.h"
|
|
11
|
|
12 using namespace Fortran::parser::literals;
|
|
13
|
|
14 namespace Fortran::evaluate {
|
|
15
|
|
16 void RealFlagWarnings(
|
|
17 FoldingContext &context, const RealFlags &flags, const char *operation) {
|
|
18 if (flags.test(RealFlag::Overflow)) {
|
236
|
19 context.messages().Say("overflow on %s"_warn_en_US, operation);
|
173
|
20 }
|
|
21 if (flags.test(RealFlag::DivideByZero)) {
|
221
|
22 if (std::strcmp(operation, "division") == 0) {
|
236
|
23 context.messages().Say("division by zero"_warn_en_US);
|
221
|
24 } else {
|
236
|
25 context.messages().Say("division by zero on %s"_warn_en_US, operation);
|
221
|
26 }
|
173
|
27 }
|
|
28 if (flags.test(RealFlag::InvalidArgument)) {
|
236
|
29 context.messages().Say("invalid argument on %s"_warn_en_US, operation);
|
173
|
30 }
|
|
31 if (flags.test(RealFlag::Underflow)) {
|
236
|
32 context.messages().Say("underflow on %s"_warn_en_US, operation);
|
173
|
33 }
|
|
34 }
|
|
35
|
|
36 ConstantSubscript &FoldingContext::StartImpliedDo(
|
|
37 parser::CharBlock name, ConstantSubscript n) {
|
|
38 auto pair{impliedDos_.insert(std::make_pair(name, n))};
|
|
39 CHECK(pair.second);
|
|
40 return pair.first->second;
|
|
41 }
|
|
42
|
|
43 std::optional<ConstantSubscript> FoldingContext::GetImpliedDo(
|
|
44 parser::CharBlock name) const {
|
|
45 if (auto iter{impliedDos_.find(name)}; iter != impliedDos_.cend()) {
|
|
46 return {iter->second};
|
|
47 } else {
|
|
48 return std::nullopt;
|
|
49 }
|
|
50 }
|
|
51
|
|
52 void FoldingContext::EndImpliedDo(parser::CharBlock name) {
|
|
53 auto iter{impliedDos_.find(name)};
|
|
54 if (iter != impliedDos_.end()) {
|
|
55 impliedDos_.erase(iter);
|
|
56 }
|
|
57 }
|
|
58 } // namespace Fortran::evaluate
|