<commit_before>#include "expand.hpp"
#include "ast.hpp"
#include "bind.hpp"
#include "eval.hpp"

#include <iostream>
#include <typeinfo>

#ifndef SASS_CONTEXT
#include "context.hpp"
#endif

namespace Sass {

  Expand::Expand(Context& ctx, Eval* eval, Env* env)
  : ctx(ctx),
    eval(eval),
    env(env),
    block_stack(vector<Block*>()),
    content_stack(vector<Block*>()),
    property_stack(vector<String*>()),
    selector_stack(vector<Selector*>())
  { }

  Statement* Expand::operator()(Block* b)
  {
    Env new_env;
    new_env.link(*env);
    env = &new_env;
    Block* bb = new (ctx.mem) Block(b->path(), b->line(), b->length(), b->is_root());
    block_stack.push_back(bb);
    append_block(b);
    block_stack.pop_back();
    env = env->parent();
    return bb;
  }

  Statement* Expand::operator()(Ruleset* r)
  {
    return new (ctx.mem) Ruleset(r->path(),
                                 r->line(),
                                 r->selector(), // TODO: expand the selector
                                 r->block()->perform(this)->block());
  }

  Statement* Expand::operator()(Propset* p)
  {
    Block* current_block = block_stack.back();
    String_Schema* combined_prop = new (ctx.mem) String_Schema(p->path(), p->line());
    if (!property_stack.empty()) {
      *combined_prop << property_stack.back()
                     << new (ctx.mem) String_Constant(p->path(), p->line(), "-")
                     << p->property_fragment(); // TODO: eval the prop into a string constant
    }
    else {
      *combined_prop << p->property_fragment();
    }
    for (size_t i = 0, S = p->declarations().size(); i < S; ++i) {
      Declaration* dec = static_cast<Declaration*>(p->declarations()[i]->perform(this));
      String_Schema* final_prop = new (ctx.mem) String_Schema(dec->path(), dec->line());
      *final_prop += combined_prop;
      *final_prop << new (ctx.mem) String_Constant(dec->path(), dec->line(), "-");
      *final_prop << dec->property();
      dec->property(final_prop);
      *current_block << dec;
    }
    for (size_t i = 0, S = p->propsets().size(); i < S; ++i) {
      property_stack.push_back(combined_prop);
      p->propsets()[i]->perform(this);
      property_stack.pop_back();
    }
    return p;
  }

  Statement* Expand::operator()(Media_Block* m)
  {
    // TODO -- consider making a new Expander (also eval the media queries)
    return new (ctx.mem) Media_Block(m->path(),
                                     m->line(),
                                     m->media_queries(),
                                     m->block()->perform(this)->block());
  }

  Statement* Expand::operator()(At_Rule* a)
  {
    Block* ab = a->block();
    Block* bb = ab ? ab->perform(this)->block() : 0;<commit_msg>let's not forget to evaluate the media query expressions<commit_after>#include "expand.hpp"
#include "ast.hpp"
#include "bind.hpp"
#include "eval.hpp"

#include <iostream>
#include <typeinfo>

#ifndef SASS_CONTEXT
#include "context.hpp"
#endif

namespace Sass {

  Expand::Expand(Context& ctx, Eval* eval, Env* env)
  : ctx(ctx),
    eval(eval),
    env(env),
    block_stack(vector<Block*>()),
    content_stack(vector<Block*>()),
    property_stack(vector<String*>()),
    selector_stack(vector<Selector*>())
  { }

  Statement* Expand::operator()(Block* b)
  {
    Env new_env;
    new_env.link(*env);
    env = &new_env;
    Block* bb = new (ctx.mem) Block(b->path(), b->line(), b->length(), b->is_root());
    block_stack.push_back(bb);
    append_block(b);
    block_stack.pop_back();
    env = env->parent();
    return bb;
  }

  Statement* Expand::operator()(Ruleset* r)
  {
    return new (ctx.mem) Ruleset(r->path(),
                                 r->line(),
                                 r->selector(), // TODO: expand the selector
                                 r->block()->perform(this)->block());
  }

  Statement* Expand::operator()(Propset* p)
  {
    Block* current_block = block_stack.back();
    String_Schema* combined_prop = new (ctx.mem) String_Schema(p->path(), p->line());
    if (!property_stack.empty()) {
      *combined_prop << property_stack.back()
                     << new (ctx.mem) String_Constant(p->path(), p->line(), "-")
                     << p->property_fragment(); // TODO: eval the prop into a string constant
    }
    else {
      *combined_prop << p->property_fragment();
    }
    for (size_t i = 0, S = p->declarations().size(); i < S; ++i) {
      Declaration* dec = static_cast<Declaration*>(p->declarations()[i]->perform(this));
      String_Schema* final_prop = new (ctx.mem) String_Schema(dec->path(), dec->line());
      *final_prop += combined_prop;
      *final_prop << new (ctx.mem) String_Constant(dec->path(), dec->line(), "-");
      *final_prop << dec->property();
      dec->property(final_prop);
      *current_block << dec;
    }
    for (size_t i = 0, S = p->propsets().size(); i < S; ++i) {
      property_stack.push_back(combined_prop);
      p->propsets()[i]->perform(this);
      property_stack.pop_back();
    }
    return p;
  }

  Statement* Expand::operator()(Media_Block* m)
  {
    Expression* media_queries = m->media_queries()->perform(eval->with(env));
    return new (ctx.mem) Media_Block(m->path(),
                                     m->line(),
                                     static_cast<List*>(media_queries),
                                     m->block()->perform(this)->block());
  }

  Statement* Expand::operator()(At_Rule* a)
  {
    Block* ab = a->block();
    Block* bb = ab ? ab->perform(this)->block() : 0;
{'fraction_non_alphanumeric': 0.17977729885057472, 'fraction_numerical': 0.0010775862068965517, 'mean_word_length': 2.5336294416243654, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 96, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7609357', 'n_tokens_mistral': 1801, 'n_tokens_neox': 1760, 'n_words': 353}