@@ -50,18 +50,25 @@ namespace Sass {
50
50
this ->source = source;
51
51
}
52
52
53
+ inline bool sort_importers (const Sass_Importer_Entry& i, const Sass_Importer_Entry& j)
54
+ { return sass_importer_get_priority (i) > sass_importer_get_priority (j); }
53
55
54
56
Context::Context (Context::Data initializers)
55
57
: // Output(this),
58
+ head_imports (0 ),
56
59
mem (Memory_Manager<AST_Node>()),
60
+ c_options (initializers.c_options()),
61
+ c_compiler (initializers.c_compiler()),
57
62
source_c_str (initializers.source_c_str()),
58
63
sources (vector<const char *>()),
59
64
plugin_paths (initializers.plugin_paths()),
60
65
include_paths (initializers.include_paths()),
61
66
queue (vector<Sass_Queued>()),
62
67
style_sheets (map<string, Block*>()),
63
68
emitter (this ),
64
- c_functions (vector<Sass_C_Function_Callback>()),
69
+ c_headers (vector<Sass_Importer_Entry>()),
70
+ c_importers (vector<Sass_Importer_Entry>()),
71
+ c_functions (vector<Sass_Function_Entry>()),
65
72
indent (initializers.indent()),
66
73
linefeed (initializers.linefeed()),
67
74
input_path (make_canonical_path(initializers.input_path())),
@@ -74,7 +81,6 @@ namespace Sass {
74
81
source_map_contents (initializers.source_map_contents()),
75
82
omit_source_map_url (initializers.omit_source_map_url()),
76
83
is_indented_syntax_src (initializers.is_indented_syntax_src()),
77
- importer (initializers.importer()),
78
84
names_to_colors (map<string, Color*>()),
79
85
colors_to_names (map<int , string>()),
80
86
precision (initializers.precision()),
@@ -91,9 +97,9 @@ namespace Sass {
91
97
92
98
include_paths.push_back (cwd);
93
99
collect_include_paths (initializers.include_paths_c_str ());
94
- collect_include_paths (initializers.include_paths_array ());
100
+ // collect_include_paths(initializers.include_paths_array());
95
101
collect_plugin_paths (initializers.plugin_paths_c_str ());
96
- collect_plugin_paths (initializers.plugin_paths_array ());
102
+ // collect_plugin_paths(initializers.plugin_paths_array());
97
103
98
104
setup_color_map ();
99
105
@@ -104,7 +110,15 @@ namespace Sass {
104
110
for (auto fn : plugins.get_functions ()) {
105
111
c_functions.push_back (fn);
106
112
}
113
+ for (auto fn : plugins.get_headers ()) {
114
+ c_headers.push_back (fn);
115
+ }
116
+ for (auto fn : plugins.get_importers ()) {
117
+ c_importers.push_back (fn);
118
+ }
107
119
120
+ sort (c_headers.begin (), c_headers.end (), sort_importers);
121
+ sort (c_importers.begin (), c_importers.end (), sort_importers);
108
122
string entry_point = initializers.entry_point ();
109
123
if (!entry_point.empty ()) {
110
124
string result (add_file (entry_point));
@@ -117,6 +131,23 @@ namespace Sass {
117
131
118
132
}
119
133
134
+ void Context::add_c_function (Sass_Function_Entry function)
135
+ {
136
+ c_functions.push_back (function);
137
+ }
138
+ void Context::add_c_header (Sass_Importer_Entry header)
139
+ {
140
+ c_headers.push_back (header);
141
+ // need to sort the array afterwards (no big deal)
142
+ sort (c_headers.begin (), c_headers.end (), sort_importers);
143
+ }
144
+ void Context::add_c_importer (Sass_Importer_Entry importer)
145
+ {
146
+ c_importers.push_back (importer);
147
+ // need to sort the array afterwards (no big deal)
148
+ sort (c_importers.begin (), c_importers.end (), sort_importers);
149
+ }
150
+
120
151
Context::~Context ()
121
152
{
122
153
// everything that gets put into sources will be freed by us
@@ -225,58 +256,45 @@ namespace Sass {
225
256
include_links.push_back (resolve_relative_path (abs_path, source_map_file, cwd));
226
257
}
227
258
228
- string Context::add_file (string path)
259
+ // Add a new import file to the context
260
+ string Context::add_file (const string& file)
229
261
{
230
262
using namespace File ;
231
- char * contents = 0 ;
232
- string real_path;
233
- path = make_canonical_path (path);
234
- for (size_t i = 0 , S = include_paths.size (); i < S; ++i) {
235
- string full_path (join_paths (include_paths[i], path));
236
- if (style_sheets.count (full_path)) return full_path;
237
- contents = resolve_and_load (full_path, real_path);
238
- if (contents) {
239
- add_source (full_path, real_path, contents);
240
- style_sheets[full_path] = 0 ;
241
- return full_path;
242
- }
263
+ string path (make_canonical_path (file));
264
+ string resolved (find_file (path, include_paths));
265
+ if (resolved == " " ) return resolved;
266
+ if (char * contents = read_file (resolved)) {
267
+ add_source (path, resolved, contents);
268
+ style_sheets[path] = 0 ;
269
+ return path;
243
270
}
244
- return string ();
271
+ return string (" " );
245
272
}
246
273
247
- string Context::add_file (string dir, string rel_filepath)
274
+ // Add a new import file to the context
275
+ // This has some previous directory context
276
+ string Context::add_file (const string& base, const string& file)
248
277
{
249
278
using namespace File ;
250
- char * contents = 0 ;
251
- string real_path;
252
- rel_filepath = make_canonical_path (rel_filepath);
253
- string full_path (join_paths (dir, rel_filepath));
254
- if (style_sheets.count (full_path)) return full_path;
255
- contents = resolve_and_load (full_path, real_path);
256
- if (contents) {
257
- add_source (full_path, real_path, contents);
258
- style_sheets[full_path] = 0 ;
259
- return full_path;
260
- }
261
- for (size_t i = 0 , S = include_paths.size (); i < S; ++i) {
262
- string full_path (join_paths (include_paths[i], rel_filepath));
263
- if (style_sheets.count (full_path)) return full_path;
264
- contents = resolve_and_load (full_path, real_path);
265
- if (contents) {
266
- add_source (full_path, real_path, contents);
267
- style_sheets[full_path] = 0 ;
268
- return full_path;
269
- }
279
+ string path (make_canonical_path (file));
280
+ string base_file (join_paths (base, path));
281
+ string resolved (resolve_file (base_file));
282
+ if (style_sheets.count (base_file)) return base_file;
283
+ if (char * contents = read_file (resolved)) {
284
+ add_source (base_file, resolved, contents);
285
+ style_sheets[base_file] = 0 ;
286
+ return base_file;
270
287
}
271
- return string ();
288
+ // now go the regular code path
289
+ return add_file (path);
272
290
}
273
291
274
292
void register_function (Context&, Signature sig, Native_Function f, Env* env);
275
293
void register_function (Context&, Signature sig, Native_Function f, size_t arity, Env* env);
276
294
void register_overload_stub (Context&, string name, Env* env);
277
295
void register_built_in_functions (Context&, Env* env);
278
- void register_c_functions (Context&, Env* env, Sass_C_Function_List );
279
- void register_c_function (Context&, Env* env, Sass_C_Function_Callback );
296
+ void register_c_functions (Context&, Env* env, Sass_Function_List );
297
+ void register_c_function (Context&, Env* env, Sass_Function_Entry );
280
298
281
299
char * Context::compile_block (Block* root)
282
300
{
@@ -295,7 +313,7 @@ namespace Sass {
295
313
{
296
314
Block* root = 0 ;
297
315
for (size_t i = 0 ; i < queue.size (); ++i) {
298
- struct Sass_Import * import = sass_make_import (
316
+ Sass_Import_Entry import = sass_make_import (
299
317
queue[i].load_path .c_str (),
300
318
queue[i].abs_path .c_str (),
301
319
0 , 0
@@ -388,7 +406,9 @@ namespace Sass {
388
406
std::vector<std::string> Context::get_included_files (size_t skip)
389
407
{
390
408
vector<string> includes = included_files;
409
+ if (includes.size () == 0 ) return includes;
391
410
std::sort ( includes.begin () + skip, includes.end () );
411
+ includes.erase ( includes.begin (), includes.begin () + skip );
392
412
includes.erase ( std::unique ( includes.begin (), includes.end () ), includes.end () );
393
413
// the skip solution seems more robust, as we may have real files named stdin
394
414
// includes.erase( std::remove( includes.begin(), includes.end(), "stdin" ), includes.end() );
@@ -423,6 +443,7 @@ namespace Sass {
423
443
name,
424
444
0 ,
425
445
0 ,
446
+ &ctx,
426
447
true );
427
448
(*env)[name + " [f]" ] = stub;
428
449
}
@@ -521,21 +542,16 @@ namespace Sass {
521
542
register_function (ctx, unique_id_sig, unique_id, env);
522
543
}
523
544
524
- void register_c_functions (Context& ctx, Env* env, Sass_C_Function_List descrs)
545
+ void register_c_functions (Context& ctx, Env* env, Sass_Function_List descrs)
525
546
{
526
547
while (descrs && *descrs) {
527
548
register_c_function (ctx, env, *descrs);
528
549
++descrs;
529
550
}
530
551
}
531
- void register_c_function (Context& ctx, Env* env, Sass_C_Function_Callback descr)
552
+ void register_c_function (Context& ctx, Env* env, Sass_Function_Entry descr)
532
553
{
533
- Definition* def = make_c_function (
534
- sass_function_get_signature (descr),
535
- sass_function_get_function (descr),
536
- sass_function_get_cookie (descr),
537
- ctx
538
- );
554
+ Definition* def = make_c_function (descr, ctx);
539
555
def->environment (env);
540
556
(*env)[def->name () + " [f]" ] = def;
541
557
}
0 commit comments