[cfe-commits] r58217 - in /cfe/trunk: Driver/PrintParserCallbacks.cpp include/clang/Parse/Action.h include/clang/Parse/Designator.h lib/Parse/ParseInit.cpp lib/Sema/Sema.h lib/Sema/SemaExpr.cpp

Chris Lattner sabre at nondot.org
Sun Oct 26 16:35:51 PDT 2008


Author: lattner
Date: Sun Oct 26 18:35:51 2008
New Revision: 58217

URL: http://llvm.org/viewvc/llvm-project?rev=58217&view=rev
Log:
pass designators into sema.  This completes parser-level designator
support as far as I know.

Modified:
    cfe/trunk/Driver/PrintParserCallbacks.cpp
    cfe/trunk/include/clang/Parse/Action.h
    cfe/trunk/include/clang/Parse/Designator.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=58217&r1=58216&r2=58217&view=diff

==============================================================================
--- cfe/trunk/Driver/PrintParserCallbacks.cpp (original)
+++ cfe/trunk/Driver/PrintParserCallbacks.cpp Sun Oct 26 18:35:51 2008
@@ -485,6 +485,7 @@
     }
     virtual ExprResult ActOnInitList(SourceLocation LParenLoc,
                                      ExprTy **InitList, unsigned NumInit,
+                                     InitListDesignations &Designators,
                                      SourceLocation RParenLoc) {
       llvm::cout << __FUNCTION__ << "\n";
       return 0;

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=58217&r1=58216&r2=58217&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Sun Oct 26 18:35:51 2008
@@ -459,6 +459,7 @@
   }
   virtual ExprResult ActOnInitList(SourceLocation LParenLoc,
                                    ExprTy **InitList, unsigned NumInit,
+                                   InitListDesignations &Designators,
                                    SourceLocation RParenLoc) {
     return 0;
   }

Modified: cfe/trunk/include/clang/Parse/Designator.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Designator.h?rev=58217&r1=58216&r2=58217&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Designator.h (original)
+++ cfe/trunk/include/clang/Parse/Designator.h Sun Oct 26 18:35:51 2008
@@ -208,6 +208,19 @@
     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;
+  }
+  
 };
 
 } // end namespace clang

Modified: cfe/trunk/lib/Parse/ParseInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseInit.cpp?rev=58217&r1=58216&r2=58217&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseInit.cpp (original)
+++ cfe/trunk/lib/Parse/ParseInit.cpp Sun Oct 26 18:35:51 2008
@@ -236,14 +236,6 @@
 Parser::ExprResult Parser::ParseBraceInitializer() {
   SourceLocation LBraceLoc = ConsumeBrace();
   
-  // We support empty initializers, but tell the user that they aren't using
-  // C99-clean code.
-  if (Tok.is(tok::r_brace)) {
-    Diag(LBraceLoc, diag::ext_gnu_empty_initializer);
-    // Match the '}'.
-    return Actions.ActOnInitList(LBraceLoc, 0, 0, ConsumeBrace());
-  }
-  
   /// InitExprs - This is the actual list of expressions contained in the
   /// initializer.
   llvm::SmallVector<ExprTy*, 8> InitExprs;
@@ -252,6 +244,15 @@
   /// was specified for it, if any.
   InitListDesignations InitExprDesignations(Actions);
 
+  // We support empty initializers, but tell the user that they aren't using
+  // C99-clean code.
+  if (Tok.is(tok::r_brace)) {
+    Diag(LBraceLoc, diag::ext_gnu_empty_initializer);
+    // Match the '}'.
+    return Actions.ActOnInitList(LBraceLoc, 0, 0, InitExprDesignations,
+                                 ConsumeBrace());
+  }
+  
   bool InitExprsOk = true;
   
   while (1) {
@@ -293,8 +294,8 @@
     if (Tok.is(tok::r_brace)) break;
   }
   if (InitExprsOk && Tok.is(tok::r_brace))
-    return Actions.ActOnInitList(LBraceLoc, &InitExprs[0], InitExprs.size(), 
-                                 ConsumeBrace());
+    return Actions.ActOnInitList(LBraceLoc, &InitExprs[0], InitExprs.size(),
+                                 InitExprDesignations, ConsumeBrace());
   
   // On error, delete any parsed subexpressions.
   for (unsigned i = 0, e = InitExprs.size(); i != e; ++i)

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=58217&r1=58216&r2=58217&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sun Oct 26 18:35:51 2008
@@ -614,6 +614,7 @@
   
   virtual ExprResult ActOnInitList(SourceLocation LParenLoc, 
                                    ExprTy **InitList, unsigned NumInit,
+                                   InitListDesignations &Designators,
                                    SourceLocation RParenLoc);
                                    
   virtual ExprResult ActOnBinOp(SourceLocation TokLoc, tok::TokenKind Kind,

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=58217&r1=58216&r2=58217&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Oct 26 18:35:51 2008
@@ -1247,11 +1247,13 @@
     if (CheckForConstantInitializer(literalExpr, literalType))
       return true;
   }
-  return new CompoundLiteralExpr(LParenLoc, literalType, literalExpr, isFileScope);
+  return new CompoundLiteralExpr(LParenLoc, literalType, literalExpr,
+                                 isFileScope);
 }
 
 Action::ExprResult Sema::
 ActOnInitList(SourceLocation LBraceLoc, ExprTy **initlist, unsigned NumInit,
+              InitListDesignations &Designators,
               SourceLocation RBraceLoc) {
   Expr **InitList = reinterpret_cast<Expr**>(initlist);
 





More information about the cfe-commits mailing list