Initial commit
[yaffs-website] / node_modules / node-sass / src / libsass / src / error_handling.hpp
1 #ifndef SASS_ERROR_HANDLING_H
2 #define SASS_ERROR_HANDLING_H
3
4 #include <string>
5 #include <sstream>
6 #include <stdexcept>
7 #include "position.hpp"
8
9 namespace Sass {
10
11   struct Backtrace;
12
13   namespace Exception {
14
15     const std::string def_msg = "Invalid sass detected";
16     const std::string def_op_msg = "Undefined operation";
17     const std::string def_op_null_msg = "Invalid null operation";
18
19     class Base : public std::runtime_error {
20       protected:
21         std::string msg;
22         std::string prefix;
23       public:
24         ParserState pstate;
25         std::vector<Sass_Import_Entry>* import_stack;
26       public:
27         Base(ParserState pstate, std::string msg = def_msg, std::vector<Sass_Import_Entry>* import_stack = 0);
28         virtual const char* errtype() const { return prefix.c_str(); }
29         virtual const char* what() const throw() { return msg.c_str(); }
30         virtual ~Base() throw() {};
31     };
32
33     class InvalidSass : public Base {
34       public:
35         InvalidSass(ParserState pstate, std::string msg);
36         virtual ~InvalidSass() throw() {};
37     };
38
39     class InvalidParent : public Base {
40       protected:
41         Selector_Ptr parent;
42         Selector_Ptr selector;
43       public:
44         InvalidParent(Selector_Ptr parent, Selector_Ptr selector);
45         virtual ~InvalidParent() throw() {};
46     };
47
48     class MissingArgument : public Base {
49       protected:
50         std::string fn;
51         std::string arg;
52         std::string fntype;
53       public:
54         MissingArgument(ParserState pstate, std::string fn, std::string arg, std::string fntype);
55         virtual ~MissingArgument() throw() {};
56     };
57
58     class InvalidArgumentType : public Base {
59       protected:
60         std::string fn;
61         std::string arg;
62         std::string type;
63         const Value_Ptr value;
64       public:
65         InvalidArgumentType(ParserState pstate, std::string fn, std::string arg, std::string type, const Value_Ptr value = 0);
66         virtual ~InvalidArgumentType() throw() {};
67     };
68
69     class InvalidSyntax : public Base {
70       public:
71         InvalidSyntax(ParserState pstate, std::string msg, std::vector<Sass_Import_Entry>* import_stack = 0);
72         virtual ~InvalidSyntax() throw() {};
73     };
74
75     /* common virtual base class (has no pstate) */
76     class OperationError : public std::runtime_error {
77       protected:
78         std::string msg;
79       public:
80         OperationError(std::string msg = def_op_msg)
81         : std::runtime_error(msg), msg(msg)
82         {};
83       public:
84         virtual const char* errtype() const { return "Error"; }
85         virtual const char* what() const throw() { return msg.c_str(); }
86         virtual ~OperationError() throw() {};
87     };
88
89     class ZeroDivisionError : public OperationError {
90       protected:
91         const Expression& lhs;
92         const Expression& rhs;
93       public:
94         ZeroDivisionError(const Expression& lhs, const Expression& rhs);
95         virtual const char* errtype() const { return "ZeroDivisionError"; }
96         virtual ~ZeroDivisionError() throw() {};
97     };
98
99     class DuplicateKeyError : public Base {
100       protected:
101         const Map& dup;
102         const Expression& org;
103       public:
104         DuplicateKeyError(const Map& dup, const Expression& org);
105         virtual const char* errtype() const { return "Error"; }
106         virtual ~DuplicateKeyError() throw() {};
107     };
108
109     class TypeMismatch : public Base {
110       protected:
111         const Expression& var;
112         const std::string type;
113       public:
114         TypeMismatch(const Expression& var, const std::string type);
115         virtual const char* errtype() const { return "Error"; }
116         virtual ~TypeMismatch() throw() {};
117     };
118
119     class InvalidValue : public Base {
120       protected:
121         const Expression& val;
122       public:
123         InvalidValue(const Expression& val);
124         virtual const char* errtype() const { return "Error"; }
125         virtual ~InvalidValue() throw() {};
126     };
127
128     class StackError : public Base {
129       protected:
130         const AST_Node& node;
131       public:
132         StackError(const AST_Node& node);
133         virtual const char* errtype() const { return "SystemStackError"; }
134         virtual ~StackError() throw() {};
135     };
136
137     class IncompatibleUnits : public OperationError {
138       protected:
139         const Number& lhs;
140         const Number& rhs;
141       public:
142         IncompatibleUnits(const Number& lhs, const Number& rhs);
143         virtual ~IncompatibleUnits() throw() {};
144     };
145
146     class UndefinedOperation : public OperationError {
147       protected:
148         Expression_Ptr_Const lhs;
149         Expression_Ptr_Const rhs;
150         const std::string op;
151       public:
152         UndefinedOperation(Expression_Ptr_Const lhs, Expression_Ptr_Const rhs, const std::string& op);
153         // virtual const char* errtype() const { return "Error"; }
154         virtual ~UndefinedOperation() throw() {};
155     };
156
157     class InvalidNullOperation : public UndefinedOperation {
158       public:
159         InvalidNullOperation(Expression_Ptr_Const lhs, Expression_Ptr_Const rhs, const std::string& op);
160         virtual ~InvalidNullOperation() throw() {};
161     };
162
163     class AlphaChannelsNotEqual : public OperationError {
164       protected:
165         Expression_Ptr_Const lhs;
166         Expression_Ptr_Const rhs;
167         const std::string op;
168       public:
169         AlphaChannelsNotEqual(Expression_Ptr_Const lhs, Expression_Ptr_Const rhs, const std::string& op);
170         // virtual const char* errtype() const { return "Error"; }
171         virtual ~AlphaChannelsNotEqual() throw() {};
172     };
173
174     class SassValueError : public Base {
175       public:
176         SassValueError(ParserState pstate, OperationError& err);
177         virtual ~SassValueError() throw() {};
178     };
179
180   }
181
182   void warn(std::string msg, ParserState pstate);
183   void warn(std::string msg, ParserState pstate, Backtrace* bt);
184
185   void deprecated_function(std::string msg, ParserState pstate);
186   void deprecated(std::string msg, std::string msg2, ParserState pstate);
187   void deprecated_bind(std::string msg, ParserState pstate);
188   // void deprecated(std::string msg, ParserState pstate, Backtrace* bt);
189
190   void error(std::string msg, ParserState pstate);
191   void error(std::string msg, ParserState pstate, Backtrace* bt);
192
193 }
194
195 #endif