Wiki Roadmap Timeline Tickets New Ticket Source Search Help / Guide About Trac Login

root/gen/cl_helpers.cpp

Revision 1650:40bd4a0d4870, 2.1 kB (checked in by Tomas Lindquist Olsen, 2 years ago)

Update to work with LLVM 2.7.

Removed use of dyn_cast, llvm no compiles
without exceptions and rtti by
default. We do need exceptions for the libconfig stuff, but rtti isn't
necessary (anymore).

Debug info needs to be rewritten, as in LLVM 2.7 the format has
completely changed. To have something to look at while rewriting, the
old code has been wrapped inside #ifndef DISABLE_DEBUG_INFO , this means
that you have to define this to compile at the moment.

Updated tango 0.99.9 patch to include updated EH runtime code, which is
needed for LLVM 2.7 as well.

Line 
1 #include "gen/cl_helpers.h"
2
3 #include "root.h"
4 #include "rmem.h"
5
6 #include <cctype>       // isupper, tolower
7 #include <algorithm>
8 #include <utility>
9 #include <stdarg.h>
10
11 namespace opts {
12
13 // Helper function
14 static char toLower(char c) {
15     if (isupper(c))
16         return tolower(c);
17     return c;
18 }
19
20 bool FlagParser::parse(cl::Option &O, llvm::StringRef ArgName, llvm::StringRef Arg, bool &Val) {
21     // Make a std::string out of it to make comparisons easier
22     // (and avoid repeated conversion)
23     llvm::StringRef argname = ArgName;
24
25     typedef std::vector<std::pair<std::string, bool> >::iterator It;
26     for (It I = switches.begin(), E = switches.end(); I != E; ++I) {
27         llvm::StringRef name = I->first;
28         if (name == argname
29                 || (name.size() < argname.size()
30                     && argname.substr(0, name.size()) == name
31                     && argname[name.size()] == '=')) {
32
33             if (!cl::parser<bool>::parse(O, ArgName, Arg, Val)) {
34                 Val = (Val == I->second);
35                 return false;
36             }
37             // Invalid option value
38             break;
39         }
40     }
41     return true;
42 }
43
44 void FlagParser::getExtraOptionNames(llvm::SmallVectorImpl<const char*> &Names) {
45     typedef std::vector<std::pair<std::string, bool> >::iterator It;
46     for (It I = switches.begin() + 1, E = switches.end(); I != E; ++I) {
47         Names.push_back(I->first.data());
48     }
49 }
50
51
52 MultiSetter::MultiSetter(bool invert, bool* p, ...) {
53     this->invert = invert;
54     if (p) {
55         locations.push_back(p);
56         va_list va;
57         va_start(va, p);
58         while (p = va_arg(va, bool*)) {
59             locations.push_back(p);
60         }
61     }
62 }
63
64 void MultiSetter::operator=(bool val) {
65     typedef std::vector<bool*>::iterator It;
66     for (It I = locations.begin(), E = locations.end(); I != E; ++I) {
67         **I = (val != invert);
68     }
69 }
70
71
72 void ArrayAdapter::push_back(const char* cstr) {
73     if (!cstr || !*cstr)
74         error("Expected argument to '-%s'", name);
75
76     if (!*arrp)
77         *arrp = new Array;
78     (*arrp)->push(mem.strdup(cstr));
79 }
80
81 } // namespace opts
Note: See TracBrowser for help on using the browser.
Copyright © 2008, LDC Development Team.