Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1403)

Side by Side Diff: tools/clang/plugins/ChromeClassTester.cpp

Issue 1072203002: Build the Clang plugin on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Win path checking and comments Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/clang/plugins/CMakeLists.txt ('k') | tools/clang/plugins/FindBadConstructsConsumer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // A general interface for filtering and only acting on classes in Chromium C++ 5 // A general interface for filtering and only acting on classes in Chromium C++
6 // code. 6 // code.
7 7
8 #include "ChromeClassTester.h" 8 #include "ChromeClassTester.h"
9 9
10 #include <algorithm>
11
10 #include "clang/AST/AST.h" 12 #include "clang/AST/AST.h"
11 #include "clang/Basic/FileManager.h" 13 #include "clang/Basic/FileManager.h"
12 #include "clang/Basic/SourceManager.h" 14 #include "clang/Basic/SourceManager.h"
13 15
14 #ifdef LLVM_ON_UNIX 16 #ifdef LLVM_ON_UNIX
15 #include <sys/param.h> 17 #include <sys/param.h>
16 #endif 18 #endif
17 19
18 using namespace clang; 20 using namespace clang;
19 21
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 124
123 if (ends_with(filename, ".cc") || ends_with(filename, ".cpp") || 125 if (ends_with(filename, ".cc") || ends_with(filename, ".cpp") ||
124 ends_with(filename, ".mm")) { 126 ends_with(filename, ".mm")) {
125 return true; 127 return true;
126 } 128 }
127 129
128 return false; 130 return false;
129 } 131 }
130 132
131 void ChromeClassTester::BuildBannedLists() { 133 void ChromeClassTester::BuildBannedLists() {
132 banned_namespaces_.push_back("std"); 134 banned_namespaces_.emplace_back("std");
133 banned_namespaces_.push_back("__gnu_cxx"); 135 banned_namespaces_.emplace_back("__gnu_cxx");
134 136
135 banned_namespaces_.push_back("blink"); 137 banned_namespaces_.emplace_back("blink");
136 banned_namespaces_.push_back("WTF"); 138 banned_namespaces_.emplace_back("WTF");
137 139
138 banned_directories_.push_back("/third_party/"); 140 // System headers:
139 banned_directories_.push_back("/native_client/"); 141 #if defined(LLVM_ON_UNIX)
140 banned_directories_.push_back("/breakpad/"); 142 banned_directories_.emplace_back("/usr/include/");
141 banned_directories_.push_back("/courgette/"); 143 banned_directories_.emplace_back("/usr/lib/");
142 banned_directories_.push_back("/pdf/"); 144 banned_directories_.emplace_back("/usr/local/include/");
143 banned_directories_.push_back("/ppapi/"); 145 banned_directories_.emplace_back("/usr/local/lib/");
144 banned_directories_.push_back("/usr/include/"); 146 #elif defined(LLVM_ON_WIN32)
145 banned_directories_.push_back("/usr/lib/"); 147 // For now, assume that only win_toolchain will be used with clang=1.
146 banned_directories_.push_back("/usr/local/include/"); 148 banned_directories_.emplace_back("/win_toolchain/");
Nico 2015/04/11 23:32:31 clang-cl should konw that stuff in win_toolchain a
dcheng 2015/04/12 03:28:58 Interesting, didn't know about that. I updated InB
147 banned_directories_.push_back("/usr/local/lib/"); 149 #endif
148 banned_directories_.push_back("/testing/"); 150
149 banned_directories_.push_back("/v8/"); 151 banned_directories_.emplace_back("/third_party/");
150 banned_directories_.push_back("/dart/"); 152 banned_directories_.emplace_back("/native_client/");
151 banned_directories_.push_back("/sdch/"); 153 banned_directories_.emplace_back("/breakpad/");
152 banned_directories_.push_back("/icu4c/"); 154 banned_directories_.emplace_back("/courgette/");
153 banned_directories_.push_back("/frameworks/"); 155 banned_directories_.emplace_back("/pdf/");
156 banned_directories_.emplace_back("/ppapi/");
157 banned_directories_.emplace_back("/testing/");
158 banned_directories_.emplace_back("/v8/");
159 banned_directories_.emplace_back("/dart/");
160 banned_directories_.emplace_back("/sdch/");
161 banned_directories_.emplace_back("/icu4c/");
162 banned_directories_.emplace_back("/frameworks/");
154 163
155 // Don't check autogenerated headers. 164 // Don't check autogenerated headers.
156 // Make puts them below $(builddir_name)/.../gen and geni. 165 // Make puts them below $(builddir_name)/.../gen and geni.
157 // Ninja puts them below OUTPUT_DIR/.../gen 166 // Ninja puts them below OUTPUT_DIR/.../gen
158 // Xcode has a fixed output directory for everything. 167 // Xcode has a fixed output directory for everything.
159 banned_directories_.push_back("/gen/"); 168 banned_directories_.emplace_back("/gen/");
160 banned_directories_.push_back("/geni/"); 169 banned_directories_.emplace_back("/geni/");
161 banned_directories_.push_back("/xcodebuild/"); 170 banned_directories_.emplace_back("/xcodebuild/");
162 171
163 // You are standing in a mazy of twisty dependencies, all resolved by 172 // You are standing in a mazy of twisty dependencies, all resolved by
164 // putting everything in the header. 173 // putting everything in the header.
165 banned_directories_.push_back("/automation/"); 174 banned_directories_.emplace_back("/automation/");
166 175
167 // Don't check system headers. 176 // Don't check system headers.
168 banned_directories_.push_back("/Developer/"); 177 banned_directories_.emplace_back("/Developer/");
169 178
170 // Used in really low level threading code that probably shouldn't be out of 179 // Used in really low level threading code that probably shouldn't be out of
171 // lined. 180 // lined.
172 ignored_record_names_.insert("ThreadLocalBoolean"); 181 ignored_record_names_.emplace("ThreadLocalBoolean");
173 182
174 // A complicated pickle derived struct that is all packed integers. 183 // A complicated pickle derived struct that is all packed integers.
175 ignored_record_names_.insert("Header"); 184 ignored_record_names_.emplace("Header");
176 185
177 // Part of the GPU system that uses multiple included header 186 // Part of the GPU system that uses multiple included header
178 // weirdness. Never getting this right. 187 // weirdness. Never getting this right.
179 ignored_record_names_.insert("Validators"); 188 ignored_record_names_.emplace("Validators");
180 189
181 // Has a UNIT_TEST only constructor. Isn't *terribly* complex... 190 // Has a UNIT_TEST only constructor. Isn't *terribly* complex...
182 ignored_record_names_.insert("AutocompleteController"); 191 ignored_record_names_.emplace("AutocompleteController");
183 ignored_record_names_.insert("HistoryURLProvider"); 192 ignored_record_names_.emplace("HistoryURLProvider");
184 193
185 // Because of chrome frame 194 // Because of chrome frame
186 ignored_record_names_.insert("ReliabilityTestSuite"); 195 ignored_record_names_.emplace("ReliabilityTestSuite");
187 196
188 // Used over in the net unittests. A large enough bundle of integers with 1 197 // Used over in the net unittests. A large enough bundle of integers with 1
189 // non-pod class member. Probably harmless. 198 // non-pod class member. Probably harmless.
190 ignored_record_names_.insert("MockTransaction"); 199 ignored_record_names_.emplace("MockTransaction");
191 200
192 // Enum type with _LAST members where _LAST doesn't mean last enum value. 201 // Enum type with _LAST members where _LAST doesn't mean last enum value.
193 ignored_record_names_.insert("ServerFieldType"); 202 ignored_record_names_.emplace("ServerFieldType");
194 203
195 // Used heavily in ui_base_unittests and once in views_unittests. Fixing this 204 // Used heavily in ui_base_unittests and once in views_unittests. Fixing this
196 // isn't worth the overhead of an additional library. 205 // isn't worth the overhead of an additional library.
197 ignored_record_names_.insert("TestAnimationDelegate"); 206 ignored_record_names_.emplace("TestAnimationDelegate");
198 207
199 // Part of our public interface that nacl and friends use. (Arguably, this 208 // Part of our public interface that nacl and friends use. (Arguably, this
200 // should mean that this is a higher priority but fixing this looks hard.) 209 // should mean that this is a higher priority but fixing this looks hard.)
201 ignored_record_names_.insert("PluginVersionInfo"); 210 ignored_record_names_.emplace("PluginVersionInfo");
202 211
203 // Measured performance improvement on cc_perftests. See 212 // Measured performance improvement on cc_perftests. See
204 // https://codereview.chromium.org/11299290/ 213 // https://codereview.chromium.org/11299290/
205 ignored_record_names_.insert("QuadF"); 214 ignored_record_names_.emplace("QuadF");
206 215
207 // Enum type with _LAST members where _LAST doesn't mean last enum value. 216 // Enum type with _LAST members where _LAST doesn't mean last enum value.
208 ignored_record_names_.insert("ViewID"); 217 ignored_record_names_.emplace("ViewID");
209 } 218 }
210 219
211 std::string ChromeClassTester::GetNamespaceImpl(const DeclContext* context, 220 std::string ChromeClassTester::GetNamespaceImpl(const DeclContext* context,
212 const std::string& candidate) { 221 const std::string& candidate) {
213 switch (context->getDeclKind()) { 222 switch (context->getDeclKind()) {
214 case Decl::TranslationUnit: { 223 case Decl::TranslationUnit: {
215 return candidate; 224 return candidate;
216 } 225 }
217 case Decl::Namespace: { 226 case Decl::Namespace: {
218 const NamespaceDecl* decl = dyn_cast<NamespaceDecl>(context); 227 const NamespaceDecl* decl = dyn_cast<NamespaceDecl>(context);
(...skipping 24 matching lines...) Expand all
243 // macro expansion. We explicitly want to allow people to do otherwise bad 252 // macro expansion. We explicitly want to allow people to do otherwise bad
244 // things through macros that were defined due to third party libraries. 253 // things through macros that were defined due to third party libraries.
245 if (filename == "<scratch space>") 254 if (filename == "<scratch space>")
246 return true; 255 return true;
247 256
248 // Don't complain about autogenerated protobuf files. 257 // Don't complain about autogenerated protobuf files.
249 if (ends_with(filename, ".pb.h")) { 258 if (ends_with(filename, ".pb.h")) {
250 return true; 259 return true;
251 } 260 }
252 261
253 #ifdef LLVM_ON_UNIX 262 #if defined(LLVM_ON_UNIX)
254 // We need to munge the paths so that they are relative to the repository 263 // We need to munge the paths so that they are relative to the repository
255 // srcroot. We first resolve the symlinktastic relative path and then 264 // srcroot. We first resolve the symlinktastic relative path and then
256 // remove our known srcroot from it if needed. 265 // remove our known srcroot from it if needed.
257 char resolvedPath[MAXPATHLEN]; 266 char resolvedPath[MAXPATHLEN];
258 if (realpath(filename.c_str(), resolvedPath)) { 267 if (realpath(filename.c_str(), resolvedPath)) {
259 filename = resolvedPath; 268 filename = resolvedPath;
260 } 269 }
261 #endif 270 #endif
262 271
272 #if defined(LLVM_ON_WIN32)
273 std::replace(filename.begin(), filename.end(), '\\', '/');
274 #endif
275
263 for (const std::string& banned_dir : banned_directories_) { 276 for (const std::string& banned_dir : banned_directories_) {
264 // If any of the banned directories occur as a component in filename, 277 // If any of the banned directories occur as a component in filename,
265 // this file is rejected. 278 // this file is rejected.
266 assert(banned_dir.front() == '/' && "Banned dir must start with '/'"); 279 assert(banned_dir.front() == '/' && "Banned dir must start with '/'");
267 assert(banned_dir.back() == '/' && "Banned dir must end with '/'"); 280 assert(banned_dir.back() == '/' && "Banned dir must end with '/'");
268 281
269 if (filename.find(banned_dir) != std::string::npos) 282 if (filename.find(banned_dir) != std::string::npos)
270 return true; 283 return true;
271 } 284 }
272 285
(...skipping 11 matching lines...) Expand all
284 PresumedLoc ploc = source_manager.getPresumedLoc(spelling_location); 297 PresumedLoc ploc = source_manager.getPresumedLoc(spelling_location);
285 if (ploc.isInvalid()) { 298 if (ploc.isInvalid()) {
286 // If we're in an invalid location, we're looking at things that aren't 299 // If we're in an invalid location, we're looking at things that aren't
287 // actually stated in the source. 300 // actually stated in the source.
288 return false; 301 return false;
289 } 302 }
290 303
291 *filename = ploc.getFilename(); 304 *filename = ploc.getFilename();
292 return true; 305 return true;
293 } 306 }
OLDNEW
« no previous file with comments | « tools/clang/plugins/CMakeLists.txt ('k') | tools/clang/plugins/FindBadConstructsConsumer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698