Commit c00c9ac6 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Wow, it's claiming to work

parent c6f450af
...@@ -108,6 +108,15 @@ private: ...@@ -108,6 +108,15 @@ private:
return rtn; return rtn;
} }
void doAssign(VarDecl* decl, RefState* newstate) {
assert(newstate);
assert(vars.count(decl));
assert(vars[decl]->num_refs == 0);
vars[decl]->type = newstate->type;
std::swap(vars[decl]->num_refs, newstate->num_refs);
}
BlockState() {} BlockState() {}
BlockState(const BlockState &rhs) { BlockState(const BlockState &rhs) {
states = rhs.states; states = rhs.states;
...@@ -118,6 +127,7 @@ private: ...@@ -118,6 +127,7 @@ private:
++it; ++it;
++it_rhs; ++it_rhs;
} }
assert(!vars.count(p.first));
vars[p.first] = &*it; vars[p.first] = &*it;
} }
} }
...@@ -154,11 +164,6 @@ private: ...@@ -154,11 +164,6 @@ private:
s1->type = OWNED; s1->type = OWNED;
s2->type = OWNED; s2->type = OWNED;
} }
if (s1->num_refs == 0) {
state1.vars.erase(decl);
state2.vars.erase(decl);
}
} }
} }
...@@ -203,7 +208,7 @@ private: ...@@ -203,7 +208,7 @@ private:
} }
RefState* handle(Expr* expr, BlockState& state) { RefState* handle(Expr* expr, BlockState& state) {
if (isa<StringLiteral>(expr)) { if (isa<StringLiteral>(expr) || isa<IntegerLiteral>(expr)) {
return NULL; return NULL;
} }
...@@ -271,20 +276,28 @@ private: ...@@ -271,20 +276,28 @@ private:
auto callee = callexpr->getCallee(); auto callee = callexpr->getCallee();
auto ft_ptr = callee->getType(); auto ft_ptr = callee->getType();
assert(ft_ptr->isPointerType()); const FunctionProtoType* ft;
auto ft = cast<FunctionProtoType>(ft_ptr->getPointeeType());
if (isa<BuiltinType>(ft_ptr)) {
ft = NULL;
} else {
assert(ft_ptr->isPointerType());
ft = cast<FunctionProtoType>(ft_ptr->getPointeeType());
}
handle(callee, state); handle(callee, state);
for (auto param : ft->param_types()) { if (ft) {
// TODO: process stolen-ness for (auto param : ft->param_types()) {
// TODO: process stolen-ness
}
} }
for (auto arg : callexpr->arguments()) { for (auto arg : callexpr->arguments()) {
handle(arg, state); handle(arg, state);
} }
bool can_throw = !ft->isNothrow(*Context, false); bool can_throw = ft && !ft->isNothrow(*Context, false);
if (can_throw) if (can_throw)
checkClean(state); checkClean(state);
...@@ -349,13 +362,26 @@ private: ...@@ -349,13 +362,26 @@ private:
assert(!state.vars.count(vardecl)); assert(!state.vars.count(vardecl));
RefState* init_state; bool is_refcounted = isRefcountedType(vardecl->getType());
if (is_refcounted)
state.vars[vardecl] = state.createBorrowed();
if (vardecl->hasInit()) { if (vardecl->hasInit()) {
init_state = handle(vardecl->getInit(), state); RefState* assigning = handle(vardecl->getInit(), state);
} else { if (is_refcounted)
init_state = state.createBorrowed(); state.doAssign(vardecl, assigning);
}
return;
}
if (auto rtnstmt = dyn_cast<ReturnStmt>(stmt)) {
auto rstate = handle(rtnstmt->getRetValue(), state);
if (isRefcountedType(rtnstmt->getRetValue()->getType())) {
assert(rstate->num_refs > 0);
// TODO: handle borrowed returns
rstate->num_refs--;
} }
state.vars[vardecl] = init_state;
return; return;
} }
...@@ -387,6 +413,7 @@ private: ...@@ -387,6 +413,7 @@ private:
rstate = state.createBorrowed(); rstate = state.createBorrowed();
} }
} }
errs() << "Starting. state has " << state.vars.size() << " vars\n";
handle(func->getBody(), state); handle(func->getBody(), state);
checkClean(state); checkClean(state);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment