Skip to content

Commit

Permalink
Add list delimiter support to the C API
Browse files Browse the repository at this point in the history
Lists gained an `is_bracketed` attribute in #2279. The primary
semantic difference is that the`is_bracketed` changes list equality
(#2281) which can matter in custom functions.

This is a breaking change so I'd like to get it into the first 3.5
beta.
  • Loading branch information
xzyfer committed Jan 5, 2017
1 parent 9ab7daa commit 9450d37
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
4 changes: 3 additions & 1 deletion include/sass/values.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ADDAPI union Sass_Value* ADDCALL sass_make_string (const char* val);
ADDAPI union Sass_Value* ADDCALL sass_make_qstring (const char* val);
ADDAPI union Sass_Value* ADDCALL sass_make_number (double val, const char* unit);
ADDAPI union Sass_Value* ADDCALL sass_make_color (double r, double g, double b, double a);
ADDAPI union Sass_Value* ADDCALL sass_make_list (size_t len, enum Sass_Separator sep);
ADDAPI union Sass_Value* ADDCALL sass_make_list (size_t len, enum Sass_Separator sep, bool is_bracketed);
ADDAPI union Sass_Value* ADDCALL sass_make_map (size_t len);
ADDAPI union Sass_Value* ADDCALL sass_make_error (const char* msg);
ADDAPI union Sass_Value* ADDCALL sass_make_warning (const char* msg);
Expand Down Expand Up @@ -116,6 +116,8 @@ ADDAPI size_t ADDCALL sass_list_get_length (const union Sass_Value* v);
// Getters and setters for Sass_List
ADDAPI enum Sass_Separator ADDCALL sass_list_get_separator (const union Sass_Value* v);
ADDAPI void ADDCALL sass_list_set_separator (union Sass_Value* v, enum Sass_Separator value);
ADDAPI bool ADDCALL sass_list_get_is_bracketed (const union Sass_Value* v);
ADDAPI void ADDCALL sass_list_set_is_bracketed (union Sass_Value* v, bool value);
// Getters and setters for Sass_List values
ADDAPI union Sass_Value* ADDCALL sass_list_get_value (const union Sass_Value* v, size_t i);
ADDAPI void ADDCALL sass_list_set_value (union Sass_Value* v, size_t i, union Sass_Value* value);
Expand Down
9 changes: 5 additions & 4 deletions src/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ namespace Sass {
Sass_Function_Fn c_func = sass_function_get_function(c_function);

To_C to_c;
union Sass_Value* c_args = sass_make_list(1, SASS_COMMA);
union Sass_Value* c_args = sass_make_list(1, SASS_COMMA, false);
sass_list_set_value(c_args, 0, message->perform(&to_c));
union Sass_Value* c_val = c_func(c_args, c_function, ctx.c_compiler);
ctx.c_options.output_style = outstyle;
Expand Down Expand Up @@ -377,7 +377,7 @@ namespace Sass {
Sass_Function_Fn c_func = sass_function_get_function(c_function);

To_C to_c;
union Sass_Value* c_args = sass_make_list(1, SASS_COMMA);
union Sass_Value* c_args = sass_make_list(1, SASS_COMMA, false);
sass_list_set_value(c_args, 0, message->perform(&to_c));
union Sass_Value* c_val = c_func(c_args, c_function, ctx.c_compiler);
ctx.c_options.output_style = outstyle;
Expand Down Expand Up @@ -410,7 +410,7 @@ namespace Sass {
Sass_Function_Fn c_func = sass_function_get_function(c_function);

To_C to_c;
union Sass_Value* c_args = sass_make_list(1, SASS_COMMA);
union Sass_Value* c_args = sass_make_list(1, SASS_COMMA, false);
sass_list_set_value(c_args, 0, message->perform(&to_c));
union Sass_Value* c_val = c_func(c_args, c_function, ctx.c_compiler);
ctx.c_options.output_style = outstyle;
Expand Down Expand Up @@ -907,7 +907,7 @@ namespace Sass {
exp.backtrace_stack.push_back(&here);

To_C to_c;
union Sass_Value* c_args = sass_make_list(params->length(), SASS_COMMA);
union Sass_Value* c_args = sass_make_list(params->length(), SASS_COMMA, false);
for(size_t i = 0; i < params->length(); i++) {
Parameter_Obj param = params->at(i);
std::string key = param->name();
Expand Down Expand Up @@ -1613,6 +1613,7 @@ namespace Sass {
for (size_t i = 0, L = sass_list_get_length(v); i < L; ++i) {
l->append(cval_to_astnode(sass_list_get_value(v, i), backtrace, pstate));
}
l->is_bracketed(sass_list_get_is_bracketed(v));
e = l;
} break;
case SASS_MAP: {
Expand Down
7 changes: 5 additions & 2 deletions src/sass_values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ extern "C" {
size_t ADDCALL sass_list_get_length(const union Sass_Value* v) { return v->list.length; }
enum Sass_Separator ADDCALL sass_list_get_separator(const union Sass_Value* v) { return v->list.separator; }
void ADDCALL sass_list_set_separator(union Sass_Value* v, enum Sass_Separator separator) { v->list.separator = separator; }
bool ADDCALL sass_list_get_is_bracketed(const union Sass_Value* v) { return v->list.is_bracketed; }
void ADDCALL sass_list_set_is_bracketed(union Sass_Value* v, bool is_bracketed) { v->list.is_bracketed = is_bracketed; }
// Getters and setters for Sass_List values
union Sass_Value* ADDCALL sass_list_get_value(const union Sass_Value* v, size_t i) { return v->list.values[i]; }
void ADDCALL sass_list_set_value(union Sass_Value* v, size_t i, union Sass_Value* value) { v->list.values[i] = value; }
Expand Down Expand Up @@ -130,13 +132,14 @@ extern "C" {
return v;
}

union Sass_Value* ADDCALL sass_make_list(size_t len, enum Sass_Separator sep)
union Sass_Value* ADDCALL sass_make_list(size_t len, enum Sass_Separator sep, bool is_bracketed)
{
union Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
if (v == 0) return 0;
v->list.tag = SASS_LIST;
v->list.length = len;
v->list.separator = sep;
v->list.is_bracketed = is_bracketed;
v->list.values = (union Sass_Value**) calloc(len, sizeof(union Sass_Value*));
if (v->list.values == 0) { free(v); return 0; }
return v;
Expand Down Expand Up @@ -247,7 +250,7 @@ extern "C" {
return sass_string_is_quoted(val) ? sass_make_qstring(val->string.value) : sass_make_string(val->string.value);
} break;
case SASS_LIST: {
union Sass_Value* list = sass_make_list(val->list.length, val->list.separator);
union Sass_Value* list = sass_make_list(val->list.length, val->list.separator, val->list.is_bracketed);
for (i = 0; i < list->list.length; i++) {
list->list.values[i] = sass_clone_value(val->list.values[i]);
}
Expand Down
3 changes: 2 additions & 1 deletion src/sass_values.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct Sass_String {
struct Sass_List {
enum Sass_Tag tag;
enum Sass_Separator separator;
bool is_bracketed;
size_t length;
// null terminated "array"
union Sass_Value** values;
Expand Down Expand Up @@ -78,4 +79,4 @@ struct Sass_MapPair {
union Sass_Value* value;
};

#endif
#endif
4 changes: 2 additions & 2 deletions src/to_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Sass {

union Sass_Value* To_C::operator()(List_Ptr l)
{
union Sass_Value* v = sass_make_list(l->length(), l->separator());
union Sass_Value* v = sass_make_list(l->length(), l->separator(), l->is_bracketed());
for (size_t i = 0, L = l->length(); i < L; ++i) {
sass_list_set_value(v, i, (*l)[i]->perform(this));
}
Expand All @@ -57,7 +57,7 @@ namespace Sass {

union Sass_Value* To_C::operator()(Arguments_Ptr a)
{
union Sass_Value* v = sass_make_list(a->length(), SASS_COMMA);
union Sass_Value* v = sass_make_list(a->length(), SASS_COMMA, false);
for (size_t i = 0, L = a->length(); i < L; ++i) {
sass_list_set_value(v, i, (*a)[i]->perform(this));
}
Expand Down
3 changes: 2 additions & 1 deletion src/values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Sass {
else if (val->concrete_type() == Expression::LIST)
{
List_Ptr_Const l = dynamic_cast<List_Ptr_Const>(val);
union Sass_Value* list = sass_make_list(l->size(), l->separator());
union Sass_Value* list = sass_make_list(l->size(), l->separator(), l->is_bracketed());
for (size_t i = 0, L = l->length(); i < L; ++i) {
Expression_Obj obj = l->at(i);
auto val = ast_node_to_sass_value(&obj);
Expand Down Expand Up @@ -106,6 +106,7 @@ namespace Sass {
for (size_t i = 0, L = sass_list_get_length(val); i < L; ++i) {
l->append(sass_value_to_ast_node(sass_list_get_value(val, i)));
}
l->is_bracketed(sass_list_get_is_bracketed(val));
return l;
}
break;
Expand Down

0 comments on commit 9450d37

Please sign in to comment.