@@ -18,7 +18,7 @@ namespace Sass {
18
18
// ///////////////////////////////////////////////////////////////////////
19
19
20
20
typedef Value* (*SassFnSig)(FN_PROTOTYPE2);
21
- typedef std::pair<ArgumentDeclarationObj , SassFnSig> SassFnPair;
21
+ typedef std::pair<CallableSignatureObj , SassFnSig> SassFnPair;
22
22
typedef sass::vector<SassFnPair> SassFnPairs;
23
23
24
24
// ///////////////////////////////////////////////////////////////////////
@@ -31,10 +31,13 @@ namespace Sass {
31
31
// Value constructor
32
32
Callable (const SourceSpan& pstate);
33
33
34
- // The main entry point to execute the function (implemented in each specialization)
35
- virtual Value* execute (Eval& eval, ArgumentInvocation* arguments, const SourceSpan& pstate) = 0;
34
+ // The main entry point to execute the function
35
+ // Must be implemented in each specialization
36
+ virtual Value* execute (Eval& eval,
37
+ CallableArguments* arguments,
38
+ const SourceSpan& pstate) = 0;
36
39
37
- // Return the function name
40
+ // Return name of this callable/function
38
41
virtual const sass::string& name () const = 0;
39
42
40
43
// Equality comparator (needed for `get-function` value)
@@ -72,9 +75,10 @@ namespace Sass {
72
75
};
73
76
74
77
// ////////////////////////////////////////////////////////////////////
78
+ // Object for the function signature holding which parameters a
79
+ // callable can have or expects and to which variable it's assigned.
75
80
// ////////////////////////////////////////////////////////////////////
76
-
77
- class ArgumentDeclaration final : public AstNode
81
+ class CallableSignature final : public AstNode
78
82
{
79
83
private:
80
84
@@ -91,18 +95,18 @@ namespace Sass {
91
95
public:
92
96
93
97
// Value constructor
94
- ArgumentDeclaration (SourceSpan&& pstate,
98
+ CallableSignature (SourceSpan&& pstate,
95
99
sass::vector<ArgumentObj>&& arguments = {},
96
100
EnvKey&& restArg = {});
97
101
98
- // Check if signature is void
102
+ // Checks if signature is void
99
103
bool isEmpty () const {
100
104
return arguments_.empty ()
101
105
&& restArg_.empty ();
102
106
}
103
107
104
- // Parse source into arguments
105
- static ArgumentDeclaration * parse (
108
+ // Parse ` source` into signature
109
+ static CallableSignature * parse (
106
110
Compiler& context, SourceData* source);
107
111
108
112
// Throws a [SassScriptException] if [positional] and
@@ -120,19 +124,23 @@ namespace Sass {
120
124
};
121
125
122
126
// ///////////////////////////////////////////////////////////////////////
127
+ // Object for the actual function arguments to pass to the function
128
+ // invocation. It must be valid in regard to the callable signature
129
+ // of the invoked function (will throw an error otherwise).
123
130
// ///////////////////////////////////////////////////////////////////////
124
-
125
- class ArgumentInvocation final : public AstNode
131
+ class CallableArguments final : public AstNode
126
132
{
127
133
private:
128
134
129
135
// The arguments passed by position.
130
136
ADD_REF (ExpressionVector, positional);
131
137
132
- // The argument expressions passed by name.
138
+ // The arguments passed by name.
133
139
ADD_REF (ExpressionFlatMap, named);
134
140
135
- // The first rest argument (as in `$args...`).
141
+ // Optional rest argument (as in `$args...`).
142
+ // Supports only one rest arg and it must be last.
143
+ // ToDo: explain difference between restArg and kwdRest.
136
144
ADD_CONSTREF (ExpressionObj, restArg);
137
145
138
146
// The second rest argument, which is expected to only contain a keyword map.
@@ -142,15 +150,15 @@ namespace Sass {
142
150
143
151
public:
144
152
145
- // Value constructor
146
- ArgumentInvocation ( const SourceSpan& pstate,
153
+ // Value move constructor
154
+ CallableArguments ( SourceSpan& & pstate,
147
155
ExpressionVector&& positional,
148
156
ExpressionFlatMap&& named,
149
157
Expression* restArgs = nullptr ,
150
158
Expression* kwdRest = nullptr );
151
159
152
- // Value constructor
153
- ArgumentInvocation ( SourceSpan& & pstate,
160
+ // Partial value move constructor
161
+ CallableArguments ( const SourceSpan& pstate,
154
162
ExpressionVector&& positional,
155
163
ExpressionFlatMap&& named,
156
164
Expression* restArgs = nullptr ,
@@ -163,8 +171,10 @@ namespace Sass {
163
171
164
172
// ///////////////////////////////////////////////////////////////////////
165
173
// The result of evaluating arguments to a function or mixin.
174
+ // It's basically the same as `CallableArguments` but with all
175
+ // based values already evaluated in order to check compliance
176
+ // with the expected callable signature.
166
177
// ///////////////////////////////////////////////////////////////////////
167
-
168
178
class ArgumentResults final {
169
179
170
180
// Arguments passed by position.
@@ -173,10 +183,10 @@ namespace Sass {
173
183
// Arguments passed by name.
174
184
// A list implementation is often more efficient
175
185
// I don't expect any function to have many arguments
176
- // Normally the trade-off is around 8 items in the list
186
+ // Normally trade-off starts around 8 items in the list
177
187
ADD_REF (ValueFlatMap, named);
178
188
179
- // The separator used for the rest argument list, if any.
189
+ // Separator used for rest argument list, if any.
180
190
ADD_REF (SassSeparator, separator);
181
191
182
192
public:
@@ -211,27 +221,6 @@ namespace Sass {
211
221
// ///////////////////////////////////////////////////////////////////////
212
222
// ///////////////////////////////////////////////////////////////////////
213
223
214
- class CallableInvocation
215
- {
216
-
217
- private:
218
-
219
- // The arguments passed to the callable.
220
- ADD_CONSTREF (ArgumentInvocationObj, arguments);
221
-
222
- public:
223
-
224
- // Value constructor
225
- CallableInvocation (
226
- ArgumentInvocation* arguments) :
227
- arguments_ (arguments)
228
- {}
229
-
230
- };
231
-
232
- // ///////////////////////////////////////////////////////////////////////
233
- // ///////////////////////////////////////////////////////////////////////
234
-
235
224
}
236
225
237
226
#endif
0 commit comments