Initial commit
[yaffs-website] / node_modules / node-sass / src / libsass / src / backtrace.hpp
1 #ifndef SASS_BACKTRACE_H
2 #define SASS_BACKTRACE_H
3
4 #include <sstream>
5
6 #include "file.hpp"
7 #include "position.hpp"
8
9 namespace Sass {
10
11
12   struct Backtrace {
13
14     Backtrace*  parent;
15     ParserState pstate;
16     std::string      caller;
17
18     Backtrace(Backtrace* prn, ParserState pstate, std::string c)
19     : parent(prn),
20       pstate(pstate),
21       caller(c)
22     { }
23
24     const std::string to_string(bool warning = false)
25     {
26       size_t i = -1;
27       std::stringstream ss;
28       std::string cwd(Sass::File::get_cwd());
29       Backtrace* this_point = this;
30
31       if (!warning) ss << std::endl << "Backtrace:";
32       // the first tracepoint (which is parent-less) is an empty placeholder
33       while (this_point->parent) {
34
35         // make path relative to the current directory
36         std::string rel_path(Sass::File::abs2rel(this_point->pstate.path, cwd, cwd));
37
38         if (warning) {
39           ss << std::endl
40              << "\t"
41              << (++i == 0 ? "on" : "from")
42              << " line "
43              << this_point->pstate.line + 1
44              << " of "
45              << rel_path;
46         } else {
47           ss << std::endl
48              << "\t"
49              << rel_path
50              << ":"
51              << this_point->pstate.line + 1
52              << this_point->parent->caller;
53         }
54
55         this_point = this_point->parent;
56       }
57
58       return ss.str();
59     }
60
61     size_t depth()
62     {
63       size_t d = 0;
64       Backtrace* p = parent;
65       while (p) {
66         ++d;
67         p = p->parent;
68       }
69       return d-1;
70     }
71
72   };
73
74 }
75
76 #endif