- Rename member function size(). New name is length().
- Store string beginning and length. Earlier it used to store string end.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76841 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel 2009-07-23 02:00:51 +00:00
parent 3091719b90
commit 2f9c3b002d
10 changed files with 30 additions and 28 deletions

View File

@ -232,7 +232,7 @@ public:
MDNode* getMDNode(Value* const* Vals, unsigned NumVals);
// MDString accessors
MDString* getMDString(const char *StrBegin, const char *StrEnd);
MDString* getMDString(const char *StrBegin, unsigned Length);
MDString* getMDString(const std::string &Str);
// FunctionType accessors

View File

@ -64,16 +64,17 @@ public:
///
class MDString : public MetadataBase {
MDString(const MDString &); // DO NOT IMPLEMENT
const char *StrBegin, *StrEnd;
const char *StrBegin;
unsigned StrLength;
friend class LLVMContextImpl;
protected:
explicit MDString(const char *begin, const char *end)
explicit MDString(const char *begin, unsigned l)
: MetadataBase(Type::MetadataTy, Value::MDStringVal),
StrBegin(begin), StrEnd(end) {}
StrBegin(begin), StrLength(l) {}
public:
intptr_t size() const { return StrEnd - StrBegin; }
unsigned length() const { return StrLength; }
/// begin() - Pointer to the first byte of the string.
///
@ -81,7 +82,7 @@ public:
/// end() - Pointer to one byte past the end of the string.
///
const char *end() const { return StrEnd; }
const char *end() const { return StrBegin + length(); }
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const MDString *) { return true; }

View File

