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
///
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.
///
/// 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; }
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;
}
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;
}
// 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.
if (const MDString *MDS = dyn_cast<MDString>(V)) {
Out << "!\"";
- PrintEscapedString(MDS->begin(), MDS->size(), Out);
+ PrintEscapedString(MDS->begin(), MDS->length(), Out);
Out << '"';
return;
}
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);
}
// 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
}
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;
}
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) {
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);
// 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);
}
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);
}
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;
// 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());
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;