Sha256: a2cc191728d35f7f98d89d9d2f34ee782873a77f75167fd476f1f5b7c8ec5f45

Contents?: true

Size: 1.57 KB

Versions: 8

Compression:

Stored size: 1.57 KB

Contents

#define SASS_BACKTRACE

#include <sstream>

#ifndef SASS_POSITION
#include "position.hpp"
#endif

#ifndef SASS_FILE
#include "file.hpp"
#endif

namespace Sass {

  using namespace std;

  struct Backtrace {

    Backtrace* parent;
    string     path;
    Position   position;
    string     caller;

    Backtrace(Backtrace* prn, string pth, Position position, string c)
    : parent(prn),
      path(pth),
      position(position),
      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->path, cwd, cwd));

        if (warning) {
          ss << endl
             << "\t"
             << (++i == 0 ? "on" : "from")
             << " line "
             << this_point->position.line
             << " of "
             << rel_path;
        } else {
          ss << endl
             << "\t"
             << rel_path
             << ":"
             << this_point->position.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;
    }

  };

}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sassc-0.0.9 ext/libsass/backtrace.hpp
sassc-0.0.8 ext/libsass/backtrace.hpp
sassc-0.0.7 ext/libsass/backtrace.hpp
sassc-0.0.6 ext/libsass/backtrace.hpp
sassc-0.0.5 ext/libsass/backtrace.hpp
sassc-0.0.4 ext/libsass/backtrace.hpp
sassc-0.0.2 ext/libsass/backtrace.hpp
sassc-0.0.1 ext/libsass/backtrace.hpp