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 if (std::strcmp(operation, "division") == 0) { 23 context.messages().Say("division by zero"_en_US); 24 } else { 25 context.messages().Say("division on %s"_en_US); 26 } 27 } 28 if (flags.test(RealFlag::InvalidArgument)) { 29 context.messages().Say("invalid argument on %s"_en_US, operation); 30 } 31 if (flags.test(RealFlag::Underflow)) { 32 context.messages().Say("underflow on %s"_en_US, operation); 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 59