Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Pass traces instead of full context to bind
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Mar 17, 2018
1 parent 72e9a04 commit 025dc4e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
24 changes: 12 additions & 12 deletions src/bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Sass {

void bind(std::string type, std::string name, Parameters_Obj ps, Arguments_Obj as, Env* env, Eval* eval)
void bind(std::string type, std::string name, Parameters_Obj ps, Arguments_Obj as, Env* env, Eval* eval, Backtraces& traces)
{
std::string callee(type + " " + name);

Expand Down Expand Up @@ -54,7 +54,7 @@ namespace Sass {
std::stringstream msg;
msg << "wrong number of arguments (" << LA << " for " << LP << ")";
msg << " for `" << name << "'";
return error(msg.str(), as->pstate(), eval->exp.traces);
return error(msg.str(), as->pstate(), traces);
}
Parameter_Obj p = ps->at(ip);

Expand Down Expand Up @@ -107,8 +107,8 @@ namespace Sass {
false,
false));
} else {
eval->exp.traces.push_back(Backtrace(key->pstate()));
throw Exception::InvalidVarKwdType(key->pstate(), eval->exp.traces, key->inspect(), a);
traces.push_back(Backtrace(key->pstate()));
throw Exception::InvalidVarKwdType(key->pstate(), traces, key->inspect(), a);
}
}

Expand Down Expand Up @@ -222,15 +222,15 @@ namespace Sass {
for (auto key : argmap->keys()) {
String_Constant_Ptr val = Cast<String_Constant>(key);
if (val == NULL) {
eval->exp.traces.push_back(Backtrace(key->pstate()));
throw Exception::InvalidVarKwdType(key->pstate(), eval->exp.traces, key->inspect(), a);
traces.push_back(Backtrace(key->pstate()));
throw Exception::InvalidVarKwdType(key->pstate(), traces, key->inspect(), a);
}
std::string param = "$" + unquote(val->value());

if (!param_map.count(param)) {
std::stringstream msg;
msg << callee << " has no parameter named " << param;
error(msg.str(), a->pstate(), eval->exp.traces);
error(msg.str(), a->pstate(), traces);
}
env->local_frame()[param] = argmap->at(key);
}
Expand All @@ -245,7 +245,7 @@ namespace Sass {
std::stringstream msg;
msg << "parameter " << p->name()
<< " provided more than once in call to " << callee;
error(msg.str(), a->pstate(), eval->exp.traces);
error(msg.str(), a->pstate(), traces);
}
// ordinal arg -- bind it to the next param
env->local_frame()[p->name()] = a->value();
Expand All @@ -259,22 +259,22 @@ namespace Sass {
} else {
std::stringstream msg;
msg << callee << " has no parameter named " << a->name();
error(msg.str(), a->pstate(), eval->exp.traces);
error(msg.str(), a->pstate(), traces);
}
}
if (param_map[a->name()]) {
if (param_map[a->name()]->is_rest_parameter()) {
std::stringstream msg;
msg << "argument " << a->name() << " of " << callee
<< "cannot be used as named argument";
error(msg.str(), a->pstate(), eval->exp.traces);
error(msg.str(), a->pstate(), traces);
}
}
if (env->has_local(a->name())) {
std::stringstream msg;
msg << "parameter " << p->name()
<< "provided more than once in call to " << callee;
error(msg.str(), a->pstate(), eval->exp.traces);
error(msg.str(), a->pstate(), traces);
}
env->local_frame()[a->name()] = a->value();
}
Expand All @@ -299,7 +299,7 @@ namespace Sass {
}
else {
// param is unbound and has no default value -- error
throw Exception::MissingArgument(as->pstate(), eval->exp.traces, name, leftover->name(), type);
throw Exception::MissingArgument(as->pstate(), traces, name, leftover->name(), type);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/bind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#define SASS_BIND_H

#include <string>
#include "backtrace.hpp"
#include "environment.hpp"
#include "ast_fwd_decl.hpp"

namespace Sass {

void bind(std::string type, std::string name, Parameters_Obj, Arguments_Obj, Env*, Eval*);
void bind(std::string type, std::string name, Parameters_Obj, Arguments_Obj, Env*, Eval*, Backtraces traces);
}

#endif
4 changes: 2 additions & 2 deletions src/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ namespace Sass {
exp.env_stack.push_back(&fn_env);

if (func || body) {
bind(std::string("Function"), c->name(), params, args, &fn_env, this);
bind(std::string("Function"), c->name(), params, args, &fn_env, this, traces);
std::string msg(", in function `" + c->name() + "`");
traces.push_back(Backtrace(c->pstate(), msg));
ctx.callee_stack.push_back({
Expand Down Expand Up @@ -1045,7 +1045,7 @@ namespace Sass {

// populates env with default values for params
std::string ff(c->name());
bind(std::string("Function"), c->name(), params, args, &fn_env, this);
bind(std::string("Function"), c->name(), params, args, &fn_env, this, traces);
std::string msg(", in function `" + c->name() + "`");
traces.push_back(Backtrace(c->pstate(), msg));
ctx.callee_stack.push_back({
Expand Down
2 changes: 1 addition & 1 deletion src/expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ namespace Sass {
new_env.local_frame()["@content[m]"] = thunk;
}

bind(std::string("Mixin"), c->name(), params, args, &new_env, &eval);
bind(std::string("Mixin"), c->name(), params, args, &new_env, &eval, traces);

Block_Obj trace_block = SASS_MEMORY_NEW(Block, c->pstate());
Trace_Obj trace = SASS_MEMORY_NEW(Trace, c->pstate(), c->name(), trace_block);
Expand Down

0 comments on commit 025dc4e

Please sign in to comment.