@ -373,7 +373,7 @@ bool LLParser::ParseNamedGlobal() {
bool LLParser::ParseMDString(MetadataBase *&MDS) {
std::string Str;
if (ParseStringConstant(Str)) return true;
MDS = Context.getMDString(Str.data(), Str.data() + Str.size());
MDS = Context.getMDString(Str.data(), Str.size());
return false;
}

View File

@ -758,7 +758,7 @@ bool BitcodeReader::ParseMetadata() {
for (unsigned i = 0; i != MDStringLength; ++i)
String[i] = Record[i];
Value *V =
Context.getMDString(String.c_str(), String.c_str() + MDStringLength);
Context.getMDString(String.c_str(), MDStringLength);
ValueList.AssignValue(V, NextValueNo++);
break;
}

View File

@ -512,7 +512,7 @@ static uint64_t GetOptimizationFlags(const Value *V) {
// Code: [strchar x N]
const char *StrBegin = MDS->begin();
for (unsigned i = 0, e = MDS->size(); i != e; ++i)
for (unsigned i = 0, e = MDS->length(); i != e; ++i)
Record.push_back(StrBegin[i]);
// Emit the finished record.

View File

@ -1139,7 +1139,7 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
if (const MDString *MDS = dyn_cast<MDString>(V)) {
Out << "!\"";
PrintEscapedString(MDS->begin(), MDS->size(), Out);
PrintEscapedString(MDS->begin(), MDS->length(), Out);
Out << '"';
return;
}
@ -1983,7 +1983,7 @@ void Value::print(raw_ostream &OS, AssemblyAnnotationWriter *AAW) const {
TypePrinter.print(MDS->getType(), OS);
OS << ' ';
OS << "!\"";
PrintEscapedString(MDS->begin(), MDS->size(), OS);
PrintEscapedString(MDS->begin(), MDS->length(), OS);
OS << '"';
} else if (const MDNode *N = dyn_cast<MDNode>(this)) {
SlotTracker SlotTable(N);

View File

@ -551,12 +551,12 @@ MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) {
}
// MDString accessors
MDString* LLVMContext::getMDString(const char *StrBegin, const char *StrEnd) {
return pImpl->getMDString(StrBegin, StrEnd);
MDString* LLVMContext::getMDString(const char *StrBegin, unsigned StrLength) {
return pImpl->getMDString(StrBegin, StrLength);
}
MDString* LLVMContext::getMDString(const std::string &Str) {
return getMDString(Str.data(), Str.data()+Str.size());
return getMDString(Str.data(), Str.size());
}
// FunctionType accessors

View File

@ -394,13 +394,13 @@ ConstantFP *LLVMContextImpl::getConstantFP(const APFloat &V) {
}
MDString *LLVMContextImpl::getMDString(const char *StrBegin,
const char *StrEnd) {
unsigned StrLength) {
sys::SmartScopedWriter<true> Writer(ConstantsLock);
StringMapEntry<MDString *> &Entry = MDStringCache.GetOrCreateValue(
StrBegin, StrEnd);
StringMapEntry<MDString *> &Entry =
MDStringCache.GetOrCreateValue(StrBegin, StrBegin + StrLength);
MDString *&S = Entry.getValue();
if (!S) S = new MDString(Entry.getKeyData(),
Entry.getKeyData() + Entry.getKeyLength());
Entry.getKeyLength());
return S;
}
@ -460,7 +460,8 @@ Constant *LLVMContextImpl::getConstantArray(const ArrayType *Ty,
void LLVMContextImpl::erase(MDString *M) {
sys::SmartScopedWriter<true> Writer(ConstantsLock);
MDStringCache.erase(MDStringCache.find(M->StrBegin, M->StrEnd));
MDStringCache.erase(MDStringCache.find(M->StrBegin,
M->StrBegin + M->length()));
}
void LLVMContextImpl::erase(MDNode *M) {

View File

@ -133,7 +133,7 @@ public:
ConstantFP *getConstantFP(const APFloat &V);
MDString *getMDString(const char *StrBegin, const char *StrEnd);
MDString *getMDString(const char *StrBegin, unsigned StrLength);
MDNode *getMDNode(Value*const* Vals, unsigned NumVals);

View File

@ -23,9 +23,9 @@ namespace {
// MDString objects, even with the same string pointer and nulls in the string.
TEST(MDStringTest, CreateDifferent) {
char x[3] = { 'f', 0, 'A' };
MDString *s1 = getGlobalContext().getMDString(&x[0], &x[3]);
MDString *s1 = getGlobalContext().getMDString(&x[0], 3);
x[2] = 'B';
MDString *s2 = getGlobalContext().getMDString(&x[0], &x[3]);
MDString *s2 = getGlobalContext().getMDString(&x[0], 3);
EXPECT_NE(s1, s2);
}
@ -35,8 +35,8 @@ TEST(MDStringTest, CreateSame) {
char x[4] = { 'a', 'b', 'c', 'X' };
char y[4] = { 'a', 'b', 'c', 'Y' };
MDString *s1 = getGlobalContext().getMDString(&x[0], &x[3]);
MDString *s2 = getGlobalContext().getMDString(&y[0], &y[3]);
MDString *s1 = getGlobalContext().getMDString(&x[0], 3);
MDString *s2 = getGlobalContext().getMDString(&y[0], 3);
EXPECT_EQ(s1, s2);
}
@ -44,7 +44,7 @@ TEST(MDStringTest, CreateSame) {
TEST(MDStringTest, PrintingSimple) {
char *str = new char[13];
strncpy(str, "testing 1 2 3", 13);
MDString *s = getGlobalContext().getMDString(str, str+13);
MDString *s = getGlobalContext().getMDString(str, 13);
strncpy(str, "aaaaaaaaaaaaa", 13);
delete[] str;
@ -56,7 +56,7 @@ TEST(MDStringTest, PrintingSimple) {
// Test printing of MDString with non-printable characters.
TEST(MDStringTest, PrintingComplex) {
char str[5] = {0, '\n', '"', '\\', -1};
MDString *s = getGlobalContext().getMDString(str+0, str+5);
MDString *s = getGlobalContext().getMDString(str+0, 5);
std::ostringstream oss;
s->print(oss);
EXPECT_STREQ("metadata !\"\\00\\0A\\22\\5C\\FF\"", oss.str().c_str());
@ -67,8 +67,8 @@ TEST(MDNodeTest, Simple) {
char x[3] = { 'a', 'b', 'c' };
char y[3] = { '1', '2', '3' };
MDString *s1 = getGlobalContext().getMDString(&x[0], &x[3]);
MDString *s2 = getGlobalContext().getMDString(&y[0], &y[3]);
MDString *s1 = getGlobalContext().getMDString(&x[0], 3);
MDString *s2 = getGlobalContext().getMDString(&y[0], 3);
ConstantInt *CI = getGlobalContext().getConstantInt(APInt(8, 0));
std::vector<Value *> V;