[cfe-commits] r41238 - in /cfe/trunk: AST/StmtDumper.cpp AST/StmtPrinter.cpp CodeGen/CGExpr.cpp CodeGen/CGObjC.cpp CodeGen/CodeGenFunction.h Parse/ParseExpr.cpp Parse/ParseObjc.cpp Sema/Sema.h Sema/SemaExpr.cpp clang.xcodeproj/project.pbxproj 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
Tue Aug 21 10:43:55 PDT 2007
Author: andersca
Date: Tue Aug 21 12:43:55 2007
New Revision: 41238
URL: http://llvm.org/viewvc/llvm-project?rev=41238&view=rev
Log:
Implement parsing and code generation of Objective-C string literals.
Added:
cfe/trunk/CodeGen/CGObjC.cpp
Modified:
cfe/trunk/AST/StmtDumper.cpp
cfe/trunk/AST/StmtPrinter.cpp
cfe/trunk/CodeGen/CGExpr.cpp
cfe/trunk/CodeGen/CodeGenFunction.h
cfe/trunk/Parse/ParseExpr.cpp
cfe/trunk/Parse/ParseObjc.cpp
cfe/trunk/Sema/Sema.h
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/clang.xcodeproj/project.pbxproj
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=41238&r1=41237&r2=41238&view=diff
==============================================================================
--- cfe/trunk/AST/StmtDumper.cpp (original)
+++ cfe/trunk/AST/StmtDumper.cpp Tue Aug 21 12:43:55 2007
@@ -492,6 +492,16 @@
fprintf(F, " %s)", Node->getValue() ? "true" : "false");
}
+//===----------------------------------------------------------------------===//
+// Obj-C Expressions
+//===----------------------------------------------------------------------===//
+
+void StmtDumper::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
+ DumpExpr(Node);
+ fprintf(F, "\n");
+ DumpSubTree(Node->getString());
+ fprintf(F, ")");
+}
//===----------------------------------------------------------------------===//
// Stmt method implementations
Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=41238&r1=41237&r2=41238&view=diff
==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Tue Aug 21 12:43:55 2007
@@ -511,6 +511,12 @@
OS << (Node->getValue() ? "true" : "false");
}
+// Obj-C
+
+void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) {
+ OS << "@";
+ VisitStringLiteral(Node->getString());
+}
//===----------------------------------------------------------------------===//
// Stmt method implementations
Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=41238&r1=41237&r2=41238&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Tue Aug 21 12:43:55 2007
@@ -566,6 +566,8 @@
return EmitConditionalOperator(cast<ConditionalOperator>(E));
case Expr::ChooseExprClass:
return EmitChooseExpr(cast<ChooseExpr>(E));
+ case Expr::ObjCStringLiteralClass:
+ return EmitObjCStringLiteral(cast<ObjCStringLiteral>(E));
}
}
Added: cfe/trunk/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGObjC.cpp?rev=41238&view=auto
==============================================================================
--- cfe/trunk/CodeGen/CGObjC.cpp (added)
+++ cfe/trunk/CodeGen/CGObjC.cpp Tue Aug 21 12:43:55 2007
@@ -0,0 +1,28 @@
+//===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Anders Carlsson and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This contains code to emit Objective-C code as LLVM code.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CodeGenFunction.h"
+#include "CodeGenModule.h"
+#include "clang/AST/Expr.h"
+#include "llvm/Constant.h"
+
+using namespace clang;
+using namespace CodeGen;
+
+RValue CodeGenFunction::EmitObjCStringLiteral(const ObjCStringLiteral* E)
+{
+ std::string S(E->getString()->getStrData(), E->getString()->getByteLength());
+
+ return RValue::get(CGM.GetAddrOfConstantCFString(S));
+}
+
Modified: cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenFunction.h?rev=41238&r1=41237&r2=41238&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.h Tue Aug 21 12:43:55 2007
@@ -61,6 +61,7 @@
class ConditionalOperator;
class ChooseExpr;
class PreDefinedExpr;
+ class ObjCStringLiteral;
class BlockVarDecl;
class EnumConstantDecl;
@@ -393,6 +394,8 @@
RValue EmitConditionalOperator(const ConditionalOperator *E);
RValue EmitChooseExpr(const ChooseExpr *E);
+ RValue EmitObjCStringLiteral(const ObjCStringLiteral* E);
+
//===--------------------------------------------------------------------===//
// Aggregate Expression Emission
//===--------------------------------------------------------------------===//
Modified: cfe/trunk/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseExpr.cpp?rev=41238&r1=41237&r2=41238&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/Parse/ParseExpr.cpp Tue Aug 21 12:43:55 2007
@@ -569,6 +569,8 @@
case tok::kw_reinterpret_cast:
case tok::kw_static_cast:
return ParseCXXCasts();
+ case tok::at:
+ return ParseObjCExpression();
default:
Diag(Tok, diag::err_expected_expression);
return ExprResult(true);
Modified: cfe/trunk/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseObjc.cpp?rev=41238&r1=41237&r2=41238&view=diff
==============================================================================
--- cfe/trunk/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/Parse/ParseObjc.cpp Tue Aug 21 12:43:55 2007
@@ -310,3 +310,27 @@
void Parser::ParseObjCClassMethodDeclaration() {
assert(0 && "Unimp");
}
+
+Parser::ExprResult Parser::ParseObjCExpression() {
+ SourceLocation AtLoc = ConsumeToken(); // the "@"
+
+ switch (Tok.getKind()) {
+ case tok::string_literal: // primary-expression: string-literal
+ case tok::wide_string_literal:
+ return ParseObjCStringLiteral();
+ default:
+ Diag(AtLoc, diag::err_unexpected_at);
+ SkipUntil(tok::semi);
+ break;
+ }
+
+ return 0;
+}
+
+Parser::ExprResult Parser::ParseObjCStringLiteral() {
+ ExprResult Res = ParseStringLiteralExpression();
+
+ if (Res.isInvalid) return Res;
+
+ return Actions.ParseObjCStringLiteral(Res.Val);
+}
Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=41238&r1=41237&r2=41238&view=diff
==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Tue Aug 21 12:43:55 2007
@@ -323,6 +323,9 @@
/// ParseCXXBoolLiteral - Parse {true,false} literals.
virtual ExprResult ParseCXXBoolLiteral(SourceLocation OpLoc,
tok::TokenKind Kind);
+
+ // ParseObjCStringLiteral - Parse Objective-C string literals.
+ virtual ExprResult ParseObjCStringLiteral(ExprTy *string);
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=41238&r1=41237&r2=41238&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Tue Aug 21 12:43:55 2007
@@ -1657,3 +1657,17 @@
return new ChooseExpr(BuiltinLoc, CondExpr, LHSExpr, RHSExpr, resType, RPLoc);
}
+// TODO: Move this to SemaObjC.cpp
+Sema::ExprResult Sema::ParseObjCStringLiteral(ExprTy *string)
+{
+ StringLiteral* S = static_cast<StringLiteral *>(string);
+
+ if (CheckBuiltinCFStringArgument(S))
+ return true;
+
+ QualType t = Context.getCFConstantStringType();
+ t = t.getQualifiedType(QualType::Const);
+ t = Context.getPointerType(t);
+
+ return new ObjCStringLiteral(S, t);
+}
Modified: cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=41238&r1=41237&r2=41238&view=diff
==============================================================================
--- cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/trunk/clang.xcodeproj/project.pbxproj Tue Aug 21 12:43:55 2007
@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
1A30A9E90B93A4C800201A91 /* ExprCXX.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1A30A9E80B93A4C800201A91 /* ExprCXX.h */; };
+ 1A7342480C7B57D500122F56 /* CGObjC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A7342470C7B57D500122F56 /* CGObjC.cpp */; };
1A869A700BA2164C008DA07A /* LiteralSupport.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 1A869A6E0BA2164C008DA07A /* LiteralSupport.h */; };
1A869AA80BA21ABA008DA07A /* LiteralSupport.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A869AA70BA21ABA008DA07A /* LiteralSupport.cpp */; };
1ABC36940C7A4BDC006DB0AB /* CGBuiltin.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1ABC36930C7A4BDC006DB0AB /* CGBuiltin.cpp */; };
@@ -196,6 +197,7 @@
/* Begin PBXFileReference section */
1A30A9E80B93A4C800201A91 /* ExprCXX.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ExprCXX.h; path = clang/AST/ExprCXX.h; sourceTree = "<group>"; };
+ 1A7342470C7B57D500122F56 /* CGObjC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CGObjC.cpp; path = CodeGen/CGObjC.cpp; sourceTree = "<group>"; };
1A869A6E0BA2164C008DA07A /* LiteralSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LiteralSupport.h; sourceTree = "<group>"; };
1A869AA70BA21ABA008DA07A /* LiteralSupport.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = LiteralSupport.cpp; sourceTree = "<group>"; };
1ABC36930C7A4BDC006DB0AB /* CGBuiltin.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CGBuiltin.cpp; path = CodeGen/CGBuiltin.cpp; sourceTree = "<group>"; };
@@ -437,6 +439,7 @@
DEF2EFF20C6CDD74000C4259 /* CGAggExpr.cpp */,
DE224FF70C7AA98800D370A5 /* CGComplexExpr.cpp */,
DE4772FB0C10EAEC002239E8 /* CGExpr.cpp */,
+ 1A7342470C7B57D500122F56 /* CGObjC.cpp */,
DE4772F90C10EAE5002239E8 /* CGStmt.cpp */,
DE928B120C05659200231DA4 /* ModuleBuilder.cpp */,
);
@@ -616,6 +619,7 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
+ compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
@@ -692,6 +696,7 @@
DEF2F0100C6CFED5000C4259 /* SemaChecking.cpp in Sources */,
1ABC36940C7A4BDC006DB0AB /* CGBuiltin.cpp in Sources */,
DE224FF80C7AA98800D370A5 /* CGComplexExpr.cpp in Sources */,
+ 1A7342480C7B57D500122F56 /* CGObjC.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=41238&r1=41237&r2=41238&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Aug 21 12:43:55 2007
@@ -811,6 +811,28 @@
static bool classof(const ChooseExpr *) { return true; }
};
+/// ObjCStringLiteral, used for Objective-C string literals
+/// i.e. @"foo".
+class ObjCStringLiteral : public Expr {
+ StringLiteral *String;
+public:
+ ObjCStringLiteral(StringLiteral *SL, QualType T)
+ : Expr(ObjCStringLiteralClass, T), String(SL) {}
+
+ StringLiteral* getString() { return String; }
+
+ const StringLiteral* getString() const { return String; }
+
+ virtual SourceRange getSourceRange() const {
+ return String->getSourceRange();
+ }
+
+ static bool classof(const Stmt *T) {
+ return T->getStmtClass() == ObjCStringLiteralClass;
+ }
+ static bool classof(const ObjCStringLiteral *) { 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=41238&r1=41237&r2=41238&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/StmtNodes.def (original)
+++ cfe/trunk/include/clang/AST/StmtNodes.def Tue Aug 21 12:43:55 2007
@@ -73,7 +73,11 @@
// C++ Expressions.
STMT(54, CXXCastExpr , Expr)
STMT(55, CXXBoolLiteralExpr , Expr)
-LAST_EXPR(55)
+
+// Obj-C Expressions.
+STMT(56, ObjCStringLiteral , Expr)
+
+LAST_EXPR(56)
#undef STMT
#undef FIRST_STMT
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=41238&r1=41237&r2=41238&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Tue Aug 21 12:43:55 2007
@@ -404,6 +404,12 @@
tok::TokenKind Kind) {
return 0;
}
+
+ //===----------------------- Obj-C Expressions --------------------------===//
+ virtual ExprResult ParseObjCStringLiteral(ExprTy *string) {
+ return 0;
+ }
+
};
/// MinimalAction - Minimal actions are used by light-weight clients of the
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=41238&r1=41237&r2=41238&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Tue Aug 21 12:43:55 2007
@@ -324,6 +324,11 @@
ExprResult ParseInitializerWithPotentialDesignator();
//===--------------------------------------------------------------------===//
+ // Objective-C Expressions
+ ExprResult ParseObjCExpression();
+ ExprResult ParseObjCStringLiteral();
+
+ //===--------------------------------------------------------------------===//
// C99 6.8: Statements and Blocks.
StmtResult ParseStatement() { return ParseStatementOrDeclaration(true); }
More information about the cfe-commits
mailing list