Skip to content

Commit c998001

Browse files
committed
Refining C-API and more streamlining
1 parent 173014e commit c998001

File tree

156 files changed

+3135
-2918
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+3135
-2918
lines changed

Makefile.conf

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
INCFILES = \
88
sass.h \
99
sass/base.h \
10-
sass/compiler.h \
11-
sass/context.h \
1210
sass/enums.h \
1311
sass/error.h \
14-
sass/function.h \
1512
sass/fwdecl.h \
1613
sass/import.h \
17-
sass/lists.h \
14+
sass/importer.h \
15+
sass/function.h \
16+
sass/compiler.h \
17+
sass/variable.h \
1818
sass/traces.h \
1919
sass/values.h \
2020
sass/version.h
@@ -42,13 +42,13 @@ HPPFILES = \
4242
charcode.hpp \
4343
color_maps.hpp \
4444
constants.hpp \
45-
context.hpp \
4645
cssize.hpp \
4746
dart_helpers.hpp \
4847
debugger.hpp \
4948
emitter.hpp \
5049
environment.hpp \
5150
exceptions.hpp \
51+
settings.hpp \
5252
memory.hpp \
5353
memory/config.hpp \
5454
memory/allocator.hpp \
@@ -74,7 +74,6 @@ HPPFILES = \
7474
interpolation.hpp \
7575
logger.hpp \
7676
json.hpp \
77-
kwd_arg_macros.hpp \
7877
randomize.hpp \
7978
mapping.hpp \
8079
ordered_map.hpp \
@@ -97,12 +96,13 @@ HPPFILES = \
9796
offset.hpp \
9897
remove_placeholders.hpp \
9998
capi_sass.hpp \
100-
capi_base.hpp \
101-
capi_list.hpp \
10299
capi_error.hpp \
103-
capi_context.hpp \
100+
capi_traces.hpp \
101+
capi_import.hpp \
102+
capi_importer.hpp \
104103
capi_compiler.hpp \
105-
capi_functions.hpp \
104+
capi_variable.hpp \
105+
capi_function.hpp \
106106
capi_values.hpp \
107107
scanner_string.hpp \
108108
source_map.hpp \
@@ -112,7 +112,7 @@ HPPFILES = \
112112
preloader.hpp \
113113
units.hpp \
114114
unicode.hpp \
115-
util_string.hpp \
115+
hashing.hpp \
116116
visitor_css.hpp \
117117
visitor_expression.hpp \
118118
visitor_selector.hpp \
@@ -122,7 +122,9 @@ HPPFILES = \
122122
callstack.hpp \
123123
environment_cnt.hpp \
124124
environment_key.hpp \
125-
environment_stack.hpp
125+
environment_stack.hpp \
126+
b64/cencode.hpp \
127+
b64/encode.hpp
126128

127129
SOURCES = \
128130
ast.cpp \
@@ -139,7 +141,6 @@ SOURCES = \
139141
ast_sel_weave.cpp \
140142
ast_selectors.cpp \
141143
modules.cpp \
142-
context.cpp \
143144
constants.cpp \
144145
compiler.cpp \
145146
fn_meta.cpp \
@@ -153,7 +154,6 @@ SOURCES = \
153154
environment.cpp \
154155
ast_fwd_decl.cpp \
155156
file.cpp \
156-
util_string.cpp \
157157
string_utils.cpp \
158158
logger.cpp \
159159
strings.cpp \
@@ -188,13 +188,14 @@ SOURCES = \
188188
scanner_string.cpp \
189189
remove_placeholders.cpp \
190190
capi_sass.cpp \
191-
capi_base.cpp \
192-
capi_lists.cpp \
193191
capi_error.cpp \
194-
capi_values.cpp \
195-
capi_context.cpp \
192+
capi_traces.cpp \
193+
capi_import.cpp \
194+
capi_importer.cpp \
196195
capi_compiler.cpp \
197-
capi_functions.cpp \
196+
capi_variable.cpp \
197+
capi_function.cpp \
198+
capi_values.cpp \
198199
character.cpp \
199200
environment_stack.cpp \
200201
source_map.cpp \

include/sass.h

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
11
#ifndef SASS_H
22
#define SASS_H
33

4-
// #define DEBUG 1
5-
64
// Note: we can't forward declare with inheritance
75
// https://stackoverflow.com/a/10145303/1550314
86

