[cfe-commits] r41273 - in /cfe/trunk: AST/StmtDumper.cpp AST/StmtPrinter.cpp Parse/ParseObjc.cpp Sema/Sema.h Sema/SemaExpr.cpp include/clang/AST/Expr.h include/clang/AST/StmtNodes.def include/clang/Parse/Action.h include/clang/Parse/Parser.h
Anders Carlsson
andersca at mac.com
Wed Aug 22 08:14:15 PDT 2007
Author: andersca
Date: Wed Aug 22 10:14:15 2007
New Revision: 41273
URL: http://llvm.org/viewvc/llvm-project?rev=41273&view=rev
Log:
Parse @encode expressions.
Modified:
cfe/trunk/AST/StmtDumper.cpp
cfe/trunk/AST/StmtPrinter.cpp
cfe/trunk/Parse/ParseObjc.cpp
cfe/trunk/Sema/Sema.h
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/StmtNodes.def
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/include/clang/Parse/Parser.h
Modified: cfe/trunk/AST/StmtDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtDumper.cpp?rev=41273&r1=41272&r2=41273&view=diff
==============================================================================
--- cfe/trunk/AST/StmtDumper.cpp (original)
+++ cfe/trunk/AST/StmtDumper.cpp Wed Aug 22 10:14:15 2007
@@ -503,6 +503,14 @@
fprintf(F, ")");
}
+void StmtDumper::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
+ DumpExpr(Node);
+
+ fprintf(F, " ");
+ DumpType(Node->getEncodedType());
+ fprintf(F, ")");
+}
+
//===----------------------------------------------------------------------===//
// Stmt method implementations
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=41273&r1=41272&r2=41273&view=diff
==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Wed Aug 22 10:14:15 2007
@@ -518,6 +518,11 @@
VisitStringLiteral(Node->getString());
}
+void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) {
+ OS << "@encode(";
+ OS << Node->getEncodedType().getAsString() << ")";
+}
+
//===----------------------------------------------------------------------===//
// Stmt method implementations
//===----------------------------------------------------------------------===//
Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=41273&r1=41272&r2=41273&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Wed Aug 22 10:14:15 2007
@@ -369,6 +369,9 @@
case tok::string_literal: // primary-expression: string-literal
case tok::wide_string_literal:
return ParseObjCStringLiteral();
+ case tok::objc_encode:
+ return ParseObjCEncodeExpression();
+ break;
default:
Diag(AtLoc, diag::err_unexpected_at);
SkipUntil(tok::semi);
@@ -385,3 +388,29 @@
return Actions.ParseObjCStringLiteral(Res.Val);
}
+
+/// objc-encode-expression:
+/// @encode ( type-name )
+Parser::ExprResult Parser::ParseObjCEncodeExpression() {
+ assert(Tok.getIdentifierInfo()->getObjCKeywordID() == tok::objc_encode &&
+ "Not an @encode expression!");
+
+ SourceLocation EncLoc = ConsumeToken();
+
+ if (Tok.getKind() != tok::l_paren) {
+ Diag(Tok, diag::err_expected_lparen_after, "@encode");
+ return true;
+ }
+
+ SourceLocation LParenLoc = ConsumeParen();
+
+ TypeTy *Ty = ParseTypeName();
+
+ if (Tok.getKind() != tok::r_paren) {
+ Diag(Tok, diag::err_expected_rparen);
+ return true;
+ }
+
+ return Actions.ParseObjCEncodeExpression(EncLoc, LParenLoc, Ty,
+ ConsumeParen());
+}
Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=41273&r1=41272&r2=41273&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Wed Aug 22 10:14:15 2007
@@ -326,6 +326,11 @@
// ParseObjCStringLiteral - Parse Objective-C string literals.
virtual ExprResult ParseObjCStringLiteral(ExprTy *string);
+ virtual ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc,
+ SourceLocation LParenLoc,
+ TypeTy *Ty,
+ SourceLocation RParenLoc);
+
private:
// UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts
// functions and arrays to their respective pointers (C99 6.3.2.1).
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=41273&r1=41272&r2=41273&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Wed Aug 22 10:14:15 2007
@@ -1658,8 +1658,7 @@
}
// TODO: Move this to SemaObjC.cpp
-Sema::ExprResult Sema::ParseObjCStringLiteral(ExprTy *string)
-{
+Sema::ExprResult Sema::ParseObjCStringLiteral(ExprTy *string) {
StringLiteral* S = static_cast<StringLiteral *>(string);
if (CheckBuiltinCFStringArgument(S))
@@ -1671,3 +1670,13 @@
return new ObjCStringLiteral(S, t);
}
+
+Sema::ExprResult Sema::ParseObjCEncodeExpression(SourceLocation AtLoc,
+ SourceLocation LParenLoc,
+ TypeTy *Ty,
+ SourceLocation RParenLoc) {
+ QualType EncodedType = QualType::getFromOpaquePtr(Ty);
+
+ QualType t = Context.getPointerType(Context.CharTy);
+ return new ObjCEncodeExpr(t, EncodedType, AtLoc, RParenLoc);
+}
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=41273&r1=41272&r2=41273&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Aug 22 10:14:15 2007
@@ -834,6 +834,25 @@
static bool classof(const ObjCStringLiteral *) { return true; }
};
+/// ObjCEncodeExpr, used for @encode in Objective-C.
+class ObjCEncodeExpr : public Expr {
+ QualType EncType;
+ SourceLocation EncLoc, RParenLoc;
+public:
+ ObjCEncodeExpr(QualType T, QualType ET,
+ SourceLocation enc, SourceLocation rp)
+ : Expr(ObjCEncodeExprClass, T), EncType(ET), EncLoc(enc), RParenLoc(rp) {}
+
+ SourceRange getSourceRange() const { return SourceRange(EncLoc, RParenLoc); }
+
+ QualType getEncodedType() const { return EncType; }
+
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == ObjCEncodeExprClass;
+ }
+ static bool classof(const ObjCEncodeExpr *) { return true; }
+};
+
} // end namespace clang
#endif
Modified: cfe/trunk/include/clang/AST/StmtNodes.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtNodes.def?rev=41273&r1=41272&r2=41273&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/trunk/include/clang/AST/StmtNodes.def Wed Aug 22 10:14:15 2007
@@ -76,6 +76,7 @@
// Obj-C Expressions.
STMT(56, ObjCStringLiteral , Expr)
+STMT(57, ObjCEncodeExpr , Expr)
LAST_EXPR(56)
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=41273&r1=41272&r2=41273&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Wed Aug 22 10:14:15 2007
@@ -409,6 +409,13 @@
virtual ExprResult ParseObjCStringLiteral(ExprTy *string) {
return 0;
}
+
+ virtual ExprResult ParseObjCEncodeExpression(SourceLocation EncLoc,
+ SourceLocation LParenLoc,
+ TypeTy *Ty,
+ SourceLocation RParenLoc) {
+ return 0;
+ }
};
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=41273&r1=41272&r2=41273&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Wed Aug 22 10:14:15 2007
@@ -327,7 +327,8 @@
// Objective-C Expressions
ExprResult ParseObjCExpression();
ExprResult ParseObjCStringLiteral();
-
+ ExprResult ParseObjCEncodeExpression();
+
//===--------------------------------------------------------------------===//
// C99 6.8: Statements and Blocks.
More information about the cfe-commits
mailing list