llvm.org GIT mirror llvm / c1b5d09
Initial checkin git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3005 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 18 years ago
4 changed file(s) with 190 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 //===- Support/TypeInfo.h - Support class for type_info objects --*- C++ -*--=//
1 //
2 // This class makes std::type_info objects behave like first class objects that
3 // can be put in maps and hashtables. This code is based off of code in the
4 // Loki C++ library from the Modern C++ Design book.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_SUPPORT_TYPEINFO_H
9 #define LLVM_SUPPORT_TYPEINFO_H
10
11 #include
12
13 struct TypeInfo {
14 TypeInfo() { // needed for containers
15 struct Nil {}; // Anonymous class distinct from all others...
16 Info = &typeid(Nil);
17 }
18
19 TypeInfo(const std::type_info &ti) : Info(&ti) { // non-explicit
20 }
21
22 // Access for the wrapped std::type_info
23 const std::type_info &get() const {
24 return *Info;
25 }
26
27 // Compatibility functions
28 bool before(const TypeInfo &rhs) const {
29 return Info->before(*rhs.Info);
30 }
31 const char *getClassName() const {
32 return Info->name();
33 }
34
35 private:
36 const std::type_info *Info;
37 };
38
39 // Comparison operators
40 inline bool operator==(const TypeInfo &lhs, const TypeInfo &rhs) {
41 return lhs.get() == rhs.get();
42 }
43
44 inline bool operator<(const TypeInfo &lhs, const TypeInfo &rhs) {
45 return lhs.before(rhs);
46 }
47
48 inline bool operator!=(const TypeInfo &lhs, const TypeInfo &rhs) {
49 return !(lhs == rhs);
50 }
51
52 inline bool operator>(const TypeInfo &lhs, const TypeInfo &rhs) {
53 return rhs < lhs;
54 }
55
56 inline bool operator<=(const TypeInfo &lhs, const TypeInfo &rhs) {
57 return !(lhs > rhs);
58 }
59
60 inline bool operator>=(const TypeInfo &lhs, const TypeInfo &rhs) {
61 return !(lhs < rhs);
62 }
63
64 #endif
0 //===- Support/TypeInfo.h - Support class for type_info objects --*- C++ -*--=//
1 //
2 // This class makes std::type_info objects behave like first class objects that
3 // can be put in maps and hashtables. This code is based off of code in the
4 // Loki C++ library from the Modern C++ Design book.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_SUPPORT_TYPEINFO_H
9 #define LLVM_SUPPORT_TYPEINFO_H
10
11 #include
12
13 struct TypeInfo {
14 TypeInfo() { // needed for containers
15 struct Nil {}; // Anonymous class distinct from all others...
16 Info = &typeid(Nil);
17 }
18
19 TypeInfo(const std::type_info &ti) : Info(&ti) { // non-explicit
20 }
21
22 // Access for the wrapped std::type_info
23 const std::type_info &get() const {
24 return *Info;
25 }
26
27 // Compatibility functions
28 bool before(const TypeInfo &rhs) const {
29 return Info->before(*rhs.Info);
30 }
31 const char *getClassName() const {
32 return Info->name();
33 }
34
35 private:
36 const std::type_info *Info;
37 };
38
39 // Comparison operators
40 inline bool operator==(const TypeInfo &lhs, const TypeInfo &rhs) {
41 return lhs.get() == rhs.get();
42 }
43
44 inline bool operator<(const TypeInfo &lhs, const TypeInfo &rhs) {
45 return lhs.before(rhs);
46 }
47
48 inline bool operator!=(const TypeInfo &lhs, const TypeInfo &rhs) {
49 return !(lhs == rhs);
50 }
51
52 inline bool operator>(const TypeInfo &lhs, const TypeInfo &rhs) {
53 return rhs < lhs;
54 }
55
56 inline bool operator<=(const TypeInfo &lhs, const TypeInfo &rhs) {
57 return !(lhs > rhs);
58 }
59
60 inline bool operator>=(const TypeInfo &lhs, const TypeInfo &rhs) {
61 return !(lhs < rhs);
62 }
63
64 #endif
0 //===-- PluginLoader.cpp - Implement -load command line option ------------===//
1 //
2 // This file implements the -load command line option processor. When
3 // linked into a program, this new command line option is available that allows
4 // users to load shared objects into the running program.
5 //
6 // Note that there are no symbols exported by the .o file generated for this
7 // .cpp file. Because of this, a program must link against support.o instead of
8 // support.a: otherwise this translation unit will not be included.
9 //
10 //===----------------------------------------------------------------------===//
11
12 #include "Support/CommandLine.h"
13 #include
14 #include
15
16 namespace {
17 struct PluginLoader {
18 void operator=(const std::string &Filename) {
19 if (dlopen(Filename.c_str(), RTLD_NOW) == 0)
20 std::cerr << "Error opening '" << Filename << "': " << dlerror()
21 << "\n -load request ignored.\n";
22 }
23 };
24 }
25
26 // This causes operator= above to be invoked for every -load option.
27 static cl::opt >
28 LoadOpt("load", cl::ZeroOrMore, cl::value_desc("plugin.so"),
29 cl::desc("Load the specified plugin"));
0 //===-- PluginLoader.cpp - Implement -load command line option ------------===//
1 //
2 // This file implements the -load command line option processor. When
3 // linked into a program, this new command line option is available that allows
4 // users to load shared objects into the running program.
5 //
6 // Note that there are no symbols exported by the .o file generated for this
7 // .cpp file. Because of this, a program must link against support.o instead of
8 // support.a: otherwise this translation unit will not be included.
9 //
10 //===----------------------------------------------------------------------===//
11
12 #include "Support/CommandLine.h"
13 #include
14 #include
15
16 namespace {
17 struct PluginLoader {
18 void operator=(const std::string &Filename) {
19 if (dlopen(Filename.c_str(), RTLD_NOW) == 0)
20 std::cerr << "Error opening '" << Filename << "': " << dlerror()
21 << "\n -load request ignored.\n";
22 }
23 };
24 }
25
26 // This causes operator= above to be invoked for every -load option.
27 static cl::opt >
28 LoadOpt("load", cl::ZeroOrMore, cl::value_desc("plugin.so"),
29 cl::desc("Load the specified plugin"));