Skip to content

Commit

Permalink
Revert "use StringRef where possible"
Browse files Browse the repository at this point in the history
This reverts commit 370b29e.

That commit broke 5 tests:

```
lang/modules/imports/ambiguous1: unexpected compiler error
lang/modules/imports/ambiguous2: unexpected compiler error
lang/modules/imports/ambiguous3: unexpected compiler error
lang/modules/imports/ambiguous4: unexpected compiler error
lang/modules/imports/ambiguous5: unexpected compiler error
```
  • Loading branch information
stepancheg committed Mar 30, 2013
1 parent 1a0975a commit 5d41139
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 51 deletions.
41 changes: 18 additions & 23 deletions compiler/codegen_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,6 @@ static IdentifierPtr valueToIdentifier(MultiCValuePtr args, unsigned index)
return (Identifier *)obj.ptr();
}

static llvm::StringRef valueToStringRef(MultiCValuePtr args, unsigned index)
{
return valueToIdentifier(args, index)->str;
}



//
Expand Down Expand Up @@ -1721,14 +1716,14 @@ void codegenPrimOp(PrimOpPtr x,
ensureArity(args, 2);
bool result = false;
ObjectPtr obj = valueToStatic(args->values[0]);
llvm::StringRef fname = valueToStringRef(args, 1);
IdentifierPtr fname = valueToIdentifier(args, 1);
if (obj.ptr() && (obj->objKind == TYPE)) {
Type *t = (Type *)obj.ptr();
if (t->typeKind == RECORD_TYPE) {
RecordType *rt = (RecordType *)t;
const llvm::StringMap<size_t> &fieldIndexMap =
recordFieldIndexMap(rt);
result = (fieldIndexMap.find(fname)
result = (fieldIndexMap.find(fname->str)
!= fieldIndexMap.end());
}
}
Expand Down Expand Up @@ -1779,14 +1774,14 @@ void codegenPrimOp(PrimOpPtr x,
ensureArity(args, 2);
RecordTypePtr rt;
llvm::Value *vrec = recordValue(args, 0, rt);
llvm::StringRef fname = valueToStringRef(args, 1);
IdentifierPtr fname = valueToIdentifier(args, 1);
const llvm::StringMap<size_t> &fieldIndexMap = recordFieldIndexMap(rt);
llvm::StringMap<size_t>::const_iterator fi =
fieldIndexMap.find(fname);
fieldIndexMap.find(fname->str);
if (fi == fieldIndexMap.end()) {
string buf;
llvm::raw_string_ostream sout(buf);
sout << "field not found: " << fname;
sout << "field not found: " << fname->str;
argumentError(1, sout.str());
}
unsigned i = unsigned(fi->second);
Expand Down Expand Up @@ -2024,36 +2019,36 @@ void codegenPrimOp(PrimOpPtr x,

case PRIM_stringLiteralByteIndex : {
ensureArity(args, 2);
llvm::StringRef ident = valueToStringRef(args, 0);
IdentifierPtr ident = valueToIdentifier(args, 0);
unsigned n = unsigned(valueToStaticSizeTOrInt(args, 1));
if (n >= ident.size())
if (n >= ident->str.size())
argumentError(1, "string literal index out of bounds");

assert(out->size() == 1);
CValuePtr outi = out->values[0];
assert(outi->type == cIntType);
llvm::Constant *value = llvm::ConstantInt::get(llvmIntType(32), size_t(ident[n]));
llvm::Constant *value = llvm::ConstantInt::get(llvmIntType(32), size_t(ident->str[n]));
ctx->builder->CreateStore(value, outi->llValue);
break;
}

case PRIM_stringLiteralBytes : {
ensureArity(args, 1);
llvm::StringRef ident = valueToStringRef(args, 0);
assert(out->size() == ident.size());
for (unsigned i = 0; i < ident.size(); ++i) {
IdentifierPtr ident = valueToIdentifier(args, 0);
assert(out->size() == ident->str.size());
for (unsigned i = 0; i < ident->str.size(); ++i) {
CValuePtr outi = out->values[i];
assert(outi->type == cIntType);
llvm::Constant *value = llvm::ConstantInt::get(llvmIntType(32), size_t(ident[i]));
llvm::Constant *value = llvm::ConstantInt::get(llvmIntType(32), size_t(ident->str[i]));
ctx->builder->CreateStore(value, outi->llValue);
}
break;
}

case PRIM_stringLiteralByteSize : {
ensureArity(args, 1);
llvm::StringRef ident = valueToStringRef(args, 0);
ValueHolderPtr vh = sizeTToValueHolder(ident.size());
IdentifierPtr ident = valueToIdentifier(args, 0);
ValueHolderPtr vh = sizeTToValueHolder(ident->str.size());
codegenStaticObject(vh.ptr(), ctx, out);
break;
}
Expand All @@ -2065,8 +2060,8 @@ void codegenPrimOp(PrimOpPtr x,

case PRIM_stringTableConstant : {
ensureArity(args, 1);
llvm::StringRef ident = valueToStringRef(args, 0);
llvm::Value *value = codegenStringTableConstant(ident);
IdentifierPtr ident = valueToIdentifier(args, 0);
llvm::Value *value = codegenStringTableConstant(ident->str);

assert(out->size() == 1);
CValuePtr out0 = out->values[0];
Expand All @@ -2077,8 +2072,8 @@ void codegenPrimOp(PrimOpPtr x,

case PRIM_FlagP : {
ensureArity(args, 1);
llvm::StringRef ident = valueToStringRef(args, 0);
llvm::StringMap<string>::const_iterator flag = globalFlags.find(ident);
IdentifierPtr ident = valueToIdentifier(args, 0);
llvm::StringMap<string>::const_iterator flag = globalFlags.find(ident->str);
ValueHolderPtr vh = boolToValueHolder(flag != globalFlags.end());
codegenStaticObject(vh.ptr(), ctx, out);
break;
Expand Down
10 changes: 5 additions & 5 deletions compiler/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ void addGlobal(ModulePtr module,
// module errors
//

static void suggestModules(llvm::raw_ostream &err, set<string> const &moduleNames, llvm::StringRef name) {
static void suggestModules(llvm::raw_ostream &err, set<string> const &moduleNames, IdentifierPtr name) {
for (set<string>::const_iterator i = moduleNames.begin(), end = moduleNames.end();
i != end;
++i)
{
err << "\n import " << *i << ".(" << name << ");";
err << "\n import " << *i << ".(" << name->str << ");";
}
}

static void ambiguousImportError(IdentifierPtr name, ImportSet const &candidates) {
string buf;
llvm::raw_string_ostream err(buf);
err << "ambiguous imported symbol: " << name;
err << "ambiguous imported symbol: " << name->str;
set<string> moduleNames;
for (const ObjectPtr *i = candidates.begin(), *end = candidates.end();
i != end;
Expand All @@ -60,7 +60,7 @@ static void ambiguousImportError(IdentifierPtr name, ImportSet const &candidates
}

err << "\n disambiguate with one of:";
suggestModules(err, moduleNames, name->str);
suggestModules(err, moduleNames, name);
error(name, err.str());
}

Expand All @@ -80,7 +80,7 @@ static void undefinedNameError(IdentifierPtr name) {

if (!suggestModuleNames.empty()) {
err << "\n maybe you need one of:";
suggestModules(err, suggestModuleNames, name->str);
suggestModules(err, suggestModuleNames, name);
}

error(name, err.str());
Expand Down
41 changes: 18 additions & 23 deletions compiler/evaluator_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,6 @@ static IdentifierPtr valueToIdentifier(MultiEValuePtr args, unsigned index)
return (Identifier *)obj.ptr();
}

static llvm::StringRef valueToStringRef(MultiEValuePtr args, unsigned index)
{
return valueToIdentifier(args, index)->str;
}



//
Expand Down Expand Up @@ -1788,14 +1783,14 @@ void evalPrimOp(PrimOpPtr x, MultiEValuePtr args, MultiEValuePtr out)
ensureArity(args, 2);
bool result = false;
ObjectPtr obj = valueToStatic(args->values[0]);
llvm::StringRef fname = valueToStringRef(args, 1);
IdentifierPtr fname = valueToIdentifier(args, 1);
if (obj.ptr() && (obj->objKind == TYPE)) {
Type *t = (Type *)obj.ptr();
if (t->typeKind == RECORD_TYPE) {
RecordType *rt = (RecordType *)t;
const llvm::StringMap<size_t> &fieldIndexMap =
recordFieldIndexMap(rt);
result = (fieldIndexMap.find(fname)
result = (fieldIndexMap.find(fname->str)
!= fieldIndexMap.end());
}
}
Expand Down Expand Up @@ -1846,14 +1841,14 @@ void evalPrimOp(PrimOpPtr x, MultiEValuePtr args, MultiEValuePtr out)
ensureArity(args, 2);
RecordTypePtr rt;
EValuePtr erec = recordValue(args, 0, rt);
llvm::StringRef fname = valueToStringRef(args, 1);
IdentifierPtr fname = valueToIdentifier(args, 1);
const llvm::StringMap<size_t> &fieldIndexMap = recordFieldIndexMap(rt);
llvm::StringMap<size_t>::const_iterator fi =
fieldIndexMap.find(fname);
fieldIndexMap.find(fname->str);
if (fi == fieldIndexMap.end()) {
string buf;
llvm::raw_string_ostream sout(buf);
sout << "field not found: " << fname;
sout << "field not found: " << fname->str;
argumentError(1, sout.str());
}
unsigned i = unsigned(fi->second);
Expand Down Expand Up @@ -2094,34 +2089,34 @@ void evalPrimOp(PrimOpPtr x, MultiEValuePtr args, MultiEValuePtr out)

case PRIM_stringLiteralByteIndex : {
ensureArity(args, 2);
llvm::StringRef ident = valueToStringRef(args, 0);
IdentifierPtr ident = valueToIdentifier(args, 0);
size_t n = valueToStaticSizeTOrInt(args, 1);
if (n >= ident.size())
if (n >= ident->str.size())
argumentError(1, "string literal index out of bounds");

assert(out->size() == 1);
EValuePtr outi = out->values[0];
assert(outi->type == cIntType);
outi->as<int>() = ident[unsigned(n)];
outi->as<int>() = ident->str[unsigned(n)];
break;
}

case PRIM_stringLiteralBytes : {
ensureArity(args, 1);
llvm::StringRef ident = valueToStringRef(args, 0);
assert(out->size() == ident.size());
for (unsigned i = 0, sz = unsigned(ident.size()); i < sz; ++i) {
IdentifierPtr ident = valueToIdentifier(args, 0);
assert(out->size() == ident->str.size());
for (unsigned i = 0, sz = unsigned(ident->str.size()); i < sz; ++i) {
EValuePtr outi = out->values[i];
assert(outi->type == cIntType);
outi->as<int>() = ident[i];
outi->as<int>() = ident->str[i];
}
break;
}

case PRIM_stringLiteralByteSize : {
ensureArity(args, 1);
llvm::StringRef ident = valueToStringRef(args, 0);
ValueHolderPtr vh = sizeTToValueHolder(ident.size());
IdentifierPtr ident = valueToIdentifier(args, 0);
ValueHolderPtr vh = sizeTToValueHolder(ident->str.size());
evalStaticObject(vh.ptr(), out);
break;
}
Expand All @@ -2133,8 +2128,8 @@ void evalPrimOp(PrimOpPtr x, MultiEValuePtr args, MultiEValuePtr out)

case PRIM_stringTableConstant : {
ensureArity(args, 1);
llvm::StringRef ident = valueToStringRef(args, 0);
const void *value = evalStringTableConstant(ident);
IdentifierPtr ident = valueToIdentifier(args, 0);
const void *value = evalStringTableConstant(ident->str);

assert(out->size() == 1);
EValuePtr out0 = out->values[0];
Expand All @@ -2152,8 +2147,8 @@ void evalPrimOp(PrimOpPtr x, MultiEValuePtr args, MultiEValuePtr out)

case PRIM_FlagP : {
ensureArity(args, 1);
llvm::StringRef ident = valueToStringRef(args, 0);
llvm::StringMap<string>::const_iterator flag = globalFlags.find(ident);
IdentifierPtr ident = valueToIdentifier(args, 0);
llvm::StringMap<string>::const_iterator flag = globalFlags.find(ident->str);
assert(out->size() == 1);
EValuePtr out0 = out->values[0];
assert(out0->type == boolType);
Expand Down

0 comments on commit 5d41139

Please sign in to comment.