Debian Codegraph @

flang/lib/Evaluate/common.cpp

raw
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 (context.languageFeatures().ShouldWarn(
19 common::UsageWarning::FoldingException)) {
20 if (flags.test(RealFlag::Overflow)) {
21 context.messages().Say("overflow on %s"_warn_en_US, operation);
22 }
23 if (flags.test(RealFlag::DivideByZero)) {
24 if (std::strcmp(operation, "division") == 0) {
25 context.messages().Say("division by zero"_warn_en_US);
26 } else {
27 context.messages().Say("division by zero on %s"_warn_en_US, operation);
28 }
29 }
30 if (flags.test(RealFlag::InvalidArgument)) {
31 context.messages().Say("invalid argument on %s"_warn_en_US, operation);
32 }
33 if (flags.test(RealFlag::Underflow)) {
34 context.messages().Say("underflow on %s"_warn_en_US, operation);
35 }
36 }
37 }
38
39 ConstantSubscript &FoldingContext::StartImpliedDo(
40 parser::CharBlock name, ConstantSubscript n) {
41 auto pair{impliedDos_.insert(std::make_pair(name, n))};
42 CHECK(pair.second);
43 return pair.first->second;
44 }
45
46 std::optional<ConstantSubscript> FoldingContext::GetImpliedDo(
47 parser::CharBlock name) const {
48 if (auto iter{impliedDos_.find(name)}; iter != impliedDos_.cend()) {
49 return {iter->second};
50 } else {
51 return std::nullopt;
52 }
53 }
54
55 void FoldingContext::EndImpliedDo(parser::CharBlock name) {
56 auto iter{impliedDos_.find(name)};
57 if (iter != impliedDos_.end()) {
58 impliedDos_.erase(iter);
59 }
60 }
61 } // namespace Fortran::evaluate