[cfe-commits] r38947 - in /cfe/cfe/trunk: AST/Sema.cpp Sema/Sema.cpp include/clang/Parse/Action.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:26:07 PDT 2007


Author: sabre
Date: Wed Jul 11 11:26:06 2007
New Revision: 38947

URL: http://llvm.org/viewvc/llvm-project?rev=38947&view=rev
Log:
Allow expression actions to fail

Modified:
    cfe/cfe/trunk/AST/Sema.cpp
    cfe/cfe/trunk/Sema/Sema.cpp
    cfe/cfe/trunk/include/clang/Parse/Action.h

Modified: cfe/cfe/trunk/AST/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.cpp?rev=38947&r1=38946&r2=38947&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Sema.cpp (original)
+++ cfe/cfe/trunk/AST/Sema.cpp Wed Jul 11 11:26:06 2007
@@ -42,39 +42,39 @@
   // Expression Parsing Callbacks.
 
   // Primary Expressions.
-  virtual ExprTy *ParseSimplePrimaryExpr(const LexerToken &Tok);
-  virtual ExprTy *ParseIntegerConstant(const LexerToken &Tok);
-  virtual ExprTy *ParseFloatingConstant(const LexerToken &Tok);
-  virtual ExprTy *ParseParenExpr(SourceLocation L, SourceLocation R,
-                                 ExprTy *Val);
+  virtual ExprResult ParseSimplePrimaryExpr(const LexerToken &Tok);
+  virtual ExprResult ParseIntegerConstant(const LexerToken &Tok);
+  virtual ExprResult ParseFloatingConstant(const LexerToken &Tok);
+  virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R,
+                                    ExprTy *Val);
   
   // Binary/Unary Operators.  'Tok' is the token for the operator.
-  virtual ExprTy *ParseUnaryOp(const LexerToken &Tok, ExprTy *Input);
-  virtual ExprTy *ParsePostfixUnaryOp(const LexerToken &Tok, ExprTy *Input);
+  virtual ExprResult ParseUnaryOp(const LexerToken &Tok, ExprTy *Input);
+  virtual ExprResult ParsePostfixUnaryOp(const LexerToken &Tok, ExprTy *Input);
   
-  virtual ExprTy *ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
-                                          ExprTy *Idx, SourceLocation RLoc);
-  virtual ExprTy *ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc,
-                                           tok::TokenKind OpKind,
-                                           SourceLocation MemberLoc,
-                                           IdentifierInfo &Member);
+  virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
+                                             ExprTy *Idx, SourceLocation RLoc);
+  virtual ExprResult ParseMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc,
+                                              tok::TokenKind OpKind,
+                                              SourceLocation MemberLoc,
+                                              IdentifierInfo &Member);
   
   /// ParseCallExpr - Handle a call to Fn with the specified array of arguments.
   /// This provides the location of the left/right parens and a list of comma
   /// locations.
-  virtual ExprTy *ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
-                                ExprTy **Args, unsigned NumArgs,
-                                SourceLocation *CommaLocs,
-                                SourceLocation RParenLoc);
+  virtual ExprResult ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
+                                   ExprTy **Args, unsigned NumArgs,
+                                   SourceLocation *CommaLocs,
+                                   SourceLocation RParenLoc);
   
   
-  virtual ExprTy *ParseBinOp(const LexerToken &Tok, ExprTy *LHS, ExprTy *RHS);
+  virtual ExprResult ParseBinOp(const LexerToken &Tok, ExprTy *LHS,ExprTy *RHS);
   
   /// ParseConditionalOp - Parse a ?: operation.  Note that 'LHS' may be null
   /// in the case of a the GNU conditional expr extension.
-  virtual ExprTy *ParseConditionalOp(SourceLocation QuestionLoc, 
-                                     SourceLocation ColonLoc,
-                                     ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
+  virtual ExprResult ParseConditionalOp(SourceLocation QuestionLoc, 
+                                        SourceLocation ColonLoc,
+                                        ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
 };
 } // end anonymous namespace
 
@@ -123,7 +123,7 @@
 // Expression Parsing Callbacks.
 //===--------------------------------------------------------------------===//
 
