QualType StrType = Context->getPointerType(Context->CharTy);
std::string StrEncoding;
Context->getObjCEncodingForType(Exp->getEncodedType(), StrEncoding);
- Expr *Replacement = new (Context) StringLiteral(*Context,StrEncoding.c_str(),
- StrEncoding.length(), false, StrType,
- SourceLocation());
+ Expr *Replacement = StringLiteral::Create(*Context,StrEncoding.c_str(),
+ StrEncoding.length(), false,StrType,
+ SourceLocation());
ReplaceStmt(Exp, Replacement);
// Replace this subexpr in the parent.
// Create a call to sel_registerName("selName").
llvm::SmallVector<Expr*, 8> SelExprs;
QualType argType = Context->getPointerType(Context->CharTy);
- SelExprs.push_back(new (Context) StringLiteral((*Context),
+ SelExprs.push_back(StringLiteral::Create(*Context,
Exp->getSelector().getAsString().c_str(),
Exp->getSelector().getAsString().size(),
false, argType, SourceLocation()));
SourceLocation()));
llvm::SmallVector<Expr*, 8> ClsExprs;
QualType argType = Context->getPointerType(Context->CharTy);
- ClsExprs.push_back(new (Context) StringLiteral(*Context,
+ ClsExprs.push_back(StringLiteral::Create(*Context,
SuperDecl->getIdentifier()->getName(),
SuperDecl->getIdentifier()->getLength(),
false, argType, SourceLocation()));
} else {
llvm::SmallVector<Expr*, 8> ClsExprs;
QualType argType = Context->getPointerType(Context->CharTy);
- ClsExprs.push_back(new (Context) StringLiteral(*Context,
- clsName->getName(),
- clsName->getLength(),
- false, argType, SourceLocation()));
+ ClsExprs.push_back(StringLiteral::Create(*Context,
+ clsName->getName(),
+ clsName->getLength(),
+ false, argType,
+ SourceLocation()));
CallExpr *Cls = SynthesizeCallToFunctionDecl(GetClassFunctionDecl,
&ClsExprs[0],
ClsExprs.size());
llvm::SmallVector<Expr*, 8> ClsExprs;
QualType argType = Context->getPointerType(Context->CharTy);
- ClsExprs.push_back(new (Context) StringLiteral(*Context,
+ ClsExprs.push_back(StringLiteral::Create(*Context,
SuperDecl->getIdentifier()->getName(),
SuperDecl->getIdentifier()->getLength(),
false, argType, SourceLocation()));
// Create a call to sel_registerName("selName"), it will be the 2nd argument.
llvm::SmallVector<Expr*, 8> SelExprs;
QualType argType = Context->getPointerType(Context->CharTy);
- SelExprs.push_back(new (Context) StringLiteral(*Context,
+ SelExprs.push_back(StringLiteral::Create(*Context,
Exp->getSelector().getAsString().c_str(),
Exp->getSelector().getAsString().size(),
false, argType, SourceLocation()));
// Create a call to objc_getProtocol("ProtocolName").
llvm::SmallVector<Expr*, 8> ProtoExprs;
QualType argType = Context->getPointerType(Context->CharTy);
- ProtoExprs.push_back(new (Context)
- StringLiteral(*Context,
+ ProtoExprs.push_back(StringLiteral::Create(*Context,
Exp->getProtocol()->getNameAsCString(),
strlen(Exp->getProtocol()->getNameAsCString()),
false, argType, SourceLocation()));
bool IsWide;
unsigned NumConcatenated;
SourceLocation TokLocs[1];
+
+ StringLiteral(QualType Ty) : Expr(StringLiteralClass, Ty) {}
public:
- StringLiteral(ASTContext &C, const char *StrData, unsigned ByteLength,
- bool Wide, QualType t, SourceLocation Loc);
- StringLiteral(ASTContext &C, const char *StrData, unsigned ByteLength,
- bool Wide, QualType t, SourceLocation *Loc, unsigned NumStrs);
+ /// This is the "fully general" constructor that allows representation of
+ /// strings formed from multiple concatenated tokens.
+ static StringLiteral *Create(ASTContext &C, const char *StrData,
+ unsigned ByteLength, bool Wide, QualType Ty,
+ SourceLocation *Loc, unsigned NumStrs);
+
+ /// Simple constructor for string literals made from one token.
+ static StringLiteral *Create(ASTContext &C, const char *StrData,
+ unsigned ByteLength,
+ bool Wide, QualType Ty, SourceLocation Loc) {
+ return Create(C, StrData, ByteLength, Wide, Ty, &Loc, 1);
+ }
void Destroy(ASTContext &C);
SourceLocation getOperatorLoc() const { return Loc; }
/// isPostfix - Return true if this is a postfix operation, like x++.
- static bool isPostfix(Opcode Op);
+ static bool isPostfix(Opcode Op) {
+ return Op == PostInc || Op == PostDec;
+ }
/// isPostfix - Return true if this is a prefix operation, like --x.
- static bool isPrefix(Opcode Op);
+ static bool isPrefix(Opcode Op) {
+ return Op == PreInc || Op == PreDec;
+ }
bool isPrefix() const { return isPrefix(Opc); }
bool isPostfix() const { return isPostfix(Opc); }
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;
}
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) {
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)
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
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.