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

source code of gtk/subprojects/libsass/src/fn_utils.hpp