-
Notifications
You must be signed in to change notification settings - Fork 464
/
Copy pathfn_utils.hpp
62 lines (49 loc) · 2.49 KB
/
fn_utils.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef SASS_FN_UTILS_H
#define SASS_FN_UTILS_H
// sass.hpp must go before all system headers to get the
// __EXTENSIONS__ fix on Solaris.
#include "sass.hpp"
#include "units.hpp"
#include "backtrace.hpp"
#include "environment.hpp"
#include "ast_fwd_decl.hpp"
#include "error_handling.hpp"
namespace Sass {
#define FN_PROTOTYPE \
Env& env, \
Env& d_env, \
Context& ctx, \
Signature sig, \
ParserState pstate, \
Backtraces& traces, \
SelectorStack selector_stack, \
SelectorStack original_stack \
typedef const char* Signature;
typedef PreValue* (*Native_Function)(FN_PROTOTYPE);
#define BUILT_IN(name) PreValue* name(FN_PROTOTYPE)
#define ARG(argname, argtype) get_arg<argtype>(argname, env, sig, pstate, traces)
// special function for weird hsla percent (10px == 10% == 10 != 0.1)
#define ARGVAL(argname) get_arg_val(argname, env, sig, pstate, traces) // double
Definition* make_native_function(Signature, Native_Function, Context& ctx);
Definition* make_c_function(Sass_Function_Entry c_func, Context& ctx);
namespace Functions {
template <typename T>
T* get_arg(const std::string& argname, Env& env, Signature sig, ParserState pstate, Backtraces traces)
{
T* val = Cast<T>(env[argname]);
if (!val) {
error("argument `" + argname + "` of `" + sig + "` must be a " + T::type_name(), pstate, traces);
}
return val;
}
Map* get_arg_m(const std::string& argname, Env& env, Signature sig, ParserState pstate, Backtraces traces); // maps only
Number* get_arg_n(const std::string& argname, Env& env, Signature sig, ParserState pstate, Backtraces traces); // numbers only
double alpha_num(const std::string& argname, Env& env, Signature sig, ParserState pstate, Backtraces traces); // colors only
double color_num(const std::string& argname, Env& env, Signature sig, ParserState pstate, Backtraces traces); // colors only
double get_arg_r(const std::string& argname, Env& env, Signature sig, ParserState pstate, Backtraces traces, double lo, double hi); // colors only
double get_arg_val(const std::string& argname, Env& env, Signature sig, ParserState pstate, Backtraces traces); // shared
SelectorListObj get_arg_sels(const std::string& argname, Env& env, Signature sig, ParserState pstate, Backtraces traces, Context& ctx); // selectors only
CompoundSelectorObj get_arg_sel(const std::string& argname, Env& env, Signature sig, ParserState pstate, Backtraces traces, Context& ctx); // selectors only
}
}
#endif