[cfe-commits] r39044 - in /cfe/cfe/trunk: AST/Sema.cpp Parse/ParseExpr.cpp Sema/Sema.cpp include/clang/Parse/Action.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:27:05 PDT 2007
Author: sabre
Date: Wed Jul 11 11:27:04 2007
New Revision: 39044
URL: http://llvm.org/viewvc/llvm-project?rev=39044&view=rev
Log:
Finish removing LexerToken from actions interface
Modified:
cfe/cfe/trunk/AST/Sema.cpp
cfe/cfe/trunk/Parse/ParseExpr.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=39044&r1=39043&r2=39044&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Sema.cpp (original)
+++ cfe/cfe/trunk/AST/Sema.cpp Wed Jul 11 11:27:04 2007
@@ -17,7 +17,6 @@
#include "clang/AST/Expr.h"
#include "clang/Parse/Scope.h"
#include "clang/Lex/IdentifierTable.h"
-#include "clang/Lex/LexerToken.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/Support/Compiler.h"
using namespace llvm;
@@ -56,14 +55,15 @@
// Expression Parsing Callbacks.
// Primary Expressions.
- virtual ExprResult ParseSimplePrimaryExpr(const LexerToken &Tok);
- virtual ExprResult ParseIntegerConstant(const LexerToken &Tok);
- virtual ExprResult ParseFloatingConstant(const LexerToken &Tok);
+ virtual ExprResult ParseSimplePrimaryExpr(SourceLocation Loc,
+ tok::TokenKind Kind);
+ virtual ExprResult ParseIntegerConstant(SourceLocation Loc);
+ virtual ExprResult ParseFloatingConstant(SourceLocation Loc);
virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R,
ExprTy *Val);
virtual ExprResult ParseStringExpr(const char *StrData, unsigned StrLen,
bool isWide,
- const LexerToken *Toks, unsigned NumToks);
+ SourceLocation *TokLocs, unsigned NumToks);
// Binary/Unary Operators. 'Tok' is the token for the operator.
virtual ExprResult ParseUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
@@ -73,7 +73,8 @@
SourceLocation LParenLoc, TypeTy *Ty,
SourceLocation RParenLoc);
- virtual ExprResult ParsePostfixUnaryOp(const LexerToken &Tok, ExprTy *Input);
+ virtual ExprResult ParsePostfixUnaryOp(SourceLocation OpLoc,
+ tok::TokenKind Kind, ExprTy *Input);
virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
ExprTy *Idx, SourceLocation RLoc);
@@ -93,7 +94,8 @@
virtual ExprResult ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
SourceLocation RParenLoc, ExprTy *Op);
- virtual ExprResult ParseBinOp(const LexerToken &Tok, ExprTy *LHS,ExprTy *RHS);
+ virtual ExprResult ParseBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
+ ExprTy *LHS,ExprTy *RHS);
/// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
/// in the case of a the GNU conditional expr extension.
@@ -166,8 +168,9 @@
// Expression Parsing Callbacks.
//===--------------------------------------------------------------------===//
-Action::ExprResult ASTBuilder::ParseSimplePrimaryExpr(const LexerToken &Tok) {
- switch (Tok.getKind()) {
+Action::ExprResult ASTBuilder::ParseSimplePrimaryExpr(SourceLocation Loc,
+ tok::TokenKind Kind) {
+ switch (Kind) {
default:
assert(0 && "Unknown simple primary expr!");
case tok::identifier: {
@@ -185,10 +188,10 @@
}
}
-Action::ExprResult ASTBuilder::ParseIntegerConstant(const LexerToken &Tok) {
+Action::ExprResult ASTBuilder::ParseIntegerConstant(SourceLocation Loc) {
return new IntegerConstant();
}
-Action::ExprResult ASTBuilder::ParseFloatingConstant(const LexerToken &Tok) {
+Action::ExprResult ASTBuilder::ParseFloatingConstant(SourceLocation Loc) {
return new FloatingConstant();
}
@@ -206,17 +209,13 @@
///
Action::ExprResult ASTBuilder::
ParseStringExpr(const char *StrData, unsigned StrLen, bool isWide,
- const LexerToken *Toks, unsigned NumToks) {
+ SourceLocation *TokLocs, unsigned NumToks) {
assert(NumToks && "Must have at least one string!");
if (!FullLocInfo)
return new StringExpr(StrData, StrLen, isWide);
- else {
- SmallVector<SourceLocation, 4> Locs;
- for (unsigned i = 0; i != NumToks; ++i)
- Locs.push_back(Toks[i].getLocation());
- return new StringExprLOC(StrData, StrLen, isWide, &Locs[0], Locs.size());
- }
+ else
+ return new StringExprLOC(StrData, StrLen, isWide, TokLocs, NumToks);
}
@@ -260,10 +259,11 @@
}
-Action::ExprResult ASTBuilder::ParsePostfixUnaryOp(const LexerToken &Tok,
+Action::ExprResult ASTBuilder::ParsePostfixUnaryOp(SourceLocation OpLoc,
+ tok::TokenKind Kind,
ExprTy *Input) {
UnaryOperator::Opcode Opc;
- switch (Tok.getKind()) {
+ switch (Kind) {
default: assert(0 && "Unknown unary op!");
case tok::plusplus: Opc = UnaryOperator::PostInc; break;
case tok::minusminus: Opc = UnaryOperator::PostDec; break;
@@ -272,7 +272,7 @@
if (!FullLocInfo)
return new UnaryOperator((Expr*)Input, Opc);
else
- return new UnaryOperatorLOC(Tok.getLocation(), (Expr*)Input, Opc);
+ return new UnaryOperatorLOC(OpLoc, (Expr*)Input, Opc);
}
Action::ExprResult ASTBuilder::
@@ -323,10 +323,11 @@
// Binary Operators. 'Tok' is the token for the operator.
-Action::ExprResult ASTBuilder::ParseBinOp(const LexerToken &Tok, ExprTy *LHS,
+Action::ExprResult ASTBuilder::ParseBinOp(SourceLocation TokLoc,
+ tok::TokenKind Kind, ExprTy *LHS,
ExprTy *RHS) {
BinaryOperator::Opcode Opc;
- switch (Tok.getKind()) {
+ switch (Kind) {
default: assert(0 && "Unknown binop!");
case tok::star: Opc = BinaryOperator::Mul; break;
case tok::slash: Opc = BinaryOperator::Div; break;
@@ -363,7 +364,7 @@
if (!FullLocInfo)
return new BinaryOperator((Expr*)LHS, (Expr*)RHS, Opc);
else
- return new BinaryOperatorLOC((Expr*)LHS, Tok.getLocation(), (Expr*)RHS,Opc);
+ return new BinaryOperatorLOC((Expr*)LHS, TokLoc, (Expr*)RHS, Opc);
}
/// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
Modified: cfe/cfe/trunk/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseExpr.cpp?rev=39044&r1=39043&r2=39044&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseExpr.cpp Wed Jul 11 11:27:04 2007
@@ -362,7 +362,8 @@
// Combine the LHS and RHS into the LHS (e.g. build AST).
if (TernaryMiddle.isInvalid)
- LHS = Actions.ParseBinOp(OpToken, LHS.Val, RHS.Val);
+ LHS = Actions.ParseBinOp(OpToken.getLocation(), OpToken.getKind(),
+ LHS.Val, RHS.Val);
else
LHS = Actions.ParseConditionalOp(OpToken.getLocation(), ColonLoc,
LHS.Val, TernaryMiddle.Val, RHS.Val);
@@ -431,7 +432,7 @@
// call ParsePostfixExpressionSuffix to handle the postfix expression
// suffixes. Cases that cannot be followed by postfix exprs should
// return without invoking ParsePostfixExpressionSuffix.
- switch (Tok.getKind()) {
+ switch (SavedKind) {
case tok::l_paren: {
// If this expression is limited to being a unary-expression, the parent can
// not start a cast expression.
@@ -472,9 +473,9 @@
// TODO: Validate whether this is an integer or floating-constant or
// neither.
if (1) {
- Res = Actions.ParseIntegerConstant(Tok);
+ Res = Actions.ParseIntegerConstant(Tok.getLocation());
} else {
- Res = Actions.ParseFloatingConstant(Tok);
+ Res = Actions.ParseFloatingConstant(Tok.getLocation());
}
ConsumeToken();
@@ -487,7 +488,7 @@
case tok::kw___func__: // primary-expression: __func__ [C99 6.4.2.2]
case tok::kw___FUNCTION__: // primary-expression: __FUNCTION__ [GNU]
case tok::kw___PRETTY_FUNCTION__: // primary-expression: __P..Y_F..N__ [GNU]
- Res = Actions.ParseSimplePrimaryExpr(Tok);
+ Res = Actions.ParseSimplePrimaryExpr(Tok.getLocation(), SavedKind);
ConsumeToken();
// These can be followed by postfix-expr pieces.
return ParsePostfixExpressionSuffix(Res);
@@ -650,7 +651,8 @@
case tok::plusplus: // postfix-expression: postfix-expression '++'
case tok::minusminus: // postfix-expression: postfix-expression '--'
if (!LHS.isInvalid)
- LHS = Actions.ParsePostfixUnaryOp(Tok, LHS.Val);
+ LHS = Actions.ParsePostfixUnaryOp(Tok.getLocation(), Tok.getKind(),
+ LHS.Val);
ConsumeToken();
break;
}
@@ -1099,10 +1101,14 @@
*ResultPtr++ = 0;
}
+ SmallVector<SourceLocation, 4> StringTokLocs;
+ for (unsigned i = 0; i != StringToks.size(); ++i)
+ StringTokLocs.push_back(StringToks[i].getLocation());
+
// Hand this off to the Actions.
ExprResult Res = Actions.ParseStringExpr(ResultBuf, ResultPtr-ResultBuf,
- AnyWide,
- &StringToks[0], StringToks.size());
+ AnyWide, &StringTokLocs[0],
+ StringTokLocs.size());
// If either buffer was heap allocated, release it now.
if (MaxTokenLength > 512) free(TokenBuf);
Modified: cfe/cfe/trunk/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.cpp?rev=39044&r1=39043&r2=39044&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/cfe/trunk/Sema/Sema.cpp Wed Jul 11 11:27:04 2007
@@ -17,7 +17,6 @@
#include "clang/AST/Expr.h"
#include "clang/Parse/Scope.h"
#include "clang/Lex/IdentifierTable.h"
-#include "clang/Lex/LexerToken.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/Support/Compiler.h"
using namespace llvm;
@@ -56,14 +55,15 @@
// Expression Parsing Callbacks.
// Primary Expressions.
- virtual ExprResult ParseSimplePrimaryExpr(const LexerToken &Tok);
- virtual ExprResult ParseIntegerConstant(const LexerToken &Tok);
- virtual ExprResult ParseFloatingConstant(const LexerToken &Tok);
+ virtual ExprResult ParseSimplePrimaryExpr(SourceLocation Loc,
+ tok::TokenKind Kind);
+ virtual ExprResult ParseIntegerConstant(SourceLocation Loc);
+ virtual ExprResult ParseFloatingConstant(SourceLocation Loc);
virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R,
ExprTy *Val);
virtual ExprResult ParseStringExpr(const char *StrData, unsigned StrLen,
bool isWide,
- const LexerToken *Toks, unsigned NumToks);
+ SourceLocation *TokLocs, unsigned NumToks);
// Binary/Unary Operators. 'Tok' is the token for the operator.
virtual ExprResult ParseUnaryOp(SourceLocation OpLoc, tok::TokenKind Op,
@@ -73,7 +73,8 @@
SourceLocation LParenLoc, TypeTy *Ty,
SourceLocation RParenLoc);
- virtual ExprResult ParsePostfixUnaryOp(const LexerToken &Tok, ExprTy *Input);
+ virtual ExprResult ParsePostfixUnaryOp(SourceLocation OpLoc,
+ tok::TokenKind Kind, ExprTy *Input);
virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
ExprTy *Idx, SourceLocation RLoc);
@@ -93,7 +94,8 @@
virtual ExprResult ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
SourceLocation RParenLoc, ExprTy *Op);
- virtual ExprResult ParseBinOp(const LexerToken &Tok, ExprTy *LHS,ExprTy *RHS);
+ virtual ExprResult ParseBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
+ ExprTy *LHS,ExprTy *RHS);
/// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
/// in the case of a the GNU conditional expr extension.
@@ -166,8 +168,9 @@
// Expression Parsing Callbacks.
//===--------------------------------------------------------------------===//
-Action::ExprResult ASTBuilder::ParseSimplePrimaryExpr(const LexerToken &Tok) {
- switch (Tok.getKind()) {
+Action::ExprResult ASTBuilder::ParseSimplePrimaryExpr(SourceLocation Loc,
+ tok::TokenKind Kind) {
+ switch (Kind) {
default:
assert(0 && "Unknown simple primary expr!");
case tok::identifier: {
@@ -185,10 +188,10 @@
}
}
-Action::ExprResult ASTBuilder::ParseIntegerConstant(const LexerToken &Tok) {
+Action::ExprResult ASTBuilder::ParseIntegerConstant(SourceLocation Loc) {
return new IntegerConstant();
}
-Action::ExprResult ASTBuilder::ParseFloatingConstant(const LexerToken &Tok) {
+Action::ExprResult ASTBuilder::ParseFloatingConstant(SourceLocation Loc) {
return new FloatingConstant();
}
@@ -206,17 +209,13 @@
///
Action::ExprResult ASTBuilder::
ParseStringExpr(const char *StrData, unsigned StrLen, bool isWide,
- const LexerToken *Toks, unsigned NumToks) {
+ SourceLocation *TokLocs, unsigned NumToks) {
assert(NumToks && "Must have at least one string!");
if (!FullLocInfo)
return new StringExpr(StrData, StrLen, isWide);
- else {
- SmallVector<SourceLocation, 4> Locs;
- for (unsigned i = 0; i != NumToks; ++i)
- Locs.push_back(Toks[i].getLocation());
- return new StringExprLOC(StrData, StrLen, isWide, &Locs[0], Locs.size());
- }
+ else
+ return new StringExprLOC(StrData, StrLen, isWide, TokLocs, NumToks);
}
@@ -260,10 +259,11 @@
}
-Action::ExprResult ASTBuilder::ParsePostfixUnaryOp(const LexerToken &Tok,
+Action::ExprResult ASTBuilder::ParsePostfixUnaryOp(SourceLocation OpLoc,
+ tok::TokenKind Kind,
ExprTy *Input) {
UnaryOperator::Opcode Opc;
- switch (Tok.getKind()) {
+ switch (Kind) {
default: assert(0 && "Unknown unary op!");
case tok::plusplus: Opc = UnaryOperator::PostInc; break;
case tok::minusminus: Opc = UnaryOperator::PostDec; break;
@@ -272,7 +272,7 @@
if (!FullLocInfo)
return new UnaryOperator((Expr*)Input, Opc);
else
- return new UnaryOperatorLOC(Tok.getLocation(), (Expr*)Input, Opc);
+ return new UnaryOperatorLOC(OpLoc, (Expr*)Input, Opc);
}
Action::ExprResult ASTBuilder::
@@ -323,10 +323,11 @@
// Binary Operators. 'Tok' is the token for the operator.
-Action::ExprResult ASTBuilder::ParseBinOp(const LexerToken &Tok, ExprTy *LHS,
+Action::ExprResult ASTBuilder::ParseBinOp(SourceLocation TokLoc,
+ tok::TokenKind Kind, ExprTy *LHS,
ExprTy *RHS) {
BinaryOperator::Opcode Opc;
- switch (Tok.getKind()) {
+ switch (Kind) {
default: assert(0 && "Unknown binop!");
case tok::star: Opc = BinaryOperator::Mul; break;
case tok::slash: Opc = BinaryOperator::Div; break;
@@ -363,7 +364,7 @@
if (!FullLocInfo)
return new BinaryOperator((Expr*)LHS, (Expr*)RHS, Opc);
else
- return new BinaryOperatorLOC((Expr*)LHS, Tok.getLocation(), (Expr*)RHS,Opc);
+ return new BinaryOperatorLOC((Expr*)LHS, TokLoc, (Expr*)RHS, Opc);
}
/// ParseConditionalOp - Parse a ?: operation. Note that 'LHS' may be null
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=39044&r1=39043&r2=39044&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Action.h Wed Jul 11 11:27:04 2007
@@ -26,7 +26,6 @@
class Action;
// Lex.
class IdentifierInfo;
- class LexerToken;
/// Action - As the parser reads the input file and recognizes the productions
/// of the grammar, it invokes methods on this class to turn the parsed input
@@ -187,9 +186,12 @@
//===--------------------------------------------------------------------===//
// Primary Expressions.
- 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 ParseSimplePrimaryExpr(SourceLocation Loc,
+ tok::TokenKind Kind) {
+ return 0;
+ }
+ virtual ExprResult ParseIntegerConstant(SourceLocation Loc) { return 0; }
+ virtual ExprResult ParseFloatingConstant(SourceLocation Loc) { return 0; }
virtual ExprResult ParseParenExpr(SourceLocation L, SourceLocation R,
ExprTy *Val) {
return Val; // Default impl returns operand.
@@ -200,12 +202,13 @@
/// array exposes the input tokens to provide location information.
virtual ExprResult ParseStringExpr(const char *StrData, unsigned StrLen,
bool isWide,
- const LexerToken *Toks, unsigned NumToks) {
+ SourceLocation *TokLocs, unsigned NumToks){
return 0;
}
// Postfix Expressions.
- virtual ExprResult ParsePostfixUnaryOp(const LexerToken &Tok, ExprTy *Input) {
+ virtual ExprResult ParsePostfixUnaryOp(SourceLocation OpLoc,
+ tok::TokenKind Kind, ExprTy *Input) {
return 0;
}
virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
@@ -247,7 +250,7 @@
return 0;
}
- virtual ExprResult ParseBinOp(const LexerToken &Tok,
+ virtual ExprResult ParseBinOp(SourceLocation TokLoc, tok::TokenKind Kind,
ExprTy *LHS, ExprTy *RHS) {
return 0;
}
More information about the cfe-commits
mailing list