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