Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sass
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
楚学文
node-sass
Commits
de3aadc3
Commit
de3aadc3
authored
Sep 04, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Oy, converted all existing built-in functions to use the new-and-improved infrastructure.
parent
863cddce
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
89 deletions
+63
-89
context.cpp
context.cpp
+42
-67
context.hpp
context.hpp
+2
-3
eval_apply.cpp
eval_apply.cpp
+19
-19
functions.cpp
functions.cpp
+0
-0
functions.hpp
functions.hpp
+0
-0
No files found.
context.cpp
View file @
de3aadc3
#include "context.hpp"
#include <cstring>
#include <iostream>
#include <sstream>
#include <unistd.h>
#include "prelexer.hpp"
#include "color_names.hpp"
...
...
@@ -73,27 +74,20 @@ namespace Sass {
}
delete
[]
image_path
;
new_Node
.
free
();
// cerr << "Deallocated " << i << " source string(s)." << endl;
}
inline
void
Context
::
register_function
(
Function_Descriptor
d
,
Primitive
ip
)
inline
void
Context
::
register_function
(
Signature
sig
,
Primitive
ip
)
{
Function
f
(
d
,
ip
,
new_Node
);
// function_env[pair<string, size_t>(f.name, f.parameters.size())] = f;
Function
f
(
const_cast
<
char
*>
(
sig
),
ip
,
*
this
);
function_env
[
f
.
name
]
=
f
;
}
inline
void
Context
::
register_function
(
Function_Descriptor
d
,
Primitive
ip
,
size_t
arity
)
{
Function
f
(
d
,
ip
,
new_Node
);
// function_env[pair<string, size_t>(f.name, arity)] = f;
function_env
[
f
.
name
]
=
f
;
}
inline
void
Context
::
register_function_2
(
const
char
*
sig
,
Primitive_2
ip
)
inline
void
Context
::
register_function
(
Signature
sig
,
Primitive
ip
,
size_t
arity
)
{
Function
f
(
const_cast
<
char
*>
(
sig
),
ip
,
*
this
);
function_env
[
f
.
name
]
=
f
;
std
::
stringstream
stub
;
stub
<<
f
.
name
<<
" "
<<
arity
;
function_env
[
stub
.
str
()]
=
f
;
}
inline
void
Context
::
register_overload_stub
(
string
name
)
...
...
@@ -105,69 +99,50 @@ namespace Sass {
{
using
namespace
Functions
;
register_function_2
(
foo_sig
,
foo
);
// RGB Functions
register_function
(
rgb_
descriptor
,
rgb
);
register_function
(
rgb_
sig
,
rgb
);
register_overload_stub
(
"rgba"
);
register_function
(
rgba_4_descriptor
,
rgba_4
);
register_function
(
rgba_2_descriptor
,
rgba_2
);
register_function
(
red_descriptor
,
red
);
register_function
(
green_descriptor
,
green
);
register_function
(
blue_descriptor
,
blue
);
register_overload_stub
(
"mix"
);
register_function
(
mix_2_descriptor
,
mix_2
);
register_function
(
mix_3_descriptor
,
mix_3
);
register_function
(
rgba_4_sig
,
rgba_4
,
4
);
register_function
(
rgba_2_sig
,
rgba_2
,
2
);
register_function
(
red_sig
,
red
);
register_function
(
green_sig
,
green
);
register_function
(
blue_sig
,
blue
);
register_function
(
mix_sig
,
mix
);
// HSL Functions
register_function
(
hsla_
descriptor
,
hsla
);
register_function
(
hsl_
descriptor
,
hsl
);
register_function
(
adjust_hue_
descriptor
,
adjust_hue
);
register_function
(
invert_
descriptor
,
invert
);
register_function
(
hsla_
sig
,
hsla
);
register_function
(
hsl_
sig
,
hsl
);
register_function
(
adjust_hue_
sig
,
adjust_hue
);
register_function
(
invert_
sig
,
invert
);
// Opacity Functions
register_function
(
alpha_
descriptor
,
alpha
);
register_function
(
opacity_
descriptor
,
alpha
);
register_function
(
opacify_
descriptor
,
opacify
);
register_function
(
fade_in_
descriptor
,
opacify
);
register_function
(
transparentize_
descriptor
,
transparentize
);
register_function
(
fade_out_
descriptor
,
transparentize
);
register_function
(
alpha_
sig
,
alpha
);
register_function
(
opacity_
sig
,
alpha
);
register_function
(
opacify_
sig
,
opacify
);
register_function
(
fade_in_
sig
,
opacify
);
register_function
(
transparentize_
sig
,
transparentize
);
register_function
(
fade_out_
sig
,
transparentize
);
// String Functions
register_function
(
unquote_
descriptor
,
unquote
);
register_function
(
quote_
descriptor
,
quote
);
register_function
(
unquote_
sig
,
unquote
);
register_function
(
quote_
sig
,
quote
);
// Number Functions
register_function
(
percentage_
descriptor
,
percentage
);
register_function
(
round_
descriptor
,
round
);
register_function
(
ceil_
descriptor
,
ceil
);
register_function
(
floor_
descriptor
,
floor
);
register_function
(
abs_
descriptor
,
abs
);
register_function
(
percentage_
sig
,
percentage
);
register_function
(
round_
sig
,
round
);
register_function
(
ceil_
sig
,
ceil
);
register_function
(
floor_
sig
,
floor
);
register_function
(
abs_
sig
,
abs
);
// List Functions
register_function
(
length_descriptor
,
length
);
register_function
(
nth_descriptor
,
nth
);
register_overload_stub
(
"join"
);
register_function
(
join_2_descriptor
,
join_2
);
register_function
(
join_3_descriptor
,
join_3
);
register_overload_stub
(
"append"
);
register_function
(
append_2_descriptor
,
append_2
);
register_function
(
append_3_descriptor
,
append_3
);
register_overload_stub
(
"compact"
);
register_function
(
compact_1_descriptor
,
compact
);
register_function
(
compact_2_descriptor
,
compact
);
register_function
(
compact_3_descriptor
,
compact
);
register_function
(
compact_4_descriptor
,
compact
);
register_function
(
compact_5_descriptor
,
compact
);
register_function
(
compact_6_descriptor
,
compact
);
register_function
(
compact_7_descriptor
,
compact
);
register_function
(
compact_8_descriptor
,
compact
);
register_function
(
compact_9_descriptor
,
compact
);
register_function
(
compact_10_descriptor
,
compact
);
register_function
(
compact_11_descriptor
,
compact
);
register_function
(
compact_12_descriptor
,
compact
);
register_function
(
length_sig
,
length
);
register_function
(
nth_sig
,
nth
);
register_function
(
join_sig
,
join
);
register_function
(
append_sig
,
append
);
register_function
(
compact_sig
,
compact
);
// Introspection Functions
register_function
(
type_of_
descriptor
,
type_of
);
register_function
(
unit_
descriptor
,
unit
);
register_function
(
unitless_
descriptor
,
unitless
);
register_function
(
comparable_
descriptor
,
comparable
);
register_function
(
type_of_
sig
,
type_of
);
register_function
(
unit_
sig
,
unit
);
register_function
(
unitless_
sig
,
unitless
);
register_function
(
comparable_
sig
,
comparable
);
// Boolean Functions
register_function
(
not_
descriptor
,
not_impl
);
register_function
(
if_
descriptor
,
if_impl
);
register_function
(
not_
sig
,
not_impl
);
register_function
(
if_
sig
,
if_impl
);
}
void
Context
::
setup_color_map
()
...
...
context.hpp
View file @
de3aadc3
...
...
@@ -38,9 +38,8 @@ namespace Sass {
Context
(
const
char
*
paths_str
=
0
,
const
char
*
img_path_str
=
0
);
~
Context
();
void
register_function_2
(
const
char
*
sig
,
Primitive_2
ip
);
void
register_function
(
Function_Descriptor
d
,
Primitive
ip
);
void
register_function
(
Function_Descriptor
d
,
Primitive
ip
,
size_t
arity
);
void
register_function
(
Signature
sig
,
Primitive
ip
);
void
register_function
(
Signature
sig
,
Primitive
ip
,
size_t
arity
);
void
register_overload_stub
(
string
name
);
void
register_functions
();
void
setup_color_map
();
...
...
eval_apply.cpp
View file @
de3aadc3
...
...
@@ -706,7 +706,7 @@ namespace Sass {
// primitive function implementation, then return its value.
Node
apply_function
(
const
Function
&
f
,
const
Node
args
,
Node
prefix
,
Environment
&
env
,
map
<
string
,
Function
>&
f_env
,
Node_Factory
&
new_Node
,
Context
&
ctx
)
{
if
(
f
.
primitive
_2
)
{
if
(
f
.
primitive
)
{
// evaluate arguments in the current environment
for
(
size_t
i
=
0
,
S
=
args
.
size
();
i
<
S
;
++
i
)
{
if
(
args
[
i
].
type
()
!=
Node
::
assignment
)
{
...
...
@@ -720,25 +720,25 @@ namespace Sass {
Environment
bindings
;
bindings
.
link
(
env
.
global
?
*
env
.
global
:
env
);
bind_arguments
(
"function "
+
f
.
name
,
f
.
parameters
,
args
,
prefix
,
bindings
,
f_env
,
new_Node
,
ctx
);
return
f
.
primitive_2
(
f
.
parameter_names
,
bindings
,
new_Node
);
}
else
if
(
f
.
primitive
)
{
map
<
Token
,
Node
>
bindings
;
// bind arguments
for
(
size_t
i
=
0
,
j
=
0
,
S
=
args
.
size
();
i
<
S
;
++
i
)
{
if
(
args
[
i
].
type
()
==
Node
::
assignment
)
{
Node
arg
(
args
[
i
]);
Token
name
(
arg
[
0
].
token
());
bindings
[
name
]
=
eval
(
arg
[
1
],
prefix
,
env
,
f_env
,
new_Node
,
ctx
);
}
else
{
// TO DO: ensure (j < f.parameters.size())
bindings
[
f
.
parameters
[
j
].
token
()]
=
eval
(
args
[
i
],
prefix
,
env
,
f_env
,
new_Node
,
ctx
);
++
j
;
}
}
return
f
(
bindings
,
new_Node
);
return
f
.
primitive
(
f
.
parameter_names
,
bindings
,
new_Node
);
}
// else if (f.primitive) {
// map<Token, Node> bindings;
// // bind arguments
// for (size_t i = 0, j = 0, S = args.size(); i < S; ++i) {
// if (args[i].type() == Node::assignment) {
// Node arg(args[i]);
// Token name(arg[0].token());
// bindings[name] = eval(arg[1], prefix, env, f_env, new_Node, ctx);
// }
// else {
// // TO DO: ensure (j < f.parameters.size())
// bindings[f.parameters[j].token()] = eval(args[i], prefix, env, f_env, new_Node, ctx);
// ++j;
// }
// }
// return f(bindings, new_Node);
// }
else
{
Node
params
(
f
.
definition
[
1
]);
Node
body
(
new_Node
(
f
.
definition
[
2
]));
...
...
functions.cpp
View file @
de3aadc3
This diff is collapsed.
Click to expand it.
functions.hpp
View file @
de3aadc3
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment