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 | 5b9cc5df25c2198f270dd1d5c438fdce70d4051d (patch) | |
tree | 8d2c36bd9fe0e47cc5ce4e5a2fd02d8dd0e31f7f /lib/Sema/MultiInitializer.cpp | |
parent | ecfcd5655758955d8958dc2a7a7b2c8eff2395b7 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150318 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/MultiInitializer.cpp')
-rw-r--r-- | lib/Sema/MultiInitializer.cpp | 93 |
1 files changed, 0 insertions, 93 deletions
diff --git a/lib/Sema/MultiInitializer.cpp b/lib/Sema/MultiInitializer.cpp deleted file mode 100644 index d8944efba3..0000000000 --- a/lib/Sema/MultiInitializer.cpp +++ /dev/null @@ -1,93 +0,0 @@ -//===--- MultiInitializer.cpp - Initializer expression group ----*- C++ -*-===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements the MultiInitializer class, which can represent a list -// initializer or a parentheses-wrapped group of expressions in a C++ member -// initializer. -// -//===----------------------------------------------------------------------===// - -#include "clang/Sema/MultiInitializer.h" -#include "clang/Sema/Initialization.h" -#include "clang/Sema/Sema.h" -#include "clang/AST/Expr.h" - -using namespace clang; - -InitListExpr *MultiInitializer::getInitList() const { - return cast<InitListExpr>(InitListOrExpressions.get<Expr*>()); -} - -SourceLocation MultiInitializer::getStartLoc() const { - return isInitializerList() ? getInitList()->getLBraceLoc() : LParenLoc; -} - -SourceLocation MultiInitializer::getEndLoc() const { - return isInitializerList() ? getInitList()->getRBraceLoc() : RParenLoc; -} - -MultiInitializer::iterator MultiInitializer::begin() const { - return isInitializerList() ? getInitList()->getInits() : getExpressions(); -} - -MultiInitializer::iterator MultiInitializer::end() const { - if (isInitializerList()) { - InitListExpr *ILE = getInitList(); - return ILE->getInits() + ILE->getNumInits(); - } - return getExpressions() + NumInitializers; -} - -bool MultiInitializer::isTypeDependent() const { - if (isInitializerList()) - return getInitList()->isTypeDependent(); - for (iterator I = begin(), E = end(); I != E; ++I) { - if ((*I)->isTypeDependent()) - return true; - } - return false; -} - -bool MultiInitializer::DiagnoseUnexpandedParameterPack(Sema &SemaRef) const { - if (isInitializerList()) - return SemaRef.DiagnoseUnexpandedParameterPack(getInitList(), - Sema::UPPC_Initializer); - for (iterator I = begin(), E = end(); I != E; ++I) { - if (SemaRef.DiagnoseUnexpandedParameterPack(*I, Sema::UPPC_Initializer)) - return true; - } - return false; -} - -Expr *MultiInitializer::CreateInitExpr(ASTContext &Ctx, QualType T) const { - if (isInitializerList()) - return InitListOrExpressions.get<Expr*>(); - - return new (Ctx) ParenListExpr(Ctx, LParenLoc, getExpressions(), - NumInitializers, RParenLoc, T); -} - -ExprResult MultiInitializer::PerformInit(Sema &SemaRef, - InitializedEntity Entity, - InitializationKind Kind) const { - Expr *Single; - Expr **Args; - unsigned NumArgs; - if (isInitializerList()) { - Single = InitListOrExpressions.get<Expr*>(); - Args = &Single; - NumArgs = 1; - } else { - Args = getExpressions(); - NumArgs = NumInitializers; - } - InitializationSequence InitSeq(SemaRef, Entity, Kind, Args, NumArgs); - return InitSeq.Perform(SemaRef, Entity, Kind, - MultiExprArg(SemaRef, Args, NumArgs), 0); -} |