[cfe-commits] [PATCH] Bug 3558: make ASTContext methods const

Jay Foad jay.foad at gmail.com
Tue Jan 4 02:10:50 PST 2011


(This is a repost of:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20101213/037293.html
I've updated the patch to current HEAD, retested, and edited the
description below.)

http://llvm.org/bugs/show_bug.cgi?id=3558

The bug says:

 There are several accessors that are "logically" const but not marked as such.
 This causes const_casts in other logically const methods like
 getLegacyIntegralTypeEncoding.  We should just mark the data they use as
 mutable or avoid calling getCanonicalType in it.

The attached patch makes ASTContext::getIntWidth() const, and then
follows it to some sort of logical conclusion, by making methods const
and fields mutable until the whole thing compiles cleanly again.

The result is that most ASTContext "get" methods are now const, and
most fields are mutable. Does this seem reasonable?

In addition, I've had to change lots of other AST code to use const
references to ASTContext, instead of non-const references. And I've
removed some const_cast<>s from ASTContext, as mentioned in the bug.

diffstat:
 include/clang/AST/ASTContext.h          |  370 ++++++++++++++++----------------
 include/clang/AST/Attr.h                |    8
 include/clang/AST/Decl.h                |    8
 include/clang/AST/DeclCXX.h             |    8
 include/clang/AST/DeclTemplate.h        |   10
 include/clang/AST/DeclarationName.h     |    4
 include/clang/AST/Expr.h                |   20 -
 include/clang/AST/NestedNameSpecifier.h |   13 -
 include/clang/AST/RecordLayout.h        |    4
 include/clang/AST/Stmt.h                |    2
 include/clang/AST/TemplateBase.h        |    2
 include/clang/AST/Type.h                |   40 +--
 lib/AST/ASTContext.cpp                  |  247 +++++++++++----------
 lib/AST/Decl.cpp                        |    8
 lib/AST/DeclCXX.cpp                     |   12 -
 lib/AST/DeclTemplate.cpp                |   10
 lib/AST/DeclarationName.cpp             |    2
 lib/AST/Expr.cpp                        |    4
 lib/AST/ExprConstant.cpp                |   30 +-
 lib/AST/NestedNameSpecifier.cpp         |   18 -
 lib/AST/RecordLayout.cpp                |    9
 lib/AST/RecordLayoutBuilder.cpp         |   21 +
 lib/AST/StmtProfile.cpp                 |    6
 lib/AST/TemplateBase.cpp                |    2
 lib/AST/Type.cpp                        |   27 +-
 25 files changed, 460 insertions(+), 425 deletions(-)

Comments? Or, OK to commit?

Or is no-one is interested in this bug any more? Or am I going about
it the wrong way?

Thanks,
Jay.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mutable.diff
Type: text/x-patch
Size: 133955 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110104/b0d55b89/attachment.bin>


More information about the cfe-commits mailing list