97
// include API headers
108
#include <sass/base.h>
9+
#include <sass/enums.h>
1110
#include <sass/fwdecl.h>
1211
#include <sass/version.h>
13-
#include <sass/lists.h>
14-
#include <sass/values.h>
1512
#include <sass/error.h>
16-
#include <sass/import.h>
1713
#include <sass/traces.h>
18-
#include <sass/functions.h>
19-
#include <sass/context.h>
14+
#include <sass/values.h>
15+
#include <sass/import.h>
16+
#include <sass/importer.h>
17+
#include <sass/function.h>
2018
#include <sass/compiler.h>
21-
22-
typedef struct SassImport* Sass_Import_Entry;
23-
typedef struct SassImporter* Sass_Importer_Entry;
24-
typedef struct SassFunction* Sass_Function_Entry;
25-
26-
typedef struct SassImportList* Sass_Import_List;
27-
typedef struct SassImporterList* Sass_Importer_List;
28-
typedef struct SassFunctionList* Sass_Function_List;
19+
#include <sass/variable.h>
2920

3021
#endif

include/sass/base.h

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
#ifndef SASS_C_BASE_H
2-
#define SASS_C_BASE_H
1+
/*****************************************************************************/
2+
/* Part of LibSass, released under the MIT license (See LICENSE.txt). */
3+
/*****************************************************************************/
4+
#ifndef SASS_BASE_H
5+
#define SASS_BASE_H
36

47
#ifdef _MSC_VER
58
#pragma warning(disable : 4503)
@@ -42,7 +45,7 @@
4245

4346
#ifdef _WIN32
4447

