diff options
author | Chris Lattner <sabre@nondot.org> | 2009-02-18 06:40:38 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-02-18 06:40:38 +0000 |
commit | f83b5afb7b482c779dc04b1fe3a92ceb6cfa54e9 (patch) | |
tree | 200bd873a2ffd50e225f201cd7e7a234c30a8082 /clang/lib/AST/Expr.cpp | |
parent | b2809a0a1b07fa1ca9dbdab0bba5171adc7db476 (diff) | |
download | bcm5719-llvm-f83b5afb7b482c779dc04b1fe3a92ceb6cfa54e9.tar.gz bcm5719-llvm-f83b5afb7b482c779dc04b1fe3a92ceb6cfa54e9.zip |
privatize all of the string literal memory allocation/creation
stuff behind a private static function.
llvm-svn: 64898
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
-rw-r--r-- | clang/lib/AST/Expr.cpp | 68 |
1 files changed, 21 insertions, 47 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) { |