HPCToolkit
ProcNameMgr.hpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // File:
50 // $HeadURL$
51 //
52 // Purpose:
53 // [The purpose of this file]
54 //
55 // Description:
56 // [The set of functions, macros, etc. defined in the file]
57 //
58 //***************************************************************************
59 
60 #ifndef ProcNameMgr_hpp
61 #define ProcNameMgr_hpp
62 
63 //************************* System Include Files ****************************
64 
65 #include <string>
66 #include <map>
67 
68 //*************************** User Include Files ****************************
69 
70 #include <include/uint.h>
71 
72 //*************************** Forward Declarations **************************
73 
74 //***************************************************************************
75 // ProcNameMgr
76 //***************************************************************************
77 
78 // --------------------------------------------------------------------------
79 // 'ProcNameMgr'
80 // --------------------------------------------------------------------------
81 
83 {
84 public:
86  virtual ~ProcNameMgr() { }
87 
88  virtual std::string
89  canonicalize(const std::string& name) = 0;
90 
91  std::string
92  canonicalizeCppTemplate(const std::string& name);
93 
94 };
95 
96 
97 // --------------------------------------------------------------------------
98 // 'CppNameMgr'
99 // --------------------------------------------------------------------------
100 
101 class CppNameMgr : public ProcNameMgr
102 {
103 public:
105  virtual ~CppNameMgr() { }
106 
107  virtual std::string
108  canonicalize(const std::string& name) {
109  return canonicalizeCppTemplate(name);
110  }
111 
112 private:
113 };
114 
115 
116 // --------------------------------------------------------------------------
117 // 'CilkNameMgr'
118 // --------------------------------------------------------------------------
119 
120 class CilkNameMgr : public ProcNameMgr
121 {
122 public:
124  virtual ~CilkNameMgr() { }
125 
126  virtual std::string
127  canonicalize(const std::string& name);
128 
129  static const std::string cilkmain;
130 
131 private:
132 
133  bool
134  isGenerated(const std::string& x,
135  const std::string& pfx, const std::string& sfx)
136  {
137  bool isSane = (x.length() > (pfx.length() + sfx.length()));
138  size_t sfx_pos = x.length() - sfx.length();
139 
140  // test suffix first becuase it fails more than the prefix comparison
141  return (isSane &&
142  x.compare(sfx_pos, sfx.length(), sfx) == 0 &&
143  x.compare(0, pfx.length(), pfx) == 0);
144  }
145 
146  std::string
147  basename(const std::string& x,
148  const std::string& pfx, const std::string& sfx)
149  {
150  // Assume: x.length() > (pfx.length() + sfx.length())
151  int len = x.length() - pfx.length() - sfx.length();
152  return x.substr(pfx.length(), len);
153  }
154 
155 private:
156  static const std::string s_procSlow_pfx, s_procSlow_sfx;
157  static const std::string s_procImport_pfx, s_procImport_sfx;
158  static const std::string s_procExport_pfx, s_procExport_sfx;
159 
160  static const std::string s_inletNorm_pfx, s_inletNorm_sfx;
161  static const std::string s_inletFast_pfx, s_inletFast_sfx;
162  static const std::string s_inletSlow_pfx, s_inletSlow_sfx;
163 };
164 
165 
166 //***************************************************************************
167 
168 #endif // ProcNameMgr_hpp
static const std::string s_procImport_sfx
static const std::string cilkmain
bool isGenerated(const std::string &x, const std::string &pfx, const std::string &sfx)
static const std::string s_procSlow_sfx
virtual ~CilkNameMgr()
virtual std::string canonicalize(const std::string &name)=0
static const std::string s_procExport_sfx
virtual std::string canonicalize(const std::string &name)
virtual ~CppNameMgr()
virtual ~ProcNameMgr()
Definition: ProcNameMgr.hpp:86
std::string canonicalizeCppTemplate(const std::string &name)
Definition: ProcNameMgr.cpp:99
static const std::string s_inletSlow_sfx
static const std::string s_inletFast_sfx
static const std::string s_inletNorm_sfx
std::string basename(const std::string &x, const std::string &pfx, const std::string &sfx)