xref: /llvm-project/flang/include/flang/Semantics/module-dependences.h (revision 5661188c5766c3136d1954d769825261715b1f9a)
1 //===-- include/flang/Semantics/module-dependences.h ------------*- C++ -*-===//
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 #ifndef FORTRAN_SEMANTICS_MODULE_DEPENDENCES_H_
10 #define FORTRAN_SEMANTICS_MODULE_DEPENDENCES_H_
11 
12 #include <cinttypes>
13 #include <map>
14 #include <optional>
15 #include <string>
16 
17 namespace Fortran::semantics {
18 
19 using ModuleCheckSumType = std::uint64_t;
20 
21 class ModuleDependences {
22 public:
AddDependence(std::string && name,bool intrinsic,ModuleCheckSumType hash)23   void AddDependence(
24       std::string &&name, bool intrinsic, ModuleCheckSumType hash) {
25     if (intrinsic) {
26       intrinsicMap_.insert_or_assign(std::move(name), hash);
27     } else {
28       nonIntrinsicMap_.insert_or_assign(std::move(name), hash);
29     }
30   }
GetRequiredHash(const std::string & name,bool intrinsic)31   std::optional<ModuleCheckSumType> GetRequiredHash(
32       const std::string &name, bool intrinsic) {
33     if (intrinsic) {
34       if (auto iter{intrinsicMap_.find(name)}; iter != intrinsicMap_.end()) {
35         return iter->second;
36       }
37     } else {
38       if (auto iter{nonIntrinsicMap_.find(name)};
39           iter != nonIntrinsicMap_.end()) {
40         return iter->second;
41       }
42     }
43     return std::nullopt;
44   }
45 
46 private:
47   std::map<std::string, ModuleCheckSumType> intrinsicMap_, nonIntrinsicMap_;
48 };
49 
50 } // namespace Fortran::semantics
51 #endif // FORTRAN_SEMANTICS_MODULE_DEPENDENCES_H_
52