* Bring back rbuild build to be used until bug 6372 is fixed.
[reactos.git] / tools / rbuild / compilerdirective.cpp
1 /*
2 * Copyright (C) 2009 KJK::Hyperion
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18 #include "pch.h"
19 #include <assert.h>
20
21 #include "rbuild.h"
22
23 #include <locale>
24
25 void
26 CompilerDirective::SetCompiler ( CompilerType compiler )
27 {
28 assert ( compiler < CompilerTypesCount );
29 compilersSet.set ( compiler );
30 }
31
32 void
33 CompilerDirective::UnsetCompiler ( CompilerType compiler )
34 {
35 assert ( compiler < CompilerTypesCount );
36 compilersSet.reset ( compiler );
37 }
38
39 void
40 CompilerDirective::SetAllCompilers ()
41 {
42 compilersSet.set ();
43 }
44
45 void
46 CompilerDirective::UnsetAllCompilers ()
47 {
48 compilersSet.reset ();
49 }
50
51 bool
52 CompilerDirective::IsCompilerSet ( CompilerType compiler ) const
53 {
54 assert ( compiler < CompilerTypesCount );
55 return compilersSet.test ( compiler );
56 }
57
58 template < std::size_t N >
59 static
60 bool
61 CompareStringElement ( const std::string::const_iterator& begin, const std::string::const_iterator& end, const char (& compareTo)[(N)] )
62 {
63 return !std::use_facet < std::collate < char > > ( std::locale::classic () )
64 .compare ( &(*begin),
65 &(*(end - 1)),
66 &compareTo[0],
67 &compareTo[(N) - 2] );
68 }
69
70 void
71 CompilerDirective::ParseCompilers ( const XMLElement& node, const std::string& defaultValue )
72 {
73 const XMLAttribute* att = node.GetAttribute ( "compiler", false );
74 const std::string& value = att ? att->value : defaultValue;
75
76 if ( value == "*" )
77 SetAllCompilers ();
78 else
79 {
80 UnsetAllCompilers ();
81
82 std::string::const_iterator beginString;
83
84 beginString = value.begin();
85
86 do
87 {
88 for ( ; beginString != value.end(); ++ beginString )
89 {
90 if ( *beginString != ',' )
91 break;
92 }
93
94 if ( beginString == value.end() )
95 break;
96
97 std::string::const_iterator endString = beginString;
98
99 for ( ; endString != value.end(); ++ endString )
100 {
101 if ( *endString == ',' )
102 break;
103 }
104
105 assert ( endString != beginString );
106
107 CompilerType compiler;
108
109 if ( CompareStringElement ( beginString, endString, "cc" ) )
110 compiler = CompilerTypeCC;
111 else if ( CompareStringElement ( beginString, endString, "cxx" ) )
112 compiler = CompilerTypeCXX;
113 else if ( CompareStringElement ( beginString, endString, "cpp" ) )
114 compiler = CompilerTypeCPP;
115 else if ( CompareStringElement ( beginString, endString, "as" ) )
116 compiler = CompilerTypeAS;
117 else if ( CompareStringElement ( beginString, endString, "midl" ) )
118 compiler = CompilerTypeMIDL;
119 else if ( CompareStringElement ( beginString, endString, "rc" ) )
120 compiler = CompilerTypeRC;
121 else if ( CompareStringElement ( beginString, endString, "nasm" ) )
122 compiler = CompilerTypeNASM;
123 else
124 {
125 throw InvalidAttributeValueException (
126 node.location,
127 "compiler",
128 value );
129 }
130
131 SetCompiler ( compiler );
132
133 beginString = endString;
134 }
135 while ( beginString != value.end() );
136
137 if ( !compilersSet.any() )
138 {
139 throw InvalidAttributeValueException (
140 node.location,
141 "compiler",
142 value );
143 }
144 }
145 }