-ASTBuilder::ExprTy *ASTBuilder::ParseSimplePrimaryExpr(const LexerToken &Tok) {
+Action::ExprResult ASTBuilder::ParseSimplePrimaryExpr(const LexerToken &Tok) {
   switch (Tok.getKind()) {
   default:
     assert(0 && "Unknown simple primary expr!");
@@ -142,16 +142,16 @@
   }
 }
 
-ASTBuilder::ExprTy *ASTBuilder::ParseIntegerConstant(const LexerToken &Tok) {
+Action::ExprResult ASTBuilder::ParseIntegerConstant(const LexerToken &Tok) {
   return new IntegerConstant();
 }
-ASTBuilder::ExprTy *ASTBuilder::ParseFloatingConstant(const LexerToken &Tok) {
+Action::ExprResult ASTBuilder::ParseFloatingConstant(const LexerToken &Tok) {
   return new FloatingConstant();
 }
 
-ASTBuilder::ExprTy *ASTBuilder::ParseParenExpr(SourceLocation L, 
-                                               SourceLocation R,
-                                               ExprTy *Val) {
+Action::ExprResult ASTBuilder::ParseParenExpr(SourceLocation L, 
+                                              SourceLocation R,
+                                              ExprTy *Val) {
   // FIXME: This is obviously just for testing.
   ((Expr*)Val)->dump();
   if (!FullLocInfo) return Val;
@@ -160,8 +160,8 @@
 }
 
 // Unary Operators.  'Tok' is the token for the operator.
-ASTBuilder::ExprTy *ASTBuilder::ParseUnaryOp(const LexerToken &Tok, 
-                                             ExprTy *Input) {
+Action::ExprResult ASTBuilder::ParseUnaryOp(const LexerToken &Tok,
+                                            ExprTy *Input) {
   UnaryOperator::Opcode Opc;
   switch (Tok.getKind()) {
   default: assert(0 && "Unknown unary op!");
@@ -183,8 +183,8 @@
     return new UnaryOperatorLOC(Tok.getLocation(), (Expr*)Input, Opc);
 }
 
-ASTBuilder::ExprTy *ASTBuilder::ParsePostfixUnaryOp(const LexerToken &Tok,
-                                                    ExprTy *Input) {
+Action::ExprResult ASTBuilder::ParsePostfixUnaryOp(const LexerToken &Tok,
+                                                   ExprTy *Input) {
   UnaryOperator::Opcode Opc;
   switch (Tok.getKind()) {
   default: assert(0 && "Unknown unary op!");
@@ -198,7 +198,7 @@
     return new UnaryOperatorLOC(Tok.getLocation(), (Expr*)Input, Opc);
 }
 
-ASTBuilder::ExprTy *ASTBuilder::
+Action::ExprResult ASTBuilder::
 ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
                         ExprTy *Idx, SourceLocation RLoc) {
   if (!FullLocInfo)
@@ -207,7 +207,7 @@
     return new ArraySubscriptExprLOC((Expr*)Base, LLoc, (Expr*)Idx, RLoc);
 }
 
-ASTBuilder::ExprTy *ASTBuilder::
+Action::ExprResult ASTBuilder::
 ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc,
                          tok::TokenKind OpKind, SourceLocation MemberLoc,
                          IdentifierInfo &Member) {
@@ -221,7 +221,7 @@
 /// ParseCallExpr - Handle a call to Fn with the specified array of arguments.
 /// This provides the location of the left/right parens and a list of comma
 /// locations.
-ASTBuilder::ExprTy *ASTBuilder::
+Action::ExprResult ASTBuilder::
 ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
               ExprTy **Args, unsigned NumArgs,
               SourceLocation *CommaLocs, SourceLocation RParenLoc) {
@@ -234,8 +234,8 @@
 
 
 // Binary Operators.  'Tok' is the token for the operator.
-ASTBuilder::ExprTy *ASTBuilder::ParseBinOp(const LexerToken &Tok, ExprTy *LHS,
-                                           ExprTy *RHS) {
+Action::ExprResult ASTBuilder::ParseBinOp(const LexerToken &Tok, ExprTy *LHS,
+                                          ExprTy *RHS) {
   BinaryOperator::Opcode Opc;
   switch (Tok.getKind()) {
   default: assert(0 && "Unknown binop!");
@@ -279,10 +279,10 @@
 
 /// ParseConditionalOp - Parse a ?: operation.  Note that 'LHS' may be null
 /// in the case of a the GNU conditional expr extension.
-ASTBuilder::ExprTy *ASTBuilder::ParseConditionalOp(SourceLocation QuestionLoc, 
-                                                   SourceLocation ColonLoc,
-                                                   ExprTy *Cond, ExprTy *LHS,
-                                                   ExprTy *RHS) {
+Action::ExprResult ASTBuilder::ParseConditionalOp(SourceLocation QuestionLoc, 
+                                                  SourceLocation ColonLoc,
+                                                  ExprTy *Cond, ExprTy *LHS,
+                                                  ExprTy *RHS) {
   if (!FullLocInfo)
     return new ConditionalOperator((Expr*)Cond, (Expr*)LHS, (Expr*)RHS);
   else

Modified: cfe/cfe/trunk/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.cpp?rev=38947&r1=38946&r2=38947&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/cfe/trunk/Sema/Sema.cpp Wed Jul 11 11:26:06 2007
@@ -42,39 +42,39 @@
   // Expression Parsing Callbacks.
 
   // Primary Expressions.
-  virtual ExprTy *ParseSimplePrimaryExpr(const LexerToken &Tok);
-  virtual ExprTy *ParseIntegerConstant(const LexerToken &Tok);
-  virtual ExprTy *ParseFloatingConstant(const LexerToken &Tok);
-  virtual ExprTy *ParseParenExpr(SourceLocation L, SourceLocation R,
-                                 ExprTy *Val);
+  virtual ExprResult ParseSimplePrimaryExpr(const LexerToken &Tok);
+  virtual ExprResult ParseIntegerConstant(const LexerToken &Tok);
+  virtual ExprResult ParseFloatingConstant(const LexerToken &Tok);
+  virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R,
+                                    ExprTy *Val);
   
   // Binary/Unary Operators.  'Tok' is the token for the operator.
-  virtual ExprTy *ParseUnaryOp(const LexerToken &Tok, ExprTy *Input);
-  virtual ExprTy *ParsePostfixUnaryOp(const LexerToken &Tok, ExprTy *Input);
+  virtual ExprResult ParseUnaryOp(const LexerToken &Tok, ExprTy *Input);
+  virtual ExprResult ParsePostfixUnaryOp(const LexerToken &Tok, ExprTy *Input);
   
-  virtual ExprTy *ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
-                                          ExprTy *Idx, SourceLocation RLoc);
-  virtual ExprTy *ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc,
-                                           tok::TokenKind OpKind,
-                                           SourceLocation MemberLoc,
-                                           IdentifierInfo &Member);
+  virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
+                                             ExprTy *Idx, SourceLocation RLoc);
+  virtual ExprResult ParseMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc,
+                                              tok::TokenKind OpKind,
+                                              SourceLocation MemberLoc,
+                                              IdentifierInfo &Member);
   
   /// ParseCallExpr - Handle a call to Fn with the specified array of arguments.
   /// This provides the location of the left/right parens and a list of comma
   /// locations.
-  virtual ExprTy *ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
-                                ExprTy **Args, unsigned NumArgs,
-                                SourceLocation *CommaLocs,
-                                SourceLocation RParenLoc);
+  virtual ExprResult ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
+                                   ExprTy **Args, unsigned NumArgs,
+                                   SourceLocation *CommaLocs,
+                                   SourceLocation RParenLoc);
   
   
-  virtual ExprTy *ParseBinOp(const LexerToken &Tok, ExprTy *LHS, ExprTy *RHS);
+  virtual ExprResult ParseBinOp(const LexerToken &Tok, ExprTy *LHS,ExprTy *RHS);
   
   /// ParseConditionalOp - Parse a ?: operation.  Note that 'LHS' may be null
   /// in the case of a the GNU conditional expr extension.
-  virtual ExprTy *ParseConditionalOp(SourceLocation QuestionLoc, 
-                                     SourceLocation ColonLoc,
-                                     ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
+  virtual ExprResult ParseConditionalOp(SourceLocation QuestionLoc, 
+                                        SourceLocation ColonLoc,
+                                        ExprTy *Cond, ExprTy *LHS, ExprTy *RHS);
 };
 } // end anonymous namespace
 
@@ -123,7 +123,7 @@
 // Expression Parsing Callbacks.
 //===--------------------------------------------------------------------===//
 
-ASTBuilder::ExprTy *ASTBuilder::ParseSimplePrimaryExpr(const LexerToken &Tok) {
+Action::ExprResult ASTBuilder::ParseSimplePrimaryExpr(const LexerToken &Tok) {
   switch (Tok.getKind()) {
   default:
     assert(0 && "Unknown simple primary expr!");
@@ -142,16 +142,16 @@
   }
 }
 
-ASTBuilder::ExprTy *ASTBuilder::ParseIntegerConstant(const LexerToken &Tok) {
+Action::ExprResult ASTBuilder::ParseIntegerConstant(const LexerToken &Tok) {
   return new IntegerConstant();
 }
-ASTBuilder::ExprTy *ASTBuilder::ParseFloatingConstant(const LexerToken &Tok) {
+Action::ExprResult ASTBuilder::ParseFloatingConstant(const LexerToken &Tok) {
   return new FloatingConstant();
 }
 
-ASTBuilder::ExprTy *ASTBuilder::ParseParenExpr(SourceLocation L, 
-                                               SourceLocation R,
-                                               ExprTy *Val) {
+Action::ExprResult ASTBuilder::ParseParenExpr(SourceLocation L, 
+                                              SourceLocation R,
+                                              ExprTy *Val) {
   // FIXME: This is obviously just for testing.
   ((Expr*)Val)->dump();
   if (!FullLocInfo) return Val;
@@ -160,8 +160,8 @@
 }
 
 // Unary Operators.  'Tok' is the token for the operator.
-ASTBuilder::ExprTy *ASTBuilder::ParseUnaryOp(const LexerToken &Tok, 
-                                             ExprTy *Input) {
+Action::ExprResult ASTBuilder::ParseUnaryOp(const LexerToken &Tok,
+                                            ExprTy *Input) {
   UnaryOperator::Opcode Opc;
   switch (Tok.getKind()) {
   default: assert(0 && "Unknown unary op!");
@@ -183,8 +183,8 @@
     return new UnaryOperatorLOC(Tok.getLocation(), (Expr*)Input, Opc);
 }
 
-ASTBuilder::ExprTy *ASTBuilder::ParsePostfixUnaryOp(const LexerToken &Tok,
-                                                    ExprTy *Input) {
+Action::ExprResult ASTBuilder::ParsePostfixUnaryOp(const LexerToken &Tok,
+                                                   ExprTy *Input) {
   UnaryOperator::Opcode Opc;
   switch (Tok.getKind()) {
   default: assert(0 && "Unknown unary op!");
@@ -198,7 +198,7 @@
     return new UnaryOperatorLOC(Tok.getLocation(), (Expr*)Input, Opc);
 }
 
-ASTBuilder::ExprTy *ASTBuilder::
+Action::ExprResult ASTBuilder::
 ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
                         ExprTy *Idx, SourceLocation RLoc) {
   if (!FullLocInfo)
@@ -207,7 +207,7 @@
     return new ArraySubscriptExprLOC((Expr*)Base, LLoc, (Expr*)Idx, RLoc);
 }
 
-ASTBuilder::ExprTy *ASTBuilder::
+Action::ExprResult ASTBuilder::
 ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc,
                          tok::TokenKind OpKind, SourceLocation MemberLoc,
                          IdentifierInfo &Member) {
@@ -221,7 +221,7 @@
 /// ParseCallExpr - Handle a call to Fn with the specified array of arguments.
 /// This provides the location of the left/right parens and a list of comma
 /// locations.
-ASTBuilder::ExprTy *ASTBuilder::
+Action::ExprResult ASTBuilder::
 ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
               ExprTy **Args, unsigned NumArgs,
               SourceLocation *CommaLocs, SourceLocation RParenLoc) {
@@ -234,8 +234,8 @@
 
 
 // Binary Operators.  'Tok' is the token for the operator.
-ASTBuilder::ExprTy *ASTBuilder::ParseBinOp(const LexerToken &Tok, ExprTy *LHS,
-                                           ExprTy *RHS) {
+Action::ExprResult ASTBuilder::ParseBinOp(const LexerToken &Tok, ExprTy *LHS,
+                                          ExprTy *RHS) {
   BinaryOperator::Opcode Opc;
   switch (Tok.getKind()) {
   default: assert(0 && "Unknown binop!");
@@ -279,10 +279,10 @@
 
 /// ParseConditionalOp - Parse a ?: operation.  Note that 'LHS' may be null
 /// in the case of a the GNU conditional expr extension.
-ASTBuilder::ExprTy *ASTBuilder::ParseConditionalOp(SourceLocation QuestionLoc, 
-                                                   SourceLocation ColonLoc,
-                                                   ExprTy *Cond, ExprTy *LHS,
-                                                   ExprTy *RHS) {
+Action::ExprResult ASTBuilder::ParseConditionalOp(SourceLocation QuestionLoc, 
+                                                  SourceLocation ColonLoc,
+                                                  ExprTy *Cond, ExprTy *LHS,
+                                                  ExprTy *RHS) {
   if (!FullLocInfo)
     return new ConditionalOperator((Expr*)Cond, (Expr*)LHS, (Expr*)RHS);
   else

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

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Action.h Wed Jul 11 11:26:06 2007
@@ -88,30 +88,30 @@
   //===--------------------------------------------------------------------===//
   
   // Primary Expressions.
-  virtual ExprTy *ParseSimplePrimaryExpr(const LexerToken &Tok) { return 0; }
-  virtual ExprTy *ParseIntegerConstant(const LexerToken &Tok) { return 0; }
-  virtual ExprTy *ParseFloatingConstant(const LexerToken &Tok) { return 0; }
-
-  virtual ExprTy *ParseParenExpr(SourceLocation L, SourceLocation R,
-                                 ExprTy *Val) {
-    return Val;
+  virtual ExprResult ParseSimplePrimaryExpr(const LexerToken &Tok) { return 0; }
+  virtual ExprResult ParseIntegerConstant(const LexerToken &Tok) { return 0; }
+  virtual ExprResult ParseFloatingConstant(const LexerToken &Tok) { return 0; }
+
+  virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R,
+                                    ExprTy *Val) {
+    return Val;  // Default impl returns operand.
   }
 
   // Binary/Unary Operators.  'Tok' is the token for the operator.
-  virtual ExprTy *ParseUnaryOp(const LexerToken &Tok, ExprTy *Input) {
+  virtual ExprResult ParseUnaryOp(const LexerToken &Tok, ExprTy *Input) {
     return 0;
   }
-  virtual ExprTy *ParsePostfixUnaryOp(const LexerToken &Tok, ExprTy *Input) {
+  virtual ExprResult ParsePostfixUnaryOp(const LexerToken &Tok, ExprTy *Input) {
     return 0;
   }
-  virtual ExprTy *ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
-                                          ExprTy *Idx, SourceLocation RLoc) {
+  virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
+                                             ExprTy *Idx, SourceLocation RLoc) {
     return 0;
   }
-  virtual ExprTy *ParseMemberReferenceExpr(ExprTy *Base, SourceLocation OpLoc,
-                                           tok::TokenKind OpKind,
-                                           SourceLocation MemberLoc,
-                                           IdentifierInfo &Member) {
+  virtual ExprResult ParseMemberReferenceExpr(ExprTy *Base,SourceLocation OpLoc,
+                                              tok::TokenKind OpKind,
+                                              SourceLocation MemberLoc,
+                                              IdentifierInfo &Member) {
     return 0;
   }
   
@@ -119,22 +119,23 @@
   /// This provides the location of the left/right parens and a list of comma
   /// locations.  There are guaranteed to be one fewer commas than arguments,
   /// unless there are zero arguments.
-  virtual ExprTy *ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
-                                ExprTy **Args, unsigned NumArgs,
-                                SourceLocation *CommaLocs,
-                                SourceLocation RParenLoc) {
+  virtual ExprResult ParseCallExpr(ExprTy *Fn, SourceLocation LParenLoc,
+                                   ExprTy **Args, unsigned NumArgs,
+                                   SourceLocation *CommaLocs,
+                                   SourceLocation RParenLoc) {
     return 0;
   }
 
-  virtual ExprTy *ParseBinOp(const LexerToken &Tok, ExprTy *LHS, ExprTy *RHS) {
+  virtual ExprResult ParseBinOp(const LexerToken &Tok,
+                                ExprTy *LHS, ExprTy *RHS) {
     return 0;
   }
 
   /// ParseConditionalOp - Parse a ?: operation.  Note that 'LHS' may be null
   /// in the case of a the GNU conditional expr extension.
-  virtual ExprTy *ParseConditionalOp(SourceLocation QuestionLoc, 
-                                     SourceLocation ColonLoc,
-                                     ExprTy *Cond, ExprTy *LHS, ExprTy *RHS) {
+  virtual ExprResult ParseConditionalOp(SourceLocation QuestionLoc, 
+                                        SourceLocation ColonLoc,
+                                        ExprTy *Cond, ExprTy *LHS, ExprTy *RHS){
     return 0;
   }
 };





More information about the cfe-commits mailing list