diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2012-02-11 23:51:47 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2012-02-11 23:51:47 +0000 |
commit | a935179ab73cfc638aba932eff341dcaafd17440 (patch) | |
tree | 7ea38fba82b29fd196d2c62863dd0854e6a5335b /clang/lib/AST/DeclPrinter.cpp | |
parent | 46afb551772fb6c86b0abcc85aa38c3d3c79f5d4 (diff) | |
download | bcm5719-llvm-a935179ab73cfc638aba932eff341dcaafd17440.tar.gz bcm5719-llvm-a935179ab73cfc638aba932eff341dcaafd17440.zip |
Represent C++ direct initializers as ParenListExprs before semantic analysis
instead of having a special-purpose function.
- ActOnCXXDirectInitializer, which was mostly duplication of
AddInitializerToDecl (leading e.g. to PR10620, which Eli fixed a few days
ago), is dropped completely.
- MultiInitializer, which was an ugly hack I added, is dropped again.
- We now have the infrastructure in place to distinguish between
int x = {1};
int x({1});
int x{1};
-- VarDecl now has getInitStyle(), which indicates which of the above was used.
-- CXXConstructExpr now has a flag to indicate that it represents list-
initialization, although this is not yet used.
- InstantiateInitializer was renamed to SubstInitializer and simplified.
- ActOnParenOrParenListExpr has been replaced by ActOnParenListExpr, which
always produces a ParenListExpr. Placed that so far failed to convert that
back to a ParenExpr containing comma operators have been fixed. I'm pretty
sure I could have made a crashing test case before this.
The end result is a (I hope) considerably cleaner design of initializers.
More importantly, the fact that I can now distinguish between the various
initialization kinds means that I can get the tricky generalized initializer
test cases Johannes Schaub supplied to work. (This is not yet done.)
This commit passed self-host, with the resulting compiler passing the tests. I
hope it doesn't break more complicated code. It's a pretty big change, but one
that I feel is necessary.
llvm-svn: 150318
Diffstat (limited to 'clang/lib/AST/DeclPrinter.cpp')
-rw-r--r-- | clang/lib/AST/DeclPrinter.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 5a6686d1648..32bdba1a0b2 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -621,16 +621,20 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) { Out << Name; Expr *Init = D->getInit(); if (!Policy.SuppressInitializers && Init) { - if (D->hasCXXDirectInitializer()) - Out << "("; - else { - CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(Init); - if (!CCE || CCE->getConstructor()->isCopyOrMoveConstructor()) - Out << " = "; + bool ImplicitInit = false; + if (CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init)) + ImplicitInit = D->getInitStyle() == VarDecl::CallInit && + Construct->getNumArgs() == 0 && !Construct->isListInitialization(); + if (!ImplicitInit) { + if (D->getInitStyle() == VarDecl::CallInit) + Out << "("; + else if (D->getInitStyle() == VarDecl::CInit) { + Out << " = "; + } + Init->printPretty(Out, Context, 0, Policy, Indentation); + if (D->getInitStyle() == VarDecl::CallInit) + Out << ")"; } - Init->printPretty(Out, Context, 0, Policy, Indentation); - if (D->hasCXXDirectInitializer()) - Out << ")"; } prettyPrintAttributes(D); } |