1 // Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "common.h"
16 #include "../common/idioms.h"
17
18 using namespace Fortran::parser::literals;
19
20 namespace Fortran::evaluate {
21
RealFlagWarnings(FoldingContext & context,const RealFlags & flags,const char * operation)22 void RealFlagWarnings(
23 FoldingContext &context, const RealFlags &flags, const char *operation) {
24 if (flags.test(RealFlag::Overflow)) {
25 context.messages().Say("overflow on %s"_en_US, operation);
26 }
27 if (flags.test(RealFlag::DivideByZero)) {
28 context.messages().Say("division by zero on %s"_en_US, operation);
29 }
30 if (flags.test(RealFlag::InvalidArgument)) {
31 context.messages().Say("invalid argument on %s"_en_US, operation);
32 }
33 if (flags.test(RealFlag::Underflow)) {
34 context.messages().Say("underflow on %s"_en_US, operation);
35 }
36 }
37
StartImpliedDo(parser::CharBlock name,ConstantSubscript n)38 ConstantSubscript &FoldingContext::StartImpliedDo(
39 parser::CharBlock name, ConstantSubscript n) {
40 auto pair{impliedDos_.insert(std::make_pair(name, n))};
41 CHECK(pair.second);
42 return pair.first->second;
43 }
44
GetImpliedDo(parser::CharBlock name) const45 std::optional<ConstantSubscript> FoldingContext::GetImpliedDo(
46 parser::CharBlock name) const {
47 if (auto iter{impliedDos_.find(name)}; iter != impliedDos_.cend()) {
48 return {iter->second};
49 } else {
50 return std::nullopt;
51 }
52 }
53
EndImpliedDo(parser::CharBlock name)54 void FoldingContext::EndImpliedDo(parser::CharBlock name) {
55 auto iter{impliedDos_.find(name)};
56 if (iter != impliedDos_.end()) {
57 impliedDos_.erase(iter);
58 }
59 }
60 }
61