1// sass.hpp must go before all system headers to get the
2// __EXTENSIONS__ fix on Solaris.
3#include "sass.hpp"
4
5#include "ast2c.hpp"
6#include "ast.hpp"
7
8namespace Sass {
9
10 union Sass_Value* AST2C::operator()(Boolean* b)
11 { return sass_make_boolean(val: b->value()); }
12
13 union Sass_Value* AST2C::operator()(Number* n)
14 { return sass_make_number(val: n->value(), unit: n->unit().c_str()); }
15
16 union Sass_Value* AST2C::operator()(Custom_Warning* w)
17 { return sass_make_warning(msg: w->message().c_str()); }
18
19 union Sass_Value* AST2C::operator()(Custom_Error* e)
20 { return sass_make_error(msg: e->message().c_str()); }
21
22 union Sass_Value* AST2C::operator()(Color_RGBA* c)
23 { return sass_make_color(r: c->r(), g: c->g(), b: c->b(), a: c->a()); }
24
25 union Sass_Value* AST2C::operator()(Color_HSLA* c)
26 {
27 Color_RGBA_Obj rgba = c->copyAsRGBA();
28 return operator()(c: rgba.ptr());
29 }
30
31 union Sass_Value* AST2C::operator()(String_Constant* s)
32 {
33 if (s->quote_mark()) {
34 return sass_make_qstring(val: s->value().c_str());
35 } else {
36 return sass_make_string(val: s->value().c_str());
37 }
38 }
39
40 union Sass_Value* AST2C::operator()(String_Quoted* s)
41 { return sass_make_qstring(val: s->value().c_str()); }
42
43 union Sass_Value* AST2C::operator()(List* l)
44 {
45 union Sass_Value* v = sass_make_list(len: l->length(), sep: l->separator(), is_bracketed: l->is_bracketed());
46 for (size_t i = 0, L = l->length(); i < L; ++i) {
47 sass_list_set_value(v, i, value: (*l)[i]->perform(op: this));
48 }
49 return v;
50 }
51
52 union Sass_Value* AST2C::operator()(Map* m)
53 {
54 union Sass_Value* v = sass_make_map(len: m->length());
55 int i = 0;
56 for (auto key : m->keys()) {
57 sass_map_set_key(v, i, key->perform(op: this));
58 sass_map_set_value(v, i, m->at(k: key)->perform(op: this));
59 i++;
60 }
61 return v;
62 }
63
64 union Sass_Value* AST2C::operator()(Arguments* a)
65 {
66 union Sass_Value* v = sass_make_list(len: a->length(), sep: SASS_COMMA, is_bracketed: false);
67 for (size_t i = 0, L = a->length(); i < L; ++i) {
68 sass_list_set_value(v, i, value: (*a)[i]->perform(op: this));
69 }
70 return v;
71 }
72
73 union Sass_Value* AST2C::operator()(Argument* a)
74 { return a->value()->perform(op: this); }
75
76 // not strictly necessary because of the fallback
77 union Sass_Value* AST2C::operator()(Null* n)
78 { return sass_make_null(); }
79
80};
81

source code of gtk/subprojects/libsass/src/ast2c.cpp