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

Side by Side Diff: tools/clang/rewrite_to_chrome_style/RewriteToChromeStyle.cpp

Issue 2622003002: rewrite_to_chrome_style: Make is-const decisions more consistent (Closed)
Patch Set: consistant-consts-2 Created 3 years, 11 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 | « no previous file | tools/clang/rewrite_to_chrome_style/tests/template-expected.cc » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // Changes Blink-style names to Chrome-style names. Currently transforms: 5 // Changes Blink-style names to Chrome-style names. Currently transforms:
6 // fields: 6 // fields:
7 // int m_operationCount => int operation_count_ 7 // int m_operationCount => int operation_count_
8 // variables (including parameters): 8 // variables (including parameters):
9 // int mySuperVariable => int my_super_variable 9 // int mySuperVariable => int my_super_variable
10 // constants: 10 // constants:
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 // Recurse on children. If they are all const (or are uses of template 384 // Recurse on children. If they are all const (or are uses of template
385 // input) then the statement can be considered const. For whatever reason the 385 // input) then the statement can be considered const. For whatever reason the
386 // below checks can give different-and-less-consistent responses if we call 386 // below checks can give different-and-less-consistent responses if we call
387 // them on a complex expression than if we call them on the most primitive 387 // them on a complex expression than if we call them on the most primitive
388 // pieces (some pieces would say false but the whole thing says true). 388 // pieces (some pieces would say false but the whole thing says true).
389 for (auto* child : expr->children()) { 389 for (auto* child : expr->children()) {
390 if (!CanBeEvaluatedAtCompileTime(child, context)) 390 if (!CanBeEvaluatedAtCompileTime(child, context))
391 return false; 391 return false;
392 } 392 }
393 393
394 // If the expression is a template input then its coming at compile time so 394 // If the expression depends on template input, we can not call
395 // we consider it const. And we can't check isEvaluatable() in this case as 395 // isEvaluatable() on it as it will do bad things/crash.
396 // it will do bad things/crash. 396 if (!expr->isInstantiationDependent()) {
397 if (expr->isInstantiationDependent()) 397 // If the expression can be evaluated at compile time, then it should have a
398 return true; 398 // kFoo style name. Otherwise, not.
399 return expr->isEvaluatable(context);
400 }
399 401
400 // If the expression can be evaluated at compile time, then it should have a 402 // We do our best to figure out special cases as we come across them here, for
401 // kFoo style name. Otherwise, not. 403 // template dependent situations. Some cases in code are only considered
402 return expr->isEvaluatable(context); 404 // instantiation dependent for some template instantiations! Which is
405 // terrible! So most importantly we try to match isEvaluatable in those cases.
406 switch (expr->getStmtClass()) {
407 case clang::Stmt::CXXThisExprClass:
408 return false;
409 case clang::Stmt::DeclRefExprClass: {
410 auto* declref = clang::dyn_cast<clang::DeclRefExpr>(expr);
411 auto* decl = declref->getDecl();
412 if (clang::dyn_cast<clang::VarDecl>(decl))
dcheng 2017/01/11 17:03:12 Nit: use isa... except I guess the followup CL cha
413 return false;
414 break;
415 }
416
417 default:
418 break;
419 }
420
421 // Otherwise, we consider depending on template parameters to not interfere
422 // with being const.. with exceptions hopefully covered above.
423 return true;
403 } 424 }
404 425
405 bool IsProbablyConst(const clang::VarDecl& decl, 426 bool IsProbablyConst(const clang::VarDecl& decl,
406 const clang::ASTContext& context) { 427 const clang::ASTContext& context) {
407 clang::QualType type = decl.getType(); 428 clang::QualType type = decl.getType();
408 if (!type.isConstQualified()) 429 if (!type.isConstQualified())
409 return false; 430 return false;
410 431
411 if (type.isVolatileQualified()) 432 if (type.isVolatileQualified())
412 return false; 433 return false;
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 for (const auto& r : replacements) { 1508 for (const auto& r : replacements) {
1488 std::string replacement_text = r.getReplacementText().str(); 1509 std::string replacement_text = r.getReplacementText().str();
1489 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0'); 1510 std::replace(replacement_text.begin(), replacement_text.end(), '\n', '\0');
1490 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset() 1511 llvm::outs() << "r:::" << r.getFilePath() << ":::" << r.getOffset()
1491 << ":::" << r.getLength() << ":::" << replacement_text << "\n"; 1512 << ":::" << r.getLength() << ":::" << replacement_text << "\n";
1492 } 1513 }
1493 llvm::outs() << "==== END EDITS ====\n"; 1514 llvm::outs() << "==== END EDITS ====\n";
1494 1515
1495 return 0; 1516 return 0;
1496 } 1517 }
OLDNEW
« no previous file with comments | « no previous file | tools/clang/rewrite_to_chrome_style/tests/template-expected.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698