-
Notifications
You must be signed in to change notification settings - Fork 464
/
context.hpp
140 lines (113 loc) · 4.71 KB
/
context.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#ifndef SASS_CONTEXT_H
#define SASS_CONTEXT_H
// sass.hpp must go before all system headers to get the
// __EXTENSIONS__ fix on Solaris.
#include "sass.hpp"
#include "ast.hpp"
#define BUFFERSIZE 255
#include "b64/encode.h"
#include "sass_context.hpp"
#include "stylesheet.hpp"
#include "plugins.hpp"
#include "output.hpp"
namespace Sass {
class Context {
public:
void import_url (Import* imp, std::string load_path, const std::string& ctx_path);
bool call_headers(const std::string& load_path, const char* ctx_path, ParserState& pstate, Import* imp)
{ return call_loader(load_path, ctx_path, pstate, imp, c_headers, false); };
bool call_importers(const std::string& load_path, const char* ctx_path, ParserState& pstate, Import* imp)
{ return call_loader(load_path, ctx_path, pstate, imp, c_importers, true); };
private:
bool call_loader(const std::string& load_path, const char* ctx_path, ParserState& pstate, Import* imp, std::vector<Sass_Importer_Entry> importers, bool only_one = true);
public:
const std::string CWD;
struct Sass_Options& c_options;
std::string entry_path;
size_t head_imports;
Plugins plugins;
Output emitter;
// generic ast node garbage container
// used to avoid possible circular refs
CallStack ast_gc;
// resources add under our control
// these are guaranteed to be freed
std::vector<char*> strings;
std::vector<Resource> resources;
std::map<const std::string, StyleSheet> sheets;
ImporterStack import_stack;
std::vector<Sass_Callee> callee_stack;
std::vector<Backtrace> traces;
Extender extender;
struct Sass_Compiler* c_compiler;
// absolute paths to includes
std::vector<std::string> included_files;
// relative includes for sourcemap
std::vector<std::string> srcmap_links;
// vectors above have same size
std::vector<std::string> plugin_paths; // relative paths to load plugins
std::vector<std::string> include_paths; // lookup paths for includes
void apply_custom_headers(Block_Obj root, const char* path, ParserState pstate);
std::vector<Sass_Importer_Entry> c_headers;
std::vector<Sass_Importer_Entry> c_importers;
std::vector<Sass_Function_Entry> c_functions;
void add_c_header(Sass_Importer_Entry header);
void add_c_importer(Sass_Importer_Entry importer);
void add_c_function(Sass_Function_Entry function);
const std::string indent; // String to be used for indentation
const std::string linefeed; // String to be used for line feeds
const std::string input_path; // for relative paths in src-map
const std::string output_path; // for relative paths to the output
const std::string source_map_file; // path to source map file (enables feature)
const std::string source_map_root; // path for sourceRoot property (pass-through)
virtual ~Context();
Context(struct Sass_Context&);
virtual Block_Obj parse() = 0;
virtual Block_Obj compile();
virtual char* render(Block_Obj root);
virtual char* render_srcmap();
void register_resource(const Include&, const Resource&);
void register_resource(const Include&, const Resource&, ParserState&);
std::vector<Include> find_includes(const Importer& import);
Include load_import(const Importer&, ParserState pstate);
Sass_Output_Style output_style() { return c_options.output_style; };
std::vector<std::string> get_included_files(bool skip = false, size_t headers = 0);
private:
void collect_plugin_paths(const char* paths_str);
void collect_plugin_paths(string_list* paths_array);
void collect_include_paths(const char* paths_str);
void collect_include_paths(string_list* paths_array);
std::string format_embedded_source_map();
std::string format_source_mapping_url(const std::string& out_path);
// void register_built_in_functions(Env* env);
// void register_function(Signature sig, Native_Function f, Env* env);
// void register_function(Signature sig, Native_Function f, size_t arity, Env* env);
// void register_overload_stub(std::string name, Env* env);
public:
const std::string& cwd() { return CWD; };
};
class File_Context : public Context {
public:
File_Context(struct Sass_File_Context& ctx)
: Context(ctx)
{ }
virtual ~File_Context();
virtual Block_Obj parse();
};
class Data_Context : public Context {
public:
char* source_c_str;
char* srcmap_c_str;
Data_Context(struct Sass_Data_Context& ctx)
: Context(ctx)
{
source_c_str = ctx.source_string;
srcmap_c_str = ctx.srcmap_string;
ctx.source_string = 0; // passed away
ctx.srcmap_string = 0; // passed away
}
virtual ~Data_Context();
virtual Block_Obj parse();
};
}
#endif