45-
/* You should define ADD_EXPORTS *only* when building the DLL. */
48+
/* You should define ADD_EXPORTS *only* when building the DLL. */
4649
#ifdef ADD_EXPORTS
4750
#define ADDAPI __declspec(dllexport)
4851
#define ADDCALL __cdecl
@@ -87,16 +90,6 @@ extern "C" {
8790
ADDAPI void ADDCALL sass_free_memory(void* ptr);
8891
ADDAPI void ADDCALL sass_free_c_string(char* ptr);
8992

90-
// Resolve a file via the given include paths in the sass option struct
91-
// find_file looks for the exact file name while find_include does a regular sass include
92-
// ADDAPI char* ADDCALL sass_find_file (const char* path, struct SassOptionsCpp* opt);
93-
// ADDAPI char* ADDCALL sass_find_include (const char* path, struct SassOptionsCpp* opt);
94-
95-
// Resolve a file relative to last import or include paths in the sass option struct
96-
// find_file looks for the exact file name while find_include does a regular sass include
97-
// ADDAPI char* ADDCALL sass_compiler_find_file(const char* path, struct SassCompiler* compiler);
98-
// ADDAPI char* ADDCALL sass_compiler_find_include(const char* path, struct SassCompiler* compiler);
99-
10093
// Return implemented sass language version
10194
ADDAPI const char* ADDCALL libsass_version(void);
10295

include/sass/compiler.h

Lines changed: 109 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,168 @@
1+
/*****************************************************************************/
2+
/* Part of LibSass, released under the MIT license (See LICENSE.txt). */
3+
/*****************************************************************************/
14
#ifndef SASS_C_COMPILER_H
25
#define SASS_C_COMPILER_H
36

47
#include <sass/base.h>
8+
#include <sass/function.h>
9+
510
#ifdef __cplusplus
611
extern "C" {
712
#endif
813

9-
// Create a new compiler from the libsass context and the given entry point
14+
/////////////////////////////////////////////////////////////////////////
15+
/////////////////////////////////////////////////////////////////////////
16+
17+
// Create a new LibSass compiler context
1018
ADDAPI struct SassCompiler* ADDCALL sass_make_compiler();
1119

12-
// Release all memory allocated with the structures
20+
// Release all memory allocated with the compiler
1321
ADDAPI void ADDCALL sass_delete_compiler(struct SassCompiler* compiler);
1422

15-
// Parse the entry point and potentially all imports within
23+
/////////////////////////////////////////////////////////////////////////
24+
/////////////////////////////////////////////////////////////////////////
25+
26+
// Parse the entry point and potentially all imports within.
1627
ADDAPI void ADDCALL sass_compiler_parse(struct SassCompiler* compiler);
1728

18-
// Evaluate the parsed entry point and store resulting ast-tree
29+
// Evaluate the parsed entry point and store resulting ast-tree.
1930
ADDAPI void ADDCALL sass_compiler_compile(struct SassCompiler* compiler);
2031

21-
// Render the evaluated ast-tree to get the final output string
32+
// Render the evaluated ast-tree to get the final output string.
2233
ADDAPI void ADDCALL sass_compiler_render(struct SassCompiler* compiler);
2334

24-
// Push function for paths (no manipulation support for now)
25-
ADDAPI void ADDCALL sass_compiler_load_plugins(struct SassCompiler* compiler, const char* paths);
35+
/////////////////////////////////////////////////////////////////////////
36+
/////////////////////////////////////////////////////////////////////////
37+
38+
// Add additional include paths where LibSass will look for includes.
39+
// Note: the passed in `paths` can be path separated (`;` on windows, `:` otherwise).
2640
ADDAPI void ADDCALL sass_compiler_add_include_paths(struct SassCompiler* compiler, const char* paths);
41+
42+
// Load dynamic loadable plugins from `paths`. Plugins are only supported on certain OSs and
43+
// are still in experimental state. This will look for `*.dll`, `*.so` or `*.dynlib` files.
44+
// It then tries to load the found libraries and does a few checks to see if the library
45+
// is actually a LibSass plugin. We then call its init hook if the library is compatible.
46+
// Note: the passed in `paths` can be path separated (`;` on windows, `:` otherwise).
47+
ADDAPI void ADDCALL sass_compiler_load_plugins(struct SassCompiler* compiler, const char* paths);
48+
49+
// Add a custom header importer that will always be executed before any other
50+
// compilations takes place. Useful to prepend a shared copyright header or to
51+
// provide global variables or functions. This feature is still in experimental state.
52+
// Note: With the adaption of Sass Modules this might be completely replaced in the future.
2753
ADDAPI void ADDCALL sass_compiler_add_custom_header(struct SassCompiler* compiler, struct SassImporter* header);
54+
55+
// Add a custom importer that will be executed when a sass `@import` rule is found.
56+
// This is useful to e.g. rewrite import locations or to load content from remote.
57+
// For more please check https://github.com/sass/libsass/blob/master/docs/api-importer.md
58+
// Note: The importer will not be called for regular css `@import url()` rules.
2859
ADDAPI void ADDCALL sass_compiler_add_custom_importer(struct SassCompiler* compiler, struct SassImporter* importer);
60+
61+
// Add a custom function that will be executed when the corresponding function call is
62+
// requested from any sass code. This is useful to provide custom functions in your code.
63+
// For more please check https://github.com/sass/libsass/blob/master/docs/api-function.md
2964
ADDAPI void ADDCALL sass_compiler_add_custom_function(struct SassCompiler* compiler, struct SassFunction* function);
3065

31-
// Setters for output and console logging styles
66+
/////////////////////////////////////////////////////////////////////////
67+
/////////////////////////////////////////////////////////////////////////
68+
69+
// Setter for output style (see `enum SassOutputStyle` for possible options).
3270
ADDAPI void ADDCALL sass_compiler_set_output_style(struct SassCompiler* compiler, enum SassOutputStyle output_style);
71+
72+
// Setter for logging style (see `enum SassLoggerStyle` for possible options).
3373
ADDAPI void ADDCALL sass_compiler_set_logger_style(struct SassCompiler* compiler, enum SassLoggerStyle log_style);
3474

35-
// Getters for compiler option values
75+
// Getter for compiler precision (how floating point numbers are truncated).
3676
ADDAPI int ADDCALL sass_compiler_get_precision(struct SassCompiler* compiler);
37-
ADDAPI const char* ADDCALL sass_compiler_get_output_path(struct SassCompiler* compiler);
38-
ADDAPI struct SassImport* ADDCALL sass_compiler_get_entry_point(struct SassCompiler* compiler);
3977

40-
// Setters for compiler option values
78+
// Setter for compiler precision (how floating point numbers are truncated).
4179
ADDAPI void ADDCALL sass_compiler_set_precision(struct SassCompiler* compiler, int precision);
42-
ADDAPI void ADDCALL sass_compiler_set_output_path(struct SassCompiler* compiler, const char* output_path);
80+
81+
// Getter for compiler entry point (which file or data to parse first).
82+
ADDAPI struct SassImport* ADDCALL sass_compiler_get_entry_point(struct SassCompiler* compiler);
83+
84+
// Setter for compiler entry point (which file or data to parse first).
4385
ADDAPI void ADDCALL sass_compiler_set_entry_point(struct SassCompiler* compiler, struct SassImport* import);
4486

45-
// Getter for sass compiler results
87+
// Getter for compiler output path (where to store the result)
88+
// Note: LibSass does not write the file, implementers should write to this path.
89+
ADDAPI const char* ADDCALL sass_compiler_get_output_path(struct SassCompiler* compiler);
90+
91+
// Setter for compiler output path (where to store the result)
92+
// Note: LibSass does not write the file, implementers should write to this path.
93+
ADDAPI void ADDCALL sass_compiler_set_output_path(struct SassCompiler* compiler, const char* output_path);
94+
95+
/////////////////////////////////////////////////////////////////////////
96+
/////////////////////////////////////////////////////////////////////////
97+
98+
// Getter for warnings that occurred during any step.
4699
ADDAPI const char* ADDCALL sass_compiler_get_warn_string(struct SassCompiler* compiler);
100+
101+
// Getter for output after parsing, compilation and rendering.
47102
ADDAPI const char* ADDCALL sass_compiler_get_output_string(struct SassCompiler* compiler);
103+
104+
// Getter for footer string containing optional source-map (embedded or link).
48105
ADDAPI const char* ADDCALL sass_compiler_get_footer_string(struct SassCompiler* compiler);
106+
107+
// Getter for string containing the optional source-mapping.
49108
ADDAPI const char* ADDCALL sass_compiler_get_srcmap_string(struct SassCompiler* compiler);
50109

51-
// Setters for source-map options
110+
/////////////////////////////////////////////////////////////////////////
111+
/////////////////////////////////////////////////////////////////////////
112+
113+
// Setter for source-map mode (how to embed or not embed the source-map).
114+
ADDAPI void ADDCALL sass_compiler_set_srcmap_mode(struct SassCompiler* compiler, enum SassSrcMapMode mode);
115+
116+
// Setter for source-map path (where to store the source-mapping).
117+
// Note: if path is not explicitly given, we will deduct one from input path.
118+
// Note: LibSass does not write the file, implementers should write to this path.
52119
ADDAPI void ADDCALL sass_compiler_set_srcmap_path(struct SassCompiler* compiler, const char* path);
120+
121+
// Setter for source-map root (simply passed to the resulting srcmap info).
122+
// Note: if not given, no root attribute will be added to the srcmap info object.
53123
ADDAPI void ADDCALL sass_compiler_set_srcmap_root(struct SassCompiler* compiler, const char* root);
54-
ADDAPI void ADDCALL sass_compiler_set_srcmap_mode(struct SassCompiler* compiler, enum SassSrcMapMode mode);
124+
125+
// Setter for source-map file-url option (renders urls in srcmap as `file://` urls)
55126
ADDAPI void ADDCALL sass_compiler_set_srcmap_file_urls(struct SassCompiler* compiler, bool enable);
127+
128+
// Setter for source-map embed-contents option (includes full sources in the srcmap info)
56129
ADDAPI void ADDCALL sass_compiler_set_srcmap_embed_contents(struct SassCompiler* compiler, bool enable);
57130

131+
/////////////////////////////////////////////////////////////////////////
132+
/////////////////////////////////////////////////////////////////////////
133+
134+
// Getter to return the number of all included files.
58135
ADDAPI size_t ADDCALL sass_compiler_get_included_files_count(struct SassCompiler* compiler);
136+
137+
// Getter to return path to the included file at position `n`.
59138
ADDAPI const char* ADDCALL sass_compiler_get_included_file_path(struct SassCompiler* compiler, size_t n);
60139

61-
ADDAPI struct SassImport* ADDCALL sass_compiler_get_last_import(struct SassCompiler* compiler);
140+
/////////////////////////////////////////////////////////////////////////
141+
/////////////////////////////////////////////////////////////////////////
62142

63-
#ifdef __cplusplus
64-
} // EO extern "C".
65-
#endif
66-
67-
#ifdef __cplusplus
68-
namespace Sass {
69-
extern "C" {
70-
#endif
143+
// Getter for current import context. Use `SassImport` functions to query the state.
144+
ADDAPI const struct SassImport* ADDCALL sass_compiler_get_last_import(struct SassCompiler* compiler);
71145

72146
// Returns pointer to error object associated with compiler.
73147
// Will be valid until the associated compiler is destroyed.
74148
ADDAPI const struct SassError* ADDCALL sass_compiler_get_error(struct SassCompiler* compiler);
75-
ADDAPI const char* ADDCALL sass_compiler_get_stderr(struct SassCompiler* compiler);
76-
77-
78149

150+
/////////////////////////////////////////////////////////////////////////
151+
/////////////////////////////////////////////////////////////////////////
79152

80-
// ADDAPI void ADDCALL sass_compiler_set_input_path(struct SassCompiler* compiler, const char* input_path);
81-
// ADDAPI void ADDCALL sass_compiler_set_source_map_file(struct SassCompiler* compiler, const char* source_map_file);
82-
// ADDAPI void ADDCALL sass_compiler_set_source_map_root(struct SassCompiler* compiler, const char* source_map_root);
153+
// Resolve a file relative to last import or include paths in the sass option struct.
154+
ADDAPI char* ADDCALL sass_compiler_find_file(const char* path, struct SassCompiler* compiler);
83155

156+
// Resolve an include relative to last import or include paths in the sass option struct.
157+
// This will do a lookup as LibSass would do internally (partials, different extensions).
158+
// ToDo: Check if we should add `includeIndex` option to check for directory index files!?
159+
ADDAPI char* ADDCALL sass_compiler_find_include(const char* path, struct SassCompiler* compiler);
84160

161+
/////////////////////////////////////////////////////////////////////////
162+
/////////////////////////////////////////////////////////////////////////
85163

86164
#ifdef __cplusplus
87165
} // EO extern "C".
88-
} // EO namespace Sass
89166
#endif
90167

91168
#endif

0 commit comments

Comments
 (0)