[cfe-commits] r67415 - in /cfe/trunk: Driver/PrintParserCallbacks.cpp include/clang/Parse/Action.h include/clang/Parse/Designator.h include/clang/Parse/Parser.h lib/Parse/ParseInit.cpp lib/Sema/Sema.h lib/Sema/SemaExpr.cpp
Douglas Gregor
dgregor at apple.com
Fri Mar 20 16:11:49 PDT 2009
Author: dgregor
Date: Fri Mar 20 18:11:49 2009
New Revision: 67415
URL: http://llvm.org/viewvc/llvm-project?rev=67415&view=rev
Log:
InitListDesignations hasn't been used (ever). Eliminate it, and
simplify the parsing and action interface for designated
initializers.
Modified:
cfe/trunk/Driver/PrintParserCallbacks.cpp
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/include/clang/Parse/Designator.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseInit.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExpr.cpp
Modified: cfe/trunk/Driver/PrintParserCallbacks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/PrintParserCallbacks.cpp?rev=67415&r1=67414&r2=67415&view=diff
==============================================================================
--- cfe/trunk/Driver/PrintParserCallbacks.cpp (original)
+++ cfe/trunk/Driver/PrintParserCallbacks.cpp Fri Mar 20 18:11:49 2009
@@ -554,7 +554,6 @@
}
virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
MultiExprArg InitList,
- InitListDesignations &Designators,
SourceLocation RParenLoc) {
llvm::cout << __FUNCTION__ << "\n";
return ExprEmpty();
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=67415&r1=67414&r2=67415&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Fri Mar 20 18:11:49 2009
@@ -684,7 +684,6 @@
}
virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
MultiExprArg InitList,
- InitListDesignations &Designators,
SourceLocation RParenLoc) {
return ExprEmpty();
}
Modified: cfe/trunk/include/clang/Parse/Designator.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Designator.h?rev=67415&r1=67414&r2=67415&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Designator.h (original)
+++ cfe/trunk/include/clang/Parse/Designator.h Fri Mar 20 18:11:49 2009
@@ -192,8 +192,6 @@
/// Designation - Represent a full designation, which is a sequence of
/// designators. This class is mostly a helper for InitListDesignations.
class Designation {
- friend class InitListDesignations;
-
/// InitIndex - The index of the initializer expression this is for. For
/// example, if the initializer were "{ A, .foo=B, C }" a Designation would
/// exist with InitIndex=1, because element #1 has a designation.
@@ -204,12 +202,15 @@
Designation(unsigned Idx) : InitIndex(Idx) {}
public:
-
+ Designation() : InitIndex(4000) {}
+
/// AddDesignator - Add a designator to the end of this list.
void AddDesignator(Designator D) {
Designators.push_back(D);
}
-
+
+ bool empty() const { return Designators.empty(); }
+
unsigned getNumDesignators() const { return Designators.size(); }
const Designator &getDesignator(unsigned Idx) const {
assert(Idx < Designators.size());
@@ -230,67 +231,7 @@
Designators[i].FreeExprs(Actions);
}
};
-
-
-/// InitListDesignations - This contains all the designators for an
-/// initializer list. This is somewhat like a two dimensional array of
-/// Designators, but is optimized for the cases when designators are not
-/// present.
-class InitListDesignations {
- Action &Actions;
-
- /// Designations - All of the designators in this init list. These are kept
- /// in order sorted by their InitIndex.
- llvm::SmallVector<Designation, 3> Designations;
-
- InitListDesignations(const InitListDesignations&); // DO NOT IMPLEMENT
- void operator=(const InitListDesignations&); // DO NOT IMPLEMENT
-public:
- InitListDesignations(Action &A) : Actions(A) {}
-
- ~InitListDesignations() {
- // Release any unclaimed memory for the expressions in this init list.
- for (unsigned i = 0, e = Designations.size(); i != e; ++i)
- Designations[i].FreeExprs(Actions);
- }
-
- bool hasAnyDesignators() const {
- return !Designations.empty();
- }
-
- Designation &CreateDesignation(unsigned Idx) {
- assert((Designations.empty() || Designations.back().InitIndex < Idx) &&
- "not sorted by InitIndex!");
- Designations.push_back(Designation(Idx));
- return Designations.back();
- }
-
- /// getDesignationForInitializer - If there is a designator for the specified
- /// initializer, return it, otherwise return null.
- const Designation *getDesignationForInitializer(unsigned Idx) const {
- // The common case is no designators.
- if (!hasAnyDesignators()) return 0;
-
- // FIXME: This should do a binary search, not a linear one.
- for (unsigned i = 0, e = Designations.size(); i != e; ++i)
- if (Designations[i].InitIndex == Idx)
- return &Designations[i];
- return 0;
- }
-
- /// EraseDesignation - If there is a designator for the specified initializer
- /// index, remove it.
- void EraseDesignation(unsigned Idx) {
- Designation *D =const_cast<Designation*>(getDesignationForInitializer(Idx));
- if (D == 0) return; // No designator.
-
- D->FreeExprs(Actions);
- unsigned SlotNo = D-&Designations[0];
- Designations.erase(Designations.begin()+SlotNo);
- }
-
-};
-
+
} // end namespace clang
#endif
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=67415&r1=67414&r2=67415&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Fri Mar 20 18:11:49 2009
@@ -718,8 +718,7 @@
return ParseBraceInitializer();
}
OwningExprResult ParseBraceInitializer();
- OwningExprResult ParseInitializerWithPotentialDesignator(
- InitListDesignations &D, unsigned InitNum);
+ OwningExprResult ParseInitializerWithPotentialDesignator();
//===--------------------------------------------------------------------===//
// clang Expressions
Modified: cfe/trunk/lib/Parse/ParseInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseInit.cpp?rev=67415&r1=67414&r2=67415&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseInit.cpp (original)
+++ cfe/trunk/lib/Parse/ParseInit.cpp Fri Mar 20 18:11:49 2009
@@ -57,9 +57,7 @@
/// initializer (because it is an expression). We need to consider this case
/// when parsing array designators.
///
-Parser::OwningExprResult Parser::
-ParseInitializerWithPotentialDesignator(InitListDesignations &Designations,
- unsigned InitNum) {
+Parser::OwningExprResult Parser::ParseInitializerWithPotentialDesignator() {
// If this is the old-style GNU extension:
// designation ::= identifier ':'
@@ -74,7 +72,7 @@
assert(Tok.is(tok::colon) && "MayBeDesignationStart not working properly!");
SourceLocation ColonLoc = ConsumeToken();
- Designation &D = Designations.CreateDesignation(InitNum);
+ Designation D;
D.AddDesignator(Designator::getField(FieldName, SourceLocation(), NameLoc));
return Actions.ActOnDesignatedInitializer(D, ColonLoc, true,
ParseInitializer());
@@ -83,7 +81,7 @@
// Desig - This is initialized when we see our first designator. We may have
// an objc message send with no designator, so we don't want to create this
// eagerly.
- Designation *Desig = 0;
+ Designation Desig;
// Parse each designator in the designator list until we find an initializer.
while (Tok.is(tok::period) || Tok.is(tok::l_square)) {
@@ -91,17 +89,13 @@
// designator: '.' identifier
SourceLocation DotLoc = ConsumeToken();
- // Create designation if we haven't already.
- if (Desig == 0)
- Desig = &Designations.CreateDesignation(InitNum);
-
if (Tok.isNot(tok::identifier)) {
Diag(Tok.getLocation(), diag::err_expected_field_designator);
return ExprError();
}
- Desig->AddDesignator(Designator::getField(Tok.getIdentifierInfo(), DotLoc,
- Tok.getLocation()));
+ Desig.AddDesignator(Designator::getField(Tok.getIdentifierInfo(), DotLoc,
+ Tok.getLocation()));
ConsumeToken(); // Eat the identifier.
continue;
}
@@ -129,14 +123,12 @@
// If we have exactly one array designator, this used the GNU
// 'designation: array-designator' extension, otherwise there should be no
// designators at all!
- if (Desig) {
- if (Desig->getNumDesignators() == 1 &&
- (Desig->getDesignator(0).isArrayDesignator() ||
- Desig->getDesignator(0).isArrayRangeDesignator()))
- Diag(StartLoc, diag::ext_gnu_missing_equal_designator);
- else
- Diag(Tok, diag::err_expected_equal_designator);
- }
+ if (Desig.getNumDesignators() == 1 &&
+ (Desig.getDesignator(0).isArrayDesignator() ||
+ Desig.getDesignator(0).isArrayRangeDesignator()))
+ Diag(StartLoc, diag::ext_gnu_missing_equal_designator);
+ else if (Desig.getNumDesignators() > 0)
+ Diag(Tok, diag::err_expected_equal_designator);
IdentifierInfo *Name = Tok.getIdentifierInfo();
SourceLocation NameLoc = ConsumeToken();
@@ -163,28 +155,21 @@
// If we have exactly one array designator, this used the GNU
// 'designation: array-designator' extension, otherwise there should be no
// designators at all!
- if (Desig) {
- if (Desig->getNumDesignators() == 1 &&
- (Desig->getDesignator(0).isArrayDesignator() ||
- Desig->getDesignator(0).isArrayRangeDesignator()))
- Diag(StartLoc, diag::ext_gnu_missing_equal_designator);
- else
- Diag(Tok, diag::err_expected_equal_designator);
- }
+ if (Desig.getNumDesignators() == 1 &&
+ (Desig.getDesignator(0).isArrayDesignator() ||
+ Desig.getDesignator(0).isArrayRangeDesignator()))
+ Diag(StartLoc, diag::ext_gnu_missing_equal_designator);
+ else if (Desig.getNumDesignators() > 0)
+ Diag(Tok, diag::err_expected_equal_designator);
return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
SourceLocation(),
0, move(Idx));
}
- // Create designation if we haven't already.
- if (Desig == 0)
- Desig = &Designations.CreateDesignation(InitNum);
-
// If this is a normal array designator, remember it.
if (Tok.isNot(tok::ellipsis)) {
- Desig->AddDesignator(Designator::getArray(Idx.release(),
- StartLoc));
+ Desig.AddDesignator(Designator::getArray(Idx.release(), StartLoc));
} else {
// Handle the gnu array range extension.
Diag(Tok, diag::ext_gnu_array_range);
@@ -195,25 +180,25 @@
SkipUntil(tok::r_square);
return move(RHS);
}
- Desig->AddDesignator(Designator::getArrayRange(Idx.release(),
- RHS.release(),
- StartLoc, EllipsisLoc));
+ Desig.AddDesignator(Designator::getArrayRange(Idx.release(),
+ RHS.release(),
+ StartLoc, EllipsisLoc));
}
SourceLocation EndLoc = MatchRHSPunctuation(tok::r_square, StartLoc);
- Desig->getDesignator(Desig->getNumDesignators() - 1).setRBracketLoc(EndLoc);
+ Desig.getDesignator(Desig.getNumDesignators() - 1).setRBracketLoc(EndLoc);
}
// Okay, we're done with the designator sequence. We know that there must be
// at least one designator, because the only case we can get into this method
// without a designator is when we have an objc message send. That case is
// handled and returned from above.
- assert(Desig && "Designator didn't get created?");
+ assert(!Desig.empty() && "Designator is empty?");
// Handle a normal designator sequence end, which is an equal.
if (Tok.is(tok::equal)) {
SourceLocation EqualLoc = ConsumeToken();
- return Actions.ActOnDesignatedInitializer(*Desig, EqualLoc, false,
+ return Actions.ActOnDesignatedInitializer(Desig, EqualLoc, false,
ParseInitializer());
}
@@ -221,9 +206,9 @@
// an initializer. If we have exactly one array designator, this
// is the GNU 'designation: array-designator' extension. Otherwise, it is a
// parse error.
- if (Desig->getNumDesignators() == 1 &&
- (Desig->getDesignator(0).isArrayDesignator() ||
- Desig->getDesignator(0).isArrayRangeDesignator())) {
+ if (Desig.getNumDesignators() == 1 &&
+ (Desig.getDesignator(0).isArrayDesignator() ||
+ Desig.getDesignator(0).isArrayRangeDesignator())) {
Diag(Tok, diag::ext_gnu_missing_equal_designator);
return ParseInitializer();
}
@@ -252,17 +237,13 @@
/// initializer.
ExprVector InitExprs(Actions);
- /// ExprDesignators - For each initializer, keep track of the designator that
- /// was specified for it, if any.
- InitListDesignations InitExprDesignations(Actions);
-
if (Tok.is(tok::r_brace)) {
// Empty initializers are a C++ feature and a GNU extension to C.
if (!getLang().CPlusPlus)
Diag(LBraceLoc, diag::ext_gnu_empty_initializer);
// Match the '}'.
return Actions.ActOnInitList(LBraceLoc, Action::MultiExprArg(Actions),
- InitExprDesignations, ConsumeBrace());
+ ConsumeBrace());
}
bool InitExprsOk = true;
@@ -273,19 +254,10 @@
// If we know that this cannot be a designation, just parse the nested
// initializer directly.
OwningExprResult SubElt(Actions);
- if (!MayBeDesignationStart(Tok.getKind(), PP))
+ if (MayBeDesignationStart(Tok.getKind(), PP))
+ SubElt = ParseInitializerWithPotentialDesignator();
+ else
SubElt = ParseInitializer();
- else {
- SubElt = ParseInitializerWithPotentialDesignator(InitExprDesignations,
- InitExprs.size());
-
- // If we had an erroneous initializer, and we had a potentially valid
- // designator, make sure to remove the designator from
- // InitExprDesignations, otherwise we'll end up with a designator with no
- // matching initializer.
- if (SubElt.isInvalid())
- InitExprDesignations.EraseDesignation(InitExprs.size());
- }
// If we couldn't parse the subelement, bail out.
if (!SubElt.isInvalid()) {
@@ -318,7 +290,7 @@
}
if (InitExprsOk && Tok.is(tok::r_brace))
return Actions.ActOnInitList(LBraceLoc, move_arg(InitExprs),
- InitExprDesignations, ConsumeBrace());
+ ConsumeBrace());
// Match the '}'.
MatchRHSPunctuation(tok::r_brace, LBraceLoc);
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=67415&r1=67414&r2=67415&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Mar 20 18:11:49 2009
@@ -1267,7 +1267,6 @@
virtual OwningExprResult ActOnInitList(SourceLocation LParenLoc,
MultiExprArg InitList,
- InitListDesignations &Designators,
SourceLocation RParenLoc);
virtual OwningExprResult ActOnDesignatedInitializer(Designation &Desig,
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=67415&r1=67414&r2=67415&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Mar 20 18:11:49 2009
@@ -2395,7 +2395,6 @@
Action::OwningExprResult
Sema::ActOnInitList(SourceLocation LBraceLoc, MultiExprArg initlist,
- InitListDesignations &Designators,
SourceLocation RBraceLoc) {
unsigned NumInit = initlist.size();
Expr **InitList = reinterpret_cast<Expr**>(initlist.release());
More information about the cfe-commits
mailing list