@@ -18,7 +18,7 @@ namespace Sass {
1818 // ///////////////////////////////////////////////////////////////////////
1919
2020 typedef Value* (*SassFnSig)(FN_PROTOTYPE2);
21- typedef std::pair<ArgumentDeclarationObj , SassFnSig> SassFnPair;
21+ typedef std::pair<CallableSignatureObj , SassFnSig> SassFnPair;
2222 typedef sass::vector<SassFnPair> SassFnPairs;
2323
2424 // ///////////////////////////////////////////////////////////////////////
@@ -31,10 +31,13 @@ namespace Sass {
3131 // Value constructor
3232 Callable (const SourceSpan& pstate);
3333
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;
3639
37- // Return the function name
40+ // Return name of this callable/function
3841 virtual const sass::string& name () const = 0;
3942
4043 // Equality comparator (needed for `get-function` value)
@@ -72,9 +75,10 @@ namespace Sass {
7275 };
7376
7477 // ////////////////////////////////////////////////////////////////////
78+ // Object for the function signature holding which parameters a
79+ // callable can have or expects and to which variable it's assigned.
7580 // ////////////////////////////////////////////////////////////////////
76-
77- class ArgumentDeclaration final : public AstNode
81+ class CallableSignature final : public AstNode
7882 {
7983 private:
8084
@@ -91,18 +95,18 @@ namespace Sass {
9195 public:
9296
9397 // Value constructor
94- ArgumentDeclaration (SourceSpan&& pstate,
98+ CallableSignature (SourceSpan&& pstate,
9599 sass::vector<ArgumentObj>&& arguments = {},
96100 EnvKey&& restArg = {});
97101
98- // Check if signature is void
102+ // Checks if signature is void
99103 bool isEmpty () const {
100104 return arguments_.empty ()
101105 && restArg_.empty ();
102106 }
103107
104- // Parse source into arguments
105- static ArgumentDeclaration * parse (
108+ // Parse ` source` into signature
109+ static CallableSignature * parse (
106110 Compiler& context, SourceData* source);
107111
108112 // Throws a [SassScriptException] if [positional] and
@@ -120,19 +124,23 @@ namespace Sass {
120124 };
121125
122126 // ///////////////////////////////////////////////////////////////////////
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).
123130 // ///////////////////////////////////////////////////////////////////////
124-
125- class ArgumentInvocation final : public AstNode
131+ class CallableArguments final : public AstNode
126132 {
127133 private:
128134
129135 // The arguments passed by position.
130136 ADD_REF (ExpressionVector, positional);
131137
132- // The argument expressions passed by name.
138+ // The arguments passed by name.
133139 ADD_REF (ExpressionFlatMap, named);
134140
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.
136144 ADD_CONSTREF (ExpressionObj, restArg);
137145
138146 // The second rest argument, which is expected to only contain a keyword map.
@@ -142,15 +150,15 @@ namespace Sass {
142150
143151 public:
144152
145- // Value constructor
146- ArgumentInvocation ( const SourceSpan& pstate,
153+ // Value move constructor
154+ CallableArguments ( SourceSpan& & pstate,
147155 ExpressionVector&& positional,
148156 ExpressionFlatMap&& named,
149157 Expression* restArgs = nullptr ,
150158 Expression* kwdRest = nullptr );
151159
152- // Value constructor
153- ArgumentInvocation ( SourceSpan& & pstate,
160+ // Partial value move constructor
161+ CallableArguments ( const SourceSpan& pstate,
154162 ExpressionVector&& positional,
155163 ExpressionFlatMap&& named,
156164 Expression* restArgs = nullptr ,
@@ -163,8 +171,10 @@ namespace Sass {
163171
164172 // ///////////////////////////////////////////////////////////////////////
165173 // 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.
166177 // ///////////////////////////////////////////////////////////////////////
167-
168178 class ArgumentResults final {
169179
170180 // Arguments passed by position.
@@ -173,10 +183,10 @@ namespace Sass {
173183 // Arguments passed by name.
174184 // A list implementation is often more efficient
175185 // 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
177187 ADD_REF (ValueFlatMap, named);
178188
179- // The separator used for the rest argument list, if any.
189+ // Separator used for rest argument list, if any.
180190 ADD_REF (SassSeparator, separator);
181191
182192 public:
@@ -211,27 +221,6 @@ namespace Sass {
211221 // ///////////////////////////////////////////////////////////////////////
212222 // ///////////////////////////////////////////////////////////////////////
213223
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-
235224}
236225
237226#endif
0 commit comments