Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Clean up function macros and force to return PreValues
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Mar 17, 2018
1 parent 37e15bb commit d0b6338
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "ast_def_macros.hpp"
#include "ast_fwd_decl.hpp"
#include "source_map.hpp"
#include "fn_utils.hpp"

#include "sass.h"

Expand Down Expand Up @@ -913,8 +914,6 @@ namespace Sass {
// Definitions for both mixins and functions. The two cases are distinguished
// by a type tag.
/////////////////////////////////////////////////////////////////////////////
struct Backtrace;
typedef Expression_Ptr (*Native_Function)(Env&, Env&, Context&, Signature, ParserState, Backtraces, SelectorStack);
class Definition : public Has_Block {
public:
enum Type { MIXIN, FUNCTION };
Expand Down
1 change: 0 additions & 1 deletion src/ast_fwd_decl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ namespace Sass {
typedef std::vector<Selector_List_Obj> SelectorStack;
typedef std::vector<Sass_Import_Entry> ImporterStack;

typedef const char* Signature;
// only to switch implementations for testing
#define environment_map std::map

Expand Down
2 changes: 1 addition & 1 deletion src/fn_miscs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace Sass {
Expand expand(ctx, &d_env, &selector_stack);
func->via_call(true); // calc invoke is allowed
if (ff) func->func(ff);
return func->perform(&expand.eval);
return Cast<PreValue>(func->perform(&expand.eval));
}

////////////////////
Expand Down
17 changes: 12 additions & 5 deletions src/fn_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,23 @@

namespace Sass {

#define BUILT_IN(name) Expression_Ptr \
name(Env& env, Env& d_env, Context& ctx, Signature sig, ParserState pstate, Backtraces traces, SelectorStack selector_stack)
#define FN_PROTOTYPE \
Env& env, \
Env& d_env, \
Context& ctx, \
Signature sig, \
ParserState pstate, \
Backtraces& traces, \
SelectorStack& selector_stack

typedef const char* Signature;
typedef PreValue_Ptr (*Native_Function)(FN_PROTOTYPE);
#define BUILT_IN(name) PreValue_Ptr name(FN_PROTOTYPE)

#define ARG(argname, argtype) get_arg<argtype>(argname, env, sig, pstate, traces)

// special function for weird hsla percent (10px == 10% == 10 != 0.1)
#define ARGVAL(argname) get_arg_val(argname, env, sig, pstate, traces) // double

typedef Expression_Ptr (*Native_Function)(Env&, Env&, Context&, Signature, ParserState, Backtraces, SelectorStack);

Definition_Ptr make_native_function(Signature, Native_Function, Context& ctx);
Definition_Ptr make_c_function(Sass_Function_Entry c_func, Context& ctx);

Expand Down

0 comments on commit d0b6338

Please sign in to comment.