Sha256: 9c92b87ee66a1e6b829fc71a29e37136d062cb925b8254f29451fbdac7af864c

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

#ifndef SASS_BACKTRACE_H
#define SASS_BACKTRACE_H

#include <sstream>

#include "file.hpp"
#include "position.hpp"

namespace Sass {

  using namespace std;

  struct Backtrace {

    Backtrace*  parent;
    ParserState pstate;
    string      caller;

    Backtrace(Backtrace* prn, ParserState pstate, string c)
    : parent(prn),
      pstate(pstate),
      caller(c)
    { }

    string to_string(bool warning = false)
    {
      size_t i = -1;
      stringstream ss;
      string cwd(Sass::File::get_cwd());
      Backtrace* this_point = this;

      if (!warning) ss << endl << "Backtrace:";
      // the first tracepoint (which is parent-less) is an empty placeholder
      while (this_point->parent) {

        // make path relative to the current directory
        string rel_path(Sass::File::resolve_relative_path(this_point->pstate.path, cwd, cwd));

        if (warning) {
          ss << endl
             << "\t"
             << (++i == 0 ? "on" : "from")
             << " line "
             << this_point->pstate.line
             << " of "
             << rel_path;
        } else {
          ss << endl
             << "\t"
             << rel_path
             << ":"
             << this_point->pstate.line
             << this_point->parent->caller;
        }

        this_point = this_point->parent;
      }

      return ss.str();
    }

    size_t depth()
    {
      size_t d = 0;
      Backtrace* p = parent;
      while (p) {
        ++d;
        p = p->parent;
      }
      return d-1;
    }

  };

}

#endif

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sassc-0.0.10 ext/libsass/backtrace.hpp