[cfe-commits] r67885 - in /cfe/trunk: include/clang/AST/Expr.h include/clang/Basic/DiagnosticParseKinds.td include/clang/Parse/Action.h lib/AST/ASTContext.cpp lib/AST/Expr.cpp lib/Parse/ParseInit.cpp lib/Sema/Sema.h lib/Sema/SemaInit.cpp test/Sema/designated-initializers.c
Douglas Gregor
dgregor at apple.com
Fri Mar 27 17:41:23 PDT 2009
Author: dgregor
Date: Fri Mar 27 19:41:23 2009
New Revision: 67885
URL: http://llvm.org/viewvc/llvm-project?rev=67885&view=rev
Log:
Make our diagnostics about the obsolete GNU designated-initializer
syntax into extension warnings, and provide code-modification hints
showing how to fix the problem.
Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Parse/ParseInit.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/test/Sema/designated-initializers.c
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=67885&r1=67884&r2=67885&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Mar 27 19:41:23 2009
@@ -1860,9 +1860,9 @@
/// expression.
SourceLocation EqualOrColonLoc;
- /// Whether this designated initializer used the GNU deprecated ':'
+ /// Whether this designated initializer used the GNU deprecated
/// syntax rather than the C99 '=' syntax.
- bool UsesColonSyntax : 1;
+ bool GNUSyntax : 1;
/// The number of designators in this initializer expression.
unsigned NumDesignators : 15;
@@ -1873,10 +1873,10 @@
unsigned NumSubExprs : 16;
DesignatedInitExpr(QualType Ty, unsigned NumDesignators,
- SourceLocation EqualOrColonLoc, bool UsesColonSyntax,
+ SourceLocation EqualOrColonLoc, bool GNUSyntax,
unsigned NumSubExprs)
: Expr(DesignatedInitExprClass, Ty),
- EqualOrColonLoc(EqualOrColonLoc), UsesColonSyntax(UsesColonSyntax),
+ EqualOrColonLoc(EqualOrColonLoc), GNUSyntax(GNUSyntax),
NumDesignators(NumDesignators), NumSubExprs(NumSubExprs) { }
public:
@@ -2022,7 +2022,7 @@
unsigned NumDesignators,
Expr **IndexExprs, unsigned NumIndexExprs,
SourceLocation EqualOrColonLoc,
- bool UsesColonSyntax, Expr *Init);
+ bool GNUSyntax, Expr *Init);
/// @brief Returns the number of designators in this initializer.
unsigned size() const { return NumDesignators; }
@@ -2041,8 +2041,8 @@
SourceLocation getEqualOrColonLoc() const { return EqualOrColonLoc; }
/// @brief Determines whether this designated initializer used the
- /// GNU 'fieldname:' syntax or the C99 '=' syntax.
- bool usesColonSyntax() const { return UsesColonSyntax; }
+ /// deprecated GNU syntax for designated initializers.
+ bool usesGNUSyntax() const { return GNUSyntax; }
/// @brief Retrieve the initializer value.
Expr *getInit() const {
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=67885&r1=67884&r2=67885&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Mar 27 19:41:23 2009
@@ -57,10 +57,10 @@
def ext_gnu_empty_initializer : Extension<
"use of GNU empty initializer extension">;
def ext_gnu_array_range : Extension<"use of GNU array range extension">;
-def ext_gnu_missing_equal_designator : Extension<
+def ext_gnu_missing_equal_designator : ExtWarn<
"use of GNU 'missing =' extension in designator">;
def err_expected_equal_designator : Error<"expected '=' or another designator">;
-def ext_gnu_old_style_field_designator : Extension<
+def ext_gnu_old_style_field_designator : ExtWarn<
"use of GNU old-style field designator extension">;
def ext_gnu_case_range : Extension<"use of GNU case range extension">;
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=67885&r1=67884&r2=67885&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Fri Mar 27 19:41:23 2009
@@ -703,15 +703,15 @@
/// @param Loc The location of the '=' or ':' prior to the
/// initialization expression.
///
- /// @param UsedColonSyntax If true, then this designated initializer
- /// used the deprecated GNU syntax @c fieldname:foo rather than the
- /// C99 syntax @c .fieldname=foo.
+ /// @param GNUSyntax If true, then this designated initializer used
+ /// the deprecated GNU syntax @c fieldname:foo or @c [expr]foo rather
+ /// than the C99 syntax @c .fieldname=foo or @c [expr]=foo.
///
/// @param Init The value that the entity (or entities) described by
/// the designation will be initialized with.
virtual OwningExprResult ActOnDesignatedInitializer(Designation &Desig,
SourceLocation Loc,
- bool UsedColonSyntax,
+ bool GNUSyntax,
OwningExprResult Init) {
return ExprEmpty();
}
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=67885&r1=67884&r2=67885&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Mar 27 19:41:23 2009
@@ -89,7 +89,6 @@
GlobalNestedNameSpecifier->Destroy(*this);
TUDecl->Destroy(*this);
-
}
void ASTContext::PrintStats() const {
Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=67885&r1=67884&r2=67885&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Fri Mar 27 19:41:23 2009
@@ -1534,7 +1534,7 @@
Designator &First =
*const_cast<DesignatedInitExpr*>(this)->designators_begin();
if (First.isFieldDesignator()) {
- if (UsesColonSyntax)
+ if (GNUSyntax)
StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc);
else
StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc);
Modified: cfe/trunk/lib/Parse/ParseInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseInit.cpp?rev=67885&r1=67884&r2=67885&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseInit.cpp (original)
+++ cfe/trunk/lib/Parse/ParseInit.cpp Fri Mar 27 19:41:23 2009
@@ -64,14 +64,22 @@
// Handle it as a field designator. Otherwise, this must be the start of a
// normal expression.
if (Tok.is(tok::identifier)) {
- Diag(Tok, diag::ext_gnu_old_style_field_designator);
-
const IdentifierInfo *FieldName = Tok.getIdentifierInfo();
+
+ std::string NewSyntax(".");
+ NewSyntax += FieldName->getName();
+ NewSyntax += " = ";
+
SourceLocation NameLoc = ConsumeToken(); // Eat the identifier.
assert(Tok.is(tok::colon) && "MayBeDesignationStart not working properly!");
SourceLocation ColonLoc = ConsumeToken();
+ Diag(Tok, diag::ext_gnu_old_style_field_designator)
+ << CodeModificationHint::CreateReplacement(SourceRange(NameLoc,
+ ColonLoc),
+ NewSyntax);
+
Designation D;
D.AddDesignator(Designator::getField(FieldName, SourceLocation(), NameLoc));
return Actions.ActOnDesignatedInitializer(D, ColonLoc, true,
@@ -209,8 +217,9 @@
if (Desig.getNumDesignators() == 1 &&
(Desig.getDesignator(0).isArrayDesignator() ||
Desig.getDesignator(0).isArrayRangeDesignator())) {
- Diag(Tok, diag::ext_gnu_missing_equal_designator);
- return Actions.ActOnDesignatedInitializer(Desig, SourceLocation(),
+ Diag(Tok, diag::ext_gnu_missing_equal_designator)
+ << CodeModificationHint::CreateInsertion(Tok.getLocation(), "=");
+ return Actions.ActOnDesignatedInitializer(Desig, Tok.getLocation(),
true, ParseInitializer());
}
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=67885&r1=67884&r2=67885&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Fri Mar 27 19:41:23 2009
@@ -1285,7 +1285,7 @@
virtual OwningExprResult ActOnDesignatedInitializer(Designation &Desig,
SourceLocation Loc,
- bool UsedColonSyntax,
+ bool GNUSyntax,
OwningExprResult Init);
virtual OwningExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc,
Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=67885&r1=67884&r2=67885&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Fri Mar 27 19:41:23 2009
@@ -1548,7 +1548,7 @@
Sema::OwningExprResult Sema::ActOnDesignatedInitializer(Designation &Desig,
SourceLocation Loc,
- bool UsedColonSyntax,
+ bool GNUSyntax,
OwningExprResult Init) {
typedef DesignatedInitExpr::Designator ASTDesignator;
@@ -1622,7 +1622,7 @@
DesignatedInitExpr *DIE
= DesignatedInitExpr::Create(Context, &Designators[0], Designators.size(),
&InitExpressions[0], InitExpressions.size(),
- Loc, UsedColonSyntax,
+ Loc, GNUSyntax,
static_cast<Expr *>(Init.release()));
return Owned(DIE);
}
Modified: cfe/trunk/test/Sema/designated-initializers.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/designated-initializers.c?rev=67885&r1=67884&r2=67885&view=diff
==============================================================================
--- cfe/trunk/test/Sema/designated-initializers.c (original)
+++ cfe/trunk/test/Sema/designated-initializers.c Fri Mar 27 19:41:23 2009
@@ -18,6 +18,7 @@
};
int iarray3[10] = {
+ [3] 2, // expected-warning{{use of GNU 'missing =' extension in designator}}
[5 ... 12] = 2 // expected-error{{array designator index (12) exceeds array bounds (10)}}
};
@@ -28,7 +29,7 @@
struct point p1 = {
.y = 1.0,
- x: 2.0,
+ x: 2.0, // expected-warning{{}}
.a = 4.0, // expected-error{{field designator 'a' does not refer to any field in type 'struct point'}}
};
More information about the cfe-commits
mailing list