[cfe-commits] r38951 - in /cfe/cfe/trunk: AST/Expr.cpp AST/Sema.cpp Parse/ParseExpr.cpp Sema/Sema.cpp include/clang/AST/Expr.h include/clang/Parse/Action.h
sabre at cs.uiuc.edu
sabre at cs.uiuc.edu
Wed Jul 11 09:26:10 PDT 2007
Author: sabre
Date: Wed Jul 11 11:26:09 2007
New Revision: 38951
URL: http://llvm.org/viewvc/llvm-project?rev=38951&view=rev
Log:
Build AST's for sizeof/alignof with type operands.
Modified:
cfe/cfe/trunk/AST/Expr.cpp
cfe/cfe/trunk/AST/Sema.cpp
cfe/cfe/trunk/Parse/ParseExpr.cpp
cfe/cfe/trunk/Sema/Sema.cpp
cfe/cfe/trunk/include/clang/AST/Expr.h
cfe/cfe/trunk/include/clang/Parse/Action.h
Modified: cfe/cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Expr.cpp?rev=38951&r1=38950&r2=38951&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Expr.cpp (original)
+++ cfe/cfe/trunk/AST/Expr.cpp Wed Jul 11 11:26:09 2007
@@ -76,6 +76,12 @@
Input->dump();
}
+void SizeOfAlignOfTypeExpr::dump_impl() const {
+ std::cerr << (isSizeof ? "sizeof(" : "alignof(");
+ // FIXME: print type.
+ std::cerr << "ty)";
+}
+
//===----------------------------------------------------------------------===//
// Postfix Operators.
//===----------------------------------------------------------------------===//
Modified: cfe/cfe/trunk/AST/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.cpp?rev=38951&r1=38950&r2=38951&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/Sema.cpp (original)
+++ cfe/cfe/trunk/AST/Sema.cpp Wed Jul 11 11:26:09 2007
@@ -50,6 +50,11 @@
// Binary/Unary Operators. 'Tok' is the token for the operator.
virtual ExprResult ParseUnaryOp(const LexerToken &Tok, ExprTy *Input);
+ virtual ExprResult
+ ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
+ SourceLocation LParenLoc, TypeTy *Ty,
+ SourceLocation RParenLoc);
+
virtual ExprResult ParsePostfixUnaryOp(const LexerToken &Tok, ExprTy *Input);
virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
@@ -187,6 +192,18 @@
return new UnaryOperatorLOC(Tok.getLocation(), (Expr*)Input, Opc);
}
+Action::ExprResult ASTBuilder::
+ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
+ SourceLocation LParenLoc, TypeTy *Ty,
+ SourceLocation RParenLoc) {
+ if (!FullLocInfo)
+ return new SizeOfAlignOfTypeExpr(isSizeof, (Type*)Ty);
+ else
+ return new SizeOfAlignOfTypeExprLOC(OpLoc, isSizeof, LParenLoc, (Type*)Ty,
+ RParenLoc);
+}
+
+
Action::ExprResult ASTBuilder::ParsePostfixUnaryOp(const LexerToken &Tok,
ExprTy *Input) {
UnaryOperator::Opcode Opc;
Modified: cfe/cfe/trunk/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/ParseExpr.cpp?rev=38951&r1=38950&r2=38951&view=diff
==============================================================================
--- cfe/cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/cfe/trunk/Parse/ParseExpr.cpp Wed Jul 11 11:26:09 2007
@@ -679,15 +679,15 @@
// expression.
ParenParseOption ExprType = CastExpr;
TypeTy *CastTy;
- SourceLocation RParenLoc;
+ SourceLocation LParenLoc = Tok.getLocation(), RParenLoc;
Operand = ParseParenExpression(ExprType, CastTy, RParenLoc);
// If ParseParenExpression parsed a '(typename)' sequence only, the this is
// sizeof/alignof a type. Otherwise, it is sizeof/alignof an expression.
if (ExprType == CastExpr) {
- // TODO: Build AST here for sizeof type.
- CastTy;
- return ExprResult(false);
+ return Actions.ParseSizeOfAlignOfTypeExpr(OpTok.getLocation(),
+ OpTok.getKind() == tok::kw_sizeof,
+ LParenLoc, CastTy, RParenLoc);
}
}
Modified: cfe/cfe/trunk/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.cpp?rev=38951&r1=38950&r2=38951&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/Sema.cpp (original)
+++ cfe/cfe/trunk/Sema/Sema.cpp Wed Jul 11 11:26:09 2007
@@ -50,6 +50,11 @@
// Binary/Unary Operators. 'Tok' is the token for the operator.
virtual ExprResult ParseUnaryOp(const LexerToken &Tok, ExprTy *Input);
+ virtual ExprResult
+ ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
+ SourceLocation LParenLoc, TypeTy *Ty,
+ SourceLocation RParenLoc);
+
virtual ExprResult ParsePostfixUnaryOp(const LexerToken &Tok, ExprTy *Input);
virtual ExprResult ParseArraySubscriptExpr(ExprTy *Base, SourceLocation LLoc,
@@ -187,6 +192,18 @@
return new UnaryOperatorLOC(Tok.getLocation(), (Expr*)Input, Opc);
}
+Action::ExprResult ASTBuilder::
+ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
+ SourceLocation LParenLoc, TypeTy *Ty,
+ SourceLocation RParenLoc) {
+ if (!FullLocInfo)
+ return new SizeOfAlignOfTypeExpr(isSizeof, (Type*)Ty);
+ else
+ return new SizeOfAlignOfTypeExprLOC(OpLoc, isSizeof, LParenLoc, (Type*)Ty,
+ RParenLoc);
+}
+
+
Action::ExprResult ASTBuilder::ParsePostfixUnaryOp(const LexerToken &Tok,
ExprTy *Input) {
UnaryOperator::Opcode Opc;
Modified: cfe/cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/AST/Expr.h?rev=38951&r1=38950&r2=38951&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/cfe/trunk/include/clang/AST/Expr.h Wed Jul 11 11:26:09 2007
@@ -110,7 +110,29 @@
public:
UnaryOperatorLOC(SourceLocation loc, Expr *Input, Opcode Opc)
: UnaryOperator(Input, Opc), Loc(loc) {}
+};
+
+/// SizeOfAlignOfTypeExpr - [C99 6.5.3.4] - This is only for sizeof/alignof of
+/// *types*. sizeof(expr) is handled by UnaryOperator.
+class SizeOfAlignOfTypeExpr : public Expr {
+ bool isSizeof; // true if sizeof, false if alignof.
+ Type *Ty;
+public:
+ SizeOfAlignOfTypeExpr(bool issizeof, Type *ty) : isSizeof(issizeof), Ty(ty) {
+ }
+ virtual void dump_impl() const;
+};
+
+class SizeOfAlignOfTypeExprLOC : public SizeOfAlignOfTypeExpr {
+ SourceLocation OpLoc, LParenLoc, RParenLoc;
+public:
+ SizeOfAlignOfTypeExprLOC(SourceLocation oploc, bool isSizeof,
+ SourceLocation lparenloc, Type *Ty,
+ SourceLocation rparenloc)
+ : SizeOfAlignOfTypeExpr(isSizeof, Ty), OpLoc(oploc), LParenLoc(lparenloc),
+ RParenLoc(rparenloc) {
+ }
};
//===----------------------------------------------------------------------===//
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=38951&r1=38950&r2=38951&view=diff
==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Action.h Wed Jul 11 11:26:09 2007
@@ -130,7 +130,13 @@
virtual ExprResult ParseUnaryOp(const LexerToken &Tok, ExprTy *Input) {
return 0;
}
-
+ virtual ExprResult
+ ParseSizeOfAlignOfTypeExpr(SourceLocation OpLoc, bool isSizeof,
+ SourceLocation LParenLoc, TypeTy *Ty,
+ SourceLocation RParenLoc) {
+ return 0;
+ }
+
virtual ExprResult ParseCastExpr(SourceLocation LParenLoc, TypeTy *Ty,
SourceLocation RParenLoc, ExprTy *Op) {
return 0;
More information about the cfe-commits
mailing list