Skip to content

Commit 1fc743c

Browse files
authored
Merge pull request #2251 from mgreter/feature/c-api-fn-call-stack
C-API: Add call stack queries (functions and mixins)
2 parents 7abaa75 + 5e21d3f commit 1fc743c

28 files changed

+535
-122
lines changed

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ matrix:
3939
- os: osx
4040
env: AUTOTOOLS=no BUILD=static
4141

42-
script: ./script/ci-build-libsass
42+
script:
43+
- ./script/ci-build-libsass
44+
- ./script/ci-build-plugin math
45+
- ./script/ci-build-plugin glob
46+
- ./script/ci-build-plugin digest
47+
- ./script/ci-build-plugin tests
4348
before_install: ./script/ci-install-deps
4449
install: ./script/ci-install-compiler
4550
after_success: ./script/ci-report-coverage

docs/api-context-internal.md

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,35 @@ enum Sass_Input_Style {
77
SASS_CONTEXT_FOLDER
88
};
99

10-
// simple linked list
11-
struct string_list {
12-
string_list* next;
13-
char* string;
14-
};
15-
1610
// sass config options structure
17-
struct Sass_Options {
18-
19-
// Precision for fractional numbers
20-
int precision;
11+
struct Sass_Inspect_Options {
2112

2213
// Output style for the generated css code
2314
// A value from above SASS_STYLE_* constants
2415
enum Sass_Output_Style output_style;
2516

17+
// Precision for fractional numbers
18+
int precision;
19+
20+
};
21+
22+
// sass config options structure
23+
struct Sass_Output_Options : Sass_Inspect_Options {
24+
25+
// String to be used for indentation
26+
const char* indent;
27+
// String to be used to for line feeds
28+
const char* linefeed;
29+
2630
// Emit comments in the generated CSS indicating
2731
// the corresponding source line.
2832
bool source_comments;
2933

34+
};
35+
36+
// sass config options structure
37+
struct Sass_Options : Sass_Output_Options {
38+
3039
// embed sourceMappingUrl as data uri
3140
bool source_map_embed;
3241

@@ -56,15 +65,9 @@ struct Sass_Options {
5665
// information in source-maps etc.
5766
char* output_path;
5867

59-
// String to be used for indentation
60-
const char* indent;
61-
// String to be used to for line feeds
62-
const char* linefeed;
63-
6468
// Colon-separated list of paths
6569
// Semicolon-separated on Windows
66-
// Note: It may be better to use
67-
// array interface instead
70+
// Maybe use array interface instead?
6871
char* include_path;
6972
char* plugin_path;
7073

@@ -82,10 +85,13 @@ struct Sass_Options {
8285
char* source_map_root;
8386

8487
// Custom functions that can be called from sccs code
85-
Sass_C_Function_List c_functions;
88+
Sass_Function_List c_functions;
8689

8790
// Callback to overload imports
88-
Sass_C_Import_Callback importer;
91+
Sass_Importer_List c_importers;
92+
93+
// List of custom headers
94+
Sass_Importer_List c_headers;
8995

9096
};
9197

@@ -111,6 +117,7 @@ struct Sass_Context : Sass_Options
111117
char* error_file;
112118
size_t error_line;
113119
size_t error_column;
120+
const char* error_src;
114121

115122
// report imported files
116123
char** included_files;
@@ -130,6 +137,7 @@ struct Sass_Data_Context : Sass_Context {
130137

131138
// provided source string
132139
char* source_string;
140+
char* srcmap_string;
133141

134142
};
135143

@@ -147,9 +155,9 @@ struct Sass_Compiler {
147155
// original c context
148156
Sass_Context* c_ctx;
149157
// Sass::Context
150-
void* cpp_ctx;
158+
Sass::Context* cpp_ctx;
151159
// Sass::Block
152-
void* root;
160+
Sass::Block_Obj root;
153161
};
154162
```
155163

docs/api-context.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,22 @@ size_t sass_context_get_error_column (struct Sass_Context* ctx);
207207
const char* sass_context_get_source_map_string (struct Sass_Context* ctx);
208208
char** sass_context_get_included_files (struct Sass_Context* ctx);
209209

210+
// Getters for Sass_Compiler options (query import stack)
211+
size_t sass_compiler_get_import_stack_size(struct Sass_Compiler* compiler);
212+
Sass_Import_Entry sass_compiler_get_last_import(struct Sass_Compiler* compiler);
213+
Sass_Import_Entry sass_compiler_get_import_entry(struct Sass_Compiler* compiler, size_t idx);
214+
// Getters for Sass_Compiler options (query function stack)
215+
size_t sass_compiler_get_callee_stack_size(struct Sass_Compiler* compiler);
216+
Sass_Callee_Entry sass_compiler_get_last_callee(struct Sass_Compiler* compiler);
217+
Sass_Callee_Entry sass_compiler_get_callee_entry(struct Sass_Compiler* compiler, size_t idx);
218+
210219
// Take ownership of memory (value on context is set to 0)
211220
char* sass_context_take_error_json (struct Sass_Context* ctx);
212221
char* sass_context_take_error_text (struct Sass_Context* ctx);
213222
char* sass_context_take_error_message (struct Sass_Context* ctx);
214223
char* sass_context_take_error_file (struct Sass_Context* ctx);
215224
char* sass_context_take_output_string (struct Sass_Context* ctx);
216225
char* sass_context_take_source_map_string (struct Sass_Context* ctx);
217-
218-
// Push function for plugin/include paths (no manipulation support for now)
219-
void sass_option_push_plugin_path (struct Sass_Options* options, const char* path);
220-
void sass_option_push_include_path (struct Sass_Options* options, const char* path);
221226
```
222227
223228
### Sass Options API
@@ -236,13 +241,15 @@ const char* sass_option_get_indent (struct Sass_Options* options);
236241
const char* sass_option_get_linefeed (struct Sass_Options* options);
237242
const char* sass_option_get_input_path (struct Sass_Options* options);
238243
const char* sass_option_get_output_path (struct Sass_Options* options);
239-
const char* sass_option_get_plugin_path (struct Sass_Options* options);
240-
const char* sass_option_get_include_path (struct Sass_Options* options);
241244
const char* sass_option_get_source_map_file (struct Sass_Options* options);
242245
const char* sass_option_get_source_map_root (struct Sass_Options* options);
243246
Sass_C_Function_List sass_option_get_c_functions (struct Sass_Options* options);
244247
Sass_C_Import_Callback sass_option_get_importer (struct Sass_Options* options);
245248
249+
// Getters for Context_Option include path array
250+
size_t sass_option_get_include_path_size(struct Sass_Options* options);
251+
const char* sass_option_get_include_path(struct Sass_Options* options, size_t i);
252+
246253
// Setters for Context_Option values
247254
void sass_option_set_precision (struct Sass_Options* options, int precision);
248255
void sass_option_set_output_style (struct Sass_Options* options, enum Sass_Output_Style output_style);
@@ -266,6 +273,16 @@ void sass_option_set_importer (struct Sass_Options* options, Sass_C_Import_Callb
266273
// Push function for paths (no manipulation support for now)
267274
void sass_option_push_plugin_path (struct Sass_Options* options, const char* path);
268275
void sass_option_push_include_path (struct Sass_Options* options, const char* path);
276+
277+
// Resolve a file via the given include paths in the sass option struct
278+
// find_file looks for the exact file name while find_include does a regular sass include
279+
char* sass_find_file (const char* path, struct Sass_Options* opt);
280+
char* sass_find_include (const char* path, struct Sass_Options* opt);
281+
282+
// Resolve a file relative to last import or include paths in the sass option struct
283+
// find_file looks for the exact file name while find_include does a regular sass include
284+
char* sass_compiler_find_file (const char* path, struct Sass_Compiler* compiler);
285+
char* sass_compiler_find_include (const char* path, struct Sass_Compiler* compiler);
269286
```
270287

271288
### More links

docs/api-doc.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ void sass_free_memory(void* ptr);
125125
char* sass_string_unquote (const char* str);
126126
char* sass_string_quote (const char* str, const char quote_mark);
127127
128-
// Resolve a file via the given include paths in the include char* array
129-
char* sass_resolve_file (const char* path, const char* incs[]);
130-
131128
// Get compiled libsass version
132129
const char* libsass_version(void);
133130

docs/api-function-example.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ union Sass_Value* call_fn_foo(const union Sass_Value* s_args, Sass_Function_Entr
1111
struct Sass_Context* ctx = sass_compiler_get_context(comp);
1212
struct Sass_Options* opts = sass_compiler_get_options(comp);
1313
// get information about previous importer entry from the stack
14-
struct Sass_Import* import = sass_compiler_get_last_import(comp);
14+
Sass_Import_Entry import = sass_compiler_get_last_import(comp);
1515
const char* prev_abs_path = sass_import_get_abs_path(import);
1616
const char* prev_imp_path = sass_import_get_imp_path(import);
1717
// get the cookie from function descriptor

docs/api-function.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,38 @@ typedef union Sass_Value* (*Sass_Function_Fn)
3030
(const union Sass_Value*, Sass_Function_Entry cb, struct Sass_Compiler* compiler);
3131

3232
// Creators for sass function list and function descriptors
33-
ADDAPI Sass_Function_List ADDCALL sass_make_function_list (size_t length);
34-
ADDAPI Sass_Function_Entry ADDCALL sass_make_function (const char* signature, Sass_Function_Fn cb, void* cookie);
33+
Sass_Function_List sass_make_function_list (size_t length);
34+
Sass_Function_Entry sass_make_function (const char* signature, Sass_Function_Fn cb, void* cookie);
3535

3636
// Setters and getters for callbacks on function lists
37-
ADDAPI Sass_Function_Entry ADDCALL sass_function_get_list_entry(Sass_Function_List list, size_t pos);
38-
ADDAPI void ADDCALL sass_function_set_list_entry(Sass_Function_List list, size_t pos, Sass_Function_Entry cb);
37+
Sass_Function_Entry sass_function_get_list_entry(Sass_Function_List list, size_t pos);
38+
void sass_function_set_list_entry(Sass_Function_List list, size_t pos, Sass_Function_Entry cb);
39+
40+
// Setters to insert an entry into the import list (you may also use [] access directly)
41+
// Since we are dealing with pointers they should have a guaranteed and fixed size
42+
void sass_import_set_list_entry (Sass_Import_List list, size_t idx, Sass_Import_Entry entry);
43+
Sass_Import_Entry sass_import_get_list_entry (Sass_Import_List list, size_t idx);
3944

4045
// Getters for custom function descriptors
41-
ADDAPI const char* ADDCALL sass_function_get_signature (Sass_Function_Entry cb);
42-
ADDAPI Sass_Function_Fn ADDCALL sass_function_get_function (Sass_Function_Entry cb);
43-
ADDAPI void* ADDCALL sass_function_get_cookie (Sass_Function_Entry cb);
46+
const char* sass_function_get_signature (Sass_Function_Entry cb);
47+
Sass_Function_Fn sass_function_get_function (Sass_Function_Entry cb);
48+
void* sass_function_get_cookie (Sass_Function_Entry cb);
49+
50+
// Getters for callee entry
51+
const char* sass_callee_get_name (Sass_Callee_Entry);
52+
const char* sass_callee_get_path (Sass_Callee_Entry);
53+
size_t sass_callee_get_line (Sass_Callee_Entry);
54+
size_t sass_callee_get_column (Sass_Callee_Entry);
55+
enum Sass_Callee_Type sass_callee_get_type (Sass_Callee_Entry);
56+
Sass_Env_Frame sass_callee_get_env (Sass_Callee_Entry);
57+
58+
// Getters and Setters for environments (lexical, local and global)
59+
union Sass_Value* sass_env_get_lexical (Sass_Env_Frame, const char*);
60+
void sass_env_set_lexical (Sass_Env_Frame, const char*, union Sass_Value*);
61+
union Sass_Value* sass_env_get_local (Sass_Env_Frame, const char*);
62+
void sass_env_set_local (Sass_Env_Frame, const char*, union Sass_Value*);
63+
union Sass_Value* sass_env_get_global (Sass_Env_Frame, const char*);
64+
void sass_env_set_global (Sass_Env_Frame, const char*, union Sass_Value*);
4465
```
4566
4667
### More links

docs/api-importer.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ By using custom importers, Sass stylesheets can be implemented in any possible w
55
You actually have to return a list of imports, since some importers may want to import multiple files from one import statement (ie. a glob/star importer). The memory you pass with source and srcmap is taken over by LibSass and freed automatically when the import is done. You are also allowed to return `0` instead of a list, which will tell LibSass to handle the import by itself (as if no custom importer was in use).
66

77
```C
8-
struct Sass_Import** rv = sass_make_import_list(1);
8+
Sass_Import_Entry* rv = sass_make_import_list(1);
99
rv[0] = sass_make_import(rel, abs, source, srcmap);
1010
```
1111

@@ -31,7 +31,7 @@ struct Sass_C_Import_Descriptor;
3131
// Typedef defining the custom importer callback
3232
typedef struct Sass_C_Import_Descriptor (*Sass_C_Import_Callback);
3333
// Typedef defining the importer c function prototype
34-
typedef struct Sass_Import** (*Sass_C_Import_Fn) (const char* url, const char* prev, void* cookie);
34+
typedef Sass_Import_Entry* (*Sass_C_Import_Fn) (const char* url, const char* prev, void* cookie);
3535

3636
// Creators for custom importer callback (with some additional pointer)
3737
// The pointer is mostly used to store the callback into the actual function
@@ -45,38 +45,38 @@ void* sass_import_get_cookie (Sass_C_Import_Callback fn);
4545
void sass_delete_importer (Sass_C_Import_Callback fn);
4646

4747
// Creator for sass custom importer return argument list
48-
struct Sass_Import** sass_make_import_list (size_t length);
48+
Sass_Import_Entry* sass_make_import_list (size_t length);
4949
// Creator for a single import entry returned by the custom importer inside the list
50-
struct Sass_Import* sass_make_import_entry (const char* path, char* source, char* srcmap);
51-
struct Sass_Import* sass_make_import (const char* rel, const char* abs, char* source, char* srcmap);
50+
Sass_Import_Entry sass_make_import_entry (const char* path, char* source, char* srcmap);
51+
Sass_Import_Entry sass_make_import (const char* rel, const char* abs, char* source, char* srcmap);
5252

5353
// set error message to abort import and to print out a message (path from existing object is used in output)
54-
struct Sass_Import* sass_import_set_error(struct Sass_Import* import, const char* message, size_t line, size_t col);
54+
Sass_Import_Entry sass_import_set_error(Sass_Import_Entry import, const char* message, size_t line, size_t col);
5555

5656
// Setters to insert an entry into the import list (you may also use [] access directly)
5757
// Since we are dealing with pointers they should have a guaranteed and fixed size
58-
void sass_import_set_list_entry (struct Sass_Import** list, size_t idx, struct Sass_Import* entry);
59-
struct Sass_Import* sass_import_get_list_entry (struct Sass_Import** list, size_t idx);
58+
void sass_import_set_list_entry (Sass_Import_Entry* list, size_t idx, Sass_Import_Entry entry);
59+
Sass_Import_Entry sass_import_get_list_entry (Sass_Import_Entry* list, size_t idx);
6060

6161
// Getters for import entry
62-
const char* sass_import_get_rel_path (struct Sass_Import*);
63-
const char* sass_import_get_abs_path (struct Sass_Import*);
64-
const char* sass_import_get_source (struct Sass_Import*);
65-
const char* sass_import_get_srcmap (struct Sass_Import*);
62+
const char* sass_import_get_imp_path (Sass_Import_Entry);
63+
const char* sass_import_get_abs_path (Sass_Import_Entry);
64+
const char* sass_import_get_source (Sass_Import_Entry);
65+
const char* sass_import_get_srcmap (Sass_Import_Entry);
6666
// Explicit functions to take ownership of these items
6767
// The property on our struct will be reset to NULL
68-
char* sass_import_take_source (struct Sass_Import*);
69-
char* sass_import_take_srcmap (struct Sass_Import*);
68+
char* sass_import_take_source (Sass_Import_Entry);
69+
char* sass_import_take_srcmap (Sass_Import_Entry);
7070

7171
// Getters for import error entries
72-
size_t sass_import_get_error_line (struct Sass_Import*);
73-
size_t sass_import_get_error_column (struct Sass_Import*);
74-
const char* sass_import_get_error_message (struct Sass_Import*);
72+
size_t sass_import_get_error_line (Sass_Import_Entry);
73+
size_t sass_import_get_error_column (Sass_Import_Entry);
74+
const char* sass_import_get_error_message (Sass_Import_Entry);
7575

7676
// Deallocator for associated memory (incl. entries)
77-
void sass_delete_import_list (struct Sass_Import**);
77+
void sass_delete_import_list (Sass_Import_Entry*);
7878
// Just in case we have some stray import structs
79-
void sass_delete_import (struct Sass_Import*);
79+
void sass_delete_import (Sass_Import_Entry);
8080
```
8181
8282
### More links

include/sass/base.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ ADDAPI void ADDCALL sass_free_memory(void* ptr);
7575
ADDAPI char* ADDCALL sass_string_quote (const char* str, const char quote_mark);
7676
ADDAPI char* ADDCALL sass_string_unquote (const char* str);
7777

78-
// Resolve a file via the given include paths in the include char* array
79-
ADDAPI char* ADDCALL sass_resolve_file (const char* path, const char* incs[]);
80-
8178
// Implemented sass language version
8279
// Hardcoded version 3.4 for time being
8380
ADDAPI const char* ADDCALL libsass_version(void);

include/sass/context.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ ADDAPI const char* ADDCALL sass_option_get_indent (struct Sass_Options* options)
8181
ADDAPI const char* ADDCALL sass_option_get_linefeed (struct Sass_Options* options);
8282
ADDAPI const char* ADDCALL sass_option_get_input_path (struct Sass_Options* options);
8383
ADDAPI const char* ADDCALL sass_option_get_output_path (struct Sass_Options* options);
84-
ADDAPI const char* ADDCALL sass_option_get_plugin_path (struct Sass_Options* options);
85-
ADDAPI const char* ADDCALL sass_option_get_include_path (struct Sass_Options* options);
8684
ADDAPI const char* ADDCALL sass_option_get_source_map_file (struct Sass_Options* options);
8785
ADDAPI const char* ADDCALL sass_option_get_source_map_root (struct Sass_Options* options);
8886
ADDAPI Sass_Importer_List ADDCALL sass_option_get_c_headers (struct Sass_Options* options);
@@ -124,6 +122,10 @@ ADDAPI size_t ADDCALL sass_context_get_error_column (struct Sass_Context* ctx);
124122
ADDAPI const char* ADDCALL sass_context_get_source_map_string (struct Sass_Context* ctx);
125123
ADDAPI char** ADDCALL sass_context_get_included_files (struct Sass_Context* ctx);
126124

125+
// Getters for options include path array
126+
ADDAPI size_t ADDCALL sass_option_get_include_path_size(struct Sass_Options* options);
127+
ADDAPI const char* ADDCALL sass_option_get_include_path(struct Sass_Options* options, size_t i);
128+
127129
// Calculate the size of the stored null terminated array
128130
ADDAPI size_t ADDCALL sass_context_get_included_files_size (struct Sass_Context* ctx);
129131

@@ -143,11 +145,24 @@ ADDAPI struct Sass_Options* ADDCALL sass_compiler_get_options(struct Sass_Compil
143145
ADDAPI size_t ADDCALL sass_compiler_get_import_stack_size(struct Sass_Compiler* compiler);
144146
ADDAPI Sass_Import_Entry ADDCALL sass_compiler_get_last_import(struct Sass_Compiler* compiler);
145147
ADDAPI Sass_Import_Entry ADDCALL sass_compiler_get_import_entry(struct Sass_Compiler* compiler, size_t idx);
148+
ADDAPI size_t ADDCALL sass_compiler_get_callee_stack_size(struct Sass_Compiler* compiler);
149+
ADDAPI Sass_Callee_Entry ADDCALL sass_compiler_get_last_callee(struct Sass_Compiler* compiler);
150+
ADDAPI Sass_Callee_Entry ADDCALL sass_compiler_get_callee_entry(struct Sass_Compiler* compiler, size_t idx);
146151

147152
// Push function for paths (no manipulation support for now)
148153
ADDAPI void ADDCALL sass_option_push_plugin_path (struct Sass_Options* options, const char* path);
149154
ADDAPI void ADDCALL sass_option_push_include_path (struct Sass_Options* options, const char* path);
150155

156+
// Resolve a file via the given include paths in the sass option struct
157+
// find_file looks for the exact file name while find_include does a regular sass include
158+
ADDAPI char* ADDCALL sass_find_file (const char* path, struct Sass_Options* opt);
159+
ADDAPI char* ADDCALL sass_find_include (const char* path, struct Sass_Options* opt);
160+
161+
// Resolve a file relative to last import or include paths in the sass option struct
162+
// find_file looks for the exact file name while find_include does a regular sass include
163+
ADDAPI char* ADDCALL sass_compiler_find_file (const char* path, struct Sass_Compiler* compiler);
164+
ADDAPI char* ADDCALL sass_compiler_find_include (const char* path, struct Sass_Compiler* compiler);
165+
151166
#ifdef __cplusplus
152167
} // __cplusplus defined.
153168
#endif

0 commit comments

Comments
 (0)