1// sass.hpp must go before all system headers to get the
2// __EXTENSIONS__ fix on Solaris.
3#include "sass.hpp"
4
5#include <iostream>
6#include <typeinfo>
7#include <string>
8
9#include "listize.hpp"
10#include "context.hpp"
11#include "backtrace.hpp"
12#include "error_handling.hpp"
13
14namespace Sass {
15
16 Listize::Listize()
17 { }
18
19 Expression* Listize::perform(AST_Node* node)
20 {
21 Listize listize;
22 return node->perform(op: &listize);
23 }
24
25 Expression* Listize::operator()(SelectorList* sel)
26 {
27 List_Obj l = SASS_MEMORY_NEW(List, sel->pstate(), sel->length(), SASS_COMMA);
28 l->from_selector(from_selector__: true);
29 for (size_t i = 0, L = sel->length(); i < L; ++i) {
30 if (!sel->at(i)) continue;
31 l->append(element: sel->at(i)->perform(op: this));
32 }
33 if (l->length()) return l.detach();
34 return SASS_MEMORY_NEW(Null, l->pstate());
35 }
36
37 Expression* Listize::operator()(CompoundSelector* sel)
38 {
39 sass::string str;
40 for (size_t i = 0, L = sel->length(); i < L; ++i) {
41 Expression* e = (*sel)[i]->perform(op: this);
42 if (e) str += e->to_string();
43 }
44 return SASS_MEMORY_NEW(String_Quoted, sel->pstate(), str);
45 }
46
47 Expression* Listize::operator()(ComplexSelector* sel)
48 {
49 List_Obj l = SASS_MEMORY_NEW(List, sel->pstate());
50 // ToDo: investigate what this does
51 // Note: seems reated to parent ref
52 l->from_selector(from_selector__: true);
53
54 for (auto component : sel->elements()) {
55 if (CompoundSelectorObj compound = Cast<CompoundSelector>(ptr: component)) {
56 if (!compound->empty()) {
57 ExpressionObj hh = compound->perform(op: this);
58 if (hh) l->append(element: hh);
59 }
60 }
61 else if (component) {
62 l->append(SASS_MEMORY_NEW(String_Quoted, component->pstate(), component->to_string()));
63 }
64 }
65
66 if (l->length() == 0) return 0;
67 return l.detach();
68 }
69
70}
71

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