Initial commit
[yaffs-website] / node_modules / node-sass / src / libsass / src / to_value.cpp
1 #include "sass.hpp"
2 #include "ast.hpp"
3 #include "to_value.hpp"
4
5 namespace Sass {
6
7   Value_Ptr To_Value::fallback_impl(AST_Node_Ptr n)
8   {
9     // throw a runtime error if this happens
10     // we want a well defined set of possible nodes
11     throw std::runtime_error("invalid node for to_value");
12     // mute warning
13     return 0;
14   }
15
16   // Custom_Error is a valid value
17   Value_Ptr To_Value::operator()(Custom_Error_Ptr e)
18   {
19     return e;
20   }
21
22   // Custom_Warning is a valid value
23   Value_Ptr To_Value::operator()(Custom_Warning_Ptr w)
24   {
25     return w;
26   }
27
28   // Boolean is a valid value
29   Value_Ptr To_Value::operator()(Boolean_Ptr b)
30   {
31     return b;
32   }
33
34   // Number is a valid value
35   Value_Ptr To_Value::operator()(Number_Ptr n)
36   {
37     return n;
38   }
39
40   // Color is a valid value
41   Value_Ptr To_Value::operator()(Color_Ptr c)
42   {
43     return c;
44   }
45
46   // String_Constant is a valid value
47   Value_Ptr To_Value::operator()(String_Constant_Ptr s)
48   {
49     return s;
50   }
51
52   // String_Quoted is a valid value
53   Value_Ptr To_Value::operator()(String_Quoted_Ptr s)
54   {
55     return s;
56   }
57
58   // List is a valid value
59   Value_Ptr To_Value::operator()(List_Ptr l)
60   {
61     List_Obj ll = SASS_MEMORY_NEW(List,
62                                l->pstate(),
63                                l->length(),
64                                l->separator(),
65                                l->is_arglist());
66     for (size_t i = 0, L = l->length(); i < L; ++i) {
67       ll->append((*l)[i]->perform(this));
68     }
69     return ll.detach();
70   }
71
72   // Map is a valid value
73   Value_Ptr To_Value::operator()(Map_Ptr m)
74   {
75     return m;
76   }
77
78   // Null is a valid value
79   Value_Ptr To_Value::operator()(Null_Ptr n)
80   {
81     return n;
82   }
83
84   // Argument returns its value
85   Value_Ptr To_Value::operator()(Argument_Ptr arg)
86   {
87     if (!arg->name().empty()) return 0;
88     return arg->value()->perform(this);
89   }
90
91   // Selector_List is converted to a string
92   Value_Ptr To_Value::operator()(Selector_List_Ptr s)
93   {
94     return SASS_MEMORY_NEW(String_Quoted,
95                            s->pstate(),
96                            s->to_string(ctx.c_options));
97   }
98
99   // Binary_Expression is converted to a string
100   Value_Ptr To_Value::operator()(Binary_Expression_Ptr s)
101   {
102     return SASS_MEMORY_NEW(String_Quoted,
103                            s->pstate(),
104                            s->to_string(ctx.c_options));
105   }
106
107 };