summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/AST/Expr.cpp68
-rw-r--r--clang/lib/AST/StmtSerialization.cpp4
-rw-r--r--clang/lib/Sema/SemaExpr.cpp14
-rw-r--r--clang/lib/Sema/SemaExprObjC.cpp6
4 files changed, 31 insertions, 61 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 81da44407b1..e436a41b550 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -37,35 +37,29 @@ double FloatingLiteral::getValueAsApproximateDouble() const {
return V.convertToDouble();
}
-
-StringLiteral::StringLiteral(ASTContext& C, const char *strData,
- unsigned byteLength, bool Wide, QualType Ty,
- SourceLocation Loc) :
- Expr(StringLiteralClass, Ty) {
- // OPTIMIZE: could allocate this appended to the StringLiteral.
- char *AStrData = new (C, 1) char[byteLength];
- memcpy(AStrData, strData, byteLength);
- StrData = AStrData;
- ByteLength = byteLength;
- IsWide = Wide;
- TokLocs[0] = Loc;
- NumConcatenated = 1;
-}
-
-StringLiteral::StringLiteral(ASTContext &C, const char *strData,
- unsigned byteLength, bool Wide, QualType Ty,
- SourceLocation *Loc, unsigned NumStrs) :
- Expr(StringLiteralClass, Ty) {
+StringLiteral *StringLiteral::Create(ASTContext &C, const char *StrData,
+ unsigned ByteLength, bool Wide,
+ QualType Ty,
+ SourceLocation *Loc, unsigned NumStrs) {
+ // Allocate enough space for the StringLiteral plus an array of locations for
+ // any concatenated string tokens.
+ void *Mem = C.Allocate(sizeof(StringLiteral)+
+ sizeof(SourceLocation)*(NumStrs-1),
+ llvm::alignof<StringLiteral>());
+ StringLiteral *SL = new (Mem) StringLiteral(Ty);
+
// OPTIMIZE: could allocate this appended to the StringLiteral.
- char *AStrData = new (C, 1) char[byteLength];
- memcpy(AStrData, strData, byteLength);
- StrData = AStrData;
- ByteLength = byteLength;
- IsWide = Wide;
- TokLocs[0] = Loc[0];
- NumConcatenated = NumStrs;
+ char *AStrData = new (C, 1) char[ByteLength];
+ memcpy(AStrData, StrData, ByteLength);
+ SL->StrData = AStrData;
+ SL->ByteLength = ByteLength;
+ SL->IsWide = Wide;
+ SL->TokLocs[0] = Loc[0];
+ SL->NumConcatenated = NumStrs;
+
if (NumStrs != 1)
- memcpy(&TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1));
+ memcpy(&SL->TokLocs[1], Loc+1, sizeof(SourceLocation)*(NumStrs-1));
+ return SL;
}
@@ -75,26 +69,6 @@ void StringLiteral::Destroy(ASTContext &C) {
C.Deallocate(this);
}
-bool UnaryOperator::isPostfix(Opcode Op) {
- switch (Op) {
- case PostInc:
- case PostDec:
- return true;
- default:
- return false;
- }
-}
-
-bool UnaryOperator::isPrefix(Opcode Op) {
- switch (Op) {
- case PreInc:
- case PreDec:
- return true;
- default:
- return false;
- }
-}
-
/// getOpcodeStr - Turn an Opcode enum value into the punctuation char it
/// corresponds to, e.g. "sizeof" or "[pre]++".
const char *UnaryOperator::getOpcodeStr(Opcode Op) {
diff --git a/clang/lib/AST/StmtSerialization.cpp b/clang/lib/AST/StmtSerialization.cpp
index 074969e9de2..e1d85aa01c5 100644
--- a/clang/lib/AST/StmtSerialization.cpp
+++ b/clang/lib/AST/StmtSerialization.cpp
@@ -971,8 +971,8 @@ StringLiteral* StringLiteral::CreateImpl(Deserializer& D, ASTContext& C) {
bool isWide = D.ReadBool();
unsigned ByteLength = D.ReadInt();
- StringLiteral* sl = new (C, llvm::alignof<StringLiteral>())
- StringLiteral(C, NULL, 0, isWide, t, SourceLocation());
+ StringLiteral* sl = StringLiteral::Create(C, NULL, 0, isWide, t,
+ SourceLocation());
char* StrData = new (C, llvm::alignof<char>()) char[ByteLength];
for (unsigned i = 0; i < ByteLength; ++i)
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 48f338e475d..b2df86abe63 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -352,17 +352,13 @@ Sema::ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks) {
StrTy = Context.getConstantArrayType(StrTy,
llvm::APInt(32, Literal.GetStringLength()+1),
ArrayType::Normal, 0);
- // Allocate enough space for the StringLiteral plus an array of locations for
- // any concatenated strings.
- void *Mem = Context.Allocate(sizeof(StringLiteral)+
- sizeof(SourceLocation)*(NumStringToks-1));
// Pass &StringTokLocs[0], StringTokLocs.size() to factory!
- return Owned(new (Mem) StringLiteral(Context, Literal.GetString(),
- Literal.GetStringLength(),
- Literal.AnyWide, StrTy,
- &StringTokLocs[0],
- StringTokLocs.size()));
+ return Owned(StringLiteral::Create(Context, Literal.GetString(),
+ Literal.GetStringLength(),
+ Literal.AnyWide, StrTy,
+ &StringTokLocs[0],
+ StringTokLocs.size()));
}
/// ShouldSnapshotBlockValueReference - Return true if a reference inside of
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 6e40b3c4a3e..886a3ca1dce 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -51,9 +51,9 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs,
S->Destroy(Context);
}
// FIXME: PASS LOCATIONS PROPERLY.
- S = new (Context) StringLiteral(Context, strBuf, Length, false,
- Context.getPointerType(Context.CharTy),
- AtLocs[0]);
+ S = StringLiteral::Create(Context, strBuf, Length, false,
+ Context.getPointerType(Context.CharTy),
+ AtLocs[0]);
}
// Verify that this composite string is acceptable for ObjC strings.
OpenPOWER on IntegriCloud