@@ -31,23 +31,6 @@ namespace Sass {
3131 Cast<Supports_Operator>(cond);
3232 }
3333
34- void str_rtrim (std::string& str, const std::string& delimiters = " \f\n\r\t\v " )
35- {
36- str.erase ( str.find_last_not_of ( delimiters ) + 1 );
37- }
38-
39- void String_Constant::rtrim ()
40- {
41- str_rtrim (value_);
42- }
43-
44- void String_Schema::rtrim ()
45- {
46- if (!empty ()) {
47- if (String_Ptr str = Cast<String>(last ())) str->rtrim ();
48- }
49- }
50-
5134 void Argument::set_delayed (bool delayed)
5235 {
5336 if (value_) value_->set_delayed (delayed);
@@ -169,236 +152,6 @@ namespace Sass {
169152 return true ;
170153 }
171154
172- Number::Number (ParserState pstate, double val, std::string u, bool zero)
173- : Value(pstate),
174- Units (),
175- value_(val),
176- zero_(zero),
177- hash_(0 )
178- {
179- size_t l = 0 ;
180- size_t r;
181- if (!u.empty ()) {
182- bool nominator = true ;
183- while (true ) {
184- r = u.find_first_of (" */" , l);
185- std::string unit (u.substr (l, r == std::string::npos ? r : r - l));
186- if (!unit.empty ()) {
187- if (nominator) numerators.push_back (unit);
188- else denominators.push_back (unit);
189- }
190- if (r == std::string::npos) break ;
191- // ToDo: should error for multiple slashes
192- // if (!nominator && u[r] == '/') error(...)
193- if (u[r] == ' /' )
194- nominator = false ;
195- // strange math parsing?
196- // else if (u[r] == '*')
197- // nominator = true;
198- l = r + 1 ;
199- }
200- }
201- concrete_type (NUMBER);
202- }
203-
204- // cancel out unnecessary units
205- void Number::reduce ()
206- {
207- // apply conversion factor
208- value_ *= this ->Units ::reduce ();
209- }
210-
211- void Number::normalize ()
212- {
213- // apply conversion factor
214- value_ *= this ->Units ::normalize ();
215- }
216-
217- bool Custom_Warning::operator == (const Expression& rhs) const
218- {
219- if (Custom_Warning_Ptr_Const r = Cast<Custom_Warning>(&rhs)) {
220- return message () == r->message ();
221- }
222- return false ;
223- }
224-
225- bool Custom_Error::operator == (const Expression& rhs) const
226- {
227- if (Custom_Error_Ptr_Const r = Cast<Custom_Error>(&rhs)) {
228- return message () == r->message ();
229- }
230- return false ;
231- }
232-
233- bool Number::operator == (const Expression& rhs) const
234- {
235- if (auto rhsnr = Cast<Number>(&rhs)) {
236- return *this == *rhsnr;
237- }
238- return false ;
239- }
240-
241- bool Number::operator == (const Number& rhs) const
242- {
243- Number l (*this ), r (rhs); l.reduce (); r.reduce ();
244- size_t lhs_units = l.numerators .size () + l.denominators .size ();
245- size_t rhs_units = r.numerators .size () + r.denominators .size ();
246- // unitless and only having one unit seems equivalent (will change in future)
247- if (!lhs_units || !rhs_units) {
248- return NEAR_EQUAL (l.value (), r.value ());
249- }
250- l.normalize (); r.normalize ();
251- Units &lhs_unit = l, &rhs_unit = r;
252- return lhs_unit == rhs_unit &&
253- NEAR_EQUAL (l.value (), r.value ());
254- }
255-
256- bool Number::operator < (const Number& rhs) const
257- {
258- Number l (*this ), r (rhs); l.reduce (); r.reduce ();
259- size_t lhs_units = l.numerators .size () + l.denominators .size ();
260- size_t rhs_units = r.numerators .size () + r.denominators .size ();
261- // unitless and only having one unit seems equivalent (will change in future)
262- if (!lhs_units || !rhs_units) {
263- return l.value () < r.value ();
264- }
265- l.normalize (); r.normalize ();
266- Units &lhs_unit = l, &rhs_unit = r;
267- if (!(lhs_unit == rhs_unit)) {
268- /* ToDo: do we always get usefull backtraces? */
269- throw Exception::IncompatibleUnits (rhs, *this );
270- }
271- return lhs_unit < rhs_unit ||
272- l.value () < r.value ();
273- }
274-
275- bool String_Quoted::operator == (const Expression& rhs) const
276- {
277- if (String_Quoted_Ptr_Const qstr = Cast<String_Quoted>(&rhs)) {
278- return (value () == qstr->value ());
279- } else if (String_Constant_Ptr_Const cstr = Cast<String_Constant>(&rhs)) {
280- return (value () == cstr->value ());
281- }
282- return false ;
283- }
284-
285- bool String_Constant::is_invisible () const {
286- return value_.empty () && quote_mark_ == 0 ;
287- }
288-
289- bool String_Constant::operator == (const Expression& rhs) const
290- {
291- if (String_Quoted_Ptr_Const qstr = Cast<String_Quoted>(&rhs)) {
292- return (value () == qstr->value ());
293- } else if (String_Constant_Ptr_Const cstr = Cast<String_Constant>(&rhs)) {
294- return (value () == cstr->value ());
295- }
296- return false ;
297- }
298-
299- bool String_Schema::is_left_interpolant (void ) const
300- {
301- return length () && first ()->is_left_interpolant ();
302- }
303- bool String_Schema::is_right_interpolant (void ) const
304- {
305- return length () && last ()->is_right_interpolant ();
306- }
307-
308- bool String_Schema::operator == (const Expression& rhs) const
309- {
310- if (String_Schema_Ptr_Const r = Cast<String_Schema>(&rhs)) {
311- if (length () != r->length ()) return false ;
312- for (size_t i = 0 , L = length (); i < L; ++i) {
313- Expression_Obj rv = (*r)[i];
314- Expression_Obj lv = (*this )[i];
315- if (!lv || !rv) return false ;
316- if (!(*lv == *rv)) return false ;
317- }
318- return true ;
319- }
320- return false ;
321- }
322-
323- bool Boolean::operator == (const Expression& rhs) const
324- {
325- if (Boolean_Ptr_Const r = Cast<Boolean>(&rhs)) {
326- return (value () == r->value ());
327- }
328- return false ;
329- }
330-
331- bool Color::operator == (const Expression& rhs) const
332- {
333- if (Color_Ptr_Const r = Cast<Color>(&rhs)) {
334- return r_ == r->r () &&
335- g_ == r->g () &&
336- b_ == r->b () &&
337- a_ == r->a ();
338- }
339- return false ;
340- }
341-
342- bool List::operator == (const Expression& rhs) const
343- {
344- if (List_Ptr_Const r = Cast<List>(&rhs)) {
345- if (length () != r->length ()) return false ;
346- if (separator () != r->separator ()) return false ;
347- if (is_bracketed () != r->is_bracketed ()) return false ;
348- for (size_t i = 0 , L = length (); i < L; ++i) {
349- Expression_Obj rv = r->at (i);
350- Expression_Obj lv = this ->at (i);
351- if (!lv || !rv) return false ;
352- if (!(*lv == *rv)) return false ;
353- }
354- return true ;
355- }
356- return false ;
357- }
358-
359- bool Map::operator == (const Expression& rhs) const
360- {
361- if (Map_Ptr_Const r = Cast<Map>(&rhs)) {
362- if (length () != r->length ()) return false ;
363- for (auto key : keys ()) {
364- Expression_Obj lv = at (key);
365- Expression_Obj rv = r->at (key);
366- if (!rv || !lv) return false ;
367- if (!(*lv == *rv)) return false ;
368- }
369- return true ;
370- }
371- return false ;
372- }
373-
374- bool Null::operator == (const Expression& rhs) const
375- {
376- return rhs.concrete_type () == NULL_VAL;
377- }
378-
379- bool Function::operator == (const Expression& rhs) const
380- {
381- if (Function_Ptr_Const r = Cast<Function>(&rhs)) {
382- Definition_Ptr_Const d1 = Cast<Definition>(definition ());
383- Definition_Ptr_Const d2 = Cast<Definition>(r->definition ());
384- return d1 && d2 && d1 == d2 && is_css () == r->is_css ();
385- }
386- return false ;
387- }
388-
389- size_t List::size () const {
390- if (!is_arglist_) return length ();
391- // arglist expects a list of arguments
392- // so we need to break before keywords
393- for (size_t i = 0 , L = length (); i < L; ++i) {
394- Expression_Obj obj = this ->at (i);
395- if (Argument_Ptr arg = Cast<Argument>(obj)) {
396- if (!arg->name ().empty ()) return i;
397- }
398- }
399- return length ();
400- }
401-
402155 Expression_Obj Hashed::at (Expression_Obj k) const
403156 {
404157 if (elements_.count (k))
@@ -431,16 +184,6 @@ namespace Sass {
431184 return to_string ({ NESTED, 5 });
432185 }
433186
434- std::string String_Quoted::inspect () const
435- {
436- return quote (value_, ' *' );
437- }
438-
439- std::string String_Constant::inspect () const
440- {
441- return quote (value_, ' *' );
442- }
443-
444187 bool Declaration::is_invisible () const
445188 {
446189 if (is_custom_property ()) return false ;
@@ -464,81 +207,12 @@ namespace Sass {
464207 }
465208 }
466209
467- Function_Call::Function_Call (ParserState pstate, std::string n, Arguments_Obj args, void * cookie)
468- : PreValue(pstate), sname_(SASS_MEMORY_NEW(String_Constant, pstate, n)), arguments_(args), func_(), via_call_(false ), cookie_(cookie), hash_(0 )
469- { concrete_type (FUNCTION); }
470- Function_Call::Function_Call (ParserState pstate, std::string n, Arguments_Obj args, Function_Obj func)
471- : PreValue(pstate), sname_(SASS_MEMORY_NEW(String_Constant, pstate, n)), arguments_(args), func_(func), via_call_(false ), cookie_(0 ), hash_(0 )
472- { concrete_type (FUNCTION); }
473- Function_Call::Function_Call (ParserState pstate, std::string n, Arguments_Obj args)
474- : PreValue(pstate), sname_(SASS_MEMORY_NEW(String_Constant, pstate, n)), arguments_(args), via_call_(false ), cookie_(0 ), hash_(0 )
475- { concrete_type (FUNCTION); }
476-
477- bool Function_Call::operator ==(const Expression& rhs) const
478- {
479- try
480- {
481- Function_Call_Ptr_Const m = Cast<Function_Call>(&rhs);
482- if (!(m && *sname () == *m->sname ())) return false ;
483- if (!(m && arguments ()->length () == m->arguments ()->length ())) return false ;
484- for (size_t i =0 , L = arguments ()->length (); i < L; ++i)
485- if (!(*(*arguments ())[i] == *(*m->arguments ())[i])) return false ;
486- return true ;
487- }
488- catch (std::bad_cast&)
489- {
490- return false ;
491- }
492- catch (...) { throw ; }
493- }
494-
495- size_t Function_Call::hash () const
496- {
497- if (hash_ == 0 ) {
498- hash_ = std::hash<std::string>()(name ());
499- for (auto argument : arguments ()->elements ())
500- hash_combine (hash_, argument->hash ());
501- }
502- return hash_;
503- }
504-
505- // ////////////////////////////////////////////////////////////////////////////////////////
506- // Convert map to (key, value) list.
507- // ////////////////////////////////////////////////////////////////////////////////////////
508- List_Obj Map::to_list (ParserState& pstate) {
509- List_Obj ret = SASS_MEMORY_NEW (List, pstate, length (), SASS_COMMA);
510-
511- for (auto key : keys ()) {
512- List_Obj l = SASS_MEMORY_NEW (List, pstate, 2 );
513- l->append (key);
514- l->append (at (key));
515- ret->append (l);
516- }
517-
518- return ret;
519- }
520-
521210 IMPLEMENT_AST_OPERATORS (Supports_Operator);
522211 IMPLEMENT_AST_OPERATORS (Supports_Negation);
523212 IMPLEMENT_AST_OPERATORS (Ruleset);
524213 IMPLEMENT_AST_OPERATORS (Media_Block);
525- IMPLEMENT_AST_OPERATORS (Custom_Warning);
526- IMPLEMENT_AST_OPERATORS (Custom_Error);
527- IMPLEMENT_AST_OPERATORS (List);
528- IMPLEMENT_AST_OPERATORS (Map);
529- IMPLEMENT_AST_OPERATORS (Function);
530- IMPLEMENT_AST_OPERATORS (Number);
531- IMPLEMENT_AST_OPERATORS (Binary_Expression);
532- IMPLEMENT_AST_OPERATORS (String_Schema);
533- IMPLEMENT_AST_OPERATORS (String_Constant);
534- IMPLEMENT_AST_OPERATORS (String_Quoted);
535- IMPLEMENT_AST_OPERATORS (Boolean);
536- IMPLEMENT_AST_OPERATORS (Color);
537- IMPLEMENT_AST_OPERATORS (Null);
538- IMPLEMENT_AST_OPERATORS (Parent_Reference);
539214 IMPLEMENT_AST_OPERATORS (Import);
540215 IMPLEMENT_AST_OPERATORS (Import_Stub);
541- IMPLEMENT_AST_OPERATORS (Function_Call);
542216 IMPLEMENT_AST_OPERATORS (Directive);
543217 IMPLEMENT_AST_OPERATORS (At_Root_Block);
544218 IMPLEMENT_AST_OPERATORS (Supports_Block);
@@ -556,7 +230,6 @@ namespace Sass {
556230 IMPLEMENT_AST_OPERATORS (Assignment);
557231 IMPLEMENT_AST_OPERATORS (Return);
558232 IMPLEMENT_AST_OPERATORS (At_Root_Query);
559- IMPLEMENT_AST_OPERATORS (Variable);
560233 IMPLEMENT_AST_OPERATORS (Comment);
561234 IMPLEMENT_AST_OPERATORS (Supports_Interpolation);
562235 IMPLEMENT_AST_OPERATORS (Supports_Declaration);
0 commit comments